@hanzo/app 0.3.94 → 0.3.96

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 (110) hide show
  1. package/dist/Account.d.ts +9 -3
  2. package/dist/Account.js +142 -141
  3. package/dist/App.js +71 -37
  4. package/dist/Bar.js +1 -1
  5. package/dist/Betas.d.ts +1 -1
  6. package/dist/Betas.js +16 -22
  7. package/dist/Board.js +114 -48
  8. package/dist/CalScheduler.d.ts +1 -0
  9. package/dist/CalScheduler.js +223 -57
  10. package/dist/Chat.js +432 -153
  11. package/dist/Contacts.js +35 -31
  12. package/dist/ContextMenu.js +126 -42
  13. package/dist/Directory.js +1 -1
  14. package/dist/Drawer.js +1 -1
  15. package/dist/Drive.js +351 -119
  16. package/dist/Gate.js +156 -13
  17. package/dist/Home.js +31 -53
  18. package/dist/Inbox.js +29 -15
  19. package/dist/InlineRename.d.ts +6 -0
  20. package/dist/InlineRename.js +41 -0
  21. package/dist/Learning.js +132 -13
  22. package/dist/Market.js +13 -9
  23. package/dist/Meet.d.ts +5 -0
  24. package/dist/Meet.js +75 -51
  25. package/dist/MoreMenu.d.ts +19 -0
  26. package/dist/MoreMenu.js +33 -0
  27. package/dist/NeedMoreUsage.js +2 -2
  28. package/dist/OrgSwitcher.js +6 -2
  29. package/dist/PreferencesDialog.js +5 -2
  30. package/dist/Rail.d.ts +73 -7
  31. package/dist/Rail.js +372 -111
  32. package/dist/Recents.js +77 -24
  33. package/dist/RightPane.js +2 -2
  34. package/dist/Search.d.ts +13 -1
  35. package/dist/Search.js +366 -50
  36. package/dist/Setup.js +34 -5
  37. package/dist/Shared.js +12 -12
  38. package/dist/Shell.d.ts +10 -0
  39. package/dist/Shell.js +258 -158
  40. package/dist/Sidebar.d.ts +14 -3
  41. package/dist/Sidebar.js +411 -129
  42. package/dist/SkipLink.d.ts +8 -0
  43. package/dist/SkipLink.js +11 -0
  44. package/dist/Start.js +51 -52
  45. package/dist/Terminals.js +159 -11
  46. package/dist/ToBottom.js +1 -1
  47. package/dist/Upgrade.d.ts +8 -3
  48. package/dist/Upgrade.js +194 -103
  49. package/dist/Usage.d.ts +1 -1
  50. package/dist/Usage.js +186 -82
  51. package/dist/WalletPill.js +8 -2
  52. package/dist/Work.js +162 -53
  53. package/dist/archive.d.ts +8 -0
  54. package/dist/archive.js +16 -0
  55. package/dist/bots/Bots.js +16 -1
  56. package/dist/bots/ComputerDialog.js +53 -26
  57. package/dist/bots/ConnectorsDialog.js +34 -15
  58. package/dist/bots/Make.js +5 -1
  59. package/dist/bots/Panel.js +37 -31
  60. package/dist/bots/Roster.d.ts +4 -1
  61. package/dist/bots/Roster.js +71 -25
  62. package/dist/bots/Thread.js +54 -27
  63. package/dist/bots/face.js +9 -3
  64. package/dist/bots/grid.d.ts +36 -0
  65. package/dist/bots/grid.js +91 -0
  66. package/dist/bots/ink.d.ts +1 -1
  67. package/dist/bots/ink.js +1 -1
  68. package/dist/bots/kit.d.ts +9 -4
  69. package/dist/bots/kit.js +3 -2
  70. package/dist/chord.d.ts +13 -0
  71. package/dist/chord.js +30 -1
  72. package/dist/crew.js +47 -4
  73. package/dist/ground.d.ts +2 -2
  74. package/dist/ground.js +3 -3
  75. package/dist/help.d.ts +7 -3
  76. package/dist/help.js +19 -14
  77. package/dist/keys.d.ts +28 -0
  78. package/dist/keys.js +58 -0
  79. package/dist/lib/arrival.d.ts +5 -0
  80. package/dist/lib/arrival.js +10 -0
  81. package/dist/lib/betas.d.ts +2 -0
  82. package/dist/lib/betas.js +10 -0
  83. package/dist/lib/branch.d.ts +11 -0
  84. package/dist/lib/branch.js +11 -0
  85. package/dist/lib/chatPreferences.d.ts +1 -1
  86. package/dist/lib/chatPreferences.js +1 -1
  87. package/dist/lib/dev-mode.d.ts +18 -0
  88. package/dist/lib/dev-mode.js +102 -0
  89. package/dist/lib/durable.d.ts +1 -1
  90. package/dist/lib/durable.js +1 -1
  91. package/dist/lib/info-hint.d.ts +7 -0
  92. package/dist/lib/info-hint.js +8 -0
  93. package/dist/lib/model-picker.d.ts +2 -0
  94. package/dist/lib/model-picker.js +12 -0
  95. package/dist/lib/owners.d.ts +5 -0
  96. package/dist/lib/owners.js +15 -0
  97. package/dist/lib/pay.d.ts +2 -0
  98. package/dist/lib/pay.js +4 -0
  99. package/dist/lib/todo.d.ts +7 -1
  100. package/dist/lib/todo.js +41 -29
  101. package/dist/look.js +39 -8
  102. package/dist/rail-open.d.ts +9 -0
  103. package/dist/rail-open.js +34 -0
  104. package/dist/renaming.d.ts +10 -0
  105. package/dist/renaming.js +25 -0
  106. package/dist/seek.d.ts +6 -1
  107. package/dist/seek.js +13 -0
  108. package/dist/thread.d.ts +2 -1
  109. package/dist/thread.js +85 -44
  110. package/package.json +11 -11
