@almadar/ui 2.46.1 → 2.47.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.
@@ -4,6 +4,7 @@ var React4 = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var LucideIcons = require('lucide-react');
6
6
 
7
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
9
 
9
10
  function _interopNamespace(e) {
@@ -2506,9 +2507,70 @@ var twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
2506
2507
  function cn(...inputs) {
2507
2508
  return twMerge(clsx(inputs));
2508
2509
  }
2510
+
2511
+ // lib/logger.ts
2512
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
2513
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
2514
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
2515
+ function getViteEnv(key) {
2516
+ try {
2517
+ const meta = ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) });
2518
+ return meta?.env?.[key];
2519
+ } catch {
2520
+ return void 0;
2521
+ }
2522
+ }
2523
+ function envGet(key, viteKey) {
2524
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
2525
+ }
2526
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
2527
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
2528
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
2529
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
2530
+ function matchesNamespace(namespace) {
2531
+ if (DEBUG_FILTER.length === 0) return true;
2532
+ return DEBUG_FILTER.some((pattern) => {
2533
+ if (pattern === "*" || pattern === "almadar:*") return true;
2534
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
2535
+ return namespace === pattern;
2536
+ });
2537
+ }
2538
+ function createLogger(namespace) {
2539
+ const nsAllowed = matchesNamespace(namespace);
2540
+ const log2 = (level, message, data, correlationId) => {
2541
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
2542
+ if (level === "DEBUG" && !nsAllowed) return;
2543
+ const prefix = `[${namespace}]`;
2544
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
2545
+ switch (level) {
2546
+ case "DEBUG":
2547
+ console.debug(prefix, message, logData ?? "");
2548
+ break;
2549
+ case "INFO":
2550
+ console.info(prefix, message, logData ?? "");
2551
+ break;
2552
+ case "WARN":
2553
+ console.warn(prefix, message, logData ?? "");
2554
+ break;
2555
+ case "ERROR":
2556
+ console.error(prefix, message, logData ?? "");
2557
+ break;
2558
+ }
2559
+ };
2560
+ return {
2561
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
2562
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
2563
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
2564
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
2565
+ };
2566
+ }
2567
+ createLogger("almadar:eventbus");
2568
+ createLogger("almadar:eventbus:subscribe");
2509
2569
  var EventBusContext = React4.createContext(null);
2510
2570
 
2511
2571
  // hooks/useEventBus.ts
