@czap/worker 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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/dist/compositor-script.d.ts +19 -0
  4. package/dist/compositor-script.d.ts.map +1 -0
  5. package/dist/compositor-script.js +374 -0
  6. package/dist/compositor-script.js.map +1 -0
  7. package/dist/compositor-startup.d.ts +200 -0
  8. package/dist/compositor-startup.d.ts.map +1 -0
  9. package/dist/compositor-startup.js +490 -0
  10. package/dist/compositor-startup.js.map +1 -0
  11. package/dist/compositor-types.d.ts +135 -0
  12. package/dist/compositor-types.d.ts.map +1 -0
  13. package/dist/compositor-types.js +7 -0
  14. package/dist/compositor-types.js.map +1 -0
  15. package/dist/compositor-worker.d.ts +65 -0
  16. package/dist/compositor-worker.d.ts.map +1 -0
  17. package/dist/compositor-worker.js +454 -0
  18. package/dist/compositor-worker.js.map +1 -0
  19. package/dist/evaluate-inline.d.ts +22 -0
  20. package/dist/evaluate-inline.d.ts.map +1 -0
  21. package/dist/evaluate-inline.js +42 -0
  22. package/dist/evaluate-inline.js.map +1 -0
  23. package/dist/host.d.ts +97 -0
  24. package/dist/host.d.ts.map +1 -0
  25. package/dist/host.js +115 -0
  26. package/dist/host.js.map +1 -0
  27. package/dist/index.d.ts +40 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +40 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/messages.d.ts +254 -0
  32. package/dist/messages.d.ts.map +1 -0
  33. package/dist/messages.js +55 -0
  34. package/dist/messages.js.map +1 -0
  35. package/dist/render-worker.d.ts +77 -0
  36. package/dist/render-worker.d.ts.map +1 -0
  37. package/dist/render-worker.js +396 -0
  38. package/dist/render-worker.js.map +1 -0
  39. package/dist/spsc-ring.d.ts +171 -0
  40. package/dist/spsc-ring.d.ts.map +1 -0
  41. package/dist/spsc-ring.js +240 -0
  42. package/dist/spsc-ring.js.map +1 -0
  43. package/package.json +51 -0
  44. package/src/compositor-script.ts +374 -0
  45. package/src/compositor-startup.ts +666 -0
  46. package/src/compositor-types.ts +175 -0
  47. package/src/compositor-worker.ts +613 -0
  48. package/src/evaluate-inline.ts +42 -0
  49. package/src/host.ts +189 -0
  50. package/src/index.ts +49 -0
  51. package/src/messages.ts +343 -0
  52. package/src/render-worker.ts +454 -0
  53. package/src/spsc-ring.ts +309 -0
