@manifest-configuration-language/browser 0.3.8 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,7 +21,7 @@ try {
21
21
 
22
22
  Call `runtime.warmUp()` to load the WebAssembly runtime before the first project operation. Pass `signal` and `timeoutMs` to warm-up or an operation to cancel it or set an upper bound for that call. Warm-up's timeout and `initializationTimeoutMs` bound worker startup; an operation's `timeoutMs` bounds execution after startup. Cancelling or timing out worker startup terminates that worker; the next queued operation can create a fresh worker. Cancelling or timing out an operation terminates its worker. Operations and warm-up are serialized because the current Go runtime uses one in-memory project root. Set `priority: "interactive"` for user-triggered work that should move ahead of queued requests, or `priority: "background"` for work that can wait behind default-priority requests. Pending completion, hover, and lint requests supersede older requests of the same project and priority; higher-priority pending requests are retained.
23
23
 
24
- `createMclRuntime()` accepts optional `onStatus` and `onOperation` callbacks for local diagnostics and performance measurements. `onStatus` receives `fetching`, `compiling`, `initializing`, `ready`, or `error` for each Worker lifecycle. `onOperation` receives the operation name, total elapsed milliseconds from API call through queue wait and completion, and a `success`, `error`, or `aborted` outcome. Events do not include source text, file paths, or project contents, and callbacks are not sent to a server. Callback exceptions do not affect runtime operations.
24
+ `createMclRuntime()` accepts optional `onStatus` and `onOperation` callbacks for local diagnostics and performance measurements. `onStatus` receives `fetching`, `compiling`, `initializing`, `ready`, or `error` for each Worker lifecycle, with the Worker generation and initialization duration on ready or error. `onOperation` receives the total duration, queue wait, time spent in the runtime, and the Worker generation. `wasmDurationMs` is present after the Worker receives an operation and measures the request round trip, excluding Worker startup and project synchronization. Events do not include source text, file paths, or project contents, and callbacks are not sent to a server. Callback exceptions do not affect runtime operations.
25
25
 
26
26
  Project files can be UTF-8 strings or `Uint8Array` values. UTF-8 files remain inline in project updates. The Browser SDK copies each changed `Uint8Array` and transfers its buffer to the Worker; the Worker sends only `{ "encoding": "binary" }` metadata in the update JSON and passes a path-to-`Uint8Array` map to the Go/WASM project session. The Go runtime copies those bytes into its bounded project filesystem. The SDK-owned and caller-owned arrays remain reusable after each update.
27
27
 
package/dist/mcl.wasm CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/mcl.wasm
3
3
  size: 96803351 bytes
4
- sha256: 399e62215cbb37c932cf7f56d50379b7622e16965e3050a5e0280c70ce2b0eae
4
+ sha256: fbb94afddae079c257f08b6f57a7476c04da51090aeb3c8d50b62f2d68a0fb1f
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifest-configuration-language/browser",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "Run MCL projects in a browser Web Worker using the Go WebAssembly runtime.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/index.d.ts CHANGED
@@ -85,11 +85,19 @@ export interface RuntimeOptions {
85
85
  }
86
86
 
87
87
  export type RuntimeStatus = "fetching" | "compiling" | "initializing" | "ready" | "error";
88
- export type RuntimeStatusEvent = { status: RuntimeStatus };
88
+ export type RuntimeStatusEvent = {
89
+ status: RuntimeStatus;
90
+ workerGeneration: number;
91
+ initializationDurationMs?: number;
92
+ };
89
93
  export type RuntimeOperationOutcome = "success" | "error" | "aborted";
90
94
  export type RuntimeOperationEvent = {
91
95
  operation: MclOperation;
92
96
  durationMs: number;
97
+ queueWaitMs: number;
98
+ executionDurationMs: number;
99
+ wasmDurationMs?: number;
100
+ workerGeneration?: number;
93
101
  outcome: RuntimeOperationOutcome;
94
102
  };
95
103
 
package/src/index.js CHANGED
@@ -112,19 +112,30 @@ export function createMclRuntime(options = {}) {
112
112
  let stopCurrent;
113
113
  let stopInitialization;
114
114
 
115
- function emitStatus(status) {
115
+ function emitStatus(status, details = {}) {
116
116
  try {
117
- Promise.resolve(options.onStatus?.({ status })).catch(() => {});
117
+ Promise.resolve(options.onStatus?.({ status, workerGeneration, ...details })).catch(() => {});
118
118
  } catch {
119
119
  // Observability callbacks must not affect runtime behavior.
120
120
  }
121
121
  }
122
122
 
123
- function emitOperation(operation, startedAt, outcome) {
123
+ function emitOperation(operation, startedAt, outcome, details = {}) {
124
124
  try {
125
+ const durationMs = Math.max(0, performance.now() - startedAt);
125
126
  Promise.resolve(options.onOperation?.({
126
127
  operation,
127
- durationMs: Math.max(0, performance.now() - startedAt),
128
+ durationMs,
129
+ queueWaitMs: details.executionStartedAt !== undefined
130
+ ? Math.max(0, details.executionStartedAt - startedAt)
131
+ : durationMs,
132
+ executionDurationMs: details.executionDurationMs ?? 0,
133
+ ...(details.wasmDurationMs === undefined
134
+ ? {}
135
+ : { wasmDurationMs: details.wasmDurationMs }),
136
+ ...(details.workerGeneration === undefined
137
+ ? {}
138
+ : { workerGeneration: details.workerGeneration }),
128
139
  outcome,
129
140
  })).catch(() => {});
130
141
  } catch {
@@ -132,7 +143,7 @@ export function createMclRuntime(options = {}) {
132
143
  }
133
144
  }
134
145
 
135
- function enqueue(operation, run, signal, scope = "runtime", requestedPriority) {
146
+ function enqueue(operation, run, signal, scope = "runtime", requestedPriority, timing) {
136
147
  if (signal?.aborted) return Promise.reject(signal.reason ?? abortError());
137
148
  const priority =
138
149
  requestPriorities[requestedPriority] ?? operationPriorities[operation] ?? 0;
@@ -192,7 +203,17 @@ export function createMclRuntime(options = {}) {
192
203
  async () => {
193
204
  pending.started = true;
194
205
  if (latestOnlyOperations.has(operation)) removePending(priority, pending);
195
- return run();
206
+ if (timing) timing.executionStartedAt = performance.now();
207
+ try {
208
+ return await run();
209
+ } finally {
210
+ if (timing) {
211
+ timing.executionDurationMs = Math.max(
212
+ 0,
213
+ performance.now() - timing.executionStartedAt,
214
+ );
215
+ }
216
+ }
196
217
  },
197
218
  { priority, signal: queueController.signal },
198
219
  )
@@ -210,6 +231,7 @@ export function createMclRuntime(options = {}) {
210
231
  function startWorker() {
211
232
  if (disposed) return Promise.reject(new Error("MCL runtime has been disposed"));
212
233
  if (ready) return ready;
234
+ const initializationStartedAt = performance.now();
213
235
  const currentWorker = workerFactory();
214
236
  worker = currentWorker;
215
237
  workerGeneration++;
@@ -218,10 +240,17 @@ export function createMclRuntime(options = {}) {
218
240
  const reportStatus = (status) => {
219
241
  if (lastStatus === status) return;
220
242
  lastStatus = status;
221
- emitStatus(status);
243
+ if (status === "ready" || status === "error") {
244
+ emitStatus(status, {
245
+ initializationDurationMs: Math.max(0, performance.now() - initializationStartedAt),
246
+ });
247
+ } else {
248
+ emitStatus(status);
249
+ }
222
250
  };
223
251
  let resolveReady;
224
252
  let rejectReady;
253
+ let initialized = false;
225
254
  const initialization = new Promise((resolve, reject) => {
226
255
  resolveReady = resolve;
227
256
  rejectReady = reject;
@@ -235,6 +264,7 @@ export function createMclRuntime(options = {}) {
235
264
  if (event.data?.type === "status") {
236
265
  reportStatus(event.data.status);
237
266
  } else if (event.data?.type === "ready") {
267
+ initialized = true;
238
268
  reportStatus("ready");
239
269
  clearTimeout(timer);
240
270
  currentWorker.removeEventListener("message", onMessage);
@@ -250,7 +280,7 @@ export function createMclRuntime(options = {}) {
250
280
  fail(new Error(event.message || "MCL worker failed"));
251
281
  };
252
282
  function fail(error) {
253
- reportStatus("error");
283
+ if (!initialized) reportStatus("error");
254
284
  clearTimeout(timer);
255
285
  currentWorker.removeEventListener("message", onMessage);
256
286
  currentWorker.removeEventListener("error", onError);
@@ -388,6 +418,8 @@ export function createMclRuntime(options = {}) {
388
418
  const signal = requestOptions.signal;
389
419
  if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
390
420
  const startedAt = performance.now();
421
+ const timing = {};
422
+ let operationWorkerGeneration;
391
423
  const run = async () => {
392
424
  if (disposed) throw new Error("MCL runtime has been disposed");
393
425
  if (requestOptions.signal?.aborted)
@@ -410,6 +442,7 @@ export function createMclRuntime(options = {}) {
410
442
  throw new DOMException("The operation was aborted", "AbortError");
411
443
  const currentWorker = worker;
412
444
  const currentGeneration = workerGeneration;
445
+ operationWorkerGeneration = currentGeneration;
413
446
  if (project) {
414
447
  await syncProjectToWorker(
415
448
  project,
@@ -423,6 +456,10 @@ export function createMclRuntime(options = {}) {
423
456
  ? undefined
424
457
  : prepareFilesForTransfer(source, files, entrypoint);
425
458
  const requestId = ++sequence;
459
+ const completeWasmTiming = () => {
460
+ if (timing.wasmStartedAt === undefined || timing.wasmDurationMs !== undefined) return;
461
+ timing.wasmDurationMs = Math.max(0, performance.now() - timing.wasmStartedAt);
462
+ };
426
463
  return await new Promise((resolve, reject) => {
427
464
  let settled = false;
428
465
  const cleanup = () => {
@@ -442,6 +479,7 @@ export function createMclRuntime(options = {}) {
442
479
  if (worker !== currentWorker || workerGeneration !== currentGeneration) return;
443
480
  const response = event.data;
444
481
  if (response?.type !== "response" || response.requestId !== requestId) return;
482
+ completeWasmTiming();
445
483
  if (!response.value.ok) finish(reject, new MclRuntimeError(response.value.error));
446
484
  else if (operation === "lint")
447
485
  finish(resolve, { operation, diagnostics: response.value.result });
@@ -450,6 +488,7 @@ export function createMclRuntime(options = {}) {
450
488
  const onError = (event) => stop(new Error(event.message || "MCL worker failed"));
451
489
  const onAbort = () => stop(new DOMException("The operation was aborted", "AbortError"));
452
490
  const stop = (error) => {
491
+ completeWasmTiming();
453
492
  finish(reject, error);
454
493
  currentWorker.terminate();
455
494
  if (worker === currentWorker) {
@@ -473,6 +512,7 @@ export function createMclRuntime(options = {}) {
473
512
  };
474
513
  if (project) message.projectId = project.id;
475
514
  else message.files = preparedFiles.files;
515
+ timing.wasmStartedAt = performance.now();
476
516
  currentWorker.postMessage(message, preparedFiles?.transferables ?? []);
477
517
  } catch (error) {
478
518
  stop(error);
@@ -490,11 +530,18 @@ export function createMclRuntime(options = {}) {
490
530
  signal,
491
531
  project?.id ?? "runtime",
492
532
  requestOptions.priority,
533
+ timing,
493
534
  );
494
- emitOperation(operation, startedAt, "success");
535
+ emitOperation(operation, startedAt, "success", {
536
+ ...timing,
537
+ workerGeneration: operationWorkerGeneration,
538
+ });
495
539
  return result;
496
540
  } catch (error) {
497
- emitOperation(operation, startedAt, error?.name === "AbortError" ? "aborted" : "error");
541
+ emitOperation(operation, startedAt, error?.name === "AbortError" ? "aborted" : "error", {
542
+ ...timing,
543
+ workerGeneration: operationWorkerGeneration,
544
+ });
498
545
  throw error;
499
546
  }
500
547
  }