mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-05-25 23:06:20 +00:00
Introduce the builtin `_a0_connector` plugin that lets the host-side A0 CLI connect to Agent Zero over authenticated HTTP and `/ws`. This adds connector capability discovery, chat/context lifecycle endpoints, log streaming, and the remote text editing, code execution, and file tree bridge used by the CLI workflow.
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""POST /api/plugins/_a0_connector/v1/chat_create."""
|
|
from __future__ import annotations
|
|
|
|
from helpers.api import Request, Response
|
|
import plugins._a0_connector.api.v1.base as connector_base
|
|
|
|
|
|
class ChatCreate(connector_base.ProtectedConnectorApiHandler):
|
|
async def process(self, input: dict, request: Request) -> dict | Response:
|
|
from helpers import projects
|
|
from plugins._a0_connector.helpers.chat_context import create_context
|
|
|
|
current_context_id = (
|
|
str(input.get("current_context", input.get("current_context_id", ""))).strip()
|
|
or None
|
|
)
|
|
project_name = str(input.get("project_name", "")).strip() or None
|
|
agent_profile = str(input.get("agent_profile", "")).strip() or None
|
|
|
|
try:
|
|
context = create_context(
|
|
lock=self.thread_lock,
|
|
current_context_id=current_context_id,
|
|
agent_profile=agent_profile,
|
|
project_name=project_name,
|
|
)
|
|
except Exception as exc:
|
|
return Response(
|
|
response=f'{{"error": "Failed to activate project: {str(exc)}"}}',
|
|
status=400,
|
|
mimetype="application/json",
|
|
)
|
|
|
|
context_data = context.output()
|
|
return {
|
|
"context_id": context.id,
|
|
"created_at": context_data.get("created_at"),
|
|
"agent_profile": agent_profile or getattr(context.agent0.config, "profile", "default"),
|
|
"project_name": context.get_data(projects.CONTEXT_DATA_KEY_PROJECT),
|
|
}
|