Skip to content
Open
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
23 changes: 12 additions & 11 deletions src/canvas/DraftAvailabilityCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import {
} from "../backend/models.ts";
import type { ModelAvailability } from "../backend/availability.ts";
import { errorMessage } from "../backend/api.ts";
import { ModelAvailabilityCard } from "./ModelAvailabilityCard";

/** A draft check never publishes an observation into the saved model catalog. */
export function DraftAvailabilityCheck({
/**
* A draft check never publishes an observation into the saved model catalog.
* The row header and the expanded card read the same observation, so the check
* lives in a hook they can share.
*/
export function useDraftAvailability({
connection,
configId,
modelId,
Expand Down Expand Up @@ -65,12 +68,10 @@ export function DraftAvailabilityCheck({
if (alive.current && serial.current === attempt) setPending(null);
}
};
return (
<ModelAvailabilityCard
value={value?.signature === signature ? value.observation : null}
checking={pending === signature}
onRefresh={() => void check()}
error={failure?.signature === signature ? failure.message : undefined}
/>
);
return {
value: value?.signature === signature ? value.observation : null,
checking: pending === signature,
error: failure?.signature === signature ? failure.message : undefined,
check: () => void check(),
};
}
55 changes: 35 additions & 20 deletions src/canvas/ModelAvailabilityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ export function ModelAvailabilityCard({
checking = false,
title,
error,
actions = true,
}: {
value?: ModelAvailability | null;
onRefresh?: () => void;
checking?: boolean;
title?: string;
error?: string;
/** The service form owns the single check entry on the row itself. */
actions?: boolean;
}) {
const { t, locale } = useI18n();
const [tick, setTick] = useState(0);
Expand All @@ -40,6 +43,9 @@ export function ModelAvailabilityCard({
}, [value, tick]);
const current = value ? currentAvailability(value) : null;
const notice = availabilityNotice(current);
// Every shared notice keeps one readable sentence. Chips alone are not enough:
// an expired observation greys them out and the row still reads "tested", so
// the reason has to stay in words.
const message = checking
? null
: error || (notice ? availabilityReason(notice) : null);
Expand All @@ -55,8 +61,35 @@ export function ModelAvailabilityCard({
aria-label={t("availability.title")}
>
<div className="cw-model-availability-heading">
<strong>{title ?? t("availability.title")}</strong>
{onRefresh && (
<div className="cw-model-availability-title">
<strong>{title ?? t("availability.title")}</strong>
{current?.operations.length ? (
<span className="cw-availability-chips">
{current.operations.map((item) => {
const chip = availabilityRow(item, notice);
return (
<span
key={`${item.operation}:${item.profile}:${item.path}`}
className="cw-availability-chip"
data-availability={chip.status}
data-stale={chip.muted || undefined}
>
<span className="cw-availability-op">
{availabilityProfile(item.profile)}
</span>
<span
className="cw-availability-state"
data-availability={chip.status}
>
{chip.text}
</span>
</span>
);
})}
</span>
) : null}
</div>
{actions && onRefresh && (
<button
type="button"
className="cw-settings-button"
Expand All @@ -76,24 +109,6 @@ export function ModelAvailabilityCard({
)}
</div>
{message && <p role={error ? "alert" : "status"}>{message}</p>}
{current?.operations.length ? (
<ul>
{current.operations.map((item) => {
const row = availabilityRow(item, notice);
return (
<li
key={`${item.operation}:${item.profile}:${item.path}`}
data-stale={row.muted || undefined}
>
<span>{availabilityProfile(item.profile)}</span>
<div>
<span data-availability={row.status}>{row.text}</span>
</div>
</li>
);
})}
</ul>
) : null}
{details.length > 0 && (
<details
className="cw-model-input-details"
Expand Down
41 changes: 29 additions & 12 deletions src/canvas/ModelPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function ModelPicker({
onTest,
results,
renderDetails,
compact = false,
}: {
modelPlaceholder: string;
available: string[];
Expand All @@ -38,6 +39,9 @@ export function ModelPicker({
onTest?: (id: string) => void;
results: Record<string, ModelTestResult>;
renderDetails?: (id: string) => ReactNode;
/** Denser form layout: the count row carries the fetch result and the
selection filter stays out of the way. */
compact?: boolean;
}) {
const t = useT();
const manualFieldId = useId();
Expand All @@ -55,6 +59,11 @@ export function ModelPicker({
);
const allSelected =
visible.length > 0 && visible.every((id) => selected.includes(id));
// The count row only exists for longer lists; without it the status line is
// the only fetch feedback and must stay.
const denseCount = compact && ids.length > 4;
const redundantStatus =
denseCount && loaded && !loading && !error && available.length > 0;
const fetchLabel = loadsPreset
? "models.service.loadSupportedModels"
: loaded ? "generation.picker.refresh" : "generation.picker.fetch";
Expand Down Expand Up @@ -119,9 +128,13 @@ export function ModelPicker({
</button>
</div>
</div>
<div role="status">
{status && <p className="cw-model-note">{status}</p>}
</div>
{/* The dense form shows the fetch result in the count row, so only a
pending, empty or failed fetch keeps its own status line. */}
{(!compact || !redundantStatus) && (
<div role="status">
{status && <p className="cw-model-note">{status}</p>}
</div>
)}
{error && (
<p className="cw-model-feedback" role="alert">
{error}
Expand Down Expand Up @@ -186,18 +199,22 @@ export function ModelPicker({
onChange={(event) => setQuery(event.target.value)}
/>
</label>
<button
type="button"
className="cw-settings-button cw-model-filter"
aria-pressed={onlySelected}
onClick={() => setOnlySelected(!onlySelected)}
>
{t("generation.picker.onlySelected")}
</button>
{!compact && (
<button
type="button"
className="cw-settings-button cw-model-filter"
aria-pressed={onlySelected}
onClick={() => setOnlySelected(!onlySelected)}
>
{t("generation.picker.onlySelected")}
</button>
)}
</div>
<div className="cw-model-bulk">
<span>
{t("generation.picker.count", { count: visible.length })}
{denseCount && loaded && !loading && !error && available.length
? t("generation.picker.fetched", { count: available.length })
: t("generation.picker.count", { count: visible.length })}
</span>
<button
type="button"
Expand Down
62 changes: 62 additions & 0 deletions src/canvas/ModelRowDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { ReactNode } from "react";
import type { ModelConfigInput } from "../backend/models.ts";
import { useT } from "../i18n/I18nProvider";
import { useDraftAvailability } from "./DraftAvailabilityCheck";
import { ModelAvailabilityCard } from "./ModelAvailabilityCard";

/** One model row of the service form.
*
* The check action sits on the model line: it offers the check until the
* service answers, then reports the result. Everything else — chips, input
* rules, the per-kind parameters — stays folded behind one summary, so a list
* of selected models keeps one line per model until the row is opened.
*/
export function ModelRowDetails({
modelId,
connection,
configId,
children,
}: {
modelId: string;
connection: ModelConfigInput;
configId?: string;
children: ReactNode;
}) {
const t = useT();
const draft = useDraftAvailability({ connection, configId, modelId });
// Chat rows already carry the picker's own connection test.
const showTest = connection.kind !== "agent";
return (
<>
{showTest && (
<button
type="button"
className="cw-settings-button cw-settings-button-quiet cw-model-row-test"
disabled={draft.checking}
aria-busy={draft.checking || undefined}
onClick={draft.check}
>
{t(
draft.checking
? "availability.checking"
: draft.error
? "availability.reason.query_failed"
: draft.value
? "availability.rowTested"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收起后这里会把所有拿到回执的非 Chat 模型都显示成「已测试」,即使三项能力都不支持或结果未知;耗时也没显示。这样用户还是得逐行展开才能看 #574 要的测试结果。能否从现有检查回执导出一个简短的行内结果(含耗时,拿不到就明确不显示),再补一个「保持折叠时通过/失败可区分」的浏览器断言?

: "availability.rowTest",
)}
</button>
)}
<details className="cw-model-row-details">
<summary>{t("models.service.capabilityDetails")}</summary>
<ModelAvailabilityCard
value={draft.value}
checking={draft.checking}
error={draft.error}
actions={false}
/>
{children}
</details>
</>
);
}
44 changes: 24 additions & 20 deletions src/canvas/ModelServiceForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DraftAvailabilityCheck } from "./DraftAvailabilityCheck";
import { ProviderPicker } from "./ProviderPicker";
import { useId, useLayoutEffect, useState, type FormEvent, type Ref } from "react";
import { errorMessage } from "../backend/api.ts";
Expand All @@ -16,6 +15,7 @@ import {
type ModelKind,
} from "../backend/rules.ts";
import { ModelCapabilityCard } from "./ModelCapabilityCard";
import { ModelRowDetails } from "./ModelRowDetails";
import {
PROVIDER_PRESETS,
matchingConnections,
Expand Down Expand Up @@ -550,28 +550,32 @@ export function ModelServiceForm({
}}
onTest={kind === "agent" ? (id) => void test(id) : undefined}
results={results}
compact
renderDetails={(id) => (
<>
<DraftAvailabilityCheck connection={{ ...value, ...optionsFor(id) }} configId={connection?.id} modelId={id} />
<ModelCapabilityCard
key={`${connection?.id ?? "new"}:${value.protocol}:${id}`}
<ModelRowDetails
modelId={id}
connection={value}
connection={{ ...value, ...optionsFor(id) }}
configId={connection?.id}
saved={savedModel(id)}
options={optionsFor(id)}
disabled={locked}
onChange={(patch) =>
setModelOptions((current) => ({
...current,
[id]: { ...current[id], ...patch },
}))
}
onValidity={(message) =>
setModelErrors((current) => ({ ...current, [id]: message }))
}
/>
</>
>
<ModelCapabilityCard
key={`${connection?.id ?? "new"}:${value.protocol}:${id}`}
modelId={id}
connection={value}
configId={connection?.id}
saved={savedModel(id)}
options={optionsFor(id)}
disabled={locked}
onChange={(patch) =>
setModelOptions((current) => ({
...current,
[id]: { ...current[id], ...patch },
}))
}
onValidity={(message) =>
setModelErrors((current) => ({ ...current, [id]: message }))
}
/>
</ModelRowDetails>
)}
/>
{segmentation && (
Expand Down
Loading
Loading