@almadar/ui 2.13.1 → 2.13.3

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.
@@ -1,15 +1,15 @@
1
- import '../chunk-X2ZDE63F.js';
1
+ import '../chunk-PERGHHON.js';
2
2
  import '../chunk-N7MVUW4R.js';
3
3
  import { registerTrait, unregisterTrait, updateTraitState } from '../chunk-42YQ6JVR.js';
4
4
  import '../chunk-3HJHHULT.js';
5
- import { useFetchedDataContext } from '../chunk-XF7GGUTH.js';
6
- import '../chunk-YYCP5CD7.js';
7
- import '../chunk-YLKXEXBP.js';
8
- import '../chunk-3CP74CBL.js';
5
+ import { useFetchedDataContext } from '../chunk-UNDQO6DL.js';
6
+ import '../chunk-MSLMORZK.js';
7
+ import '../chunk-DKQN5FVU.js';
8
+ import '../chunk-Y7IHEYYE.js';
9
9
  import { useEventBus } from '../chunk-YXZM3WCF.js';
10
10
  import '../chunk-3JGAROCW.js';
11
- import '../chunk-2XXSUIOK.js';
12
11
  import { recordTransition } from '../chunk-WCTZ7WZX.js';
12
+ import '../chunk-2XXSUIOK.js';
13
13
  import '../chunk-K2D5D3WK.js';
14
14
  import '../chunk-PKBMQBKP.js';
15
15
  import { createContext, useMemo, useContext, useState, useRef, useEffect, useCallback } from 'react';
@@ -107,6 +107,8 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
107
107
  const [traitStates, setTraitStates] = useState(() => {
108
108
  return manager.getAllStates();
109
109
  });
110
+ const eventQueueRef = useRef([]);
111
+ const processingRef = useRef(false);
110
112
  const traitBindingsRef = useRef(traitBindings);
111
113
  const managerRef = useRef(manager);
112
114
  const slotsActionsRef = useRef(slotsActions);
@@ -311,7 +313,7 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
311
313
  for (const id of intervals) clearInterval(id);
312
314
  };
313
315
  }, [traitBindings, runTickEffects]);
314
- const processEvent = useCallback((eventKey, payload) => {
316
+ const processEventQueued = useCallback(async (eventKey, payload) => {
315
317
  const normalizedEvent = normalizeEventKey(eventKey);
316
318
  const bindings = traitBindingsRef.current;
317
319
  const currentManager = managerRef.current;
@@ -443,7 +445,8 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
443
445
  entityId
444
446
  };
445
447
  const executor = new EffectExecutor({ handlers, bindings: bindingCtx, context: effectContext });
446
- executor.executeAll(result.effects).then(() => {
448
+ try {
449
+ await executor.executeAll(result.effects);
447
450
  console.log(
448
451
  "[TraitStateMachine] After executeAll, pendingSlots:",
449
452
  Object.fromEntries(pendingSlots.entries())
@@ -464,14 +467,14 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
464
467
  fetchedDataContext.setData({ [linkedEntity]: updated });
465
468
  }
466
469
  }
467
- }).catch((error) => {
470
+ } catch (error) {
468
471
  console.error(
469
472
  "[TraitStateMachine] Effect execution error:",
470
473
  error,
471
474
  "| effects:",
472
475
  JSON.stringify(result.effects)
473
476
  );
474
- });
477
+ }
475
478
  } else if (!result.executed) {
476
479
  if (result.guardResult === false) {
477
480
  console.log(
@@ -533,9 +536,28 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
533
536
  onEventProcessed(normalizedEvent, payload);
534
537
  }
535
538
  }, [entities, fetchedDataContext, eventBus]);
539
+ const drainEventQueue = useCallback(async () => {
540
+ if (processingRef.current) return;
541
+ processingRef.current = true;
542
+ try {
543
+ while (eventQueueRef.current.length > 0) {
544
+ const entry = eventQueueRef.current.shift();
545
+ await processEventQueued(entry.eventKey, entry.payload);
546
+ }
547
+ } finally {
548
+ processingRef.current = false;
549
+ }
550
+ }, [processEventQueued]);
551
+ const enqueueAndDrain = useCallback((eventKey, payload) => {
552
+ eventQueueRef.current.push({ eventKey, payload });
553
+ void drainEventQueue();
554
+ }, [drainEventQueue]);
555
+ useCallback((eventKey, payload) => {
556
+ enqueueAndDrain(eventKey, payload);
557
+ }, [enqueueAndDrain]);
536
558
  const sendEvent = useCallback((eventKey, payload) => {
537
- processEvent(eventKey, payload);
538
- }, [processEvent]);
559
+ enqueueAndDrain(eventKey, payload);
560
+ }, [enqueueAndDrain]);
539
561
  const getTraitState = useCallback((traitName) => {
540
562
  return managerRef.current.getState(traitName);
541
563
  }, []);
