@manifest-configuration-language/browser 0.3.7 → 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 +2 -0
- package/dist/mcl.wasm +1 -1
- package/package.json +1 -1
- package/src/index.d.ts +21 -0
- package/src/index.js +99 -5
- package/src/worker.js +5 -0
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@ 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, 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
|
+
|
|
24
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.
|
|
25
27
|
|
|
26
28
|
An open project is a Worker-backed session. Call `project.update(files)` with the complete next snapshot when project files change, then use the returned project handle for subsequent operations. The SDK validates changed files, sends only changed, added, and removed files to the Worker, and applies those deltas to a bounded in-memory Go/WASM filesystem. Each operation sends its entrypoint source and session ID; the project filesystem is not resent or rebuilt. If a canceled or timed-out operation terminates the Worker, the next operation restores the complete snapshot before running. Existing `runtime.parse`, `runtime.render`, and other source-based methods continue to use per-request files.
|
package/dist/mcl.wasm
CHANGED
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -77,9 +77,30 @@ export type MclResult =
|
|
|
77
77
|
export interface RuntimeOptions {
|
|
78
78
|
initializationTimeoutMs?: number;
|
|
79
79
|
operationTimeoutMs?: number;
|
|
80
|
+
/** Receives local WebAssembly initialization state changes without project data. */
|
|
81
|
+
onStatus?: (event: RuntimeStatusEvent) => void;
|
|
82
|
+
/** Receives local operation latency measurements without source or project data. */
|
|
83
|
+
onOperation?: (event: RuntimeOperationEvent) => void;
|
|
80
84
|
workerFactory?: () => Worker;
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
export type RuntimeStatus = "fetching" | "compiling" | "initializing" | "ready" | "error";
|
|
88
|
+
export type RuntimeStatusEvent = {
|
|
89
|
+
status: RuntimeStatus;
|
|
90
|
+
workerGeneration: number;
|
|
91
|
+
initializationDurationMs?: number;
|
|
92
|
+
};
|
|
93
|
+
export type RuntimeOperationOutcome = "success" | "error" | "aborted";
|
|
94
|
+
export type RuntimeOperationEvent = {
|
|
95
|
+
operation: MclOperation;
|
|
96
|
+
durationMs: number;
|
|
97
|
+
queueWaitMs: number;
|
|
98
|
+
executionDurationMs: number;
|
|
99
|
+
wasmDurationMs?: number;
|
|
100
|
+
workerGeneration?: number;
|
|
101
|
+
outcome: RuntimeOperationOutcome;
|
|
102
|
+
};
|
|
103
|
+
|
|
83
104
|
export interface MclRuntime {
|
|
84
105
|
openProject(files: ProjectFiles): MclProject;
|
|
85
106
|
warmUp(options?: RequestOptions): Promise<void>;
|
package/src/index.js
CHANGED
|
@@ -112,7 +112,38 @@ export function createMclRuntime(options = {}) {
|
|
|
112
112
|
let stopCurrent;
|
|
113
113
|
let stopInitialization;
|
|
114
114
|
|
|
115
|
-
function
|
|
115
|
+
function emitStatus(status, details = {}) {
|
|
116
|
+
try {
|
|
117
|
+
Promise.resolve(options.onStatus?.({ status, workerGeneration, ...details })).catch(() => {});
|
|
118
|
+
} catch {
|
|
119
|
+
// Observability callbacks must not affect runtime behavior.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function emitOperation(operation, startedAt, outcome, details = {}) {
|
|
124
|
+
try {
|
|
125
|
+
const durationMs = Math.max(0, performance.now() - startedAt);
|
|
126
|
+
Promise.resolve(options.onOperation?.({
|
|
127
|
+
operation,
|
|
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 }),
|
|
139
|
+
outcome,
|
|
140
|
+
})).catch(() => {});
|
|
141
|
+
} catch {
|
|
142
|
+
// Observability callbacks must not affect runtime behavior.
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function enqueue(operation, run, signal, scope = "runtime", requestedPriority, timing) {
|
|
116
147
|
if (signal?.aborted) return Promise.reject(signal.reason ?? abortError());
|
|
117
148
|
const priority =
|
|
118
149
|
requestPriorities[requestedPriority] ?? operationPriorities[operation] ?? 0;
|
|
@@ -172,7 +203,17 @@ export function createMclRuntime(options = {}) {
|
|
|
172
203
|
async () => {
|
|
173
204
|
pending.started = true;
|
|
174
205
|
if (latestOnlyOperations.has(operation)) removePending(priority, pending);
|
|
175
|
-
|
|
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
|
+
}
|
|
176
217
|
},
|
|
177
218
|
{ priority, signal: queueController.signal },
|
|
178
219
|
)
|
|
@@ -190,12 +231,26 @@ export function createMclRuntime(options = {}) {
|
|
|
190
231
|
function startWorker() {
|
|
191
232
|
if (disposed) return Promise.reject(new Error("MCL runtime has been disposed"));
|
|
192
233
|
if (ready) return ready;
|
|
234
|
+
const initializationStartedAt = performance.now();
|
|
193
235
|
const currentWorker = workerFactory();
|
|
194
236
|
worker = currentWorker;
|
|
195
237
|
workerGeneration++;
|
|
196
238
|
workerProject = undefined;
|
|
239
|
+
let lastStatus;
|
|
240
|
+
const reportStatus = (status) => {
|
|
241
|
+
if (lastStatus === status) return;
|
|
242
|
+
lastStatus = 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
|
+
}
|
|
250
|
+
};
|
|
197
251
|
let resolveReady;
|
|
198
252
|
let rejectReady;
|
|
253
|
+
let initialized = false;
|
|
199
254
|
const initialization = new Promise((resolve, reject) => {
|
|
200
255
|
resolveReady = resolve;
|
|
201
256
|
rejectReady = reject;
|
|
@@ -206,7 +261,11 @@ export function createMclRuntime(options = {}) {
|
|
|
206
261
|
initializationTimeoutMs,
|
|
207
262
|
);
|
|
208
263
|
const onMessage = (event) => {
|
|
209
|
-
if (event.data?.type === "
|
|
264
|
+
if (event.data?.type === "status") {
|
|
265
|
+
reportStatus(event.data.status);
|
|
266
|
+
} else if (event.data?.type === "ready") {
|
|
267
|
+
initialized = true;
|
|
268
|
+
reportStatus("ready");
|
|
210
269
|
clearTimeout(timer);
|
|
211
270
|
currentWorker.removeEventListener("message", onMessage);
|
|
212
271
|
currentWorker.removeEventListener("error", onError);
|
|
@@ -216,8 +275,12 @@ export function createMclRuntime(options = {}) {
|
|
|
216
275
|
fail(new Error(event.data.message || "MCL WebAssembly initialization failed"));
|
|
217
276
|
}
|
|
218
277
|
};
|
|
219
|
-
const onError = (event) =>
|
|
278
|
+
const onError = (event) => {
|
|
279
|
+
reportStatus("error");
|
|
280
|
+
fail(new Error(event.message || "MCL worker failed"));
|
|
281
|
+
};
|
|
220
282
|
function fail(error) {
|
|
283
|
+
if (!initialized) reportStatus("error");
|
|
221
284
|
clearTimeout(timer);
|
|
222
285
|
currentWorker.removeEventListener("message", onMessage);
|
|
223
286
|
currentWorker.removeEventListener("error", onError);
|
|
@@ -354,6 +417,9 @@ export function createMclRuntime(options = {}) {
|
|
|
354
417
|
) {
|
|
355
418
|
const signal = requestOptions.signal;
|
|
356
419
|
if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
420
|
+
const startedAt = performance.now();
|
|
421
|
+
const timing = {};
|
|
422
|
+
let operationWorkerGeneration;
|
|
357
423
|
const run = async () => {
|
|
358
424
|
if (disposed) throw new Error("MCL runtime has been disposed");
|
|
359
425
|
if (requestOptions.signal?.aborted)
|
|
@@ -376,6 +442,7 @@ export function createMclRuntime(options = {}) {
|
|
|
376
442
|
throw new DOMException("The operation was aborted", "AbortError");
|
|
377
443
|
const currentWorker = worker;
|
|
378
444
|
const currentGeneration = workerGeneration;
|
|
445
|
+
operationWorkerGeneration = currentGeneration;
|
|
379
446
|
if (project) {
|
|
380
447
|
await syncProjectToWorker(
|
|
381
448
|
project,
|
|
@@ -389,6 +456,10 @@ export function createMclRuntime(options = {}) {
|
|
|
389
456
|
? undefined
|
|
390
457
|
: prepareFilesForTransfer(source, files, entrypoint);
|
|
391
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
|
+
};
|
|
392
463
|
return await new Promise((resolve, reject) => {
|
|
393
464
|
let settled = false;
|
|
394
465
|
const cleanup = () => {
|
|
@@ -408,6 +479,7 @@ export function createMclRuntime(options = {}) {
|
|
|
408
479
|
if (worker !== currentWorker || workerGeneration !== currentGeneration) return;
|
|
409
480
|
const response = event.data;
|
|
410
481
|
if (response?.type !== "response" || response.requestId !== requestId) return;
|
|
482
|
+
completeWasmTiming();
|
|
411
483
|
if (!response.value.ok) finish(reject, new MclRuntimeError(response.value.error));
|
|
412
484
|
else if (operation === "lint")
|
|
413
485
|
finish(resolve, { operation, diagnostics: response.value.result });
|
|
@@ -416,6 +488,7 @@ export function createMclRuntime(options = {}) {
|
|
|
416
488
|
const onError = (event) => stop(new Error(event.message || "MCL worker failed"));
|
|
417
489
|
const onAbort = () => stop(new DOMException("The operation was aborted", "AbortError"));
|
|
418
490
|
const stop = (error) => {
|
|
491
|
+
completeWasmTiming();
|
|
419
492
|
finish(reject, error);
|
|
420
493
|
currentWorker.terminate();
|
|
421
494
|
if (worker === currentWorker) {
|
|
@@ -439,6 +512,7 @@ export function createMclRuntime(options = {}) {
|
|
|
439
512
|
};
|
|
440
513
|
if (project) message.projectId = project.id;
|
|
441
514
|
else message.files = preparedFiles.files;
|
|
515
|
+
timing.wasmStartedAt = performance.now();
|
|
442
516
|
currentWorker.postMessage(message, preparedFiles?.transferables ?? []);
|
|
443
517
|
} catch (error) {
|
|
444
518
|
stop(error);
|
|
@@ -449,7 +523,27 @@ export function createMclRuntime(options = {}) {
|
|
|
449
523
|
throw error;
|
|
450
524
|
}
|
|
451
525
|
};
|
|
452
|
-
|
|
526
|
+
try {
|
|
527
|
+
const result = await enqueue(
|
|
528
|
+
operation,
|
|
529
|
+
run,
|
|
530
|
+
signal,
|
|
531
|
+
project?.id ?? "runtime",
|
|
532
|
+
requestOptions.priority,
|
|
533
|
+
timing,
|
|
534
|
+
);
|
|
535
|
+
emitOperation(operation, startedAt, "success", {
|
|
536
|
+
...timing,
|
|
537
|
+
workerGeneration: operationWorkerGeneration,
|
|
538
|
+
});
|
|
539
|
+
return result;
|
|
540
|
+
} catch (error) {
|
|
541
|
+
emitOperation(operation, startedAt, error?.name === "AbortError" ? "aborted" : "error", {
|
|
542
|
+
...timing,
|
|
543
|
+
workerGeneration: operationWorkerGeneration,
|
|
544
|
+
});
|
|
545
|
+
throw error;
|
|
546
|
+
}
|
|
453
547
|
}
|
|
454
548
|
|
|
455
549
|
function warmUp(requestOptions = {}) {
|
package/src/worker.js
CHANGED
|
@@ -73,6 +73,7 @@ async function initialize() {
|
|
|
73
73
|
initialized = (async () => {
|
|
74
74
|
if (!runtimeAssets?.wasmURL || !runtimeAssets?.wasmExecURL)
|
|
75
75
|
throw new Error("MCL runtime assets were not configured");
|
|
76
|
+
postMessage({ type: "status", status: "fetching" });
|
|
76
77
|
await import(runtimeAssets.wasmExecURL);
|
|
77
78
|
const go = new Go();
|
|
78
79
|
const response = await runtimeFetch(runtimeAssets.wasmURL);
|
|
@@ -80,11 +81,13 @@ async function initialize() {
|
|
|
80
81
|
// Load the runtime before denying network APIs, then lock them before Go starts.
|
|
81
82
|
denyNetworkAccess();
|
|
82
83
|
let instance;
|
|
84
|
+
postMessage({ type: "status", status: "compiling" });
|
|
83
85
|
try {
|
|
84
86
|
({ instance } = await WebAssembly.instantiateStreaming(response.clone(), go.importObject));
|
|
85
87
|
} catch {
|
|
86
88
|
({ instance } = await WebAssembly.instantiate(await response.arrayBuffer(), go.importObject));
|
|
87
89
|
}
|
|
90
|
+
postMessage({ type: "status", status: "initializing" });
|
|
88
91
|
const wasmReady = waitForWasmReady();
|
|
89
92
|
await Promise.race([
|
|
90
93
|
wasmReady,
|
|
@@ -92,8 +95,10 @@ async function initialize() {
|
|
|
92
95
|
throw new Error("MCL WebAssembly exited before initialization completed");
|
|
93
96
|
}),
|
|
94
97
|
]);
|
|
98
|
+
postMessage({ type: "status", status: "ready" });
|
|
95
99
|
postMessage({ type: "ready" });
|
|
96
100
|
})().catch((error) => {
|
|
101
|
+
postMessage({ type: "status", status: "error" });
|
|
97
102
|
postMessage({ type: "fatal", message: error instanceof Error ? error.message : String(error) });
|
|
98
103
|
throw error;
|
|
99
104
|
});
|