-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_codex_live_sessions.go
More file actions
373 lines (348 loc) · 15.3 KB
/
app_codex_live_sessions.go
File metadata and controls
373 lines (348 loc) · 15.3 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
package main
import wailsapp "github.com/linhay/gettokens/internal/wailsapp"
type CodexLiveSessionsSnapshot struct {
GeneratedAt string `json:"generatedAt"`
SidecarReady bool `json:"sidecarReady"`
Source string `json:"source"`
Retention string `json:"retentionLabel"`
Summary CodexLiveSessionSummary `json:"summary"`
Sessions []CodexLiveSession `json:"sessions"`
}
type CodexLiveSessionSummary struct {
ActiveSessions int `json:"activeSessions"`
ActiveRequests int `json:"activeRequests"`
WebsocketSessions int `json:"websocketSessions"`
HTTPSessions int `json:"httpSessions"`
DegradedSessions int `json:"degradedSessions"`
ErrorSessions int `json:"errorSessions"`
}
type CodexLiveSessionHistoryInput struct {
SessionID string `json:"sessionID"`
Window string `json:"window,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
type CodexLiveSessionHistoryResponse struct {
Window string `json:"window"`
GeneratedAt string `json:"generatedAt"`
Limit int `json:"limit"`
Offset int `json:"offset"`
Items []CodexLiveRequest `json:"items"`
}
type CodexLiveSession struct {
SessionID string `json:"sessionID"`
ProjectName string `json:"projectName,omitempty"`
ExecutionSessionID string `json:"executionSessionID,omitempty"`
DownstreamSessionID string `json:"downstreamSessionID,omitempty"`
CodexWindowID string `json:"codexWindowID,omitempty"`
Status string `json:"status"`
StartedAt string `json:"startedAt"`
LastEventAt string `json:"lastEventAt"`
DurationMs int64 `json:"durationMs"`
RequestCount int `json:"requestCount"`
ActiveRequestID string `json:"activeRequestID,omitempty"`
LastRequestID string `json:"lastRequestID,omitempty"`
Model string `json:"model"`
AuthID string `json:"authID,omitempty"`
AccountKey string `json:"accountKey,omitempty"`
AuthLabel string `json:"authLabel,omitempty"`
AccountPresent bool `json:"accountPresent"`
AccountCoarseAvailable bool `json:"accountCoarseAvailable"`
AccountFilteredReasons []string `json:"accountFilteredReasons,omitempty"`
Provider string `json:"provider,omitempty"`
DownstreamTransport string `json:"downstreamTransport"`
UpstreamTransport string `json:"upstreamTransport"`
FallbackInferred bool `json:"fallbackInferred,omitempty"`
FallbackConfidence string `json:"fallbackConfidence,omitempty"`
FallbackReason string `json:"fallbackReason,omitempty"`
TimingSummary *CodexLiveTimingSummary `json:"timingSummary,omitempty"`
RecentEvents []CodexLiveTimelineEvent `json:"recentEvents"`
Requests []CodexLiveRequest `json:"requests"`
}
type CodexLiveRequest struct {
RequestID string `json:"requestID"`
ClientRequestID string `json:"clientRequestID,omitempty"`
UpstreamRequestID string `json:"upstreamRequestID,omitempty"`
SessionID string `json:"sessionID"`
Sequence int `json:"sequence"`
Model string `json:"model"`
Status string `json:"status"`
StartedAt string `json:"startedAt"`
CompletedAt string `json:"completedAt,omitempty"`
DownstreamTransport string `json:"downstreamTransport"`
UpstreamTransport string `json:"upstreamTransport"`
ConnectionReused bool `json:"connectionReused,omitempty"`
AuthID string `json:"authID,omitempty"`
AccountKey string `json:"accountKey,omitempty"`
AuthLabel string `json:"authLabel,omitempty"`
AccountPresent bool `json:"accountPresent"`
AccountCoarseAvailable bool `json:"accountCoarseAvailable"`
AccountFilteredReasons []string `json:"accountFilteredReasons,omitempty"`
Provider string `json:"provider,omitempty"`
ProxyRoute string `json:"proxyRoute,omitempty"`
Usage *CodexLiveTokenUsage `json:"usage,omitempty"`
Timing CodexLiveTimingMetrics `json:"timing,omitempty"`
Error *CodexLiveErrorSummary `json:"error,omitempty"`
Timeline []CodexLiveTimelineEvent `json:"timeline"`
}
type CodexLiveTokenUsage struct {
InputTokens int64 `json:"inputTokens"`
CachedInputTokens int64 `json:"cachedInputTokens"`
OutputTokens int64 `json:"outputTokens"`
TotalTokens int64 `json:"totalTokens"`
}
type CodexLiveTimingMetrics struct {
QueueWaitMs int64 `json:"queueWaitMs,omitempty"`
AuthSelectMs int64 `json:"authSelectMs,omitempty"`
UpstreamConnectMs int64 `json:"upstreamConnectMs,omitempty"`
FirstEventMs int64 `json:"firstEventMs,omitempty"`
FirstTokenMs int64 `json:"firstTokenMs,omitempty"`
AverageEventGapMs int64 `json:"averageEventGapMs,omitempty"`
LongestEventGapMs int64 `json:"longestEventGapMs,omitempty"`
StreamDurationMs int64 `json:"streamDurationMs,omitempty"`
TotalDurationMs int64 `json:"totalDurationMs,omitempty"`
ReconnectCount int `json:"reconnectCount,omitempty"`
OutputTokensPerSecond float64 `json:"outputTokensPerSecond,omitempty"`
TotalTokensPerSecond float64 `json:"totalTokensPerSecond,omitempty"`
}
type CodexLiveTimingSummary struct {
Window string `json:"window"`
SampleCount int `json:"sampleCount"`
SequenceFrom int `json:"sequenceFrom,omitempty"`
SequenceTo int `json:"sequenceTo,omitempty"`
ActiveIncluded bool `json:"activeIncluded,omitempty"`
GeneratedAt string `json:"generatedAt"`
Averages CodexLiveTimingSummaryAverages `json:"averages"`
}
type CodexLiveTimingSummaryAverages struct {
QueueWaitMs *int64 `json:"queueWaitMs,omitempty"`
AuthSelectMs *int64 `json:"authSelectMs,omitempty"`
UpstreamConnectMs *int64 `json:"upstreamConnectMs,omitempty"`
FirstEventMs *int64 `json:"firstEventMs,omitempty"`
FirstTokenMs *int64 `json:"firstTokenMs,omitempty"`
AverageEventGapMs *int64 `json:"averageEventGapMs,omitempty"`
LongestEventGapMs *int64 `json:"longestEventGapMs,omitempty"`
StreamDurationMs *int64 `json:"streamDurationMs,omitempty"`
TotalDurationMs *int64 `json:"totalDurationMs,omitempty"`
ReconnectCount *int `json:"reconnectCount,omitempty"`
OutputTokensPerSecond *float64 `json:"outputTokensPerSecond,omitempty"`
TotalTokensPerSecond *float64 `json:"totalTokensPerSecond,omitempty"`
}
type CodexLiveErrorSummary struct {
StatusCode int `json:"statusCode,omitempty"`
Code string `json:"code,omitempty"`
Message string `json:"message"`
Retryable bool `json:"retryable,omitempty"`
}
type CodexLiveTimelineEvent struct {
ID string `json:"id"`
At string `json:"at"`
Lane string `json:"lane"`
Kind string `json:"kind"`
Label string `json:"label"`
Severity string `json:"severity"`
Detail string `json:"detail,omitempty"`
}
func (a *App) GetCodexLiveSessionsSnapshot() (*CodexLiveSessionsSnapshot, error) {
result, err := a.core.GetCodexLiveSessionsSnapshot()
if err != nil {
return nil, err
}
return mapCodexLiveSessionsSnapshot(result), nil
}
func (a *App) ClearCodexLiveSessions() error {
return a.core.ClearCodexLiveSessions()
}
func (a *App) GetCodexLiveSessionHistory(input CodexLiveSessionHistoryInput) (*CodexLiveSessionHistoryResponse, error) {
result, err := a.core.GetCodexLiveSessionHistory(wailsapp.CodexLiveSessionHistoryInput{
SessionID: input.SessionID,
Window: input.Window,
Limit: input.Limit,
Offset: input.Offset,
})
if err != nil {
return nil, err
}
return mapCodexLiveSessionHistoryResponse(result), nil
}
func mapCodexLiveSessionsSnapshot(result *wailsapp.CodexLiveSessionsSnapshot) *CodexLiveSessionsSnapshot {
if result == nil {
return &CodexLiveSessionsSnapshot{Sessions: []CodexLiveSession{}}
}
return &CodexLiveSessionsSnapshot{
GeneratedAt: result.GeneratedAt,
SidecarReady: result.SidecarReady,
Source: result.Source,
Retention: result.Retention,
Summary: CodexLiveSessionSummary{
ActiveSessions: result.Summary.ActiveSessions,
ActiveRequests: result.Summary.ActiveRequests,
WebsocketSessions: result.Summary.WebsocketSessions,
HTTPSessions: result.Summary.HTTPSessions,
DegradedSessions: result.Summary.DegradedSessions,
ErrorSessions: result.Summary.ErrorSessions,
},
Sessions: mapCodexLiveSessions(result.Sessions),
}
}
func mapCodexLiveSessions(items []wailsapp.CodexLiveSession) []CodexLiveSession {
if len(items) == 0 {
return []CodexLiveSession{}
}
out := make([]CodexLiveSession, 0, len(items))
for _, item := range items {
out = append(out, CodexLiveSession{
SessionID: item.SessionID,
ProjectName: item.ProjectName,
ExecutionSessionID: item.ExecutionSessionID,
DownstreamSessionID: item.DownstreamSessionID,
CodexWindowID: item.CodexWindowID,
Status: item.Status,
StartedAt: item.StartedAt,
LastEventAt: item.LastEventAt,
DurationMs: item.DurationMs,
RequestCount: item.RequestCount,
ActiveRequestID: item.ActiveRequestID,
LastRequestID: item.LastRequestID,
Model: item.Model,
AuthID: item.AuthID,
AuthLabel: item.AuthLabel,
Provider: item.Provider,
DownstreamTransport: item.DownstreamTransport,
UpstreamTransport: item.UpstreamTransport,
FallbackInferred: item.FallbackInferred,
FallbackConfidence: item.FallbackConfidence,
FallbackReason: item.FallbackReason,
TimingSummary: mapCodexLiveTimingSummary(item.TimingSummary),
RecentEvents: mapCodexLiveTimelineEvents(item.RecentEvents),
Requests: mapCodexLiveRequests(item.Requests),
})
}
return out
}
func mapCodexLiveSessionHistoryResponse(result *wailsapp.CodexLiveSessionHistoryResponse) *CodexLiveSessionHistoryResponse {
if result == nil {
return &CodexLiveSessionHistoryResponse{Items: []CodexLiveRequest{}}
}
return &CodexLiveSessionHistoryResponse{
Window: result.Window,
GeneratedAt: result.GeneratedAt,
Limit: result.Limit,
Offset: result.Offset,
Items: mapCodexLiveRequests(result.Items),
}
}
func mapCodexLiveRequests(items []wailsapp.CodexLiveRequest) []CodexLiveRequest {
if len(items) == 0 {
return []CodexLiveRequest{}
}
out := make([]CodexLiveRequest, 0, len(items))
for _, item := range items {
out = append(out, CodexLiveRequest{
RequestID: item.RequestID,
ClientRequestID: item.ClientRequestID,
UpstreamRequestID: item.UpstreamRequestID,
SessionID: item.SessionID,
Sequence: item.Sequence,
Model: item.Model,
Status: item.Status,
StartedAt: item.StartedAt,
CompletedAt: item.CompletedAt,
DownstreamTransport: item.DownstreamTransport,
UpstreamTransport: item.UpstreamTransport,
ConnectionReused: item.ConnectionReused,
AuthID: item.AuthID,
AuthLabel: item.AuthLabel,
Provider: item.Provider,
ProxyRoute: item.ProxyRoute,
Usage: mapCodexLiveTokenUsage(item.Usage),
Timing: mapCodexLiveTiming(item.Timing),
Error: mapCodexLiveError(item.Error),
Timeline: mapCodexLiveTimelineEvents(item.Timeline),
})
}
return out
}
func mapCodexLiveTokenUsage(item *wailsapp.CodexLiveTokenUsage) *CodexLiveTokenUsage {
if item == nil {
return nil
}
return &CodexLiveTokenUsage{
InputTokens: item.InputTokens,
CachedInputTokens: item.CachedInputTokens,
OutputTokens: item.OutputTokens,
TotalTokens: item.TotalTokens,
}
}
func mapCodexLiveTiming(item wailsapp.CodexLiveTimingMetrics) CodexLiveTimingMetrics {
return CodexLiveTimingMetrics{
QueueWaitMs: item.QueueWaitMs,
AuthSelectMs: item.AuthSelectMs,
UpstreamConnectMs: item.UpstreamConnectMs,
FirstEventMs: item.FirstEventMs,
FirstTokenMs: item.FirstTokenMs,
AverageEventGapMs: item.AverageEventGapMs,
LongestEventGapMs: item.LongestEventGapMs,
StreamDurationMs: item.StreamDurationMs,
TotalDurationMs: item.TotalDurationMs,
ReconnectCount: item.ReconnectCount,
OutputTokensPerSecond: item.OutputTokensPerSecond,
TotalTokensPerSecond: item.TotalTokensPerSecond,
}
}
func mapCodexLiveTimingSummary(item *wailsapp.CodexLiveTimingSummary) *CodexLiveTimingSummary {
if item == nil {
return nil
}
return &CodexLiveTimingSummary{
Window: item.Window,
SampleCount: item.SampleCount,
SequenceFrom: item.SequenceFrom,
SequenceTo: item.SequenceTo,
ActiveIncluded: item.ActiveIncluded,
GeneratedAt: item.GeneratedAt,
Averages: CodexLiveTimingSummaryAverages{
QueueWaitMs: item.Averages.QueueWaitMs,
AuthSelectMs: item.Averages.AuthSelectMs,
UpstreamConnectMs: item.Averages.UpstreamConnectMs,
FirstEventMs: item.Averages.FirstEventMs,
FirstTokenMs: item.Averages.FirstTokenMs,
AverageEventGapMs: item.Averages.AverageEventGapMs,
LongestEventGapMs: item.Averages.LongestEventGapMs,
StreamDurationMs: item.Averages.StreamDurationMs,
TotalDurationMs: item.Averages.TotalDurationMs,
ReconnectCount: item.Averages.ReconnectCount,
OutputTokensPerSecond: item.Averages.OutputTokensPerSecond,
TotalTokensPerSecond: item.Averages.TotalTokensPerSecond,
},
}
}
func mapCodexLiveError(item *wailsapp.CodexLiveErrorSummary) *CodexLiveErrorSummary {
if item == nil {
return nil
}
return &CodexLiveErrorSummary{
StatusCode: item.StatusCode,
Code: item.Code,
Message: item.Message,
Retryable: item.Retryable,
}
}
func mapCodexLiveTimelineEvents(items []wailsapp.CodexLiveTimelineEvent) []CodexLiveTimelineEvent {
if len(items) == 0 {
return []CodexLiveTimelineEvent{}
}
out := make([]CodexLiveTimelineEvent, 0, len(items))
for _, item := range items {
out = append(out, CodexLiveTimelineEvent{
ID: item.ID,
At: item.At,
Lane: item.Lane,
Kind: item.Kind,
Label: item.Label,
Severity: item.Severity,
Detail: item.Detail,
})
}
return out
}