mirror of
https://github.com/open-webui/computer.git
synced 2026-11-19 20:27:05 +03:00
refac
This commit is contained in:
@@ -12,10 +12,67 @@ Push a hotfix from the train. Check on a deploy from bed. Ship a side project fr
|
||||
|
||||
Close the tab. Come back tomorrow on any device. Everything is where you left it. Sessions survive disconnects. Your work doesn't care which screen you're on.
|
||||
|
||||
AI is there if you want it. Bring your own key. Works fine without it.
|
||||
|
||||
Life is short. Touch grass.
|
||||
|
||||
## What you get
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 📁 **File browser** | Navigate, create, rename, upload, drag and drop. Icons by type, sizes at a glance. |
|
||||
| ⌨️ **Terminal** | Full PTY-backed shell in the browser. Anything you'd run at your desk. |
|
||||
| 🔀 **Git** | Stage, commit, diff, branch, push. Visual changes view. No command line required. |
|
||||
| ✏️ **Editor** | Syntax-highlighted editing with tabs. Open multiple files side by side. |
|
||||
| 📂 **Workspaces** | Multiple projects, one instance. Switch without losing your place. |
|
||||
| 🔍 **Search** | Find files by name, search across file contents and chat history. ⌘K to find anything. |
|
||||
| 📱 **Mobile-first** | Not a desktop UI made smaller. Built for the screen in your pocket. |
|
||||
| 🔄 **Sessions persist** | Terminal keeps running when you close the tab. Come back on any device. |
|
||||
|
||||
## AI agent
|
||||
|
||||
Bring your own API key. Works with OpenAI, Anthropic, Ollama, or any OpenAI-compatible endpoint.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 💬 **Chat** | Built-in AI with streaming responses and tool calling. Not just conversation: it can act. |
|
||||
| 🔧 **File tools** | AI reads, writes, edits, and searches your codebase directly. |
|
||||
| ▶️ **Run commands** | AI executes shell commands and reads the output. Foreground or background. |
|
||||
| 🌐 **Web browsing** | Navigate pages, click elements, fill forms, take screenshots. |
|
||||
| 🔍 **Web search** | Brave, DuckDuckGo, Exa, Tavily, Perplexity, or any chat completions endpoint. |
|
||||
| 🖼️ **Image understanding** | AI reads and describes images and screenshots from your workspace. |
|
||||
| 📋 **Plan mode** | Request an implementation plan before the AI writes a single line. |
|
||||
| ✏️ **Output editing** | Review and edit AI-generated changes before applying. |
|
||||
| 📎 **File mentions** | Type `@` to give the AI context about specific files. |
|
||||
| 🧩 **Skills** | Reusable instruction sets (SKILL.md files). Type `$` to mention one. |
|
||||
| ⏱️ **Automations** | Schedule recurring AI tasks. "Run tests every morning." "Deploy every Friday." |
|
||||
| 🤖 **Sub-agents** | AI spins up parallel workers for complex tasks. Each gets full tool access. |
|
||||
| 🔌 **Tool servers** | Connect external tools via MCP or OpenAPI. |
|
||||
| 🧠 **Context compaction** | Long conversations are automatically summarised to stay fast. |
|
||||
|
||||
## Messaging bots
|
||||
|
||||
Connect the AI to your chat apps. Full tool access, streaming responses, conversations synced back to the web UI.
|
||||
|
||||
**Telegram** · **Discord** · **Slack** · **WhatsApp** · **Signal**
|
||||
|
||||
Message your computer from wherever you are. Ask it to check a build, push a fix, or explain a file. Switch workspaces with `/workspace`, start fresh with `/new`.
|
||||
|
||||
## Gateway API
|
||||
|
||||
cptr exposes an OpenAI-compatible API (`/v1/chat/completions`). Any client that speaks OpenAI, including [Open WebUI](https://github.com/open-webui/open-webui), can use each cptr workspace as a model with full agent capabilities: file access, terminal, web search, tools.
|
||||
|
||||
## More
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 🎙️ **Voice memos** | Record audio, auto-transcribe to markdown. |
|
||||
| 💬 **Message queue** | Queue follow-up messages while the AI is responding. |
|
||||
| 🔔 **Notifications** | Browser notifications and webhooks (Slack, Discord, Teams) when tasks finish. |
|
||||
| 📊 **Usage** | Token counts and timing on every response. |
|
||||
| 📄 **System prompts** | Per-model, per-workspace, or global. Template variables included. |
|
||||
| ⌨️ **Keyboard shortcuts** | Customisable keybindings with a settings panel. |
|
||||
| 🌍 **10 languages** | EN, DE, ES, FR, JA, KO, PT-BR, RU, ZH-CN, ZH-TW. |
|
||||
| 🔐 **Auth** | Username/password with JWT sessions. Signup toggle for admins. |
|
||||
|
||||
## Design principles
|
||||
|
||||
**Mobile is first-class.** The interface is built for the phone. Touch-native, portrait-native, designed for the screen people carry. Sessions survive disconnects because on a phone, they will. If a feature only works at a desk, it's not done.
|
||||
|
||||
+12
@@ -128,6 +128,18 @@ from cptr.utils.proxy_middleware import ProxyFallbackMiddleware
|
||||
|
||||
app.add_middleware(ProxyFallbackMiddleware)
|
||||
|
||||
# CORS middleware: uses CPTR_CORS_ALLOWED_ORIGINS env var (default "*").
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from cptr.env import CORS_ALLOWED_ORIGINS
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=CORS_ALLOWED_ORIGINS if isinstance(CORS_ALLOWED_ORIGINS, list) else ["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
# Path normalization middleware (Windows: \ → / in JSON responses)
|
||||
import platform
|
||||
|
||||
+10
@@ -37,3 +37,13 @@ STREAM_WRITE_TIMEOUT_SECONDS = float(os.environ.get("CPTR_STREAM_WRITE_TIMEOUT",
|
||||
# ── Automation scheduler ────────────────────────────────────
|
||||
AUTOMATION_POLL_INTERVAL = int(os.environ.get("AUTOMATION_POLL_INTERVAL", "10"))
|
||||
|
||||
# ── CORS ────────────────────────────────────────────────────
|
||||
# Socket.IO CORS allowed origins.
|
||||
# Default → "*" (allow all origins)
|
||||
# Comma-separated list → allow specific origins only
|
||||
# e.g. "https://example.com,https://app.example.com"
|
||||
_cors_raw = os.environ.get("CPTR_CORS_ALLOWED_ORIGINS", "*")
|
||||
if _cors_raw.strip() == "*":
|
||||
CORS_ALLOWED_ORIGINS = "*"
|
||||
else:
|
||||
CORS_ALLOWED_ORIGINS = [o.strip() for o in _cors_raw.split(",") if o.strip()] or "*"
|
||||
|
||||
+2
-1
@@ -10,8 +10,9 @@ from __future__ import annotations
|
||||
import socketio
|
||||
|
||||
from cptr.utils.config import check_access
|
||||
from cptr.env import CORS_ALLOWED_ORIGINS
|
||||
|
||||
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
|
||||
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins=CORS_ALLOWED_ORIGINS)
|
||||
|
||||
# user_id → set of connected sids
|
||||
_user_sids: dict[str, set[str]] = {}
|
||||
|
||||
@@ -70,11 +70,41 @@ class ProxyFallbackMiddleware:
|
||||
await self.app(scope, receive, send)
|
||||
return
|
||||
|
||||
# Auth check: this middleware runs before the auth middleware (outermost),
|
||||
# so we must verify the session ourselves to prevent unauthenticated SSRF.
|
||||
if not self._is_authenticated(scope):
|
||||
# Not authenticated — fall through to the normal app (which will
|
||||
# either serve a page or return 401 via the auth middleware).
|
||||
await self.app(scope, receive, send)
|
||||
return
|
||||
|
||||
if scope["type"] == "http":
|
||||
await self._proxy_http(scope, receive, send, port, path)
|
||||
elif scope["type"] == "websocket":
|
||||
await self._proxy_websocket(scope, receive, send, port, path)
|
||||
|
||||
@staticmethod
|
||||
def _is_authenticated(scope: Scope) -> bool:
|
||||
"""Check if the request carries a valid cptr session cookie."""
|
||||
from cptr.utils.config import check_access
|
||||
|
||||
headers = dict(scope.get("headers", []))
|
||||
cookie_header = (headers.get(b"cookie") or b"").decode("latin-1", errors="replace")
|
||||
|
||||
token = None
|
||||
for part in cookie_header.split(";"):
|
||||
part = part.strip()
|
||||
if part.startswith("cptr_session="):
|
||||
token = part.split("=", 1)[1]
|
||||
break
|
||||
|
||||
if not token:
|
||||
return False
|
||||
|
||||
client = scope.get("client")
|
||||
client_host = client[0] if client else "127.0.0.1"
|
||||
return check_access(client_host=client_host, jwt_token=token) is not None
|
||||
|
||||
def _resolve_port(self, scope: Scope) -> int | None:
|
||||
"""Determine which proxy port this request belongs to."""
|
||||
from cptr.routers.proxy import resolve_cached_port
|
||||
|
||||
Reference in New Issue
Block a user