@@ -561,7 +583,7 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
561
583
  }
562
584
  const unsub = eventBus.on(`UI:${eventKey}`, (event) => {
563
585
  console.log("[TraitStateMachine] Received event:", `UI:${eventKey}`, event);
564
- processEvent(eventKey, event.payload);
586
+ enqueueAndDrain(eventKey, event.payload);
565
587
  });
566
588
  unsubscribes.push(unsub);
567
589
  }
@@ -570,7 +592,7 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
570
592
  unsub();
571
593
  }
572
594
  };
573
- }, [traitBindings, eventBus, processEvent]);
595
+ }, [traitBindings, eventBus, enqueueAndDrain]);
574
596
  return {
575
597
  traitStates,
576
598
  sendEvent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "2.13.1",
3
+ "version": "2.13.3",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "main": "./dist/components/index.js",
@@ -1,149 +1,5 @@
1
1
  import { ClassValue } from 'clsx';
2
2
 
3
- /**
4
- * Utility function to merge Tailwind CSS classes
5
- * Combines clsx for conditional classes with tailwind-merge to handle conflicts
6
- */
7
- declare function cn(...inputs: ClassValue[]): string;
8
-
9
- /**
10
- * Verification Registry - Tracks runtime verification checks and transition traces
11
- *
12
- * Provides:
13
- * 1. A checklist of pass/fail checks (INIT has fetch, bridge connected, etc.)
14
- * 2. A full transition timeline with effect execution results
15
- * 3. ServerBridge health snapshot
16
- * 4. window.__orbitalVerification for Playwright/automation
17
- *
18
- * @packageDocumentation
19
- */
20
- type CheckStatus = "pass" | "fail" | "pending" | "warn";
21
- interface VerificationCheck {
22
- id: string;
23
- label: string;
24
- status: CheckStatus;
25
- details?: string;
26
- /** Timestamp when status last changed */
27
- updatedAt: number;
28
- }
29
- interface EffectTrace {
30
- type: string;
31
- args: unknown[];
32
- status: "executed" | "failed" | "skipped";
33
- error?: string;
34
- durationMs?: number;
35
- }
36
- interface TransitionTrace {
37
- id: string;
38
- traitName: string;
39
- from: string;
40
- to: string;
41
- event: string;
42
- guardExpression?: string;
43
- guardResult?: boolean;
44
- effects: EffectTrace[];
45
- timestamp: number;
46
- }
47
- interface BridgeHealth {
48
- connected: boolean;
49
- eventsForwarded: number;
50
- eventsReceived: number;
51
- lastError?: string;
52
- lastHeartbeat: number;
53
- }
54
- interface VerificationSummary {
55
- totalChecks: number;
56
- passed: number;
57
- failed: number;
58
- warnings: number;
59
- pending: number;
60
- }
61
- interface VerificationSnapshot {
62
- checks: VerificationCheck[];
63
- transitions: TransitionTrace[];
64
- bridge: BridgeHealth | null;
65
- summary: VerificationSummary;
66
- }
67
- type ChangeListener = () => void;
68
- declare function registerCheck(id: string, label: string, status?: CheckStatus, details?: string): void;
69
- declare function updateCheck(id: string, status: CheckStatus, details?: string): void;
70
- declare function getAllChecks(): VerificationCheck[];
71
- declare function recordTransition(trace: Omit<TransitionTrace, "id">): void;
72
- declare function getTransitions(): TransitionTrace[];
73
- declare function getTransitionsForTrait(traitName: string): TransitionTrace[];
74
- declare function updateBridgeHealth(health: BridgeHealth): void;
75
- declare function getBridgeHealth(): BridgeHealth | null;
76
- declare function getSummary(): VerificationSummary;
77
- declare function getSnapshot(): VerificationSnapshot;
78
- declare function subscribeToVerification(listener: ChangeListener): () => void;
79
- /** Asset load status for canvas verification */
80
- type AssetLoadStatus = "loaded" | "failed" | "pending";
81
- /** Event bus log entry for verification */
82
- interface EventLogEntry {
83
- type: string;
84
- payload?: Record<string, unknown>;
85
- timestamp: number;
86
- }
87
- /** Exposed on window for Playwright to query */
88
- interface OrbitalVerificationAPI {
89
- getSnapshot: () => VerificationSnapshot;
90
- getChecks: () => VerificationCheck[];
91
- getTransitions: () => TransitionTrace[];
92
- getBridge: () => BridgeHealth | null;
93
- getSummary: () => VerificationSummary;
94
- /** Wait for a specific event to be processed */
95
- waitForTransition: (event: string, timeoutMs?: number) => Promise<TransitionTrace | null>;
96
- /** Send an event into the runtime (requires eventBus binding) */
97
- sendEvent?: (event: string, payload?: Record<string, unknown>) => void;
98
- /** Get current trait state */
99
- getTraitState?: (traitName: string) => string | undefined;
100
- /** Capture a canvas frame as PNG data URL. Registered by game organisms. */
101
- captureFrame?: () => string | null;
102
- /** Asset load status map. Registered by game organisms. */
103
- assetStatus?: Record<string, AssetLoadStatus>;
104
- /** Event bus log. Records all emit() calls for verification. */
105
- eventLog?: EventLogEntry[];
106
- /** Clear the event log. */
107
- clearEventLog?: () => void;
108
- }
109
- declare global {
110
- interface Window {
111
- __orbitalVerification?: OrbitalVerificationAPI;
112
- }
113
- }
114
- /**
115
- * Wait for a transition matching the given event to appear.
116
- * Returns the trace or null on timeout.
117
- */
118
- declare function waitForTransition(event: string, timeoutMs?: number): Promise<TransitionTrace | null>;
119
- /**
120
- * Bind the EventBus so automation can send events and log emissions.
121
- * Call this during app initialization.
122
- */
123
- declare function bindEventBus(eventBus: {
124
- emit: (type: string, payload?: Record<string, unknown>) => void;
125
- onAny?: (listener: (event: {
126
- type: string;
127
- payload?: Record<string, unknown>;
128
- }) => void) => () => void;
129
- }): void;
130
- /**
131
- * Bind a trait state getter so automation can query current states.
132
- */
133
- declare function bindTraitStateGetter(getter: (traitName: string) => string | undefined): void;
134
- /**
135
- * Register a canvas frame capture function.
136
- * Called by game organisms (IsometricCanvas, PlatformerCanvas, SimulationCanvas)
137
- * so the verifier can snapshot canvas content at checkpoints.
138
- */
139
- declare function bindCanvasCapture(captureFn: () => string | null): void;
140
- /**
141
- * Update asset load status for canvas verification.
142
- * Game organisms call this when images load or fail.
143
- */
144
- declare function updateAssetStatus(url: string, status: AssetLoadStatus): void;
145
- declare function clearVerification(): void;
146
-
147
3
  /**
148
4
  * Orbital State Machine Visualizer
149
5
  *
@@ -329,4 +185,148 @@ declare function parseMarkdownWithCodeBlocks(content: string | undefined | null)
329
185
  */
330
186
  declare function parseContentSegments(content: string | undefined | null): ContentSegment[];
331
187
 
188
+ /**
189
+ * Verification Registry - Tracks runtime verification checks and transition traces
190
+ *
191
+ * Provides:
192
+ * 1. A checklist of pass/fail checks (INIT has fetch, bridge connected, etc.)
193
+ * 2. A full transition timeline with effect execution results
194
+ * 3. ServerBridge health snapshot
195
+ * 4. window.__orbitalVerification for Playwright/automation
196
+ *
197
+ * @packageDocumentation
198
+ */
199
+ type CheckStatus = "pass" | "fail" | "pending" | "warn";
200
+ interface VerificationCheck {
201
+ id: string;
202
+ label: string;
203
+ status: CheckStatus;
204
+ details?: string;
205
+ /** Timestamp when status last changed */
206
+ updatedAt: number;
207
+ }
208
+ interface EffectTrace {
209
+ type: string;
210
+ args: unknown[];
211
+ status: "executed" | "failed" | "skipped";
212
+ error?: string;
213
+ durationMs?: number;
214
+ }
215
+ interface TransitionTrace {
216
+ id: string;
217
+ traitName: string;
218
+ from: string;
219
+ to: string;
220
+ event: string;
221
+ guardExpression?: string;
222
+ guardResult?: boolean;
223
+ effects: EffectTrace[];
224
+ timestamp: number;
225
+ }
226
+ interface BridgeHealth {
227
+ connected: boolean;
228
+ eventsForwarded: number;
229
+ eventsReceived: number;
230
+ lastError?: string;
231
+ lastHeartbeat: number;
232
+ }
233
+ interface VerificationSummary {
234
+ totalChecks: number;
235
+ passed: number;
236
+ failed: number;
237
+ warnings: number;
238
+ pending: number;
239
+ }
240
+ interface VerificationSnapshot {
241
+ checks: VerificationCheck[];
242
+ transitions: TransitionTrace[];
243
+ bridge: BridgeHealth | null;
244
+ summary: VerificationSummary;
245
+ }
246
+ type ChangeListener = () => void;
247
+ declare function registerCheck(id: string, label: string, status?: CheckStatus, details?: string): void;
248
+ declare function updateCheck(id: string, status: CheckStatus, details?: string): void;
249
+ declare function getAllChecks(): VerificationCheck[];
250
+ declare function recordTransition(trace: Omit<TransitionTrace, "id">): void;
251
+ declare function getTransitions(): TransitionTrace[];
252
+ declare function getTransitionsForTrait(traitName: string): TransitionTrace[];
253
+ declare function updateBridgeHealth(health: BridgeHealth): void;
254
+ declare function getBridgeHealth(): BridgeHealth | null;
255
+ declare function getSummary(): VerificationSummary;
256
+ declare function getSnapshot(): VerificationSnapshot;
257
+ declare function subscribeToVerification(listener: ChangeListener): () => void;
258
+ /** Asset load status for canvas verification */
259
+ type AssetLoadStatus = "loaded" | "failed" | "pending";
260
+ /** Event bus log entry for verification */
261
+ interface EventLogEntry {
262
+ type: string;
263
+ payload?: Record<string, unknown>;
264
+ timestamp: number;
265
+ }
266
+ /** Exposed on window for Playwright to query */
267
+ interface OrbitalVerificationAPI {
268
+ getSnapshot: () => VerificationSnapshot;
269
+ getChecks: () => VerificationCheck[];
270
+ getTransitions: () => TransitionTrace[];
271
+ getBridge: () => BridgeHealth | null;
272
+ getSummary: () => VerificationSummary;
273
+ /** Wait for a specific event to be processed */
274
+ waitForTransition: (event: string, timeoutMs?: number) => Promise<TransitionTrace | null>;
275
+ /** Send an event into the runtime (requires eventBus binding) */
276
+ sendEvent?: (event: string, payload?: Record<string, unknown>) => void;
277
+ /** Get current trait state */
278
+ getTraitState?: (traitName: string) => string | undefined;
279
+ /** Capture a canvas frame as PNG data URL. Registered by game organisms. */
280
+ captureFrame?: () => string | null;
281
+ /** Asset load status map. Registered by game organisms. */
282
+ assetStatus?: Record<string, AssetLoadStatus>;
283
+ /** Event bus log. Records all emit() calls for verification. */
284
+ eventLog?: EventLogEntry[];
285
+ /** Clear the event log. */
286
+ clearEventLog?: () => void;
287
+ }
288
+ declare global {
289
+ interface Window {
290
+ __orbitalVerification?: OrbitalVerificationAPI;
291
+ }
292
+ }
293
+ /**
294
+ * Wait for a transition matching the given event to appear.
295
+ * Returns the trace or null on timeout.
296
+ */
297
+ declare function waitForTransition(event: string, timeoutMs?: number): Promise<TransitionTrace | null>;
298
+ /**
299
+ * Bind the EventBus so automation can send events and log emissions.
300
+ * Call this during app initialization.
301
+ */
302
+ declare function bindEventBus(eventBus: {
303
+ emit: (type: string, payload?: Record<string, unknown>) => void;
304
+ onAny?: (listener: (event: {
305
+ type: string;
306
+ payload?: Record<string, unknown>;
307
+ }) => void) => () => void;
308
+ }): void;
309
+ /**
310
+ * Bind a trait state getter so automation can query current states.
311
+ */
312
+ declare function bindTraitStateGetter(getter: (traitName: string) => string | undefined): void;
313
+ /**
314
+ * Register a canvas frame capture function.
315
+ * Called by game organisms (IsometricCanvas, PlatformerCanvas, SimulationCanvas)
316
+ * so the verifier can snapshot canvas content at checkpoints.
317
+ */
318
+ declare function bindCanvasCapture(captureFn: () => string | null): void;
319
+ /**
320
+ * Update asset load status for canvas verification.
321
+ * Game organisms call this when images load or fail.
322
+ */
323
+ declare function updateAssetStatus(url: string, status: AssetLoadStatus): void;
324
+ declare function clearVerification(): void;
325
+
326
+ /**
327
+ * Utility function to merge Tailwind CSS classes
328
+ * Combines clsx for conditional classes with tailwind-merge to handle conflicts
329
+ */
330
+ declare function cn(...inputs: ClassValue[]): string;
331
+
332
332
  export { type AssetLoadStatus as A, type BridgeHealth as B, type CheckStatus as C, DEFAULT_CONFIG as D, type EffectTrace as E, getSummary as F, getTransitions as G, getTransitionsForTrait as H, parseContentSegments as I, parseMarkdownWithCodeBlocks as J, recordTransition as K, registerCheck as L, renderStateMachineToDomData as M, renderStateMachineToSvg as N, subscribeToVerification as O, updateAssetStatus as P, updateBridgeHealth as Q, type RenderOptions as R, type StateDefinition as S, type TransitionDefinition as T, updateCheck as U, type VerificationCheck as V, waitForTransition as W, type ContentSegment as a, type DomEntityBox as b, type DomLayoutData as c, type DomOutputsBox as d, type DomStateNode as e, type DomTransitionLabel as f, type DomTransitionPath as g, type EntityDefinition as h, type EventLogEntry as i, type StateMachineDefinition as j, type TransitionTrace as k, type VerificationSnapshot as l, type VerificationSummary as m, type VisualizerConfig as n, bindCanvasCapture as o, bindEventBus as p, bindTraitStateGetter as q, clearVerification as r, cn as s, extractOutputsFromTransitions as t, extractStateMachine as u, formatGuard as v, getAllChecks as w, getBridgeHealth as x, getEffectSummary as y, getSnapshot as z };