Skip to content

v0.6.78: file block get#4589

Merged
Sg312 merged 3 commits into
mainfrom
staging
May 14, 2026
Merged

v0.6.78: file block get#4589
Sg312 merged 3 commits into
mainfrom
staging

Conversation

@Sg312
Copy link
Copy Markdown
Collaborator

@Sg312 Sg312 commented May 14, 2026

@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 14, 2026 1:47am

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR adds a get operation to the file block, allowing workflows to retrieve a workspace file object by either a UI file-picker selection or a direct file ID string, without parsing the file contents.

  • New file_get tool (tools/file/get.ts, registered in registry.ts): posts to /api/tools/file/manage with operation: 'get' and returns the file metadata (id, name, url, size, type, key, context).
  • Route handler (app/api/tools/file/manage/route.ts): new case 'get' extracts the file ID from either fileId or a fileInput object, scopes the DB lookup to workspaceId to prevent cross-workspace access, and returns the file record.
  • Contract schema (lib/api/contracts/tools/file.ts): z.discriminatedUnion replaced with z.union because the new get schema uses .refine(); fileInput is typed as z.any() with the presence check deferred to a refinement.

Confidence Score: 4/5

The change is a narrowly scoped read-only addition; all DB lookups are gated by workspaceId, so the access boundary is intact.

The implementation is clean and consistent with the existing append/write patterns. The switch from discriminatedUnion to union in the contract schema silently degrades validation error messages for all three operations, and the get response exposes the internal storage identifier that other operations omit.

apps/sim/lib/api/contracts/tools/file.ts and apps/sim/app/api/tools/file/manage/route.ts

Important Files Changed

Filename Overview
apps/sim/tools/file/get.ts New tool definition for file_get; straightforward structure matching other file tool patterns.
apps/sim/lib/api/contracts/tools/file.ts Body schema switched from z.discriminatedUnion to z.union; fileInput typed as z.any(). The union change degrades validation error specificity.
apps/sim/app/api/tools/file/manage/route.ts New get case scopes the DB lookup by workspaceId. Exposes internal storage key in the response in addition to the already-available URL.
apps/sim/blocks/blocks/file.ts Adds file_get to the operation dropdown with basic and advanced sub-blocks, consistent with the existing append pattern.
apps/sim/tools/file/index.ts Exports the new fileGetTool; no issues.
apps/sim/tools/registry.ts Registers file_get in the global tool registry; no issues.

Sequence Diagram

sequenceDiagram
    participant Block as FileV3Block
    participant Tool as file_get tool
    participant API as /api/tools/file/manage
    participant DB as workspace-file-manager

    Block->>Tool: params with getFileInput or getFileId
    Tool->>API: POST operation get with fileId or fileInput
    API->>API: checkInternalAuth and validate
    API->>DB: getWorkspaceFile(workspaceId, selectedFileId)
    DB-->>API: WorkspaceFileRecord or null
    alt file found
        API-->>Tool: success with file metadata
        Tool-->>Block: success output
    else not found
        API-->>Tool: 404 error
        Tool-->>Block: failure output
    end
Loading

Reviews (1): Last reviewed commit: "improvement(file-block): add get operati..." | Re-trigger Greptile

Comment thread apps/sim/lib/api/contracts/tools/file.ts
Comment thread apps/sim/app/api/tools/file/manage/route.ts
* File block get

* Lint

* Fix

* Fix auth
* fix(mothership): persist @-mentioned resources across send and merge on hydration

* fix(mship-resources): handle ADD/DELETE race and reorder during pending flush

- Track in-flight ADD promises so DELETE chains off finally(), preventing orphaned server rows when a user removes a resource before its POST resolves
- Defer reorder PATCH until pending flush completes; emit with full local order
- Clear new refs in reset paths

* fix(mship-resources): defer reorder when ADDs are in-flight on existing chat

reorderResources previously only checked pendingPersistResourceKeysRef. When a
chatId exists, addResource fires the POST immediately and only tracks the
promise in inFlightResourceAddsRef — so a reorder before those ADDs settle
shipped a PATCH the server rejected, and the silent catch lost the reorder.

Now treat in-flight ADDs like pending ones: defer the PATCH and replay it
after Promise.allSettled on the in-flight map.
@cursor
Copy link
Copy Markdown

cursor Bot commented May 14, 2026

PR Summary

Medium Risk
Adds a new file-management API operation and a new workflow tool, plus refactors client chat resource persistence to use contract-based requests with retry/ordering logic; these touch backend routing and complex client state syncing and could introduce edge-case regressions.

Overview
Adds a new get operation to the /api/tools/file/manage endpoint (with assertActiveWorkspaceAccess) to fetch a workspace file by ID/selected file input and return a normalized file object.

Extends the File block/tooling with file_get (UI inputs, schema/contract support, tool registration) so workflows can retrieve a workspace file object.

Refactors use-chat resource persistence away from ad-hoc fetch calls to requestJson + typed contracts, adding pending/in-flight tracking, deferred deletes, and post-flush reorder syncing during chat hydration and resource changes.

Reviewed by Cursor Bugbot for commit 1c111ff. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1c111ff. Configure here.

Comment thread apps/sim/lib/api/contracts/tools/file.ts
@Sg312 Sg312 merged commit c09a2c9 into main May 14, 2026
28 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.

2 participants