WorkflowEditor.vue 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458
  1. <script setup>
  2. import { ref, computed, reactive, onMounted, markRaw, nextTick } from 'vue'
  3. import { useRoute, useRouter } from 'vue-router'
  4. import { VueFlow, useVueFlow } from '@vue-flow/core'
  5. import { Background } from '@vue-flow/background'
  6. import {
  7. NInput, NSelect, NButton, NIcon, NCheckbox, useMessage
  8. } from 'naive-ui'
  9. import {
  10. ArrowBackOutline, SaveOutline, ChatbubbleEllipsesOutline,
  11. SparklesOutline, RocketOutline, FlaskOutline, GitBranchOutline, ExitOutline,
  12. PlayOutline, CloseOutline, ColorWandOutline, LinkOutline, TrashOutline, OpenOutline,
  13. TimeOutline, LibraryOutline
  14. } from '@vicons/ionicons5'
  15. import { useWorkflowStore } from '../../stores/workflow'
  16. import { useSkillStore } from '../../stores/skill'
  17. import { runWorkflow, autoAssociate } from '../../api/workflow'
  18. import { getAgentTemplate } from '../../api/agentTemplate'
  19. import { getModelList } from '../../api/model'
  20. import { getDataSources } from '../../api/datasource'
  21. import { getGraphSources } from '../../api/graphsource'
  22. import { getKbDocuments } from '../../api/knowledge'
  23. import { listKnowledgeBases } from '../../api/rag'
  24. import { normalizeKebabCase, isValidKebabCase } from '../../utils/workflowName'
  25. import InputNode from '../../components/workflow/nodes/InputNode.vue'
  26. import LLMNode from '../../components/workflow/nodes/LLMNode.vue'
  27. import AgentNode from '../../components/workflow/nodes/AgentNode.vue'
  28. import SkillNode from '../../components/workflow/nodes/SkillNode.vue'
  29. import KnowledgeRetrievalNode from '../../components/workflow/nodes/KnowledgeRetrievalNode.vue'
  30. import OutputNode from '../../components/workflow/nodes/OutputNode.vue'
  31. import ConditionNode from '../../components/workflow/nodes/ConditionNode.vue'
  32. import SmartActionNode from '../../components/workflow/nodes/SmartActionNode.vue'
  33. import VirtualGroupNode from '../../components/workflow/nodes/VirtualGroupNode.vue'
  34. import CodeEditor from '../../components/skill/CodeEditor.vue'
  35. import { inferNewEdge, refreshMappingsForNode, getNodeOutputs, getReachablePredecessors, IO_TYPES } from '../../utils/ioInference'
  36. import { useVersionHistory } from '../../composables/useVersionHistory'
  37. import { useWorkflowRunner } from '../../composables/useWorkflowRunner'
  38. import { useNodeFields } from '../../composables/useNodeFields'
  39. import '@vue-flow/core/dist/style.css'
  40. import '@vue-flow/core/dist/theme-default.css'
  41. const route = useRoute()
  42. const router = useRouter()
  43. const wfStore = useWorkflowStore()
  44. const skillStore = useSkillStore()
  45. const message = useMessage()
  46. // 路由参数 name(kebab-case);旧数字 id 作为字符串同样可被后端解析
  47. const routeName = computed(() => route.params.name || null)
  48. // 工作流 form 字段:name (kebab-case 唯一标识) / displayName (中文显示名) / description
  49. const form = ref({
  50. name: '',
  51. displayName: '',
  52. description: ''
  53. })
  54. const saving = ref(false)
  55. // 名称 5 态机(参考 SkillEdit.vue):
  56. // empty / invalid / will-rename / will-normalize / valid
  57. const nameState = computed(() => {
  58. const raw = form.value.name || ''
  59. if (!raw.trim()) return { status: 'empty', normalized: '', changed: false }
  60. const normalized = normalizeKebabCase(raw)
  61. const valid = isValidKebabCase(normalized)
  62. if (!valid) return { status: 'invalid', normalized, changed: false }
  63. // 编辑态:规范化后与路由 name 不同 → 保存时触发重命名
  64. if (routeName.value && normalized !== routeName.value) {
  65. return { status: 'will-rename', normalized, changed: true }
  66. }
  67. // raw 不规范但规范化后等于当前 name → 仅规范化输入
  68. if (normalized !== raw) return { status: 'will-normalize', normalized, changed: true }
  69. return { status: 'valid', normalized, changed: false }
  70. })
  71. // 兼容字段(保留旧变量名以减少 template 改动):workflowName = displayName
  72. const workflowName = computed({
  73. get: () => form.value.displayName,
  74. set: v => { form.value.displayName = v }
  75. })
  76. const workflowDesc = computed({
  77. get: () => form.value.description,
  78. set: v => { form.value.description = v }
  79. })
  80. // ========== SmartAction 弹出编辑器 ==========
  81. const showPromptEditor = ref(false)
  82. const promptEditValue = ref('')
  83. // ========== Vue Flow ==========
  84. const {
  85. onConnect, addEdges, addNodes, removeNodes, removeEdges,
  86. updateNodeData: vfUpdateNode,
  87. project, vueFlowRef, getNodes, getEdges, setNodes, setEdges, fitView, onInit,
  88. onNodeDrag, onNodeDragStop
  89. } = useVueFlow()
  90. const selectedNode = ref(null)
  91. // 从 userInput 节点提取输入字段定义
  92. const inputFields = computed(() => {
  93. const fields = []
  94. for (const node of getNodes.value) {
  95. if (node.type === 'userInput' && node.data?.variables) {
  96. for (const v of node.data.variables) {
  97. if (v.name) fields.push(v)
  98. }
  99. }
  100. }
  101. return fields
  102. })
  103. const formData = reactive({})
  104. const canRun = computed(() => !!routeName.value && !running.value && getNodes.value.length > 0)
  105. // ========== 自动关联 ==========
  106. const associating = ref(false)
  107. const hasAssociations = ref(false)
  108. // ========== 版本历史 ==========
  109. const {
  110. showVersionPanel, versions, versionsLoading, selectedVersion, versionContent,
  111. editingMessage, editingMessageText,
  112. toggleVersionPanel, handleVersionSelect, handleRollback,
  113. startEditMessage, saveMessage, cancelEditMessage,
  114. formatTime, formatVersionJson
  115. } = useVersionHistory()
  116. // ========== 工作流运行状态 ==========
  117. const {
  118. running, showRunDialog, showResult, workflowResult,
  119. nodeStatuses, activeTab, nodeResults, expandedLogs, expandedContext, expandedThinking,
  120. lastRunId, lastRunWorkflowId,
  121. startRun, openRunDialog, cancelRun, closeResult,
  122. statusText, logTypeIcon, logTypeLabel, formatTimestamp, toggleLogs,
  123. toggleContext, toggleThinking, formatContextValue
  124. } = useWorkflowRunner({
  125. getNodes,
  126. nodeTypeInfo: {
  127. userInput: { color: '#10B981', typeLabel: '用户输入' },
  128. llm: { color: '#8B5CF6', typeLabel: '大模型' },
  129. skill: { color: '#06B6D4', typeLabel: '技能' },
  130. agent: { color: '#F59E0B', typeLabel: '智能体' },
  131. smartAction: { color: '#EC4899', typeLabel: '智能操作' },
  132. condition: { color: '#F97316', typeLabel: '条件' },
  133. knowledgeRetrieval: { color: '#10B981', typeLabel: '知识库检索' },
  134. output: { color: '#EF4444', typeLabel: '输出' }
  135. },
  136. workflowIdRef: routeName
  137. })
  138. const defaultEdgeStyle = { stroke: '#666', strokeWidth: 2 }
  139. const selectedEdgeStyle = { stroke: '#facc15', strokeWidth: 3 }
  140. // 运行结果高亮:点击画布节点后滚动到对应结果卡片并短暂高亮
  141. const highlightedNodeId = ref(null)
  142. let highlightTimer = null
  143. function scrollToNodeResult(nodeId) {
  144. if (activeTab.value !== 'result' || nodeResults.length === 0) return
  145. const el = document.getElementById('node-result-' + nodeId)
  146. if (!el) return
  147. el.scrollIntoView({ behavior: 'smooth', block: 'center' })
  148. highlightedNodeId.value = nodeId
  149. if (highlightTimer) clearTimeout(highlightTimer)
  150. highlightTimer = setTimeout(() => { highlightedNodeId.value = null }, 2000)
  151. }
  152. onConnect((params) => {
  153. const sourceNode = getNodes.value.find(n => n.id === params.source)
  154. const targetNode = getNodes.value.find(n => n.id === params.target)
  155. const inferred = sourceNode && targetNode ? inferNewEdge(sourceNode, targetNode, getNodes.value, getEdges.value) : null
  156. addEdges([{
  157. ...params,
  158. type: 'bezier',
  159. animated: true,
  160. // 视觉上统一灰色,io 推断状态仅写入 data 供属性面板展示(不再影响线条颜色)
  161. style: defaultEdgeStyle,
  162. data: inferred?.data || {}
  163. }])
  164. })
  165. // 自适应更新虚线框与其源节点的连线端点:
  166. // 虚线框在源节点上方时,连线从虚线框底边中点连到源节点顶边中点;
  167. // 虚线框在源节点下方时,连线从虚线框顶边中点连到源节点底边中点。
  168. function updateVirtualGroupEdge(edge) {
  169. if (!edge?.data?.virtual) return
  170. const group = getNodes.value.find(n => n.id === edge.source)
  171. const source = getNodes.value.find(n => n.id === edge.target)
  172. if (!group || !source) return
  173. const groupH = group.dimensions?.height || group.height || 0
  174. const sourceH = source.dimensions?.height || source.height || 0
  175. const groupCenterY = group.position.y + groupH / 2
  176. const sourceCenterY = source.position.y + sourceH / 2
  177. if (groupCenterY < sourceCenterY) {
  178. // 虚线框在源节点上方
  179. edge.sourceHandle = 'bottom'
  180. edge.targetHandle = 'top-target'
  181. } else {
  182. // 虚线框在源节点下方
  183. edge.sourceHandle = 'top'
  184. edge.targetHandle = 'bottom-target'
  185. }
  186. }
  187. let virtualEdgeDragInProgress = false
  188. onNodeDrag(({ node }) => {
  189. if (node?.type !== 'virtualGroup') return
  190. if (virtualEdgeDragInProgress) return
  191. virtualEdgeDragInProgress = true
  192. requestAnimationFrame(() => {
  193. virtualEdgeDragInProgress = false
  194. const virtualEdges = getEdges.value.filter(e => e.data?.virtual && e.source === node.id)
  195. for (const edge of virtualEdges) {
  196. const prevSourceHandle = edge.sourceHandle
  197. const prevTargetHandle = edge.targetHandle
  198. updateVirtualGroupEdge(edge)
  199. if (edge.sourceHandle !== prevSourceHandle || edge.targetHandle !== prevTargetHandle) {
  200. // 通过替换 edge 对象触发 Vue Flow 重新计算路径
  201. getEdges.value = getEdges.value.map(e => (e.id === edge.id ? { ...edge } : e))
  202. }
  203. }
  204. })
  205. })
  206. onNodeDragStop(() => {
  207. virtualEdgeDragInProgress = false
  208. })
  209. // 批量更新边的映射数据(仅写入 data,不再改变 style;视觉统一灰色,避免不同映射状态造成颜色差异)
  210. function applyEdgeMappingUpdates(updates) {
  211. for (const upd of updates) {
  212. const edge = getEdges.value.find(e => e.id === upd.id)
  213. if (edge) {
  214. edge.data = { ...edge.data, ...upd.data }
  215. }
  216. }
  217. }
  218. // ========== 节点类型定义 ==========
  219. const nodeTypes = [
  220. { type: 'userInput', label: '用户输入', icon: markRaw(ChatbubbleEllipsesOutline), color: '#10B981' },
  221. { type: 'llm', label: '大模型处理', icon: markRaw(SparklesOutline), color: '#8B5CF6' },
  222. { type: 'skill', label: '技能', icon: markRaw(FlaskOutline), color: '#06B6D4' },
  223. { type: 'agent', label: '智能体', icon: markRaw(RocketOutline), color: '#F59E0B' },
  224. { type: 'smartAction', label: '智能操作', icon: markRaw(ColorWandOutline), color: '#EC4899' },
  225. { type: 'knowledgeRetrieval', label: '知识库检索', icon: markRaw(LibraryOutline), color: '#10B981' },
  226. { type: 'condition', label: '条件分支', icon: markRaw(GitBranchOutline), color: '#F97316' },
  227. { type: 'output', label: '输出', icon: markRaw(ExitOutline), color: '#EF4444' }
  228. ]
  229. const nodeTypeInfo = {
  230. userInput: { color: '#10B981', typeLabel: '用户输入', icon: markRaw(ChatbubbleEllipsesOutline) },
  231. llm: { color: '#8B5CF6', typeLabel: '大模型', icon: markRaw(SparklesOutline) },
  232. skill: { color: '#06B6D4', typeLabel: '技能', icon: markRaw(FlaskOutline) },
  233. agent: { color: '#F59E0B', typeLabel: '智能体', icon: markRaw(RocketOutline) },
  234. smartAction: { color: '#EC4899', typeLabel: '智能操作', icon: markRaw(ColorWandOutline) },
  235. knowledgeRetrieval: { color: '#10B981', typeLabel: '知识库检索', icon: markRaw(LibraryOutline) },
  236. condition: { color: '#F97316', typeLabel: '条件', icon: markRaw(GitBranchOutline) },
  237. output: { color: '#EF4444', typeLabel: '输出', icon: markRaw(ExitOutline) }
  238. }
  239. function getDefaultData(type) {
  240. switch (type) {
  241. case 'userInput': return { nodeName: '', label: '用户输入', variables: [] }
  242. case 'llm': return { nodeName: '', label: '大模型处理', modelId: null, systemPrompt: '', userPrompt: '', inputs: [], outputs: [{ name: 'result', label: 'LLM 输出', type: 'string', description: '' }], failStrategy: 'abort' }
  243. case 'agent': return { nodeName: '', label: '智能体', agentId: '', agentName: '', modelId: null, failStrategy: 'abort' }
  244. case 'skill': return { nodeName: '', label: '技能', skillId: '', skillName: '', modelId: null, failStrategy: 'abort' }
  245. case 'smartAction': return { nodeName: '', label: '智能操作', actionPrompt: '', modelId: null, inputs: [], outputs: [{ name: 'result', label: '操作结果', type: 'string', description: '' }], failStrategy: 'abort' }
  246. case 'knowledgeRetrieval': return {
  247. nodeName: '',
  248. label: '知识库检索',
  249. source: 'document',
  250. query: '',
  251. allDocuments: true,
  252. documentIds: [],
  253. allDatasources: false,
  254. datasourceIds: [],
  255. allGraphSources: false,
  256. graphSourceIds: [],
  257. knowledgeBaseId: null,
  258. topK: 5
  259. }
  260. case 'condition': return { nodeName: '', label: '条件分支', conditions: [{ type: 'IF', expression: '' }] }
  261. case 'output': return { nodeName: '', label: '输出', fields: [{ name: 'result', label: '输出结果', type: 'string', description: '' }] }
  262. default: return { nodeName: '', label: '节点' }
  263. }
  264. }
  265. let nodeIdCounter = 0
  266. function genId() { return `node-${++nodeIdCounter}-${Date.now()}` }
  267. // ========== 拖拽到画布 ==========
  268. function onDragOver(e) {
  269. e.preventDefault()
  270. e.dataTransfer.dropEffect = 'move'
  271. }
  272. function onDrop(e) {
  273. const type = e.dataTransfer.getData('application/vueflow')
  274. if (!type) return
  275. const bounds = vueFlowRef.value.getBoundingClientRect()
  276. const position = project({
  277. x: e.clientX - bounds.left,
  278. y: e.clientY - bounds.top
  279. })
  280. const id = genId()
  281. addNodes([{
  282. id,
  283. type,
  284. position,
  285. data: getDefaultData(type)
  286. }])
  287. }
  288. function onDragStart(e, type) {
  289. e.dataTransfer.setData('application/vueflow', type)
  290. e.dataTransfer.effectAllowed = 'move'
  291. }
  292. // ========== 节点选中 ==========
  293. function onNodeClick({ node }) {
  294. selectedNode.value = node
  295. scrollToNodeResult(node.id)
  296. }
  297. function onPaneClick() {
  298. selectedNode.value = null
  299. selectedEdgeId.value = null
  300. contextMenu.value = null
  301. }
  302. // ========== 节点右键菜单 ==========
  303. const contextMenu = ref(null) // { x, y, nodeId }
  304. function onNodeContextMenu({ event, node }) {
  305. event.preventDefault()
  306. contextMenu.value = { x: event.clientX, y: event.clientY, nodeId: node.id }
  307. }
  308. function closeContextMenu() {
  309. contextMenu.value = null
  310. }
  311. function deleteNodeById(nodeId) {
  312. const affectedNodeIds = new Set()
  313. for (const edge of getEdges.value) {
  314. if (edge.source === nodeId || edge.target === nodeId) {
  315. affectedNodeIds.add(edge.source)
  316. affectedNodeIds.add(edge.target)
  317. }
  318. }
  319. removeNodes(nodeId)
  320. if (selectedNode.value?.id === nodeId) {
  321. selectedNode.value = null
  322. }
  323. closeContextMenu()
  324. for (const id of affectedNodeIds) {
  325. if (id !== nodeId) {
  326. applyEdgeMappingUpdates(refreshMappingsForNode(id, getNodes.value, getEdges.value))
  327. }
  328. }
  329. }
  330. // ========== 连接线选中与删除 ==========
  331. const selectedEdgeId = ref(null)
  332. function onEdgeClick({ edge }) {
  333. selectedEdgeId.value = edge.id
  334. selectedNode.value = null
  335. }
  336. function deleteSelectedEdge() {
  337. if (!selectedEdgeId.value) return
  338. const edge = getEdges.value.find(e => e.id === selectedEdgeId.value)
  339. const sourceId = edge?.source
  340. const targetId = edge?.target
  341. removeEdges(selectedEdgeId.value)
  342. selectedEdgeId.value = null
  343. if (sourceId) applyEdgeMappingUpdates(refreshMappingsForNode(sourceId, getNodes.value, getEdges.value))
  344. if (targetId) applyEdgeMappingUpdates(refreshMappingsForNode(targetId, getNodes.value, getEdges.value))
  345. }
  346. function onKeyDown(e) {
  347. if (e.key === 'Delete' || e.key === 'Backspace') {
  348. const tag = e.target?.tagName
  349. if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return
  350. if (selectedNode.value) {
  351. deleteNodeById(selectedNode.value.id)
  352. } else {
  353. deleteSelectedEdge()
  354. }
  355. }
  356. }
  357. const selectedData = computed(() => selectedNode.value?.data || null)
  358. const selectedEdge = computed(() => {
  359. if (!selectedEdgeId.value) return null
  360. return getEdges.value.find(e => e.id === selectedEdgeId.value) || null
  361. })
  362. // ========== 输入变量关联:列出所有可达前驱节点的输出字段供选择 ==========
  363. // 关联范围:不仅限直接上游,而是通过边反向 BFS 找出画布中所有可达的前序节点
  364. const inputMappingOptions = computed(() => {
  365. if (!selectedNode.value) return []
  366. const predecessors = getReachablePredecessors(selectedNode.value.id, getNodes.value, getEdges.value)
  367. const opts = []
  368. for (const src of predecessors) {
  369. const outputs = getNodeOutputs(src)
  370. for (const out of outputs) {
  371. const value = JSON.stringify({ nodeId: src.id, field: out.name })
  372. opts.push({
  373. label: `${src.data?.nodeName || src.data?.label || src.id}.${out.name}`,
  374. value,
  375. nodeId: src.id,
  376. field: out.name
  377. })
  378. }
  379. }
  380. return opts
  381. })
  382. function currentMappingValue(input) {
  383. if (!input?.mapping?.sourceNodeId) return null
  384. return JSON.stringify({ nodeId: input.mapping.sourceNodeId, field: input.mapping.sourceField })
  385. }
  386. function updateInputMapping(input, value) {
  387. if (!value) {
  388. input.mapping = null
  389. } else {
  390. const parsed = JSON.parse(value)
  391. input.mapping = { sourceNodeId: parsed.nodeId, sourceField: parsed.field, sourcePath: null, autoMapped: false }
  392. }
  393. onFieldChange('inputs', [...selectedData.value.inputs])
  394. }
  395. function clearInputMapping(input) {
  396. input.mapping = null
  397. onFieldChange('inputs', [...selectedData.value.inputs])
  398. }
  399. // ========== 节点名称编辑(含重名校验) ==========
  400. function updateNodeName(value) {
  401. const trimmed = (value || '').trim()
  402. if (trimmed && selectedNode.value) {
  403. const duplicate = getNodes.value.find(n =>
  404. n.id !== selectedNode.value.id &&
  405. n.data?.nodeName === trimmed
  406. )
  407. if (duplicate) {
  408. message.warning(`节点名称「${trimmed}」已被其他节点使用`)
  409. return
  410. }
  411. }
  412. onFieldChange('nodeName', trimmed)
  413. }
  414. // ========== 智能体选项 ==========
  415. const agentOptions = computed(() =>
  416. (skillStore.skills || []).map(s => ({
  417. label: s.displayName || s.translatedDisplayName || s.name || s.folderName,
  418. value: s.folderName
  419. }))
  420. )
  421. // ========== 数据库模型选项 ==========
  422. const dbModels = ref([])
  423. const defaultModelId = ref(null)
  424. const modelOptions = computed(() =>
  425. dbModels.value.map(m => ({
  426. label: `${m.name} (${m.modelName})`,
  427. value: m.id
  428. }))
  429. )
  430. async function fetchDbModels() {
  431. try {
  432. const res = await getModelList()
  433. dbModels.value = res.data || []
  434. const defaultModel = dbModels.value.find(m => m.isDefault)
  435. defaultModelId.value = defaultModel?.id || null
  436. } catch (e) {
  437. message.error('加载模型列表失败')
  438. }
  439. }
  440. // 失败策略选项
  441. const failStrategyOptions = [
  442. { label: '终止工作流', value: 'abort' },
  443. { label: '跳过继续', value: 'skip' }
  444. ]
  445. // ========== 知识库检索节点:下拉/复选框数据源 ==========
  446. const krSourceOptions = [
  447. { label: '文档数据库', value: 'document' },
  448. { label: '结构化数据库', value: 'structured' },
  449. { label: '知识图谱库', value: 'graph' },
  450. { label: '混合检索', value: 'hybrid' }
  451. ]
  452. const krDocuments = ref([])
  453. const krDocumentsLoading = ref(false)
  454. const krDatasources = ref([])
  455. const krDatasourcesLoading = ref(false)
  456. const krGraphSources = ref([])
  457. const krGraphSourcesLoading = ref(false)
  458. const krKnowledgeBases = ref([])
  459. const krKnowledgeBasesLoading = ref(false)
  460. const krDocumentOptions = computed(() => krDocuments.value.map(d => ({ label: d.name || `#${d.id}`, value: String(d.id) })))
  461. const krDatasourceOptions = computed(() => krDatasources.value.map(d => ({ label: d.name || `#${d.id}`, value: String(d.id) })))
  462. const krGraphSourceOptions = computed(() => krGraphSources.value.map(d => ({ label: d.name || `#${d.id}`, value: String(d.id) })))
  463. const krKnowledgeBaseOptions = computed(() => krKnowledgeBases.value.map(kb => ({ label: kb.name || `#${kb.id}`, value: kb.id })))
  464. async function loadKrDocuments() {
  465. if (krDocuments.value.length || krDocumentsLoading.value) return
  466. krDocumentsLoading.value = true
  467. try {
  468. const res = await getKbDocuments({ page: 1, size: 1000 })
  469. krDocuments.value = res.data?.items || []
  470. } catch (e) {
  471. message.error('加载文档列表失败')
  472. } finally {
  473. krDocumentsLoading.value = false
  474. }
  475. }
  476. async function loadKrDatasources() {
  477. if (krDatasources.value.length || krDatasourcesLoading.value) return
  478. krDatasourcesLoading.value = true
  479. try {
  480. const res = await getDataSources()
  481. krDatasources.value = res.data || []
  482. } catch (e) {
  483. message.error('加载结构化数据源失败')
  484. } finally {
  485. krDatasourcesLoading.value = false
  486. }
  487. }
  488. async function loadKrGraphSources() {
  489. if (krGraphSources.value.length || krGraphSourcesLoading.value) return
  490. krGraphSourcesLoading.value = true
  491. try {
  492. const res = await getGraphSources()
  493. krGraphSources.value = res.data || []
  494. } catch (e) {
  495. message.error('加载图谱数据源失败')
  496. } finally {
  497. krGraphSourcesLoading.value = false
  498. }
  499. }
  500. async function loadKrKnowledgeBases() {
  501. if (krKnowledgeBases.value.length || krKnowledgeBasesLoading.value) return
  502. krKnowledgeBasesLoading.value = true
  503. try {
  504. krKnowledgeBases.value = await listKnowledgeBases() || []
  505. } catch (e) {
  506. message.error('加载知识库列表失败')
  507. } finally {
  508. krKnowledgeBasesLoading.value = false
  509. }
  510. }
  511. function toggleKrListField(field, value) {
  512. if (!selectedData.value) return
  513. const list = new Set(selectedData.value[field] || [])
  514. if (list.has(value)) list.delete(value)
  515. else list.add(value)
  516. onFieldChange(field, [...list])
  517. }
  518. // ========== 节点字段操作(来自 composable) ==========
  519. const {
  520. onFieldChange, onModelChange,
  521. addListField, removeListField,
  522. addVariable, removeVariable,
  523. addOutputField, removeOutputField,
  524. addElif, removeElif, onConditionChange,
  525. syncLlmFieldsFromTemplate
  526. } = useNodeFields({
  527. selectedNode,
  528. selectedData,
  529. vfUpdateNode,
  530. getNodes: () => getNodes,
  531. getEdges: () => getEdges,
  532. applyEdgeMappingUpdates,
  533. skillStore,
  534. agentOptions
  535. })
  536. // 兼容原有命名(template 中使用)
  537. const addLlmField = addListField
  538. const removeLlmField = removeListField
  539. const addAgentField = addListField
  540. const removeAgentField = removeListField
  541. const addConditionInput = () => addListField('inputs')
  542. const removeConditionInput = removeListField.bind(null, 'inputs')
  543. // ========== 边状态文案 ==========
  544. function edgeStatusText(status) {
  545. return { ok: '匹配完成', unmapped: '未映射', partial: '部分匹配', mismatch: '类型不匹配' }[status] || '未知'
  546. }
  547. // ========== SmartAction 弹出编辑器 ==========
  548. function openPromptEditor() {
  549. promptEditValue.value = selectedData.value?.actionPrompt || ''
  550. showPromptEditor.value = true
  551. }
  552. function confirmPromptEdit() {
  553. onFieldChange('actionPrompt', promptEditValue.value)
  554. showPromptEditor.value = false
  555. }
  556. // ========== 自动关联 ==========
  557. async function handleAutoAssociate() {
  558. if (associating.value) return
  559. clearAssociations()
  560. associating.value = true
  561. try {
  562. const graphData = JSON.stringify({
  563. nodes: getNodes.value.map(n => ({ id: n.id, type: n.type, position: n.position, data: n.data })),
  564. edges: getEdges.value.filter(e => !e.data?.virtual).map(e => ({ id: e.id, source: e.source, target: e.target, sourceHandle: e.sourceHandle, data: e.data }))
  565. })
  566. const res = await autoAssociate(graphData)
  567. const associations = res.data || []
  568. if (associations.length === 0) {
  569. message.info('未发现隐式关联的技能')
  570. return
  571. }
  572. const groups = {}
  573. for (const a of associations) {
  574. if (!groups[a.sourceNodeId]) groups[a.sourceNodeId] = []
  575. const list = groups[a.sourceNodeId]
  576. if (!list.some(x => x.folderName === a.skillFolderName)) {
  577. list.push({ folderName: a.skillFolderName, skillName: a.skillName || a.skillFolderName })
  578. }
  579. }
  580. const skillNodeMap = {}
  581. const GROUP_WIDTH = 240
  582. const GROUP_PADDING_X = 12 // 左右内边距
  583. const GROUP_PADDING_TOP = 30 // 顶部预留 label 高度
  584. const GROUP_PADDING_BOTTOM = 14 // 底部内边距
  585. const SKILL_HEIGHT = 96 // 单个技能节点占位高度(含余量)
  586. const SKILL_GAP = 12
  587. const GAP_TO_ORIGIN = 120
  588. const ts = Date.now()
  589. const groupNodes = [] // 虚框父节点
  590. const skillNodes = [] // 技能子节点
  591. const edgesToAdd = []
  592. const groupMap = {} // sourceNodeId -> groupId
  593. for (const [sourceNodeId, items] of Object.entries(groups)) {
  594. const sourceNode = getNodes.value.find(n => n.id === sourceNodeId)
  595. if (!sourceNode) continue
  596. // 源节点实际宽度(Vue Flow 渲染后测量),fallback 估计值 200
  597. const sourceWidth = sourceNode.dimensions?.width || sourceNode.width || 200
  598. const groupHeight = GROUP_PADDING_TOP + GROUP_PADDING_BOTTOM
  599. + items.length * SKILL_HEIGHT
  600. + (items.length - 1) * SKILL_GAP
  601. // 水平居中:源节点中心 X - 虚框宽度 / 2
  602. const groupX = sourceNode.position.x + sourceWidth / 2 - GROUP_WIDTH / 2
  603. const groupY = sourceNode.position.y + GAP_TO_ORIGIN
  604. const groupId = 'vg-' + sourceNodeId + '-' + ts
  605. groupMap[sourceNodeId] = groupId
  606. groupNodes.push({
  607. id: groupId,
  608. type: 'virtualGroup',
  609. position: { x: groupX, y: groupY },
  610. width: GROUP_WIDTH,
  611. height: groupHeight,
  612. zIndex: 0,
  613. data: {
  614. virtual: true,
  615. width: GROUP_WIDTH,
  616. height: groupHeight,
  617. label: items.length + ' 个关联技能'
  618. },
  619. style: { width: GROUP_WIDTH + 'px', height: groupHeight + 'px' },
  620. class: 'virtual-group-node',
  621. draggable: true, // 允许整体拖动
  622. selectable: false
  623. })
  624. }
  625. // 先加入父节点并等待其进入 Vue Flow 商店、完成尺寸测量,再添加子节点。
  626. // 之前失败的原因是 parentNode 依赖父节点 dimensions,同步批量添加时尺寸尚未就绪。
  627. if (groupNodes.length) addNodes(groupNodes)
  628. await nextTick()
  629. for (const [sourceNodeId, items] of Object.entries(groups)) {
  630. const groupId = groupMap[sourceNodeId]
  631. if (!groupId) continue
  632. items.forEach((item, idx) => {
  633. if (skillNodeMap[item.folderName]) return
  634. const existing = getNodes.value.find(n => n.type === 'skill' && n.data?.skillId === item.folderName)
  635. if (existing) {
  636. skillNodeMap[item.folderName] = existing.id
  637. return
  638. }
  639. const skillId = 'virtual-' + item.folderName + '-' + ts
  640. // 使用 Vue Flow 原生 parentNode 分组:子节点坐标相对于父节点,
  641. // extent: 'parent' 保证子节点随父节点一起移动且不会脱离虚线框。
  642. skillNodes.push({
  643. id: skillId,
  644. type: 'skill',
  645. parentNode: groupId,
  646. extent: 'parent',
  647. position: { x: GROUP_PADDING_X, y: GROUP_PADDING_TOP + idx * (SKILL_HEIGHT + SKILL_GAP) },
  648. style: { width: (GROUP_WIDTH - GROUP_PADDING_X * 2) + 'px' },
  649. data: {
  650. label: item.skillName,
  651. skillId: item.folderName,
  652. skillName: item.skillName,
  653. virtual: true
  654. },
  655. class: 'virtual-node',
  656. draggable: false, // 子节点不单独拖动
  657. selectable: false,
  658. connectable: false,
  659. zIndex: 2
  660. })
  661. skillNodeMap[item.folderName] = skillId
  662. })
  663. const edge = {
  664. id: 've-' + groupId,
  665. source: groupId,
  666. sourceHandle: 'top',
  667. target: sourceNodeId,
  668. targetHandle: 'bottom-target',
  669. type: 'straight',
  670. animated: false,
  671. style: { stroke: '#818cf8', strokeWidth: 1.5, strokeDasharray: '6 4' },
  672. class: 'virtual-group-edge',
  673. data: { virtual: true }
  674. }
  675. updateVirtualGroupEdge(edge)
  676. edgesToAdd.push(edge)
  677. }
  678. if (skillNodes.length) addNodes(skillNodes)
  679. if (edgesToAdd.length) addEdges(edgesToAdd)
  680. hasAssociations.value = true
  681. const totalSkills = Object.keys(skillNodeMap).length
  682. message.success(`发现 ${totalSkills} 个隐式关联技能(${Object.keys(groups).length} 组)`)
  683. } catch (e) {
  684. message.error(e.response?.data?.message || '关联分析失败')
  685. } finally {
  686. associating.value = false
  687. }
  688. }
  689. function clearAssociations() {
  690. const virtualNodes = getNodes.value.filter(n => n.data?.virtual)
  691. const virtualEdges = getEdges.value.filter(e => e.data?.virtual)
  692. if (virtualEdges.length) removeEdges(virtualEdges.map(e => e.id))
  693. if (virtualNodes.length) removeNodes(virtualNodes.map(n => n.id))
  694. hasAssociations.value = false
  695. }
  696. // ========== 保存前图结构校验 ==========
  697. function validateGraphData() {
  698. const nodes = getNodes.value.filter(n => !n.data?.virtual)
  699. const edges = getEdges.value.filter(e => !e.data?.virtual)
  700. const inputNodes = nodes.filter(n => n.type === 'userInput')
  701. const outputNodes = nodes.filter(n => n.type === 'output')
  702. if (!inputNodes.length) {
  703. return { valid: false, message: '工作流必须包含至少一个用户输入节点' }
  704. }
  705. if (!outputNodes.length) {
  706. return { valid: false, message: '工作流必须包含至少一个输出节点' }
  707. }
  708. const outgoing = {}
  709. edges.forEach(e => {
  710. if (!outgoing[e.source]) outgoing[e.source] = []
  711. outgoing[e.source].push(e.target)
  712. })
  713. function computeReachable(start) {
  714. const visited = new Set()
  715. const stack = [start]
  716. while (stack.length) {
  717. const current = stack.pop()
  718. if (visited.has(current)) continue
  719. visited.add(current)
  720. for (const target of outgoing[current] || []) {
  721. if (!visited.has(target)) stack.push(target)
  722. }
  723. }
  724. return visited
  725. }
  726. let hasConnectedPath = false
  727. for (const input of inputNodes) {
  728. const reachable = computeReachable(input.id)
  729. for (const output of outputNodes) {
  730. if (!reachable.has(output.id)) continue
  731. const direct = outgoing[input.id]?.includes(output.id)
  732. if (direct) {
  733. const candidates = (outgoing[input.id] || []).filter(nextId => nextId !== output.id)
  734. const stack = [...candidates]
  735. const visited = new Set()
  736. while (stack.length) {
  737. const current = stack.pop()
  738. if (visited.has(current)) continue
  739. visited.add(current)
  740. if (current === output.id) {
  741. hasConnectedPath = true
  742. break
  743. }
  744. for (const target of outgoing[current] || []) {
  745. if (!visited.has(target)) stack.push(target)
  746. }
  747. }
  748. } else {
  749. hasConnectedPath = true
  750. }
  751. if (hasConnectedPath) break
  752. }
  753. if (hasConnectedPath) break
  754. }
  755. if (!hasConnectedPath) {
  756. return { valid: false, message: '用户输入节点与输出节点必须通过其他节点连接起来' }
  757. }
  758. return { valid: true }
  759. }
  760. // ========== 保存 ==========
  761. async function handleSave() {
  762. // 校验 displayName(必填)
  763. if (!form.value.displayName.trim()) {
  764. message.warning('请输入工作流中文名称')
  765. return
  766. }
  767. // 校验 name(kebab-case)
  768. if (nameState.value.status === 'invalid') {
  769. message.error('名称规范化后仍非法(需含至少一个字母或数字)')
  770. return
  771. }
  772. if (nameState.value.status === 'empty') {
  773. message.warning('请输入工作流名称(kebab-case)')
  774. return
  775. }
  776. // 应用规范化(如用户输入大写/空格,保存时使用 normalized)
  777. const finalName = nameState.value.normalized
  778. const validation = validateGraphData()
  779. if (!validation.valid) {
  780. message.warning(validation.message)
  781. return
  782. }
  783. saving.value = true
  784. try {
  785. const graphData = JSON.stringify({
  786. nodes: getNodes.value.filter(n => !n.data?.virtual).map(n => ({ id: n.id, type: n.type, position: n.position, data: n.data })),
  787. edges: getEdges.value.filter(e => !e.data?.virtual).map(e => ({ id: e.id, source: e.source, target: e.target, sourceHandle: e.sourceHandle, data: e.data }))
  788. })
  789. if (routeName.value) {
  790. // 编辑态:用规范化后的 name 作为 URL 标识(若变化则后端会重命名)
  791. const updated = await wfStore.save(routeName.value, {
  792. name: finalName,
  793. displayName: form.value.displayName,
  794. description: form.value.description,
  795. graphData
  796. })
  797. message.success('工作流已保存')
  798. // 若 name 发生变化,跳转到新 URL
  799. if (updated?.name && updated.name !== routeName.value) {
  800. router.replace(`/orchestration/edit/${updated.name}`)
  801. }
  802. } else {
  803. // 新建:先 create 再 save 提交 graphData
  804. const created = await wfStore.create({
  805. name: finalName,
  806. displayName: form.value.displayName,
  807. description: form.value.description
  808. })
  809. await wfStore.save(created.name, {
  810. name: finalName,
  811. displayName: form.value.displayName,
  812. description: form.value.description,
  813. graphData
  814. })
  815. message.success('工作流已创建')
  816. router.replace(`/orchestration/edit/${created.name}`)
  817. }
  818. } catch (e) {
  819. message.error(e.response?.data?.message || '保存失败')
  820. } finally {
  821. saving.value = false
  822. }
  823. }
  824. function goBack() {
  825. router.push('/orchestration')
  826. }
  827. // ========== 文件选择(运行时上传) ==========
  828. function onFileSelect(e, isDir = false) {
  829. const files = Array.from(e.target.files || [])
  830. files.forEach(f => {
  831. const relativePath = isDir ? f.webkitRelativePath : f.name
  832. uploadFiles.value.push({ file: f, relativePath })
  833. })
  834. e.target.value = ''
  835. }
  836. // 文件上传列表(运行对话框使用)
  837. const uploadFiles = ref([])
  838. // 启动运行(包装 composable,处理上传文件 + 输入字段)
  839. async function handleStartRun() {
  840. const inputs = {}
  841. inputFields.value.forEach(f => {
  842. if (formData[f.name]) inputs[f.name] = formData[f.name]
  843. })
  844. await startRun(routeName.value, inputs, uploadFiles.value)
  845. uploadFiles.value = []
  846. }
  847. function handleOpenRunDialog() {
  848. openRunDialog(inputFields, formData)
  849. uploadFiles.value = []
  850. }
  851. // 回滚应用到画布(供 useVersionHistory 调用)
  852. async function applyVersionToCanvas(wf) {
  853. if (!wf) return
  854. // 回滚仅恢复 graphData + description;name/displayName 保持当前以避免与 URL 错位
  855. workflowDesc.value = wf.description || ''
  856. if (wf.graphData) {
  857. const data = JSON.parse(wf.graphData)
  858. setNodes((data.nodes || []).map(n => ({ ...n, data: { ...getDefaultData(n.type), ...n.data } })))
  859. setEdges((data.edges || []).map(e => ({
  860. ...e,
  861. type: 'bezier',
  862. animated: true,
  863. style: defaultEdgeStyle,
  864. data: e.data || {}
  865. })))
  866. await nextTick()
  867. for (const node of getNodes.value) {
  868. applyEdgeMappingUpdates(refreshMappingsForNode(node.id, getNodes.value, getEdges.value))
  869. }
  870. fitView({ padding: 0.5 })
  871. }
  872. }
  873. // 包装版本历史的方法以适配本组件 API
  874. async function handleRollbackWrap(v) {
  875. await handleRollback(routeName.value, v, applyVersionToCanvas)
  876. }
  877. async function handleVersionSelectWrap(v) {
  878. await handleVersionSelect(routeName.value, v)
  879. }
  880. async function toggleVersionPanelWrap() {
  881. await toggleVersionPanel(routeName.value)
  882. }
  883. async function saveMessageWrap(v) {
  884. await saveMessage(routeName.value, v)
  885. }
  886. // ========== 初始化 ==========
  887. onMounted(async () => {
  888. skillStore.fetchSkills()
  889. fetchDbModels()
  890. // 预加载知识库检索节点所需的资源列表(失败不阻塞主流程)
  891. loadKrDocuments()
  892. loadKrDatasources()
  893. loadKrGraphSources()
  894. loadKrKnowledgeBases()
  895. if (routeName.value) {
  896. // 编辑已有工作流(routeName 为 kebab-case name 或旧数字 id 字符串)
  897. try {
  898. const wf = await wfStore.fetchOne(routeName.value)
  899. // 后端迁移后:wf.name 为 kebab-case 唯一标识,wf.displayName 为中文显示名
  900. form.value.name = wf.name || ''
  901. form.value.displayName = wf.displayName || wf.name || ''
  902. form.value.description = wf.description || ''
  903. if (wf.graphData) {
  904. applyGraphData(wf.graphData)
  905. }
  906. } catch {
  907. message.error('工作流不存在')
  908. goBack()
  909. }
  910. } else if (route.query.templateId) {
  911. // 从模板创建:加载模板 graphData 作为初始内容
  912. try {
  913. const tplId = Number(route.query.templateId)
  914. const { data: tpl } = await getAgentTemplate(tplId)
  915. if (tpl) {
  916. // 用模板名作为 displayName 初始值(name 留空,由用户填写并规范化)
  917. if (tpl.name) form.value.displayName = `${tpl.name}-工作流`
  918. if (tpl.description) form.value.description = tpl.description
  919. if (tpl.graphData) {
  920. applyGraphData(tpl.graphData)
  921. message.info(`已加载模板「${tpl.name}」`)
  922. }
  923. }
  924. } catch (e) {
  925. /* 全局拦截器已处理 */
  926. message.warning('模板加载失败,将创建空白工作流')
  927. }
  928. }
  929. await nextTick()
  930. fitView({ padding: 0.5 })
  931. })
  932. // 将 graphData(JSON 字符串)应用到画布
  933. function applyGraphData(graphData) {
  934. try {
  935. const parsed = typeof graphData === 'string' ? JSON.parse(graphData) : graphData
  936. addNodes((parsed.nodes || []).map(n => {
  937. const defaults = getDefaultData(n.type)
  938. return { ...n, data: { ...defaults, ...n.data, label: defaults.label } }
  939. }))
  940. const edgeData = (parsed.edges || []).map(e => ({
  941. ...e,
  942. type: 'bezier',
  943. animated: true,
  944. style: defaultEdgeStyle,
  945. data: e.data || {}
  946. }))
  947. if (edgeData.length) addEdges(edgeData)
  948. for (const node of getNodes.value) {
  949. applyEdgeMappingUpdates(refreshMappingsForNode(node.id, getNodes.value, getEdges.value))
  950. }
  951. } catch { /* ignore */ }
  952. }
  953. </script>
  954. <template>
  955. <div class="workflow-editor" @keydown="onKeyDown" tabindex="0">
  956. <!-- 顶部工具栏 -->
  957. <div class="editor-toolbar">
  958. <div class="toolbar-left">
  959. <button class="icon-btn" title="返回列表" @click="goBack">
  960. <n-icon size="18">
  961. <ArrowBackOutline />
  962. </n-icon>
  963. </button>
  964. <div class="toolbar-form">
  965. <div class="wf-field wf-field-show">
  966. <label class="wf-label">
  967. 智能体展示名称
  968. <span class="label-hint">(可包含中文)</span>
  969. </label>
  970. <n-input v-model:value="form.displayName" placeholder="如:军事分析助手" style="width: 200px" size="small"
  971. :maxlength="100" />
  972. </div>
  973. <div class="wf-field wf-field-name">
  974. <label class="wf-label">
  975. 智能体名称
  976. <span class="label-hint">(kebab-case,唯一标识,禁用大写/空格/下划线/中文)</span>
  977. </label>
  978. <n-input v-model:value="form.name" placeholder="如:military-analyze-agent" size="small"
  979. :maxlength="64"
  980. :status="nameState.status === 'invalid' ? 'error' : nameState.status === 'will-rename' || nameState.status === 'will-normalize' ? 'warning' : 'success'" />
  981. </div>
  982. <div class="wf-field wf-field-grow">
  983. <label class="wf-label">智能体描述</label>
  984. <n-input v-model:value="form.description" placeholder="请输入智能体描述" size="small"
  985. :maxlength="500" />
  986. </div>
  987. <div class="wf-name-hint">
  988. <span v-if="nameState.status === 'will-rename'" class="hint-warn">
  989. ⚠ 保存时将重命名:<code>{{ routeName }}</code> → <code>{{ nameState.normalized }}</code>
  990. </span>
  991. <span v-else-if="nameState.status === 'will-normalize'" class="hint-warn">
  992. 将规范化为:<code>{{ nameState.normalized }}</code>
  993. </span>
  994. <span v-else-if="nameState.status === 'invalid'" class="hint-error">
  995. 规范化后仍非法(需含字母或数字)
  996. </span>
  997. <span v-else-if="nameState.status === 'valid'" class="hint-ok">
  998. ✓ 合法 kebab-case
  999. </span>
  1000. </div>
  1001. </div>
  1002. </div>
  1003. <div class="toolbar-right">
  1004. <button :class="['version-btn', { active: showVersionPanel }]" @click="toggleVersionPanelWrap"
  1005. :disabled="!routeName">
  1006. <n-icon size="16">
  1007. <TimeOutline />
  1008. </n-icon>
  1009. <span>版本历史</span>
  1010. </button>
  1011. <button class="associate-btn" :class="{ active: hasAssociations }" @click="handleAutoAssociate"
  1012. :disabled="associating">
  1013. <n-icon size="16">
  1014. <LinkOutline />
  1015. </n-icon>
  1016. <span>{{ associating ? '分析中...' : hasAssociations ? '重新关联' : '自动关联' }}</span>
  1017. </button>
  1018. <button v-if="hasAssociations" class="clear-assoc-btn" @click="clearAssociations" title="清除关联">
  1019. <n-icon size="14">
  1020. <TrashOutline />
  1021. </n-icon>
  1022. </button>
  1023. <button class="run-btn" :class="{ 'is-running': running }" @click="handleOpenRunDialog" :disabled="!canRun">
  1024. <n-icon size="16">
  1025. <PlayOutline />
  1026. </n-icon>
  1027. <span>{{ running ? '执行中...' : '运行' }}</span>
  1028. </button>
  1029. <button class="primary-btn" @click="handleSave" :disabled="saving">
  1030. <n-icon size="16">
  1031. <SaveOutline />
  1032. </n-icon>
  1033. <span>{{ saving ? '保存中...' : '完成' }}</span>
  1034. </button>
  1035. </div>
  1036. </div>
  1037. <div class="editor-body">
  1038. <!-- 左侧节点工具栏 -->
  1039. <div class="sidebar-nodes">
  1040. <div class="sidebar-title">节点</div>
  1041. <div v-for="nt in nodeTypes" :key="nt.type" class="node-type-item" draggable="true"
  1042. @dragstart="onDragStart($event, nt.type)">
  1043. <div class="nt-icon" :style="{ background: nt.color }">
  1044. <n-icon size="14">
  1045. <component :is="nt.icon" />
  1046. </n-icon>
  1047. </div>
  1048. <span class="nt-label">{{ nt.label }}</span>
  1049. </div>
  1050. </div>
  1051. <!-- 中间画布 -->
  1052. <div class="canvas-area" @dragover="onDragOver" @drop="onDrop">
  1053. <VueFlow :default-viewport="{ zoom: 1, x: 0, y: 0 }" :min-zoom="0.1" :max-zoom="2" :elements-selectable="true"
  1054. :select-nodes-on-drag="false" @node-click="onNodeClick" @node-contextmenu="onNodeContextMenu"
  1055. @pane-click="onPaneClick" @edge-click="onEdgeClick" :snap-to-grid="true" :snap-grid="[20, 20]">
  1056. <template #node-userInput="nodeProps">
  1057. <InputNode :data="nodeProps.data" />
  1058. </template>
  1059. <template #node-llm="nodeProps">
  1060. <LLMNode :data="nodeProps.data" />
  1061. </template>
  1062. <template #node-agent="nodeProps">
  1063. <AgentNode :data="nodeProps.data" />
  1064. </template>
  1065. <template #node-skill="nodeProps">
  1066. <SkillNode :data="nodeProps.data" />
  1067. </template>
  1068. <template #node-knowledgeRetrieval="nodeProps">
  1069. <KnowledgeRetrievalNode :data="nodeProps.data" />
  1070. </template>
  1071. <template #node-output="nodeProps">
  1072. <OutputNode :data="nodeProps.data" />
  1073. </template>
  1074. <template #node-condition="nodeProps">
  1075. <ConditionNode :data="nodeProps.data" />
  1076. </template>
  1077. <template #node-smartAction="nodeProps">
  1078. <SmartActionNode :data="nodeProps.data" />
  1079. </template>
  1080. <template #node-virtualGroup="nodeProps">
  1081. <VirtualGroupNode :data="nodeProps.data"
  1082. :style="{ width: nodeProps.data.width + 'px', height: nodeProps.data.height + 'px' }" />
  1083. </template>
  1084. <Background :gap="20" :size="1" pattern-color="rgba(255,255,255,0.05)" />
  1085. </VueFlow>
  1086. </div>
  1087. <!-- 右侧面板 - Tab 页 -->
  1088. <div class="sidebar-right">
  1089. <div class="sidebar-tabs">
  1090. <button class="tab-btn" :class="{ active: activeTab === 'props' }" @click="activeTab = 'props'">节点属性</button>
  1091. <button class="tab-btn" :class="{ active: activeTab === 'result' }" @click="activeTab = 'result'">
  1092. 运行结果
  1093. <span v-if="nodeResults.length" class="result-badge">{{ nodeResults.length }}</span>
  1094. </button>
  1095. </div>
  1096. <div class="sidebar-tab-content">
  1097. <!-- 节点属性 Tab -->
  1098. <div v-show="activeTab === 'props'" class="tab-pane">
  1099. <template v-if="selectedData">
  1100. <!-- 节点名称(可选,画布内唯一) -->
  1101. <div class="prop-section">
  1102. <label class="prop-label">节点名称</label>
  1103. <n-input :value="selectedData?.nodeName || ''" placeholder="可选,留空则仅显示节点类型" size="small"
  1104. @update:value="v => updateNodeName(v)" />
  1105. </div>
  1106. <!-- 用户输入节点 -->
  1107. <template v-if="selectedNode?.type === 'userInput'">
  1108. <div class="prop-section">
  1109. <div class="prop-header">
  1110. <span class="prop-label">输入变量</span>
  1111. <button class="text-btn" @click="addVariable">+ 添加</button>
  1112. </div>
  1113. <div v-for="(v, i) in selectedData?.variables || []" :key="i" class="var-form">
  1114. <div class="var-form-row">
  1115. <n-input :value="v.name" placeholder="变量名" size="small"
  1116. @update:value="nv => { v.name = nv; onFieldChange('variables', [...selectedData.variables]) }" />
  1117. <n-input :value="v.label" placeholder="中文名" size="small"
  1118. @update:value="nv => { v.label = nv; onFieldChange('variables', [...selectedData.variables]) }" />
  1119. </div>
  1120. <div class="var-form-row">
  1121. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1122. @update:value="nv => { v.type = nv; onFieldChange('variables', [...selectedData.variables]) }" />
  1123. <n-input :value="v.description" placeholder="描述" size="small"
  1124. @update:value="nv => { v.description = nv; onFieldChange('variables', [...selectedData.variables]) }" />
  1125. </div>
  1126. <button class="text-btn danger" @click="removeVariable(i)">删除</button>
  1127. </div>
  1128. <div v-if="!selectedData?.variables?.length" class="empty-hint">暂无变量</div>
  1129. </div>
  1130. </template>
  1131. <!-- 大模型处理节点 -->
  1132. <template v-if="selectedNode?.type === 'llm'">
  1133. <div class="prop-section">
  1134. <label class="prop-label">模型</label>
  1135. <n-select :value="selectedData?.modelId == null ? null : Number(selectedData.modelId)"
  1136. :options="modelOptions" placeholder="选择模型(默认使用默认模型)" size="small" clearable
  1137. @update:value="v => onModelChange(v, dbModels)" />
  1138. </div>
  1139. <div class="prop-section">
  1140. <label class="prop-label">系统提示词</label>
  1141. <n-input :value="selectedData?.systemPrompt" type="textarea" :rows="3" placeholder="输入系统提示词"
  1142. size="small" @update:value="v => onFieldChange('systemPrompt', v)" />
  1143. </div>
  1144. <div class="prop-section">
  1145. <label class="prop-label">用户提示词</label>
  1146. <n-input :value="selectedData?.userPrompt" type="textarea" :rows="3"
  1147. placeholder="输入用户提示词,可用 {{变量名}} 引用变量" size="small"
  1148. @update:value="v => onFieldChange('userPrompt', v)" />
  1149. </div>
  1150. <!-- 前置数据 -->
  1151. <div class="prop-section">
  1152. <div class="prop-header">
  1153. <span class="prop-label">前置数据</span>
  1154. <div style="display:flex;gap:4px">
  1155. <button class="text-btn" @click="syncLlmFieldsFromTemplate('inputs')">从模板同步</button>
  1156. <button class="text-btn" @click="addLlmField('inputs')">+ 添加</button>
  1157. </div>
  1158. </div>
  1159. <div v-for="(v, i) in selectedData?.inputs || []" :key="'in-' + i" class="var-form">
  1160. <div class="var-form-row">
  1161. <n-input :value="v.name" placeholder="变量名" size="small"
  1162. @update:value="nv => { v.name = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1163. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1164. @update:value="nv => { v.type = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1165. </div>
  1166. <div class="var-form-row">
  1167. <n-input :value="v.label" placeholder="中文名" size="small"
  1168. @update:value="nv => { v.label = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1169. <button class="text-btn danger" @click="removeLlmField('inputs', i)">删除</button>
  1170. </div>
  1171. <div class="var-form-row mapping-row">
  1172. <n-select :value="currentMappingValue(v)"
  1173. :options="[{ label: '自动推断', value: null }, ...inputMappingOptions]" size="small"
  1174. clearable placeholder="关联方式:自动推断"
  1175. @update:value="nv => updateInputMapping(v, nv)" />
  1176. </div>
  1177. </div>
  1178. <div v-if="!selectedData?.inputs?.length" class="empty-hint">可用 {{ 变量名 }} 引用,或手动添加</div>
  1179. </div>
  1180. <!-- 输出变量 -->
  1181. <div class="prop-section">
  1182. <div class="prop-header">
  1183. <span class="prop-label">输出变量</span>
  1184. <button class="text-btn" @click="addLlmField('outputs')">+ 添加</button>
  1185. </div>
  1186. <div v-for="(v, i) in selectedData?.outputs || []" :key="'out-' + i" class="var-form">
  1187. <div class="var-form-row">
  1188. <n-input :value="v.name" placeholder="变量名" size="small"
  1189. @update:value="nv => { v.name = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1190. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1191. @update:value="nv => { v.type = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1192. </div>
  1193. <div class="var-form-row">
  1194. <n-input :value="v.label" placeholder="中文名" size="small"
  1195. @update:value="nv => { v.label = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1196. <button class="text-btn danger" @click="removeLlmField('outputs', i)">删除</button>
  1197. </div>
  1198. </div>
  1199. <div v-if="!selectedData?.outputs?.length" class="empty-hint">默认输出 result 变量</div>
  1200. </div>
  1201. <!-- 失败策略 -->
  1202. <div class="prop-section">
  1203. <label class="prop-label">失败策略</label>
  1204. <n-select :value="selectedData?.failStrategy || 'abort'" :options="failStrategyOptions" size="small"
  1205. @update:value="v => onFieldChange('failStrategy', v)" />
  1206. </div>
  1207. </template>
  1208. <!-- 智能体节点 -->
  1209. <template v-if="selectedNode?.type === 'agent'">
  1210. <div class="prop-section">
  1211. <label class="prop-label">选择智能体</label>
  1212. <n-select :value="selectedData?.agentId" :options="agentOptions" placeholder="选择技能" size="small"
  1213. filterable @update:value="v => onFieldChange('agentId', v)" />
  1214. </div>
  1215. <div class="prop-section">
  1216. <label class="prop-label">模型</label>
  1217. <n-select :value="selectedData?.modelId == null ? null : Number(selectedData.modelId)"
  1218. :options="modelOptions" placeholder="默认使用默认模型" size="small" clearable
  1219. @update:value="v => onModelChange(v, dbModels)" />
  1220. </div>
  1221. <!-- 前置数据 -->
  1222. <div class="prop-section">
  1223. <div class="prop-header">
  1224. <span class="prop-label">前置数据</span>
  1225. <button class="text-btn" @click="addAgentField('inputs')">+ 添加</button>
  1226. </div>
  1227. <div v-for="(v, i) in selectedData?.inputs || []" :key="'in-' + i" class="var-form">
  1228. <div class="var-form-row">
  1229. <n-input :value="v.name" placeholder="变量名" size="small"
  1230. @update:value="nv => { v.name = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1231. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1232. @update:value="nv => { v.type = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1233. </div>
  1234. <div class="var-form-row">
  1235. <n-input :value="v.label" placeholder="中文名" size="small"
  1236. @update:value="nv => { v.label = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1237. <button class="text-btn danger" @click="removeAgentField('inputs', i)">删除</button>
  1238. </div>
  1239. <div class="var-form-row mapping-row">
  1240. <n-select :value="currentMappingValue(v)"
  1241. :options="[{ label: '自动推断', value: null }, ...inputMappingOptions]" size="small"
  1242. clearable placeholder="关联方式:自动推断"
  1243. @update:value="nv => updateInputMapping(v, nv)" />
  1244. </div>
  1245. </div>
  1246. <div v-if="!selectedData?.inputs?.length" class="empty-hint">选择技能后自动填充</div>
  1247. </div>
  1248. <!-- 输出变量 -->
  1249. <div class="prop-section">
  1250. <div class="prop-header">
  1251. <span class="prop-label">输出变量</span>
  1252. <button class="text-btn" @click="addAgentField('outputs')">+ 添加</button>
  1253. </div>
  1254. <div v-for="(v, i) in selectedData?.outputs || []" :key="'out-' + i" class="var-form">
  1255. <div class="var-form-row">
  1256. <n-input :value="v.name" placeholder="变量名" size="small"
  1257. @update:value="nv => { v.name = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1258. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1259. @update:value="nv => { v.type = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1260. </div>
  1261. <div class="var-form-row">
  1262. <n-input :value="v.label" placeholder="中文名" size="small"
  1263. @update:value="nv => { v.label = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1264. <button class="text-btn danger" @click="removeAgentField('outputs', i)">删除</button>
  1265. </div>
  1266. </div>
  1267. <div v-if="!selectedData?.outputs?.length" class="empty-hint">选择技能后自动填充</div>
  1268. </div>
  1269. <!-- 失败策略 -->
  1270. <div class="prop-section">
  1271. <label class="prop-label">失败策略</label>
  1272. <n-select :value="selectedData?.failStrategy || 'abort'" :options="failStrategyOptions" size="small"
  1273. @update:value="v => onFieldChange('failStrategy', v)" />
  1274. </div>
  1275. </template>
  1276. <!-- 技能节点 -->
  1277. <template v-if="selectedNode?.type === 'skill'">
  1278. <div class="prop-section">
  1279. <label class="prop-label">选择技能</label>
  1280. <n-select :value="selectedData?.skillId" :options="agentOptions" placeholder="选择技能" size="small"
  1281. filterable @update:value="v => onFieldChange('skillId', v)" />
  1282. </div>
  1283. <div class="prop-section">
  1284. <label class="prop-label">模型</label>
  1285. <n-select :value="selectedData?.modelId == null ? null : Number(selectedData.modelId)"
  1286. :options="modelOptions" placeholder="默认使用默认模型" size="small" clearable
  1287. @update:value="v => onModelChange(v, dbModels)" />
  1288. </div>
  1289. <!-- 前置数据 -->
  1290. <div class="prop-section">
  1291. <div class="prop-header">
  1292. <span class="prop-label">前置数据</span>
  1293. <button class="text-btn" @click="addAgentField('inputs')">+ 添加</button>
  1294. </div>
  1295. <div v-for="(v, i) in selectedData?.inputs || []" :key="'in-' + i" class="var-form">
  1296. <div class="var-form-row">
  1297. <n-input :value="v.name" placeholder="变量名" size="small"
  1298. @update:value="nv => { v.name = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1299. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1300. @update:value="nv => { v.type = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1301. </div>
  1302. <div class="var-form-row">
  1303. <n-input :value="v.label" placeholder="中文名" size="small"
  1304. @update:value="nv => { v.label = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1305. <button class="text-btn danger" @click="removeAgentField('inputs', i)">删除</button>
  1306. </div>
  1307. <div class="var-form-row mapping-row">
  1308. <n-select :value="currentMappingValue(v)"
  1309. :options="[{ label: '自动推断', value: null }, ...inputMappingOptions]" size="small"
  1310. clearable placeholder="关联方式:自动推断"
  1311. @update:value="nv => updateInputMapping(v, nv)" />
  1312. </div>
  1313. </div>
  1314. <div v-if="!selectedData?.inputs?.length" class="empty-hint">选择技能后自动填充</div>
  1315. </div>
  1316. <!-- 输出变量 -->
  1317. <div class="prop-section">
  1318. <div class="prop-header">
  1319. <span class="prop-label">输出变量</span>
  1320. <button class="text-btn" @click="addAgentField('outputs')">+ 添加</button>
  1321. </div>
  1322. <div v-for="(v, i) in selectedData?.outputs || []" :key="'out-' + i" class="var-form">
  1323. <div class="var-form-row">
  1324. <n-input :value="v.name" placeholder="变量名" size="small"
  1325. @update:value="nv => { v.name = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1326. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1327. @update:value="nv => { v.type = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1328. </div>
  1329. <div class="var-form-row">
  1330. <n-input :value="v.label" placeholder="中文名" size="small"
  1331. @update:value="nv => { v.label = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1332. <button class="text-btn danger" @click="removeAgentField('outputs', i)">删除</button>
  1333. </div>
  1334. </div>
  1335. <div v-if="!selectedData?.outputs?.length" class="empty-hint">选择技能后自动填充</div>
  1336. </div>
  1337. <!-- 失败策略 -->
  1338. <div class="prop-section">
  1339. <label class="prop-label">失败策略</label>
  1340. <n-select :value="selectedData?.failStrategy || 'abort'" :options="failStrategyOptions" size="small"
  1341. @update:value="v => onFieldChange('failStrategy', v)" />
  1342. </div>
  1343. </template>
  1344. <!-- 智能操作节点 -->
  1345. <template v-if="selectedNode?.type === 'smartAction'">
  1346. <div class="prop-section">
  1347. <div class="prop-header">
  1348. <span class="prop-label">操作要求</span>
  1349. <button class="text-btn" @click="openPromptEditor" title="在编辑器中打开">
  1350. <n-icon size="12">
  1351. <OpenOutline />
  1352. </n-icon> 展开
  1353. </button>
  1354. </div>
  1355. <n-input :value="selectedData?.actionPrompt" type="textarea" :rows="5" placeholder="描述你希望 AI 执行的操作..."
  1356. size="small" @update:value="v => onFieldChange('actionPrompt', v)" />
  1357. </div>
  1358. <div class="prop-section">
  1359. <label class="prop-label">模型</label>
  1360. <n-select :value="selectedData?.modelId == null ? null : Number(selectedData.modelId)"
  1361. :options="modelOptions" placeholder="默认使用默认模型" size="small" clearable
  1362. @update:value="v => onModelChange(v, dbModels)" />
  1363. </div>
  1364. <!-- 前置数据 -->
  1365. <div class="prop-section">
  1366. <div class="prop-header">
  1367. <span class="prop-label">前置数据</span>
  1368. <button class="text-btn" @click="addAgentField('inputs')">+ 添加</button>
  1369. </div>
  1370. <div v-for="(v, i) in selectedData?.inputs || []" :key="'in-' + i" class="var-form">
  1371. <div class="var-form-row">
  1372. <n-input :value="v.name" placeholder="变量名" size="small"
  1373. @update:value="nv => { v.name = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1374. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1375. @update:value="nv => { v.type = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1376. </div>
  1377. <div class="var-form-row">
  1378. <n-input :value="v.label" placeholder="中文名" size="small"
  1379. @update:value="nv => { v.label = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1380. <button class="text-btn danger" @click="removeAgentField('inputs', i)">删除</button>
  1381. </div>
  1382. <div class="var-form-row mapping-row">
  1383. <n-select :value="currentMappingValue(v)"
  1384. :options="[{ label: '自动推断', value: null }, ...inputMappingOptions]" size="small"
  1385. clearable placeholder="关联方式:自动推断"
  1386. @update:value="nv => updateInputMapping(v, nv)" />
  1387. </div>
  1388. </div>
  1389. <div v-if="!selectedData?.inputs?.length" class="empty-hint">可用 {{ 变量名 }} 引用,或手动添加</div>
  1390. </div>
  1391. <!-- 输出变量 -->
  1392. <div class="prop-section">
  1393. <div class="prop-header">
  1394. <span class="prop-label">输出变量</span>
  1395. <button class="text-btn" @click="addAgentField('outputs')">+ 添加</button>
  1396. </div>
  1397. <div v-for="(v, i) in selectedData?.outputs || []" :key="'out-' + i" class="var-form">
  1398. <div class="var-form-row">
  1399. <n-input :value="v.name" placeholder="变量名" size="small"
  1400. @update:value="nv => { v.name = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1401. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1402. @update:value="nv => { v.type = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1403. </div>
  1404. <div class="var-form-row">
  1405. <n-input :value="v.label" placeholder="中文名" size="small"
  1406. @update:value="nv => { v.label = nv; onFieldChange('outputs', [...selectedData.outputs]) }" />
  1407. <button class="text-btn danger" @click="removeAgentField('outputs', i)">删除</button>
  1408. </div>
  1409. </div>
  1410. <div v-if="!selectedData?.outputs?.length" class="empty-hint">默认输出 result 变量</div>
  1411. </div>
  1412. <!-- 失败策略 -->
  1413. <div class="prop-section">
  1414. <label class="prop-label">失败策略</label>
  1415. <n-select :value="selectedData?.failStrategy || 'abort'" :options="failStrategyOptions" size="small"
  1416. @update:value="v => onFieldChange('failStrategy', v)" />
  1417. </div>
  1418. </template>
  1419. <!-- 知识库检索节点 -->
  1420. <template v-if="selectedNode?.type === 'knowledgeRetrieval'">
  1421. <div class="prop-section">
  1422. <label class="prop-label">检索来源</label>
  1423. <n-select :value="selectedData?.source || 'document'" :options="krSourceOptions" size="small"
  1424. @update:value="v => onFieldChange('source', v)" />
  1425. </div>
  1426. <div class="prop-section">
  1427. <label class="prop-label">检索语句</label>
  1428. <n-input :value="selectedData?.query" type="textarea" :rows="3" placeholder="输入检索语句,可用 {{变量名}} 引用上游变量"
  1429. size="small" @update:value="v => onFieldChange('query', v)" />
  1430. </div>
  1431. <!-- 文档数据库 -->
  1432. <template v-if="(selectedData?.source || 'document') === 'document'">
  1433. <div class="prop-section">
  1434. <label class="kr-checkbox-row">
  1435. <n-checkbox :checked="!!selectedData?.allDocuments"
  1436. @update:checked="v => onFieldChange('allDocuments', v)" />
  1437. <span>在所有文档中检索</span>
  1438. </label>
  1439. <div v-if="!selectedData?.allDocuments" class="kr-list">
  1440. <div v-if="krDocumentsLoading" class="empty-hint">加载中...</div>
  1441. <div v-else-if="!krDocumentOptions.length" class="empty-hint">暂无文档</div>
  1442. <label v-for="opt in krDocumentOptions" :key="opt.value" class="kr-checkbox-row">
  1443. <n-checkbox :checked="(selectedData?.documentIds || []).includes(opt.value)"
  1444. @update:checked="() => toggleKrListField('documentIds', opt.value)" />
  1445. <span>{{ opt.label }}</span>
  1446. </label>
  1447. </div>
  1448. </div>
  1449. <div class="prop-section">
  1450. <label class="prop-label">TopK(命中条数)</label>
  1451. <n-input :value="String(selectedData?.topK ?? 5)" type="text" size="small"
  1452. @update:value="v => onFieldChange('topK', Math.max(1, parseInt(v) || 5))" />
  1453. </div>
  1454. </template>
  1455. <!-- 结构化数据库 -->
  1456. <template v-if="selectedData?.source === 'structured'">
  1457. <div class="prop-section">
  1458. <label class="kr-checkbox-row">
  1459. <n-checkbox :checked="!!selectedData?.allDatasources"
  1460. @update:checked="v => onFieldChange('allDatasources', v)" />
  1461. <span>在所有数据源中检索</span>
  1462. </label>
  1463. <div v-if="!selectedData?.allDatasources" class="kr-list">
  1464. <div v-if="krDatasourcesLoading" class="empty-hint">加载中...</div>
  1465. <div v-else-if="!krDatasourceOptions.length" class="empty-hint">暂无数据源</div>
  1466. <label v-for="opt in krDatasourceOptions" :key="opt.value" class="kr-checkbox-row">
  1467. <n-checkbox :checked="(selectedData?.datasourceIds || []).includes(opt.value)"
  1468. @update:checked="() => toggleKrListField('datasourceIds', opt.value)" />
  1469. <span>{{ opt.label }}</span>
  1470. </label>
  1471. </div>
  1472. </div>
  1473. </template>
  1474. <!-- 知识图谱库 -->
  1475. <template v-if="selectedData?.source === 'graph'">
  1476. <div class="prop-section">
  1477. <label class="kr-checkbox-row">
  1478. <n-checkbox :checked="!!selectedData?.allGraphSources"
  1479. @update:checked="v => onFieldChange('allGraphSources', v)" />
  1480. <span>在所有数据源中检索</span>
  1481. </label>
  1482. <div v-if="!selectedData?.allGraphSources" class="kr-list">
  1483. <div v-if="krGraphSourcesLoading" class="empty-hint">加载中...</div>
  1484. <div v-else-if="!krGraphSourceOptions.length" class="empty-hint">暂无图谱数据源</div>
  1485. <label v-for="opt in krGraphSourceOptions" :key="opt.value" class="kr-checkbox-row">
  1486. <n-checkbox :checked="(selectedData?.graphSourceIds || []).includes(opt.value)"
  1487. @update:checked="() => toggleKrListField('graphSourceIds', opt.value)" />
  1488. <span>{{ opt.label }}</span>
  1489. </label>
  1490. </div>
  1491. </div>
  1492. </template>
  1493. <!-- 混合检索 -->
  1494. <template v-if="selectedData?.source === 'hybrid'">
  1495. <div class="prop-section">
  1496. <label class="prop-label">知识库</label>
  1497. <div v-if="krKnowledgeBasesLoading" class="empty-hint">加载中...</div>
  1498. <n-select :value="selectedData?.knowledgeBaseId" :options="krKnowledgeBaseOptions"
  1499. placeholder="选择知识库" size="small" @update:value="v => onFieldChange('knowledgeBaseId', v)" />
  1500. <div v-if="!krKnowledgeBaseOptions.length && !krKnowledgeBasesLoading" class="empty-hint">暂无知识库
  1501. </div>
  1502. </div>
  1503. </template>
  1504. </template>
  1505. <!-- 条件分支节点 -->
  1506. <template v-if="selectedNode?.type === 'condition'">
  1507. <div class="prop-section">
  1508. <div class="prop-header">
  1509. <span class="prop-label">条件分支</span>
  1510. <button class="text-btn" @click="addElif">+ ELIF</button>
  1511. </div>
  1512. <div v-for="(c, i) in selectedData?.conditions || []" :key="i" class="cond-form">
  1513. <div class="cond-form-row">
  1514. <span class="cond-tag">{{ c.type }}</span>
  1515. <n-input :value="c.expression" placeholder="自然语言条件,可用 {{变量名}}" size="small"
  1516. @update:value="v => onConditionChange(i, 'expression', v)" />
  1517. <button v-if="c.type === 'ELIF'" class="text-btn danger" @click="removeElif(i)">✕</button>
  1518. </div>
  1519. </div>
  1520. </div>
  1521. <div class="prop-section">
  1522. <div class="prop-header">
  1523. <span class="prop-label">前置数据</span>
  1524. <button class="text-btn" @click="addConditionInput">+ 添加</button>
  1525. </div>
  1526. <div v-for="(v, i) in selectedData?.inputs || []" :key="i" class="var-form">
  1527. <div class="var-form-row">
  1528. <n-input :value="v.name" placeholder="变量名" size="small"
  1529. @update:value="nv => { v.name = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1530. <n-select :value="v.type" :options="IO_TYPES" size="small" style="width:100px"
  1531. @update:value="nv => { v.type = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1532. </div>
  1533. <div class="var-form-row">
  1534. <n-input :value="v.label" placeholder="中文名" size="small"
  1535. @update:value="nv => { v.label = nv; onFieldChange('inputs', [...selectedData.inputs]) }" />
  1536. <button class="text-btn danger" @click="removeConditionInput(i)">删除</button>
  1537. </div>
  1538. <div class="var-form-row mapping-row">
  1539. <n-select :value="currentMappingValue(v)"
  1540. :options="[{ label: '自动推断', value: null }, ...inputMappingOptions]" size="small"
  1541. clearable placeholder="关联方式:自动推断"
  1542. @update:value="nv => updateInputMapping(v, nv)" />
  1543. </div>
  1544. </div>
  1545. <div v-if="!selectedData?.inputs?.length" class="empty-hint">连接上游节点后自动推断,或手动添加</div>
  1546. <div class="passthrough-hint">所有前置数据将透传至下游节点</div>
  1547. </div>
  1548. </template>
  1549. <!-- 输出节点 -->
  1550. <template v-if="selectedNode?.type === 'output'">
  1551. <div class="prop-section">
  1552. <div class="prop-header">
  1553. <span class="prop-label">接收字段</span>
  1554. <button class="text-btn" @click="addOutputField">+ 添加</button>
  1555. </div>
  1556. <div v-for="(f, i) in selectedData?.fields || []" :key="i" class="var-form">
  1557. <div class="var-form-row">
  1558. <n-input :value="f.name" placeholder="字段名" size="small"
  1559. @update:value="nv => { f.name = nv; onFieldChange('fields', [...selectedData.fields]) }" />
  1560. <n-select :value="f.type" :options="IO_TYPES" size="small" style="width:100px"
  1561. @update:value="nv => { f.type = nv; onFieldChange('fields', [...selectedData.fields]) }" />
  1562. </div>
  1563. <div class="var-form-row">
  1564. <n-input :value="f.label" placeholder="中文名" size="small"
  1565. @update:value="nv => { f.label = nv; onFieldChange('fields', [...selectedData.fields]) }" />
  1566. <button class="text-btn danger" @click="removeOutputField(i)">删除</button>
  1567. </div>
  1568. </div>
  1569. <div v-if="!selectedData?.fields?.length" class="empty-hint">连接上游节点后自动推断,或手动添加</div>
  1570. </div>
  1571. </template>
  1572. </template>
  1573. <!-- 边映射信息 -->
  1574. <template v-else-if="selectedEdge?.data">
  1575. <div class="prop-section">
  1576. <div class="prop-header">
  1577. <span class="prop-label">连接映射</span>
  1578. <span class="edge-status-badge" :class="'es-' + selectedEdge.data.status">
  1579. {{ edgeStatusText(selectedEdge.data.status) }}
  1580. </span>
  1581. </div>
  1582. <!-- 已映射字段 -->
  1583. <div v-if="selectedEdge.data.mapping?.length" class="mapping-list">
  1584. <div v-for="m in selectedEdge.data.mapping" :key="m.sourceField + '-' + m.targetField"
  1585. class="mapping-item mapped">
  1586. <span class="mapping-field">{{ m.sourceField }}</span>
  1587. <span class="mapping-arrow">→</span>
  1588. <span class="mapping-field">{{ m.targetField }}</span>
  1589. </div>
  1590. </div>
  1591. <!-- 类型不匹配 -->
  1592. <div v-if="selectedEdge.data.typeMismatches?.length" class="mapping-list">
  1593. <div v-for="tm in selectedEdge.data.typeMismatches" :key="tm.source.name"
  1594. class="mapping-item mismatch">
  1595. <span class="mapping-field">{{ tm.source.name }}</span>
  1596. <span class="mapping-type">({{ tm.source.type }})</span>
  1597. <span class="mapping-arrow">→</span>
  1598. <span class="mapping-field">{{ tm.target.name }}</span>
  1599. <span class="mapping-type">({{ tm.target.type }})</span>
  1600. </div>
  1601. </div>
  1602. <!-- 未匹配的目标前置数据 -->
  1603. <div v-if="selectedEdge.data.unmatchedTarget?.length">
  1604. <div class="prop-label" style="margin-top:8px">未匹配前置数据</div>
  1605. <div v-for="f in selectedEdge.data.unmatchedTarget" :key="f.name" class="mapping-item unmapped">
  1606. <span class="mapping-field">{{ f.name }}</span>
  1607. <span class="mapping-type">({{ f.type }})</span>
  1608. </div>
  1609. </div>
  1610. <!-- 多余的源输出 -->
  1611. <div v-if="selectedEdge.data.unmatchedSource?.length">
  1612. <div class="prop-label" style="margin-top:8px">多余输出</div>
  1613. <div v-for="f in selectedEdge.data.unmatchedSource" :key="f.name" class="mapping-item extra">
  1614. <span class="mapping-field">{{ f.name }}</span>
  1615. <span class="mapping-type">({{ f.type }})</span>
  1616. </div>
  1617. </div>
  1618. <div
  1619. v-if="!selectedEdge.data.mapping?.length && !selectedEdge.data.typeMismatches?.length && !(selectedEdge.data.unmatchedTarget?.length) && !(selectedEdge.data.unmatchedSource?.length)"
  1620. class="empty-hint">
  1621. 无需映射
  1622. </div>
  1623. </div>
  1624. </template>
  1625. <div v-else class="empty-props-hint">点击节点或连线查看详情</div>
  1626. </div>
  1627. <!-- 运行结果 Tab -->
  1628. <div v-show="activeTab === 'result'" class="tab-pane">
  1629. <div v-if="nodeResults.length === 0" class="empty-hint">暂无运行结果</div>
  1630. <div v-for="r in nodeResults" :key="r.nodeId" :id="'node-result-' + r.nodeId" class="node-result-card"
  1631. :class="{ highlighted: highlightedNodeId === r.nodeId }" :style="{ borderLeftColor: r.color }">
  1632. <div class="nrc-header" @click="toggleLogs(r.nodeId)" style="cursor: pointer">
  1633. <div class="nrc-icon" :style="{ background: r.color }">
  1634. <n-icon size="12">
  1635. <component :is="nodeTypeInfo[r.type]?.icon" />
  1636. </n-icon>
  1637. </div>
  1638. <div class="nrc-info">
  1639. <span class="nrc-label">{{ r.label }}</span>
  1640. <span class="nrc-type">{{ r.typeLabel }}</span>
  1641. </div>
  1642. <span v-if="r.logs && r.logs.length" class="nrc-log-count">{{ r.logs.length }} 条日志</span>
  1643. <span class="nrc-status" :class="'status-' + r.status">{{ statusText(r.status) }}</span>
  1644. <span v-if="r.logs && r.logs.length" class="nrc-expand"
  1645. :class="{ expanded: expandedLogs[r.nodeId] }">▶</span>
  1646. </div>
  1647. <!-- 流式思考过程(实时累加,节点完成后保留为历史)
  1648. 折叠时仅隐藏 body,streamingThinking 仍持续累加,展开后可继续输出 -->
  1649. <div v-if="r.streamingThinking" class="nrc-thinking" :class="{ live: r.status === 'running' }">
  1650. <div class="nrc-thinking-header" @click="toggleThinking(r.nodeId)" style="cursor: pointer">
  1651. <span class="nrc-thinking-tag">💭 思考过程</span>
  1652. <span v-if="r.status === 'running'" class="nrc-thinking-live">实时输出中…</span>
  1653. <span v-else class="nrc-thinking-static">{{ r.streamingThinking.length }} 字</span>
  1654. <span class="nrc-thinking-expand" :class="{ expanded: expandedThinking[r.nodeId] !== false }">▶</span>
  1655. </div>
  1656. <pre v-show="expandedThinking[r.nodeId] !== false"
  1657. class="nrc-thinking-body">{{ r.streamingThinking }}</pre>
  1658. </div>
  1659. <div class="nrc-vars" v-if="r.output">
  1660. <div class="nrc-var" v-for="(value, key) in r.output" :key="key">
  1661. <span class="nrc-var-key" :style="{ color: r.color }">{{ key }}</span>
  1662. <span class="nrc-var-value">{{ typeof value === 'object' ? JSON.stringify(value, null, 2) :
  1663. String(value)
  1664. }}</span>
  1665. </div>
  1666. </div>
  1667. <!-- 完整上下文快照(节点执行后的全部 variables,debug 视图) -->
  1668. <div v-if="r.contextSnapshot" class="nrc-ctx-toggle" @click="toggleContext(r.nodeId)">
  1669. <span class="nrc-ctx-icon" :class="{ expanded: expandedContext[r.nodeId] }">▶</span>
  1670. <span class="nrc-ctx-label">查看完整上下文({{ Object.keys(r.contextSnapshot).length }} 个变量)</span>
  1671. </div>
  1672. <div v-if="expandedContext[r.nodeId] && r.contextSnapshot" class="nrc-ctx-panel">
  1673. <div class="nrc-ctx-var" v-for="(value, key) in r.contextSnapshot" :key="key">
  1674. <span class="nrc-ctx-key">{{ key }}</span>
  1675. <span class="nrc-ctx-value">{{ formatContextValue(value) }}</span>
  1676. </div>
  1677. </div>
  1678. <!-- 执行日志 -->
  1679. <div v-if="expandedLogs[r.nodeId] && r.logs && r.logs.length" class="nrc-logs">
  1680. <div class="nrc-log" v-for="(log, idx) in r.logs" :key="idx"
  1681. :class="'log-type-' + (log.type || 'info').toLowerCase()">
  1682. <span class="nrc-log-icon">{{ logTypeIcon(log.type) }}</span>
  1683. <span class="nrc-log-time">{{ formatTimestamp(log.timestamp) }}</span>
  1684. <span class="nrc-log-tag">{{ logTypeLabel(log.type) }}</span>
  1685. <span class="nrc-log-msg">{{ log.message }}</span>
  1686. <div v-if="log.detail" class="nrc-log-detail">{{ log.detail }}</div>
  1687. </div>
  1688. </div>
  1689. </div>
  1690. <div v-if="showResult && workflowResult" class="nrc-clear-row">
  1691. <a v-if="lastRunId && lastRunWorkflowId"
  1692. :href="`/api/workflows/${lastRunWorkflowId}/runs/${lastRunId}/download`" class="text-btn"
  1693. style="text-decoration:none; color: var(--primary)">下载工作目录</a>
  1694. <button class="text-btn danger" @click="closeResult">清除结果</button>
  1695. </div>
  1696. </div>
  1697. </div>
  1698. </div>
  1699. </div>
  1700. <!-- 运行对话框 -->
  1701. <div class="dialog-overlay" v-if="showRunDialog" @click.self="cancelRun">
  1702. <div class="run-dialog">
  1703. <div class="dialog-header">
  1704. <span class="dialog-title">运行工作流</span>
  1705. <button class="icon-btn" @click="cancelRun"><n-icon size="16">
  1706. <CloseOutline />
  1707. </n-icon></button>
  1708. </div>
  1709. <div class="dialog-body">
  1710. <div v-if="inputFields.length === 0" class="empty-hint">此工作流无需输入参数</div>
  1711. <div v-for="f in inputFields" :key="f.name" class="run-field">
  1712. <label class="run-field-label">{{ f.label || f.name }}</label>
  1713. <n-input v-model:value="formData[f.name]" :placeholder="f.description || f.name"
  1714. :type="f.type === 'number' ? 'text' : 'text'" size="small" />
  1715. </div>
  1716. <div class="run-upload">
  1717. <label class="run-field-label">上传文件到工作目录</label>
  1718. <div class="upload-btns">
  1719. <div class="upload-area" @click="$refs.fileInput.click()">
  1720. <input ref="fileInput" type="file" multiple style="display:none"
  1721. @change="onFileSelect($event, false)" />
  1722. <span class="upload-hint">选择文件</span>
  1723. </div>
  1724. <div class="upload-area" @click="$refs.dirInput.click()">
  1725. <input ref="dirInput" type="file" webkitdirectory style="display:none"
  1726. @change="onFileSelect($event, true)" />
  1727. <span class="upload-hint">选择目录</span>
  1728. </div>
  1729. </div>
  1730. <div v-if="uploadFiles.length" class="upload-list">
  1731. <div v-for="(f, i) in uploadFiles" :key="i" class="upload-item">
  1732. <span class="upload-name">{{ f.relativePath }}</span>
  1733. <button class="upload-remove" @click="uploadFiles.splice(i, 1)">×</button>
  1734. </div>
  1735. </div>
  1736. </div>
  1737. </div>
  1738. <div class="dialog-footer">
  1739. <button class="cancel-btn" @click="cancelRun">取消</button>
  1740. <button class="primary-btn" @click="handleStartRun">
  1741. <n-icon size="14">
  1742. <PlayOutline />
  1743. </n-icon>
  1744. <span>开始执行</span>
  1745. </button>
  1746. </div>
  1747. </div>
  1748. </div>
  1749. <!-- 操作要求编辑器弹出框 -->
  1750. <div class="dialog-overlay" v-if="showPromptEditor" @click.self="showPromptEditor = false">
  1751. <div class="prompt-editor-dialog">
  1752. <div class="dialog-header">
  1753. <span class="dialog-title">编辑操作要求</span>
  1754. <button class="icon-btn" @click="showPromptEditor = false"><n-icon size="16">
  1755. <CloseOutline />
  1756. </n-icon></button>
  1757. </div>
  1758. <div class="prompt-editor-body">
  1759. <CodeEditor v-model="promptEditValue" language="markdown" height="100%" :minimap="false" />
  1760. </div>
  1761. <div class="dialog-footer">
  1762. <button class="cancel-btn" @click="showPromptEditor = false">取消</button>
  1763. <button class="primary-btn" @click="confirmPromptEdit">确认</button>
  1764. </div>
  1765. </div>
  1766. </div>
  1767. <!-- 版本历史面板 -->
  1768. <transition name="slide-right">
  1769. <div v-if="showVersionPanel" class="version-panel">
  1770. <div class="vp-header">
  1771. <h3 class="vp-title">版本历史</h3>
  1772. <button class="icon-btn" @click="toggleVersionPanelWrap"><n-icon size="16">
  1773. <CloseOutline />
  1774. </n-icon></button>
  1775. </div>
  1776. <div class="vp-list">
  1777. <n-spin v-if="versionsLoading" size="small" />
  1778. <div v-else-if="!versions.length" class="vp-empty">暂无版本(保存后自动创建)</div>
  1779. <div v-else class="version-items">
  1780. <div v-for="v in versions" :key="v.number" class="version-item"
  1781. :class="{ active: selectedVersion?.number === v.number }">
  1782. <div class="vi-main" @click="handleVersionSelectWrap(v)">
  1783. <div class="vi-row">
  1784. <span class="vi-version">v{{ v.number }}<span v-if="v.current" class="vi-current">当前</span></span>
  1785. <span class="vi-time">{{ formatTime(v.createdAt) }}</span>
  1786. </div>
  1787. <div v-if="editingMessage !== v.number" class="vi-message" @dblclick="startEditMessage(v)">
  1788. {{ v.message || '双击编辑备注' }}
  1789. </div>
  1790. <div v-else class="vi-message-edit">
  1791. <n-input v-model:value="editingMessageText" size="tiny" placeholder="版本备注"
  1792. @keyup.enter="saveMessageWrap(v)" @keyup.escape="cancelEditMessage" />
  1793. <n-button size="tiny" type="primary" @click="saveMessageWrap(v)">✓</n-button>
  1794. <n-button size="tiny" @click="cancelEditMessage">✕</n-button>
  1795. </div>
  1796. </div>
  1797. <div class="vi-actions">
  1798. <button v-if="!v.current" class="vi-action-btn rollback-btn" @click.stop="handleRollbackWrap(v)"
  1799. title="回滚到此版本">↩</button>
  1800. </div>
  1801. </div>
  1802. </div>
  1803. </div>
  1804. <div v-if="selectedVersion" class="vp-content">
  1805. <div class="vp-content-header">
  1806. <span>v{{ selectedVersion.number }} 的数据</span>
  1807. </div>
  1808. <pre class="version-json">{{ formatVersionJson(versionContent) }}</pre>
  1809. </div>
  1810. </div>
  1811. </transition>
  1812. <!-- 右键菜单 -->
  1813. <Teleport to="body">
  1814. <div v-if="contextMenu" class="context-menu-overlay" @click="closeContextMenu"
  1815. @contextmenu.prevent="closeContextMenu">
  1816. <div class="context-menu" :style="{ left: contextMenu.x + 'px', top: contextMenu.y + 'px' }">
  1817. <button class="ctx-item ctx-danger" @click="deleteNodeById(contextMenu.nodeId)">
  1818. 删除节点
  1819. </button>
  1820. </div>
  1821. </div>
  1822. </Teleport>
  1823. </div>
  1824. </template>
  1825. <style scoped>
  1826. .workflow-editor {
  1827. height: calc(100vh - var(--header-height));
  1828. display: flex;
  1829. flex-direction: column;
  1830. margin: -28px -32px;
  1831. background: #13111a;
  1832. }
  1833. .editor-toolbar {
  1834. display: flex;
  1835. align-items: center;
  1836. justify-content: space-between;
  1837. padding: 10px 16px;
  1838. background: var(--bg-card, #1a1a2e);
  1839. border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  1840. flex-shrink: 0;
  1841. }
  1842. .toolbar-left,
  1843. .toolbar-right {
  1844. display: flex;
  1845. align-items: center;
  1846. gap: 10px;
  1847. }
  1848. /* 让左侧工具栏占满 toolbar 中间空间,使描述输入框可扩展到版本历史按钮左侧 */
  1849. .toolbar-left {
  1850. flex: 1;
  1851. min-width: 0;
  1852. }
  1853. /* 名称 5 态机提示 */
  1854. .name-status-hint {
  1855. font-size: 11px;
  1856. white-space: nowrap;
  1857. max-width: 220px;
  1858. overflow: hidden;
  1859. text-overflow: ellipsis;
  1860. }
  1861. .name-status-hint .hint-warn {
  1862. color: #e0a526;
  1863. }
  1864. .name-status-hint .hint-error {
  1865. color: #ef4444;
  1866. }
  1867. .name-status-hint .hint-ok {
  1868. color: #22c55e;
  1869. }
  1870. /* 工具栏表单:grid 布局让名称提示跨名称、描述两列延伸到描述字段右边界 */
  1871. .toolbar-form {
  1872. display: grid;
  1873. grid-template-columns: auto auto 1fr;
  1874. column-gap: 14px;
  1875. row-gap: 4px;
  1876. align-items: start;
  1877. flex: 1;
  1878. min-width: 0;
  1879. }
  1880. .wf-field {
  1881. display: flex;
  1882. flex-direction: column;
  1883. gap: 4px;
  1884. min-width: 0;
  1885. }
  1886. /* 让 wf-field 内的 n-input 拉伸到 field 宽度(默认 inline-flex 不会自动占满) */
  1887. .wf-field :deep(.n-input) {
  1888. width: 100%;
  1889. }
  1890. /* 三列定位:展示名称 / 名称 / 描述(描述占满剩余空间) */
  1891. .wf-field-show {
  1892. grid-column: 1;
  1893. grid-row: 1;
  1894. }
  1895. .wf-field-name {
  1896. grid-column: 2;
  1897. grid-row: 1;
  1898. }
  1899. .wf-field.wf-field-grow {
  1900. grid-column: 3;
  1901. grid-row: 1;
  1902. min-width: 0;
  1903. }
  1904. .wf-label {
  1905. font-size: 12px;
  1906. font-weight: 500;
  1907. color: var(--text-secondary, #aaa);
  1908. line-height: 1.2;
  1909. }
  1910. .wf-label .label-hint {
  1911. font-size: 11px;
  1912. font-weight: 400;
  1913. color: var(--text-tertiary, #888);
  1914. }
  1915. .wf-name-hint {
  1916. grid-column: 2 / -1;
  1917. grid-row: 2;
  1918. font-size: 11px;
  1919. min-height: 14px;
  1920. line-height: 1.2;
  1921. white-space: nowrap;
  1922. overflow: hidden;
  1923. text-overflow: ellipsis;
  1924. }
  1925. .wf-name-hint code {
  1926. background: rgba(255, 255, 255, 0.06);
  1927. padding: 1px 5px;
  1928. border-radius: 3px;
  1929. font-family: 'Consolas', 'Monaco', monospace;
  1930. font-size: 10px;
  1931. }
  1932. .wf-name-hint .hint-warn {
  1933. color: #e0a526;
  1934. }
  1935. .wf-name-hint .hint-error {
  1936. color: #ef4444;
  1937. }
  1938. .wf-name-hint .hint-ok {
  1939. color: #22c55e;
  1940. }
  1941. .editor-body {
  1942. flex: 1;
  1943. display: flex;
  1944. overflow: hidden;
  1945. }
  1946. /* 左侧节点栏 */
  1947. .sidebar-nodes {
  1948. width: 180px;
  1949. background: var(--bg-card, #1a1a2e);
  1950. border-right: 1px solid rgba(255, 255, 255, 0.08);
  1951. padding: 12px;
  1952. display: flex;
  1953. flex-direction: column;
  1954. gap: 6px;
  1955. flex-shrink: 0;
  1956. }
  1957. .sidebar-title {
  1958. font-size: 12px;
  1959. font-weight: 600;
  1960. color: var(--text-secondary, #999);
  1961. text-transform: uppercase;
  1962. letter-spacing: 1px;
  1963. margin-bottom: 6px;
  1964. }
  1965. .node-type-item {
  1966. display: flex;
  1967. align-items: center;
  1968. gap: 8px;
  1969. padding: 8px 10px;
  1970. border-radius: 8px;
  1971. cursor: grab;
  1972. transition: background 0.15s;
  1973. border: 1px solid rgba(255, 255, 255, 0.06);
  1974. }
  1975. .node-type-item:hover {
  1976. background: rgba(255, 255, 255, 0.06);
  1977. }
  1978. .node-type-item:active {
  1979. cursor: grabbing;
  1980. }
  1981. .nt-icon {
  1982. width: 28px;
  1983. height: 28px;
  1984. display: flex;
  1985. align-items: center;
  1986. justify-content: center;
  1987. border-radius: 6px;
  1988. color: #fff;
  1989. flex-shrink: 0;
  1990. }
  1991. .nt-label {
  1992. font-size: 13px;
  1993. color: var(--text-primary, #e0e0e0);
  1994. }
  1995. /* 中间画布 */
  1996. .canvas-area {
  1997. flex: 1;
  1998. background: #0f0d17;
  1999. }
  2000. /* 覆盖 VueFlow 默认主题的节点白色背景 */
  2001. .canvas-area :deep(.vue-flow__node) {
  2002. background: transparent !important;
  2003. padding: 0 !important;
  2004. border: none !important;
  2005. box-shadow: none !important;
  2006. }
  2007. /* 选中连接线高亮 - stroke 必须作用于 path 子元素 */
  2008. .canvas-area :deep(.vue-flow__edge.selected .vue-flow__edge-path) {
  2009. stroke: #facc15 !important;
  2010. stroke-width: 3 !important;
  2011. }
  2012. .canvas-area :deep(.vue-flow__edge:hover .vue-flow__edge-path) {
  2013. stroke: #facc15 !important;
  2014. }
  2015. .canvas-area :deep(.vue-flow__edge) {
  2016. cursor: pointer;
  2017. }
  2018. /* 右侧面板 - Tab 页 */
  2019. .sidebar-right {
  2020. width: 300px;
  2021. background: var(--bg-card, #1a1a2e);
  2022. border-left: 1px solid rgba(255, 255, 255, 0.08);
  2023. display: flex;
  2024. flex-direction: column;
  2025. flex-shrink: 0;
  2026. overflow: hidden;
  2027. }
  2028. .sidebar-tabs {
  2029. display: flex;
  2030. border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  2031. flex-shrink: 0;
  2032. }
  2033. .tab-btn {
  2034. flex: 1;
  2035. padding: 10px 0;
  2036. border: none;
  2037. background: transparent;
  2038. color: var(--text-secondary, #999);
  2039. font-size: 13px;
  2040. cursor: pointer;
  2041. transition: all 0.15s;
  2042. position: relative;
  2043. display: flex;
  2044. align-items: center;
  2045. justify-content: center;
  2046. gap: 4px;
  2047. }
  2048. .tab-btn:hover {
  2049. color: var(--text-primary, #e0e0e0);
  2050. }
  2051. .tab-btn.active {
  2052. color: var(--text-primary, #e0e0e0);
  2053. font-weight: 600;
  2054. }
  2055. .tab-btn.active::after {
  2056. content: '';
  2057. position: absolute;
  2058. bottom: 0;
  2059. left: 20%;
  2060. right: 20%;
  2061. height: 2px;
  2062. background: var(--color-primary, #2563EB);
  2063. border-radius: 1px;
  2064. }
  2065. .result-badge {
  2066. display: inline-flex;
  2067. align-items: center;
  2068. justify-content: center;
  2069. min-width: 16px;
  2070. height: 16px;
  2071. padding: 0 4px;
  2072. border-radius: 8px;
  2073. background: var(--color-primary, #2563EB);
  2074. color: #fff;
  2075. font-size: 10px;
  2076. font-weight: 600;
  2077. }
  2078. .sidebar-tab-content {
  2079. flex: 1;
  2080. overflow-y: auto;
  2081. }
  2082. .tab-pane {
  2083. padding: 12px;
  2084. }
  2085. .empty-props-hint {
  2086. color: var(--text-tertiary, #555);
  2087. font-size: 13px;
  2088. text-align: center;
  2089. padding: 40px 0;
  2090. }
  2091. /* 节点结果卡片 */
  2092. .node-result-card {
  2093. background: rgba(255, 255, 255, 0.03);
  2094. border-radius: 8px;
  2095. border-left: 3px solid #666;
  2096. margin-bottom: 10px;
  2097. overflow: hidden;
  2098. transition: background 0.3s, box-shadow 0.3s;
  2099. }
  2100. .node-result-card.highlighted {
  2101. animation: highlight-pulse 2s ease;
  2102. }
  2103. @keyframes highlight-pulse {
  2104. 0% {
  2105. background: rgba(129, 140, 248, 0.18);
  2106. box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.45);
  2107. }
  2108. 70% {
  2109. background: rgba(129, 140, 248, 0.08);
  2110. box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.2);
  2111. }
  2112. 100% {
  2113. background: rgba(255, 255, 255, 0.03);
  2114. box-shadow: none;
  2115. }
  2116. }
  2117. .nrc-header {
  2118. display: flex;
  2119. align-items: center;
  2120. gap: 8px;
  2121. padding: 8px 10px;
  2122. border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  2123. }
  2124. .nrc-icon {
  2125. width: 22px;
  2126. height: 22px;
  2127. display: flex;
  2128. align-items: center;
  2129. justify-content: center;
  2130. border-radius: 5px;
  2131. color: #fff;
  2132. flex-shrink: 0;
  2133. }
  2134. .nrc-info {
  2135. flex: 1;
  2136. min-width: 0;
  2137. display: flex;
  2138. flex-direction: column;
  2139. gap: 1px;
  2140. }
  2141. .nrc-label {
  2142. font-size: 12px;
  2143. font-weight: 600;
  2144. color: var(--text-primary, #e0e0e0);
  2145. white-space: nowrap;
  2146. overflow: hidden;
  2147. text-overflow: ellipsis;
  2148. }
  2149. .nrc-type {
  2150. font-size: 10px;
  2151. color: var(--text-tertiary, #666);
  2152. }
  2153. .nrc-status {
  2154. font-size: 10px;
  2155. padding: 2px 6px;
  2156. border-radius: 4px;
  2157. font-weight: 600;
  2158. flex-shrink: 0;
  2159. }
  2160. .nrc-status.status-running {
  2161. background: rgba(99, 102, 241, 0.15);
  2162. color: #818cf8;
  2163. }
  2164. .nrc-status.status-success {
  2165. background: rgba(16, 185, 129, 0.15);
  2166. color: #34d399;
  2167. }
  2168. .nrc-status.status-failed {
  2169. background: rgba(239, 68, 68, 0.15);
  2170. color: #f87171;
  2171. }
  2172. .nrc-status.status-skipped {
  2173. background: rgba(107, 114, 128, 0.15);
  2174. color: #9ca3af;
  2175. }
  2176. .nrc-status.status-no_run {
  2177. background: rgba(107, 114, 128, 0.10);
  2178. color: #6b7280;
  2179. }
  2180. .nrc-vars {
  2181. padding: 6px 10px;
  2182. }
  2183. /* 流式思考过程区块 */
  2184. .nrc-thinking {
  2185. margin: 6px 10px;
  2186. border-radius: 6px;
  2187. background: rgba(168, 85, 247, 0.05);
  2188. border: 1px solid rgba(168, 85, 247, 0.2);
  2189. overflow: hidden;
  2190. }
  2191. .nrc-thinking.live {
  2192. border-color: rgba(168, 85, 247, 0.5);
  2193. box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.15);
  2194. }
  2195. .nrc-thinking-header {
  2196. display: flex;
  2197. align-items: center;
  2198. gap: 8px;
  2199. padding: 5px 10px;
  2200. font-size: 11px;
  2201. background: rgba(168, 85, 247, 0.08);
  2202. }
  2203. .nrc-thinking-tag {
  2204. color: #c084fc;
  2205. font-weight: 600;
  2206. }
  2207. .nrc-thinking-live {
  2208. color: #ec4899;
  2209. font-size: 10px;
  2210. animation: nrc-pulse 1.2s ease-in-out infinite;
  2211. }
  2212. .nrc-thinking-static {
  2213. color: #888;
  2214. font-size: 10px;
  2215. }
  2216. .nrc-thinking-expand {
  2217. margin-left: auto;
  2218. font-size: 10px;
  2219. color: var(--text-tertiary, #666);
  2220. transition: transform 0.2s;
  2221. flex-shrink: 0;
  2222. }
  2223. .nrc-thinking-expand.expanded {
  2224. transform: rotate(90deg);
  2225. }
  2226. .nrc-thinking-body {
  2227. margin: 0;
  2228. padding: 8px 12px;
  2229. max-height: 320px;
  2230. overflow: auto;
  2231. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;
  2232. font-size: 11px;
  2233. line-height: 1.6;
  2234. color: var(--text-secondary, #b0b0b0);
  2235. white-space: pre-wrap;
  2236. word-break: break-word;
  2237. }
  2238. @keyframes nrc-pulse {
  2239. 0%,
  2240. 100% {
  2241. opacity: 0.55;
  2242. }
  2243. 50% {
  2244. opacity: 1;
  2245. }
  2246. }
  2247. .nrc-var {
  2248. display: flex;
  2249. flex-direction: column;
  2250. gap: 2px;
  2251. padding: 4px 0;
  2252. border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  2253. }
  2254. .nrc-var:last-child {
  2255. border-bottom: none;
  2256. }
  2257. .nrc-var-key {
  2258. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
  2259. font-size: 11px;
  2260. font-weight: 600;
  2261. }
  2262. .nrc-var-value {
  2263. font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
  2264. font-size: 11px;
  2265. color: var(--text-secondary, #aaa);
  2266. white-space: pre-wrap;
  2267. word-break: break-all;
  2268. max-height: 120px;
  2269. overflow-y: auto;
  2270. }
  2271. /* 完整上下文快照折叠区(debug 视图) */
  2272. .nrc-ctx-toggle {
  2273. display: flex;
  2274. align-items: center;
  2275. gap: 6px;
  2276. padding: 6px 10px;
  2277. cursor: pointer;
  2278. border-top: 1px solid rgba(255, 255, 255, 0.04);
  2279. font-size: 11px;
  2280. color: var(--text-secondary, #aaa);
  2281. user-select: none;
  2282. }
  2283. .nrc-ctx-toggle:hover {
  2284. background: rgba(99, 102, 241, 0.05);
  2285. }
  2286. .nrc-ctx-icon {
  2287. font-size: 9px;
  2288. color: var(--text-tertiary, #888);
  2289. transition: transform 0.2s;
  2290. }
  2291. .nrc-ctx-icon.expanded {
  2292. transform: rotate(90deg);
  2293. }
  2294. .nrc-ctx-label {
  2295. font-weight: 500;
  2296. }
  2297. .nrc-ctx-panel {
  2298. padding: 6px 10px;
  2299. border-top: 1px solid rgba(255, 255, 255, 0.04);
  2300. max-height: 280px;
  2301. overflow-y: auto;
  2302. background: rgba(0, 0, 0, 0.15);
  2303. }
  2304. .nrc-ctx-var {
  2305. display: flex;
  2306. flex-direction: column;
  2307. gap: 2px;
  2308. padding: 4px 0;
  2309. border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  2310. }
  2311. .nrc-ctx-var:last-child {
  2312. border-bottom: none;
  2313. }
  2314. .nrc-ctx-key {
  2315. font-family: 'Cascadia Code', 'Fira Code', monospace;
  2316. font-size: 11px;
  2317. font-weight: 600;
  2318. color: #818cf8;
  2319. }
  2320. .nrc-ctx-value {
  2321. font-family: 'Cascadia Code', 'Fira Code', monospace;
  2322. font-size: 11px;
  2323. color: var(--text-secondary, #ccc);
  2324. white-space: pre-wrap;
  2325. word-break: break-all;
  2326. max-height: 80px;
  2327. overflow-y: auto;
  2328. }
  2329. .nrc-clear-row {
  2330. text-align: center;
  2331. padding: 10px 0 4px;
  2332. border-top: 1px solid rgba(255, 255, 255, 0.06);
  2333. margin-top: 8px;
  2334. }
  2335. .nrc-log-count {
  2336. font-size: 10px;
  2337. padding: 2px 6px;
  2338. border-radius: 4px;
  2339. background: rgba(99, 102, 241, 0.1);
  2340. color: #818cf8;
  2341. flex-shrink: 0;
  2342. }
  2343. .nrc-expand {
  2344. font-size: 10px;
  2345. color: var(--text-tertiary, #666);
  2346. transition: transform 0.2s;
  2347. flex-shrink: 0;
  2348. }
  2349. .nrc-expand.expanded {
  2350. transform: rotate(90deg);
  2351. }
  2352. .nrc-logs {
  2353. border-top: 1px solid rgba(255, 255, 255, 0.04);
  2354. padding: 6px 10px;
  2355. max-height: 400px;
  2356. overflow-y: auto;
  2357. }
  2358. .nrc-log {
  2359. padding: 4px 0;
  2360. border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  2361. font-size: 11px;
  2362. line-height: 1.5;
  2363. }
  2364. .nrc-log:last-child {
  2365. border-bottom: none;
  2366. }
  2367. .nrc-log-icon {
  2368. margin-right: 4px;
  2369. }
  2370. .nrc-log-time {
  2371. font-family: 'Cascadia Code', 'Fira Code', monospace;
  2372. font-size: 10px;
  2373. color: var(--text-tertiary, #555);
  2374. margin-right: 6px;
  2375. }
  2376. .nrc-log-tag {
  2377. font-size: 10px;
  2378. padding: 1px 4px;
  2379. border-radius: 3px;
  2380. margin-right: 6px;
  2381. font-weight: 600;
  2382. flex-shrink: 0;
  2383. }
  2384. .log-type-tool_call .nrc-log-tag {
  2385. background: rgba(59, 130, 246, 0.15);
  2386. color: #60a5fa;
  2387. }
  2388. .log-type-tool_result .nrc-log-tag {
  2389. background: rgba(16, 185, 129, 0.15);
  2390. color: #34d399;
  2391. }
  2392. .log-type-thinking .nrc-log-tag {
  2393. background: rgba(168, 85, 247, 0.15);
  2394. color: #c084fc;
  2395. }
  2396. .log-type-error .nrc-log-tag {
  2397. background: rgba(239, 68, 68, 0.15);
  2398. color: #f87171;
  2399. }
  2400. .log-type-info .nrc-log-tag {
  2401. background: rgba(107, 114, 128, 0.15);
  2402. color: #9ca3af;
  2403. }
  2404. .nrc-log-msg {
  2405. color: var(--text-secondary, #ccc);
  2406. word-break: break-all;
  2407. }
  2408. .nrc-log-detail {
  2409. margin-top: 3px;
  2410. margin-left: 22px;
  2411. font-family: 'Cascadia Code', 'Fira Code', monospace;
  2412. font-size: 10px;
  2413. color: var(--text-tertiary, #888);
  2414. background: rgba(0, 0, 0, 0.2);
  2415. padding: 4px 6px;
  2416. border-radius: 4px;
  2417. white-space: pre-wrap;
  2418. word-break: break-all;
  2419. max-height: 100px;
  2420. overflow-y: auto;
  2421. }
  2422. .prop-section {
  2423. margin-bottom: 14px;
  2424. }
  2425. .prop-header {
  2426. display: flex;
  2427. align-items: center;
  2428. justify-content: space-between;
  2429. margin-bottom: 6px;
  2430. }
  2431. .prop-label {
  2432. display: block;
  2433. font-size: 12px;
  2434. font-weight: 500;
  2435. color: var(--text-secondary, #999);
  2436. margin-bottom: 6px;
  2437. }
  2438. .var-form {
  2439. background: rgba(255, 255, 255, 0.03);
  2440. border-radius: 6px;
  2441. padding: 8px;
  2442. margin-bottom: 8px;
  2443. }
  2444. .var-form-row {
  2445. display: flex;
  2446. gap: 6px;
  2447. margin-bottom: 6px;
  2448. }
  2449. /* 关联方式行:作为前置数据的一个属性,紧跟字段定义 */
  2450. .var-form-row.mapping-row {
  2451. margin-top: 2px;
  2452. padding-top: 6px;
  2453. border-top: 1px dashed rgba(255, 255, 255, 0.06);
  2454. }
  2455. .cond-form {
  2456. margin-bottom: 8px;
  2457. }
  2458. .cond-form-row {
  2459. display: flex;
  2460. align-items: center;
  2461. gap: 6px;
  2462. }
  2463. .cond-tag {
  2464. font-size: 11px;
  2465. padding: 2px 8px;
  2466. border-radius: 4px;
  2467. background: rgba(249, 115, 22, 0.15);
  2468. color: #F97316;
  2469. flex-shrink: 0;
  2470. font-weight: 600;
  2471. }
  2472. .text-btn {
  2473. background: none;
  2474. border: none;
  2475. color: var(--color-accent, #2563EB);
  2476. font-size: 12px;
  2477. cursor: pointer;
  2478. padding: 2px 4px;
  2479. }
  2480. .text-btn:hover {
  2481. text-decoration: underline;
  2482. }
  2483. .text-btn.danger {
  2484. color: #EF4444;
  2485. }
  2486. .empty-hint {
  2487. font-size: 12px;
  2488. color: var(--text-tertiary, #555);
  2489. font-style: italic;
  2490. }
  2491. .kr-checkbox-row {
  2492. display: flex;
  2493. align-items: center;
  2494. gap: 6px;
  2495. font-size: 12px;
  2496. cursor: pointer;
  2497. margin-bottom: 4px;
  2498. }
  2499. .kr-list {
  2500. margin-top: 6px;
  2501. max-height: 240px;
  2502. overflow-y: auto;
  2503. padding-right: 4px;
  2504. }
  2505. .passthrough-hint {
  2506. font-size: 11px;
  2507. color: var(--text-tertiary, #555);
  2508. margin-top: 6px;
  2509. padding: 4px 8px;
  2510. background: rgba(249, 115, 22, 0.08);
  2511. border-radius: 4px;
  2512. color: #fb923c;
  2513. }
  2514. /* 通用按钮 */
  2515. .icon-btn {
  2516. width: 32px;
  2517. height: 32px;
  2518. display: flex;
  2519. align-items: center;
  2520. justify-content: center;
  2521. border-radius: 6px;
  2522. border: 1px solid rgba(255, 255, 255, 0.12);
  2523. background: transparent;
  2524. color: var(--text-secondary, #999);
  2525. cursor: pointer;
  2526. transition: all 0.15s;
  2527. }
  2528. .icon-btn:hover {
  2529. background: rgba(255, 255, 255, 0.08);
  2530. color: #fff;
  2531. }
  2532. .primary-btn {
  2533. display: flex;
  2534. align-items: center;
  2535. gap: 6px;
  2536. padding: 7px 16px;
  2537. background: var(--color-primary, #2563EB);
  2538. color: #fff;
  2539. border: none;
  2540. border-radius: 6px;
  2541. font-size: 13px;
  2542. cursor: pointer;
  2543. transition: all 0.15s;
  2544. }
  2545. .primary-btn:hover {
  2546. filter: brightness(1.15);
  2547. }
  2548. .primary-btn:disabled {
  2549. opacity: 0.5;
  2550. cursor: not-allowed;
  2551. }
  2552. /* 自动关联按钮 */
  2553. .associate-btn {
  2554. display: flex;
  2555. align-items: center;
  2556. gap: 6px;
  2557. padding: 7px 16px;
  2558. background: rgba(129, 140, 248, 0.12);
  2559. color: #818cf8;
  2560. border: 1px solid rgba(129, 140, 248, 0.25);
  2561. border-radius: 6px;
  2562. font-size: 13px;
  2563. cursor: pointer;
  2564. transition: all 0.15s;
  2565. }
  2566. .associate-btn:hover {
  2567. background: rgba(129, 140, 248, 0.2);
  2568. border-color: rgba(129, 140, 248, 0.4);
  2569. }
  2570. .associate-btn:disabled {
  2571. opacity: 0.5;
  2572. cursor: not-allowed;
  2573. }
  2574. .associate-btn.active {
  2575. background: rgba(129, 140, 248, 0.18);
  2576. border-color: rgba(129, 140, 248, 0.35);
  2577. }
  2578. .clear-assoc-btn {
  2579. display: flex;
  2580. align-items: center;
  2581. justify-content: center;
  2582. width: 30px;
  2583. height: 30px;
  2584. background: transparent;
  2585. color: var(--text-tertiary);
  2586. border: 1px solid var(--border-color);
  2587. border-radius: 6px;
  2588. cursor: pointer;
  2589. transition: all 0.15s;
  2590. }
  2591. .clear-assoc-btn:hover {
  2592. color: #f87171;
  2593. border-color: rgba(239, 68, 68, 0.3);
  2594. background: rgba(239, 68, 68, 0.08);
  2595. }
  2596. /* 虚拟节点(自动关联产生的技能节点) */
  2597. .canvas-area :deep(.vue-flow__node.virtual-node) {
  2598. opacity: 0.75;
  2599. pointer-events: none;
  2600. }
  2601. .canvas-area :deep(.vue-flow__node.virtual-node .base-node) {
  2602. /* 内容也穿透:鼠标按下技能节点时事件落到下层虚框,由父节点接管拖拽实现整体移动 */
  2603. pointer-events: none;
  2604. border-style: dashed !important;
  2605. border-color: #818cf8 !important;
  2606. background: rgba(129, 140, 248, 0.06) !important;
  2607. }
  2608. .canvas-area :deep(.vue-flow__node.virtual-node .base-node:hover) {
  2609. border-color: #a5b4fc !important;
  2610. }
  2611. /* 虚线分组容器节点:必须保留 pointer-events 以接收拖动事件实现整体拖动 */
  2612. .canvas-area :deep(.vue-flow__node.virtual-group-node) {
  2613. pointer-events: all !important;
  2614. }
  2615. .canvas-area :deep(.vue-flow__node.virtual-group-node .vue-flow__handle) {
  2616. pointer-events: none !important;
  2617. opacity: 0 !important;
  2618. width: 1px !important;
  2619. height: 1px !important;
  2620. min-width: 1px !important;
  2621. min-height: 1px !important;
  2622. background: transparent !important;
  2623. border: none !important;
  2624. }
  2625. /* 虚线分组边 */
  2626. .canvas-area :deep(.vue-flow__edge.virtual-group-edge .vue-flow__edge-path) {
  2627. stroke: #818cf8;
  2628. stroke-width: 1.5;
  2629. stroke-dasharray: 5 4;
  2630. opacity: 0.7;
  2631. }
  2632. /* 运行按钮 */
  2633. .run-btn {
  2634. display: flex;
  2635. align-items: center;
  2636. gap: 6px;
  2637. padding: 7px 16px;
  2638. background: #10B981;
  2639. color: #fff;
  2640. border: none;
  2641. border-radius: 6px;
  2642. font-size: 13px;
  2643. cursor: pointer;
  2644. transition: all 0.15s;
  2645. }
  2646. .run-btn:hover {
  2647. filter: brightness(1.15);
  2648. }
  2649. .run-btn:disabled {
  2650. opacity: 0.5;
  2651. cursor: not-allowed;
  2652. }
  2653. .run-btn.is-running {
  2654. background: #6366f1;
  2655. animation: pulse-btn 1.5s infinite;
  2656. }
  2657. @keyframes pulse-btn {
  2658. 0%,
  2659. 100% {
  2660. opacity: 1;
  2661. }
  2662. 50% {
  2663. opacity: 0.7;
  2664. }
  2665. }
  2666. /* 节点执行状态 */
  2667. .canvas-area :deep(.vue-flow__node.node-status-running) {
  2668. animation: node-pulse 1.5s infinite;
  2669. }
  2670. .canvas-area :deep(.vue-flow__node.node-status-success) {
  2671. filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.5));
  2672. }
  2673. .canvas-area :deep(.vue-flow__node.node-status-failed) {
  2674. filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.6));
  2675. }
  2676. .canvas-area :deep(.vue-flow__node.node-status-skipped) {
  2677. opacity: 0.4;
  2678. }
  2679. @keyframes node-pulse {
  2680. 0%,
  2681. 100% {
  2682. filter: drop-shadow(0 0 6px rgba(37, 99, 235, 0.5));
  2683. }
  2684. 50% {
  2685. filter: drop-shadow(0 0 16px rgba(37, 99, 235, 0.9));
  2686. }
  2687. }
  2688. /* 运行对话框 */
  2689. .dialog-overlay {
  2690. position: fixed;
  2691. inset: 0;
  2692. background: rgba(0, 0, 0, 0.75);
  2693. display: flex;
  2694. align-items: center;
  2695. justify-content: center;
  2696. z-index: 100;
  2697. }
  2698. .run-dialog {
  2699. background: var(--bg-card, #1a1a2e);
  2700. border-radius: 12px;
  2701. width: 400px;
  2702. max-height: 80vh;
  2703. display: flex;
  2704. flex-direction: column;
  2705. border: 1px solid rgba(255, 255, 255, 0.1);
  2706. }
  2707. .prompt-editor-dialog {
  2708. background: var(--bg-card, #1a1a2e);
  2709. border-radius: 12px;
  2710. width: 80vw;
  2711. max-width: 960px;
  2712. height: 75vh;
  2713. display: flex;
  2714. flex-direction: column;
  2715. border: 1px solid rgba(255, 255, 255, 0.1);
  2716. }
  2717. .prompt-editor-body {
  2718. flex: 1;
  2719. min-height: 0;
  2720. overflow: hidden;
  2721. }
  2722. .dialog-header {
  2723. display: flex;
  2724. align-items: center;
  2725. justify-content: space-between;
  2726. padding: 14px 18px;
  2727. border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  2728. }
  2729. .dialog-title {
  2730. font-size: 15px;
  2731. font-weight: 600;
  2732. color: var(--text-primary, #e0e0e0);
  2733. }
  2734. .dialog-body {
  2735. padding: 16px 18px;
  2736. overflow-y: auto;
  2737. flex: 1;
  2738. }
  2739. .dialog-footer {
  2740. display: flex;
  2741. justify-content: flex-end;
  2742. gap: 10px;
  2743. padding: 12px 18px;
  2744. border-top: 1px solid rgba(255, 255, 255, 0.08);
  2745. }
  2746. .cancel-btn {
  2747. padding: 7px 16px;
  2748. border: 1px solid rgba(255, 255, 255, 0.15);
  2749. background: transparent;
  2750. color: var(--text-secondary, #999);
  2751. border-radius: 6px;
  2752. cursor: pointer;
  2753. font-size: 13px;
  2754. }
  2755. .cancel-btn:hover {
  2756. background: rgba(255, 255, 255, 0.06);
  2757. }
  2758. .run-field {
  2759. margin-bottom: 12px;
  2760. }
  2761. .run-field-label {
  2762. display: block;
  2763. font-size: 12px;
  2764. color: var(--text-secondary, #999);
  2765. margin-bottom: 4px;
  2766. }
  2767. /* 文件上传区域 */
  2768. .run-upload {
  2769. margin-top: 16px;
  2770. }
  2771. .upload-btns {
  2772. display: flex;
  2773. gap: 8px;
  2774. }
  2775. .upload-area {
  2776. flex: 1;
  2777. border: 1px dashed rgba(255, 255, 255, 0.2);
  2778. border-radius: 6px;
  2779. padding: 12px;
  2780. text-align: center;
  2781. cursor: pointer;
  2782. transition: border-color 0.2s;
  2783. }
  2784. .upload-area:hover {
  2785. border-color: var(--primary);
  2786. }
  2787. .upload-hint {
  2788. font-size: 12px;
  2789. color: var(--text-secondary, #999);
  2790. }
  2791. .upload-list {
  2792. margin-top: 8px;
  2793. }
  2794. .upload-item {
  2795. display: flex;
  2796. align-items: center;
  2797. justify-content: space-between;
  2798. padding: 4px 8px;
  2799. font-size: 12px;
  2800. color: var(--text-primary, #eee);
  2801. background: rgba(255, 255, 255, 0.05);
  2802. border-radius: 4px;
  2803. margin-bottom: 4px;
  2804. }
  2805. .upload-name {
  2806. flex: 1;
  2807. overflow: hidden;
  2808. text-overflow: ellipsis;
  2809. white-space: nowrap;
  2810. }
  2811. .upload-remove {
  2812. background: none;
  2813. border: none;
  2814. color: var(--text-secondary, #999);
  2815. cursor: pointer;
  2816. font-size: 16px;
  2817. padding: 0 4px;
  2818. line-height: 1;
  2819. }
  2820. .upload-remove:hover {
  2821. color: #f87171;
  2822. }
  2823. /* 边映射状态 */
  2824. .edge-status-badge {
  2825. font-size: 11px;
  2826. padding: 2px 8px;
  2827. border-radius: 4px;
  2828. font-weight: 600;
  2829. }
  2830. .edge-status-badge.es-ok {
  2831. background: rgba(34, 197, 94, 0.15);
  2832. color: #4ade80;
  2833. }
  2834. .edge-status-badge.es-unmapped {
  2835. background: rgba(107, 114, 128, 0.15);
  2836. color: #9ca3af;
  2837. }
  2838. .edge-status-badge.es-partial {
  2839. background: rgba(245, 158, 11, 0.15);
  2840. color: #fbbf24;
  2841. }
  2842. .edge-status-badge.es-mismatch {
  2843. background: rgba(239, 68, 68, 0.15);
  2844. color: #f87171;
  2845. }
  2846. .mapping-list {
  2847. margin-top: 6px;
  2848. }
  2849. .mapping-item {
  2850. display: flex;
  2851. align-items: center;
  2852. gap: 4px;
  2853. padding: 4px 8px;
  2854. border-radius: 4px;
  2855. margin-bottom: 3px;
  2856. font-size: 12px;
  2857. font-family: 'Cascadia Code', 'Fira Code', monospace;
  2858. }
  2859. .mapping-item.mapped {
  2860. background: rgba(34, 197, 94, 0.08);
  2861. }
  2862. .mapping-item.mismatch {
  2863. background: rgba(239, 68, 68, 0.08);
  2864. }
  2865. .mapping-item.unmapped {
  2866. background: rgba(245, 158, 11, 0.08);
  2867. }
  2868. .mapping-item.extra {
  2869. background: rgba(107, 114, 128, 0.06);
  2870. }
  2871. .mapping-field {
  2872. color: var(--text-primary, #e0e0e0);
  2873. font-weight: 500;
  2874. }
  2875. .mapping-arrow {
  2876. color: var(--text-tertiary, #666);
  2877. }
  2878. .mapping-type {
  2879. color: var(--text-tertiary, #666);
  2880. font-size: 10px;
  2881. }
  2882. /* 右键菜单 */
  2883. .context-menu-overlay {
  2884. position: fixed;
  2885. inset: 0;
  2886. z-index: 200;
  2887. }
  2888. .context-menu {
  2889. position: fixed;
  2890. background: #1e1b2e;
  2891. border: 1px solid rgba(255, 255, 255, 0.12);
  2892. border-radius: 8px;
  2893. padding: 4px;
  2894. min-width: 140px;
  2895. box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  2896. }
  2897. .ctx-item {
  2898. display: flex;
  2899. align-items: center;
  2900. gap: 8px;
  2901. width: 100%;
  2902. padding: 8px 12px;
  2903. border: none;
  2904. border-radius: 6px;
  2905. background: transparent;
  2906. color: var(--text-primary, #e0e0e0);
  2907. font-size: 13px;
  2908. cursor: pointer;
  2909. transition: background 0.12s;
  2910. text-align: left;
  2911. }
  2912. .ctx-item:hover {
  2913. background: rgba(255, 255, 255, 0.08);
  2914. }
  2915. .ctx-item.ctx-danger {
  2916. color: #f87171;
  2917. }
  2918. .ctx-item.ctx-danger:hover {
  2919. background: rgba(239, 68, 68, 0.15);
  2920. }
  2921. /* 版本历史面板 */
  2922. .version-panel {
  2923. position: fixed;
  2924. right: 0;
  2925. top: 0;
  2926. bottom: 0;
  2927. width: 380px;
  2928. background: var(--bg-secondary, #fff);
  2929. border-left: 1px solid var(--border-color, #e5e7eb);
  2930. display: flex;
  2931. flex-direction: column;
  2932. z-index: 100;
  2933. box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
  2934. }
  2935. .version-panel .vp-header {
  2936. display: flex;
  2937. align-items: center;
  2938. justify-content: space-between;
  2939. padding: 12px 16px;
  2940. border-bottom: 1px solid var(--border-color, #e5e7eb);
  2941. }
  2942. .version-panel .vp-title {
  2943. font-size: 15px;
  2944. font-weight: 600;
  2945. margin: 0;
  2946. }
  2947. .version-panel .vp-list {
  2948. max-height: 300px;
  2949. overflow-y: auto;
  2950. padding: 8px;
  2951. }
  2952. .version-panel .vp-empty {
  2953. text-align: center;
  2954. color: var(--text-tertiary, #999);
  2955. padding: 24px 0;
  2956. font-size: 13px;
  2957. }
  2958. .version-panel .version-items {
  2959. display: flex;
  2960. flex-direction: column;
  2961. gap: 4px;
  2962. }
  2963. .version-panel .version-item {
  2964. display: flex;
  2965. align-items: stretch;
  2966. border-radius: 6px;
  2967. border: 1px solid transparent;
  2968. cursor: pointer;
  2969. transition: all 0.15s;
  2970. }
  2971. .version-panel .version-item:hover {
  2972. background: rgba(37, 99, 235, 0.06);
  2973. }
  2974. .version-panel .version-item.active {
  2975. background: rgba(37, 99, 235, 0.1);
  2976. border-color: rgba(37, 99, 235, 0.3);
  2977. }
  2978. .version-panel .vi-main {
  2979. flex: 1;
  2980. padding: 8px 10px;
  2981. min-width: 0;
  2982. }
  2983. .version-panel .vi-row {
  2984. display: flex;
  2985. align-items: center;
  2986. justify-content: space-between;
  2987. gap: 8px;
  2988. }
  2989. .version-panel .vi-version {
  2990. font-size: 13px;
  2991. font-weight: 600;
  2992. color: var(--color-accent, #2563eb);
  2993. }
  2994. .version-panel .vi-current {
  2995. font-size: 10px;
  2996. font-weight: 500;
  2997. background: rgba(34, 197, 94, 0.15);
  2998. color: #22c55e;
  2999. padding: 0 4px;
  3000. border-radius: 3px;
  3001. margin-left: 4px;
  3002. vertical-align: middle;
  3003. }
  3004. .version-panel .vi-time {
  3005. font-size: 11px;
  3006. color: var(--text-tertiary, #999);
  3007. }
  3008. .version-panel .vi-message {
  3009. font-size: 12px;
  3010. color: var(--text-secondary, #666);
  3011. margin-top: 2px;
  3012. white-space: nowrap;
  3013. overflow: hidden;
  3014. text-overflow: ellipsis;
  3015. }
  3016. .version-panel .vi-message-edit {
  3017. display: flex;
  3018. gap: 4px;
  3019. margin-top: 4px;
  3020. align-items: center;
  3021. }
  3022. .version-panel .vi-actions {
  3023. display: flex;
  3024. flex-direction: column;
  3025. justify-content: center;
  3026. gap: 2px;
  3027. padding: 4px 6px;
  3028. opacity: 0;
  3029. transition: opacity 0.15s;
  3030. }
  3031. .version-panel .version-item:hover .vi-actions {
  3032. opacity: 1;
  3033. }
  3034. .vi-action-btn {
  3035. width: 24px;
  3036. height: 24px;
  3037. display: flex;
  3038. align-items: center;
  3039. justify-content: center;
  3040. border: none;
  3041. border-radius: 4px;
  3042. cursor: pointer;
  3043. font-size: 13px;
  3044. background: transparent;
  3045. transition: background 0.15s;
  3046. }
  3047. .rollback-btn {
  3048. color: var(--color-danger, #ef4444);
  3049. }
  3050. .rollback-btn:hover {
  3051. background: rgba(239, 68, 68, 0.15);
  3052. }
  3053. .version-panel .vp-content {
  3054. flex: 1;
  3055. display: flex;
  3056. flex-direction: column;
  3057. overflow: hidden;
  3058. border-top: 1px solid var(--border-color, #e5e7eb);
  3059. }
  3060. .version-panel .vp-content-header {
  3061. padding: 8px 16px;
  3062. font-size: 13px;
  3063. font-weight: 500;
  3064. color: var(--text-secondary, #666);
  3065. border-bottom: 1px solid var(--border-color, #e5e7eb);
  3066. flex-shrink: 0;
  3067. }
  3068. .version-json {
  3069. flex: 1;
  3070. overflow: auto;
  3071. padding: 12px 16px;
  3072. margin: 0;
  3073. font-size: 11px;
  3074. line-height: 1.5;
  3075. white-space: pre-wrap;
  3076. word-break: break-all;
  3077. color: var(--text-secondary, #666);
  3078. font-family: 'Consolas', 'Monaco', monospace;
  3079. background: transparent;
  3080. }
  3081. /* 版本按钮 */
  3082. .version-btn {
  3083. display: inline-flex;
  3084. align-items: center;
  3085. gap: 4px;
  3086. padding: 5px 10px;
  3087. border: 1px solid var(--border-color, #e5e7eb);
  3088. border-radius: 6px;
  3089. background: var(--bg-secondary, #fff);
  3090. color: var(--text-secondary, #666);
  3091. cursor: pointer;
  3092. font-size: 13px;
  3093. transition: all 0.2s;
  3094. }
  3095. .version-btn:hover:not(:disabled) {
  3096. border-color: var(--color-accent, #2563eb);
  3097. color: var(--color-accent, #2563eb);
  3098. }
  3099. .version-btn.active {
  3100. background: var(--color-accent, #2563eb);
  3101. color: #fff;
  3102. border-color: var(--color-accent, #2563eb);
  3103. }
  3104. .version-btn:disabled {
  3105. opacity: 0.4;
  3106. cursor: not-allowed;
  3107. }
  3108. /* 右侧滑入动画 */
  3109. .slide-right-enter-active,
  3110. .slide-right-leave-active {
  3111. transition: transform 0.25s ease;
  3112. }
  3113. .slide-right-enter-from,
  3114. .slide-right-leave-to {
  3115. transform: translateX(100%);
  3116. }
  3117. </style>