Skip to content
Open
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
5a61a35
remove unused import
ckouder Jan 27, 2026
354bad2
WIP: replace fetch course metadata
ckouder Jan 28, 2026
73e306e
replace fetch course metadata with react query hook
ckouder Jan 28, 2026
4ca047c
use node 22
ckouder Feb 2, 2026
921e4bc
Merge branch 'refactor/refactor-queries' into refactor/refactor-queri…
ckouder Feb 3, 2026
456d0f3
fetch replace: fetchCourseMetadata
ckouder Feb 3, 2026
e11872b
Merge branch 'illinois-chat' into refactor/refactor-queries-2
ckouder Feb 3, 2026
a055caa
make fetchCourseMetadata internal
ckouder Feb 3, 2026
6e9593a
fetch replace: getContexts
ckouder Feb 3, 2026
a63f4d2
fetch replace: /api/UIUC-api/chat-file-upload
ckouder Feb 3, 2026
add9057
fetch replace: /api/UIUC-api/downloadConvoHistoryUser
ckouder Feb 3, 2026
e9917db
fetch replace: /api/UIUC-api/getPresignedUrl
ckouder Feb 3, 2026
01b8eed
fetch replace: /api/UIUC-api/ingestCanvas
ckouder Feb 3, 2026
579ca62
fetch replace: /api/UIUC-api/getAllCourseNames
ckouder Feb 3, 2026
1f7e545
fetch replace: /api/UIUC-api/uploadToS3
ckouder Feb 3, 2026
bf6e5a0
fetch replace: /api/UIUC-api/ingest
ckouder Feb 3, 2026
821d78b
fetch replace: /api/UIUC-api/getMaintenanceModeDetails
ckouder Feb 3, 2026
4dac526
fetch replace: /api/UIUC-api/getCourseExists
ckouder Feb 3, 2026
2e71ea2
fetch replace: /api/UIUC-api/getAllCourseData
ckouder Feb 3, 2026
84cb255
fetch replace: /api/UIUC-api/getConversationStats
ckouder Feb 3, 2026
73a06a0
fetch replace: /api/UIUC-api/getProjectStats
ckouder Feb 3, 2026
f3f1765
fetch replace: /api/UIUC-api/getWeeklyTrends
ckouder Feb 3, 2026
54ee78a
fetch replace: /api/UIUC-api/getModelUsageCounts
ckouder Feb 3, 2026
5e8d274
fetch replace: /api/UIUC-api/tools/testN8nAPI
ckouder Feb 3, 2026
47b4cac
fetch replace: /api/UIUC-api/tools/testN8nAPI
ckouder Feb 3, 2026
6a86603
fetch replace: /api/UIUC-api/tools/upsertN8nAPIKey
ckouder Feb 3, 2026
153ecd6
fetch replace: /api/UIUC-api/getN8Napikey
ckouder Feb 3, 2026
f972a19
fetch replace: /api/UIUC-api/tools/activateWorkflow
ckouder Feb 3, 2026
6a4f02d
fetch replace: /api/UIUC-api/getAllCourseMetadata
ckouder Feb 3, 2026
e2bacbd
fetch replace: /api/UIUC-api/getMaintenanceModeFast
ckouder Feb 3, 2026
0b04854
fetch replace /api/UIUC-api/newsletterUnsubscribe
ckouder Feb 3, 2026
da9944d
fetch replace: /api/chat-api/keys/generate
ckouder Feb 3, 2026
1a5c4c7
fetch replace: /api/chat-api/keys/fetch
ckouder Feb 3, 2026
ee58889
fetch replace: /api/chat-api/keys/rotate
ckouder Feb 3, 2026
e1967a2
fetch replace: /api/chat-api/keys/delete
ckouder Feb 3, 2026
1f1cb08
fetch replace: /api/materialsTable/successDocs
ckouder Feb 3, 2026
fb3386a
fetch replace: /api/materialsTable/fetchProjectMaterials
ckouder Feb 3, 2026
0492a33
fetch replace: /api/materialsTable/docsInProgress
ckouder Feb 3, 2026
dba6207
fetch replace: /api/models
ckouder Feb 3, 2026
93bf5db
fetch replace: /api/materialsTable/fetchFailedDocuments
ckouder Feb 3, 2026
c37229c
fetch replace: /api/getNomicMapForQueries
ckouder Feb 3, 2026
baa2fdc
fetch replace: /api/getNomicMapForQueries
ckouder Feb 3, 2026
2c1160a
Merge branch 'refactor-queries-3' into refactor/refactor-queries
ckouder Feb 3, 2026
4c53970
remove unused files; update ApiKeyManagement
ckouder Feb 4, 2026
05b95f0
fetch replace: /api/UIUC-api/logConversation
ckouder Feb 4, 2026
523bbc4
fetch replace: /api/materialsTable/fetchProjectMaterials
ckouder Feb 4, 2026
bf0ebaa
fetch replace: /api/getDefaultPostPrompt
ckouder Feb 4, 2026
f39042a
fetch replace: /api/allNewRoutingChat
ckouder Feb 4, 2026
20b714d
replace callSetCourseMetadata with react query hook
ckouder Feb 4, 2026
536edd9
WIP: refactor ChatInput for getPresignedUrl
ckouder Feb 6, 2026
bc4ad95
Merge branch 'illinois-chat' into refactor/refactor-queries
ckouder Feb 6, 2026
e04f965
fix test cases
ckouder Feb 6, 2026
1751266
uncomment shard6
ckouder Feb 6, 2026
5a79e40
fetch replace: /api/UIUC-api/createProject
ckouder Feb 11, 2026
66ef0d2
fetch replace: fetchContexts
ckouder Feb 11, 2026
5f903dd
remove unused files
ckouder Feb 11, 2026
e68b9ec
add more react query hooks
ckouder Feb 11, 2026
86da228
add types for react query hooks
ckouder Feb 11, 2026
4bc4765
add more types for react query hooks
ckouder Feb 12, 2026
ad9520f
add comments and sort import
ckouder Feb 12, 2026
eeac86c
unify conversation history download hooks and harden folder errors
ckouder Feb 20, 2026
c8e5c04
fix tests
ckouder Feb 20, 2026
5fb561a
unify download hooks and standardize query error handling
ckouder Feb 20, 2026
3616ee1
complete track a query refactor and centralize query keys
ckouder Feb 20, 2026
87fd948
fix tests
ckouder Feb 20, 2026
e4fd5b1
add query keys for react query hooks
ckouder Feb 23, 2026
ab7eef1
sort query keys
ckouder Feb 25, 2026
ea5d352
remove api key input from chatbar
ckouder Feb 25, 2026
440e4f5
remove plugins
ckouder Feb 25, 2026
5b45732
WIP: clean up home state with react query hook state variables
ckouder Feb 25, 2026
bf39177
home state clean up - replace modelError with react query hook variable
ckouder Feb 25, 2026
23b665d
home state clean up - remove selectedModel because never used
ckouder Feb 25, 2026
45a0b94
home state clean up - replace llmProviders with react query hook vari…
ckouder Feb 25, 2026
b2fbf66
home state clean up - replace isImg2TextLoading with react query hook…
ckouder Feb 25, 2026
dafd651
home state clean up - replace isRouting with react query hook variables
ckouder Feb 25, 2026
31f53e7
replace remaining state variables with react query hook state variables
ckouder Feb 25, 2026
9151771
add CLAUDE.md
ckouder Feb 25, 2026
c27a5e8
update refactoring progress
ckouder Feb 25, 2026
89f8aa2
add more coverage tests
ckouder Feb 25, 2026
98ba593
Potential fix for code scanning alert no. 208: Incomplete string esca…
ckouder Feb 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.12.0
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.12.0
2 changes: 1 addition & 1 deletion __tests__/pages/api/__tests__/getContexts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vi.mock('~/pages/api/authorization', () => ({
withCourseAccessFromRequest: () => (h: any) => h,
}))

