Files
pyMC_Repeater/repeater/web/html/assets/Companions-DMecktoP.js
T
2026-03-10 12:50:51 +00:00

2 lines
19 KiB
JavaScript

import{a as z,r as d,o as O,L as C,b as s,e,f as A,g as x,i as J,k as N,t as i,F as T,h as R,w as u,v as c,j as B,p as a}from"./index-C4FtHzmM.js";import{_ as q}from"./ConfirmDialog.vue_vue_type_script_setup_true_lang-B2gkCnr2.js";import{_ as W}from"./MessageDialog.vue_vue_type_script_setup_true_lang-CZwrKPz1.js";const G={class:"p-6 space-y-6"},Q={class:"relative overflow-hidden rounded-[20px] p-6 mb-6 glass-card backdrop-blur-xl border border-stroke-subtle dark:border-white/10"},X={class:"relative flex items-center justify-between"},Y={key:0,class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Z={class:"group relative overflow-hidden glass-card backdrop-blur-xl border border-stroke-subtle dark:border-white/10 rounded-[15px] p-5"},ee={class:"relative flex items-center justify-between"},te={class:"text-3xl font-bold text-content-primary dark:text-content-primary"},re={class:"glass-card backdrop-blur-xl border border-stroke-subtle dark:border-white/10 rounded-[15px] p-6"},oe={key:0,class:"flex items-center justify-center py-12"},ne={key:1,class:"flex items-center justify-center py-12"},se={class:"text-center"},ae={class:"text-content-secondary dark:text-content-muted text-sm mb-4"},le={key:2,class:"space-y-4"},de={class:"relative flex items-start justify-between"},ie={class:"flex-1"},ue={class:"flex items-center gap-3 mb-4"},ce={class:"relative"},pe={key:0,class:"absolute inset-0 bg-accent-green/50 rounded-full animate-ping"},me={class:"text-xl font-bold text-content-primary dark:text-content-primary"},be={key:0,class:"text-content-muted dark:text-content-muted text-sm"},xe={class:"grid grid-cols-1 md:grid-cols-2 gap-3 text-sm mb-3"},ye={class:"text-content-primary dark:text-content-primary/90 ml-2"},ve={class:"text-content-primary dark:text-content-primary/90 ml-2"},ke={class:"text-content-primary dark:text-content-primary/90 ml-2"},ge={class:"flex items-center gap-2"},fe={key:0,class:"text-content-primary dark:text-content-primary/90 font-mono ml-2 text-xs"},we={key:1,class:"text-content-muted dark:text-content-muted ml-2 text-xs"},he=["onClick"],_e={class:"text-xs text-content-muted dark:text-content-muted"},Ce={key:0,class:"ml-2 font-mono text-content-primary dark:text-content-primary/90 break-all"},Me={key:1,class:"ml-2 text-content-muted dark:text-content-muted"},$e={class:"ml-4 flex flex-wrap gap-2"},Ie=["onClick"],Ne=["onClick"],Ve={key:3,class:"text-center py-12 text-content-secondary dark:text-content-muted"},je={key:1,class:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"},Ee={class:"bg-white dark:bg-surface-elevated backdrop-blur-xl border border-stroke-subtle dark:border-white/10 rounded-[15px] p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto"},De={class:"space-y-4"},Ue={class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},Ae={key:0},Te={key:1,class:"text-content-secondary dark:text-content-muted text-sm"},Be={class:"grid grid-cols-2 gap-4"},Fe={key:2,class:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"},Pe={class:"bg-white dark:bg-surface-elevated backdrop-blur-xl border border-stroke-subtle dark:border-white/10 rounded-[15px] p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto"},Se={class:"space-y-4"},He=["value"],Ke={class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},Le={key:0},ze={class:"grid grid-cols-2 gap-4"},We=z({name:"CompanionsView",__name:"Companions",setup(Oe){const M=d(!1),y=d(null),v=d(null),k=d(!1),w=d(!1),n=d(null),m=d(!1),b=d(!1),g=d(new Set),h=d(!1),_=d(""),$=d(!1),I=d({message:"",variant:"success"}),l=d({name:"",identity_key:"",type:"companion",settings:{node_name:"",tcp_port:5e3,bind_address:"0.0.0.0"}});O(async()=>{await f()});async function f(){M.value=!0,y.value=null;try{const o=await C.getIdentities();o.success?v.value=o.data:y.value=o.error||"Failed to load identities"}catch(o){y.value=o instanceof Error?o.message:"Failed to load identities"}finally{M.value=!1}}async function F(){try{const o=await C.createIdentity({...l.value,settings:{node_name:l.value.settings.node_name||l.value.name,tcp_port:l.value.settings.tcp_port??5e3,bind_address:l.value.settings.bind_address||"0.0.0.0"}});o.success?(k.value=!1,V(),await f(),p(o.message||"Companion created successfully!","success")):p(`Failed to create companion: ${o.error}`,"error")}catch(o){p(`Error creating companion: ${o}`,"error")}}async function P(){try{const o=await C.updateIdentity({name:n.value.name,new_name:n.value.new_name,identity_key:n.value.identity_key,type:"companion",settings:{node_name:n.value.settings?.node_name,tcp_port:n.value.settings?.tcp_port,bind_address:n.value.settings?.bind_address}});o.success?(w.value=!1,n.value=null,await f(),p(o.message||"Companion updated successfully!","success")):p(`Failed to update companion: ${o.error}`,"error")}catch(o){p(`Error updating companion: ${o}`,"error")}}function S(o){_.value=o,h.value=!0}async function H(){const o=_.value;h.value=!1;try{const t=await C.deleteIdentity(o,"companion");t.success?(await f(),p(t.message||"Companion deleted successfully!","success")):p(`Failed to delete companion: ${t.error}`,"error")}catch(t){p(`Error deleting companion: ${t}`,"error")}finally{_.value=""}}function p(o,t){I.value={message:o,variant:t},$.value=!0}function K(o){n.value=JSON.parse(JSON.stringify(o)),n.value.settings||(n.value.settings={node_name:"",tcp_port:5e3,bind_address:"0.0.0.0"}),n.value.new_name="",b.value=!1,w.value=!0}function V(){l.value={name:"",identity_key:"",type:"companion",settings:{node_name:"",tcp_port:5e3,bind_address:"0.0.0.0"}},m.value=!1}function j(){k.value=!1,w.value=!1,n.value=null,m.value=!1,b.value=!1,V()}function L(o){g.value.has(o)?g.value.delete(o):g.value.add(o)}const E=()=>v.value?.configured_companions??[],D=()=>v.value?.total_configured_companions??0;return(o,t)=>(a(),s(T,null,[e("div",G,[e("div",Q,[t[18]||(t[18]=e("div",{class:"absolute inset-0 bg-gradient-to-br from-primary/20 via-secondary/10 to-accent-purple/20 opacity-50"},null,-1)),t[19]||(t[19]=e("div",{class:"absolute inset-0 bg-gradient-to-tl from-accent-green/10 via-transparent to-primary/10 animate-pulse"},null,-1)),e("div",X,[t[17]||(t[17]=J('<div class="flex items-center gap-4"><div class="relative"><div class="absolute inset-0 bg-primary/30 blur-xl rounded-full"></div><div class="relative bg-primary/20 p-4 rounded-[15px] border border-primary/30"><svg class="w-8 h-8 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"></path></svg></div></div><div><h1 class="text-3xl font-bold text-content-primary dark:text-content-primary mb-1">Companions</h1><p class="text-content-secondary dark:text-content-muted text-sm">Manage companion identities (TCP frame server)</p></div></div>',1)),e("button",{onClick:t[0]||(t[0]=r=>k.value=!0),class:"group relative px-6 py-3 bg-gradient-to-r from-primary/30 to-secondary/30 hover:from-primary/40 hover:to-secondary/40 text-content-primary dark:text-content-primary rounded-[12px] border border-primary/50 transition-all hover:scale-105 hover:shadow-lg hover:shadow-primary/20"},t[16]||(t[16]=[e("span",{class:"flex items-center gap-2"},[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})]),N(" Add Companion ")],-1)]))])]),v.value&&D()>0?(a(),s("div",Y,[e("div",Z,[e("div",ee,[e("div",null,[t[20]||(t[20]=e("div",{class:"text-content-secondary dark:text-content-muted text-xs font-medium mb-2 uppercase tracking-wide"},"Total Configured",-1)),e("div",te,i(D()),1)])])])])):x("",!0),e("div",re,[M.value?(a(),s("div",oe,t[21]||(t[21]=[e("div",{class:"text-center"},[e("div",{class:"animate-spin w-8 h-8 border-2 border-stroke-subtle dark:border-stroke/20 border-t-primary rounded-full mx-auto mb-4"}),e("div",{class:"text-content-secondary dark:text-content-primary/70"},"Loading companions...")],-1)]))):y.value?(a(),s("div",ne,[e("div",se,[t[22]||(t[22]=e("div",{class:"text-red-600 dark:text-red-400 mb-2"},"Failed to load companions",-1)),e("div",ae,i(y.value),1),e("button",{onClick:f,class:"px-4 py-2 bg-primary/20 hover:bg-primary/30 text-content-primary dark:text-content-primary rounded-lg border border-primary/50 transition-colors"}," Retry ")])])):v.value&&E().length>0?(a(),s("div",le,[(a(!0),s(T,null,R(E(),r=>(a(),s("div",{key:r.name,class:"group relative overflow-hidden glass-card backdrop-blur-xl rounded-[15px] p-5 border border-stroke-subtle dark:border-white/10 hover:border-primary/30 transition-all duration-300"},[e("div",de,[e("div",ie,[e("div",ue,[e("div",ce,[r.registered?(a(),s("div",pe)):x("",!0),e("div",{class:B(["relative w-3 h-3 rounded-full",r.registered?"bg-accent-green":"bg-accent-red"])},null,2)]),e("h3",me,i(r.name),1),e("span",{class:B(["px-3 py-1 text-xs font-semibold rounded-full",r.registered?"bg-accent-green/20 text-accent-green border border-accent-green/30":"bg-accent-red/20 text-accent-red border border-accent-red/30"])},i(r.registered?"● Active":"○ Inactive"),3),r.hash?(a(),s("span",be,i(r.hash),1)):x("",!0)]),e("div",xe,[e("div",null,[t[23]||(t[23]=e("span",{class:"text-content-muted dark:text-content-muted"},"Node Name:",-1)),e("span",ye,i(r.settings?.node_name||r.name),1)]),e("div",null,[t[24]||(t[24]=e("span",{class:"text-content-muted dark:text-content-muted"},"TCP Port:",-1)),e("span",ve,i(r.settings?.tcp_port??5e3),1)]),e("div",null,[t[25]||(t[25]=e("span",{class:"text-content-muted dark:text-content-muted"},"Bind Address:",-1)),e("span",ke,i(r.settings?.bind_address||"0.0.0.0"),1)]),e("div",ge,[t[26]||(t[26]=e("span",{class:"text-content-muted dark:text-content-muted"},"Identity Key:",-1)),g.value.has(r.name)?(a(),s("span",fe,i(r.identity_key),1)):(a(),s("span",we,"••••••••••••••••")),e("button",{onClick:U=>L(r.name),class:"text-primary/70 hover:text-primary text-xs underline"},i(g.value.has(r.name)?"Hide":"Show"),9,he)])]),e("div",_e,[t[27]||(t[27]=e("span",{class:"text-content-muted dark:text-content-muted"},"Public Key:",-1)),r.public_key?(a(),s("span",Ce,i(r.public_key),1)):(a(),s("span",Me,"—"))])]),e("div",$e,[e("button",{onClick:U=>K(r),class:"px-3 py-1 bg-primary/20 hover:bg-primary/30 text-primary rounded text-xs transition-colors"}," Edit ",8,Ie),e("button",{onClick:U=>S(r.name),class:"px-3 py-1 bg-accent-red/20 hover:bg-accent-red/30 text-accent-red rounded text-xs transition-colors"}," Delete ",8,Ne)])])]))),128))])):(a(),s("div",Ve,[t[28]||(t[28]=e("svg",{class:"w-16 h-16 mx-auto mb-4 text-content-muted dark:text-content-muted/60",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})],-1)),t[29]||(t[29]=e("p",{class:"text-lg mb-2"},"No companions configured",-1)),t[30]||(t[30]=e("p",{class:"text-sm mb-4"},"Add a companion to run a TCP frame server for firmware or other clients",-1)),e("button",{onClick:t[1]||(t[1]=r=>k.value=!0),class:"px-4 py-2 bg-primary/20 hover:bg-primary/30 text-primary rounded-lg border border-primary/50 transition-colors"}," + Add Companion ")]))]),k.value?(a(),s("div",je,[e("div",Ee,[t[37]||(t[37]=e("h2",{class:"text-xl font-bold text-content-primary dark:text-content-primary mb-4"},"Add Companion",-1)),e("div",De,[e("div",null,[t[31]||(t[31]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"Name *",-1)),u(e("input",{"onUpdate:modelValue":t[2]||(t[2]=r=>l.value.name=r),type:"text",placeholder:"e.g., TestCompanion",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary placeholder-gray-500 dark:placeholder-white/40 focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,l.value.name]])]),e("div",null,[e("label",Ue,[t[32]||(t[32]=N(" Identity Key (Optional) ",-1)),e("button",{onClick:t[3]||(t[3]=r=>m.value=!m.value),type:"button",class:"ml-2 text-primary/70 hover:text-primary text-xs underline"},i(m.value?"Hide":"Show/Edit"),1)]),m.value?(a(),s("div",Ae,[u(e("input",{"onUpdate:modelValue":t[4]||(t[4]=r=>l.value.identity_key=r),type:"text",placeholder:"Leave empty to auto-generate (32 bytes hex)",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary font-mono text-sm placeholder-gray-500 dark:placeholder-white/40 focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,l.value.identity_key]]),t[33]||(t[33]=e("p",{class:"text-content-secondary dark:text-content-muted text-xs mt-1"},"32 or 64 bytes hex. Leave empty to auto-generate.",-1))])):(a(),s("div",Te," Will be auto-generated if not provided "))]),e("div",null,[t[34]||(t[34]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"Node Name",-1)),u(e("input",{"onUpdate:modelValue":t[5]||(t[5]=r=>l.value.settings.node_name=r),type:"text",placeholder:"Display name (defaults to Name)",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary placeholder-gray-500 dark:placeholder-white/40 focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,l.value.settings.node_name]])]),e("div",Be,[e("div",null,[t[35]||(t[35]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"TCP Port",-1)),u(e("input",{"onUpdate:modelValue":t[6]||(t[6]=r=>l.value.settings.tcp_port=r),type:"number",min:"1",max:"65535",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,l.value.settings.tcp_port,void 0,{number:!0}]])]),e("div",null,[t[36]||(t[36]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"Bind Address",-1)),u(e("input",{"onUpdate:modelValue":t[7]||(t[7]=r=>l.value.settings.bind_address=r),type:"text",placeholder:"0.0.0.0",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary placeholder-gray-500 dark:placeholder-white/40 focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,l.value.settings.bind_address]])])])]),e("div",{class:"flex justify-end gap-3 mt-6"},[e("button",{onClick:j,class:"px-4 py-2 bg-background-mute dark:bg-white/5 hover:bg-stroke-subtle dark:hover:bg-white/10 text-content-primary dark:text-content-primary rounded-lg transition-colors"}," Cancel "),e("button",{onClick:F,class:"px-4 py-2 bg-primary/20 hover:bg-primary/30 text-primary rounded-lg border border-primary/50 transition-colors"}," Create ")])])])):x("",!0),w.value&&n.value?(a(),s("div",Fe,[e("div",Pe,[t[44]||(t[44]=e("h2",{class:"text-xl font-bold text-content-primary dark:text-content-primary mb-4"},"Edit Companion",-1)),e("div",Se,[e("div",null,[t[38]||(t[38]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"Current Name",-1)),e("input",{value:n.value.name,disabled:"",type:"text",class:"w-full bg-background-mute dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-muted dark:text-content-muted cursor-not-allowed"},null,8,He)]),e("div",null,[t[39]||(t[39]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"New Name (optional)",-1)),u(e("input",{"onUpdate:modelValue":t[8]||(t[8]=r=>n.value.new_name=r),type:"text",placeholder:"Leave empty to keep current name",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary placeholder-gray-500 dark:placeholder-white/40 focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,n.value.new_name]])]),e("div",null,[e("label",Ke,[t[40]||(t[40]=N(" Identity Key (Optional) ",-1)),e("button",{onClick:t[9]||(t[9]=r=>b.value=!b.value),type:"button",class:"ml-2 text-primary/70 hover:text-primary text-xs underline"},i(b.value?"Hide":"Show/Edit"),1)]),b.value?(a(),s("div",Le,[u(e("input",{"onUpdate:modelValue":t[10]||(t[10]=r=>n.value.identity_key=r),type:"text",placeholder:"Leave empty to keep current key",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary font-mono text-sm placeholder-gray-500 dark:placeholder-white/40 focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,n.value.identity_key]])])):x("",!0)]),e("div",null,[t[41]||(t[41]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"Node Name",-1)),u(e("input",{"onUpdate:modelValue":t[11]||(t[11]=r=>n.value.settings.node_name=r),type:"text",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,n.value.settings.node_name]])]),e("div",ze,[e("div",null,[t[42]||(t[42]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"TCP Port",-1)),u(e("input",{"onUpdate:modelValue":t[12]||(t[12]=r=>n.value.settings.tcp_port=r),type:"number",min:"1",max:"65535",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,n.value.settings.tcp_port,void 0,{number:!0}]])]),e("div",null,[t[43]||(t[43]=e("label",{class:"block text-content-secondary dark:text-content-primary/70 text-sm mb-2"},"Bind Address",-1)),u(e("input",{"onUpdate:modelValue":t[13]||(t[13]=r=>n.value.settings.bind_address=r),type:"text",class:"w-full bg-white dark:bg-white/5 border border-stroke-subtle dark:border-stroke/10 rounded-lg px-4 py-2 text-content-primary dark:text-content-primary focus:outline-none focus:border-primary/50 transition-colors"},null,512),[[c,n.value.settings.bind_address]])])])]),e("div",{class:"flex justify-end gap-3 mt-6"},[e("button",{onClick:j,class:"px-4 py-2 bg-background-mute dark:bg-white/5 hover:bg-stroke-subtle dark:hover:bg-white/10 text-content-primary dark:text-content-primary rounded-lg transition-colors"}," Cancel "),e("button",{onClick:P,class:"px-4 py-2 bg-primary/20 hover:bg-primary/30 text-primary rounded-lg border border-primary/50 transition-colors"}," Update ")])])])):x("",!0)]),A(q,{show:h.value,title:"Delete Companion",message:`Are you sure you want to delete '${_.value}'? Restart required to fully remove.`,"confirm-text":"Delete","cancel-text":"Cancel",variant:"danger",onClose:t[14]||(t[14]=r=>h.value=!1),onConfirm:H},null,8,["show","message"]),A(W,{show:$.value,message:I.value.message,variant:I.value.variant,onClose:t[15]||(t[15]=r=>$.value=!1)},null,8,["show","message","variant"])],64))}});export{We as default};