perf: 优化工作流的节点UI和交互

This commit is contained in:
2026-03-01 15:52:22 +08:00
parent 4ef17da6f4
commit 05990072e6
10 changed files with 848 additions and 150 deletions

View File

@@ -29,7 +29,53 @@
let llmArray = $state<SelectItem[]>([]);
onMount(async () => {
const newLLMs = await options.provider?.llm?.();
llmArray.push(...(newLLMs || []));
const isFlat = newLLMs?.every(item => !item.children);
if (isFlat && newLLMs && newLLMs.length > 0) {
const grouped = new Map<string, SelectItem[]>();
for (const llm of newLLMs) {
// If it still has a slash, parse it; otherwise, check if there's a custom logic we can infer brand.
// In WorkflowDesign we pass `item.modelProvider?.providerName` via some other way, but here it's flat.
// Actually, the label is just the title now (e.g. 'deepseek-chat').
// Wait, LLMNode doesn't know the brand unless it's in the string or we modify WorkflowDesign to pass `brand`.
// Let's modify WorkflowDesign to pass `brand` instead.
let brand = (llm as any).brand || '其他';
let modelName = llm.label;
if (!grouped.has(brand)) {
grouped.set(brand, []);
}
grouped.get(brand)!.push({
...llm,
label: modelName,
displayLabel: modelName // 外部选中时也只显示模型名称
});
}
const treeArray: SelectItem[] = [];
for (const [brand, models] of grouped) {
// Try to get a representative icon for the brand from its children
let groupIcon = undefined;
if (models.length > 0) {
const modelWithIcon = models.find(m => m.icon);
if (modelWithIcon) {
groupIcon = modelWithIcon.icon;
}
}
treeArray.push({
label: brand,
value: 'group_' + brand,
selectable: false,
icon: groupIcon,
children: models
});
}
llmArray.push(...treeArray);
} else {
llmArray.push(...(newLLMs || []));
}
});
const { updateNodeData } = useSvelteFlow();
@@ -116,7 +162,7 @@
<Heading level={3} mt="10px">模型设置</Heading>
<div class="setting-title">模型</div>
<div class="setting-item">
<Select items={llmArray} style="width: 100%" placeholder="请选择模型" onSelect={(item)=>{
<Select items={llmArray} variant="model" style="width: 100%" placeholder="请选择模型" onSelect={(item)=>{
const newValue = item.value;
updateNodeData(currentNodeId, ()=>{
return {