Usage export as CSV: by period and by place, person, key and model, from the rollups
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
15a7237a02
commit
57739d736a
11 files changed
+428
-2
No files matched your search
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
@@ -45,3 +47,25 @@ func auditDialog(e store.AuditEvent) (string, string) {
|
||||
b.WriteString("\n" + sDim.Render("any key"))
|
||||
return e.Action, b.String()
|
||||
}
|
||||
|
||||
// usageExportForm writes usage to a CSV file on this machine, as `llmgw ctl
|
||||
// usage export` does.
|
||||
func (m *consoleModel) usageExportForm() {
|
||||
now := time.Now().UTC()
|
||||
first := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
m.openForm(&formDialog{title: "Export usage as CSV",
|
||||
fields: []formField{
|
||||
textF("from", first.AddDate(0, -1, 0).Format("2006-01-02"), "first day"),
|
||||
textF("to", first.Format("2006-01-02"), "the day after the last"),
|
||||
textF("period", "day", "hour, day or month"),
|
||||
textF("by", "project,model", "org, team, project, user, key, model"),
|
||||
textF("file", "/tmp/llmgw-usage-"+first.AddDate(0, -1, 0).Format("2006-01")+".csv", "written on this machine"),
|
||||
},
|
||||
submit: func(m *consoleModel, v []string) (tea.Cmd, error) {
|
||||
if v[4] == "" {
|
||||
return nil, fmt.Errorf("a file to write")
|
||||
}
|
||||
return m.runCLI("Export usage", "ctl", "usage", "export", "--from", v[0], "--to", v[1],
|
||||
"--period", v[2], "--by", v[3], "--output", v[4]), nil
|
||||
}})
|
||||
}
|
||||
Reference in new issue
Block a user