-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.py
More file actions
177 lines (120 loc) · 4.28 KB
/
Copy pathtypes.py
File metadata and controls
177 lines (120 loc) · 4.28 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"""Type definitions for the Hawk SDK, mirroring the Go SDK types."""
from __future__ import annotations
from datetime import datetime # noqa: TC003
from enum import Enum
from typing import Any, Generic, TypeVar
from pydantic import BaseModel, Field
class ChatRequest(BaseModel):
"""Request body for POST /v1/chat."""
prompt: str
session_id: str | None = Field(
None,
alias="session_id",
max_length=128,
pattern=r"^[A-Za-z0-9._-]+$",
)
model: str | None = None
max_turns: int | None = Field(None, alias="max_turns")
autonomy: str | None = None
cwd: str | None = None
agent: str | None = None
tools: list[dict[str, Any]] | None = None
tool_results: list[ToolResult] | None = Field(None, alias="tool_results")
tool_choice: str | None = None
parallel_tool_calls: bool | None = None
model_config = {"populate_by_name": True}
class ChatResponse(BaseModel):
"""Response from POST /v1/chat."""
session_id: str = Field(alias="session_id")
response: str
tokens_in: int = Field(alias="tokens_in")
tokens_out: int = Field(alias="tokens_out")
turns_taken: int = Field(alias="turns_taken")
duration: str
tool_calls: list[dict[str, Any]] | None = Field(None, alias="tool_calls")
model_config = {"populate_by_name": True}
class HealthResponse(BaseModel):
"""Response from GET /v1/health."""
status: str
version: str
uptime: str
active_sessions: int = Field(alias="active_sessions")
started_at: str = Field(alias="started_at")
model_config = {"populate_by_name": True}
class SessionSummary(BaseModel):
"""A session entry in the list response."""
id: str
created_at: datetime = Field(alias="created_at")
last_used: datetime = Field(alias="last_used")
turns: int
cwd: str
model_config = {"populate_by_name": True}
class SessionDetail(BaseModel):
"""Full session detail from GET /v1/sessions/{id}."""
id: str
created_at: datetime = Field(alias="created_at")
updated_at: datetime = Field(alias="updated_at")
model: str
provider: str
cwd: str
name: str
message_count: int = Field(alias="message_count")
tool_calls: int = Field(alias="tool_calls")
model_config = {"populate_by_name": True}
class Message(BaseModel):
"""A conversation message."""
role: str
content: str | None = None
tool_use: list[ToolCall] | None = Field(None, alias="tool_use")
tool_result: list[ToolResult] | None = Field(None, alias="tool_results")
model_config = {"populate_by_name": True}
class ToolCall(BaseModel):
"""A tool call within a message."""
id: str
name: str
arguments: dict[str, Any] = Field(default_factory=dict)
class ToolResult(BaseModel):
"""Result of executing a tool call."""
tool_use_id: str = Field(alias="tool_use_id")
content: str
is_error: bool = Field(False, alias="is_error")
model_config = {"populate_by_name": True}
class Usage(BaseModel):
"""Token usage information."""
prompt_tokens: int = 0
completion_tokens: int = 0
total_tokens: int = 0
class ModelStat(BaseModel):
"""Per-model usage in StatsResponse."""
model: str
requests: int
cost_usd: float = Field(alias="cost_usd")
model_config = {"populate_by_name": True}
class StatsResponse(BaseModel):
"""Response from GET /v1/stats."""
total_sessions: int = Field(alias="total_sessions")
total_messages: int = Field(alias="total_messages")
total_tool_calls: int = Field(alias="total_tool_calls")
total_cost_usd: float = Field(alias="total_cost_usd")
active_days: int = Field(alias="active_days")
models: list[ModelStat] = Field(default_factory=list)
model_config = {"populate_by_name": True}
T = TypeVar("T")
class PaginatedResponse(BaseModel, Generic[T]):
"""Wraps paginated list results."""
data: list[T]
total: int
offset: int
limit: int
has_more: bool = Field(alias="has_more")
model_config = {"populate_by_name": True}
class StreamEventType(str, Enum):
"""Types of streaming events."""
CONTENT = "content"
TOOL_CALL = "tool_call"
COMPLETION = "done"
ERROR = "error"
class StreamEvent(BaseModel):
"""A single SSE event from the chat stream."""
event: str | None = None
data: str = ""