import{ai as N,r as A,d as x,u as E,c as h,z as j,e as z,f as g,g as p,h as o,w as i,j as n,l as R,n as O,q as B,a6 as I,s as F,t as l,M}from"./index-a0da86f0.js";import{I as b}from"./iconify-56cbf3ff.js";import T from"./AIAgentFlowBuilder-9839caaa.js";import{useFlowBuilderStore as L}from"./flowBuilder-c7c3e16b.js";import{getRecord as $,updateRecord as q}from"./common-fa44b7a0.js";import{_ as P}from"./_plugin-vue_export-helper-c27b6911.js";const G=async e=>{try{const r=await $("Local Ai Agent",e);if(!r.success)throw new Error(r.message||"获取AI Agent详情失败");return r.data}catch(r){throw new Error(r.message||"获取AI Agent详情失败")}},H=async(e,r)=>{try{const t=await q("Local Ai Agent",e,r);if(!t.success)throw new Error(t.message||"更新AI Agent失败");return t.data}catch(t){throw console.error("Error in updateAgentApi:",t),new Error(t.message||"更新AI Agent失败")}},J=N("agent",()=>{const e=A(null);return{currentAgent:e,fetchAgent:async u=>{try{const s=await G(u);e.value=s}catch(s){throw console.error("获取AI Agent详情失败:",s),s}},updateAgent:async(u,s)=>{try{return await H(u,s),e.value&&e.value.name===u&&(e.value={...e.value,...s}),{success:!0}}catch(c){throw console.error("更新AI Agent失败:",c),c}}}}),K={class:"flow-builder"},Q={class:"flow-builder-header"},U={class:"header-left"},W={class:"title"},X={class:"header-right"},Y={class:"flow-builder-content"},Z=x({__name:"FlowBuilderContainer",props:{initialValue:{},agentId:{}},emits:["save"],setup(e,{emit:r}){const t=e,u=r,s=R(),c=E(),f=J(),w=L(),d=A(""),S=h(()=>{if(t.initialValue&&Object.keys(t.initialValue).length>0)return t.initialValue;const a=w.getFlowData();return a&&Object.keys(a).length>0?a:{}}),v=A(),_=h(()=>t.agentId||w.getAgentId()),k=h(()=>d.value?`${d.value}`:l("Flow Builder"));j(_,async a=>{var m,y;if(a)try{await f.fetchAgent(a),d.value=((m=f.currentAgent)==null?void 0:m.agent_name)||((y=f.currentAgent)==null?void 0:y.name)||""}catch(D){console.error("获取智能体信息失败:",D),d.value=""}else d.value=""},{immediate:!0});const C=async()=>{try{if(!v.value){c.error(l("Flow Builder is not initialized"));return}const a=v.value.getFlowData();_.value?(await f.updateAgent(_.value,{agent_flow:a}),c.success(l("Flow saved successfully"))):(u("save",a),c.success(l("Flow saved successfully")))}catch(a){c.error(l("Save failed")+": "+(a.message||l("An error occurred during save")))}},V=()=>{w.deactivateFlowBuilder(),s.back()};return(a,m)=>(O(),z("div",K,[g("div",Q,[g("div",U,[g("h2",W,p(k.value),1)]),g("div",X,[o(n(M),null,{default:i(()=>[o(n(B),{size:"small",onClick:V},{icon:i(()=>[o(n(I),null,{default:i(()=>[o(n(b),{icon:"tabler:arrow-left"})]),_:1})]),default:i(()=>[F(" "+p(n(l)("Back")),1)]),_:1}),o(n(B),{size:"small",type:"primary",onClick:C,class:"save-btn-brand"},{icon:i(()=>[o(n(I),null,{default:i(()=>[o(n(b),{icon:"tabler:check"})]),_:1})]),default:i(()=>[F(" "+p(n(l)("Save")),1)]),_:1})]),_:1})])]),g("div",Y,[o(T,{ref_key:"flowBuilderRef",ref:v,"initial-value":S.value,"agent-id":_.value},null,8,["initial-value","agent-id"])])]))}});const ee=P(Z,[["__scopeId","data-v-c0f6c106"]]),le=Object.freeze(Object.defineProperty({__proto__:null,default:ee},Symbol.toStringTag,{value:"Module"}));export{ee as F,le as a,J as u};
