Admin view in the web UI
This commit is contained in:
+27
-12
@@ -282,27 +282,38 @@ func (m *Manager) LiveCount() int {
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
Running int
|
||||
Queued int
|
||||
Running []api.TurnRef
|
||||
Queued []api.TurnRef
|
||||
Caps api.Caps
|
||||
RateLimits map[string]map[string]any
|
||||
}
|
||||
|
||||
func (m *Manager) Usage(ctx context.Context) (Usage, error) {
|
||||
u := Usage{RateLimits: map[string]map[string]any{}}
|
||||
u := Usage{
|
||||
Running: []api.TurnRef{},
|
||||
Queued: []api.TurnRef{},
|
||||
Caps: api.Caps{Global: m.limits.Global, PerVendor: map[string]int{}},
|
||||
RateLimits: map[string]map[string]any{},
|
||||
}
|
||||
for vendor, n := range m.limits.PerVendor {
|
||||
u.Caps.PerVendor[string(vendor)] = n
|
||||
}
|
||||
|
||||
counts, err := m.store.CountRunning(ctx)
|
||||
running, err := m.store.SessionsInState(ctx, api.AgentSessionStateRunning)
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
for _, n := range counts {
|
||||
u.Running += n
|
||||
for _, sess := range running {
|
||||
u.Running = append(u.Running, api.TurnRef{SessionId: sess.Id, TaskId: sess.TaskId, Vendor: string(sess.Vendor)})
|
||||
}
|
||||
|
||||
queued, err := m.store.QueuedTurns(ctx)
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
u.Queued = len(queued)
|
||||
for _, q := range queued {
|
||||
u.Queued = append(u.Queued, api.TurnRef{SessionId: q.SessionID, TaskId: q.TaskID, Vendor: string(q.Vendor)})
|
||||
}
|
||||
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
@@ -325,11 +336,6 @@ func (m *Manager) turn(ctx context.Context, sess api.AgentSession, task api.Task
|
||||
return m.start(ctx, sess, task, actor, text, images, api.AgentSessionStateIdle)
|
||||
}
|
||||
|
||||
err = transition(ctx, m.store, sess.Id, api.AgentSessionStateIdle, api.AgentSessionStateQueued, actor)
|
||||
if err != nil {
|
||||
return api.AgentSession{}, err
|
||||
}
|
||||
|
||||
err = m.store.EnqueueTurn(ctx, store.QueuedTurn{
|
||||
SessionID: sess.Id,
|
||||
Vendor: sess.Vendor,
|
||||
@@ -342,6 +348,15 @@ func (m *Manager) turn(ctx context.Context, sess api.AgentSession, task api.Task
|
||||
return api.AgentSession{}, err
|
||||
}
|
||||
|
||||
err = transition(ctx, m.store, sess.Id, api.AgentSessionStateIdle, api.AgentSessionStateQueued, actor)
|
||||
if err != nil {
|
||||
derr := m.store.DeleteQueuedTurn(ctx, sess.Id)
|
||||
if derr != nil {
|
||||
slog.Error("remove queued turn", "session", sess.Id, "err", derr)
|
||||
}
|
||||
return api.AgentSession{}, err
|
||||
}
|
||||
|
||||
return m.store.GetSession(ctx, sess.Id)
|
||||
}
|
||||
|
||||
|
||||
@@ -753,7 +753,7 @@ func TestConcurrencyQueue(t *testing.T) {
|
||||
}
|
||||
|
||||
usage, err := m.Usage(e.ctx)
|
||||
if err != nil || usage.Running != 1 || usage.Queued != 1 {
|
||||
if err != nil || len(usage.Running) != 1 || len(usage.Queued) != 1 || usage.Queued[0].TaskId != second.TaskId {
|
||||
t.Fatalf("usage %+v %v", usage, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user