Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions agent/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"mu/apps"
"mu/internal/ai"
"mu/internal/api"
"mu/internal/auth"
"mu/internal/event"
"mu/work"
)
Expand Down Expand Up @@ -471,14 +472,18 @@ func errText(text string, err error) string {
}

func spendCredit(post *work.Post, postID string) bool {
// Admin bypasses budget and credit checks
if acc, err := auth.GetAccount(post.AuthorID); err == nil && acc.Admin {
return true
}
if post.Cost > 0 && work.BudgetRemaining(postID) < creditPerCall {
work.AddLog(postID, "budget", "Budget exceeded", 0)
return false
}
if work.SpendCredits != nil {
err := work.SpendCredits(post.AuthorID, creditPerCall, "work_agent")
if err != nil {
work.AddLog(postID, "info", fmt.Sprintf("Credit deduction skipped: %v", err), 0)
if err := work.SpendCredits(post.AuthorID, creditPerCall, "work_agent"); err != nil {
work.AddLog(postID, "budget", "Insufficient credits", 0)
return false
}
}
return true
Expand Down
4 changes: 2 additions & 2 deletions work/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ func handlePost(w http.ResponseWriter, r *http.Request) {
kind = KindShow
}

// Validate budget
if kind == KindTask && cost > 0 && sess.Account != "micro" {
// Validate budget (skip for admin)
if kind == KindTask && cost > 0 && !acc.Admin {
wal := wallet.GetWallet(sess.Account)
if wal.Balance < cost {
respondError(w, r, "/work?kind=task", fmt.Sprintf("Insufficient credits (%d available, %d budget)", wal.Balance, cost))
Expand Down
Loading