diff --git a/changelog/unreleased/kiro-plan-credit-unit.md b/changelog/unreleased/kiro-plan-credit-unit.md new file mode 100644 index 00000000..4a2550fa --- /dev/null +++ b/changelog/unreleased/kiro-plan-credit-unit.md @@ -0,0 +1,7 @@ +### English + +- Kiro account cards now show the subscription tier (Free / Pro / Pro+ / Power) and label the credit meter as credits instead of `INVOCATIONS`. + +### 中文 + +- Kiro 账号卡片现在会显示会员类型(Free / Pro / Pro+ / Power),积分额度的单位也从 `INVOCATIONS` 改为显示为积分。 diff --git a/internal/providers/kiro/account.go b/internal/providers/kiro/account.go index 81baa798..e67088f9 100644 --- a/internal/providers/kiro/account.go +++ b/internal/providers/kiro/account.go @@ -365,7 +365,9 @@ func (c *Client) rememberIdentity(ctx context.Context, accountID string, cred Cr func quotaFromUsage(usage usageLimits, fetchedAt time.Time) *providers.QuotaInfo { breakdown := creditBreakdown(usage.UsageBreakdownList) unit := "credits" - if breakdown != nil { + // The CREDIT breakdown is metered in credits even though Kiro labels its + // unit INVOCATIONS; other resource types keep the unit Kiro states. + if breakdown != nil && !strings.EqualFold(breakdown.ResourceType, "CREDIT") { unit = firstNonEmpty(strings.TrimSpace(breakdown.Unit), strings.TrimSpace(breakdown.Currency), "credits") } info := &providers.QuotaInfo{ @@ -475,7 +477,7 @@ func subscriptionPlan(usage usageLimits) string { } raw := strings.ToUpper(firstNonEmpty(usage.SubscriptionInfo.SubscriptionTitle, usage.SubscriptionInfo.SubscriptionName, usage.SubscriptionInfo.SubscriptionType)) switch { - case strings.Contains(raw, "PRO_PLUS"), strings.Contains(raw, "PROPLUS"): + case strings.Contains(raw, "PRO_PLUS"), strings.Contains(raw, "PROPLUS"), strings.Contains(raw, "PRO+"): return "PRO_PLUS" case strings.Contains(raw, "POWER"): return "POWER" diff --git a/internal/providers/kiro/account_test.go b/internal/providers/kiro/account_test.go index 8dcbc88c..a3933430 100644 --- a/internal/providers/kiro/account_test.go +++ b/internal/providers/kiro/account_test.go @@ -291,6 +291,29 @@ func TestQuotaOverageExhaustedBlocksAccount(t *testing.T) { } } +// Kiro labels the CREDIT breakdown's unit INVOCATIONS; the card must still +// say credits, and the subscription tier must come through. +func TestQuotaCreditBreakdownIsCredits(t *testing.T) { + usage := usageLimits{ + SubscriptionInfo: &struct { + SubscriptionName string `json:"subscriptionName"` + SubscriptionTitle string `json:"subscriptionTitle"` + SubscriptionType string `json:"subscriptionType"` + OverageCapability string `json:"overageCapability"` + }{SubscriptionTitle: "KIRO PRO+"}, + UsageBreakdownList: []usageBreakdown{{ + ResourceType: "CREDIT", CurrentUsage: 552.37, UsageLimit: 907, Unit: "INVOCATIONS", + }}, + } + quota := quotaFromUsage(usage, time.Now().UTC()) + if quota.Unit != "credits" || len(quota.Windows) == 0 || quota.Windows[0].Unit != "credits" { + t.Fatalf("unit = %q windows = %+v", quota.Unit, quota.Windows) + } + if quota.Plan != "PRO_PLUS" { + t.Fatalf("plan = %q, want PRO_PLUS", quota.Plan) + } +} + func TestBuilderIDProfileIsRequestScoped(t *testing.T) { cred := Credential{AuthMethod: "builder_id", Region: "us-east-1", AccessToken: "access"} if cred.requestProfileArn() != builderIDProfileArn { diff --git a/internal/runtime/manager_quota.go b/internal/runtime/manager_quota.go index e5a62b88..0caf7d11 100644 --- a/internal/runtime/manager_quota.go +++ b/internal/runtime/manager_quota.go @@ -110,7 +110,8 @@ func quotaSnapshotFromInfo(info *providers.QuotaInfo) *QuotaSnapshot { quota.ExpiringRemain = info.ExpiringRemain quota.Packages = quotaPackagesFromInfo(info.Packages) } - if info.ProviderID == "codex" { + // Codex and Kiro report a subscription tier the account card shows. + if info.ProviderID == "codex" || info.ProviderID == "kiro" { quota.Plan = strings.TrimSpace(info.Plan) } return quota diff --git a/internal/runtime/providers_test.go b/internal/runtime/providers_test.go index facc89cb..aacdc8dd 100644 --- a/internal/runtime/providers_test.go +++ b/internal/runtime/providers_test.go @@ -496,6 +496,45 @@ func TestManagerRefreshPersistsQoderBreakdown(t *testing.T) { } } +// The Kiro subscription tier must survive the generic quota path so the +// account card can show it. +func TestManagerRefreshPersistsKiroPlan(t *testing.T) { + ctx := context.Background() + store, err := sqlstore.OpenStore(filepath.Join(t.TempDir(), "qoder.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + account, err := store.Create(ctx, accounts.CreateAccount{Name: "K", Provider: "kiro", Region: "us-east-1", Enabled: false}) + if err != nil { + t.Fatal(err) + } + prober := &fakeProber{ + health: providers.AccountHealth{Ready: true, Hot: true, UID: "k-uid"}, + quota: &providers.QuotaInfo{ + Used: 552.37, Total: 907, Remaining: 354.63, Percentage: 60.9, Unit: "credits", + FetchedAt: "2026-11-20T00:00:00Z", ProviderID: "kiro", Plan: "PRO_PLUS", + Windows: []providers.QuotaWindow{{ID: "credits", Label: "Credits", Used: 552.37, Total: 907, Remaining: 354.63, Percentage: 60.9, Unit: "credits"}}, + }, + } + registry := providers.NewRegistry() + registry.Register(providers.Adapter{ID: "kiro", Prober: prober}) + manager := accountruntime.NewManager(accountruntime.ManagerConfig{DataDir: t.TempDir()}, store, &fakeStarter{}) + manager.SetProviders(registry) + manager.Pool().Upsert(executor.Item{ID: account.ID, Provider: "kiro", Runtime: "in_process"}) + + if err := manager.RefreshAccount(ctx, account.ID, true); err != nil { + t.Fatalf("refresh err = %v", err) + } + stored, err := store.Get(ctx, account.ID) + if err != nil { + t.Fatal(err) + } + if stored.Quota == nil || stored.Quota.Plan != "PRO_PLUS" { + t.Fatalf("kiro plan lost through generic path: %+v", stored.Quota) + } +} + func TestManagerRefreshClearsRecoveredDevinQuotaCooldown(t *testing.T) { ctx := context.Background() store, err := sqlstore.OpenStore(filepath.Join(t.TempDir(), "qoder.db"))