mirror of
https://github.com/open-webui/open-terminal.git
synced 2026-11-22 21:50:43 -05:00
refac
This commit is contained in:
1 parent
138931701e
commit
b9f4b07ab8
6 files changed
+121
-13
No files matched your search
@@ -101,6 +101,17 @@ Install and sign in to the agent CLIs as the user running Open Terminal. In a co
|
||||
| Pi | `pi --mode rpc` | `OPEN_TERMINAL_PI_COMMAND` |
|
||||
| Hermes | `hermes acp` | `OPEN_TERMINAL_HERMES_COMMAND` |
|
||||
| Antigravity | `agy acp` | `OPEN_TERMINAL_ANTIGRAVITY_COMMAND` |
|
||||
| GitHub Copilot | `copilot --acp` | `OPEN_TERMINAL_COPILOT_COMMAND` |
|
||||
| Goose | `goose acp` | `OPEN_TERMINAL_GOOSE_COMMAND` |
|
||||
| Qwen Code | `qwen --acp` | `OPEN_TERMINAL_QWEN_COMMAND` |
|
||||
|
||||
Any other ACP agent, such as those in the [ACP Registry](https://agentclientprotocol.com/get-started/registry), can be added without a code change. List them in `OPEN_TERMINAL_ACP_AGENTS` as a JSON object of ids, display names and launch commands:
|
||||
|
||||
```bash
|
||||
OPEN_TERMINAL_ACP_AGENTS='{"droid": {"name": "Factory Droid", "command": "droid exec --output-format acp-daemon"}, "kiro": {"name": "Kiro", "command": "kiro-cli acp"}}'
|
||||
```
|
||||
|
||||
Each one appears as `acp-<id>` (for example `acp-droid`). Ids are lowercase letters, digits, `-` and `_`. These agents run with plain ACP: they get no agent-specific sign-in step, and in Auto they ask before acting instead of using their own reviewer. Because each entry is a command Open Terminal runs, it can only be set in Open Terminal's environment, not through its API.
|
||||
|
||||
These adapters target current CLI protocols. ACP model discovery prefers session config options and also reads the native `models` field still advertised by current agents such as Gemini. Pi requires the current RPC `agent_settled` completion event and `--session-id` support. There are no hardcoded model lists. Log in through the CLI before using WebUI; the integration does not run interactive login flows. ACP agents execute their own filesystem and terminal tools in this environment. Pi follows its native tool policy; WebUI forwards extension confirmation dialogs but does not add a separate per-tool permission layer.
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
"""GitHub Copilot ACP launch and discovery."""
|
||||
|
||||
from . import acp
|
||||
|
||||
NAME = "GitHub Copilot"
|
||||
BINARY = "copilot"
|
||||
COMMAND_ENV = "OPEN_TERMINAL_COPILOT_COMMAND"
|
||||
|
||||
|
||||
def arguments(options):
|
||||
return ["--acp"]
|
||||
|
||||
|
||||
async def discover(send, response, cwd):
|
||||
return await acp.discover(send, response, cwd, auth_method=None)
|
||||
@@ -0,0 +1,15 @@
|
||||
"""Goose ACP launch and discovery."""
|
||||
|
||||
from . import acp
|
||||
|
||||
NAME = "Goose"
|
||||
BINARY = "goose"
|
||||
COMMAND_ENV = "OPEN_TERMINAL_GOOSE_COMMAND"
|
||||
|
||||
|
||||
def arguments(options):
|
||||
return ["acp"]
|
||||
|
||||
|
||||
async def discover(send, response, cwd):
|
||||
return await acp.discover(send, response, cwd, auth_method=None)
|
||||
@@ -0,0 +1,15 @@
|
||||
"""Qwen Code ACP launch and discovery."""
|
||||
|
||||
from . import acp
|
||||
|
||||
NAME = "Qwen Code"
|
||||
BINARY = "qwen"
|
||||
COMMAND_ENV = "OPEN_TERMINAL_QWEN_COMMAND"
|
||||
|
||||
|
||||
def arguments(options):
|
||||
return ["--acp"]
|
||||
|
||||
|
||||
async def discover(send, response, cwd):
|
||||
return await acp.discover(send, response, cwd, auth_method=None)
|
||||
@@ -4,7 +4,6 @@ import asyncio
|
||||
import contextlib
|
||||
import json
|
||||
import time
|
||||
from typing import Literal
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, WebSocket
|
||||
@@ -51,21 +50,13 @@ def payload(session):
|
||||
include_in_schema=False,
|
||||
)
|
||||
async def create(
|
||||
provider: Literal[
|
||||
"codex",
|
||||
"claude-code",
|
||||
"cursor",
|
||||
"grok",
|
||||
"opencode",
|
||||
"cline",
|
||||
"gemini",
|
||||
"pi",
|
||||
"hermes",
|
||||
"antigravity",
|
||||
],
|
||||
provider: str,
|
||||
body: runtime.Start,
|
||||
request: Request,
|
||||
):
|
||||
# Built-ins plus any agents configured in OPEN_TERMINAL_ACP_AGENTS.
|
||||
if provider not in runtime.PROVIDERS:
|
||||
raise HTTPException(404, "Unknown agent provider")
|
||||
fs = get_filesystem(request)
|
||||
owner = request.headers.get("x-user-id") or "single"
|
||||
chat = request.headers.get("x-session-id", "")
|
||||
|
||||
@@ -6,7 +6,10 @@ import asyncio
|
||||
import contextlib
|
||||
import errno
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import signal
|
||||
import time
|
||||
@@ -21,6 +24,7 @@ from pydantic import BaseModel, Field
|
||||
|
||||
from open_terminal.env import sanitized_environ
|
||||
from . import (
|
||||
acp,
|
||||
codex,
|
||||
claude_code,
|
||||
cursor,
|
||||
@@ -31,8 +35,13 @@ from . import (
|
||||
pi,
|
||||
hermes,
|
||||
antigravity,
|
||||
copilot,
|
||||
goose,
|
||||
qwen,
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LIMIT = 16 * 1024 * 1024
|
||||
PROVIDERS = {
|
||||
"codex": codex,
|
||||
@@ -45,7 +54,59 @@ PROVIDERS = {
|
||||
"pi": pi,
|
||||
"hermes": hermes,
|
||||
"antigravity": antigravity,
|
||||
"copilot": copilot,
|
||||
"goose": goose,
|
||||
"qwen": qwen,
|
||||
}
|
||||
|
||||
|
||||
class ConfiguredAcp:
|
||||
"""An ACP agent declared in OPEN_TERMINAL_ACP_AGENTS, run with plain ACP and no per-agent handling."""
|
||||
|
||||
COMMAND_ENV = ""
|
||||
|
||||
def __init__(self, name: str, command: list[str]):
|
||||
self.NAME = name
|
||||
self.BINARY, *self.args = command
|
||||
|
||||
def arguments(self, options):
|
||||
return list(self.args)
|
||||
|
||||
async def discover(self, send, response, cwd):
|
||||
return await acp.discover(send, response, cwd, auth_method=None)
|
||||
|
||||
|
||||
def configured_agents(raw: str | None) -> dict[str, ConfiguredAcp]:
|
||||
"""Read `{"id": {"name": ..., "command": ...}}`; ids get an `acp-` prefix so they never shadow built-ins."""
|
||||
try:
|
||||
entries = json.loads(raw or "{}")
|
||||
except json.JSONDecodeError:
|
||||
log.warning(
|
||||
"OPEN_TERMINAL_ACP_AGENTS is not valid JSON; no extra agents loaded"
|
||||
)
|
||||
return {}
|
||||
if not isinstance(entries, dict):
|
||||
log.warning(
|
||||
"OPEN_TERMINAL_ACP_AGENTS must be a JSON object; no extra agents loaded"
|
||||
)
|
||||
return {}
|
||||
agents = {}
|
||||
for key, spec in entries.items():
|
||||
spec = spec if isinstance(spec, dict) else {}
|
||||
try:
|
||||
command = shlex.split(spec.get("command") or "")
|
||||
except (TypeError, ValueError):
|
||||
command = []
|
||||
if not re.fullmatch(r"[a-z0-9][a-z0-9_-]{0,47}", str(key)) or not command:
|
||||
log.warning(
|
||||
"Skipping ACP agent %r: it needs a lowercase id and a command", key
|
||||
)
|
||||
continue
|
||||
agents[f"acp-{key}"] = ConfiguredAcp(str(spec.get("name") or key), command)
|
||||
return agents
|
||||
|
||||
|
||||
PROVIDERS.update(configured_agents(os.environ.get("OPEN_TERMINAL_ACP_AGENTS")))
|
||||
sessions: dict[str, Session] = {}
|
||||
creation_lock = asyncio.Lock()
|
||||
|
||||
|
||||
Reference in new issue
Block a user