forked from mckaywrigley/chatbot-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.tsx
235 lines (211 loc) · 6.79 KB
/
context.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import { Tables } from "@/supabase/types"
import {
ChatFile,
ChatMessage,
ChatSettings,
LLM,
MessageImage,
OpenRouterLLM
} from "@/types"
import { AssistantImage } from "@/types/assistant-image"
import { Dispatch, SetStateAction, createContext } from "react"
interface ChatbotUIContext {
// PROFILE STORE
profile: Tables<"profiles"> | null
setProfile: Dispatch<SetStateAction<Tables<"profiles"> | null>>
// ITEMS STORE
assistants: Tables<"assistants">[]
collections: Tables<"collections">[]
chats: Tables<"chats">[]
files: Tables<"files">[]
folders: Tables<"folders">[]
presets: Tables<"presets">[]
prompts: Tables<"prompts">[]
tools: Tables<"tools">[]
workspaces: Tables<"workspaces">[]
setAssistants: Dispatch<SetStateAction<Tables<"assistants">[]>>
setCollections: Dispatch<SetStateAction<Tables<"collections">[]>>
setChats: Dispatch<SetStateAction<Tables<"chats">[]>>
setFiles: Dispatch<SetStateAction<Tables<"files">[]>>
setFolders: Dispatch<SetStateAction<Tables<"folders">[]>>
setPresets: Dispatch<SetStateAction<Tables<"presets">[]>>
setPrompts: Dispatch<SetStateAction<Tables<"prompts">[]>>
setTools: Dispatch<SetStateAction<Tables<"tools">[]>>
setWorkspaces: Dispatch<SetStateAction<Tables<"workspaces">[]>>
// MODELS STORE
availableLocalModels: LLM[]
setAvailableLocalModels: Dispatch<SetStateAction<LLM[]>>
availableOpenRouterModels: OpenRouterLLM[]
setAvailableOpenRouterModels: Dispatch<SetStateAction<OpenRouterLLM[]>>
// WORKSPACE STORE
selectedWorkspace: Tables<"workspaces"> | null
setSelectedWorkspace: Dispatch<SetStateAction<Tables<"workspaces"> | null>>
// PRESET STORE
selectedPreset: Tables<"presets"> | null
setSelectedPreset: Dispatch<SetStateAction<Tables<"presets"> | null>>
// ASSISTANT STORE
selectedAssistant: Tables<"assistants"> | null
assistantImages: AssistantImage[]
openaiAssistants: any[]
setSelectedAssistant: Dispatch<SetStateAction<Tables<"assistants"> | null>>
setAssistantImages: Dispatch<SetStateAction<AssistantImage[]>>
setOpenaiAssistants: Dispatch<SetStateAction<any[]>>
// PASSIVE CHAT STORE
userInput: string
chatMessages: ChatMessage[]
chatSettings: ChatSettings | null
selectedChat: Tables<"chats"> | null
chatFileItems: Tables<"file_items">[]
setUserInput: Dispatch<SetStateAction<string>>
setChatMessages: Dispatch<SetStateAction<ChatMessage[]>>
setChatSettings: Dispatch<SetStateAction<ChatSettings>>
setSelectedChat: Dispatch<SetStateAction<Tables<"chats"> | null>>
setChatFileItems: Dispatch<SetStateAction<Tables<"file_items">[]>>
// ACTIVE CHAT STORE
abortController: AbortController | null
firstTokenReceived: boolean
isGenerating: boolean
setAbortController: Dispatch<SetStateAction<AbortController | null>>
setFirstTokenReceived: Dispatch<SetStateAction<boolean>>
setIsGenerating: Dispatch<SetStateAction<boolean>>
// CHAT INPUT COMMAND STORE
isPromptPickerOpen: boolean
slashCommand: string
isAtPickerOpen: boolean
atCommand: string
isToolPickerOpen: boolean
toolCommand: string
focusPrompt: boolean
focusFile: boolean
focusTool: boolean
setIsPromptPickerOpen: Dispatch<SetStateAction<boolean>>
setSlashCommand: Dispatch<SetStateAction<string>>
setIsAtPickerOpen: Dispatch<SetStateAction<boolean>>
setAtCommand: Dispatch<SetStateAction<string>>
setIsToolPickerOpen: Dispatch<SetStateAction<boolean>>
setToolCommand: Dispatch<SetStateAction<string>>
setFocusPrompt: Dispatch<SetStateAction<boolean>>
setFocusFile: Dispatch<SetStateAction<boolean>>
setFocusTool: Dispatch<SetStateAction<boolean>>
// ATTACHMENTS STORE
chatFiles: ChatFile[]
chatImages: MessageImage[]
newMessageFiles: ChatFile[]
newMessageImages: MessageImage[]
showFilesDisplay: boolean
setChatFiles: Dispatch<SetStateAction<ChatFile[]>>
setChatImages: Dispatch<SetStateAction<MessageImage[]>>
setNewMessageFiles: Dispatch<SetStateAction<ChatFile[]>>
setNewMessageImages: Dispatch<SetStateAction<MessageImage[]>>
setShowFilesDisplay: Dispatch<SetStateAction<boolean>>
// RETRIEVAL STORE
useRetrieval: boolean
sourceCount: number
setUseRetrieval: Dispatch<SetStateAction<boolean>>
setSourceCount: Dispatch<SetStateAction<number>>
// TOOL STORE
selectedTools: Tables<"tools">[]
setSelectedTools: Dispatch<SetStateAction<Tables<"tools">[]>>
toolInUse: string
setToolInUse: Dispatch<SetStateAction<string>>
}
export const ChatbotUIContext = createContext<ChatbotUIContext>({
// PROFILE STORE
profile: null,
setProfile: () => {},
// ITEMS STORE
assistants: [],
collections: [],
chats: [],
files: [],
folders: [],
presets: [],
prompts: [],
tools: [],
workspaces: [],
setAssistants: () => {},
setCollections: () => {},
setChats: () => {},
setFiles: () => {},
setFolders: () => {},
setPresets: () => {},
setPrompts: () => {},
setTools: () => {},
setWorkspaces: () => {},
// MODELS STORE
availableLocalModels: [],
setAvailableLocalModels: () => {},
availableOpenRouterModels: [],
setAvailableOpenRouterModels: () => {},
// WORKSPACE STORE
selectedWorkspace: null,
setSelectedWorkspace: () => {},
// PRESET STORE
selectedPreset: null,
setSelectedPreset: () => {},
// ASSISTANT STORE
selectedAssistant: null,
assistantImages: [],
openaiAssistants: [],
setSelectedAssistant: () => {},
setAssistantImages: () => {},
setOpenaiAssistants: () => {},
// PASSIVE CHAT STORE
userInput: "",
selectedChat: null,
chatMessages: [],
chatSettings: null,
chatFileItems: [],
setUserInput: () => {},
setChatMessages: () => {},
setChatSettings: () => {},
setSelectedChat: () => {},
setChatFileItems: () => {},
// CHAT INPUT COMMAND STORE
isPromptPickerOpen: false,
slashCommand: "",
isAtPickerOpen: false,
atCommand: "",
isToolPickerOpen: false,
toolCommand: "",
focusPrompt: false,
focusFile: false,
focusTool: false,
setIsPromptPickerOpen: () => {},
setSlashCommand: () => {},
setIsAtPickerOpen: () => {},
setAtCommand: () => {},
setIsToolPickerOpen: () => {},
setToolCommand: () => {},
setFocusPrompt: () => {},
setFocusFile: () => {},
setFocusTool: () => {},
// ACTIVE CHAT STORE
isGenerating: false,
firstTokenReceived: false,
abortController: null,
setIsGenerating: () => {},
setFirstTokenReceived: () => {},
setAbortController: () => {},
// ATTACHMENTS STORE
chatFiles: [],
chatImages: [],
newMessageFiles: [],
newMessageImages: [],
showFilesDisplay: false,
setChatFiles: () => {},
setChatImages: () => {},
setNewMessageFiles: () => {},
setNewMessageImages: () => {},
setShowFilesDisplay: () => {},
// RETRIEVAL STORE
useRetrieval: false,
sourceCount: 4,
setUseRetrieval: () => {},
setSourceCount: () => {},
// TOOL STORE
selectedTools: [],
setSelectedTools: () => {},
toolInUse: "none",
setToolInUse: () => {}
})