@@ -20,13 +20,23 @@ export type ChatStoreState = {
2020}
2121
2222type ChatStoreActions = {
23- setMessages : ( value : ChatMessage [ ] | ( ( prev : ChatMessage [ ] ) => ChatMessage [ ] ) ) => void
24- setStreamingAgents : ( value : Set < string > | ( ( prev : Set < string > ) => Set < string > ) ) => void
25- setCollapsedAgents : ( value : Set < string > | ( ( prev : Set < string > ) => Set < string > ) ) => void
26- setFocusedAgentId : ( value : string | null | ( ( prev : string | null ) => string | null ) ) => void
23+ setMessages : (
24+ value : ChatMessage [ ] | ( ( prev : ChatMessage [ ] ) => ChatMessage [ ] ) ,
25+ ) => void
26+ setStreamingAgents : (
27+ value : Set < string > | ( ( prev : Set < string > ) => Set < string > ) ,
28+ ) => void
29+ setCollapsedAgents : (
30+ value : Set < string > | ( ( prev : Set < string > ) => Set < string > ) ,
31+ ) => void
32+ setFocusedAgentId : (
33+ value : string | null | ( ( prev : string | null ) => string | null ) ,
34+ ) => void
2735 setInputValue : ( value : string | ( ( prev : string ) => string ) ) => void
2836 setInputFocused : ( focused : boolean ) => void
29- setActiveSubagents : ( value : Set < string > | ( ( prev : Set < string > ) => Set < string > ) ) => void
37+ setActiveSubagents : (
38+ value : Set < string > | ( ( prev : Set < string > ) => Set < string > ) ,
39+ ) => void
3040 setIsChainInProgress : ( active : boolean ) => void
3141 setSlashSelectedIndex : ( value : number | ( ( prev : number ) => number ) ) => void
3242 setAgentSelectedIndex : ( value : number | ( ( prev : number ) => number ) ) => void
@@ -38,15 +48,7 @@ type ChatStore = ChatStoreState & ChatStoreActions
3848enableMapSet ( )
3949
4050const initialState : ChatStoreState = {
41- messages : [
42- {
43- id : 'ai-seed-1' ,
44- variant : 'ai' ,
45- content :
46- "Hey there! Welcome to the demo — feel free to ask anything or just say hello when you're ready." ,
47- timestamp : formatTimestamp ( ) ,
48- } ,
49- ] ,
51+ messages : [ ] ,
5052 streamingAgents : new Set < string > ( ) ,
5153 collapsedAgents : new Set < string > ( ) ,
5254 focusedAgentId : null ,
@@ -58,70 +60,80 @@ const initialState: ChatStoreState = {
5860 agentSelectedIndex : 0 ,
5961}
6062
61- export const useChatStore = create < ChatStore > ( ) ( immer ( ( set ) => ( {
62- ...initialState ,
63-
64- setMessages : ( value ) =>
65- set ( ( state ) => {
66- state . messages = typeof value === 'function' ? value ( state . messages ) : value
67- } ) ,
68-
69- setStreamingAgents : ( value ) =>
70- set ( ( state ) => {
71- state . streamingAgents = typeof value === 'function' ? value ( state . streamingAgents ) : value
72- } ) ,
73-
74- setCollapsedAgents : ( value ) =>
75- set ( ( state ) => {
76- state . collapsedAgents = typeof value === 'function' ? value ( state . collapsedAgents ) : value
77- } ) ,
78-
79- setFocusedAgentId : ( value ) =>
80- set ( ( state ) => {
81- state . focusedAgentId = typeof value === 'function' ? value ( state . focusedAgentId ) : value
82- } ) ,
83-
84- setInputValue : ( value ) =>
85- set ( ( state ) => {
86- state . inputValue = typeof value === 'function' ? value ( state . inputValue ) : value
87- } ) ,
88-
89- setInputFocused : ( focused ) =>
90- set ( ( state ) => {
91- state . inputFocused = focused
92- } ) ,
93-
94- setActiveSubagents : ( value ) =>
95- set ( ( state ) => {
96- state . activeSubagents = typeof value === 'function' ? value ( state . activeSubagents ) : value
97- } ) ,
98-
99- setIsChainInProgress : ( active ) =>
100- set ( ( state ) => {
101- state . isChainInProgress = active
102- } ) ,
103-
104- setSlashSelectedIndex : ( value ) =>
105- set ( ( state ) => {
106- state . slashSelectedIndex = typeof value === 'function' ? value ( state . slashSelectedIndex ) : value
107- } ) ,
108-
109- setAgentSelectedIndex : ( value ) =>
110- set ( ( state ) => {
111- state . agentSelectedIndex = typeof value === 'function' ? value ( state . agentSelectedIndex ) : value
112- } ) ,
113-
114- reset : ( ) =>
115- set ( ( state ) => {
116- state . messages = initialState . messages . slice ( )
117- state . streamingAgents = new Set ( initialState . streamingAgents )
118- state . collapsedAgents = new Set ( initialState . collapsedAgents )
119- state . focusedAgentId = initialState . focusedAgentId
120- state . inputValue = initialState . inputValue
121- state . inputFocused = initialState . inputFocused
122- state . activeSubagents = new Set ( initialState . activeSubagents )
123- state . isChainInProgress = initialState . isChainInProgress
124- state . slashSelectedIndex = initialState . slashSelectedIndex
125- state . agentSelectedIndex = initialState . agentSelectedIndex
126- } ) ,
127- } ) ) )
63+ export const useChatStore = create < ChatStore > ( ) (
64+ immer ( ( set ) => ( {
65+ ...initialState ,
66+
67+ setMessages : ( value ) =>
68+ set ( ( state ) => {
69+ state . messages =
70+ typeof value === 'function' ? value ( state . messages ) : value
71+ } ) ,
72+
73+ setStreamingAgents : ( value ) =>
74+ set ( ( state ) => {
75+ state . streamingAgents =
76+ typeof value === 'function' ? value ( state . streamingAgents ) : value
77+ } ) ,
78+
79+ setCollapsedAgents : ( value ) =>
80+ set ( ( state ) => {
81+ state . collapsedAgents =
82+ typeof value === 'function' ? value ( state . collapsedAgents ) : value
83+ } ) ,
84+
85+ setFocusedAgentId : ( value ) =>
86+ set ( ( state ) => {
87+ state . focusedAgentId =
88+ typeof value === 'function' ? value ( state . focusedAgentId ) : value
89+ } ) ,
90+
91+ setInputValue : ( value ) =>
92+ set ( ( state ) => {
93+ state . inputValue =
94+ typeof value === 'function' ? value ( state . inputValue ) : value
95+ } ) ,
96+
97+ setInputFocused : ( focused ) =>
98+ set ( ( state ) => {
99+ state . inputFocused = focused
100+ } ) ,
101+
102+ setActiveSubagents : ( value ) =>
103+ set ( ( state ) => {
104+ state . activeSubagents =
105+ typeof value === 'function' ? value ( state . activeSubagents ) : value
106+ } ) ,
107+
108+ setIsChainInProgress : ( active ) =>
109+ set ( ( state ) => {
110+ state . isChainInProgress = active
111+ } ) ,
112+
113+ setSlashSelectedIndex : ( value ) =>
114+ set ( ( state ) => {
115+ state . slashSelectedIndex =
116+ typeof value === 'function' ? value ( state . slashSelectedIndex ) : value
117+ } ) ,
118+
119+ setAgentSelectedIndex : ( value ) =>
120+ set ( ( state ) => {
121+ state . agentSelectedIndex =
122+ typeof value === 'function' ? value ( state . agentSelectedIndex ) : value
123+ } ) ,
124+
125+ reset : ( ) =>
126+ set ( ( state ) => {
127+ state . messages = initialState . messages . slice ( )
128+ state . streamingAgents = new Set ( initialState . streamingAgents )
129+ state . collapsedAgents = new Set ( initialState . collapsedAgents )
130+ state . focusedAgentId = initialState . focusedAgentId
131+ state . inputValue = initialState . inputValue
132+ state . inputFocused = initialState . inputFocused
133+ state . activeSubagents = new Set ( initialState . activeSubagents )
134+ state . isChainInProgress = initialState . isChainInProgress
135+ state . slashSelectedIndex = initialState . slashSelectedIndex
136+ state . agentSelectedIndex = initialState . agentSelectedIndex
137+ } ) ,
138+ } ) ) ,
139+ )
0 commit comments