You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
14 KiB
1 lines
14 KiB
import{g as ie,C as de,c as o,a as t,q as r,s as y,F as u,r as p,l as v,H as ce,t as d,d as E,v as _,b as z,x as D,p as q,y as g,z as re,A as L,o as a,L as N,n as ue,_ as pe}from"./DMxDLVSv.js";import{u as me}from"./CCZrj3X-.js";import{u as ve}from"./B-sqZCu-.js";import{L as F}from"./DD3V9C6_.js";import{_ as P}from"./mgru9RGc.js";const _e={class:"flex items-center justify-between mb-5 flex-wrap gap-3"},be={class:"flex items-center gap-3"},ge=["value"],fe={key:0,class:"text-center py-20 text-slate-300"},xe={class:"flex items-center gap-2 mb-3"},ye={class:"text-xs text-slate-400"},ke={class:"text-xs text-slate-400"},Te={class:"agent-grid"},he=["onClick"],we={class:"flex items-start justify-between gap-2"},Se={class:"min-w-0"},Ae={class:"font-semibold text-sm text-slate-800 truncate"},Ce={class:"text-[11px] text-slate-400 mt-0.5 truncate"},Ve={class:"flex items-center gap-1 flex-shrink-0"},Ue={key:0,class:"badge badge-success badge-xs"},Le={key:1,class:"badge badge-ghost badge-xs"},Ne=["onClick"],Me={key:0,class:"text-xs text-slate-500 mt-2 line-clamp-2"},Oe={class:"flex flex-wrap items-center gap-1.5 mt-3"},$e={key:1,class:"text-[11px] text-slate-400 mt-2 truncate"},je={class:"ag-box"},Be={class:"flex items-center justify-between mb-4"},Ie={class:"flex items-center gap-3"},Ee={class:"text-base font-semibold text-slate-800"},ze={class:"scope-chip"},De={class:"ed-section"},qe={class:"type-row"},Fe=["disabled","onClick"],Pe={class:"ttab-title"},Ge={class:"ttab-desc"},Je={key:0,class:"ed-tip"},He={class:"ed-section"},Re={class:"grid grid-cols-2 gap-3"},Xe=["disabled"],Ye={class:"mt-3"},Ke={class:"grid grid-cols-3 gap-3 mt-3"},Qe={class:"ed-section"},We={class:"slot-row"},Ze={class:"slot-item"},et={class:"ed-label inline"},tt=["onUpdate:modelValue"],st={value:"",disabled:""},lt=["value"],nt={key:0,class:"slot-arrow"},ot={class:"ed-section"},at={class:"grid grid-cols-2 gap-3"},it={class:"mt-3"},dt={key:0,class:"text-xs text-slate-300 py-2"},ct=["onUpdate:modelValue"],rt=["value"],ut=["onUpdate:modelValue"],pt=["onUpdate:modelValue"],mt=["onClick"],vt={key:0,class:"ed-section"},_t={class:"mt-3"},bt={class:"flex items-center gap-2 text-sm cursor-pointer"},gt={class:"ed-footer"},ft={class:"flex items-center gap-2 text-sm cursor-pointer"},xt={class:"flex gap-2"},yt=["disabled"],G=1,J=2,kt=3,Tt=4,ht=5,wt=7,H=9,St=ie({__name:"agents",setup(At){const M=[{value:"chat",label:"对话",icon:"💬",hint:"STT → LLM → TTS 三段拼接",color:"#b45309",bg:"#fef9c3"},{value:"translate",label:"翻译",icon:"🧩",hint:"STT → MT → TTS 三段拼接",color:"#059669",bg:"#dcfce7"},{value:"sts-chat",label:"端到端对话",icon:"⚡",hint:"单个 STS 服务直接完成语音对话",color:"#be185d",bg:"#fce7f3"},{value:"ast-translate",label:"端到端翻译",icon:"🚀",hint:"单个 AST 服务直接完成语音翻译",color:"#c2410c",bg:"#fff7ed"}],R={chat:[{key:"stt_svc_id",slot:"STT",label:"语音识别",cats:[G],color:"#1664ff"},{key:"llm_svc_id",slot:"LLM",label:"大语言模型",cats:[ht,H],color:"#b45309"},{key:"tts_svc_id",slot:"TTS",label:"语音合成",cats:[J],color:"#7c3aed"}],translate:[{key:"stt_svc_id",slot:"STT",label:"语音识别",cats:[G],color:"#1664ff"},{key:"mt_svc_id",slot:"MT",label:"机器翻译",cats:[kt],color:"#059669"},{key:"tts_svc_id",slot:"TTS",label:"语音合成",cats:[J],color:"#7c3aed"}],"sts-chat":[{key:"sts_svc_id",slot:"STS",label:"端到端语音对话",cats:[wt],color:"#be185d"}],"ast-translate":[{key:"ast_svc_id",slot:"AST",label:"端到端语音翻译",cats:[Tt],color:"#f97316"}]};function f(n){return R[n]??[]}const{webApi:k,consoleApi:X}=me(),{success:O,error:x}=ve(),b=g(""),A=g([]),T=g([]),h=g([]),w=g(!1),m=g(!1),C=g(!1);function V(){return{app_name:"",id:"",name:"",type:"translate",description:"",avatar_url:"",enable:!0,stt_svc_id:"",llm_svc_id:"",tts_svc_id:"",mt_svc_id:"",sts_svc_id:"",ast_svc_id:"",system_prompt:"",gender:0,greeting_enabled:!1,greeting_text:"",support_langs:"",default_lang:"",voice_map:[],sort:0}}const l=re(V()),Y=L(()=>l.type==="chat"||l.type==="sts-chat"),$=L(()=>{const n=(l.support_langs||"").split(",").map(e=>e.trim()).filter(Boolean);return n.length?F.filter(e=>n.includes(e.code)):F}),K=L(()=>M.map(n=>({...n,type:n.value,items:T.value.filter(e=>e.type===n.value).sort((e,s)=>(s.sort||0)-(e.sort||0)||(e.name||"").localeCompare(s.name||""))})).filter(n=>n.items.length));async function Q(){try{const n=await X("products/list",{});A.value=(n??[]).map(e=>e.name).filter(Boolean)}catch{A.value=[]}}async function W(){try{const n=await k("getsvcconfigs",{app_name:b.value});h.value=n?.items??[]}catch{h.value=[]}}async function U(){try{const n=await k("getagents",{app_name:b.value});T.value=(n?.items??[]).map(e=>({...e,voice_map:e.voice_map??[]}))}catch(n){x(n?.message??"加载失败"),T.value=[]}}async function j(){await Promise.all([W(),U()])}function B(n){return(n.categories||"").split(",").map(Number)}function I(n){return h.value.filter(e=>e.enable&&B(e).some(s=>n.includes(s)))}function Z(n){return B(n).includes(H)}function ee(n){if(!n)return"未配置";const e=h.value.find(s=>s.id===n);return e?e.name:n}function te(n){return f(n.type).map(e=>({slot:e.slot,color:e.color,id:n[e.key]}))}function se(){Object.assign(l,V()),m.value=!1,w.value=!0}function le(n){Object.assign(l,V(),n,{voice_map:(n.voice_map??[]).map(e=>({...e}))}),m.value=!0,w.value=!0}function S(){w.value=!1}function ne(){l.voice_map.push({language:l.default_lang||"",gender:0,voice:""})}async function oe(){if(!l.id.trim()||!l.name.trim()){x("Agent ID 和 名称 必填");return}for(const n of f(l.type))if(!(l[n.key]||"").trim()){x(`${n.slot} ${n.label} 必选`);return}C.value=!0;try{const n={...JSON.parse(JSON.stringify(l)),app_name:b.value,id:l.id.trim(),name:l.name.trim(),stt_svc_id:"",llm_svc_id:"",tts_svc_id:"",mt_svc_id:"",sts_svc_id:"",ast_svc_id:""};for(const e of f(l.type))n[e.key]=l[e.key];n.voice_map=l.voice_map.filter(e=>e.language&&e.voice),await k(m.value?"updateagent":"addagent",n),O("保存成功"),S(),await U()}catch(n){x(n?.message??"保存失败")}finally{C.value=!1}}function ae(n){window.confirm(`确定删除 Agent「${n.name||n.id}」吗?引用它的通话翻译规则会失效。`)&&k("delagent",{app_name:b.value,id:n.id}).then(()=>{O("已删除"),U()}).catch(e=>x(e?.message??"删除失败"))}return de(async()=>{await Q(),await j()}),(n,e)=>(a(),o("div",null,[t("div",_e,[e[15]||(e[15]=t("div",null,[t("h2",{class:"text-lg font-semibold text-slate-800"},"Agent 配置"),t("p",{class:"text-xs text-slate-400 mt-1"}," 把已配置的第三方服务编排成可下发客户端的智能体。四种类型按需引用不同服务;通话翻译规则只能引用「翻译」与「端到端翻译」两类。 ")],-1)),t("div",be,[e[14]||(e[14]=t("span",{class:"text-sm text-slate-500"},"作用域",-1)),r(t("select",{"onUpdate:modelValue":e[0]||(e[0]=s=>b.value=s),class:"select select-bordered select-sm",onChange:j},[e[13]||(e[13]=t("option",{value:""},"全局默认",-1)),(a(!0),o(u,null,p(A.value,s=>(a(),o("option",{key:s,value:s},d(s),9,ge))),128))],544),[[y,b.value]]),t("button",{class:"btn btn-primary btn-sm text-white",onClick:se},"+ 新建 Agent")])]),T.value.length?v("",!0):(a(),o("div",fe,[...e[16]||(e[16]=[t("div",{class:"text-5xl mb-3"},"🤖",-1),t("p",{class:"text-sm"},"当前作用域下还没有 Agent",-1),t("p",{class:"text-xs mt-1"},"先在「第三方服务配置」里配好服务,再来把它们组装成 Agent",-1)])])),(a(!0),o(u,null,p(K.value,s=>(a(),o("div",{key:s.type,class:"mb-6"},[t("div",xe,[t("span",{class:"type-tag",style:N({background:s.bg,color:s.color})},d(s.icon)+" "+d(s.label),5),t("span",ye,d(s.hint),1),e[17]||(e[17]=t("span",{class:"text-xs text-slate-300"},"·",-1)),t("span",ke,d(s.items.length)+" 个",1)]),t("div",Te,[(a(!0),o(u,null,p(s.items,c=>(a(),o("div",{key:c.id,class:"agent-card",onClick:i=>le(c)},[t("div",we,[t("div",Se,[t("div",Ae,d(c.name||c.id),1),t("div",Ce,d(c.id),1)]),t("div",Ve,[c.enable?(a(),o("span",Ue,"启用")):(a(),o("span",Le,"停用")),t("button",{class:"btn btn-ghost btn-xs text-error",onClick:q(i=>ae(c),["stop"])},"删除",8,Ne)])]),c.description?(a(),o("p",Me,d(c.description),1)):v("",!0),t("div",Oe,[(a(!0),o(u,null,p(te(c),i=>(a(),o("span",{key:i.slot,class:"svc-pill",style:N({background:i.color})},d(i.slot)+": "+d(ee(i.id)),5))),128))]),c.support_langs?(a(),o("div",$e," 支持语言:"+d(c.support_langs),1)):v("",!0)],8,he))),128))])]))),128)),r(t("div",{class:"ag-overlay",onClick:q(S,["self"])},[t("div",je,[t("div",Be,[t("div",Ie,[t("h3",Ee,d(m.value?"编辑 Agent":"新建 Agent"),1),t("span",ze,d(b.value||"全局默认"),1)]),t("button",{class:"btn btn-ghost btn-xs",onClick:S},"✕ 关闭")]),t("section",De,[e[18]||(e[18]=t("div",{class:"ed-section-title"},"类型",-1)),t("div",qe,[(a(),o(u,null,p(M,s=>t("button",{key:s.value,type:"button",class:ue(["ttab",{on:l.type===s.value,locked:m.value&&l.type!==s.value}]),disabled:m.value,onClick:c=>l.type=s.value},[t("span",Pe,d(s.icon)+" "+d(s.label),1),t("span",Ge,d(s.hint),1)],10,Fe)),64))]),m.value?(a(),o("p",Je,"类型创建后不可更改;需要换类型请新建一个 Agent。")):v("",!0)]),t("section",He,[e[26]||(e[26]=t("div",{class:"ed-section-title"},"基本信息",-1)),t("div",Re,[t("div",null,[e[19]||(e[19]=t("span",{class:"ed-label"},[E("Agent ID "),t("i",{class:"req"},"*")],-1)),r(t("input",{"onUpdate:modelValue":e[1]||(e[1]=s=>l.id=s),disabled:m.value,class:"input input-bordered input-sm w-full",placeholder:"如 trans-cn-en(作用域内唯一,创建后不可改)"},null,8,Xe),[[_,l.id]])]),t("div",null,[e[20]||(e[20]=t("span",{class:"ed-label"},[E("名称 "),t("i",{class:"req"},"*")],-1)),r(t("input",{"onUpdate:modelValue":e[2]||(e[2]=s=>l.name=s),class:"input input-bordered input-sm w-full",placeholder:"展示名,如 中英实时翻译"},null,512),[[_,l.name]])])]),t("div",Ye,[e[21]||(e[21]=t("span",{class:"ed-label"},"描述",-1)),r(t("input",{"onUpdate:modelValue":e[3]||(e[3]=s=>l.description=s),class:"input input-bordered input-sm w-full",placeholder:"这个 Agent 用在什么场景"},null,512),[[_,l.description]])]),t("div",Ke,[t("div",null,[e[22]||(e[22]=t("span",{class:"ed-label"},"头像 URL",-1)),r(t("input",{"onUpdate:modelValue":e[4]||(e[4]=s=>l.avatar_url=s),class:"input input-bordered input-sm w-full",placeholder:"可留空"},null,512),[[_,l.avatar_url]])]),t("div",null,[e[23]||(e[23]=t("span",{class:"ed-label"},"排序(越大越靠前)",-1)),r(t("input",{"onUpdate:modelValue":e[5]||(e[5]=s=>l.sort=s),type:"number",class:"input input-bordered input-sm w-full"},null,512),[[_,l.sort,void 0,{number:!0}]])]),t("div",null,[e[25]||(e[25]=t("span",{class:"ed-label"},"音色性别偏好",-1)),r(t("select",{"onUpdate:modelValue":e[6]||(e[6]=s=>l.gender=s),class:"select select-bordered select-sm w-full"},[...e[24]||(e[24]=[t("option",{value:0},"不限",-1),t("option",{value:1},"男",-1),t("option",{value:2},"女",-1)])],512),[[y,l.gender,void 0,{number:!0}]])])])]),t("section",Qe,[e[27]||(e[27]=t("div",{class:"ed-section-title"},"服务编排",-1)),t("div",We,[(a(!0),o(u,null,p(f(l.type),(s,c)=>(a(),o(u,{key:s.key},[t("div",Ze,[t("span",{class:"stage-tag",style:N({background:s.color})},d(s.slot),5),t("span",et,d(s.label),1),r(t("select",{"onUpdate:modelValue":i=>l[s.key]=i,class:"select select-bordered select-sm w-full"},[t("option",st,d(I(s.cats).length?"请选择服务":"(无可用服务,请先去第三方服务配置里添加)"),1),(a(!0),o(u,null,p(I(s.cats),i=>(a(),o("option",{key:i.id,value:i.id},d(i.name)+d(Z(i)?" 🖼":""),9,lt))),128))],8,tt),[[y,l[s.key]]])]),c<f(l.type).length-1?(a(),o("span",nt,"→")):v("",!0)],64))),128))])]),t("section",ot,[e[33]||(e[33]=t("div",{class:"ed-section-title"},"语言与音色",-1)),t("div",at,[t("div",null,[e[28]||(e[28]=t("span",{class:"ed-label"},"支持语言(多选)",-1)),z(P,{modelValue:l.support_langs,"onUpdate:modelValue":e[7]||(e[7]=s=>l.support_langs=s),multiple:""},null,8,["modelValue"])]),t("div",null,[e[29]||(e[29]=t("span",{class:"ed-label"},"默认语言",-1)),z(P,{modelValue:l.default_lang,"onUpdate:modelValue":e[8]||(e[8]=s=>l.default_lang=s),options:$.value},null,8,["modelValue","options"])])]),t("div",it,[t("div",{class:"flex items-center justify-between mb-1"},[e[30]||(e[30]=t("span",{class:"ed-label mb-0"},"音色覆盖(不填则用 TTS 服务自带默认音色)",-1)),t("button",{class:"btn btn-ghost btn-xs",onClick:ne},"+ 添加一行")]),l.voice_map.length?v("",!0):(a(),o("div",dt,"未设置音色覆盖")),(a(!0),o(u,null,p(l.voice_map,(s,c)=>(a(),o("div",{key:c,class:"voice-row"},[r(t("select",{"onUpdate:modelValue":i=>s.language=i,class:"select select-bordered select-xs"},[e[31]||(e[31]=t("option",{value:""},"(语言)",-1)),(a(!0),o(u,null,p($.value,i=>(a(),o("option",{key:i.code,value:i.code},d(i.code)+" · "+d(i.name),9,rt))),128))],8,ct),[[y,s.language]]),r(t("select",{"onUpdate:modelValue":i=>s.gender=i,class:"select select-bordered select-xs"},[...e[32]||(e[32]=[t("option",{value:0},"不限",-1),t("option",{value:1},"男",-1),t("option",{value:2},"女",-1)])],8,ut),[[y,s.gender,void 0,{number:!0}]]),r(t("input",{"onUpdate:modelValue":i=>s.voice=i,class:"input input-bordered input-xs flex-1",placeholder:"音色名,如 zh-CN-XiaoxiaoNeural"},null,8,pt),[[_,s.voice]]),t("button",{class:"btn btn-ghost btn-xs text-error",onClick:i=>l.voice_map.splice(c,1)},"删除",8,mt)]))),128))])]),Y.value?(a(),o("section",vt,[e[36]||(e[36]=t("div",{class:"ed-section-title"},"对话设定",-1)),t("div",null,[e[34]||(e[34]=t("span",{class:"ed-label"},"系统提示词",-1)),r(t("textarea",{"onUpdate:modelValue":e[9]||(e[9]=s=>l.system_prompt=s),class:"textarea textarea-bordered w-full text-xs",rows:"3",placeholder:"定义这个智能体的人设与行为"},null,512),[[_,l.system_prompt]])]),t("div",_t,[t("label",bt,[r(t("input",{"onUpdate:modelValue":e[10]||(e[10]=s=>l.greeting_enabled=s),type:"checkbox",class:"checkbox checkbox-sm checkbox-primary"},null,512),[[D,l.greeting_enabled]]),e[35]||(e[35]=t("span",null,"开场白",-1))]),l.greeting_enabled?r((a(),o("input",{key:0,"onUpdate:modelValue":e[11]||(e[11]=s=>l.greeting_text=s),class:"input input-bordered input-sm w-full mt-2",placeholder:"接通后先说的一句话"},null,512)),[[_,l.greeting_text]]):v("",!0)])])):v("",!0),t("div",gt,[t("label",ft,[r(t("input",{"onUpdate:modelValue":e[12]||(e[12]=s=>l.enable=s),type:"checkbox",class:"checkbox checkbox-sm checkbox-primary"},null,512),[[D,l.enable]]),e[37]||(e[37]=t("span",null,"启用",-1))]),t("div",xt,[t("button",{class:"btn btn-ghost btn-sm",onClick:S},"取消"),t("button",{class:"btn btn-primary btn-sm text-white",disabled:C.value,onClick:oe},"保存",8,yt)])])])],512),[[ce,w.value]])]))}}),Mt=pe(St,[["__scopeId","data-v-4a81d81a"]]);export{Mt as default};
|
|
|