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