Spaces:
Running

File size: 2,215 Bytes
fd5dd94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Request/response models for the HTTP API."""

from __future__ import annotations

import uuid
from datetime import datetime
from typing import Any, Literal

from pydantic import BaseModel, EmailStr, Field


class SignupIn(BaseModel):
    business_name: str = Field(min_length=2, max_length=200)
    email: EmailStr
    password: str = Field(min_length=10, max_length=200)


class LoginIn(BaseModel):
    email: EmailStr
    password: str
    tenant_id: uuid.UUID | None = None


class TokenPair(BaseModel):
    access_token: str
    refresh_token: str
    tenant_id: uuid.UUID
    token_type: str = "bearer"  # noqa: S105


class RefreshIn(BaseModel):
    refresh_token: str


class StepUpIn(BaseModel):
    code: str = Field(pattern=r"^\d{6}$")


class ChatIn(BaseModel):
    message: str = Field(min_length=1, max_length=4000)


class EventIn(BaseModel):
    type: str
    source: Literal["webhook", "email", "whatsapp", "cron", "manual"] = "manual"
    text: str | None = Field(default=None, max_length=20000)
    payload: dict[str, Any] = Field(default_factory=dict)


class RunOut(BaseModel):
    run_id: uuid.UUID
    thread_id: str
    status: str
    intent: str | None = None
    output: str | None = None
    error: str | None = None
    pending: list[dict[str, Any]] = Field(default_factory=list)
    actions: list[dict[str, Any]] = Field(default_factory=list)


class ApprovalOut(BaseModel):
    id: uuid.UUID
    tool: str
    status: str
    reason: str
    policy_rule: str | None
    args: dict[str, Any]
    provenance: dict[str, Literal["trusted", "untrusted"]]
    preview: dict[str, Any]
    required_role: str
    requires_stepup: bool
    run_id: uuid.UUID | None
    created_at: datetime
    expires_at: datetime
    wait_seconds: int


class DecisionIn(BaseModel):
    decision: Literal["approve", "edit", "reject", "respond"]
    note: str | None = Field(default=None, max_length=2000)
    edited_args: dict[str, Any] | None = None


class KillSwitchIn(BaseModel):
    scope: Literal["tenant", "tool"]
    target: str | None = None  # tool name for scope=tool
    enabled: bool
    reason: str = ""