summaryrefslogtreecommitdiff
path: root/internal/controlplane/types.go
blob: 7dfb7346656d5469d71ec4b265bb7a13b1754181 (plain)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package controlplane

import (
	"time"

	"aigw/internal/auth"
	"aigw/internal/domain"
)

type Tenant struct {
	ID        string    `json:"id"`
	Slug      string    `json:"slug"`
	Name      string    `json:"name"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
}

type Project struct {
	ID        string    `json:"id"`
	TenantID  string    `json:"tenant_id"`
	Slug      string    `json:"slug"`
	Name      string    `json:"name"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
}

type APIKey struct {
	ID        string    `json:"id"`
	TenantID  string    `json:"tenant_id"`
	ProjectID string    `json:"project_id"`
	Name      string    `json:"name"`
	KeyPrefix string    `json:"key_prefix"`
	Scopes    []string  `json:"scopes"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
}

type CreatedAPIKey struct {
	APIKey
	Key string `json:"key"`
}

type Provider struct {
	ID         string    `json:"id"`
	Name       string    `json:"name"`
	Protocol   string    `json:"protocol"`
	BaseURL    string    `json:"base_url"`
	Enabled    bool      `json:"enabled"`
	RouteCount int       `json:"route_count"`
	CreatedAt  time.Time `json:"created_at"`
}

type Route struct {
	ID            string `json:"id"`
	ProviderID    string `json:"provider_id"`
	ProviderName  string `json:"provider_name"`
	Protocol      string `json:"protocol"`
	UpstreamModel string `json:"upstream_model"`
	Priority      int    `json:"priority"`
	Weight        int    `json:"weight"`
	Enabled       bool   `json:"enabled"`
}

type Model struct {
	ID                              string    `json:"id"`
	PublicID                        string    `json:"public_id"`
	OwnedBy                         string    `json:"owned_by"`
	InputPriceMicrosPerMillion      int64     `json:"input_price_micros_per_million"`
	OutputPriceMicrosPerMillion     int64     `json:"output_price_micros_per_million"`
	CacheReadPriceMicrosPerMillion  int64     `json:"cache_read_price_micros_per_million"`
	CacheWritePriceMicrosPerMillion int64     `json:"cache_write_price_micros_per_million"`
	Enabled                         bool      `json:"enabled"`
	Routes                          []Route   `json:"routes"`
	CreatedAt                       time.Time `json:"created_at"`
}

type Overview struct {
	Generation        int64  `json:"generation"`
	RuntimeGeneration int64  `json:"runtime_generation"`
	RedisConfigured   bool   `json:"redis_configured"`
	RedisConnected    bool   `json:"redis_connected"`
	Tenants           int64  `json:"tenants"`
	Projects          int64  `json:"projects"`
	APIKeys           int64  `json:"api_keys"`
	Providers         int64  `json:"providers"`
	Models            int64  `json:"models"`
	BillingEnabled    bool   `json:"billing_enabled"`
	StripeEnabled     bool   `json:"stripe_enabled"`
	BillingCurrency   string `json:"billing_currency,omitempty"`
}

type Snapshot struct {
	Generation int64
	Models     []domain.Model
	APIKeys    []auth.HashedKeyRecord
	Limits     []domain.LimitPolicy
}

type ChangeEvent struct {
	Generation int64  `json:"generation"`
	Resource   string `json:"resource"`
	ID         string `json:"id,omitempty"`
	ChangedAt  string `json:"changed_at"`
}

type ChangeMessage struct {
	Payload string
}

type CreateTenantInput struct {
	Slug string `json:"slug"`
	Name string `json:"name"`
}

type CreateProjectInput struct {
	TenantID string `json:"tenant_id"`
	Slug     string `json:"slug"`
	Name     string `json:"name"`
}

type CreateAPIKeyInput struct {
	TenantID  string   `json:"tenant_id"`
	ProjectID string   `json:"project_id"`
	Name      string   `json:"name"`
	Scopes    []string `json:"scopes"`
}

type CreateProviderInput struct {
	Name     string `json:"name"`
	Protocol string `json:"protocol"`
	BaseURL  string `json:"base_url"`
	APIKey   string `json:"api_key"`
}

type RouteInput struct {
	ProviderID    string `json:"provider_id"`
	UpstreamModel string `json:"upstream_model"`
	Priority      int    `json:"priority"`
	Weight        int    `json:"weight"`
}

type CreateModelInput struct {
	PublicID                        string       `json:"public_id"`
	OwnedBy                         string       `json:"owned_by"`
	InputPriceMicrosPerMillion      int64        `json:"input_price_micros_per_million"`
	OutputPriceMicrosPerMillion     int64        `json:"output_price_micros_per_million"`
	CacheReadPriceMicrosPerMillion  int64        `json:"cache_read_price_micros_per_million"`
	CacheWritePriceMicrosPerMillion int64        `json:"cache_write_price_micros_per_million"`
	Routes                          []RouteInput `json:"routes"`
}

type ConsoleActor struct {
	ID          string `json:"id,omitempty"`
	TenantID    string `json:"tenant_id,omitempty"`
	Email       string `json:"email"`
	DisplayName string `json:"display_name"`
	Role        string `json:"role"`
	Bootstrap   bool   `json:"bootstrap"`
}

type ConsoleUser struct {
	ID          string     `json:"id"`
	TenantID    string     `json:"tenant_id,omitempty"`
	Email       string     `json:"email"`
	DisplayName string     `json:"display_name"`
	Role        string     `json:"role"`
	TokenPrefix string     `json:"token_prefix"`
	Status      string     `json:"status"`
	LastUsedAt  *time.Time `json:"last_used_at,omitempty"`
	CreatedAt   time.Time  `json:"created_at"`
}

type CreatedConsoleUser struct {
	ConsoleUser
	Token string `json:"token"`
}

type CreateConsoleUserInput struct {
	TenantID    string `json:"tenant_id"`
	Email       string `json:"email"`
	DisplayName string `json:"display_name"`
	Role        string `json:"role"`
}

type ProjectLimit struct {
	domain.LimitPolicy
	ProjectName string    `json:"project_name"`
	TenantName  string    `json:"tenant_name"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type SetProjectLimitInput struct {
	RequestsPerMinute  int64 `json:"requests_per_minute"`
	TokensPerMinute    int64 `json:"tokens_per_minute"`
	ConcurrentRequests int64 `json:"concurrent_requests"`
	MonthlySpendMicros int64 `json:"monthly_spend_micros"`
}

type UsageRecord struct {
	RequestID                string    `json:"request_id"`
	TenantID                 string    `json:"tenant_id"`
	ProjectID                string    `json:"project_id"`
	KeyID                    string    `json:"key_id"`
	PublicModel              string    `json:"public_model"`
	ProviderID               string    `json:"provider_id,omitempty"`
	UpstreamModel            string    `json:"upstream_model,omitempty"`
	Protocol                 string    `json:"protocol"`
	Stream                   bool      `json:"stream"`
	StatusCode               int       `json:"status_code"`
	Success                  bool      `json:"success"`
	ErrorType                string    `json:"error_type,omitempty"`
	Attempts                 int       `json:"attempts"`
	StartedAt                time.Time `json:"started_at"`
	DurationMS               int64     `json:"duration_ms"`
	InputTokens              int64     `json:"input_tokens"`
	OutputTokens             int64     `json:"output_tokens"`
	TotalTokens              int64     `json:"total_tokens"`
	CacheCreationInputTokens int64     `json:"cache_creation_input_tokens"`
	CacheReadInputTokens     int64     `json:"cache_read_input_tokens"`
	CostMicros               int64     `json:"cost_micros"`
	ChargedMicros            int64     `json:"charged_micros"`
	UncollectedMicros        int64     `json:"uncollected_micros"`
}

type UsageSummary struct {
	PeriodStart        time.Time `json:"period_start"`
	TenantID           string    `json:"tenant_id"`
	ProjectID          string    `json:"project_id"`
	ProjectName        string    `json:"project_name"`
	RequestCount       int64     `json:"request_count"`
	SuccessfulRequests int64     `json:"successful_requests"`
	InputTokens        int64     `json:"input_tokens"`
	OutputTokens       int64     `json:"output_tokens"`
	TotalTokens        int64     `json:"total_tokens"`
	CostMicros         int64     `json:"cost_micros"`
	ChargedMicros      int64     `json:"charged_micros"`
	UncollectedMicros  int64     `json:"uncollected_micros"`
}

type AuditLog struct {
	ID         int64     `json:"id"`
	ActorID    string    `json:"actor_id,omitempty"`
	ActorType  string    `json:"actor_type"`
	ActorRole  string    `json:"actor_role"`
	TenantID   string    `json:"tenant_id,omitempty"`
	RequestID  string    `json:"request_id"`
	Method     string    `json:"method"`
	Path       string    `json:"path"`
	Action     string    `json:"action"`
	StatusCode int       `json:"status_code"`
	RemoteIP   string    `json:"remote_ip,omitempty"`
	UserAgent  string    `json:"user_agent,omitempty"`
	CreatedAt  time.Time `json:"created_at"`
}

type AuditInput struct {
	Actor      ConsoleActor
	RequestID  string
	Method     string
	Path       string
	Action     string
	StatusCode int
	RemoteIP   string
	UserAgent  string
}