Skip to content

AI Generation: Add Word document (.docx) input support #71

@johlju

Description

@johlju

Summary

Allow users to attach Word documents (.docx) as context when generating requirements with the AI feature. Word documents (e.g. requirement specifications, meeting notes, business rules) would have their text extracted and sent alongside the prompt.

Background

Image attachment support has been implemented (vision-capable models). PDF support is tracked in #70. Word document support is the third document type to add.

Approach

LLM APIs (including OpenRouter) do not natively support .docx files. Text must be extracted before sending to the model.

Recommended: Server-side extraction with mammoth

Use the mammoth library to convert .docx to plain text or simplified HTML on the server (API route).

  • Pros: Clean text extraction; handles styles, lists, tables; small dependency (~150 KB); well-maintained
  • Cons: Adds a server-side dependency; complex formatting (charts, SmartArt, embedded objects) may be lost

Alternative: Browser-side extraction

Use mammoth in the browser to extract text before sending, similar to the PDF client-side approach.

  • Pros: No server-side dependency
  • Cons: Increases client bundle size; extraction happens on the user's device

Considerations

  • Token consumption: Word documents can contain substantial text. Need a character/token limit with a warning.
  • File size limit: Suggest max 20 MB per document.
  • Max file count: Suggest max 2 documents (shared limit with PDFs).
  • Supported formats: .docx only (modern Office Open XML). Legacy .doc format is not supported by mammoth and should be rejected with a clear error message.
  • Images in Word docs: Embedded images could optionally be extracted and sent as image content parts (if a vision-capable model is selected), but this adds complexity — defer to a follow-up.
  • UI: Extend the existing file drop zone — add .docx to accepted MIME types. Show a document icon instead of a thumbnail preview.

Acceptance Criteria

  • User can attach .docx files in the AI generation dialog
  • Text is extracted from the document and sent as prompt context
  • Legacy .doc files are rejected with a clear error message
  • File size and count limits are enforced with clear error messages
  • Token cost warning is shown for attached documents
  • Translation keys added for both en and sv

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions