@contentgrowth/llm-service 0.9.98 → 1.0.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.
@@ -148,303 +148,19 @@ function ChatHeader({
148
148
  }
149
149
 
150
150
  // src/ui/react/components/ChatInputArea.tsx
151
- import { useState as useState3, useRef as useRef3, useImperativeHandle, forwardRef, useEffect as useEffect3, useCallback as useCallback3, useLayoutEffect } from "react";
151
+ import { useState as useState2, useRef as useRef2, useImperativeHandle, forwardRef, useEffect as useEffect2, useCallback as useCallback2, useLayoutEffect } from "react";
152
152
  import { MicrophoneIcon, StopIcon, PaperAirplaneIcon, XMarkIcon, Square2StackIcon } from "@heroicons/react/24/outline";
153
153
 
154
- // src/ui/react/hooks/useSpeechRecognition.ts
155
- import { useState, useEffect, useCallback, useRef } from "react";
156
- var useSpeechRecognition = (onResult, onEnd, language = "en-US") => {
157
- const [isListening, setIsListening] = useState(false);
158
- const [transcript, setTranscript] = useState("");
159
- const [error, setError] = useState(null);
160
- const [isSupported, setIsSupported] = useState(false);
161
- const recognitionRef = useRef(null);
162
- const isSimulatingRef = useRef(false);
163
- const simulationTimeoutRef = useRef(null);
164
- const languageRef = useRef(language);
165
- const instanceIdRef = useRef(Math.random().toString(36).slice(2));
166
- const lastStartAtRef = useRef(null);
167
- const lastStopAtRef = useRef(null);
168
- const onResultRef = useRef(onResult);
169
- const onEndRef = useRef(onEnd);
170
- useEffect(() => {
171
- onResultRef.current = onResult;
172
- onEndRef.current = onEnd;
173
- }, [onResult, onEnd]);
174
- useEffect(() => {
175
- languageRef.current = language;
176
- if (recognitionRef.current) {
177
- console.log("[useSpeechRecognition] Updating language to:", language);
178
- recognitionRef.current.lang = language;
179
- }
180
- }, [language]);
181
- const isStartingRef = useRef(false);
182
- useEffect(() => {
183
- var _a;
184
- if (typeof window !== "undefined") {
185
- const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
186
- console.log("[useSpeechRecognition] Env - isSecureContext:", window.isSecureContext, "protocol:", (_a = window.location) == null ? void 0 : _a.protocol);
187
- const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || "ontouchstart" in window || navigator.maxTouchPoints > 0;
188
- console.log("[useSpeechRecognition] Init check - SpeechRecognition available:", !!SpeechRecognition, "isMobile:", isMobile, "instanceId:", instanceIdRef.current);
189
- setIsSupported(!!SpeechRecognition);
190
- }
191
- return () => {
192
- console.log("[useSpeechRecognition] Effect cleanup - stopping recognition");
193
- if (isSimulatingRef.current && simulationTimeoutRef.current) {
194
- clearTimeout(simulationTimeoutRef.current);
195
- simulationTimeoutRef.current = null;
196
- }
197
- if (recognitionRef.current) {
198
- try {
199
- recognitionRef.current.stop();
200
- } catch (e) {
201
- }
202
- recognitionRef.current = null;
203
- }
204
- if (typeof window !== "undefined") {
205
- const w = window;
206
- if (w.__llmSpeechRecognitionActiveInstanceId === instanceIdRef.current) {
207
- console.log("[useSpeechRecognition] Cleanup clearing global active instance lock. instanceId:", instanceIdRef.current);
208
- w.__llmSpeechRecognitionActiveInstanceId = null;
209
- }
210
- }
211
- };
212
- }, []);
213
- const createRecognitionInstance = useCallback(() => {
214
- const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
215
- if (!SpeechRecognition) {
216
- console.error("[useSpeechRecognition] SpeechRecognition not available");
217
- return null;
218
- }
219
- console.log("[useSpeechRecognition] Creating NEW recognition instance within user gesture context. Timestamp:", Date.now());
220
- const recognition = new SpeechRecognition();
221
- const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || "ontouchstart" in window || navigator.maxTouchPoints > 0;
222
- recognition.continuous = !isMobile;
223
- recognition.interimResults = true;
224
- recognition.lang = languageRef.current;
225
- console.log("[useSpeechRecognition] Instance created. continuous:", recognition.continuous, "interimResults:", recognition.interimResults, "lang:", recognition.lang, "isMobile:", isMobile, "instanceId:", instanceIdRef.current);
226
- recognition.onaudiostart = () => {
227
- console.log("[useSpeechRecognition] Native onaudiostart. Timestamp:", Date.now(), "instanceId:", instanceIdRef.current);
228
- };
229
- recognition.onaudioend = () => {
230
- console.log("[useSpeechRecognition] Native onaudioend. Timestamp:", Date.now(), "instanceId:", instanceIdRef.current);
231
- };
232
- recognition.onsoundstart = () => {
233
- console.log("[useSpeechRecognition] Native onsoundstart. Timestamp:", Date.now(), "instanceId:", instanceIdRef.current);
234
- };
235
- recognition.onsoundend = () => {
236
- console.log("[useSpeechRecognition] Native onsoundend. Timestamp:", Date.now(), "instanceId:", instanceIdRef.current);
237
- };
238
- recognition.onspeechstart = () => {
239
- console.log("[useSpeechRecognition] Native onspeechstart. Timestamp:", Date.now(), "instanceId:", instanceIdRef.current);
240
- };
241
- recognition.onspeechend = () => {
242
- console.log("[useSpeechRecognition] Native onspeechend. Timestamp:", Date.now(), "instanceId:", instanceIdRef.current);
243
- };
244
- recognition.onnomatch = () => {
245
- console.log("[useSpeechRecognition] Native onnomatch. Timestamp:", Date.now(), "instanceId:", instanceIdRef.current);
246
- };
247
- recognition.onstart = () => {
248
- console.log("[useSpeechRecognition] Native onstart event fired. Timestamp:", Date.now());
249
- isStartingRef.current = false;
250
- setIsListening(true);
251
- setError(null);
252
- if (typeof window !== "undefined") {
253
- const w = window;
254
- w.__llmSpeechRecognitionActiveInstanceId = instanceIdRef.current;
255
- console.log("[useSpeechRecognition] Set global active instance lock. instanceId:", instanceIdRef.current);
256
- }
257
- };
258
- recognition.onend = () => {
259
- console.log("[useSpeechRecognition] Native onend event fired. Timestamp:", Date.now());
260
- isStartingRef.current = false;
261
- if (recognitionRef.current === recognition) {
262
- console.log("[useSpeechRecognition] Nullifying recognitionRef (onend)");
263
- recognitionRef.current = null;
264
- }
265
- if (isSimulatingRef.current) {
266
- console.log("[useSpeechRecognition] onend ignored - simulating");
267
- return;
268
- }
269
- setIsListening(false);
270
- if (onEndRef.current) onEndRef.current();
271
- if (typeof window !== "undefined") {
272
- const w = window;
273
- if (w.__llmSpeechRecognitionActiveInstanceId === instanceIdRef.current) {
274
- w.__llmSpeechRecognitionActiveInstanceId = null;
275
- console.log("[useSpeechRecognition] Cleared global active instance lock. instanceId:", instanceIdRef.current);
276
- }
277
- }
278
- };
279
- recognition.onresult = (event) => {
280
- console.log("[useSpeechRecognition] onresult event. results count:", event.results.length);
281
- let interimTranscript = "";
282
- let finalTranscript = "";
283
- for (let i = event.results.length - 1; i < event.results.length; ++i) {
284
- const result = event.results[i];
285
- if (result.isFinal) {
286
- finalTranscript += result[0].transcript;
287
- console.log("[useSpeechRecognition] Final transcript:", finalTranscript);
288
- if (onResultRef.current) onResultRef.current(finalTranscript, true);
289
- } else {
290
- interimTranscript += result[0].transcript;
291
- console.log("[useSpeechRecognition] Interim transcript:", interimTranscript);
292
- if (onResultRef.current) onResultRef.current(interimTranscript, false);
293
- }
294
- }
295
- setTranscript((prev) => prev + finalTranscript);
296
- };
297
- recognition.onerror = (event) => {
298
- console.error("[useSpeechRecognition] Native onerror event:", event.error, "Timestamp:", Date.now());
299
- console.error("[useSpeechRecognition] Error context - lastStartAt:", lastStartAtRef.current, "lastStopAt:", lastStopAtRef.current, "instanceId:", instanceIdRef.current);
300
- console.error("[useSpeechRecognition] Error details - This could be caused by:");
301
- if (event.error === "aborted") {
302
- console.error("[useSpeechRecognition] - aborted: Recognition was aborted. Common causes: keyboard appeared, focus changed, another recognition started, or page navigation");
303
- } else if (event.error === "not-allowed") {
304
- console.error("[useSpeechRecognition] - not-allowed: Microphone permission denied");
305
- } else if (event.error === "no-speech") {
306
- console.error("[useSpeechRecognition] - no-speech: No speech detected");
307
- } else if (event.error === "network") {
308
- console.error("[useSpeechRecognition] - network: Network error during recognition");
309
- }
310
- if (recognitionRef.current === recognition) {
311
- console.log("[useSpeechRecognition] Nullifying recognitionRef (onerror)");
312
- recognitionRef.current = null;
313
- }
314
- isStartingRef.current = false;
315
- if (event.error === "not-allowed" && process.env.NODE_ENV === "development") {
316
- console.warn("Speech recognition blocked. Simulating input for development...");
317
- isSimulatingRef.current = true;
318
- setError(null);
319
- setIsListening(true);
320
- simulationTimeoutRef.current = setTimeout(() => {
321
- const mockText = "This is a simulated voice input for testing.";
322
- setTranscript((prev) => prev + (prev ? " " : "") + mockText);
323
- if (onResultRef.current) onResultRef.current(mockText, true);
324
- isSimulatingRef.current = false;
325
- setIsListening(false);
326
- if (onEndRef.current) onEndRef.current();
327
- simulationTimeoutRef.current = null;
328
- }, 3e3);
329
- return;
330
- }
331
- console.error("Speech recognition error", event.error);
332
- setError(event.error);
333
- setIsListening(false);
334
- if (typeof window !== "undefined") {
335
- const w = window;
336
- if (w.__llmSpeechRecognitionActiveInstanceId === instanceIdRef.current) {
337
- w.__llmSpeechRecognitionActiveInstanceId = null;
338
- console.log("[useSpeechRecognition] Cleared global active instance lock after error. instanceId:", instanceIdRef.current);
339
- }
340
- }
341
- };
342
- return recognition;
343
- }, []);
344
- const start = useCallback(() => {
345
- var _a;
346
- const startTimestamp = Date.now();
347
- console.log("[useSpeechRecognition] start() called. Timestamp:", startTimestamp);
348
- console.log("[useSpeechRecognition] State check - isListening:", isListening, "isStarting:", isStartingRef.current, "hasExistingInstance:", !!recognitionRef.current);
349
- if (typeof document !== "undefined") {
350
- console.log("[useSpeechRecognition] Document hasFocus:", document.hasFocus(), "activeElement:", (_a = document.activeElement) == null ? void 0 : _a.tagName);
351
- }
352
- if (isSimulatingRef.current) {
353
- console.log("[useSpeechRecognition] isSimulating, ignoring start");
354
- return;
355
- }
356
- if (isStartingRef.current) {
357
- console.warn("[useSpeechRecognition] Already starting - ignoring duplicate call");
358
- return;
359
- }
360
- if (isListening) {
361
- console.warn("[useSpeechRecognition] App state says already listening - ignoring");
362
- return;
363
- }
364
- if (typeof window !== "undefined") {
365
- const w = window;
366
- if (w.__llmSpeechRecognitionActiveInstanceId && w.__llmSpeechRecognitionActiveInstanceId !== instanceIdRef.current) {
367
- console.error("[useSpeechRecognition] Another recognition instance appears active. activeInstanceId:", w.__llmSpeechRecognitionActiveInstanceId, "thisInstanceId:", instanceIdRef.current);
368
- }
369
- }
370
- try {
371
- if (recognitionRef.current) {
372
- console.log("[useSpeechRecognition] Stopping existing instance before creating new one");
373
- try {
374
- recognitionRef.current.onend = null;
375
- recognitionRef.current.onerror = null;
376
- recognitionRef.current.stop();
377
- } catch (e) {
378
- }
379
- recognitionRef.current = null;
380
- }
381
- const recognition = createRecognitionInstance();
382
- if (!recognition) {
383
- console.error("[useSpeechRecognition] Failed to create recognition instance");
384
- setError("Speech recognition not available");
385
- return;
386
- }
387
- recognitionRef.current = recognition;
388
- setTranscript("");
389
- isStartingRef.current = true;
390
- lastStartAtRef.current = Date.now();
391
- console.log("[useSpeechRecognition] About to call recognition.start(). Timestamp:", Date.now());
392
- recognitionRef.current.start();
393
- console.log("[useSpeechRecognition] recognition.start() executed successfully. Timestamp:", Date.now());
394
- } catch (error2) {
395
- isStartingRef.current = false;
396
- console.error("[useSpeechRecognition] Failed to start recognition:", (error2 == null ? void 0 : error2.message) || error2);
397
- if ((error2 == null ? void 0 : error2.name) === "InvalidStateError") {
398
- console.error("[useSpeechRecognition] InvalidStateError - recognition may already be running");
399
- }
400
- setError((error2 == null ? void 0 : error2.message) || "Failed to start speech recognition");
401
- }
402
- }, [isListening, createRecognitionInstance]);
403
- const stop = useCallback(() => {
404
- console.log("[useSpeechRecognition] stop() called");
405
- lastStopAtRef.current = Date.now();
406
- if (isSimulatingRef.current) {
407
- if (simulationTimeoutRef.current) {
408
- clearTimeout(simulationTimeoutRef.current);
409
- simulationTimeoutRef.current = null;
410
- }
411
- const mockText = "This is a simulated voice input for testing.";
412
- setTranscript((prev) => prev + (prev ? " " : "") + mockText);
413
- if (onResultRef.current) onResultRef.current(mockText, true);
414
- isSimulatingRef.current = false;
415
- setIsListening(false);
416
- if (onEndRef.current) onEndRef.current();
417
- return;
418
- }
419
- if (recognitionRef.current) {
420
- recognitionRef.current.stop();
421
- console.log("[useSpeechRecognition] recognition.stop() executed");
422
- }
423
- }, []);
424
- const resetTranscript = useCallback(() => {
425
- setTranscript("");
426
- }, []);
427
- return {
428
- isListening,
429
- transcript,
430
- start,
431
- stop,
432
- resetTranscript,
433
- isSupported,
434
- error
435
- };
436
- };
437
-
438
154
  // src/ui/react/hooks/useAudioRecorder.ts
439
- import { useState as useState2, useRef as useRef2, useCallback as useCallback2 } from "react";
155
+ import { useState, useRef, useCallback } from "react";
440
156
  var useAudioRecorder = (onStop) => {
441
- const [isRecording, setIsRecording] = useState2(false);
442
- const [isSimulated, setIsSimulated] = useState2(false);
443
- const [blob, setBlob] = useState2(null);
444
- const [error, setError] = useState2(null);
445
- const mediaRecorderRef = useRef2(null);
446
- const chunksRef = useRef2([]);
447
- const start = useCallback2(async () => {
157
+ const [isRecording, setIsRecording] = useState(false);
158
+ const [isSimulated, setIsSimulated] = useState(false);
159
+ const [blob, setBlob] = useState(null);
160
+ const [error, setError] = useState(null);
161
+ const mediaRecorderRef = useRef(null);
162
+ const chunksRef = useRef([]);
163
+ const start = useCallback(async () => {
448
164
  try {
449
165
  if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
450
166
  if (process.env.NODE_ENV === "development") {
@@ -456,7 +172,12 @@ var useAudioRecorder = (onStop) => {
456
172
  }
457
173
  throw new Error("Media devices not available. Ensure you are using HTTPS or localhost.");
458
174
  }
459
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
175
+ const stream = await navigator.mediaDevices.getUserMedia({
176
+ audio: {
177
+ noiseSuppression: true,
178
+ echoCancellation: true
179
+ }
180
+ });
460
181
  const mediaRecorder = new MediaRecorder(stream);
461
182
  mediaRecorderRef.current = mediaRecorder;
462
183
  chunksRef.current = [];
@@ -482,7 +203,7 @@ var useAudioRecorder = (onStop) => {
482
203
  setError(e.message || "Microphone access denied");
483
204
  }
484
205
  }, [onStop]);
485
- const stop = useCallback2(() => {
206
+ const stop = useCallback(() => {
486
207
  if (isSimulated) {
487
208
  setIsRecording(false);
488
209
  setIsSimulated(false);
@@ -506,9 +227,9 @@ var useAudioRecorder = (onStop) => {
506
227
  };
507
228
 
508
229
  // src/ui/react/hooks/useProactiveResize.ts
509
- import { useEffect as useEffect2 } from "react";
230
+ import { useEffect } from "react";
510
231
  function useProactiveResize(textareaRef, measurementRef, value, disabled) {
511
- useEffect2(() => {
232
+ useEffect(() => {
512
233
  if (!textareaRef.current || !measurementRef.current) return;
513
234
  const styles = window.getComputedStyle(textareaRef.current);
514
235
  measurementRef.current.style.width = styles.width;
@@ -544,22 +265,18 @@ var ChatInputArea = forwardRef(({
544
265
  defaultInputMode = "text"
545
266
  }, ref) => {
546
267
  var _a, _b, _c, _d;
547
- const [internalMessage, setInternalMessage] = useState3("");
548
- const [voiceTrigger, setVoiceTrigger] = useState3(null);
549
- const [isTranscribing, setIsTranscribing] = useState3(false);
550
- const [voiceError, setVoiceError] = useState3(null);
551
- const [isFocused, setIsFocused] = useState3(false);
552
- const [showDebug, setShowDebug] = useState3(false);
553
- const [logs, setLogs] = useState3([]);
554
- const tapCountRef = useRef3({ count: 0, lastTap: 0 });
555
- useEffect3(() => {
268
+ const [internalMessage, setInternalMessage] = useState2("");
269
+ const [voiceTrigger, setVoiceTrigger] = useState2(null);
270
+ const [isTranscribing, setIsTranscribing] = useState2(false);
271
+ const [voiceError, setVoiceError] = useState2(null);
272
+ const [isFocused, setIsFocused] = useState2(false);
273
+ const [showDebug, setShowDebug] = useState2(false);
274
+ const [logs, setLogs] = useState2([]);
275
+ const tapCountRef = useRef2({ count: 0, lastTap: 0 });
276
+ useEffect2(() => {
556
277
  const originalLog = console.log;
557
278
  const originalWarn = console.warn;
558
279
  const originalError = console.error;
559
- const formatTime = () => {
560
- const now = /* @__PURE__ */ new Date();
561
- return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}.${now.getMilliseconds().toString().padStart(3, "0")}`;
562
- };
563
280
  const addLog = (type, args) => {
564
281
  try {
565
282
  const msg = args.map((arg) => {
@@ -567,7 +284,7 @@ var ChatInputArea = forwardRef(({
567
284
  if (typeof arg === "object") return JSON.stringify(arg);
568
285
  return String(arg);
569
286
  }).join(" ");
570
- setLogs((prev) => [...prev, `[${formatTime()}] [${type}] ${msg}`].slice(-50));
287
+ setLogs((prev) => [`[${type}] ${msg}`, ...prev].slice(0, 50));
571
288
  } catch (e) {
572
289
  }
573
290
  };
@@ -589,15 +306,15 @@ var ChatInputArea = forwardRef(({
589
306
  console.error = originalError;
590
307
  };
591
308
  }, []);
592
- const copyLogs = useCallback3(() => {
309
+ const copyLogs = useCallback2(() => {
593
310
  navigator.clipboard.writeText(logs.join("\n")).then(() => alert("Logs copied to clipboard")).catch((err) => console.error("Failed to copy logs", err));
594
311
  }, [logs]);
595
- const textareaRef = useRef3(null);
596
- const measurementRef = useRef3(null);
597
- const pendingSelectionRef = useRef3(null);
312
+ const textareaRef = useRef2(null);
313
+ const measurementRef = useRef2(null);
314
+ const pendingSelectionRef = useRef2(null);
598
315
  const isControlled = value !== void 0;
599
316
  const message = isControlled ? value : internalMessage;
600
- const messageRef = useRef3(message);
317
+ const messageRef = useRef2(message);
601
318
  messageRef.current = message;
602
319
  useLayoutEffect(() => {
603
320
  if (pendingSelectionRef.current && textareaRef.current) {
@@ -607,18 +324,18 @@ var ChatInputArea = forwardRef(({
607
324
  pendingSelectionRef.current = null;
608
325
  }
609
326
  }, [message]);
610
- const onChangeRef = useRef3(onChange);
611
- useEffect3(() => {
327
+ const onChangeRef = useRef2(onChange);
328
+ useEffect2(() => {
612
329
  onChangeRef.current = onChange;
613
330
  }, [onChange]);
614
331
  const { voice: globalVoice } = useChatConfig();
615
332
  const isVoiceEnabled = (_a = globalVoice == null ? void 0 : globalVoice.enabled) != null ? _a : !!propVoiceConfig;
616
333
  const voiceConfig = isVoiceEnabled ? propVoiceConfig || (globalVoice == null ? void 0 : globalVoice.config) : void 0;
617
- const voiceConfigRef = useRef3(voiceConfig);
618
- useEffect3(() => {
334
+ const voiceConfigRef = useRef2(voiceConfig);
335
+ useEffect2(() => {
619
336
  voiceConfigRef.current = voiceConfig;
620
337
  }, [voiceConfig]);
621
- const triggerChange = useCallback3((newValue) => {
338
+ const triggerChange = useCallback2((newValue) => {
622
339
  setVoiceError(null);
623
340
  if (isControlled && onChangeRef.current) {
624
341
  const syntheticEvent = {
@@ -632,7 +349,7 @@ var ChatInputArea = forwardRef(({
632
349
  }, [isControlled]);
633
350
  const isInputDisabled = (currentTask == null ? void 0 : currentTask.complete) || (lastInteractiveMessage == null ? void 0 : lastInteractiveMessage.interactive) && (((_b = lastInteractiveMessage == null ? void 0 : lastInteractiveMessage.interactiveData) == null ? void 0 : _b.function) === "form" && !(lastInteractiveMessage == null ? void 0 : lastInteractiveMessage.isResponseSubmitted) || ((_c = lastInteractiveMessage == null ? void 0 : lastInteractiveMessage.interactiveData) == null ? void 0 : _c.function) === "confirm" && !(lastInteractiveMessage == null ? void 0 : lastInteractiveMessage.isResponseSubmitted));
634
351
  useProactiveResize(textareaRef, measurementRef, message, isInputDisabled || !!voiceTrigger);
635
- const insertTextAtCursor = useCallback3((text) => {
352
+ const insertTextAtCursor = useCallback2((text) => {
636
353
  const textarea = textareaRef.current;
637
354
  const currentVal = messageRef.current || "";
638
355
  if (!textarea) {
@@ -650,23 +367,16 @@ var ChatInputArea = forwardRef(({
650
367
  pendingSelectionRef.current = { start: selectionStart, end: selectionEnd };
651
368
  triggerChange(newText);
652
369
  }, [triggerChange]);
653
- const handleVoiceResult = useCallback3((text, isFinal) => {
370
+ const handleVoiceResult = useCallback2((text, isFinal) => {
654
371
  if (isFinal) {
655
372
  insertTextAtCursor(text);
656
373
  }
657
374
  }, [insertTextAtCursor]);
658
- const handleVoiceEnd = useCallback3(() => {
375
+ const handleVoiceEnd = useCallback2(() => {
659
376
  var _a2, _b2;
660
377
  setVoiceTrigger(null);
661
378
  (_b2 = (_a2 = voiceConfigRef.current) == null ? void 0 : _a2.onVoiceEnd) == null ? void 0 : _b2.call(_a2);
662
379
  }, []);
663
- const nativeSpeech = useSpeechRecognition(handleVoiceResult, handleVoiceEnd, voiceConfig == null ? void 0 : voiceConfig.language);
664
- useEffect3(() => {
665
- if (nativeSpeech.error) {
666
- setVoiceError(nativeSpeech.error);
667
- console.error("[ChatInputArea] Native Speech Error:", nativeSpeech.error);
668
- }
669
- }, [nativeSpeech.error]);
670
380
  const customRecorder = useAudioRecorder(async (blob) => {
671
381
  var _a2, _b2, _c2;
672
382
  setVoiceTrigger(null);
@@ -726,65 +436,27 @@ var ChatInputArea = forwardRef(({
726
436
  handleSubmit();
727
437
  }
728
438
  };
729
- const isMobile = useCallback3(() => {
730
- if (typeof window === "undefined") return false;
731
- return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || "ontouchstart" in window || navigator.maxTouchPoints > 0;
732
- }, []);
733
439
  const startRecording = async (trigger) => {
734
- var _a2, _b2;
735
- console.log("[ChatInputArea] startRecording called. trigger:", trigger, "isMobile:", isMobile());
736
- console.log("[ChatInputArea] Current state - voiceTrigger:", voiceTrigger, "isTranscribing:", isTranscribing);
737
- if (voiceTrigger || isTranscribing) {
738
- console.log("[ChatInputArea] startRecording ignored - already active");
739
- return;
740
- }
440
+ var _a2;
441
+ if (voiceTrigger || isTranscribing) return;
741
442
  setVoiceTrigger(trigger);
742
443
  setVoiceError(null);
743
- if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "native") {
744
- console.log("[ChatInputArea] Using native speech recognition");
745
- if (!nativeSpeech.isSupported) {
746
- console.error("[ChatInputArea] Native speech not supported");
747
- alert("Speech recognition is not supported in this browser.");
748
- setVoiceTrigger(null);
749
- return;
750
- }
751
- console.log("[ChatInputArea] Calling nativeSpeech.start()...");
752
- nativeSpeech.start();
753
- console.log("[ChatInputArea] nativeSpeech.start() called");
754
- console.log("[ChatInputArea] Calling voiceConfig.onVoiceStart if exists...");
755
- try {
756
- (_a2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceStart) == null ? void 0 : _a2.call(voiceConfig);
757
- console.log("[ChatInputArea] voiceConfig.onVoiceStart completed");
758
- } catch (e) {
759
- console.error("[ChatInputArea] voiceConfig.onVoiceStart threw error", e);
760
- }
761
- } else {
762
- console.log("[ChatInputArea] Using custom recorder");
763
- console.log("[ChatInputArea] Calling voiceConfig.onVoiceStart if exists (custom mode)...");
764
- try {
765
- (_b2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceStart) == null ? void 0 : _b2.call(voiceConfig);
766
- console.log("[ChatInputArea] voiceConfig.onVoiceStart completed");
767
- } catch (e) {
768
- console.error("[ChatInputArea] voiceConfig.onVoiceStart threw error", e);
769
- }
444
+ (_a2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceStart) == null ? void 0 : _a2.call(voiceConfig);
445
+ try {
770
446
  await customRecorder.start();
771
- console.log("[ChatInputArea] Custom recorder started");
772
- }
773
- if (!isMobile()) {
774
- console.log("[ChatInputArea] Re-focusing textarea (desktop only)");
775
- setTimeout(() => {
776
- var _a3;
777
- return (_a3 = textareaRef.current) == null ? void 0 : _a3.focus();
778
- }, 0);
447
+ } catch (e) {
448
+ console.error("[ChatInputArea] Failed to start recorder:", e);
449
+ setVoiceError("Mic access denied");
450
+ setVoiceTrigger(null);
779
451
  }
452
+ setTimeout(() => {
453
+ var _a3;
454
+ return (_a3 = textareaRef.current) == null ? void 0 : _a3.focus();
455
+ }, 0);
780
456
  };
781
457
  const stopRecording = () => {
782
458
  if (!voiceTrigger) return;
783
- if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "native") {
784
- nativeSpeech.stop();
785
- } else {
786
- customRecorder.stop();
787
- }
459
+ customRecorder.stop();
788
460
  };
789
461
  const getPlaceholder = () => {
790
462
  if (placeholder) return placeholder;
@@ -963,7 +635,7 @@ var ChatInputArea = forwardRef(({
963
635
  ChatInputArea.displayName = "ChatInputArea";
964
636
 
965
637
  // src/ui/react/components/TapToTalk.tsx
966
- import React3, { useState as useState4, useCallback as useCallback4, useRef as useRef4 } from "react";
638
+ import React3, { useState as useState3, useCallback as useCallback3, useRef as useRef3 } from "react";
967
639
  import { MicrophoneIcon as MicrophoneIcon2, XMarkIcon as XMarkIcon2, Square2StackIcon as Square2StackIcon2 } from "@heroicons/react/24/outline";
968
640
  import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
969
641
  var TapToTalk = ({
@@ -978,20 +650,16 @@ var TapToTalk = ({
978
650
  var _a;
979
651
  const globalConfig = useChatConfig();
980
652
  const voiceConfig = propVoiceConfig || ((_a = globalConfig.voice) == null ? void 0 : _a.config);
981
- const [isTranscribing, setIsTranscribing] = useState4(false);
982
- const [voiceTrigger, setVoiceTrigger] = useState4(null);
983
- const [errorMsg, setErrorMsg] = useState4(null);
984
- const [showDebug, setShowDebug] = useState4(false);
985
- const [logs, setLogs] = useState4([]);
986
- const tapCountRef = useRef4({ count: 0, lastTap: 0 });
653
+ const [isTranscribing, setIsTranscribing] = useState3(false);
654
+ const [voiceTrigger, setVoiceTrigger] = useState3(null);
655
+ const [errorMsg, setErrorMsg] = useState3(null);
656
+ const [showDebug, setShowDebug] = useState3(false);
657
+ const [logs, setLogs] = useState3([]);
658
+ const tapCountRef = useRef3({ count: 0, lastTap: 0 });
987
659
  React3.useEffect(() => {
988
660
  const originalLog = console.log;
989
661
  const originalWarn = console.warn;
990
662
  const originalError = console.error;
991
- const formatTime = () => {
992
- const now = /* @__PURE__ */ new Date();
993
- return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}.${now.getMilliseconds().toString().padStart(3, "0")}`;
994
- };
995
663
  const addLog = (type, args) => {
996
664
  try {
997
665
  const msg = args.map((arg) => {
@@ -999,7 +667,7 @@ var TapToTalk = ({
999
667
  if (typeof arg === "object") return JSON.stringify(arg);
1000
668
  return String(arg);
1001
669
  }).join(" ");
1002
- setLogs((prev) => [...prev, `[${formatTime()}] [${type}] ${msg}`].slice(-50));
670
+ setLogs((prev) => [`[${type}] ${msg}`, ...prev].slice(0, 50));
1003
671
  } catch (e) {
1004
672
  }
1005
673
  };
@@ -1021,26 +689,12 @@ var TapToTalk = ({
1021
689
  console.error = originalError;
1022
690
  };
1023
691
  }, []);
1024
- const copyLogs = useCallback4(() => {
692
+ const copyLogs = useCallback3(() => {
1025
693
  navigator.clipboard.writeText(logs.join("\n")).then(() => alert("Logs copied to clipboard")).catch((err) => console.error("Failed to copy logs", err));
1026
694
  }, [logs]);
1027
- const handleVoiceResult = useCallback4((text, isFinal) => {
1028
- if (isFinal) {
1029
- onResult(text);
1030
- setErrorMsg(null);
1031
- setVoiceTrigger(null);
1032
- }
1033
- }, [onResult]);
1034
- const handleVoiceEnd = useCallback4(() => {
695
+ const handleVoiceEnd = useCallback3(() => {
1035
696
  setVoiceTrigger(null);
1036
697
  }, []);
1037
- const nativeSpeech = useSpeechRecognition(handleVoiceResult, handleVoiceEnd, voiceConfig == null ? void 0 : voiceConfig.language);
1038
- React3.useEffect(() => {
1039
- if (nativeSpeech.error) {
1040
- setErrorMsg(nativeSpeech.error);
1041
- console.error("[TapToTalk] Native Speech Error:", nativeSpeech.error);
1042
- }
1043
- }, [nativeSpeech.error]);
1044
698
  const customRecorder = useAudioRecorder(async (blob) => {
1045
699
  setVoiceTrigger(null);
1046
700
  setIsTranscribing(true);
@@ -1052,7 +706,7 @@ var TapToTalk = ({
1052
706
  setIsTranscribing(false);
1053
707
  return;
1054
708
  }
1055
- if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "custom" && voiceConfig.onAudioCapture) {
709
+ if (voiceConfig == null ? void 0 : voiceConfig.onAudioCapture) {
1056
710
  try {
1057
711
  const text = await voiceConfig.onAudioCapture(blob);
1058
712
  if (text) onResult(text);
@@ -1066,82 +720,53 @@ var TapToTalk = ({
1066
720
  setIsTranscribing(false);
1067
721
  }
1068
722
  });
1069
- const isListening = !!voiceTrigger || nativeSpeech.isListening || customRecorder.isRecording;
723
+ const isListening = !!voiceTrigger || customRecorder.isRecording;
1070
724
  const isActive = isListening || isTranscribing;
1071
- const processingRef = useRef4(false);
1072
- const isMobile = useCallback4(() => {
1073
- if (typeof window === "undefined") return false;
1074
- return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || "ontouchstart" in window || navigator.maxTouchPoints > 0;
1075
- }, []);
1076
- const toggleVoice = async (e) => {
1077
- const now = Date.now();
1078
- if (now - tapCountRef.current.lastTap < 500) {
1079
- tapCountRef.current.count++;
1080
- } else {
1081
- tapCountRef.current.count = 1;
1082
- }
1083
- tapCountRef.current.lastTap = now;
1084
- if (tapCountRef.current.count >= 5) {
1085
- setShowDebug((prev) => !prev);
1086
- tapCountRef.current.count = 0;
1087
- if (isActive) {
1088
- console.log("[TapToTalk] Debug trigger force-stop");
1089
- if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "native") nativeSpeech.stop();
1090
- else customRecorder.stop();
1091
- setVoiceTrigger(null);
1092
- }
1093
- return;
1094
- }
1095
- console.log("[TapToTalk] toggleVoice called. isMobile:", isMobile());
725
+ const processingRef = useRef3(false);
726
+ const toggleVoice = async () => {
1096
727
  if (processingRef.current) {
1097
728
  console.log("[TapToTalk] toggleVoice ignored - processing");
1098
729
  return;
1099
730
  }
1100
731
  processingRef.current = true;
1101
- console.log("[TapToTalk] toggleVoice called. isActive:", isActive, "isListening:", isListening, "isTranscribing:", isTranscribing);
732
+ console.log("[TapToTalk] toggleVoice called. isActive:", isActive);
1102
733
  try {
734
+ const now = Date.now();
735
+ if (now - tapCountRef.current.lastTap < 500) {
736
+ tapCountRef.current.count++;
737
+ } else {
738
+ tapCountRef.current.count = 1;
739
+ }
740
+ tapCountRef.current.lastTap = now;
741
+ if (tapCountRef.current.count >= 5) {
742
+ setShowDebug((prev) => !prev);
743
+ tapCountRef.current.count = 0;
744
+ if (isActive) {
745
+ console.log("[TapToTalk] Debug trigger force-stop");
746
+ customRecorder.stop();
747
+ setVoiceTrigger(null);
748
+ }
749
+ return;
750
+ }
1103
751
  if (isActive) {
1104
752
  if (isTranscribing && !isListening) {
1105
753
  console.log("[TapToTalk] Ignoring click during transcription");
1106
754
  return;
1107
755
  }
1108
756
  console.log("[TapToTalk] Stopping voice...");
1109
- if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "native") {
1110
- nativeSpeech.stop();
1111
- } else {
1112
- customRecorder.stop();
1113
- }
757
+ customRecorder.stop();
1114
758
  setVoiceTrigger(null);
1115
759
  } else {
1116
- console.log("[TapToTalk] Starting voice... mode:", voiceConfig == null ? void 0 : voiceConfig.mode);
760
+ console.log("[TapToTalk] Starting voice...");
1117
761
  setErrorMsg(null);
762
+ onFocusTarget == null ? void 0 : onFocusTarget();
1118
763
  setVoiceTrigger("click");
1119
- console.log("[TapToTalk] voiceTrigger set to click");
1120
- if (!isMobile() && onFocusTarget) {
1121
- console.log("[TapToTalk] Desktop: calling onFocusTarget()");
1122
- onFocusTarget();
1123
- }
1124
- if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "custom") {
1125
- console.log("[TapToTalk] Starting custom recorder...");
1126
- try {
1127
- await customRecorder.start();
1128
- console.log("[TapToTalk] Custom recorder started successfully");
1129
- } catch (e2) {
1130
- console.error("[TapToTalk] Custom recorder failed:", e2);
1131
- setErrorMsg("Mic access denied");
1132
- setVoiceTrigger(null);
1133
- }
1134
- } else {
1135
- console.log("[TapToTalk] Starting native speech recognition...");
1136
- if (!nativeSpeech.isSupported) {
1137
- console.error("[TapToTalk] Native speech not supported");
1138
- setErrorMsg("Speech not supported");
1139
- setVoiceTrigger(null);
1140
- return;
1141
- }
1142
- console.log("[TapToTalk] Calling nativeSpeech.start()...");
1143
- nativeSpeech.start();
1144
- console.log("[TapToTalk] nativeSpeech.start() called");
764
+ try {
765
+ await customRecorder.start();
766
+ } catch (e) {
767
+ console.error("[TapToTalk] Custom recorder failed:", e);
768
+ setErrorMsg("Mic access denied");
769
+ setVoiceTrigger(null);
1145
770
  }
1146
771
  }
1147
772
  } finally {
@@ -1187,7 +812,6 @@ var TapToTalk = ({
1187
812
  /* @__PURE__ */ jsxs4(
1188
813
  "button",
1189
814
  {
1190
- type: "button",
1191
815
  onClick: toggleVoice,
1192
816
  disabled: disabled || isTranscribing && !isListening,
1193
817
  className: `flex items-center justify-center gap-3 px-6 py-3 rounded-xl transition-all duration-300 w-full font-medium shadow-md active:scale-[0.98]
@@ -1196,9 +820,9 @@ var TapToTalk = ({
1196
820
  ${className}`,
1197
821
  title: label,
1198
822
  children: [
1199
- /* @__PURE__ */ jsx6("div", { className: "flex items-center justify-center shrink-0 pointer-events-none", children: Icon }),
1200
- /* @__PURE__ */ jsx6("span", { className: "truncate pointer-events-none", children: label }),
1201
- errorMsg && /* @__PURE__ */ jsx6("span", { className: "text-[10px] bg-white/20 px-1.5 py-0.5 rounded text-red-100 animate-in fade-in slide-in-from-right-1 pointer-events-none", children: errorMsg })
823
+ /* @__PURE__ */ jsx6("div", { className: "flex items-center justify-center shrink-0", children: Icon }),
824
+ /* @__PURE__ */ jsx6("span", { className: "truncate", children: label }),
825
+ errorMsg && /* @__PURE__ */ jsx6("span", { className: "text-[10px] bg-white/20 px-1.5 py-0.5 rounded text-red-100 animate-in fade-in slide-in-from-right-1", children: errorMsg })
1202
826
  ]
1203
827
  }
1204
828
  )
@@ -1206,17 +830,17 @@ var TapToTalk = ({
1206
830
  };
1207
831
 
1208
832
  // src/ui/react/components/ChatMessageList.tsx
1209
- import { useEffect as useEffect6, useRef as useRef6 } from "react";
833
+ import { useEffect as useEffect5, useRef as useRef5 } from "react";
1210
834
 
1211
835
  // src/ui/react/components/interactive/ConfirmInteraction.tsx
1212
- import { useState as useState5 } from "react";
836
+ import { useState as useState4 } from "react";
1213
837
  import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1214
838
  var ConfirmInteraction = ({
1215
839
  parameters,
1216
840
  onResponse,
1217
841
  isResponseSubmitted
1218
842
  }) => {
1219
- const [selectedOption, setSelectedOption] = useState5(null);
843
+ const [selectedOption, setSelectedOption] = useState4(null);
1220
844
  const params = parameters;
1221
845
  const { yesPrompt, noPrompt } = params;
1222
846
  console.log("[ConfirmInteraction] Parameters:", params);
@@ -1249,7 +873,7 @@ var ConfirmInteraction = ({
1249
873
  var ConfirmInteraction_default = ConfirmInteraction;
1250
874
 
1251
875
  // src/ui/react/components/interactive/SelectInteraction.tsx
1252
- import { useState as useState6, useEffect as useEffect4 } from "react";
876
+ import { useState as useState5, useEffect as useEffect3 } from "react";
1253
877
  import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1254
878
  var SelectInteraction = ({
1255
879
  parameters,
@@ -1257,11 +881,11 @@ var SelectInteraction = ({
1257
881
  isResponseSubmitted,
1258
882
  message
1259
883
  }) => {
1260
- const [selectedOption, setSelectedOption] = useState6(null);
1261
- const [customOption, setCustomOption] = useState6(null);
884
+ const [selectedOption, setSelectedOption] = useState5(null);
885
+ const [customOption, setCustomOption] = useState5(null);
1262
886
  const params = parameters;
1263
887
  const { question, options, placeholder } = params;
1264
- useEffect4(() => {
888
+ useEffect3(() => {
1265
889
  if (isResponseSubmitted && (message == null ? void 0 : message.responseValue)) {
1266
890
  const responseValueStr = String(message.responseValue);
1267
891
  setSelectedOption(responseValueStr);
@@ -1300,7 +924,7 @@ var SelectInteraction = ({
1300
924
  var SelectInteraction_default = SelectInteraction;
1301
925
 
1302
926
  // src/ui/react/components/interactive/FormInteraction.tsx
1303
- import { useState as useState7, useEffect as useEffect5, useRef as useRef5 } from "react";
927
+ import { useState as useState6, useEffect as useEffect4, useRef as useRef4 } from "react";
1304
928
  import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";
1305
929
  import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1306
930
  var FormInteraction = ({
@@ -1309,11 +933,11 @@ var FormInteraction = ({
1309
933
  isResponseSubmitted,
1310
934
  submittedValues
1311
935
  }) => {
1312
- const [isModalOpen, setIsModalOpen] = useState7(false);
1313
- const [formValues, setFormValues] = useState7({});
1314
- const [isExpanded, setIsExpanded] = useState7(false);
1315
- const [parsedFields, setParsedFields] = useState7([]);
1316
- const formButtonsRef = useRef5(null);
936
+ const [isModalOpen, setIsModalOpen] = useState6(false);
937
+ const [formValues, setFormValues] = useState6({});
938
+ const [isExpanded, setIsExpanded] = useState6(false);
939
+ const [parsedFields, setParsedFields] = useState6([]);
940
+ const formButtonsRef = useRef4(null);
1317
941
  const parseParameters = () => {
1318
942
  const { prompt, description, submitText = "Submit", cancelText = "Cancel" } = parameters;
1319
943
  let fieldsArray = [];
@@ -1374,7 +998,7 @@ var FormInteraction = ({
1374
998
  };
1375
999
  };
1376
1000
  const params = parseParameters();
1377
- useEffect5(() => {
1001
+ useEffect4(() => {
1378
1002
  const processedParams = parseParameters();
1379
1003
  setParsedFields(processedParams.fields);
1380
1004
  const initialValues = {};
@@ -1392,7 +1016,7 @@ var FormInteraction = ({
1392
1016
  setIsModalOpen(true);
1393
1017
  }
1394
1018
  }, [parameters, isResponseSubmitted]);
1395
- useEffect5(() => {
1019
+ useEffect4(() => {
1396
1020
  if (isModalOpen && formButtonsRef.current) {
1397
1021
  setTimeout(() => {
1398
1022
  var _a;
@@ -1700,10 +1324,10 @@ var ChatMessageList = ({
1700
1324
  getContextExample,
1701
1325
  onInteractiveResponse
1702
1326
  }) => {
1703
- const chatContainerRef = useRef6(null);
1704
- const lastMessageRef = useRef6(null);
1705
- const processingIndicatorRef = useRef6(null);
1706
- useEffect6(() => {
1327
+ const chatContainerRef = useRef5(null);
1328
+ const lastMessageRef = useRef5(null);
1329
+ const processingIndicatorRef = useRef5(null);
1330
+ useEffect5(() => {
1707
1331
  if (isProcessing && processingIndicatorRef.current) {
1708
1332
  processingIndicatorRef.current.scrollIntoView({ behavior: "smooth" });
1709
1333
  return;
@@ -1947,7 +1571,6 @@ export {
1947
1571
  transcribeAudio,
1948
1572
  useAudioRecorder,
1949
1573
  useChatConfig,
1950
- useProactiveResize,
1951
- useSpeechRecognition
1574
+ useProactiveResize
1952
1575
  };
1953
1576
  //# sourceMappingURL=index.js.map