11import useCommands from "@/lib/hooks/use-commands" ;
2- import { Command , MenuAction } from "@/lib/types" ;
2+ import { Command } from "@/lib/types" ;
33import {
44 addToast ,
55 Button ,
@@ -25,16 +25,20 @@ const inputPlaceholders = [
2525export default function CommandViewer ( ) {
2626 const editorContext = useContext ( EditorContext ) ;
2727
28- const { chatWithAssistant } = usePlatformAIAssistant ( ) ;
28+ const { chatWithAssistant, history } = usePlatformAIAssistant ( ) ;
2929 const { commands, runCommand, setKeywordFilter } = useCommands ( ) ;
30- const { registerMenuAction, unregisterMenuAction } = useMenuActions ( "view" ) ;
3130
3231 const [ inputPlaceholder , setInputPlaceholder ] = useState ( "" ) ;
3332 const [ selectCommandIndex , setSelectCommandIndex ] = useState ( - 1 ) ;
3433 const [ inputTextValue , setInputTextValue ] = useState ( "" ) ;
34+ const [ inputAudioValue , setInputAudioValue ] = useState <
35+ ReadableStream < ArrayBuffer > | undefined
36+ > ( undefined ) ;
3537 const [ isInputVoice , setIsInputVoice ] = useState ( false ) ;
3638 const [ isOutputVoice , setIsOutputVoice ] = useState ( false ) ;
3739
40+ const historyRef = useRef < HTMLDivElement > ( null ) ;
41+
3842 const runCommandCallback = useCallback (
3943 async ( command : Command ) => {
4044 const result = await runCommand ( command , { } ) ;
@@ -81,6 +85,13 @@ export default function CommandViewer() {
8185 handlePressedKeys ( editorContext ?. editorStates . pressedKeys ?? [ ] ) ;
8286 } , [ editorContext ?. editorStates . pressedKeys ] ) ;
8387
88+ // Scroll to bottom when history changes
89+ useEffect ( ( ) => {
90+ if ( historyRef . current ) {
91+ historyRef . current . scrollTop = historyRef . current . scrollHeight ;
92+ }
93+ } , [ history ] ) ;
94+
8495 function handleKeyDown ( e : KeyboardEvent ) {
8596 // Prevent default behavior for certain keys
8697 const key = e . key ;
@@ -157,9 +168,12 @@ export default function CommandViewer() {
157168 } else if ( isEnterPressed && ! isControlPressed ) {
158169 // Chat with assistant if ctrl is not pressed
159170 console . log ( "Chatting with assistant" ) ;
160- chatWithAssistant ( inputTextValue , isOutputVoice ) ;
161- }
162- else if ( isArrowUpPressed ) {
171+ if ( isInputVoice ) {
172+ chatWithAssistant ( inputAudioValue , isOutputVoice ) ;
173+ } else {
174+ chatWithAssistant ( inputTextValue , isOutputVoice ) ;
175+ }
176+ } else if ( isArrowUpPressed ) {
163177 setSelectCommandIndex ( ( prev ) =>
164178 prev === 0 ? commands . length - 1 : prev - 1 ,
165179 ) ;
@@ -222,6 +236,29 @@ export default function CommandViewer() {
222236 onKeyDown = { ( e ) => handleKeyDown ( e as any ) }
223237 onKeyUp = { ( e ) => handleKeyUp ( e as any ) }
224238 />
239+
240+ { history . length > 0 && (
241+ < div
242+ ref = { historyRef }
243+ className = "bg-content1 flex max-h-60 flex-col gap-y-1 overflow-y-auto rounded-2xl p-2 shadow-md"
244+ >
245+ { history . map ( ( entry , index ) => (
246+ < div key = { index } >
247+ { entry . role === "user" ? (
248+ < div className = "text-primary-foreground bg-primary rounded-lg p-2 text-sm" >
249+ < span className = "font-bold" > You: </ span >
250+ { entry . message . content . text }
251+ </ div >
252+ ) : (
253+ < div className = "text-default-foreground bg-default rounded-lg p-2 text-sm" >
254+ < span className = "font-bold" > Assistant: </ span >
255+ { entry . message . content . text }
256+ </ div >
257+ ) }
258+ </ div >
259+ ) ) }
260+ </ div >
261+ ) }
225262 < div className = "bg-content1 rounded-2xl shadow-md" >
226263 < div className = "px-3 pt-2" >
227264 < p className = "text-sm font-bold whitespace-nowrap" >
0 commit comments