-
Notifications
You must be signed in to change notification settings - Fork 78
chore(DATAGO-117985): Refactoring chat provider for better encapsulation #716
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
Conversation
WhiteSource Policy Violation Summary✅︎ No Blocking Whitesource Policy Violations found in solaceai/solace-agent-mesh-ui-pr-716! |
| previewFileContent: FileAttachment | null; | ||
| submittedFeedback: Record<string, { type: "up" | "down"; text: string }>; | ||
| // Artifact Rendering State | ||
| artifactRenderingState: ArtifactRenderingState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All artifact rendering state support was unused, so removing it.
| setArtifactRenderingState: React.Dispatch<React.SetStateAction<ArtifactRenderingState>>; | ||
|
|
||
| /* Session Management Actions */ | ||
| updateSessionName: (sessionId: string, newName: string, showNotification?: boolean) => Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating a session name never shows a notification now, so removing the optional unused parameter.
| * Custom hook to manage artifact CRUD operations | ||
| * Handles upload, download, delete (single and batch), and modal state | ||
| */ | ||
| export const useArtifactOperations = ({ sessionId, artifacts, setArtifacts, artifactsRefetch, addNotification, setError, previewArtifact, closePreview }: UseArtifactOperationsOptions): UseArtifactOperationsReturn => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracting the code to support artifact crud operations to a hook for better encapsulation.
| * Custom hook to manage artifact preview functionality | ||
| * Handles opening artifacts, navigating versions, and managing preview state | ||
| */ | ||
| export const useArtifactPreview = ({ sessionId, projectId, artifacts, setError }: UseArtifactPreviewOptions): UseArtifactPreviewReturn => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracting artifact preview support to a hook for better encapsulation.
| /** | ||
| * Parsed task structure (after JSON parsing but before migration) | ||
| */ | ||
| export interface ParsedTaskData extends Omit<StoredTaskData, "messageBubbles" | "taskMetadata"> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarifying these two types... StoredTaskData is what comes up from the API and ParsedTaskData is after the JSON strings are parsed into JSON objects.
| * @param file - The file to convert | ||
| * @returns A promise that resolves to the Base64 string | ||
| */ | ||
| export const fileToBase64 = (file: File): Promise<string> => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracting some repeated utility functions for files.
| * @param task - The task to migrate | ||
| * @returns The migrated task at the current schema version | ||
| */ | ||
| export const migrateTask = (task: ParsedTaskData): ParsedTaskData => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracting a chat task migration to its own file for better encapsulation.
| import { v4 } from "uuid"; | ||
|
|
||
| import { useConfigContext, useArtifacts, useAgentCards, useErrorDialog, useBackgroundTaskMonitor } from "@/lib/hooks"; | ||
| import { useConfigContext, useArtifacts, useAgentCards, useErrorDialog, useBackgroundTaskMonitor, useArtifactPreview, useArtifactOperations } from "@/lib/hooks"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All changes to this file flow from moving the code into reusable functions or hooks. Nothing functional has changed.
| ); | ||
|
|
||
| // Artifact Rendering Actions | ||
| const toggleArtifactExpanded = useCallback((filename: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused, removing.
|





This pull request introduces a significant refactor to how artifact-related operations and state are managed in the frontend. The main changes involve removing artifact rendering state and actions from the global chat context, and introducing dedicated custom hooks for artifact operations and artifact preview functionality. This modularization improves code maintainability, reusability, and separation of concerns.
The most important changes are:
Artifact State & Actions Refactor
ArtifactRenderingStateand associated actions from theChatContext, simplifying the chat state and actions interface. Artifact rendering and expansion logic are now handled via dedicated hooks instead of being managed globally. [1] [2] [3] [4]New Custom Hooks
useArtifactOperationshook to encapsulate artifact upload, download, single/batch delete, and related modal state logic. This hook provides a clean interface for artifact CRUD operations and notification/error handling. [1] [2]useArtifactPreviewhook to manage artifact preview state, including loading versions, navigating between versions, and handling preview state transitions. [1] [2]Type and Interface Updates
ArtifactRenderingStateand to clarify interfaces for artifact operations and preview state. [1] [2]Session Storage Improvements
StoredTaskDatato storemessageBubblesandtaskMetadataas JSON strings, and introduced a newParsedTaskDatainterface for parsed task structures, improving clarity and type safety for persisted data.