@mica-js/simulator 2.0.0 → 2.1.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 +343 -7
- package/dist/ddl.d.ts +4 -0
- package/dist/ddl.js +1 -0
- package/dist/device.d.ts +111 -0
- package/dist/device.js +0 -0
- package/dist/index.d.ts +257 -783
- package/dist/index.js +4339 -3178
- package/dist/index.js.map +1 -1
- package/dist/model.d.ts +4 -0
- package/dist/model.js +1 -0
- package/dist/rpc-D-9O3TZf.js +108 -0
- package/dist/rpc-D-9O3TZf.js.map +1 -0
- package/dist/sandbox.d.ts +75 -109
- package/dist/sandbox.js +71 -80
- package/dist/sandbox.js.map +1 -1
- package/package.json +33 -11
- package/dist/rpc-BIxQr_wd.js +0 -12
- package/dist/rpc-BIxQr_wd.js.map +0 -1
package/dist/model.d.ts
ADDED
package/dist/model.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@mica-js/device-model";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { defineRpcService } from "@mica-js/core/rpc";
|
|
2
|
+
//#region src/simulation-runtime/payload.ts
|
|
3
|
+
/** Stable key of one device endpoint. */
|
|
4
|
+
function targetKey(symbol, port) {
|
|
5
|
+
return `${symbol}\u0000${port}`;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Value equality of two payloads.
|
|
9
|
+
*
|
|
10
|
+
* A canvas topic is a `level` unless it carries text or bytes (RFC 0017), so re-sending the value a
|
|
11
|
+
* device already published only costs a widget repaint. Byte payloads compare by content because a
|
|
12
|
+
* device may hand out a fresh buffer per step.
|
|
13
|
+
*/
|
|
14
|
+
function samePayload(previous, next) {
|
|
15
|
+
if (Object.is(previous, next)) return true;
|
|
16
|
+
if (previous instanceof Uint8Array && next instanceof Uint8Array) {
|
|
17
|
+
if (previous.length !== next.length) return false;
|
|
18
|
+
for (let index = 0; index < previous.length; index += 1) if (previous[index] !== next[index]) return false;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (typeof previous !== "object" || previous === null) return false;
|
|
22
|
+
if (typeof next !== "object" || next === null) return false;
|
|
23
|
+
const a = previous;
|
|
24
|
+
const b = next;
|
|
25
|
+
return a.x === b.x && a.y === b.y && a.z === b.z;
|
|
26
|
+
}
|
|
27
|
+
function isVec2d(value) {
|
|
28
|
+
if (typeof value !== "object" || value === null) return false;
|
|
29
|
+
const point = value;
|
|
30
|
+
return typeof point.x === "number" && typeof point.y === "number";
|
|
31
|
+
}
|
|
32
|
+
/** Whether `payload` matches the declared topic payload type. */
|
|
33
|
+
function payloadMatches(type, payload) {
|
|
34
|
+
switch (type) {
|
|
35
|
+
case "boolean": return typeof payload === "boolean";
|
|
36
|
+
case "number": return typeof payload === "number";
|
|
37
|
+
case "string": return typeof payload === "string";
|
|
38
|
+
case "bytes":
|
|
39
|
+
case "bytes<rgb565>":
|
|
40
|
+
case "bytes<segments>": return payload instanceof Uint8Array;
|
|
41
|
+
case "vec2d": return isVec2d(payload);
|
|
42
|
+
case "vec3d": return isVec2d(payload) && typeof payload.z === "number";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Copies a byte payload so an RPC transfer never detaches the producer's buffer. */
|
|
46
|
+
function copyBytePayload(payload) {
|
|
47
|
+
return payload instanceof Uint8Array ? new Uint8Array(payload) : payload;
|
|
48
|
+
}
|
|
49
|
+
/** Snapshots mutable payloads accepted by the prepared topic contract. */
|
|
50
|
+
function copyPayload(payload) {
|
|
51
|
+
if (payload instanceof Uint8Array) return new Uint8Array(payload);
|
|
52
|
+
return typeof payload === "object" && payload !== null ? { ...payload } : payload;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/simulation-runtime/rpc.ts
|
|
56
|
+
/**
|
|
57
|
+
* Wire name of the prepared simulation runtime.
|
|
58
|
+
*
|
|
59
|
+
* The same id is registered on the primary sandbox RPC channel and on the direct topic port, so a
|
|
60
|
+
* widget guest reaches the running simulation without a second protocol.
|
|
61
|
+
*/
|
|
62
|
+
var simulationRuntimeService = defineRpcService("simulation-runtime");
|
|
63
|
+
/** Topic-port view of the same wire service registered by the runtime guest. */
|
|
64
|
+
var simulationRuntimeTopicService = defineRpcService("simulation-runtime");
|
|
65
|
+
/**
|
|
66
|
+
* Transfer list for one proxy call.
|
|
67
|
+
*
|
|
68
|
+
* Asset bytes and delivered byte payloads are copied by the adapter before the call, so transferring
|
|
69
|
+
* their buffers here never detaches a caller-owned array.
|
|
70
|
+
*/
|
|
71
|
+
function simulationRuntimeCallTransfer(member, args) {
|
|
72
|
+
if (member === "deliver") {
|
|
73
|
+
const message = args[0];
|
|
74
|
+
return transferableBuffer(message?.payload);
|
|
75
|
+
}
|
|
76
|
+
if (member === "load") return assetTransferList(args[0]);
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Transfer list for one event registration callback.
|
|
81
|
+
*
|
|
82
|
+
* `value` is the callback's argument array (see `RpcRegistrationOptions.transfer`). The guest copies
|
|
83
|
+
* a byte payload before invoking the listener, so the published buffer is safe to transfer.
|
|
84
|
+
*/
|
|
85
|
+
function simulationRuntimeEventTransfer(member, value) {
|
|
86
|
+
if (member !== "onDidPublish" || !Array.isArray(value)) return [];
|
|
87
|
+
const message = value[0];
|
|
88
|
+
return transferableBuffer(message?.payload);
|
|
89
|
+
}
|
|
90
|
+
function transferableBuffer(payload) {
|
|
91
|
+
if (!(payload instanceof Uint8Array)) return [];
|
|
92
|
+
return payload.buffer instanceof ArrayBuffer ? [payload.buffer] : [];
|
|
93
|
+
}
|
|
94
|
+
function assetTransferList(input) {
|
|
95
|
+
if (typeof input !== "object" || input === null) return [];
|
|
96
|
+
const assets = input.assets;
|
|
97
|
+
if (typeof assets !== "object" || assets === null) return [];
|
|
98
|
+
const buffers = /* @__PURE__ */ new Set();
|
|
99
|
+
for (const entries of Object.values(assets)) {
|
|
100
|
+
if (typeof entries !== "object" || entries === null) continue;
|
|
101
|
+
for (const bytes of Object.values(entries)) if (bytes instanceof Uint8Array && bytes.buffer instanceof ArrayBuffer) buffers.add(bytes.buffer);
|
|
102
|
+
}
|
|
103
|
+
return [...buffers];
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { copyBytePayload as a, samePayload as c, simulationRuntimeTopicService as i, targetKey as l, simulationRuntimeEventTransfer as n, copyPayload as o, simulationRuntimeService as r, payloadMatches as s, simulationRuntimeCallTransfer as t };
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=rpc-D-9O3TZf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-D-9O3TZf.js","names":[],"sources":["../src/simulation-runtime/payload.ts","../src/simulation-runtime/rpc.ts"],"sourcesContent":["import type { PayloadType } from '@mica-js/document/canvas';\n\n/** Stable key of one device endpoint. */\nexport function targetKey(symbol: string, port: string): string {\n return `${symbol}\\u0000${port}`;\n}\n\n/**\n * Value equality of two payloads.\n *\n * A canvas topic is a `level` unless it carries text or bytes (RFC 0017), so re-sending the value a\n * device already published only costs a widget repaint. Byte payloads compare by content because a\n * device may hand out a fresh buffer per step.\n */\nexport function samePayload(previous: unknown, next: unknown): boolean {\n if (Object.is(previous, next)) return true;\n if (previous instanceof Uint8Array && next instanceof Uint8Array) {\n if (previous.length !== next.length) return false;\n for (let index = 0; index < previous.length; index += 1) {\n if (previous[index] !== next[index]) return false;\n }\n return true;\n }\n if (typeof previous !== 'object' || previous === null) return false;\n if (typeof next !== 'object' || next === null) return false;\n const a = previous as { readonly x?: unknown; readonly y?: unknown; readonly z?: unknown };\n const b = next as { readonly x?: unknown; readonly y?: unknown; readonly z?: unknown };\n return a.x === b.x && a.y === b.y && a.z === b.z;\n}\n\nfunction isVec2d(value: unknown): boolean {\n if (typeof value !== 'object' || value === null) return false;\n const point = value as { readonly x?: unknown; readonly y?: unknown };\n return typeof point.x === 'number' && typeof point.y === 'number';\n}\n\n/** Whether `payload` matches the declared topic payload type. */\nexport function payloadMatches(type: PayloadType, payload: unknown): boolean {\n switch (type) {\n case 'boolean':\n return typeof payload === 'boolean';\n case 'number':\n return typeof payload === 'number';\n case 'string':\n return typeof payload === 'string';\n case 'bytes':\n case 'bytes<rgb565>':\n case 'bytes<segments>':\n return payload instanceof Uint8Array;\n case 'vec2d':\n return isVec2d(payload);\n case 'vec3d':\n return isVec2d(payload) && typeof (payload as { readonly z?: unknown }).z === 'number';\n }\n}\n\n/** Copies a byte payload so an RPC transfer never detaches the producer's buffer. */\nexport function copyBytePayload(payload: unknown): unknown {\n return payload instanceof Uint8Array ? new Uint8Array(payload) : payload;\n}\n\n/** Snapshots mutable payloads accepted by the prepared topic contract. */\nexport function copyPayload(payload: unknown): unknown {\n if (payload instanceof Uint8Array) return new Uint8Array(payload);\n return typeof payload === 'object' && payload !== null ? { ...payload } : payload;\n}\n","import { defineRpcService } from '@mica-js/core/rpc';\nimport type { TimePs } from '@mica-js/core';\nimport type {\n IPreparedSimulation,\n ISimulationDiagnostic,\n ISimulationMessage,\n ISimulationTickReport,\n} from './types';\n\n/** Methods the runtime guest exposes over the primary sandbox RPC channel. */\nexport interface ISimulationRuntimeRpc {\n load(input: IPreparedSimulation): Promise<void>;\n reset(): Promise<void>;\n tick(dt: TimePs): Promise<ISimulationTickReport>;\n deliver(message: ISimulationMessage): Promise<void>;\n onDidPublish(listener: (message: ISimulationMessage) => void): () => void;\n onDidDiagnostic(listener: (diagnostic: ISimulationDiagnostic) => void): () => void;\n dispose(): Promise<void>;\n}\n\n/**\n * Wire name of the prepared simulation runtime.\n *\n * The same id is registered on the primary sandbox RPC channel and on the direct topic port, so a\n * widget guest reaches the running simulation without a second protocol.\n */\nexport const simulationRuntimeService =\n defineRpcService<ISimulationRuntimeRpc>('simulation-runtime');\n\n/** The data plane the direct topic port exposes: deliveries in, publishes out. */\nexport interface ISimulationRuntimeTopicRpc {\n deliver(message: ISimulationMessage): Promise<void>;\n onDidPublish(listener: (message: ISimulationMessage) => void): () => void;\n}\n\n/** Topic-port view of the same wire service registered by the runtime guest. */\nexport const simulationRuntimeTopicService =\n defineRpcService<ISimulationRuntimeTopicRpc>('simulation-runtime');\n\n/**\n * Transfer list for one proxy call.\n *\n * Asset bytes and delivered byte payloads are copied by the adapter before the call, so transferring\n * their buffers here never detaches a caller-owned array.\n */\nexport function simulationRuntimeCallTransfer(\n member: string,\n args: readonly unknown[],\n): readonly ArrayBuffer[] {\n if (member === 'deliver') {\n const message = args[0] as ISimulationMessage | undefined;\n return transferableBuffer(message?.payload);\n }\n if (member === 'load') return assetTransferList(args[0]);\n return [];\n}\n\n/**\n * Transfer list for one event registration callback.\n *\n * `value` is the callback's argument array (see `RpcRegistrationOptions.transfer`). The guest copies\n * a byte payload before invoking the listener, so the published buffer is safe to transfer.\n */\nexport function simulationRuntimeEventTransfer(\n member: string,\n value: unknown,\n): readonly ArrayBuffer[] {\n if (member !== 'onDidPublish' || !Array.isArray(value)) return [];\n const message = value[0] as ISimulationMessage | undefined;\n return transferableBuffer(message?.payload);\n}\n\nfunction transferableBuffer(payload: unknown): readonly ArrayBuffer[] {\n if (!(payload instanceof Uint8Array)) return [];\n return payload.buffer instanceof ArrayBuffer ? [payload.buffer] : [];\n}\n\nfunction assetTransferList(input: unknown): readonly ArrayBuffer[] {\n if (typeof input !== 'object' || input === null) return [];\n const assets = (input as { readonly assets?: unknown }).assets;\n if (typeof assets !== 'object' || assets === null) return [];\n const buffers = new Set<ArrayBuffer>();\n for (const entries of Object.values(assets)) {\n if (typeof entries !== 'object' || entries === null) continue;\n for (const bytes of Object.values(entries)) {\n if (bytes instanceof Uint8Array && bytes.buffer instanceof ArrayBuffer) {\n buffers.add(bytes.buffer);\n }\n }\n }\n return [...buffers];\n}\n"],"mappings":";;;AAGA,SAAgB,UAAU,QAAgB,MAAsB;CAC9D,OAAO,GAAG,OAAO,QAAQ;AAC3B;;;;;;;;AASA,SAAgB,YAAY,UAAmB,MAAwB;CACrE,IAAI,OAAO,GAAG,UAAU,IAAI,GAAG,OAAO;CACtC,IAAI,oBAAoB,cAAc,gBAAgB,YAAY;EAChE,IAAI,SAAS,WAAW,KAAK,QAAQ,OAAO;EAC5C,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS,GACpD,IAAI,SAAS,WAAW,KAAK,QAAQ,OAAO;EAE9C,OAAO;CACT;CACA,IAAI,OAAO,aAAa,YAAY,aAAa,MAAM,OAAO;CAC9D,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM,OAAO;CACtD,MAAM,IAAI;CACV,MAAM,IAAI;CACV,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;AACjD;AAEA,SAAS,QAAQ,OAAyB;CACxC,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,QAAQ;CACd,OAAO,OAAO,MAAM,MAAM,YAAY,OAAO,MAAM,MAAM;AAC3D;;AAGA,SAAgB,eAAe,MAAmB,SAA2B;CAC3E,QAAQ,MAAR;EACE,KAAK,WACH,OAAO,OAAO,YAAY;EAC5B,KAAK,UACH,OAAO,OAAO,YAAY;EAC5B,KAAK,UACH,OAAO,OAAO,YAAY;EAC5B,KAAK;EACL,KAAK;EACL,KAAK,mBACH,OAAO,mBAAmB;EAC5B,KAAK,SACH,OAAO,QAAQ,OAAO;EACxB,KAAK,SACH,OAAO,QAAQ,OAAO,KAAK,OAAQ,QAAqC,MAAM;CAClF;AACF;;AAGA,SAAgB,gBAAgB,SAA2B;CACzD,OAAO,mBAAmB,aAAa,IAAI,WAAW,OAAO,IAAI;AACnE;;AAGA,SAAgB,YAAY,SAA2B;CACrD,IAAI,mBAAmB,YAAY,OAAO,IAAI,WAAW,OAAO;CAChE,OAAO,OAAO,YAAY,YAAY,YAAY,OAAO,EAAE,GAAG,QAAQ,IAAI;AAC5E;;;;;;;;;ACvCA,IAAa,2BACX,iBAAwC,oBAAoB;;AAS9D,IAAa,gCACX,iBAA6C,oBAAoB;;;;;;;AAQnE,SAAgB,8BACd,QACA,MACwB;CACxB,IAAI,WAAW,WAAW;EACxB,MAAM,UAAU,KAAK;EACrB,OAAO,mBAAmB,SAAS,OAAO;CAC5C;CACA,IAAI,WAAW,QAAQ,OAAO,kBAAkB,KAAK,EAAE;CACvD,OAAO,CAAC;AACV;;;;;;;AAQA,SAAgB,+BACd,QACA,OACwB;CACxB,IAAI,WAAW,kBAAkB,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;CAChE,MAAM,UAAU,MAAM;CACtB,OAAO,mBAAmB,SAAS,OAAO;AAC5C;AAEA,SAAS,mBAAmB,SAA0C;CACpE,IAAI,EAAE,mBAAmB,aAAa,OAAO,CAAC;CAC9C,OAAO,QAAQ,kBAAkB,cAAc,CAAC,QAAQ,MAAM,IAAI,CAAC;AACrE;AAEA,SAAS,kBAAkB,OAAwC;CACjE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,CAAC;CACzD,MAAM,SAAU,MAAwC;CACxD,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO,CAAC;CAC3D,MAAM,0BAAU,IAAI,IAAiB;CACrC,KAAK,MAAM,WAAW,OAAO,OAAO,MAAM,GAAG;EAC3C,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM;EACrD,KAAK,MAAM,SAAS,OAAO,OAAO,OAAO,GACvC,IAAI,iBAAiB,cAAc,MAAM,kBAAkB,aACzD,QAAQ,IAAI,MAAM,MAAM;CAG9B;CACA,OAAO,CAAC,GAAG,OAAO;AACpB"}
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,136 +1,102 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceMetadata } from '@mica-js/document/schematic';
|
|
2
2
|
import { Event as Event_2 } from '@mica-js/core/lifecycle';
|
|
3
|
-
import { PayloadType } from '@mica-js/core/canvas';
|
|
4
3
|
import { SandboxWorker } from '@mica-js/sandbox';
|
|
5
4
|
import { SandboxWorkerOptions } from '@mica-js/sandbox';
|
|
6
|
-
import { SchematicDocument } from '@mica-js/
|
|
5
|
+
import { SchematicDocument } from '@mica-js/document/schematic';
|
|
6
|
+
import { default as simulationRuntimeGuestScript } from './guest/simulation-runtime.ts?sandbox-worker-code';
|
|
7
|
+
import { TimePs } from '@mica-js/core';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
* Builds
|
|
10
|
+
* Builds an `ISimulationRuntime` that runs inside one sandbox worker.
|
|
10
11
|
*
|
|
11
|
-
* The
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* and schematic bytes arrive through the typed `host-capabilities` service. `Circuit` stays entirely
|
|
15
|
-
* inside the guest.
|
|
12
|
+
* The adapter owns the worker: it starts the RPC channel, forwards the optional topic port, and
|
|
13
|
+
* terminates the worker on `dispose`. The worker receives only `MessagePort`s, so device modules
|
|
14
|
+
* are imported and executed inside the guest, never on the editor thread.
|
|
16
15
|
*/
|
|
17
|
-
export declare function
|
|
16
|
+
export declare function createSimulationRuntimeFromWorker(worker: SandboxWorker, options?: ISimulationRuntimeWorkerOptions): Promise<ISimulationRuntime>;
|
|
18
17
|
|
|
19
|
-
/**
|
|
20
|
-
|
|
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;
|
|
18
|
+
/** Creates the optional browser worker; the runtime adapter takes ownership of it. */
|
|
19
|
+
export declare function createSimulationRuntimeGuestSandbox(options?: SandboxWorkerOptions): SandboxWorker;
|
|
26
20
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly
|
|
31
|
-
/**
|
|
32
|
-
readonly
|
|
33
|
-
/**
|
|
34
|
-
readonly
|
|
35
|
-
readonly code: 'device/input-failed' | 'device/output-failed';
|
|
36
|
-
readonly deviceId: string;
|
|
37
|
-
readonly message: string;
|
|
38
|
-
}[];
|
|
21
|
+
/** A prepared schematic and its separately resolved resource bytes. */
|
|
22
|
+
declare interface IPreparedSimulation {
|
|
23
|
+
readonly schematic: SchematicDocument;
|
|
24
|
+
readonly devices: readonly IPreparedSimulationDevice[];
|
|
25
|
+
/** Fixed board voltages by exact schematic net name; ignored for empty sheets. Ground stays zero. */
|
|
26
|
+
readonly voltageReferences?: Readonly<Record<string, number>>;
|
|
27
|
+
/** assets[symbolId][src]; required for every effective image/binary resource reference. */
|
|
28
|
+
readonly assets?: Readonly<Record<string, Readonly<Record<string, Uint8Array>>>>;
|
|
39
29
|
}
|
|
40
30
|
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* time back from {@link getSimTime}, so there is exactly one authority for time.
|
|
48
|
-
*/
|
|
49
|
-
export declare interface DeviceSimulationHost {
|
|
50
|
-
/**
|
|
51
|
-
* Reads and mounts the schematic behind `uri`; `undefined` clears the runtime.
|
|
52
|
-
*
|
|
53
|
-
* The implementation reads the bytes through its own `fs` and resolves the `image` / `binary`
|
|
54
|
-
* properties of every symbol against that schematic URI.
|
|
55
|
-
*/
|
|
56
|
-
loadSchematic(uri: string | undefined): Promise<void>;
|
|
57
|
-
/** Resets the loaded runtime to its initial state without unloading the schematic. */
|
|
58
|
-
reset(): Promise<void>;
|
|
59
|
-
/** Advances one fixed step of `dt` picoseconds when the widget host is in simulation mode. */
|
|
60
|
-
tick(dt: number): Promise<DeviceSimTickReport>;
|
|
61
|
-
/** Queues one payload for a device endpoint; consumed at the next {@link tick}. */
|
|
62
|
-
deliver(target: CanvasBindingTarget, payload: unknown, simTime?: number): Promise<void>;
|
|
63
|
-
/** Subscribes to device publishes; registering itself is a local operation. */
|
|
64
|
-
readonly onDidPublish: Event_2<SimulationPublish>;
|
|
65
|
-
/** Endpoints of the running devices, in schematic order. */
|
|
66
|
-
getTopics(): Promise<readonly DeviceTopic[]>;
|
|
67
|
-
/** Current simulation time, in picoseconds. */
|
|
68
|
-
getSimTime(): Promise<number>;
|
|
69
|
-
/** Schematic the runtime was built from. */
|
|
70
|
-
getSchematic(): Promise<SchematicDocument | undefined>;
|
|
71
|
-
/** Releases the runtime. */
|
|
72
|
-
dispose(): Promise<void>;
|
|
31
|
+
/** A current SDK device: JSON metadata plus self-contained ESM with named model/create exports. */
|
|
32
|
+
declare interface IPreparedSimulationDevice {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly definition: DeviceMetadata;
|
|
35
|
+
/** Imported only by the runtime guest, never by the editor that prepares this DTO. */
|
|
36
|
+
readonly code: string;
|
|
73
37
|
}
|
|
74
38
|
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
39
|
+
/** Serializable projection of a board diagnostic or invalid device topic publication. */
|
|
40
|
+
declare interface ISimulationDiagnostic {
|
|
41
|
+
readonly code: SimulationDiagnosticCode;
|
|
42
|
+
/** Empty only for a board-wide diagnostic with no associated instance. */
|
|
43
|
+
readonly symbol: string;
|
|
44
|
+
readonly port?: string;
|
|
45
|
+
readonly message: string;
|
|
46
|
+
readonly simTime: TimePs;
|
|
47
|
+
readonly runtimeCode?: RuntimeDiagnosticCode;
|
|
48
|
+
readonly phase?: RuntimePhase;
|
|
83
49
|
}
|
|
84
50
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* The default device simulation guest script, bundled and minified into this module while the
|
|
94
|
-
* package is built.
|
|
95
|
-
*
|
|
96
|
-
* It is a classic script: every dependency is inlined, so the sandbox runs it without a module
|
|
97
|
-
* loader. It resolves no devices — a package that owns devices passes its own guest script to the
|
|
98
|
-
* sandbox instead.
|
|
99
|
-
*/
|
|
100
|
-
export declare const deviceSimulationHostGuestScript: string;
|
|
51
|
+
declare interface ISimulationMessage {
|
|
52
|
+
readonly target: ISimulationMessageTarget;
|
|
53
|
+
readonly payload: unknown;
|
|
54
|
+
/** End of the tick that delivered this publication, in integer picoseconds. */
|
|
55
|
+
readonly simTime: TimePs;
|
|
56
|
+
}
|
|
101
57
|
|
|
102
|
-
|
|
103
|
-
export declare interface DeviceTopic {
|
|
58
|
+
declare interface ISimulationMessageTarget {
|
|
104
59
|
readonly symbol: string;
|
|
105
|
-
/** Reference designator shown to users; informational for the canvas. */
|
|
106
|
-
readonly designator?: string;
|
|
107
60
|
readonly port: string;
|
|
108
|
-
readonly direction: 'input' | 'output';
|
|
109
|
-
readonly type: PayloadType;
|
|
110
|
-
readonly title?: string;
|
|
111
61
|
}
|
|
112
62
|
|
|
113
|
-
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
*/
|
|
117
|
-
|
|
63
|
+
/** Owns a Board; failed load/reset leaves the previous board and queued inputs intact. */
|
|
64
|
+
declare interface ISimulationRuntime {
|
|
65
|
+
load(input: IPreparedSimulation): Promise<void>;
|
|
66
|
+
/** Recreates the captured board synchronously without re-importing modules. */
|
|
67
|
+
reset(): Promise<void>;
|
|
68
|
+
/** Advances by a positive integer number of picoseconds, up to MAX_TIME_PS. */
|
|
69
|
+
tick(dt: TimePs): Promise<ISimulationTickReport>;
|
|
70
|
+
/** Snapshots a declared input; the next tick delivers it before Board.runUntil. */
|
|
71
|
+
deliver(message: ISimulationMessage): Promise<void>;
|
|
72
|
+
readonly onDidPublish: Event_2<ISimulationMessage>;
|
|
73
|
+
readonly onDidDiagnostic: Event_2<ISimulationDiagnostic>;
|
|
74
|
+
dispose(): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Startup options of the worker-backed runtime adapter. */
|
|
78
|
+
export declare interface ISimulationRuntimeWorkerOptions {
|
|
118
79
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
80
|
+
* Extra port transferred after the RPC port.
|
|
81
|
+
*
|
|
82
|
+
* The guest registers the `simulation-runtime` data plane on it; the caller keeps the other end
|
|
83
|
+
* so a widget guest can deliver and subscribe without the host relaying.
|
|
121
84
|
*/
|
|
122
|
-
readonly
|
|
123
|
-
/** Host capability: source of schematic bytes; the guest never reads the host file system. */
|
|
124
|
-
readonly fs: DeviceSimulationHostFileSystem;
|
|
125
|
-
/** Extra ports transferred after the RPC port in the guest's first startup message. */
|
|
126
|
-
readonly ports?: readonly MessagePort[];
|
|
85
|
+
readonly topicPort?: MessagePort;
|
|
127
86
|
}
|
|
128
87
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
readonly
|
|
133
|
-
readonly simTime: number;
|
|
88
|
+
declare interface ISimulationTickReport {
|
|
89
|
+
readonly simTime: TimePs;
|
|
90
|
+
/** One successful Board.runUntil call, or zero when no board is loaded. */
|
|
91
|
+
readonly executed: number;
|
|
134
92
|
}
|
|
135
93
|
|
|
94
|
+
declare type RuntimeDiagnosticCode = 'INVALID_CONFIGURATION' | 'MODEL_VALIDATION_FAILED' | 'RESOURCE_ALLOCATION_FAILED' | 'INVALID_ELECTRICAL_PARAMETER' | 'CONFLICTING_REFERENCE' | 'ELECTRICAL_SOLVE_FAILED' | 'CHANNEL_CONSUMER_CONFLICT' | 'INVALID_CALL_STATE' | 'OBJECT_DISPOSED' | 'BOARD_FAULTED' | 'INVALID_BINDING' | 'MODEL_EXECUTION_FAILED' | 'JIT_FAILED' | 'DEVICE_CALLBACK_FAILED' | 'ASYNC_HOOK_RESULT' | 'CHANNEL_OVERFLOW' | 'REPORTED_ERROR' | 'CLEANUP_FAILED' | 'STALE_REPORT' | 'HOST_LISTENER_FAILED';
|
|
95
|
+
|
|
96
|
+
declare type RuntimePhase = 'library' | 'assembly' | 'initialize' | 'execute' | 'translate' | 'sync' | 'topic' | 'dispose' | 'host' | 'report';
|
|
97
|
+
|
|
98
|
+
declare type SimulationDiagnosticCode = 'device/input-failed' | 'device/output-failed' | 'board/error' | 'board/diagnostic';
|
|
99
|
+
|
|
100
|
+
export { simulationRuntimeGuestScript }
|
|
101
|
+
|
|
136
102
|
export { }
|