Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(model-hub): pin the route picker source column and make rows clickable (#2113)

Call White335f62e6c159
diff --git a/ui/e2e/model-catalog/route-direct-edit.spec.ts b/ui/e2e/model-catalog/route-direct-edit.spec.ts
index 648346b74..25f75a216 100644
--- a/ui/e2e/model-catalog/route-direct-edit.spec.ts
+++ b/ui/e2e/model-catalog/route-direct-edit.spec.ts
@@ -310,3 +310,148 @@ for (const [label, width] of [['small', 390], ['large', 430]] as const) {
expect(head.x).toBeGreaterThanOrEqual(0);
});
}
+
+// Two columns, and the left one names the source that supplies the models in the
+// right one. Written into that source's first row, the name is on screen for
+// exactly as long as that one row is: a few models down the left column is
+// blank, and the reader is left to remember what they are looking at. The name
+// belongs to the group, so the assertion is the reader's own question — look at
+// the left column, level with the models on screen, and read what is there. Not
+// which element the fix draws it in, and not the accessibility tree, where a
+// screen-reader-only label would answer correctly while the column beside the
+// models sat empty.
+//
+// Read off the painted boxes rather than by hit-testing the point: the name is
+// `pointer-events: none` so that it does not take the clicks of the row it
+// covers, and a question asked with `elementsFromPoint` would be answered by
+// whatever is underneath it. Everything with text of its own that covers the
+// point is returned, so a column that is somehow saying two things at once is
+// not quietly reported as saying the first of them.
+const sourceColumnAtTop = (list: Locator) => list.evaluate((element: HTMLElement) => {
+ const edge = element.getBoundingClientRect();
+ const x = edge.left + edge.width * 0.25;
+ const y = edge.top + 8;
+ return [...element.querySelectorAll<HTMLElement>('*')]
+ .filter((node) => {
+ const own = [...node.childNodes]
+ .filter((child) => child.nodeType === Node.TEXT_NODE)
+ .map((child) => child.textContent?.trim() ?? '')
+ .join('');
+ if (!own) return false;
+ const style = getComputedStyle(node);
+ if (style.visibility === 'hidden' || style.display === 'none' || Number(style.opacity) === 0) return false;
+ const rect = node.getBoundingClientRect();
+ return rect.left <= x && x <= rect.right && rect.top <= y && y <= rect.bottom;
+ })
+ .map((node) => node.textContent?.trim() ?? '');
+});
+
+test('MH-ROUTING-007: the picker keeps each source beside its own models', async ({ page }) => {
+ const copy = (key: string) => hub(key, {}, 'zh');
+ await page.goto('/e2e/model-catalog/fixture.html?view=route&backend=codex&lang=zh&stocked=1');
+ await page.getByRole('button', { name: 'Open route', exact: true }).click();
+ const dialog = page.locator('.model-hub-route-dialog');
+ await dialog.getByRole('button', { name: copy('routeDialog.editHop'), exact: true }).first().click();
+ const selector = page.locator('.model-hub-route-selector');
+ await expect(selector).toBeVisible();
+ await settled(selector);
+
+ const list = selector.locator('.model-hub-route-selector-list');
+ const firstRow = list.locator('.model-hub-route-selector-group').first()
+ .locator('.model-hub-route-candidate').first();
+ const box = (await list.boundingBox())!;
+ const restingRow = (await firstRow.boundingBox())!;
+ expect(await sourceColumnAtTop(list)).toEqual(['Provider A']);
+
+ const scrolled = await list.evaluate((element: HTMLElement) => {
+ const own = [...element.querySelector('.model-hub-route-selector-group')!
+ .querySelectorAll<HTMLElement>('.model-hub-route-candidate')];
+ // As far down this one group as the list goes: the name has to hold for as
+ // long as any of its own models are on screen, not only for its first.
+ element.scrollTop = Math.min(
+ own[own.length - 1].offsetTop - own[0].offsetTop,
+ element.scrollHeight - element.clientHeight,
+ );
+ return element.scrollTop;
+ });
+ // A list with nothing below its fold would make everything after this vacuous,
+ // and the row the name used to be written into has gone off the top of it,
+ // which is exactly what used to leave the column blank.
+ expect(scrolled).toBeGreaterThan(0);
+ const movedRow = (await firstRow.boundingBox())!;
+ expect(movedRow.y).toBeLessThan(restingRow.y);
+ expect(movedRow.y + movedRow.height).toBeLessThanOrEqual(box.y);
+
+ // This source's own models are still what is being read, so its name is still
+ // owed. Past its last one the next group's name takes the top, which is the
+ // order the groups are read in anyway.
+ const showing = await list.evaluate((element: HTMLElement) => {
+ const edge = element.getBoundingClientRect();
+ return [...element.querySelector('.model-hub-route-selector-group')!
+ .querySelectorAll<HTMLElement>('.model-hub-route-candidate')]
+ .filter((row) => {
+ const rect = row.getBoundingClientRect();
+ return rect.bottom > edge.top && rect.top < edge.bottom;
+ }).length;
+ });
+ expect(showing).toBeGreaterThan(0);
+ expect(await sourceColumnAtTop(list)).toEqual(['Provider A']);
+});
+
+// The pinned name is drawn over the top visible row and is that row's sibling,
+// not its child, so the half of the row nearest the pointer is the half a click
+// would land on the label instead — and that row would be the one that does not
+// answer. Aimed at the source column of the row the name is covering, which is
+// the row a reader reaches for first.
+test('MH-ROUTING-007: the pinned source does not take the row\'s clicks', async ({ page }) => {
+ const copy = (key: string) => hub(key, {}, 'zh');
+ await page.goto('/e2e/model-catalog/fixture.html?view=route&backend=codex&lang=zh&stocked=1');
+ await page.getByRole('button', { name: 'Open route', exact: true }).click();
+ const dialog = page.locator('.model-hub-route-dialog');
+ await dialog.getByRole('button', { name: copy('routeDialog.editHop'), exact: true }).first().click();
+ const selector = page.locator('.model-hub-route-selector');
+ await expect(selector).toBeVisible();
+ await settled(selector);
+
+ const list = selector.locator('.model-hub-route-selector-list');
+ const group = list.locator('.model-hub-route-selector-group').first();
+ const row = group.locator('.model-hub-route-candidate').first();
+ // The row the name is on top of, and the quarter of its width the name covers.
+ const heading = (await group.locator('[cmdk-group-heading]').boundingBox())!;
+ const box = (await row.boundingBox())!;
+ const aim = { x: box.x + box.width * 0.25, y: box.y + box.height / 2 };
+ expect(aim.x).toBeGreaterThan(heading.x);
+ expect(aim.x).toBeLessThan(heading.x + heading.width);
+ expect(aim.y).toBeGreaterThan(heading.y);
+ expect(aim.y).toBeLessThan(heading.y + heading.height);
+
+ // What the pointer would reach there, before asking what happens when it does:
+ // a label that answers here is the whole defect, and it answers silently.
+ expect(await page.evaluate(({ x, y }) => {
+ const hit = document.elementFromPoint(x, y);
+ return hit?.closest('.model-hub-route-candidate') ? 'row' : (hit?.tagName ?? 'none');
+ }, aim)).toBe('row');
+
+ await expect(row).toHaveAttribute('data-selected', 'false');
+ await page.mouse.click(aim.x, aim.y);
+ await expect(row).toHaveAttribute('data-selected', 'true');
+});
+
+// A row you can click says so under the pointer. The global rule in `index.css`
+// covers buttons and anything wearing a button role; a candidate is neither — it
+// is `role="option"` — and the primitive it is built from ships an arrow on
+// purpose. Every item in this codebase carries an `onSelect`, so the cursor is
+// read off the rendered row rather than off the class meant to produce it.
+test('MH-ROUTING-007: a candidate row reads as clickable', async ({ page }) => {
+ const copy = (key: string) => hub(key, {}, 'zh');
+ await page.goto('/e2e/model-catalog/fixture.html?view=route&backend=codex&lang=zh&stocked=1');
+ await page.getByRole('button', { name: 'Open route', exact: true }).click();
+ const dialog = page.locator('.model-hub-route-dialog');
+ await dialog.getByRole('button', { name: copy('routeDialog.editHop'), exact: true }).first().click();
+ const selector = page.locator('.model-hub-route-selector');
+ await expect(selector).toBeVisible();
+
+ const row = selector.locator('.model-hub-route-candidate').first();
+ await row.hover();
+ expect(await row.evaluate((element: HTMLElement) => getComputedStyle(element).cursor)).toBe('pointer');
+});
diff --git a/ui/src/components/settings/models/RouteCandidatePopover.tsx b/ui/src/components/settings/models/RouteCandidatePopover.tsx
index 6c7164d11..f7815df6a 100644
--- a/ui/src/components/settings/models/RouteCandidatePopover.tsx
+++ b/ui/src/components/settings/models/RouteCandidatePopover.tsx
@@ -202,21 +202,25 @@ export const RouteCandidatePopover: React.FC<{
</CommandEmpty>
)}
{groups.map((group) => (
+ // The source is a property of the group, not of its first row.
+ // Printed into that row it was the first thing to scroll away,
+ // and a reader six models down had a blank column where the name
+ // belonged. cmdk already emits one heading per group — the
+ // accessible label for this very set — so the name is drawn there
+ // instead of duplicated into a cell, and CSS keeps it in view for
+ // as long as any of its own models are.
<CommandGroup
key={group.source.id}
heading={group.source.display_name}
- className="model-hub-route-selector-group [&_[cmdk-group-heading]]:sr-only"
+ className="model-hub-route-selector-group"
>
- {group.items.map((item, itemIndex) => (
+ {group.items.map((item) => (
<CommandItem
key={candidateKey(item.hop)}
value={candidateKey(item.hop)}
onSelect={() => { setCustomModel(''); setCandidate(item); }}
className="model-hub-route-candidate model-hub-route-selector-row text-foreground"
>
- <span className="model-hub-route-candidate-source truncate">
- {itemIndex === 0 ? group.source.display_name : ""}
- </span>
<span className="model-hub-route-candidate-model truncate font-mono">
{item.hop.model_id}
</span>
diff --git a/ui/src/components/settings/models/RouteChainDialog.test.tsx b/ui/src/components/settings/models/RouteChainDialog.test.tsx
index d22d11870..ffb716a75 100644
--- a/ui/src/components/settings/models/RouteChainDialog.test.tsx
+++ b/ui/src/components/settings/models/RouteChainDialog.test.tsx
@@ -1155,19 +1155,24 @@ describe("RouteChainDialog", () => {
expect(screen.getByText("Model")).toBeTruthy();
// Both halves of a candidate are legible: the model id AND which source
// supplies it. The source column is what a sizing rework once dropped, so
- // the assertion is over the rendered row grid, not over the mere presence
- // of the name somewhere in the panel.
- const rows = [...document.querySelectorAll(".model-hub-route-candidate")];
+ // the assertion is over the rendered groups, not over the mere presence of
+ // the name somewhere in the panel. It is named once per group and on the
+ // group itself — a name drawn into the first row leaves the column blank
+ // for every row after it, and blank again for all of them once that row has
+ // scrolled away.
+ const groups = [...document.querySelectorAll(".model-hub-route-selector-group")];
expect(
- rows.map((row) => [
- row.querySelector(".model-hub-route-candidate-source")?.textContent,
- row.querySelector(".model-hub-route-candidate-model")?.textContent,
+ groups.map((group) => [
+ group.querySelector("[cmdk-group-heading]")?.textContent,
+ [...group.querySelectorAll(".model-hub-route-candidate-model")].map((cell) => cell.textContent),
]),
).toEqual([
- ["API key", "claude-haiku-5"],
- ["", "claude-sonnet-5"],
- ["Claude subscription", "sonnet-5"],
+ ["API key", ["claude-haiku-5", "claude-sonnet-5"]],
+ ["Claude subscription", ["sonnet-5"]],
]);
+ // And the name is not also duplicated into a row, which is what would put
+ // it back on the list's scroll.
+ expect(document.querySelector(".model-hub-route-candidate-source")).toBeNull();
});
it("narrows the candidates to what was typed without claiming none exist", async () => {
diff --git a/ui/src/components/settings/models/modelHubStylePolicy.test.ts b/ui/src/components/settings/models/modelHubStylePolicy.test.ts
index ca81a6041..3680da467 100644
--- a/ui/src/components/settings/models/modelHubStylePolicy.test.ts
+++ b/ui/src/components/settings/models/modelHubStylePolicy.test.ts
@@ -272,6 +272,48 @@ describe('Model Hub visual token policy', () => {
expect(route).toMatch(/--radix-popover-content-available-width,\s*var\(--model-hub-route-selector-inline-max\)/);
});
+ // The panel has two columns and the left one names a source that supplies
+ // several models. Written into a row, that name is on screen for exactly as
+ // long as that one row is: six models down the column beside the list is
+ // blank, which is a reader being asked to remember what they are looking at.
+ // The name belongs to the group, so it is drawn on the group's own heading and
+ // held against the list that scrolls. These are one mechanism in three rules
+ // and none of them works alone, which is why they are read together.
+ it('keeps each source beside its own models while the list scrolls', () => {
+ const group = surfaceCssBody
+ .match(/\.model-hub-route-selector-group\s*\{([^}]*)\}/)?.[1] ?? '';
+ const heading = surfaceCssBody
+ .match(/\.model-hub-route-selector-group \[cmdk-group-heading\]\s*\{([^}]*)\}/)?.[1] ?? '';
+ const items = surfaceCssBody
+ .match(/\.model-hub-route-selector-group \[cmdk-group-items\]\s*\{([^}]*)\}/)?.[1] ?? '';
+
+ expect(heading).toMatch(/position:\s*sticky/);
+ expect(heading).toMatch(/top:\s*0/);
+ // Sticky is resolved against the nearest scrolling ancestor, and cmdk's group
+ // ships `overflow: hidden`, which makes the group that ancestor: a box that
+ // never scrolls, so the heading would hold a position it already holds and
+ // leave with the rest of the group. The list is the scroller, not the group.
+ expect(group).toMatch(/overflow:\s*visible/);
+ // The heading covers the first column while the rows span both, so the name
+ // lands in the cell the rows leave empty and a highlighted row still washes
+ // the full width underneath it.
+ expect(group).toMatch(/grid-template-columns:\s*minmax\(0, 1fr\) minmax\(0, 1fr\)/);
+ expect(heading).toMatch(/grid-area:\s*1 \/ 1 \/ 2 \/ 2/);
+ expect(items).toMatch(/grid-area:\s*1 \/ 1 \/ 2 \/ -1/);
+ // Against the top of its own rows rather than centred over all of them: a
+ // heading stretched down the group would sit beside its third model and stick
+ // from there.
+ expect(heading).toMatch(/align-self:\s*start/);
+ // And bounded by that cell, which the cell it replaced already was: a source
+ // named at length reads across the models it is there to label otherwise.
+ expect(heading).toMatch(/text-overflow:\s*ellipsis/);
+ expect(heading).toMatch(/white-space:\s*nowrap/);
+ // Drawn over the top visible row and a sibling of it, so it would otherwise
+ // take that row's clicks and hovers itself — the row the pointer is nearest
+ // being the one that stops answering. A label is not aimed at.
+ expect(heading).toMatch(/pointer-events:\s*none/);
+ });
+
// The panel is one flexible list plus bands that cannot shrink, so the list is
// the only child a new band can be paid for out of — which is what happened:
// the manual source/model pair went straight into the column, nothing
diff --git a/ui/src/components/settings/models/modelHubSurface.css b/ui/src/components/settings/models/modelHubSurface.css
index 0f6bae3dc..bd9cb3046 100644
--- a/ui/src/components/settings/models/modelHubSurface.css
+++ b/ui/src/components/settings/models/modelHubSurface.css
@@ -1275,9 +1275,52 @@
flex: 1 1 auto;
overflow-y: auto;
}
-.model-hub-route-selector-group { padding: 0 6px 6px; }
+/* The source column, kept in view. The group lays its heading over the first
+ column while its rows span the whole grid, so the name occupies the cell the
+ rows leave empty and the selected row still washes edge to edge under it.
+ Sticky against the list means the name is on screen for exactly as long as
+ one of its own models is: the next group's heading arrives at the top by
+ pushing this one out, which is the same order the groups are read in. */
+.model-hub-route-selector-group {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
+ gap: 10px;
+ /* cmdk's group ships `overflow: hidden`. Left on, it would be the heading's
+ own scroll container — a box that never scrolls — and the heading would
+ stick to the top of the group it is already at the top of, which is to say
+ it would not move at all. The list is the scroller; the group is not. */
+ overflow: visible;
+ padding: 0 6px 6px;
+}
+.model-hub-route-selector-group [cmdk-group-heading] {
+ position: sticky;
+ top: 0;
+ z-index: 1;
+ grid-area: 1 / 1 / 2 / 2;
+ align-self: start;
+ /* It is drawn over the top visible row, and it is that row's sibling, not its
+ child — so without this the source half of the row the user is most likely
+ to aim at swallows the click and the hover, and the one row nearest the
+ pointer is the one that does not answer it. The name is a label; nothing in
+ it is aimed at. */
+ pointer-events: none;
+ /* Aligned with the rows it labels: the row's own inline padding, and the
+ block padding that centers one line in the 28px row beside it. */
+ padding: 6px 8px;
+ /* Its grid cell bounds the column, not the text: a source named at length
+ would otherwise run straight across the models it is there to label. Kept
+ from the cell this replaced, which truncated for the same reason. */
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ color: var(--foreground);
+ font-size: 11.5px;
+ font-weight: 400;
+ line-height: 16px;
+}
+.model-hub-route-selector-group [cmdk-group-items] { grid-area: 1 / 1 / 2 / -1; }
.model-hub-route-candidate { min-height: 28px; font-size: 11.5px; line-height: 16px; }
-.model-hub-route-candidate-model { color: var(--model-hub-ink-73); }
+.model-hub-route-candidate-model { grid-column: 2; color: var(--model-hub-ink-73); }
.model-hub-route-candidate:hover { background: var(--model-hub-wash-0a); }
.model-hub-route-candidate[data-selected="true"] {
background: var(--model-hub-mint-1a);
diff --git a/ui/src/components/ui/command.tsx b/ui/src/components/ui/command.tsx
index 9547ca293..24d8fd341 100644
--- a/ui/src/components/ui/command.tsx
+++ b/ui/src/components/ui/command.tsx
@@ -87,7 +87,11 @@ const CommandItem = React.forwardRef<
<CommandPrimitive.Item
ref={ref}
className={cn(
- "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent/10 data-[selected=true]:text-accent-ink data-[disabled=true]:opacity-50",
+ // Every item in this codebase carries an `onSelect`: there is no such
+ // thing here as one you only read. `index.css` already says a control
+ // you can click reads as a hand; an item is a control that happens to
+ // be `role="option"` rather than a button, so it says so too.
+ "relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent/10 data-[selected=true]:text-accent-ink data-[disabled=true]:opacity-50",
className
)}
{...props}