@@ -67,6 +67,21 @@ func extractResetTime(raw any) string {
6767 return ""
6868}
6969
70+ func formatCodingPlanReset (tierName , raw string ) string {
71+ resetAt , ok := parseRFC3339ResetTime (raw )
72+ if ! ok {
73+ return ""
74+ }
75+ switch strings .ToLower (strings .TrimSpace (tierName )) {
76+ case tierFiveHour :
77+ return formatResetDuration (resetAt .Sub (usageTextNow ()))
78+ case tierWeeklyLimit :
79+ return resetAt .Format ("01-02" )
80+ default :
81+ return ""
82+ }
83+ }
84+
7085func parseZhipuTokenTiers (data map [string ]any ) []Tier {
7186 type row struct {
7287 resetMS * int64
@@ -116,7 +131,7 @@ func parseZhipuTokenTiers(data map[string]any) []Tier {
116131 if rows [j ].resetMS != nil {
117132 rightVal = * rows [j ].resetMS
118133 }
119- if (! leftHas && rightHas ) || (leftHas && rightHas && leftVal > rightVal ) {
134+ if (leftHas && ! rightHas ) || (leftHas && rightHas && leftVal > rightVal ) {
120135 rows [i ], rows [j ] = rows [j ], rows [i ]
121136 }
122137 }
@@ -196,7 +211,7 @@ func queryKimiCodingPlan(apiKey string) Result {
196211 })
197212 }
198213 }
199- return Result { Success : true , Kind : "token_plan" , Tiers : tiers }
214+ return resultWithCodingPlanTiers ( tiers )
200215}
201216
202217func queryZhipuCodingPlan (apiKey string ) Result {
@@ -229,7 +244,7 @@ func queryZhipuCodingPlan(apiKey string) Result {
229244 if data == nil {
230245 return Result {Success : false , Kind : "token_plan" , Error : "Missing 'data' field in response" }
231246 }
232- return Result { Success : true , Kind : "token_plan" , Tiers : parseZhipuTokenTiers (data )}
247+ return resultWithCodingPlanTiers ( parseZhipuTokenTiers (data ))
233248}
234249
235250func queryMiniMaxCodingPlan (apiKey string , cn bool ) Result {
@@ -297,7 +312,7 @@ func queryMiniMaxCodingPlan(apiKey string, cn bool) Result {
297312 }
298313 }
299314 }
300- return Result { Success : true , Kind : "token_plan" , Tiers : tiers }
315+ return resultWithCodingPlanTiers ( tiers )
301316}
302317
303318// QueryCodingPlan queries token-plan utilization for Kimi / Zhipu / MiniMax coding endpoints.
@@ -350,3 +365,30 @@ func TiersToUsageData(tiers []Tier) []Data {
350365 }
351366 return out
352367}
368+
369+ func formatCodingPlanUsageText (tiers []Tier ) string {
370+ parts := make ([]string , 0 , len (tiers ))
371+ for _ , tier := range tiers {
372+ name := TierDisplayName (tier .Name )
373+ if name == "" {
374+ name = strings .TrimSpace (tier .Name )
375+ }
376+ if name == "" {
377+ continue
378+ }
379+ body := name + " " + formatNumber (tier .Utilization ) + "%"
380+ if reset := formatCodingPlanReset (tier .Name , tier .ResetsAt ); reset != "" {
381+ body += "(" + reset + ")"
382+ }
383+ parts = append (parts , body )
384+ }
385+ return strings .Join (parts , " · " )
386+ }
387+
388+ func resultWithCodingPlanTiers (tiers []Tier ) Result {
389+ res := Result {Success : true , Kind : "token_plan" , Text : formatCodingPlanUsageText (tiers ), Tiers : tiers }
390+ if len (tiers ) > 0 {
391+ res .Data = TiersToUsageData (tiers )
392+ }
393+ return res
394+ }
0 commit comments