@contentgrowth/llm-service 0.8.6 → 0.8.7

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.
@@ -441,20 +441,28 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
441
441
  const message = isControlled ? value : internalMessage;
442
442
  const messageRef = (0, import_react5.useRef)(message);
443
443
  messageRef.current = message;
444
+ const onChangeRef = (0, import_react5.useRef)(onChange);
445
+ (0, import_react5.useEffect)(() => {
446
+ onChangeRef.current = onChange;
447
+ }, [onChange]);
444
448
  const { voice: globalVoice } = useChatConfig();
445
449
  const isVoiceEnabled = (_a = globalVoice == null ? void 0 : globalVoice.enabled) != null ? _a : !!propVoiceConfig;
446
450
  const voiceConfig = isVoiceEnabled ? propVoiceConfig || (globalVoice == null ? void 0 : globalVoice.config) : void 0;
447
- const triggerChange = (newValue) => {
448
- if (isControlled && onChange && textareaRef.current) {
451
+ const voiceConfigRef = (0, import_react5.useRef)(voiceConfig);
452
+ (0, import_react5.useEffect)(() => {
453
+ voiceConfigRef.current = voiceConfig;
454
+ }, [voiceConfig]);
455
+ const triggerChange = (0, import_react5.useCallback)((newValue) => {
456
+ if (isControlled && onChangeRef.current && textareaRef.current) {
449
457
  const syntheticEvent = {
450
458
  target: { value: newValue },
451
459
  currentTarget: { value: newValue }
452
460
  };
453
- onChange(syntheticEvent);
461
+ onChangeRef.current(syntheticEvent);
454
462
  } else {
455
463
  setInternalMessage(newValue);
456
464
  }
457
- };
465
+ }, [isControlled]);
458
466
  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));
459
467
  useProactiveResize(textareaRef, measurementRef, message, isInputDisabled || !!voiceTrigger || inputMode === "voice");
460
468
  const handleVoiceKeyDown = (e) => {
@@ -484,20 +492,20 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
484
492
  triggerChange(messageRef.current + (messageRef.current ? " " : "") + text);
485
493
  }, []);
486
494
  const handleVoiceEnd = (0, import_react5.useCallback)(() => {
487
- var _a2;
495
+ var _a2, _b2;
488
496
  console.log("[ChatInputArea] nativeSpeech onEnd triggered");
489
497
  setVoiceTrigger(null);
490
- (_a2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceEnd) == null ? void 0 : _a2.call(voiceConfig);
491
- }, [voiceConfig]);
498
+ (_b2 = (_a2 = voiceConfigRef.current) == null ? void 0 : _a2.onVoiceEnd) == null ? void 0 : _b2.call(_a2);
499
+ }, []);
492
500
  const nativeSpeech = useSpeechRecognition(handleVoiceResult, handleVoiceEnd, voiceConfig == null ? void 0 : voiceConfig.language);
493
501
  const customRecorder = useAudioRecorder(async (blob) => {
494
- var _a2;
502
+ var _a2, _b2, _c2;
495
503
  console.log("[ChatInputArea] customRecorder onStop triggered");
496
504
  setVoiceTrigger(null);
497
- (_a2 = voiceConfig == null ? void 0 : voiceConfig.onVoiceEnd) == null ? void 0 : _a2.call(voiceConfig);
498
- if (voiceConfig == null ? void 0 : voiceConfig.onAudioCapture) {
505
+ (_b2 = (_a2 = voiceConfigRef.current) == null ? void 0 : _a2.onVoiceEnd) == null ? void 0 : _b2.call(_a2);
506
+ if ((_c2 = voiceConfigRef.current) == null ? void 0 : _c2.onAudioCapture) {
499
507
  try {
500
- const text = await voiceConfig.onAudioCapture(blob);
508
+ const text = await voiceConfigRef.current.onAudioCapture(blob);
501
509
  if (text) triggerChange(messageRef.current + (messageRef.current ? " " : "") + text);
502
510
  } catch (e) {
503
511
  console.error("[ChatInputArea] Audio capture failed", e);