@contentgrowth/llm-service 0.9.94 → 0.9.96

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.
@@ -546,6 +546,10 @@ var ChatInputArea = forwardRef(({
546
546
  const originalLog = console.log;
547
547
  const originalWarn = console.warn;
548
548
  const originalError = console.error;
549
+ const formatTime = () => {
550
+ const now = /* @__PURE__ */ new Date();
551
+ 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")}`;
552
+ };
549
553
  const addLog = (type, args) => {
550
554
  try {
551
555
  const msg = args.map((arg) => {
@@ -553,7 +557,7 @@ var ChatInputArea = forwardRef(({
553
557
  if (typeof arg === "object") return JSON.stringify(arg);
554
558
  return String(arg);
555
559
  }).join(" ");
556
- setLogs((prev) => [`[${type}] ${msg}`, ...prev].slice(0, 50));
560
+ setLogs((prev) => [`[${formatTime()}] [${type}] ${msg}`, ...prev].slice(0, 50));
557
561
  } catch (e) {
558
562
  }
559
563
  };
@@ -717,57 +721,64 @@ var ChatInputArea = forwardRef(({
717
721
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || "ontouchstart" in window || navigator.maxTouchPoints > 0;
718
722
  }, []);
719
723
  const startRecording = async (trigger) => {
720
- var _a2, _b2;
721
724
  console.log("[ChatInputArea] startRecording called. trigger:", trigger, "isMobile:", isMobile());
722
725
  console.log("[ChatInputArea] Current state - voiceTrigger:", voiceTrigger, "isTranscribing:", isTranscribing);
723
726
  if (voiceTrigger || isTranscribing) {
724
727
  console.log("[ChatInputArea] startRecording ignored - already active");
725
728
  return;
726
729
  }
727
- setVoiceTrigger(trigger);
728
- setVoiceError(null);
729
- if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "native") {
730
- console.log("[ChatInputArea] Using native speech recognition");
731
- if (!nativeSpeech.isSupported) {
732
- console.error("[ChatInputArea] Native speech not supported");
733
- alert("Speech recognition is not supported in this browser.");
734
- setVoiceTrigger(null);
735
- return;
730
+ const performStart = async () => {
731
+ var _a2, _b2;
732
+ setVoiceTrigger(trigger);
733
+ setVoiceError(null);
734
+ if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "native") {
735
+ console.log("[ChatInputArea] Using native speech recognition");
736
+ if (!nativeSpeech.isSupported) {
737
+ console.error("[ChatInputArea] Native speech not supported");
738
+ alert("Speech recognition is not supported in this browser.");
739
+ setVoiceTrigger(null);
740
+ return;
741
+ }
742
+ console.log("[ChatInputArea] Calling nativeSpeech.start()...");
743
+ nativeSpeech.start();
744
+ console.log("[ChatInputArea] nativeSpeech.start() called");
745
+ console.log("[ChatInputArea] Calling voiceConfig.onVoiceStart if exists (after nativeSpeech.start)...");
746
+ try {
747
+ (_a2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceStart) == null ? void 0 : _a2.call(voiceConfig);
748
+ console.log("[ChatInputArea] voiceConfig.onVoiceStart completed");
749
+ } catch (e) {
750
+ console.error("[ChatInputArea] voiceConfig.onVoiceStart threw error", e);
751
+ }
752
+ } else {
753
+ console.log("[ChatInputArea] Using custom recorder");
754
+ console.log("[ChatInputArea] Calling voiceConfig.onVoiceStart if exists (custom mode)...");
755
+ try {
756
+ (_b2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceStart) == null ? void 0 : _b2.call(voiceConfig);
757
+ console.log("[ChatInputArea] voiceConfig.onVoiceStart completed");
758
+ } catch (e) {
759
+ console.error("[ChatInputArea] voiceConfig.onVoiceStart threw error", e);
760
+ }
761
+ await customRecorder.start();
762
+ console.log("[ChatInputArea] Custom recorder started");
736
763
  }
737
- console.log("[ChatInputArea] Calling nativeSpeech.start()...");
738
- nativeSpeech.start();
739
- console.log("[ChatInputArea] nativeSpeech.start() called");
740
- console.log("[ChatInputArea] Calling voiceConfig.onVoiceStart if exists (after nativeSpeech.start)...");
741
- try {
742
- (_a2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceStart) == null ? void 0 : _a2.call(voiceConfig);
743
- console.log("[ChatInputArea] voiceConfig.onVoiceStart completed");
744
- } catch (e) {
745
- console.error("[ChatInputArea] voiceConfig.onVoiceStart threw error", e);
764
+ };
765
+ if (isMobile()) {
766
+ console.log("[ChatInputArea] SKIPPING textarea focus on mobile to prevent keyboard conflict");
767
+ if (document.activeElement instanceof HTMLElement) {
768
+ console.log("[ChatInputArea] Blur active element on mobile BEFORE start");
769
+ document.activeElement.blur();
746
770
  }
771
+ console.log("[ChatInputArea] Mobile: Waiting 300ms before starting recognition...");
772
+ setTimeout(() => {
773
+ performStart();
774
+ }, 300);
747
775
  } else {
748
- console.log("[ChatInputArea] Using custom recorder");
749
- console.log("[ChatInputArea] Calling voiceConfig.onVoiceStart if exists (custom mode)...");
750
- try {
751
- (_b2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceStart) == null ? void 0 : _b2.call(voiceConfig);
752
- console.log("[ChatInputArea] voiceConfig.onVoiceStart completed");
753
- } catch (e) {
754
- console.error("[ChatInputArea] voiceConfig.onVoiceStart threw error", e);
755
- }
756
- await customRecorder.start();
757
- console.log("[ChatInputArea] Custom recorder started");
758
- }
759
- if (!isMobile()) {
776
+ await performStart();
760
777
  console.log("[ChatInputArea] Re-focusing textarea (desktop only)");
761
778
  setTimeout(() => {
762
- var _a3;
763
- return (_a3 = textareaRef.current) == null ? void 0 : _a3.focus();
779
+ var _a2;
780
+ return (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
764
781
  }, 0);
765
- } else {
766
- console.log("[ChatInputArea] SKIPPING textarea focus on mobile to prevent keyboard conflict");
767
- if (document.activeElement instanceof HTMLElement) {
768
- console.log("[ChatInputArea] Blur active element on mobile");
769
- document.activeElement.blur();
770
- }
771
782
  }
772
783
  };
773
784
  const stopRecording = () => {
@@ -980,6 +991,10 @@ var TapToTalk = ({
980
991
  const originalLog = console.log;
981
992
  const originalWarn = console.warn;
982
993
  const originalError = console.error;
994
+ const formatTime = () => {
995
+ const now = /* @__PURE__ */ new Date();
996
+ 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")}`;
997
+ };
983
998
  const addLog = (type, args) => {
984
999
  try {
985
1000
  const msg = args.map((arg) => {
@@ -987,7 +1002,7 @@ var TapToTalk = ({
987
1002
  if (typeof arg === "object") return JSON.stringify(arg);
988
1003
  return String(arg);
989
1004
  }).join(" ");
990
- setLogs((prev) => [`[${type}] ${msg}`, ...prev].slice(0, 50));
1005
+ setLogs((prev) => [`[${formatTime()}] [${type}] ${msg}`, ...prev].slice(0, 50));
991
1006
  } catch (e) {
992
1007
  }
993
1008
  };
@@ -1066,6 +1081,24 @@ var TapToTalk = ({
1066
1081
  e.preventDefault();
1067
1082
  e.stopPropagation();
1068
1083
  }
1084
+ const now = Date.now();
1085
+ if (now - tapCountRef.current.lastTap < 500) {
1086
+ tapCountRef.current.count++;
1087
+ } else {
1088
+ tapCountRef.current.count = 1;
1089
+ }
1090
+ tapCountRef.current.lastTap = now;
1091
+ if (tapCountRef.current.count >= 5) {
1092
+ setShowDebug((prev) => !prev);
1093
+ tapCountRef.current.count = 0;
1094
+ if (isActive) {
1095
+ console.log("[TapToTalk] Debug trigger force-stop");
1096
+ if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "native") nativeSpeech.stop();
1097
+ else customRecorder.stop();
1098
+ setVoiceTrigger(null);
1099
+ }
1100
+ return;
1101
+ }
1069
1102
  console.log("[TapToTalk] toggleVoice called. isMobile:", isMobile());
1070
1103
  if (processingRef.current) {
1071
1104
  console.log("[TapToTalk] toggleVoice ignored - processing");
@@ -1074,24 +1107,6 @@ var TapToTalk = ({
1074
1107
  processingRef.current = true;
1075
1108
  console.log("[TapToTalk] toggleVoice called. isActive:", isActive, "isListening:", isListening, "isTranscribing:", isTranscribing);
1076
1109
  try {
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
1110
  if (isActive) {
1096
1111
  if (isTranscribing && !isListening) {
1097
1112
  console.log("[TapToTalk] Ignoring click during transcription");
@@ -1107,41 +1122,47 @@ var TapToTalk = ({
1107
1122
  } else {
1108
1123
  console.log("[TapToTalk] Starting voice... mode:", voiceConfig == null ? void 0 : voiceConfig.mode);
1109
1124
  setErrorMsg(null);
1110
- if (onFocusTarget && !isMobile()) {
1111
- console.log("[TapToTalk] calling onFocusTarget() (desktop only)");
1112
- onFocusTarget();
1113
- } else {
1114
- if (onFocusTarget) {
1115
- console.log("[TapToTalk] SKIPPING onFocusTarget on mobile to prevent keyboard conflict");
1125
+ const performStart = async () => {
1126
+ setVoiceTrigger("click");
1127
+ console.log("[TapToTalk] voiceTrigger set to click");
1128
+ if ((voiceConfig == null ? void 0 : voiceConfig.mode) === "custom") {
1129
+ console.log("[TapToTalk] Starting custom recorder...");
1130
+ try {
1131
+ await customRecorder.start();
1132
+ console.log("[TapToTalk] Custom recorder started successfully");
1133
+ } catch (e2) {
1134
+ console.error("[TapToTalk] Custom recorder failed:", e2);
1135
+ setErrorMsg("Mic access denied");
1136
+ setVoiceTrigger(null);
1137
+ }
1138
+ } else {
1139
+ console.log("[TapToTalk] Starting native speech recognition...");
1140
+ if (!nativeSpeech.isSupported) {
1141
+ console.error("[TapToTalk] Native speech not supported");
1142
+ setErrorMsg("Speech not supported");
1143
+ setVoiceTrigger(null);
1144
+ return;
1145
+ }
1146
+ console.log("[TapToTalk] Calling nativeSpeech.start()...");
1147
+ nativeSpeech.start();
1148
+ console.log("[TapToTalk] nativeSpeech.start() called");
1116
1149
  }
1117
- if (isMobile() && document.activeElement instanceof HTMLElement) {
1118
- console.log("[TapToTalk] Blurring active element on mobile");
1150
+ };
1151
+ if (isMobile()) {
1152
+ console.log("[TapToTalk] Mobile: Blurring active element and skipping onFocusTarget");
1153
+ if (document.activeElement instanceof HTMLElement) {
1119
1154
  document.activeElement.blur();
1120
1155
  }
1121
- }
1122
- setVoiceTrigger("click");
1123
- console.log("[TapToTalk] voiceTrigger set to click");
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
- }
1156
+ console.log("[TapToTalk] Mobile: Waiting 300ms before starting recognition...");
1157
+ setTimeout(() => {
1158
+ performStart();
1159
+ }, 300);
1134
1160
  } 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;
1161
+ if (onFocusTarget) {
1162
+ console.log("[TapToTalk] Desktop: calling onFocusTarget()");
1163
+ onFocusTarget();
1141
1164
  }
1142
- console.log("[TapToTalk] Calling nativeSpeech.start()...");
1143
- nativeSpeech.start();
1144
- console.log("[TapToTalk] nativeSpeech.start() called");
1165
+ performStart();
1145
1166
  }
1146
1167
  }
1147
1168
  } finally {