@hanzo/app 0.2.46 → 0.2.48
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/App.js +6 -5
- package/dist/Chat.js +5 -1
- package/dist/Me.js +2 -2
- package/dist/Setup.js +38 -2
- package/dist/Usage.d.ts +18 -0
- package/dist/Usage.js +95 -0
- package/dist/lib/served.js +23 -6
- package/dist/lib/tokens.d.ts +30 -0
- package/dist/lib/tokens.js +66 -0
- package/package.json +3 -3
package/dist/App.js
CHANGED
|
@@ -68,6 +68,7 @@ import { Builder, HostProvider, PrefsProvider, route, tabs } from '@hanzo/build'
|
|
|
68
68
|
import { nav as places } from '@hanzo/studio';
|
|
69
69
|
import { useAi } from './lib/ai.js';
|
|
70
70
|
import { Chat } from './Chat.js';
|
|
71
|
+
import { UsageProvider } from './Usage.js';
|
|
71
72
|
import { Column } from './Column.js';
|
|
72
73
|
import { Learning } from './Learning.js';
|
|
73
74
|
import { isPlans, leave, useDevHost } from './dev.js';
|
|
@@ -270,9 +271,9 @@ function Window({ bar, betas }) {
|
|
|
270
271
|
shut();
|
|
271
272
|
setFinding(true);
|
|
272
273
|
};
|
|
273
|
-
return (_jsx(AiProvider, { client: client ?? undefined, children: _jsx(HostProvider, { host: host, children: _jsx(PrefsProvider, { children: _jsxs(YStack, { ref: windowRef, "data-slot": "window", ...(bar ? floor : null), flex: 1, minW: 0, height: bar ? '100%' : '100dvh', overflow: "hidden", rounded: bar ? '$3' : undefined, "$max-md": { position: 'fixed', t: TOP, l: 0, r: 0, height: HEIGHT, ...{ overflow: 'clip' } }, children: [bar ? (_jsxs(XStack, { "data-slot": "title-bar", height: BAR, shrink: 0, items: "center", gap: 2, pl: (bar.inset ?? 0) + 6, pr: "$2", onMouseDown: dragWindow, onDoubleClick: toggleWindowMaximize, ...bar.drag, children: [_jsx(XStack, { "$max-md": { display: 'none' }, children: _jsx(Toggle, { open: !closed, onPress: flip }) }), _jsx(XStack, { $md: { display: 'none' }, children: _jsx(Toggle, { open: drawer.state === 'open', onPress: drawer.open, label: t('Open sidebar') }) }), _jsx(Mark, { label: t('Back'), "data-slot": "back", onPress: () => router.back(), children: _jsx(ArrowLeft, { size: 18, "aria-hidden": true, "data-i18n-mirror": true }) }), _jsx(Mark, { label: t('Forward'), "data-slot": "forward", onPress: () => router.forward(), children: _jsx(ArrowRight, { size: 18, "aria-hidden": true, "data-i18n-mirror": true }) }), _jsx(XStack, { flex: 1, self: "stretch", ...bar.drag }), bar.controls !== undefined ? (bar.controls) : !bar.inset ? (_jsx(WindowControls, {})) : null] })) : null, _jsxs(XStack, { ref: drawer.pane, "data-room": "", "data-app": mode, "data-slot": "frame", ...(bar ? null : floor), ...(drawer.slide ? RAISED : null),
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
274
|
+
return (_jsx(AiProvider, { client: client ?? undefined, children: _jsx(HostProvider, { host: host, children: _jsx(PrefsProvider, { children: _jsx(UsageProvider, { children: _jsxs(YStack, { ref: windowRef, "data-slot": "window", ...(bar ? floor : null), flex: 1, minW: 0, height: bar ? '100%' : '100dvh', overflow: "hidden", rounded: bar ? '$3' : undefined, "$max-md": { position: 'fixed', t: TOP, l: 0, r: 0, height: HEIGHT, ...{ overflow: 'clip' } }, children: [bar ? (_jsxs(XStack, { "data-slot": "title-bar", height: BAR, shrink: 0, items: "center", gap: 2, pl: (bar.inset ?? 0) + 6, pr: "$2", onMouseDown: dragWindow, onDoubleClick: toggleWindowMaximize, ...bar.drag, children: [_jsx(XStack, { "$max-md": { display: 'none' }, children: _jsx(Toggle, { open: !closed, onPress: flip }) }), _jsx(XStack, { $md: { display: 'none' }, children: _jsx(Toggle, { open: drawer.state === 'open', onPress: drawer.open, label: t('Open sidebar') }) }), _jsx(Mark, { label: t('Back'), "data-slot": "back", onPress: () => router.back(), children: _jsx(ArrowLeft, { size: 18, "aria-hidden": true, "data-i18n-mirror": true }) }), _jsx(Mark, { label: t('Forward'), "data-slot": "forward", onPress: () => router.forward(), children: _jsx(ArrowRight, { size: 18, "aria-hidden": true, "data-i18n-mirror": true }) }), _jsx(XStack, { flex: 1, self: "stretch", ...bar.drag }), bar.controls !== undefined ? (bar.controls) : !bar.inset ? (_jsx(WindowControls, {})) : null] })) : null, _jsxs(XStack, { ref: drawer.pane, "data-room": "", "data-app": mode, "data-slot": "frame", ...(bar ? null : floor), ...(drawer.slide ? RAISED : null),
|
|
275
|
+
// inline-style: the slide, a transform with no logical form whose sign and distance the drawer writes on the element itself, a drag every frame (Drawer.tsx).
|
|
276
|
+
style: drawer.slide ?? undefined, flex: 1, minW: 0, minH: 0, paddingInlineEnd: "var(--pane-gap)", pb: "var(--pane-gap)",
|
|
277
|
+
// The gap above the pane is the gap at its end and foot; a window's own bar above it is that gap.
|
|
278
|
+
pt: bar ? 0 : 'var(--pane-gap)', "$max-md": { p: 0 }, children: [drawer.slide ? _jsx(Lift, {}) : null, _jsx(YStack, { height: "100%", "$max-md": { display: 'none' }, children: _jsx(Rail, { host: host, mode: mode, at: where, inside: inside, open: !closed, toggle: bar ? undefined : flip, onChat: toChat, onDev: toDev, onStudio: toStudio, onTabs: toTabs, go: move, onOrg: org }) }), closed || alone ? null : (_jsx(YStack, { "$max-md": { display: 'none' }, children: _jsx(Column, { host: host, mode: mode, thread: thread, go: move, onShut: () => setClosed(true), onSeek: seek, onBack: back, places: sidebar }) })), _jsxs(YStack, { "data-slot": "stage", flex: 1, minW: 0, minH: 0, marginInlineStart: closed || alone ? 0 : 'var(--pane-gap)', "$max-md": { marginInlineStart: 0, pb: `max(var(--pane-gap), ${FOOT})` }, children: [bar ? null : _jsx(Top, { host: host, mode: mode, places: sidebar, open: drawer.state !== 'shut', go: move, onMenu: drawer.open, onChat: toChat, onDev: toDev }), _jsx(XStack, { "data-slot": "panes", flex: 1, minW: 0, minH: 0, children: mode === 'chat' ? (_jsx(Paned, { framed: true, children: _jsx(Chat, {}) })) : mode === 'tabs' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(Suspense, { fallback: null, children: _jsx(Terminals, {}) }) })) : mode === 'studio' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(YStack, { flex: 1, minH: 0, height: "100%", children: _jsx(Suspense, { fallback: null, children: _jsx(Studio, { host: maker, rail: false }) }) }) })) : at.mode === 'hosted' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflow: "hidden", flex: 1, minW: 0, minH: 0, children: _jsx(Suspense, { fallback: null, children: _jsx(Hosted, { id: at.id, go: move }) }) })) : mode === 'beta' ? (_jsx(YStack, { render: "main", "data-slot": "pane", ...pane(), overflowY: "auto", overflowX: "hidden", flex: 1, minW: 0, minH: 0, p: "$4", $md: { p: '$6' }, children: betas ?? (_jsx(Suspense, { fallback: null, children: _jsx(Betas, { go: move }) })) })) : (_jsx(YStack, { render: "main", "data-slot": "pane", ...(run ? null : { ...pane(), overflow: 'hidden' }), flex: 1, minW: 0, minH: 0, children: plans ? null : _jsx(Builder, { host: host, rail: false }) })) })] })] }), drawer.state === 'shut' ? null : (_jsx(Layer, { drawer: drawer, top: bar ? BAR : 0, children: _jsxs(XStack, { flex: 1, minH: 0, children: [_jsx(YStack, { "data-slot": "drawer-rail", shrink: 0, pt: "$2", children: _jsx(Rail, { host: host, mode: mode, at: where, inside: inside, open: true, onChat: toChat, onDev: toDev, onStudio: toStudio, onTabs: toTabs, go: move, onOrg: org }) }), _jsx(YStack, { flex: 1, minW: 0, children: _jsx(Column, { host: host, mode: mode, thread: thread, go: move, onShut: shut, onSeek: seek, onBack: back, drawer: true, places: sidebar }) })] }) })), finding ? _jsx(Palette, { go: move, onClose: found, mode: mode, host: host }) : null, learning ? _jsx(Learning, { open: true, onClose: () => setLearning(false) }) : null] }) }) }) }) }));
|
|
278
279
|
}
|
package/dist/Chat.js
CHANGED
|
@@ -75,6 +75,7 @@ import { first } from './lib/first.js';
|
|
|
75
75
|
import { BAD } from "./lib/mix.js";
|
|
76
76
|
import { brand } from './where.js';
|
|
77
77
|
import { BAND } from './ground.js';
|
|
78
|
+
import { UsageControl } from './Usage.js';
|
|
78
79
|
import { shared, useChatPreferences } from './lib/chatPreferences.js';
|
|
79
80
|
import { handleHint } from './hint.js';
|
|
80
81
|
// NO REASONING PANEL HERE. Every assistant turn opened a "Thinking" disclosure
|
|
@@ -503,7 +504,8 @@ function Thread({ placeholder = message(), initial, anonymous = false, heading,
|
|
|
503
504
|
// THE PLAN decides what the chip may offer: Free answers from the free lane
|
|
504
505
|
// alone, so it opens there and lists the rest as upgrades (@hanzo/build).
|
|
505
506
|
const catalog = useRef([]);
|
|
506
|
-
const
|
|
507
|
+
const planUsage = useLimits(!anonymous, org(), (id) => nameOf(id, catalog.current));
|
|
508
|
+
const { limits, notice, reload: reread } = planUsage;
|
|
507
509
|
const mind = useMind(target, anonymous ? "free" : limits?.plan);
|
|
508
510
|
catalog.current = mind.models;
|
|
509
511
|
// Chat's effort is its own (six steps, sent as `reasoning_effort`); a
|
|
@@ -751,6 +753,7 @@ function Thread({ placeholder = message(), initial, anonymous = false, heading,
|
|
|
751
753
|
// before the model is asked and asks without them, so a question about the
|
|
752
754
|
// world, in any language, is answered from what the web says now and streams.
|
|
753
755
|
params: {
|
|
756
|
+
stream_options: { include_usage: true },
|
|
754
757
|
reasoning_effort: chatPrefs.effort || 'high',
|
|
755
758
|
...(!anonymous && house(rowOf(model)?.family) ? { tools: WEB } : {}),
|
|
756
759
|
},
|
|
@@ -1473,6 +1476,7 @@ function Thread({ placeholder = message(), initial, anonymous = false, heading,
|
|
|
1473
1476
|
// Chat keeps to the effort alone until the person asks for more: the family chips, the mode.
|
|
1474
1477
|
chips: anonymous ? undefined : families,
|
|
1475
1478
|
defaults: { chips: false, mode: false },
|
|
1479
|
+
status: anonymous ? null : _jsx(UsageControl, { read: planUsage, context: { model, window: rowOf(model)?.context_window, messages: chat.messages, draft, tools: !anonymous && house(rowOf(model)?.family) ? WEB : undefined } }),
|
|
1476
1480
|
limits,
|
|
1477
1481
|
onUpgrade: (id) => setAsk({ model: nameOf(id, listed) }),
|
|
1478
1482
|
voice,
|
package/dist/Me.js
CHANGED
|
@@ -36,7 +36,7 @@ import { phrase, locales } from '@hanzo/i18n';
|
|
|
36
36
|
import { useI18n } from '@hanzo/i18n/react';
|
|
37
37
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
38
38
|
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
39
|
-
import { ArrowUpRight, BookOpen, Building2, Check, ChevronsUpDown, CircleHelp, CircleUserRound, Download, FileText, FlaskConical, Info, Keyboard, Languages, LifeBuoy, LogOut, MessagesSquare, Palette, Plus, ScrollText, Settings, ShieldCheck, Sparkles, Users, X, } from 'lucide-react';
|
|
39
|
+
import { ArrowUpRight, Activity, BookOpen, Building2, Check, ChevronsUpDown, CircleHelp, CircleUserRound, Download, FileText, FlaskConical, Info, Keyboard, Languages, LifeBuoy, LogOut, MessagesSquare, Palette, Plus, ScrollText, Settings, ShieldCheck, Sparkles, Users, X, } from 'lucide-react';
|
|
40
40
|
import { label, Meter, said as spoken, useStanding } from '@hanzo/build';
|
|
41
41
|
import { useOrganizations } from '@hanzo/iam/react';
|
|
42
42
|
import { Button, Dialog, DialogContent, DialogTitle, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Input, Kbd, } from '@hanzo/ui';
|
|
@@ -223,7 +223,7 @@ export function Me({ host, narrow = false, above = false, onOrg, defaultAccountO
|
|
|
223
223
|
$touchable: narrow ? { width: 44, minH: 44 } : undefined, px: narrow ? 0 : '$2', gap: "$2.5", rounded: narrow ? 999 : '$5', borderWidth: narrow && above ? 1 : 0, borderColor: narrow && above ? 'var(--border-strong)' : undefined, bg: narrow && above ? 'var(--pane-fill)' : undefined, items: "center", justify: narrow ? 'center' : 'flex-start', hoverStyle: { bg: '$hover' }, focusVisibleStyle: { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' }, cursor: "pointer", children: [_jsx(Face, { host: host, size: narrow ? (above ? 32 : 26) : 32 }), narrow ? null : (_jsxs(_Fragment, { children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$3", fontWeight: "600", color: "$ink", numberOfLines: 1, text: "start", children: who }), working ? (_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, text: "start", children: working })) : null] }), isFree ? (_jsx(Button, { size: "xs", variant: "outline", "data-slot": "me-upgrade", px: "$2", py: "$0.5", rounded: "$3", onPress: (e) => {
|
|
224
224
|
e?.stopPropagation?.();
|
|
225
225
|
getPro();
|
|
226
|
-
}, cursor: "pointer", children: t('Upgrade plan') })) : null, _jsx(ChevronsUpDown, { size: 14, "aria-hidden": true, opacity: 0.6 })] }))] }) }), _jsxs(DropdownMenuContent, { minW: 260, maxW: "calc(100vw - 16px)", "aria-labelledby": undefined, "aria-label": t('Account'), onCloseAutoFocus: back, children: [_jsxs(DropdownMenuSub, { open: account, onOpenChange: setAccount, children: [_jsxs(DropdownMenuSubTrigger, { minH: 48, gap: "$2.5", "data-slot": "me-account", children: [_jsx(Face, { host: host, size: 28 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: who }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: host.person.email || working })] })] }), account ? (_jsxs(DropdownMenuSubContent, { minW: 240, maxW: "calc(100vw - 16px)", pointerEvents: "auto", children: [_jsx(Meter, { read: read, onPlans: () => leave('here'), onBilling: () => (setOpen(false), showSettings('billing')) }), _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { onSelect: () => showSettings('account'), children: _jsx(Line, { icon: _jsx(CircleUserRound, { size: 16, "aria-hidden": true }), children: t('Profile') }) }), _jsx(DropdownMenuItem, { onSelect: () => showSettings('general'), children: _jsx(Line, { icon: _jsx(Palette, { size: 16, "aria-hidden": true }), children: t('Personalization') }) }), _jsx(DropdownMenuItem, { "aria-keyshortcuts": "Control+, Meta+,", onSelect: () => showSettings('general'), children: _jsx(Line, { icon: _jsx(Settings, { size: 16, "aria-hidden": true }), trail: _jsx(DropdownMenuShortcut, { "aria-hidden": true, children: _jsx("bdi", { dir: "ltr", children: apple ? '⌘,' : 'Ctrl+,' }) }), children: t('Settings') }) }), _jsx(DropdownMenuItem, { onSelect: () => window.location.assign(site('/beta')), children: _jsx(Line, { icon: _jsx(FlaskConical, { size: 16, "aria-hidden": true }), children: t('Beta') }) })] })) : null] }), _jsxs(DropdownMenuSub, { open: orgs, onOpenChange: setOrgs, children: [_jsx(DropdownMenuSubTrigger, { "data-slot": "me-orgs", children: _jsx(Line, { icon: _jsx(Mark, { org: here ?? all[0] }), trail: _jsx(Check, { size: 16, "aria-label": t('Current') }), children: t('{org} · {plan}', { org: (here ? (here.personal ? t('Personal') : here.display) : current), plan: planName || t('No plan') }) }) }), orgs ? (_jsxs(DropdownMenuSubContent, { minW: 260, maxW: "calc(100vw - 16px)", pointerEvents: "auto", children: [_jsx(DropdownMenuLabel, { children: t('Organizations') }), all.map((o) => (_jsx(DropdownMenuItem, { onSelect: () => o.name !== current && onOrg(o.name), children: _jsx(Line, { icon: _jsx(Mark, { org: o }), sub: [o.personal ? t('Personal') : said(o.role, t), planFor(o) || (isFree && o.personal ? t('Free') : '')].filter(Boolean).join(' - '), trail: o.name === current ? _jsx(Check, { size: 16, "aria-label": t('Current') }) : null, children: o.display }) }, o.name))), _jsx(DropdownMenuItem, { onSelect: () => setCreating(true), children: _jsx(Line, { icon: _jsx(Plus, { size: 16, "aria-hidden": true }), children: t('Create organization') }) }), _jsx(DropdownMenuItem, { onSelect: () => out(site(settings('organization'))), children: _jsx(Line, { icon: _jsx(Settings, { size: 16, "aria-hidden": true }), children: t('Organization settings') }) }), where().team ? null : here && !here.personal ? (_jsx(DropdownMenuItem, { onSelect: () => out(`${ENTRY}&org=${encodeURIComponent(here.name)}`), children: _jsx(Line, { icon: _jsx(Users, { size: 16, "aria-hidden": true }), trail: _jsx(ArrowUpRight, { size: 14, "aria-hidden": true, opacity: 0.6 }), children: t('Open in Hanzo Team') }) })) : (_jsx(DropdownMenuItem, { onSelect: () => setCreating(true), children: _jsx(Line, { icon: _jsx(Users, { size: 16, "aria-hidden": true }), children: t('Create a team') }) })), superAdmin() ? (_jsx(DropdownMenuItem, { onSelect: choose, children: _jsx(Line, { icon: _jsx(Building2, { size: 16, "aria-hidden": true }), children: t('All organizations') }) })) : null] })) : null] }), _jsx(DropdownMenuItem, { onSelect: () => leave('here'), children: _jsx(Line, { icon: _jsx(Sparkles, { size: 16, "aria-hidden": true }), children: t(plans) }) }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuSub, { open: lang, onOpenChange: (next) => {
|
|
226
|
+
}, cursor: "pointer", children: t('Upgrade plan') })) : null, _jsx(ChevronsUpDown, { size: 14, "aria-hidden": true, opacity: 0.6 })] }))] }) }), _jsxs(DropdownMenuContent, { minW: 260, maxW: "calc(100vw - 16px)", "aria-labelledby": undefined, "aria-label": t('Account'), onCloseAutoFocus: back, children: [_jsxs(DropdownMenuSub, { open: account, onOpenChange: setAccount, children: [_jsxs(DropdownMenuSubTrigger, { minH: 48, gap: "$2.5", "data-slot": "me-account", children: [_jsx(Face, { host: host, size: 28 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: who }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: host.person.email || working })] })] }), account ? (_jsxs(DropdownMenuSubContent, { minW: 240, maxW: "calc(100vw - 16px)", pointerEvents: "auto", children: [_jsx(Meter, { read: read, onPlans: () => leave('here'), onBilling: () => (setOpen(false), showSettings('billing')) }), _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { onSelect: () => showSettings('account'), children: _jsx(Line, { icon: _jsx(CircleUserRound, { size: 16, "aria-hidden": true }), children: t('Profile') }) }), _jsx(DropdownMenuItem, { onSelect: () => showSettings('general'), children: _jsx(Line, { icon: _jsx(Palette, { size: 16, "aria-hidden": true }), children: t('Personalization') }) }), _jsx(DropdownMenuItem, { "aria-keyshortcuts": "Control+, Meta+,", onSelect: () => showSettings('general'), children: _jsx(Line, { icon: _jsx(Settings, { size: 16, "aria-hidden": true }), trail: _jsx(DropdownMenuShortcut, { "aria-hidden": true, children: _jsx("bdi", { dir: "ltr", children: apple ? '⌘,' : 'Ctrl+,' }) }), children: t('Settings') }) }), _jsx(DropdownMenuItem, { onSelect: () => window.location.assign(site('/beta')), children: _jsx(Line, { icon: _jsx(FlaskConical, { size: 16, "aria-hidden": true }), children: t('Beta') }) })] })) : null] }), _jsxs(DropdownMenuSub, { open: orgs, onOpenChange: setOrgs, children: [_jsx(DropdownMenuSubTrigger, { "data-slot": "me-orgs", children: _jsx(Line, { icon: _jsx(Mark, { org: here ?? all[0] }), trail: _jsx(Check, { size: 16, "aria-label": t('Current') }), children: t('{org} · {plan}', { org: (here ? (here.personal ? t('Personal') : here.display) : current), plan: planName || t('No plan') }) }) }), orgs ? (_jsxs(DropdownMenuSubContent, { minW: 260, maxW: "calc(100vw - 16px)", pointerEvents: "auto", children: [_jsx(DropdownMenuLabel, { children: t('Organizations') }), all.map((o) => (_jsx(DropdownMenuItem, { onSelect: () => o.name !== current && onOrg(o.name), children: _jsx(Line, { icon: _jsx(Mark, { org: o }), sub: [o.personal ? t('Personal') : said(o.role, t), planFor(o) || (isFree && o.personal ? t('Free') : '')].filter(Boolean).join(' - '), trail: o.name === current ? _jsx(Check, { size: 16, "aria-label": t('Current') }) : null, children: o.display }) }, o.name))), _jsx(DropdownMenuItem, { onSelect: () => setCreating(true), children: _jsx(Line, { icon: _jsx(Plus, { size: 16, "aria-hidden": true }), children: t('Create organization') }) }), _jsx(DropdownMenuItem, { onSelect: () => out(site(settings('organization'))), children: _jsx(Line, { icon: _jsx(Settings, { size: 16, "aria-hidden": true }), children: t('Organization settings') }) }), where().team ? null : here && !here.personal ? (_jsx(DropdownMenuItem, { onSelect: () => out(`${ENTRY}&org=${encodeURIComponent(here.name)}`), children: _jsx(Line, { icon: _jsx(Users, { size: 16, "aria-hidden": true }), trail: _jsx(ArrowUpRight, { size: 14, "aria-hidden": true, opacity: 0.6 }), children: t('Open in Hanzo Team') }) })) : (_jsx(DropdownMenuItem, { onSelect: () => setCreating(true), children: _jsx(Line, { icon: _jsx(Users, { size: 16, "aria-hidden": true }), children: t('Create a team') }) })), superAdmin() ? (_jsx(DropdownMenuItem, { onSelect: choose, children: _jsx(Line, { icon: _jsx(Building2, { size: 16, "aria-hidden": true }), children: t('All organizations') }) })) : null] })) : null] }), _jsx(DropdownMenuItem, { onSelect: () => showSettings('usage'), children: _jsx(Line, { icon: _jsx(Activity, { size: 16, "aria-hidden": true }), children: t('Usage') }) }), _jsx(DropdownMenuItem, { onSelect: () => leave('here'), children: _jsx(Line, { icon: _jsx(Sparkles, { size: 16, "aria-hidden": true }), children: t(plans) }) }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuSub, { open: lang, onOpenChange: (next) => {
|
|
227
227
|
setLang(next);
|
|
228
228
|
if (!next)
|
|
229
229
|
setLangQuery('');
|
package/dist/Setup.js
CHANGED
|
@@ -59,6 +59,8 @@ export function Setup({ go } = {}) {
|
|
|
59
59
|
const [busy, setBusy] = useState(null);
|
|
60
60
|
const [modalOpen, setModalOpen] = useState(false);
|
|
61
61
|
const [errorMsg, setErrorMsg] = useState(null);
|
|
62
|
+
// A first press on Disconnect asks; the second lets go of GitHub.
|
|
63
|
+
const [dropping, setDropping] = useState(false);
|
|
62
64
|
const [syncTurn, setSyncTurn] = useState(0);
|
|
63
65
|
const signed = isAuthenticated && Boolean(accessToken);
|
|
64
66
|
const accountList = Array.isArray(googleAccounts) ? googleAccounts : [];
|
|
@@ -281,6 +283,40 @@ export function Setup({ go } = {}) {
|
|
|
281
283
|
setGithubDone(true);
|
|
282
284
|
setStep(slackDone ? 3 : 2);
|
|
283
285
|
});
|
|
286
|
+
// Let go of the org's GitHub accounts, so another can be connected. The platform
|
|
287
|
+
// also removes its App from an account no other organization uses, so the next
|
|
288
|
+
// connect is a fresh install. An org admin's act: anyone else is told so.
|
|
289
|
+
const handleDisconnectGithub = async () => {
|
|
290
|
+
if (!dropping) {
|
|
291
|
+
setDropping(true);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
setBusy('github');
|
|
295
|
+
setErrorMsg(null);
|
|
296
|
+
try {
|
|
297
|
+
const res = await fetch(`${api()}/v1/provider/github/disconnect`, {
|
|
298
|
+
method: 'POST',
|
|
299
|
+
headers: { ...scope(), 'Content-Type': 'application/json' },
|
|
300
|
+
body: '{}',
|
|
301
|
+
});
|
|
302
|
+
if (!res.ok) {
|
|
303
|
+
setErrorMsg(res.status === 403
|
|
304
|
+
? t('Only an organization admin can disconnect GitHub.')
|
|
305
|
+
: t('Could not disconnect {provider} right now. Please try again.', { provider: 'GitHub' }));
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
setGithubDone(false);
|
|
309
|
+
setStep(1);
|
|
310
|
+
setSyncTurn((n) => n + 1);
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
setErrorMsg(t('Could not disconnect {provider} right now. Please try again.', { provider: 'GitHub' }));
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
setDropping(false);
|
|
317
|
+
setBusy(null);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
284
320
|
// 2. Connect Slack
|
|
285
321
|
const handleConnectSlack = () => connectOAuthProvider('slack', 'Slack', () => {
|
|
286
322
|
setSlackDone(true);
|
|
@@ -290,13 +326,13 @@ export function Setup({ go } = {}) {
|
|
|
290
326
|
const handleConnectGoogle = () => connectOAuthProvider('google', 'Google', () => {
|
|
291
327
|
setGoogleDone(true);
|
|
292
328
|
});
|
|
293
|
-
return (_jsxs(_Fragment, { children: [_jsxs(YStack, { "data-slot": "setup", role: "region", "aria-label": t('Onboarding (1-2-3)'), gap: "$2.5", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "$raised", width: "100%", overflow: "hidden", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$1.5", minW: 0, flex: 1, children: [_jsx(Sparkles, { size: 15, color: "var(--primary)", "aria-hidden": true }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: allDone ? t('Onboarding complete') : t('Quick setup ({n}/3)', { n: totalDone }) })] }), _jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Box, { render: "button", "aria-label": t('Expand onboarding popup'), onClick: () => setModalOpen(true), p: "$1", rounded: 999, hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Maximize2, { size: 13, "aria-hidden": true, color: "$soft" }) }), _jsx(Box, { render: "button", "aria-label": t('Dismiss'), onClick: () => setLater(true), p: "$1", rounded: 999, hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(X, { size: 13, "aria-hidden": true, color: "$soft" }) })] })] }), _jsxs(XStack, { gap: "$1", width: "100%", children: [_jsx(Box, { render: "button", "aria-label": t('Step 1: Connect GitHub'), onClick: () => setStep(1), flex: 1, height: 6, rounded: 3, bg: githubDone ? GOOD : activeStep === 1 ? '$ink' : '$edge', cursor: "pointer" }), _jsx(Box, { render: "button", "aria-label": t('Step 2: Connect Slack'), onClick: () => setStep(2), flex: 1, height: 6, rounded: 3, bg: slackDone ? GOOD : activeStep === 2 ? '$ink' : '$edge', cursor: "pointer" }), _jsx(Box, { render: "button", "aria-label": t('Step 3: Connect a plugin'), onClick: () => setStep(3), flex: 1, height: 6, rounded: 3, bg: pluginDone ? GOOD : activeStep === 3 ? '$ink' : '$edge', cursor: "pointer" })] }), allDone ? (_jsxs(YStack, { gap: "$2", pt: "$1", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Check, { size: 16, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$2", color: "$ink", fontWeight: "500", children: t('GitHub, Slack & a plugin connected') })] }), workspace && accountList.length > 0 ? (_jsx(XStack, { gap: "$1", flexWrap: "wrap", children: accountList.map((acct) => (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$0.5", rounded: "$2", bg: "$edge", children: [_jsx(Text, { fontSize: "$1", color: "$ink", numberOfLines: 1, children: acct }), _jsx(Box, { render: "button", "aria-label": t('Remove {account}', { account: acct }), onClick: () => removeGoogleAccount(acct), cursor: "pointer", children: _jsx(X, { size: 11, color: "$soft", "aria-hidden": true }) })] }, acct))) })) : null, _jsxs(XStack, { gap: "$1.5", items: "center", flexWrap: "wrap", children: [workspace ? (_jsx(Box, { render: "button", onClick: handleConnectGoogle, px: "$2.5", py: "$1", rounded: "$3", bg: "$edge", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(Plus, { size: 12, color: "$ink", "aria-hidden": true }), _jsx(Text, { fontSize: "$1", fontWeight: "500", color: "$ink", children: t('Add Google account') })] }) })) : null, _jsx(Box, { render: "button", onClick: () => setLater(true), px: "$2.5", py: "$1", rounded: "$3", bg: "$edge", hoverStyle: { bg: '$hover' }, items: "center", justify: "center", cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "500", children: t('Done') }) })] })] })) : activeStep === 1 ? (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(ProviderMark, { org: "github", size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('1. Connect GitHub') })] }), githubDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Sync repositories, PRs, and team repository context.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: handleConnectGithub, "aria-disabled": busy === 'github', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'github' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'github' ? t('Connecting…') : githubDone ? t('Reconnect') : t('Connect GitHub') }) }), _jsx(Box, { render: "button", onClick: () => setStep(2), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Skip') }) })] })] })) : activeStep === 2 ? (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(SlackMark, { size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('2. Connect Slack') })] }), slackDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Route agent notifications and chat in team channels.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: handleConnectSlack, "aria-disabled": busy === 'slack', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'slack' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'slack' ? t('Connecting…') : slackDone ? t('Reconnect') : t('Connect Slack') }) }), _jsx(Box, { render: "button", onClick: () => setStep(3), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Skip') }) })] })] })) : (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(Plug, { size: 18, color: "var(--foreground)", "aria-hidden": true }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('3. Connect a plugin') })] }), pluginDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Give your agents tools: build a plugin or add an MCP server in Customize.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: openPlugins, px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: pluginDone ? t('Open plugins') : t('Connect a plugin') }) }), _jsx(Box, { render: "button", onClick: () => setLater(true), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: pluginDone ? t('Done') : t('Skip') }) })] }), workspace ? (_jsxs(YStack, { gap: "$2", minW: 0, pt: "$2", borderTopWidth: 1, borderColor: "$borderColor", "data-slot": "setup-workspace", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(ProviderMark, { org: "google", size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('Google Workspace') })] }), hasGoogle ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: accountList.length > 1
|
|
329
|
+
return (_jsxs(_Fragment, { children: [_jsxs(YStack, { "data-slot": "setup", role: "region", "aria-label": t('Onboarding (1-2-3)'), gap: "$2.5", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "$raised", width: "100%", overflow: "hidden", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$1.5", minW: 0, flex: 1, children: [_jsx(Sparkles, { size: 15, color: "var(--primary)", "aria-hidden": true }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: allDone ? t('Onboarding complete') : t('Quick setup ({n}/3)', { n: totalDone }) })] }), _jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Box, { render: "button", "aria-label": t('Expand onboarding popup'), onClick: () => setModalOpen(true), p: "$1", rounded: 999, hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Maximize2, { size: 13, "aria-hidden": true, color: "$soft" }) }), _jsx(Box, { render: "button", "aria-label": t('Dismiss'), onClick: () => setLater(true), p: "$1", rounded: 999, hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(X, { size: 13, "aria-hidden": true, color: "$soft" }) })] })] }), _jsxs(XStack, { gap: "$1", width: "100%", children: [_jsx(Box, { render: "button", "aria-label": t('Step 1: Connect GitHub'), onClick: () => setStep(1), flex: 1, height: 6, rounded: 3, bg: githubDone ? GOOD : activeStep === 1 ? '$ink' : '$edge', cursor: "pointer" }), _jsx(Box, { render: "button", "aria-label": t('Step 2: Connect Slack'), onClick: () => setStep(2), flex: 1, height: 6, rounded: 3, bg: slackDone ? GOOD : activeStep === 2 ? '$ink' : '$edge', cursor: "pointer" }), _jsx(Box, { render: "button", "aria-label": t('Step 3: Connect a plugin'), onClick: () => setStep(3), flex: 1, height: 6, rounded: 3, bg: pluginDone ? GOOD : activeStep === 3 ? '$ink' : '$edge', cursor: "pointer" })] }), allDone ? (_jsxs(YStack, { gap: "$2", pt: "$1", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Check, { size: 16, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$2", color: "$ink", fontWeight: "500", children: t('GitHub, Slack & a plugin connected') })] }), workspace && accountList.length > 0 ? (_jsx(XStack, { gap: "$1", flexWrap: "wrap", children: accountList.map((acct) => (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$0.5", rounded: "$2", bg: "$edge", children: [_jsx(Text, { fontSize: "$1", color: "$ink", numberOfLines: 1, children: acct }), _jsx(Box, { render: "button", "aria-label": t('Remove {account}', { account: acct }), onClick: () => removeGoogleAccount(acct), cursor: "pointer", children: _jsx(X, { size: 11, color: "$soft", "aria-hidden": true }) })] }, acct))) })) : null, _jsxs(XStack, { gap: "$1.5", items: "center", flexWrap: "wrap", children: [workspace ? (_jsx(Box, { render: "button", onClick: handleConnectGoogle, px: "$2.5", py: "$1", rounded: "$3", bg: "$edge", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(Plus, { size: 12, color: "$ink", "aria-hidden": true }), _jsx(Text, { fontSize: "$1", fontWeight: "500", color: "$ink", children: t('Add Google account') })] }) })) : null, _jsx(Box, { render: "button", onClick: () => setLater(true), px: "$2.5", py: "$1", rounded: "$3", bg: "$edge", hoverStyle: { bg: '$hover' }, items: "center", justify: "center", cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "500", children: t('Done') }) })] })] })) : activeStep === 1 ? (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(ProviderMark, { org: "github", size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('1. Connect GitHub') })] }), githubDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Sync repositories, PRs, and team repository context.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: handleConnectGithub, "aria-disabled": busy === 'github', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'github' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'github' ? t('Connecting…') : githubDone ? t('Reconnect') : t('Connect GitHub') }) }), githubDone ? (_jsx(Box, { render: "button", onClick: () => void handleDisconnectGithub(), "aria-disabled": busy === 'github', px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: dropping ? '$ink' : '$soft', children: dropping ? t('Confirm disconnect') : t('Disconnect') }) })) : null, _jsx(Box, { render: "button", onClick: () => setStep(2), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Skip') }) })] })] })) : activeStep === 2 ? (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(SlackMark, { size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('2. Connect Slack') })] }), slackDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Route agent notifications and chat in team channels.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: handleConnectSlack, "aria-disabled": busy === 'slack', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'slack' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'slack' ? t('Connecting…') : slackDone ? t('Reconnect') : t('Connect Slack') }) }), _jsx(Box, { render: "button", onClick: () => setStep(3), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Skip') }) })] })] })) : (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(Plug, { size: 18, color: "var(--foreground)", "aria-hidden": true }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('3. Connect a plugin') })] }), pluginDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Give your agents tools: build a plugin or add an MCP server in Customize.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: openPlugins, px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: pluginDone ? t('Open plugins') : t('Connect a plugin') }) }), _jsx(Box, { render: "button", onClick: () => setLater(true), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: pluginDone ? t('Done') : t('Skip') }) })] }), workspace ? (_jsxs(YStack, { gap: "$2", minW: 0, pt: "$2", borderTopWidth: 1, borderColor: "$borderColor", "data-slot": "setup-workspace", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(ProviderMark, { org: "google", size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('Google Workspace') })] }), hasGoogle ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: accountList.length > 1
|
|
294
330
|
? t('{n} connected', { n: accountList.length })
|
|
295
331
|
: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Grant Drive, Docs, Sheets, Gmail & Calendar permissions. Add personal, work, or multiple org accounts.') }), accountList.length > 0 ? (_jsx(XStack, { gap: "$1", flexWrap: "wrap", children: accountList.map((acct) => (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$0.5", rounded: "$2", bg: "$edge", children: [_jsx(Text, { fontSize: "$1", color: "$ink", numberOfLines: 1, children: acct }), _jsx(Box, { render: "button", "aria-label": t('Remove {account}', { account: acct }), onClick: () => removeGoogleAccount(acct), cursor: "pointer", children: _jsx(X, { size: 11, color: "$soft", "aria-hidden": true }) })] }, acct))) })) : null, _jsx(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: _jsx(Box, { render: "button", onClick: handleConnectGoogle, "aria-disabled": busy === 'google', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'google' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'google'
|
|
296
332
|
? t('Connecting…')
|
|
297
333
|
: hasGoogle
|
|
298
334
|
? t('+ Add Google account')
|
|
299
|
-
: t('Connect Google') }) }) })] })) : null] })), errorMsg ? (_jsx(Text, { fontSize: "$1", color: "$red10", children: errorMsg })) : null] }), _jsx(Dialog, { open: modalOpen, onOpenChange: setModalOpen, children: _jsxs(DialogContent, { maxW: 520, rounded: "$6", gap: "$4", p: "$5", children: [_jsx(DialogTitle, { children: _jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Sparkles, { size: 20, color: "var(--primary)", "aria-hidden": true }), _jsx(Text, { fontSize: "$5", fontWeight: "600", color: "$ink", children: t('Set up {brand} in 3 steps', { brand: brand() }) })] }) }), _jsx(Text, { fontSize: "$2", color: "$soft", children: t('Connect your code, your team chat, and the tools your agents use.', { brand: brand() }) }), _jsxs(YStack, { gap: "$3", children: [_jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: githubDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(ProviderMark, { org: "github", size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('1. GitHub') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Sync repositories, PRs, and code context') })] })] }), githubDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: handleConnectGithub, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'github' ? t('Connecting…') : t('Connect') }) }))] }), _jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: slackDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(SlackMark, { size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('2. Slack') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Notifications and agent bot chat in channels') })] })] }), slackDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: handleConnectSlack, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'slack' ? t('Connecting…') : t('Connect') }) }))] }), _jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: pluginDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(Plug, { size: 24, color: "var(--foreground)", "aria-hidden": true }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('3. Plugins') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Plugins and MCP servers your agents can call') })] })] }), pluginDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: openPlugins, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: t('Open') }) }))] }), workspace ? (_jsxs(YStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: hasGoogle ? GOOD : '$borderColor', bg: "$raised", gap: "$2.5", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(ProviderMark, { org: "google", size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('Google Workspace · private beta') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Edit Drive files, Docs, Sheets, Gmail & Calendar across personal and business accounts') })] })] }), _jsx(Box, { render: "button", onClick: handleConnectGoogle, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'google'
|
|
335
|
+
: t('Connect Google') }) }) })] })) : null] })), errorMsg ? (_jsx(Text, { fontSize: "$1", color: "$red10", children: errorMsg })) : null] }), _jsx(Dialog, { open: modalOpen, onOpenChange: setModalOpen, children: _jsxs(DialogContent, { maxW: 520, rounded: "$6", gap: "$4", p: "$5", children: [_jsx(DialogTitle, { children: _jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Sparkles, { size: 20, color: "var(--primary)", "aria-hidden": true }), _jsx(Text, { fontSize: "$5", fontWeight: "600", color: "$ink", children: t('Set up {brand} in 3 steps', { brand: brand() }) })] }) }), _jsx(Text, { fontSize: "$2", color: "$soft", children: t('Connect your code, your team chat, and the tools your agents use.', { brand: brand() }) }), _jsxs(YStack, { gap: "$3", children: [_jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: githubDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(ProviderMark, { org: "github", size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('1. GitHub') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Sync repositories, PRs, and code context') })] })] }), githubDone ? (_jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] }), _jsx(Box, { render: "button", onClick: () => void handleDisconnectGithub(), "aria-disabled": busy === 'github', px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: dropping ? '$ink' : '$soft', children: dropping ? t('Confirm disconnect') : t('Disconnect') }) })] })) : (_jsx(Box, { render: "button", onClick: handleConnectGithub, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'github' ? t('Connecting…') : t('Connect') }) }))] }), _jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: slackDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(SlackMark, { size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('2. Slack') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Notifications and agent bot chat in channels') })] })] }), slackDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: handleConnectSlack, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'slack' ? t('Connecting…') : t('Connect') }) }))] }), _jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: pluginDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(Plug, { size: 24, color: "var(--foreground)", "aria-hidden": true }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('3. Plugins') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Plugins and MCP servers your agents can call') })] })] }), pluginDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: openPlugins, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: t('Open') }) }))] }), workspace ? (_jsxs(YStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: hasGoogle ? GOOD : '$borderColor', bg: "$raised", gap: "$2.5", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(ProviderMark, { org: "google", size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('Google Workspace · private beta') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Edit Drive files, Docs, Sheets, Gmail & Calendar across personal and business accounts') })] })] }), _jsx(Box, { render: "button", onClick: handleConnectGoogle, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'google'
|
|
300
336
|
? t('Connecting…')
|
|
301
337
|
: hasGoogle
|
|
302
338
|
? t('+ Add account')
|
package/dist/Usage.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UseLimits } from '@hanzo/ui/product/useLimits';
|
|
2
|
+
import { type Turn } from './lib/tokens.js';
|
|
3
|
+
export interface ContextUsage {
|
|
4
|
+
model: string;
|
|
5
|
+
window?: number;
|
|
6
|
+
messages: readonly Turn[];
|
|
7
|
+
draft?: string;
|
|
8
|
+
tools?: unknown;
|
|
9
|
+
}
|
|
10
|
+
/** The account control, shared by Chat, Dev and Studio through the composer slot. */
|
|
11
|
+
export declare function UsageControl({ context, read }: {
|
|
12
|
+
context?: ContextUsage;
|
|
13
|
+
read?: UseLimits;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
15
|
+
/** Every shared composer in the app gets the same account usage entry. */
|
|
16
|
+
export declare function UsageProvider({ children }: {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}): import("react").JSX.Element;
|
package/dist/Usage.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
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';
|
|
4
|
+
import { useI18n } from '@hanzo/i18n/react';
|
|
5
|
+
import { Activity, ArrowUpRight } from 'lucide-react';
|
|
6
|
+
import { Anchor, Button, Popover, PopoverContent, PopoverTrigger, Progress, Text, XStack, YStack } from '@hanzo/ui';
|
|
7
|
+
import { ComposerStatusProvider } from '@hanzo/ui/chat';
|
|
8
|
+
import { UsageMeter } from '@hanzo/ui/product/UsageMeter';
|
|
9
|
+
import { label } from '@hanzo/build/plan';
|
|
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 { useRooms } from './host.js';
|
|
15
|
+
import { tokensOf } from './lib/tokens.js';
|
|
16
|
+
import { payPage } from './lib/pay.js';
|
|
17
|
+
import { useLimits } from './lib/limits.js';
|
|
18
|
+
import { contextOf, readTokens, subscribeTokens, tokenKey } from './lib/tokens.js';
|
|
19
|
+
const integer = (n) => n.toLocaleString(undefined, { maximumFractionDigits: 0 });
|
|
20
|
+
/** The account control, shared by Chat, Dev and Studio through the composer slot. */
|
|
21
|
+
export function UsageControl({ context, read }) {
|
|
22
|
+
const { t } = useI18n();
|
|
23
|
+
const [open, setOpen] = useState(false);
|
|
24
|
+
const currentOrg = org();
|
|
25
|
+
const identity = `${currentOrg}:${subject()}`;
|
|
26
|
+
const { path } = useRooms();
|
|
27
|
+
const run = path?.match(/^\/dev\/run\/([^/]+)/)?.[1];
|
|
28
|
+
const [account, setAccount] = useState(null);
|
|
29
|
+
const [runUsage, setRunUsage] = useState(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!open || !currentOrg || !bearer())
|
|
32
|
+
return;
|
|
33
|
+
const abort = new AbortController();
|
|
34
|
+
const scoped = (input, init) => {
|
|
35
|
+
const headers = new Headers(init?.headers);
|
|
36
|
+
for (const [k, v] of Object.entries(scope()))
|
|
37
|
+
headers.set(k, v);
|
|
38
|
+
headers.set('X-Org-Id', currentOrg);
|
|
39
|
+
return fetch(input, { ...init, headers });
|
|
40
|
+
};
|
|
41
|
+
const refresh = () => {
|
|
42
|
+
void fetchCloudUsage({ baseUrl: api(), token: bearer(), range: '30d', org: currentOrg, signal: abort.signal, fetch: scoped }).then((data) => { if (!abort.signal.aborted)
|
|
43
|
+
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)
|
|
44
|
+
setAccount({ key: identity, error: t('Account usage is unavailable. See all usage to retry.') }); });
|
|
45
|
+
if (run)
|
|
46
|
+
void scoped(`${api()}/v1/agent/sessions/${encodeURIComponent(decodeURIComponent(run))}`, { signal: abort.signal }).then(async (response) => {
|
|
47
|
+
if (!response.ok)
|
|
48
|
+
return;
|
|
49
|
+
const data = await response.json();
|
|
50
|
+
for (const event of [...(data.recent ?? [])].reverse()) {
|
|
51
|
+
let payload = event.payload;
|
|
52
|
+
if (typeof payload === 'string') {
|
|
53
|
+
try {
|
|
54
|
+
payload = JSON.parse(payload);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const value = tokensOf(payload?.usage);
|
|
61
|
+
if (value && !abort.signal.aborted) {
|
|
62
|
+
setRunUsage({ key: `${identity}:${run}`, value });
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}).catch(() => { });
|
|
67
|
+
};
|
|
68
|
+
refresh();
|
|
69
|
+
const timer = setInterval(refresh, 15000);
|
|
70
|
+
window.addEventListener('focus', refresh);
|
|
71
|
+
return () => { abort.abort(); clearInterval(timer); window.removeEventListener('focus', refresh); };
|
|
72
|
+
}, [open, identity, run, t]);
|
|
73
|
+
const aggregate = account?.key === identity ? account : null;
|
|
74
|
+
// Chat lends its existing read. Other surfaces read only when the popover opens.
|
|
75
|
+
const fallback = useLimits(!read && open && hasSession(), org());
|
|
76
|
+
const usage = read ?? fallback;
|
|
77
|
+
const { limits, answered } = usage;
|
|
78
|
+
const estimate = context ? contextOf(context.messages, context.draft, context.tools) : null;
|
|
79
|
+
const key = context ? tokenKey(org(), context.model, context.messages, subject() ?? '') : '';
|
|
80
|
+
const counted = useSyncExternalStore(subscribeTokens, () => readTokens(key), () => null);
|
|
81
|
+
const tokens = counted ?? (runUsage?.key === `${identity}:${run}` ? runUsage.value : null);
|
|
82
|
+
const capacity = context?.window && context.window > 0 ? context.window : null;
|
|
83
|
+
const percent = estimate && capacity ? Math.round(estimate.total / capacity * 100) : null;
|
|
84
|
+
const plan = limits?.plan ? label(limits.plan) : null;
|
|
85
|
+
const highest = limits ? Math.max(0, ...Object.values(limits.classes).flatMap((c) => c ? [c.percent, ...(c.window ? [c.window.percent] : [])] : [])) : null;
|
|
86
|
+
const title = plan ? `${plan.name}${plan.tag ? ` ${plan.tag}` : ''}` : t('Plan usage');
|
|
87
|
+
const toggle = (on) => { setOpen(on); if (on && read)
|
|
88
|
+
read.reload(); };
|
|
89
|
+
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: integer(n) })] }, name);
|
|
90
|
+
return (_jsxs(Popover, { open: open, onOpenChange: toggle, placement: "top-end", children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { type: "button", variant: "ghost", size: "sm", px: "$2", minW: 32, height: 32, hitSlop: 6, "aria-label": t('Context, tokens and plan usage'), "data-slot": "composer-usage", children: [_jsx(Activity, { size: 15, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", 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", children: _jsx(Anchor, { href: payPage('/cart'), "data-slot": "composer-upgrade", children: t('Upgrade plan') }) }), _jsx(Button, { asChild: true, size: "sm", variant: "outline", children: _jsx(Anchor, { href: payPage('/amount/card'), "data-slot": "composer-buy-credits", children: t('Buy credits') }) })] })] }) })] }));
|
|
91
|
+
}
|
|
92
|
+
/** Every shared composer in the app gets the same account usage entry. */
|
|
93
|
+
export function UsageProvider({ children }) {
|
|
94
|
+
return _jsx(ComposerStatusProvider, { value: _jsx(UsageControl, {}, org()), children: children });
|
|
95
|
+
}
|
package/dist/lib/served.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* byte is passed through untouched. Each chat answer's usage headers, and a
|
|
11
11
|
* billing refusal's envelope, go to @hanzo/ui's `observe`.
|
|
12
12
|
*/
|
|
13
|
+
import { recordTokens, tokenKey, tokensOf, tokenSubject } from './tokens.js';
|
|
13
14
|
import { observe } from '@hanzo/ui/product/useLimits';
|
|
14
15
|
const listeners = new Set();
|
|
15
16
|
/** Hears every served completion from now on; answers the unsubscribe. */
|
|
@@ -39,10 +40,13 @@ export function observed(base) {
|
|
|
39
40
|
if (!COMPLETION.test(url) || !res.ok)
|
|
40
41
|
return res;
|
|
41
42
|
let asked = '';
|
|
43
|
+
let key = '';
|
|
42
44
|
try {
|
|
43
45
|
const body = typeof init?.body === 'string' ? JSON.parse(init.body) : null;
|
|
44
46
|
if (typeof body?.model === 'string')
|
|
45
47
|
asked = body.model;
|
|
48
|
+
if (Array.isArray(body?.messages))
|
|
49
|
+
key = tokenKey(new Headers(init?.headers).get('X-Org-Id'), asked, body.messages, tokenSubject(new Headers(init?.headers).get('Authorization')));
|
|
46
50
|
}
|
|
47
51
|
catch {
|
|
48
52
|
/* a body that is not JSON names no model */
|
|
@@ -50,13 +54,18 @@ export function observed(base) {
|
|
|
50
54
|
const header = res.headers.get('x-hanzo-served');
|
|
51
55
|
if (header) {
|
|
52
56
|
tell({ asked, served: header });
|
|
53
|
-
return res;
|
|
54
57
|
}
|
|
58
|
+
const usage = (frame) => {
|
|
59
|
+
const counted = tokensOf(frame?.usage);
|
|
60
|
+
if (counted)
|
|
61
|
+
recordTokens(key, { ...counted, ...(typeof frame.model === 'string' ? { model: frame.model } : {}) });
|
|
62
|
+
};
|
|
55
63
|
if (!res.body || !(res.headers.get('content-type') ?? '').includes('text/event-stream')) {
|
|
56
64
|
res
|
|
57
65
|
.clone()
|
|
58
66
|
.json()
|
|
59
67
|
.then((d) => {
|
|
68
|
+
usage(d);
|
|
60
69
|
if (typeof d?.model === 'string' && d.model)
|
|
61
70
|
tell({ asked, served: d.model });
|
|
62
71
|
})
|
|
@@ -64,16 +73,14 @@ export function observed(base) {
|
|
|
64
73
|
return res;
|
|
65
74
|
}
|
|
66
75
|
const decoder = new TextDecoder();
|
|
67
|
-
let heard =
|
|
76
|
+
let heard = Boolean(header);
|
|
68
77
|
let carry = '';
|
|
69
78
|
const watch = new TransformStream({
|
|
70
79
|
transform(chunk, out) {
|
|
71
80
|
out.enqueue(chunk);
|
|
72
|
-
if (heard)
|
|
73
|
-
return;
|
|
74
81
|
carry += decoder.decode(chunk, { stream: true });
|
|
75
82
|
let at = carry.indexOf('\n');
|
|
76
|
-
while (
|
|
83
|
+
while (at >= 0) {
|
|
77
84
|
const line = carry.slice(0, at).trim();
|
|
78
85
|
carry = carry.slice(at + 1);
|
|
79
86
|
at = carry.indexOf('\n');
|
|
@@ -84,7 +91,8 @@ export function observed(base) {
|
|
|
84
91
|
continue;
|
|
85
92
|
try {
|
|
86
93
|
const frame = JSON.parse(data);
|
|
87
|
-
|
|
94
|
+
usage(frame);
|
|
95
|
+
if (!heard && typeof frame.model === 'string' && frame.model) {
|
|
88
96
|
heard = true;
|
|
89
97
|
tell({ asked, served: frame.model });
|
|
90
98
|
}
|
|
@@ -94,6 +102,15 @@ export function observed(base) {
|
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
104
|
},
|
|
105
|
+
flush() {
|
|
106
|
+
const line = (carry + decoder.decode()).trim();
|
|
107
|
+
if (!line.startsWith('data:'))
|
|
108
|
+
return;
|
|
109
|
+
try {
|
|
110
|
+
usage(JSON.parse(line.slice(5).trim()));
|
|
111
|
+
}
|
|
112
|
+
catch { /* unfinished frame */ }
|
|
113
|
+
},
|
|
97
114
|
});
|
|
98
115
|
return new Response(res.body.pipeThrough(watch), { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
99
116
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Reported token usage and explicitly estimated context. Never stores prompt text. */
|
|
2
|
+
export interface Tokens {
|
|
3
|
+
input: number;
|
|
4
|
+
output: number;
|
|
5
|
+
total: number;
|
|
6
|
+
cached?: number;
|
|
7
|
+
reasoning?: number;
|
|
8
|
+
model?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface Turn {
|
|
11
|
+
role: string;
|
|
12
|
+
content?: unknown;
|
|
13
|
+
}
|
|
14
|
+
export declare function tokensOf(raw: unknown): Tokens | null;
|
|
15
|
+
/** Stable request identity: organization, model, and transcript through the last user turn. */
|
|
16
|
+
export declare function tokenKey(org: string | null, model: string, messages: readonly Turn[], subject?: string): string;
|
|
17
|
+
export declare const subscribeTokens: (f: () => void) => () => void;
|
|
18
|
+
export declare const readTokens: (key: string) => Tokens;
|
|
19
|
+
export declare function recordTokens(key: string, usage: Tokens): void;
|
|
20
|
+
export declare function clearTokens(): void;
|
|
21
|
+
export declare function contextOf(messages: readonly Turn[], draft?: string, tools?: unknown): {
|
|
22
|
+
rows: {
|
|
23
|
+
name: string;
|
|
24
|
+
tokens: number;
|
|
25
|
+
}[];
|
|
26
|
+
total: number;
|
|
27
|
+
images: boolean;
|
|
28
|
+
};
|
|
29
|
+
/** A rotated IAM token keeps the same subject. An opaque token has no subject. */
|
|
30
|
+
export declare function tokenSubject(authorization: string | null): string;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const count = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0;
|
|
2
|
+
export function tokensOf(raw) {
|
|
3
|
+
if (!raw || typeof raw !== 'object')
|
|
4
|
+
return null;
|
|
5
|
+
const v = raw;
|
|
6
|
+
const input = v.prompt_tokens ?? v.input_tokens;
|
|
7
|
+
const output = v.completion_tokens ?? v.output_tokens;
|
|
8
|
+
if (!count(input) || !count(output))
|
|
9
|
+
return null;
|
|
10
|
+
const cached = v.prompt_tokens_details?.cached_tokens ?? v.cache_read_input_tokens;
|
|
11
|
+
const reasoning = v.completion_tokens_details?.reasoning_tokens;
|
|
12
|
+
return { input, output, total: count(v.total_tokens) ? v.total_tokens : input + output,
|
|
13
|
+
...(count(cached) ? { cached } : {}), ...(count(reasoning) ? { reasoning } : {}) };
|
|
14
|
+
}
|
|
15
|
+
/** Stable request identity: organization, model, and transcript through the last user turn. */
|
|
16
|
+
export function tokenKey(org, model, messages, subject = '') {
|
|
17
|
+
let last = messages.length - 1;
|
|
18
|
+
while (last >= 0 && messages[last].role !== 'user')
|
|
19
|
+
last--;
|
|
20
|
+
if (last < 0)
|
|
21
|
+
return '';
|
|
22
|
+
const text = JSON.stringify(messages.slice(0, last + 1).map(({ role, content }) => ({ role, content })));
|
|
23
|
+
let a = 2166136261, b = 5381;
|
|
24
|
+
for (let i = 0; i < text.length; i++) {
|
|
25
|
+
a = Math.imul(a ^ text.charCodeAt(i), 16777619);
|
|
26
|
+
b = Math.imul(b, 33) ^ text.charCodeAt(i);
|
|
27
|
+
}
|
|
28
|
+
return `${org ?? ''}:${subject}:${model}:${text.length}:${a >>> 0}:${b >>> 0}`;
|
|
29
|
+
}
|
|
30
|
+
const held = new Map();
|
|
31
|
+
const listeners = new Set();
|
|
32
|
+
export const subscribeTokens = (f) => { listeners.add(f); return () => { listeners.delete(f); }; };
|
|
33
|
+
export const readTokens = (key) => held.get(key) ?? null;
|
|
34
|
+
export function recordTokens(key, usage) {
|
|
35
|
+
if (!key)
|
|
36
|
+
return;
|
|
37
|
+
held.delete(key);
|
|
38
|
+
held.set(key, usage);
|
|
39
|
+
if (held.size > 100)
|
|
40
|
+
held.delete(held.keys().next().value);
|
|
41
|
+
for (const f of listeners)
|
|
42
|
+
f();
|
|
43
|
+
}
|
|
44
|
+
export function clearTokens() { held.clear(); for (const f of listeners)
|
|
45
|
+
f(); }
|
|
46
|
+
const textOf = (v) => typeof v === 'string' ? v : Array.isArray(v) ? v.filter((p) => p?.type === 'text').map((p) => p.text ?? '').join('\n') : '';
|
|
47
|
+
export function contextOf(messages, draft = '', tools) {
|
|
48
|
+
const system = messages.filter((m) => m.role === 'system' || m.role === 'developer').map((m) => textOf(m.content)).join('\n');
|
|
49
|
+
const conversation = messages.filter((m) => m.role !== 'system' && m.role !== 'developer').map((m) => textOf(m.content)).join('\n');
|
|
50
|
+
const estimate = (s) => s ? Math.ceil(s.length / 4) : 0;
|
|
51
|
+
const rows = [{ name: 'System & instructions', tokens: estimate(system) }, { name: 'Tool definitions', tokens: estimate(tools ? JSON.stringify(tools) : '') }, { name: 'Conversation', tokens: estimate(conversation) }, { name: 'Draft', tokens: estimate(draft) }];
|
|
52
|
+
return { rows, total: rows.reduce((n, r) => n + r.tokens, 0), images: messages.some((m) => Array.isArray(m.content) && m.content.some((p) => p?.type !== 'text')) };
|
|
53
|
+
}
|
|
54
|
+
/** A rotated IAM token keeps the same subject. An opaque token has no subject. */
|
|
55
|
+
export function tokenSubject(authorization) {
|
|
56
|
+
try {
|
|
57
|
+
const part = authorization?.replace(/^Bearer /i, '').split('.')[1];
|
|
58
|
+
if (!part)
|
|
59
|
+
return '';
|
|
60
|
+
const v = JSON.parse(atob(part.replace(/-/g, '+').replace(/_/g, '/')));
|
|
61
|
+
return typeof v.sub === 'string' ? v.sub : '';
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.48",
|
|
4
4
|
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@hanzo/logo": ">=1.0.26",
|
|
61
61
|
"@hanzo/studio": ">=0.1.0",
|
|
62
62
|
"@hanzo/tabs": ">=0.1.8",
|
|
63
|
-
"@hanzo/ui": ">=8.29.
|
|
63
|
+
"@hanzo/ui": ">=8.29.26",
|
|
64
64
|
"@hanzo/usage": ">=0.1.18",
|
|
65
65
|
"@hanzo/voice": ">=0.1.16",
|
|
66
66
|
"@hanzogui/shell": "^8.3.20",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@hanzo/logo": "1.0.26",
|
|
82
82
|
"@hanzo/studio": "0.1.0",
|
|
83
83
|
"@hanzo/tabs": "github:hanzo-inc/tabs",
|
|
84
|
-
"@hanzo/ui": "8.29.
|
|
84
|
+
"@hanzo/ui": "8.29.26",
|
|
85
85
|
"@hanzo/usage": "0.1.18",
|
|
86
86
|
"@hanzo/voice": "0.1.19",
|
|
87
87
|
"@hanzogui/config": "8.3.5",
|