[PR #22156] [CLOSED] feat: add upload_file_to_terminal builtin tool #26522

Closed
opened 2026-04-20 06:33:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22156
Author: @Classic298
Created: 3/2/2026
Status: Closed

Base: devHead: feat/upload-file-to-terminal-tool


📝 Commits (5)

📊 Changes

3 files changed (+146 additions, -0 deletions)

View changed files

📝 backend/open_webui/tools/builtin.py (+139 -0)
📝 backend/open_webui/utils/middleware.py (+1 -0)
📝 backend/open_webui/utils/tools.py (+6 -0)

📄 Description

Addresses: https://github.com/open-webui/open-webui/issues/22528

Description

Adds a new builtin tool, upload_file_to_terminal, that allows an AI model to upload files attached to a chat directly to a connected Open Terminal server's working directory.

Changes

backend/open_webui/tools/builtin.py

  • New upload_file_to_terminal function in the TERMINAL TOOLS section
  • Resolves chat file attachments by name (with case-insensitive fallback)
  • Retrieves file content from Open WebUI's storage layer (supports local, S3, GCS, Azure backends)
  • Resolves terminal connections from both system terminals (by ID in TERMINAL_SERVER_CONNECTIONS) and direct/user-configured terminals (by matching URL in metadata tool_servers)
  • Queries the terminal server's current working directory via GET /files/cwd before uploading
  • Uploads the file using POST /files/upload with proper auth headers

backend/open_webui/utils/tools.py

  • Imports upload_file_to_terminal
  • Conditionally registers it in get_builtin_tools when a terminal_id is present in metadata and the terminal builtin capability is enabled

backend/open_webui/utils/middleware.py

  • Syncs extra_params["metadata"] after metadata is reassigned to a new dict (which adds terminal_id, tool_ids, files). Without this fix, builtin tools could not see terminal_id because extra_params still referenced the old metadata dict.

How It Works

When a user attaches a file to a chat and asks the model to upload it to the terminal:

  1. The model calls upload_file_to_terminal with the filename
  2. The tool finds the file in the chat's attached files metadata
  3. It retrieves the file from Open WebUI's storage
  4. It resolves the terminal connection (system or direct)
  5. It queries the terminal's CWD, then uploads the file there

Testing

Tested locally with Open Terminal. Verified:

  • Tool appears in the model's available tools when a terminal is connected
  • File lookup, storage retrieval, and upload all function end-to-end
  • Both system and direct terminal connections are supported

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 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/open-webui/open-webui/pull/22156 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 3/2/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `feat/upload-file-to-terminal-tool` --- ### 📝 Commits (5) - [`2ef5a93`](https://github.com/open-webui/open-webui/commit/2ef5a93a473c8b9d936ce79a14896e11cc9be5bc) feat: add upload_file_to_terminal builtin tool - [`9722916`](https://github.com/open-webui/open-webui/commit/9722916d90da855fa10c08b0ea01ac39679828cc) fixes - [`f978e33`](https://github.com/open-webui/open-webui/commit/f978e333e4e51cc504da190b9999f8057f39b6e0) feat - [`7394d38`](https://github.com/open-webui/open-webui/commit/7394d389645a5431a77fbc1f077247e05857cbb0) Merge branch 'dev' into feat/upload-file-to-terminal-tool - [`be7b392`](https://github.com/open-webui/open-webui/commit/be7b392626bff03a6fdf3f8c2d3ad4c78260e238) . (#168) ### 📊 Changes **3 files changed** (+146 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/tools/builtin.py` (+139 -0) 📝 `backend/open_webui/utils/middleware.py` (+1 -0) 📝 `backend/open_webui/utils/tools.py` (+6 -0) </details> ### 📄 Description Addresses: https://github.com/open-webui/open-webui/issues/22528 ### Description Adds a new builtin tool, upload_file_to_terminal, that allows an AI model to upload files attached to a chat directly to a connected Open Terminal server's working directory. ### Changes **backend/open_webui/tools/builtin.py** - New upload_file_to_terminal function in the TERMINAL TOOLS section - Resolves chat file attachments by name (with case-insensitive fallback) - Retrieves file content from Open WebUI's storage layer (supports local, S3, GCS, Azure backends) - Resolves terminal connections from both system terminals (by ID in TERMINAL_SERVER_CONNECTIONS) and direct/user-configured terminals (by matching URL in metadata tool_servers) - Queries the terminal server's current working directory via GET /files/cwd before uploading - Uploads the file using POST /files/upload with proper auth headers **backend/open_webui/utils/tools.py** - Imports upload_file_to_terminal - Conditionally registers it in get_builtin_tools when a terminal_id is present in metadata and the terminal builtin capability is enabled **backend/open_webui/utils/middleware.py** - Syncs extra_params["__metadata__"] after metadata is reassigned to a new dict (which adds terminal_id, tool_ids, files). Without this fix, builtin tools could not see terminal_id because extra_params still referenced the old metadata dict. ### How It Works When a user attaches a file to a chat and asks the model to upload it to the terminal: 1. The model calls upload_file_to_terminal with the filename 2. The tool finds the file in the chat's attached files metadata 3. It retrieves the file from Open WebUI's storage 4. It resolves the terminal connection (system or direct) 5. It queries the terminal's CWD, then uploads the file there ### Testing Tested locally with Open Terminal. Verified: - Tool appears in the model's available tools when a terminal is connected - File lookup, storage retrieval, and upload all function end-to-end - Both system and direct terminal connections are supported ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. --> By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 06:33:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#26522