mirror of
https://github.com/open-webui/computer.git
synced 2026-11-28 16:11:44 -05:00
refac
This commit is contained in:
1 parent
6f7ee2d610
commit
e687f0e4ba
2 files changed
+49
-2
No files matched your search
@@ -158,6 +158,18 @@ async def detect_profile(profile: dict[str, Any]) -> AgentDetection:
|
||||
)
|
||||
return AgentDetection("ready", command, version, None, models)
|
||||
|
||||
if profile.get("agent") == "cline":
|
||||
models = await _probe_cline_models(command, profile)
|
||||
if not models:
|
||||
return AgentDetection(
|
||||
"auth_unknown",
|
||||
command,
|
||||
version,
|
||||
"Could not discover Cline models. Check `cline auth` or add models manually.",
|
||||
[],
|
||||
)
|
||||
return AgentDetection("ready", command, version, None, models)
|
||||
|
||||
return AgentDetection("error", command, version, "Unknown agent")
|
||||
|
||||
|
||||
@@ -387,6 +399,28 @@ async def _probe_opencode_models(command: str, profile: dict[str, Any]) -> list[
|
||||
await proc.wait()
|
||||
|
||||
|
||||
async def _probe_cline_models(command: str, profile: dict[str, Any]) -> list[str] | None:
|
||||
from cptr.utils.agents.acp import AcpClient, acp_models_from_setup
|
||||
|
||||
env = os.environ.copy()
|
||||
if profile.get("home"):
|
||||
env["HOME"] = os.path.expanduser(str(profile["home"]))
|
||||
client = AcpClient(
|
||||
command=command,
|
||||
args=["--acp"],
|
||||
cwd=os.getcwd(),
|
||||
env=env,
|
||||
auth_method_id=None,
|
||||
)
|
||||
try:
|
||||
await asyncio.wait_for(client.start(), timeout=10)
|
||||
return acp_models_from_setup(client.setup_result) or None
|
||||
except Exception:
|
||||
return None
|
||||
finally:
|
||||
await client.close()
|
||||
|
||||
|
||||
def _free_port() -> int:
|
||||
with socket.socket() as sock:
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
|
||||
@@ -70,10 +70,20 @@ DEFAULT_AGENT_PROFILES: list[dict[str, Any]] = [
|
||||
"server_url": "",
|
||||
"server_password": "",
|
||||
},
|
||||
{
|
||||
"id": "cline",
|
||||
"agent": "cline",
|
||||
"name": "Cline",
|
||||
"mode": "auto",
|
||||
"command": "cline",
|
||||
"home": None,
|
||||
"models": [],
|
||||
"default_model": "",
|
||||
},
|
||||
]
|
||||
|
||||
_PROFILE_ID_RE = re.compile(r"^[a-z][a-z0-9_-]{0,63}$")
|
||||
_VALID_AGENTS = {"codex", "claude_code", "cursor", "grok", "opencode"}
|
||||
_VALID_AGENTS = {"codex", "claude_code", "cursor", "grok", "opencode", "cline"}
|
||||
_VALID_MODES = {"auto", "enabled", "disabled"}
|
||||
_VALID_CODEX_APPROVAL = {"ask", "auto", "full"}
|
||||
_VALID_CODEX_SANDBOX = {"read-only", "workspace-write", "danger-full-access"}
|
||||
@@ -92,6 +102,7 @@ _AGENT_DEFAULTS: dict[str, dict[str, str]] = {
|
||||
},
|
||||
"grok": {"name": "Grok", "command": "grok", "model": ""},
|
||||
"opencode": {"name": "OpenCode", "command": "opencode", "model": ""},
|
||||
"cline": {"name": "Cline", "command": "cline", "model": ""},
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +118,9 @@ def normalize_agent_profile(raw: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
agent = str(profile.get("agent") or "").strip()
|
||||
if agent not in _VALID_AGENTS:
|
||||
raise HTTPException(400, "agent must be codex, claude_code, cursor, grok, or opencode")
|
||||
raise HTTPException(
|
||||
400, "agent must be codex, claude_code, cursor, grok, opencode, or cline"
|
||||
)
|
||||
defaults = _AGENT_DEFAULTS[agent]
|
||||
|
||||
mode = str(profile.get("mode") or "auto").strip()
|
||||
|
||||
Reference in new issue
Block a user