@mica-js/simulator 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ import { CanvasBindingTarget } from '@mica-js/core/canvas';
2
+ import { Event as Event_2 } from '@mica-js/core/lifecycle';
3
+ import { PayloadType } from '@mica-js/core/canvas';
4
+ import { SandboxWorker } from '@mica-js/sandbox';
5
+ import { SandboxWorkerOptions } from '@mica-js/sandbox';
6
+ import { SchematicDocument } from '@mica-js/core/schematic';
7
+
8
+ /**
9
+ * Builds a `DeviceSimulationHost` that runs the unified-IR circuit inside a `@mica-js/sandbox` guest.
10
+ *
11
+ * The caller creates the sandbox and passes it in with the other initialization options, so the
12
+ * same host adapter works with the Vite-generated guest class and with in-process RPC peers. The
13
+ * sandbox receives only a `MessagePort`; every call below travels over the typed `guest` RPC service
14
+ * and schematic bytes arrive through the typed `host-capabilities` service. `Circuit` stays entirely
15
+ * inside the guest.
16
+ */
17
+ export declare function createDeviceSimulationHostFromSandbox({ sandbox, fs, ports, }: SandboxDeviceSimulationHostOptions): Promise<DeviceSimulationHost>;
18
+
19
+ /**
20
+ * Creates the default device simulation guest worker.
21
+ *
22
+ * Pass the worker to `createDeviceSimulationHostFromSandbox` — or let
23
+ * `@mica-js/canvas-editor`'s `SandboxHostProvider` start it, which is what it does by default.
24
+ */
25
+ export declare function createDeviceSimulationHostGuestSandbox(options?: SandboxWorkerOptions): SandboxWorker;
26
+
27
+ /** What one {@link DeviceSimulationHost.tick} call executed. */
28
+ export declare interface DeviceSimTickReport {
29
+ /** Simulation time after the step, in picoseconds. */
30
+ readonly simTime: number;
31
+ /** Circuit steps executed by this call. */
32
+ readonly executed: number;
33
+ }
34
+
35
+ /**
36
+ * Simulation the canvas runtime drives (RFC 0018).
37
+ *
38
+ * Every method returns a promise, so a same-thread implementation and a cross-thread one are called
39
+ * the same way and `WidgetHost` and the simulation can live on different threads. The host owns the
40
+ * frame clock: it calls {@link tick} with one fixed step at a time and reads the current simulation
41
+ * time back from {@link getSimTime}, so there is exactly one authority for time.
42
+ */
43
+ export declare interface DeviceSimulationHost {
44
+ /**
45
+ * Reads and mounts the schematic behind `uri`; `undefined` clears the runtime.
46
+ *
47
+ * The implementation reads the bytes through its own `fs` and resolves the `image` / `binary`
48
+ * properties of every symbol against that schematic URI.
49
+ */
50
+ loadSchematic(uri: string | undefined): Promise<void>;
51
+ /** Resets the loaded runtime to its initial state without unloading the schematic. */
52
+ reset(): Promise<void>;
53
+ /** Advances one fixed step of `dt` picoseconds when the widget host is in simulation mode. */
54
+ tick(dt: number): Promise<DeviceSimTickReport>;
55
+ /** Queues one payload for a device endpoint; consumed at the next {@link tick}. */
56
+ deliver(target: CanvasBindingTarget, payload: unknown, simTime?: number): Promise<void>;
57
+ /** Subscribes to device publishes; registering itself is a local operation. */
58
+ readonly onDidPublish: Event_2<SimulationPublish>;
59
+ /** Endpoints of the running devices, in schematic order. */
60
+ getTopics(): Promise<readonly DeviceTopic[]>;
61
+ /** Current simulation time, in picoseconds. */
62
+ getSimTime(): Promise<number>;
63
+ /** Schematic the runtime was built from. */
64
+ getSchematic(): Promise<SchematicDocument | undefined>;
65
+ /** Releases the runtime. */
66
+ dispose(): Promise<void>;
67
+ }
68
+
69
+ /**
70
+ * Read-only byte access the device host needs for schematics.
71
+ *
72
+ * Structurally equal to RFC 0019's `HostFs`, so one object can serve `WidgetHost` and the device
73
+ * host without a second adapter.
74
+ */
75
+ export declare interface DeviceSimulationHostFileSystem {
76
+ read(uri: string): Promise<Uint8Array>;
77
+ }
78
+
79
+ /**
80
+ * The packaged guest as a worker class, kept for callers that construct it with `new`.
81
+ *
82
+ * @deprecated Prefer {@link createDeviceSimulationHostGuestSandbox}.
83
+ */
84
+ export declare const DeviceSimulationHostGuestSandbox: new (options?: SandboxWorkerOptions) => SandboxWorker;
85
+
86
+ /**
87
+ * The default device simulation guest script, bundled and minified into this module while the
88
+ * package is built.
89
+ *
90
+ * It is a classic script: every dependency is inlined, so the sandbox runs it without a module
91
+ * loader. It resolves no devices — a package that owns devices passes its own guest script to the
92
+ * sandbox instead.
93
+ */
94
+ export declare const deviceSimulationHostGuestScript: string;
95
+
96
+ /** One endpoint of a mounted device instance, as the simulation reports it. */
97
+ export declare interface DeviceTopic {
98
+ readonly symbol: string;
99
+ /** Reference designator shown to users; informational for the canvas. */
100
+ readonly designator?: string;
101
+ readonly port: string;
102
+ readonly direction: 'input' | 'output';
103
+ readonly type: PayloadType;
104
+ readonly title?: string;
105
+ }
106
+
107
+ /**
108
+ * The running sandbox the host adapter drives: the full public surface of `SandboxWorker`, kept
109
+ * structural so tests can inject an in-process RPC peer.
110
+ */
111
+ export declare interface SandboxDeviceSimulationHostOptions {
112
+ /**
113
+ * The running sandbox to drive. The caller creates it — for example with the Vite-generated
114
+ * `DeviceSimulationHostGuestSandbox` — and this factory never constructs one.
115
+ */
116
+ readonly sandbox: SandboxWorker;
117
+ /** Host capability: source of schematic bytes; the guest never reads the host file system. */
118
+ readonly fs: DeviceSimulationHostFileSystem;
119
+ /** Extra ports transferred after the RPC port in the guest's first startup message. */
120
+ readonly ports?: readonly MessagePort[];
121
+ }
122
+
123
+ /** One payload a simulation published for an endpoint the canvas can bind to. */
124
+ export declare interface SimulationPublish {
125
+ readonly target: CanvasBindingTarget;
126
+ readonly payload: unknown;
127
+ readonly simTime: number;
128
+ }
129
+
130
+ export { }