[PR #5658] [MERGED] Support pulling generated documents from API calls #5512

Closed
opened 2026-06-05 15:21:35 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5658
Author: @timothycarambat
Created: 5/19/2026
Status: Merged
Merged: 5/19/2026
Merged by: @timothycarambat

Base: masterHead: 5652-api-generated-docs


📝 Commits (4)

  • abd8380 support pulling generated documents from API calls
  • 7d0700c revert async wait
  • 0b7014f fix strictness of packMessages to handle streaming chunks but keep functionality
  • 351eb52 Merge branch 'master' into 5652-api-generated-docs

📊 Changes

4 files changed (+210 additions, -6 deletions)

View changed files

📝 server/endpoints/api/document/index.js (+95 -0)
📝 server/swagger/openapi.json (+76 -0)
📝 server/utils/agents/ephemeral.js (+24 -4)
📝 server/utils/chats/apiChatHandler.js (+15 -2)

📄 Description

Pull Request Type

  • feat (New feature)
  • 🐛 fix (Bug fix)
  • ♻️ refactor (Code refactoring without changing behavior)
  • 💄 style (UI style changes)
  • 🔨 chore (Build, CI, maintenance)
  • 📝 docs (Documentation updates)

Relevant Issues

resolves #5652

Description

Adds support for returning fileDownloadCard events to the API responses for chat/stream as respective events with a new output key.

This new key contains the storage filename to pull a file from the generated document directory as a binary so it can be downloaded with that same API key.

This should not impact any existing integrations with the API as the response is additive.

For streaming, outputs will only be present in finalizeResponseStream

{
    "uuid": "58efb129-0bd8-4c39-965f-f3cc8d841747",
    "type": "finalizeResponseStream",
    "textResponse": "The PDF document titled **\"hello_world_multilingual.pdf\"** has been successfully created and saved. It contains the \"Hello World\" message in multiple languages: English, Spanish, French, German, Japanese, and Chinese (Simplified). Let me know if you need any modifications or further assistance!",
    "thoughts": [
        "@agent is executing `create-pdf-file` tool {\n  \"filename\": \"hello_world_multilingual.pdf\",\n  \"content\": \"# Hello World in Multiple Languages\\n\\n## English\\nHello World!\\n\\n## Spanish\\n¡Hola Mundo!\\n\\n## French\\nBonjour le Monde!\\n\\n## German\\nHallo Welt!\\n\\n## Japanese\\nこんにちは、世界!\\n\\n## Chinese (Simplified)\\n你好,世界!\"\n}",
        "@agent: Creating PDF document \"hello_world_multilingual.pdf\"",
        "@agent: Successfully created PDF document \"hello_world_multilingual.pdf\""
    ],
    "outputs": [
        {
            "filename": "hello_world_multilingual.pdf",
            "storageFilename": "pdf-e5460fb4-2bb0-447b-988a-8badfe6b5ba4.pdf",
            "fileSize": 31120
        }
    ],
    "close": true,
    "error": false
}

Examples

curl --location 'http://localhost:3001/api/v1/workspace/sample/chat' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer xxxxxxxx' \
--data-raw '{
  "message": "@agent make a simple hello world PDF document in multiple languages",
  "mode": "automatic",
  "reset": true
}'
{
    "id": "49f6c469-2e84-4b64-a122-c495cf4d95f6",
    "type": "textResponse",
    "sources": [],
    "close": true,
    "error": null,
    "textResponse": "The PDF document \"hello_world_multilingual.pdf\" has been successfully created and contains greetings in multiple languages. Let me know if you need any modifications or further assistance!",
    "thoughts": [
        "@agent is executing `create-pdf-file` tool {\n  \"filename\": \"hello_world_multilingual.pdf\",\n  \"content\": \"# Hello World in Multiple Languages\\n\\n## English\\nHello World!\\n\\n## Spanish\\n¡Hola Mundo!\\n\\n## French\\nBonjour le Monde!\\n\\n## German\\nHallo Welt!\\n\\n## Italian\\nCiao Mondo!\\n\\n## Japanese\\nこんにちは世界!\\n\\n## Korean\\n안녕하세요 세계!\\n\\n## Russian\\nПривет, мир!\\n\\n## Portuguese\\nOlá Mundo!\\n\\n## Arabic\\nمرحبًا عالم!\\n\\n## Chinese\\n你好世界!\"\n}",
        "@agent: Creating PDF document \"hello_world_multilingual.pdf\"",
        "@agent: Successfully created PDF document \"hello_world_multilingual.pdf\""
    ],
    "outputs": [
        {
            "filename": "hello_world_multilingual.pdf",
            "storageFilename": "pdf-4d50c082-6bf6-40dd-9ee4-b12a3eff1c60.pdf",
            "fileSize": 37994
        }
    ]
}

Then to download can use the new api/v1/document/generated-files/{filename} endpoint

curl -X GET "http://localhost:3001/api/v1/document/generated-files/pdf-4d50c082-6bf6-40dd-9ee4-b12a3eff1c60.pdf" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  --output quarterly-sales-report.pdf

Additional Information

  • No side effects with any other ephemeral agent system since this relies on the API only http-socket plugin.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/5658 **Author:** [@timothycarambat](https://github.com/timothycarambat) **Created:** 5/19/2026 **Status:** ✅ Merged **Merged:** 5/19/2026 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `5652-api-generated-docs` --- ### 📝 Commits (4) - [`abd8380`](https://github.com/Mintplex-Labs/anything-llm/commit/abd8380024449593d39af90270ddd9fde3fb36f5) support pulling generated documents from API calls - [`7d0700c`](https://github.com/Mintplex-Labs/anything-llm/commit/7d0700cd71a898a83a0602b91ee4f04e122f1b30) revert async wait - [`0b7014f`](https://github.com/Mintplex-Labs/anything-llm/commit/0b7014fe6cb0a666b5bcf560e0d3ced339fbafa2) fix strictness of packMessages to handle streaming chunks but keep functionality - [`351eb52`](https://github.com/Mintplex-Labs/anything-llm/commit/351eb52a09e0ab822c40495e421a793f682752c3) Merge branch 'master' into 5652-api-generated-docs ### 📊 Changes **4 files changed** (+210 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `server/endpoints/api/document/index.js` (+95 -0) 📝 `server/swagger/openapi.json` (+76 -0) 📝 `server/utils/agents/ephemeral.js` (+24 -4) 📝 `server/utils/chats/apiChatHandler.js` (+15 -2) </details> ### 📄 Description ### Pull Request Type <!-- For change type, change [ ] to [x]. --> - [x] ✨ feat (New feature) - [ ] 🐛 fix (Bug fix) - [x] ♻️ refactor (Code refactoring without changing behavior) - [ ] 💄 style (UI style changes) - [ ] 🔨 chore (Build, CI, maintenance) - [ ] 📝 docs (Documentation updates) ### Relevant Issues <!-- Use "resolves #xxx" to auto resolve on merge. Otherwise, please use "connect #xxx" --> resolves #5652 ### Description Adds support for returning `fileDownloadCard` events to the API responses for `chat/stream` as respective events with a new `output` key. This new key contains the storage filename to pull a file from the generated document directory as a binary so it can be downloaded with that same API key. This should not impact any existing integrations with the API as the response is additive. For streaming, `outputs` will only be present in `finalizeResponseStream` ```json { "uuid": "58efb129-0bd8-4c39-965f-f3cc8d841747", "type": "finalizeResponseStream", "textResponse": "The PDF document titled **\"hello_world_multilingual.pdf\"** has been successfully created and saved. It contains the \"Hello World\" message in multiple languages: English, Spanish, French, German, Japanese, and Chinese (Simplified). Let me know if you need any modifications or further assistance!", "thoughts": [ "@agent is executing `create-pdf-file` tool {\n \"filename\": \"hello_world_multilingual.pdf\",\n \"content\": \"# Hello World in Multiple Languages\\n\\n## English\\nHello World!\\n\\n## Spanish\\n¡Hola Mundo!\\n\\n## French\\nBonjour le Monde!\\n\\n## German\\nHallo Welt!\\n\\n## Japanese\\nこんにちは、世界!\\n\\n## Chinese (Simplified)\\n你好,世界!\"\n}", "@agent: Creating PDF document \"hello_world_multilingual.pdf\"", "@agent: Successfully created PDF document \"hello_world_multilingual.pdf\"" ], "outputs": [ { "filename": "hello_world_multilingual.pdf", "storageFilename": "pdf-e5460fb4-2bb0-447b-988a-8badfe6b5ba4.pdf", "fileSize": 31120 } ], "close": true, "error": false } ``` <!-- Describe the changes in this PR that are impactful to the repo. What problem does it solve? --> ### Examples ```bash curl --location 'http://localhost:3001/api/v1/workspace/sample/chat' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer xxxxxxxx' \ --data-raw '{ "message": "@agent make a simple hello world PDF document in multiple languages", "mode": "automatic", "reset": true }' ``` ```json { "id": "49f6c469-2e84-4b64-a122-c495cf4d95f6", "type": "textResponse", "sources": [], "close": true, "error": null, "textResponse": "The PDF document \"hello_world_multilingual.pdf\" has been successfully created and contains greetings in multiple languages. Let me know if you need any modifications or further assistance!", "thoughts": [ "@agent is executing `create-pdf-file` tool {\n \"filename\": \"hello_world_multilingual.pdf\",\n \"content\": \"# Hello World in Multiple Languages\\n\\n## English\\nHello World!\\n\\n## Spanish\\n¡Hola Mundo!\\n\\n## French\\nBonjour le Monde!\\n\\n## German\\nHallo Welt!\\n\\n## Italian\\nCiao Mondo!\\n\\n## Japanese\\nこんにちは世界!\\n\\n## Korean\\n안녕하세요 세계!\\n\\n## Russian\\nПривет, мир!\\n\\n## Portuguese\\nOlá Mundo!\\n\\n## Arabic\\nمرحبًا عالم!\\n\\n## Chinese\\n你好世界!\"\n}", "@agent: Creating PDF document \"hello_world_multilingual.pdf\"", "@agent: Successfully created PDF document \"hello_world_multilingual.pdf\"" ], "outputs": [ { "filename": "hello_world_multilingual.pdf", "storageFilename": "pdf-4d50c082-6bf6-40dd-9ee4-b12a3eff1c60.pdf", "fileSize": 37994 } ] } ``` Then to download can use the new `api/v1/document/generated-files/{filename}` endpoint ```bash curl -X GET "http://localhost:3001/api/v1/document/generated-files/pdf-4d50c082-6bf6-40dd-9ee4-b12a3eff1c60.pdf" \ -H "Authorization: Bearer YOUR_API_KEY" \ --output quarterly-sales-report.pdf ``` <!-- Add screenshots or screen recordings to demonstrate the changes, especially for UI updates. --> ### Additional Information - No side effects with any other `ephemeral` agent system since this relies on the API only `http-socket` plugin. <!-- Add any other context about the Pull Request here that was not captured above. --> ### Developer Validations <!-- All of the applicable items should be checked. --> - [ ] I ran `yarn lint` from the root of the repo & committed changes - [ ] Relevant documentation has been updated (if applicable) - [ ] I have tested my code functionality - [ ] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 15:21:35 -04:00
yindo closed this issue 2026-06-05 15:21:35 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#5512