diff --git a/calliope-web/src/lib/components/manage/ComfyConnections.svelte b/calliope-web/src/lib/components/manage/ComfyConnections.svelte index e5cc7d65..acdcff18 100644 --- a/calliope-web/src/lib/components/manage/ComfyConnections.svelte +++ b/calliope-web/src/lib/components/manage/ComfyConnections.svelte @@ -1,18 +1,14 @@ {#if $settingsQuery.isLoading}

正在读取连接… -

{:else if $settingsQuery.isError}{:else if $settingsQuery.isError}

连接加载失败

{:else} -
- {#each endpoints as ep (ep.id)}{@const rec = tests[ep.id]} -
-
- {ep.name}{rec?.ms != null ? Math.round(rec.ms) + "ms" : "—"} -
-
{ep.base_url}
-
- {rec?.ok === false - ? "连接失败 · " + (rec.reason ?? "原因未知") - : rec?.ok - ? "连接测试通过" - : "尚未测试"} · 队列未知 · 显存未知 -
-
- {workflowsBound(ep.id)} 个工作流使用 -
-
- {/each} - - -
{/if} - - + loading={formPending} + onclick={runTest}>测试连接 + {/if} + + {/if} + import "./models-v2.css"; import { createMutation, createQuery, useQueryClient, } from "@tanstack/svelte-query"; - import { untrack } from "svelte"; - import { SvelteSet } from "svelte/reactivity"; - import { fade } from "svelte/transition"; - import Modal from "$lib/components/ui/Modal.svelte"; + import { page } from "$app/state"; + import { onMount } from "svelte"; import Button from "$lib/components/ui/Button.svelte"; import ConfirmDialog from "$lib/components/ui/ConfirmDialog.svelte"; - import Icon from "$lib/components/ui/Icon.svelte"; import { settings, type LlmProfile, type Settings } from "$lib/api"; + import { classifyEndpoint, endpointTypeLabel } from "$lib/endpointKind"; import { randomId } from "$lib/ids"; import { toast } from "$lib/toast"; import { t } from "$lib/i18n.svelte"; @@ -41,6 +40,7 @@ at: number; fails: number; reason?: string; + detail?: string; }; const TESTS_KEY = "calliope.models.tests"; let tests = $state>({}); @@ -94,8 +94,6 @@ let formPending = $state(false); let showErrors = $state(false); - const TIMEOUT_OPTIONS = [5, 10, 15, 30, 60]; - function resetForm() { formMode = "idle"; editingId = null; @@ -145,7 +143,11 @@ if (!form.model.trim()) errs.model = t("models.errModel"); // Key is required when creating; on edit an empty field keeps the // stored key (masked tail placeholder covers the affordance). - if (formMode === "add" && !form.apiKey.trim()) + if ( + formMode === "add" && + !form.apiKey.trim() && + classifyEndpoint(form.baseUrl) === "cloud" + ) errs.apiKey = t("models.errKey"); return errs; }); @@ -198,7 +200,12 @@ showErrors = true; if (!urlValid || !form.model.trim()) return; // On add the key is required before anything can be probed. - if (formMode === "add" && !form.apiKey.trim()) return; + if ( + formMode === "add" && + !form.apiKey.trim() && + classifyEndpoint(form.baseUrl) === "cloud" + ) + return; formPending = true; formTest = null; formTestFailure = null; @@ -313,7 +320,7 @@ function submitSave() { showErrors = true; - if (!formValid || !formTest?.ok || $saveMutation.isPending) return; + if (!formValid || $saveMutation.isPending) return; $saveMutation.mutate(); } @@ -343,7 +350,8 @@ ok: false, at: Date.now(), fails: (prev?.fails ?? 0) + 1, - reason: cls.text + (cls.detail ? `(${cls.detail})` : ""), + reason: cls.text, + detail: cls.detail, }); } } catch (err) { @@ -370,14 +378,16 @@ } function agentsUsing(s: Settings, profileId: string): number { - return Object.values(s.agent_llm_assignments ?? {}).filter( - (v) => v === profileId, + return ["story", "style", "script", "assets", "video"].filter( + (role) => s.agent_llm_assignments?.[role] === profileId, ).length; } const deleteMessage = $derived.by(() => { const s = $settingsQuery.data; if (!deleteTarget || !s) return ""; + if (deleteTarget.id === s.llm_active_id) + return "请先将另一个模型设为默认。"; const n = agentsUsing(s, deleteTarget.id); return n > 0 ? t("models.delConfirmUsed", { n }) @@ -388,6 +398,7 @@ mutationFn: async () => { const s = $settingsQuery.data; const target = deleteTarget; + if (target?.id === s?.llm_active_id) throw new Error("请先另设默认模型"); if (!s || !target) throw new Error("no target"); const list = llmProfilesFromSettings(s).filter((p) => p.id !== target.id); return settings.update({ @@ -504,330 +515,277 @@ function keyTail(profile: LlmProfile): string { const tail = profile.api_key_tail ?? ""; - return tail ? `sk-****${tail}` : ""; + return tail ? `已保存 ••••末 ${tail} · 留空不修改` : "已保存 · 留空不修改"; } - loadTests(); + onMount(loadTests); // Prune stale test records once the profile list is known. $effect(() => { const data = $settingsQuery.data; if (data) pruneTests(data.llm_profiles.map((p) => p.id)); }); - // Test each model once per visit (1-token probe) so the cards show real - // state instead of 「未测试」; results younger than 10 minutes are reused. - const autoProbed = new SvelteSet(); + let highlight = $state(false); $effect(() => { - const list = $settingsQuery.data?.llm_profiles ?? []; - untrack(() => { - const now = Date.now(); - for (const p of list) { - if (autoProbed.has(p.id)) continue; - autoProbed.add(p.id); - const rec = tests[p.id]; - if (!rec || now - rec.at > 600_000) void testProfile(p); - } - }); + const role = page.url.searchParams.get("role"); + if (!role || !$settingsQuery.data) return; + highlight = true; + const frame = requestAnimationFrame(() => + document + .getElementById(`role-${role}`) + ?.scrollIntoView({ block: "center" }), + ); + const timer = setTimeout(() => (highlight = false), 1200); + return () => { + cancelAnimationFrame(frame); + clearTimeout(timer); + }; }); + function affected(s: Settings, id: string) { + return [ + ...AGENTS.map((a) => ({ role: a.role, label: t(a.labelKey) })), + { role: "translate", label: "提示词翻译" }, + { role: "polish", label: "提示词润色" }, + ] + .filter( + (a) => (s.agent_llm_assignments?.[a.role] || s.llm_active_id) === id, + ) + .map((a) => a.label) + .join("、"); + } -{#if $settingsQuery.isLoading}

- 正在读取模型… -

{:else if !$settingsQuery.data}

正在读取模型…

+{:else if !$settingsQuery.data}

模型加载失败 -

{:else}{@const s = $settingsQuery.data}{@const profiles = s.llm_profiles} -
- {#each profiles as profile (profile.id)}{@const rec = tests[profile.id]} -
-
- {profile.name}{rec?.ms != null ? Math.round(rec.ms) + "ms" : "—"} +

+{:else}{@const s = $settingsQuery.data}{@const profiles = s.llm_profiles} +
+
+
+ {profiles.length} 个模型 · {profiles.filter((p) => tests[p.id]?.ok) + .length} 个测试通过测试结果记录在本浏览器,换设备需重新测试 +
+ {#each profiles.filter((p) => tests[p.id]?.ok === false) as p (p.id)}
+
+ 「{p.name}」连接失败使用它的功能:{affected(s, p.id)} · {tests[p.id].reason ?? + "连接失败"} +
+ +
{/each} +
+
+ 模型 / 地址用途连接状态操作
-
{profile.base_url}
-
{profile.model}
-
- {rec?.ok === false - ? (rec.reason ?? "连接失败") - : rec?.ok - ? "连接测试通过" - : "尚未测试"} -
-
- {agentsUsing(s, profile.id)} 个智能体使用 -
-
{/each} -
-
-
-

{t("models.agentsTitle")}

- {t("models.agentsHint")} -
-
- {#each AGENTS as agent (agent.role)} -
+
云端接口 · 后续开放
-
{/if} - + + +{/if} $deleteMutation.mutate()} oncancel={() => (deleteTarget = null)} diff --git a/calliope-web/src/lib/components/manage/ManagementPage.svelte b/calliope-web/src/lib/components/manage/ManagementPage.svelte index 725bbc35..820015e0 100644 --- a/calliope-web/src/lib/components/manage/ManagementPage.svelte +++ b/calliope-web/src/lib/components/manage/ManagementPage.svelte @@ -28,10 +28,6 @@ > {title}{@render tools?.()}{@render actions?.()} - - {/snippet}
small, +.md-f small { + color: var(--tx-2); + font-size: 11px; +} +.nm { + border: 0; + background: none; + text-align: left; + color: inherit; + cursor: pointer; + padding: 0; +} +.role-sub { + font-size: 11px; + color: var(--tx-3); + padding: 8px 14px; + background: var(--bg-2); +} +.role-note { + font-size: 11px; + color: var(--tx-2); + padding: 10px 14px; + margin: 0; + line-height: 1.6; +} +.role.highlight { + background: color-mix(in srgb, var(--sc-manage) 18%, transparent); + transition: background var(--t-slow); +} +.f2 .f-error { + color: var(--err); +} +.md-b .a-input { + height: 32px; + box-sizing: border-box; + width: 100%; + font-size: 12.5px; +} +@media (max-width: 1280px) { + .mlist-h, + .mrow { + grid-template-columns: minmax(0, 1fr) 150px 84px; + } + .mlist-h .use, + .mrow .use { + display: none; + } +} + +.role > span { + font-size: 12px; + color: var(--tx-2); +} +.mdl-alert small { + overflow-wrap: anywhere; +} diff --git a/calliope-web/src/routes/connections/+page.svelte b/calliope-web/src/routes/connections/+page.svelte index d33cf431..4f5a2e5b 100644 --- a/calliope-web/src/routes/connections/+page.svelte +++ b/calliope-web/src/routes/connections/+page.svelte @@ -29,6 +29,7 @@ {#each [["comfy", "ComfyUI 连接"], ["llm", "大语言模型"], ["image", "图片模型 · 后续"], ["video", "视频模型 · 后续"]] as [value, label] (value)}添加模型{/snippet} {#if tab === "comfy"} + import { onMount } from "svelte"; import { beforeNavigate, goto, afterNavigate } from "$app/navigation"; + import { resolve } from "$app/paths"; import { SvelteURL } from "svelte/reactivity"; import { createMutation, @@ -69,6 +71,16 @@ skills: "/agents", }; + let modelTests = $state>({}); + onMount(() => { + try { + modelTests = JSON.parse( + localStorage.getItem("calliope.models.tests") ?? "{}", + ); + } catch { + modelTests = {}; + } + }); const client = useQueryClient(); let tab = $state
("queue"); @@ -383,6 +395,33 @@ >重试

{:else if $settingsQuery.data}{@const s = $settingsQuery.data} +
+

提示词工具

+ {#each [["translate", "提示词翻译"], ["polish", "提示词润色"]] as [role, label] (role)}{@const assigned = + s.agent_llm_assignments?.[role]}{@const model = + s.llm_profiles.find( + (p) => p.id === (assigned || s.llm_active_id), + )} +

+ {label}:{assigned ? "" : "跟随默认 · "}{model?.name} · {model?.model} + {modelTests[model?.id ?? ""]?.ok === true + ? "已连接" + : modelTests[model?.id ?? ""]?.ok === false + ? "连接失败" + : "未测试"}(本浏览器记录) +

{/each} + +

+ 只在点击时调用;先预览,点「替换」才改原文。技术片段由服务器核对;小模型质量有限。 +

+
+

任务队列 规则说明