Skip to content

Re-enable chat attachments on agent-chat (post /api/upload removal) #121

@junixlabs

Description

@junixlabs

Context

The refactor in 2bbcb1a unified issue attachment uploads on a shared persistIssueAttachment service backed by POST /issues/:id/attachments (multipart) and inline attachments[] (base64) on issue create across REST + MCP.

As part of that cleanup the legacy Strapi-era POST /api/upload endpoint was removed from @forge/core. One caller still lives outside the issue domain and now fails loud:

  • packages/dev/src/pages/project/agent-chat/useAgentChatHandlers.ts:58 — paste/drop a file in the desktop agent-chat panel ⇒ uploadFile() throws legacy /api/upload no longer exists.

The function is intentionally a fail-loud stub (not silently dropped) so the gap surfaces in QA instead of regressing into ghost files.

Goal

Restore chat attachments end-to-end without re-introducing a generic upload endpoint. Attachments should live next to the agent-session message they were posted with.

Proposed shape

  1. Schema — add agent_session_attachments (or fold into existing agent_messages payload) with the same FK/storage pattern as issue_attachments (uploader, mime, size, path, key prefix agent-sessions/<id>/<ts>-<name>).
  2. Service — extract a generic persistAttachmentBytes({ scope: 'issue' | 'agent-session', parentId, bytes, ... }) from packages/core/src/issues/attachment-service.ts so it can back both surfaces. ALLOWED_MIMES + size caps stay in one place.
  3. RoutesPOST /agent-sessions/:id/attachments (multipart) for desktop paste-flow; inline base64 array on forge_agent_messages MCP create if/when it's needed.
  4. Desktop client — replace uploadFile() callsite with uploadAgentSessionAttachment(sessionId, file) mirroring uploadIssueAttachment. Pre-create staging not needed because the message row exists before the upload.
  5. Drop the stub — once wired, delete uploadFile() and its index re-export entirely.

Out of scope

  • Chat attachments on the web widget / mobile (no current callers).
  • Streaming uploads >10 MB (cap stays at UPLOADS_MAX_BYTES).

Links

  • Service: packages/core/src/issues/attachment-service.ts
  • Stub callsite: packages/dev/src/lib/api/misc.ts (uploadFile)
  • Failing chat callsite: packages/dev/src/pages/project/agent-chat/useAgentChatHandlers.ts:58
  • Refactor commit: 2bbcb1a

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions