@@ -5,6 +5,8 @@ import { capitalize } from "@cocalc/util/misc";
5
5
import { Actions , CodeEditorState } from "../code-editor/actions" ;
6
6
import { AI_ASSIST_TAG } from "./consts" ;
7
7
import { 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" ;
8
10
9
11
export interface Options {
10
12
codegen ?: boolean ;
@@ -29,11 +31,27 @@ export default async function createChat({
29
31
30
32
const { message } = await createChatMessage ( actions , frameId , options , input ) ;
31
33
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
+ }
37
55
38
56
await chatActions . sendChat ( {
39
57
input : message ,
@@ -43,7 +61,9 @@ export default async function createChat({
43
61
44
62
chatActions . scrollToBottom ( ) ;
45
63
// 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.
46
65
setTimeout ( ( ) => chatActions . scrollToBottom ( ) , 1000 ) ;
66
+ setTimeout ( ( ) => chatActions . scrollToBottom ( ) , 3000 ) ;
47
67
}
48
68
49
69
export async function createChatMessage (
0 commit comments