@mica-js/editor 0.13.0 → 0.15.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/fused.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { c as planPolylineSegmentDrag, n as orthogonalWaypoints, t as extendWirePath } from "./wire-JZIiIOI0.js";
2
- import { Q as isHtmlViewError, _ as resolveTheme, a as createHtmlViewHost, f as WORKBENCH_DARK_COLORS, g as readCanvasTheme, h as normalizeTheme, m as WORKBENCH_THEME_CSS_VARIABLES, p as WORKBENCH_LIGHT_COLORS, v as themeStyle } from "./html-HXwZq1my.js";
3
- import { a as createFusedRuntime } from "./runtime-hyeAcSP7.js";
2
+ import { Z as isHtmlViewError, _ as resolveTheme, a as createHtmlViewHost, f as WORKBENCH_DARK_COLORS, g as readCanvasTheme, h as normalizeTheme, m as WORKBENCH_THEME_CSS_VARIABLES, p as WORKBENCH_LIGHT_COLORS, v as themeStyle } from "./html-B0pN-5Mx.js";
3
+ import { a as createFusedRuntime, d as loggedStartupFailures, f as summarizeStartup, m as writeWorkbenchConsole, p as writeFusedLog } from "./runtime-DuxZ_yVl.js";
4
4
  import { DisposableStore, Emitter } from "@mica-js/core/lifecycle";
5
5
  import { projectOnSegment } from "@mica-js/document/schematic";
6
6
  import { timePs } from "@mica-js/core";
7
7
  import { createRoot } from "react-dom/client";
8
8
  import { flushSync } from "react-dom";
9
9
  import { FusedDocumentError, deriveFusedTopology, parseFusedDocument, parseGeometry2D } from "@mica-js/document/fused";
10
- import { PreparationError, openDevicePackage, resolveInstanceProperties } from "@mica-js/sdk/fused";
10
+ import { PreparationError, openDevicePackage, resolveCompatibleDeviceLock, resolveInstanceProperties } from "@mica-js/sdk/fused";
11
11
  import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
12
12
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
13
  //#region src/fused/context/keys.ts
