Skip to content

feat(mothership): add files to mship block#4584

Merged
Sg312 merged 4 commits into
stagingfrom
feat/mothership-block-files
May 13, 2026
Merged

feat(mothership): add files to mship block#4584
Sg312 merged 4 commits into
stagingfrom
feat/mothership-block-files

Conversation

@Sg312
Copy link
Copy Markdown
Collaborator

@Sg312 Sg312 commented May 13, 2026

Summary

Add files to mship block

Type of Change

  • New feature

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 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 13, 2026 11:30pm

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 13, 2026

Greptile Summary

This PR adds file attachment support to the Mothership block, allowing users to upload files (basic mode) or reference files from previous blocks (advanced mode) that are then forwarded as base64-encoded attachments to the Mothership execute endpoint.

  • mothership-handler.ts: Introduces buildMothershipFileAttachments which reads each file from storage, encodes it, and builds a MothershipFileAttachment array; adds a toUserFile helper and logs fileAttachmentCount on execution.
  • mothership.ts / mothership-tasks.ts: Exposes files as a new file[] input on the block config and extends the execute body schema with an optional fileAttachments array.
  • route.ts: Destructures fileAttachments from the validated body and conditionally passes it through to the Mothership lifecycle.

Confidence Score: 3/5

The block and API surface changes are clean; the main risk is in the handler's toUserFile URL fallback, where a storage key is silently used as a URL, leading to opaque failures when files arrive without explicit URL fields.

The URL-fallback-to-key issue in toUserFile means file references lacking a url or path field will have their storage key treated as an HTTP URL. If readUserFileContent uses the URL field for network access, execution silently fails in a way that is difficult to diagnose. The test suite only exercises the happy path where path is always present, leaving the fallback branch uncovered.

apps/sim/executor/handlers/mothership/mothership-handler.ts — specifically the toUserFile URL fallback and the redundant base64 decode/re-encode in buildMothershipFileAttachments

Important Files Changed

Filename Overview
apps/sim/executor/handlers/mothership/mothership-handler.ts Adds file attachment support via buildMothershipFileAttachments; introduces toUserFile that duplicates existing file-utils normalization and has a risky URL fallback to the storage key
apps/sim/lib/api/contracts/mothership-tasks.ts Adds mothershipExecuteFileAttachmentSchema with passthrough for flexibility; source is optional which could allow documents without a source to pass validation
apps/sim/blocks/blocks/mothership.ts Adds attachmentFiles (file-upload, basic mode) and fileReferences (short-input, advanced mode) subblocks mapped to files canonical param; clean addition following existing patterns
apps/sim/app/api/mothership/execute/route.ts Destructures fileAttachments from validated body and conditionally spreads it into the request payload; straightforward and correct
apps/sim/executor/handlers/mothership/mothership-handler.test.ts Adds a well-structured test for file attachment flow; only tests the path-to-URL path, not the key-only fallback case

Sequence Diagram

sequenceDiagram
    participant Block as Mothership Block
    participant Handler as MothershipBlockHandler
    participant Storage as readUserFileContent
    participant API as /api/mothership/execute
    participant Mship as Mothership Lifecycle

    Block->>Handler: execute(ctx, block, inputs)
    Handler->>Handler: normalizeFileInput(files)
    loop For each file
        Handler->>Handler: toUserFile(file)
        Handler->>Storage: readUserFileContent(userFile)
        Storage-->>Handler: base64 string
        Handler->>Handler: Buffer.from + createFileContent
    end
    Handler->>API: POST with fileAttachments
    API->>Mship: runHeadlessCopilotLifecycle
    Mship-->>API: result
    API-->>Handler: JSON response
    Handler-->>Block: BlockOutput
Loading

Reviews (1): Last reviewed commit: "Add files to mship block" | Re-trigger Greptile

Comment thread apps/sim/executor/handlers/mothership/mothership-handler.ts Outdated
Comment thread apps/sim/executor/handlers/mothership/mothership-handler.ts Outdated
Comment thread apps/sim/executor/handlers/mothership/mothership-handler.ts Outdated
@Sg312 Sg312 merged commit 2441d5a into staging May 13, 2026
13 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/mothership-block-files branch May 14, 2026 02:49
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