11<!-- eslint-disable no-console -->
22<script setup lang="ts">
3- import type { Doc } from ' backend-convex/convex/_generated/dataModel'
3+ import type { Doc , Id } from ' backend-convex/convex/_generated/dataModel'
44import type Lenis from ' lenis'
55import { keyBy , sleep , uniquePromise } from ' @namesmt/utils'
66import { api } from ' backend-convex/convex/_generated/api'
@@ -47,7 +47,7 @@ const cachedThreadsMessages: {
4747 [threadId : string ]: Array <CustomMessage >
4848} = {}
4949const messages = ref <Array <CustomMessage >>([])
50- const messagesMapped = computed (() => keyBy (messages .value , ' id' ))
50+ const messagesKeyed = computed (() => keyBy (messages .value , ' id' ))
5151const streamingMessages = ref (0 )
5252const isFetching = ref (false )
5353const chatInput = ref (' ' )
@@ -144,6 +144,8 @@ async function handleSubmit({ input, confirmMultiStream = false }: HandleSubmitA
144144 streamId: undefined ,
145145 } as any as CustomMessage )
146146
147+ // For some reason creating object reference first does not work, so we push and then get last message
148+ const targetMessage = messages .value [messages .value .length - 1 ]!
147149 chatInput .value = ' '
148150
149151 nextTick (() => { doScrollBottom ({ tries: 2 }) })
@@ -166,7 +168,10 @@ async function handleSubmit({ input, confirmMultiStream = false }: HandleSubmitA
166168 generateThreadTitle (convex , { threadId: newThreadId , lockerKey })
167169 }
168170
169- const targetMessage = messages .value [messages .value .length - 1 ]!
171+ await until (threadIdRef ).toBeTruthy ({ timeout: 5000 , throwOnTimeout: true })
172+
173+ targetMessage .threadId = threadIdRef .value as Id <' threads' >
174+
170175 throttle (
171176 1 ,
172177 async () => await streamToMessage ({ message: targetMessage , content: userInput }),
@@ -175,7 +180,7 @@ async function handleSubmit({ input, confirmMultiStream = false }: HandleSubmitA
175180}
176181
177182async function resumeStreamProcess(streamSessionId : string , messageId : string ) {
178- const message = messagesMapped .value [messageId ]
183+ const message = messagesKeyed .value [messageId ]
179184 if (! message )
180185 return console .warn (' Trying to resume stream for message that does not exist:' , messageId )
181186
@@ -464,7 +469,7 @@ function alertIsStreaming(input: string) {
464469 <p >{{ $t('chat.message.copy') }}</p >
465470 </TooltipContent >
466471 </Tooltip >
467- <Tooltip :delay-duration =" 500" >
472+ <Tooltip v-show = " m.isStreaming === false " :delay-duration =" 500" >
468473 <TooltipTrigger as-child >
469474 <Button
470475 variant =" ghost" size =" icon" class =" size-7" @click =" _branchThreadFromMessage({
0 commit comments