052591281d
- Complete agent system with planning and execution - Bridge API with FastAPI server - WhatsApp-style mobile dashboard - Enhanced web search with query improvement - Security guards and policy checks - Comprehensive documentation
89 lines
2.4 KiB
Python
89 lines
2.4 KiB
Python
"""Pydantic schemas for Bridge V1.2 API."""
|
|
from __future__ import annotations
|
|
|
|
from enum import Enum
|
|
from typing import Any, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class RunStatus(str, Enum):
|
|
CREATED = "created"
|
|
RUNNING = "running"
|
|
DONE = "done"
|
|
FAILED = "failed"
|
|
|
|
|
|
# --- Request bodies ---
|
|
|
|
class CreateRunRequest(BaseModel):
|
|
goal: str = Field(..., min_length=1, max_length=2000)
|
|
run_id: Optional[str] = Field(None)
|
|
adapter: str = Field("local_echo", description="Adapter: stub | local_echo | openai | cloudcode | agent")
|
|
|
|
|
|
# --- Response bodies ---
|
|
|
|
class RunResponse(BaseModel):
|
|
run_id: str
|
|
goal: str
|
|
status: RunStatus
|
|
adapter: str
|
|
adapter_mode: Optional[str] = None
|
|
instruction: Optional[str] = None
|
|
response: Optional[str] = None
|
|
error: Optional[str] = None
|
|
exit_code: Optional[int] = None
|
|
# Agent-specific (only populated when adapter="agent")
|
|
agent_run_id: Optional[str] = None
|
|
agent_final_status: Optional[str] = None
|
|
agent_state_path: Optional[str] = None
|
|
created_at: str
|
|
updated_at: str
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
status: str
|
|
adapters: dict[str, Any]
|
|
openai_mode: str # "real" | "stub"
|
|
decision_backend: str # "ollama" | "stub"
|
|
ollama_model: str # active Ollama model
|
|
|
|
|
|
# --- Chat ---
|
|
|
|
class ChatRequest(BaseModel):
|
|
message: str = Field(..., min_length=1, max_length=1000)
|
|
trace_id: Optional[str] = Field(None, description="Optional trace ID for observability")
|
|
|
|
|
|
class ChatResponse(BaseModel):
|
|
reply: str
|
|
cjk_detected: bool = False
|
|
fallback_used: bool = False
|
|
model: str
|
|
trace_id: Optional[str] = None
|
|
|
|
|
|
# --- Controller ---
|
|
|
|
class ControllerRunRequest(BaseModel):
|
|
goal: str = Field(..., min_length=1, max_length=2000)
|
|
run_id: Optional[str] = Field(None, description="Optional controller run ID (auto-generated if omitted)")
|
|
|
|
|
|
class ControllerResponse(BaseModel):
|
|
controller_run_id: str
|
|
original_goal: str
|
|
final_status: str # running | done | failed | stopped
|
|
decision_mode: str # "real" | "stub"
|
|
iteration_count: int
|
|
decisions: list[dict[str, Any]]
|
|
linked_bridge_run_ids: list[str]
|
|
bridge_run_results: list[dict[str, Any]]
|
|
recovery_attempted: bool = False
|
|
recovery_reason: Optional[str] = None
|
|
rewritten_goal: Optional[str] = None
|
|
created_at: str
|
|
updated_at: str
|