@@ -2446,6 +2446,7 @@ var FusedDocumentSession = class FusedDocumentSession {
2446
2446
  #saveDocument;
2447
2447
  #access;
2448
2448
  #packages;
2449
+ #resolutionError;
2449
2450
  #createId;
2450
2451
  #historyLimit;
2451
2452
  #subscriptions = new DisposableStore();
@@ -2456,6 +2457,7 @@ var FusedDocumentSession = class FusedDocumentSession {
2456
2457
  #contentKeys = /* @__PURE__ */ new WeakMap();
2457
2458
  #document;
2458
2459
  #savedKey;
2460
+ #pendingResolvedLocks;
2459
2461
  #past = [];
2460
2462
  #future = [];
2461
2463
  #decisions;
@@ -2469,14 +2471,16 @@ var FusedDocumentSession = class FusedDocumentSession {
2469
2471
  #appliedRevision = 0;
2470
2472
  #disposed = false;
2471
2473
  #lastStateSignature = "";
2472
- constructor(options, document, decisions) {
2474
+ constructor(options, document, decisions, pendingResolvedLocks, resolutionError) {
2473
2475
  this.#saveDocument = options.saveDocument;
2474
2476
  this.#access = options.access;
2475
2477
  this.#packages = new DeviceCache(options.devices);
2478
+ this.#resolutionError = resolutionError;
2476
2479
  this.#createId = options.createId ?? (() => globalThis.crypto.randomUUID());
2477
2480
  this.#historyLimit = options.historyLimit ?? DEFAULT_HISTORY_LIMIT;
2478
2481
  this.#document = document;
2479
2482
  this.#savedKey = canonicalJson(document);
2483
+ this.#pendingResolvedLocks = pendingResolvedLocks;
2480
2484
  this.#decisions = decisions;
2481
2485
  }
2482
2486
  /**
@@ -2495,8 +2499,15 @@ var FusedDocumentSession = class FusedDocumentSession {
2495
2499
  } catch (cause) {
2496
2500
  throw toSessionError(cause, "edit/invalid-document");
2497
2501
  }
2502
+ const original = document;
2503
+ let resolutionError;
2504
+ if (options.deviceVersionPolicy === "compatible" && options.devices.resolve !== void 0) try {
2505
+ document = await resolveDocumentDevices(original, options.devices);
2506
+ } catch (cause) {
2507
+ resolutionError = toSessionError(cause, "device/unavailable");
2508
+ }
2498
2509
  const decisions = await evaluateDecisions(options.access, document);
2499
- const session = new FusedDocumentSession(options, document, decisions);
2510
+ const session = new FusedDocumentSession(options, document, decisions, document !== original, resolutionError);
2500
2511
  await session.#start();
2501
2512
  session.#subscriptions.add(options.access.onDidChange(() => {
2502
2513
  session.#refreshAccessInBackground();
@@ -2525,8 +2536,8 @@ var FusedDocumentSession = class FusedDocumentSession {
2525
2536
  dirty: this.#documentKey(this.#document) !== this.#savedKey,
2526
2537
  readOnly,
2527
2538
  running: this.#running,
2528
- canEditContent: !readOnly && !this.#running,
2529
- canEditLayout: !readOnly,
2539
+ canEditContent: !readOnly && this.#resolutionError === void 0 && !this.#running,
2540
+ canEditLayout: !readOnly && this.#resolutionError === void 0,
2530
2541
  access: this.#decisions
2531
2542
  };
2532
2543
  }
@@ -2554,6 +2565,7 @@ var FusedDocumentSession = class FusedDocumentSession {
2554
2565
  /** Manifests, geometry and verified files of every device the document uses. */
2555
2566
  getPreparedDevices() {
2556
2567
  return this.#enqueue(async () => {
2568
+ if (this.#resolutionError !== void 0) throw this.#resolutionError;
2557
2569
  const prepared = await this.#packages.prepareDocument(this.#document);
2558
2570
  this.#prepared = sameDevices(this.#prepared, prepared) ? this.#prepared : prepared;
2559
2571
  return this.#prepared;
@@ -2580,6 +2592,7 @@ var FusedDocumentSession = class FusedDocumentSession {
2580
2592
  if (running) {
2581
2593
  const decision = decisions.run;
2582
2594
  if (!decision.allowed) throw accessDenied("access/run-denied", decision);
2595
+ if (this.#resolutionError !== void 0) throw this.#resolutionError;
2583
2596
  }
2584
2597
  if (running === this.#running) {
2585
2598
  this.#publishState();
@@ -2771,6 +2784,7 @@ var FusedDocumentSession = class FusedDocumentSession {
2771
2784
  const document = this.#document;
2772
2785
  await this.#authorize("layout", document, document);
2773
2786
  if (this.#saveDocument === void 0) throw new FusedSessionError("save/unavailable", "The host does not provide document saving.");
2787
+ if (this.#pendingResolvedLocks && this.#documentKey(document) === this.#savedKey) return;
2774
2788
  try {
2775
2789
  await this.#saveDocument(document);
2776
2790
  } catch (cause) {
@@ -2778,6 +2792,7 @@ var FusedDocumentSession = class FusedDocumentSession {
2778
2792
  }
2779
2793
  this.#assertAlive();
2780
2794
  this.#savedKey = this.#documentKey(document);
2795
+ this.#pendingResolvedLocks = false;
2781
2796
  this.#publishState();
2782
2797
  });
2783
2798
  }
@@ -2821,6 +2836,7 @@ var FusedDocumentSession = class FusedDocumentSession {
2821
2836
  }
2822
2837
  async #start() {
2823
2838
  try {
2839
+ if (this.#resolutionError !== void 0) throw this.#resolutionError;
2824
2840
  const verified = await verifyFusedDocument(this.#document, this.#packages);
2825
2841
  this.#document = verified.document;
2826
2842
  this.#prepared = verified.devices;
@@ -2844,6 +2860,7 @@ var FusedDocumentSession = class FusedDocumentSession {
2844
2860
  return this.#enqueue(async () => {
2845
2861
  await this.#settleAccess();
2846
2862
  this.#requireEdit(mode);
2863
+ if (this.#resolutionError !== void 0) throw this.#resolutionError;
2847
2864
  const current = this.#document;
2848
2865
  const built = await build(current);
2849
2866
  const verified = await verifyFusedDocument(built.document, this.#packages, {
@@ -3126,6 +3143,29 @@ function sameDevices(previous, next) {
3126
3143
  for (const [deviceId, device] of previous) if (next.get(deviceId) !== device) return false;
3127
3144
  return true;
3128
3145
  }
3146
+ async function resolveDocumentDevices(document, registry) {
3147
+ const ids = new Set(document.instances.map((instance) => instance.device));
3148
+ const dependencies = { ...document.dependencies };
3149
+ let changed = false;
3150
+ for (const id of ids) {
3151
+ const dependency = document.dependencies[id];
3152
+ if (dependency === void 0) continue;
3153
+ const lock = await resolveCompatibleDeviceLock(registry, {
3154
+ id,
3155
+ ...dependency
3156
+ });
3157
+ if (lock.version === dependency.version) continue;
3158
+ dependencies[id] = {
3159
+ version: lock.version,
3160
+ integrity: lock.integrity
3161
+ };
3162
+ changed = true;
3163
+ }
3164
+ return changed ? parseFusedDocument({
3165
+ ...document,
3166
+ dependencies
3167
+ }) : document;
3168
+ }
3129
3169
  function canonicalJson(value) {
3130
3170
  if (value === null || typeof value === "boolean" || typeof value === "number") return JSON.stringify(value) ?? "null";
3131
3171
  if (typeof value === "string") return JSON.stringify(value);
@@ -3646,8 +3686,8 @@ function CanvasPart(props) {
3646
3686
  const business = useRef(void 0);
3647
3687
  const current = useRef(props);
3648
3688
  current.current = props;
3649
- const run = (task) => {
3650
- task.catch(props.onError);
3689
+ const run = (operation, task) => {
3690
+ task.catch((error) => props.onOperationFailure(operation, error));
3651
3691
  };
3652
3692
  const fit = () => setViewport(fitViewport(props.document, props.devices, size.width, size.height));
3653
3693
  const zoom = (factor, center = {
@@ -3879,10 +3919,10 @@ function CanvasPart(props) {
3879
3919
  }
3880
3920
  return best?.point ?? snap(point, alt);
3881
3921
  }
3882
- function commit(action) {
3922
+ function commit(operation, action) {
3883
3923
  if (committing.current) return;
3884
3924
  committing.current = true;
3885
- action().catch(props.onError).finally(() => {
3925
+ action().catch((error) => props.onOperationFailure(operation, error)).finally(() => {
3886
3926
  committing.current = false;
3887
3927
  });
3888
3928
  }
@@ -3900,14 +3940,14 @@ function CanvasPart(props) {
3900
3940
  return;
3901
3941
  }
3902
3942
  if (props.state.tool !== "wire") {
3903
- commit(() => props.onEndpoint(endpoint));
3943
+ commit(props.state.tool === "label" ? "label.add" : "reference.add", () => props.onEndpoint(endpoint));
3904
3944
  return;
3905
3945
  }
3906
3946
  if (connection === void 0) setConnection({
3907
3947
  endpoint,
3908
3948
  bends: []
3909
3949
  });
3910
- else commit(async () => {
3950
+ else commit("wire.add", async () => {
3911
3951
  await props.onConnect(connection.endpoint, endpoint, connection.bends);
3912
3952
  setConnection(void 0);
3913
3953
  props.onCancel();
@@ -3929,7 +3969,7 @@ function CanvasPart(props) {
3929
3969
  return;
3930
3970
  }
3931
3971
  pendingWireStart.current = endpoint;
3932
- commit(async () => {
3972
+ commit("canvas.setTool", async () => {
3933
3973
  try {
3934
3974
  await props.onStartWire();
3935
3975
  } catch (error) {
@@ -3984,7 +4024,7 @@ function CanvasPart(props) {
3984
4024
  setCandidates([]);
3985
4025
  cancelGesture();
3986
4026
  props.onCancel();
3987
- run(props.onDelete());
4027
+ run("selection.delete", props.onDelete());
3988
4028
  }
3989
4029
  },
3990
4030
  onPointerDown: (event) => {
@@ -4028,7 +4068,7 @@ function CanvasPart(props) {
4028
4068
  }
4029
4069
  const placing = props.placement;
4030
4070
  if (placing !== void 0 && !props.state.readOnly) {
4031
- commit(() => props.onPlace(placing, snap(point, event.altKey)));
4071
+ commit("device.add", () => props.onPlace(placing, snap(point, event.altKey)));
4032
4072
  return;
4033
4073
  }
4034
4074
  if (props.state.tool !== "select" && !props.state.readOnly) {
@@ -4272,21 +4312,21 @@ function CanvasPart(props) {
4272
4312
  x: active.original.x + point.x - active.start.x,
4273
4313
  y: active.original.y + point.y - active.start.y
4274
4314
  }, event.altKey);
4275
- if (position.x !== active.original.x || position.y !== active.original.y) run(props.onMove(active.instanceId, position));
4315
+ if (position.x !== active.original.x || position.y !== active.original.y) run("device.move", props.onMove(active.instanceId, position));
4276
4316
  } else if (active?.kind === "wire") {
4277
4317
  const point = toScene(local(event), viewport);
4278
4318
  const delta = snap({
4279
4319
  x: point.x - active.start.x,
4280
4320
  y: point.y - active.start.y
4281
4321
  }, event.altKey);
4282
- if (delta.x !== 0 || delta.y !== 0) commit(() => props.onMoveSegment(active.wireId, active.segment, delta));
4322
+ if (delta.x !== 0 || delta.y !== 0) commit("wire.moveSegment", () => props.onMoveSegment(active.wireId, active.segment, delta));
4283
4323
  } else if (active?.kind === "text") {
4284
4324
  const point = toScene(local(event), viewport);
4285
4325
  const delta = snap({
4286
4326
  x: point.x - active.start.x,
4287
4327
  y: point.y - active.start.y
4288
4328
  }, event.altKey);
4289
- if (delta.x !== 0 || delta.y !== 0) commit(() => props.onMoveText(active.target, textDragOffset(props.document, props.devices, active.target, delta)));
4329
+ if (delta.x !== 0 || delta.y !== 0) commit("text.move", () => props.onMoveText(active.target, textDragOffset(props.document, props.devices, active.target, delta)));
4290
4330
  else if (active.target.kind === "reference") {
4291
4331
  const reference = props.document.references.find((value) => value.id === active.target.id);
4292
4332
  if (reference !== void 0 && atAnchor(reference.target, active.start)) startWire(reference.target);
@@ -4298,7 +4338,7 @@ function CanvasPart(props) {
4298
4338
  x: active.original.x + point.x - active.start.x,
4299
4339
  y: active.original.y + point.y - active.start.y
4300
4340
  }, event.altKey);
4301
- if (position.x !== active.original.x || position.y !== active.original.y) commit(() => props.onMoveLabel(active.labelId, position));
4341
+ if (position.x !== active.original.x || position.y !== active.original.y) commit("label.move", () => props.onMoveLabel(active.labelId, position));
4302
4342
  }
4303
4343
  } else if (active?.kind === "reference") {
4304
4344
  if (active.moved) {
@@ -4307,7 +4347,7 @@ function CanvasPart(props) {
4307
4347
  x: active.original.x + point.x - active.start.x,
4308
4348
  y: active.original.y + point.y - active.start.y
4309
4349
  }, event.altKey);
4310
- if (position.x !== active.original.x || position.y !== active.original.y) commit(() => props.onMoveReference(active.referenceId, position));
4350
+ if (position.x !== active.original.x || position.y !== active.original.y) commit("reference.move", () => props.onMoveReference(active.referenceId, position));
4311
4351
  } else {
4312
4352
  const reference = props.document.references.find((value) => value.id === active.referenceId);
4313
4353
  if (reference !== void 0 && atAnchor(reference.target, active.start)) startWire(reference.target);
@@ -4548,18 +4588,18 @@ function ToolbarPart(props) {
4548
4588
  const visible = items.slice(0, layout.count);
4549
4589
  const overflow = items.slice(layout.count);
4550
4590
  const runMode = props.state.mode === "run";
4551
- const control = (action) => {
4591
+ const control = (operation, action) => {
4552
4592
  setMore(false);
4553
4593
  setControlling(true);
4554
- action().catch(props.onError).finally(() => setControlling(false));
4594
+ action().catch((error) => props.onOperationFailure(operation, error)).finally(() => setControlling(false));
4555
4595
  };
4556
4596
  const execute = (item) => {
4557
4597
  setMore(false);
4558
4598
  if (!props.registry.enabled(item)) return;
4559
4599
  try {
4560
- Promise.resolve(item.execute(props.context)).catch(props.onError);
4600
+ Promise.resolve(item.execute(props.context)).catch((error) => props.onOperationFailure(item.id, error));
4561
4601
  } catch (error) {
4562
- props.onError(error);
4602
+ props.onOperationFailure(item.id, error);
4563
4603
  }
4564
4604
  };
4565
4605
  const itemButton = (item) => /* @__PURE__ */ jsxs("button", {
@@ -4609,12 +4649,12 @@ function ToolbarPart(props) {
4609
4649
  children: [/* @__PURE__ */ jsxs("button", {
4610
4650
  className: "is-primary",
4611
4651
  disabled: props.state.busy || controlling,
4612
- onClick: () => control(() => props.context.workbench.setMode(runMode ? "edit" : "run")),
4652
+ onClick: () => control(runMode ? "simulation.stop" : "simulation.start", () => props.context.workbench.setMode(runMode ? "edit" : "run")),
4613
4653
  children: [/* @__PURE__ */ jsx(Icon, { name: runMode ? "debug-stop" : "play" }), runMode ? "停止" : "运行"]
4614
4654
  }), runMode && /* @__PURE__ */ jsxs("button", {
4615
4655
  disabled: props.state.busy || controlling,
4616
4656
  title: "重启仿真",
4617
- onClick: () => control(() => props.context.workbench.executeCommand("simulation.restart")),
4657
+ onClick: () => control("simulation.restart", () => props.context.workbench.executeCommand("simulation.restart")),
4618
4658
  children: [/* @__PURE__ */ jsx(Icon, { name: "debug-restart" }), "重启"]
4619
4659
  })]
4620
4660
  }),
@@ -5613,20 +5653,83 @@ function InspectorView(props) {
5613
5653
  }
5614
5654
  //#endregion
5615
5655
  //#region src/fused/views/problems.tsx
5656
+ var levels = [
5657
+ {
5658
+ severity: "error",
5659
+ label: "错误",
5660
+ icon: "error"
5661
+ },
5662
+ {
5663
+ severity: "warning",
5664
+ label: "警告",
5665
+ icon: "warning"
5666
+ },
5667
+ {
5668
+ severity: "info",
5669
+ label: "提示",
5670
+ icon: "info"
5671
+ }
5672
+ ];
5673
+ var descriptions = {
5674
+ "layout/body-overlap": ["器件外形重叠", "可以在画布上移动器件,将它们分开。"],
5675
+ "view2d/unsupported": ["无法显示在 2D 视图中", "此器件未定义 2D 外形。"],
5676
+ "view2d/render-failed": ["2D 绘制失败", "器件的动态图形可能无法显示。"],
5677
+ "runtime/presentation-failed": ["器件显示异常", "视图可能无法显示或更新。"],
5678
+ "runtime/prepare-failed": ["仿真准备失败", "请查看技术详情,确认是哪个器件或资源未能加载。"],
5679
+ "device/unavailable": ["器件加载失败", "请检查文档锁定的器件版本是否可用。"],
5680
+ "view/load-failed": ["器件面板加载失败", "此面板暂时无法使用。"],
5681
+ "view/bridge-failed": ["器件面板连接中断", "面板无法与工作台交换数据。"],
5682
+ "view/execution-failed": ["器件面板运行异常", "面板中的数据或控件可能无法更新。"],
5683
+ "audio/failed": ["音频异常", "仿真声音可能无法播放或更新。"],
5684
+ "save/failed": ["文档保存失败", "本次修改尚未保存。"]
5685
+ };
5616
5686
  function ProblemsView(props) {
5617
- return /* @__PURE__ */ jsxs("section", {
5687
+ const instances = new Map(props.instances.map((instance) => [instance.id, instance]));
5688
+ return /* @__PURE__ */ jsx("section", {
5618
5689
  className: "mica-wb-problems",
5619
5690
  "aria-label": "问题",
5620
- children: [props.diagnostics.length === 0 && /* @__PURE__ */ jsx("p", {
5691
+ children: props.diagnostics.length === 0 ? /* @__PURE__ */ jsx("p", {
5621
5692
  className: "mica-wb-empty",
5622
- children: "没有发现问题"
5623
- }), props.diagnostics.map((diagnostic, index) => /* @__PURE__ */ jsxs("button", {
5624
- className: `mica-wb-diagnostic is-${diagnostic.severity}`,
5625
- onClick: () => {
5626
- if (diagnostic.instanceId !== void 0) props.onReveal(diagnostic.instanceId);
5627
- },
5628
- children: [/* @__PURE__ */ jsx("strong", { children: diagnostic.code }), /* @__PURE__ */ jsx("span", { children: diagnostic.message })]
5629
- }, `${diagnostic.code}:${index}`))]
5693
+ children: "暂无问题"
5694
+ }) : /* @__PURE__ */ jsx("ul", {
5695
+ className: "mica-wb-problem-list",
5696
+ role: "list",
5697
+ children: levels.flatMap(({ severity, label, icon }) => props.diagnostics.filter((diagnostic) => diagnostic.severity === severity).map((diagnostic) => {
5698
+ const instance = instances.get(diagnostic.instanceId ?? "");
5699
+ const description = Object.hasOwn(descriptions, diagnostic.code) ? descriptions[diagnostic.code] : void 0;
5700
+ const title = description?.[0] ?? (diagnostic.message || "问题详情不可用");
5701
+ return /* @__PURE__ */ jsxs("li", {
5702
+ className: `mica-wb-diagnostic is-${severity}`,
5703
+ children: [
5704
+ /* @__PURE__ */ jsxs("span", {
5705
+ className: "mica-wb-diagnostic-level",
5706
+ children: [
5707
+ /* @__PURE__ */ jsx(Icon, { name: icon }),
5708
+ " ",
5709
+ label
5710
+ ]
5711
+ }),
5712
+ /* @__PURE__ */ jsx("strong", { children: instance?.designator ? `${instance.designator} · ${title}` : title }),
5713
+ description !== void 0 && /* @__PURE__ */ jsx("p", { children: description[1] }),
5714
+ instance !== void 0 && /* @__PURE__ */ jsx("button", {
5715
+ type: "button",
5716
+ onClick: () => props.onReveal(instance.id),
5717
+ children: instance.designator ? `定位 ${instance.designator}` : "定位器件"
5718
+ }),
5719
+ /* @__PURE__ */ jsxs("details", { children: [
5720
+ /* @__PURE__ */ jsx("summary", { children: "技术详情" }),
5721
+ /* @__PURE__ */ jsx("code", { children: diagnostic.code }),
5722
+ description !== void 0 && /* @__PURE__ */ jsx("p", { children: diagnostic.message })
5723
+ ] })
5724
+ ]
5725
+ }, JSON.stringify([
5726
+ severity,
5727
+ diagnostic.code,
5728
+ diagnostic.instanceId,
5729
+ diagnostic.message
5730
+ ]));
5731
+ }))
5732
+ })
5630
5733
  });
5631
5734
  }
5632
5735
  //#endregion
@@ -5695,7 +5798,7 @@ function HtmlViewsPart(props) {
5695
5798
  const [draft, setDraft] = useState({});
5696
5799
  const ordering = useRef(void 0);
5697
5800
  const running = ui.workbench.getState().mode === "run" && !ui.workbench.getState().busy;
5698
- const run = (task) => void task.catch(ui.error);
5801
+ const run = (operation, task) => void task.catch((error) => ui.failOperation(operation, error));
5699
5802
  const lastExpanded = layout.views.filter((view) => view.location === "sidebar" && !view.collapsed && manifest.view?.[view.viewId] !== void 0).at(-1)?.viewId;
5700
5803
  useEffect(() => {
5701
5804
  if (!running) return;
@@ -5721,7 +5824,7 @@ function HtmlViewsPart(props) {
5721
5824
  layout,
5722
5825
  ui
5723
5826
  ]);
5724
- const change = (viewId, patch) => run(ui.changeViewLayout(instance.id, {
5827
+ const change = (viewId, patch) => run("view.setLayout", ui.changeViewLayout(instance.id, {
5725
5828
  ...layout,
5726
5829
  views: layout.views.map((view) => view.viewId === viewId ? {
5727
5830
  ...view,
@@ -5760,7 +5863,7 @@ function HtmlViewsPart(props) {
5760
5863
  const [item] = ordered.splice(source, 1);
5761
5864
  if (item !== void 0) {
5762
5865
  ordered.splice(target, 0, item);
5763
- run(ui.changeViewLayout(instance.id, {
5866
+ run("view.setLayout", ui.changeViewLayout(instance.id, {
5764
5867
  ...layout,
5765
5868
  views: ordered
5766
5869
  }));
@@ -5786,7 +5889,7 @@ function HtmlViewsPart(props) {
5786
5889
  if (previous === void 0) return;
5787
5890
  ordered[index - 1] = view;
5788
5891
  ordered[index] = previous;
5789
- run(ui.changeViewLayout(instance.id, {
5892
+ run("view.setLayout", ui.changeViewLayout(instance.id, {
5790
5893
  ...layout,
5791
5894
  views: ordered
5792
5895
  }));
@@ -5795,7 +5898,7 @@ function HtmlViewsPart(props) {
5795
5898
  }), /* @__PURE__ */ jsx("button", {
5796
5899
  title: "浮动视图",
5797
5900
  "aria-label": `将${definition.title}设为浮动`,
5798
- onClick: () => run(ui.workbench.executeCommand("view.setLocation", {
5901
+ onClick: () => run("view.setLocation", ui.workbench.executeCommand("view.setLocation", {
5799
5902
  instanceId: instance.id,
5800
5903
  viewId: view.viewId,
5801
5904
  location: "floating"
@@ -5920,7 +6023,7 @@ function FloatingView({ ui, handle }) {
5920
6023
  ...view,
5921
6024
  floatingBounds: constrain(value)
5922
6025
  } : view)
5923
- }).catch(ui.error);
6026
+ }).catch((error) => ui.failOperation("view.setLayout", error));
5924
6027
  const start = (event, kind) => {
5925
6028
  if (event.button !== 0 || drag.current !== void 0) return;
5926
6029
  if (event.target instanceof Element && event.target.closest("button") !== null) return;
@@ -5975,23 +6078,18 @@ function FloatingView({ ui, handle }) {
5975
6078
  instance?.designator ?? handle.instanceId,
5976
6079
  " · ",
5977
6080
  handle.title
5978
- ] }), /* @__PURE__ */ jsxs("span", {
6081
+ ] }), /* @__PURE__ */ jsx("span", {
5979
6082
  className: "mica-wb-panel-actions",
5980
- children: [/* @__PURE__ */ jsx("button", {
5981
- title: "停靠视图",
6083
+ children: /* @__PURE__ */ jsx("button", {
6084
+ title: "停靠回信息侧栏",
5982
6085
  "aria-label": `停靠${handle.title}`,
5983
6086
  onClick: () => void ui.workbench.executeCommand("view.setLocation", {
5984
6087
  instanceId: handle.instanceId,
5985
6088
  viewId: handle.viewId,
5986
6089
  location: "sidebar"
5987
- }).catch(ui.error),
6090
+ }).catch((error) => ui.failOperation("view.setLocation", error)),
5988
6091
  children: /* @__PURE__ */ jsx(Icon, { name: "layout-sidebar-right" })
5989
- }), /* @__PURE__ */ jsx("button", {
5990
- title: "关闭视图",
5991
- "aria-label": `关闭${handle.title}`,
5992
- onClick: () => handle.close(),
5993
- children: /* @__PURE__ */ jsx(Icon, { name: "close" })
5994
- })]
6092
+ })
5995
6093
  })]
5996
6094
  }),
5997
6095
  /* @__PURE__ */ jsx(ViewSlot, {
@@ -6092,11 +6190,11 @@ function WorkbenchPart({ ui }) {
6092
6190
  };
6093
6191
  })();
6094
6192
  const layout = single === void 0 || manifest === void 0 ? void 0 : ui.viewLayout(single.id);
6095
- const run = (task) => {
6096
- task.catch(ui.error);
6193
+ const run = (operation, task) => {
6194
+ task.catch((error) => ui.failOperation(operation, error));
6097
6195
  };
6098
6196
  const setProperty = (key, value) => {
6099
- if (single !== void 0) run(ui.workbench.executeCommand("device.setProperty", {
6197
+ if (single !== void 0) run("device.setProperty", ui.workbench.executeCommand("device.setProperty", {
6100
6198
  instanceId: single.id,
6101
6199
  key,
6102
6200
  value
@@ -6117,7 +6215,7 @@ function WorkbenchPart({ ui }) {
6117
6215
  const propertyCollapsed = layout?.properties.collapsed ?? emptyPropertiesCollapsed;
6118
6216
  const toggleProperties = (collapsed) => {
6119
6217
  if (single === void 0 || layout === void 0) setEmptyPropertiesCollapsed(collapsed);
6120
- else run(ui.changeViewLayout(single.id, {
6218
+ else run("view.setLayout", ui.changeViewLayout(single.id, {
6121
6219
  ...layout,
6122
6220
  properties: {
6123
6221
  ...layout.properties,
@@ -6155,14 +6253,14 @@ function WorkbenchPart({ ui }) {
6155
6253
  const propertyActions = single === void 0 || layout === void 0 ? void 0 : /* @__PURE__ */ jsx("button", {
6156
6254
  title: "恢复视图布局",
6157
6255
  "aria-label": "恢复视图布局",
6158
- onClick: () => run(ui.changeViewLayout(single.id, void 0)),
6256
+ onClick: () => run("view.setLayout", ui.changeViewLayout(single.id, void 0)),
6159
6257
  children: /* @__PURE__ */ jsx(Icon, { name: "discard" })
6160
6258
  });
6161
6259
  const floatingActions = [...floating].filter(([, view]) => ui.htmlViews.get(view.instanceId, view.viewId) === void 0).map(([key, view]) => /* @__PURE__ */ jsx("button", {
6162
6260
  title: view.title,
6163
6261
  "aria-label": `${document.instances.find((instance) => instance.id === view.instanceId)?.designator ?? view.instanceId} ${view.title}`,
6164
6262
  disabled: state.busy,
6165
- onClick: () => run(ui.workbench.executeCommand("view.open", {
6263
+ onClick: () => run("view.open", ui.workbench.executeCommand("view.open", {
6166
6264
  instanceId: view.instanceId,
6167
6265
  viewId: view.viewId
6168
6266
  })),
@@ -6199,21 +6297,22 @@ function WorkbenchPart({ ui }) {
6199
6297
  if (target instanceof HTMLElement && (target.matches("input,textarea,select") || target.isContentEditable)) return;
6200
6298
  if (event.code === "Space" && state.mode === "edit" && !state.readOnly && !state.busy) {
6201
6299
  event.preventDefault();
6202
- if (!event.repeat) run(ui.workbench.executeCommand("selection.rotate", { degrees: 90 }));
6300
+ if (!event.repeat) run("selection.rotate", ui.workbench.executeCommand("selection.rotate", { degrees: 90 }));
6203
6301
  return;
6204
6302
  }
6205
6303
  if (!(event.ctrlKey || event.metaKey)) return;
6206
6304
  if (event.key.toLowerCase() === "s") {
6207
6305
  event.preventDefault();
6208
- run(ui.workbench.save());
6306
+ run("document.save", ui.workbench.save());
6209
6307
  }
6210
6308
  if (event.key.toLowerCase() === "z") {
6211
6309
  event.preventDefault();
6212
- run(ui.workbench.executeCommand(event.shiftKey ? "document.redo" : "document.undo"));
6310
+ const command = event.shiftKey ? "document.redo" : "document.undo";
6311
+ run(command, ui.workbench.executeCommand(command));
6213
6312
  }
6214
6313
  if (event.key.toLowerCase() === "y") {
6215
6314
  event.preventDefault();
6216
- run(ui.workbench.executeCommand("document.redo"));
6315
+ run("document.redo", ui.workbench.executeCommand("document.redo"));
6217
6316
  }
6218
6317
  },
6219
6318
  children: [
@@ -6231,7 +6330,7 @@ function WorkbenchPart({ ui }) {
6231
6330
  frame,
6232
6331
  onReady: ui.setCanvas,
6233
6332
  onSelection: (targets) => ui.workbench.setSelection(targets),
6234
- onOpenProperties: () => run(ui.workbench.executeCommand("workbench.openContainer", {
6333
+ onOpenProperties: () => run("workbench.openContainer", ui.workbench.executeCommand("workbench.openContainer", {
6235
6334
  id: "mica.properties",
6236
6335
  focus: true
6237
6336
  })),
@@ -6287,6 +6386,7 @@ function WorkbenchPart({ ui }) {
6287
6386
  },
6288
6387
  onInput: ui.input,
6289
6388
  onError: ui.error,
6389
+ onOperationFailure: ui.failOperation,
6290
6390
  onFocus: ui.focus,
6291
6391
  onViewport: ui.viewport,
6292
6392
  children: [
@@ -6294,19 +6394,16 @@ function WorkbenchPart({ ui }) {
6294
6394
  state,
6295
6395
  registry: ui.contributions,
6296
6396
  context: ui.context,
6297
- onError: ui.error
6397
+ onOperationFailure: ui.failOperation
6298
6398
  }),
6399
+ state.mode === "run" && !state.busy && state.simulationStatus === "starting" && /* @__PURE__ */ jsx(SimulationStarting, {}),
6299
6400
  /* @__PURE__ */ jsxs("div", {
6300
6401
  className: "mica-wb-canvas-status",
6301
6402
  children: [
6302
- state.mode === "run" && !state.busy && state.simulationStatus !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(SimulationSpeed, {
6403
+ state.mode === "run" && !state.busy && state.simulationStatus !== void 0 && /* @__PURE__ */ jsx(SimulationSpeed, {
6303
6404
  ui,
6304
6405
  status: state.simulationStatus
6305
- }), state.simulationStatus === "starting" && /* @__PURE__ */ jsx("div", {
6306
- className: "mica-wb-status",
6307
- role: "status",
6308
- children: "仿真启动中…"
6309
- })] }),
6406
+ }),
6310
6407
  state.busy && /* @__PURE__ */ jsx("div", {
6311
6408
  className: "mica-wb-status",
6312
6409
  role: "status",
@@ -6340,11 +6437,6 @@ function WorkbenchPart({ ui }) {
6340
6437
  ] }), "单击放置 · Esc 取消"]
6341
6438
  })
6342
6439
  ]
6343
- }),
6344
- ui.diagnostics.some((diagnostic) => diagnostic.severity === "error") && /* @__PURE__ */ jsxs("button", {
6345
- className: "mica-wb-problem-indicator",
6346
- onClick: () => run(ui.workbench.executeCommand("workbench.openContainer", { id: "mica.problems" })),
6347
- children: [ui.diagnostics.filter((diagnostic) => diagnostic.severity === "error").length, " problems"]
6348
6440
  })
6349
6441
  ]
6350
6442
  }),
@@ -6356,7 +6448,7 @@ function WorkbenchPart({ ui }) {
6356
6448
  container: active,
6357
6449
  views: ui.contributions.views.filter((view) => view.containerId === active.id && ui.contributions.visible(view)),
6358
6450
  context: ui.context,
6359
- onClose: () => run(ui.workbench.executeCommand("workbench.closeContainer")),
6451
+ onClose: () => run("workbench.closeContainer", ui.workbench.executeCommand("workbench.closeContainer")),
6360
6452
  report: ui.report,
6361
6453
  children: [
6362
6454
  active.id === "mica.instances" && /* @__PURE__ */ jsx(InstancesView, {
@@ -6371,19 +6463,19 @@ function WorkbenchPart({ ui }) {
6371
6463
  instance: single,
6372
6464
  manifest: single === void 0 ? void 0 : ui.devices.get(single.device)?.manifest,
6373
6465
  annotation,
6374
- onRenameLabel: (labelId, name) => run(ui.workbench.executeCommand("label.setName", {
6466
+ onRenameLabel: (labelId, name) => run("label.setName", ui.workbench.executeCommand("label.setName", {
6375
6467
  labelId,
6376
6468
  name
6377
6469
  })),
6378
- onSetVoltage: (referenceId, voltage) => run(ui.workbench.executeCommand("reference.setVoltage", {
6470
+ onSetVoltage: (referenceId, voltage) => run("reference.setVoltage", ui.workbench.executeCommand("reference.setVoltage", {
6379
6471
  referenceId,
6380
6472
  voltage
6381
6473
  })),
6382
- onSetReferenceName: (referenceId, name) => run(ui.workbench.executeCommand("reference.setName", {
6474
+ onSetReferenceName: (referenceId, name) => run("reference.setName", ui.workbench.executeCommand("reference.setName", {
6383
6475
  referenceId,
6384
6476
  name
6385
6477
  })),
6386
- onSetRotation: (referenceId, rotation) => run(ui.workbench.executeCommand("reference.setRotation", {
6478
+ onSetRotation: (referenceId, rotation) => run("reference.setRotation", ui.workbench.executeCommand("reference.setRotation", {
6387
6479
  referenceId,
6388
6480
  rotation
6389
6481
  })),
@@ -6396,7 +6488,7 @@ function WorkbenchPart({ ui }) {
6396
6488
  snapshots: single === void 0 ? void 0 : ui.programSnapshot(single.id),
6397
6489
  onSet: setProperty,
6398
6490
  onReset: (key) => {
6399
- if (single !== void 0) run(ui.workbench.executeCommand("device.removeProperty", {
6491
+ if (single !== void 0) run("device.removeProperty", ui.workbench.executeCommand("device.removeProperty", {
6400
6492
  instanceId: single.id,
6401
6493
  key
6402
6494
  }));
@@ -6410,7 +6502,7 @@ function WorkbenchPart({ ui }) {
6410
6502
  await ui.commitResource(single.id, key, single.properties?.[key], value, signal);
6411
6503
  },
6412
6504
  onOpenProject: ui.openProject,
6413
- onError: ui.error,
6505
+ onError: (error) => ui.failOperation("inspector.edit", error),
6414
6506
  collapsed: propertyCollapsed,
6415
6507
  height: multipleInfoViews ? propertyHeight ?? layout?.properties.height : void 0,
6416
6508
  onToggle: toggleProperties,
@@ -6418,7 +6510,7 @@ function WorkbenchPart({ ui }) {
6418
6510
  }), single !== void 0 && manifest !== void 0 && layout !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [multipleInfoViews && !layout.properties.collapsed && /* @__PURE__ */ jsx(PanelResizer, {
6419
6511
  height: layout.properties.height,
6420
6512
  onPreview: setPropertyHeight,
6421
- onCommit: (height) => run(ui.changeViewLayout(single.id, {
6513
+ onCommit: (height) => run("view.setLayout", ui.changeViewLayout(single.id, {
6422
6514
  ...layout,
6423
6515
  properties: {
6424
6516
  ...layout.properties,
@@ -6433,6 +6525,7 @@ function WorkbenchPart({ ui }) {
6433
6525
  })] })] }),
6434
6526
  active.id === "mica.problems" && /* @__PURE__ */ jsx(ProblemsView, {
6435
6527
  diagnostics: ui.diagnostics,
6528
+ instances: document.instances,
6436
6529
  onReveal: ui.reveal
6437
6530
  })
6438
6531
  ]
@@ -6442,8 +6535,8 @@ function WorkbenchPart({ ui }) {
6442
6535
  active: active?.id,
6443
6536
  problemCount: ui.diagnostics.length,
6444
6537
  onActivate: (id) => {
6445
- if (id === state.activeContainer) run(ui.workbench.executeCommand("workbench.closeContainer"));
6446
- else run(ui.workbench.executeCommand("workbench.openContainer", {
6538
+ if (id === state.activeContainer) run("workbench.closeContainer", ui.workbench.executeCommand("workbench.closeContainer"));
6539
+ else run("workbench.openContainer", ui.workbench.executeCommand("workbench.openContainer", {
6447
6540
  id,
6448
6541
  focus: true
6449
6542
  }));
@@ -6453,6 +6546,36 @@ function WorkbenchPart({ ui }) {
6453
6546
  ]
6454
6547
  });
6455
6548
  }
6549
+ function SimulationStarting() {
6550
+ return /* @__PURE__ */ jsxs("div", {
6551
+ className: "mica-wb-simulation-starting",
6552
+ role: "status",
6553
+ children: [/* @__PURE__ */ jsx("svg", {
6554
+ viewBox: "0 0 1024 1024",
6555
+ width: "72",
6556
+ height: "72",
6557
+ fill: "currentColor",
6558
+ "aria-hidden": "true",
6559
+ children: [
6560
+ ["M148 263 L499 90 L499 177 L231 308 Z", "0;0;0.105;0.73;0.87;0.96;1"],
6561
+ ["M532 90 L891 267 L805 309 L532 177 Z", "0;0.13;0.235;0.73;0.87;0.96;1"],
6562
+ ["M118 290 L465 469 L465 922 L118 738 Z M191 411 L191 691 L392 797 L392 515 Z", "0;0.26;0.365;0.73;0.87;0.96;1"],
6563
+ ["M532 399 L604 362 L604 545 L905 395 L905 740 L532 934 Z M604 632 L604 808 L832 692 L832 518 Z", "0;0.39;0.495;0.73;0.87;0.96;1"]
6564
+ ].map(([path, keyTimes]) => /* @__PURE__ */ jsx("path", {
6565
+ d: path,
6566
+ fillRule: "evenodd",
6567
+ opacity: "0",
6568
+ children: /* @__PURE__ */ jsx("animate", {
6569
+ attributeName: "opacity",
6570
+ dur: "3s",
6571
+ repeatCount: "indefinite",
6572
+ values: "0;0;1;1;1;0;0",
6573
+ keyTimes
6574
+ })
6575
+ }, path))
6576
+ }), /* @__PURE__ */ jsx("span", { children: "仿真启动中…" })]
6577
+ });
6578
+ }
6456
6579
  /**
6457
6580
  * 画布左下角的实时率读数。只订阅速度事件,运行中每半秒更新一次,
6458
6581
  * 不会带动整个工作台重渲染。
@@ -6506,6 +6629,16 @@ async function decodeResourceImage(bytes, name) {
6506
6629
  }
6507
6630
  async function createWorkbench(options) {
6508
6631
  validateViewBase(options.viewBaseUrlTemplate);
6632
+ const samples = [];
6633
+ const observability = {
6634
+ ...options.observability,
6635
+ onLog: options.observability?.onLog ?? writeWorkbenchConsole,
6636
+ onSample(sample) {
6637
+ if (samples.length === 1024) samples.shift();
6638
+ samples.push(sample);
6639
+ options.observability?.onSample?.(sample);
6640
+ }
6641
+ };
6509
6642
  function validateTheme(value) {
6510
6643
  const result = normalizeTheme(value);
6511
6644
  for (const [token, color] of Object.entries(result.colors ?? {})) if (!CSS.supports("color", color)) throw new Error(`Invalid CSS color for ${token}: ${color}`);
@@ -6522,6 +6655,7 @@ async function createWorkbench(options) {
6522
6655
  const selectionChanged = disposables.add(new Emitter());
6523
6656
  const stateChanged = disposables.add(new Emitter());
6524
6657
  const diagnosticsChanged = disposables.add(new Emitter());
6658
+ const operationFailed = disposables.add(new Emitter());
6525
6659
  const openProject = disposables.add(new Emitter());
6526
6660
  const uiChanged = disposables.add(new Emitter());
6527
6661
  const defaultAccessChanged = disposables.add(new Emitter());
@@ -6575,6 +6709,7 @@ async function createWorkbench(options) {
6575
6709
  document: options.document,
6576
6710
  ...options.saveDocument === void 0 ? {} : { saveDocument: options.saveDocument },
6577
6711
  devices: options.deviceProvider,
6712
+ deviceVersionPolicy: options.deviceVersionPolicy ?? "compatible",
6578
6713
  access
6579
6714
  });
6580
6715
  } catch (error) {
@@ -6654,9 +6789,17 @@ async function createWorkbench(options) {
6654
6789
  uiChanged.fire();
6655
6790
  if (changed) stateChanged.fire(state);
6656
6791
  }
6657
- const report = (diagnostic) => {
6792
+ const report = (diagnostic, log = true) => {
6658
6793
  if (disposed) return;
6659
6794
  if (diagnostics.some((value) => value.code === diagnostic.code && value.message === diagnostic.message && value.instanceId === diagnostic.instanceId)) return;
6795
+ if (log) writeFusedLog(observability, "workbench", {
6796
+ code: diagnostic.code,
6797
+ message: diagnostic.message,
6798
+ level: diagnostic.severity === "error" ? "error" : "warn",
6799
+ scope: "diagnostic",
6800
+ data: [],
6801
+ ...diagnostic.instanceId === void 0 ? {} : { instanceId: diagnostic.instanceId }
6802
+ });
6660
6803
  diagnostics.push(Object.freeze({ ...diagnostic }));
6661
6804
  diagnosticsChanged.fire(diagnostic);
6662
6805
  update();
@@ -6665,7 +6808,7 @@ async function createWorkbench(options) {
6665
6808
  code: errorCode(reason),
6666
6809
  message: errorMessage(reason),
6667
6810
  severity: "error"
6668
- });
6811
+ }, typeof reason !== "object" || reason === null || !loggedStartupFailures.has(reason));
6669
6812
  function refreshLayoutDiagnostics() {
6670
6813
  const retained = diagnostics.filter((item) => item.code !== "layout/body-overlap");
6671
6814
  diagnostics.splice(0, diagnostics.length, ...retained);
@@ -6762,7 +6905,7 @@ async function createWorkbench(options) {
6762
6905
  imageLocks.set(id, device.lock.integrity);
6763
6906
  }
6764
6907
  }
6765
- async function createRuntime(targetMode) {
6908
+ async function createRuntime(targetMode, requestedAt) {
6766
6909
  const generation = ++runtimeGeneration;
6767
6910
  const document = documentSession.getDocument();
6768
6911
  const devices = documentSession.getDevices().getLoadedDevices();
@@ -6771,7 +6914,10 @@ async function createWorkbench(options) {
6771
6914
  return manifest?.view2d?.entry !== void 0 || Object.values(manifest?.properties ?? {}).some((property) => property.type === "program");
6772
6915
  })) return void 0;
6773
6916
  const result = await createFusedRuntime({
6917
+ observability,
6918
+ ...requestedAt === void 0 ? {} : { requestedAt },
6774
6919
  ...options.audio === void 0 ? {} : { audio: options.audio },
6920
+ ...options.deviceStateProvider === void 0 ? {} : { deviceStateProvider: options.deviceStateProvider },
6775
6921
  document,
6776
6922
  registry: options.deviceProvider,
6777
6923
  step,
@@ -6791,7 +6937,7 @@ async function createWorkbench(options) {
6791
6937
  message: diagnostic.message,
6792
6938
  severity: "error",
6793
6939
  ...diagnostic.instanceId === void 0 ? {} : { instanceId: diagnostic.instanceId }
6794
- });
6940
+ }, false);
6795
6941
  },
6796
6942
  onOverlay: (frame) => {
6797
6943
  if (disposed || generation !== runtimeGeneration) {
@@ -6862,6 +7008,7 @@ async function createWorkbench(options) {
6862
7008
  async function setMode(next) {
6863
7009
  assertReady();
6864
7010
  if (next !== "edit" && next !== "run") throw new Error(`Invalid workbench mode: ${String(next)}`);
7011
+ const requestedAt = performance.now();
6865
7012
  return enqueue(async () => {
6866
7013
  assertReady();
6867
7014
  if (next === mode) return;
@@ -6878,8 +7025,11 @@ async function createWorkbench(options) {
6878
7025
  const document = documentSession.getDocument();
6879
7026
  if (runtime === void 0 || runtimeDocument !== document) {
6880
7027
  await releaseRuntime();
6881
- runtime = await createRuntime("run");
6882
- } else await runtime.prepareDisplay({ mode: "run" });
7028
+ runtime = await createRuntime("run", requestedAt);
7029
+ } else await runtime.prepareDisplay({
7030
+ mode: "run",
7031
+ requestedAt
7032
+ });
6883
7033
  if (runtime === void 0) throw new Error("Run mode requires a mounted runtime");
6884
7034
  simulation.attach(runtime);
6885
7035
  await documentSession.refreshAccess();
@@ -6887,6 +7037,7 @@ async function createWorkbench(options) {
6887
7037
  if (!permission.allowed) throw new Error(permission.message);
6888
7038
  mode = "run";
6889
7039
  } else try {
7040
+ if (options.deviceStateProvider !== void 0) await runtime?.pause();
6890
7041
  await documentSession.setRunning(false);
6891
7042
  mode = "edit";
6892
7043
  if (runtime === void 0) presentationSignature = "";
@@ -6918,9 +7069,7 @@ async function createWorkbench(options) {
6918
7069
  mode = "edit";
6919
7070
  presentationSignature = "";
6920
7071
  }
6921
- const failure = failures.length === 1 ? reason : new AggregateError(failures, "Failed to enter and release the run session");
6922
- error(failure);
6923
- throw failure;
7072
+ throw failures.length === 1 ? reason : new AggregateError(failures, "Failed to enter and release the run session");
6924
7073
  } finally {
6925
7074
  busy = false;
6926
7075
  update();
@@ -7166,11 +7315,13 @@ async function createWorkbench(options) {
7166
7315
  "view.setLayout": ({ instanceId, layout }) => changeViewLayout(instanceId, layout)
7167
7316
  };
7168
7317
  const workbench = {
7318
+ getStartupPerformance: () => summarizeStartup(samples),
7169
7319
  contextKeys,
7170
7320
  onDidChangeContent: content.event,
7171
7321
  onDidChangeSelection: selectionChanged.event,
7172
7322
  onDidChangeState: stateChanged.event,
7173
7323
  onDidReportDiagnostic: diagnosticsChanged.event,
7324
+ onDidFailOperation: operationFailed.event,
7174
7325
  onDidRequestOpenProject: openProject.event,
7175
7326
  getDocument: () => {
7176
7327
  assertReady();
@@ -7209,9 +7360,13 @@ async function createWorkbench(options) {
7209
7360
  },
7210
7361
  dispose() {
7211
7362
  if (disposal !== void 0) return disposal;
7212
- disposed = true;
7213
- abort.abort();
7214
7363
  disposal = (async () => {
7364
+ if (options.deviceStateProvider !== void 0) {
7365
+ await transition;
7366
+ await runtime?.pause();
7367
+ }
7368
+ disposed = true;
7369
+ abort.abort();
7215
7370
  const errors = [];
7216
7371
  const release = async (action) => {
7217
7372
  try {
@@ -7235,7 +7390,10 @@ async function createWorkbench(options) {
7235
7390
  mount.remove();
7236
7391
  environment.remove();
7237
7392
  if (errors.length) throw new AggregateError(errors, "Failed to release workbench resources");
7238
- })();
7393
+ })().catch((reason) => {
7394
+ if (!disposed) disposal = void 0;
7395
+ throw reason;
7396
+ });
7239
7397
  return disposal;
7240
7398
  }
7241
7399
  };
@@ -7367,6 +7525,15 @@ async function createWorkbench(options) {
7367
7525
  },
7368
7526
  report,
7369
7527
  error,
7528
+ failOperation: (operation, reason) => {
7529
+ if (disposed) return;
7530
+ error(reason);
7531
+ operationFailed.fire({
7532
+ operation,
7533
+ code: errorCode(reason),
7534
+ error: reason
7535
+ });
7536
+ },
7370
7537
  input: (instanceId, event) => {
7371
7538
  try {
7372
7539
  runtime?.display.input(instanceId, event);