|
1 | | -import { Button } from "../../components/ui/Button"; |
2 | 1 | import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator"; |
3 | 2 | import { ChatGptUsageSummary } from "./ChatGptUsageSummary"; |
4 | 3 | import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView"; |
5 | 4 | import { EnvironmentId, USAGE_CONTRACT_VERSION, type UsageProviderKind } from "@t3tools/contracts"; |
6 | 5 | import { type RouteProp, useIsFocused, useRoute } from "@react-navigation/native"; |
7 | | -import { cursorKeychainAccessEnvironments } from "@t3tools/client-runtime/state/usage"; |
8 | 6 | import { |
9 | 7 | updatingProvidersLabel, |
10 | 8 | usageEnvironmentProgress, |
@@ -38,12 +36,9 @@ import { SegmentedControl } from "../../components/ui/SegmentedControl"; |
38 | 36 | import { useReduceMotionEnabled } from "../../lib/appState"; |
39 | 37 | import { AppText as Text } from "../../components/ui/AppText"; |
40 | 38 | import { useWorkspaceSettledContentWidth } from "../layout/workspace-content-width"; |
41 | | -import { ProviderIcon } from "../../components/ProviderIcon"; |
42 | 39 | import { cn } from "../../lib/cn"; |
43 | 40 | import { SettingsScreen } from "../settings/components/SettingsScreen"; |
44 | 41 | import { useUsage, type EnvironmentUsageStatus } from "../../state/usage"; |
45 | | -import { serverEnvironment } from "../../state/server"; |
46 | | -import { useAtomCommand } from "../../state/use-atom-command"; |
47 | 42 | import { SettingsSection } from "../settings/components/SettingsSection"; |
48 | 43 | import { UsageDailyChart } from "./UsageDailyChart"; |
49 | 44 | import { toggleUsageEnvironment } from "./usageEnvironmentSelection"; |
@@ -72,7 +67,6 @@ const WIDE_CHART_HEIGHT = 260; |
72 | 67 | const WIDE_WIDTH = 600; |
73 | 68 | const MAX_CONTENT_WIDTH = 1080; |
74 | 69 | const providerLabel = (provider: UsageProviderKind) => PROVIDER_LABEL[provider]; |
75 | | -const CURSOR_KEYCHAIN_COPY = "Requires access to your Cursor login in macOS Keychain."; |
76 | 70 |
|
77 | 71 | export function UsageRouteScreen(props: { readonly workspace?: boolean }) { |
78 | 72 | const route = useRoute<RouteProp<{ Usage: { tab?: string } | undefined }, "Usage">>(); |
@@ -114,11 +108,6 @@ function UsageScreen(props: { |
114 | 108 | ); |
115 | 109 | const isFocused = useIsFocused(); |
116 | 110 | const limits = useRefreshLimits(selectedEnvironmentIds, isFocused && view === "limits"); |
117 | | - const cursorAccessEnvironments = cursorKeychainAccessEnvironments(selectedEnvironments); |
118 | | - const refreshAfterCursorEnable = () => { |
119 | | - void refresh(); |
120 | | - void limits.refreshAfterEnable(); |
121 | | - }; |
122 | 111 | const sourceMessages = usageSourceMessages( |
123 | 112 | selectedEnvironments.flatMap((environment) => environment.summary?.sources ?? []), |
124 | 113 | ); |
@@ -183,16 +172,7 @@ function UsageScreen(props: { |
183 | 172 | isPast24Hours, |
184 | 173 | timeZone: window.timeZone, |
185 | 174 | }; |
186 | | - const providers = ( |
187 | | - <ProviderSection |
188 | | - merged={merged} |
189 | | - metric={metric} |
190 | | - cursorAccessEnvironments={cursorAccessEnvironments} |
191 | | - showCursorEnvironment={selectedEnvironments.length > 1} |
192 | | - onCursorEnabled={refreshAfterCursorEnable} |
193 | | - compact={wide} |
194 | | - /> |
195 | | - ); |
| 175 | + const providers = <ProviderSection merged={merged} metric={metric} compact={wide} />; |
196 | 176 |
|
197 | 177 | const showEnvironmentFilter = environments.length > 0 || selectedEnvironmentIds !== null; |
198 | 178 | const selectEnvironment = (value: string) => { |
@@ -291,14 +271,6 @@ function UsageScreen(props: { |
291 | 271 | failedLabels={limits.failedLabels} |
292 | 272 | selectedEnvironmentIds={selectedEnvironmentIds} |
293 | 273 | wide={wide} |
294 | | - cursorPrompt={ |
295 | | - cursorAccessEnvironments.length > 0 ? ( |
296 | | - <CursorEnableLimits |
297 | | - environments={cursorAccessEnvironments} |
298 | | - onEnabled={refreshAfterCursorEnable} |
299 | | - /> |
300 | | - ) : null |
301 | | - } |
302 | 274 | /> |
303 | 275 | ) : ( |
304 | 276 | <> |
@@ -429,105 +401,6 @@ function UsageUpdating({ |
429 | 401 | ); |
430 | 402 | } |
431 | 403 |
|
432 | | -function CursorEnableAction({ |
433 | | - environmentId, |
434 | | - label, |
435 | | - onEnabled, |
436 | | - buttonText = "Enable", |
437 | | -}: { |
438 | | - readonly environmentId: EnvironmentId; |
439 | | - readonly label: string; |
440 | | - readonly onEnabled: () => void; |
441 | | - readonly buttonText?: string; |
442 | | -}) { |
443 | | - const updateSettings = useAtomCommand(serverEnvironment.updateSettings, { |
444 | | - label: "enable Cursor account usage", |
445 | | - }); |
446 | | - const [pending, setPending] = useState(false); |
447 | | - const enable = async () => { |
448 | | - setPending(true); |
449 | | - const result = await updateSettings({ |
450 | | - environmentId, |
451 | | - input: { patch: { cursorKeychainUsageEnabled: true } }, |
452 | | - }).finally(() => setPending(false)); |
453 | | - if (result._tag === "Success") onEnabled(); |
454 | | - }; |
455 | | - return ( |
456 | | - <Button |
457 | | - label={buttonText} |
458 | | - tone="primary" |
459 | | - accessibilityLabel={`Enable Cursor usage from ${label}`} |
460 | | - accessibilityHint={CURSOR_KEYCHAIN_COPY} |
461 | | - disabled={pending} |
462 | | - onPress={() => void enable()} |
463 | | - loading={pending} |
464 | | - /> |
465 | | - ); |
466 | | -} |
467 | | - |
468 | | -function CursorEnableRow({ |
469 | | - environmentId, |
470 | | - label, |
471 | | - showEnvironment, |
472 | | - bordered, |
473 | | - onEnabled, |
474 | | -}: { |
475 | | - readonly environmentId: EnvironmentId; |
476 | | - readonly label: string; |
477 | | - readonly showEnvironment: boolean; |
478 | | - readonly bordered: boolean; |
479 | | - readonly onEnabled: () => void; |
480 | | -}) { |
481 | | - const colors = useProviderColors(); |
482 | | - return ( |
483 | | - <View |
484 | | - className={cn( |
485 | | - "flex-row items-center justify-between gap-3 p-4", |
486 | | - bordered && "border-t border-border-subtle", |
487 | | - )} |
488 | | - > |
489 | | - <View className="min-w-0 flex-1 flex-row items-center gap-2"> |
490 | | - <View className="size-2.5 rounded-full" style={{ backgroundColor: colors.cursor }} /> |
491 | | - <Text className="shrink text-lg text-foreground"> |
492 | | - Cursor{showEnvironment ? ` · ${label}` : ""} |
493 | | - </Text> |
494 | | - </View> |
495 | | - <CursorEnableAction environmentId={environmentId} label={label} onEnabled={onEnabled} /> |
496 | | - </View> |
497 | | - ); |
498 | | -} |
499 | | - |
500 | | -function CursorEnableLimits({ |
501 | | - environments, |
502 | | - onEnabled, |
503 | | -}: { |
504 | | - readonly environments: readonly EnvironmentUsageStatus[]; |
505 | | - readonly onEnabled: () => void; |
506 | | -}) { |
507 | | - return ( |
508 | | - <View className="gap-3"> |
509 | | - <View className="flex-row items-center gap-2 px-1"> |
510 | | - <ProviderIcon provider="cursor" size={18} /> |
511 | | - <Text className="text-base font-t3-medium text-foreground">Cursor</Text> |
512 | | - </View> |
513 | | - <View className="items-start gap-3 rounded-[24px] border-continuous bg-grouped-card p-4"> |
514 | | - <Text className="text-xs text-foreground-muted">{CURSOR_KEYCHAIN_COPY}</Text> |
515 | | - <View className="flex-row flex-wrap gap-2"> |
516 | | - {environments.map((environment) => ( |
517 | | - <CursorEnableAction |
518 | | - key={environment.environmentId} |
519 | | - environmentId={environment.environmentId} |
520 | | - label={environment.label} |
521 | | - buttonText={environments.length > 1 ? `Enable on ${environment.label}` : "Enable"} |
522 | | - onEnabled={onEnabled} |
523 | | - /> |
524 | | - ))} |
525 | | - </View> |
526 | | - </View> |
527 | | - </View> |
528 | | - ); |
529 | | -} |
530 | | - |
531 | 404 | function ChartCard(props: { |
532 | 405 | readonly merged: MergedUsage; |
533 | 406 | readonly days: readonly string[]; |
@@ -632,54 +505,21 @@ function UsageSummary(props: { readonly merged: MergedUsage; readonly metric: Us |
632 | 505 | function ProviderSection(props: { |
633 | 506 | readonly merged: MergedUsage; |
634 | 507 | readonly metric: UsageChartMetric; |
635 | | - readonly cursorAccessEnvironments: readonly EnvironmentUsageStatus[]; |
636 | | - readonly showCursorEnvironment: boolean; |
637 | | - readonly onCursorEnabled: () => void; |
638 | 508 | /** Drops the share bar so the list fits beside the chart. */ |
639 | 509 | readonly compact: boolean; |
640 | 510 | }) { |
641 | 511 | const { merged, metric } = props; |
642 | 512 | const colors = useProviderColors(); |
643 | | - if (merged.providers.length === 0 && props.cursorAccessEnvironments.length === 0) return null; |
| 513 | + if (merged.providers.length === 0) return null; |
644 | 514 |
|
645 | 515 | // Hermes lacks toSorted. |
646 | 516 | const ordered = [...merged.providers].sort((a, b) => |
647 | 517 | metric === "cost" ? b.costUsd - a.costUsd : b.totalTokens - a.totalTokens, |
648 | 518 | ); |
649 | | - const rows: Array< |
650 | | - | { readonly kind: "usage"; readonly provider: (typeof ordered)[number] } |
651 | | - | { readonly kind: "enable"; readonly environment: EnvironmentUsageStatus } |
652 | | - > = ordered.map((provider) => ({ kind: "usage", provider })); |
653 | | - const cursorInsertAt = |
654 | | - Math.max( |
655 | | - ordered.findIndex((provider) => provider.provider === "codex"), |
656 | | - ordered.findIndex((provider) => provider.provider === "claude"), |
657 | | - ) + 1; |
658 | | - rows.splice( |
659 | | - cursorInsertAt, |
660 | | - 0, |
661 | | - ...props.cursorAccessEnvironments.map((environment) => ({ |
662 | | - kind: "enable" as const, |
663 | | - environment, |
664 | | - })), |
665 | | - ); |
666 | 519 |
|
667 | 520 | return ( |
668 | 521 | <SettingsSection title="Providers"> |
669 | | - {rows.map((row, index) => { |
670 | | - if (row.kind === "enable") { |
671 | | - return ( |
672 | | - <CursorEnableRow |
673 | | - key={`enable:${row.environment.environmentId}`} |
674 | | - environmentId={row.environment.environmentId} |
675 | | - label={row.environment.label} |
676 | | - showEnvironment={props.showCursorEnvironment} |
677 | | - bordered={index > 0} |
678 | | - onEnabled={props.onCursorEnabled} |
679 | | - /> |
680 | | - ); |
681 | | - } |
682 | | - const provider = row.provider; |
| 522 | + {ordered.map((provider, index) => { |
683 | 523 | const share = metric === "cost" ? provider.costShare : provider.tokenShare; |
684 | 524 | return ( |
685 | 525 | <View |
|
0 commit comments