Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hanzo/ui",
"version": "8.33.7",
"version": "8.33.8",
"type": "module",
"description": "Hanzo UI — the one canonical Hanzo component library, on @hanzo/gui + @hanzo/design. ONE substrate: every component renders through @hanzo/gui primitives, so the same import works on web, native (expo) and desktop (Tauri). Self-contained (theme.css), presentational, host-agnostic, clean-room.",
"exports": {
Expand Down
6 changes: 4 additions & 2 deletions pkg/ui/scripts/composer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,12 @@ for (const [width, height, ratio] of [
// Under the frame: labelled controls at least a word tall, a transparent edge and no fill at rest, at the text edge.
check(m.words.some((w) => /^Effort: /.test(w.name)) && m.words.some((w) => /^Model: /.test(w.name)), `${name}: the model and the effort are words under the frame (${m.words.map((w) => w.name).join(', ')})`)
if (kind === 'dev') check(m.words.filter((w) => /Where the run runs|Repository|Branch/.test(w.name)).length === 3, `${name}: the pills are words under the frame`)
// Closed, each one reads as what it chooses, its title before its value: never two bare "Auto"s side by side (hanzo-inc/app#313).
// Closed, each one reads as what it chooses: its title alone while it is on Auto, its title before its value once chosen away from it.
// Never two bare "Auto"s side by side (hanzo-inc/app#313), nor "Effort Auto" beside "Model Enso Auto" (#460).
for (const w of m.words.filter((w) => /^(Model|Effort|Mode): /.test(w.name))) {
const [title, value] = w.name.split(': ')
check(w.text.startsWith(title) && w.text.endsWith(value) && w.text !== value, `${name}: ${title} is titled on the row, not only its value ("${w.text}")`)
if (/\bAuto$/.test(value)) check(w.text === title, `${name}: ${title} on Auto is its title alone ("${w.text}")`)
else check(w.text.startsWith(title) && w.text.endsWith(value) && w.text !== value, `${name}: ${title} is titled on the row, not only its value ("${w.text}")`)
}
for (const w of m.words) {
// Model, Effort and Mode are labelled controls (the label over the value); the pills and chips stay words.
Expand Down
42 changes: 35 additions & 7 deletions pkg/ui/src/chat/Tune.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,41 @@ describe('Tune', () => {
expect(set).toHaveBeenCalledWith('auto')
})

it('titles each closed word with what it chooses, so two Autos never stand alone (hanzo-inc/app#313)', () => {
it('draws a word on Auto as its title alone, so two Autos never stand beside each other (hanzo-inc/app#460)', () => {
const auto = [{ id: 'auto', label: 'Auto', note: 'Adaptive' }]
mount(<Tune mind={mind()} effort={{ value: 'auto', set: () => {}, items: auto }} mode={{ value: 'auto', set: () => {}, items: auto }} />)
const text = (slot: string) => host.querySelector<HTMLElement>(`[data-slot="${slot}"]`)!.textContent
expect(text('model-picker')).toBe('ModelEnso')
expect(text('effort')).toBe('EffortAuto')
expect(text('mode')).toBe('ModeAuto')
expect(text('model-picker')).toBe('Model')
expect(text('effort')).toBe('Effort')
expect(text('mode')).toBe('Mode')
expect(host.textContent).not.toContain('Auto')
// The accessible name still says what is in force.
expect(label('Model')!.getAttribute('aria-label')).toBe('Model: Enso')
expect(host.querySelector('[data-slot="effort"]')!.getAttribute('aria-label')).toBe('Effort: Auto')
expect(host.querySelector('[data-slot="mode"]')!.getAttribute('aria-label')).toBe('Mode: Auto')
})

it('draws a word chosen away from Auto as its title and its value', () => {
const items = [
{ id: 'auto', label: 'Auto', note: 'Adaptive' },
{ id: 'high', label: 'High', note: 'Thinks longer' },
]
mount(<Tune mind={mind({ model: 'thinker' })} effort={{ value: 'high', set: () => {}, items }} mode={{ value: 'high', set: () => {}, items }} />)
const text = (slot: string) => host.querySelector<HTMLElement>(`[data-slot="${slot}"]`)!.textContent
expect(text('model-picker')).toBe('ModelThinker')
expect(text('effort')).toBe('EffortHigh')
expect(text('mode')).toBe('ModeHigh')
})

it('lists Auto as a checked option inside the Effort list', () => {
const items = [
{ id: 'auto', label: 'Auto', note: 'Adaptive' },
{ id: 'high', label: 'High', note: 'Thinks longer' },
]
mount(<Tune effort={{ value: 'auto', set: () => {}, items }} />)
act(() => host.querySelector<HTMLElement>('[data-slot="effort"]')!.click())
const auto = [...document.querySelectorAll<HTMLElement>('[role="option"]')].find((o) => o.textContent?.startsWith('Auto'))!
expect(auto.getAttribute('aria-selected')).toBe('true')
})

it('draws nothing where the surface has no model, no effort and no mode', () => {
Expand Down Expand Up @@ -159,9 +187,9 @@ describe('Tune, effort and mode lists', () => {
})

it('names the model from the catalog, with the catalog\'s own description in its tip', () => {
mount(<Tune mind={mind()} />)
expect(label('Model')!.getAttribute('aria-label')).toBe('Model: Enso')
expect(host.textContent).toContain('Enso')
mount(<Tune mind={mind({ model: 'thinker' })} />)
expect(label('Model')!.getAttribute('aria-label')).toBe('Model: Thinker')
expect(host.textContent).toContain('Thinker')
})
it('leaves the mode list in the order it was given', () => {
mount(<Tune mode={{ value: 'fast', set: () => {}, items }} />)
Expand Down
25 changes: 20 additions & 5 deletions pkg/ui/src/chat/Tune.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
* and add Plan. The chips are the surface's own: Chat's are the model families
* the catalog lists, Dev's are the places a run reaches.
*
* A word that is on Auto (the house router, the adaptive effort, the automatic
* mode) is drawn as its title alone, "Model", "Effort", "Mode": Auto is an option
* inside each list, checked there, and never a second "Auto" beside the first
* (hanzo-inc/app#460). One chosen away from Auto reads its title and its value.
*
* Its words are the reader's language (@hanzo/i18n `t`): efforts and modes are
* marked English (`phrase`), drawn through `t`; model names are the catalog's.
*/
Expand All @@ -22,13 +27,16 @@ import { forwardRef, useCallback, useRef, useState, type CSSProperties, type Rea

import { Popover, PopoverContent, PopoverTrigger, Sheet, SheetContent, SheetTitle, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../backends/gui'
import { slot } from '../backends/gui/slot'
import { grants, modelName, type ModelCatalogEntry, type PauseSource } from '../models/catalog'
import { ENSO, grants, modelName, type ModelCatalogEntry, type PauseSource } from '../models/catalog'
import { ModelPicker } from '../models/ModelPicker'
import { RING } from './look'
import type { Way } from './ways'

const STRONG = 'var(--border-strong)' as const

/** The id every short list gives its automatic way (ways.ts EFFORTS, a surface's modes). */
const AUTO = 'auto'

// The composer lowers `--tap-target` to 24px (Composer.tsx `FLOOR`); the words under the frame are thumbs' targets, so on a phone they take it back to 44.
// inline-style: a custom property, which no gui prop carries.
const PHONE_FLOOR = { '--tap-target': '44px' } as CSSProperties
Expand Down Expand Up @@ -82,7 +90,8 @@ const Word = forwardRef<
HTMLElement,
{
category: string
children: ReactNode
/** The value in force; absent where the word is on Auto and the title stands alone. */
children?: ReactNode
label: string
slotName: string
open: boolean
Expand Down Expand Up @@ -128,7 +137,11 @@ const Word = forwardRef<
focusVisibleStyle={RING}
$max-sm={{ minH: 44 }}
>
{compact ? (
{children == null ? (
<Text fontSize="$2" lineHeight={16} fontWeight="500" color="$ink" numberOfLines={1} shrink={1}>
{category}
</Text>
) : compact ? (
<XStack items="center" gap="$1" minW={0} shrink={1}>
<Text fontSize="$1" lineHeight={14} color="$soft" numberOfLines={1} shrink={0}>
{category}
Expand Down Expand Up @@ -232,7 +245,8 @@ function Opens({
category: string
hint: string
label: string
word: ReactNode
/** The value in force, or null where the word is on Auto and only its title is drawn. */
word: ReactNode | null
slotName: string
disabled?: boolean
children: (close: () => void, compact: boolean) => ReactNode
Expand Down Expand Up @@ -415,7 +429,7 @@ function Pick({
const now = modes.items.find((m) => m.id === modes.value) ?? modes.items[0]
if (!now) return null
return (
<Opens category={title} hint={hint} label={label(t(now.label))} word={t(now.label)} slotName={slotName} disabled={disabled}>
<Opens category={title} hint={hint} label={label(t(now.label))} word={now.id === AUTO ? null : t(now.label)} slotName={slotName} disabled={disabled}>
{(close, compact) => (
<Choices
title={title}
Expand Down Expand Up @@ -469,6 +483,7 @@ export function Tune({
<ModelPicker
quiet
stacked
bare={mind.model === ENSO}
size="sm"
name={t('Model')}
describe={t('Model: {name}', { name: resolvedName })}
Expand Down
7 changes: 7 additions & 0 deletions pkg/ui/src/models/ModelPicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ describe('ModelPicker, stacked', () => {
expect(trigger.textContent).toBe('ModelEnso')
})

it('draws its title alone where it is bare, the model being the checked row of its list', async () => {
await mount(<ModelPicker stacked bare quiet name="Model" models={MODELS} value="enso-auto" onChange={() => {}} />)
const trigger = host.querySelector('[data-slot="model-picker"]')!
expect(trigger.textContent).toBe('Model')
expect(trigger.getAttribute('aria-label')).toBe('Model: Enso')
})

it('holds a model the catalog lacks by its id, read as words', async () => {
await mount(<ModelPicker stacked name="Model" models={MODELS} value="vendor/odd-one" onChange={() => {}} />)
expect(host.querySelector('[data-slot="model-picker"]')!.textContent).toContain('Vendor Odd One')
Expand Down
9 changes: 8 additions & 1 deletion pkg/ui/src/models/ModelPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export interface ModelPickerProps {
quiet?: boolean
/** Stack the micro-label (`name`) cleanly above (or beside on narrow screens) the active model value. */
stacked?: boolean
/** With `stacked`: the model is the house default, so only the micro-label (`name`) is drawn; the model is the checked row in the list. */
bare?: boolean
size?: 'sm' | 'md'
/** Absent, "Choose a model" in the reader's language. */
placeholder?: string
Expand Down Expand Up @@ -98,6 +100,7 @@ export function ModelPicker({
disabled = false,
quiet = false,
stacked = false,
bare = false,
size = 'md',
placeholder,
name: named,
Expand Down Expand Up @@ -229,7 +232,11 @@ export function ModelPicker({
}
}}
>
{stacked ? (
{stacked && bare ? (
<Text fontSize="$2" lineHeight={16} fontWeight="500" color="$ink" numberOfLines={1} shrink={1}>
{name}
</Text>
) : stacked ? (
<YStack flexDirection={sheet ? 'row' : 'column'} items={sheet ? 'center' : 'flex-start'} gap={sheet ? '$1' : 1} minW={0} shrink={1}>
<Text fontSize="$1" lineHeight={14} color="$soft" numberOfLines={1} shrink={0}>
{name}
Expand Down
Loading