@tellegen/engine 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,393 @@
1
+ /** The browser engine API. Requests run in a dedicated Web Worker when the
2
+ * browser allows one — a solve never blocks the page — and on the calling
3
+ * thread otherwise (see host.ts). Nothing downloads until the first engine
4
+ * call; dropped files are parsed locally and never leave the machine. */
5
+ import { engineHost } from "./host.js";
6
+ import { isPermanentWasmLoadFailure } from "./errors.js";
7
+ export { CONTRACT_SOURCE_SHA256, CONTRACT_VERSION, FORMULATION_IDS, SOLVE_STATUSES, } from "./generated/contracts.js";
8
+ export async function preloadEngine() {
9
+ await engineHost().call({ op: "preload" });
10
+ }
11
+ /** Asserts a request that must carry a payload actually did. */
12
+ function expectText(value) {
13
+ if (value === null)
14
+ throw new Error("engine returned no payload");
15
+ return value;
16
+ }
17
+ /** powerio format token from a file name; null for non-case files. */
18
+ export function formatOf(name) {
19
+ const ext = name.split(".").pop()?.toLowerCase();
20
+ return ext === "m" || ext === "raw" || ext === "aux" ? ext : null;
21
+ }
22
+ export async function ingestCase(text, format) {
23
+ return JSON.parse(expectText(await engineHost().call({ op: "ingest_case", text, format })));
24
+ }
25
+ /** Parse a multiconductor distribution case for viewing. `format` is a
26
+ * distribution reader token (`dss`, `bmopf`, `pmd`) or `pio` for a `.pio.json`
27
+ * package carrying a multiconductor payload. Rejects on malformed input or a
28
+ * balanced package (which the study-restore path handles). */
29
+ export async function ingestDistCase(text, format) {
30
+ return JSON.parse(expectText(await engineHost().call({ op: "ingest_dist_case", text, format })));
31
+ }
32
+ /** True for binary display files (PowerWorld .pwd), read via parseDisplay.
33
+ * Kept separate from formatOf: a .pwd is display data, not a case format. */
34
+ export function isDisplayFile(name) {
35
+ return name.split(".").pop()?.toLowerCase() === "pwd";
36
+ }
37
+ export async function parseDisplay(bytes) {
38
+ return JSON.parse(expectText(await engineHost().call({ op: "parse_display", bytes, format: "pwd" })));
39
+ }
40
+ /** Parse a geographic sidecar (buscoords CSV, aliased CSV/JSON records,
41
+ * GeoJSON) from raw dropped bytes through powerio's tolerant reader. `hint`
42
+ * is the file name (picks CSV against JSON; "" sniffs). Rejects input with
43
+ * no usable coordinates. */
44
+ export async function parseGeo(bytes, hint) {
45
+ return JSON.parse(expectText(await engineHost().call({ op: "parse_geo", bytes, hint })));
46
+ }
47
+ /** Apply a parsed layer onto a case network (matching by uid, external id,
48
+ * name, and the unordered branch endpoint pair). Rejects when nothing
49
+ * matched. */
50
+ export async function applyGeo(networkJson, layer) {
51
+ return JSON.parse(expectText(await engineHost().call({
52
+ op: "apply_geo",
53
+ network_json: networkJson,
54
+ layer,
55
+ })));
56
+ }
57
+ /** Stamp a computed layout (bus id => [lon, lat]) onto a case network with
58
+ * its provenance, so saves and exports carry it. */
59
+ export async function applyLayout(networkJson, coords, kind) {
60
+ return JSON.parse(expectText(await engineHost().call({
61
+ op: "apply_layout",
62
+ network_json: networkJson,
63
+ coords: JSON.stringify(coords),
64
+ kind,
65
+ })));
66
+ }
67
+ /** A case's coordinates as a canonical `.geo.json` document. Rejects when the
68
+ * case carries none. */
69
+ export async function extractGeo(networkJson) {
70
+ return expectText(await engineHost().call({ op: "extract_geo", network_json: networkJson }));
71
+ }
72
+ /** Fill case coordinates from a PowerWorld `.pwd` sibling: substation symbols
73
+ * project to approximate longitude/latitude and join onto buses through the
74
+ * `SubNum` extras key. Rejects when no bus joined. */
75
+ export async function applyDisplayGeo(networkJson, bytes) {
76
+ return JSON.parse(expectText(await engineHost().call({
77
+ op: "apply_display_geo",
78
+ network_json: networkJson,
79
+ bytes,
80
+ })));
81
+ }
82
+ export async function capabilities() {
83
+ return JSON.parse(expectText(await engineHost().call({ op: "capabilities" })));
84
+ }
85
+ export async function solveJson(networkJson, request = {}) {
86
+ return JSON.parse(expectText(await engineHost().call({
87
+ op: "solve_json",
88
+ network_json: networkJson,
89
+ request: JSON.stringify(request),
90
+ })));
91
+ }
92
+ export { errorText } from "./errors.js";
93
+ /** True when the engine wasm module has failed to load in a way it can never
94
+ * recover from in this browser. Nothing solves client side when this is true;
95
+ * the caller decides whether a server fallback exists. */
96
+ export function isPermanentEngineFailure(message) {
97
+ return isPermanentWasmLoadFailure(message);
98
+ }
99
+ /** An all-digit record key is the numeric-id form (object keys are strings at
100
+ * runtime); anything else is a powerio row uid, sent as a string. */
101
+ function toElementKey(key) {
102
+ return /^\d+$/.test(key) ? Number(key) : key;
103
+ }
104
+ /** A `NetworkEdit[]` for the wasm Study, dropping zero deltas so an unchanged
105
+ * element is never sent. */
106
+ function toEdits(deltas, rates) {
107
+ const edits = Object.entries(deltas)
108
+ .filter(([, mw]) => mw !== 0)
109
+ .map(([bus, p_mw]) => ({ kind: "add_load", bus: toElementKey(bus), p_mw }));
110
+ for (const [branch, delta_mw] of Object.entries(rates)) {
111
+ if (delta_mw !== 0) {
112
+ edits.push({
113
+ kind: "adjust_branch_rating",
114
+ branch: toElementKey(branch),
115
+ delta_mw,
116
+ });
117
+ }
118
+ }
119
+ return edits;
120
+ }
121
+ /** The (operand, parameter) cells the UI drives: a study whose sensitivity column is
122
+ * ∂(price, active) / ∂(demand, active) for a bus target, or ∂(price, active) /
123
+ * ∂(line limit) for a branch target. The *formulation* is no longer fixed here — it is
124
+ * a parameter threaded from the UI's selector through `createStudy` (every formulation the
125
+ * full wasm build carries returns LMP, so these columns apply to all of them). The
126
+ * operand/parameters stay centralized so `createStudy` and the Study's `commit`/`preview`
127
+ * requests read one source. */
128
+ const STUDY_CAPABILITY = {
129
+ /** The watched operand: locational marginal price (active power). */
130
+ operand: { Price: "Active" },
131
+ /** The varied bus parameter: bus demand (active power). */
132
+ parameter: { Demand: "Active" },
133
+ /** The varied branch parameter: the thermal rating (serde unit variant). */
134
+ ratingParameter: "LineLimit",
135
+ };
136
+ /** UI-facing formulation menu: tag, a short label, and a one-line description. The order
137
+ * is the menu order; `dcopf` is first and is the default. */
138
+ export const FORMULATIONS = [
139
+ { id: "dcopf", label: "DC OPF", hint: "DC optimal power flow (the default)" },
140
+ {
141
+ id: "socwr",
142
+ label: "SOCWR",
143
+ hint: "Jabr second-order-cone relaxation of AC OPF",
144
+ },
145
+ {
146
+ id: "acopf",
147
+ label: "AC OPF",
148
+ hint: "full nonlinear AC optimal power flow",
149
+ disabled: true,
150
+ },
151
+ ];
152
+ /** The default formulation: DC OPF, preserving the prior fixed behavior byte-for-byte. */
153
+ export const DEFAULT_FORMULATION = "dcopf";
154
+ /** The `Operand[]` JSON `Study.preview` watches (the LMP column). */
155
+ const PREVIEW_OPERANDS_JSON = JSON.stringify([STUDY_CAPABILITY.operand]);
156
+ /** The `SensRequest[]` JSON for `Study.commit`: the ∂LMP/∂demand column at a dense bus
157
+ * index, or the ∂LMP/∂rating column at a dense branch index, or `[]` when there is no
158
+ * target. NOTE: `SensRequest.indices` are **dense positional** indices into the target's
159
+ * axis (0-based), *not* external ids — `BrowserStudy` translates the selected external id
160
+ * to its dense index before calling this. */
161
+ function sensitivitiesJson(target) {
162
+ if (target === null)
163
+ return "[]";
164
+ return JSON.stringify([
165
+ {
166
+ operand: STUDY_CAPABILITY.operand,
167
+ parameter: target.kind === "bus"
168
+ ? STUDY_CAPABILITY.parameter
169
+ : STUDY_CAPABILITY.ratingParameter,
170
+ indices: [target.index],
171
+ },
172
+ ]);
173
+ }
174
+ /** Extract the ∂LMP/∂parameter column from the first requested `SensitivityMatrix` into
175
+ * the `SensitivityColumn` the map and legend consume, the same shape the server serves.
176
+ * Rows are Price operands per bus; the single column is the selected parameter, so the
177
+ * column is `values[r][0]` keyed by each row's source bus id, and the source element is
178
+ * `cols[0].element`: a bus for the demand parameter (`parameter: "d"`) or a branch for
179
+ * the rating parameter (`parameter: "fmax"`). Returns null when no matrix was requested
180
+ * or its column has no recognized source element. */
181
+ function sensitivityColumn(caseId, matrices) {
182
+ const m = matrices[0];
183
+ const el = m?.cols[0]?.element;
184
+ if (!m || !el)
185
+ return null;
186
+ const values = m.rows
187
+ .map((row, r) => ({ bus: row.element.Bus, value: m.values[r]?.[0] ?? 0 }))
188
+ .filter((v) => v.bus !== undefined);
189
+ const shared = { case: caseId, operand: "lmp", units: m.units, values };
190
+ if (el.Bus !== undefined) {
191
+ return { ...shared, parameter: "d", bus: el.Bus };
192
+ }
193
+ if (el.Branch !== undefined) {
194
+ return { ...shared, parameter: "fmax", branch: el.Branch };
195
+ }
196
+ return null;
197
+ }
198
+ function solveResponseToSolution(out) {
199
+ return {
200
+ objective: out.objective ?? 0,
201
+ lmp: (out.lmp ?? []).map((e) => ({ bus: e.bus, usd_per_mwh: e.value })),
202
+ va: out.va ?? [],
203
+ w: out.w ?? [],
204
+ flows: (out.flows ?? []).map((f) => ({
205
+ branch: f.branch,
206
+ mw: f.pf,
207
+ loading: f.loading,
208
+ })),
209
+ dispatch: (out.dispatch ?? []).map((d) => ({ gen: d.gen, mw: d.pg })),
210
+ };
211
+ }
212
+ /** Build-once browser transport for the reactive demand drag. The network is
213
+ * parsed and the model built when the Study is created; `commit` solves exactly
214
+ * at the UI's absolute demand delta state and `preview` returns a first-order
215
+ * linearization toward an absolute demand delta state, neither re-parsing the
216
+ * network. The wasm Study lives behind the engine host (a dedicated worker
217
+ * when the browser allows one), so every method is async. */
218
+ export class BrowserStudy {
219
+ #host;
220
+ /** The caller-allocated handle naming the wasm Study on the host. */
221
+ #handle;
222
+ /** External bus id -> dense positional bus index, built once from the committed solution's
223
+ * LMP ordering (each `lmp[i].bus` sits at dense index `i`). The engine keys `SensRequest`
224
+ * by this dense index, not the external bus id, so the selected bus must be translated
225
+ * before a sensitivity request. Null until first needed; the bus set is solve-invariant. */
226
+ #busToIndex = null;
227
+ /** External branch id -> dense positional branch index, from the committed solution's
228
+ * flows ordering — the branch-axis counterpart of `#busToIndex`. */
229
+ #branchToIndex = null;
230
+ constructor(host, handle) {
231
+ this.#host = host;
232
+ this.#handle = handle;
233
+ }
234
+ async #solution() {
235
+ return JSON.parse(expectText(await this.#host.call({ op: "study_solution", study: this.#handle })));
236
+ }
237
+ async #replaceEdits(deltas, rates, target) {
238
+ const sensitivities = sensitivitiesJson(await this.#senseTarget(target));
239
+ return JSON.parse(expectText(await this.#host.call({
240
+ op: "study_replace_edits",
241
+ study: this.#handle,
242
+ edits: JSON.stringify(toEdits(deltas, rates)),
243
+ sensitivities,
244
+ })));
245
+ }
246
+ /** The dense-axis sensitivity target the engine expects for a selection (external
247
+ * ids), or null when nothing is selected or the id is unknown. Memoizes the
248
+ * id->index maps from the committed solution's LMP / flows order — the same axis
249
+ * orders the engine's dense sensitivity columns use. */
250
+ async #senseTarget(target) {
251
+ if (target === null)
252
+ return null;
253
+ if ("bus" in target) {
254
+ if (!this.#busToIndex) {
255
+ const sol = await this.#solution();
256
+ this.#busToIndex = new Map((sol.lmp ?? []).map((e, i) => [e.bus, i]));
257
+ }
258
+ const index = this.#busToIndex.get(target.bus);
259
+ return index === undefined ? null : { kind: "bus", index };
260
+ }
261
+ if (!this.#branchToIndex) {
262
+ const sol = await this.#solution();
263
+ this.#branchToIndex = new Map((sol.flows ?? []).map((f, i) => [f.branch, i]));
264
+ }
265
+ const index = this.#branchToIndex.get(target.branch);
266
+ return index === undefined ? null : { kind: "branch", index };
267
+ }
268
+ /** Exact solve at demand = base + `deltas` and ratings = base + `rates`, replacing
269
+ * the committed point. When `target` names a bus or branch, its ∂LMP/∂parameter
270
+ * column is computed in the *same* solve and returned (no second round-trip);
271
+ * otherwise `sensitivity` is null. `caseId` labels the returned column. Returns the
272
+ * UI Solution, the solver iterates, and the column. */
273
+ async commit(caseId, deltas, rates, target) {
274
+ const out = await this.#replaceEdits(deltas, rates, target);
275
+ return {
276
+ solution: solveResponseToSolution(out.solution),
277
+ iterations: out.iterations ?? [],
278
+ sensitivity: target === null ? null : sensitivityColumn(caseId, out.sensitivities),
279
+ };
280
+ }
281
+ /** The ∂LMP/∂parameter column at `target` for this study's formulation, computed by
282
+ * an exact re-solve at the edited point (the same one-call path `commit` uses, but
283
+ * returning only the column). Used when a bus or branch is selected so the overlay
284
+ * matches the active formulation rather than always the DC sensitivity. `caseId`
285
+ * labels the column; returns null when no recognized column comes back. */
286
+ async sensitivity(caseId, deltas, rates, target) {
287
+ const out = await this.#replaceEdits(deltas, rates, target);
288
+ return sensitivityColumn(caseId, out.sensitivities);
289
+ }
290
+ /** First-order LMP preview for replacing the committed point with
291
+ * demand = base + `deltas` and ratings = base + `rates`, with no re-solve:
292
+ * predicted per-bus ΔLMP and the predicted Δobjective. */
293
+ async preview(deltas, rates = {}) {
294
+ const out = JSON.parse(expectText(await this.#host.call({
295
+ op: "study_preview",
296
+ study: this.#handle,
297
+ edits: JSON.stringify(toEdits(deltas, rates)),
298
+ operands: PREVIEW_OPERANDS_JSON,
299
+ })));
300
+ const lmp = (out.operands[0]?.values ?? [])
301
+ .filter((v) => v.element.Bus !== undefined)
302
+ .map((v) => ({ bus: v.element.Bus, usd_per_mwh: v.value }));
303
+ return { lmp, objectiveDelta: out.objective_delta };
304
+ }
305
+ /** The Study's current exact solution. Called immediately after Study creation
306
+ * to cache the base point for formulation comparisons. */
307
+ async currentSolution() {
308
+ return solveResponseToSolution(await this.#solution());
309
+ }
310
+ /** Serialize this study as a `.pio.json` package: the base network payload, the
311
+ * edit log as the study block, and the formulation and solve options under
312
+ * `study.app["tellegen"]`. The returned text is ready to download or hand to
313
+ * `exportStudy`. */
314
+ async savePackage() {
315
+ return expectText(await this.#host.call({ op: "study_save_package", study: this.#handle }));
316
+ }
317
+ /** Apply a parsed geographic layer (the canonical `.geo.json` from
318
+ * `parseGeo` or `applyLayout`) onto this study's base network, so the next
319
+ * `savePackage` or export carries the coordinates on screen. Locations are
320
+ * metadata the model never reads; nothing re-solves. */
321
+ async applyGeoLayer(layer) {
322
+ return JSON.parse(expectText(await this.#host.call({
323
+ op: "study_apply_geo",
324
+ study: this.#handle,
325
+ layer,
326
+ })));
327
+ }
328
+ /** Release the wasm Study; call when discarding it (e.g. the case's
329
+ * networkJson changed, or the case was removed). Fire and forget: the
330
+ * handle is invalid from this call on. */
331
+ free() {
332
+ void this.#host
333
+ .call({ op: "study_free", study: this.#handle })
334
+ .catch(() => { });
335
+ }
336
+ }
337
+ /** Construct a build-once Study over `networkJson` for `formulation`, parsing the network
338
+ * and solving the base case once. `formulation` is a `Problem` tag (`dcopf`/`acopf`/`socwr`,
339
+ * defaulting to DC OPF); the full wasm build solves every one entirely in the browser.
340
+ * Throws if the engine module can't load (or the formulation is unknown/not built); the
341
+ * caller must catch and fall back (see `isPermanentEngineFailure`). */
342
+ let studySeq = 0;
343
+ export async function createStudy(networkJson, formulation = DEFAULT_FORMULATION) {
344
+ const host = engineHost();
345
+ // Handles are allocated here, not by the host, so a pending build replayed
346
+ // onto the fallback host keeps naming the same study.
347
+ const handle = ++studySeq;
348
+ await host.call({
349
+ op: "study_new",
350
+ study: handle,
351
+ network_json: networkJson,
352
+ formulation,
353
+ });
354
+ return new BrowserStudy(host, handle);
355
+ }
356
+ /** Restore a study saved by `BrowserStudy.savePackage`: the case, edit sliders,
357
+ * formulation, and solve options in one step. Rejects on a malformed package or one
358
+ * that is not a tellegen study (the engine fails the load closed). */
359
+ export async function loadPackage(text) {
360
+ return JSON.parse(expectText(await engineHost().call({ op: "load_package", text })));
361
+ }
362
+ /** Export a saved study package at commit `commit` to a powerio `format` (`matpower`,
363
+ * `psse`, `powerio-json`, ...). Returns the serialized case text, the writer's fidelity
364
+ * warnings, and the format token and file extension. */
365
+ export async function exportStudy(packageJson, commit, format) {
366
+ return JSON.parse(expectText(await engineHost().call({
367
+ op: "export_study",
368
+ package_json: packageJson,
369
+ commit,
370
+ format,
371
+ })));
372
+ }
373
+ export const browserWasmTransport = {
374
+ preloadEngine,
375
+ ingestCase,
376
+ ingestDistCase,
377
+ parseDisplay,
378
+ parseGeo,
379
+ applyGeo,
380
+ applyLayout,
381
+ extractGeo,
382
+ applyDisplayGeo,
383
+ capabilities,
384
+ solveJson,
385
+ createStudy,
386
+ loadPackage,
387
+ exportStudy,
388
+ };
389
+ export function createBrowserWasmTransport() {
390
+ return browserWasmTransport;
391
+ }
392
+ export { BrowserStudy as Study };
393
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;yEAGyE;AACzE,OAAO,EAAE,UAAU,EAAmB,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAczD,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,cAAc,GACf,MAAM,0BAA0B,CAAC;AAyKlC,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,MAAM,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED,gEAAgE;AAChE,SAAS,UAAU,CAAC,KAAoB;IACtC,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAClE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,CAAC;IACjD,OAAO,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACpE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,IAAY,EACZ,MAAc;IAEd,OAAO,IAAI,CAAC,KAAK,CACf,UAAU,CAAC,MAAM,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CACzE,CAAC;AACJ,CAAC;AAED;;;8DAG8D;AAC9D,MAA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IACX,WAAW;IACX,WAAW;CACZ,CAAC;AAEF,MAAM,UAAU,0BAA0B;IACxC,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED,OAAO,EAAE,YAAY,IAAI,KAAK,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ /** Lazy loader for the powerio wasm module on the calling thread, used by the
2
+ * main-thread fallback host. The worker entry has its own loader (static
3
+ * imports keep the worker a single chunk). Nothing downloads until the first
4
+ * engine call; dropped files are parsed locally and never leave the machine. */
5
+ export type WasmModule = typeof import("./wasm-pkg/tellegen.js");
6
+ export type WasmStudy = InstanceType<WasmModule["Study"]>;
7
+ /** The one wasm module (Study, all formulations, sensitivities). Resolve the
8
+ * wasm asset only when the engine is used: SvelteKit's dev mode SSR pass can
9
+ * evaluate this module without touching the wasm loader. */
10
+ export declare function engineModule(): Promise<WasmModule>;
11
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;gFAGgF;AAIhF,MAAM,MAAM,UAAU,GAAG,cAAc,wBAAwB,CAAC,CAAC;AACjE,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AAK1D;;4DAE4D;AAC5D,wBAAgB,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC,CAiBlD"}
package/dist/module.js ADDED
@@ -0,0 +1,31 @@
1
+ /** Lazy loader for the powerio wasm module on the calling thread, used by the
2
+ * main-thread fallback host. The worker entry has its own loader (static
3
+ * imports keep the worker a single chunk). Nothing downloads until the first
4
+ * engine call; dropped files are parsed locally and never leave the machine. */
5
+ import { errorText, isPermanentWasmLoadFailure } from "./errors.js";
6
+ let engineReady = null;
7
+ let engineUnsupported = null;
8
+ /** The one wasm module (Study, all formulations, sensitivities). Resolve the
9
+ * wasm asset only when the engine is used: SvelteKit's dev mode SSR pass can
10
+ * evaluate this module without touching the wasm loader. */
11
+ export function engineModule() {
12
+ if (engineUnsupported)
13
+ return Promise.reject(new Error(engineUnsupported));
14
+ const wasmUrl = new URL("./wasm-pkg/tellegen_bg.wasm", import.meta.url).href;
15
+ engineReady ??= import("./wasm-pkg/tellegen.js")
16
+ .then(async (mod) => {
17
+ await mod.default({ module_or_path: wasmUrl });
18
+ return mod;
19
+ })
20
+ .catch((e) => {
21
+ const message = errorText(e);
22
+ // Don't cache a rejected load: a transient failure (chunk fetch or
23
+ // instantiate) must not disable the engine for the whole session.
24
+ engineReady = null;
25
+ if (isPermanentWasmLoadFailure(message))
26
+ engineUnsupported = message;
27
+ throw e;
28
+ });
29
+ return engineReady;
30
+ }
31
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;gFAGgF;AAEhF,OAAO,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAKpE,IAAI,WAAW,GAA+B,IAAI,CAAC;AACnD,IAAI,iBAAiB,GAAkB,IAAI,CAAC;AAE5C;;4DAE4D;AAC5D,MAAM,UAAU,YAAY;IAC1B,IAAI,iBAAiB;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC3E,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,6BAA6B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IAC7E,WAAW,KAAK,MAAM,CAAC,wBAAwB,CAAC;SAC7C,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAClB,MAAM,GAAG,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/C,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACX,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QAC7B,mEAAmE;QACnE,kEAAkE;QAClE,WAAW,GAAG,IAAI,CAAC;QACnB,IAAI,0BAA0B,CAAC,OAAO,CAAC;YAAE,iBAAiB,GAAG,OAAO,CAAC;QACrE,MAAM,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;IACL,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,101 @@
1
+ /** The engine call protocol: one request shape shared by the worker host
2
+ * (postMessage) and the main-thread host (direct dispatch), so a request built
3
+ * once runs on either side. Payloads are the wasm surface's own JSON strings
4
+ * (or raw display bytes); the typed translation stays in index.ts. Study
5
+ * handles are allocated by the caller, which keeps them valid when pending
6
+ * requests replay against the other host. */
7
+ import type { WasmModule, WasmStudy } from "./module.js";
8
+ export type EngineRequest = {
9
+ op: "preload";
10
+ } | {
11
+ op: "ingest_case";
12
+ text: string;
13
+ format: string;
14
+ } | {
15
+ op: "ingest_dist_case";
16
+ text: string;
17
+ format: string;
18
+ } | {
19
+ op: "parse_display";
20
+ bytes: Uint8Array;
21
+ format: string;
22
+ } | {
23
+ op: "parse_geo";
24
+ bytes: Uint8Array;
25
+ hint: string;
26
+ } | {
27
+ op: "apply_geo";
28
+ network_json: string;
29
+ layer: string;
30
+ } | {
31
+ op: "apply_layout";
32
+ network_json: string;
33
+ coords: string;
34
+ kind: string;
35
+ } | {
36
+ op: "extract_geo";
37
+ network_json: string;
38
+ } | {
39
+ op: "apply_display_geo";
40
+ network_json: string;
41
+ bytes: Uint8Array;
42
+ } | {
43
+ op: "capabilities";
44
+ } | {
45
+ op: "solve_json";
46
+ network_json: string;
47
+ request: string;
48
+ } | {
49
+ op: "study_new";
50
+ study: number;
51
+ network_json: string;
52
+ formulation: string;
53
+ } | {
54
+ op: "study_replace_edits";
55
+ study: number;
56
+ edits: string;
57
+ sensitivities: string;
58
+ } | {
59
+ op: "study_preview";
60
+ study: number;
61
+ edits: string;
62
+ operands: string;
63
+ } | {
64
+ op: "study_solution";
65
+ study: number;
66
+ } | {
67
+ op: "study_save_package";
68
+ study: number;
69
+ } | {
70
+ op: "study_apply_geo";
71
+ study: number;
72
+ layer: string;
73
+ } | {
74
+ op: "load_package";
75
+ text: string;
76
+ } | {
77
+ op: "export_study";
78
+ package_json: string;
79
+ commit: number;
80
+ format: string;
81
+ } | {
82
+ op: "study_free";
83
+ study: number;
84
+ };
85
+ export type WorkerRequest = EngineRequest & {
86
+ id: number;
87
+ };
88
+ export type WorkerResponse = {
89
+ id: number;
90
+ ok: true;
91
+ value: string | null;
92
+ } | {
93
+ id: number;
94
+ ok: false;
95
+ error: string;
96
+ };
97
+ /** Run one request against a loaded wasm module. `studies` maps caller
98
+ * allocated handles to live wasm Study instances on this side of the
99
+ * boundary. */
100
+ export declare function runRequest(mod: WasmModule, studies: Map<number, WasmStudy>, req: EngineRequest): string | null;
101
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;6CAK6C;AAE7C,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,MAAM,aAAa,GACrB;IAAE,EAAE,EAAE,SAAS,CAAA;CAAE,GACjB;IAAE,EAAE,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,EAAE,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,EAAE,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,EAAE,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,EAAE,E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;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,EAAE,EAAE,cAAc,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC5E;IAAE,EAAE,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,MAAM,MAAM,cAAc,GACtB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC9C;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7C;;eAEe;AACf,wBAAgB,UAAU,CACxB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/B,GAAG,EAAE,aAAa,GACjB,MAAM,GAAG,IAAI,CAmDf"}
@@ -0,0 +1,63 @@
1
+ /** The engine call protocol: one request shape shared by the worker host
2
+ * (postMessage) and the main-thread host (direct dispatch), so a request built
3
+ * once runs on either side. Payloads are the wasm surface's own JSON strings
4
+ * (or raw display bytes); the typed translation stays in index.ts. Study
5
+ * handles are allocated by the caller, which keeps them valid when pending
6
+ * requests replay against the other host. */
7
+ /** Run one request against a loaded wasm module. `studies` maps caller
8
+ * allocated handles to live wasm Study instances on this side of the
9
+ * boundary. */
10
+ export function runRequest(mod, studies, req) {
11
+ const study = (handle) => {
12
+ const s = studies.get(handle);
13
+ if (!s)
14
+ throw new Error(`unknown study handle ${handle}`);
15
+ return s;
16
+ };
17
+ switch (req.op) {
18
+ case "preload":
19
+ return null; // loading the module was the work
20
+ case "ingest_case":
21
+ return mod.ingest_case(req.text, req.format);
22
+ case "ingest_dist_case":
23
+ return mod.ingest_dist_case(req.text, req.format);
24
+ case "parse_display":
25
+ return mod.parse_display(req.bytes, req.format);
26
+ case "parse_geo":
27
+ return mod.parse_geo(req.bytes, req.hint);
28
+ case "apply_geo":
29
+ return mod.apply_geo(req.network_json, req.layer);
30
+ case "apply_layout":
31
+ return mod.apply_layout(req.network_json, req.coords, req.kind);
32
+ case "extract_geo":
33
+ return mod.extract_geo(req.network_json);
34
+ case "apply_display_geo":
35
+ return mod.apply_display_geo(req.network_json, req.bytes);
36
+ case "capabilities":
37
+ return mod.capabilities_json();
38
+ case "solve_json":
39
+ return mod.solve_json(req.network_json, req.request);
40
+ case "study_new":
41
+ studies.set(req.study, new mod.Study(req.network_json, req.formulation));
42
+ return null;
43
+ case "study_replace_edits":
44
+ return study(req.study).replace_edits(req.edits, req.sensitivities);
45
+ case "study_preview":
46
+ return study(req.study).preview_replacement(req.edits, req.operands);
47
+ case "study_solution":
48
+ return study(req.study).solution();
49
+ case "study_save_package":
50
+ return study(req.study).save_package();
51
+ case "study_apply_geo":
52
+ return study(req.study).apply_geo(req.layer);
53
+ case "load_package":
54
+ return mod.load_package(req.text);
55
+ case "export_study":
56
+ return mod.export_study(req.package_json, req.commit, req.format);
57
+ case "study_free":
58
+ studies.get(req.study)?.free();
59
+ studies.delete(req.study);
60
+ return null;
61
+ }
62
+ }
63
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;6CAK6C;AAgC7C;;eAEe;AACf,MAAM,UAAU,UAAU,CACxB,GAAe,EACf,OAA+B,EAC/B,GAAkB;IAElB,MAAM,KAAK,GAAG,CAAC,MAAc,EAAa,EAAE;QAC1C,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,CAAC,CAAC;YAAE,MAAM,I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