feat(connectors): POST /api/connectors/files — stage images for LinkedIn/X posts
Problem
Connector actions with file_uploadable fields (LINKEDIN_CREATE_LINKED_IN_POST.images[], TWITTER_CREATION_OF_A_POST) need a Composio { name, mimetype, s3key } descriptor whose s3key already lives in Composio storage. The execute path forwards parameters verbatim and never stages the file, so any s3key we pass is looked up literally and 404s. (recoupable/chat#1809)
Change — Option A (explicit upload endpoint)
New POST /api/connectors/files: given { url, toolSlug }, stage the image via the SDK helper composio.files.upload({ file, toolSlug, toolkitSlug }) and return flat { success, name, mimetype, s3key }. The caller passes that descriptor into parameters.images[] on the existing POST /api/connectors/actions. No behavior change to the execute path or any other action.
Layering mirrors the connectors siblings (route → handler → validate → domain fn):
uploadConnectorFile.ts—composio.files.upload({ file: url, toolSlug, toolkitSlug });toolkitSlugderived from the action slug (deriveToolkitSlug).validateUploadConnectorFileBody.ts— zod{ url (valid URL), toolSlug }.validateUploadConnectorFileRequest.ts—validateAuthContextgate. Noaccount_idaccepted/used: the upload is scoped by tool/toolkit, not by connected account (satisfies the issue's auth Done-when cleanly).uploadConnectorFileHandler.ts— 200 success / 400 invalid body / 401 unauth / 502 upstream (Composio fetch/store failure).
Decisions (from the issue's open questions)
- Option A over auto-upload (B): no change to execution semantics, s3key reusable, mirrors what chat does.
- URL-only input:
composio.files.uploadaccepts a URL string and infers name/mimetype; covers the marketing-graphics use case with the simplest contract. Multipart bytes can be a fast follow-up. - Generic across
file_uploadabletoolkits (linkedin, twitter) via the derivedtoolkitSlug.
TDD
- RED→GREEN per unit (5 new files, 5 test files). Full
lib/composio/connectorssuite green: 129 tests / 27 files.tscadds 0 new errors; eslint clean.
Verification (next)
- Preview:
POST /api/connectors/filesreturns a reals3key; 400/401 paths. - Live: post to LinkedIn (and X) with the returned descriptor and attach the post URL/screenshot — pending a connected test account + key from @sweetmantech.
Merge order: docs#246 → this PR. Implements recoupable/chat#1809.
🤖 Generated with Claude Code
Summary by cubic
Adds POST /api/connectors/files to stage images in Composio for LinkedIn and X posts, returning { name, mimetype, s3key } for file_uploadable fields to prevent 404s.
-
New Features
- Endpoint accepts
{ url, toolSlug }, derives toolkit, uploads via Composio, and returns{ success, name, mimetype, s3key }. - Auth required (
x-api-keyorAuthorization: Bearer); CORS preflight supported. 400 on invalid or malformed JSON (via sharedsafeParseJson), 401 unauth, 502 upstream. - Upload is scoped by tool/toolkit; no
account_id. No changes to the execute path or other actions.
- Endpoint accepts
-
Migration
- Call POST
/api/connectors/fileswith a public image URL and the action slug (e.g.LINKEDIN_CREATE_LINKED_IN_POST,TWITTER_CREATION_OF_A_POST). - Pass the returned
{ name, mimetype, s3key }intoparameters.images[](or otherfile_uploadablefields) when calling POST/api/connectors/actions.
- Call POST