diff --git a/src/canvas/DraftAvailabilityCheck.tsx b/src/canvas/DraftAvailabilityCheck.tsx index 6230c01fa..c96e8b614 100644 --- a/src/canvas/DraftAvailabilityCheck.tsx +++ b/src/canvas/DraftAvailabilityCheck.tsx @@ -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, @@ -65,12 +68,10 @@ export function DraftAvailabilityCheck({ if (alive.current && serial.current === attempt) setPending(null); } }; - return ( - 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(), + }; } diff --git a/src/canvas/ModelAvailabilityCard.tsx b/src/canvas/ModelAvailabilityCard.tsx index fbc311366..0c9542ec6 100644 --- a/src/canvas/ModelAvailabilityCard.tsx +++ b/src/canvas/ModelAvailabilityCard.tsx @@ -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); @@ -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); @@ -55,8 +61,35 @@ export function ModelAvailabilityCard({ aria-label={t("availability.title")} >
- {title ?? t("availability.title")} - {onRefresh && ( +
+ {title ?? t("availability.title")} + {current?.operations.length ? ( + + {current.operations.map((item) => { + const chip = availabilityRow(item, notice); + return ( + + + {availabilityProfile(item.profile)} + + + {chip.text} + + + ); + })} + + ) : null} +
+ {actions && onRefresh && (
-
- {status &&

{status}

} -
+ {/* 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) && ( +
+ {status &&

{status}

} +
+ )} {error && (

{error} @@ -186,18 +199,22 @@ export function ModelPicker({ onChange={(event) => setQuery(event.target.value)} /> - + {!compact && ( + + )}

- {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 })} + )} +
+ {t("models.service.capabilityDetails")} + + {children} +
+ + ); +} diff --git a/src/canvas/ModelServiceForm.tsx b/src/canvas/ModelServiceForm.tsx index 7311da83d..b23f54832 100644 --- a/src/canvas/ModelServiceForm.tsx +++ b/src/canvas/ModelServiceForm.tsx @@ -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"; @@ -16,6 +15,7 @@ import { type ModelKind, } from "../backend/rules.ts"; import { ModelCapabilityCard } from "./ModelCapabilityCard"; +import { ModelRowDetails } from "./ModelRowDetails"; import { PROVIDER_PRESETS, matchingConnections, @@ -550,28 +550,32 @@ export function ModelServiceForm({ }} onTest={kind === "agent" ? (id) => void test(id) : undefined} results={results} + compact renderDetails={(id) => ( - <> - - - setModelOptions((current) => ({ - ...current, - [id]: { ...current[id], ...patch }, - })) - } - onValidity={(message) => - setModelErrors((current) => ({ ...current, [id]: message })) - } - /> - + > + + setModelOptions((current) => ({ + ...current, + [id]: { ...current[id], ...patch }, + })) + } + onValidity={(message) => + setModelErrors((current) => ({ ...current, [id]: message })) + } + /> + )} /> {segmentation && ( diff --git a/src/canvas/model-settings.css b/src/canvas/model-settings.css index 9ddb679f1..017de9bf6 100644 --- a/src/canvas/model-settings.css +++ b/src/canvas/model-settings.css @@ -676,12 +676,94 @@ .cw-model-editor-scroll > .cw-model-connection-details { margin: 0 0 16px; } .cw-model-editor-scroll > .cw-provider-key { margin: 0 0 18px; } +/* The row keeps one line until the summary is opened: the fold label sits + inline with the model name and the test action. */ +.cw-model-option > .cw-model-row-details { + flex: 0 0 auto; + margin-left: auto; +} +.cw-model-option > .cw-model-row-details[open] { + flex-basis: 100%; + margin-left: 0; +} +.cw-model-row-details > summary { + display: flex; + align-items: center; + gap: 6px; + cursor: pointer; + list-style: none; + color: var(--settings-muted); + font-size: var(--settings-caption-size); + white-space: nowrap; +} +.cw-model-row-details > summary::-webkit-details-marker { + display: none; +} +.cw-model-row-details > summary::before { + content: "▸"; + font-size: 10px; + line-height: 1; +} +.cw-model-row-details[open] > summary::before { + content: "▾"; +} +.cw-model-row-details[open] > summary { + margin-bottom: 8px; +} + .cw-model-availability { padding: 12px 0; font-size: var(--settings-label-size, 13px); } .cw-model-option > .cw-model-availability { flex-basis: 100%; width: 100%; min-width: 0; border-top: 1px solid var(--settings-border); } .cw-model-availability-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; } +.cw-model-availability-title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 0; } +.cw-availability-chips { display: flex; flex-wrap: wrap; gap: 6px; } +.cw-availability-chip { + display: inline-flex; + align-items: center; + gap: 7px; + padding: 3px 10px; + border: 1px solid var(--settings-border); + border-radius: 999px; + background: var(--settings-input); + color: var(--settings-text); + font-size: var(--settings-caption-size); + line-height: 1.5; + white-space: nowrap; +} +.cw-availability-chip .cw-availability-op { color: inherit; } +.cw-availability-chip[data-availability="available"] { + border-color: color-mix(in srgb, var(--settings-positive) 45%, transparent); + background: var(--settings-positive-background); + color: var(--settings-positive); +} +.cw-availability-chip[data-availability="unavailable"] { + border-color: color-mix(in srgb, var(--settings-negative) 45%, transparent); + background: var(--settings-negative-background); + color: var(--settings-negative); +} +.cw-availability-chip[data-availability="unknown"] { color: var(--settings-text); } .cw-model-availability p, .cw-model-availability small { color: var(--settings-muted); } .cw-model-availability ul { display: grid; gap: 8px; margin: 10px 0; padding: 0; list-style: none; } .cw-model-availability li { display: grid; grid-template-columns: minmax(80px, 1fr) minmax(0, 3fr); gap: 12px; overflow-wrap: anywhere; } +.cw-availability-state { + display: inline-flex; + align-items: center; + gap: 5px; + color: var(--settings-muted); +} +.cw-availability-state::before { + content: ""; + width: 5px; + height: 5px; + flex: none; + border-radius: 50%; + background: currentColor; +} +.cw-availability-state[data-availability="available"] { color: var(--settings-positive); } +.cw-availability-state[data-availability="unavailable"] { + color: var(--settings-negative); + font-weight: 500; +} +.cw-availability-state[data-availability="unknown"] { color: var(--settings-muted); } .cw-model-availability-details { padding: 12px 16px; border-top: 1px solid var(--settings-border); } .cw-model-availability-details summary { cursor: pointer; } .cw-model-availability [data-availability="unavailable"] { color: var(--cw-danger, #b45336); } @@ -693,3 +775,7 @@ .cw-model-input-details dd { margin: 0; } .cw-model-input-details small { display: block; } .cw-model-input-details summary small { display: inline; margin-inline-start: 8px; } + +/* The check action rides on the model line; the capability card follows it on + its own line, so a row costs one line until the service answers. */ +.cw-model-row-test { margin-inline-start: auto; } diff --git a/src/canvas/themes.css b/src/canvas/themes.css index e8096fc82..74ac0a933 100644 --- a/src/canvas/themes.css +++ b/src/canvas/themes.css @@ -10,6 +10,10 @@ --settings-input: #19191b; --settings-warning: #f3b7a6; --settings-warning-background: #45332c; + --settings-positive: #8ed3a8; + --settings-positive-background: #24382e; + --settings-negative: #f0a3a3; + --settings-negative-background: #43282a; } :root[data-theme="light"] { color-scheme: light; @@ -25,6 +29,10 @@ --settings-input: #fafbfc; --settings-warning: #9a4d36; --settings-warning-background: #fff1e9; + --settings-positive: #2f7a4f; + --settings-positive-background: #eaf6ee; + --settings-negative: #a63c3c; + --settings-negative-background: #fdeeee; } :root[data-theme="light"] .cw-workspace { background: #f7f8fa; diff --git a/src/i18n/messages/en-US/availability.ts b/src/i18n/messages/en-US/availability.ts index d54d31528..01efc4f8a 100644 --- a/src/i18n/messages/en-US/availability.ts +++ b/src/i18n/messages/en-US/availability.ts @@ -50,6 +50,9 @@ export const availability = { "availability.checkedAt": "Last checked: {time}", "availability.status.available": "Supported", "availability.status.unknown": "Unknown", + "availability.rowTest": "Test", + "availability.rowTested": "Tested", + "availability.rowExpired": "Expired", "availability.reason.not_checked": "Not checked", "availability.reason.supported": "Supported", "availability.reason.operation_unsupported": "Not supported", diff --git a/src/i18n/messages/en-US/models.ts b/src/i18n/messages/en-US/models.ts index 70f5c5557..8fcff9de9 100644 --- a/src/i18n/messages/en-US/models.ts +++ b/src/i18n/messages/en-US/models.ts @@ -136,6 +136,7 @@ export const models = { "models.service.reuseConnection": "Reuse saved connection · {model}", "models.service.reuseHint": "Otherwise this will be saved as a separate connection.", + "models.service.capabilityDetails": "Capabilities and parameters", "models.service.loadSupportedModels": "Load supported models", "models.service.minimaxNote": "The model list comes from the built-in declaration. Loading it does not verify the key or create a video task.", diff --git a/src/i18n/messages/zh-CN/availability.ts b/src/i18n/messages/zh-CN/availability.ts index 0f453af53..6b9bca899 100644 --- a/src/i18n/messages/zh-CN/availability.ts +++ b/src/i18n/messages/zh-CN/availability.ts @@ -50,6 +50,9 @@ export const availability = { "availability.checkedAt": "最近检查:{time}", "availability.status.available": "支持", "availability.status.unknown": "待确认", + "availability.rowTest": "测试", + "availability.rowTested": "已测试", + "availability.rowExpired": "已过期", "availability.reason.not_checked": "尚未检查", "availability.reason.supported": "支持", "availability.reason.operation_unsupported": "不支持", diff --git a/src/i18n/messages/zh-CN/models.ts b/src/i18n/messages/zh-CN/models.ts index 4734a16a0..3a0519aa7 100644 --- a/src/i18n/messages/zh-CN/models.ts +++ b/src/i18n/messages/zh-CN/models.ts @@ -112,6 +112,7 @@ export const models = { "models.service.existingConnections": "已有相同地址的连接", "models.service.reuseConnection": "复用已保存连接 · {model}", "models.service.reuseHint": "不复用则保存为独立连接。", + "models.service.capabilityDetails": "服务能力与参数", "models.service.loadSupportedModels": "载入支持的模型", "models.service.minimaxNote": "模型列表来自内置声明,载入不验证密钥,也不创建视频任务。", diff --git a/tests/browser/capability_discovery.mjs b/tests/browser/capability_discovery.mjs index 3f153e4c6..5c3afae71 100644 --- a/tests/browser/capability_discovery.mjs +++ b/tests/browser/capability_discovery.mjs @@ -260,7 +260,44 @@ try { .locator(".cw-model-manual") .getByRole("button", { name: "Add", exact: true }) .click(); + // The check action rides on the model line; the capability card follows it. + const test = page.locator(".cw-model-row-test").first(); + await test.waitFor(); + assert.equal( + (await test.textContent())?.trim(), + "Test", + "a model that was never checked offers the check action", + ); + // #574: a selected model keeps one line until its summary is opened, and the + // only check entry on that line is the row action. + const row = page.locator(".cw-model-option").first(); + const fold = row.locator(".cw-model-row-details"); + await fold.waitFor(); + assert.equal( + await fold.evaluate((element) => element.open), + false, + "capability details stay folded by default", + ); + assert.equal( + await row.locator("button").count(), + 1, + "the folded row offers exactly one action", + ); + assert.equal( + (await fold.locator("> summary").innerText()).trim(), + "Capabilities and parameters", + "the fold is labelled", + ); + await fold.locator("> summary").click(); const draft = page.locator(".cw-model-editor .cw-model-availability"); + await draft.waitFor(); + // The row action is the only check entry, so every workflow click goes there. + const checkRow = () => page.locator(".cw-model-row-test").first().click(); + assert.equal( + await row.locator("button").count(), + 1, + "opening the fold does not add a second action", + ); async function presentInBothLanguages(state, expected) { for (const locale of ["en-US", "zh-CN"]) { await page.evaluate((next) => { @@ -385,9 +422,7 @@ try { const lateDraft = page.waitForResponse((response) => response.url().endsWith("/model-configs/availability/check"), ); - await draft - .getByRole("button", { name: /^(Check|Refresh|Retry)$/, exact: true }) - .click(); + await checkRow(); await page .getByLabel("Service URL (Base URL)", { exact: true }) .fill(serviceUrl + "/changed"); @@ -402,9 +437,7 @@ try { .getByLabel("Service URL (Base URL)", { exact: true }) .fill(serviceUrl); delay = 0; - await draft - .getByRole("button", { name: /^(Check|Refresh|Retry)$/, exact: true }) - .click(); + await checkRow(); await draft.getByText("Not supported").first().waitFor(); assert.equal( (await call("/api/model-configs")).some((item) => item.modelId === served), @@ -424,10 +457,10 @@ try { const draftUrl = page.getByLabel("Service URL (Base URL)", { exact: true }); async function checkDraft(nextMode) { mode = nextMode; - await draft - .getByRole("button", { name: /^(Check|Refresh|Retry)$/, exact: true }) - .click(); - await until(async () => !(await draft.getByRole("button").isDisabled())); + await checkRow(); + await until( + async () => !(await page.locator(".cw-model-row-test").first().isDisabled()), + ); assert.equal(await draftUrl.inputValue(), serviceUrl); assert.equal( (await call("/api/model-configs")).some( @@ -447,8 +480,16 @@ try { "Single-image editing", "Multi-image editing", ]) - assert.equal(await draft.getByText(label, { exact: true }).count(), 1); - assert.equal(await draft.locator("[data-availability=available]").count(), 3); + assert.equal( + await draft.getByText(label, { exact: true }).count(), + 1, + `${label} appears once, with its state beside it`, + ); + assert.equal( + await draft.locator(".cw-availability-chip[data-availability=available]").count(), + 3, + "every supported capability is marked on its chip", + ); await draft.getByText("Input requirements", { exact: true }).click(); await presentInBothLanguages("normal", null); assert.equal( @@ -474,7 +515,7 @@ try { }), ); }); - await draft.getByText("多图编辑", { exact: true }).waitFor(); + await draft.locator(".cw-availability-op", { hasText: "多图编辑" }).waitFor(); assert.equal(await draft.getByText("选区输入", { exact: true }).count(), 1); assert.equal(await draft.getByText("1–3 张", { exact: true }).count(), 1); assert.equal(await draft.getByText("服务声明", { exact: true }).count(), 1); @@ -491,7 +532,7 @@ try { }), ); }); - await draft.getByText("Multi-image editing", { exact: true }).waitFor(); + await draft.locator(".cw-availability-op", { hasText: "Multi-image editing" }).waitFor(); await checkDraft("partial"); assert.equal(await draft.getByRole("status").count(), 0); assert.equal( @@ -505,7 +546,10 @@ try { await draft.getByText("Service paused", { exact: true }).count(), 0, ); - assert.equal(await draft.locator("[data-availability=available]").count(), 3); + assert.equal( + await draft.locator(".cw-availability-chip[data-availability=available]").count(), + 3, + ); await checkDraft("partial"); await presentInBothLanguages("partial", { "en-US": "Image count not confirmed", @@ -573,7 +617,7 @@ try { 0, ); assert.equal( - await draft.locator("li [data-availability=unknown]").count(), + await draft.locator(".cw-availability-chip[data-availability=unknown]").count(), 3, ); } @@ -602,11 +646,15 @@ try { // Freeze before the response: advancing to pauseAt after receiving it would // expire the very observation whose two language presentations we inspect. await pauseCapabilityClock(); - await draft.getByRole("button", { name: "Retry", exact: true }).click(); + await checkRow(); assert.equal( - await draft.getByText("Checking…", { exact: true }).count(), + await page + .locator(".cw-model-row-test") + .first() + .getByText("Checking…", { exact: true }) + .count(), 1, - "checking appears only on the button", + "checking appears only on the row action", ); assert.equal(await draft.getByRole("status").count(), 0); await draft.getByText("Service paused", { exact: true }).waitFor(); @@ -630,21 +678,17 @@ try { 0, ); assert.equal( - await draft.locator("[data-availability=available]").count(), + await draft.locator(".cw-availability-chip[data-availability=available]").count(), 3, "pause expiry restores the retained declaration", ); await page.clock.fastForward(25100); - await draft - .getByText("Results expired. Refresh to check again.", { exact: true }) - .waitFor(); - assert.equal( - await draft - .getByText("Results expired. Refresh to check again.", { exact: true }) - .count(), - 1, - ); - assert.equal(await draft.locator("li[data-stale]").count(), 3); + // An expired observation marks every capability and the row instead of + // repeating one banner line. + await draft.locator(".cw-availability-chip[data-stale]").first().waitFor(); + assert.equal(await draft.locator(".cw-availability-chip[data-stale]").count(), 3); + // #574 review: an expired observation keeps a readable sentence, not just grey + // chips, because the row action still reads "Tested". await presentInBothLanguages("expired", { "en-US": "Results expired. Refresh to check again.", "zh-CN": "检查结果已过期,请刷新", @@ -830,7 +874,10 @@ try { await page.unroute(refreshUrl); await page.waitForTimeout(100); assert.equal(await serviceCard.getByText("Not supported", { exact: true }).count(), 0); - assert.equal(await serviceCard.locator("[data-availability=available]").count(), 3); + assert.equal( + await serviceCard.locator(".cw-availability-chip[data-availability=available]").count(), + 3, + ); // A remote negative declaration already 21 days old must not block this // saved selection or the actual generation performed below. diff --git a/tests/browser/kling_video.mjs b/tests/browser/kling_video.mjs index 06f9e85b2..5a6f96e38 100644 --- a/tests/browser/kling_video.mjs +++ b/tests/browser/kling_video.mjs @@ -185,6 +185,13 @@ try { await page .getByRole("checkbox", { name: "kling-4.0-flash", exact: true }) .check(); + const flashCard = page + .locator(".cw-model-option") + .filter({ hasText: "kling-4.0-flash" }) + .locator(".cw-model-capability-card") + .first(); + if (!(await flashCard.evaluate((element) => element.open))) + await flashCard.locator("summary").click(); await page.getByText(text.flashSummary, { exact: true }).waitFor(); await page.getByText("720P", { exact: true }).waitFor(); await page diff --git a/tests/browser/provider_settings.mjs b/tests/browser/provider_settings.mjs index aff5d2800..5b5ce1b80 100644 --- a/tests/browser/provider_settings.mjs +++ b/tests/browser/provider_settings.mjs @@ -105,6 +105,13 @@ try { } finally { await page.unroute(discoveryEndpoint); } + // The check action rides on the model line; the card is already visible. + await page.locator(".cw-model-row-test").first().waitFor(); + const firstFold = page.locator(".cw-model-row-details").first(); + await firstFold.waitFor(); + if (!(await firstFold.evaluate((element) => element.open))) + await firstFold.locator("> summary").click(); + await page.locator(".cw-model-editor .cw-model-availability").first().waitFor(); await page .getByText("Text-to-video / first-last frame / multimodal references", { exact: true }).first() .waitFor(); @@ -136,9 +143,22 @@ try { .locator(".cw-model-option") .filter({ hasText: "image-card" }); const textCard = page.locator(".cw-model-option").filter({ hasText: "text-card" }); - await textCard.locator("summary").click(); + // The row folds its capability detail; the card inside folds its options. + const openDetails = async (option) => { + const rowFold = option.locator(".cw-model-row-details").first(); + if ( + (await rowFold.count()) && + !(await rowFold.evaluate((element) => element.open)) + ) + await rowFold.locator("> summary").click(); + const card = option.locator(".cw-model-capability-card").first(); + if (!(await card.count())) return; + if (!(await card.evaluate((element) => element.open))) + await card.locator("summary").click(); + }; + await openDetails(textCard); await textCard.getByRole("checkbox", { name: "Image understanding", exact: true }).uncheck(); - await card.locator("summary").click(); + await openDetails(card); await card.getByRole("checkbox", { name: "Image understanding", exact: true }).check(); await page.screenshot({ path: "/tmp/provider-settings-agent.png" }); await page.getByRole("button", { name: "Save service", exact: true }).click();