Skip to content

refactor: align file mentions with sandbox files flow (#1664)#1675

Merged
arpitgupta1214 merged 1 commit into
mainfrom
test
Apr 14, 2026
Merged

refactor: align file mentions with sandbox files flow (#1664)#1675
arpitgupta1214 merged 1 commit into
mainfrom
test

Conversation

@arpitgupta1214

@arpitgupta1214 arpitgupta1214 commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator
  • feat: move file list to dedicated api

  • refactor: share listed file row type

  • fix: update listed file row import

  • refactor: drop unused owner email field

  • refactor: keep mentions on sandbox file list

  • refactor: source mentions from sandbox file tree

  • chore: remove unused file listing route and hooks

  • fix: restore mention image thumbnails from sandbox

  • refactor: move mention preview loading into suggestion item

  • refactor: extract sandbox mention preview hook

  • refactor: unify sandbox file content hooks

  • fix: allow optional selected path in sandbox file content hook

  • fix: trim sandbox root prefix in mention paths

  • refactor: extract WORKSPACE_ORGS_PATH to shared module

The .openclaw/workspace/orgs prefix was duplicated in useArtistFilesForMentions (file-mention picker) and getSubtreeAtPath (/files page filetree). Share a single const so both stay in lockstep if the sandbox layout changes.

  • refactor: only export WORKSPACE_ORGS_PATH, derive PREFIX at call site

Drop the WORKSPACE_ORGS_PREFIX export. The only caller that needs the trailing / constructs it locally, keeping the shared module minimal.



Summary by cubic

Aligns the file mention picker with the sandbox file flow. Mentions now source from the sandbox file tree and load previews/attachments via a unified sandbox content hook, while legacy file listing APIs and hooks are removed.

  • Refactors

    • Source mentionable files from the sandbox file tree; switch from storage_key to path and derive MIME via getMimeFromPath.
    • Centralize .openclaw/workspace/orgs as WORKSPACE_ORGS_PATH and reuse it across the file picker and /files tree.
    • Move preview loading into SuggestionItem using useSandboxFileContent (now useQuery-based with optional path).
    • Unify sandbox file content hooks; remove /api/files/list, useFilesManager, and useBatchSignedUrls.
    • Update chat flow to fetch mentioned file contents via sandbox: attach images/PDFs as file parts and prepend text file contents to the message.
  • Bug Fixes

    • Restore image thumbnails in mention suggestions using sandbox content URLs.
    • Trim sandbox root prefix from mention paths for cleaner display.
    • Keep mentions in sync with the sandbox file list.

Written for commit 877d35a. Summary will update on new commits.

Summary by CodeRabbit

Release Notes

  • Refactor
    • Streamlined the file mention system in chat to improve integration with sandbox file access and handling.
    • Consolidated file path conventions across the application for consistency.

* feat: move file list to dedicated api

* refactor: share listed file row type

* fix: update listed file row import

* refactor: drop unused owner email field

* refactor: keep mentions on sandbox file list

* refactor: source mentions from sandbox file tree

* chore: remove unused file listing route and hooks

* fix: restore mention image thumbnails from sandbox

* refactor: move mention preview loading into suggestion item

* refactor: extract sandbox mention preview hook

* refactor: unify sandbox file content hooks

* fix: allow optional selected path in sandbox file content hook

* fix: trim sandbox root prefix in mention paths

* refactor: extract WORKSPACE_ORGS_PATH to shared module

The .openclaw/workspace/orgs prefix was duplicated in
useArtistFilesForMentions (file-mention picker) and getSubtreeAtPath
(/files page filetree). Share a single const so both stay in lockstep
if the sandbox layout changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: only export WORKSPACE_ORGS_PATH, derive PREFIX at call site

Drop the WORKSPACE_ORGS_PREFIX export. The only caller that needs the
trailing `/` constructs it locally, keeping the shared module minimal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Sweets Sweetman <sweetmantech@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recoup-chat Building Building Preview Apr 14, 2026 10:59pm

Request Review

@coderabbitai

coderabbitai Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5c8ca818-9050-4eb6-b70a-519072058e39

📥 Commits

Reviewing files that changed from the base of the PR and between 1388a1f and 877d35a.

📒 Files selected for processing (11)
  • app/api/files/list/route.ts
  • components/VercelChat/FileMentionsInput.tsx
  • components/VercelChat/SuggestionItem.tsx
  • hooks/useArtistFilesForMentions.ts
  • hooks/useBatchSignedUrls.ts
  • hooks/useFileMentionSuggestions.ts
  • hooks/useFilesManager.ts
  • hooks/useSandboxFileContent.ts
  • hooks/useVercelChat.ts
  • lib/sandboxes/getSubtreeAtPath.ts
  • lib/sandboxes/workspaceOrgsPath.ts

📝 Walkthrough

Walkthrough

This PR replaces the legacy file manager API and file listing hooks with a sandbox file tree-based approach. It removes the /api/files/list endpoint and useFilesManager hook, migrating file mention suggestions to use useSandboxes and refactoring file content fetching from imperative mutations to reactive React Query patterns. Data models shift from storage_key to path, and image previews now load on-demand via useSandboxFileContent.

Changes

Cohort / File(s) Summary
API Removal
app/api/files/list/route.ts
Deleted the GET handler for file listing, which previously parsed ownerAccountId/artistAccountId from query parameters, called listFilesByArtist(), and returned filtered results.
Legacy Hooks Removal
hooks/useFilesManager.ts, hooks/useBatchSignedUrls.ts
Removed useFilesManager (177 lines; directory listing, folder creation, file upload mutations) and useBatchSignedUrls (30 lines; batch signed URL fetching keyed by storage_key).
Data Model Refactor
hooks/useArtistFilesForMentions.ts, hooks/useFileMentionSuggestions.ts
Migrated from useFilesManager + storage_key to useSandboxes + path; flattened FileNode tree into MentionableFile[]; made is_directory required and updated relative_path derivation to strip WORKSPACE_ORGS_PATH prefix.
File Content & Preview
hooks/useSandboxFileContent.ts, components/VercelChat/SuggestionItem.tsx
Refactored useSandboxFileContent from mutation-based to query-based (React Query); SuggestionItem now derives image URLs via the hook instead of accepting an imageUrl prop and detects images by extension on entry.path.
Component Integration
components/VercelChat/FileMentionsInput.tsx
Removed useBatchSignedUrls dependency; no longer preloads signed URLs before passing to SuggestionItem.
Chat Flow Update
hooks/useVercelChat.ts
Replaced signed-URL + KnowledgeBaseEntry flow with sandbox file + access token flow; mentionAttachments (data URLs) and mentionTextContext (prepended text) now source from mentioned files; updated auth to use usePrivy().getAccessToken().
Path Constant Extraction
lib/sandboxes/workspaceOrgsPath.ts, lib/sandboxes/getSubtreeAtPath.ts
Added exported constant WORKSPACE_ORGS_PATH = ".openclaw/workspace/orgs"; updated getSubtreeAtPath to import the constant instead of defining it locally.

Sequence Diagram

sequenceDiagram
    participant User as User (Typing @)
    participant FileMentionsInput
    participant useArtistFilesForMentions
    participant useSandboxes
    participant SuggestionItem
    participant useSandboxFileContent
    participant QueryClient as React Query

    User->>FileMentionsInput: Type `@mention` trigger
    FileMentionsInput->>useArtistFilesForMentions: Request file suggestions
    useArtistFilesForMentions->>useSandboxes: Fetch filetree & isLoading
    useSandboxes-->>useArtistFilesForMentions: Return FileNode tree
    useArtistFilesForMentions->>useArtistFilesForMentions: Flatten tree to MentionableFile[]
    useArtistFilesForMentions-->>FileMentionsInput: Return {files, isLoading}
    FileMentionsInput->>SuggestionItem: Render each file (entry, highlightedDisplay)
    SuggestionItem->>useSandboxFileContent: Query file content/imageUrl (if isImage)
    useSandboxFileContent->>QueryClient: useQuery({path, enabled})
    QueryClient-->>useSandboxFileContent: Fetch & cache file content
    useSandboxFileContent-->>SuggestionItem: Return {content, imageUrl, loading}
    SuggestionItem->>SuggestionItem: Render image preview or fallback icon
    SuggestionItem-->>User: Display suggestion with thumbnail
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

Suggested reviewers

  • sweetmantech

✨ Files take flight, from API to tree,
Sandbox paths dance, now path runs free—
No more signed URLs, just content on-demand,
The mention system refactored, strong and grand! 🌳📝

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@arpitgupta1214 arpitgupta1214 merged commit e727664 into main Apr 14, 2026
2 of 4 checks passed
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