function renderStructuredData(items, type) { if (!items || items.length === 0) { return `
暂无${type === 'workflow' ? '工序' : '能力'}数据
`; } let html = ''; items.forEach((item, idx) => { let title = item.method || item.name || (item.action && item.action.description) || (type === 'workflow' ? '工作流' : `节点 ${idx + 1}`); // Unstructured what tags let unstructTags = ''; if (item.unstructured_what && Array.isArray(item.unstructured_what)) { unstructTags = item.unstructured_what.map(t => `${t}`).join(''); } html += `
${title}
${unstructTags}
`; // Render apply_to or apply_to_draft const applyTo = item.apply_to_draft || item.apply_to; const suggestApplyTo = item.apply_to_draft ? null : item.suggest_apply_to; if (applyTo && typeof applyTo === 'object' && Object.keys(applyTo).length > 0) { html += `
apply_to
`; const renderPathBadge = (path, highlight = false) => { const pathStr = typeof path === 'object' && path !== null ? (path.element || path.category_path || path.path || '') : String(path || ''); if (!pathStr) return ''; const parts = pathStr.split('/'); const leaf = parts.pop(); const prefix = parts.length > 0 ? parts.join('/') + '/' : ''; const leafStyle = highlight ? 'background:#eff6ff; color:#2563eb; border:1px solid #bfdbfe;' : ''; return ` ${prefix ? `${prefix}` : ''} ${leaf} `; }; Object.entries(applyTo).forEach(([k, v]) => { if (Array.isArray(v) && v.length > 0) { html += `
${k}
`; v.forEach(path => { html += renderPathBadge(path); }); html += `
`; } }); if (typeof suggestApplyTo === 'string' && suggestApplyTo.trim()) { html += `
最优
${renderPathBadge(suggestApplyTo, true)}
`; } html += `
`; } if (item.action && typeof item.action === 'object' && (item.action.description || item.action.reasoning)) { const actionDescription = item.action.description ? String(item.action.description).replace(//g, '>') : ''; const actionReasoning = item.action.reasoning ? String(item.action.reasoning).replace(//g, '>') : ''; html += `
action
${actionDescription ? ` ${actionDescription} ${actionReasoning ? `` : ''} ` : ''}
`; } // Render stage if (item.stage) { let stages = Array.isArray(item.stage) ? item.stage : [item.stage]; if (stages.length > 0) { html += `
stage
`; stages.forEach(st => { const stageUpper = st.toUpperCase(); const stageClass = stageUpper === 'GENERATE' ? 'stage-blue' : 'stage-purple'; html += `${stageUpper}`; }); html += `
`; } } // Render effects if (item.effects && Array.isArray(item.effects) && item.effects.length > 0) { html += `
effects
    ${item.effects.map(li => `
  • ${li.replace(//g, '>')}
  • `).join('')}
`; } // Render body if (item.body && typeof item.body === 'string') { html += `
body
${item.body.replace(//g, '>')}
`; } // Render steps array specially if (item.steps && Array.isArray(item.steps)) { html += `
steps
`; item.steps.forEach((step, stepIdx) => { const stepTitle = step.method || step.description || `步骤 ${step.order || stepIdx + 1}`; html += `
${step.order || stepIdx + 1} ${stepTitle.replace(//g, '>')}
${step.body ? step.body.replace(//g, '>') : ''}
${step.tools && step.tools.length > 0 ? `
${step.tools.map(t => `${t}`).join('')}
` : ''}
`; }); html += `
`; } // Helper for inputs/outputs const renderDataObjList = (list) => { return list.map(io => { const dt = io.data_type || '未知'; const desc = io.description || ''; return `
${dt}${desc}
`; }).join(''); }; // Render inputs if (item.inputs && Array.isArray(item.inputs) && item.inputs.length > 0) { html += `
inputs
${renderDataObjList(item.inputs)}
`; } else if (item.inputs && typeof item.inputs === 'object' && Object.keys(item.inputs).length > 0 && !Array.isArray(item.inputs)) { // Fallback for old schema html += `
inputs
`; Object.entries(item.inputs).forEach(([k, v]) => { html += `
${k}${v}
`; }); html += `
`; } // Render outputs if (item.outputs && Array.isArray(item.outputs) && item.outputs.length > 0) { html += `
outputs
${renderDataObjList(item.outputs)}
`; } else if (item.outputs && typeof item.outputs === 'object' && Object.keys(item.outputs).length > 0 && !Array.isArray(item.outputs)) { // Fallback for old schema html += `
outputs
`; Object.entries(item.outputs).forEach(([k, v]) => { html += `
${k}${v}
`; }); html += `
`; } // Render tools if (item.tools && Array.isArray(item.tools) && item.tools.length > 0) { html += `
tools
${item.tools.map(t => `${t}`).join('')}
`; } html += `
`; }); return html; }