vi.mock('~/pages/util/fetchContexts', () => ({
vi.mock('~/hooks/__internal__/fetchContextsFromBackend', () => ({
default: hoisted.fetchContextsFromBackend,
}))

Expand Down
121 changes: 49 additions & 72 deletions src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// src/components/Chat/Chat.tsx
import { useDownloadPresignedUrlQuery } from '~/hooks/queries/useDownloadPresignedUrl'
import { useFetchEnabledDocGroups } from '@/hooks/queries/useFetchEnabledDocGroups'
import { useFetchLLMProviders } from '@/hooks/queries/useFetchLLMProviders'
import { useDeleteMessages } from '@/hooks/queries/useDeleteMessages'
import { useLogConversation } from '@/hooks/queries/useLogConversation'
import { useQueryRewrite } from '@/hooks/queries/useQueryRewrite'
import { useRouteChat } from '@/hooks/queries/useRouteChat'
import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'

import { Button, Text } from '@mantine/core'
import {
IconAlertCircle,
Expand Down Expand Up @@ -29,7 +38,6 @@ import { v4 as uuidv4 } from 'uuid'

import HomeContext from '~/pages/api/home/home.context'

import { fetchPresignedUrl } from '~/utils/apiUtils'
import { ChatInput } from './ChatInput'
import { ChatLoader } from './ChatLoader'
import { ErrorMessageDiv } from './ErrorMessageDiv'
Expand Down Expand Up @@ -57,13 +65,6 @@ import { Montserrat } from 'next/font/google'
import Head from 'next/head'
import { useRouter } from 'next/router'
import { useAuth } from 'react-oidc-context'
import { useFetchEnabledDocGroups } from '@/hooks/queries/useFetchEnabledDocGroups'
import { useFetchLLMProviders } from '@/hooks/queries/useFetchLLMProviders'
import { useDeleteMessages } from '@/hooks/queries/useDeleteMessages'
import { useLogConversation } from '@/hooks/queries/useLogConversation'
import { useQueryRewrite } from '@/hooks/queries/useQueryRewrite'
import { useRouteChat } from '@/hooks/queries/useRouteChat'
import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
import { CropwizardLicenseDisclaimer } from '~/pages/cropwizard-licenses'

import { get_user_permission } from '~/components/UIUC-Components/runAuthCheck'
Expand Down Expand Up @@ -110,57 +111,44 @@ export const Chat = memo(
const auth = useAuth()
const router = useRouter()
const queryClient = useQueryClient()
const { refetch: refetchLLMProviders } = useFetchLLMProviders({
projectName: courseName,
})
const { mutateAsync: runQueryRewriteAsync } = useQueryRewrite()
const { mutateAsync: routeChatAsync } = useRouteChat()
// const
const [bannerUrl, setBannerUrl] = useState<string | null>(null)
const getCurrentPageName = () => {
// /CS-125/dashboard --> CS-125
return router.asPath.slice(1).split('/')[0] as string
}
const [chat_ui] = useState(new ChatUI(new MLCEngine()))

const [inputContent, setInputContent] = useState<string>('')

const [enabledDocumentGroups, setEnabledDocumentGroups] = useState<
string[]
>(['All Documents']) // Default to 'All Documents' so retrieval can work immediately
const [enabledTools, setEnabledTools] = useState<string[]>([])
const bannerS3Path = courseMetadata?.banner_image_s3 || undefined

// React Query hooks
const { refetch: refetchLLMProviders } = useFetchLLMProviders({
projectName: courseName,
})
const { mutateAsync: runQueryRewriteAsync } = useQueryRewrite()
const { mutateAsync: routeChatAsync } = useRouteChat()
const { data: bannerUrl } = useDownloadPresignedUrlQuery(
bannerS3Path,
courseName,
)
const logConversationMutation = useLogConversation(getCurrentPageName())

const {
data: documentGroupsHook,
isSuccess: isSuccessDocumentGroups,
// isError: isErrorDocumentGroups,
} = useFetchEnabledDocGroups(getCurrentPageName())

const {
data: toolsHook,
isSuccess: isSuccessTools,
isLoading: isLoadingTools,
isError: isErrorTools,
error: toolLoadingError,
} = useFetchAllWorkflows(getCurrentPageName())
const updateConversationMutation = useUpdateConversation(
currentEmail,
queryClient,
courseName,
)
const deleteMessagesMutation = useDeleteMessages(currentEmail, courseName)

const permission = get_user_permission(courseMetadata, auth)

useEffect(() => {
if (
courseMetadata?.banner_image_s3 &&
courseMetadata.banner_image_s3 !== ''
) {
fetchPresignedUrl(courseMetadata.banner_image_s3, courseName).then(
(url) => {
setBannerUrl(url)
},
)
}
}, [courseMetadata])

const {
state: {
selectedConversation,
Expand All @@ -181,6 +169,16 @@ export const Chat = memo(
dispatch: homeDispatch,
} = useContext(HomeContext)

// const
const [chat_ui] = useState(new ChatUI(new MLCEngine()))

const [inputContent, setInputContent] = useState<string>('')

const [enabledDocumentGroups, setEnabledDocumentGroups] = useState<
string[]
>(['All Documents']) // Default to 'All Documents' so retrieval can work immediately
const [enabledTools, setEnabledTools] = useState<string[]>([])

useEffect(() => {
const loadModel = async () => {
if (selectedConversation?.model && !chat_ui.isModelLoading()) {
Expand Down Expand Up @@ -215,13 +213,6 @@ export const Chat = memo(
const chatContainerRef = useRef<HTMLDivElement>(null)
const textareaRef = useRef<HTMLTextAreaElement>(null)
const editedMessageIdRef = useRef<string | undefined>(undefined)
const updateConversationMutation = useUpdateConversation(
currentEmail,
queryClient,
courseName,
)

const deleteMessagesMutation = useDeleteMessages(currentEmail, courseName)

// Document Groups
useEffect(() => {
Expand Down Expand Up @@ -281,22 +272,14 @@ export const Chat = memo(
) => {
// Log conversation to database
try {
const response = await fetch(`/api/UIUC-api/logConversation`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(
createLogConversationPayload(
getCurrentPageName(),
conversation,
message,
earliestEditedMessageId,
),
await logConversationMutation.mutateAsync(
createLogConversationPayload(
getCurrentPageName(),
conversation,
message,
earliestEditedMessageId,
),
})
// const data = await response.json()
// return data.success
)
} catch (error) {
console.error('Error setting course data:', error)
}
Expand Down Expand Up @@ -1937,19 +1920,13 @@ export const Chat = memo(
updatedConversation.messages.length - 1
] ?? null
if (latestAssistantMessage) {
await fetch('/api/UIUC-api/logConversation', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(
createLogConversationPayload(
getCurrentPageName(),
updatedConversation,
latestAssistantMessage,
),
await logConversationMutation.mutateAsync(
createLogConversationPayload(
getCurrentPageName(),
updatedConversation,
latestAssistantMessage,
),
})
)
}
} catch (error) {
homeDispatch({
Expand Down
Loading
Loading