@cuekit-ai/react 1.2.3 → 1.3.1

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/dist/index.js CHANGED
@@ -55,12 +55,223 @@ var init_globals = __esm({
55
55
  }
56
56
  });
57
57
 
58
+ // src/core/intent-store.ts
59
+ var store, GlobalStore;
60
+ var init_intent_store = __esm({
61
+ "src/core/intent-store.ts"() {
62
+ "use strict";
63
+ store = {
64
+ screenMetadata: {},
65
+ allElementsData: []
66
+ };
67
+ GlobalStore = {
68
+ // 🔹 Screen Metadata Methods
69
+ setMetadata(screen, metadata) {
70
+ store.screenMetadata[screen] = metadata;
71
+ },
72
+ getMetadata(screen) {
73
+ return store.screenMetadata[screen];
74
+ },
75
+ clearMetadata(screen) {
76
+ delete store.screenMetadata[screen];
77
+ },
78
+ // 🔹 Generic Store Access Methods
79
+ setData(key, value) {
80
+ store[key] = value;
81
+ },
82
+ getData(key) {
83
+ return store[key];
84
+ },
85
+ clearData(key) {
86
+ delete store[key];
87
+ },
88
+ // 🔹 Element Data Management
89
+ setElement(elementData) {
90
+ const index2 = store.allElementsData.findIndex((e3) => e3.elementId === elementData.elementId);
91
+ if (index2 >= 0) {
92
+ console.log("Updating existing element");
93
+ store.allElementsData[index2] = elementData;
94
+ } else {
95
+ console.log("Adding new element");
96
+ store.allElementsData.push(elementData);
97
+ }
98
+ },
99
+ getElementById(elementId) {
100
+ const match = store.allElementsData.find((e3) => e3.elementId === elementId);
101
+ if (!match) {
102
+ console.warn(`[GlobalStore] No element found for ID: ${elementId}`);
103
+ console.log("All elements in store:", store.allElementsData);
104
+ }
105
+ return match;
106
+ },
107
+ deleteElementById(id) {
108
+ store.allElementsData = store.allElementsData.filter((e3) => e3.elementId !== id);
109
+ },
110
+ clearAllElements() {
111
+ store.allElementsData = [];
112
+ }
113
+ };
114
+ }
115
+ });
116
+
117
+ // src/core/navigation.ts
118
+ function setNavigationHandler(handler) {
119
+ navigationHandler = handler;
120
+ }
121
+ function navigate(path2, params) {
122
+ const safeParams = params || {};
123
+ const absolutePath = path2.startsWith("/") ? path2 : `/${path2}`;
124
+ if (navigationHandler) {
125
+ try {
126
+ navigationHandler(absolutePath, safeParams);
127
+ } catch (error) {
128
+ console.error("[CueKit] navigation handler failed, falling back to default:", error);
129
+ }
130
+ return;
131
+ }
132
+ let fullPath = absolutePath;
133
+ if (safeParams) {
134
+ const searchParams = new URLSearchParams(safeParams).toString();
135
+ if (searchParams) {
136
+ fullPath += `?${searchParams}`;
137
+ }
138
+ }
139
+ if (navigation) {
140
+ navigation.push(fullPath);
141
+ } else {
142
+ if (typeof window !== "undefined") {
143
+ window.location.href = fullPath;
144
+ }
145
+ }
146
+ }
147
+ function getCurrentScreenName() {
148
+ try {
149
+ const path2 = getCurrentPath();
150
+ return path2 || "UnknownScreen";
151
+ } catch (e3) {
152
+ return "UnknownScreen";
153
+ }
154
+ }
155
+ function getCurrentRouteParams() {
156
+ try {
157
+ const params = {};
158
+ const searchParams = getSearchParams();
159
+ if (searchParams instanceof URLSearchParams) {
160
+ searchParams.forEach((value, key) => {
161
+ params[key] = value;
162
+ });
163
+ } else {
164
+ return searchParams;
165
+ }
166
+ return params;
167
+ } catch (e3) {
168
+ return {};
169
+ }
170
+ }
171
+ function onStateChange() {
172
+ const routeName = getCurrentScreenName();
173
+ const params = getCurrentRouteParams();
174
+ if (params && params.metadata) {
175
+ try {
176
+ const metadata = JSON.parse(params.metadata);
177
+ GlobalStore.setMetadata(routeName, metadata);
178
+ } catch (error) {
179
+ console.error("Failed to parse metadata from URL:", error);
180
+ }
181
+ }
182
+ }
183
+ function getElementPath(element3) {
184
+ if (element3.id) {
185
+ return `id(${element3.id})`;
186
+ }
187
+ const path2 = [];
188
+ let current = element3;
189
+ while (current && current !== document.body) {
190
+ let index2 = 1;
191
+ let sibling = current.previousElementSibling;
192
+ while (sibling) {
193
+ if (sibling.tagName === current.tagName) {
194
+ index2++;
195
+ }
196
+ sibling = sibling.previousElementSibling;
197
+ }
198
+ path2.unshift(`${current.tagName.toLowerCase()}[${index2}]`);
199
+ current = current.parentElement;
200
+ }
201
+ return path2.join("/");
202
+ }
203
+ var navigation, navigationHandler, getCurrentPath, getSearchParams, safeNavigate, handleNavigationAndClick;
204
+ var init_navigation = __esm({
205
+ "src/core/navigation.ts"() {
206
+ "use strict";
207
+ init_intent_store();
208
+ navigationHandler = null;
209
+ getCurrentPath = () => {
210
+ if (typeof window === "undefined") return "";
211
+ return window.location.pathname;
212
+ };
213
+ getSearchParams = () => {
214
+ if (typeof window === "undefined") return new URLSearchParams();
215
+ return new URLSearchParams(window.location.search);
216
+ };
217
+ safeNavigate = (name2, params = {}) => {
218
+ if (name2) {
219
+ navigate(name2, params);
220
+ } else {
221
+ console.warn("[CueKit] route name not provided");
222
+ }
223
+ };
224
+ handleNavigationAndClick = (routeName, elementHash) => {
225
+ safeNavigate(routeName);
226
+ if (typeof MutationObserver === "undefined" || typeof document === "undefined") return;
227
+ const observer = new MutationObserver((mutationsList, observer2) => {
228
+ setTimeout(() => {
229
+ const allElements = document.querySelectorAll("*");
230
+ let elementToClick = null;
231
+ for (const element3 of allElements) {
232
+ if (element3 instanceof HTMLElement) {
233
+ const tagName = element3.tagName.toLowerCase();
234
+ const text7 = (element3.textContent || "").trim().substring(0, 50);
235
+ let sibling = element3.previousElementSibling;
236
+ let position3 = 1;
237
+ while (sibling) {
238
+ if (sibling.tagName === element3.tagName) {
239
+ position3++;
240
+ }
241
+ sibling = sibling.previousElementSibling;
242
+ }
243
+ const path2 = getElementPath(element3);
244
+ const idString = `${tagName}[${position3}]_(${text7})_${path2}`;
245
+ let hash = 0;
246
+ for (let i2 = 0; i2 < idString.length; i2++) {
247
+ const char = idString.charCodeAt(i2);
248
+ hash = (hash << 5) - hash + char;
249
+ hash |= 0;
250
+ }
251
+ const elementHashValue = hash.toString(36);
252
+ if (elementHashValue === elementHash) {
253
+ elementToClick = element3;
254
+ break;
255
+ }
256
+ }
257
+ }
258
+ if (elementToClick) {
259
+ elementToClick.click();
260
+ observer2.disconnect();
261
+ }
262
+ }, 100);
263
+ });
264
+ observer.observe(document.body, { childList: true, subtree: true });
265
+ };
266
+ }
267
+ });
268
+
58
269
  // src/constants/index.ts
59
270
  var WEBRTC_BACKEND_SERVER_URL;
60
271
  var init_constants = __esm({
61
272
  "src/constants/index.ts"() {
62
273
  "use strict";
63
- WEBRTC_BACKEND_SERVER_URL = "https://api-webrtc.cuekit.ai";
274
+ WEBRTC_BACKEND_SERVER_URL = "https://api-webrtc-dev.ansyr.ai";
64
275
  }
65
276
  });
66
277
 
@@ -4472,15 +4683,15 @@ function requireSdp() {
4472
4683
  return Math.random().toString().substr(2, 22);
4473
4684
  };
4474
4685
  SDPUtils2.writeSessionBoilerplate = function(sessId, sessVer, sessUser) {
4475
- let sessionId2;
4686
+ let sessionId;
4476
4687
  const version2 = sessVer !== void 0 ? sessVer : 2;
4477
4688
  if (sessId) {
4478
- sessionId2 = sessId;
4689
+ sessionId = sessId;
4479
4690
  } else {
4480
- sessionId2 = SDPUtils2.generateSessionId();
4691
+ sessionId = SDPUtils2.generateSessionId();
4481
4692
  }
4482
4693
  const user = sessUser || "thisisadapterortc";
4483
- return "v=0\r\no=" + user + " " + sessionId2 + " " + version2 + " IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n";
4694
+ return "v=0\r\no=" + user + " " + sessionId + " " + version2 + " IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n";
4484
4695
  };
