@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.
- package/dist/Account.d.ts +9 -3
- package/dist/Account.js +142 -141
- package/dist/App.js +71 -37
- package/dist/Bar.js +1 -1
- package/dist/Betas.d.ts +1 -1
- package/dist/Betas.js +16 -22
- package/dist/Board.js +114 -48
- package/dist/CalScheduler.d.ts +1 -0
- package/dist/CalScheduler.js +223 -57
- package/dist/Chat.js +432 -153
- package/dist/Contacts.js +35 -31
- package/dist/ContextMenu.js +126 -42
- package/dist/Directory.js +1 -1
- package/dist/Drawer.js +1 -1
- package/dist/Drive.js +351 -119
- package/dist/Gate.js +156 -13
- package/dist/Home.js +31 -53
- package/dist/Inbox.js +29 -15
- package/dist/InlineRename.d.ts +6 -0
- package/dist/InlineRename.js +41 -0
- package/dist/Learning.js +132 -13
- package/dist/Market.js +13 -9
- package/dist/Meet.d.ts +5 -0
- package/dist/Meet.js +75 -51
- package/dist/MoreMenu.d.ts +19 -0
- package/dist/MoreMenu.js +33 -0
- package/dist/NeedMoreUsage.js +2 -2
- package/dist/OrgSwitcher.js +6 -2
- package/dist/PreferencesDialog.js +5 -2
- package/dist/Rail.d.ts +73 -7
- package/dist/Rail.js +372 -111
- package/dist/Recents.js +77 -24
- package/dist/RightPane.js +2 -2
- package/dist/Search.d.ts +13 -1
- package/dist/Search.js +366 -50
- package/dist/Setup.js +34 -5
- package/dist/Shared.js +12 -12
- package/dist/Shell.d.ts +10 -0
- package/dist/Shell.js +258 -158
- package/dist/Sidebar.d.ts +14 -3
- package/dist/Sidebar.js +411 -129
- package/dist/SkipLink.d.ts +8 -0
- package/dist/SkipLink.js +11 -0
- package/dist/Start.js +51 -52
- package/dist/Terminals.js +159 -11
- package/dist/ToBottom.js +1 -1
- package/dist/Upgrade.d.ts +8 -3
- package/dist/Upgrade.js +194 -103
- package/dist/Usage.d.ts +1 -1
- package/dist/Usage.js +186 -82
- package/dist/WalletPill.js +8 -2
- package/dist/Work.js +162 -53
- package/dist/archive.d.ts +8 -0
- package/dist/archive.js +16 -0
- package/dist/bots/Bots.js +16 -1
- package/dist/bots/ComputerDialog.js +53 -26
- package/dist/bots/ConnectorsDialog.js +34 -15
- package/dist/bots/Make.js +5 -1
- package/dist/bots/Panel.js +37 -31
- package/dist/bots/Roster.d.ts +4 -1
- package/dist/bots/Roster.js +71 -25
- package/dist/bots/Thread.js +54 -27
- package/dist/bots/face.js +9 -3
- package/dist/bots/grid.d.ts +36 -0
- package/dist/bots/grid.js +91 -0
- package/dist/bots/ink.d.ts +1 -1
- package/dist/bots/ink.js +1 -1
- package/dist/bots/kit.d.ts +9 -4
- package/dist/bots/kit.js +3 -2
- package/dist/chord.d.ts +13 -0
- package/dist/chord.js +30 -1
- package/dist/crew.js +47 -4
- package/dist/ground.d.ts +2 -2
- package/dist/ground.js +3 -3
- package/dist/help.d.ts +7 -3
- package/dist/help.js +19 -14
- package/dist/keys.d.ts +28 -0
- package/dist/keys.js +58 -0
- package/dist/lib/arrival.d.ts +5 -0
- package/dist/lib/arrival.js +10 -0
- package/dist/lib/betas.d.ts +2 -0
- package/dist/lib/betas.js +10 -0
- package/dist/lib/branch.d.ts +11 -0
- package/dist/lib/branch.js +11 -0
- package/dist/lib/chatPreferences.d.ts +1 -1
- package/dist/lib/chatPreferences.js +1 -1
- package/dist/lib/dev-mode.d.ts +18 -0
- package/dist/lib/dev-mode.js +102 -0
- package/dist/lib/durable.d.ts +1 -1
- package/dist/lib/durable.js +1 -1
- package/dist/lib/info-hint.d.ts +7 -0
- package/dist/lib/info-hint.js +8 -0
- package/dist/lib/model-picker.d.ts +2 -0
- package/dist/lib/model-picker.js +12 -0
- package/dist/lib/owners.d.ts +5 -0
- package/dist/lib/owners.js +15 -0
- package/dist/lib/pay.d.ts +2 -0
- package/dist/lib/pay.js +4 -0
- package/dist/lib/todo.d.ts +7 -1
- package/dist/lib/todo.js +41 -29
- package/dist/look.js +39 -8
- package/dist/rail-open.d.ts +9 -0
- package/dist/rail-open.js +34 -0
- package/dist/renaming.d.ts +10 -0
- package/dist/renaming.js +25 -0
- package/dist/seek.d.ts +6 -1
- package/dist/seek.js +13 -0
- package/dist/thread.d.ts +2 -1
- package/dist/thread.js +85 -44
- package/package.json +11 -11
package/dist/Usage.js
CHANGED
|
@@ -1,101 +1,205 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
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,
|
|
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 {
|
|
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
|
|
12
|
-
import {
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
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
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
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
|
|
98
|
-
|
|
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 }) {
|
package/dist/WalletPill.js
CHANGED
|
@@ -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
|
-
|
|
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 ?
|
|
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
|
}
|