package/dist/Usage.js CHANGED
@@ -1,101 +1,205 @@
1
1
  'use client';
2
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useState, useSyncExternalStore } from 'react';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
4
4
  import { useI18n } from '@hanzo/i18n/react';
5
- import { ArrowUpRight } from 'lucide-react';
6
- import { Anchor, Button, Popover, PopoverContent, PopoverTrigger, Progress, SizableText, Text, XStack, YStack } from '@hanzo/ui';
5
+ import { ArrowUpRight, Gauge, Sparkles } from 'lucide-react';
6
+ import { Anchor, Box, Popover, PopoverContent, PopoverTrigger, Progress, ProgressRing, Text, XStack, YStack, } from '@hanzo/ui';
7
7
  import { ComposerStatusProvider } from '@hanzo/ui/chat';
8
- import { UsageMeter } from '@hanzo/ui/product/UsageMeter';
8
+ import { CLASSES, classesLabel } from '@hanzo/ui/product/limits';
9
9
  import { label } from '@hanzo/build/plan';
10
10
  import { showSettings } from './open.js';
11
- import { hasSession, org, subject, bearer, scope } from './lib/session.js';
12
- import { fetchCloudUsage } from '@hanzo/usage';
13
- import { api } from './lib/api.js';
14
- import { useHost } from './host.js';
15
- import { tokensOf } from './lib/tokens.js';
11
+ import { hasSession, org, subject } from './lib/session.js';
12
+ import { cents } from './lib/org.js';
16
13
  import { payPage } from './lib/pay.js';
17
- import { useLimits } from './lib/limits.js';
14
+ import { resets, useLimits } from './lib/limits.js';
15
+ import { useTier } from './lib/tier.js';
16
+ import { rememberSettingsReturn, useDevMode } from './lib/dev-mode.js';
18
17
  import { contextOf, readTokens, subscribeTokens, tokenKey } from './lib/tokens.js';
