Skip to content

Conversation

@sureshattaluri
Copy link

Problem

When clicking on files in the UI, a runtime error occurs: codeTree.value[0].value.split is not a function.

The root cause is a type mismatch between the backend and frontend:

  • Backend: Sends files as FileData objects with structure {content: string[], created_at: string, modified_at: string}
  • Frontend: Expected files as plain strings in Record<string, string>

Solution

This PR fixes the type mismatch by:

  1. Added FileData type (src/app/types/types.ts)

    • Defined FileData interface matching backend structure
    • Kept FileItem for UI layer with plain string content
  2. Updated useChat hook (src/app/hooks/useChat.ts)

    • Changed StateType.files to Record<string, FileData>
    • Added helper functions to convert FileData to plain strings
    • Updated event handler to convert FileData before passing to parent
  3. Updated page component (src/app/page.tsx)

    • Updated thread state fetching to expect Record<string, FileData>
    • Converted FileData objects to strings when setting local state
    • Added same helper functions for consistency

Changes

  • src/app/types/types.ts: Added FileData interface
  • src/app/hooks/useChat.ts: Type updates and conversion logic
  • src/app/page.tsx: Thread state handling updates

Testing

The fix maintains clean separation:

  • API layer works with structured FileData objects
  • UI layer works with plain strings
  • Conversion happens at the boundary

This ensures files can now be clicked and viewed without errors while preserving all file metadata from the backend.

@vercel
Copy link

vercel bot commented Oct 27, 2025

@sureshattaluri is attempting to deploy a commit to the nick-langchainde's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant