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
7 changes: 7 additions & 0 deletions changelog/unreleased/kiro-plan-credit-unit.md
Original file line number Diff line number Diff line change
@@ -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` 改为显示为积分。
6 changes: 4 additions & 2 deletions internal/providers/kiro/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions internal/providers/kiro/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion internal/runtime/manager_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions internal/runtime/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Loading