19
- /**
20
- * A Button that is a link: `asChild` draws the Anchor with the Button's classes,
21
- * so each says what it owns — the box is the Button's (its props over its size),
22
- * the label's line the Anchor's (over the line its own size sets). gui types a
23
- * line height as a number or a token; `normal` is the value the page reads.
24
- */
25
- const LINK_BOX = { display: 'inline-flex', items: 'center', justify: 'center', height: '100%', width: '100%' };
26
- const LINK_LINE = { lineHeight: 'normal' };
27
- /** The account control, shared by Chat, Dev and Studio through the composer slot. */
18
+ const HOVER_CLOSE_MS = 150;
19
+ const STRONG = 'var(--border-strong)';
20
+ const FOCUS_RING = { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' };
21
+ /** Crisp monochrome bar color; warning/error appear only at >=85% or 100% capped. */
22
+ function barColor(percent, capped = false) {
23
+ if (capped || percent >= 100)
24
+ return 'var(--state-error)';
25
+ if (percent >= 85)
26
+ return 'var(--chrome-dot-yellow)';
27
+ return 'var(--foreground)';
28
+ }
29
+ /** Compact live usage symbol + hover breakdown shared by Chat, Dev, and Studio. */
28
30
  export function UsageControl({ context, read }) {
29
31
  const { t, format } = useI18n();
32
+ const [devMode] = useDevMode();
30
33
  const [open, setOpen] = useState(false);
34
+ const [now, setNow] = useState(() => Date.now());
35
+ const closeTimer = useRef(null);
36
+ const hoverOpenedAt = useRef(0);
37
+ const signedIn = hasSession();
31
38
  const currentOrg = org();
32
- const identity = `${currentOrg}:${subject()}`;
33
- const { path } = useHost();
34
- const run = path?.match(/^\/dev\/run\/([^/]+)/)?.[1];
35
- const [account, setAccount] = useState(null);
36
- const [runUsage, setRunUsage] = useState(null);
37
- useEffect(() => {
38
- if (!open || !currentOrg || !bearer())
39
- return;
40
- const abort = new AbortController();
41
- const scoped = (input, init) => {
42
- const headers = new Headers(init?.headers);
43
- for (const [k, v] of Object.entries(scope()))
44
- headers.set(k, v);
45
- headers.set('X-Org-Id', currentOrg);
46
- return fetch(input, { ...init, headers });
47
- };
48
- const refresh = () => {
49
- void fetchCloudUsage({ baseUrl: api(), token: bearer(), range: '30d', org: currentOrg, signal: abort.signal, fetch: scoped }).then((data) => { if (!abort.signal.aborted)
50
- setAccount(data.scope?.org === currentOrg && !data.scope.allOrgs ? { key: identity, data } : { key: identity, error: t('Account usage did not match this organization.') }); }, () => { if (!abort.signal.aborted)
51
- setAccount({ key: identity, error: t('Account usage is unavailable. See all usage to retry.') }); });
52
- if (run)
53
- void scoped(`${api()}/v1/agent/sessions/${encodeURIComponent(decodeURIComponent(run))}`, { signal: abort.signal }).then(async (response) => {
54
- if (!response.ok)
55
- return;
56
- const data = await response.json();
57
- for (const event of [...(data.recent ?? [])].reverse()) {
58
- let payload = event.payload;
59
- if (typeof payload === 'string') {
60
- try {
61
- payload = JSON.parse(payload);
62
- }
63
- catch {
64
- continue;
65
- }
66
- }
67
- const value = tokensOf(payload?.usage);
68
- if (value && !abort.signal.aborted) {
69
- setRunUsage({ key: `${identity}:${run}`, value });
70
- break;
71
- }
72
- }
73
- }).catch(() => { });
74
- };
75
- refresh();
76
- const timer = setInterval(refresh, 15000);
77
- window.addEventListener('focus', refresh);
78
- return () => { abort.abort(); clearInterval(timer); window.removeEventListener('focus', refresh); };
79
- }, [open, identity, run, t]);
80
- const aggregate = account?.key === identity ? account : null;
81
- // Chat lends its existing read. Other surfaces read only when the popover opens.
82
- const fallback = useLimits(!read && open && hasSession(), org());
39
+ const fallback = useLimits(!read && signedIn, currentOrg);
83
40
  const usage = read ?? fallback;
84
41
  const { limits, answered } = usage;
42
+ const { tier } = useTier(signedIn && Boolean(currentOrg), currentOrg);
43
+ const key = signedIn && context ? tokenKey(currentOrg, context.model, context.messages, subject() ?? '') : '';
44
+ const counted = useSyncExternalStore(subscribeTokens, () => (key ? readTokens(key) : null), () => null);
45
+ useEffect(() => {
46
+ return () => {
47
+ if (closeTimer.current)
48
+ clearTimeout(closeTimer.current);
49
+ };
50
+ }, []);
51
+ useEffect(() => {
52
+ if (!open)
53
+ return;
54
+ setNow(Date.now());
55
+ const id = setInterval(() => setNow(Date.now()), 60_000);
56
+ return () => clearInterval(id);
57
+ }, [open]);
58
+ const clearCloseTimer = () => {
59
+ if (closeTimer.current) {
60
+ clearTimeout(closeTimer.current);
61
+ closeTimer.current = null;
62
+ }
63
+ };
64
+ const handleMouseEnter = () => {
65
+ clearCloseTimer();
66
+ if (!open) {
67
+ hoverOpenedAt.current = Date.now();
68
+ setOpen(true);
69
+ if (read)
70
+ read.reload();
71
+ }
72
+ };
73
+ const handleMouseLeave = () => {
74
+ clearCloseTimer();
75
+ closeTimer.current = setTimeout(() => {
76
+ setOpen(false);
77
+ }, HOVER_CLOSE_MS);
78
+ };
79
+ if (!signedIn)
80
+ return null;
85
81
  const estimate = context ? contextOf(context.messages, context.draft, context.tools) : null;
86
- const key = context ? tokenKey(org(), context.model, context.messages, subject() ?? '') : '';
87
- const counted = useSyncExternalStore(subscribeTokens, () => readTokens(key), () => null);
88
- const tokens = counted ?? (runUsage?.key === `${identity}:${run}` ? runUsage.value : null);
89
82
  const capacity = context?.window && context.window > 0 ? context.window : null;
90
- const percent = estimate && capacity ? Math.round(estimate.total / capacity * 100) : null;
91
- const plan = limits?.plan ? label(limits.plan) : null;
92
- const highest = limits ? Math.max(0, ...Object.values(limits.classes).flatMap((c) => c ? [c.percent, ...(c.window ? [c.window.percent] : [])] : [])) : null;
93
- const title = plan ? `${plan.name}${plan.tag ? ` ${plan.tag}` : ''}` : t('Plan usage');
94
- const toggle = (on) => { setOpen(on); if (on && read)
95
- read.reload(); };
83
+ const contextPercent = estimate && capacity ? Math.round((estimate.total / capacity) * 100) : null;
84
+ const classEntries = limits ? Object.values(limits.classes).filter(Boolean) : [];
85
+ const windows = classEntries.flatMap((c) => (c?.window ? [c.window] : []));
86
+ const highestWindow = windows.length ? windows.reduce((best, w) => (w.percent > best.percent ? w : best), windows[0]) : null;
87
+ const highestWeekly = classEntries.length
88
+ ? Math.max(0, ...classEntries.map((c) => c?.percent ?? 0))
89
+ : null;
90
+ const highest = highestWindow || highestWeekly !== null
91
+ ? Math.max(highestWindow?.percent ?? 0, highestWeekly ?? 0)
92
+ : null;
93
+ const livePercent = highest !== null ? Math.round(highest) : contextPercent;
94
+ const showPercent = livePercent !== null && livePercent > 0;
95
+ const isCapped = limits?.state === 'limited' || (livePercent !== null && livePercent >= 100);
96
+ const isNear = !isCapped && livePercent !== null && livePercent >= 85;
97
+ const toneColor = isCapped
98
+ ? 'var(--state-error)'
99
+ : isNear
100
+ ? '$ink'
101
+ : '$aside';
102
+ const ringColor = isCapped
103
+ ? 'var(--state-error)'
104
+ : isNear
105
+ ? 'var(--chrome-dot-yellow)'
106
+ : showPercent
107
+ ? 'var(--foreground)'
108
+ : 'var(--text-secondary)';
109
+ const planInfo = limits?.plan
110
+ ? label(limits.plan)
111
+ : tier?.plan
112
+ ? label(tier.plan)
113
+ : null;
114
+ const planBadge = planInfo
115
+ ? `${planInfo.name}${planInfo.tag ? ` ${planInfo.tag}` : ''}`
116
+ : tier?.tier?.displayName || t('Free');
117
+ const formatReset = (iso) => {
118
+ if (!iso)
119
+ return null;
120
+ const at = Date.parse(iso);
121
+ if (Number.isFinite(at) && at > now) {
122
+ const diffMins = Math.floor((at - now) / 60_000);
123
+ if (diffMins < 1)
124
+ return t('Resets in <1m');
125
+ if (diffMins < 60)
126
+ return t('Resets in {m}m', { m: diffMins });
127
+ if (diffMins < 24 * 60) {
128
+ const hours = Math.floor(diffMins / 60);
129
+ const mins = diffMins % 60;
130
+ return mins > 0
131
+ ? t('Resets in {h}h {m}m', { h: hours, m: mins })
132
+ : t('Resets in {h}h', { h: hours });
133
+ }
134
+ const days = Math.floor(diffMins / (24 * 60));
135
+ return t('Resets in {d}d', { d: days });
136
+ }
137
+ const r = resets(iso, now, format);
138
+ if (!r)
139
+ return null;
140
+ if (r.date) {
141
+ return r.time
142
+ ? t('Resets {date} at {time}', { date: r.date, time: r.time })
143
+ : t('Resets {date}', { date: r.date });
144
+ }
145
+ return r.time ? t('Resets at {time}', { time: r.time }) : t('Resets at midnight');
146
+ };
147
+ const sessionPercent = highestWindow?.percent ?? contextPercent ?? livePercent ?? 0;
148
+ const sessionCapped = highestWindow?.state === 'limited' || sessionPercent >= 100;
149
+ const windowResetText = formatReset(highestWindow?.resets_at);
150
+ const weeklyRows = limits
151
+ ? CLASSES.flatMap((c) => {
152
+ const k = limits.classes[c];
153
+ return k ? [{ id: c, name: classesLabel([c], t), limit: k }] : [];
154
+ })
155
+ : [];
156
+ const showSafetyNet = isCapped ||
157
+ isNear ||
158
+ weeklyRows.some(({ limit }) => limit.state === 'limited' || limit.percent >= 85);
159
+ const hasCredits = typeof tier?.balance?.effectiveAvailable === 'number';
160
+ const creditsLabel = hasCredits
161
+ ? cents(tier.balance.effectiveAvailable, tier.balance.currency || 'usd')
162
+ : null;
96
163
  const integer = (n) => format.number(n, { maximumFractionDigits: 0 });
97
- const metric = (name, n) => _jsxs(XStack, { justify: "space-between", gap: "$3", children: [_jsx(Text, { fontSize: "$2", color: "$soft", children: name }), _jsx(Text, { fontSize: "$2", color: "$ink", fontVariant: ['tabular-nums'], children: _jsx("bdi", { children: integer(n) }) })] }, name);
98
- return (_jsxs(Popover, { open: open, onOpenChange: toggle, placement: "top-end", children: [_jsx(PopoverTrigger, { asChild: true, children: _jsx(XStack, { render: "button", type: 'button', items: "center", height: 28, px: 5, rounded: 8, bg: "transparent", hoverStyle: { bg: '$hover' }, transition: "quickest", cursor: "pointer", "$max-sm": { height: 36 }, "aria-label": t('Context, tokens and plan usage'), "data-slot": "composer-usage", children: _jsx(SizableText, { size: "$3", color: highest !== null && highest >= 95 ? '$bad' : '$soft', children: percent !== null ? `${percent}%` : highest !== null ? `${Math.round(highest)}%` : t('Usage') }) }) }), _jsx(PopoverContent, { solid: true, width: 360, maxW: "calc(100vw - 24px)", maxH: "min(680px, calc(100dvh - 100px))", overflowY: "auto", "aria-label": t('Context, tokens and plan usage'), "data-slot": "composer-usage-panel", children: _jsxs(YStack, { gap: "$4", minW: 0, children: [_jsxs(XStack, { justify: "space-between", items: "center", gap: "$3", children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('Usage') }), _jsxs(Button, { type: "button", size: "sm", variant: "link", onClick: () => { setOpen(false); showSettings('usage'); }, "data-slot": "composer-see-usage", children: [t('See all usage'), " ", _jsx(ArrowUpRight, { size: 13 })] })] }), context && estimate ? (_jsxs(YStack, { gap: "$2", "data-slot": "composer-context", children: [_jsxs(XStack, { justify: "space-between", gap: "$2", children: [_jsx(Text, { fontSize: "$2", fontWeight: "600", children: t('Context · estimated') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: capacity ? t('{used} / {max} tokens', { used: integer(estimate.total), max: integer(capacity) }) : t('{used} tokens', { used: integer(estimate.total) }) })] }), percent !== null ? _jsx(Progress, { value: Math.min(100, percent), height: 5, "aria-label": t('Estimated context used'), indicatorColor: percent >= 90 ? '$bad' : '$good' }) : null, estimate.rows.filter((r) => r.tokens > 0).map((r) => metric(t(r.name), r.tokens)), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Text estimate; model tokenization and attachments can change the total.') }), !capacity ? _jsx(Text, { fontSize: "$1", color: "$soft", children: t('This model does not report a context capacity.') }) : null] })) : null, _jsxs(YStack, { gap: "$2", "data-slot": "composer-reported-tokens", children: [_jsx(Text, { fontSize: "$2", fontWeight: "600", children: t('Last response · reported tokens') }), tokens ? _jsxs(_Fragment, { children: [metric(t('Input'), tokens.input), metric(t('Output'), tokens.output), tokens.cached !== undefined ? metric(t('Cached input'), tokens.cached) : null, tokens.reasoning !== undefined ? metric(t('Reasoning'), tokens.reasoning) : null, metric(t('Total'), tokens.total)] }) : _jsx(Text, { fontSize: "$2", color: "$soft", children: t('No token counts reported for this conversation yet. See all usage for account totals.') })] }), _jsxs(YStack, { gap: "$2", "data-slot": "composer-account-usage", children: [_jsx(Text, { fontSize: "$2", fontWeight: "600", children: t('Account · last 30 days') }), aggregate?.data ? _jsxs(_Fragment, { children: [metric(t('Tokens'), aggregate.data.totals.tokens), metric(t('Input'), aggregate.data.totals.promptTokens), metric(t('Output'), aggregate.data.totals.completionTokens), metric(t('Requests'), aggregate.data.totals.requests)] }) : _jsx(Text, { fontSize: "$2", color: "$soft", children: aggregate?.error ?? t('Reading account usage…') })] }), _jsxs(YStack, { gap: "$2", "data-slot": "composer-plan-usage", children: [_jsx(Text, { fontSize: "$2", fontWeight: "600", children: title }), limits ? _jsx(UsageMeter, { limits: limits, size: "sm" }) : _jsx(Text, { fontSize: "$2", color: "$soft", children: t(answered ? 'Plan usage is unavailable. Try again.' : 'Reading plan usage…') }), answered && !limits ? _jsx(Button, { type: "button", size: "sm", variant: "link", onClick: usage.reload, children: t('Retry') }) : null] }), _jsxs(XStack, { gap: "$3", justify: "space-between", flexWrap: "wrap", children: [_jsx(Button, { asChild: true, size: "sm", ...LINK_BOX, children: _jsx(Anchor, { href: payPage('/cart'), "data-slot": "composer-upgrade", ...LINK_LINE, children: t('Upgrade plan') }) }), _jsx(Button, { asChild: true, size: "sm", variant: "outline", ...LINK_BOX, children: _jsx(Anchor, { href: payPage('/amount/card'), "data-slot": "composer-buy-credits", ...LINK_LINE, children: t('Buy credits') }) })] })] }) })] }));
164
+ const toggle = (next) => {
165
+ clearCloseTimer();
166
+ setOpen(next);
167
+ if (next && read)
168
+ read.reload();
169
+ };
170
+ const openSettingsTab = (section) => {
171
+ setOpen(false);
172
+ rememberSettingsReturn();
173
+ showSettings(section);
174
+ };
175
+ return (_jsxs(Popover, { open: open, onOpenChange: toggle, placement: "top-end", allowFlip: true, stayInFrame: true, children: [_jsx(PopoverTrigger, { asChild: true, disablePressTrigger: true, children: _jsxs(XStack, { render: _jsx("button", { type: "button" }), onClick: () => {
176
+ if (open && Date.now() - hoverOpenedAt.current < 500) {
177
+ clearCloseTimer();
178
+ return;
179
+ }
180
+ toggle(!open);
181
+ }, items: "center", justify: "center", gap: "$1.5", height: 28, px: "$2", rounded: "$3", borderWidth: 1, borderColor: open ? STRONG : 'transparent', bg: open ? '$hover' : 'transparent', hoverStyle: { bg: '$hover', borderColor: STRONG }, focusVisibleStyle: FOCUS_RING, transition: "quickest", cursor: "pointer", "$max-sm": { height: 44, minH: 44 }, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, "aria-label": showPercent
182
+ ? t('Usage: {percent}% used ({plan})', { percent: livePercent, plan: planBadge })
183
+ : t('Plan usage ({plan})', { plan: planBadge }), "data-slot": "composer-usage", children: [showPercent ? (_jsx(ProgressRing, { size: "sm", value: livePercent, barColor: ringColor, "aria-label": t('{percent}% used', { percent: livePercent }) })) : (_jsx(Gauge, { size: 15, color: ringColor, "aria-hidden": true })), showPercent ? (_jsxs(Text, { fontSize: "$1", lineHeight: 14, fontWeight: "500", color: toneColor, fontVariant: ['tabular-nums'], numberOfLines: 1, children: [livePercent, "%"] })) : null] }) }), _jsx(PopoverContent, { solid: true, bg: "var(--popover)", borderWidth: 1, borderColor: STRONG, boxShadow: "var(--shadow-floating)", rounded: "$4", p: "$3", width: 260, maxW: "calc(100vw - 24px)", z: "var(--z-popover)", onMouseEnter: clearCloseTimer, onMouseLeave: handleMouseLeave, onKeyDown: (e) => {
184
+ if (e.key === 'Escape') {
185
+ e.preventDefault?.();
186
+ setOpen(false);
187
+ }
188
+ }, "aria-label": t('Usage breakdown'), "data-slot": "composer-usage-panel", children: _jsxs(YStack, { gap: "$2.5", minW: 0, children: [_jsxs(XStack, { justify: "space-between", items: "center", gap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$1.5", minW: 0, children: [_jsx(Text, { fontFamily: "$body", fontSize: "$2", fontWeight: "600", color: "$ink", children: t('Usage') }), _jsx(XStack, { px: "$1.5", py: 1, rounded: "$10", bg: "$panel", borderWidth: 1, borderColor: STRONG, items: "center", justify: "center", shrink: 0, children: _jsx(Text, { fontFamily: "$body", fontSize: "$1", fontWeight: "500", color: "$ink", numberOfLines: 1, children: planBadge }) })] }), creditsLabel ? (_jsx(Anchor, { href: payPage('/amount/card'), "data-slot": "composer-buy-credits", fontFamily: "$body", fontSize: "$1", fontWeight: "500", color: "$ink", fontVariant: ['tabular-nums'], hoverStyle: { opacity: 0.75, textDecorationLine: 'none' }, focusVisibleStyle: FOCUS_RING, textDecorationLine: "none", children: creditsLabel })) : null] }), _jsxs(YStack, { gap: "$1", "data-slot": "composer-current-window", children: [_jsxs(XStack, { justify: "space-between", items: "baseline", gap: "$2", children: [_jsx(Text, { fontFamily: "$body", fontSize: "$1", color: "$aside", children: t('Session') }), _jsxs(Text, { fontFamily: "$body", fontSize: "$1", color: "$ink", fontVariant: ['tabular-nums'], children: [Math.round(sessionPercent), "%", windowResetText ? ` · ${windowResetText.replace(/^Resets in\s+/i, '')}` : ''] })] }), _jsx(Progress, { value: Math.min(100, sessionPercent), height: 3, indicatorColor: barColor(sessionPercent, sessionCapped), "aria-label": t('Session allowance usage') })] }), (() => {
189
+ const topWeekly = weeklyRows.reduce((best, row) => (!best || row.limit.percent > best.limit.percent ? row : best), null);
190
+ if (!topWeekly)
191
+ return null;
192
+ const pct = Math.round(topWeekly.limit.percent);
193
+ const capped = topWeekly.limit.state === 'limited' || pct >= 100;
194
+ const resetLine = formatReset(topWeekly.limit.resets_at);
195
+ return (_jsxs(YStack, { gap: "$1", "data-slot": "composer-plan-usage", children: [_jsxs(XStack, { justify: "space-between", items: "baseline", gap: "$2", children: [_jsx(Text, { fontFamily: "$body", fontSize: "$1", color: "$aside", children: t('Weekly') }), _jsxs(Text, { fontFamily: "$body", fontSize: "$1", color: capped ? 'var(--state-error)' : '$ink', fontVariant: ['tabular-nums'], children: [pct, "%", resetLine ? ` · ${resetLine.replace(/^Resets in\s+/i, '')}` : ''] })] }), _jsx(Progress, { value: Math.min(100, pct), height: 3, indicatorColor: barColor(pct, capped), "aria-label": t('Weekly allowance: {percent}% used', { percent: pct }) })] }));
196
+ })(), showSafetyNet ? (_jsxs(XStack, { "data-slot": "composer-credit-safety-net", role: "status", bg: "$panel", borderWidth: 1, borderColor: STRONG, rounded: "$3", px: "$2", py: "$1.5", items: "center", justify: "space-between", gap: "$2", children: [_jsx(Text, { fontFamily: "$body", fontSize: "$1", color: "$ink", numberOfLines: 1, grow: 1, shrink: 1, children: t('Running low on allowance') }), _jsx(Box, { render: _jsx("button", { type: "button" }), "data-slot": "composer-safety-add-credits", onClick: () => {
197
+ setOpen(false);
198
+ window.location.assign(payPage('/cart'));
199
+ }, px: "$2", py: 2, rounded: "$2", bg: "$raised", borderWidth: 1, borderColor: STRONG, cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: FOCUS_RING, children: _jsx(Text, { fontFamily: "$body", fontSize: "$1", fontWeight: "600", color: "$ink", children: t('Top up') }) })] })) : null, devMode && counted ? (_jsxs(XStack, { justify: "space-between", items: "center", children: [_jsx(Text, { fontFamily: "$body", fontSize: "$1", color: "$hint", children: t('Last turn') }), _jsxs(Text, { fontFamily: "$mono", fontSize: "$1", color: "$aside", fontVariant: ['tabular-nums'], children: [integer(counted.total), " tok"] })] })) : null, _jsxs(XStack, { justify: "space-between", items: "center", pt: "$2", borderTopWidth: 1, borderColor: "$edge", gap: "$2", children: [_jsxs(XStack, { render: _jsx("button", { type: "button" }), "data-slot": "composer-upgrade", onClick: () => {
200
+ setOpen(false);
201
+ window.location.assign(payPage('/cart'));
202
+ }, items: "center", justify: "center", gap: "$1.5", px: "$2.5", py: "$1", minH: 28, "$max-sm": { minH: 40 }, rounded: "$2", bg: "var(--primary)", borderWidth: 0, cursor: "pointer", hoverStyle: { opacity: 0.9 }, focusVisibleStyle: FOCUS_RING, children: [_jsx(Sparkles, { size: 12, color: "var(--primary-foreground)", "aria-hidden": true }), _jsx(Text, { fontFamily: "$body", fontSize: "$1", fontWeight: "600", color: "var(--primary-foreground)", numberOfLines: 1, children: t('Upgrade') })] }), _jsx(XStack, { items: "center", gap: "$1", children: _jsxs(XStack, { render: _jsx("button", { type: "button" }), "data-slot": "composer-see-usage", onClick: () => openSettingsTab('usage'), items: "center", justify: "center", gap: 4, px: "$2", py: "$1", minH: 28, "$max-sm": { minH: 40 }, rounded: "$2", bg: "transparent", borderWidth: 0, cursor: "pointer", hoverStyle: { bg: '$hover' }, focusVisibleStyle: FOCUS_RING, children: [_jsx(Text, { fontFamily: "$body", fontSize: "$1", fontWeight: "500", color: "$aside", numberOfLines: 1, children: t('Details') }), _jsx(ArrowUpRight, { size: 12, color: "var(--text-secondary)", "aria-hidden": true })] }) })] })] }) })] }));
99
203
  }
100
204
  /** Every shared composer in the app gets the same account usage entry. */
101
205
  export function UsageProvider({ children }) {
@@ -8,20 +8,26 @@ import { cents } from './lib/org.js';
8
8
  import { payPage } from './lib/pay.js';
9
9
  import { org } from './lib/session.js';
10
10
  import { useTier } from './lib/tier.js';
11
+ import { useDevMode } from './lib/dev-mode.js';
11
12
  export function WalletPill({ alwaysShow = false, compact = false, }) {
12
13
  const { t } = useI18n();
14
+ const [devMode] = useDevMode();
13
15
  const { isAuthenticated } = useIam();
14
16
  const currentOrg = org();
15
17
  const { tier, wrong } = useTier(isAuthenticated && Boolean(currentOrg), currentOrg);
16
18
  if (!isAuthenticated)
17
19
  return null;
18
20
  const hasBalance = typeof tier?.balance?.effectiveAvailable === 'number';
19
- if (!alwaysShow && !hasBalance)
21
+ const positiveBalance = hasBalance && tier.balance.effectiveAvailable > 0;
22
+ // Extra credits are merged into the live UsageControl hover breakdown so compact bars don't duplicate billing pills unless Developer mode is active.
23
+ if (!alwaysShow && compact && !devMode)
24
+ return null;
25
+ if (!alwaysShow && !positiveBalance && !devMode)
20
26
  return null;
21
27
  const balance = hasBalance
22
28
  ? cents(tier.balance.effectiveAvailable, tier.balance.currency || 'usd')
23
29
  : wrong
24
30
  ? t('Wallet')
25
31
  : '…';
26
- return (_jsxs(XStack, { render: "a", href: payPage('/amount/card'), "data-slot": "wallet-pill", "aria-label": t('Wallet credits: {balance}. Add funds', { balance }), height: compact ? 26 : 30, px: compact ? 9 : 11, gap: 6, rounded: 8, items: "center", bg: "var(--pane-fill, var(--card))", borderWidth: 1, borderColor: "var(--pane-edge, var(--border))", cursor: "pointer", hoverStyle: { bg: 'var(--muted)' }, "$platform-web": { textDecoration: 'none' }, children: [_jsx(Wallet, { size: compact ? 12.5 : 13.5, color: "var(--muted-foreground)", "aria-hidden": true }), !compact ? (_jsx(Text, { fontSize: 12.5, lineHeight: 16, color: "var(--muted-foreground)", numberOfLines: 1, children: t('Credits') })) : null, _jsx(Text, { fontSize: 12.5, lineHeight: 16, fontWeight: "600", color: "var(--foreground)", numberOfLines: 1, children: balance }), !compact ? (_jsxs(XStack, { height: 20, px: 7, gap: 3, rounded: 6, items: "center", bg: "var(--secondary)", borderWidth: 1, borderColor: "var(--pane-edge, var(--border))", children: [_jsx(Plus, { size: 11, color: "var(--foreground)", "aria-hidden": true }), _jsx(Text, { fontSize: 11.5, lineHeight: 15, fontWeight: "500", color: "var(--foreground)", numberOfLines: 1, children: t('Add funds') })] })) : null] }));
32
+ return (_jsxs(XStack, { render: "a", href: payPage('/amount/card'), "data-slot": "wallet-pill", "aria-label": t('Wallet credits: {balance}. Add funds', { balance }), height: compact ? 26 : 30, px: compact ? '$2' : '$2.5', gap: "$1.5", rounded: "$3", items: "center", bg: "var(--surface-card)", borderWidth: 1, borderColor: "$edge", cursor: "pointer", hoverStyle: { bg: '$hover' }, "$platform-web": { textDecoration: 'none' }, children: [_jsx(Wallet, { size: compact ? 12 : 13, color: "var(--text-secondary)", "aria-hidden": true }), !compact ? (_jsx(Text, { fontSize: "$1", lineHeight: 16, color: "$aside", numberOfLines: 1, children: t('Credits') })) : null, _jsx(Text, { fontSize: "$1", lineHeight: 16, fontWeight: "600", color: "$ink", fontVariant: ['tabular-nums'], numberOfLines: 1, children: balance }), !compact ? (_jsxs(XStack, { height: 20, px: "$1.5", gap: "$0.5", rounded: "$2", items: "center", bg: "$raised", borderWidth: 1, borderColor: "$edge", children: [_jsx(Plus, { size: 11, color: "var(--foreground)", "aria-hidden": true }), _jsx(Text, { fontSize: "$1", lineHeight: 15, fontWeight: "500", color: "$ink", numberOfLines: 1, children: t('Add funds') })] })) : null] }));
27
33
  }