@kortix/ui 0.15.6 → 0.15.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/README.md +7 -7
  2. package/dist/_vendor/kortix-shared.js +36 -1
  3. package/dist/_vendor/shared/my-kortix-agent.d.ts +7 -0
  4. package/dist/_vendor/shared/pixel-mark.d.ts +18 -0
  5. package/dist/customize/connectors/catalog/connector-categories.d.ts +2 -2
  6. package/dist/customize/connectors/catalog/connector-categories.js +2 -2
  7. package/dist/customize/connectors/detail/connector-modal.js +1 -1
  8. package/dist/customize/providers/provider-accordion.js +3 -2
  9. package/dist/customize/providers/provider-connect.d.ts +7 -0
  10. package/dist/customize/providers/provider-connect.js +21 -2
  11. package/dist/customize/providers/provider-sheet.js +3 -2
  12. package/dist/customize/sections/gateway-view.d.ts +2 -2
  13. package/dist/customize/sections/gateway-view.js +30 -15
  14. package/dist/customize/sections/llm-provider/chatgpt-subscription-connect.d.ts +3 -1
  15. package/dist/customize/sections/llm-provider/chatgpt-subscription-connect.js +2 -2
  16. package/dist/customize/sections/view/account-secret-resources-panel.js +8 -5
  17. package/dist/customize/sections/view/agent-editor-basics-fields.js +1 -1
  18. package/dist/customize/sections/view/gateway/gateway-logs.d.ts +1 -1
  19. package/dist/customize/sections/view/git-view.js +1 -1
  20. package/dist/customize/sections/view/permission-editor.js +1 -1
  21. package/dist/customize/sections/view/review-center-connected.js +15 -3
  22. package/dist/customize/sections/view/subscription-usage.d.ts +269 -17
  23. package/dist/customize/sections/view/subscription-usage.js +197 -54
  24. package/dist/customize/shared/entity/entity-modal.js +8 -10
  25. package/dist/files/project/components/drive-toolbar.d.ts +1 -1
  26. package/dist/files/project/components/drive-toolbar.js +1 -1
  27. package/dist/files/project/store/version-store.d.ts +1 -1
  28. package/dist/files/renderers/shared/scroll-area-compat.d.ts +6 -6
  29. package/dist/files/renderers/shared/scroll-area-compat.js +7 -9
  30. package/dist/files/renderers/shared/select-compat.js +3 -7
  31. package/dist/files/viewer/file-preview-modal.d.ts +10 -11
  32. package/dist/files/viewer/file-preview-modal.js +17 -18
  33. package/dist/i18n/en.d.ts +40 -47
  34. package/dist/i18n/en.js +47 -54
  35. package/dist/i18n/ui-catalog/app-registry-translation-keys.generated.js +5 -0
  36. package/dist/index.js +1 -1
  37. package/dist/internal/account-hub/account-hub-location.js +2 -2
  38. package/dist/internal/account-hub/use-account-members.d.ts +28 -1
  39. package/dist/internal/account-hub/use-account-members.js +27 -10
  40. package/dist/internal/auth/auth-primitives.d.ts +27 -0
  41. package/dist/internal/auth/auth-primitives.js +21 -0
  42. package/dist/internal/billing/index.d.ts +1 -0
  43. package/dist/internal/billing/index.js +2 -0
  44. package/dist/internal/billing/use-free-grant-unspent.d.ts +10 -0
  45. package/dist/internal/billing/use-free-grant-unspent.js +20 -0
  46. package/dist/internal/components/agent-mark.d.ts +1 -8
  47. package/dist/internal/components/agent-mark.js +2 -19
  48. package/dist/internal/lib/billing/billing-gate-state.d.ts +20 -0
  49. package/dist/internal/lib/billing/billing-gate-state.js +22 -0
  50. package/dist/internal/lib/error-handler.js +0 -2
  51. package/dist/internal/lib/navigation/modified-click.js +2 -2
  52. package/dist/internal/lib/pixel-mark.d.ts +3 -20
  53. package/dist/internal/lib/pixel-mark.js +3 -34
  54. package/dist/internal/notifications/notification-inbox.js +1 -1
  55. package/dist/internal/stores/active-space-store.d.ts +1 -1
  56. package/dist/internal/stores/browser-recents-store.d.ts +1 -1
  57. package/dist/internal/stores/current-account-store.d.ts +1 -1
  58. package/dist/internal/stores/first-chat-store.d.ts +1 -1
  59. package/dist/internal/stores/mobile-app-promo-store.d.ts +1 -1
  60. package/dist/internal/stores/session-browser-store.d.ts +1 -1
  61. package/dist/internal/stores/session-expanded-store.d.ts +1 -1
  62. package/dist/internal/stores/session-filter-store.d.ts +1 -1
  63. package/dist/internal/stores/session-history-view-store.d.ts +1 -1
  64. package/dist/internal/stores/session-hover-store.d.ts +1 -1
  65. package/dist/internal/stores/session-hover-store.js +1 -1
  66. package/dist/internal/stores/session-panel-memory-store.d.ts +1 -1
  67. package/dist/internal/stores/sound-store.d.ts +1 -1
  68. package/dist/internal/stores/tab-store.d.ts +1 -1
  69. package/dist/internal/stores/upgrade-dialog-store.d.ts +0 -2
  70. package/dist/internal/stores/upgrade-dialog-store.js +0 -2
  71. package/dist/internal/stores/user-preferences-store.d.ts +1 -1
  72. package/dist/internal/stores/web-notification-store.d.ts +1 -1
  73. package/dist/lib/base-ui-compat.d.ts +149 -0
  74. package/dist/lib/base-ui-compat.js +339 -0
  75. package/dist/lib/portal-container.d.ts +3 -7
  76. package/dist/lib/portal-container.js +5 -3
  77. package/dist/lib/z-stack.d.ts +4 -4
  78. package/dist/lib/z-stack.js +5 -5
  79. package/dist/markdown/setup-links/approval-decision.d.ts +1 -1
  80. package/dist/markdown/setup-links/approval-decision.js +1 -1
  81. package/dist/primitives/accordion.d.ts +36 -5
  82. package/dist/primitives/accordion.js +41 -8
  83. package/dist/primitives/alert-dialog.d.ts +33 -11
  84. package/dist/primitives/alert-dialog.js +41 -19
  85. package/dist/primitives/avatar.d.ts +5 -2
  86. package/dist/primitives/avatar.js +3 -3
  87. package/dist/primitives/badge.js +1 -1
  88. package/dist/primitives/breadcrumb.js +1 -1
  89. package/dist/primitives/button-group.js +3 -3
  90. package/dist/primitives/button.js +1 -1
  91. package/dist/primitives/checkbox.d.ts +14 -5
  92. package/dist/primitives/checkbox.js +24 -9
  93. package/dist/primitives/collapsible.d.ts +16 -4
  94. package/dist/primitives/collapsible.js +18 -7
  95. package/dist/primitives/command-core.d.ts +121 -0
  96. package/dist/primitives/command-core.js +642 -0
  97. package/dist/primitives/command.d.ts +38 -4
  98. package/dist/primitives/command.js +22 -13
  99. package/dist/primitives/context-menu.d.ts +61 -31
  100. package/dist/primitives/context-menu.js +40 -53
  101. package/dist/primitives/dialog.d.ts +48 -10
  102. package/dist/primitives/dialog.js +48 -19
  103. package/dist/primitives/disclosure.d.ts +1 -1
  104. package/dist/primitives/disclosure.js +2 -2
  105. package/dist/primitives/drawer.d.ts +28 -9
  106. package/dist/primitives/drawer.js +42 -18
  107. package/dist/primitives/dropdown-menu.d.ts +55 -33
  108. package/dist/primitives/dropdown-menu.js +46 -82
  109. package/dist/primitives/faded-scroll-area.js +2 -1
  110. package/dist/primitives/hint.js +3 -3
  111. package/dist/primitives/hover-card.d.ts +17 -5
  112. package/dist/primitives/hover-card.js +45 -8
  113. package/dist/primitives/item.js +2 -2
  114. package/dist/primitives/label.d.ts +5 -2
  115. package/dist/primitives/label.js +10 -3
  116. package/dist/primitives/menu-base.d.ts +150 -0
  117. package/dist/primitives/menu-base.js +171 -0
  118. package/dist/primitives/menu-recipe.d.ts +1 -1
  119. package/dist/primitives/menu-recipe.js +2 -7
  120. package/dist/primitives/modal.d.ts +19 -52
  121. package/dist/primitives/modal.js +24 -28
  122. package/dist/primitives/navigation-menu.d.ts +36 -11
  123. package/dist/primitives/navigation-menu.js +31 -12
  124. package/dist/primitives/popover.d.ts +31 -6
  125. package/dist/primitives/popover.js +79 -12
  126. package/dist/primitives/preview-image.d.ts +18 -7
  127. package/dist/primitives/preview-image.js +14 -11
  128. package/dist/primitives/progress.d.ts +4 -2
  129. package/dist/primitives/progress.js +4 -3
  130. package/dist/primitives/project-icon-picker.js +2 -2
  131. package/dist/primitives/radio-group.d.ts +28 -5
  132. package/dist/primitives/radio-group.js +18 -10
  133. package/dist/primitives/scroll-area.d.ts +2 -2
  134. package/dist/primitives/scroll-area.js +8 -3
  135. package/dist/primitives/select.d.ts +55 -12
  136. package/dist/primitives/select.js +93 -36
  137. package/dist/primitives/separator.d.ts +6 -2
  138. package/dist/primitives/separator.js +10 -2
  139. package/dist/primitives/sheet.d.ts +17 -10
  140. package/dist/primitives/sheet.js +19 -22
  141. package/dist/primitives/sidebar-menu-primitives.js +8 -8
  142. package/dist/primitives/slider-native.d.ts +2 -2
  143. package/dist/primitives/slider-native.js +11 -9
  144. package/dist/primitives/slider.d.ts +24 -6
  145. package/dist/primitives/slider.js +26 -24
  146. package/dist/primitives/slot.d.ts +6 -0
  147. package/dist/primitives/slot.js +7 -0
  148. package/dist/primitives/split-sheet.js +1 -1
  149. package/dist/primitives/stepper.js +1 -1
  150. package/dist/primitives/switch.d.ts +16 -3
  151. package/dist/primitives/switch.js +7 -6
  152. package/dist/primitives/tabs.d.ts +36 -20
  153. package/dist/primitives/tabs.js +131 -102
  154. package/dist/primitives/toggle.d.ts +16 -3
  155. package/dist/primitives/toggle.js +8 -3
  156. package/dist/primitives/tooltip.d.ts +24 -5
  157. package/dist/primitives/tooltip.js +32 -10
  158. package/dist/primitives/type-to-confirm-dialog.d.ts +1 -1
  159. package/dist/primitives/type-to-confirm-dialog.js +1 -1
  160. package/dist/session/composer/animated-placeholder.js +1 -1
  161. package/dist/session/composer/chat-input/chat-input-control.js +3 -3
  162. package/dist/session/composer/editor/composer-editor.js +1 -1
  163. package/dist/session/composer/menus/menu-shell.d.ts +1 -1
  164. package/dist/session/composer/menus/menu-shell.js +1 -1
  165. package/dist/session/composer/menus/mount.js +1 -1
  166. package/dist/session/composer/reasoning-effort-selector.js +1 -1
  167. package/dist/session/header/session-site-header.js +2 -2
  168. package/dist/session/header/subagent-hover-card.js +2 -2
  169. package/dist/session/media/image-preview.js +1 -1
  170. package/dist/session/models/model-selector.d.ts +1 -1
  171. package/dist/session/models/model-selector.js +18 -12
  172. package/dist/session/models/subscription-switcher.d.ts +37 -0
  173. package/dist/session/models/subscription-switcher.js +97 -0
  174. package/dist/session/models/subscription-windows.d.ts +40 -0
  175. package/dist/session/models/subscription-windows.js +86 -0
  176. package/dist/session/overrides/session-overrides-control.js +3 -3
  177. package/dist/session/panel/diff-dialog.js +1 -1
  178. package/dist/session/panel/easy/detail-view.js +3 -3
  179. package/dist/session/panel/mobile-tool-drawer.js +2 -2
  180. package/dist/session/panel/panel-fallback.js +1 -1
  181. package/dist/session/panel/session-files-explorer.d.ts +1 -1
  182. package/dist/session/panel/session-files-explorer.js +1 -1
  183. package/dist/session/prompts/ask-deck.d.ts +14 -2
  184. package/dist/session/prompts/ask-deck.js +6 -2
  185. package/dist/session/thread/session-chat.js +2 -2
  186. package/dist/session/thread/session-context-message-explorer.js +1 -1
  187. package/dist/session/thread/turn-share.js +3 -4
  188. package/dist/session/tool/shared/show-helpers.js +1 -1
  189. package/dist/session/turn/message-time-label.js +1 -1
  190. package/dist/styles.css +1 -1
  191. package/dist/test-utils/intl.d.ts +40 -47
  192. package/dist/workspace/admin/settings-search.js +4 -12
  193. package/dist/workspace/inbox/workspace-inbox.js +11 -2
  194. package/dist/workspace/layout/new-session-create.d.ts +4 -2
  195. package/dist/workspace/layout/new-session-create.js +11 -0
  196. package/dist/workspace/projects/modal/project-icon-field.js +9 -23
  197. package/dist/workspace/review/approval-modal.d.ts +6 -6
  198. package/dist/workspace/review/approval-modal.js +10 -14
  199. package/dist/workspace/review/review-center.d.ts +9 -2
  200. package/dist/workspace/review/review-center.js +258 -126
  201. package/dist/workspace/review/review-detail.d.ts +20 -10
  202. package/dist/workspace/review/review-detail.js +39 -44
  203. package/dist/workspace/review/review-meta.d.ts +27 -6
  204. package/dist/workspace/review/review-meta.js +46 -34
  205. package/dist/workspace/sessions/session-row.js +1 -1
  206. package/dist/workspace/sidebar/footer/project-download-app-nav.d.ts +10 -0
  207. package/dist/workspace/sidebar/footer/project-download-app-nav.js +53 -0
  208. package/dist/workspace/sidebar/footer/promo-nav-row.d.ts +2 -1
  209. package/dist/workspace/sidebar/footer/promo-nav-row.js +1 -1
  210. package/dist/workspace/sidebar/project-session-list.js +2 -2
  211. package/dist/workspace/sidebar/project-sidebar.d.ts +6 -1
  212. package/dist/workspace/sidebar/project-sidebar.js +3 -2
  213. package/dist/workspace/sidebar/session-brief-hover-card.d.ts +1 -1
  214. package/dist/workspace/sidebar/session-brief-hover-card.js +3 -3
  215. package/dist/workspace/sidebar/session-title.d.ts +2 -2
  216. package/dist/workspace/sidebar/session-title.js +2 -2
  217. package/dist/workspace/sidebar/workspace-menu-model.d.ts +19 -13
  218. package/dist/workspace/sidebar/workspace-menu-model.js +7 -8
  219. package/dist/workspace/sidebar/workspace-menu-section.js +1 -1
  220. package/dist/workspace/spaces/space-links.js +1 -1
  221. package/dist/workspace/spaces/space-threads-tab.js +1 -1
  222. package/package.json +16 -35
  223. package/skills/kortix-ui/SKILL.md +1 -1
  224. package/skills/kortix-ui/references/custom-dashboard.md +1 -1
  225. package/dist/customize/sections/view/subscription-usage-tab.d.ts +0 -25
  226. package/dist/customize/sections/view/subscription-usage-tab.js +0 -121
