mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-06-12 08:11:04 +00:00
6895e369f6
- Remove standalone mode code: file-based stores, standalone gateway, heartbeat service, SQLite memory, standalone docker-compose - Rename docker-compose.managed.yml → docker-compose.postgres.yml - Clean up ~130 Go comments referencing "managed mode" qualifier - Simplify docker-compose.yml env vars (providers/channels via web UI) - Update .env.example to essential vars only (token + encryption key) - Add setup wizard UI (provider → agent → channel bootstrap flow) - Add logs.tail WebSocket handler for live log streaming - Add cursor-pointer to interactive UI components - Clean up config page (remove standalone-only sections) - Update README and docs for managed-only architecture
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package methods
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/nextlevelbuilder/goclaw/internal/channels"
|
|
"github.com/nextlevelbuilder/goclaw/internal/gateway"
|
|
"github.com/nextlevelbuilder/goclaw/pkg/protocol"
|
|
)
|
|
|
|
// QuotaMethods handles quota.usage — returns per-user quota consumption for the dashboard.
|
|
// Nil-safe: returns {enabled: false} when quotaChecker is nil (quota not configured).
|
|
// When checker is nil but db is available, still queries today's summary from traces.
|
|
type QuotaMethods struct {
|
|
checker *channels.QuotaChecker
|
|
db *sql.DB
|
|
}
|
|
|
|
func NewQuotaMethods(checker *channels.QuotaChecker, db *sql.DB) *QuotaMethods {
|
|
return &QuotaMethods{checker: checker, db: db}
|
|
}
|
|
|
|
func (m *QuotaMethods) Register(router *gateway.MethodRouter) {
|
|
router.Register(protocol.MethodQuotaUsage, m.handleUsage)
|
|
}
|
|
|
|
func (m *QuotaMethods) handleUsage(ctx context.Context, client *gateway.Client, req *protocol.RequestFrame) {
|
|
if m.checker == nil {
|
|
result := channels.QuotaUsageResult{
|
|
Enabled: false,
|
|
Entries: []channels.QuotaUsageEntry{},
|
|
}
|
|
// Still query today's summary from traces when DB is available
|
|
if m.db != nil {
|
|
channels.QueryTodaySummary(ctx, m.db, &result)
|
|
}
|
|
client.SendResponse(protocol.NewOKResponse(req.ID, result))
|
|
return
|
|
}
|
|
|
|
result := m.checker.Usage(ctx)
|
|
client.SendResponse(protocol.NewOKResponse(req.ID, result))
|
|
}
|