feat(connectors): POST /api/connectors/files — stage images for LinkedIn/X posts

Merged
SW
5mo ago
+500-0

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 }); toolkitSlug derived from the action slug (deriveToolkitSlug).
  • validateUploadConnectorFileBody.ts — zod { url (valid URL), toolSlug }.
  • validateUploadConnectorFileRequest.ts — validateAuthContext gate. No account_id accepted/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.upload accepts 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_uploadable toolkits (linkedin, twitter) via the derived toolkitSlug.

TDD

  • RED→GREEN per unit (5 new files, 5 test files). Full lib/composio/connectors suite green: 129 tests / 27 files. tsc adds 0 new errors; eslint clean.

Verification (next)

  • Preview: POST /api/connectors/files returns a real s3key; 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-key or Authorization: Bearer); CORS preflight supported. 400 on invalid or malformed JSON (via shared safeParseJson), 401 unauth, 502 upstream.
    • Upload is scoped by tool/toolkit; no account_id. No changes to the execute path or other actions.
  • Migration

    • Call POST /api/connectors/files with 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 } into parameters.images[] (or other file_uploadable fields) when calling POST /api/connectors/actions.