@@ -5,6 +5,8 @@ import { capitalize } from "@cocalc/util/misc";
55import { Actions , CodeEditorState } from "../code-editor/actions" ;
66import { AI_ASSIST_TAG } from "./consts" ;
77import { modelToMention } from "./llm-selector" ;
8+ import type { ChatActions } from "@cocalc/frontend/chat/actions" ;
9+ import type { Actions as ChatEditorActions } from "@cocalc/frontend/frame-editors/chat-editor/actions" ;
810
911export interface Options {
1012 codegen ?: boolean ;
@@ -29,11 +31,27 @@ export default async function createChat({
2931
3032 const { message } = await createChatMessage ( actions , frameId , options , input ) ;
3133
32- const chatActions = await getChatActions (
33- actions . redux ,
34- actions . project_id ,
35- actions . path ,
36- ) ;
34+ let chatActions : ChatActions | undefined ;
35+ if ( actions . path . endsWith ( ".sage-chat" ) ) {
36+ // a full chatroom (not a different doc type)
37+ chatActions = ( actions as ChatEditorActions ) . getChatActions ( frameId ) ;
38+ if ( chatActions == null ) {
39+ const id = actions . show_focused_frame_of_type ( "chatroom" ) ;
40+ chatActions = ( actions as ChatEditorActions ) . getChatActions ( id ) ;
41+ if ( chatActions == null ) {
42+ console . warn ( "Bug getting chatroom" ) ;
43+ // this should be impossible -- fallback to side chat.
44+ }
45+ }
46+ }
47+ if ( chatActions == null ) {
48+ // get side chat-specific actions
49+ chatActions = await getChatActions (
50+ actions . redux ,
51+ actions . project_id ,
52+ actions . path ,
53+ ) ;
54+ }
3755
3856 await chatActions . sendChat ( {
3957 input : message ,
@@ -43,7 +61,9 @@ export default async function createChat({
4361
4462 chatActions . scrollToBottom ( ) ;
4563 // scroll to bottom again *after* the message starts getting responded to.
64+ // Don't scroll too much though, since user wants to actual stop and READ.
4665 setTimeout ( ( ) => chatActions . scrollToBottom ( ) , 1000 ) ;
66+ setTimeout ( ( ) => chatActions . scrollToBottom ( ) , 3000 ) ;
4767}
4868
4969export async function createChatMessage (
0 commit comments