Skip to content

Conversation

@lgh-solace
Copy link
Collaborator

@lgh-solace lgh-solace commented Dec 22, 2025

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

  • Removed ArtifactRenderingState and associated actions from the ChatContext, 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

  • Added useArtifactOperations hook 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]
  • Added useArtifactPreview hook to manage artifact preview state, including loading versions, navigating between versions, and handling preview state transitions. [1] [2]

Type and Interface Updates

  • Updated types to remove references to ArtifactRenderingState and to clarify interfaces for artifact operations and preview state. [1] [2]

Session Storage Improvements

  • Updated StoredTaskData to store messageBubbles and taskMetadata as JSON strings, and introduced a new ParsedTaskData interface for parsed task structures, improving clarity and type safety for persisted data.

@github-actions
Copy link

github-actions bot commented Dec 22, 2025

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;
Copy link
Collaborator Author

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>;
Copy link
Collaborator Author

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 => {
Copy link
Collaborator Author

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 => {
Copy link
Collaborator Author

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"> {
Copy link
Collaborator Author

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> =>
Copy link
Collaborator Author

@lgh-solace lgh-solace Dec 22, 2025

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 => {
Copy link
Collaborator Author

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";
Copy link
Collaborator Author

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) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, removing.

@lgh-solace lgh-solace marked this pull request as ready for review December 22, 2025 19:35
@lgh-solace lgh-solace requested a review from ziyanwan December 22, 2025 19:35
@sonarqube-solacecloud
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@lgh-solace lgh-solace merged commit febbbb9 into main Dec 24, 2025
25 checks passed
@lgh-solace lgh-solace deleted the lgh-chatProvider2 branch December 24, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants