[PR #23349] [CLOSED] feat: add upload_file_to_terminal builtin tool #27158

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

📋 Pull Request Information

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

Base: devHead: upload-file-tool


📝 Commits (10+)

  • 8921a01 feat: add upload_file_to_terminal builtin tool with file_id and acces… (#170)
  • 13c53b8 . (#171)
  • 73db792 Auth bypass fix
  • 2e20018 Add direct server connection support
  • febc4d5 fix
  • 297369b fix: await has_connection_access to prevent authorization bypass
  • 4cbbe73 fix: restrict uploads to admin-configured terminals, resolve before fetching file, accept 2xx
  • b2b0702 fix: guard JSON parsing on upload response for non-JSON success bodies
  • f165f7d fix: offload blocking storage and file reads to worker thread
  • 8416b9c fix: repair system_oauth path and stream file uploads to terminal

📊 Changes

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

View changed files

📝 backend/open_webui/tools/builtin.py (+186 -0)
📝 backend/open_webui/utils/middleware.py (+1 -0)
📝 backend/open_webui/utils/tools.py (+7 -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 to a connected Open Terminal server's working directory.

It can upload user uploaded files and files from knowledge bases the user has access to!

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

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/23349 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 4/2/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `upload-file-tool` --- ### 📝 Commits (10+) - [`8921a01`](https://github.com/open-webui/open-webui/commit/8921a01660f6b3ad1e6ce4383222456ca8de47e8) feat: add upload_file_to_terminal builtin tool with file_id and acces… (#170) - [`13c53b8`](https://github.com/open-webui/open-webui/commit/13c53b89c1edcfa43d70c5701e89a6ce0a07f238) . (#171) - [`73db792`](https://github.com/open-webui/open-webui/commit/73db7921e116bb1a3b149ce7c4c2f3d66cb3da6c) Auth bypass fix - [`2e20018`](https://github.com/open-webui/open-webui/commit/2e20018a9eaecea279ea4e2765a809e243bb9433) Add direct server connection support - [`febc4d5`](https://github.com/open-webui/open-webui/commit/febc4d530d68e8eca2bfab8c46d295799ae9c2de) fix - [`297369b`](https://github.com/open-webui/open-webui/commit/297369b195b1a65cba8e651a855d83a1dce2fa83) fix: await has_connection_access to prevent authorization bypass - [`4cbbe73`](https://github.com/open-webui/open-webui/commit/4cbbe73376dc61f093a0d2c690d24b80db5cfd6e) fix: restrict uploads to admin-configured terminals, resolve before fetching file, accept 2xx - [`b2b0702`](https://github.com/open-webui/open-webui/commit/b2b0702eeaa80cdc62ca114bf4edabcb67446d65) fix: guard JSON parsing on upload response for non-JSON success bodies - [`f165f7d`](https://github.com/open-webui/open-webui/commit/f165f7dc3d4768ea5ad60617bed6f271080e9c49) fix: offload blocking storage and file reads to worker thread - [`8416b9c`](https://github.com/open-webui/open-webui/commit/8416b9cfb5e14d589316054128a188a0aa91306d) fix: repair system_oauth path and stream file uploads to terminal ### 📊 Changes **3 files changed** (+194 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/tools/builtin.py` (+186 -0) 📝 `backend/open_webui/utils/middleware.py` (+1 -0) 📝 `backend/open_webui/utils/tools.py` (+7 -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 to a connected Open Terminal server's working directory. <ins>**It can upload user uploaded files and files from knowledge bases the user has access to!**</ins> ### 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. Your PR will NOT be reviewed or merged until you check the box below confirming that you have read and agree to the terms of the CLA. --> - [x] 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:54:35 -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#27158