@alquimia-ai/ui 1.5.0 → 1.5.2

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.
@@ -17,8 +17,9 @@ interface SpeechToTextProps extends React.HTMLAttributes<HTMLDivElement> {
17
17
  speechToText: (audio: string) => Promise<string>;
18
18
  handleReplaceInput: (text: string) => void;
19
19
  setIsAudioRecording: React.Dispatch<React.SetStateAction<boolean>>;
20
+ onSendAudio?: () => void;
20
21
  }
21
- declare function SpeechToText({ className, speechToText, RecordAudioIcon, IdleAudioIcon, handleReplaceInput, setIsAudioRecording, ...props }: SpeechToTextProps): react_jsx_runtime.JSX.Element;
22
+ declare function SpeechToText({ className, speechToText, RecordAudioIcon, IdleAudioIcon, handleReplaceInput, setIsAudioRecording, onSendAudio, ...props }: SpeechToTextProps): react_jsx_runtime.JSX.Element;
22
23
 
23
24
  interface AssistantProps extends React$1.HTMLAttributes<HTMLDivElement> {
24
25
  sdk: AlquimiaSDK;
@@ -60,6 +61,7 @@ interface AssistantInputProps extends React$1.FormHTMLAttributes<HTMLFormElement
60
61
  handleInputChange: (event: React$1.ChangeEvent<HTMLInputElement>) => void;
61
62
  isMessageStreaming: boolean;
62
63
  speechToTextComponent?: React$1.ReactNode;
64
+ placeholders?: [string, string];
63
65
  }
64
66
  declare const AssistantInput: React$1.ForwardRefExoticComponent<AssistantInputProps & React$1.RefAttributes<HTMLFormElement>>;
65
67
 
@@ -17,8 +17,9 @@ interface SpeechToTextProps extends React.HTMLAttributes<HTMLDivElement> {
17
17
  speechToText: (audio: string) => Promise<string>;
18
18
  handleReplaceInput: (text: string) => void;
19
19
  setIsAudioRecording: React.Dispatch<React.SetStateAction<boolean>>;
20
+ onSendAudio?: () => void;
20
21
  }
21
- declare function SpeechToText({ className, speechToText, RecordAudioIcon, IdleAudioIcon, handleReplaceInput, setIsAudioRecording, ...props }: SpeechToTextProps): react_jsx_runtime.JSX.Element;
22
+ declare function SpeechToText({ className, speechToText, RecordAudioIcon, IdleAudioIcon, handleReplaceInput, setIsAudioRecording, onSendAudio, ...props }: SpeechToTextProps): react_jsx_runtime.JSX.Element;
22
23
 
23
24
  interface AssistantProps extends React$1.HTMLAttributes<HTMLDivElement> {
24
25
  sdk: AlquimiaSDK;
@@ -60,6 +61,7 @@ interface AssistantInputProps extends React$1.FormHTMLAttributes<HTMLFormElement
60
61
  handleInputChange: (event: React$1.ChangeEvent<HTMLInputElement>) => void;
61
62
  isMessageStreaming: boolean;
62
63
  speechToTextComponent?: React$1.ReactNode;
64
+ placeholders?: [string, string];
63
65
  }
64
66
  declare const AssistantInput: React$1.ForwardRefExoticComponent<AssistantInputProps & React$1.RefAttributes<HTMLFormElement>>;
65
67
 
@@ -143,12 +143,14 @@ function SpeechToText({
143
143
  IdleAudioIcon,
144
144
  handleReplaceInput,
145
145
  setIsAudioRecording,
146
+ onSendAudio,
146
147
  ...props
147
148
  }) {
148
149
  const [isRecording, setIsRecording] = (0, import_react2.useState)(false);
149
150
  const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
150
151
  const [mediaRecorder, setMediaRecorder] = (0, import_react2.useState)(null);
151
152
  const [audioBlob, setAudioBlob] = (0, import_react2.useState)(null);
153
+ const [speechResult, setSpeechResult] = (0, import_react2.useState)(null);
152
154
  const startRecording = async () => {
153
155
  setIsRecording(true);
154
156
  const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
@@ -172,6 +174,7 @@ function SpeechToText({
172
174
  const transcription = await speechToText(audioBase64);
173
175
  if (transcription) {
174
176
  handleReplaceInput(transcription);
177
+ setSpeechResult(transcription);
175
178
  setIsLoading(false);
176
179
  }
177
180
  } catch (error) {
@@ -189,6 +192,14 @@ function SpeechToText({
189
192
  (0, import_react2.useEffect)(() => {
190
193
  isLoading || isRecording ? setIsAudioRecording(true) : setIsAudioRecording(false);
191
194
  }, [isRecording, isLoading]);
195
+ (0, import_react2.useEffect)(() => {
196
+ if (speechResult) {
197
+ setTimeout(() => {
198
+ onSendAudio && onSendAudio();
199
+ setSpeechResult(null);
200
+ }, 200);
201
+ }
202
+ }, [speechResult]);
192
203
  const handleRecordButtonClick = () => {
193
204
  if (isRecording) {
194
205
  stopRecording();
@@ -2771,8 +2782,10 @@ var AssistantInput = React34.forwardRef(
2771
2782
  handleInputChange,
2772
2783
  isMessageStreaming,
2773
2784
  speechToTextComponent,
2785
+ placeholders,
2774
2786
  ...props
2775
2787
  }, ref) => {
2788
+ const placeholder = placeholders ? isMessageStreaming ? placeholders[0] : placeholders[1] : isMessageStreaming ? "Processing..." : "Type your message here...";
2776
2789
  return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
2777
2790
  "form",
2778
2791
  {
@@ -2788,7 +2801,7 @@ var AssistantInput = React34.forwardRef(
2788
2801
  disabled: isButtonDisabled,
2789
2802
  value: input,
2790
2803
  onChange: handleInputChange,
2791
- placeholder: isMessageStreaming ? "Procesando..." : "Escribe tu mensaje aqu\xED...",
2804
+ placeholder,
2792
2805
  className: cn(
2793
2806
  "flex-1 text-sm p-3 rounded-lg focus:outline-none w-full",
2794
2807
  "border border-input bg-background text-foreground",