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): give the manual model draft its own two lines (#1860)

Max1ddd1cb37b44
diff --git a/ui/src/components/settings/models/SourceDetailPanel.test.tsx b/ui/src/components/settings/models/SourceDetailPanel.test.tsx
index 752d182a8..5f39b432b 100644
--- a/ui/src/components/settings/models/SourceDetailPanel.test.tsx
+++ b/ui/src/components/settings/models/SourceDetailPanel.test.tsx
@@ -898,6 +898,27 @@ describe('SourceDetailPanel', () => {
expect((add as HTMLButtonElement).disabled).toBe(true);
});
+ // Where the draft's cells sit is the stylesheet's decision — it lays the band
+ // out over two lines of its own rather than in the columns the table header
+ // names — so no cell may restate the column count in its class list. Seeded in
+ // the state where every cell exists, a failed add, and asserted over whatever
+ // the band renders: a cell added later is covered without editing a list.
+ it('places every manual-draft cell without column arithmetic in the markup', async () => {
+ vi.spyOn(modelsApi, 'addCustomModel').mockRejectedValueOnce(new Error('write failed'));
+ renderPanel();
+ await userEvent.click(screen.getAllByRole('button', { name: /^Add model$|^添加模型$/i })[0]);
+ const draft = screen.getByPlaceholderText(/^Model ID$|^模型 ID$/i)
+ .closest('[data-manual-model-draft]') as HTMLElement;
+ await userEvent.type(within(draft).getByPlaceholderText(/^Model ID$|^模型 ID$/i), 'model-b');
+ await userEvent.click(within(draft).getByRole('button', { name: /^Add model$|^添加模型$/i }));
+ // The failure line is the fourth cell, and the only one that has to be
+ // waited for; the count is what proves the band is fully seeded.
+ await waitFor(() => { expect(draft.children.length).toBe(4); });
+
+ const cells = Array.from(draft.children).map((cell) => cell.className);
+ expect(cells.filter((name) => /(?:col|row)-(?:span|start|end)-/.test(name))).toEqual([]);
+ });
+
it('keeps a failed refetch visible beside the inventory it could not replace', async () => {
vi.spyOn(modelsApi, 'refreshSource').mockRejectedValueOnce(new Error('lost response'));
renderPanel();
diff --git a/ui/src/components/settings/models/SourceDetailPanel.tsx b/ui/src/components/settings/models/SourceDetailPanel.tsx
index 6dac18358..cea6a689b 100644
--- a/ui/src/components/settings/models/SourceDetailPanel.tsx
+++ b/ui/src/components/settings/models/SourceDetailPanel.tsx
@@ -1009,14 +1009,14 @@ export const SourceDetailPanel: React.FC<{
<div
data-manual-model-draft
data-source-dialog-local-escape
- className="model-hub-source-table-draft grid gap-3 border-y border-mint/20 bg-mint/[0.05] md:items-center md:gap-y-0"
+ className="model-hub-source-table-draft grid gap-3 border-y border-mint/20 bg-mint/[0.05] md:items-center"
onKeyDown={(event) => {
if (event.key !== 'Escape') return;
event.preventDefault();
if (!busy) setManualDraft(null);
}}
>
- <span className="flex min-w-0 items-center gap-2"><Input
+ <span className="model-hub-source-draft-line flex min-w-0 items-center gap-2"><Input
autoFocus
value={manualDraft.modelId}
onChange={(event) => setManualDraft((current) => current ? { ...current, modelId: event.target.value, failed: false, retryRead: false } : current)}
@@ -1028,7 +1028,7 @@ export const SourceDetailPanel: React.FC<{
<Button variant="ghost" size="xs" disabled={busy} onClick={() => setManualDraft(null)}>{t('common.cancel')}</Button>
<Button size="xs" disabled={busy || !manualDraft.modelId.trim() || source.models.some((model) => model.id === manualDraft.modelId.trim())} onClick={() => void addManualModel()}>{manualDraft.failed ? t('settings.models.sourceDetail.retry') : t('settings.models.sourceDetail.action.addModel')}</Button>
</div>
- {manualDraft.failed && <p className="text-[11px] text-destructive-ink md:col-span-3">{t('settings.models.sourceDetail.fail.addModel')}</p>}
+ {manualDraft.failed && <p className="model-hub-source-draft-line text-[11px] text-destructive-ink">{t('settings.models.sourceDetail.fail.addModel')}</p>}
</div>
)}
</div>
diff --git a/ui/src/components/settings/models/modelHubStylePolicy.test.ts b/ui/src/components/settings/models/modelHubStylePolicy.test.ts
index b7adcaed2..04147e43d 100644
--- a/ui/src/components/settings/models/modelHubStylePolicy.test.ts
+++ b/ui/src/components/settings/models/modelHubStylePolicy.test.ts
@@ -123,4 +123,53 @@ describe('Model Hub visual token policy', () => {
expect(restated).toEqual([]);
});
+
+ // Both properties are decided by CSS that jsdom does not resolve — a grid track
+ // and a line break — so they are asserted where they are declared. They are
+ // stated as one rule each rather than as the rows that must not break: the
+ // manual-draft band broke because 手动添加 has no min-content floor to overflow
+ // against, and the same shape was already latent on any committed row whose
+ // model id was long enough to make its own pill the part that gives.
+ it('never lets a source-table pill be the part of a row that gives', () => {
+ const pill = surfaceCss.match(/\.model-hub-source-pill \{([^}]*)\}/)?.[1] ?? '';
+ expect(pill).toContain('white-space: nowrap');
+ expect(pill).toContain('flex-shrink: 0');
+
+ // And no call site hands the give back with a utility, whichever pill it draws.
+ const reopened = productFiles(__dirname).flatMap((path) => (
+ [...readFileSync(path, 'utf8').matchAll(/(['"`])((?:(?!\1)[\s\S])*)\1/g)]
+ .filter((match) => /model-hub-source-pill/.test(match[2])
+ && /(?:^|\s)(?:whitespace-(?!nowrap)|shrink(?!-0)|flex-shrink)/.test(match[2]))
+ .map((match) => `${path}:${match[2]}`)
+ ));
+
+ expect(reopened).toEqual([]);
+ });
+
+ // A column heading is a claim about the cells beneath it, so the draft either
+ // keeps the row's tracks or stops standing in them. It cannot do both: its
+ // controls are words where a row's are two 26px icons, and the only cell with
+ // room to pay the difference is the shared 1fr — which slides the tier cell
+ // out from under 推理强度. The draft takes its own two lines instead.
+ it('keeps the manual draft off the row columns and out of column arithmetic', () => {
+ // The property rather than the draft's own rule: whichever rule hands out
+ // the row template, its selector list must not name the draft. Reading only
+ // the override would pass while the shared rule still declared the token on
+ // the draft earlier and left source order to clean up after it.
+ const sharing = [...surfaceCssBody.matchAll(/([^{}]*)\{[^{}]*var\(--model-hub-source-table-columns\)[^{}]*\}/g)]
+ .map((match) => match[1]);
+ expect(sharing.some((selector) => selector.includes('model-hub-source-table-row'))).toBe(true);
+ for (const selector of sharing) expect(selector).not.toContain('model-hub-source-table-draft');
+
+ // Anchored on the preceding `}` so this is the draft's own rule, not the
+ // shared band whose selector list also ends in this class.
+ const draft = surfaceCssBody.match(/\}\s*\.model-hub-source-table-draft \{([^}]*)\}/)?.[1] ?? '';
+ expect(draft).toContain('grid-template-columns: minmax(0, 1fr) auto');
+
+ // Full width as a span to both edges, never as a count: the count has
+ // already changed once, and the cell that carried it through the change is
+ // how the failure line lands in an implicit fourth track.
+ const line = surfaceCssBody.match(/\.model-hub-source-draft-line \{([^}]*)\}/)?.[1] ?? '';
+ expect(line).toContain('grid-column: 1 / -1');
+ });
});
diff --git a/ui/src/components/settings/models/modelHubSurface.css b/ui/src/components/settings/models/modelHubSurface.css
index 5fc00dcf5..63c7f2f69 100644
--- a/ui/src/components/settings/models/modelHubSurface.css
+++ b/ui/src/components/settings/models/modelHubSurface.css
@@ -1248,13 +1248,20 @@
}
.model-hub-source-search { background: var(--model-hub-wash-05); }
.model-hub-source-table { border-radius: var(--model-hub-source-radius); }
+/* Every band sits inside the same table edges and splits its cells by the same
+ gap, whether or not it stands in the table's columns. */
.model-hub-source-table-head,
.model-hub-source-table-row,
.model-hub-source-table-draft {
- grid-template-columns: var(--model-hub-source-table-columns);
column-gap: var(--model-hub-source-table-gap);
padding-inline: var(--model-hub-source-table-padding-x);
}
+/* The columns are what a heading makes a claim about, so only the bands read
+ against that heading take them. */
+.model-hub-source-table-head,
+.model-hub-source-table-row {
+ grid-template-columns: var(--model-hub-source-table-columns);
+}
.model-hub-source-row-action {
width: 26px;
height: 26px;
@@ -1281,11 +1288,23 @@
min-height: var(--model-hub-source-table-row-height);
padding-block: var(--model-hub-source-table-padding-y);
}
+/* The draft is a form, not a row, so it stops claiming the row's columns.
+ Sharing them cannot work: the trailing track is cut for two 26px icon buttons,
+ the draft's controls are words instead — 取消 plus 添加模型 measure 128px, and
+ more than that in English — and the only cell with room to pay for the
+ difference is the shared 1fr, which would slide the tier cell out from under
+ the header it is read against. Two lines instead: the model id over the full
+ width, then the tier editor beside controls sized by their own labels. Height
+ follows that content, as it does for a row whose tier editor is open. */
.model-hub-source-table-draft {
- --model-hub-source-table-draft-height: 56px;
- min-height: var(--model-hub-source-table-draft-height);
+ grid-template-columns: minmax(0, 1fr) auto;
padding-block: var(--model-hub-source-table-padding-y);
}
+/* Stated as a span to both edges rather than as a column count: the count is a
+ layout decision that has already changed once, and a cell carrying `col-span-3`
+ through that change is how the failure line ends up in an implicit fourth
+ track. Correct in the stacked band below md too, where there is one column. */
+.model-hub-source-draft-line { grid-column: 1 / -1; }
.model-hub-source-add-hint {
color: var(--model-hub-source-summary-ink);
font-size: var(--model-hub-source-tier-size);
@@ -1299,10 +1318,20 @@
--model-hub-source-manual-input-radius: 7px;
border-radius: var(--model-hub-source-manual-input-radius);
}
+/* A pill is a fixed label, so it is never the part of a row that gives. Both
+ declarations are load-bearing and neither works alone: `nowrap` because a
+ Chinese label has no min-content floor — it breaks between characters, so a
+ flex row that runs short turns 手动添加 into two lines instead of overflowing —
+ and `flex-shrink: 0` because nowrap alone would let the fill shrink out from
+ under text that no longer wraps. Stated here rather than at a call site: the
+ label beside a field or a truncating id is the same shape everywhere it
+ appears, and the field or the id is what should absorb the shortfall. */
.model-hub-source-pill {
--model-hub-source-pill-size: 10px;
font-size: var(--model-hub-source-pill-size);
line-height: 14px;
+ white-space: nowrap;
+ flex-shrink: 0;
}
.model-hub-source-tier { font-size: var(--model-hub-source-tier-size); }
.model-hub-source-tier-chip {