no gemini
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package antigravity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UsageBucket struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Window string `json:"window"`
|
||||
RemainingFraction float64 `json:"remaining_fraction"`
|
||||
ResetTime time.Time `json:"reset_time"`
|
||||
}
|
||||
|
||||
type UsageGroup struct {
|
||||
Name string `json:"name"`
|
||||
Buckets []UsageBucket `json:"buckets"`
|
||||
}
|
||||
|
||||
func ReadUsage(ctx context.Context) ([]UsageGroup, error) {
|
||||
out, err := exec.CommandContext(ctx, "agy", "--output-format", "json", "--print", "/usage").Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("agy /usage: %w", err)
|
||||
}
|
||||
resp := struct {
|
||||
Command struct {
|
||||
Data struct {
|
||||
Groups []UsageGroup `json:"groups"`
|
||||
} `json:"data"`
|
||||
} `json:"command"`
|
||||
}{}
|
||||
err = json.Unmarshal(out, &resp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("agy /usage: %w", err)
|
||||
}
|
||||
return resp.Command.Data.Groups, nil
|
||||
}
|
||||
Reference in New Issue
Block a user