Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reroute threads and messages requests to cortex.cpp backend #4249

Merged
merged 13 commits into from
Dec 17, 2024

Conversation

louis-jan
Copy link
Contributor

Describe Your Changes

This PR refactors the application architecture by moving the /threads, /messages, and /assistants functionalities to the backend. This change aims to reduce the reliance on native APIs (e.g., fs operations) in the frontend and centralize these operations within the backend.

Some of the key changes

  • Decouple threads and assistants (active thread & active assistant atoms)
  • Thread and message operations routed to cortex.cpp backend.
  • Reduced number of requests processed (threads and assistants settings updated)

Fixes Issues

Changes made

The code changes include a series of substantial modifications across multiple files aimed at improving the handling of conversational threads and their related components. Here’s a summary of the changes:

  1. Method Renaming and Expansion: Several abstract methods in ConversationalExtension were renamed for clarity, such as getThreads to listThreads, and new methods were added (createThread, modifyThread, etc.) to handle CRUD operations more comprehensively.

  2. Elimination of Local Storage and Use of API: Local file operations were removed, replaced by network requests using ky. This includes using endpoints like /v1/threads and mapping the CRUD operations to matching API calls.

  3. New Dependencies: Introduced libraries like ky for HTTP requests and p-queue for request queuing, which are now included in the package.json.

  4. Enhancement of Thread Handling: The assistant data for a thread is now handled more robustly, with methods added to modify and retrieve assistant information (getThreadAssistant, modifyThreadAssistant, etc.).

  5. Global Typings: A global.d.ts was added to declare global constants (API_URL, SOCKET_URL) and enhance type definitions.

  6. Atom Management: Various states have been moved and managed using z, improving state management with jotai by transitioning to more structured atoms like activeAssistantAtom.

  7. Refactoring UI Components: The code for UI components in various React files was updated to work with the new thread and message methods, and to utilize the newly structured atom states. This includes fetching and displaying thread messages and managing assistant-specific data.

  8. Removal and Clean-Up: Code no longer needed, like handling JSON read/write for threads, was removed, and some test files were deleted to reflect updated logic that no longer relies on local file storage.

Overall, these changes enhance the application's ability to manage conversational data by shifting from a file-based system to an API service-driven architecture while also refactoring and making the code more maintainable and scalable.

@github-actions github-actions bot added the type: feature request A new feature label Dec 9, 2024
@louis-jan louis-jan force-pushed the feat/threads-messages-requests-to-backend branch from 7801073 to a446642 Compare December 9, 2024 09:34
Copy link
Contributor

github-actions bot commented Dec 9, 2024

Barecheck - Code coverage report

Total: 69.27%

Your code coverage diff: 0.05% ▴

