1005 lines
35 KiB
Svelte
1005 lines
35 KiB
Svelte
<script lang="ts">
|
|
import "./workspace.css";
|
|
import { reduceMotion } from "$lib/reduceMotion.svelte";
|
|
import { onMount, untrack } from "svelte";
|
|
import { page } from "$app/state";
|
|
import { goto } from "$app/navigation";
|
|
import { resolve } from "$app/paths";
|
|
import { createQuery, useQueryClient } from "@tanstack/svelte-query";
|
|
import { toStore } from "svelte/store";
|
|
import AppShell from "$lib/components/shell/AppShell.svelte";
|
|
import type { IconName } from "$lib/components/ui/icons";
|
|
import Icon from "$lib/components/ui/Icon.svelte";
|
|
import AgentChat from "./AgentChat.svelte";
|
|
import AgentPlanPanel from "./AgentPlanPanel.svelte";
|
|
import Modal from "$lib/components/ui/Modal.svelte";
|
|
import AgentComposer from "./AgentComposer.svelte";
|
|
import {
|
|
agentApi,
|
|
resultsApi,
|
|
jobsApi,
|
|
assetUrl,
|
|
settings,
|
|
workflows,
|
|
workbenchApi,
|
|
type AgentDeliverable,
|
|
type AgentSession,
|
|
type WorkbenchStageKey,
|
|
} from "$lib/api";
|
|
import { createUploadManager } from "$lib/comfy/useUpload.svelte";
|
|
import type { AgentAttachment } from "$lib/agentComposer";
|
|
import type { AgentComposerPayload } from "$lib/agentComposer";
|
|
import { connectEvents } from "$lib/events";
|
|
import { toast } from "$lib/toast";
|
|
|
|
const client = useQueryClient();
|
|
const stageNames: Record<WorkbenchStageKey, string> = {
|
|
script: "剧本创作",
|
|
style: "视觉设计",
|
|
storyboard: "分镜设计",
|
|
assets: "素材资产",
|
|
shot: "镜头脚本",
|
|
};
|
|
const assistantIcons: Record<string, IconName> = {
|
|
script: "project-book",
|
|
style: "nav-palette",
|
|
storyboard: "project-grid",
|
|
assets: "project-image",
|
|
shot: "project-film",
|
|
};
|
|
const assistantColors: Record<string, string> = {
|
|
script: "var(--sc-agent)",
|
|
style: "var(--gold)",
|
|
storyboard: "var(--sc-image)",
|
|
assets: "var(--sc-asset)",
|
|
shot: "var(--sc-video)",
|
|
};
|
|
const assistantDescriptions: Record<string, string> = {
|
|
script: "故事、人物、场次与台词",
|
|
style: "风格板、色彩与参考图",
|
|
storyboard: "镜头拆分、景别与时长",
|
|
assets: "角色、场景、道具出图",
|
|
shot: "逐镜视频提示词与生成",
|
|
};
|
|
const keys = Object.keys(stageNames) as WorkbenchStageKey[];
|
|
const registry = createQuery({
|
|
queryKey: ["agents-registry"],
|
|
queryFn: agentApi.listNamedAgents,
|
|
});
|
|
const config = createQuery({ queryKey: ["settings"], queryFn: settings.get });
|
|
const skills = createQuery({
|
|
queryKey: ["b4-skills"],
|
|
queryFn: () => agentApi.listSkillsAdmin(),
|
|
});
|
|
const wfQuery = createQuery({
|
|
queryKey: ["b4-workflows"],
|
|
queryFn: workflows.list,
|
|
});
|
|
const projects = createQuery({
|
|
queryKey: ["b4-projects"],
|
|
queryFn: agentApi.listLinkableProjects,
|
|
});
|
|
const sessions = createQuery({
|
|
queryKey: ["b4-sessions"],
|
|
queryFn: async () =>
|
|
(
|
|
await Promise.all([
|
|
agentApi.listSessions(),
|
|
...keys.map(agentApi.listAgentSessions),
|
|
])
|
|
)
|
|
.flat()
|
|
.sort((a, b) => b.updated_at.localeCompare(a.updated_at)),
|
|
});
|
|
const allResults = createQuery({
|
|
queryKey: ["b4-results"],
|
|
queryFn: () => resultsApi.list(),
|
|
});
|
|
const activeId = $derived(
|
|
Number(page.url.searchParams.get("session")) || null,
|
|
);
|
|
const session = createQuery(
|
|
toStore(() => ({
|
|
queryKey: ["agent-session", activeId],
|
|
queryFn: () => agentApi.getSession(activeId!),
|
|
enabled: activeId != null,
|
|
})),
|
|
);
|
|
const taskResults = $derived(
|
|
($allResults.data ?? []).filter((r) => r.session_id === activeId),
|
|
);
|
|
let filter = $state("all");
|
|
let agentKey = $state<WorkbenchStageKey | "">("");
|
|
let projectId = $state<number | null>(null);
|
|
let draft = $state("");
|
|
let busy = $state(false);
|
|
let error = $state("");
|
|
let streaming = $state("");
|
|
let reasoning = $state("");
|
|
let particles = $state<HTMLCanvasElement | null>(null);
|
|
let liveTools = $state<
|
|
{
|
|
tool: string;
|
|
args?: Record<string, unknown>;
|
|
result?: unknown;
|
|
phase: "running" | "done" | "error";
|
|
}[]
|
|
>([]);
|
|
const running = $derived($session.data?.running === true);
|
|
let editing = $state<AgentDeliverable | null>(null);
|
|
let text = $state("");
|
|
let targetProject = $state<number | null>(null);
|
|
let targetStage = $state<WorkbenchStageKey>("script");
|
|
let saving = $state(false);
|
|
let dirty = $state(false);
|
|
let artifactTab = $state("shots");
|
|
let compareOpen = $state(false);
|
|
let previousText = $state("");
|
|
async function comparePrevious() {
|
|
if (!editing) return;
|
|
try {
|
|
const versions = await resultsApi.versions(editing.id);
|
|
previousText = versions[0]?.content ?? "";
|
|
compareOpen = true;
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
}
|
|
}
|
|
function parseContent(value: string): Record<string, unknown> | null {
|
|
try {
|
|
const start = value.indexOf("{");
|
|
const end = value.lastIndexOf("}");
|
|
return JSON.parse(value.slice(start, end + 1));
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
function editShot(index: number, key: string, value: string | number) {
|
|
const data = parseContent(text);
|
|
if (!data || !Array.isArray(data.shots)) return;
|
|
data.shots[index] = { ...data.shots[index], [key]: value };
|
|
text = JSON.stringify(data, null, 2);
|
|
dirty = true;
|
|
}
|
|
|
|
let selectedSkill = $state("");
|
|
let uploadInput = $state<HTMLInputElement | null>(null);
|
|
let attachments = $state<AgentAttachment[]>([]);
|
|
const uploads = createUploadManager();
|
|
let uploadBusy = $state(false);
|
|
async function upload(event: Event) {
|
|
const files = Array.from((event.target as HTMLInputElement).files ?? []);
|
|
uploadBusy = true;
|
|
try {
|
|
for (const file of files.slice(0, 8 - attachments.length)) {
|
|
const path = await uploads.upload("b4-reference", file);
|
|
const meta = uploads.uploadMetaFor(path);
|
|
attachments.push({ path, name: meta.name, kind: meta.kind });
|
|
}
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
} finally {
|
|
uploadBusy = false;
|
|
(event.target as HTMLInputElement).value = "";
|
|
}
|
|
}
|
|
async function assignModel(id: string) {
|
|
busy = true;
|
|
try {
|
|
await settings.update({
|
|
agent_llm_assignments: {
|
|
[activeAgent?.llm_role ?? "main"]: id || null,
|
|
},
|
|
});
|
|
await client.invalidateQueries({ queryKey: ["settings"] });
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
} finally {
|
|
busy = false;
|
|
}
|
|
}
|
|
|
|
const shownTasks = $derived(
|
|
($sessions.data ?? []).filter(
|
|
(s) =>
|
|
filter === "all" ||
|
|
(filter === "sandbox"
|
|
? s.project_id == null
|
|
: s.running ||
|
|
s.task_status === "awaiting_confirm" ||
|
|
s.task_status === "awaiting_input"),
|
|
),
|
|
);
|
|
const activeAgent = $derived(
|
|
($registry.data ?? []).find(
|
|
(a) => a.key === ($session.data?.agent_key || agentKey),
|
|
),
|
|
);
|
|
const enabledSkills = $derived(
|
|
($skills.data ?? []).filter(
|
|
(s) => s.is_enabled && (!agentKey || s.bindings?.[agentKey]),
|
|
),
|
|
);
|
|
const profiles = $derived($config.data?.llm_profiles ?? []);
|
|
function modelName(key?: string | null) {
|
|
const a = ($registry.data ?? []).find((a) => a.key === key);
|
|
const id =
|
|
(a && $config.data?.agent_llm_assignments?.[a.llm_role]) ||
|
|
$config.data?.llm_active_id;
|
|
return (
|
|
profiles.find((p) => p.id === id)?.name ||
|
|
$config.data?.llm_model ||
|
|
"未配置模型"
|
|
);
|
|
}
|
|
function status(s: AgentSession) {
|
|
return s.running
|
|
? "运行中"
|
|
: ({
|
|
ready: "未开始",
|
|
awaiting_confirm: "待你确认",
|
|
returned: "已带回项目",
|
|
completed: "已完成",
|
|
error: "失败",
|
|
cancelled: "已停止",
|
|
interrupted: "运行中断",
|
|
awaiting_input: "等待回答",
|
|
}[s.task_status ?? "ready"] ?? "未开始");
|
|
}
|
|
function openResult(r: AgentDeliverable) {
|
|
editing = r;
|
|
text = r.content;
|
|
targetProject = r.project_id;
|
|
targetStage = r.stage_key;
|
|
dirty = false;
|
|
error = "";
|
|
}
|
|
async function openTask(id: number) {
|
|
if (dirty) {
|
|
error = "请先保存成果草稿,再切换任务。";
|
|
return false;
|
|
}
|
|
streaming = "";
|
|
reasoning = "";
|
|
liveTools = [];
|
|
await goto(resolve(`/agents?session=${id}`));
|
|
return true;
|
|
}
|
|
async function launchAssistant(key: WorkbenchStageKey) {
|
|
if (busy || uploadBusy) return;
|
|
agentKey = key;
|
|
if (draft.trim()) {
|
|
await send({
|
|
content: draft,
|
|
mentions: [],
|
|
attachments: [...attachments],
|
|
});
|
|
return;
|
|
}
|
|
busy = true;
|
|
try {
|
|
const s = await agentApi.createSession({
|
|
agent_key: key,
|
|
project_id: projectId,
|
|
});
|
|
await openTask(s.id);
|
|
await refresh();
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
} finally {
|
|
busy = false;
|
|
}
|
|
}
|
|
async function home() {
|
|
if (dirty) {
|
|
error = "请先保存成果草稿,再新建任务。";
|
|
return;
|
|
}
|
|
editing = null;
|
|
error = "";
|
|
agentKey = "";
|
|
await goto(resolve("/agents"));
|
|
}
|
|
$effect(() => {
|
|
const id = activeId,
|
|
results = taskResults;
|
|
untrack(() => {
|
|
if (editing?.session_id !== id) {
|
|
editing = null;
|
|
dirty = false;
|
|
}
|
|
if (!editing && results.length) openResult(results[0]);
|
|
});
|
|
});
|
|
$effect(() => {
|
|
// Entering another task/home is the next legitimate loop trigger.
|
|
const canvas = particles;
|
|
void activeId;
|
|
if (!canvas) return;
|
|
delete canvas.dataset.motionRevision;
|
|
canvas.parentElement?.querySelectorAll('[data-motion-held]').forEach((node) => node.removeAttribute('data-motion-held'));
|
|
});
|
|
$effect(() => {
|
|
const revision = reduceMotion.loopRevision;
|
|
if (!particles || activeId || reduceMotion.mode !== "full")
|
|
return;
|
|
// Switching back to full does not start particles in the current scene.
|
|
if (particles.dataset.motionRevision && Number(particles.dataset.motionRevision) !== revision) return;
|
|
particles.dataset.motionRevision = String(revision);
|
|
const canvas = particles,
|
|
ctx = canvas.getContext("2d");
|
|
if (!ctx) return;
|
|
const points = Array.from({ length: 46 }, () => ({
|
|
x: Math.random(),
|
|
y: Math.random(),
|
|
v: 0.15 + Math.random() * 0.35,
|
|
s: Math.random() * 1.6 + 0.4,
|
|
a: Math.random() * 0.5 + 0.15,
|
|
}));
|
|
const resize = () => {
|
|
canvas.width = canvas.clientWidth;
|
|
canvas.height = canvas.clientHeight;
|
|
};
|
|
resize();
|
|
const observer = new ResizeObserver(resize);
|
|
observer.observe(canvas);
|
|
let raf = 0;
|
|
const frame = () => {
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
if (
|
|
!activeId &&
|
|
document.documentElement.dataset.motion === "full" &&
|
|
!matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
) {
|
|
const color =
|
|
getComputedStyle(document.documentElement)
|
|
.getPropertyValue("--particle")
|
|
.trim() || "168,121,255";
|
|
for (const point of points) {
|
|
point.y -= point.v / Math.max(1, canvas.height);
|
|
point.x +=
|
|
(Math.sin((point.y * canvas.height) / 60) * 0.2) /
|
|
Math.max(1, canvas.width);
|
|
if (point.y < 0) {
|
|
point.y = 1;
|
|
point.x = Math.random();
|
|
}
|
|
ctx.beginPath();
|
|
ctx.arc(
|
|
point.x * canvas.width,
|
|
point.y * canvas.height,
|
|
point.s,
|
|
0,
|
|
7,
|
|
);
|
|
ctx.fillStyle = `rgba(${color},${point.a})`;
|
|
ctx.fill();
|
|
}
|
|
}
|
|
raf = requestAnimationFrame(frame);
|
|
};
|
|
const visibility = () => {
|
|
cancelAnimationFrame(raf);
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
if (!document.hidden) frame();
|
|
};
|
|
document.addEventListener("visibilitychange", visibility);
|
|
visibility();
|
|
return () => {
|
|
cancelAnimationFrame(raf);
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
document.removeEventListener("visibilitychange", visibility);
|
|
observer.disconnect();
|
|
};
|
|
});
|
|
async function refresh() {
|
|
await Promise.all([
|
|
client.invalidateQueries({ queryKey: ["b4-sessions"] }),
|
|
client.invalidateQueries({ queryKey: ["b4-results"] }),
|
|
client.invalidateQueries({ queryKey: ["agent-session"] }),
|
|
]);
|
|
}
|
|
onMount(() =>
|
|
connectEvents((ev) => {
|
|
if (ev.type.startsWith("job."))
|
|
void client.invalidateQueries({ queryKey: ["b4-jobs"] });
|
|
if (ev.type === "events.resync" || ev.type === "agent.session.updated") {
|
|
void refresh();
|
|
return;
|
|
}
|
|
if (
|
|
ev.data?.session_id !== activeId &&
|
|
(ev.data?.message as { session_id?: number } | undefined)
|
|
?.session_id !== activeId
|
|
)
|
|
return;
|
|
if (ev.type === "agent.token")
|
|
streaming += String(ev.data?.content ?? "");
|
|
if (ev.type === "agent.thinking")
|
|
reasoning += String(ev.data?.content ?? "");
|
|
if (ev.type === "agent.message") {
|
|
streaming = "";
|
|
void client.invalidateQueries({
|
|
queryKey: ["agent-session", activeId],
|
|
});
|
|
}
|
|
if (ev.type === "agent.plan" || ev.type === "agent.task")
|
|
void client.invalidateQueries({
|
|
queryKey: ["agent-session", activeId],
|
|
});
|
|
if (ev.type === "agent.tool") {
|
|
const tool = String(ev.data?.tool ?? "");
|
|
if (ev.data?.phase === "start")
|
|
liveTools.push({
|
|
tool,
|
|
args: ev.data?.args as Record<string, unknown>,
|
|
phase: "running",
|
|
});
|
|
else {
|
|
const index = liveTools
|
|
.map((t) => t.tool === tool && t.phase === "running")
|
|
.lastIndexOf(true);
|
|
if (index >= 0)
|
|
liveTools[index] = {
|
|
...liveTools[index],
|
|
result: ev.data?.result,
|
|
phase:
|
|
(ev.data?.result as { ok?: boolean })?.ok === false
|
|
? "error"
|
|
: "done",
|
|
};
|
|
}
|
|
}
|
|
}),
|
|
);
|
|
async function send(payload: AgentComposerPayload) {
|
|
if (busy || uploadBusy) return;
|
|
busy = true;
|
|
error = "";
|
|
try {
|
|
let sid = activeId;
|
|
if (!sid) {
|
|
const s = await agentApi.createSession({
|
|
project_id: projectId,
|
|
agent_key: agentKey || null,
|
|
});
|
|
sid = s.id;
|
|
await goto(resolve(`/agents?session=${sid}`));
|
|
}
|
|
const skill = enabledSkills.find((s) => s.dir === selectedSkill);
|
|
if (
|
|
skill &&
|
|
payload.mentions.filter((m) => m.type === "skill").length < 4 &&
|
|
!payload.mentions.some(
|
|
(m) => m.type === "skill" && m.name === skill.dir,
|
|
)
|
|
)
|
|
payload.mentions.push({
|
|
type: "skill",
|
|
name: skill.dir,
|
|
description: skill.description,
|
|
});
|
|
await agentApi.postMessage(sid, payload);
|
|
draft = "";
|
|
attachments = [];
|
|
await refresh();
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
} finally {
|
|
busy = false;
|
|
}
|
|
}
|
|
async function save() {
|
|
if (!editing || saving) return null;
|
|
saving = true;
|
|
error = "";
|
|
try {
|
|
const r = await resultsApi.patch(editing.id, {
|
|
revision: editing.revision,
|
|
content: text,
|
|
project_id: targetProject,
|
|
stage_key: targetStage,
|
|
});
|
|
openResult(r);
|
|
await client.invalidateQueries({ queryKey: ["b4-results"] });
|
|
toast.success("草稿已保存");
|
|
return r;
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
return null;
|
|
} finally {
|
|
saving = false;
|
|
}
|
|
}
|
|
async function returnToProject() {
|
|
if (!editing || !targetProject || saving) return;
|
|
const r = dirty ? await save() : editing;
|
|
if (!r) return;
|
|
saving = true;
|
|
error = "";
|
|
try {
|
|
const res = await resultsApi.store({
|
|
deliverable_id: r.id,
|
|
revision: r.revision,
|
|
project_id: targetProject,
|
|
stage_key: targetStage,
|
|
});
|
|
toast.success(
|
|
res.already_attached ? "该版本已带回项目" : "已带回项目,等待确认",
|
|
);
|
|
await refresh();
|
|
await goto(resolve(`/workbench/${targetProject}?stage=${targetStage}`));
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
} finally {
|
|
saving = false;
|
|
}
|
|
}
|
|
const projectJobs = createQuery(
|
|
toStore(() => ({
|
|
queryKey: ["b4-jobs", targetProject],
|
|
queryFn: () => jobsApi.list(targetProject!),
|
|
enabled: targetProject != null,
|
|
})),
|
|
);
|
|
function shotJob(id: string) {
|
|
return ($projectJobs.data ?? []).find(
|
|
(j) =>
|
|
j.payload?.stage_key === targetStage &&
|
|
j.payload?.target_id === id &&
|
|
j.status === "done" &&
|
|
j.output_paths?.length,
|
|
);
|
|
}
|
|
const structuredShots = $derived.by(() => {
|
|
const data = parseContent(text);
|
|
return Array.isArray(data?.shots)
|
|
? (data.shots as {
|
|
id: string;
|
|
description?: string;
|
|
prompt?: string;
|
|
duration_sec?: number;
|
|
}[])
|
|
: [];
|
|
});
|
|
async function redraw(shot: {
|
|
id: string;
|
|
description?: string;
|
|
prompt?: string;
|
|
duration_sec?: number;
|
|
}) {
|
|
if (!targetProject || saving || !shot.id) return;
|
|
saving = true;
|
|
error = "";
|
|
try {
|
|
await workbenchApi.generate(targetProject, {
|
|
kind: targetStage === "shot" ? "video" : "image",
|
|
stage_key: targetStage,
|
|
target_id: shot.id,
|
|
prompt: shot.prompt || shot.description || "",
|
|
duration_sec: shot.duration_sec,
|
|
});
|
|
toast.success(`仅镜头 ${shot.id} 已入队`);
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
} finally {
|
|
saving = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
{#snippet header()}
|
|
<header class="b4-header">
|
|
{#if activeId}<div class="b4-crumb"><button onclick={home}>智能体</button>/<b>{$session.data?.title ?? "加载任务…"}</b></div><span class="a-tag sc">{$session.data ? status($session.data) : "加载中"}</span>{:else}<div class="b4-crumb"><button onclick={home}><b>智能体</b></button></div><span class="b4-subtitle">把创作任务交给助手,成果回到项目等你确认</span>{/if}<span class="b4-grow"></span>{#if activeId}<span class="b4-chip"
|
|
><Icon name="agent-cpu" size={14}/><b>{modelName($session.data?.agent_key)}</b></span
|
|
>{/if}<a class="a-btn secondary sm" href={resolve("/agents?legacy=1")}
|
|
>原会话与技能管理</a
|
|
>
|
|
</header>
|
|
{/snippet}
|
|
{#snippet shellHeader()}{/snippet}
|
|
<AppShell active="agents" title="智能体" workspace pageHeader={shellHeader}>
|
|
<div class="b4" class:task-view={activeId != null}>
|
|
{@render header()}
|
|
<div class="aurora fx-only"><i></i><i></i><i></i></div>
|
|
<canvas class="particles fx-only" bind:this={particles} aria-hidden="true"
|
|
></canvas>
|
|
<div class={activeId ? "atask" : "agent-grid"}>
|
|
<aside class="tasklist">
|
|
<div class="tl-h">
|
|
<button class="a-btn scene" onclick={home}
|
|
><Icon name="plus" size={14} />新任务</button
|
|
>{#if !activeId}<div class="b4-seg">
|
|
{#each [["active", "进行中"], ["all", "全部"], ["sandbox", "沙盒"]] as [value, label] (value)}<button
|
|
class:on={filter === value}
|
|
onclick={() => (filter = value)}>{label}</button
|
|
>{/each}
|
|
</div>{/if}
|
|
</div>
|
|
<div class="tl-b">
|
|
{#each shownTasks as s (s.id)}<button
|
|
class="titem"
|
|
data-session-id={s.id}
|
|
class:on={s.id === activeId}
|
|
onclick={() => openTask(s.id)}
|
|
title={s.task_summary || s.title}
|
|
><b>{s.title}</b><span class="meta"
|
|
><i class="dot" style:--agent-task-dot={s.running ? "var(--agent-task-running)" : s.task_status === "returned" ? "var(--agent-task-returned)" : s.task_status === "awaiting_confirm" ? "var(--agent-task-confirm)" : "var(--agent-task-idle)"}></i>{status(s)}<span class="b4-grow"></span>{s
|
|
.project?.title ?? "沙盒"}</span
|
|
></button
|
|
>{:else}<p class="b4-empty">
|
|
{$sessions.isPending ? "加载任务…" : "暂无任务"}
|
|
</p>{/each}
|
|
</div>
|
|
</aside>
|
|
{#if !activeId}
|
|
<div class="agent-home">
|
|
<div class="ahero">
|
|
<div class="hero-copy">
|
|
<span class="eyebrow">主创智能体 · 统筹五个阶段助手</span>
|
|
<h2>从一个想法,到一组能直接开拍的镜头</h2>
|
|
<p class="muted">
|
|
它会先列计划,再调用剧本、视觉、分镜、素材与镜头助手;每一步的成果都是可编辑草稿,你确认后才写入项目。
|
|
</p>
|
|
<div class="steps">
|
|
{#each ["说出想法", "确认计划", "编辑成果", "带回项目"] as label, i (label)}<span
|
|
><i>{i + 1}</i>{label}</span
|
|
>{/each}
|
|
</div>
|
|
<div class="big-input">
|
|
<textarea
|
|
aria-label="任务想法"
|
|
bind:value={draft}
|
|
placeholder="描述你的创作想法、目标与要求…"
|
|
></textarea>
|
|
<div class="b4-row">
|
|
<label class="b4-chip"
|
|
><Icon name="nav-project" size={14} />绑定:<select
|
|
aria-label="绑定项目"
|
|
bind:value={projectId}
|
|
><option value={null}>沙盒</option
|
|
>{#each $projects.data ?? [] as p (p.id)}<option
|
|
value={p.id}>{p.title}</option
|
|
>{/each}</select
|
|
></label
|
|
><label class="b4-chip"
|
|
><Icon name="agent-cpu" size={14} /><select
|
|
aria-label="任务模型"
|
|
disabled={busy}
|
|
value={$config.data?.agent_llm_assignments?.[
|
|
activeAgent?.llm_role ?? "main"
|
|
] ?? ""}
|
|
onchange={(e) => assignModel(e.currentTarget.value)}
|
|
><option value="">{modelName(agentKey)}</option
|
|
>{#each profiles as p (p.id)}<option value={p.id}
|
|
>{p.name}</option
|
|
>{/each}</select
|
|
></label
|
|
><label class="b4-chip"
|
|
><Icon name="project-book" size={14} />技能
|
|
<select aria-label="任务技能" bind:value={selectedSkill}
|
|
><option value="">不指定</option
|
|
>{#each enabledSkills as s (s.dir)}<option value={s.dir}
|
|
>{s.name}</option
|
|
>{/each}</select
|
|
></label
|
|
><input
|
|
hidden
|
|
type="file"
|
|
bind:this={uploadInput}
|
|
multiple
|
|
accept="image/*,video/*,audio/*,.txt,.md,.docx"
|
|
onchange={upload}
|
|
/><button
|
|
class="b4-chip"
|
|
disabled={uploadBusy || busy}
|
|
onclick={() => uploadInput?.click()}
|
|
><Icon name="upload" size={14} />参考材料{attachments.length
|
|
? ` · ${attachments.length}`
|
|
: ""}</button
|
|
><span class="b4-grow"></span><button
|
|
class="a-btn primary"
|
|
disabled={busy || uploadBusy || !draft.trim()}
|
|
onclick={() =>
|
|
send({
|
|
content: draft,
|
|
mentions: [],
|
|
attachments: [...attachments],
|
|
})}><Icon name="agent-send" size={14} />开始任务</button
|
|
>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="orb fx-only">
|
|
<div class="ring r2"></div>
|
|
<div class="ring"></div>
|
|
<div class="core"></div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="sec-h">
|
|
<h2>阶段助手</h2>
|
|
<span class="dim">每个助手对应项目的一个阶段,也可以单独调用</span
|
|
>
|
|
</div>
|
|
<div class="roster">
|
|
{#each $registry.data ?? [] as a, i (a.key)}<button
|
|
class="acard"
|
|
style:--c={assistantColors[a.key]}
|
|
disabled={busy || uploadBusy}
|
|
onclick={() => launchAssistant(a.key as WorkbenchStageKey)}
|
|
><span class="num">0{i + 1}</span><span class="ic"
|
|
><Icon name={assistantIcons[a.key]} size={18} /></span
|
|
>
|
|
<div class="tx">
|
|
<b>{stageNames[a.key as WorkbenchStageKey]}</b>
|
|
<p>{assistantDescriptions[a.key]}</p>
|
|
<div class="b4-row">
|
|
<span class="a-tag">{a.skill_count} 个技能</span><span
|
|
class="b4-grow"
|
|
></span><span class="dim">{modelName(a.key)}</span>
|
|
</div>
|
|
</div></button
|
|
>{/each}
|
|
</div>
|
|
</div>
|
|
<div class="mini-row">
|
|
<div class="panel">
|
|
<h3>最近成果<span class="dim">点开即可编辑,再带回项目</span></h3>
|
|
<div class="outrow">
|
|
{#each ($allResults.data ?? []).slice(0, 4) as r (r.id)}<button
|
|
class="outcard"
|
|
data-deliverable-id={r.id}
|
|
onclick={async () => {
|
|
if (await openTask(r.session_id)) openResult(r);
|
|
}}
|
|
><div class="t"><Icon name="file" size={24} /></div>
|
|
<div class="d">
|
|
<b>{r.title}</b><span class="dim"
|
|
>{stageNames[r.stage_key]} · 草稿 v{r.revision}</span
|
|
>
|
|
</div></button
|
|
>{:else}<p class="b4-empty">
|
|
暂无成果,完成任务后将在这里显示。
|
|
</p>{/each}
|
|
</div>
|
|
</div>
|
|
<div class="panel">
|
|
<h3>
|
|
技能库<span class="a-tag">{($skills.data ?? []).length}</span
|
|
><span class="b4-grow"></span><a
|
|
class="a-btn sm ghost"
|
|
href={resolve("/agents?legacy=1")}>管理</a
|
|
>
|
|
</h3>
|
|
<div class="skills">
|
|
{#each ($skills.data ?? [])
|
|
.filter((s) => s.is_enabled)
|
|
.slice(0, 7) as s (s.dir)}<button
|
|
class="skill"
|
|
title={s.description}
|
|
onclick={() => {
|
|
selectedSkill = s.dir;
|
|
agentKey = "";
|
|
}}><i></i>{s.name}</button
|
|
>{:else}<span class="dim">尚未添加技能</span>{/each}<a
|
|
class="skill dim"
|
|
href={resolve("/agents?legacy=1")}>+ 学习新技能</a
|
|
>
|
|
</div>
|
|
<p class="dim">
|
|
技能 = 可复用的规则 +
|
|
示例。可从对话中“记住这个做法”生成,也可导入 Markdown。
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{:else}
|
|
<div class="convo">
|
|
<div class="convo-b">
|
|
{#if $session.data?.plan}<AgentPlanPanel
|
|
plan={$session.data.plan}
|
|
/>{/if}<AgentChat
|
|
studio
|
|
messages={$session.data?.messages ?? []}
|
|
{liveTools}
|
|
{streaming}
|
|
streamingReasoning={reasoning}
|
|
{running}
|
|
loading={$session.isPending}
|
|
onAnswer={(option, _scope, seq) =>
|
|
send({
|
|
content: option,
|
|
mentions: [],
|
|
attachments: [],
|
|
answer_to: seq,
|
|
})}
|
|
/>
|
|
</div>
|
|
<div class="convo-in">
|
|
<AgentComposer
|
|
studio
|
|
{running}
|
|
onSend={send}
|
|
onCancel={() => {
|
|
if (activeId) void agentApi.cancel(activeId);
|
|
}}
|
|
workflows={($wfQuery.data ?? [])
|
|
.filter((w) => w.is_enabled)
|
|
.map((w) => ({
|
|
id: w.id,
|
|
name: w.name,
|
|
kind: w.kind as "image" | "video",
|
|
}))}
|
|
skills={($skills.data ?? [])
|
|
.filter((s) => s.is_enabled)
|
|
.map((s) => ({
|
|
name: s.dir,
|
|
description: s.description,
|
|
tags: s.tags,
|
|
}))}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<aside class="artifact">
|
|
<div class="art-h">
|
|
<div class="b4-row">
|
|
<b>{editing ? stageNames[editing.stage_key] : "成果"} · 草稿</b
|
|
><span class="a-tag sc">未确认</span><span class="b4-grow"
|
|
></span><span class="dim mono art-meta"
|
|
>{structuredShots.length
|
|
? `${structuredShots.length} 镜 · ${structuredShots.reduce((sum, shot) => sum + (Number(shot.duration_sec) || 0), 0)}s`
|
|
: editing
|
|
? `v${editing.revision}`
|
|
: ""}</span
|
|
>
|
|
</div>
|
|
{#if taskResults.length > 1}<div class="b4-seg">
|
|
{#each taskResults as r (r.id)}<button
|
|
class:on={editing?.id === r.id}
|
|
onclick={() => {
|
|
if (!dirty) openResult(r);
|
|
else error = "请先保存当前成果";
|
|
}}>成果 {r.id}</button
|
|
>{/each}
|
|
</div>{/if}
|
|
<div class="b4-seg art-tabs">
|
|
<button
|
|
class:on={artifactTab === "shots"}
|
|
onclick={() => (artifactTab = "shots")}>镜头</button
|
|
>
|
|
<button disabled title="当前成果没有角色数据">角色</button>
|
|
<button
|
|
class:on={artifactTab === "text"}
|
|
onclick={() => (artifactTab = "text")}>原文</button
|
|
>
|
|
<button onclick={comparePrevious} disabled={!editing}
|
|
>对比上一版</button
|
|
>
|
|
</div>
|
|
</div>
|
|
<div class="art-b">
|
|
{#if editing}
|
|
{#if structuredShots.length && artifactTab === "shots"}
|
|
{#each structuredShots as shot, i (shot.id)}
|
|
<div class="shot">
|
|
<div class="th">
|
|
<span>{String(i + 1).padStart(2, "0")}</span
|
|
>{#if shotJob(shot.id)?.kind === "video"}<video
|
|
src={assetUrl(shotJob(shot.id)!.output_paths![0]) ??
|
|
""}
|
|
controls
|
|
muted
|
|
preload="metadata"
|
|
aria-label={`镜头 ${shot.id} 视频`}
|
|
|
|
></video>{:else if shotJob(shot.id)?.output_paths?.[0]}<img
|
|
src={assetUrl(shotJob(shot.id)!.output_paths![0]) ??
|
|
""}
|
|
alt={`镜头 ${shot.id} 草图`}
|
|
/>{:else}<small class="dim">暂无草图</small>{/if}
|
|
</div>
|
|
<div class="shot-copy">
|
|
<textarea
|
|
aria-label={`镜头 ${shot.id} 描述`}
|
|
value={shot.description || shot.prompt || ""}
|
|
oninput={(e) =>
|
|
editShot(
|
|
i,
|
|
shot.description != null ? "description" : "prompt",
|
|
e.currentTarget.value,
|
|
)}
|
|
></textarea>
|
|
<div class="b4-row">
|
|
<label class="a-tag mono"
|
|
><input
|
|
aria-label={`镜头 ${shot.id} 时长`}
|
|
type="number"
|
|
min="0.1"
|
|
step="0.1"
|
|
value={shot.duration_sec ?? 3}
|
|
oninput={(e) =>
|
|
editShot(
|
|
i,
|
|
"duration_sec",
|
|
Number(e.currentTarget.value),
|
|
)}
|
|
/>s</label
|
|
><span class="b4-grow"></span><button
|
|
class="a-btn sm ghost"
|
|
disabled={saving || !targetProject || dirty}
|
|
onclick={() => redraw(shot)}><Icon name="project-refresh" size={14}/>重画</button
|
|
>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{/each}
|
|
{:else}<textarea
|
|
class="draft-editor"
|
|
aria-label="成果草稿"
|
|
bind:value={text}
|
|
oninput={() => (dirty = true)}
|
|
></textarea>{/if}
|
|
{:else}<p class="b4-empty">
|
|
暂无成果。任务完成后,真实回复将在这里形成可编辑草稿。
|
|
</p>{/if}
|
|
</div>
|
|
<div class="art-f">
|
|
<label class="b4-row dim"
|
|
>带回到<span class="b4-chip"><select
|
|
aria-label="成果项目"
|
|
bind:value={targetProject}
|
|
onchange={() => (dirty = true)}
|
|
disabled={!editing}
|
|
><option value={null}>选择项目</option
|
|
>{#each $projects.data ?? [] as p (p.id)}<option value={p.id}
|
|
>{p.title}</option
|
|
>{/each}</select
|
|
> · <select
|
|
class="stage-select"
|
|
aria-label="成果阶段"
|
|
bind:value={targetStage}
|
|
onchange={() => (dirty = true)}
|
|
disabled={!editing}
|
|
>{#each keys as key (key)}<option value={key}
|
|
>{stageNames[key]}</option
|
|
>{/each}</select
|
|
></span></label
|
|
>
|
|
<div class="b4-row">
|
|
<button
|
|
class="a-btn secondary"
|
|
disabled={!editing || saving}
|
|
onclick={save}>保存草稿</button
|
|
><button
|
|
class="a-btn primary"
|
|
disabled={!editing || !targetProject || saving}
|
|
onclick={returnToProject}
|
|
><Icon name="arrow-right" size={14} />带回项目待确认</button
|
|
>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
{/if}
|
|
</div>
|
|
{#if error}<div class="b4-error" role="alert">
|
|
{error}<button class="a-btn sm ghost" onclick={() => (error = "")}
|
|
>关闭</button
|
|
>
|
|
</div>{/if}
|
|
</div>
|
|
</AppShell>
|
|
|
|
<Modal bind:open={compareOpen} title="对比上一版" size="lg">
|
|
<div class="b4-compare">
|
|
<section>
|
|
<h3>上一保存版本</h3>
|
|
<pre>{previousText || "尚无上一保存版本"}</pre>
|
|
</section>
|
|
<section>
|
|
<h3>当前草稿{dirty ? " · 未保存" : ""}</h3>
|
|
<pre>{text}</pre>
|
|
</section>
|
|
</div>
|
|
</Modal>
|