HEL-840: unify connection details and prompt model assignments
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
<script lang="ts">
|
||||
import CloudModels from "./CloudModels.svelte";
|
||||
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 { onMount } from "svelte";
|
||||
|
||||
import Modal from "$lib/components/ui/Modal.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 { comfy, settings, workflows, type ComfyEndpoint } from "$lib/api";
|
||||
import { toast } from "$lib/toast";
|
||||
@@ -48,6 +44,7 @@
|
||||
ok: boolean;
|
||||
ms?: number;
|
||||
version?: string;
|
||||
device?: string;
|
||||
at: number;
|
||||
reason?: string;
|
||||
};
|
||||
@@ -89,9 +86,12 @@
|
||||
headerName: "",
|
||||
notes: "",
|
||||
});
|
||||
let formTest = $state<{ ok: boolean; ms?: number; version?: string } | null>(
|
||||
null,
|
||||
);
|
||||
let formTest = $state<{
|
||||
ok: boolean;
|
||||
ms?: number;
|
||||
version?: string;
|
||||
device?: string;
|
||||
} | null>(null);
|
||||
let formTestFailure = $state<{ message: string; detail: string } | null>(
|
||||
null,
|
||||
);
|
||||
@@ -186,6 +186,7 @@
|
||||
ok: true,
|
||||
ms: res.elapsed_ms,
|
||||
version: res.comfyui_version,
|
||||
device: res.device_name,
|
||||
};
|
||||
} else {
|
||||
formTest = { ok: false };
|
||||
@@ -232,6 +233,7 @@
|
||||
ok: true,
|
||||
ms: formTest.ms,
|
||||
version: formTest.version,
|
||||
device: formTest.device,
|
||||
at: Date.now(),
|
||||
});
|
||||
} else if (formTest?.ok && res.endpoints.length) {
|
||||
@@ -244,6 +246,7 @@
|
||||
ok: true,
|
||||
ms: formTest.ms,
|
||||
version: formTest.version,
|
||||
device: formTest.device,
|
||||
at: Date.now(),
|
||||
});
|
||||
}
|
||||
@@ -261,7 +264,7 @@
|
||||
|
||||
function submitSave() {
|
||||
showErrors = true;
|
||||
if (!formValid || !formTest?.ok || $saveMutation.isPending) return;
|
||||
if (!formValid || $saveMutation.isPending) return;
|
||||
$saveMutation.mutate();
|
||||
}
|
||||
|
||||
@@ -280,6 +283,7 @@
|
||||
ok: true,
|
||||
ms: res.elapsed_ms,
|
||||
version: res.comfyui_version,
|
||||
device: res.device_name,
|
||||
at: Date.now(),
|
||||
});
|
||||
} else {
|
||||
@@ -363,12 +367,7 @@
|
||||
},
|
||||
});
|
||||
|
||||
function tokenTail(ep: ComfyEndpoint): string {
|
||||
const tail = ep.token_tail ?? "";
|
||||
return tail ? `****${tail}` : "";
|
||||
}
|
||||
|
||||
loadTests();
|
||||
onMount(loadTests);
|
||||
$effect(() => {
|
||||
// prune stale test records once the endpoint list is known
|
||||
const data = $settingsQuery.data;
|
||||
@@ -383,258 +382,186 @@
|
||||
if (changed) saveTests(next);
|
||||
}
|
||||
});
|
||||
|
||||
// Probe every connection once per visit so the cards show real state
|
||||
// instead of 「未测试」; results younger than a minute are reused.
|
||||
const autoProbed = new SvelteSet<string>();
|
||||
$effect(() => {
|
||||
const list = endpoints;
|
||||
untrack(() => {
|
||||
const now = Date.now();
|
||||
for (const ep of list) {
|
||||
if (autoProbed.has(ep.id)) continue;
|
||||
autoProbed.add(ep.id);
|
||||
const rec = tests[ep.id];
|
||||
if (!rec || now - rec.at > 60_000) void testEndpoint(ep);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if $settingsQuery.isLoading}<p class="mg-empty">
|
||||
正在读取连接…
|
||||
</p>{:else if $settingsQuery.isError}<p class="mg-empty" role="alert">
|
||||
</p>{:else if $settingsQuery.isError}<p class="mg-empty">
|
||||
连接加载失败<Button onclick={() => $settingsQuery.refetch()}>重试</Button>
|
||||
</p>{:else}
|
||||
<div class="mg-cards">
|
||||
{#each endpoints as ep (ep.id)}{@const rec = tests[ep.id]}
|
||||
<article class="mg-card">
|
||||
<div class="mg-row">
|
||||
<span
|
||||
class="mg-dot"
|
||||
class:ok={rec?.ok === true}
|
||||
class:err={rec?.ok === false}
|
||||
></span><b>{ep.name}</b><span class="mg-grow"></span><span
|
||||
class="mg-latency"
|
||||
>{rec?.ms != null ? Math.round(rec.ms) + "ms" : "—"}</span
|
||||
>
|
||||
</div>
|
||||
<div class="mg-mono">{ep.base_url}</div>
|
||||
<div class="mg-muted">
|
||||
{rec?.ok === false
|
||||
? "连接失败 · " + (rec.reason ?? "原因未知")
|
||||
: rec?.ok
|
||||
? "连接测试通过"
|
||||
: "尚未测试"} · 队列未知 · 显存未知
|
||||
</div>
|
||||
<div class="mg-row">
|
||||
<span class="mg-tag">{workflowsBound(ep.id)} 个工作流使用</span><span
|
||||
class="mg-grow"
|
||||
></span><Button
|
||||
size="sm"
|
||||
loading={pendingTests[ep.id]}
|
||||
onclick={() => testEndpoint(ep)}>测试连接</Button
|
||||
><Button variant="ghost" size="sm" onclick={() => startEdit(ep)}
|
||||
>编辑</Button
|
||||
>
|
||||
</div>
|
||||
</article>
|
||||
{/each}
|
||||
<CloudModels />
|
||||
<button class="mg-card pending mg-add" onclick={startAdd}
|
||||
><Icon name="plus" size={22} />添加连接</button
|
||||
>
|
||||
</div>{/if}
|
||||
<Modal
|
||||
open={formMode !== "idle"}
|
||||
title={formMode === "add" ? t("conn.formTitleAdd") : t("conn.formTitleEdit")}
|
||||
dismissible={!formPending && !$saveMutation.isPending}
|
||||
onclose={resetForm}
|
||||
>
|
||||
<aside
|
||||
class="form-col"
|
||||
class:open={formMode !== "idle"}
|
||||
aria-label={t("conn.formTitleAdd")}
|
||||
>
|
||||
{#if formMode !== "idle"}
|
||||
<div class="form-head">
|
||||
<h2>
|
||||
{formMode === "add"
|
||||
? t("conn.formTitleAdd")
|
||||
: t("conn.formTitleEdit")}
|
||||
</h2>
|
||||
<div class="mdl">
|
||||
<div class="mdl-body">
|
||||
<div class="mdl-sum">
|
||||
{endpoints.length} 个 ComfyUI 连接<small
|
||||
>测试结果记录在本浏览器,换设备需重新测试</small
|
||||
>
|
||||
</div>
|
||||
|
||||
<label class="f-field">
|
||||
<span class="f-label">{t("conn.fName")}<em>*</em></span>
|
||||
<input
|
||||
class="f-input"
|
||||
class:invalid={showErrors && formErrors.name}
|
||||
value={form.name}
|
||||
disabled={formPending}
|
||||
oninput={(e) => (form.name = e.currentTarget.value)}
|
||||
placeholder={t("conn.fNamePh")}
|
||||
/>
|
||||
{#if showErrors && formErrors.name}<span class="f-error"
|
||||
>{formErrors.name}</span
|
||||
>{/if}
|
||||
</label>
|
||||
|
||||
<label class="f-field">
|
||||
<span class="f-label">{t("conn.fBaseUrl")}<em>*</em></span>
|
||||
<input
|
||||
class="f-input mono"
|
||||
class:invalid={showErrors && formErrors.baseUrl}
|
||||
value={form.baseUrl}
|
||||
disabled={formPending}
|
||||
spellcheck="false"
|
||||
oninput={(e) => {
|
||||
form.baseUrl = e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
placeholder={t("conn.fBaseUrlPh")}
|
||||
/>
|
||||
{#if showErrors && formErrors.baseUrl}
|
||||
<span class="f-error">{formErrors.baseUrl}</span>
|
||||
{/if}
|
||||
<span class="f-hint">{t("conn.baseUrlHelp")}</span>
|
||||
</label>
|
||||
|
||||
<div class="f-field">
|
||||
<span class="f-label">{t("conn.fAuth")}</span>
|
||||
<div class="mg-seg" role="radiogroup" aria-label={t("conn.fAuth")}>
|
||||
{#each [["none", t("conn.authNone")], ["bearer", t("conn.authBearer")], ["header", t("conn.authHeader")]] as [value, label] (value)}
|
||||
<button
|
||||
type="button"
|
||||
class="seg-item"
|
||||
class:on={form.authType === value}
|
||||
aria-pressed={form.authType === value}
|
||||
onclick={() => {
|
||||
form.authType = value as typeof form.authType;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
<div class="mlist">
|
||||
<div class="mlist-h">
|
||||
<span>连接 / 地址</span><span class="use">用途</span><span
|
||||
>连接状态</span
|
||||
><span>操作</span>
|
||||
</div>
|
||||
{#each endpoints as ep (ep.id)}{@const rec = tests[ep.id]}
|
||||
<div class="mrow" class:on={editingId === ep.id}>
|
||||
<button class="nm" onclick={() => startEdit(ep)}
|
||||
><b>{ep.name}</b><small title={ep.base_url}>{ep.base_url}</small
|
||||
>{#if rec?.ok}<small
|
||||
>版本 {rec.version ?? "未知"} · {rec.device ??
|
||||
"显卡未知"}</small
|
||||
>{/if}</button
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<span class="f-hint">{t("conn.authHelp")}</span>
|
||||
<div class="use">
|
||||
{#if ep.id === activeId}<span class="utag def">当前使用</span
|
||||
>{/if}<span class="utag">工作流 ×{workflowsBound(ep.id)}</span>
|
||||
</div>
|
||||
<span
|
||||
class="spill"
|
||||
class:ok={rec?.ok === true}
|
||||
class:err={rec?.ok === false}
|
||||
class:run={pendingTests[ep.id]}
|
||||
><i></i>{pendingTests[ep.id]
|
||||
? "测试中"
|
||||
: rec?.ok
|
||||
? `已连接 · ${Math.round(rec.ms ?? 0)}ms`
|
||||
: rec?.ok === false
|
||||
? "连接失败"
|
||||
: "未测试"}</span
|
||||
>
|
||||
<div class="acts">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
disabled={pendingTests[ep.id]}
|
||||
onclick={() => testEndpoint(ep)}>测试</Button
|
||||
><Button size="sm" variant="ghost" onclick={() => startEdit(ep)}
|
||||
>编辑</Button
|
||||
>
|
||||
</div>
|
||||
</div>{/each}
|
||||
</div>
|
||||
|
||||
{#if form.authType !== "none"}
|
||||
{#if form.authType === "header"}
|
||||
<label class="f-field">
|
||||
<span class="f-label">{t("conn.fHeaderName")}<em>*</em></span>
|
||||
<input
|
||||
class="f-input mono"
|
||||
class:invalid={showErrors && formErrors.headerName}
|
||||
value={form.headerName}
|
||||
disabled={formPending}
|
||||
spellcheck="false"
|
||||
oninput={(e) => {
|
||||
form.headerName = e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
placeholder={t("conn.fHeaderNamePh")}
|
||||
/>
|
||||
{#if showErrors && formErrors.headerName}
|
||||
<span class="f-error">{formErrors.headerName}</span>
|
||||
{/if}
|
||||
</label>
|
||||
{/if}
|
||||
<label class="f-field">
|
||||
<span class="f-label">
|
||||
{t("conn.fToken")}
|
||||
<span class="kh-inline mono">{t("conn.keyNoEcho")}</span>
|
||||
</span>
|
||||
<span class="key-wrap">
|
||||
<input
|
||||
class="f-input key-input"
|
||||
type="password"
|
||||
value={form.token}
|
||||
disabled={formPending}
|
||||
autocomplete="off"
|
||||
oninput={(e) => {
|
||||
form.token = e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
placeholder={formMode === "edit" && editingEndpoint?.has_token
|
||||
? t("conn.tokenSaved")
|
||||
: "…"}
|
||||
/>
|
||||
{#if formMode === "edit" && editingEndpoint?.has_token && tokenTail(editingEndpoint)}
|
||||
<span class="kh mono">{tokenTail(editingEndpoint)}</span>
|
||||
{/if}
|
||||
</span>
|
||||
<span class="f-hint">{t("conn.keyHelp")}</span>
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
<label class="f-field">
|
||||
<span class="f-label">{t("conn.fNotes")}</span>
|
||||
<input
|
||||
class="f-input"
|
||||
value={form.notes}
|
||||
disabled={formPending}
|
||||
oninput={(e) => (form.notes = e.currentTarget.value)}
|
||||
placeholder={t("conn.fNotesPh")}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{#if formTest?.ok}
|
||||
<div class="result-bar ok" transition:fade={{ duration: 250 }}>
|
||||
{t("conn.testOk", {
|
||||
ms: formTest.ms ?? "?",
|
||||
v: formTest.version ?? "?",
|
||||
})}
|
||||
</div>
|
||||
{:else if formTest?.ok === false && formTestFailure}
|
||||
<div class="result-bar err" transition:fade={{ duration: 250 }}>
|
||||
<p>{t("conn.testFail", { reason: formTestFailure.message })}</p>
|
||||
{#if formTestFailure.detail}
|
||||
<p class="mono detail">{formTestFailure.detail}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="form-actions">
|
||||
<span class="need-test" class:passed={formTest?.ok}
|
||||
>{t("conn.needTest")}</span
|
||||
>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
loading={formPending}
|
||||
onclick={runTest}
|
||||
>
|
||||
{formPending ? t("conn.testing") : t("conn.testBtn")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
disabled={!formValid || !formTest?.ok}
|
||||
loading={$saveMutation.isPending}
|
||||
onclick={submitSave}
|
||||
>
|
||||
{t("conn.save")}
|
||||
</Button>
|
||||
<p class="role-note">
|
||||
队列:未知 · 显存:未知。现有接口未返回这两项,不影响生成。
|
||||
</p>
|
||||
<div class="soon-row">云端接口 · 后续开放</div>
|
||||
</div>
|
||||
<aside class="mdl-detail">
|
||||
<div class="md-h">
|
||||
<b
|
||||
>{formMode === "idle"
|
||||
? "连接详情"
|
||||
: formMode === "add"
|
||||
? "添加 ComfyUI 连接"
|
||||
: "编辑 ComfyUI 连接"}</b
|
||||
><Button size="sm" variant="ghost" onclick={resetForm}>关闭</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{#if formMode === "edit" && editingId}<div class="mg-row">
|
||||
{#if editingId !== activeId}<Button
|
||||
{#if formMode === "idle"}<p class="mg-empty">
|
||||
选择连接查看详情
|
||||
</p>{:else}<div class="md-b">
|
||||
{#each [["name", "连接名称"], ["baseUrl", "接口地址"]] as [key, label] (key)}<label
|
||||
class="f2"
|
||||
><span>{label} *</span><input
|
||||
class="a-input"
|
||||
value={form[key as "name" | "baseUrl"]}
|
||||
placeholder={key === "baseUrl"
|
||||
? "http://127.0.0.1:8188"
|
||||
: "本机 ComfyUI"}
|
||||
oninput={(e) => {
|
||||
form[key as "name" | "baseUrl"] = e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
/>{#if showErrors && formErrors[key]}<small class="f-error"
|
||||
>{formErrors[key]}</small
|
||||
>{/if}</label
|
||||
>{/each}
|
||||
<label class="f2"
|
||||
><span>认证方式</span><select
|
||||
class="a-select"
|
||||
bind:value={form.authType}
|
||||
onchange={touchFormConnectivity}
|
||||
><option value="none">无认证</option><option value="bearer"
|
||||
>Bearer Token</option
|
||||
><option value="header">自定义请求头</option></select
|
||||
></label
|
||||
>
|
||||
{#if form.authType === "header"}<label class="f2"
|
||||
><span>请求头名称 *</span><input
|
||||
class="a-input"
|
||||
bind:value={form.headerName}
|
||||
oninput={touchFormConnectivity}
|
||||
/></label
|
||||
>{/if}
|
||||
{#if form.authType !== "none"}<label class="f2"
|
||||
><span>认证密钥</span><input
|
||||
class="a-input"
|
||||
type="password"
|
||||
bind:value={form.token}
|
||||
autocomplete="off"
|
||||
placeholder={editingEndpoint?.has_token
|
||||
? "已保存 · 留空不修改"
|
||||
: "输入密钥"}
|
||||
oninput={touchFormConnectivity}
|
||||
/><small>密钥不回显</small></label
|
||||
>{/if}
|
||||
<label class="f2"
|
||||
><span>备注</span><input
|
||||
class="a-input"
|
||||
bind:value={form.notes}
|
||||
/></label
|
||||
>
|
||||
{#if formTest?.ok}<div class="testbox ok">
|
||||
连接测试通过 · {formTest.ms} ms<br />版本 {formTest.version ??
|
||||
"未知"} · 显卡 {formTest.device ?? "未知"}
|
||||
</div>{:else if formTestFailure}<div class="testbox err">
|
||||
<b>{formTestFailure.message}</b>
|
||||
<details>
|
||||
<summary>服务器原始响应</summary>
|
||||
<pre>{formTestFailure.detail}</pre>
|
||||
</details>
|
||||
</div>{/if}
|
||||
{#if editingId && tests[editingId]}{@const rec =
|
||||
tests[editingId]}<small
|
||||
>上次测试 {new Date(
|
||||
rec.at,
|
||||
).toLocaleTimeString()}(本浏览器记录)</small
|
||||
>{#if rec.ok}<p>
|
||||
版本 {rec.version ?? "未知"}<br />显卡 {rec.device ?? "未知"}<br
|
||||
/>队列 未知 · 显存 未知
|
||||
</p>{:else}<div class="testbox err">
|
||||
<b>连接失败</b>
|
||||
<details>
|
||||
<summary>服务器原始响应</summary>
|
||||
<pre>{rec.reason}</pre>
|
||||
</details>
|
||||
</div>{/if}{/if}
|
||||
{#if editingEndpoint}<div class="acts">
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={editingId === activeId}
|
||||
onclick={() => $defaultMutation.mutate(editingId!)}
|
||||
>设为当前连接</Button
|
||||
><Button
|
||||
size="sm"
|
||||
variant="danger"
|
||||
onclick={() => requestDelete(editingEndpoint!)}>删除</Button
|
||||
>
|
||||
</div>{/if}
|
||||
</div>
|
||||
<div class="md-f">
|
||||
<span class="mg-grow"></span><Button
|
||||
size="sm"
|
||||
onclick={() => $defaultMutation.mutate(editingId!)}>设为默认</Button
|
||||
>{/if}<Button
|
||||
size="sm"
|
||||
variant="danger"
|
||||
onclick={() => {
|
||||
const target = editingEndpoint;
|
||||
if (target) requestDelete(target);
|
||||
}}>删除</Button
|
||||
>
|
||||
</div>{/if}
|
||||
</aside></Modal
|
||||
>
|
||||
loading={formPending}
|
||||
onclick={runTest}>测试连接</Button
|
||||
><Button
|
||||
size="sm"
|
||||
variant="primary"
|
||||
disabled={!formValid}
|
||||
loading={$saveMutation.isPending}
|
||||
onclick={submitSave}>保存</Button
|
||||
>
|
||||
</div>{/if}
|
||||
</aside>
|
||||
</div>{/if}
|
||||
<ConfirmDialog
|
||||
bind:open={deleteOpen}
|
||||
title={t("conn.delTitle")}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
<script lang="ts">
|
||||
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<Record<string, TestRec>>({});
|
||||
@@ -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<string>();
|
||||
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("、");
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if $settingsQuery.isLoading}<p class="mg-empty">
|
||||
正在读取模型…
|
||||
</p>{:else if !$settingsQuery.data}<p class="mg-empty" role="alert">
|
||||
{#if $settingsQuery.isLoading}<p class="mg-empty">正在读取模型…</p>
|
||||
{:else if !$settingsQuery.data}<p class="mg-empty">
|
||||
模型加载失败<Button onclick={() => $settingsQuery.refetch()}>重试</Button>
|
||||
</p>{:else}{@const s = $settingsQuery.data}{@const profiles = s.llm_profiles}
|
||||
<div class="mg-cards">
|
||||
{#each profiles as profile (profile.id)}{@const rec = tests[profile.id]}
|
||||
<article class="mg-card">
|
||||
<div class="mg-row">
|
||||
<span
|
||||
class="mg-dot"
|
||||
class:ok={rec?.ok === true}
|
||||
class:err={rec?.ok === false}
|
||||
></span><b>{profile.name}</b><span class="mg-grow"></span><span
|
||||
class="mg-latency"
|
||||
>{rec?.ms != null ? Math.round(rec.ms) + "ms" : "—"}</span
|
||||
>
|
||||
</p>
|
||||
{:else}{@const s = $settingsQuery.data}{@const profiles = s.llm_profiles}
|
||||
<div class="mdl">
|
||||
<div class="mdl-body">
|
||||
<div class="mdl-sum">
|
||||
<span
|
||||
>{profiles.length} 个模型 · {profiles.filter((p) => tests[p.id]?.ok)
|
||||
.length} 个测试通过</span
|
||||
><small>测试结果记录在本浏览器,换设备需重新测试</small>
|
||||
</div>
|
||||
{#each profiles.filter((p) => tests[p.id]?.ok === false) as p (p.id)}<div
|
||||
class="mdl-alert"
|
||||
>
|
||||
<div>
|
||||
<b>「{p.name}」连接失败</b><small
|
||||
>使用它的功能:{affected(s, p.id)} · {tests[p.id].reason ??
|
||||
"连接失败"}</small
|
||||
>
|
||||
</div>
|
||||
<Button size="sm" onclick={() => startEdit(p)}>查看并修复</Button>
|
||||
</div>{/each}
|
||||
<div class="mlist">
|
||||
<div class="mlist-h">
|
||||
<span>模型 / 地址</span><span class="use">用途</span><span
|
||||
>连接状态</span
|
||||
><span>操作</span>
|
||||
</div>
|
||||
<div class="mg-mono">{profile.base_url}</div>
|
||||
<div class="mg-muted">{profile.model}</div>
|
||||
<div class="mg-dim">
|
||||
{rec?.ok === false
|
||||
? (rec.reason ?? "连接失败")
|
||||
: rec?.ok
|
||||
? "连接测试通过"
|
||||
: "尚未测试"}
|
||||
</div>
|
||||
<div class="mg-row">
|
||||
<span class="mg-tag">{agentsUsing(s, profile.id)} 个智能体使用</span
|
||||
><span class="mg-grow"></span><Button
|
||||
size="sm"
|
||||
loading={pendingTests[profile.id]}
|
||||
onclick={() => testProfile(profile)}>测试连接</Button
|
||||
><Button size="sm" variant="ghost" onclick={() => startEdit(profile)}
|
||||
>编辑</Button
|
||||
>
|
||||
</div>
|
||||
</article>{/each}<button class="mg-card pending mg-add" onclick={startAdd}
|
||||
><Icon name="plus" size={22} />添加大语言模型</button
|
||||
>
|
||||
<div class="model-assignments">
|
||||
<section class="mg-field">
|
||||
<div class="mg-row">
|
||||
<h2>{t("models.agentsTitle")}</h2>
|
||||
<span class="panel-hint">{t("models.agentsHint")}</span>
|
||||
</div>
|
||||
<div class="mg-assignments">
|
||||
{#each AGENTS as agent (agent.role)}
|
||||
<label class="agent-cell">
|
||||
<span
|
||||
class="avatar"
|
||||
style:background={agent.color}
|
||||
class:dark={agent.dark}
|
||||
{#each profiles as p (p.id)}{@const rec = tests[p.id]}
|
||||
<div class="mrow" class:on={editingId === p.id}>
|
||||
<button class="nm" onclick={() => startEdit(p)}
|
||||
><b
|
||||
>{p.name}
|
||||
<small>{endpointTypeLabel(classifyEndpoint(p.base_url))}</small
|
||||
></b
|
||||
><small title={p.base_url}>{p.model} · {p.base_url}</small
|
||||
></button
|
||||
>
|
||||
<div class="use">
|
||||
{#if p.id === s.llm_active_id}<span class="utag def">默认</span
|
||||
>{/if}{#if agentsUsing(s, p.id)}<span class="utag"
|
||||
>智能体 ×{agentsUsing(s, p.id)}</span
|
||||
>{/if}{#each [["translate", "翻译"], ["polish", "润色"]] as [role, label] (role)}{#if s.agent_llm_assignments?.[role] === p.id}<span
|
||||
class="utag pt">{label}</span
|
||||
>{/if}{/each}
|
||||
</div>
|
||||
<span
|
||||
class="spill"
|
||||
class:ok={rec?.ok === true}
|
||||
class:err={rec?.ok === false}
|
||||
class:run={pendingTests[p.id]}
|
||||
><i></i>{pendingTests[p.id]
|
||||
? "测试中"
|
||||
: rec?.ok
|
||||
? `已连接 · ${Math.round(rec.ms ?? 0)}ms`
|
||||
: rec?.ok === false
|
||||
? `连接失败 · ${rec.fails} 次`
|
||||
: "未测试"}</span
|
||||
>
|
||||
<div class="acts">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
disabled={pendingTests[p.id]}
|
||||
onclick={() => testProfile(p)}>测试</Button
|
||||
><Button size="sm" variant="ghost" onclick={() => startEdit(p)}
|
||||
>编辑</Button
|
||||
>
|
||||
{agent.char}
|
||||
</span>
|
||||
<span class="agent-name">{t(agent.labelKey)}</span>
|
||||
<select
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<section class="role-t">
|
||||
<h3>模型分工 <small>未单独指定时跟随默认模型</small></h3>
|
||||
<div class="role-sub">智能体</div>
|
||||
<div class="role-g">
|
||||
{#each AGENTS as agent (agent.role)}<label class="role"
|
||||
><span>{t(agent.labelKey)}</span><select
|
||||
class="a-select"
|
||||
value={s.agent_llm_assignments?.[agent.role] ?? ""}
|
||||
onchange={(e) =>
|
||||
setAssignment(agent.role, e.currentTarget.value)}
|
||||
>
|
||||
<option value="">{t("models.agentDefault")}</option>
|
||||
{#each profiles as p (p.id)}
|
||||
<option
|
||||
value={p.id}
|
||||
class:unavailable={tests[p.id]?.ok === false}
|
||||
>
|
||||
{p.name} — {p.model}{tests[p.id]?.ok === false
|
||||
? t("models.unavailable")
|
||||
: ""}
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
{/each}
|
||||
><option value=""
|
||||
>跟随默认(当前:{profiles.find(
|
||||
(p) => p.id === s.llm_active_id,
|
||||
)?.name})</option
|
||||
>{#each profiles as p (p.id)}<option value={p.id}
|
||||
>{p.name} · {p.model}</option
|
||||
>{/each}</select
|
||||
></label
|
||||
>{/each}
|
||||
</div>
|
||||
<div class="role-sub">提示词工具</div>
|
||||
<div class="role-g">
|
||||
{#each [["translate", "提示词翻译"], ["polish", "提示词润色"]] as [role, label] (role)}<label
|
||||
id={"role-" + role}
|
||||
class="role"
|
||||
class:highlight={highlight &&
|
||||
(page.url.searchParams.get("role") === role ||
|
||||
page.url.searchParams.get("role") === "tools")}
|
||||
><span>{label}</span><select
|
||||
class="a-select"
|
||||
value={s.agent_llm_assignments?.[role] ?? ""}
|
||||
onchange={(e) => setAssignment(role, e.currentTarget.value)}
|
||||
><option value=""
|
||||
>跟随默认(当前:{profiles.find(
|
||||
(p) => p.id === s.llm_active_id,
|
||||
)?.name})</option
|
||||
>{#each profiles as p (p.id)}<option value={p.id}
|
||||
>{p.name} · {p.model}</option
|
||||
>{/each}</select
|
||||
></label
|
||||
>{/each}
|
||||
</div>
|
||||
<p class="role-note">
|
||||
只在点击时调用;先给结果,点「替换」才改;LoRA
|
||||
标签、权重写法由服务器逐字核对。小模型质量有限,建议选指令跟随较好的模型。自动方向:正文含中文即中译英,可换向重译。
|
||||
</p>
|
||||
</section>
|
||||
<div class="soon-row">云端接口 · 后续开放</div>
|
||||
</div>
|
||||
</div>{/if}
|
||||
<Modal
|
||||
open={formMode !== "idle"}
|
||||
title={formMode === "edit"
|
||||
? t("models.formTitleEdit")
|
||||
: t("models.formTitleAdd")}
|
||||
dismissible={!formPending}
|
||||
onclose={resetForm}
|
||||
size="md"
|
||||
><aside
|
||||
class="form-col"
|
||||
class:open={formMode !== "idle"}
|
||||
aria-label={t("models.formTitleAdd")}
|
||||
>
|
||||
{#if formMode === "idle"}
|
||||
<div class="form-idle">
|
||||
<Icon name="sparkle" size={20} />
|
||||
<p>{t("models.idleFormHint")}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="form-head">
|
||||
<h2>
|
||||
{formMode === "add"
|
||||
? t("models.formTitleAdd")
|
||||
: t("models.formTitleEdit")}
|
||||
</h2>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="icon-btn"
|
||||
aria-label={t("models.formClose")}
|
||||
onclick={resetForm}
|
||||
>
|
||||
<Icon name="close" size={16} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<label class="f-field">
|
||||
<span class="f-label">{t("models.fName")}<em>*</em></span>
|
||||
<input
|
||||
class="f-input"
|
||||
class:invalid={showErrors && formErrors.name}
|
||||
value={form.name}
|
||||
disabled={formPending}
|
||||
oninput={(e) => (form.name = e.currentTarget.value)}
|
||||
placeholder={t("models.fNamePh")}
|
||||
/>
|
||||
{#if showErrors && formErrors.name}<span class="f-error"
|
||||
>{formErrors.name}</span
|
||||
>{/if}
|
||||
</label>
|
||||
|
||||
<div class="f-field">
|
||||
<span class="f-label">{t("models.fApiType")}</span>
|
||||
<div class="seg" role="radiogroup" aria-label={t("models.fApiType")}>
|
||||
<span class="seg-item selected" role="radio" aria-checked="true">
|
||||
{t("models.apiOpenai")}
|
||||
</span>
|
||||
<span class="seg-item disabled" aria-disabled="true">
|
||||
{t("models.apiAnthropic")}
|
||||
</span>
|
||||
<span class="seg-item disabled" aria-disabled="true"
|
||||
>{t("models.apiOther")}</span
|
||||
<aside class="mdl-detail" aria-label="模型详情">
|
||||
{#if formMode === "idle"}<div class="md-h"><b>模型详情</b></div>
|
||||
<p class="mg-empty">选择模型查看详情或添加自定义模型</p>
|
||||
{:else}
|
||||
<div class="md-h">
|
||||
<b>{formMode === "add" ? "添加自定义模型" : "编辑模型"}</b><Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onclick={resetForm}>关闭</Button
|
||||
>
|
||||
</div>
|
||||
<span class="f-hint">{t("models.apiTypeHelp")}</span>
|
||||
</div>
|
||||
|
||||
<label class="f-field">
|
||||
<span class="f-label">{t("models.fBaseUrl")}<em>*</em></span>
|
||||
<input
|
||||
class="f-input mono"
|
||||
class:invalid={showErrors && formErrors.baseUrl}
|
||||
value={form.baseUrl}
|
||||
disabled={formPending}
|
||||
spellcheck="false"
|
||||
oninput={(e) => {
|
||||
form.baseUrl = e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
placeholder="http://192.168.200.18:11434/v1"
|
||||
/>
|
||||
{#if showErrors && formErrors.baseUrl}
|
||||
<span class="f-error">{formErrors.baseUrl}</span>
|
||||
{/if}
|
||||
<span class="f-hint">{t("models.baseUrlHelp")}</span>
|
||||
</label>
|
||||
|
||||
<label class="f-field">
|
||||
<span class="f-label">{t("models.fModel")}<em>*</em></span>
|
||||
<input
|
||||
class="f-input mono"
|
||||
class:invalid={showErrors && formErrors.model}
|
||||
value={form.model}
|
||||
disabled={formPending}
|
||||
spellcheck="false"
|
||||
oninput={(e) => {
|
||||
form.model = e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
placeholder="deepseek-chat"
|
||||
/>
|
||||
{#if showErrors && formErrors.model}
|
||||
<span class="f-error">{formErrors.model}</span>
|
||||
{/if}
|
||||
<span class="f-hint">{t("models.modelHelp")}</span>
|
||||
</label>
|
||||
|
||||
<label class="f-field">
|
||||
<span class="f-label">
|
||||
{t("models.fApiKey")}<em>*</em>
|
||||
<span class="kh-inline mono">{t("models.keyNoEcho")}</span>
|
||||
</span>
|
||||
<span class="key-wrap">
|
||||
<input
|
||||
class="f-input key-input"
|
||||
type="password"
|
||||
class:invalid={showErrors && formErrors.apiKey}
|
||||
value={form.apiKey}
|
||||
disabled={formPending}
|
||||
autocomplete="off"
|
||||
oninput={(e) => {
|
||||
form.apiKey = e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
placeholder={formMode === "edit" && editingProfile?.api_key
|
||||
? t("models.keyKeepHint")
|
||||
: "sk-…"}
|
||||
/>
|
||||
{#if formMode === "edit" && editingProfile?.api_key && keyTail(editingProfile)}
|
||||
<span class="kh mono">{keyTail(editingProfile)}</span>
|
||||
{/if}
|
||||
</span>
|
||||
{#if showErrors && formErrors.apiKey}
|
||||
<span class="f-error">{formErrors.apiKey}</span>
|
||||
{/if}
|
||||
<span class="f-hint">{t("models.keyHelp")}</span>
|
||||
</label>
|
||||
|
||||
<label class="f-field">
|
||||
<span class="f-label">{t("models.fTimeout")}</span>
|
||||
<select
|
||||
class="f-input"
|
||||
value={form.timeout}
|
||||
disabled={formPending}
|
||||
onchange={(e) => {
|
||||
form.timeout = Number(e.currentTarget.value);
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
>
|
||||
{#each TIMEOUT_OPTIONS as sec (sec)}
|
||||
<option value={sec}>{t("models.timeoutSec", { n: sec })}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{#if formTest?.ok}
|
||||
<div class="result-bar ok" transition:fade={{ duration: 250 }}>
|
||||
{t("models.testOk", {
|
||||
ms: formTest.ms ?? "?",
|
||||
model: form.model.trim(),
|
||||
})}
|
||||
<div class="md-b">
|
||||
{#each [["name", "名称", "自定义模型"], ["baseUrl", "接口地址", "http://127.0.0.1:11434/v1"], ["model", "模型名称", "模型名称"]] as [key, label, ph] (key)}<label
|
||||
class="f2"
|
||||
><span>{label} *</span><input
|
||||
class="a-input"
|
||||
value={form[key as "name" | "baseUrl" | "model"]}
|
||||
placeholder={ph}
|
||||
disabled={formPending}
|
||||
oninput={(e) => {
|
||||
form[key as "name" | "baseUrl" | "model"] =
|
||||
e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
/>{#if showErrors && formErrors[key]}<small class="f-error"
|
||||
>{formErrors[key]}</small
|
||||
>{/if}</label
|
||||
>{/each}
|
||||
<label class="f2"
|
||||
><span>API 密钥</span><input
|
||||
class="a-input"
|
||||
type="password"
|
||||
value={form.apiKey}
|
||||
autocomplete="off"
|
||||
placeholder={editingProfile?.api_key
|
||||
? keyTail(editingProfile)
|
||||
: "本地模型可留空"}
|
||||
disabled={formPending}
|
||||
oninput={(e) => {
|
||||
form.apiKey = e.currentTarget.value;
|
||||
touchFormConnectivity();
|
||||
}}
|
||||
/>{#if showErrors && formErrors.apiKey}<small class="f-error"
|
||||
>{formErrors.apiKey}</small
|
||||
>{/if}<small>密钥不回显 · 留空不修改已有密钥</small></label
|
||||
>
|
||||
{#if formTest?.ok}<div class="testbox ok">
|
||||
连接测试通过 · {formTest.ms} ms
|
||||
</div>{:else if formTestFailure}<div class="testbox err">
|
||||
<b>{formTestFailure.text}</b>
|
||||
<details>
|
||||
<summary>服务器原始响应</summary>
|
||||
<pre>{formTestFailure.detail}</pre>
|
||||
</details>
|
||||
</div>{/if}
|
||||
{#if editingId && tests[editingId]}{@const rec =
|
||||
tests[editingId]}<small
|
||||
>上次测试 {new Date(
|
||||
rec.at,
|
||||
).toLocaleTimeString()}(本浏览器记录)</small
|
||||
>{#if rec.ok === false}<div class="testbox err">
|
||||
<b>{rec.reason}</b>
|
||||
<details>
|
||||
<summary>服务器原始响应</summary>
|
||||
<pre>{rec.detail ?? rec.reason}</pre>
|
||||
</details>
|
||||
</div>{/if}{/if}
|
||||
{#if editingProfile}<div class="usage">
|
||||
<small>当前用途</small>
|
||||
<p>{affected(s, editingProfile.id) || "未单独指定用途"}</p>
|
||||
</div>
|
||||
<div class="acts">
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={editingId === s.llm_active_id}
|
||||
onclick={() => $defaultMutation.mutate(editingId!)}
|
||||
>设为默认</Button
|
||||
><Button
|
||||
size="sm"
|
||||
variant="danger"
|
||||
disabled={editingId === s.llm_active_id}
|
||||
title={editingId === s.llm_active_id ? "请先另设默认模型" : ""}
|
||||
onclick={() => requestDelete(editingProfile!)}>删除</Button
|
||||
>
|
||||
</div>{/if}
|
||||
</div>
|
||||
{:else if formTest?.ok === false && formTestFailure}
|
||||
<div class="result-bar err" transition:fade={{ duration: 250 }}>
|
||||
<p>
|
||||
{t("models.testFail", { reason: formTestFailure.text })}
|
||||
</p>
|
||||
{#if formTestFailure.detail}
|
||||
<p class="mono detail">{formTestFailure.detail}</p>
|
||||
{/if}
|
||||
<div class="md-f">
|
||||
<small>必填完整即可保存</small><span class="mg-grow"></span><Button
|
||||
size="sm"
|
||||
loading={formPending}
|
||||
onclick={runTest}>测试连接</Button
|
||||
><Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
disabled={!formValid}
|
||||
loading={$saveMutation.isPending}
|
||||
onclick={submitSave}>保存</Button
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="form-actions">
|
||||
<span class="need-test" class:passed={formTest?.ok}
|
||||
>{t("models.needTest")}</span
|
||||
>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
loading={formPending}
|
||||
onclick={runTest}
|
||||
>
|
||||
{formPending ? t("models.testing") : t("models.testBtn")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
disabled={!formValid || !formTest?.ok}
|
||||
loading={$saveMutation.isPending}
|
||||
onclick={submitSave}
|
||||
>
|
||||
{t("models.save")}
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{#if formMode === "edit" && editingId}<div class="mg-row">
|
||||
{#if editingId !== $settingsQuery.data?.llm_active_id}<Button
|
||||
size="sm"
|
||||
onclick={() => $defaultMutation.mutate(editingId!)}>设为默认</Button
|
||||
>{/if}<Button
|
||||
size="sm"
|
||||
variant="danger"
|
||||
onclick={() => {
|
||||
const target = editingProfile;
|
||||
if (target) requestDelete(target);
|
||||
}}>删除</Button
|
||||
>
|
||||
</div>{/if}
|
||||
</aside></Modal
|
||||
>
|
||||
</aside>
|
||||
</div>
|
||||
{/if}
|
||||
<ConfirmDialog
|
||||
bind:open={deleteOpen}
|
||||
title={t("models.delTitle")}
|
||||
message={deleteMessage}
|
||||
confirmLabel={t("models.delete")}
|
||||
title="删除模型"
|
||||
message={deleteMessage + " 指定此模型的用途将改为跟随默认。"}
|
||||
confirmLabel="删除"
|
||||
danger
|
||||
onconfirm={() => $deleteMutation.mutate()}
|
||||
oncancel={() => (deleteTarget = null)}
|
||||
|
||||
@@ -28,10 +28,6 @@
|
||||
>
|
||||
<b>{title}</b>{@render tools?.()}<span class="mg-grow"
|
||||
></span>{@render actions?.()}
|
||||
<!-- The approved header reserves this inline width independently of demo copy. -->
|
||||
<span class="mg-header-reserve" aria-hidden="true"
|
||||
><span></span><span>    </span></span
|
||||
>
|
||||
</header>
|
||||
{/snippet}
|
||||
<section
|
||||
|
||||
@@ -0,0 +1,477 @@
|
||||
.mdl,
|
||||
.mdl * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.mdl {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) var(--mdl-detail);
|
||||
min-height: 0;
|
||||
--scene: var(--sc-manage);
|
||||
}
|
||||
.mdl-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
.mdl-body {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 14px 16px 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
}
|
||||
.mdl-sum {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-size: 12px;
|
||||
color: var(--tx-2);
|
||||
justify-content: space-between;
|
||||
}
|
||||
.mdl-sum .grow {
|
||||
flex: 1;
|
||||
}
|
||||
.mdl-alert {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
padding: 10px 12px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid color-mix(in srgb, var(--err) 40%, transparent);
|
||||
background: color-mix(in srgb, var(--err) 8%, transparent);
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.mdl-alert svg {
|
||||
color: var(--err);
|
||||
}
|
||||
.mdl-alert small {
|
||||
display: block;
|
||||
color: var(--tx-2);
|
||||
font-size: 11.5px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
.mlist {
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--line);
|
||||
background: var(--bg-1);
|
||||
overflow: hidden;
|
||||
}
|
||||
.mlist-h {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 168px 110px;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
height: 32px;
|
||||
padding: 0 14px;
|
||||
font-size: 11px;
|
||||
color: var(--tx-3);
|
||||
border-bottom: 1px solid var(--line);
|
||||
background: rgb(var(--ink) / 0.02);
|
||||
}
|
||||
.mrow {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 168px 110px;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
min-height: var(--mdl-list-row);
|
||||
padding: 8px 14px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
}
|
||||
.mrow:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.mrow:hover {
|
||||
background: rgb(var(--ink) / 0.03);
|
||||
}
|
||||
.mrow.on {
|
||||
background: color-mix(in srgb, var(--sc-manage) 9%, transparent);
|
||||
}
|
||||
.mrow.on::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 8px;
|
||||
bottom: 8px;
|
||||
width: 2px;
|
||||
border-radius: 2px;
|
||||
background: var(--sc-manage);
|
||||
}
|
||||
.mrow .nm {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
}
|
||||
.mrow .nm b {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
display: block;
|
||||
}
|
||||
.mrow .nm small {
|
||||
font: 500 11px var(--mono);
|
||||
color: var(--tx-2);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.mrow .use {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
flex-wrap: wrap;
|
||||
min-width: 0;
|
||||
}
|
||||
.mrow .acts {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 4px;
|
||||
}
|
||||
.spill {
|
||||
justify-self: start;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
height: 22px;
|
||||
padding: 0 8px;
|
||||
border-radius: 999px;
|
||||
font-size: 11.5px;
|
||||
white-space: nowrap;
|
||||
border: 1px solid var(--line-2);
|
||||
color: var(--tx-2);
|
||||
background: rgb(var(--ink) / 0.03);
|
||||
max-width: 100%;
|
||||
}
|
||||
.spill i {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--tx-3);
|
||||
flex: none;
|
||||
}
|
||||
.spill.ok {
|
||||
color: var(--ok);
|
||||
border-color: color-mix(in srgb, var(--ok) 35%, transparent);
|
||||
background: color-mix(in srgb, var(--ok) 8%, transparent);
|
||||
}
|
||||
.spill.ok i {
|
||||
background: var(--ok);
|
||||
}
|
||||
.spill.err {
|
||||
color: var(--err);
|
||||
border-color: color-mix(in srgb, var(--err) 35%, transparent);
|
||||
background: color-mix(in srgb, var(--err) 8%, transparent);
|
||||
}
|
||||
.spill.err i {
|
||||
background: var(--err);
|
||||
}
|
||||
.spill.run {
|
||||
color: var(--info);
|
||||
border-color: color-mix(in srgb, var(--info) 35%, transparent);
|
||||
}
|
||||
.spill.run i {
|
||||
background: var(--info);
|
||||
animation: pulse2 1s var(--ease-io) infinite;
|
||||
}
|
||||
@keyframes pulse2 {
|
||||
50% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
}
|
||||
html[data-motion="off"] .spill.run i {
|
||||
animation: none;
|
||||
}
|
||||
.spill .ms {
|
||||
font: 500 11px var(--mono);
|
||||
}
|
||||
.utag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
height: 18px;
|
||||
padding: 0 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 10.5px;
|
||||
color: var(--tx-2);
|
||||
border: 1px solid var(--line-2);
|
||||
}
|
||||
.utag.def {
|
||||
color: var(--gold);
|
||||
border-color: color-mix(in srgb, var(--gold) 40%, transparent);
|
||||
}
|
||||
.utag.pt {
|
||||
color: color-mix(in srgb, var(--sc-image) 80%, var(--hi));
|
||||
border-color: color-mix(in srgb, var(--sc-image) 40%, transparent);
|
||||
}
|
||||
.role-t {
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--line);
|
||||
background: var(--bg-1);
|
||||
}
|
||||
.role-t h3 {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
padding: 10px 14px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.role-t h3 small {
|
||||
font-size: 11.5px;
|
||||
color: var(--tx-3);
|
||||
font-weight: 400;
|
||||
}
|
||||
.role-g {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0;
|
||||
}
|
||||
.role {
|
||||
display: grid;
|
||||
grid-template-columns: 92px minmax(0, 1fr);
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
padding: 8px 14px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.role:nth-child(odd) {
|
||||
border-right: 1px solid var(--line);
|
||||
}
|
||||
.role:nth-last-child(-n + 2) {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.role .sel {
|
||||
width: 100%;
|
||||
height: 28px;
|
||||
}
|
||||
.soon-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 14px;
|
||||
border-radius: 12px;
|
||||
border: 1px dashed var(--line-2);
|
||||
font-size: 12px;
|
||||
color: var(--tx-3);
|
||||
}
|
||||
.soon-row b {
|
||||
color: var(--tx-2);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.mdl-detail {
|
||||
border-left: 1px solid var(--line);
|
||||
background: var(--bg-1);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
[data-theme="bluehour"] .mdl-detail {
|
||||
background: color-mix(in srgb, var(--bg-1) 78%, transparent);
|
||||
}
|
||||
.md-h {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
height: 44px;
|
||||
padding: 0 10px 0 16px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
flex: none;
|
||||
}
|
||||
.md-h b {
|
||||
font-size: 13.5px;
|
||||
flex: 1;
|
||||
}
|
||||
.md-b {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 14px 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
min-height: 0;
|
||||
}
|
||||
.f2 {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
.f2 .help {
|
||||
font-size: 11px;
|
||||
color: var(--tx-3);
|
||||
}
|
||||
.f2 .help.err {
|
||||
color: var(--err);
|
||||
}
|
||||
.testbox {
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--line-2);
|
||||
padding: 10px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.testbox.ok {
|
||||
border-color: color-mix(in srgb, var(--ok) 35%, transparent);
|
||||
background: color-mix(in srgb, var(--ok) 6%, transparent);
|
||||
}
|
||||
.testbox.err {
|
||||
border-color: color-mix(in srgb, var(--err) 35%, transparent);
|
||||
background: color-mix(in srgb, var(--err) 6%, transparent);
|
||||
}
|
||||
.testbox .t {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.testbox.ok .t {
|
||||
color: var(--ok);
|
||||
}
|
||||
.testbox.err .t {
|
||||
color: var(--err);
|
||||
}
|
||||
.testbox p {
|
||||
color: var(--tx-2);
|
||||
line-height: 1.5;
|
||||
}
|
||||
.testbox details summary {
|
||||
cursor: pointer;
|
||||
font-size: 11.5px;
|
||||
color: var(--tx-3);
|
||||
list-style: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.testbox details summary::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
.testbox pre {
|
||||
margin-top: 6px;
|
||||
max-height: 110px;
|
||||
overflow: auto;
|
||||
padding: 8px;
|
||||
border-radius: 6px;
|
||||
background: var(--well);
|
||||
border: 1px solid var(--line);
|
||||
font: 500 10.5px/1.5 var(--mono);
|
||||
color: var(--tx-2);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
.md-f {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 16px;
|
||||
border-top: 1px solid var(--line);
|
||||
margin-top: auto;
|
||||
}
|
||||
.md-f .grow {
|
||||
flex: 1;
|
||||
}
|
||||
.usage {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
@media (max-width: 1366px) {
|
||||
.mlist-h,
|
||||
.mrow {
|
||||
grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 150px 92px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 1280px) {
|
||||
.mlist-h,
|
||||
.mrow {
|
||||
grid-template-columns: minmax(0, 1.3fr) 150px 84px;
|
||||
}
|
||||
.mlist-h .c-use,
|
||||
.mrow .use {
|
||||
display: none;
|
||||
}
|
||||
.role-g {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.role:nth-child(odd) {
|
||||
border-right: 0;
|
||||
}
|
||||
.role:nth-last-child(2) {
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
}
|
||||
|
||||
.mdl-body small,
|
||||
.f2 small,
|
||||
.md-b > 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;
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
{#each [["comfy", "ComfyUI 连接"], ["llm", "大语言模型"], ["image", "图片模型 · 后续"], ["video", "视频模型 · 后续"]] as [value, label] (value)}<button
|
||||
class:on={tab === value}
|
||||
aria-pressed={tab === value}
|
||||
disabled={value === "image" || value === "video"}
|
||||
onclick={() =>
|
||||
goto(resolve(`/connections?tab=${value}`), {
|
||||
replaceState: true,
|
||||
@@ -38,11 +39,12 @@
|
||||
>{/each}
|
||||
</div>{/snippet}
|
||||
{#snippet actions()}<Button
|
||||
variant="scene"
|
||||
size="sm"
|
||||
disabled={tab === "image" || tab === "video"}
|
||||
onclick={() =>
|
||||
tab === "comfy" ? comfyPanel?.startAdd() : llmPanel?.startAdd()}
|
||||
><Icon name="plus" size={14} />添加</Button
|
||||
><Icon name="plus" size={14} />添加模型</Button
|
||||
>{/snippet}
|
||||
{#if tab === "comfy"}<ComfyConnections
|
||||
bind:this={comfyPanel}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<script lang="ts">
|
||||
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<Record<string, { ok: boolean; ms?: number }>>({});
|
||||
onMount(() => {
|
||||
try {
|
||||
modelTests = JSON.parse(
|
||||
localStorage.getItem("calliope.models.tests") ?? "{}",
|
||||
);
|
||||
} catch {
|
||||
modelTests = {};
|
||||
}
|
||||
});
|
||||
const client = useQueryClient();
|
||||
let tab = $state<Section>("queue");
|
||||
|
||||
@@ -383,6 +395,33 @@
|
||||
>重试</Button
|
||||
>
|
||||
</p>{:else if $settingsQuery.data}{@const s = $settingsQuery.data}
|
||||
<section class="mg-field wide">
|
||||
<h3>提示词工具</h3>
|
||||
{#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),
|
||||
)}
|
||||
<p>
|
||||
{label}:{assigned ? "" : "跟随默认 · "}{model?.name} · {model?.model}
|
||||
<span class="mg-dim"
|
||||
>{modelTests[model?.id ?? ""]?.ok === true
|
||||
? "已连接"
|
||||
: modelTests[model?.id ?? ""]?.ok === false
|
||||
? "连接失败"
|
||||
: "未测试"}(本浏览器记录)</span
|
||||
>
|
||||
</p>{/each}
|
||||
<Button
|
||||
size="sm"
|
||||
onclick={() => goto(resolve("/connections?tab=llm&role=tools"))}
|
||||
>去模型分工修改</Button
|
||||
>
|
||||
<p class="mg-dim">
|
||||
只在点击时调用;先预览,点「替换」才改原文。技术片段由服务器核对;小模型质量有限。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="mg-field">
|
||||
<h3>任务队列 <span class="mg-tag">规则说明</span></h3>
|
||||
<div class="queue-fields">
|
||||
|
||||
Reference in New Issue
Block a user