2572
+ var log = createLogger("almadar:eventbus");
2573
+ var subLog2 = createLogger("almadar:eventbus:subscribe");
2512
2574
  function getGlobalEventBus() {
2513
2575
  if (typeof window !== "undefined") {
2514
2576
  return window.__kflowEventBus ?? null;
@@ -2525,6 +2587,7 @@ var fallbackEventBus = {
2525
2587
  timestamp: Date.now()
2526
2588
  };
2527
2589
  const handlers = fallbackListeners.get(type);
2590
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
2528
2591
  if (handlers) {
2529
2592
  handlers.forEach((handler) => {
2530
2593
  try {
@@ -2547,6 +2610,7 @@ var fallbackEventBus = {
2547
2610
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
2548
2611
  }
2549
2612
  fallbackListeners.get(type).add(listener);
2613
+ subLog2.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
2550
2614
  return () => {
2551
2615
  const handlers = fallbackListeners.get(type);
2552
2616
  if (handlers) {
@@ -2570,6 +2634,7 @@ var fallbackEventBus = {
2570
2634
  },
2571
2635
  onAny: (listener) => {
2572
2636
  fallbackAnyListeners.add(listener);
2637
+ subLog2.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
2573
2638
  return () => {
2574
2639
  fallbackAnyListeners.delete(listener);
2575
2640
  };
@@ -2482,9 +2482,70 @@ var twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
2482
2482
  function cn(...inputs) {
2483
2483
  return twMerge(clsx(inputs));
2484
2484
  }
2485
+
2486
+ // lib/logger.ts
2487
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
2488
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
2489
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
2490
+ function getViteEnv(key) {
2491
+ try {
2492
+ const meta = import.meta;
2493
+ return meta?.env?.[key];
2494
+ } catch {
2495
+ return void 0;
2496
+ }
2497
+ }
2498
+ function envGet(key, viteKey) {
2499
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
2500
+ }
2501
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
2502
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
2503
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
2504
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
2505
+ function matchesNamespace(namespace) {
2506
+ if (DEBUG_FILTER.length === 0) return true;
2507
+ return DEBUG_FILTER.some((pattern) => {
2508
+ if (pattern === "*" || pattern === "almadar:*") return true;
2509
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
2510
+ return namespace === pattern;
2511
+ });
2512
+ }
2513
+ function createLogger(namespace) {
2514
+ const nsAllowed = matchesNamespace(namespace);
2515
+ const log2 = (level, message, data, correlationId) => {
2516
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
2517
+ if (level === "DEBUG" && !nsAllowed) return;
2518
+ const prefix = `[${namespace}]`;
2519
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
2520
+ switch (level) {
2521
+ case "DEBUG":
2522
+ console.debug(prefix, message, logData ?? "");
2523
+ break;
2524
+ case "INFO":
2525
+ console.info(prefix, message, logData ?? "");
2526
+ break;
2527
+ case "WARN":
2528
+ console.warn(prefix, message, logData ?? "");
2529
+ break;
2530
+ case "ERROR":
2531
+ console.error(prefix, message, logData ?? "");
2532
+ break;
2533
+ }
2534
+ };
2535
+ return {
2536
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
2537
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
2538
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
2539
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
2540
+ };
2541
+ }
2542
+ createLogger("almadar:eventbus");
2543
+ createLogger("almadar:eventbus:subscribe");
2485
2544
  var EventBusContext = createContext(null);
2486
2545
 
2487
2546
  // hooks/useEventBus.ts
2547
+ var log = createLogger("almadar:eventbus");
2548
+ var subLog2 = createLogger("almadar:eventbus:subscribe");
2488
2549
  function getGlobalEventBus() {
2489
2550
  if (typeof window !== "undefined") {
2490
2551
  return window.__kflowEventBus ?? null;
@@ -2501,6 +2562,7 @@ var fallbackEventBus = {
2501
2562
  timestamp: Date.now()
2502
2563
  };
2503
2564
  const handlers = fallbackListeners.get(type);
2565
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
2504
2566
  if (handlers) {
2505
2567
  handlers.forEach((handler) => {
2506
2568
  try {
@@ -2523,6 +2585,7 @@ var fallbackEventBus = {
2523
2585
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
2524
2586
  }
2525
2587
  fallbackListeners.get(type).add(listener);
2588
+ subLog2.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
2526
2589
  return () => {
2527
2590
  const handlers = fallbackListeners.get(type);
2528
2591
  if (handlers) {
@@ -2546,6 +2609,7 @@ var fallbackEventBus = {
2546
2609
  },
2547
2610
  onAny: (listener) => {
2548
2611
  fallbackAnyListeners.add(listener);
2612
+ subLog2.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
2549
2613
  return () => {
2550
2614
  fallbackAnyListeners.delete(listener);
2551
2615
  };
@@ -5,6 +5,7 @@ var providers = require('@almadar/ui/providers');
5
5
  require('react/jsx-runtime');
6
6
  var reactQuery = require('@tanstack/react-query');
7
7
 
8
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
8
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
10
 
10
11
  var React2__default = /*#__PURE__*/_interopDefault(React2);
@@ -872,6 +873,67 @@ function useDeepAgentGeneration() {
872
873
  submitInterruptDecisions
873
874
  };
874
875
  }
876
+
877
+ // lib/logger.ts
878
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
879
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
880
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
881
+ function getViteEnv(key) {
882
+ try {
883
+ const meta = ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) });
884
+ return meta?.env?.[key];
885
+ } catch {
886
+ return void 0;
887
+ }
888
+ }
889
+ function envGet(key, viteKey) {
890
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
891
+ }
892
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
893
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
894
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
895
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
896
+ function matchesNamespace(namespace) {
897
+ if (DEBUG_FILTER.length === 0) return true;
898
+ return DEBUG_FILTER.some((pattern) => {
899
+ if (pattern === "*" || pattern === "almadar:*") return true;
900
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
901
+ return namespace === pattern;
902
+ });
903
+ }
904
+ function createLogger(namespace) {
905
+ const nsAllowed = matchesNamespace(namespace);
906
+ const log2 = (level, message, data, correlationId) => {
907
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
908
+ if (level === "DEBUG" && !nsAllowed) return;
909
+ const prefix = `[${namespace}]`;
910
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
911
+ switch (level) {
912
+ case "DEBUG":
913
+ console.debug(prefix, message, logData ?? "");
914
+ break;
915
+ case "INFO":
916
+ console.info(prefix, message, logData ?? "");
917
+ break;
918
+ case "WARN":
919
+ console.warn(prefix, message, logData ?? "");
920
+ break;
921
+ case "ERROR":
922
+ console.error(prefix, message, logData ?? "");
923
+ break;
924
+ }
925
+ };
926
+ return {
927
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
928
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
929
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
930
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
931
+ };
932
+ }
933
+
934
+ // hooks/useEventBus.ts
935
+ var log = createLogger("almadar:eventbus");
936
+ var subLog = createLogger("almadar:eventbus:subscribe");
875
937
  function getGlobalEventBus() {
876
938
  if (typeof window !== "undefined") {
877
939
  return window.__kflowEventBus ?? null;
@@ -888,6 +950,7 @@ var fallbackEventBus = {
888
950
  timestamp: Date.now()
889
951
  };
890
952
  const handlers = fallbackListeners.get(type);
953
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
891
954
  if (handlers) {
892
955
  handlers.forEach((handler) => {
893
956
  try {
@@ -910,6 +973,7 @@ var fallbackEventBus = {
910
973
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
911
974
  }
912
975
  fallbackListeners.get(type).add(listener);
976
+ subLog.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
913
977
  return () => {
914
978
  const handlers = fallbackListeners.get(type);
915
979
  if (handlers) {
@@ -933,6 +997,7 @@ var fallbackEventBus = {
933
997
  },
934
998
  onAny: (listener) => {
935
999
  fallbackAnyListeners.add(listener);
1000
+ subLog.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
936
1001
  return () => {
937
1002
  fallbackAnyListeners.delete(listener);
938
1003
  };
@@ -1611,21 +1676,21 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1611
1676
  update: options?.events?.update || ENTITY_EVENTS.UPDATE,
1612
1677
  delete: options?.events?.delete || ENTITY_EVENTS.DELETE
1613
1678
  };
1614
- const log = (message, data) => {
1679
+ const log2 = (message, data) => {
1615
1680
  if (options?.debug) {
1616
1681
  console.log(`[useOrbitalMutations:${orbitalName}] ${message}`, data ?? "");
1617
1682
  }
1618
1683
  };
1619
1684
  const createMutation = reactQuery.useMutation({
1620
1685
  mutationFn: async (data) => {
1621
- log("Creating entity", data);
1686
+ log2("Creating entity", data);
1622
1687
  return sendOrbitalEvent(orbitalName, {
1623
1688
  event: events.create,
1624
1689
  payload: { data, entityType: entityName }
1625
1690
  });
1626
1691
  },
1627
1692
  onSuccess: (response) => {
1628
- log("Create succeeded", response);
1693
+ log2("Create succeeded", response);
1629
1694
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1630
1695
  },
1631
1696
  onError: (error) => {
@@ -1637,7 +1702,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1637
1702
  id,
1638
1703
  data
1639
1704
  }) => {
1640
- log(`Updating entity ${id}`, data);
1705
+ log2(`Updating entity ${id}`, data);
1641
1706
  return sendOrbitalEvent(orbitalName, {
1642
1707
  event: events.update,
1643
1708
  entityId: id,
@@ -1645,7 +1710,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1645
1710
  });
1646
1711
  },
1647
1712
  onSuccess: (response, variables) => {
1648
- log("Update succeeded", response);
1713
+ log2("Update succeeded", response);
1649
1714
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1650
1715
  queryClient.invalidateQueries({
1651
1716
  queryKey: entityDataKeys.detail(entityName, variables.id)
@@ -1657,7 +1722,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1657
1722
  });
1658
1723
  const deleteMutation = reactQuery.useMutation({
1659
1724
  mutationFn: async (id) => {
1660
- log(`Deleting entity ${id}`);
1725
+ log2(`Deleting entity ${id}`);
1661
1726
  return sendOrbitalEvent(orbitalName, {
1662
1727
  event: events.delete,
1663
1728
  entityId: id,
@@ -1665,7 +1730,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1665
1730
  });
1666
1731
  },
1667
1732
  onSuccess: (response, id) => {
1668
- log("Delete succeeded", response);
1733
+ log2("Delete succeeded", response);
1669
1734
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1670
1735
  queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
1671
1736
  },
@@ -866,6 +866,67 @@ function useDeepAgentGeneration() {
866
866
  submitInterruptDecisions
867
867
  };
868
868
  }
869
+
870
+ // lib/logger.ts
871
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
872
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
873
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
874
+ function getViteEnv(key) {
875
+ try {
876
+ const meta = import.meta;
877
+ return meta?.env?.[key];
878
+ } catch {
879
+ return void 0;
880
+ }
881
+ }
882
+ function envGet(key, viteKey) {
883
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
884
+ }
885
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
886
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
887
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
888
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
889
+ function matchesNamespace(namespace) {
890
+ if (DEBUG_FILTER.length === 0) return true;
891
+ return DEBUG_FILTER.some((pattern) => {
892
+ if (pattern === "*" || pattern === "almadar:*") return true;
893
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
894
+ return namespace === pattern;
895
+ });
896
+ }
897
+ function createLogger(namespace) {
898
+ const nsAllowed = matchesNamespace(namespace);
899
+ const log2 = (level, message, data, correlationId) => {
900
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
901
+ if (level === "DEBUG" && !nsAllowed) return;
902
+ const prefix = `[${namespace}]`;
903
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
904
+ switch (level) {
905
+ case "DEBUG":
906
+ console.debug(prefix, message, logData ?? "");
907
+ break;
908
+ case "INFO":
909
+ console.info(prefix, message, logData ?? "");
910
+ break;
911
+ case "WARN":
912
+ console.warn(prefix, message, logData ?? "");
913
+ break;
914
+ case "ERROR":
915
+ console.error(prefix, message, logData ?? "");
916
+ break;
917
+ }
918
+ };
919
+ return {
920
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
921
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
922
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
923
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
924
+ };
925
+ }
926
+
927
+ // hooks/useEventBus.ts
928
+ var log = createLogger("almadar:eventbus");
929
+ var subLog = createLogger("almadar:eventbus:subscribe");
869
930
  function getGlobalEventBus() {
870
931
  if (typeof window !== "undefined") {
871
932
  return window.__kflowEventBus ?? null;
@@ -882,6 +943,7 @@ var fallbackEventBus = {
882
943
  timestamp: Date.now()
883
944
  };
884
945
  const handlers = fallbackListeners.get(type);
946
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
885
947
  if (handlers) {
886
948
  handlers.forEach((handler) => {
887
949
  try {
@@ -904,6 +966,7 @@ var fallbackEventBus = {
904
966
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
905
967
  }
906
968
  fallbackListeners.get(type).add(listener);
969
+ subLog.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
907
970
  return () => {
908
971
  const handlers = fallbackListeners.get(type);
909
972
  if (handlers) {
@@ -927,6 +990,7 @@ var fallbackEventBus = {
927
990
  },
928
991
  onAny: (listener) => {
929
992
  fallbackAnyListeners.add(listener);
993
+ subLog.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
930
994
  return () => {
931
995
  fallbackAnyListeners.delete(listener);
932
996
  };
@@ -1605,21 +1669,21 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1605
1669
  update: options?.events?.update || ENTITY_EVENTS.UPDATE,
1606
1670
  delete: options?.events?.delete || ENTITY_EVENTS.DELETE
1607
1671
  };
1608
- const log = (message, data) => {
1672
+ const log2 = (message, data) => {
1609
1673
  if (options?.debug) {
1610
1674
  console.log(`[useOrbitalMutations:${orbitalName}] ${message}`, data ?? "");
1611
1675
  }
1612
1676
  };
1613
1677
  const createMutation = useMutation({
1614
1678
  mutationFn: async (data) => {
1615
- log("Creating entity", data);
1679
+ log2("Creating entity", data);
1616
1680
  return sendOrbitalEvent(orbitalName, {
1617
1681
  event: events.create,
1618
1682
  payload: { data, entityType: entityName }
1619
1683
  });
1620
1684
  },
1621
1685
  onSuccess: (response) => {
1622
- log("Create succeeded", response);
1686
+ log2("Create succeeded", response);
1623
1687
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1624
1688
  },
1625
1689
  onError: (error) => {
@@ -1631,7 +1695,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1631
1695
  id,
1632
1696
  data
1633
1697
  }) => {
1634
- log(`Updating entity ${id}`, data);
1698
+ log2(`Updating entity ${id}`, data);
1635
1699
  return sendOrbitalEvent(orbitalName, {
1636
1700
  event: events.update,
1637
1701
  entityId: id,
@@ -1639,7 +1703,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1639
1703
  });
1640
1704
  },
1641
1705
  onSuccess: (response, variables) => {
1642
- log("Update succeeded", response);
1706
+ log2("Update succeeded", response);
1643
1707
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1644
1708
  queryClient.invalidateQueries({
1645
1709
  queryKey: entityDataKeys.detail(entityName, variables.id)
@@ -1651,7 +1715,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1651
1715
  });
1652
1716
  const deleteMutation = useMutation({
1653
1717
  mutationFn: async (id) => {
1654
- log(`Deleting entity ${id}`);
1718
+ log2(`Deleting entity ${id}`);
1655
1719
  return sendOrbitalEvent(orbitalName, {
1656
1720
  event: events.delete,
1657
1721
  entityId: id,
@@ -1659,7 +1723,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1659
1723
  });
1660
1724
  },
1661
1725
  onSuccess: (response, id) => {
1662
- log("Delete succeeded", response);
1726
+ log2("Delete succeeded", response);
1663
1727
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1664
1728
  queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
1665
1729
  },
@@ -3,6 +3,7 @@
3
3
  var clsx = require('clsx');
4
4
  var tailwindMerge = require('tailwind-merge');
5
5
 
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
6
7
  function cn(...inputs) {
7
8
  return tailwindMerge.twMerge(clsx.clsx(inputs));
8
9
  }
@@ -427,7 +428,69 @@ function clearTraits() {
427
428
  notifyListeners4();
428
429
  }
429
430
 
431
+ // lib/logger.ts
432
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
433
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
434
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
435
+ function getViteEnv(key) {
436
+ try {
437
+ const meta = ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) });
438
+ return meta?.env?.[key];
439
+ } catch {
440
+ return void 0;
441
+ }
442
+ }
443
+ function envGet(key, viteKey) {
444
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
445
+ }
446
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
447
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
448
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
449
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
450
+ function matchesNamespace(namespace) {
451
+ if (DEBUG_FILTER.length === 0) return true;
452
+ return DEBUG_FILTER.some((pattern) => {
453
+ if (pattern === "*" || pattern === "almadar:*") return true;
454
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
455
+ return namespace === pattern;
456
+ });
457
+ }
458
+ function createLogger(namespace) {
459
+ const nsAllowed = matchesNamespace(namespace);
460
+ const log2 = (level, message, data, correlationId) => {
461
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
462
+ if (level === "DEBUG" && !nsAllowed) return;
463
+ const prefix = `[${namespace}]`;
464
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
465
+ switch (level) {
466
+ case "DEBUG":
467
+ console.debug(prefix, message, logData ?? "");
468
+ break;
469
+ case "INFO":
470
+ console.info(prefix, message, logData ?? "");
471
+ break;
472
+ case "WARN":
473
+ console.warn(prefix, message, logData ?? "");
474
+ break;
475
+ case "ERROR":
476
+ console.error(prefix, message, logData ?? "");
477
+ break;
478
+ }
479
+ };
480
+ return {
481
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
482
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
483
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
484
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
485
+ };
486
+ }
487
+ var _cidCounter = 0;
488
+ function generateCorrelationId() {
489
+ return `evt-${Date.now()}-${++_cidCounter}`;
490
+ }
491
+
430
492
  // lib/verificationRegistry.ts
493
+ var log = createLogger("almadar:bridge");
431
494
  var MAX_TRANSITIONS = 500;
432
495
  function getState() {
433
496
  if (typeof window !== "undefined") {
@@ -471,6 +534,7 @@ function recordTransition(trace) {
471
534
  ...trace,
472
535
  id: `t-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
473
536
  };
537
+ log.info("transition:recorded", { trait: trace.traitName, from: trace.from, to: trace.to, event: trace.event, effectCount: trace.effects.length });
474
538
  getState().transitions.push(entry);
475
539
  if (getState().transitions.length > MAX_TRANSITIONS) {
476
540
  getState().transitions.shift();
@@ -620,10 +684,12 @@ function waitForTransition(event, timeoutMs = 1e4) {
620
684
  }
621
685
  function bindEventBus(eventBus) {
622
686
  if (typeof window === "undefined") return;
687
+ log.info("bindEventBus", { hasOnAny: !!eventBus.onAny });
623
688
  exposeOnWindow();
624
689
  if (window.__orbitalVerification) {
625
690
  window.__orbitalVerification.sendEvent = (event, payload) => {
626
691
  const prefixed = event.startsWith("UI:") ? event : `UI:${event}`;
692
+ log.debug("sendEvent", { event: prefixed, payloadKeys: payload ? Object.keys(payload) : [] });
627
693
  eventBus.emit(prefixed, payload);
628
694
  };
629
695
  const eventLog = [];
@@ -1461,6 +1527,7 @@ exports.clearTicks = clearTicks;
1461
1527
  exports.clearTraits = clearTraits;
1462
1528
  exports.clearVerification = clearVerification;
1463
1529
  exports.cn = cn;
1530
+ exports.createLogger = createLogger;
1464
1531
  exports.debug = debug;
1465
1532
  exports.debugCollision = debugCollision;
1466
1533
  exports.debugError = debugError;
@@ -1477,6 +1544,7 @@ exports.extractOutputsFromTransitions = extractOutputsFromTransitions;
1477
1544
  exports.extractStateMachine = extractStateMachine;
1478
1545
  exports.formatGuard = formatGuard;
1479
1546
  exports.formatNestedFieldLabel = formatNestedFieldLabel;
1547
+ exports.generateCorrelationId = generateCorrelationId;
1480
1548
  exports.getAllChecks = getAllChecks;
1481
1549
  exports.getAllTicks = getAllTicks;
1482
1550
  exports.getAllTraits = getAllTraits;
@@ -16,3 +16,4 @@ export * from './verificationRegistry';
16
16
  export * from './getNestedValue';
17
17
  export * from './visualizer';
18
18
  export * from './parseContentSegments';
19
+ export * from './logger';