@@ -20,14 +20,14 @@ import { useCloseChangeRequest, useMergeChangeRequest, useRequestChangesOnChange
20
20
  import { useProjectCans } from '../../../internal/lib/use-project-can.js';
21
21
  import { useSettingsPanelStore } from '../../../internal/stores/settings-panel-store.js';
22
22
  import { listProjectSessions, PROJECT_SESSION_NAME_LOOKUP_LIMIT, REVIEW_CONTROL_ACTIONS, reviewVerdictAllowed, } from '@kortix/sdk';
23
- import { clearStartStash, contract, qk, reviewItemsOf } from '@kortix/sdk/react';
23
+ import { clearStartStash, contract, qk, reviewItemsOf, useSessionAsks } from '@kortix/sdk/react';
24
24
  import { useQuery, useQueryClient } from '@tanstack/react-query';
25
25
  import { useUiRouter, useUiSearchParams } from '../../../providers/ui-provider.js';
26
26
  import { useEffect, useMemo, useState } from 'react';
27
27
  import { invalidateReviewInbox, useActReviewItem, useBulkActReviewItems, useResolveReviewApproval, useReviewItemById, useReviewItems, withFreshApprovalDetail, } from '../../../workspace/review/hooks/use-review-items.js';
28
28
  import { mapApiReviewItem } from '../../../workspace/review/map.js';
29
29
  import { connectorCallId, crChangeRequestId, isApprovalExpiredError, itemDeepLink, } from '../../../workspace/review/review-actions.js';
30
- import { AskDeck } from '../../../session/prompts/ask-deck.js';
30
+ import { AskDeck, DECK_KINDS } from '../../../session/prompts/ask-deck.js';
31
31
  import { ReviewCenter } from '../../../workspace/review/review-center.js';
32
32
  import { REVIEW_VERDICT_ANNOUNCED } from '../../../workspace/review/review-reducer.js';
33
33
  /**
@@ -49,6 +49,12 @@ export function ReviewCenterConnected({ projectName }) {
49
49
  // role still sees the inbox, with no verdict control. The inbox stays live
50
50
  // for every viewer: an unresolved probe offers no verdict.
51
51
  const cans = useProjectCans(projectId, REVIEW_CONTROL_ACTIONS);
52
+ // The deck claims the inbox's empty pane only while an agent asks something
53
+ // (or the asks still load). With none, its own "Nothing waits on you" would
54
+ // sit beside rows that do wait, so the pane shows "Select an item" instead.
55
+ // Same query as the deck's own: a cache hit, not a second request.
56
+ const asks = useSessionAsks(projectId, { enabled: Boolean(projectId) });
57
+ const deckShows = asks.isLoading || asks.isError || (asks.data?.asks ?? []).some((ask) => DECK_KINDS.has(ask.kind));
52
58
  const qc = useQueryClient();
53
59
  const router = useUiRouter();
54
60
  const closeCustomize = useSettingsPanelStore((s) => s.close);
@@ -271,7 +277,13 @@ export function ReviewCenterConnected({ projectName }) {
271
277
  // The effect above has already warmed this href.
272
278
  router.push(href);
273
279
  }
274
- return (_jsx(ReviewCenter, { needsYouDeck: projectId ? _jsx(AskDeck, { projectId: projectId, onOpenSession: openSession }) : null, initialItems: items, segment: segment, onSegmentChange: setSegment, loadMore: hasNextPage
280
+ return (_jsx(ReviewCenter, { needsYouDeck: projectId && deckShows
281
+ ? ({ paused }) => (
282
+ // `empty={null}`: in the 5 s Undo window after the last card,
283
+ // the deck draws nothing (the inbox shows its own empty state)
284
+ // rather than "Nothing waits on you" beside rows that do.
285
+ _jsx(AskDeck, { projectId: projectId, onOpenSession: openSession, empty: null, paused: paused }))
286
+ : undefined, initialItems: items, segment: segment, onSegmentChange: setSegment, loadMore: hasNextPage
275
287
  ? {
276
288
  onLoadMore: () => void fetchNextPage(),
277
289
  isLoading: isFetchingNextPage,
@@ -1,9 +1,8 @@
1
- import type { AccountSecretResource, SubscriptionAccount, SubscriptionUsage, SubscriptionUsageWindow } from '@kortix/sdk';
2
- export type UsageTone = 'ok' | 'near' | 'critical' | 'limited';
3
- /** Warn at 80%, turn red at 95%, and distinguish a provider-enforced limit. */
4
- export declare function usageTone(window: SubscriptionUsageWindow, limited: boolean): UsageTone;
5
- /** The model name of a model-specific weekly window (`seven_day_opus` → `Opus`), or null. */
6
- export declare function weeklyModel(id: string): string | null;
1
+ import type { AccountSecretResource, SubscriptionConnection, SubscriptionUsage, SubscriptionUsageWindow } from '@kortix/sdk';
2
+ import { accountLine, isBlockingWindow, loginLimit, modelName, usageTone, weeklyModel, windowLabel, type UsageTone } from '../../../session/models/subscription-windows.js';
3
+ export { accountLine, isBlockingWindow, loginLimit, modelName, usageTone, weeklyModel, windowLabel, type UsageTone };
4
+ /** The provider-list row that carries each subscription login's usage. */
5
+ export declare const SUBSCRIPTION_ROW: Readonly<Record<string, string>>;
7
6
  /**
8
7
  * A reset time a person reads at a glance: the clock time today, the weekday
9
8
  * and time within a week, else the date.
@@ -11,24 +10,277 @@ export declare function weeklyModel(id: string): string | null;
11
10
  export declare function formatReset(iso: string, now: number, locale: string): string;
12
11
  /** The usage to show: the live read when it answered, else the snapshot the list carried. */
13
12
  export declare function shownUsage(live: SubscriptionUsage | null | undefined, listed: SubscriptionUsage | null | undefined): SubscriptionUsage | null;
14
- /**
15
- * `person@example.test · Pro`: who the login signs in as. The email is left out
16
- * when the label already shows it; null when the provider says nothing.
17
- */
18
- export declare function accountLine(account: SubscriptionAccount | null | undefined, label: string): string | null;
19
13
  /** The login's email and plan, under its name: the live read when it answered, else the list's. */
20
- export declare function SubscriptionAccountLine({ accountId, secret }: {
14
+ export declare function SubscriptionAccountLine({ accountId, projectId, secret }: {
21
15
  accountId: string;
16
+ projectId: string;
22
17
  secret: AccountSecretResource;
23
18
  }): import("react").JSX.Element | null;
24
19
  export declare function isSubscriptionLogin(secret: Pick<AccountSecretResource, 'provider_id'>): boolean;
20
+ /** A login the gateway can route to: active, readable, signed in. */
21
+ export declare function usable(secret: Pick<SubscriptionConnection, 'active' | 'needs_reauth_at' | 'status'>): boolean;
22
+ export interface SubscriptionSummary {
23
+ total: number;
24
+ /** Logins that can take a model call now, by their reported usage. */
25
+ available: number;
26
+ /** Usable logins with no usage reported yet: neither available nor limited. */
27
+ unknown: number;
28
+ limited: number;
29
+ /** When the first limited login gets capacity back. */
30
+ nextBack: string | null;
31
+ /** The fullest blocking window across the available logins. */
32
+ peak: SubscriptionUsageWindow | null;
33
+ }
34
+ /**
35
+ * One provider's logins in one line: how many can work now, when the next
36
+ * one is back, and the fullest window of the ones that can.
37
+ */
38
+ export declare function summarizeSubscriptions(logins: Array<{
39
+ secret: Pick<SubscriptionConnection, 'active' | 'needs_reauth_at' | 'status'>;
40
+ usage: SubscriptionUsage | null;
41
+ }>, now: number): SubscriptionSummary;
42
+ /** Every ChatGPT and Claude login this project can use, by provider-list row. */
43
+ export declare function useSubscriptionLogins(accountId: string | null | undefined, projectId: string): {
44
+ logins: SubscriptionConnection[];
45
+ data: {
46
+ subscriptions: SubscriptionConnection[];
47
+ };
48
+ error: Error;
49
+ isError: true;
50
+ isPending: false;
51
+ isLoading: false;
52
+ isLoadingError: false;
53
+ isRefetchError: true;
54
+ isSuccess: false;
55
+ isPlaceholderData: false;
56
+ status: "error";
57
+ dataUpdatedAt: number;
58
+ errorUpdatedAt: number;
59
+ failureCount: number;
60
+ failureReason: Error | null;
61
+ errorUpdateCount: number;
62
+ isFetched: boolean;
63
+ isFetchedAfterMount: boolean;
64
+ isFetching: boolean;
65
+ isInitialLoading: boolean;
66
+ isPaused: boolean;
67
+ isRefetching: boolean;
68
+ isStale: boolean;
69
+ isEnabled: boolean;
70
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
71
+ subscriptions: SubscriptionConnection[];
72
+ }, Error>>;
73
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
74
+ } | {
75
+ logins: SubscriptionConnection[];
76
+ data: {
77
+ subscriptions: SubscriptionConnection[];
78
+ };
79
+ error: null;
80
+ isError: false;
81
+ isPending: false;
82
+ isLoading: false;
83
+ isLoadingError: false;
84
+ isRefetchError: false;
85
+ isSuccess: true;
86
+ isPlaceholderData: false;
87
+ status: "success";
88
+ dataUpdatedAt: number;
89
+ errorUpdatedAt: number;
90
+ failureCount: number;
91
+ failureReason: Error | null;
92
+ errorUpdateCount: number;
93
+ isFetched: boolean;
94
+ isFetchedAfterMount: boolean;
95
+ isFetching: boolean;
96
+ isInitialLoading: boolean;
97
+ isPaused: boolean;
98
+ isRefetching: boolean;
99
+ isStale: boolean;
100
+ isEnabled: boolean;
101
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
102
+ subscriptions: SubscriptionConnection[];
103
+ }, Error>>;
104
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
105
+ } | {
106
+ logins: SubscriptionConnection[];
107
+ data: undefined;
108
+ error: Error;
109
+ isError: true;
110
+ isPending: false;
111
+ isLoading: false;
112
+ isLoadingError: true;
113
+ isRefetchError: false;
114
+ isSuccess: false;
115
+ isPlaceholderData: false;
116
+ status: "error";
117
+ dataUpdatedAt: number;
118
+ errorUpdatedAt: number;
119
+ failureCount: number;
120
+ failureReason: Error | null;
121
+ errorUpdateCount: number;
122
+ isFetched: boolean;
123
+ isFetchedAfterMount: boolean;
124
+ isFetching: boolean;
125
+ isInitialLoading: boolean;
126
+ isPaused: boolean;
127
+ isRefetching: boolean;
128
+ isStale: boolean;
129
+ isEnabled: boolean;
130
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
131
+ subscriptions: SubscriptionConnection[];
132
+ }, Error>>;
133
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
134
+ } | {
135
+ logins: SubscriptionConnection[];
136
+ data: undefined;
137
+ error: null;
138
+ isError: false;
139
+ isPending: true;
140
+ isLoading: true;
141
+ isLoadingError: false;
142
+ isRefetchError: false;
143
+ isSuccess: false;
144
+ isPlaceholderData: false;
145
+ status: "pending";
146
+ dataUpdatedAt: number;
147
+ errorUpdatedAt: number;
148
+ failureCount: number;
149
+ failureReason: Error | null;
150
+ errorUpdateCount: number;
151
+ isFetched: boolean;
152
+ isFetchedAfterMount: boolean;
153
+ isFetching: boolean;
154
+ isInitialLoading: boolean;
155
+ isPaused: boolean;
156
+ isRefetching: boolean;
157
+ isStale: boolean;
158
+ isEnabled: boolean;
159
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
160
+ subscriptions: SubscriptionConnection[];
161
+ }, Error>>;
162
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
163
+ } | {
164
+ logins: SubscriptionConnection[];
165
+ data: undefined;
166
+ error: null;
167
+ isError: false;
168
+ isPending: true;
169
+ isLoadingError: false;
170
+ isRefetchError: false;
171
+ isSuccess: false;
172
+ isPlaceholderData: false;
173
+ status: "pending";
174
+ dataUpdatedAt: number;
175
+ errorUpdatedAt: number;
176
+ failureCount: number;
177
+ failureReason: Error | null;
178
+ errorUpdateCount: number;
179
+ isFetched: boolean;
180
+ isFetchedAfterMount: boolean;
181
+ isFetching: boolean;
182
+ isLoading: boolean;
183
+ isInitialLoading: boolean;
184
+ isPaused: boolean;
185
+ isRefetching: boolean;
186
+ isStale: boolean;
187
+ isEnabled: boolean;
188
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
189
+ subscriptions: SubscriptionConnection[];
190
+ }, Error>>;
191
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
192
+ } | {
193
+ logins: SubscriptionConnection[];
194
+ data: {
195
+ subscriptions: SubscriptionConnection[];
196
+ };
197
+ isError: false;
198
+ error: null;
199
+ isPending: false;
200
+ isLoading: false;
201
+ isLoadingError: false;
202
+ isRefetchError: false;
203
+ isSuccess: true;
204
+ isPlaceholderData: true;
205
+ status: "success";
206
+ dataUpdatedAt: number;
207
+ errorUpdatedAt: number;
208
+ failureCount: number;
209
+ failureReason: Error | null;
210
+ errorUpdateCount: number;
211
+ isFetched: boolean;
212
+ isFetchedAfterMount: boolean;
213
+ isFetching: boolean;
214
+ isInitialLoading: boolean;
215
+ isPaused: boolean;
216
+ isRefetching: boolean;
217
+ isStale: boolean;
218
+ isEnabled: boolean;
219
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<{
220
+ subscriptions: SubscriptionConnection[];
221
+ }, Error>>;
222
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
223
+ };
25
224
  /**
26
- * The plan usage of one ChatGPT or Claude login, under its name in the account
27
- * list: one bar per window (5-hour, weekly, a model's weekly), each with its
28
- * reset time. It shows the snapshot the list carried at once and asks the
29
- * server for a fresh read every minute while it is on screen.
225
+ * The provider list's line for ChatGPT or Claude: `70% weekly · resets Wed`,
226
+ * `1 of 3 at limit · back Fri 4:30 AM`, or null when nothing is reported.
30
227
  */