Uncovered files and lines
FileLines
core/src/browser/extensions/conversational.ts23
core/src/node/api/restful/helper/builder.ts44, 51-52, 60, 87-88, 102-103, 146, 176, 221, 242, 255, 258, 261, 277-278, 282, 288, 290-292, 294, 300, 316
web/containers/ErrorMessage/index.tsx66-67
web/containers/ModelDropdown/index.tsx104, 115, 125-126, 129, 131-132, 134-135, 137-140, 142, 150, 173-176, 178, 180, 199, 203, 212, 219, 222-223, 259-261, 265, 289-291, 293, 297, 300-305, 312-313, 324, 346, 362, 383, 392, 398, 406-407, 410-415, 418, 421, 473-474, 476, 502, 510, 512, 537, 542-543, 545, 549-551, 553-554, 556, 566-569, 597, 605, 607
web/containers/Providers/Jotai.tsx17
web/helpers/atoms/ChatMessage.atom.ts48, 72-73, 75-76, 78, 81-82, 89-90, 92, 95-96, 99-100, 111, 114-115, 120, 123-124, 128, 131-132, 134-135, 138, 154-159, 161, 164-165, 167-168
web/hooks/useActiveModel.ts47, 51-52, 55-56, 58, 60, 62, 64, 66, 68-69, 74, 80, 84-85, 94, 96, 99-101, 104-105, 110, 117, 123-124, 127, 132-133, 139-141, 143-144, 146, 148-150, 158-160, 162, 164-165
web/hooks/useCreateNewThread.ts44, 46, 51-52, 55-56, 161-162, 164-165, 172-173, 184, 193, 228, 231
web/hooks/useDeleteThread.ts72-73
web/hooks/usePath.ts17, 19-21, 24-25, 27-29, 32-34, 36-37, 39, 42-44, 48, 50, 52-56, 60, 62-66
web/hooks/useRecommendedModel.ts36, 51-52, 54-55, 58, 60-62, 67, 69-70, 74, 78-80, 83-84, 87, 90-91, 94
web/hooks/useSendChatMessage.ts97-98, 100-101, 105-106, 109-110, 118, 120-122, 125-126, 128-129, 131, 133-135, 137, 139, 141, 145, 148-149, 155-156, 160, 171-172, 175, 179, 182, 190, 193, 197, 200, 205, 207-208, 211-215, 218, 221, 227, 232-233
web/hooks/useSetActiveThread.ts21, 23, 25-27, 29-30, 34-35, 37, 45, 50
web/hooks/useUpdateModelParameters.ts104, 106
web/screens/Thread/ThreadCenterPanel/index.tsx41, 43, 46, 49, 52, 81-82, 87-88, 92, 94, 97, 100-101, 109-112, 114-116, 124, 127-128, 130, 132, 138, 144-145, 165, 167
web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx42, 46, 49, 53-54, 58
web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx81, 89, 94, 107-111, 121-123, 128, 131, 157, 166, 172, 174, 239-241, 261-262, 290, 313, 365-367, 369-371, 373-375, 377, 381-382, 394
web/screens/Thread/ThreadCenterPanel/EditChatInput/index.tsx40-42, 44-51, 53-54, 57-61, 65-69, 74-76, 80-86, 88, 93-94, 97-102, 106-107, 140, 148, 156, 159
web/screens/Thread/ThreadCenterPanel/FileUploadPreview/index.tsx14-15, 17-19
web/screens/Thread/ThreadCenterPanel/ImageUploadPreview/index.tsx17-19, 21-24, 27-28, 31-33
web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx17-21, 23-24, 35-37, 40, 59
web/screens/Thread/ThreadCenterPanel/MessageToolbar/index.tsx38-45, 47-48, 50, 53, 57, 59, 64, 69, 71, 77, 79, 84-85, 88, 133
web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx15, 21
web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx14, 19
web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx29-33, 35, 37, 41, 43, 47
web/screens/Thread/ThreadLeftPanel/index.tsx59-60, 79-80, 82-83, 88, 103-104, 111, 130, 138, 140, 172, 176, 190, 194, 208, 212
web/screens/Thread/ThreadLeftPanel/ModalEditTitleThread/index.tsx24, 30-32, 45, 60, 64
web/screens/Thread/ThreadRightPanel/index.tsx86, 99, 103, 106, 111-115, 119-120, 126, 130, 133, 159-160, 174, 179, 181-182, 184, 188, 192, 196, 202, 206, 245
web/screens/Thread/ThreadRightPanel/Tools/index.tsx22-27, 29, 33-36, 38-39, 41, 50, 52-53, 75, 77-78, 101, 131, 222
web/utils/file.ts18-21, 23, 30
web/utils/messageRequestBuilder.ts38-39, 51-54, 56, 63, 68-69, 76, 81, 96-97, 102, 118-119, 123-124, 129, 132, 138-142, 144, 146, 148, 156, 159, 163
web/utils/threadMessageBuilder.ts54, 63

@louis-jan louis-jan force-pushed the feat/threads-messages-requests-to-backend branch from 11fe565 to f6ba447 Compare December 12, 2024 09:39
@louis-jan louis-jan marked this pull request as ready for review December 16, 2024 10:37
Copy link
Contributor

This is the build for this pull request. You can download it from the Artifacts section here: Build URL.

@louis-jan louis-jan changed the title feat: reroute threads and messages requests to the backend feat: reroute threads and messages requests to cortex.cpp backend Dec 16, 2024
Copy link
Contributor

This is the build for this pull request. You can download it from the Artifacts section here: Build URL.

@louis-jan louis-jan merged commit a3b3287 into dev Dec 17, 2024
10 checks passed
@louis-jan louis-jan deleted the feat/threads-messages-requests-to-backend branch December 17, 2024 03:56
@github-actions github-actions bot added this to the v0.5.12 milestone Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants