1
- // client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
2
- import { UICompBuilder } from "comps/generators" ;
3
- import { NameConfig , withExposingConfigs } from "comps/generators/withExposing" ;
4
- import { chatChildrenMap } from "./chatCompTypes" ;
5
- import { ChatView } from "./chatView" ;
6
- import { ChatPropertyView } from "./chatPropertyView" ;
7
-
8
- // Build the component
9
- const ChatTmpComp = new UICompBuilder (
10
- chatChildrenMap ,
11
- ( props , dispatch ) => (
12
- < ChatView
13
- { ...props }
14
- chatQuery = { props . chatQuery . value }
15
- currentMessage = { props . currentMessage . value }
16
- dispatch = { dispatch }
17
- />
18
- )
19
- )
20
- . setPropertyViewFn ( ( children ) => < ChatPropertyView children = { children } /> )
21
- . build ( ) ;
22
-
23
- // Export the component with exposed variables
24
- export const ChatComp = withExposingConfigs ( ChatTmpComp , [
25
- new NameConfig ( "text" , "Chat component text" ) ,
26
- new NameConfig ( "currentMessage" , "Current user message" ) ,
1
+ // client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
2
+
3
+ import { UICompBuilder } from "comps/generators" ;
4
+ import { NameConfig , withExposingConfigs } from "comps/generators/withExposing" ;
5
+ import { StringControl } from "comps/controls/codeControl" ;
6
+ import { stringExposingStateControl } from "comps/controls/codeStateControl" ;
7
+ import { withDefault } from "comps/generators" ;
8
+ import { BoolControl } from "comps/controls/boolControl" ;
9
+ import { dropdownControl } from "comps/controls/dropdownControl" ;
10
+ import QuerySelectControl from "comps/controls/querySelectControl" ;
11
+ import { ChatCore } from "./components/ChatCore" ;
12
+ import { ChatPropertyView } from "./chatPropertyView" ;
13
+ import { createChatStorage } from "./utils/storageFactory" ;
14
+ import { QueryHandler , createMessageHandler } from "./handlers/messageHandlers" ;
15
+ import { useMemo } from "react" ;
16
+ import { changeChildAction } from "lowcoder-core" ;
17
+
18
+ import "@assistant-ui/styles/index.css" ;
19
+ import "@assistant-ui/styles/markdown.css" ;
20
+
21
+ // ============================================================================
22
+ // SIMPLIFIED CHILDREN MAP - ONLY ESSENTIAL PROPS
23
+ // ============================================================================
24
+
25
+ const ModelTypeOptions = [
26
+ { label : "Query" , value : "query" } ,
27
+ { label : "N8N Workflow" , value : "n8n" } ,
28
+ ] as const ;
29
+
30
+ export const chatChildrenMap = {
31
+ // Storage
32
+ tableName : withDefault ( StringControl , "default" ) ,
33
+
34
+ // Message Handler Configuration
35
+ handlerType : dropdownControl ( ModelTypeOptions , "query" ) ,
36
+ chatQuery : QuerySelectControl , // Only used for "query" type
37
+ modelHost : withDefault ( StringControl , "" ) , // Only used for "n8n" type
38
+ systemPrompt : withDefault ( StringControl , "You are a helpful assistant." ) ,
39
+ streaming : BoolControl . DEFAULT_TRUE ,
40
+
41
+ // UI Configuration
42
+ placeholder : withDefault ( StringControl , "Chat Component" ) ,
43
+
44
+ // Exposed Variables (not shown in Property View)
45
+ currentMessage : stringExposingStateControl ( "currentMessage" , "" ) ,
46
+ } ;
47
+
48
+ // ============================================================================
49
+ // CLEAN CHATCOMP - USES NEW ARCHITECTURE
50
+ // ============================================================================
51
+
52
+ const ChatTmpComp = new UICompBuilder (
53
+ chatChildrenMap ,
54
+ ( props , dispatch ) => {
55
+ // Create storage from tableName
56
+ const storage = useMemo ( ( ) =>
57
+ createChatStorage ( props . tableName ) ,
58
+ [ props . tableName ]
59
+ ) ;
60
+
61
+ // Create message handler based on type
62
+ const messageHandler = useMemo ( ( ) => {
63
+ const handlerType = props . handlerType ;
64
+
65
+ if ( handlerType === "query" ) {
66
+ return new QueryHandler ( {
67
+ chatQuery : props . chatQuery . value ,
68
+ dispatch,
69
+ streaming : props . streaming
70
+ } ) ;
71
+ } else if ( handlerType === "n8n" ) {
72
+ return createMessageHandler ( "n8n" , {
73
+ modelHost : props . modelHost ,
74
+ systemPrompt : props . systemPrompt ,
75
+ streaming : props . streaming
76
+ } ) ;
77
+ } else {
78
+ // Fallback to mock handler
79
+ return createMessageHandler ( "mock" , {
80
+ chatQuery : props . chatQuery . value ,
81
+ dispatch,
82
+ streaming : props . streaming
83
+ } ) ;
84
+ }
85
+ } , [
86
+ props . handlerType ,
87
+ props . chatQuery ,
88
+ props . modelHost ,
89
+ props . systemPrompt ,
90
+ props . streaming ,
91
+ dispatch
92
+ ] ) ;
93
+
94
+ // Handle message updates for exposed variable
95
+ const handleMessageUpdate = ( message : string ) => {
96
+ dispatch ( changeChildAction ( "currentMessage" , message , false ) ) ;
97
+ } ;
98
+
99
+ return (
100
+ < ChatCore
101
+ storage = { storage }
102
+ messageHandler = { messageHandler }
103
+ onMessageUpdate = { handleMessageUpdate }
104
+ />
105
+ ) ;
106
+ }
107
+ )
108
+ . setPropertyViewFn ( ( children ) => < ChatPropertyView children = { children } /> )
109
+ . build ( ) ;
110
+
111
+ // ============================================================================
112
+ // EXPORT WITH EXPOSED VARIABLES
113
+ // ============================================================================
114
+
115
+ export const ChatComp = withExposingConfigs ( ChatTmpComp , [
116
+ new NameConfig ( "currentMessage" , "Current user message" ) ,
27
117
] ) ;
0 commit comments