31
- export declare function SubscriptionUsageMeters({ accountId, secret }: {
228
+ export declare function useSubscriptionRowSummary(): (summary: SubscriptionSummary | undefined, now: number) => {
229
+ text: string;
230
+ percent: number;
231
+ tone: UsageTone;
232
+ } | null;
233
+ /** The provider list's mini meter beside its summary line. */
234
+ export declare function SubscriptionRowMeter({ text, percent, tone }: {
235
+ text: string;
236
+ percent: number;
237
+ tone: UsageTone;
238
+ }): import("react").JSX.Element;
239
+ /** Every window of one login, one per line, with the states around them. Props only: the design-system preview can use it. */
240
+ export declare function SubscriptionLoginWindows({ providerId, usage, loading, error, now, }: {
241
+ providerId: string | null | undefined;
242
+ usage: SubscriptionUsage | null;
243
+ loading: boolean;
244
+ error: boolean;
245
+ now: number;
246
+ }): import("react").JSX.Element;
247
+ /**
248
+ * The usage under one ChatGPT or Claude account in the provider sheet's
249
+ * account list: the limit state, then every window. The row above it already
250
+ * names the login.
251
+ */
252
+ export declare function SubscriptionAccountUsage({ accountId, projectId, secret }: {
32
253
  accountId: string;
254
+ projectId: string;
33
255
  secret: AccountSecretResource;
34
256
  }): import("react").JSX.Element | null;
257
+ /**
258
+ * Every login's shown usage for a summary: the live read when it answered
259
+ * (a project-stored login's list snapshot stays empty), else the list's.
260
+ */
261
+ export declare function useLiveSubscriptionUsages(accountId: string | null | undefined, projectId: string, logins: SubscriptionConnection[]): {
262
+ usages: {
263
+ secret: SubscriptionConnection;
264
+ usage: SubscriptionUsage | null;
265
+ }[];
266
+ updatedAt: number;
267
+ };
268
+ /**
269
+ * "Subscription usage" on top of the ChatGPT (OpenAI) or Claude (Anthropic)
270
+ * provider sheet: how many logins can work now and when the next one is back,
271
+ * shown once there is more than one login or one is at its limit. Each
272
+ * account's own windows sit under it in the account list; a project-stored
273
+ * login that list does not carry is shown here.
274
+ */
275
+ export declare function SubscriptionUsageSection({ accountId, projectId, providerId, compact }: {
276
+ accountId: string;
277
+ projectId: string;
278
+ providerId: 'codex' | 'claude-agent';
279
+ /** The quick dialog's accordion: headings there are `text-xs`. */
280
+ compact?: boolean;
281
+ }): import("react").JSX.Element | null;
282
+ /** The windows of the project-stored ChatGPT login, for its legacy card in the OpenAI sheet. */
283
+ export declare function LegacyChatGptUsage({ accountId, projectId }: {
284
+ accountId: string;
285
+ projectId: string;
286
+ }): import("react").JSX.Element | null;
@@ -1,26 +1,20 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useSubscriptionUsage } from '@kortix/sdk/react';
3
+ import { useCallback } from 'react';
4
+ import { useSubscriptionConnections, useSubscriptionUsage, useSubscriptionUsages } from '@kortix/sdk/react';
4
5
  import { useLocale, useTranslations } from '../../../i18n/index.js';
6
+ import { cn } from '../../../lib/utils.js';
7
+ import { Badge } from '../../../primitives/badge.js';
5
8
  import { Progress } from '../../../primitives/progress.js';
9
+ import { accountLine, currentWindows as current, isBlockingWindow, loginLimit, modelName, usageTone, weeklyModel, windowLabel, } from '../../../session/models/subscription-windows.js';
10
+ export { accountLine, isBlockingWindow, loginLimit, modelName, usageTone, weeklyModel, windowLabel };
6
11
  /** Providers whose stored value is a subscription login with plan windows. */
7
12
  const SUBSCRIPTION_PROVIDERS = new Set(['codex', 'claude-agent']);
13
+ /** The provider-list row that carries each subscription login's usage. */
14
+ export const SUBSCRIPTION_ROW = { codex: 'openai', 'claude-agent': 'anthropic' };
8
15
  /** A snapshot older than this says when it was observed. */
9
16
  const STALE_MS = 10 * 60 * 1000;
10
- /** Warn at 80%, turn red at 95%, and distinguish a provider-enforced limit. */
11
- export function usageTone(window, limited) {
12
- if (window.used_percent >= 100 || (limited && window.used_percent >= 90))
13
- return 'limited';
14
- if (window.used_percent >= 95)
15
- return 'critical';
16
- return window.used_percent >= 80 ? 'near' : 'ok';
17
- }
18
17
  const TONE_BAR = { ok: 'bg-primary', near: 'bg-kortix-orange', critical: 'bg-kortix-red', limited: 'bg-kortix-red' };
19
- /** The model name of a model-specific weekly window (`seven_day_opus` → `Opus`), or null. */
20
- export function weeklyModel(id) {
21
- const model = /^(?:seven_day|7d)_([a-z]+)$/.exec(id)?.[1];
22
- return model ? model[0].toUpperCase() + model.slice(1) : null;
23
- }
24
18
  /**
25
19
  * A reset time a person reads at a glance: the clock time today, the weekday
26
20
  * and time within a week, else the date.
@@ -42,57 +36,206 @@ export function shownUsage(live, listed) {
42
36
  return Date.parse(live.observed_at) >= Date.parse(listed.observed_at) ? live : listed;
43
37
  return live ?? listed ?? null;
44
38
  }
45
- /**
46
- * `person@example.test · Pro`: who the login signs in as. The email is left out
47
- * when the label already shows it; null when the provider says nothing.
48
- */
49
- export function accountLine(account, label) {
50
- if (!account)
51
- return null;
52
- const email = account.email && !label.toLowerCase().includes(account.email.toLowerCase()) ? account.email : null;
53
- const plan = account.plan ? account.plan[0].toUpperCase() + account.plan.slice(1) : null;
54
- return [email, plan].filter(Boolean).join(' · ') || null;
55
- }
56
39
  /** The login's email and plan, under its name: the live read when it answered, else the list's. */
57
- export function SubscriptionAccountLine({ accountId, secret }) {
58
- const live = useSubscriptionUsage(accountId, secret.secret_id, { enabled: isSubscriptionLogin(secret) });
40
+ export function SubscriptionAccountLine({ accountId, projectId, secret }) {
41
+ const live = useSubscriptionUsage(accountId, secret.secret_id, { projectId, storage: 'account_resource', enabled: isSubscriptionLogin(secret) && usable(secret) });
59
42
  const line = accountLine(live.data?.provider_account ?? secret.provider_account, secret.label);
60
43
  return line ? _jsx("span", { className: "text-muted-foreground block truncate text-xs font-normal", children: line }) : null;
61
44
  }
62
45
  export function isSubscriptionLogin(secret) {
63
46
  return Boolean(secret.provider_id && SUBSCRIPTION_PROVIDERS.has(secret.provider_id));
64
47
  }
65
- function UsageWindowMeter({ window, limited, now }) {
66
- const t = useTranslations('pooledSecrets');
48
+ /** A login the gateway can route to: active, readable, signed in. */
49
+ export function usable(secret) {
50
+ return secret.active && !secret.needs_reauth_at && secret.status !== 'undecryptable';
51
+ }
52
+ /**
53
+ * One provider's logins in one line: how many can work now, when the next
54
+ * one is back, and the fullest window of the ones that can.
55
+ */
56
+ export function summarizeSubscriptions(logins, now) {
57
+ let available = 0;
58
+ let unknown = 0;
59
+ let limited = 0;
60
+ let nextBack = null;
61
+ let peak = null;
62
+ for (const { secret, usage } of logins) {
63
+ if (!usable(secret))
64
+ continue;
65
+ // Only a plan window says whether the login can work; extra usage or code review alone does not.
66
+ if (!usage || !current(usage, now).some((window) => isBlockingWindow(window.id))) {
67
+ unknown += 1;
68
+ continue;
69
+ }
70
+ const limit = loginLimit(usage, now);
71
+ if (limit.limited) {
72
+ limited += 1;
73
+ if (limit.until && (!nextBack || Date.parse(limit.until) < Date.parse(nextBack)))
74
+ nextBack = limit.until;
75
+ continue;
76
+ }
77
+ available += 1;
78
+ for (const window of usage ? current(usage, now) : []) {
79
+ if (isBlockingWindow(window.id) && (!peak || window.used_percent > peak.used_percent))
80
+ peak = window;
81
+ }
82
+ }
83
+ return { total: logins.length, available, unknown, limited, nextBack, peak };
84
+ }
85
+ /** Every ChatGPT and Claude login this project can use, by provider-list row. */
86
+ export function useSubscriptionLogins(accountId, projectId) {
87
+ const resources = useSubscriptionConnections(accountId, projectId);
88
+ const logins = (resources.data?.subscriptions ?? []).filter((secret) => secret.can_use && isSubscriptionLogin(secret));
89
+ return { ...resources, logins };
90
+ }
91
+ /**
92
+ * The provider list's line for ChatGPT or Claude: `70% weekly · resets Wed`,
93
+ * `1 of 3 at limit · back Fri 4:30 AM`, or null when nothing is reported.
94
+ */
95
+ export function useSubscriptionRowSummary() {
96
+ const t = useTranslations('subscriptionUsage');
97
+ const locale = useLocale();
98
+ return useCallback((summary, now) => {
99
+ if (!summary || summary.total === 0)
100
+ return null;
101
+ const back = summary.nextBack ? formatReset(summary.nextBack, now, locale) : null;
102
+ if (summary.limited > 0 && summary.available === 0 && summary.unknown === 0) {
103
+ return { text: back ? t('rowAllLimitedBack', { time: back }) : t('rowAllLimited'), percent: 100, tone: 'limited' };
104
+ }
105
+ if (summary.limited > 0) {
106
+ const text = back ? t('rowSomeLimitedBack', { limited: summary.limited, total: summary.total, time: back })
107
+ : t('rowSomeLimited', { limited: summary.limited, total: summary.total });
108
+ // The bar is the logins that still work: their fullest window.
109
+ return { text, percent: Math.round(summary.peak?.used_percent ?? 0), tone: summary.peak ? usageTone(summary.peak, false) : 'ok' };
110
+ }
111
+ if (!summary.peak)
112
+ return null;
113
+ const percent = Math.round(summary.peak.used_percent);
114
+ return {
115
+ text: t('rowPeak', { percent, window: windowLabel(summary.peak.id, t) }),
116
+ percent,
117
+ tone: usageTone(summary.peak, false),
118
+ };
119
+ }, [t, locale]);
120
+ }
121
+ /** The provider list's mini meter beside its summary line. */
122
+ export function SubscriptionRowMeter({ text, percent, tone }) {
123
+ return (_jsxs("span", { className: "text-muted-foreground flex shrink-0 items-center gap-2 text-xs tabular-nums", "data-subscription-usage-row": "", children: [_jsx("span", { className: "bg-muted block h-1 w-10 overflow-hidden rounded-full", "aria-hidden": true, children: _jsx("span", { className: cn('block h-full', TONE_BAR[tone]), style: { width: `${Math.min(100, percent)}%` } }) }), _jsx("span", { className: "max-w-72 truncate", children: text })] }));
124
+ }
125
+ function UsageWindowMeter({ window, limited, now, modelWeekly }) {
126
+ const t = useTranslations('subscriptionUsage');
127
+ const locale = useLocale();
128
+ const label = windowLabel(window.id, t, { modelWeekly });
129
+ const percent = Math.round(Math.min(100, Math.max(0, window.used_percent)));
130
+ const passed = Boolean(window.resets_at && Date.parse(window.resets_at) <= now);
131
+ const blocking = isBlockingWindow(window.id);
132
+ // A full window that stops nothing else (code review, extra usage, one
133
+ // model) is red, but says when it resets, not that the login is back.
134
+ const tone = blocking ? usageTone(window, limited) : window.used_percent >= 95 ? 'critical' : usageTone(window, false);
135
+ const reset = window.resets_at && !passed ? formatReset(window.resets_at, now, locale) : null;
136
+ const detail = passed ? t('resetPassed')
137
+ : tone === 'limited' && reset ? t('percentBack', { percent, time: reset })
138
+ : reset ? t('percentResets', { percent, time: reset }) : t('percent', { percent });
139
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-1.5", "data-usage-window": window.id, children: [_jsxs("div", { className: "flex items-baseline justify-between gap-3 text-xs", children: [_jsx("span", { className: "text-foreground min-w-0 truncate", children: label }), _jsx("span", { className: cn('shrink-0 tabular-nums', tone === 'limited' && !passed ? 'text-foreground' : 'text-muted-foreground'), children: detail })] }), _jsx(Progress, { value: passed ? 0 : percent, "aria-label": t('meterLabel', { label, percent }), className: "bg-muted h-1", indicatorClassName: passed ? 'bg-muted-foreground' : TONE_BAR[tone] })] }));
140
+ }
141
+ /** Claude reports no 5-hour window until a message opens one: say so instead of hiding the limit. */
142
+ function NotStartedWindow({ id }) {
143
+ const t = useTranslations('subscriptionUsage');
144
+ const label = windowLabel(id, t);
145
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-1.5", "data-usage-window": id, children: [_jsxs("div", { className: "flex items-baseline justify-between gap-3 text-xs", children: [_jsx("span", { className: "text-foreground min-w-0 truncate", children: label }), _jsx("span", { className: "text-muted-foreground shrink-0", children: t('notStarted') })] }), _jsx(Progress, { value: 0, "aria-label": t('meterLabel', { label, percent: 0 }), className: "bg-muted h-1" })] }));
146
+ }
147
+ /** Every window of one login, one per line, with the states around them. Props only: the design-system preview can use it. */
148
+ export function SubscriptionLoginWindows({ providerId, usage, loading, error, now, }) {
149
+ const t = useTranslations('subscriptionUsage');
67
150
  const locale = useLocale();
68
- const model = weeklyModel(window.id);
69
- const label = window.id === 'five_hour' ? t('usageFiveHour')
70
- : window.id === 'weekly' ? t('usageWeekly')
71
- : model ? t('usageWeeklyModel', { model }) : window.id;
72
- const tone = usageTone(window, limited);
73
- const percent = Math.round(window.used_percent);
74
- const reset = window.resets_at && Date.parse(window.resets_at) > now ? formatReset(window.resets_at, now, locale) : null;
75
- const detail = tone === 'limited'
76
- ? reset ? t('usageLimitResets', { time: reset }) : t('usageLimitReached')
77
- : reset ? t('usagePercentResets', { percent, time: reset }) : t('usagePercent', { percent });
78
- return (_jsxs("div", { className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex items-baseline justify-between gap-3 text-xs", children: [_jsx("span", { className: "text-muted-foreground shrink-0", children: label }), _jsx("span", { className: tone === 'limited' ? 'text-foreground min-w-0 truncate tabular-nums' : 'text-muted-foreground min-w-0 truncate tabular-nums', children: detail })] }), _jsx(Progress, { value: Math.min(100, window.used_percent), "aria-label": t('usageAriaLabel', { window: label, percent }), className: "bg-muted h-1", indicatorClassName: TONE_BAR[tone] })] }));
151
+ const limit = loginLimit(usage, now);
152
+ const windows = usage?.windows ?? [];
153
+ const missingFiveHour = providerId === 'claude-agent' && usage?.source === 'usage_endpoint' && windows.length > 0
154
+ && !windows.some((window) => window.id === 'five_hour');
155
+ const stale = usage && now - Date.parse(usage.observed_at) > STALE_MS;
156
+ const modelWeekly = windows.some((window) => weeklyModel(window.id) !== null);
157
+ if (!windows.length) {
158
+ return _jsx("p", { className: "text-muted-foreground text-xs", children: loading ? t('checking') : error ? t('loadFailed') : t('noUsageYet') });
159
+ }
160
+ return (_jsxs("div", { className: "flex flex-col gap-3", "data-subscription-windows": "", children: [missingFiveHour ? _jsx(NotStartedWindow, { id: "five_hour" }) : null, windows.map((window) => _jsx(UsageWindowMeter, { window: window, limited: limit.limited, now: now, modelWeekly: modelWeekly }, window.id)), error ? _jsx("p", { className: "text-muted-foreground text-xs", children: t('refreshFailed') })
161
+ : stale ? _jsx("p", { className: "text-muted-foreground text-xs", children: t('observed', { time: formatReset(usage.observed_at, now, locale) }) }) : null] }));
162
+ }
163
+ /** One login's live read: the same query the sheet's summary and the provider list read. */
164
+ function useLoginUsage(accountId, projectId, secretId, storage, enabled) {
165
+ return useSubscriptionUsage(accountId, secretId, { projectId, storage, enabled });
79
166
  }
80
167
  /**
81
- * The plan usage of one ChatGPT or Claude login, under its name in the account
82
- * list: one bar per window (5-hour, weekly, a model's weekly), each with its
83
- * reset time. It shows the snapshot the list carried at once and asks the
84
- * server for a fresh read every minute while it is on screen.
168
+ * The usage under one ChatGPT or Claude account in the provider sheet's
169
+ * account list: the limit state, then every window. The row above it already
170
+ * names the login.
85
171
  */
86
- export function SubscriptionUsageMeters({ accountId, secret }) {
87
- const t = useTranslations('pooledSecrets');
172
+ export function SubscriptionAccountUsage({ accountId, projectId, secret }) {
173
+ const t = useTranslations('subscriptionUsage');
174
+ const live = useLoginUsage(accountId, projectId, secret.secret_id, 'account_resource', usable(secret));
175
+ const usage = shownUsage(live.data?.usage, secret.usage);
176
+ // The clock of the newest read, the account list's included: a failed live
177
+ // read must not keep a passed reset looking current.
178
+ const listed = useSubscriptionLogins(accountId, projectId).dataUpdatedAt;
179
+ const now = Math.max(live.dataUpdatedAt, listed);
180
+ if (!usable(secret))
181
+ return null;
182
+ return (_jsxs("div", { className: "mt-2.5 flex flex-col gap-2.5 font-normal", "data-subscription-login": "", children: [loginLimit(usage, now).limited ? _jsx(Badge, { size: "sm", variant: "destructive", className: "self-start", children: t('limitReached') }) : null, _jsx(SubscriptionLoginWindows, { providerId: secret.provider_id, usage: usage, loading: live.isFetching, error: live.isError, now: now })] }));
183
+ }
184
+ /** A project-stored login (made before pooled accounts) has no row in the account list: it gets its own block here. */
185
+ function LegacyLogin({ accountId, projectId, secret, now }) {
186
+ const t = useTranslations('subscriptionUsage');
187
+ const live = useLoginUsage(accountId, projectId, secret.secret_id, secret.storage, secret.can_use && usable(secret));
188
+ const usage = shownUsage(live.data?.usage, secret.usage);
189
+ const line = accountLine(live.data?.provider_account ?? secret.provider_account, secret.label);
190
+ const at = Math.max(now, live.dataUpdatedAt);
191
+ return (_jsxs("li", { className: "border-border flex min-w-0 flex-col gap-2.5 rounded-md border px-3 py-2", "data-subscription-login": "", children: [_jsxs("div", { className: "flex min-w-0 items-start justify-between gap-3", children: [_jsxs("p", { className: "min-w-0 text-sm", children: [_jsx("span", { className: "text-foreground font-medium", children: secret.label }), line ? _jsx("span", { className: "text-muted-foreground block truncate text-xs", children: line }) : null] }), !usable(secret) ? _jsx("span", { className: "text-muted-foreground shrink-0 text-xs", children: secret.active ? t('reconnectToSee') : t('inactive') })
192
+ : loginLimit(usage, at).limited ? _jsx(Badge, { size: "sm", variant: "destructive", children: t('limitReached') }) : null] }), usable(secret) ? _jsx(SubscriptionLoginWindows, { providerId: secret.provider_id, usage: usage, loading: live.isFetching, error: live.isError, now: at }) : null] }));
193
+ }
194
+ /**
195
+ * Every login's shown usage for a summary: the live read when it answered
196
+ * (a project-stored login's list snapshot stays empty), else the list's.
197
+ */
198
+ export function useLiveSubscriptionUsages(accountId, projectId, logins) {
199
+ const reads = useSubscriptionUsages(accountId, projectId, logins);
200
+ const usages = logins.map((secret, index) => ({ secret, usage: shownUsage(reads[index]?.data?.usage, secret.usage) }));
201
+ const updatedAt = Math.max(0, ...reads.map((read) => read.dataUpdatedAt));
202
+ return { usages, updatedAt };
203
+ }
204
+ /**
205
+ * "Subscription usage" on top of the ChatGPT (OpenAI) or Claude (Anthropic)
206
+ * provider sheet: how many logins can work now and when the next one is back,
207
+ * shown once there is more than one login or one is at its limit. Each
208
+ * account's own windows sit under it in the account list; a project-stored
209
+ * login that list does not carry is shown here.
210
+ */
211
+ export function SubscriptionUsageSection({ accountId, projectId, providerId, compact = false }) {
212
+ const t = useTranslations('subscriptionUsage');
88
213
  const locale = useLocale();
89
- const live = useSubscriptionUsage(accountId, secret.secret_id, { enabled: isSubscriptionLogin(secret) });
214
+ const { logins: all, dataUpdatedAt } = useSubscriptionLogins(accountId, projectId);
215
+ const logins = all.filter((secret) => secret.provider_id === providerId);
216
+ const live = useLiveSubscriptionUsages(accountId, projectId, logins);
217
+ // A project-stored ChatGPT login has its own card below (its windows sit in
218
+ // it); a project-stored Claude login has no other row.
219
+ const legacy = providerId === 'claude-agent' ? logins.filter((secret) => secret.storage === 'project') : [];
220
+ const now = Math.max(dataUpdatedAt, live.updatedAt);
221
+ const summary = summarizeSubscriptions(live.usages, now);
222
+ const showSummary = logins.length > 1 || summary.limited > 0;
223
+ if (!showSummary && !legacy.length)
224
+ return null;
225
+ return (_jsxs("section", { className: "space-y-3", "aria-label": t('title'), "data-subscription-usage": providerId, children: [_jsx("p", { className: cn('text-foreground font-medium', compact ? 'text-xs' : 'text-sm'), children: t('title') }), showSummary ? (_jsxs("div", { className: "bg-muted/60 flex flex-wrap gap-x-8 gap-y-2 rounded-md px-3 py-2.5", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("p", { className: "text-muted-foreground text-xs", children: t('availableNow') }), _jsx("p", { className: "text-foreground text-sm font-medium tabular-nums", children: t('availableCount', { available: summary.available, total: summary.total }) })] }), summary.unknown > 0 ? (_jsxs("div", { className: "min-w-0", children: [_jsx("p", { className: "text-muted-foreground text-xs", children: t('notReported') }), _jsx("p", { className: "text-foreground text-sm font-medium tabular-nums", children: summary.unknown })] })) : null, summary.nextBack ? (_jsxs("div", { className: "min-w-0", children: [_jsx("p", { className: "text-muted-foreground text-xs", children: t('nextBack') }), _jsx("p", { className: "text-foreground text-sm font-medium tabular-nums", children: formatReset(summary.nextBack, now, locale) })] })) : null] })) : null, legacy.length ? (_jsx("ul", { className: "space-y-1", children: legacy.map((secret) => (_jsx(LegacyLogin, { accountId: accountId, projectId: projectId, secret: secret, now: now }, `${secret.storage}:${secret.secret_id}`))) })) : null] }));
226
+ }
227
+ /** The windows of the project-stored ChatGPT login, for its legacy card in the OpenAI sheet. */
228
+ export function LegacyChatGptUsage({ accountId, projectId }) {
229
+ const { logins, dataUpdatedAt } = useSubscriptionLogins(accountId, projectId);
230
+ const secret = logins.find((login) => login.provider_id === 'codex' && login.storage === 'project');
231
+ return secret ? _jsx(LegacyWindows, { accountId: accountId, projectId: projectId, secret: secret, now: dataUpdatedAt }) : null;
232
+ }
233
+ function LegacyWindows({ accountId, projectId, secret, now }) {
234
+ const t = useTranslations('subscriptionUsage');
235
+ const live = useLoginUsage(accountId, projectId, secret.secret_id, secret.storage, secret.can_use && usable(secret));
90
236
  const usage = shownUsage(live.data?.usage, secret.usage);
91
- const now = Math.max(Date.now(), live.dataUpdatedAt);
92
- if (!usage) {
93
- // Nothing to say while the first read runs; after it, say when numbers appear.
94
- return live.isFetching ? null : _jsx("span", { className: "text-muted-foreground block text-xs font-normal", children: t('usageNotSeen') });
95
- }
96
- const observed = Date.parse(usage.observed_at);
97
- return (_jsxs("div", { className: "mt-1.5 flex flex-col gap-1.5 font-normal", children: [usage.windows.map((window) => _jsx(UsageWindowMeter, { window: window, limited: usage.limited, now: now }, window.id)), now - observed > STALE_MS && (_jsx("span", { className: "text-muted-foreground text-xs", children: t('usageObserved', { time: formatReset(usage.observed_at, now, locale) }) }))] }));
237
+ const at = Math.max(now, live.dataUpdatedAt);
238
+ if (!usable(secret))
239
+ return null;
240
+ return (_jsxs("div", { className: "flex flex-col gap-2.5", "data-subscription-login": "", children: [loginLimit(usage, at).limited ? _jsx(Badge, { size: "sm", variant: "destructive", className: "self-start", children: t('limitReached') }) : null, _jsx(SubscriptionLoginWindows, { providerId: secret.provider_id, usage: usage, loading: live.isFetching, error: live.isError, now: at })] }));
98
241
  }