@@ -0,0 +1,490 @@
1
+ /**
2
+ * Startup packet building, startup mode management, and compositor lease
3
+ * lifecycle helpers for the CompositorWorker module.
4
+ *
5
+ * @module
6
+ */
7
+ import { RuntimeCoordinator } from '@czap/core';
8
+ import { COMPOSITOR_WORKER_SCRIPT } from './compositor-script.js';
9
+ // ---------------------------------------------------------------------------
10
+ // Module-level cached state
11
+ // ---------------------------------------------------------------------------
12
+ let cachedCompositorWorkerUrl = null;
13
+ let cachedCreateObjectUrl = null;
14
+ let cleanupRegistered = false;
15
+ let standbyCompositorLease = null;
16
+ // ---------------------------------------------------------------------------
17
+ // Timing helpers
18
+ // ---------------------------------------------------------------------------
19
+ /**
20
+ * Return the current high-resolution wall-clock time in nanoseconds.
21
+ *
22
+ * Uses `performance.now()` when available; falls back to `Date.now()`
23
+ * in environments without the performance timeline.
24
+ */
25
+ export function currentTimeNs() {
26
+ const currentTimeMs = typeof performance !== 'undefined' ? performance.now() : Date.now();
27
+ return currentTimeMs * 1e6;
28
+ }
29
+ /**
30
+ * Forward a fine-grained startup-diagnostic duration sample to a
31
+ * telemetry sink (if the sink opts into diagnostic stages).
32
+ *
33
+ * Safe to call when `telemetry` is undefined or does not implement
34
+ * `recordDiagnosticStage` -- the call becomes a no-op.
35
+ */
36
+ export function recordStartupDiagnosticStage(telemetry, stage, durationNs) {
37
+ const recordDiagnosticStage = telemetry?.recordDiagnosticStage;
38
+ recordDiagnosticStage?.(stage, durationNs);
39
+ }
40
+ /**
41
+ * Notify a telemetry sink that the worker acknowledged a resolved-state
42
+ * hydration. Safe to call when the sink does not implement
43
+ * `onResolvedStateSettled`.
44
+ */
45
+ export function notifyResolvedStateSettled(telemetry, states) {
46
+ const onResolvedStateSettled = telemetry?.onResolvedStateSettled;
47
+ onResolvedStateSettled?.(states);
48
+ }
49
+ // ---------------------------------------------------------------------------
50
+ // Startup packet state management
51
+ // ---------------------------------------------------------------------------
52
+ /**
53
+ * Project a set of bootstrap registrations down to the minimal
54
+ * `{ name, states }` shape the runtime coordinator needs to seed its
55
+ * quantizer registry.
56
+ */
57
+ export function registrationsToRuntimeSeed(registrations) {
58
+ return registrations.map((registration) => ({
59
+ name: registration.name,
60
+ states: registration.states,
61
+ }));
62
+ }
63
+ /**
64
+ * Build a fresh {@link StartupPacketState} seeded with an initial
65
+ * bootstrap mode and registration list. Used by the compositor worker to
66
+ * stage messages before flushing them in a single `startup-compute` post.
67
+ */
68
+ export function createStartupPacketState(bootstrapMode, initialRegistrations = []) {
69
+ return {
70
+ bootstrapMode,
71
+ registrations: new Map(initialRegistrations.map((registration) => [registration.name, registration])),
72
+ registrationList: initialRegistrations.length > 0 ? [...initialRegistrations] : [],
73
+ runtimeSeedList: initialRegistrations.length > 0 ? registrationsToRuntimeSeed(initialRegistrations) : [],
74
+ updates: [],
75
+ runtimeSeedDirty: false,
76
+ };
77
+ }
78
+ /**
79
+ * Snapshot a {@link StartupPacketState} into an immutable
80
+ * {@link StartupComputePacket} suitable for `postMessage`.
81
+ */
82
+ export function buildStartupComputePacket(packet) {
83
+ const builtPacket = {
84
+ bootstrapMode: packet.bootstrapMode,
85
+ registrations: getStartupPacketRegistrations(packet),
86
+ updates: packet.updates,
87
+ };
88
+ return builtPacket;
89
+ }
90
+ /**
91
+ * Return the ordered list of registrations in the startup packet,
92
+ * caching the result so repeated reads are O(1).
93
+ */
94
+ export function getStartupPacketRegistrations(packet) {
95
+ if (packet.registrationList !== null) {
96
+ return packet.registrationList;
97
+ }
98
+ packet.registrationList = Array.from(packet.registrations.values());
99
+ return packet.registrationList;
100
+ }
101
+ /**
102
+ * Return the runtime-seed projection of the startup packet's
103
+ * registrations, recomputing on demand if invalidated.
104
+ */
105
+ export function getStartupPacketRuntimeSeed(packet) {
106
+ if (packet.runtimeSeedList !== null && !packet.runtimeSeedDirty) {
107
+ return packet.runtimeSeedList;
108
+ }
109
+ packet.runtimeSeedList = registrationsToRuntimeSeed(getStartupPacketRegistrations(packet));
110
+ packet.runtimeSeedDirty = false;
111
+ return packet.runtimeSeedList;
112
+ }
113
+ /**
114
+ * Return `true` when the given runtime coordinator already has every
115
+ * quantizer referenced by the runtime seed registered (by name).
116
+ *
117
+ * Used to decide whether a pre-warmed lease's runtime can be reused
118
+ * as-is or must be reset before replay.
119
+ */
120
+ export function runtimeMatchesStartupSeed(runtime, runtimeSeed) {
121
+ const registeredNames = runtime.registeredNames();
122
+ if (!sameArray(registeredNames, runtimeSeed.map((registration) => registration.name))) {
123
+ return false;
124
+ }
125
+ for (const registration of runtimeSeed) {
126
+ if (!runtime.hasQuantizer(registration.name)) {
127
+ return false;
128
+ }
129
+ }
130
+ return true;
131
+ }
132
+ /**
133
+ * Insert or overwrite a registration in the startup packet, invalidating
134
+ * derived caches. Pass `invalidateRuntimeSeed: false` when the caller
135
+ * already knows the runtime seed is structurally unchanged (e.g. only
136
+ * initial state or blend weights changed).
137
+ */
138
+ export function setStartupPacketRegistration(packet, registration, invalidateRuntimeSeed = true) {
139
+ packet.registrations.set(registration.name, registration);
140
+ packet.registrationList = null;
141
+ if (invalidateRuntimeSeed) {
142
+ packet.runtimeSeedList = null;
143
+ packet.runtimeSeedDirty = true;
144
+ }
145
+ }
146
+ /**
147
+ * Drop a registration by name from the startup packet and invalidate
148
+ * derived caches.
149
+ */
150
+ export function removeStartupPacketRegistration(packet, name) {
151
+ packet.registrations.delete(name);
152
+ packet.registrationList = null;
153
+ packet.runtimeSeedList = null;
154
+ packet.runtimeSeedDirty = true;
155
+ }
156
+ /**
157
+ * Queue a {@link WorkerUpdate} to be replayed after bootstrap. Order is
158
+ * preserved to match main-thread issue order.
159
+ */
160
+ export function pushStartupPacketUpdate(packet, update) {
161
+ packet.updates.push(update);
162
+ }
163
+ /**
164
+ * Filter the packet's pending update queue in-place. Typically used to
165
+ * drop redundant updates (e.g. newer `set-blend` supersedes older ones).
166
+ */
167
+ export function filterStartupPacketUpdates(packet, keep) {
168
+ if (packet.updates.length === 0) {
169
+ return;
170
+ }
171
+ const filtered = packet.updates.filter(keep);
172
+ if (filtered.length !== packet.updates.length) {
173
+ packet.updates = filtered;
174
+ }
175
+ }
176
+ /**
177
+ * Structural equality check for `Record<string, number>` blend-weight
178
+ * maps. `undefined === undefined` is true; mismatched presence is false.
179
+ */
180
+ export function sameNumericRecord(left, right) {
181
+ if (left === right) {
182
+ return true;
183
+ }
184
+ if (!left || !right) {
185
+ return left === right;
186
+ }
187
+ const leftKeys = Object.keys(left);
188
+ const rightKeys = Object.keys(right);
189
+ if (leftKeys.length !== rightKeys.length) {
190
+ return false;
191
+ }
192
+ for (const key of leftKeys) {
193
+ if (left[key] !== right[key]) {
194
+ return false;
195
+ }
196
+ }
197
+ return true;
198
+ }
199
+ /**
200
+ * Merge an updated initial-state assignment into an existing registration.
201
+ * Also scrubs any queued `evaluate` update targeting the same quantizer,
202
+ * since the new initial state supersedes it.
203
+ */
204
+ export function setStartupPacketInitialState(packet, registration, state) {
205
+ const currentRegistration = packet.registrations.get(registration.name);
206
+ const defaultState = currentRegistration.states[0];
207
+ const nextRegistration = state === defaultState
208
+ ? (() => {
209
+ const { initialState: _initialState, ...withoutInitialState } = currentRegistration;
210
+ return withoutInitialState;
211
+ })()
212
+ : { ...currentRegistration, initialState: state };
213
+ const nextInitialState = 'initialState' in nextRegistration ? nextRegistration.initialState : undefined;
214
+ if (currentRegistration.boundaryId !== nextRegistration.boundaryId ||
215
+ !sameArray(currentRegistration.states, nextRegistration.states) ||
216
+ !sameArray(currentRegistration.thresholds, nextRegistration.thresholds) ||
217
+ currentRegistration.initialState !== nextInitialState ||
218
+ !sameNumericRecord(currentRegistration.blendWeights, nextRegistration.blendWeights)) {
219
+ setStartupPacketRegistration(packet, nextRegistration, false);
220
+ }
221
+ filterStartupPacketUpdates(packet, (update) => !(update.type === 'evaluate' && update.name === registration.name));
222
+ }
223
+ /**
224
+ * Merge updated blend weights for an existing registration. Returns
225
+ * `false` when no registration with that name is present (the update is
226
+ * ignored). Scrubs superseded `set-blend` updates from the queue.
227
+ */
228
+ export function setStartupPacketBlendWeights(packet, name, weights) {
229
+ const registration = packet.registrations.get(name);
230
+ if (!registration) {
231
+ return false;
232
+ }
233
+ if (!sameNumericRecord(registration.blendWeights, weights)) {
234
+ setStartupPacketRegistration(packet, {
235
+ ...registration,
236
+ blendWeights: weights,
237
+ }, false);
238
+ }
239
+ filterStartupPacketUpdates(packet, (update) => !(update.type === 'set-blend' && update.name === name));
240
+ return true;
241
+ }
242
+ /**
243
+ * Remove a registration and every pending update targeting it.
244
+ * Equivalent to undoing `add-quantizer` + any in-flight mutations.
245
+ */
246
+ export function removeStartupPacketEntries(packet, name) {
247
+ removeStartupPacketRegistration(packet, name);
248
+ if (packet.updates.length === 0) {
249
+ return;
250
+ }
251
+ const filtered = packet.updates.filter((update) => update.name !== name);
252
+ if (filtered.length !== packet.updates.length) {
253
+ packet.updates = filtered;
254
+ }
255
+ }
256
+ /**
257
+ * Clear all transient state on a startup packet, leaving only the
258
+ * `bootstrapMode` in place. Used when the lease is recycled and the
259
+ * caller wants to start accumulating fresh messages.
260
+ */
261
+ export function resetStartupPacketTransientState(packet) {
262
+ packet.registrations.clear();
263
+ packet.registrationList = [];
264
+ packet.runtimeSeedList = [];
265
+ packet.updates = [];
266
+ packet.runtimeSeedDirty = false;
267
+ }
268
+ // ---------------------------------------------------------------------------
269
+ // Compositor worker URL and blob management
270
+ // ---------------------------------------------------------------------------
271
+ function revokeCachedCompositorWorkerUrl() {
272
+ if (!cachedCompositorWorkerUrl) {
273
+ return;
274
+ }
275
+ URL.revokeObjectURL(cachedCompositorWorkerUrl);
276
+ cachedCompositorWorkerUrl = null;
277
+ cachedCreateObjectUrl = null;
278
+ }
279
+ function disposeStandbyCompositorLease() {
280
+ standbyCompositorLease?.worker.terminate();
281
+ standbyCompositorLease = null;
282
+ }
283
+ /** Typed helper that extracts globalThis.process without casting at call sites. */
284
+ function getNodeProcess() {
285
+ /* v8 ignore next — `globalThis` is available in every ES2020+ host (Node, browsers,
286
+ workers). The guard is defense-in-depth in case the module is ever loaded in a
287
+ pre-ES2020 sandbox where `globalThis` is missing. */
288
+ if (typeof globalThis === 'undefined' || !('process' in globalThis))
289
+ return null;
290
+ const p = globalThis.process;
291
+ /* v8 ignore next — Node's `process` is always the NodeJS.Process object; this guard
292
+ covers hosts that define `process` as a non-object (e.g. a compatibility shim that
293
+ sets it to `undefined` while still keeping the property slot). */
294
+ if (typeof p !== 'object' || p === null)
295
+ return null;
296
+ return p;
297
+ }
298
+ function registerCachedWorkerCleanup() {
299
+ if (cleanupRegistered) {
300
+ return;
301
+ }
302
+ cleanupRegistered = true;
303
+ const cleanup = () => {
304
+ disposeStandbyCompositorLease();
305
+ revokeCachedCompositorWorkerUrl();
306
+ };
307
+ if (typeof globalThis.addEventListener === 'function') {
308
+ globalThis.addEventListener('pagehide', cleanup, { once: true });
309
+ return;
310
+ }
311
+ const proc = getNodeProcess();
312
+ if (proc !== null && typeof proc.once === 'function')
313
+ proc.once('exit', cleanup);
314
+ }
315
+ function getCompositorWorkerUrl() {
316
+ if (cachedCompositorWorkerUrl && cachedCreateObjectUrl === URL.createObjectURL) {
317
+ return cachedCompositorWorkerUrl;
318
+ }
319
+ if (cachedCompositorWorkerUrl) {
320
+ revokeCachedCompositorWorkerUrl();
321
+ }
322
+ cachedCompositorWorkerUrl = URL.createObjectURL(new Blob([COMPOSITOR_WORKER_SCRIPT], { type: 'application/javascript' }));
323
+ cachedCreateObjectUrl = URL.createObjectURL;
324
+ registerCachedWorkerCleanup();
325
+ return cachedCompositorWorkerUrl;
326
+ }
327
+ function createRawCompositorWorker() {
328
+ const url = getCompositorWorkerUrl();
329
+ return new Worker(url, { type: 'classic', name: 'czap-compositor' });
330
+ }
331
+ function createRuntimeCoordinator(capacity) {
332
+ return RuntimeCoordinator.create({
333
+ capacity,
334
+ name: 'czap-worker-runtime',
335
+ });
336
+ }
337
+ // ---------------------------------------------------------------------------
338
+ // Compositor lease lifecycle
339
+ // ---------------------------------------------------------------------------
340
+ /**
341
+ * Claim a compositor lease: either hand back the standby pre-warmed
342
+ * worker (if one is parked and matches the requested capacity) or mint a
343
+ * fresh `Worker` + {@link RuntimeCoordinator}. Emits
344
+ * `claim-or-create` and `coordinator-reset-or-create` stage samples to
345
+ * the optional telemetry sink.
346
+ *
347
+ * @param capacity - Runtime coordinator capacity to request.
348
+ * @param startupTelemetry - Optional sink for stage timings.
349
+ * @returns The worker, its coordinator, and any bootstrap snapshot the
350
+ * parked lease brought with it.
351
+ */
352
+ export function claimCompositorLease(capacity, startupTelemetry) {
353
+ if (standbyCompositorLease &&
354
+ (standbyCompositorLease.workerConstructor !== Worker ||
355
+ standbyCompositorLease.createObjectUrl !== URL.createObjectURL ||
356
+ standbyCompositorLease.capacity !== capacity)) {
357
+ disposeStandbyCompositorLease();
358
+ }
359
+ const claimStartNs = currentTimeNs();
360
+ const claimedLease = standbyCompositorLease;
361
+ standbyCompositorLease = null;
362
+ const worker = claimedLease?.worker ?? createRawCompositorWorker();
363
+ startupTelemetry?.recordStage('claim-or-create', currentTimeNs() - claimStartNs);
364
+ const coordinatorStartNs = currentTimeNs();
365
+ const runtime = claimedLease?.runtime ?? createRuntimeCoordinator(capacity);
366
+ const bootstrapSnapshot = claimedLease?.bootstrapSnapshot ?? [];
367
+ if (claimedLease) {
368
+ const runtimeResetStartNs = currentTimeNs();
369
+ runtime.reset();
370
+ recordStartupDiagnosticStage(startupTelemetry, 'coordinator-reset-or-create:runtime-reset-reuse', currentTimeNs() - runtimeResetStartNs);
371
+ }
372
+ startupTelemetry?.recordStage('coordinator-reset-or-create', currentTimeNs() - coordinatorStartNs);
373
+ return {
374
+ worker,
375
+ runtime,
376
+ bootstrapSnapshot,
377
+ };
378
+ }
379
+ /**
380
+ * Park a compositor lease in the module-level standby slot so a future
381
+ * {@link claimCompositorLease} can reuse it. If the standby slot is
382
+ * already occupied, the incoming lease is disposed (`dispose` message +
383
+ * `terminate()`) instead.
384
+ */
385
+ export function parkOrDisposeCompositorLease(lease) {
386
+ if (!standbyCompositorLease &&
387
+ typeof Worker !== 'undefined' &&
388
+ Worker === lease.worker.constructor &&
389
+ typeof URL.createObjectURL === 'function' &&
390
+ URL.createObjectURL === cachedCreateObjectUrl) {
391
+ standbyCompositorLease = {
392
+ ...lease,
393
+ workerConstructor: Worker,
394
+ createObjectUrl: URL.createObjectURL,
395
+ };
396
+ return;
397
+ }
398
+ _send(lease.worker, { type: 'dispose' });
399
+ lease.worker.terminate();
400
+ }
401
+ // ---------------------------------------------------------------------------
402
+ // Utility helpers
403
+ // ---------------------------------------------------------------------------
404
+ /**
405
+ * Internal `postMessage` helper with an explicit transfer-list default.
406
+ * Named with a leading underscore to signal that host code should use
407
+ * the typed methods on {@link CompositorWorkerShape} instead.
408
+ */
409
+ export function _send(worker, msg, transfer) {
410
+ worker.postMessage(msg, transfer ?? []);
411
+ }
412
+ /**
413
+ * Convert a registration's thresholds to a Float64Array for transfer.
414
+ * Returns a new registration object with the typed array and the ArrayBuffer to transfer.
415
+ */
416
+ export function prepareRegistrationForTransfer(registration) {
417
+ const f64 = new Float64Array(registration.thresholds);
418
+ return {
419
+ registration: { ...registration, thresholds: f64 },
420
+ buffer: f64.buffer,
421
+ };
422
+ }
423
+ /**
424
+ * Prepare a list of registrations for transfer, returning new registrations
425
+ * and the collected ArrayBuffers to include in the transfer list.
426
+ */
427
+ export function prepareRegistrationsForTransfer(registrations) {
428
+ const buffers = [];
429
+ const prepared = registrations.map((reg) => {
430
+ const { registration, buffer } = prepareRegistrationForTransfer(reg);
431
+ buffers.push(buffer);
432
+ return registration;
433
+ });
434
+ return { registrations: prepared, buffers };
435
+ }
436
+ /**
437
+ * Structural equality for two `ArrayLike` sequences (same length, same
438
+ * `===` elements at every index). Works for both plain arrays and typed
439
+ * arrays.
440
+ */
441
+ export function sameArray(left, right) {
442
+ if (left.length !== right.length) {
443
+ return false;
444
+ }
445
+ for (let index = 0; index < left.length; index++) {
446
+ if (left[index] !== right[index]) {
447
+ return false;
448
+ }
449
+ }
450
+ return true;
451
+ }
452
+ /**
453
+ * Return `true` when two bootstrap registrations share the same
454
+ * `boundaryId`, state list, and threshold list. Used to elide redundant
455
+ * `add-quantizer` messages during bootstrap coalescing.
456
+ */
457
+ export function sameBootstrapRegistration(left, right) {
458
+ if (!left) {
459
+ return false;
460
+ }
461
+ return (left.boundaryId === right.boundaryId &&
462
+ sameArray(left.states, right.states) &&
463
+ sameArray(left.thresholds, right.thresholds));
464
+ }
465
+ /**
466
+ * Quantize a numeric value against a registration's thresholds and
467
+ * return the corresponding state label. Falls back to `states[0]` if the
468
+ * value lies below every threshold.
469
+ */
470
+ export function evaluateRegistrationState(registration, value) {
471
+ for (let index = registration.thresholds.length - 1; index >= 0; index--) {
472
+ if (value >= registration.thresholds[index]) {
473
+ return registration.states[index] ?? registration.states[0];
474
+ }
475
+ }
476
+ return registration.states[0];
477
+ }
478
+ /**
479
+ * Re-shape a {@link ResolvedStateAckPayload} into the flat
480
+ * {@link ResolvedStateEntry} form that the main-thread state store
481
+ * consumes. Propagates `ack.generation` into each entry.
482
+ */
483
+ export function toResolvedStateEntriesFromAck(ack) {
484
+ return ack.states.map((state) => ({
485
+ name: state.name,
486
+ state: state.state,
487
+ generation: ack.generation,
488
+ }));
489
+ }
490
+ //# sourceMappingURL=compositor-startup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositor-startup.js","sourceRoot":"","sources":["../src/compositor-startup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAehD,OAAO,EAAE,wBAAwB,EA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BAA6B,CAAC,GAA4B;IACxE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAChC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Type definitions for the CompositorWorker module.
3
+ *
4
+ * @module
5
+ */
6
+ import type { RuntimeCoordinator, CompositeState } from '@czap/core';
7
+ import type { WorkerUpdate, BootstrapQuantizerRegistration, StartupComputePacket, ResolvedStateEntry } from './messages.js';
8
+ /**
9
+ * A `CompositeState` snapshot emitted by the compositor worker, optionally
10
+ * annotated with per-quantizer generation counters. The generation map
11
+ * enables receivers to drop stale out-of-order messages.
12
+ */
13
+ export type CompositorWorkerState = CompositeState & {
14
+ readonly resolvedStateGenerations?: Record<string, number>;
15
+ };
16
+ /**
17
+ * Acknowledgement payload emitted by the worker after it applies a
18
+ * resolved-state update from the main thread.
19
+ */
20
+ export interface ResolvedStateAckPayload {
21
+ /** Generation counter the worker acknowledges. */
22
+ readonly generation: number;
23
+ /** The state transitions the worker actually observed. */
24
+ readonly states: readonly {
25
+ readonly name: string;
26
+ readonly state: string;
27
+ }[];
28
+ /** Whether non-discrete outputs (blend, CSS, etc.) changed in this round. */
29
+ readonly additionalOutputsChanged: boolean;
30
+ }
31
+ /**
32
+ * Host-facing surface of a compositor worker. Returned by
33
+ * {@link CompositorWorker} as the public control/observation API. Owns
34
+ * the underlying `Worker` -- call {@link CompositorWorkerShape.dispose}
35
+ * to terminate and release resources.
36
+ */
37
+ export interface CompositorWorkerShape {
38
+ /** The underlying Worker instance. */
39
+ readonly worker: Worker;
40
+ /** Shared runtime coordination surface reflecting host-side worker state. */
41
+ readonly runtime: RuntimeCoordinator.Shape;
42
+ /** Register a quantizer in the worker. */
43
+ addQuantizer(name: string, boundary: {
44
+ readonly id: string;
45
+ readonly states: readonly string[];
46
+ readonly thresholds: readonly number[];
47
+ }): void;
48
+ /** Remove a quantizer from the worker. */
49
+ removeQuantizer(name: string): void;
50
+ /** Evaluate a quantizer with a numeric value (threshold-based). */
51
+ evaluate(name: string, value: number): void;
52
+ /** Override blend weights for a quantizer. */
53
+ setBlendWeights(name: string, weights: Record<string, number>): void;
54
+ /** Seed resolved quantizer state into the worker without raw threshold evaluation. */
55
+ bootstrapResolvedState(states: readonly ResolvedStateEntry[]): void;
56
+ /** Mirror resolved quantizer state updates into the worker without raw threshold evaluation. */
57
+ applyResolvedState(states: readonly ResolvedStateEntry[]): void;
58
+ /** Request the worker to compute and return a CompositeState. */
59
+ requestCompute(): void;
60
+ /** Subscribe to state updates from the worker. Returns an unsubscribe function. */
61
+ onState(callback: (state: CompositorWorkerState) => void): () => void;
62
+ /** Subscribe to resolved-state acknowledgement updates. Returns an unsubscribe function. */
63
+ onResolvedStateAck(callback: (ack: ResolvedStateAckPayload) => void): () => void;
64
+ /** Subscribe to metrics updates. Returns an unsubscribe function. */
65
+ onMetrics(callback: (fps: number, budgetUsed: number) => void): () => void;
66
+ /** Terminate the worker and clean up resources. */
67
+ dispose(): void;
68
+ }
69
+ /**
70
+ * Named stages of the compositor-worker startup handshake. Used for
71
+ * structured telemetry so hosts can instrument how long each phase took.
72
+ */
73
+ export type CompositorWorkerStartupStage = 'claim-or-create' | 'coordinator-reset-or-create' | 'listener-bind';
74
+ /**
75
+ * Pluggable telemetry sink invoked during compositor-worker startup.
76
+ * `recordStage` is called once per stage with an elapsed-time sample;
77
+ * `onResolvedStateSettled` (optional) fires once the worker confirms a
78
+ * resolved-state hydration.
79
+ */
80
+ export interface CompositorWorkerStartupTelemetry {
81
+ /** Record how long a startup stage took. `durationNs` is in nanoseconds. */
82
+ recordStage(stage: CompositorWorkerStartupStage, durationNs: number): void;
83
+ /** Fired when the worker acknowledges the resolved-state bootstrap. */
84
+ onResolvedStateSettled?(states: readonly ResolvedStateEntry[]): void;
85
+ }
86
+ /**
87
+ * Finer-grained diagnostic stages emitted during startup and compute
88
+ * dispatch. Useful for pinpointing message-queue / callback latency in
89
+ * profiling builds.
90
+ */
91
+ export type CompositorWorkerStartupDiagnosticStage = 'coordinator-reset-or-create:runtime-reset-reuse' | 'request-compute:packet-finalize' | 'request-compute:dispatch-send' | 'request-compute:post-send-bookkeeping' | 'state-delivery:message-receipt' | 'state-delivery:callback-queue-turn' | 'state-delivery:host-callback-delivery';
92
+ /**
93
+ * A pre-warmed compositor worker held in a standby pool, ready to be
94
+ * claimed by a new host without paying the Worker+Blob-URL boot cost.
95
+ *
96
+ * The lease exposes both the raw `Worker` and its associated coordinator,
97
+ * plus the constructors used to mint more workers if the pool is empty.
98
+ */
99
+ export interface StandbyCompositorLease {
100
+ /** The warm Worker instance. */
101
+ readonly worker: Worker;
102
+ /** Shared runtime coordinator already attached to the worker. */
103
+ readonly runtime: RuntimeCoordinator.Shape;
104
+ /** Pooled pool capacity advertised by the lease. */
105
+ readonly capacity: number;
106
+ /** Worker constructor used to mint peers. */
107
+ readonly workerConstructor: typeof Worker;
108
+ /** Blob URL factory used to mint worker sources. */
109
+ readonly createObjectUrl: typeof URL.createObjectURL;
110
+ /** Previously-bootstrapped registrations the lease already knows about. */
111
+ readonly bootstrapSnapshot: readonly BootstrapQuantizerRegistration[];
112
+ }
113
+ /**
114
+ * Mutable scratch state used while coalescing startup messages into a
115
+ * single {@link StartupComputePacket}. Internal to the startup pipeline;
116
+ * exported for tests and host-side diagnostic inspectors.
117
+ */
118
+ export interface StartupPacketState {
119
+ /** The bootstrap mode the packet will advertise. */
120
+ bootstrapMode: StartupComputePacket['bootstrapMode'];
121
+ /** Deduplicated registrations keyed by quantizer name. */
122
+ registrations: Map<string, BootstrapQuantizerRegistration>;
123
+ /** Cached ordered registration list (invalidated when the map mutates). */
124
+ registrationList: readonly BootstrapQuantizerRegistration[] | null;
125
+ /** Cached runtime seed list derived from registrations. */
126
+ runtimeSeedList: readonly {
127
+ readonly name: string;
128
+ readonly states: readonly string[];
129
+ }[] | null;
130
+ /** Pending updates to replay after bootstrap. */
131
+ updates: WorkerUpdate[];
132
+ /** Whether `runtimeSeedList` needs to be recomputed. */
133
+ runtimeSeedDirty: boolean;
134
+ }
135
+ //# sourceMappingURL=compositor-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositor-types.d.ts","sourceRoot":"","sources":["../src/compositor-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,KAAK,EACV,YAAY,EACZ,8BAA8B,EAC9B,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAMvB;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG;IACnD,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5D,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,kDAAkD;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,SAAS;QACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,EAAE,CAAC;IACJ,6EAA6E;IAC7E,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAC;CAC5C;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAE3C,0CAA0C;IAC1C,YAAY,CACV,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE;QACR,QAAQ,CAAC,EA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EAAE,CAAC;IACxB,wDAAwD;IACxD,gBAAgB,EAAE,OAAO,CAAC;CAC3B"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Type definitions for the CompositorWorker module.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=compositor-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositor-types.js","sourceRoot":"","sources":["../src/compositor-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}