4485
4696
  SDPUtils2.getDirection = function(mediaSection, sessionpart) {
4486
4697
  const lines = SDPUtils2.splitLines(mediaSection);
@@ -5204,8 +5415,8 @@ function isWeb() {
5204
5415
  function isReactNative() {
5205
5416
  return navigator.product == "ReactNative";
5206
5417
  }
5207
- function isCloud(serverUrl3) {
5208
- return serverUrl3.hostname.endsWith(".livekit.cloud") || serverUrl3.hostname.endsWith(".livekit.run");
5418
+ function isCloud(serverUrl2) {
5419
+ return serverUrl2.hostname.endsWith(".livekit.cloud") || serverUrl2.hostname.endsWith(".livekit.run");
5209
5420
  }
5210
5421
  function getLKReactNativeInfo() {
5211
5422
  if (global && global.LiveKitReactNativeGlobal) {
@@ -7127,8 +7338,8 @@ function applyUserDataCompat(newObj, oldObj) {
7127
7338
  newObj.destinationIdentities = destinationIdentities;
7128
7339
  oldObj.destinationIdentities = destinationIdentities;
7129
7340
  }
7130
- function getCloudConfigUrl(serverUrl3) {
7131
- return "".concat(serverUrl3.protocol.replace("ws", "http"), "//").concat(serverUrl3.host, "/settings");
7341
+ function getCloudConfigUrl(serverUrl2) {
7342
+ return "".concat(serverUrl2.protocol.replace("ws", "http"), "//").concat(serverUrl2.host, "/settings");
7132
7343
  }
7133
7344
  function isElementInPiP(el) {
7134
7345
  var _a, _b;
@@ -22657,6 +22868,269 @@ var init_livekit_client_esm = __esm({
22657
22868
  }
22658
22869
  });
22659
22870
 
22871
+ // src/utils/jsx-encoder.ts
22872
+ function generateStableDOMId(element3) {
22873
+ const tagName = element3.tagName.toLowerCase();
22874
+ const text7 = (element3.textContent || "").trim().substring(0, 50);
22875
+ let sibling = element3.previousElementSibling;
22876
+ let position3 = 1;
22877
+ while (sibling) {
22878
+ if (sibling.tagName === element3.tagName) {
22879
+ position3++;
22880
+ }
22881
+ sibling = sibling.previousElementSibling;
22882
+ }
22883
+ const path2 = getElementPath2(element3);
22884
+ const idString = `${tagName}[${position3}]_(${text7})_${path2}`;
22885
+ let hash = 0;
22886
+ for (let i2 = 0; i2 < idString.length; i2++) {
22887
+ const char = idString.charCodeAt(i2);
22888
+ hash = (hash << 5) - hash + char;
22889
+ hash |= 0;
22890
+ }
22891
+ return hash.toString(36);
22892
+ }
22893
+ function getElementPath2(element3) {
22894
+ if (element3.id) {
22895
+ return `id(${element3.id})`;
22896
+ }
22897
+ if (element3.tagName.toLowerCase() === "body") {
22898
+ return "/body";
22899
+ }
22900
+ let ix = 0;
22901
+ const siblings = element3.parentNode?.children || new HTMLCollection();
22902
+ for (let i2 = 0; i2 < siblings.length; i2++) {
22903
+ const sibling = siblings[i2];
22904
+ if (sibling === element3) {
22905
+ return `${getElementPath2(element3.parentNode)}/${element3.tagName}[${ix + 1}]`;
22906
+ }
22907
+ if (sibling.nodeType === 1 && sibling.tagName === element3.tagName) {
22908
+ ix++;
22909
+ }
22910
+ }
22911
+ return "not_found";
22912
+ }
22913
+ var init_jsx_encoder = __esm({
22914
+ "src/utils/jsx-encoder.ts"() {
22915
+ "use strict";
22916
+ }
22917
+ });
22918
+
22919
+ // src/utils/element-service.ts
22920
+ function getInteractiveElements() {
22921
+ return document.querySelectorAll(INTERACTIVE_ELEMENT_SELECTOR);
22922
+ }
22923
+ function getImmediateText(element3) {
22924
+ let text7 = "";
22925
+ if (element3.childNodes) {
22926
+ for (const node2 of Array.from(element3.childNodes)) {
22927
+ if (node2.nodeType === 3) {
22928
+ text7 += node2.textContent || "";
22929
+ }
22930
+ }
22931
+ }
22932
+ return text7.trim();
22933
+ }
22934
+ function captureFullDOMStructure() {
22935
+ console.log("\u{1F333} Capturing full DOM structure...");
22936
+ const components = [];
22937
+ const interactiveElements = getInteractiveElements();
22938
+ interactiveElements.forEach((element3) => {
22939
+ if (element3 instanceof HTMLElement && !element3.closest("[data-cuekit-ignore]")) {
22940
+ const nodeData = buildFlatDOMNode(element3);
22941
+ if (nodeData) {
22942
+ components.push(nodeData);
22943
+ }
22944
+ }
22945
+ });
22946
+ const result = { components };
22947
+ console.log("\u{1F333} Full DOM structure captured:", result);
22948
+ return result;
22949
+ }
22950
+ function buildFlatDOMNode(element3) {
22951
+ if (element3.tagName.toLowerCase() === "script" || element3.hasAttribute("data-cuekit-ignore") || element3.style.display === "none" || element3.style.visibility === "hidden") {
22952
+ return null;
22953
+ }
22954
+ const hash = generateStableDOMId(element3);
22955
+ const text7 = getImmediateText(element3).substring(0, 100);
22956
+ const isClickable = isElementClickable(element3);
22957
+ const componentType = element3.tagName.toLowerCase();
22958
+ return {
22959
+ hash,
22960
+ text: text7,
22961
+ isClickable,
22962
+ componentType,
22963
+ children: []
22964
+ // No children in a flat structure
22965
+ };
22966
+ }
22967
+ function isElementClickable(element3) {
22968
+ const interactiveSelectors = [
22969
+ "button",
22970
+ "a",
22971
+ "input",
22972
+ "select",
22973
+ "textarea",
22974
+ '[role="button"]',
22975
+ '[role="link"]',
22976
+ '[role="tab"]',
22977
+ "[data-onclick-id]",
22978
+ "[data-on-press-id]",
22979
+ "[onclick]",
22980
+ "[onmousedown]",
22981
+ "[onmouseup]",
22982
+ "[ontouchstart]",
22983
+ "[ontouchend]",
22984
+ "[onkeydown]",
22985
+ "[onkeyup]",
22986
+ "[onkeypress]"
22987
+ ];
22988
+ for (const selector of interactiveSelectors) {
22989
+ if (element3.matches(selector)) {
22990
+ return true;
22991
+ }
22992
+ }
22993
+ const hasClickEvents = element3.onclick !== null || element3.getAttribute("onclick") !== null;
22994
+ const hasInteractiveEvents = element3.ontouchstart !== null || element3.getAttribute("ontouchstart") !== null || element3.ontouchend !== null || element3.getAttribute("ontouchend") !== null || element3.onkeydown !== null || element3.getAttribute("onkeydown") !== null || element3.onkeyup !== null || element3.getAttribute("onkeyup") !== null || element3.onkeypress !== null || element3.getAttribute("onkeypress") !== null;
22995
+ const hasPointerCursor = element3.style.cursor === "pointer" || getComputedStyle(element3).cursor === "pointer";
22996
+ const hasTabIndex = element3.hasAttribute("tabindex") && parseInt(element3.getAttribute("tabindex") || "0") >= 0;
22997
+ const hasInteractiveDataAttrs = element3.hasAttribute("data-clickable") || element3.hasAttribute("data-interactive") || element3.hasAttribute("data-action") || element3.hasAttribute("data-handler");
22998
+ const hasInteractiveAria = element3.hasAttribute("aria-pressed") || element3.hasAttribute("aria-expanded") || element3.hasAttribute("aria-selected") || element3.hasAttribute("aria-checked");
22999
+ return hasClickEvents || hasInteractiveEvents || hasPointerCursor || hasTabIndex || hasInteractiveDataAttrs || hasInteractiveAria;
23000
+ }
23001
+ function executeAction(action) {
23002
+ console.log("\u{1F3AF} Executing element action:", action);
23003
+ const { action_type, target_element, target } = action;
23004
+ switch (action_type) {
23005
+ case "click":
23006
+ return clickElement(target_element);
23007
+ case "navigate":
23008
+ return navigateToElement(target_element || target);
23009
+ case "input":
23010
+ case "focus":
23011
+ return focusElement(target_element);
23012
+ case "toggle":
23013
+ return toggleElement(target_element);
23014
+ default:
23015
+ console.warn(`\u26A0\uFE0F Unknown action type: ${action_type}`);
23016
+ return false;
23017
+ }
23018
+ }
23019
+ function getFullDOMStructure() {
23020
+ console.log("\u{1F333} ElementService: Getting full DOM structure...");
23021
+ return captureFullDOMStructure();
23022
+ }
23023
+ function clickElement(elementId) {
23024
+ if (!elementId) {
23025
+ console.warn("\u26A0\uFE0F No element ID provided for click action");
23026
+ return false;
23027
+ }
23028
+ const domStructure = getFullDOMStructure();
23029
+ const elementToClick = findElementById(domStructure, elementId);
23030
+ if (elementToClick) {
23031
+ console.log(`\u{1F3AF} Clicking element: ${elementId}`);
23032
+ const domElement = findDOMElementById(elementId);
23033
+ if (domElement) {
23034
+ domElement.click();
23035
+ return true;
23036
+ }
23037
+ } else {
23038
+ console.warn(`\u26A0\uFE0F Element not found: ${elementId}`);
23039
+ }
23040
+ return false;
23041
+ }
23042
+ function navigateToElement(target) {
23043
+ if (!target) {
23044
+ console.warn("\u26A0\uFE0F No target provided for navigation action");
23045
+ return false;
23046
+ }
23047
+ console.log(`\u{1F9ED} Navigating to: ${target}`);
23048
+ if (target.includes("/") || target.startsWith("http")) {
23049
+ safeNavigate(target, {});
23050
+ } else {
23051
+ handleNavigationAndClick(target, target);
23052
+ }
23053
+ return true;
23054
+ }
23055
+ function focusElement(elementId) {
23056
+ if (!elementId) {
23057
+ console.warn("\u26A0\uFE0F No element ID provided for focus action");
23058
+ return false;
23059
+ }
23060
+ const domElement = findDOMElementById(elementId);
23061
+ if (domElement instanceof HTMLInputElement || domElement instanceof HTMLTextAreaElement || domElement instanceof HTMLSelectElement) {
23062
+ console.log(`\u{1F4DD} Focusing element: ${elementId}`);
23063
+ domElement.focus();
23064
+ return true;
23065
+ } else {
23066
+ console.warn(`\u26A0\uFE0F Focusable element not found: ${elementId}`);
23067
+ return false;
23068
+ }
23069
+ }
23070
+ function toggleElement(elementId) {
23071
+ if (!elementId) {
23072
+ console.warn("\u26A0\uFE0F No element ID provided for toggle action");
23073
+ return false;
23074
+ }
23075
+ const domElement = findDOMElementById(elementId);
23076
+ if (domElement instanceof HTMLElement) {
23077
+ console.log(`\u{1F504} Toggling element: ${elementId}`);
23078
+ if (domElement instanceof HTMLInputElement) {
23079
+ if (domElement.type === "checkbox") {
23080
+ domElement.checked = !domElement.checked;
23081
+ } else if (domElement.type === "radio") {
23082
+ domElement.checked = true;
23083
+ }
23084
+ domElement.dispatchEvent(new Event("change", { bubbles: true }));
23085
+ } else {
23086
+ domElement.click();
23087
+ }
23088
+ return true;
23089
+ } else {
23090
+ console.warn(`\u26A0\uFE0F Toggleable element not found: ${elementId}`);
23091
+ return false;
23092
+ }
23093
+ }
23094
+ function findElementById(domStructure, elementId) {
23095
+ const searchInComponents = (components) => {
23096
+ for (const component of components) {
23097
+ if (component.hash === elementId) {
23098
+ return component;
23099
+ }
23100
+ if (component.children.length > 0) {
23101
+ const found = searchInComponents(component.children);
23102
+ if (found) return found;
23103
+ }
23104
+ }
23105
+ return null;
23106
+ };
23107
+ return searchInComponents(domStructure.components);
23108
+ }
23109
+ function findDOMElementById(elementId) {
23110
+ const interactiveElements = getInteractiveElements();
23111
+ for (const element3 of interactiveElements) {
23112
+ if (element3 instanceof HTMLElement) {
23113
+ console.log("\u{1F50D} Checking element:", element3);
23114
+ const hash = generateStableDOMId(element3);
23115
+ console.log("\u{1F50D} Generated hash:", hash);
23116
+ if (hash === elementId) {
23117
+ console.log("\u{1F50D} Found element:", element3);
23118
+ return element3;
23119
+ }
23120
+ }
23121
+ }
23122
+ return null;
23123
+ }
23124
+ var INTERACTIVE_ELEMENT_SELECTOR;
23125
+ var init_element_service = __esm({
23126
+ "src/utils/element-service.ts"() {
23127
+ "use strict";
23128
+ init_jsx_encoder();
23129
+ init_navigation();
23130
+ INTERACTIVE_ELEMENT_SELECTOR = 'a, button, input, textarea, select, [role="button"], [onclick]';
23131
+ }
23132
+ });
23133
+
22660
23134
  // src/utils/webrtc-service.ts
22661
23135
  var webrtc_service_exports = {};
22662
23136
  __export(webrtc_service_exports, {
@@ -22668,6 +23142,7 @@ __export(webrtc_service_exports, {
22668
23142
  getRoomName: () => getRoomName,
22669
23143
  isConnected: () => isConnected,
22670
23144
  sendData: () => sendData,
23145
+ sendRuntimeData: () => sendRuntimeData,
22671
23146
  sendScreenStatus: () => sendScreenStatus,
22672
23147
  sendStaticData: () => sendStaticData,
22673
23148
  sendUserCommand: () => sendUserCommand,
@@ -22787,19 +23262,19 @@ function setupEventListeners() {
22787
23262
  }).on(RoomEvent.TrackUnsubscribed, (track) => {
22788
23263
  track.detach().forEach((element3) => element3.remove());
22789
23264
  }).on(RoomEvent.DataReceived, (payload, participant) => {
22790
- handleDataReceived(payload, participant);
23265
+ console.log("\u{1F4E1} LiveKit data received:", new TextDecoder().decode(payload));
23266
+ try {
23267
+ const message = JSON.parse(new TextDecoder().decode(payload));
23268
+ console.log("\u{1F4E1} LiveKit data received:", message);
23269
+ callbacks.onNavigationCommand?.(message);
23270
+ } catch (error) {
23271
+ const message = new TextDecoder().decode(payload);
23272
+ callbacks.onNavigationCommand?.({ type: "raw_text", data: message });
23273
+ }
22791
23274
  }).on(RoomEvent.Disconnected, () => {
22792
23275
  setWebRTCConnectionState({ isConnected: false, isConnecting: false });
22793
23276
  });
22794
23277
  }
22795
- function handleDataReceived(payload, participant) {
22796
- try {
22797
- const message = JSON.parse(new TextDecoder().decode(payload));
22798
- callbacks.onNavigationCommand?.(message);
22799
- } catch (error) {
22800
- console.error("\u{1F3A4} WebRTCService: Error parsing data:", error);
22801
- }
22802
- }
22803
23278
  function updateParticipantsList() {
22804
23279
  if (!room) return;
22805
23280
  const participants = [
@@ -22812,7 +23287,10 @@ function updateParticipantsList() {
22812
23287
  async function sendData(data, reliable = true) {
22813
23288
  if (!room) throw new Error("Not connected to room");
22814
23289
  try {
22815
- await room.localParticipant.publishData(new TextEncoder().encode(JSON.stringify(data)), {
23290
+ console.log("\u{1F4E1} LiveKit data sending:", data);
23291
+ const encoder = new TextEncoder();
23292
+ const encodedData = encoder.encode(data);
23293
+ await room.localParticipant.publishData(encodedData, {
22816
23294
  reliable
22817
23295
  });
22818
23296
  } catch (error) {
@@ -22843,14 +23321,30 @@ function getParticipants() {
22843
23321
  }
22844
23322
  async function sendUserCommand(command) {
22845
23323
  if (!room) return;
22846
- const userCommand = {
22847
- type: "user_command",
22848
- data: {
22849
- command,
22850
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
22851
- }
22852
- };
22853
- await sendData(userCommand);
23324
+ console.log(`\u{1F4AC} Sending user command: "${command}"`);
23325
+ await sendData(command);
23326
+ }
23327
+ async function sendRuntimeData() {
23328
+ if (!room) {
23329
+ console.error("\u274C Cannot send runtime data without a room connection");
23330
+ return;
23331
+ }
23332
+ try {
23333
+ const domStructure = captureFullDOMStructure();
23334
+ const screenName = getCurrentScreenName();
23335
+ const response = {
23336
+ type: "runtime_data_response",
23337
+ data: {
23338
+ components: domStructure.components,
23339
+ current_screen: screenName
23340
+ }
23341
+ };
23342
+ console.log("\u{1F4E6} Sending runtime data response");
23343
+ await sendData(JSON.stringify(response));
23344
+ console.log("\u{1F4E6} Runtime data sent successfully");
23345
+ } catch (error) {
23346
+ console.error("\u274C Failed to send runtime data:", error);
23347
+ }
22854
23348
  }
22855
23349
  async function sendStaticData(componentData, appId = "default") {
22856
23350
  try {
@@ -22881,10 +23375,6 @@ async function disconnectFromRoom() {
22881
23375
  await room.disconnect();
22882
23376
  room = null;
22883
23377
  }
22884
- if (eventSource) {
22885
- eventSource.close();
22886
- eventSource = null;
22887
- }
22888
23378
  if (reconnectTimeout) {
22889
23379
  clearTimeout(reconnectTimeout);
22890
23380
  reconnectTimeout = null;
@@ -22898,15 +23388,16 @@ async function disconnectFromRoom() {
22898
23388
  function getRoom() {
22899
23389
  return room;
22900
23390
  }
22901
- var room, eventSource, reconnectTimeout, serverUrl, callbacks, audioContainerRef, livekitUrl, token, roomName;
23391
+ var room, reconnectTimeout, serverUrl, callbacks, audioContainerRef, livekitUrl, token, roomName;
22902
23392
  var init_webrtc_service = __esm({
22903
23393
  "src/utils/webrtc-service.ts"() {
22904
23394
  "use strict";
22905
23395
  init_livekit_client_esm();
22906
23396
  init_globals();
22907
23397
  init_constants();
23398
+ init_element_service();
23399
+ init_navigation();
22908
23400
  room = null;
22909
- eventSource = null;
22910
23401
  reconnectTimeout = null;
22911
23402
  serverUrl = WEBRTC_BACKEND_SERVER_URL || "https://bdd4c945f073.ngrok-free.app";
22912
23403
  callbacks = {};
@@ -23258,19 +23749,11 @@ __export(index_exports, {
23258
23749
  VoiceIntensityVisualizer: () => VoiceIntensityVisualizer,
23259
23750
  captureFullDOMStructure: () => captureFullDOMStructure,
23260
23751
  configureWebRTCServer: () => configureWebRTCServer,
23261
- connectSSE: () => connectSSE,
23262
- disconnectSSE: () => disconnectSSE,
23263
23752
  executeAction: () => executeAction,
23264
23753
  getFullDOMStructure: () => getFullDOMStructure,
23265
- getSSEConnectionState: () => getSSEConnectionState,
23266
- getSSEConnectionStatus: () => getSSEConnectionStatus,
23267
23754
  getWebRTCServerConfig: () => getWebRTCServerConfig,
23268
23755
  initWebRTC: () => initWebRTC,
23269
23756
  initWebRTCWithDeployedBackend: () => initWebRTCWithDeployedBackend,
23270
- sendDashboardData: () => sendDashboardData,
23271
- sendElementData: () => sendElementData,
23272
- sendRuntimeData: () => sendRuntimeData,
23273
- setSSECallbacks: () => setSSECallbacks,
23274
23757
  useCuekit: () => useCuekit,
23275
23758
  useQubeContext: () => useQubeContext,
23276
23759
  useWebRTC: () => useWebRTC
@@ -23296,204 +23779,9 @@ function InitCuekit(config) {
23296
23779
  setWebRTCConfig(webRTCConfig);
23297
23780
  }
23298
23781
 
23299
- // src/core/intent-store.ts
23300
- var store = {
23301
- screenMetadata: {},
23302
- allElementsData: []
23303
- };
23304
- var GlobalStore = {
23305
- // 🔹 Screen Metadata Methods
23306
- setMetadata(screen, metadata) {
23307
- store.screenMetadata[screen] = metadata;
23308
- },
23309
- getMetadata(screen) {
23310
- return store.screenMetadata[screen];
23311
- },
23312
- clearMetadata(screen) {
23313
- delete store.screenMetadata[screen];
23314
- },
23315
- // 🔹 Generic Store Access Methods
23316
- setData(key, value) {
23317
- store[key] = value;
23318
- },
23319
- getData(key) {
23320
- return store[key];
23321
- },
23322
- clearData(key) {
23323
- delete store[key];
23324
- },
23325
- // 🔹 Element Data Management
23326
- setElement(elementData) {
23327
- const index2 = store.allElementsData.findIndex((e3) => e3.elementId === elementData.elementId);
23328
- if (index2 >= 0) {
23329
- console.log("Updating existing element");
23330
- store.allElementsData[index2] = elementData;
23331
- } else {
23332
- console.log("Adding new element");
23333
- store.allElementsData.push(elementData);
23334
- }
23335
- },
23336
- getElementById(elementId) {
23337
- const match = store.allElementsData.find((e3) => e3.elementId === elementId);
23338
- if (!match) {
23339
- console.warn(`[GlobalStore] No element found for ID: ${elementId}`);
23340
- console.log("All elements in store:", store.allElementsData);
23341
- }
23342
- return match;
23343
- },
23344
- deleteElementById(id) {
23345
- store.allElementsData = store.allElementsData.filter((e3) => e3.elementId !== id);
23346
- },
23347
- clearAllElements() {
23348
- store.allElementsData = [];
23349
- }
23350
- };
23351
-
23352
- // src/core/navigation.ts
23353
- var navigation;
23354
- var navigationHandler = null;
23355
- function setNavigationHandler(handler) {
23356
- navigationHandler = handler;
23357
- }
23358
- function navigate(path2, params) {
23359
- const safeParams = params || {};
23360
- const absolutePath = path2.startsWith("/") ? path2 : `/${path2}`;
23361
- if (navigationHandler) {
23362
- try {
23363
- navigationHandler(absolutePath, safeParams);
23364
- } catch (error) {
23365
- console.error("[CueKit] navigation handler failed, falling back to default:", error);
23366
- }
23367
- return;
23368
- }
23369
- let fullPath = absolutePath;
23370
- if (safeParams) {
23371
- const searchParams = new URLSearchParams(safeParams).toString();
23372
- if (searchParams) {
23373
- fullPath += `?${searchParams}`;
23374
- }
23375
- }
23376
- if (navigation) {
23377
- navigation.push(fullPath);
23378
- } else {
23379
- if (typeof window !== "undefined") {
23380
- window.location.href = fullPath;
23381
- }
23382
- }
23383
- }
23384
- var getCurrentPath = () => {
23385
- if (typeof window === "undefined") return "";
23386
- return window.location.pathname;
23387
- };
23388
- var getSearchParams = () => {
23389
- if (typeof window === "undefined") return new URLSearchParams();
23390
- return new URLSearchParams(window.location.search);
23391
- };
23392
- var safeNavigate = (name2, params = {}) => {
23393
- if (name2) {
23394
- navigate(name2, params);
23395
- } else {
23396
- console.warn("[CueKit] route name not provided");
23397
- }
23398
- };
23399
- function getCurrentScreenName() {
23400
- try {
23401
- const path2 = getCurrentPath();
23402
- return path2 || "UnknownScreen";
23403
- } catch (e3) {
23404
- return "UnknownScreen";
23405
- }
23406
- }
23407
- function getCurrentRouteParams() {
23408
- try {
23409
- const params = {};
23410
- const searchParams = getSearchParams();
23411
- if (searchParams instanceof URLSearchParams) {
23412
- searchParams.forEach((value, key) => {
23413
- params[key] = value;
23414
- });
23415
- } else {
23416
- return searchParams;
23417
- }
23418
- return params;
23419
- } catch (e3) {
23420
- return {};
23421
- }
23422
- }
23423
- function onStateChange() {
23424
- const routeName = getCurrentScreenName();
23425
- const params = getCurrentRouteParams();
23426
- if (params && params.metadata) {
23427
- try {
23428
- const metadata = JSON.parse(params.metadata);
23429
- GlobalStore.setMetadata(routeName, metadata);
23430
- } catch (error) {
23431
- console.error("Failed to parse metadata from URL:", error);
23432
- }
23433
- }
23434
- }
23435
- var handleNavigationAndClick = (routeName, elementHash) => {
23436
- safeNavigate(routeName);
23437
- if (typeof MutationObserver === "undefined" || typeof document === "undefined") return;
23438
- const observer = new MutationObserver((mutationsList, observer2) => {
23439
- setTimeout(() => {
23440
- const allElements = document.querySelectorAll("*");
23441
- let elementToClick = null;
23442
- for (const element3 of allElements) {
23443
- if (element3 instanceof HTMLElement) {
23444
- const tagName = element3.tagName.toLowerCase();
23445
- const text7 = (element3.textContent || "").trim().substring(0, 50);
23446
- let sibling = element3.previousElementSibling;
23447
- let position3 = 1;
23448
- while (sibling) {
23449
- if (sibling.tagName === element3.tagName) {
23450
- position3++;
23451
- }
23452
- sibling = sibling.previousElementSibling;
23453
- }
23454
- const path2 = getElementPath(element3);
23455
- const idString = `${tagName}[${position3}]_(${text7})_${path2}`;
23456
- let hash = 0;
23457
- for (let i2 = 0; i2 < idString.length; i2++) {
23458
- const char = idString.charCodeAt(i2);
23459
- hash = (hash << 5) - hash + char;
23460
- hash |= 0;
23461
- }
23462
- const elementHashValue = hash.toString(36);
23463
- if (elementHashValue === elementHash) {
23464
- elementToClick = element3;
23465
- break;
23466
- }
23467
- }
23468
- }
23469
- if (elementToClick) {
23470
- elementToClick.click();
23471
- observer2.disconnect();
23472
- }
23473
- }, 100);
23474
- });
23475
- observer.observe(document.body, { childList: true, subtree: true });
23476
- };
23477
- function getElementPath(element3) {
23478
- if (element3.id) {
23479
- return `id(${element3.id})`;
23480
- }
23481
- const path2 = [];
23482
- let current = element3;
23483
- while (current && current !== document.body) {
23484
- let index2 = 1;
23485
- let sibling = current.previousElementSibling;
23486
- while (sibling) {
23487
- if (sibling.tagName === current.tagName) {
23488
- index2++;
23489
- }
23490
- sibling = sibling.previousElementSibling;
23491
- }
23492
- path2.unshift(`${current.tagName.toLowerCase()}[${index2}]`);
23493
- current = current.parentElement;
23494
- }
23495
- return path2.join("/");
23496
- }
23782
+ // src/providers/cuekit-provider.tsx
23783
+ init_navigation();
23784
+ init_intent_store();
23497
23785
 
23498
23786
  // src/utils/webrtc-config.ts
23499
23787
  init_constants();
@@ -23725,7 +24013,7 @@ init_livekit_client_esm();
23725
24013
  init_webrtc_service();
23726
24014
  init_globals();
23727
24015
  var useWebRTC = (options) => {
23728
- const [isConnected4, setIsConnected] = (0, import_react2.useState)(false);
24016
+ const [isConnected2, setIsConnected] = (0, import_react2.useState)(false);
23729
24017
  const [isConnecting, setIsConnecting] = (0, import_react2.useState)(false);
23730
24018
  const [connectionState, setConnectionState] = (0, import_react2.useState)(null);
23731
24019
  const [participants, setParticipants] = (0, import_react2.useState)([]);
@@ -23789,7 +24077,7 @@ var useWebRTC = (options) => {
23789
24077
  return getParticipants().map((p) => p.identity);
23790
24078
  }, [participants]);
23791
24079
  return {
23792
- isConnected: isConnected4,
24080
+ isConnected: isConnected2,
23793
24081
  isConnecting,
23794
24082
  connectionState,
23795
24083
  room: room2,
@@ -23806,469 +24094,9 @@ var useWebRTC = (options) => {
23806
24094
  };
23807
24095
  };
23808
24096
 
23809
- // src/utils/sse-service.ts
23810
- init_constants();
23811
-
23812
- // src/utils/jsx-encoder.ts
23813
- function generateStableDOMId(element3) {
23814
- const tagName = element3.tagName.toLowerCase();
23815
- const text7 = (element3.textContent || "").trim().substring(0, 50);
23816
- let sibling = element3.previousElementSibling;
23817
- let position3 = 1;
23818
- while (sibling) {
23819
- if (sibling.tagName === element3.tagName) {
23820
- position3++;
23821
- }
23822
- sibling = sibling.previousElementSibling;
23823
- }
23824
- const path2 = getElementPath2(element3);
23825
- const idString = `${tagName}[${position3}]_(${text7})_${path2}`;
23826
- let hash = 0;
23827
- for (let i2 = 0; i2 < idString.length; i2++) {
23828
- const char = idString.charCodeAt(i2);
23829
- hash = (hash << 5) - hash + char;
23830
- hash |= 0;
23831
- }
23832
- return hash.toString(36);
23833
- }
23834
- function getElementPath2(element3) {
23835
- if (element3.id) {
23836
- return `id(${element3.id})`;
23837
- }
23838
- if (element3.tagName.toLowerCase() === "body") {
23839
- return "/body";
23840
- }
23841
- let ix = 0;
23842
- const siblings = element3.parentNode?.children || new HTMLCollection();
23843
- for (let i2 = 0; i2 < siblings.length; i2++) {
23844
- const sibling = siblings[i2];
23845
- if (sibling === element3) {
23846
- return `${getElementPath2(element3.parentNode)}/${element3.tagName}[${ix + 1}]`;
23847
- }
23848
- if (sibling.nodeType === 1 && sibling.tagName === element3.tagName) {
23849
- ix++;
23850
- }
23851
- }
23852
- return "not_found";
23853
- }
23854
-
23855
- // src/utils/patch-react.ts
23856
- function getImmediateText(element3) {
23857
- let text7 = "";
23858
- if (element3.childNodes) {
23859
- for (const node2 of Array.from(element3.childNodes)) {
23860
- if (node2.nodeType === 3) {
23861
- text7 += node2.textContent || "";
23862
- }
23863
- }
23864
- }
23865
- return text7.trim();
23866
- }
23867
- function captureFullDOMStructure() {
23868
- console.log("\u{1F333} Capturing full DOM structure...");
23869
- const components = [];
23870
- const interactiveElements = document.querySelectorAll(
23871
- 'a, button, input, textarea, select, [role="button"], [onclick]'
23872
- );
23873
- interactiveElements.forEach((element3) => {
23874
- if (element3 instanceof HTMLElement && !element3.closest("[data-cuekit-ignore]")) {
23875
- const nodeData = buildFlatDOMNode(element3);
23876
- if (nodeData) {
23877
- components.push(nodeData);
23878
- }
23879
- }
23880
- });
23881
- const result = { components };
23882
- console.log("\u{1F333} Full DOM structure captured:", result);
23883
- return result;
23884
- }
23885
- function buildFlatDOMNode(element3) {
23886
- if (element3.tagName.toLowerCase() === "script" || element3.hasAttribute("data-cuekit-ignore") || element3.style.display === "none" || element3.style.visibility === "hidden") {
23887
- return null;
23888
- }
23889
- const hash = generateStableDOMId(element3);
23890
- const text7 = getImmediateText(element3).substring(0, 100);
23891
- const isClickable = isElementClickable(element3);
23892
- const componentType = element3.tagName.toLowerCase();
23893
- return {
23894
- hash,
23895
- text: text7,
23896
- isClickable,
23897
- componentType,
23898
- children: []
23899
- // No children in a flat structure
23900
- };
23901
- }
23902
- function isElementClickable(element3) {
23903
- const interactiveSelectors = [
23904
- "button",
23905
- "a",
23906
- "input",
23907
- "select",
23908
- "textarea",
23909
- '[role="button"]',
23910
- '[role="link"]',
23911
- '[role="tab"]',
23912
- "[data-onclick-id]",
23913
- "[data-on-press-id]",
23914
- "[onclick]",
23915
- "[onmousedown]",
23916
- "[onmouseup]",
23917
- "[ontouchstart]",
23918
- "[ontouchend]",
23919
- "[onkeydown]",
23920
- "[onkeyup]",
23921
- "[onkeypress]"
23922
- ];
23923
- for (const selector of interactiveSelectors) {
23924
- if (element3.matches(selector)) {
23925
- return true;
23926
- }
23927
- }
23928
- const hasClickEvents = element3.onclick !== null || element3.getAttribute("onclick") !== null;
23929
- const hasInteractiveEvents = element3.ontouchstart !== null || element3.getAttribute("ontouchstart") !== null || element3.ontouchend !== null || element3.getAttribute("ontouchend") !== null || element3.onkeydown !== null || element3.getAttribute("onkeydown") !== null || element3.onkeyup !== null || element3.getAttribute("onkeyup") !== null || element3.onkeypress !== null || element3.getAttribute("onkeypress") !== null;
23930
- const hasPointerCursor = element3.style.cursor === "pointer" || getComputedStyle(element3).cursor === "pointer";
23931
- const hasTabIndex = element3.hasAttribute("tabindex") && parseInt(element3.getAttribute("tabindex") || "0") >= 0;
23932
- const hasInteractiveDataAttrs = element3.hasAttribute("data-clickable") || element3.hasAttribute("data-interactive") || element3.hasAttribute("data-action") || element3.hasAttribute("data-handler");
23933
- const hasInteractiveAria = element3.hasAttribute("aria-pressed") || element3.hasAttribute("aria-expanded") || element3.hasAttribute("aria-selected") || element3.hasAttribute("aria-checked");
23934
- return hasClickEvents || hasInteractiveEvents || hasPointerCursor || hasTabIndex || hasInteractiveDataAttrs || hasInteractiveAria;
23935
- }
23936
-
23937
- // src/utils/sse-service.ts
23938
- init_globals();
23939
- var eventSource2 = null;
23940
- var isConnected3 = false;
23941
- var serverUrl2 = WEBRTC_BACKEND_SERVER_URL || "https://bdd4c945f073.ngrok-free.app";
23942
- var callbacks2 = {};
23943
- var sessionId = null;
23944
- function setSSECallbacks(newCallbacks) {
23945
- callbacks2 = newCallbacks;
23946
- }
23947
- async function connectSSE(newSessionId) {
23948
- if (eventSource2) {
23949
- eventSource2.close();
23950
- }
23951
- if (typeof EventSource === "undefined") {
23952
- console.warn("\u{1F527} EventSource not available, SSE functionality disabled");
23953
- callbacks2.onError?.("EventSource not available");
23954
- return;
23955
- }
23956
- try {
23957
- const url = `${serverUrl2}/navigation/stream?session_id=${newSessionId}`;
23958
- eventSource2 = new EventSource(url);
23959
- sessionId = newSessionId;
23960
- eventSource2.onopen = () => {
23961
- console.log("\u{1F517} SSE connection opened");
23962
- isConnected3 = true;
23963
- callbacks2.onConnectionChange?.(true);
23964
- };
23965
- eventSource2.onmessage = (event) => {
23966
- console.log("\u{1F4E1} SSE MESSAGE RECEIVED:", event.data);
23967
- try {
23968
- const data = JSON.parse(event.data);
23969
- console.log("\u{1F4E1} SSE MESSAGE PARSED:", data);
23970
- handleSSEMessage(data);
23971
- } catch (error) {
23972
- console.error("\u274C Failed to parse SSE message:", error);
23973
- }
23974
- };
23975
- eventSource2.onerror = (error) => {
23976
- console.error("\u274C SSE connection error:", error);
23977
- isConnected3 = false;
23978
- callbacks2.onConnectionChange?.(false);
23979
- callbacks2.onError?.("SSE connection failed");
23980
- };
23981
- } catch (error) {
23982
- console.error("\u274C Failed to create SSE connection:", error);
23983
- callbacks2.onError?.("Failed to create SSE connection");
23984
- }
23985
- }
23986
- function handleSSEMessage(data) {
23987
- console.log("\u{1F50D} Processing SSE message type:", data.type);
23988
- console.log("\u{1F50D} Full SSE data:", data);
23989
- console.log("\u{1F50D} SSE data.data:", data.data);
23990
- const actionEvent = data;
23991
- console.log("\u{1F50D} Created action event:", actionEvent);
23992
- callbacks2.onActionEvent?.(actionEvent);
23993
- switch (actionEvent.type) {
23994
- case "static_data_ready":
23995
- console.log("\u{1F4E6} Handling static_data_ready event");
23996
- callbacks2.onStaticDataUpdate?.(actionEvent.data);
23997
- break;
23998
- case "ai_intent":
23999
- console.log("\u{1F3AF} Handling ai_intent event");
24000
- callbacks2.onIntentUpdate?.(actionEvent.data);
24001
- break;
24002
- case "request_runtime_data":
24003
- console.log("\u{1F4E6} Handling request_runtime_data event");
24004
- sendRuntimeData();
24005
- break;
24006
- case "user_speech_chunk":
24007
- console.log("\u{1F464} Handling user_speech_chunk event");
24008
- const userSpeechEntry = {
24009
- speaker: "user",
24010
- text: actionEvent.data?.text_chunk,
24011
- is_final: actionEvent.data?.is_final
24012
- };
24013
- callbacks2.onConversationUpdate?.(userSpeechEntry);
24014
- break;
24015
- case "ai_speech_chunk":
24016
- console.log("\u{1F916} Handling ai_speech_chunk event");
24017
- callbacks2.onConversationUpdate?.({
24018
- speaker: "ai",
24019
- text: actionEvent.data?.text_chunk,
24020
- is_final: actionEvent.data?.is_final
24021
- });
24022
- break;
24023
- case "ai_interrupted":
24024
- console.log("\u{1F507} Handling ai_interrupted event");
24025
- break;
24026
- case "tool_log":
24027
- console.log("\u{1F527} Handling tool_log event");
24028
- callbacks2.onToolStatusUpdate?.(actionEvent.data);
24029
- break;
24030
- case "connection":
24031
- console.log("\u{1F517} Handling connection event");
24032
- break;
24033
- case "keepalive":
24034
- console.log("\u{1F493} Handling keepalive event");
24035
- break;
24036
- default:
24037
- console.log("\u{1F50D} Unknown SSE message type:", data.type);
24038
- }
24039
- }
24040
- async function sendRuntimeData() {
24041
- if (!sessionId) {
24042
- console.error("\u274C Cannot send runtime data without a session ID");
24043
- return;
24044
- }
24045
- try {
24046
- const domStructure = captureFullDOMStructure();
24047
- const screenName = getCurrentScreenName();
24048
- const response = await fetch(`${serverUrl2}/api/runtime/data/${sessionId}`, {
24049
- method: "POST",
24050
- headers: {
24051
- "Content-Type": "application/json",
24052
- Authorization: `Bearer ${_apiKey}`
24053
- },
24054
- body: JSON.stringify({
24055
- session_id: sessionId,
24056
- components: domStructure.components,
24057
- screen: screenName
24058
- })
24059
- });
24060
- if (!response.ok) {
24061
- const errorData = await response.json();
24062
- throw new Error(errorData.detail || "Failed to send runtime data");
24063
- }
24064
- console.log("\u{1F4E6} Runtime data sent successfully");
24065
- } catch (error) {
24066
- console.error("\u274C Failed to send runtime data:", error);
24067
- callbacks2.onError?.("Failed to send runtime data");
24068
- }
24069
- }
24070
- async function sendDashboardData(dashboardData) {
24071
- try {
24072
- console.log("\u{1F4E4} SSEService: Sending dashboard data...");
24073
- const response = await fetch(`${serverUrl2}/ai/data`, {
24074
- method: "POST",
24075
- headers: {
24076
- "Content-Type": "application/json"
24077
- },
24078
- body: JSON.stringify({
24079
- type: "dashboard_data",
24080
- data: dashboardData
24081
- })
24082
- });
24083
- if (!response.ok) {
24084
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
24085
- }
24086
- console.log("\u2705 SSEService: Dashboard data sent successfully");
24087
- } catch (error) {
24088
- console.error("\u274C SSEService: Failed to send dashboard data:", error);
24089
- }
24090
- }
24091
- async function sendElementData(appId = "default") {
24092
- try {
24093
- console.log("\u{1F4E4} SSEService: Sending element data...");
24094
- const domStructure = captureFullDOMStructure();
24095
- const currentPage = getCurrentScreenName();
24096
- const elementData = {
24097
- app_id: appId,
24098
- current_page: currentPage,
24099
- dom_structure: domStructure,
24100
- timestamp: Date.now()
24101
- };
24102
- const response = await fetch(`${serverUrl2}/ai/data`, {
24103
- method: "POST",
24104
- headers: {
24105
- "Content-Type": "application/json"
24106
- },
24107
- body: JSON.stringify(elementData)
24108
- });
24109
- if (!response.ok) {
24110
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
24111
- }
24112
- console.log("\u2705 SSEService: Element data sent successfully");
24113
- return elementData;
24114
- } catch (error) {
24115
- console.error("\u274C SSEService: Failed to send element data:", error);
24116
- throw error;
24117
- }
24118
- }
24119
- function disconnectSSE() {
24120
- console.log("\u{1F50C} SSEService: Disconnecting SSE...");
24121
- if (eventSource2) {
24122
- eventSource2.close();
24123
- eventSource2 = null;
24124
- }
24125
- isConnected3 = false;
24126
- callbacks2.onConnectionChange?.(false);
24127
- }
24128
- function getSSEConnectionStatus() {
24129
- return isConnected3 && eventSource2?.readyState === EventSource.OPEN;
24130
- }
24131
- function getSSEConnectionState() {
24132
- if (isConnected3 && eventSource2?.readyState === EventSource.OPEN) return "connected";
24133
- if (eventSource2?.readyState === EventSource.CONNECTING) return "connecting";
24134
- return "disconnected";
24135
- }
24136
-
24137
- // src/utils/element-service.ts
24138
- function executeAction(action) {
24139
- console.log("\u{1F3AF} Executing element action:", action);
24140
- const { action_type, target_element, target } = action;
24141
- switch (action_type) {
24142
- case "click":
24143
- return clickElement(target_element);
24144
- case "navigate":
24145
- return navigateToElement(target_element || target);
24146
- case "input":
24147
- case "focus":
24148
- return focusElement(target_element);
24149
- case "toggle":
24150
- return toggleElement(target_element);
24151
- default:
24152
- console.warn(`\u26A0\uFE0F Unknown action type: ${action_type}`);
24153
- return false;
24154
- }
24155
- }
24156
- function getFullDOMStructure() {
24157
- console.log("\u{1F333} ElementService: Getting full DOM structure...");
24158
- return captureFullDOMStructure();
24159
- }
24160
- function clickElement(elementId) {
24161
- if (!elementId) {
24162
- console.warn("\u26A0\uFE0F No element ID provided for click action");
24163
- return false;
24164
- }
24165
- const domStructure = getFullDOMStructure();
24166
- const elementToClick = findElementById(domStructure, elementId);
24167
- if (elementToClick) {
24168
- console.log(`\u{1F3AF} Clicking element: ${elementId}`);
24169
- const domElement = findDOMElementById(elementId);
24170
- if (domElement) {
24171
- domElement.click();
24172
- return true;
24173
- }
24174
- } else {
24175
- console.warn(`\u26A0\uFE0F Element not found: ${elementId}`);
24176
- }
24177
- return false;
24178
- }
24179
- function navigateToElement(target) {
24180
- if (!target) {
24181
- console.warn("\u26A0\uFE0F No target provided for navigation action");
24182
- return false;
24183
- }
24184
- console.log(`\u{1F9ED} Navigating to: ${target}`);
24185
- if (target.includes("/") || target.startsWith("http")) {
24186
- safeNavigate(target, {});
24187
- } else {
24188
- handleNavigationAndClick(target, target);
24189
- }
24190
- return true;
24191
- }
24192
- function focusElement(elementId) {
24193
- if (!elementId) {
24194
- console.warn("\u26A0\uFE0F No element ID provided for focus action");
24195
- return false;
24196
- }
24197
- const domElement = findDOMElementById(elementId);
24198
- if (domElement instanceof HTMLInputElement || domElement instanceof HTMLTextAreaElement || domElement instanceof HTMLSelectElement) {
24199
- console.log(`\u{1F4DD} Focusing element: ${elementId}`);
24200
- domElement.focus();
24201
- return true;
24202
- } else {
24203
- console.warn(`\u26A0\uFE0F Focusable element not found: ${elementId}`);
24204
- return false;
24205
- }
24206
- }
24207
- function toggleElement(elementId) {
24208
- if (!elementId) {
24209
- console.warn("\u26A0\uFE0F No element ID provided for toggle action");
24210
- return false;
24211
- }
24212
- const domElement = findDOMElementById(elementId);
24213
- if (domElement instanceof HTMLElement) {
24214
- console.log(`\u{1F504} Toggling element: ${elementId}`);
24215
- if (domElement instanceof HTMLInputElement) {
24216
- if (domElement.type === "checkbox") {
24217
- domElement.checked = !domElement.checked;
24218
- } else if (domElement.type === "radio") {
24219
- domElement.checked = true;
24220
- }
24221
- domElement.dispatchEvent(new Event("change", { bubbles: true }));
24222
- } else {
24223
- domElement.click();
24224
- }
24225
- return true;
24226
- } else {
24227
- console.warn(`\u26A0\uFE0F Toggleable element not found: ${elementId}`);
24228
- return false;
24229
- }
24230
- }
24231
- function findElementById(domStructure, elementId) {
24232
- const searchInComponents = (components) => {
24233
- for (const component of components) {
24234
- if (component.hash === elementId) {
24235
- return component;
24236
- }
24237
- if (component.children.length > 0) {
24238
- const found = searchInComponents(component.children);
24239
- if (found) return found;
24240
- }
24241
- }
24242
- return null;
24243
- };
24244
- return searchInComponents(domStructure.components);
24245
- }
24246
- function findDOMElementById(elementId) {
24247
- const allElements = document.querySelectorAll("*");
24248
- for (const element3 of allElements) {
24249
- if (element3 instanceof HTMLElement) {
24250
- const hash = generateHash(element3);
24251
- if (hash === elementId) {
24252
- return element3;
24253
- }
24254
- }
24255
- }
24256
- return null;
24257
- }
24258
- function generateHash(element3) {
24259
- const tagName = element3.tagName.toLowerCase();
24260
- const text7 = (element3.textContent || "").trim().substring(0, 50);
24261
- const idString = `${tagName}_${text7}_${element3.tagName}`;
24262
- let hash = 0;
24263
- for (let i2 = 0; i2 < idString.length; i2++) {
24264
- const char = idString.charCodeAt(i2);
24265
- hash = (hash << 5) - hash + char;
24266
- hash |= 0;
24267
- }
24268
- return hash.toString(36);
24269
- }
24270
-
24271
24097
  // src/hooks/use-cuekit.ts
24098
+ init_webrtc_service();
24099
+ init_element_service();
24272
24100
  var useCuekit = (options) => {
24273
24101
  const [messages, setMessages] = (0, import_react3.useState)([]);
24274
24102
  const currentUserMessageRef = (0, import_react3.useRef)(null);
@@ -24319,89 +24147,85 @@ var useCuekit = (options) => {
24319
24147
  }, []);
24320
24148
  const [micState, setMicState] = (0, import_react3.useState)("idle");
24321
24149
  const [status, setStatus] = (0, import_react3.useState)("");
24322
- const [isSseConnected, setIsSseConnected] = (0, import_react3.useState)(false);
24323
- const [lastActionEvent, setLastActionEvent] = (0, import_react3.useState)(null);
24324
- (0, import_react3.useEffect)(() => {
24325
- setSSECallbacks({
24326
- onActionEvent: (event) => {
24327
- setLastActionEvent(event);
24328
- switch (event.type) {
24329
- case "user_speech_chunk":
24330
- case "ai_speech_chunk": {
24331
- const role = event.type === "user_speech_chunk" ? "user" : "ai";
24332
- if (role === "user" && currentAIMessageRef.current) {
24333
- const finalMessageId = currentAIMessageRef.current.id;
24334
- setMessages(
24335
- (prev) => prev.map((m) => m.id === finalMessageId ? { ...m, isFinal: true } : m)
24336
- );
24337
- currentAIMessageRef.current = null;
24338
- }
24339
- if (role === "ai" && currentUserMessageRef.current) {
24340
- const finalMessageId = currentUserMessageRef.current.id;
24341
- setMessages(
24342
- (prev) => prev.map((m) => m.id === finalMessageId ? { ...m, isFinal: true } : m)
24343
- );
24344
- currentUserMessageRef.current = null;
24345
- }
24346
- const entry = {
24347
- speaker: role,
24348
- text: event.data.text_chunk,
24349
- is_final: event.data.is_final,
24350
- timestamp: new Date(event.timestamp || Date.now()).toISOString()
24351
- };
24352
- handleMessageChunk(entry.text, entry.speaker, entry.is_final);
24353
- if (entry.is_final) {
24354
- if (entry.speaker === "user") {
24355
- setMicState("thinking");
24356
- } else if (entry.speaker === "ai") {
24357
- setTimeout(() => setMicState("listening"), 1e3);
24358
- }
24359
- }
24360
- break;
24361
- }
24362
- case "ai_intent": {
24363
- const intent = event.data;
24364
- if (intent.actionType === "click" && intent.actionMetadata.elementId) {
24365
- executeAction({
24366
- action_type: "click",
24367
- target_element: intent.actionMetadata.elementId
24368
- });
24369
- } else if (intent.actionType === "navigate" && intent.actionMetadata.routeName) {
24370
- executeAction({
24371
- action_type: "navigate",
24372
- target_element: intent.actionMetadata.routeName
24373
- });
24374
- }
24375
- break;
24376
- }
24377
- case "ai_interrupted": {
24378
- handleAIInterruption();
24379
- break;
24380
- }
24381
- case "keepalive": {
24382
- if (currentUserMessageRef.current) {
24383
- const finalMessageId = currentUserMessageRef.current.id;
24384
- setMessages(
24385
- (prev) => prev.map((m) => m.id === finalMessageId ? { ...m, isFinal: true } : m)
24386
- );
24387
- currentUserMessageRef.current = null;
24388
- }
24389
- if (currentAIMessageRef.current) {
24390
- const finalMessageId = currentAIMessageRef.current.id;
24391
- setMessages(
24392
- (prev) => prev.map((m) => m.id === finalMessageId ? { ...m, isFinal: true } : m)
24393
- );
24394
- currentAIMessageRef.current = null;
24395
- }
24396
- break;
24150
+ const handleNavigationCommand = (event) => {
24151
+ console.log(`\u{1F9E0} Processing event in useCuekit: ${event.type}`, event);
24152
+ switch (event.type) {
24153
+ case "user_speech_chunk":
24154
+ case "ai_speech_chunk": {
24155
+ const role = event.type === "user_speech_chunk" ? "user" : "ai";
24156
+ if (role === "user" && currentAIMessageRef.current) {
24157
+ const finalMessageId = currentAIMessageRef.current.id;
24158
+ setMessages(
24159
+ (prev) => prev.map((m) => m.id === finalMessageId ? { ...m, isFinal: true } : m)
24160
+ );
24161
+ currentAIMessageRef.current = null;
24162
+ }
24163
+ if (role === "ai" && currentUserMessageRef.current) {
24164
+ const finalMessageId = currentUserMessageRef.current.id;
24165
+ setMessages(
24166
+ (prev) => prev.map((m) => m.id === finalMessageId ? { ...m, isFinal: true } : m)
24167
+ );
24168
+ currentUserMessageRef.current = null;
24169
+ }
24170
+ const entry = {
24171
+ speaker: role,
24172
+ text: event.data.text_chunk,
24173
+ is_final: event.data.is_final,
24174
+ timestamp: new Date(event.timestamp || Date.now()).toISOString()
24175
+ };
24176
+ handleMessageChunk(entry.text, entry.speaker, entry.is_final);
24177
+ if (entry.is_final) {
24178
+ if (entry.speaker === "user") {
24179
+ setMicState("thinking");
24180
+ } else if (entry.speaker === "ai") {
24181
+ setTimeout(() => setMicState("listening"), 1e3);
24397
24182
  }
24398
24183
  }
24399
- },
24400
- onConnectionChange: (isConnected4) => {
24401
- setIsSseConnected(isConnected4);
24184
+ break;
24402
24185
  }
24403
- });
24404
- }, [handleMessageChunk, handleAIInterruption]);
24186
+ case "ai_intent": {
24187
+ const intent = event.data;
24188
+ if (intent.actionType === "click" && intent.actionMetadata.elementId) {
24189
+ executeAction({
24190
+ action_type: "click",
24191
+ target_element: intent.actionMetadata.elementId
24192
+ });
24193
+ } else if (intent.actionType === "navigate" && intent.actionMetadata.routeName) {
24194
+ executeAction({
24195
+ action_type: "navigate",
24196
+ target_element: intent.actionMetadata.routeName
24197
+ });
24198
+ }
24199
+ break;
24200
+ }
24201
+ case "request_runtime_data": {
24202
+ console.log("\u{1F9E0} Requesting runtime data");
24203
+ sendRuntimeData();
24204
+ break;
24205
+ }
24206
+ case "ai_interrupted": {
24207
+ handleAIInterruption();
24208
+ break;
24209
+ }
24210
+ case "keepalive": {
24211
+ if (currentUserMessageRef.current) {
24212
+ const finalMessageId = currentUserMessageRef.current.id;
24213
+ setMessages(
24214
+ (prev) => prev.map((m) => m.id === finalMessageId ? { ...m, isFinal: true } : m)
24215
+ );
24216
+ currentUserMessageRef.current = null;
24217
+ }
24218
+ if (currentAIMessageRef.current) {
24219
+ const finalMessageId = currentAIMessageRef.current.id;
24220
+ setMessages(
24221
+ (prev) => prev.map((m) => m.id === finalMessageId ? { ...m, isFinal: true } : m)
24222
+ );
24223
+ currentAIMessageRef.current = null;
24224
+ }
24225
+ break;
24226
+ }
24227
+ }
24228
+ };
24405
24229
  const handleConnectionStateChange = (state) => {
24406
24230
  switch (state) {
24407
24231
  case "connecting":
@@ -24425,32 +24249,22 @@ var useCuekit = (options) => {
24425
24249
  };
24426
24250
  const webrtc = useWebRTC({
24427
24251
  ...options,
24428
- onConnectionStateChange: handleConnectionStateChange
24252
+ onConnectionStateChange: handleConnectionStateChange,
24253
+ onNavigationCommand: handleNavigationCommand
24429
24254
  });
24430
24255
  const connect = (0, import_react3.useCallback)(
24431
24256
  async (identity, apiKey, appId) => {
24432
- const authData = await webrtc.connect(identity, apiKey, appId);
24433
- if (authData?.session_id) {
24434
- connectSSE(authData.session_id);
24435
- }
24257
+ await webrtc.connect(identity, apiKey, appId);
24436
24258
  },
24437
24259
  [webrtc]
24438
24260
  );
24439
24261
  const disconnect = (0, import_react3.useCallback)(async () => {
24440
24262
  await webrtc.disconnect();
24441
- disconnectSSE();
24442
24263
  clearMessages();
24443
24264
  setMicState("idle");
24444
24265
  }, [webrtc, clearMessages]);
24445
- (0, import_react3.useEffect)(() => {
24446
- if (lastActionEvent?.type === "ai_interrupted") {
24447
- handleAIInterruption();
24448
- }
24449
- }, [lastActionEvent, handleAIInterruption]);
24450
24266
  return {
24451
24267
  ...webrtc,
24452
- isSseConnected,
24453
- lastActionEvent,
24454
24268
  messages,
24455
24269
  micState,
24456
24270
  setMicState,
@@ -37216,7 +37030,7 @@ var ChatPopup = ({
37216
37030
  onSendText,
37217
37031
  onEndCall,
37218
37032
  messages,
37219
- isConnected: isConnected4,
37033
+ isConnected: isConnected2,
37220
37034
  micState,
37221
37035
  error,
37222
37036
  currentTheme = "dark",
@@ -37803,7 +37617,7 @@ var ChatPopup = ({
37803
37617
  }
37804
37618
  }
37805
37619
  ),
37806
- isConnected4 && onEndCall && /* @__PURE__ */ import_react9.default.createElement(
37620
+ isConnected2 && onEndCall && /* @__PURE__ */ import_react9.default.createElement(
37807
37621
  "button",
37808
37622
  {
37809
37623
  type: "submit",
@@ -40002,13 +39816,12 @@ var MicButton = ({
40002
39816
  const aiSpeechTimeoutRef = (0, import_react15.useRef)(null);
40003
39817
  const activeAITracksRef = (0, import_react15.useRef)(/* @__PURE__ */ new Set());
40004
39818
  const {
40005
- isConnected: isConnected4,
39819
+ isConnected: isConnected2,
40006
39820
  isConnecting,
40007
39821
  error: voiceError,
40008
39822
  connect: voiceConnect,
40009
39823
  disconnect: voiceDisconnect,
40010
39824
  sendUserCommand: sendUserCommand2,
40011
- lastActionEvent,
40012
39825
  messages: messageManagerMessages,
40013
39826
  micState,
40014
39827
  setMicState,
@@ -40088,8 +39901,8 @@ var MicButton = ({
40088
39901
  console.log("\u{1F3A4} MicButton: Current active AI tracks:", Array.from(activeAITracksRef.current));
40089
39902
  console.log("\u{1F3A4} MicButton: Current status:", status);
40090
39903
  console.log("\u{1F3A4} MicButton: Current mic state:", micState);
40091
- console.log("\u{1F3A4} MicButton: Is listening:", isConnected4);
40092
- console.log("\u{1F3A4} MicButton: Is connected:", isConnected4);
39904
+ console.log("\u{1F3A4} MicButton: Is listening:", isConnected2);
39905
+ console.log("\u{1F3A4} MicButton: Is connected:", isConnected2);
40093
39906
  if (isSpeaking && trackId) {
40094
39907
  console.log("\u{1F3A4} MicButton: ===== AI SPEECH START =====");
40095
39908
  console.log("\u{1F3A4} MicButton: Adding track to active set:", trackId);
@@ -40144,7 +39957,7 @@ var MicButton = ({
40144
39957
  console.log("\u{1F3A4} MicButton: - Status:", status);
40145
39958
  console.log("\u{1F3A4} MicButton: ================================");
40146
39959
  },
40147
- [status, micState, isConnected4]
39960
+ [status, micState, isConnected2]
40148
39961
  );
40149
39962
  (0, import_react15.useEffect)(() => {
40150
39963
  if (audioContainerRef2.current) {
@@ -40157,10 +39970,9 @@ var MicButton = ({
40157
39970
  }
40158
39971
  };
40159
39972
  }, [handleAISpeech]);
40160
- const isListening = isConnected4;
40161
- const transcript = (lastActionEvent?.type === "user_speech_chunk" || lastActionEvent?.type === "ai_speech_chunk") && lastActionEvent?.data?.text_chunk ? lastActionEvent.data.text_chunk : "";
40162
- const getUserFriendlyStatus = (micState2, isConnected5) => {
40163
- if (!isConnected5) {
39973
+ const isListening = isConnected2;
39974
+ const getUserFriendlyStatus = (micState2, isConnected3) => {
39975
+ if (!isConnected3) {
40164
39976
  return "Connecting...";
40165
39977
  }
40166
39978
  if (status && !status.includes("error") && !status.includes("failed") && !status.includes("Connection error") && !status.includes("Unable to")) {
@@ -40170,28 +39982,28 @@ var MicButton = ({
40170
39982
  if (micState2 === "thinking") return "Thinking...";
40171
39983
  if (micState2 === "replying") return "Responding...";
40172
39984
  if (micState2 === "idle") {
40173
- if (isConnected5) return "Listening...";
39985
+ if (isConnected3) return "Listening...";
40174
39986
  return "Connecting...";
40175
39987
  }
40176
- return isConnected5 ? "Ready" : "Connecting...";
39988
+ return isConnected3 ? "Ready" : "Connecting...";
40177
39989
  };
40178
39990
  (0, import_react15.useEffect)(() => {
40179
- if (isConnected4) {
39991
+ if (isConnected2) {
40180
39992
  console.log("\u{1F3A4} MicButton: WebRTC and SSE connections established - ready for commands");
40181
39993
  } else {
40182
39994
  console.log("\u{1F3A4} MicButton: WebRTC not yet connected - ignoring speech");
40183
39995
  }
40184
- }, [isConnected4]);
39996
+ }, [isConnected2]);
40185
39997
  (0, import_react15.useEffect)(() => {
40186
39998
  console.log("\u{1F3A4} MicButton: Auto-open check:", {
40187
- isConnected: isConnected4,
39999
+ isConnected: isConnected2,
40188
40000
  chatIsOpen: isChatOpen
40189
40001
  });
40190
- if (isConnected4 && !isChatOpen) {
40002
+ if (isConnected2 && !isChatOpen) {
40191
40003
  console.log("\u{1F3A4} MicButton: Auto-opening chat popup");
40192
40004
  openChat();
40193
40005
  }
40194
- }, [isConnected4, isChatOpen, openChat]);
40006
+ }, [isConnected2, isChatOpen, openChat]);
40195
40007
  (0, import_react15.useEffect)(() => {
40196
40008
  if (messageManagerMessages.length > 0 && !isChatOpen) {
40197
40009
  console.log("\u{1F3A4} MicButton: Auto-opening chat popup due to messages");
@@ -40199,7 +40011,7 @@ var MicButton = ({
40199
40011
  }
40200
40012
  }, [messageManagerMessages.length, isChatOpen, openChat]);
40201
40013
  const handleMicClick = (0, import_react15.useCallback)(() => {
40202
- const shouldStop = micState === "listening" && isConnected4;
40014
+ const shouldStop = micState === "listening" && isConnected2;
40203
40015
  if (shouldStop) {
40204
40016
  console.log("\u{1F3A4} MicButton: User wants to stop - closing everything");
40205
40017
  voiceDisconnect().then(() => {
@@ -40224,7 +40036,7 @@ var MicButton = ({
40224
40036
  }
40225
40037
  }, [
40226
40038
  micState,
40227
- isConnected4,
40039
+ isConnected2,
40228
40040
  voiceDisconnect,
40229
40041
  voiceConnect,
40230
40042
  apiKey,
@@ -40232,19 +40044,6 @@ var MicButton = ({
40232
40044
  openChat,
40233
40045
  showBorderGlow
40234
40046
  ]);
40235
- (0, import_react15.useEffect)(() => {
40236
- if (!isConnected4) {
40237
- return;
40238
- }
40239
- if (transcript && transcript.trim() && !aiSpeakingRef.current) {
40240
- console.log("\u{1F3A4} MicButton: Processing new transcript:", transcript);
40241
- sendUserCommand2(transcript).then(() => {
40242
- console.log("\u{1F3A4} MicButton: User command sent successfully");
40243
- }).catch((error) => {
40244
- console.error("\u{1F3A4} MicButton: Failed to send user command:", error);
40245
- });
40246
- }
40247
- }, [transcript, isConnected4, sendUserCommand2]);
40248
40047
  const handleSendText = async (textToSend) => {
40249
40048
  console.log("\u{1F3A4} MicButton: handleSendText called with:", textToSend);
40250
40049
  setMicState("thinking");
@@ -40252,7 +40051,7 @@ var MicButton = ({
40252
40051
  if (!isChatOpen) {
40253
40052
  openChat();
40254
40053
  }
40255
- if (isConnected4) {
40054
+ if (isConnected2) {
40256
40055
  console.log("\u{1F3A4} MicButton: Sending via WebRTC");
40257
40056
  try {
40258
40057
  await sendUserCommand2(textToSend);
@@ -40449,13 +40248,13 @@ var MicButton = ({
40449
40248
  text: msg.text,
40450
40249
  sender: msg.role === "ai" ? "assistant" : "user"
40451
40250
  })),
40452
- isConnected: isConnected4 ?? false,
40251
+ isConnected: isConnected2 ?? false,
40453
40252
  micState,
40454
40253
  participants,
40455
40254
  error: voiceError,
40456
40255
  currentTheme,
40457
40256
  onThemeToggle: setCurrentTheme,
40458
- status: getUserFriendlyStatus(micState, isConnected4 ?? false),
40257
+ status: getUserFriendlyStatus(micState, isConnected2 ?? false),
40459
40258
  anchor: { position: screenPosition, bottom: bottomSpace, size: buttonSize }
40460
40259
  }
40461
40260
  ), isChatOpen && isChatMinimized && /* @__PURE__ */ import_react15.default.createElement(
@@ -40482,3 +40281,7 @@ var MicButton = ({
40482
40281
  /* @__PURE__ */ import_react15.default.createElement("span", { style: { fontSize: 12, fontWeight: 600, color: "hsl(var(--voice-text))" } }, "Open chat")
40483
40282
  ), /* @__PURE__ */ import_react15.default.createElement("div", { ref: audioContainerRef2, style: { display: "none" } }), showBorderGlow && showBodyGlow && /* @__PURE__ */ import_react15.default.createElement(border_glow_default, { isActive: true }));
40484
40283
  };
40284
+
40285
+ // src/index.ts
40286
+ init_element_service();
40287
+ init_element_service();