HEL-892: expose source-reviewed workflow documentation in shared drawer

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-28 08:23:47 +08:00
co-authored by multica-agent
parent d927925000
commit d9f3328958
23 changed files with 963 additions and 6 deletions
@@ -0,0 +1,246 @@
<script lang="ts">
import { toStore } from "svelte/store";
import { createQuery } from "@tanstack/svelte-query";
import { workflows, apiErrorMessage, type Workflow } from "$lib/api";
import Drawer from "./ui/Drawer.svelte";
import Button from "./ui/Button.svelte";
import Card from "./ui/Card.svelte";
import StatusChip from "./ui/StatusChip.svelte";
let {
open = $bindable(false),
workflow,
}: { open?: boolean; workflow: Workflow | null } = $props();
// Keep the list lightweight. Only this read-only GET loads the selected document.
const detail = createQuery(
toStore(() => {
const id = workflow?.id;
return {
queryKey: ["workflow-document", id],
queryFn: () => workflows.get(id!),
enabled: open && workflow !== null,
staleTime: 0,
};
}),
);
const wf = $derived($detail.data);
const doc = $derived(wf?.doc_json);
const review = $derived(doc?.source_review);
const deps = $derived(doc?.dependencies);
const categories: Record<string, string> = {
runtime_parameter: "有源侧用途依据",
frontend_state: "前端状态(非运行参数)",
current_value_only: "仅确认现值",
semantic_unknown: "语义待确认",
};
function value(v: unknown): string {
if (v === undefined) return "未记录";
return typeof v === "string" ? v : JSON.stringify(v, null, 2);
}
</script>
<Drawer bind:open title="工作流说明" width={440}>
<div class="document-content" aria-live="polite">
<h3>{workflow?.name}</h3>
{#if $detail.isPending || $detail.isFetching}
<p role="status">正在读取说明…</p>
{:else if $detail.isError}
<p role="alert">说明读取失败:{apiErrorMessage($detail.error)}</p>
<Button onclick={() => $detail.refetch()}>重试</Button>
{:else if wf}
<div class="document-status">
<StatusChip status="pending" label="已入库" />
<StatusChip
status="pending"
label={doc?.status?.doc_done && wf.doc_completed_at
? "说明已定稿"
: "说明未定稿"}
/>
<StatusChip
status="pending"
label={doc?.status?.exec_verified && wf.exec_verified_at
? "有实跑通过记录"
: "未验证实跑"}
/>
</div>
{#if wf.import_state === "needs_conversion"}
<Card title="待转换 / 待补材料">
<p>此条目尚不可执行,仍可阅读说明。</p>
<p>{wf.import_issues?.[0]?.message || "可靠转换尚未完成。"}</p>
<details>
<summary>全部转换阻碍({wf.import_issues?.length ?? 0})</summary>
{#each wf.import_issues ?? [] as issue}<p>{issue.message}</p>{/each}
</details>
</Card>
{/if}
<Card title="用途与来源">
<p>
{doc?.purpose ||
wf.description ||
"此旧工作流尚无详细说明,保留现有输入输出供核对。"}
</p>
{#if doc?.source_path || wf.source_repo_path}<p>
源文件:{doc?.source_path || wf.source_repo_path}
</p>{/if}
{#if review?.scope?.length}<p>
已审范围:{review.scope.join(";")}
</p>{/if}
{#each review?.semantic_review?.conclusions ?? [] as conclusion}<p>
{conclusion}
</p>{/each}
</Card>
<Card title="素材要求与输入输出">
{#each doc?.materials ?? [] as material}
<p>
素材槽 {material.slot}:{material.desc}({material.required
? "必需"
: "可选"})
</p>
{/each}
<h4>输入映射</h4>
{#each doc?.io?.inputs ?? wf.input_schema ?? [] as input}
<p>
{input.label} · {input.kind} · 节点 {input.nodeId} / {input.role ??
"未标记角色"}({input.required ? "必需" : "可选"})
</p>
{:else}<p>未记录可靠输入映射;不能据此判定无需素材。</p>{/each}
<h4>输出映射</h4>
{#each doc?.io?.outputs ?? wf.output_schema ?? [] as output}
<p>{output.label} · {output.kind} · 节点 {output.nodeId}</p>
{:else}<p>未记录可靠输出映射,实际输出待核对。</p>{/each}
{#if review?.semantic_review?.material_requirements}
<details>
<summary>源文件素材审校</summary>
<pre>{value(review.semantic_review.material_requirements)}</pre>
</details>
{/if}
</Card>
<Card title="参数与源现值">
<p>
源现值不代表推荐值。下列审校分类与单位、范围、调整效果的确认分别记录。
</p>
{#each doc?.params ?? [] as param}
{@const fields = (review?.reviewed_named_fields ?? []).filter(
(f) => f.node_id === param.node_id && f.field === param.field,
)}
<details>
<summary>节点 {param.node_id} · {param.field}</summary>
<p>源现值:</p>
<pre>{value(param.default)}</pre>
{#each fields as field}
<p>
{categories[field.category ?? ""] ??
"源字段局部审校"}:{field.label}
</p>
{#if field.scope}<p>{field.scope}</p>{/if}
{#if field.operation_check}<p>{field.operation_check}</p>{/if}
{#if field.connections}<details>
<summary>源连线依据</summary>
<pre>{value(field.connections)}</pre>
</details>{/if}
{:else}<p>已保留源字段与现值;语义待确认。</p>{/each}
<p>单位:{param.unit ?? "待确认"}</p>
<p>
范围:{param.range_source && param.range_source !== "unverified"
? `${param.min ?? "未记录下界"} ~ ${param.max ?? "未记录上界"}(${param.range_source})`
: "待确认"}
</p>
{#if param.options}<p>可选值:{value(param.options)}</p>{/if}
<p>调整效果:{param.effect || "待确认"}</p>
</details>
{:else}<p>暂无具名参数说明;位置控件不能按顺序猜测。</p>{/each}
</Card>
<Card title="模型与节点引用">
<p>
环境检查:{deps?.check_state === "unchecked" || !deps?.check_state
? "未检查"
: deps.check_state}。源引用不等于实际加载依赖,未检查不能判定缺失或就位。
</p>
{#if deps?.checked_at}<p>检查时间:{deps.checked_at}</p>{/if}
{#if deps?.source}<p>定义来源:{deps.source}</p>{/if}
<p>模型位置:{deps?.model_locations || "未检查"}</p>
<details>
<summary>模型引用({deps?.models?.length ?? 0})</summary>
{#each deps?.models ?? [] as model}<p>{model}</p>{:else}<p>
无记录,不代表环境就绪。
</p>{/each}
</details>
<details>
<summary>源节点类型({deps?.node_types?.length ?? 0})</summary>
{#each deps?.node_types ?? [] as node}<p>{node}</p>{/each}
</details>
{#if deps?.node_packs?.length}<p>
节点包:{deps.node_packs.join(";")}
</p>{/if}
</Card>
<Card title="使用步骤">
<ol>
{#each doc?.steps ?? [] as step}<li>{step}</li>{:else}<li>
此工作流尚未补充使用步骤。
</li>{/each}
</ol>
</Card>
<Card title="常见问题与待确认项">
{#each doc?.errors ?? [] as error}<details>
<summary>{error.symptom}</summary>
<p>{error.fix}</p>
</details>{/each}
{#each review?.unconfirmed ?? [] as item}<p>待确认:{item}</p>{/each}
{#if !doc}<p>
此旧工作流暂无说明数据,说明定稿、依赖环境和实跑状态均待核对。
</p>{/if}
</Card>
{#if doc?.source_notes?.length}
<Card title="源文件注释">
{#each doc.source_notes as note}<details>
<summary>节点 {note.node_id}</summary>
<pre>{value(note.content)}</pre>
</details>{/each}
</Card>
{/if}
{/if}
</div>
{#snippet footer()}<Button onclick={() => (open = false)}>关闭</Button
>{/snippet}
</Drawer>
<style>
.document-content {
display: grid;
gap: 12px;
min-width: 0;
overflow-wrap: anywhere;
}
.document-content :global(*) {
min-width: 0;
}
.document-status {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
h3,
h4,
p {
margin: 0 0 8px;
}
details {
margin: 8px 0;
}
summary {
cursor: pointer;
}
pre {
white-space: pre-wrap;
overflow-wrap: anywhere;
font: inherit;
margin: 8px 0;
}
ol {
margin: 0;
padding-left: 20px;
}
li + li {
margin-top: 8px;
}
</style>