adam-agent-server 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/App-RIYRYLKD.js +9 -0
- package/dist/adam-tools-YBKSTHVJ.js +1 -0
- package/dist/approval-handler-JYIS2PKQ.js +1 -0
- package/dist/audit-manager-7M2CDMP5.js +1 -0
- package/dist/bree-engine-Y24K4PXN.js +1 -0
- package/dist/channels-WMCY4QC3.js +1 -0
- package/dist/{channels-NAPXRIOX.js → channels-WZOYE4O4.js} +1 -1
- package/dist/chunk-2HN2TSP6.js +5 -0
- package/dist/{chunk-ROSOI75V.js → chunk-3RAFA6QK.js} +1 -1
- package/dist/{chunk-I5RUEOSQ.js → chunk-4TCP2AT7.js} +1 -1
- package/dist/{chunk-42RHY3Q3.js → chunk-6DXNXLYG.js} +1 -1
- package/dist/chunk-6HD6NYIB.js +1 -0
- package/dist/{chunk-GA7GEIXB.js → chunk-6YURWVQG.js} +1 -1
- package/dist/chunk-7IFLU3CY.js +4 -0
- package/dist/{chunk-QMKQBU3R.js → chunk-7LBDLAUQ.js} +1 -1
- package/dist/{chunk-BONI2HUN.js → chunk-AJVN3KPM.js} +1 -1
- package/dist/{chunk-4TBGFHYX.js → chunk-AR2IZMM2.js} +1 -1
- package/dist/chunk-B4WHT7DX.js +8 -0
- package/dist/{chunk-XFTRKHH2.js → chunk-BIIP363C.js} +1 -1
- package/dist/{chunk-KHPXEUSY.js → chunk-CDVIT7L5.js} +1 -1
- package/dist/{chunk-BCELBB5Q.js → chunk-EGS6U3V5.js} +2 -2
- package/dist/{chunk-NFSXJNPD.js → chunk-EJVUUIAV.js} +1 -1
- package/dist/{chunk-X26NKAXY.js → chunk-GMCIKDTC.js} +1 -1
- package/dist/{chunk-2C5U3CNX.js → chunk-GUQAIWCQ.js} +1 -1
- package/dist/chunk-IHP7JV6J.js +1 -0
- package/dist/chunk-JTMFEUDA.js +1 -0
- package/dist/chunk-KLQOILIJ.js +21 -0
- package/dist/{chunk-CREHL4BN.js → chunk-KVSO3KGZ.js} +1 -1
- package/dist/{chunk-YEV5YTS3.js → chunk-MPRAVJUO.js} +1 -1
- package/dist/{chunk-6VPL5CXB.js → chunk-OEKM2W3K.js} +1 -1
- package/dist/{chunk-TEMWI6U5.js → chunk-OFOVSC72.js} +1 -1
- package/dist/chunk-PMHNW5IL.js +49 -0
- package/dist/{chunk-35DBEYMG.js → chunk-Q4YE5BU7.js} +1 -1
- package/dist/{chunk-PT55643Q.js → chunk-QN6BEJF5.js} +1 -1
- package/dist/{chunk-64FIXWFL.js → chunk-SWPXG2CY.js} +1 -1
- package/dist/{chunk-CFTWJZVX.js → chunk-U5NRQNBB.js} +14 -14
- package/dist/{chunk-QC6QVNKP.js → chunk-UW3OJG7U.js} +3 -3
- package/dist/chunk-WVGNP2LQ.js +3 -0
- package/dist/cli.js +4 -4
- package/dist/{config-N2GMLTPU.js → config-EI3SCA4W.js} +1 -1
- package/dist/config-OH6Q2D2Y.js +1 -0
- package/dist/{db-S6HDMJ3B.js → db-4NY7ZOS2.js} +1 -1
- package/dist/{delivery-log-VAI35G5V.js → delivery-log-SC2ULFCK.js} +1 -1
- package/dist/engine-JKSNQQDM.js +1 -0
- package/dist/{evolution-audit-KCFDGNSM.js → evolution-audit-KUBXFUHI.js} +1 -1
- package/dist/index.js +10 -10
- package/dist/{learner-ABYVK33T.js → learner-UYDFNURD.js} +1 -1
- package/dist/{memories-3ZAV55YZ.js → memories-FQCRKMK6.js} +1 -1
- package/dist/{memory-extractor-BHHKD7X7.js → memory-extractor-FUOJ5D77.js} +2 -2
- package/dist/memory-service-ANR67OPY.js +1 -0
- package/dist/outbound-gateway-6FQRWYFF.js +1 -0
- package/dist/role-presets-LRP6P5O2.js +1 -0
- package/dist/{roles-LXRHEVUK.js → roles-3UTFKSHI.js} +1 -1
- package/dist/runtime-B2DP3JNB.js +1 -0
- package/dist/session-manager-VYKNKQ46.js +1 -0
- package/dist/{task-templates-XQNKAA4U.js → task-templates-PSP7GOJJ.js} +1 -1
- package/package.json +2 -1
- package/web/dist/assets/Card-4mOZntHG.js +1 -0
- package/web/dist/assets/ChannelDetail-e6rVX_y8.js +1 -0
- package/web/dist/assets/Channels-DJvZPKer.js +12 -0
- package/web/dist/assets/Chat-hTZdEwyE.js +1 -0
- package/web/dist/assets/Dashboard-B4rL_ePs.js +1 -0
- package/web/dist/assets/{EmptyState-DBFJc4PL.js → EmptyState-BlgMMAr-.js} +1 -1
- package/web/dist/assets/EnvVarEditor-C8kRWejV.js +1 -0
- package/web/dist/assets/Evolution-BGwFCo7X.js +6 -0
- package/web/dist/assets/GoalDetail-BH2ku-0t.js +1 -0
- package/web/dist/assets/Goals-DynDtpMC.js +1 -0
- package/web/dist/assets/Logs-CyJFouE6.js +1 -0
- package/web/dist/assets/Memories-ClcFD7OG.js +1 -0
- package/web/dist/assets/{NotFound-Cidygwnn.js → NotFound-CSjhzSGa.js} +1 -1
- package/web/dist/assets/Plugins-SNOQNNcL.js +1 -0
- package/web/dist/assets/RoleDetail-vlTPiYwY.js +33 -0
- package/web/dist/assets/Roles-CFcuHIvA.js +1 -0
- package/web/dist/assets/Settings-C9Kuz-6D.js +1 -0
- package/web/dist/assets/Strategies-DZWlQCHp.js +1 -0
- package/web/dist/assets/Switch-DOi0EFHj.js +1 -0
- package/web/dist/assets/Table-BxbnOSbq.js +1 -0
- package/web/dist/assets/TaskDetail-DjmmnldI.js +2 -0
- package/web/dist/assets/Work-CvESHC3Y.js +1 -0
- package/web/dist/assets/index-BFmC20R2.js +52 -0
- package/web/dist/assets/index-CaocwyO8.css +2 -0
- package/web/dist/assets/{vendor-icons-ZPvC5PUS.js → vendor-icons-CkI4-NxL.js} +1 -1
- package/web/dist/assets/{vendor-react--nRVf2Ep.js → vendor-react-DLRtONKt.js} +1 -1
- package/web/dist/assets/vendor-state-B_-GdGNJ.js +1 -0
- package/web/dist/index.html +5 -5
- package/dist/App-SCPYTYGQ.js +0 -9
- package/dist/adam-tools-FNJJT7AA.js +0 -1
- package/dist/approval-handler-UDWAC5MF.js +0 -4
- package/dist/audit-manager-SCX53YJT.js +0 -1
- package/dist/bree-engine-2DB2QECM.js +0 -1
- package/dist/channels-PQCV74ZI.js +0 -1
- package/dist/chunk-3TIHZZMK.js +0 -1
- package/dist/chunk-7KCBFM2C.js +0 -52
- package/dist/chunk-FXFHGIY6.js +0 -8
- package/dist/chunk-IZQI6QQ7.js +0 -1
- package/dist/chunk-NQHTOFQP.js +0 -1
- package/dist/chunk-REKCZ3GY.js +0 -1
- package/dist/chunk-U3XVAAXA.js +0 -17
- package/dist/config-L4R273R3.js +0 -1
- package/dist/engine-E67UAI3G.js +0 -1
- package/dist/memory-service-5QHTKIUU.js +0 -1
- package/dist/outbound-gateway-ZFKSN2UT.js +0 -1
- package/dist/role-presets-OTU2M37Y.js +0 -1
- package/dist/runtime-UCOE6LNN.js +0 -1
- package/dist/session-manager-RPXFZKMY.js +0 -1
- package/web/dist/assets/Card-BecEmnPW.js +0 -1
- package/web/dist/assets/ChannelDetail-BajTUEU0.js +0 -1
- package/web/dist/assets/Channels-Bhy6rP_t.js +0 -12
- package/web/dist/assets/Chat-Dvt_Oo7d.js +0 -1
- package/web/dist/assets/Dashboard-DlrAor-C.js +0 -1
- package/web/dist/assets/Evolution-Dlsnnr4G.js +0 -6
- package/web/dist/assets/GoalDetail-BuUxwYdd.js +0 -1
- package/web/dist/assets/Goals-CkPQOev6.js +0 -1
- package/web/dist/assets/Logs-D33PqDAd.js +0 -1
- package/web/dist/assets/Memories-D31dbUM6.js +0 -1
- package/web/dist/assets/Plugins-XlBr07x8.js +0 -1
- package/web/dist/assets/RoleDetail-rZFlgXzh.js +0 -33
- package/web/dist/assets/Roles-d29AC6Kh.js +0 -1
- package/web/dist/assets/Settings-Bjh_RXYf.js +0 -1
- package/web/dist/assets/Strategies-Cf4ghknk.js +0 -1
- package/web/dist/assets/Switch-CxzUYL49.js +0 -1
- package/web/dist/assets/Table-tkJ-cuiE.js +0 -1
- package/web/dist/assets/TaskDetail-jMBJbaRU.js +0 -2
- package/web/dist/assets/Work-CCLTkitf.js +0 -1
- package/web/dist/assets/index-CVubgAlC.css +0 -2
- package/web/dist/assets/index-Ds41VvOC.js +0 -52
- package/web/dist/assets/vendor-state-CH64feAE.js +0 -1
package/dist/chunk-IZQI6QQ7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{f as oe}from"./chunk-4TBGFHYX.js";import{a as ae,b as _,c as Q,d as de,e as ce}from"./chunk-64FIXWFL.js";import{c as f,h as T}from"./chunk-INNDBLZE.js";import{z as g}from"zod/v4";import{v4 as Pt}from"uuid";import{randomUUID as fe}from"crypto";import Qe from"crypto";var le="1.0.0",v="";function Ke(e){let t=e.split(".").map(i=>parseInt(i,10)),r=t[0]??0,s=t[1]??0,n=t[2]??0;return(r&255)<<16|(s&255)<<8|n&255}var H=Ke(le),He=35e3,ue=15e3,Xe=1e4;function O(){return{channel_version:le}}function Je(e){return e.endsWith("/")?e:`${e}/`}function Ye(){let e=Qe.randomBytes(4).readUInt32BE(0);return Buffer.from(String(e),"utf-8").toString("base64")}function Ze(e){let t={"Content-Type":"application/json",AuthorizationType:"ilink_bot_token","Content-Length":String(Buffer.byteLength(e.body,"utf-8")),"X-WECHAT-UIN":Ye(),"iLink-App-Id":v,"iLink-App-ClientVersion":String(H)};return e.token?.trim()&&(t.Authorization=`Bearer ${e.token.trim()}`),e.routeTag&&(t.SKRouteTag=e.routeTag),t}async function N(e){let t=Je(e.baseUrl),r=new URL(e.endpoint,t),s=Ze({token:e.token,routeTag:e.routeTag,body:e.body}),n=new AbortController,i=setTimeout(()=>n.abort(),e.timeoutMs);try{let o=await fetch(r.toString(),{method:"POST",headers:s,body:e.body,signal:n.signal});clearTimeout(i);let a=await o.text();if(!o.ok)throw new Error(`${e.label} ${o.status}: ${a}`);return a}catch(o){throw clearTimeout(i),o}}async function ge(e){let t=e.timeoutMs??He;try{let r=await N({baseUrl:e.baseUrl,endpoint:"ilink/bot/getupdates",body:JSON.stringify({get_updates_buf:e.get_updates_buf??"",base_info:O()}),token:e.token,routeTag:e.routeTag,timeoutMs:t,label:"getUpdates"});return JSON.parse(r)}catch(r){if(r instanceof Error&&r.name==="AbortError")return{ret:0,msgs:[],get_updates_buf:e.get_updates_buf};throw r}}var et=new Set([-2,-3]),K=3,tt=1e3;async function F(e){let t=(await import("./logger-QCJUU7GV.js")).getLogger("channels");for(let r=1;r<=K;r++){let s=await N({baseUrl:e.baseUrl,endpoint:"ilink/bot/sendmessage",body:JSON.stringify({...e.body,base_info:O()}),token:e.token,routeTag:e.routeTag,timeoutMs:e.timeoutMs??ue,label:"sendMessage"});t.info({status:200,responseBody:s.slice(0,300)},"apiFetch sendMessage response");try{let n=JSON.parse(s);if(n.ret&&n.ret!==0){if(et.has(n.ret)&&r<K){t.warn({ret:n.ret,attempt:r,maxRetries:K},"sendMessage: transient iLink error, retrying"),await new Promise(i=>setTimeout(i,tt*r));continue}throw t.error({ret:n.ret,errmsg:n.errmsg,attempt:r},"sendMessage: iLink API returned non-zero ret"),new Error(`sendMessage failed: iLink ret=${n.ret}${n.errmsg?` errmsg=${n.errmsg}`:""}`)}}catch(n){if(n instanceof SyntaxError)t.warn({rawText:s.slice(0,200),attempt:r},"sendMessage: non-JSON response, treating as success");else throw n}return}}async function pe(e){await N({baseUrl:e.baseUrl,endpoint:"ilink/bot/sendtyping",body:JSON.stringify({...e.body,base_info:O()}),token:e.token,routeTag:e.routeTag,timeoutMs:e.timeoutMs??Xe,label:"sendTyping"})}async function me(e){let t=await N({baseUrl:e.baseUrl,endpoint:"ilink/bot/getuploadurl",body:JSON.stringify({filekey:e.filekey,media_type:e.media_type,to_user_id:e.to_user_id,rawsize:e.rawsize,rawfilemd5:e.rawfilemd5,filesize:e.filesize,thumb_rawsize:e.thumb_rawsize,thumb_rawfilemd5:e.thumb_rawfilemd5,thumb_filesize:e.thumb_filesize,no_need_thumb:e.no_need_thumb,aeskey:e.aeskey,base_info:O()}),token:e.token,routeTag:e.routeTag,timeoutMs:e.timeoutMs??ue,label:"getUploadUrl"});return JSON.parse(t)}var nt=5*6e4,rt=35e3,ye="3",h=new Map;function X(e){return Date.now()-e.startedAt<nt}function it(){for(let[e,t]of h)X(t)||h.delete(e)}async function he(e,t,r){let s=e.endsWith("/")?e:`${e}/`,n=new URL(`ilink/bot/get_bot_qrcode?bot_type=${encodeURIComponent(t)}`,s),i={"iLink-App-Id":v};r&&(i.SKRouteTag=r);let o=await fetch(n.toString(),{headers:i});if(!o.ok){let a=await o.text().catch(()=>"(unreadable)");throw new Error(`Failed to fetch QR code: ${o.status} ${o.statusText} body=${a}`)}return await o.json()}async function st(e,t,r){let s=e.endsWith("/")?e:`${e}/`,n=new URL(`ilink/bot/get_qrcode_status?qrcode=${encodeURIComponent(t)}`,s),i={"iLink-App-Id":v,"iLink-App-ClientVersion":String(H)};r&&(i.SKRouteTag=r);let o=new AbortController,a=setTimeout(()=>o.abort(),rt);try{let c=await fetch(n.toString(),{headers:i,signal:o.signal});clearTimeout(a);let l=await c.text();if(!c.ok)throw new Error(`Failed to poll QR status: ${c.status} ${c.statusText}`);return JSON.parse(l)}catch(c){if(clearTimeout(a),c instanceof Error&&c.name==="AbortError")return{status:"wait"};throw c}}async function be(e){let t=e.accountId||fe();it();let r=h.get(t);if(!e.force&&r&&X(r)&&r.qrcodeUrl)return{qrcodeUrl:r.qrcodeUrl,message:"QR code ready. Scan with WeChat.",sessionKey:t};if(!e.apiBaseUrl)return{message:"No baseUrl configured for this WeChat channel.",sessionKey:t};try{let s=e.botType||ye,n=await he(e.apiBaseUrl,s,e.routeTag),i={sessionKey:t,id:fe(),qrcode:n.qrcode,qrcodeUrl:n.qrcode_img_content,startedAt:Date.now()};return h.set(t,i),{qrcodeUrl:n.qrcode_img_content,message:"Scan the QR code with WeChat to connect.",sessionKey:t}}catch(s){return{message:`Failed to start login: ${String(s)}`,sessionKey:t}}}var ot=3;async function _e(e){let t=h.get(e.sessionKey);if(!t)return{connected:!1,message:"No active login session. Start QR login first."};if(!X(t))return h.delete(e.sessionKey),{connected:!1,message:"QR code expired. Please start again."};let r=Math.max(e.timeoutMs??48e4,1e3),s=Date.now()+r,n=1;for(;Date.now()<s;){try{let i=await st(e.apiBaseUrl,t.qrcode,e.routeTag);switch(t.status=i.status,i.status){case"wait":break;case"scaned":break;case"expired":{if(n++,n>ot)return h.delete(e.sessionKey),{connected:!1,message:"Login timeout: QR expired multiple times."};try{let o=e.botType||ye,a=await he(e.apiBaseUrl,o,e.routeTag);t.qrcode=a.qrcode,t.qrcodeUrl=a.qrcode_img_content,t.startedAt=Date.now()}catch(o){return h.delete(e.sessionKey),{connected:!1,message:`QR refresh failed: ${String(o)}`}}break}case"confirmed":return i.ilink_bot_id?(h.delete(e.sessionKey),{connected:!0,botToken:i.bot_token,accountId:i.ilink_bot_id,baseUrl:i.baseurl,userId:i.ilink_user_id,message:"Connected to WeChat successfully!"}):(h.delete(e.sessionKey),{connected:!1,message:"Login failed: server did not return bot ID."})}}catch(i){return h.delete(e.sessionKey),{connected:!1,message:`Login failed: ${String(i)}`}}await new Promise(i=>setTimeout(i,1e3))}return h.delete(e.sessionKey),{connected:!1,message:"Login timeout. Please try again."}}import M,{promises as A}from"fs";import x from"path";import{homedir as re}from"os";var $={IMAGE:1,VIDEO:2,FILE:3,VOICE:4},L={NONE:0,USER:1,BOT:2},m={NONE:0,TEXT:1,IMAGE:2,VOICE:3,FILE:4,VIDEO:5},D={NEW:0,GENERATING:1,FINISH:2},we={TYPING:1,CANCEL:2};T();var at=f("channels"),J=-14,B=3600*1e3,R=new Map;function xe(e){let t=Date.now()+B;R.set(e,t),at.info({channelId:e},`Session paused until ${new Date(t).toISOString()} (${B/1e3}s)`)}function W(e){let t=R.get(e);return t===void 0?!1:Date.now()>=t?(R.delete(e),!1):!0}function Ie(e){let t=R.get(e);if(t===void 0)return 0;let r=t-Date.now();return r<=0?(R.delete(e),0):r}function Te(e){R.delete(e)}T();import ve from"fs";import Oe from"path";import{homedir as ft}from"os";import{createCipheriv as dt,createDecipheriv as ct}from"crypto";function Ue(e,t){let r=dt("aes-128-ecb",t,null);return Buffer.concat([r.update(e),r.final()])}function ke(e,t){let r=ct("aes-128-ecb",t,null);return Buffer.concat([r.update(e),r.final()])}function Ce(e){return Math.ceil((e+1)/16)*16}function Y(e,t){return`${t}/download?encrypted_query_param=${encodeURIComponent(e)}`}function Me(e){return`${e.cdnBaseUrl}/upload?encrypted_query_param=${encodeURIComponent(e.uploadParam)}&filekey=${encodeURIComponent(e.filekey)}`}T();var Kt=f("channels");function lt(e){let t=Buffer.from(e,"base64");if(t.length===16)return t;if(t.length===32&&/^[0-9a-fA-F]{32}$/.test(t.toString("ascii")))return Buffer.from(t.toString("ascii"),"hex");throw new Error(`aes_key must decode to 16 raw bytes or 32-char hex, got ${t.length} bytes`)}async function Re(e){let t=await fetch(e);if(!t.ok)throw new Error(`CDN download ${t.status} ${t.statusText}`);return Buffer.from(await t.arrayBuffer())}async function E(e){let{encryptQueryParam:t,aesKeyBase64:r,cdnBaseUrl:s,fullUrl:n}=e,i=lt(r),o=n?.trim()||(t?Y(t,s):null);if(!o)throw new Error("CDN download: need full_url or encrypt_query_param");let a=await Re(o);return ke(a,i)}async function Ee(e){let{encryptQueryParam:t,cdnBaseUrl:r,fullUrl:s}=e,n=s?.trim()||(t?Y(t,r):null);if(!n)throw new Error("CDN download: need full_url or encrypt_query_param");return Re(n)}T();var q=f("channels"),Se=24e3;function ut(e,t){let r=e.byteLength,s=44+r,n=Buffer.allocUnsafe(s),i=0;return n.write("RIFF",i),i+=4,n.writeUInt32LE(s-8,i),i+=4,n.write("WAVE",i),i+=4,n.write("fmt ",i),i+=4,n.writeUInt32LE(16,i),i+=4,n.writeUInt16LE(1,i),i+=2,n.writeUInt16LE(1,i),i+=2,n.writeUInt32LE(t,i),i+=4,n.writeUInt32LE(t*2,i),i+=4,n.writeUInt16LE(2,i),i+=2,n.writeUInt16LE(16,i),i+=2,n.write("data",i),i+=4,n.writeUInt32LE(r,i),i+=4,Buffer.from(e.buffer,e.byteOffset,e.byteLength).copy(n,i),n}async function Pe(e){try{let{decode:t}=await import("silk-wasm");q.debug(`silkToWav: decoding ${e.length} bytes of SILK`);let r=await t(e,Se);q.debug(`silkToWav: decoded duration=${r.duration}ms pcmBytes=${r.data.byteLength}`);let s=ut(r.data,Se);return q.debug(`silkToWav: WAV size=${s.length}`),s}catch(t){return q.warn(`silkToWav: transcode failed, will use raw silk err=${String(t)}`),null}}import gt from"path";var pt={".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".csv":"text/csv",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".mp3":"audio/mpeg",".ogg":"audio/ogg",".wav":"audio/wav",".amr":"audio/amr",".silk":"audio/x-silk",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm",".mkv":"video/x-matroska",".avi":"video/x-msvideo",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".bmp":"image/bmp"},mt={"image/jpeg":".jpg","image/jpg":".jpg","image/png":".png","image/gif":".gif","image/webp":".webp","image/bmp":".bmp","video/mp4":".mp4","video/quicktime":".mov","video/webm":".webm","video/x-matroska":".mkv","video/x-msvideo":".avi","audio/mpeg":".mp3","audio/ogg":".ogg","audio/wav":".wav","audio/amr":".amr","audio/x-silk":".silk","application/pdf":".pdf","application/zip":".zip","application/x-tar":".tar","application/gzip":".gz","text/plain":".txt","text/csv":".csv"};function j(e){let t=gt.extname(e).toLowerCase();return pt[t]??"application/octet-stream"}function Ae(e){let t=e.split(";")[0].trim().toLowerCase();return mt[t]??".bin"}var C=f("channels"),Ne=100*1024*1024;function yt(e){return Ae(e)??".bin"}async function S(e,t,r,s,n=Ne,i){if(e.length>n)throw new Error(`Media too large: ${e.length} bytes exceeds ${n} bytes`);let o=Oe.join(ft(),".adam","wechat","media",s,r);await ve.promises.mkdir(o,{recursive:!0});let a;if(i&&/^[a-zA-Z0-9._-]+$/.test(i))a=i;else{let l=t?yt(t):".bin",d=Date.now(),u=Math.random().toString(36).slice(2,7);a=`${d}-${u}${l}`}let c=Oe.join(o,a);return await ve.promises.writeFile(c,e),C.debug(`saveMedia: saved ${e.length} bytes to ${c}`),c}async function Fe(e,t){let{cdnBaseUrl:r,channelId:s}=t;if(e.type===m.IMAGE){let n=e.image_item;if(!n?.media?.encrypt_query_param&&!n?.media?.full_url)return null;let i=n.aeskey?Buffer.from(n.aeskey,"hex").toString("base64"):n.media?.aes_key;try{let o=i?await E({encryptQueryParam:n.media?.encrypt_query_param,aesKeyBase64:i,cdnBaseUrl:r,fullUrl:n.media?.full_url}):await Ee({encryptQueryParam:n.media?.encrypt_query_param,cdnBaseUrl:r,fullUrl:n.media?.full_url});return{path:await S(o,"image/png","inbound",s),mimeType:"image/png",type:"image"}}catch(o){return C.error({channelId:s},`Image download/decrypt failed: ${String(o)}`),null}}if(e.type===m.VOICE){let n=e.voice_item;if(!n?.media?.encrypt_query_param&&!n?.media?.full_url||!n?.media?.aes_key)return null;try{let i=await E({encryptQueryParam:n.media.encrypt_query_param,aesKeyBase64:n.media.aes_key,cdnBaseUrl:r,fullUrl:n.media.full_url}),o=await Pe(i);if(o){let a=await S(o,"audio/wav","inbound",s);return C.debug(`Voice: saved WAV to ${a}`),{path:a,mimeType:"audio/wav",type:"audio"}}else{let a=await S(i,"audio/silk","inbound",s);return C.debug(`Voice: silk transcode unavailable, saved raw SILK to ${a}`),{path:a,mimeType:"audio/silk",type:"audio"}}}catch(i){return C.error({channelId:s},`Voice download/transcode failed: ${String(i)}`),null}}if(e.type===m.FILE){let n=e.file_item;if(!n?.media?.encrypt_query_param&&!n?.media?.full_url||!n?.media?.aes_key)return null;try{let i=await E({encryptQueryParam:n.media.encrypt_query_param,aesKeyBase64:n.media.aes_key,cdnBaseUrl:r,fullUrl:n.media.full_url}),o=j(n.file_name??"file.bin");return{path:await S(i,o,"inbound",s,Ne,n.file_name),mimeType:o,type:"file"}}catch(i){return C.error({channelId:s},`File download failed: ${String(i)}`),null}}if(e.type===m.VIDEO){let n=e.video_item;if(!n?.media?.encrypt_query_param&&!n?.media?.full_url||!n?.media?.aes_key)return null;try{let i=await E({encryptQueryParam:n.media.encrypt_query_param,aesKeyBase64:n.media.aes_key,cdnBaseUrl:r,fullUrl:n.media.full_url});return{path:await S(i,"video/mp4","inbound",s),mimeType:"video/mp4",type:"video"}}catch(i){return C.error({channelId:s},`Video download failed: ${String(i)}`),null}}return null}import De from"path";import Z from"crypto";import ht from"fs/promises";T();var U=f("channels"),V=3;async function bt(e){let{buf:t,uploadFullUrl:r,uploadParam:s,filekey:n,cdnBaseUrl:i,label:o,aeskey:a}=e,c=Ue(t,a),l=r?.trim(),d;if(l)d=l;else if(s)d=Me({cdnBaseUrl:i,uploadParam:s,filekey:n});else throw new Error(`${o}: CDN upload URL missing (need upload_full_url or upload_param)`);U.debug(`${o}: CDN POST url=${d} ciphertextSize=${c.length}`);let u,y;for(let b=1;b<=V;b++)try{let p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/octet-stream"},body:new Uint8Array(c)});if(p.status>=400&&p.status<500){let I=p.headers.get("x-error-message")??await p.text();throw U.error(`${o}: CDN client error attempt=${b} status=${p.status} errMsg=${I}`),new Error(`CDN upload client error ${p.status}: ${I}`)}if(p.status!==200){let I=p.headers.get("x-error-message")??`status ${p.status}`;throw U.error(`${o}: CDN server error attempt=${b} status=${p.status} errMsg=${I}`),new Error(`CDN upload server error: ${I}`)}if(u=p.headers.get("x-encrypted-param")??void 0,!u)throw U.error(`${o}: CDN response missing x-encrypted-param header attempt=${b}`),new Error("CDN upload response missing x-encrypted-param header");U.debug(`${o}: CDN upload success attempt=${b}`);break}catch(p){if(y=p,p instanceof Error&&p.message.includes("client error"))throw p;b<V?U.warn(`${o}: attempt ${b} failed, retrying... err=${String(p)}`):U.error(`${o}: all ${V} attempts failed err=${String(p)}`)}if(!u)throw y instanceof Error?y:new Error(`CDN upload failed after ${V} attempts`);return{downloadParam:u}}async function ee(e){let{filePath:t,toUserId:r,opts:s,cdnBaseUrl:n,mediaType:i,label:o}=e,a=await ht.readFile(t),c=a.length,l=Z.createHash("md5").update(a).digest("hex"),d=Ce(c),u=Z.randomBytes(16).toString("hex"),y=Z.randomBytes(16);U.debug(`${o}: file=${t} rawsize=${c} filesize=${d} md5=${l} filekey=${u}`);let b=await me({...s,filekey:u,media_type:i,to_user_id:r,rawsize:c,rawfilemd5:l,filesize:d,no_need_thumb:!0,aeskey:y.toString("hex")}),p=b.upload_full_url?.trim(),I=b.upload_param;if(!p&&!I)throw new Error(`${o}: getUploadUrl returned no upload URL (need upload_full_url or upload_param)`);let{downloadParam:Ge}=await bt({buf:a,uploadFullUrl:p||void 0,uploadParam:I??void 0,filekey:u,cdnBaseUrl:n,aeskey:y,label:`${o}[orig filekey=${u}]`});return{filekey:u,downloadEncryptedQueryParam:Ge,aeskey:y.toString("hex"),fileSize:c,fileSizeCiphertext:d}}async function $e(e){return ee({...e,mediaType:$.IMAGE,label:"uploadImageToWeixin"})}async function Le(e){return ee({...e,mediaType:$.VIDEO,label:"uploadVideoToWeixin"})}async function te(e){return ee({...e,mediaType:$.FILE,label:"uploadFileAttachmentToWeixin"})}T();var P=f("channels");function _t(){return`adam-wechat-${Date.now()}-${Math.random().toString(36).slice(2,7)}`}function wt(e){let t=e;return t=t.replace(/```[^\n]*\n?([\s\S]*?)```/g,(r,s)=>s.trim()),t=t.replace(/!\[[^\]]*\]\([^)]*\)/g,""),t=t.replace(/\[([^\]]+)\]\([^)]*\)/g,"$1"),t=t.replace(/^\|[\s:|-]+\|$/gm,""),t=t.replace(/^\|(.+)\|$/gm,(r,s)=>s.split("|").map(n=>n.trim()).join(" ")),t}async function ne(e){let{to:t,text:r,mediaItem:s,opts:n,label:i}=e,o=[],a=wt(r);a&&o.push({type:m.TEXT,text_item:{text:a}}),o.push(s);let c="";for(let l of o){c=_t();let d={msg:{from_user_id:"",to_user_id:t,client_id:c,message_type:L.BOT,message_state:D.FINISH,item_list:[l],context_token:n.contextToken}};await F({baseUrl:n.baseUrl,token:n.token,routeTag:n.routeTag,body:d})}return P.debug(`${i}: sent to=${t} messageId=${c}`),{messageId:c}}async function xt(e){let{to:t,text:r,uploaded:s,opts:n}=e,i={type:m.IMAGE,image_item:{media:{encrypt_query_param:s.downloadEncryptedQueryParam,aes_key:Buffer.from(s.aeskey).toString("base64"),encrypt_type:1},mid_size:s.fileSizeCiphertext}};return ne({to:t,text:r,mediaItem:i,opts:n,label:"sendImageMessage"})}async function It(e){let{to:t,text:r,uploaded:s,opts:n}=e,i={type:m.VIDEO,video_item:{media:{encrypt_query_param:s.downloadEncryptedQueryParam,aes_key:Buffer.from(s.aeskey).toString("base64"),encrypt_type:1},video_size:s.fileSizeCiphertext}};return ne({to:t,text:r,mediaItem:i,opts:n,label:"sendVideoMessage"})}async function Be(e){let{to:t,text:r,fileName:s,uploaded:n,opts:i}=e,o={type:m.FILE,file_item:{media:{encrypt_query_param:n.downloadEncryptedQueryParam,aes_key:Buffer.from(n.aeskey).toString("base64"),encrypt_type:1},file_name:s,len:String(n.fileSize)}};return ne({to:t,text:r,mediaItem:o,opts:i,label:"sendFileMessage"})}async function We(e){let{filePath:t,to:r,text:s,opts:n,cdnBaseUrl:i}=e,o=j(t),a={baseUrl:n.baseUrl,token:n.token,routeTag:n.routeTag};if(o.startsWith("video/")){P.debug(`sendWeixinMediaFile: uploading video filePath=${t} to=${r}`);let d=await Le({filePath:t,toUserId:r,opts:a,cdnBaseUrl:i});return It({to:r,text:s,uploaded:d,opts:n})}if(o.startsWith("image/")){P.debug(`sendWeixinMediaFile: uploading image filePath=${t} to=${r}`);let d=await $e({filePath:t,toUserId:r,opts:a,cdnBaseUrl:i});return xt({to:r,text:s,uploaded:d,opts:n})}if(o.startsWith("audio/")){let d=De.basename(t);P.debug(`sendWeixinMediaFile: uploading audio as file filePath=${t} name=${d} to=${r}`);let u=await te({filePath:t,fileName:d,toUserId:r,opts:a,cdnBaseUrl:i});return Be({to:r,text:s,fileName:d,uploaded:u,opts:n})}let c=De.basename(t);P.debug(`sendWeixinMediaFile: uploading file attachment filePath=${t} name=${c} to=${r}`);let l=await te({filePath:t,fileName:c,toUserId:r,opts:a,cdnBaseUrl:i});return Be({to:r,text:s,fileName:c,uploaded:l,opts:n})}T();var w=f("channels"),qe="https://novac2c.cdn.weixin.qq.com/c2c",ie=new Map;function Ve(e){return x.join(re(),".adam","wechat",`${e}.context-tokens.json`)}function Tt(e){let t=Ve(e);try{let r=M.readFileSync(t,"utf-8"),s=JSON.parse(r);for(let[n,i]of Object.entries(s))typeof i=="string"&&i&&ie.set(`${e}:${n}`,i);w.debug({channelId:e,count:Object.keys(s).length},"Restored context tokens from disk")}catch{}}function Ut(e,t,r){let s=Ve(e);try{let n={};try{let o=M.readFileSync(s,"utf-8");n=JSON.parse(o)}catch{}n[t]=r;let i=x.dirname(s);M.mkdirSync(i,{recursive:!0}),M.writeFileSync(s,JSON.stringify(n),"utf-8")}catch(n){w.warn({channelId:e,userId:t},`Failed to persist context token: ${String(n)}`)}}function kt(e,t,r){ie.set(`${e}:${t}`,r),Ut(e,t,r)}function je(e,t){return ie.get(`${e}:${t}`)}function ze(e){return x.join(re(),".adam","wechat",`${e}.sync`)}function Ct(e){try{return M.readFileSync(ze(e),"utf-8")}catch{return""}}function Mt(e,t){let r=ze(e);M.mkdirSync(x.dirname(r),{recursive:!0}),M.writeFileSync(r,t,"utf-8")}var Rt=0;function Et(){return`adam-wechat-${Date.now()}-${++Rt}`}var z=class{platform="wechat";id;config;status="disconnected";messageHandler=null;pollAbort=null;getUpdatesBuf="";constructor(t,r){if(this.id=t,!r.baseUrl)throw new Error("WeChat adapter requires baseUrl");this.config=r}async connect(){if(!this.config.botToken)throw new Error("WeChat adapter requires botToken. Complete QR login first.");this.status="connecting",this.getUpdatesBuf=Ct(this.id),Tt(this.id),this.pollAbort=new AbortController,this.status="connected",w.info({channelId:this.id},"WeChat adapter connected, starting long-poll"),this.startLongPoll()}async disconnect(){this.pollAbort&&(this.pollAbort.abort(),this.pollAbort=null),this.status="disconnected",w.info({channelId:this.id},"WeChat adapter disconnected")}getStatus(){return this.status==="connected"&&W(this.id)?"error":this.status}async sendMessage(t,r){if(W(this.id)){let o=Math.ceil(Ie(this.id)/6e4);throw new Error(`WeChat session paused, ${o} min remaining. Re-scan QR to reconnect.`)}let s=Et(),n=je(this.id,t),i=this.config.cdnBaseUrl??qe;if(r.mediaUrl)try{let o=!r.mediaUrl.includes("://")||r.mediaUrl.startsWith("file://"),a=x.join(re(),".adam","wechat","media","outbound-tmp");await A.mkdir(a,{recursive:!0});let c=this.getExtensionFromMediaType(r.mediaType),l;if(o){let u=r.mediaUrl.startsWith("file://")?new URL(r.mediaUrl).pathname:x.isAbsolute(r.mediaUrl)?r.mediaUrl:x.resolve(r.mediaUrl),y=await A.readFile(u);l=x.join(a,`${Date.now()}-${Math.random().toString(36).slice(2,7)}${c}`),await A.writeFile(l,y)}else{let u=await fetch(r.mediaUrl);if(!u.ok)throw new Error(`Failed to fetch media: ${u.status}`);let y=Buffer.from(await u.arrayBuffer());l=x.join(a,`${Date.now()}-${Math.random().toString(36).slice(2,7)}${c}`),await A.writeFile(l,y)}let d=await We({filePath:l,to:t,text:r.content??"",opts:{baseUrl:this.config.baseUrl,token:this.config.botToken,routeTag:this.config.routeTag,contextToken:n},cdnBaseUrl:i});return await A.unlink(l).catch(()=>{}),d.messageId}catch(o){throw w.error({channelId:this.id},`sendMessage media handling failed: ${String(o)}`),o}return await F({baseUrl:this.config.baseUrl,token:this.config.botToken,routeTag:this.config.routeTag,body:{msg:{from_user_id:"",to_user_id:t,client_id:s,message_type:L.BOT,message_state:D.FINISH,item_list:r.content?[{type:m.TEXT,text_item:{text:r.content}}]:void 0,context_token:n}}}),s}onMessage(t){this.messageHandler=t}async sendTypingIndicator(t){if(W(this.id))return;let r=je(this.id,t);try{await pe({baseUrl:this.config.baseUrl,token:this.config.botToken,routeTag:this.config.routeTag,body:{ilink_user_id:t,status:we.TYPING}})}catch{}}updateConfig(t){Object.assign(this.config,t)}async startLongPoll(){let t=this.pollAbort?.signal,r=0,s=3,n=3e4,i=2e3;for(;!t?.aborted;)try{let o=await ge({baseUrl:this.config.baseUrl,token:this.config.botToken,routeTag:this.config.routeTag,get_updates_buf:this.getUpdatesBuf});if(o.ret===J||o.errcode===J){xe(this.id),this.status="error",w.error({channelId:this.id},"Session expired (errcode=-14), pausing for 1 hour"),await this.sleep(B,t),Te(this.id),this.status="connected";continue}if(o.ret!==void 0&&o.ret!==0||o.errcode!==void 0&&o.errcode!==0){r++,w.error({channelId:this.id,ret:o.ret,errcode:o.errcode},"getUpdates API error"),r>=s?(r=0,await this.sleep(n,t)):await this.sleep(i,t);continue}r=0,o.get_updates_buf&&(this.getUpdatesBuf=o.get_updates_buf,Mt(this.id,o.get_updates_buf));for(let c of o.msgs??[])await this.processInbound(c)}catch(o){if(t?.aborted)return;r++,w.error({channelId:this.id,error:o},"getUpdates error"),r>=s?(r=0,await this.sleep(n,t)):await this.sleep(i,t)}}async processInbound(t){if(!this.messageHandler)return;let r=!!t.group_id,s=r?t.group_id:t.from_user_id??"",n=t.from_user_id??"";t.context_token&&s&&kt(this.id,s,t.context_token);let i="",o,a=[];for(let d of t.item_list??[])d.type===m.TEXT&&d.text_item?.text&&(i+=d.text_item.text),d.type===m.IMAGE&&(o="image",a.push(d)),d.type===m.VOICE&&(o="audio",a.push(d),d.voice_item?.text&&!i&&(i=d.voice_item.text)),d.type===m.FILE&&(o="file",a.push(d)),d.type===m.VIDEO&&(o="video",a.push(d));if(!i&&!o)return;let c;if(a.length>0){let d=this.config.cdnBaseUrl??qe;try{let u=await Fe(a[0],{cdnBaseUrl:d,channelId:this.id});u&&(c=u.path,o=u.type)}catch(u){w.error({channelId:this.id},`Media download failed: ${String(u)}`)}}let l={channelId:this.id,platform:"wechat",chatId:s,senderId:n,content:i,mediaType:o,mediaPath:c,isGroup:r,timestamp:t.create_time_ms??Date.now(),raw:t};this.messageHandler(l)}getExtensionFromMediaType(t){switch(t){case"image":return".png";case"video":return".mp4";case"audio":return".mp3";default:return".bin"}}sleep(t,r){return new Promise((s,n)=>{let i=setTimeout(s,t);r?.addEventListener("abort",()=>{clearTimeout(i),n(new Error("aborted"))},{once:!0})})}};T();var St=f("channels"),G=class{platform="discord";id;config;status="disconnected";messageHandler=null;client=null;constructor(t,r){if(this.id=t,!r.botToken)throw new Error("Discord adapter requires botToken");this.config=r}async connect(){this.status="connecting";try{let{Client:t,GatewayIntentBits:r}=await import("discord.js");this.client=new t({intents:[r.Guilds,r.GuildMessages,r.MessageContent,r.DirectMessages]});let s=this.client;s.on("messageCreate",n=>{if(!this.messageHandler||n.author.bot||this.config.allowedGuildIds?.length&&n.guildId&&!this.config.allowedGuildIds.includes(n.guildId))return;let i={channelId:this.id,platform:"discord",chatId:n.channelId,senderId:n.author.id,senderName:n.author.displayName??n.author.username,content:n.content,isGroup:!!n.guildId,timestamp:n.createdTimestamp,raw:n};this.messageHandler(i)}),await s.login(this.config.botToken),this.status="connected",St.info({channelId:this.id},"Discord bot connected")}catch(t){throw this.status="error",t}}async disconnect(){this.client&&await this.client.destroy(),this.client=null,this.status="disconnected"}getStatus(){return this.status}async sendMessage(t,r){if(!this.client)throw new Error("Discord client not connected");let n=await this.client.channels.fetch(t);if(!n||!("send"in n))throw new Error(`Channel ${t} not found or not text channel`);return(await n.send({content:r.content,reply:r.replyToMessageId?{messageReference:r.replyToMessageId}:void 0})).id}onMessage(t){this.messageHandler=t}async sendTypingIndicator(t){if(!this.client)return;let s=await this.client.channels.fetch(t);s&&"sendTyping"in s&&await s.sendTyping()}};var k=g.object({id:g.string().uuid()}),At=g.object({name:g.string().min(1,"name is required"),platform:g.string().min(1,"platform is required"),config:g.record(g.string(),g.unknown()),enabled:g.boolean().optional().default(!0),linkedRoleId:g.string().optional(),allowedChatIds:g.array(g.string()).optional()}),vt=g.object({name:g.string().min(1).optional(),enabled:g.boolean().optional(),config:g.record(g.string(),g.unknown()).optional(),linkedRoleId:g.string().optional(),allowedChatIds:g.array(g.string()).optional()}),se;function zn(e){se=e}function Gn(){return se}async function Qn(e){let t=se;e.get("/channels",{schema:{tags:["Channels"],summary:"List channels",querystring:{type:"object",properties:{enabled:{type:"boolean"}}}}},async(r,s)=>({channels:de(r.query.enabled)})),e.post("/channels",{schema:{tags:["Channels"],summary:"Create a channel",body:{type:"object",required:["name","platform","config"],properties:{name:{type:"string",minLength:1},platform:{type:"string",minLength:1},config:{type:"object"},enabled:{type:"boolean"},linkedRoleId:{type:"string"},allowedChatIds:{type:"array",items:{type:"string"}}}}}},async(r,s)=>{let n=At.safeParse(r.body);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});let{name:i,platform:o,config:a,enabled:c,linkedRoleId:l,allowedChatIds:d}=n.data,u={id:Pt(),name:i,platform:o,enabled:c,status:"disconnected",config:a,linkedRoleId:l,allowedChatIds:d,createdAt:Date.now(),messageCount:0};return ae(u),s.status(201).send({channel:u})}),e.get("/channels/:id",{schema:{tags:["Channels"],summary:"Get channel by ID",params:{type:"object",required:["id"],properties:{id:{type:"string",format:"uuid"}}}}},async(r,s)=>{let n=k.safeParse(r.params);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});let i=_(n.data.id);return i?{channel:i}:s.status(404).send({code:"NOT_FOUND",message:"Channel not found"})}),e.patch("/channels/:id",{schema:{tags:["Channels"],summary:"Update channel",params:{type:"object",required:["id"],properties:{id:{type:"string",format:"uuid"}}},body:{type:"object",properties:{name:{type:"string"},enabled:{type:"boolean"},config:{type:"object"},linkedRoleId:{type:"string"},allowedChatIds:{type:"array",items:{type:"string"}}}}}},async(r,s)=>{let n=k.safeParse(r.params);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});let i=_(n.data.id);if(!i)return s.status(404).send({code:"NOT_FOUND",message:"Channel not found"});let o=vt.safeParse(r.body);return o.success?(Q(i.id,o.data),{channel:_(i.id)}):s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(o.error)})}),e.delete("/channels/:id",{schema:{tags:["Channels"],summary:"Delete channel",params:{type:"object",required:["id"],properties:{id:{type:"string",format:"uuid"}}}}},async(r,s)=>{let n=k.safeParse(r.params);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});let i=_(n.data.id);return i?(ce(i.id),s.status(204).send()):s.status(404).send({code:"NOT_FOUND",message:"Channel not found"})}),e.post("/channels/:id/connect",{schema:{tags:["Channels"],summary:"Connect channel",params:{type:"object",required:["id"],properties:{id:{type:"string",format:"uuid"}}}}},async(r,s)=>{let n=k.safeParse(r.params);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});if(!t)return s.status(501).send({code:"NOT_IMPLEMENTED",message:"Channel manager not initialized"});let i=_(n.data.id);if(!i)return s.status(404).send({code:"NOT_FOUND",message:"Channel not found"});if(!t.hasAdapter(i.id)&&i.platform==="discord"){let o=i.config;if(!o.botToken)return s.status(400).send({code:"MISSING_CONFIG",message:"Discord channel requires botToken in config"});let a=new G(i.id,{botToken:o.botToken});await t.addChannel(i,a)}if(!t.hasAdapter(i.id))return s.status(400).send({code:"NO_ADAPTER",message:"No adapter registered for this channel. Install the appropriate adapter first."});try{return await t.connectChannel(i.id),{channelId:i.id,status:"connected"}}catch(o){return s.status(500).send({code:"CONNECT_FAILED",message:String(o)})}}),e.post("/channels/:id/disconnect",{schema:{tags:["Channels"],summary:"Disconnect channel",params:{type:"object",required:["id"],properties:{id:{type:"string",format:"uuid"}}}}},async(r,s)=>{let n=k.safeParse(r.params);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});if(!t)return s.status(501).send({code:"NOT_IMPLEMENTED",message:"Channel manager not initialized"});let i=_(n.data.id);return i?(await t.disconnectChannel(i.id),{channelId:i.id,status:"disconnected"}):s.status(404).send({code:"NOT_FOUND",message:"Channel not found"})}),e.get("/channels/:id/messages",{schema:{tags:["Channels"],summary:"Get channel message history",params:{type:"object",required:["id"],properties:{id:{type:"string",format:"uuid"}}},querystring:{type:"object",properties:{limit:{type:"integer",minimum:1,maximum:200,default:50},offset:{type:"integer",minimum:0,default:0}}}}},async(r,s)=>{let n=k.safeParse(r.params);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});let i=_(n.data.id);if(!i)return s.status(404).send({code:"NOT_FOUND",message:"Channel not found"});let{limit:o=50,offset:a=0}=r.query;return{messages:oe(i.id,o,a)}}),e.post("/channels/:id/wechat/qr-start",{schema:{tags:["WeChat"],summary:"Start WeChat QR login",params:{type:"object",required:["id"],properties:{id:{type:"string",format:"uuid"}}}}},async(r,s)=>{let n=k.safeParse(r.params);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});let i=_(n.data.id);if(!i)return s.status(404).send({code:"NOT_FOUND",message:"Channel not found"});if(i.platform!=="wechat")return s.status(400).send({code:"INVALID_PLATFORM",message:"Channel is not a WeChat channel"});let o=i.config;return await be({apiBaseUrl:o.baseUrl,routeTag:o.routeTag})}),e.post("/channels/:id/wechat/qr-wait",{schema:{tags:["WeChat"],summary:"Wait for WeChat QR scan",params:{type:"object",required:["id"],properties:{id:{type:"string",format:"uuid"}}},body:{type:"object",properties:{sessionKey:{type:"string"},timeoutMs:{type:"number"}}}}},async(r,s)=>{let n=k.safeParse(r.params);if(!n.success)return s.status(400).send({code:"VALIDATION_ERROR",message:g.prettifyError(n.error)});let i=_(n.data.id);if(!i)return s.status(404).send({code:"NOT_FOUND",message:"Channel not found"});if(i.platform!=="wechat")return s.status(400).send({code:"INVALID_PLATFORM",message:"Channel is not a WeChat channel"});let o=i.config,{sessionKey:a,timeoutMs:c}=r.body??{},l=await _e({sessionKey:a??"",apiBaseUrl:o.baseUrl,timeoutMs:c??12e4,routeTag:o.routeTag});if(l.connected&&l.botToken){let d={...o,botToken:l.botToken,accountId:l.accountId,baseUrl:l.baseUrl??o.baseUrl,userId:l.userId};if(Q(i.id,{config:d}),t){let u=new z(i.id,d),y=_(i.id);y&&await t.addChannel(y,u)}}return{connected:l.connected,accountId:l.accountId,message:l.message}})}export{z as a,G as b,zn as c,Gn as d,Qn as e};
|
package/dist/chunk-NQHTOFQP.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as R}from"./chunk-BCELBB5Q.js";import{f as E}from"./chunk-GA7GEIXB.js";import{b as g}from"./chunk-ROSOI75V.js";import{b as v}from"./chunk-BONI2HUN.js";import{e as m}from"./chunk-4TBGFHYX.js";import{b as x}from"./chunk-64FIXWFL.js";import{a as w,b as k,c as o,d as h,e as T,f as P,g as S}from"./chunk-TEMWI6U5.js";import{a as f}from"./chunk-L7JP7DUO.js";import{c as D,h as C}from"./chunk-INNDBLZE.js";C();import{v4 as _}from"uuid";var s=D("admin"),y=new Map,u=null,p=null,c=null,I=class{constructor(){f.on("task_status_change",e=>{(e.newStatus==="completed"||e.newStatus==="failed")&&this.handleTaskStatusChange(e.taskId,e.newStatus).catch(n=>{s.error({taskId:e.taskId,error:n},"Delivery processing failed")})}),f.on("plan_approval_request",e=>{this.handlePlanApprovalRequest(e.taskId,e.planId,e.plan).catch(n=>{s.error({taskId:e.taskId,error:n},"Delivery processing failed (plan_approval)")})}),s.info("DeliveryEngine initialized")}async handlePlanApprovalRequest(e,n,r){let t=g(e),i=this.getSourceChannelForTask(e);if(i){let d=JSON.stringify(r).slice(0,500),{sendApprovalToChannel:b}=await import("./approval-handler-UDWAC5MF.js");await b(i.channelId,i.chatId,n,e,d)}let a=`Plan approval requested for task ${e}: ${JSON.stringify(r).slice(0,500)}`;await this.matchAndDeliver("plan_approval_request",{templateId:t?.templateId,roleId:t?.roleId,prompt:t?.prompt,taskStatus:"pending"},a,e)}getSourceChannelForTask(e){try{let n=m(e);if(!n)return null;let r=v(n.sessionId);return!r||r.source.type!=="channel"||!r.source.channelId||!r.source.chatId?null:{channelId:r.source.channelId,chatId:r.source.chatId}}catch{return null}}async handleTaskStatusChange(e,n){let r=g(e);if(!r)return;let t={templateId:r.templateId,roleId:r.roleId,prompt:r.prompt,taskStatus:n},i=n==="completed"?"task_complete":"task_error",a=r.result??r.error??"";await this.matchAndDeliver(i,t,a,e)}async matchAndDeliver(e,n,r,t){let i=E(e,n);if(i.length!==0){s.debug({eventType:e,ruleCount:i.length,taskId:t},"Matched delivery rules");for(let a of i){if(!this.checkRateLimit(a)){s.warn({ruleId:a.id,maxPerMinute:a.maxPerMinute},"Delivery rate limit exceeded, skipping");continue}if(a.skipOriginChannel&&a.target.type==="channel"&&t&&this.isOriginChannel(t,a.target))continue;let d={id:_(),ruleId:a.id,taskId:t,status:"pending",target:a.target,content:r,attempts:0,createdAt:Date.now(),expiresAt:Date.now()+w,source:"rule"};k(d),await this.attemptDelivery(d,a)}}}async attemptDeliveryPublic(e,n){return this.attemptDelivery(e,n)}async attemptDelivery(e,n){let r=R();try{if(e.target.type==="channel"){let t=e.target.chatId;!t&&e.target.channelId&&(t=x(e.target.channelId)?.config?.userId);let i=await r.send({taskId:e.taskId,channelId:e.target.channelId,chatId:t,content:e.content,messageType:"deliver"});i.success?(h(e.id),s.info({entryId:e.id,ruleId:n.id,targetType:"channel"},"Delivery successful")):o(e.id,"failed",i.error??"Gateway returned failure")}else if(e.target.type==="webhook"){let t=await r.send({taskId:e.taskId,webhookUrl:e.target.webhookUrl,content:e.content,messageType:"deliver"});t.success?(h(e.id),s.info({entryId:e.id,ruleId:n.id,targetType:"webhook"},"Webhook delivery successful")):o(e.id,"failed",t.error??"Gateway returned failure")}}catch(t){let i=t instanceof Error?t.message:String(t);o(e.id,"failed",i),s.warn({entryId:e.id,error:i},"Delivery attempt failed")}}checkRateLimit(e){let n=Date.now(),r=6e4,t=y.get(e.id);t||(t=[],y.set(e.id,t));let i=n-r;for(;t.length>0&&t[0]<i;)t.shift();return t.length>=e.maxPerMinute?!1:(t.push(n),!0)}isOriginChannel(e,n){try{if(n.type!=="channel"||!n.channelId)return!1;let r=m(e);if(!r)return!1;let t=v(r.sessionId);return t?t.source.type==="channel"&&t.source.channelId===n.channelId&&(!n.chatId||t.source.chatId===n.chatId):!1}catch{return!1}}async retryPending(){let e=T("rule",50),n=P("rule",50),r=[...e,...n];if(r.length!==0){s.debug({count:r.length},"Retrying pending/failed deliveries");for(let t of r){if(t.attempts>=3){o(t.id,"failed","Max retries (3) exceeded");continue}let i={id:t.ruleId??"retry-synthetic",eventType:"*",matchCriteria:{},target:t.target,maxPerMinute:5,skipOriginChannel:!0,enabled:!0,createdAt:0};await this.attemptDelivery(t,i)}}}};function U(){return c}function W(){c||(c=new I,u=setInterval(()=>{c?.retryPending().catch(l=>{s.error({error:l},"Delivery retry scan failed")})},6e4),p=setInterval(()=>{try{let l=S();l>0&&s.info({cleaned:l},"Expired delivery log entries cleaned up")}catch(l){s.error({error:l},"Delivery cleanup failed")}},36e5),s.info("DeliveryEngine started with retry (60s) and cleanup (1h) timers"))}function $(){u&&(clearInterval(u),u=null),p&&(clearInterval(p),p=null),c=null,y.clear(),s.info("DeliveryEngine stopped")}export{I as a,U as b,W as c,$ as d};
|
package/dist/chunk-REKCZ3GY.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var c=["defaults.model","defaults.effort","defaults.maxTurns","defaults.maxBudgetUsd","defaults.timeout","logging.level","roles.evolution.triggerEvery","roles.evolution.reflectionThreshold","chat.sessionTimeoutMinutes","chat.maxSessionTurns","chat.autoTitle","chat.archiveExtractMemory","server.timezone","anthropic.apiKey","anthropic.baseUrl","anthropic.model","anthropic.defaultOpusModel","anthropic.defaultSonnetModel","anthropic.defaultHaikuModel","anthropic.smallFastModel","defaults.approvalTimeout","defaults.deniedReadPaths","defaults.approvalRequired"],f=["server.port","server.host","server.apiKey"],d={"anthropic.apiKey":"ANTHROPIC_API_KEY","anthropic.baseUrl":"ANTHROPIC_BASE_URL","anthropic.model":"ANTHROPIC_MODEL","anthropic.defaultOpusModel":"ANTHROPIC_DEFAULT_OPUS_MODEL","anthropic.defaultSonnetModel":"ANTHROPIC_DEFAULT_SONNET_MODEL","anthropic.defaultHaikuModel":"ANTHROPIC_DEFAULT_HAIKU_MODEL","anthropic.smallFastModel":"ANTHROPIC_SMALL_FAST_MODEL"},i=null;function v(t){i=JSON.parse(JSON.stringify(t))}function a(){if(!i)throw new Error("Runtime config not initialized. Call initRuntimeConfig first.");return i}function T(t){let o=a(),s=t();for(let[n,e]of Object.entries(s))l(o,n,e)}function k(){let t=a(),o={};for(let[s,n]of Object.entries(d)){let e=g(t,s);e&&typeof e=="string"&&e.length>0?o[n]=e:process.env[n]&&(o[n]=process.env[n])}return o}function A(t,o){let s=a(),n=[],e=[];for(let[r,u]of Object.entries(t)){if(!p(r)){h(r)?e.push(`"${r}" requires restart. Cannot modify at runtime.`):e.push(`"${r}" is not a recognized config path.`);continue}l(s,r,u)&&(n.push(r),o?.(r,u))}return{success:e.length===0,updated:n,errors:e}}function l(t,o,s){let n=o.split("."),e=t;for(let r=0;r<n.length-1;r++)if(e&&typeof e=="object")e=e[n[r]];else return!1;return e&&typeof e=="object"?(e[n[n.length-1]]=s,!0):!1}function g(t,o){let s=o.split("."),n=t;for(let e of s)if(n&&typeof n=="object")n=n[e];else return;return n}function p(t){return c.includes(t)}function h(t){return f.includes(t)}export{c as a,f as b,v as c,a as d,T as e,k as f,A as g,g as h,p as i,h as j};
|
package/dist/chunk-U3XVAAXA.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import{d as o,h as p}from"./chunk-WBAPIPST.js";import{c as m,e as g}from"./chunk-FCV2DPZQ.js";var y={};g(y,{ensureRoleWorkspace:()=>h,getRoleWorkspacePath:()=>c,syncRoleSettings:()=>d,writeRoleCLAUDEmd:()=>u});import{mkdirSync as i,writeFileSync as a}from"fs";import{join as s,basename as f}from"path";function c(n){let e=f(n);if(e!==n||!n)throw new Error(`Invalid role name for workspace: ${n}`);return s(R,"roles",e)}function h(n){let e=c(n.name);return i(e,{recursive:!0}),i(s(e,".claude"),{recursive:!0}),u(e,n),d(n.id,n.allowedTools,e),e}function u(n,e){let r=e.learnedRules&&e.learnedRules.length>0?e.learnedRules.map(l=>`- ${l}`).join(`
|
|
2
|
-
`):"(no learned rules yet)",t=`# ${e.name}
|
|
3
|
-
|
|
4
|
-
${e.cagPrompt}
|
|
5
|
-
|
|
6
|
-
## Learned Rules
|
|
7
|
-
${r}
|
|
8
|
-
`;e.name==="chat-manager"&&(t+=`
|
|
9
|
-
|
|
10
|
-
## Compaction Instructions
|
|
11
|
-
When summarizing, preserve:
|
|
12
|
-
- Active task IDs and their current status
|
|
13
|
-
- User's pending requests not yet addressed
|
|
14
|
-
- Key decisions made and their rationale
|
|
15
|
-
- Role assignments and execution outcomes
|
|
16
|
-
- Channel/session routing context
|
|
17
|
-
`),a(s(n,"CLAUDE.md"),t,"utf-8")}function d(n,e,r){let t={};e&&(t.allowedTools=e),a(s(r,".claude","settings.json"),JSON.stringify(t,null,2),"utf-8")}var R,v=m(()=>{"use strict";p();R=process.env.ADAM_TEST_DIR||o});export{c as a,h as b,u as c,d,y as e,v as f};
|
package/dist/config-L4R273R3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as b,b as c,d,e}from"./chunk-3TIHZZMK.js";import{a}from"./chunk-6KLG4APZ.js";import"./chunk-REKCZ3GY.js";import"./chunk-WBAPIPST.js";import"./chunk-INNDBLZE.js";import"./chunk-FCV2DPZQ.js";export{a as DEFAULT_CONFIG,e as getChatConfig,d as getDefaults,b as loadConfig,c as loadDefaultConfig};
|
package/dist/engine-E67UAI3G.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c,d}from"./chunk-NQHTOFQP.js";import"./chunk-BCELBB5Q.js";import"./chunk-GA7GEIXB.js";import"./chunk-ROSOI75V.js";import"./chunk-BONI2HUN.js";import"./chunk-4TBGFHYX.js";import"./chunk-64FIXWFL.js";import"./chunk-TEMWI6U5.js";import"./chunk-L7JP7DUO.js";import"./chunk-CREHL4BN.js";import"./chunk-WBAPIPST.js";import"./chunk-INNDBLZE.js";import"./chunk-FCV2DPZQ.js";export{a as DeliveryEngine,b as getDeliveryEngine,c as initDeliveryEngine,d as stopDeliveryEngine};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c}from"./chunk-2C5U3CNX.js";import"./chunk-2CMR5AG7.js";import"./chunk-I5RUEOSQ.js";import"./chunk-FXFHGIY6.js";import"./chunk-QMKQBU3R.js";import"./chunk-CREHL4BN.js";import"./chunk-WBAPIPST.js";import"./chunk-INNDBLZE.js";import"./chunk-FCV2DPZQ.js";export{b as getRelevantMemoryContext,a as queryMemory,c as queryMemoryByTier};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c}from"./chunk-BCELBB5Q.js";import"./chunk-64FIXWFL.js";import"./chunk-TEMWI6U5.js";import"./chunk-L7JP7DUO.js";import"./chunk-CREHL4BN.js";import"./chunk-WBAPIPST.js";import"./chunk-INNDBLZE.js";import"./chunk-FCV2DPZQ.js";export{a as OutboundGateway,b as getOutboundGateway,c as isRecentlySent};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b}from"./chunk-XFTRKHH2.js";import"./chunk-U3XVAAXA.js";import"./chunk-FXFHGIY6.js";import"./chunk-QMKQBU3R.js";import"./chunk-CREHL4BN.js";import"./chunk-WBAPIPST.js";import"./chunk-INNDBLZE.js";import"./chunk-FCV2DPZQ.js";export{a as CHAT_MANAGER_ROLE_ID,b as initializeDefaultRoles};
|
package/dist/runtime-UCOE6LNN.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j}from"./chunk-REKCZ3GY.js";import"./chunk-FCV2DPZQ.js";export{a as MUTABLE_PATHS,b as RESTART_REQUIRED_PATHS,f as buildSdkAuthEnv,h as getNestedValue,d as getRuntimeConfig,c as initRuntimeConfig,i as isMutablePath,j as isRestartRequiredPath,e as loadPersistedConfig,g as updateMutableConfig};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}from"./chunk-YEV5YTS3.js";import"./chunk-BONI2HUN.js";import"./chunk-4TBGFHYX.js";import"./chunk-L7JP7DUO.js";import"./chunk-2CMR5AG7.js";import"./chunk-I5RUEOSQ.js";import"./chunk-3TIHZZMK.js";import"./chunk-6KLG4APZ.js";import"./chunk-REKCZ3GY.js";import"./chunk-FXFHGIY6.js";import"./chunk-QMKQBU3R.js";import"./chunk-CREHL4BN.js";import"./chunk-WBAPIPST.js";import"./chunk-INNDBLZE.js";import"./chunk-FCV2DPZQ.js";export{p as _resetForTest,e as archiveSession,b as createSession,g as deleteSession,c as getActiveSession,d as getSession,m as getTimeoutPollerInterval,i as incrementMessageCount,n as initSessionManager,j as listSessions,f as restoreSession,o as shutdownSessionManager,k as startTimeoutPoller,l as stopTimeoutPoller,h as touchSession,a as warmCache};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{Z as t}from"./vendor-icons-ZPvC5PUS.js";import{t as n}from"./vendor-react--nRVf2Ep.js";import{n as r}from"./dist-HyCSN_hp.js";var i=e(t(),1),a=n(),o=i.forwardRef(({className:e,padding:t=!0,...n},i)=>(0,a.jsx)(`div`,{ref:i,className:r(`rounded-lg border border-slate-800 bg-slate-900 text-slate-200 shadow-sm`,t&&`p-4`,e),...n}));o.displayName=`Card`;var s=i.forwardRef(({className:e,...t},n)=>(0,a.jsx)(`div`,{ref:n,className:r(`mb-3 flex items-center justify-between`,e),...t}));s.displayName=`CardHeader`;var c=i.forwardRef(({className:e,...t},n)=>(0,a.jsx)(`h3`,{ref:n,className:r(`text-sm font-medium text-slate-400`,e),...t}));c.displayName=`CardTitle`;var l=i.forwardRef(({className:e,...t},n)=>(0,a.jsx)(`p`,{ref:n,className:r(`text-xs text-slate-500`,e),...t}));l.displayName=`CardDescription`;var u=i.forwardRef(({className:e,...t},n)=>(0,a.jsx)(`div`,{ref:n,className:r(``,e),...t}));u.displayName=`CardContent`;var d=i.forwardRef(({className:e,...t},n)=>(0,a.jsx)(`div`,{ref:n,className:r(`flex items-center pt-2`,e),...t}));d.displayName=`CardFooter`;export{s as n,c as r,o as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{J as t,L as n,S as r,Z as i,_ as a,j as o}from"./vendor-icons-ZPvC5PUS.js";import{d as s,r as c,t as l}from"./vendor-react--nRVf2Ep.js";import{r as u}from"./dist-HyCSN_hp.js";import{t as d}from"./index-Ds41VvOC.js";import{n as f,r as p,t as m}from"./Card-BecEmnPW.js";import{n as h}from"./format-DvtQjPZn.js";var g=e(i(),1),_=l();function v(){let{id:e}=s(),[i,l]=(0,g.useState)(null),[v,b]=(0,g.useState)([]),[x,S]=(0,g.useState)([]),[C,w]=(0,g.useState)(null);if((0,g.useEffect)(()=>{e&&((async()=>{try{l((await u(`/channels/${e}`)).channel),w(null)}catch(e){w(e instanceof Error?e.message:`Failed to load channel`)}})(),u(`/delivery-rules`).then(t=>b(t.filter(t=>t.target.type===`channel`&&t.target.channelId===e))).catch(()=>b([])),u(`/delivery-rules`).then(async t=>{let n=t.filter(t=>t.target.type===`channel`&&t.target.channelId===e),r=[];for(let e of n.slice(0,3))try{let t=await u(`/delivery-rules/${e.id}/log`);r.push(...t.log??[])}catch{}r.sort((e,t)=>t.createdAt-e.createdAt),S(r.slice(0,20))}).catch(()=>S([])))},[e]),C)return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(c,{to:`/channels`,className:`flex items-center gap-1.5 text-sm text-slate-400 hover:text-slate-200`,children:[(0,_.jsx)(t,{size:14}),` Back to Channels`]}),(0,_.jsx)(m,{className:`text-center text-red-400`,children:C})]});if(!i)return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(c,{to:`/channels`,className:`flex items-center gap-1.5 text-sm text-slate-400 hover:text-slate-200`,children:[(0,_.jsx)(t,{size:14}),` Back to Channels`]}),(0,_.jsx)(m,{className:`text-center text-slate-500`,children:`Loading...`})]});let T=e=>e===`connected`?`success`:e===`connecting`?`warning`:e===`error`?`destructive`:`secondary`,E=e=>{switch(e){case`wechat`:return`WeChat`;case`telegram`:return`Telegram`;case`slack`:return`Slack`;case`discord`:return`Discord`;default:return e.charAt(0).toUpperCase()+e.slice(1)}},D={...i.config};for(let e of[`botToken`,`apiKey`,`secret`,`password`,`token`])e in D&&(D[e]=`********`);return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(c,{to:`/channels`,className:`flex items-center gap-1.5 text-sm text-slate-400 hover:text-slate-200`,children:[(0,_.jsx)(t,{size:14}),` Back to Channels`]}),(0,_.jsx)(m,{children:(0,_.jsx)(`div`,{className:`flex items-start justify-between gap-4`,children:(0,_.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,_.jsx)(d,{variant:T(i.status),children:i.status}),(0,_.jsx)(d,{variant:`outline`,children:E(i.platform)}),i.enabled?(0,_.jsx)(d,{variant:`success`,children:`enabled`}):(0,_.jsx)(d,{variant:`secondary`,children:`disabled`}),(0,_.jsx)(`span`,{className:`font-mono text-xs text-slate-500`,children:i.id})]}),(0,_.jsx)(`h2`,{className:`text-lg font-semibold text-slate-200`,children:i.name})]})})}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[(0,_.jsx)(y,{icon:n,label:`Created`,value:h(i.createdAt),mono:!0}),(0,_.jsx)(y,{icon:r,label:`Messages`,value:String(i.messageCount),mono:!0}),i.lastMessageAt&&(0,_.jsx)(y,{icon:n,label:`Last Message`,value:h(i.lastMessageAt),mono:!0}),i.linkedRoleId&&(0,_.jsx)(y,{icon:a,label:`Linked Role`,value:i.linkedRoleId.slice(0,8)+`...`,mono:!0})]}),(0,_.jsxs)(m,{children:[(0,_.jsx)(f,{children:(0,_.jsx)(p,{children:`Configuration`})}),(0,_.jsx)(`pre`,{className:`max-h-64 overflow-auto whitespace-pre-wrap rounded-md bg-slate-800 p-3 font-mono text-xs text-slate-300`,children:JSON.stringify(D,null,2)})]}),v.length>0&&(0,_.jsxs)(m,{children:[(0,_.jsx)(f,{children:(0,_.jsxs)(p,{className:`flex items-center gap-2`,children:[(0,_.jsx)(o,{size:14}),` Delivery Rules (`,v.length,`)`]})}),(0,_.jsx)(`div`,{className:`space-y-2`,children:v.map(e=>(0,_.jsxs)(`div`,{className:`rounded-md border border-slate-700 bg-slate-800/50 p-2`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(d,{variant:`outline`,children:e.eventType}),e.enabled?(0,_.jsx)(d,{variant:`success`,children:`active`}):(0,_.jsx)(d,{variant:`secondary`,children:`disabled`}),(0,_.jsxs)(`span`,{className:`text-xs text-slate-500`,children:[`max `,e.maxPerMinute,`/min`]})]}),(0,_.jsxs)(`p`,{className:`mt-1 text-xs text-slate-400 font-mono`,children:[`Rule: `,e.id]})]},e.id))})]}),x.length>0&&(0,_.jsxs)(m,{children:[(0,_.jsx)(f,{children:(0,_.jsxs)(p,{className:`flex items-center gap-2`,children:[(0,_.jsx)(r,{size:14}),` Delivery Log (`,x.length,`)`]})}),(0,_.jsx)(`div`,{className:`space-y-2`,children:x.slice(0,10).map(e=>(0,_.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-slate-800 p-2`,children:[(0,_.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,_.jsx)(`span`,{className:`text-sm text-slate-300 font-mono`,children:e.taskId.slice(0,8)}),(0,_.jsx)(`span`,{className:`text-xs text-slate-500 ml-2`,children:h(e.createdAt)})]}),(0,_.jsx)(d,{variant:e.status===`delivered`?`default`:e.status===`failed`?`destructive`:`outline`,children:e.status})]},e.id))})]})]})}function y({icon:e,label:t,value:n,mono:r}){return(0,_.jsxs)(m,{className:`flex flex-col gap-1`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-1.5 text-slate-500`,children:[(0,_.jsx)(e,{size:12}),(0,_.jsx)(`span`,{className:`text-xs`,children:t})]}),(0,_.jsx)(`span`,{className:`text-sm text-slate-200 truncate ${r?`font-mono text-xs`:``}`,children:n})]})}export{v as ChannelDetail};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{S as t,Z as n,_ as r,a as i,b as a,g as o,m as s,t as c,v as l}from"./vendor-icons-ZPvC5PUS.js";import{t as u}from"./vendor-react--nRVf2Ep.js";import{r as d}from"./dist-HyCSN_hp.js";import{f,t as p}from"./index-Ds41VvOC.js";import{n as m,r as h,t as g}from"./Card-BecEmnPW.js";import{t as _}from"./EmptyState-DBFJc4PL.js";var v=e(n(),1),y=u(),b=[`telegram`,`slack`,`discord`,`openclaw`,`wechat`,`whatsapp`],x={telegram:`{
|
|
2
|
-
"botToken": ""
|
|
3
|
-
}`,slack:`{
|
|
4
|
-
"botToken": "",
|
|
5
|
-
"signingSecret": ""
|
|
6
|
-
}`,discord:`{
|
|
7
|
-
"botToken": ""
|
|
8
|
-
}`,openclaw:`{
|
|
9
|
-
"gatewayUrl": "ws://127.0.0.1:18789"
|
|
10
|
-
}`,wechat:`{
|
|
11
|
-
"baseUrl": "https://ilinkai.weixin.qq.com"
|
|
12
|
-
}`,whatsapp:`{}`},S=e=>{switch(e){case`connected`:return`success`;case`connecting`:return`warning`;case`error`:return`destructive`;default:return`secondary`}};function C({initial:e,onSubmit:t,onCancel:n}){let[r,i]=(0,v.useState)(e?.name??``),[a,o]=(0,v.useState)(e?.platform??`telegram`),[s,l]=(0,v.useState)(e?.config?JSON.stringify(e.config,null,2):x[e?.platform??`telegram`]??`{}`),[u,d]=(0,v.useState)(e?.enabled??!0),[p,m]=(0,v.useState)(``);function _(e){if(e.preventDefault(),!r.trim()){m(`Name is required`);return}let n;try{n=JSON.parse(s)}catch{m(`Invalid JSON in config`);return}m(``),t({name:r.trim(),platform:a,config:n,enabled:u})}return(0,y.jsx)(g,{children:(0,y.jsxs)(`form`,{onSubmit:_,className:`space-y-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,y.jsx)(h,{className:`text-slate-200`,children:e?`Edit Channel`:`New Channel`}),(0,y.jsx)(f,{variant:`ghost`,size:`icon`,type:`button`,onClick:n,children:(0,y.jsx)(c,{size:14})})]}),p&&(0,y.jsx)(`div`,{className:`text-xs text-red-400`,children:p}),(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,y.jsx)(`label`,{className:`text-xs text-slate-400`,children:`Name`}),(0,y.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`My Telegram Bot`,className:`rounded-md border border-slate-700 bg-slate-800 px-3 py-1.5 text-sm text-slate-200 placeholder:text-slate-500 focus:border-blue-500 focus:outline-none`})]}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,y.jsx)(`label`,{className:`text-xs text-slate-400`,children:`Platform`}),(0,y.jsx)(`select`,{value:a,onChange:t=>{o(t.target.value),e||l(x[t.target.value]??`{}`)},className:`rounded-md border border-slate-700 bg-slate-800 px-3 py-1.5 text-sm text-slate-200 focus:border-blue-500 focus:outline-none`,children:b.map(e=>(0,y.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,y.jsx)(`label`,{className:`text-xs text-slate-400`,children:`Config (JSON)`}),(0,y.jsx)(`textarea`,{value:s,onChange:e=>l(e.target.value),rows:4,className:`resize-none rounded-md border border-slate-700 bg-slate-800 px-3 py-1.5 font-mono text-xs text-slate-200 placeholder:text-slate-500 focus:border-blue-500 focus:outline-none`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`input`,{type:`checkbox`,id:`ch-enabled`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-slate-700 bg-slate-800`}),(0,y.jsx)(`label`,{htmlFor:`ch-enabled`,className:`text-xs text-slate-400`,children:`Enabled`})]}),!e&&a===`wechat`&&(0,y.jsx)(`div`,{className:`rounded bg-blue-900/30 border border-blue-800/50 px-3 py-2 text-xs text-blue-300`,children:`Creating a WeChat channel will start a QR code scan. Have your WeChat app ready.`}),(0,y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,y.jsx)(f,{type:`submit`,size:`sm`,children:e?`Save`:a===`wechat`&&!e?`Create & Connect`:`Create`}),(0,y.jsx)(f,{type:`button`,variant:`ghost`,size:`sm`,onClick:n,children:`Cancel`})]})]})})}function w({channelId:e,onClose:t}){let[n,r]=(0,v.useState)([]),[i,a]=(0,v.useState)(!0);return(0,v.useEffect)(()=>{(async()=>{try{r((await d(`/channels/${e}/messages`)).messages)}catch{}a(!1)})()},[e]),(0,y.jsxs)(g,{children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,y.jsx)(h,{children:`Channel Messages`}),(0,y.jsx)(f,{variant:`ghost`,size:`icon`,onClick:t,children:(0,y.jsx)(c,{size:14})})]}),i?(0,y.jsx)(`div`,{className:`text-xs text-slate-500`,children:`Loading...`}):n.length===0?(0,y.jsx)(`div`,{className:`text-xs text-slate-500`,children:`No messages yet`}):(0,y.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-2`,children:n.map(e=>(0,y.jsxs)(`div`,{className:`rounded bg-slate-800/50 px-3 py-2 text-xs`,children:[(0,y.jsx)(`span`,{className:e.role===`user`?`text-blue-400`:`text-emerald-400`,children:e.role}),(0,y.jsx)(`span`,{className:`text-slate-500 ml-2`,children:new Date(e.createdAt).toLocaleTimeString()}),(0,y.jsx)(`div`,{className:`mt-1 text-slate-300`,children:e.content})]},e.id))})]})}function T(){let[e,n]=(0,v.useState)([]),[c,u]=(0,v.useState)(!0),[b,x]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(null),[j,M]=(0,v.useState)(!1);(0,v.useEffect)(()=>{N()},[]);async function N(){try{n((await d(`/channels`)).channels)}catch{}u(!1)}async function P(e){try{let t=await d(`/channels`,{method:`POST`,body:JSON.stringify(e)});x(!1),N(),e.platform===`wechat`&&t.channel?.id&&I(t.channel.id)}catch{}}async function F(e){if(T)try{await d(`/channels/${T.id}`,{method:`PATCH`,body:JSON.stringify(e)}),E(null),N()}catch{}}async function I(t){if(e.find(e=>e.id===t)?.platform===`wechat`)try{let e=await d(`/channels/${t}/wechat/qr-start`,{method:`POST`});if(e.qrcodeUrl&&e.sessionKey){A({channelId:t,qrcodeUrl:e.qrcodeUrl,sessionKey:e.sessionKey}),M(!0);try{(await d(`/channels/${t}/wechat/qr-wait`,{method:`POST`,body:JSON.stringify({sessionKey:e.sessionKey,timeoutMs:12e4})})).connected&&N()}catch{}A(null),M(!1)}}catch{}else try{await d(`/channels/${t}/connect`,{method:`POST`}),N()}catch{}}async function L(e){try{await d(`/channels/${e}/disconnect`,{method:`POST`}),N()}catch{}}async function R(e){try{await d(`/channels/${e}`,{method:`DELETE`}),n(t=>t.filter(t=>t.id!==e))}catch{}}return c?(0,y.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,y.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-2 border-slate-700 border-t-blue-500`})}):(0,y.jsxs)(`div`,{className:`space-y-6`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,y.jsx)(`h1`,{className:`text-lg font-semibold text-slate-100`,children:`Channels`}),(0,y.jsxs)(f,{size:`sm`,onClick:()=>{x(!0),E(null)},children:[(0,y.jsx)(o,{size:14}),` Add Channel`]})]}),b&&!T&&(0,y.jsx)(C,{onSubmit:P,onCancel:()=>x(!1)}),T&&(0,y.jsx)(C,{initial:T,onSubmit:F,onCancel:()=>E(null)}),D&&(0,y.jsx)(w,{channelId:D,onClose:()=>O(null)}),k&&(0,y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,y.jsxs)(g,{className:`max-w-sm text-center`,children:[(0,y.jsx)(h,{className:`mb-3 text-slate-200`,children:`Scan QR Code with WeChat`}),(0,y.jsx)(`img`,{src:`https://api.qrserver.com/v1/create-qr-code/?size=256x256&data=${encodeURIComponent(k.qrcodeUrl)}`,alt:`WeChat QR Code`,className:`mx-auto h-64 w-64 rounded bg-white p-2`}),(0,y.jsx)(`p`,{className:`mt-3 text-xs text-slate-400`,children:j?`Waiting for scan...`:`Open WeChat and scan the QR code`}),(0,y.jsx)(`a`,{href:k.qrcodeUrl,target:`_blank`,rel:`noopener noreferrer`,className:`mt-1 block text-[10px] text-blue-400 hover:text-blue-300 truncate max-w-[280px] mx-auto`,children:k.qrcodeUrl}),(0,y.jsx)(f,{variant:`ghost`,size:`sm`,className:`mt-3`,onClick:()=>{A(null),M(!1)},children:`Cancel`})]})}),e.length===0&&!b?(0,y.jsx)(_,{icon:(0,y.jsx)(s,{size:24}),title:`No channels`,description:`Add a channel to connect Adam to messaging platforms like Telegram, Slack, or Discord.`}):(0,y.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 lg:grid-cols-3`,children:e.map(e=>(0,y.jsxs)(g,{children:[(0,y.jsxs)(m,{children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(s,{size:16,className:`text-slate-400`}),(0,y.jsx)(h,{className:`text-slate-200`,children:e.name})]}),(0,y.jsx)(p,{variant:S(e.status),children:e.status})]}),(0,y.jsxs)(`div`,{className:`space-y-2 text-xs text-slate-400`,children:[(0,y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,y.jsx)(`span`,{children:`Platform`}),(0,y.jsx)(`span`,{className:`text-slate-300`,children:e.platform})]}),(0,y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,y.jsx)(`span`,{children:`Messages`}),(0,y.jsx)(`span`,{className:`text-slate-300`,children:e.messageCount})]}),(0,y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,y.jsx)(`span`,{children:`Enabled`}),(0,y.jsx)(`span`,{className:e.enabled?`text-emerald-400`:`text-slate-500`,children:e.enabled?`Yes`:`No`})]})]}),(0,y.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 border-t border-slate-800 pt-3`,children:[e.status===`connected`?(0,y.jsxs)(f,{variant:`secondary`,size:`sm`,onClick:()=>void L(e.id),children:[(0,y.jsx)(l,{size:12}),` Disconnect`]}):(0,y.jsxs)(f,{variant:`secondary`,size:`sm`,onClick:()=>void I(e.id),children:[(0,y.jsx)(r,{size:12}),` Connect`]}),(0,y.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>{E(e),x(!1)},children:(0,y.jsx)(a,{size:12})}),(0,y.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>O(e.id),children:(0,y.jsx)(t,{size:12})}),(0,y.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>void R(e.id),children:(0,y.jsx)(i,{size:12})})]})]},e.id))})]})}export{T as Channels};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{C as t,Y as n,Z as r,a as i,f as a,g as o,l as s}from"./vendor-icons-ZPvC5PUS.js";import{t as c}from"./vendor-react--nRVf2Ep.js";import{a as l,r as u}from"./dist-HyCSN_hp.js";import{t as d}from"./vendor-state-CH64feAE.js";import{f}from"./index-Ds41VvOC.js";import{a as p}from"./format-DvtQjPZn.js";var m=e(r(),1),h=d((e,t)=>({sessions:[],activeSessionId:null,messages:[],loading:!1,sending:!1,_chatWs:null,_chatWsReconnectDelay:1e3,fetchSessions:async()=>{try{e({sessions:(await u(`/chat/sessions`)).sessions})}catch{}},fetchMessages:async t=>{e({loading:!0});try{e({messages:(await u(`/chat/sessions/${t}`)).messages,loading:!1})}catch{e({messages:[],loading:!1})}},sendMessage:async n=>{if(t().sending)return null;e({sending:!0});try{let r=await u(`/chat/messages`,{method:`POST`,body:JSON.stringify({content:n,source:{type:`web`},sessionId:t().activeSessionId??void 0})});return e({activeSessionId:r.sessionId,sending:!1}),t().fetchSessions(),r}catch{return e({sending:!1}),null}},createSession:async()=>{try{let t=await u(`/chat/sessions`,{method:`POST`,body:JSON.stringify({source:{type:`web`}})});return e(e=>({sessions:[t.session,...e.sessions],activeSessionId:t.session.id,messages:[]})),t.session}catch{return null}},archiveSession:async t=>{try{await u(`/chat/sessions/${t}/archive`,{method:`POST`}),e(e=>({sessions:e.sessions.map(e=>e.id===t?{...e,status:`archived`}:e),activeSessionId:e.activeSessionId===t?null:e.activeSessionId,messages:e.activeSessionId===t?[]:e.messages}))}catch{}},restoreSession:async t=>{try{await u(`/chat/sessions/${t}/restore`,{method:`POST`}),e(e=>({sessions:e.sessions.map(e=>e.id===t?{...e,status:`active`}:e)}))}catch{}},deleteSession:async t=>{try{await u(`/chat/sessions/${t}`,{method:`DELETE`}),e(e=>({sessions:e.sessions.filter(e=>e.id!==t),activeSessionId:e.activeSessionId===t?null:e.activeSessionId,messages:e.activeSessionId===t?[]:e.messages}))}catch{}},setActiveSession:n=>{e({activeSessionId:n,messages:[]}),n&&t().fetchMessages(n)},connectChatStream:()=>{let n=t()._chatWs;if(n&&n.readyState<=1)return;let r=window.location.protocol===`https:`?`wss:`:`ws:`,i=localStorage.getItem(`adam_api_key`),a=new URL(`${r}//${window.location.host}/chat/stream`);i&&a.searchParams.set(`api_key`,i);let o=new WebSocket(a.toString());o.onopen=()=>{e({_chatWs:o,_chatWsReconnectDelay:1e3})},o.onclose=()=>{let n=t()._chatWsReconnectDelay;e({_chatWs:null,_chatWsReconnectDelay:Math.min(n*2,1e4)}),setTimeout(()=>{t().connectChatStream()},n)},o.onerror=()=>{o.close()},o.onmessage=n=>{try{let r=JSON.parse(n.data);if(r.type===`chat_message`&&r.message){let n=r.message,{activeSessionId:i,messages:a}=t();if(n.sessionId!==i||a.some(e=>e.id===n.id))return;e(e=>({messages:[...e.messages,n]}))}else r.type===`session_created`&&t().fetchSessions()}catch{}},e({_chatWs:o})},disconnectChatStream:()=>{let n=t()._chatWs;n&&(n.onclose=null,n.onerror=null,n.onmessage=null,n.close(),e({_chatWs:null}))}})),g=c();function _({message:e}){let t=e.role===`user`;return(0,g.jsx)(`div`,{className:l(`flex`,t?`justify-end`:`justify-start`),children:(0,g.jsxs)(`div`,{className:l(`max-w-[80%] rounded-lg px-3.5 py-2.5 text-sm leading-relaxed`,t?`bg-blue-600 text-white`:`border border-slate-700 bg-slate-800 text-slate-200`),children:[(0,g.jsx)(`div`,{className:`whitespace-pre-wrap break-words`,children:e.content}),(0,g.jsx)(`div`,{className:l(`mt-1.5 text-[10px]`,t?`text-blue-200/60`:`text-slate-500`),children:p(typeof e.createdAt==`number`?e.createdAt:new Date(e.createdAt).getTime())})]})})}function v({onSend:e,disabled:t,placeholder:n=`Type a message...`}){let[r,i]=(0,m.useState)(``),a=(0,m.useRef)(null),o=()=>{let n=r.trim();!n||t||(e(n),i(``),a.current&&(a.current.style.height=`auto`))},c=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),o())},l=()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,120)}px`)};return(0,g.jsxs)(`div`,{className:`flex items-end gap-2 border-t border-slate-800 bg-slate-950 px-4 py-3`,children:[(0,g.jsx)(`textarea`,{ref:a,value:r,onChange:e=>{i(e.target.value),l()},onKeyDown:c,placeholder:n,disabled:t,rows:1,className:`flex-1 resize-none rounded-md border border-slate-700 bg-slate-800 px-3 py-2 text-sm text-slate-200 placeholder:text-slate-500 focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 disabled:opacity-50`}),(0,g.jsx)(f,{onClick:o,disabled:t||!r.trim(),size:`default`,"aria-label":`Send message`,children:(0,g.jsx)(s,{size:16})})]})}function y(e){let t=Math.floor((Date.now()-e)/1e3);if(t<60)return`just now`;let n=Math.floor(t/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function b({session:e,isActive:t,onSelect:r,onArchive:o,onRestore:s,onDelete:c}){let u=e.status===`archived`;return(0,g.jsxs)(`button`,{onClick:r,className:l(`group flex w-full flex-col gap-1 rounded-md px-2.5 py-2 text-left transition-colors`,t?`bg-slate-800 text-slate-100`:`text-slate-400 hover:bg-slate-800/50 hover:text-slate-300`,u&&`opacity-60`),children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsx)(`span`,{className:`truncate text-xs font-medium`,children:e.title??e.id.slice(0,8)}),(0,g.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100`,children:[u?(0,g.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),s()},onKeyDown:e=>{e.key===`Enter`&&(e.stopPropagation(),s())},className:`rounded p-0.5 text-slate-500 hover:text-emerald-400`,title:`Restore`,children:(0,g.jsx)(a,{size:12})}):(0,g.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),o()},onKeyDown:e=>{e.key===`Enter`&&(e.stopPropagation(),o())},className:`rounded p-0.5 text-slate-500 hover:text-amber-400`,title:`Archive`,children:(0,g.jsx)(n,{size:12})}),(0,g.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),c()},onKeyDown:e=>{e.key===`Enter`&&(e.stopPropagation(),c())},className:`rounded p-0.5 text-slate-500 hover:text-red-400`,title:`Delete`,children:(0,g.jsx)(i,{size:12})})]})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-slate-500`,children:[(0,g.jsxs)(`span`,{children:[e.messageCount,` turns`]}),(0,g.jsx)(`span`,{children:y(e.lastActiveAt)}),u&&(0,g.jsx)(`span`,{className:`rounded bg-slate-700 px-1 py-0.5 text-[9px]`,children:`archived`})]})]})}function x({sessions:e,activeSessionId:t,onSelectSession:n,onNewSession:r,onArchiveSession:i,onRestoreSession:a,onDeleteSession:s}){let c=e.filter(e=>e.status===`active`),l=e.filter(e=>e.status===`archived`);return(0,g.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-800 px-3 py-2.5`,children:[(0,g.jsx)(`span`,{className:`text-xs font-medium text-slate-400`,children:`Sessions`}),(0,g.jsx)(f,{variant:`ghost`,size:`sm`,onClick:r,children:(0,g.jsx)(o,{size:14})})]}),(0,g.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-1.5 py-1.5`,children:[c.length===0&&l.length===0&&(0,g.jsx)(`div`,{className:`px-2 py-4 text-center text-xs text-slate-500`,children:`No sessions yet`}),c.length>0&&(0,g.jsx)(`div`,{className:`space-y-0.5`,children:c.map(e=>(0,g.jsx)(b,{session:e,isActive:e.id===t,onSelect:()=>n(e.id),onArchive:()=>i(e.id),onRestore:()=>a(e.id),onDelete:()=>s(e.id)},e.id))}),l.length>0&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`mt-3 mb-1 px-2 text-[10px] font-medium uppercase tracking-wider text-slate-600`,children:`Archived`}),(0,g.jsx)(`div`,{className:`space-y-0.5`,children:l.map(e=>(0,g.jsx)(b,{session:e,isActive:e.id===t,onSelect:()=>n(e.id),onArchive:()=>i(e.id),onRestore:()=>a(e.id),onDelete:()=>s(e.id)},e.id))})]})]})]})}function S(){let e=h(e=>e.sessions),n=h(e=>e.activeSessionId),r=h(e=>e.messages),i=h(e=>e.sending),a=h(e=>e.fetchSessions),o=h(e=>e.sendMessage),s=h(e=>e.createSession),c=h(e=>e.archiveSession),l=h(e=>e.restoreSession),u=h(e=>e.deleteSession),d=h(e=>e.setActiveSession),f=h(e=>e.connectChatStream),p=h(e=>e.disconnectChatStream),y=(0,m.useRef)(null);return(0,m.useEffect)(()=>{a()},[a]),(0,m.useEffect)(()=>(f(),()=>p()),[f,p]),(0,m.useEffect)(()=>{y.current?.scrollIntoView?.({behavior:`smooth`})},[r]),(0,g.jsxs)(`div`,{className:`flex h-full overflow-hidden`,children:[(0,g.jsx)(`div`,{className:`hidden w-56 flex-shrink-0 border-r border-slate-800 bg-slate-950 lg:block`,children:(0,g.jsx)(x,{sessions:e,activeSessionId:n,onSelectSession:d,onNewSession:()=>void s(),onArchiveSession:e=>void c(e),onRestoreSession:e=>void l(e),onDeleteSession:e=>void u(e)})}),(0,g.jsxs)(`div`,{className:`flex flex-1 flex-col`,children:[(0,g.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 py-4`,children:r.length===0?(0,g.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 text-slate-500`,children:[(0,g.jsx)(`div`,{className:`rounded-full bg-slate-800 p-3`,children:(0,g.jsx)(t,{size:24})}),(0,g.jsx)(`div`,{className:`text-sm`,children:`Start a conversation with Adam`}),(0,g.jsx)(`div`,{className:`text-xs text-slate-600`,children:`Type a message below to begin`})]}):(0,g.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-3`,children:[r.map(e=>(0,g.jsx)(_,{message:e},e.id)),(0,g.jsx)(`div`,{ref:y})]})}),(0,g.jsx)(`div`,{className:`mx-auto w-full max-w-3xl`,children:(0,g.jsx)(v,{onSend:async e=>{await o(e)},disabled:i})})]})]})}export{S as Chat};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{B as t,D as n,H as r,I as i,V as a,X as o,Z as s,s as c,z as l}from"./vendor-icons-ZPvC5PUS.js";import{r as u,t as d}from"./vendor-react--nRVf2Ep.js";import{C as f,n as p,t as m}from"./index-Ds41VvOC.js";import{n as h,r as g,t as _}from"./Card-BecEmnPW.js";import{a as v,o as y,t as b}from"./format-DvtQjPZn.js";import{a as x,i as S,n as C,o as w,r as T,t as E}from"./Table-tkJ-cuiE.js";var D=e(s(),1),O=d();function k(){let e=f(e=>e.tasks),s=f(e=>e.goals),d=f(e=>e.stats),k=f(e=>e.readiness),j=f(e=>e.roles),M=f(e=>e.executionPool),N=f(e=>e.fetchTasks),P=f(e=>e.fetchGoals),F=f(e=>e.fetchRoles),I=f(e=>e.fetchExecutionPool);(0,D.useEffect)(()=>{N(),P(),F(),I();let e=setInterval(()=>{N(),I()},5e3);return()=>clearInterval(e)},[N,P,F,I]);let L=e.filter(e=>e.status===`running`).length,R=e.filter(e=>e.status===`completed`).length,z=e.filter(e=>e.status===`failed`).length,B=[...e].sort((e,t)=>t.createdAt-e.createdAt).slice(0,8);return(0,O.jsxs)(`div`,{className:`space-y-6`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`h1`,{className:`text-lg font-semibold text-slate-100`,children:`Dashboard`}),k&&(0,O.jsx)(`span`,{role:`status`,"aria-live":`polite`,children:(0,O.jsx)(m,{variant:k.status===`ready`?`success`:`destructive`,children:k.status===`ready`?`Server Ready`:`Not Ready`})})]}),(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,role:`region`,"aria-label":`Server statistics`,children:[(0,O.jsx)(A,{icon:n,label:`Active Tasks`,value:d.activeTasks||L,color:`text-blue-400`}),(()=>{let e=j.filter(e=>e.status===`active`).length,t=j.length,n=j.filter(e=>e.status===`probation`).length,r=j.filter(e=>e.status===`retired`).length,i=[n>0?`${n} probation`:``,r>0?`${r} retired`:``].filter(Boolean).join(` · `);return(0,O.jsx)(A,{icon:o,label:`Role Health`,value:i?`${e}/${t} | ${i}`:`${e}/${t}`,color:r>0?`text-red-400`:n>0?`text-amber-400`:`text-emerald-400`})})(),(0,O.jsx)(A,{icon:l,label:`Roles`,value:j.length,color:`text-emerald-400`}),(0,O.jsx)(A,{icon:t,label:`Cost Today`,value:b(d.totalCostToday),color:`text-purple-400`})]}),(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,role:`region`,"aria-label":`Additional statistics`,children:[(0,O.jsx)(A,{icon:a,label:`Completed`,value:R,color:`text-emerald-400`}),(0,O.jsx)(A,{icon:r,label:`Failed`,value:z,color:`text-red-400`}),(0,O.jsx)(A,{icon:c,label:`Goals`,value:s.length,color:`text-orange-400`}),(0,O.jsx)(A,{icon:i,label:`Execution Pool`,value:`${M.active}/${M.max} | ${M.queued} queued`,color:`text-blue-400`})]}),(0,O.jsx)(`div`,{className:`grid gap-4 lg:grid-cols-1`,children:(0,O.jsxs)(_,{children:[(0,O.jsx)(h,{children:(0,O.jsx)(g,{children:`System Checks`})}),k?(0,O.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:Object.entries(k.checks).map(([e,t])=>(0,O.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md bg-slate-800/30 px-3 py-2`,children:[(0,O.jsx)(`div`,{className:t?`h-2 w-2 rounded-full bg-emerald-500`:`h-2 w-2 rounded-full bg-red-500`}),(0,O.jsx)(`span`,{className:`text-xs capitalize text-slate-300`,children:e})]},e))}):(0,O.jsx)(`span`,{className:`text-xs text-slate-500`,children:`Loading...`})]})}),(0,O.jsxs)(_,{padding:!1,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between px-4 pt-4`,children:[(0,O.jsx)(g,{children:`Recent Tasks`}),(0,O.jsx)(u,{to:`/work`,className:`text-xs text-blue-400 hover:text-blue-300`,children:`View all`})]}),(0,O.jsx)(`div`,{className:`mt-3`,children:(0,O.jsxs)(E,{children:[(0,O.jsx)(x,{children:(0,O.jsxs)(w,{children:[(0,O.jsx)(S,{children:`ID`}),(0,O.jsx)(S,{children:`Prompt`}),(0,O.jsx)(S,{children:`Status`}),(0,O.jsx)(S,{children:`Role`}),(0,O.jsx)(S,{children:`Created`})]})}),(0,O.jsxs)(C,{children:[B.map(e=>(0,O.jsxs)(w,{children:[(0,O.jsx)(T,{children:(0,O.jsx)(u,{to:`/tasks/${e.id}`,className:`font-mono text-xs text-blue-400 hover:text-blue-300`,children:e.id.slice(0,8)})}),(0,O.jsx)(T,{children:y(e.prompt,60)}),(0,O.jsx)(T,{children:(0,O.jsx)(m,{variant:p(e.status),children:e.status})}),(0,O.jsx)(T,{children:(0,O.jsx)(`span`,{className:`font-mono text-xs text-slate-500`,children:e.roleId?e.roleId.slice(0,12):`—`})}),(0,O.jsx)(T,{className:`text-xs text-slate-500`,children:v(e.createdAt)})]},e.id)),B.length===0&&(0,O.jsx)(w,{children:(0,O.jsx)(T,{colSpan:5,className:`text-center text-slate-500`,children:`No tasks yet`})})]})]})})]})]})}function A({icon:e,label:t,value:n,color:r}){return(0,O.jsxs)(_,{className:`flex items-center gap-3`,children:[(0,O.jsx)(`div`,{className:`rounded-md bg-slate-800 p-2 ${r}`,children:(0,O.jsx)(e,{size:16})}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`div`,{className:`text-lg font-semibold text-slate-100`,children:n}),(0,O.jsx)(`div`,{className:`text-xs text-slate-500`,children:t})]})]})}export{k as Dashboard};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{N as t,Z as n,p as r}from"./vendor-icons-ZPvC5PUS.js";import{t as i}from"./vendor-react--nRVf2Ep.js";import{r as a}from"./dist-HyCSN_hp.js";import{C as o,f as s,t as c}from"./index-Ds41VvOC.js";import{t as l}from"./Card-BecEmnPW.js";import{a as u}from"./format-DvtQjPZn.js";import{t as d}from"./EmptyState-DBFJc4PL.js";var f=e(n(),1),p=i();function m(){let e=o(e=>e.roles),n=o(e=>e.fetchRoles),[i,m]=(0,f.useState)([]),[h,g]=(0,f.useState)(!0),[_,v]=(0,f.useState)(`all`);(0,f.useEffect)(()=>{n()},[n]);let y=(0,f.useCallback)(async()=>{g(!0);try{let e=new URLSearchParams({limit:`50`});_!==`all`&&e.set(`roleId`,_),m(await a(`/evolution-audit?${e}`))}catch{m([])}finally{g(!1)}},[_]);(0,f.useEffect)(()=>{y()},[y]);let b=t=>t?e.find(e=>e.id===t)?.name??t.slice(0,8):`System`;return(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,p.jsx)(`h1`,{className:`text-lg font-semibold text-slate-100`,children:`Evolution Audit`}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsxs)(`select`,{className:`rounded border border-slate-700 bg-slate-900 px-2 py-1.5 text-sm text-slate-200 focus:border-blue-500 focus:outline-none`,value:_,onChange:e=>v(e.target.value),children:[(0,p.jsx)(`option`,{value:`all`,children:`All roles`}),e.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,p.jsx)(s,{variant:`ghost`,size:`sm`,onClick:()=>void y(),children:(0,p.jsx)(r,{size:14})})]})]}),(0,p.jsx)(l,{children:h?(0,p.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,p.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-slate-700 border-t-blue-500`})}):i.length===0?(0,p.jsx)(d,{icon:(0,p.jsx)(t,{size:32}),title:`No evolution records`,description:`Evolution occurs when roles accumulate enough task experience`}):(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`p`,{className:`text-xs text-slate-500`,children:[i.length,` records`]}),i.map(e=>(0,p.jsxs)(`div`,{className:`rounded border border-slate-800 p-3`,children:[(0,p.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,p.jsx)(c,{variant:`info`,children:b(e.roleId)}),(0,p.jsx)(`span`,{className:`text-xs text-slate-500`,children:u(e.timestamp)}),e.triggerTaskId&&(0,p.jsxs)(`span`,{className:`text-[10px] text-slate-600`,children:[`triggered by task `,e.triggerTaskId.slice(0,8)]})]}),e.diff.includes(`--- Diagnostic Report ---`)?(0,p.jsxs)(`div`,{className:`space-y-2`,children:[(0,p.jsxs)(`div`,{className:`rounded bg-slate-950 p-2`,children:[(0,p.jsx)(`p`,{className:`mb-1 text-[10px] font-medium text-slate-400`,children:`Diagnostic Report`}),(0,p.jsx)(`pre`,{className:`whitespace-pre-wrap font-mono text-xs text-slate-400`,children:e.diff.split(`--- Rules Diff ---`)[0]?.replace(`--- Diagnostic Report ---
|
|
2
|
-
`,``).trim()})]}),(0,p.jsxs)(`div`,{className:`rounded bg-slate-950 p-2`,children:[(0,p.jsx)(`p`,{className:`mb-1 text-[10px] font-medium text-slate-400`,children:`Rules Changes`}),(0,p.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap font-mono text-xs`,children:(e.diff.split(`--- Rules Diff ---`)[1]??``).trim().split(`
|
|
3
|
-
`).map((e,t)=>(0,p.jsxs)(`span`,{className:e.startsWith(`+`)?`text-green-400`:e.startsWith(`-`)?`text-red-400`:`text-slate-400`,children:[e,`
|
|
4
|
-
`]},t))})]})]}):(0,p.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap rounded bg-slate-950 p-2 font-mono text-xs`,children:e.diff.split(`
|
|
5
|
-
`).map((e,t)=>(0,p.jsxs)(`span`,{className:e.startsWith(`+`)?`text-green-400`:e.startsWith(`-`)?`text-red-400`:`text-slate-400`,children:[e,`
|
|
6
|
-
`]},t))})]},e.id))]})})]})}export{m as Evolution};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{A as t,F as n,J as r,L as i,Z as a,s as o}from"./vendor-icons-ZPvC5PUS.js";import{d as s,r as c,t as l}from"./vendor-react--nRVf2Ep.js";import{r as u}from"./dist-HyCSN_hp.js";import{t as d}from"./index-Ds41VvOC.js";import{n as f,r as p,t as m}from"./Card-BecEmnPW.js";import{n as h}from"./format-DvtQjPZn.js";var g=e(a(),1),_=l();function v(){let{id:e}=s(),[a,l]=(0,g.useState)(null),[v,b]=(0,g.useState)([]),[x,S]=(0,g.useState)(null);if((0,g.useEffect)(()=>{e&&(async()=>{try{let t=await u(`/goals/${e}`);l(t.goal),S(null);try{b((await u(`/strategies?role=${t.goal.roleId}`)).strategies??[])}catch{}}catch(e){S(e instanceof Error?e.message:`Failed to load goal`)}})()},[e]),x)return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(c,{to:`/goals`,className:`flex items-center gap-1.5 text-sm text-slate-400 hover:text-slate-200`,children:[(0,_.jsx)(r,{size:14}),` Back to Goals`]}),(0,_.jsx)(m,{className:`text-center text-red-400`,children:x})]});if(!a)return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(c,{to:`/goals`,className:`flex items-center gap-1.5 text-sm text-slate-400 hover:text-slate-200`,children:[(0,_.jsx)(r,{size:14}),` Back to Goals`]}),(0,_.jsx)(m,{className:`text-center text-slate-500`,children:`Loading...`})]});let C=a.targetValue>0?Math.min(100,a.currentValue/a.targetValue*100):0,w=a.deadline>0&&a.deadline<Date.now()&&a.status!==`completed`;return(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(c,{to:`/goals`,className:`flex items-center gap-1.5 text-sm text-slate-400 hover:text-slate-200`,children:[(0,_.jsx)(r,{size:14}),` Back to Goals`]}),(0,_.jsx)(m,{children:(0,_.jsx)(`div`,{className:`flex items-start justify-between gap-4`,children:(0,_.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,_.jsx)(d,{variant:(e=>e===`completed`?`success`:e===`executing`||e===`evaluating`?`warning`:e===`failed`?`destructive`:`secondary`)(a.status),children:a.status}),(0,_.jsx)(d,{variant:`outline`,children:a.roleId}),(0,_.jsx)(d,{variant:`outline`,children:a.metricType}),(0,_.jsx)(`span`,{className:`font-mono text-xs text-slate-500`,children:a.id})]}),(0,_.jsx)(`h2`,{className:`text-lg font-semibold text-slate-200`,children:a.name}),a.description&&(0,_.jsx)(`p`,{className:`text-sm text-slate-400 mt-1`,children:a.description})]})})}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[(0,_.jsx)(y,{icon:o,label:`Progress`,value:`${a.currentValue} / ${a.targetValue}`}),(0,_.jsx)(y,{icon:i,label:w?`Overdue`:`Deadline`,value:h(a.deadline),mono:!0}),(0,_.jsx)(y,{icon:n,label:`Budget`,value:`$${a.budgetUsd.toFixed(2)}`}),(0,_.jsx)(y,{icon:t,label:`Created`,value:h(a.createdAt),mono:!0})]}),(0,_.jsxs)(m,{children:[(0,_.jsx)(f,{children:(0,_.jsx)(p,{children:`Progress`})}),(0,_.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,_.jsx)(`div`,{className:`flex-1 h-3 rounded-full bg-slate-700 overflow-hidden`,children:(0,_.jsx)(`div`,{className:`h-full rounded-full transition-all ${w?`bg-red-500`:`bg-blue-500`}`,style:{width:`${C}%`}})}),(0,_.jsxs)(`span`,{className:`text-sm text-slate-300 font-mono`,children:[C.toFixed(1),`%`]})]}),(0,_.jsxs)(`div`,{className:`mt-2 flex items-center justify-between text-xs text-slate-500`,children:[(0,_.jsxs)(`span`,{children:[a.currentValue,` current`]}),(0,_.jsxs)(`span`,{children:[a.targetValue,` target`]})]})]}),(a.deliverTo??[]).length>0&&(0,_.jsxs)(m,{children:[(0,_.jsx)(f,{children:(0,_.jsx)(p,{children:`Delivery Targets`})}),(0,_.jsx)(`div`,{className:`space-y-1.5`,children:(a.deliverTo??[]).map((e,t)=>(0,_.jsx)(`div`,{className:`flex items-center gap-2 text-sm text-slate-300`,children:e.type===`channel`?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(d,{variant:`outline`,children:`Channel`}),(0,_.jsx)(`span`,{className:`font-mono text-xs`,children:e.channelId.slice(0,8)}),e.chatId&&(0,_.jsxs)(`span`,{className:`text-xs text-slate-500`,children:[`chat: `,e.chatId.slice(0,8)]})]}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(d,{variant:`outline`,children:`Session`}),(0,_.jsx)(`span`,{className:`text-xs text-slate-400`,children:`Chat session`})]})},t))})]}),v.length>0&&(0,_.jsxs)(m,{children:[(0,_.jsx)(f,{children:(0,_.jsxs)(p,{className:`flex items-center gap-2`,children:[(0,_.jsx)(t,{size:14}),` Strategies (`,v.length,`)`]})}),(0,_.jsx)(`div`,{className:`space-y-2`,children:v.map(e=>(0,_.jsxs)(`div`,{className:`flex items-center justify-between text-sm border-b border-slate-800 pb-2`,children:[(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`span`,{className:`text-slate-200`,children:e.name}),(0,_.jsx)(`span`,{className:`text-xs text-slate-500 ml-2`,children:e.taskType})]}),(0,_.jsxs)(d,{variant:`outline`,children:[e.trialCount,` trials`]})]},e.id))})]})]})}function y({icon:e,label:t,value:n,mono:r}){return(0,_.jsxs)(m,{className:`flex flex-col gap-1`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-1.5 text-slate-500`,children:[(0,_.jsx)(e,{size:12}),(0,_.jsx)(`span`,{className:`text-xs`,children:t})]}),(0,_.jsx)(`span`,{className:`text-sm text-slate-200 truncate ${r?`font-mono text-xs`:``}`,children:n})]})}export{v as GoalDetail};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{Z as t,a as n,b as r,g as i,p as a,s as o,t as s,x as c,y as l}from"./vendor-icons-ZPvC5PUS.js";import{t as u}from"./vendor-react--nRVf2Ep.js";import{r as d}from"./dist-HyCSN_hp.js";import{C as f,a as ee,c as p,d as m,f as h,i as g,l as _,n as v,o as y,r as b,s as x,t as S,u as te,w as C}from"./index-Ds41VvOC.js";import{n as w,r as T,t as E}from"./Card-BecEmnPW.js";import{n as D,t as ne}from"./format-DvtQjPZn.js";import{t as O}from"./EmptyState-DBFJc4PL.js";var k=e(t(),1),A=u();function j({value:e,onChange:t,label:n=`Delivery Targets`}){let[r,i]=(0,k.useState)([]),[a,o]=(0,k.useState)(!1);(0,k.useEffect)(()=>{let e=!1;return Promise.all([d(`/channels`).catch(()=>({channels:[]})),d(`/chat/sessions`).catch(()=>({sessions:[]}))]).then(([t,n])=>{if(e)return;let r=new Map(t.channels.map(e=>[e.id,e])),a=[];for(let e of n.sessions)if(e.source.type===`channel`&&e.source.channelId&&e.source.chatId){let t=r.get(e.source.channelId);a.push({id:e.id,channelId:e.source.channelId,channelName:t?.name??e.source.channelId.slice(0,8),platform:t?.platform??`unknown`,chatId:e.source.chatId})}let o=new Set;i(a.filter(e=>{let t=`${e.channelId}:${e.chatId}`;return o.has(t)?!1:(o.add(t),!0)}))}),()=>{e=!0}},[]);let s=(t,n)=>e.some(e=>e.type===`channel`&&e.channelId===t&&e.chatId===n),c=(n,r)=>{s(n,r)?t(e.filter(e=>!(e.type===`channel`&&e.channelId===n&&e.chatId===r))):t([...e,{type:`channel`,channelId:n,chatId:r}])},l=e.filter(e=>e.type===`channel`).length;return(0,A.jsxs)(`div`,{className:`relative`,children:[(0,A.jsx)(`label`,{className:`text-xs text-slate-400`,children:n}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>o(!a),className:`mt-1 w-full rounded-md border border-slate-700 bg-slate-800 px-3 py-1.5 text-left text-sm text-slate-200 hover:border-slate-600 focus:border-blue-500 focus:outline-none`,children:l===0?`Default (current session)`:`${l} channel${l>1?`s`:``} selected`}),a&&(0,A.jsxs)(`div`,{className:`absolute z-10 mt-1 w-full rounded-md border border-slate-700 bg-slate-800 py-1 shadow-lg`,children:[r.length===0?(0,A.jsx)(`div`,{className:`px-3 py-2 text-xs text-slate-500`,children:`No active channel conversations. Start a chat on WeChat/Telegram first.`}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`px-3 py-1 text-xs text-slate-500`,children:`Channel conversations`}),r.map(e=>(0,A.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 px-3 py-1.5 text-xs text-slate-300 hover:bg-slate-700`,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:s(e.channelId,e.chatId),onChange:()=>c(e.channelId,e.chatId),className:`rounded border-slate-600 bg-slate-700`}),(0,A.jsx)(`span`,{className:`truncate font-medium`,children:e.channelName}),(0,A.jsxs)(`span`,{className:`text-slate-500`,children:[`(`,e.platform,`)`]})]},`${e.channelId}:${e.chatId}`))]}),l>0&&(0,A.jsx)(`button`,{type:`button`,onClick:()=>{t([]),o(!1)},className:`mt-1 w-full border-t border-slate-700 px-3 py-1 text-left text-xs text-red-400 hover:bg-slate-700`,children:`Clear all`}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`w-full border-t border-slate-700 px-3 py-1 text-left text-xs text-slate-500 hover:bg-slate-700`,children:`Done`})]})]})}var M={active:`paused`,paused:`active`,completed:`active`,failed:`active`},N={active:(0,A.jsx)(c,{size:12}),paused:(0,A.jsx)(l,{size:12}),completed:(0,A.jsx)(a,{size:12}),failed:(0,A.jsx)(a,{size:12})};function P(){let e=f(e=>e.goals),t=f(e=>e.fetchGoals),c=f(e=>e.updateGoal),u=f(e=>e.deleteGoal),[P,F]=(0,k.useState)(!1),[I,L]=(0,k.useState)(``),[R,z]=(0,k.useState)(!1),[B,V]=(0,k.useState)(null),[H,U]=(0,k.useState)(null),[W,G]=(0,k.useState)(``),[K,q]=(0,k.useState)(``),[J,Y]=(0,k.useState)([]),[X,Z]=(0,k.useState)([]),[Q,re]=(0,k.useState)([]),[$,ie]=(0,k.useState)([]);(0,k.useEffect)(()=>{t();let e=setInterval(()=>void t(),1e4);return()=>clearInterval(e)},[t]);let ae=async()=>{if(I.trim()){z(!0),V(null);try{await d(`/goals`,{method:`POST`,body:JSON.stringify({input:I.trim(),deliverTo:Q.length>0?Q:void 0,reportTo:$.length>0?$:void 0})}),L(``),F(!1),t()}catch(e){V(e instanceof Error?e.message:`Failed to create goal`)}finally{z(!1)}}};return(0,A.jsxs)(`div`,{className:`space-y-4`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,A.jsx)(`h1`,{className:`text-lg font-semibold text-slate-100`,children:`Goals`}),(0,A.jsxs)(`div`,{className:`flex gap-2`,children:[(0,A.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void t(),children:(0,A.jsx)(a,{size:14})}),(0,A.jsxs)(h,{size:`sm`,onClick:()=>F(!P),children:[(0,A.jsx)(i,{size:14}),`New Goal`]})]})]}),P&&(0,A.jsxs)(E,{className:`space-y-3`,children:[(0,A.jsx)(`textarea`,{className:`w-full rounded-md border border-slate-700 bg-slate-800 px-3 py-2 text-sm text-slate-200 placeholder:text-slate-500 focus:border-blue-500 focus:outline-none`,placeholder:`Describe your goal in natural language...`,rows:3,value:I,onChange:e=>L(e.target.value)}),(0,A.jsx)(j,{value:Q,onChange:re,label:`Deliver To (results)`}),(0,A.jsx)(j,{value:$,onChange:ie,label:`Report To (status)`}),B&&(0,A.jsx)(`p`,{className:`text-xs text-red-400`,children:B}),(0,A.jsxs)(`div`,{className:`flex gap-2`,children:[(0,A.jsx)(h,{onClick:()=>void ae(),disabled:R||!I.trim(),children:R?`Creating...`:`Create`}),(0,A.jsx)(h,{variant:`ghost`,onClick:()=>F(!1),children:`Cancel`})]})]}),e.length===0?(0,A.jsx)(O,{icon:(0,A.jsx)(o,{size:32}),title:`No goals`,description:`Create a goal to start goal-driven task orchestration`}):(0,A.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:e.map(e=>{let t=e.targetValue>0?Math.min(100,Math.round(e.currentValue/e.targetValue*100)):0,i=new Date(e.deadline).getTime()<Date.now()&&e.status!==`completed`,a=H===e.id;return(0,A.jsxs)(E,{children:[(0,A.jsxs)(w,{children:[a?(0,A.jsx)(`input`,{className:`flex-1 rounded-md border border-slate-700 bg-slate-800 px-2 py-1 text-sm text-slate-200 focus:border-blue-500 focus:outline-none`,value:W,onChange:e=>G(e.target.value),autoFocus:!0}):(0,A.jsx)(T,{className:`text-slate-200 text-sm font-medium truncate max-w-[180px]`,children:e.name}),(0,A.jsx)(S,{variant:v(e.status),children:e.status})]}),a?(0,A.jsx)(`textarea`,{className:`w-full rounded-md border border-slate-700 bg-slate-800 px-2 py-1 text-xs text-slate-200 placeholder:text-slate-500 focus:border-blue-500 focus:outline-none mb-3`,placeholder:`Description...`,rows:2,value:K,onChange:e=>q(e.target.value)}):e.description?(0,A.jsx)(`p`,{className:`text-xs text-slate-400 mb-3 line-clamp-2`,children:e.description}):null,a&&(0,A.jsxs)(`div`,{className:`mb-3 space-y-2`,children:[(0,A.jsx)(j,{value:J,onChange:Y,label:`Deliver To (results)`}),(0,A.jsx)(j,{value:X,onChange:Z,label:`Report To (status)`})]}),(0,A.jsxs)(`div`,{className:`mb-3`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,A.jsx)(`span`,{className:`text-xs text-slate-500`,children:`Progress`}),(0,A.jsxs)(`span`,{className:`font-mono text-xs text-slate-300`,children:[t,`%`]})]}),(0,A.jsx)(`div`,{className:`h-1.5 rounded-full bg-slate-800`,children:(0,A.jsx)(`div`,{className:`h-full rounded-full transition-all ${t>=100?`bg-emerald-500`:`bg-blue-500`}`,style:{width:`${t}%`}})}),(0,A.jsxs)(`div`,{className:`flex items-center justify-between mt-1`,children:[(0,A.jsxs)(`span`,{className:`font-mono text-[10px] text-slate-500`,children:[e.currentValue,` / `,e.targetValue]}),(0,A.jsx)(`span`,{className:`font-mono text-[10px] text-slate-500`,children:e.metricType})]})]}),(0,A.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,A.jsxs)(`div`,{className:`flex justify-between`,children:[(0,A.jsx)(`span`,{className:`text-slate-500`,children:`Role`}),(0,A.jsx)(S,{variant:`muted`,className:`text-[10px]`,children:e.roleId})]}),(0,A.jsxs)(`div`,{className:`flex justify-between`,children:[(0,A.jsx)(`span`,{className:`text-slate-500`,children:`Budget`}),(0,A.jsx)(`span`,{className:`font-mono text-slate-300`,children:ne(e.budgetUsd)})]}),(0,A.jsxs)(`div`,{className:`flex justify-between`,children:[(0,A.jsx)(`span`,{className:`text-slate-500 ${i?`text-red-400`:``}`,children:`Deadline`}),(0,A.jsx)(`span`,{className:`text-slate-300 ${i?`text-red-400`:``}`,children:D(e.deadline)})]}),(0,A.jsxs)(`div`,{className:`flex justify-between`,children:[(0,A.jsx)(`span`,{className:`text-slate-500`,children:`Created`}),(0,A.jsx)(`span`,{className:`text-slate-400`,children:D(e.createdAt)})]})]}),(0,A.jsx)(`div`,{className:`flex items-center gap-1 mt-3 pt-3 border-t border-slate-800`,children:a?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(h,{size:`sm`,variant:`ghost`,onClick:async()=>{try{await c(e.id,{name:W,description:K,deliverTo:J,reportTo:X}),U(null),C.success(`Goal updated`)}catch(e){C.error(e instanceof Error?e.message:`Failed to update`)}},children:`Save`}),(0,A.jsx)(h,{size:`sm`,variant:`ghost`,onClick:()=>U(null),children:(0,A.jsx)(s,{size:14})})]}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(h,{size:`sm`,variant:`ghost`,title:`Edit`,onClick:()=>{U(e.id),G(e.name),q(e.description??``),Y(e.deliverTo??[]),Z(e.reportTo??[])},children:(0,A.jsx)(r,{size:14})}),(0,A.jsxs)(h,{size:`sm`,variant:`ghost`,title:`Change to ${M[e.status]}`,onClick:async()=>{try{await c(e.id,{status:M[e.status]}),C.success(`Status changed to ${M[e.status]}`)}catch(e){C.error(e instanceof Error?e.message:`Failed to update status`)}},children:[N[e.status]??(0,A.jsx)(l,{size:12}),(0,A.jsx)(`span`,{className:`ml-1 text-xs`,children:M[e.status]})]}),(0,A.jsx)(`div`,{className:`ml-auto`,children:(0,A.jsxs)(b,{children:[(0,A.jsx)(m,{asChild:!0,children:(0,A.jsx)(h,{size:`sm`,variant:`ghost`,title:`Delete`,className:`text-red-400 hover:text-red-300`,children:(0,A.jsx)(n,{size:14})})}),(0,A.jsxs)(y,{children:[(0,A.jsxs)(_,{children:[(0,A.jsx)(te,{children:`Delete goal`}),(0,A.jsxs)(x,{children:[`This will permanently delete "`,e.name,`". This action cannot be undone.`]})]}),(0,A.jsxs)(p,{children:[(0,A.jsx)(ee,{children:`Cancel`}),(0,A.jsx)(g,{className:`bg-red-600 hover:bg-red-700`,onClick:async()=>{try{await u(e.id),C.success(`Goal deleted`)}catch(e){C.error(e instanceof Error?e.message:`Failed to delete`)}},children:`Delete`})]})]})]})})]})})]},e.id)})})]})}export{P as Goals,j as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{Z as t,a as n,o as r,x as i,y as a}from"./vendor-icons-ZPvC5PUS.js";import{t as o}from"./vendor-react--nRVf2Ep.js";import{C as s,f as c}from"./index-Ds41VvOC.js";import{t as l}from"./Card-BecEmnPW.js";import{t as u}from"./EmptyState-DBFJc4PL.js";var d=e(t(),1),f=o(),p={debug:`text-slate-500`,info:`text-blue-400`,warn:`text-amber-400`,error:`text-red-400`},m={adam:`text-purple-400`,manager:`text-cyan-400`,worker:`text-green-400`,scheduler:`text-orange-400`,api:`text-blue-400`,ws:`text-teal-400`,store:`text-yellow-400`,embedding:`text-pink-400`},h=[`adam`,`manager`,`worker`,`scheduler`,`api`,`ws`,`store`,`embedding`],g=[`debug`,`info`,`warn`,`error`];function _(){let e=s(e=>e.logs),t=(0,d.useRef)(null),[o,_]=(0,d.useState)(!0),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(null),C=(0,d.useMemo)(()=>e.filter(e=>!(y&&e.level!==y||x&&e.component!==x)),[e,y,x]);return(0,d.useEffect)(()=>{o&&t.current&&(t.current.scrollTop=t.current.scrollHeight)},[C,o]),(0,f.jsxs)(`div`,{className:`flex h-full flex-col gap-4`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,f.jsx)(`h1`,{className:`text-lg font-semibold text-slate-100`,children:`Logs`}),(0,f.jsxs)(`div`,{className:`flex gap-2`,children:[(0,f.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>_(!o),title:o?`Pause auto-scroll`:`Resume auto-scroll`,children:o?(0,f.jsx)(i,{size:14}):(0,f.jsx)(a,{size:14})}),(0,f.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>{s.setState({logs:[]})},title:`Clear logs`,children:(0,f.jsx)(n,{size:14})})]})]}),(0,f.jsxs)(`div`,{className:`flex flex-wrap gap-4`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs text-slate-500`,children:`Level:`}),(0,f.jsxs)(`div`,{className:`flex gap-1`,children:[(0,f.jsx)(v,{active:y===null,onClick:()=>b(null),children:`All`}),g.map(e=>(0,f.jsx)(v,{active:y===e,onClick:()=>b(y===e?null:e),children:e},e))]})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs text-slate-500`,children:`Component:`}),(0,f.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,f.jsx)(v,{active:x===null,onClick:()=>S(null),children:`All`}),h.map(e=>(0,f.jsx)(v,{active:x===e,onClick:()=>S(x===e?null:e),children:e},e))]})]})]}),(0,f.jsx)(l,{padding:!1,className:`flex-1 min-h-0`,children:C.length===0?(0,f.jsx)(u,{icon:(0,f.jsx)(r,{size:32}),title:`No log entries`,description:`Log events will appear here in real-time via WebSocket`}):(0,f.jsx)(`div`,{ref:t,className:`h-full max-h-[calc(100vh-280px)] overflow-y-auto p-3 font-mono text-xs leading-5`,children:C.map((e,t)=>{let n=new Date(e.timestamp).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,fractionalSecondDigits:3}),r=p[e.level]??`text-slate-400`,i=m[e.component]??`text-slate-400`;return(0,f.jsxs)(`div`,{className:`flex gap-2 hover:bg-slate-800/30 px-1 rounded`,children:[(0,f.jsx)(`span`,{className:`text-slate-600 shrink-0`,children:n}),(0,f.jsx)(`span`,{className:`w-12 shrink-0 uppercase ${r}`,children:e.level.padEnd(5)}),(0,f.jsxs)(`span`,{className:`w-20 shrink-0 ${i}`,children:[`[`,e.component,`]`]}),(0,f.jsx)(`span`,{className:`text-slate-300 break-all`,children:e.msg})]},t)})})}),(0,f.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-slate-500`,children:[(0,f.jsxs)(`span`,{children:[C.length,` entries `,C.length!==e.length&&`(${e.length} total)`]}),(0,f.jsx)(`span`,{children:o?`Auto-scrolling`:`Paused`})]})]})}function v({active:e,onClick:t,children:n}){return(0,f.jsx)(`button`,{onClick:t,className:`rounded px-2 py-0.5 text-xs transition-colors ${e?`bg-slate-700 text-slate-200`:`text-slate-500 hover:text-slate-300`}`,children:n})}export{_ as Logs};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{Z as t,p as n,q as r,u as i}from"./vendor-icons-ZPvC5PUS.js";import{t as a}from"./vendor-react--nRVf2Ep.js";import{r as o}from"./dist-HyCSN_hp.js";import{C as s,f as c,t as l}from"./index-Ds41VvOC.js";import{t as u}from"./Card-BecEmnPW.js";import{a as d}from"./format-DvtQjPZn.js";import{t as f}from"./EmptyState-DBFJc4PL.js";var p=e(t(),1),m=a();function h(){let e=s(e=>e.roles),t=s(e=>e.fetchRoles),[a,h]=(0,p.useState)(``),[g,_]=(0,p.useState)([]),[v,y]=(0,p.useState)(!1),[b,x]=(0,p.useState)(``),[S,C]=(0,p.useState)(!1),[w,T]=(0,p.useState)(`all`),[E,D]=(0,p.useState)(new Set);(0,p.useEffect)(()=>{t()},[t]),(0,p.useEffect)(()=>{!a&&e.length>0&&h(e[0].id)},[e,a]);let O=(0,p.useCallback)(async()=>{if(a){y(!0);try{_((await o(`/memories/${a}?limit=100`)).memories)}catch{_([])}finally{y(!1)}}},[a]);(0,p.useEffect)(()=>{a&&O()},[a,O]);let k=async()=>{if(!(!b.trim()||!a)){C(!0);try{_((await o(`/memories/query`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:a,prompt:b.trim(),topK:20})})).memories)}catch{_([])}finally{C(!1)}}},A=()=>{x(``),O()},j=g.filter(e=>w===`high`?e.importance>3:w===`medium`?e.importance===3:w===`low`?e.importance<3:!0),M=e=>e>=4?`text-red-400`:e===3?`text-yellow-400`:`text-slate-500`;return(0,m.jsxs)(`div`,{className:`space-y-4`,children:[(0,m.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,m.jsx)(`h1`,{className:`text-lg font-semibold text-slate-100`,children:`Memories`}),(0,m.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>void O(),children:(0,m.jsx)(n,{size:14})})]}),(0,m.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,m.jsx)(`select`,{className:`rounded border border-slate-700 bg-slate-900 px-2 py-1.5 text-sm text-slate-200 focus:border-blue-500 focus:outline-none`,value:a,onChange:e=>h(e.target.value),children:e.map(e=>(0,m.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,m.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,m.jsx)(`input`,{className:`w-64 rounded border border-slate-700 bg-slate-900 px-2 py-1.5 text-sm text-slate-200 placeholder-slate-600 focus:border-blue-500 focus:outline-none`,value:b,onChange:e=>x(e.target.value),onKeyDown:e=>e.key===`Enter`&&void k(),placeholder:`Search memories...`}),(0,m.jsx)(c,{size:`sm`,variant:`ghost`,onClick:()=>void k(),disabled:S,children:(0,m.jsx)(i,{size:14})}),b&&(0,m.jsx)(c,{size:`sm`,variant:`ghost`,onClick:A,children:`Clear`})]}),(0,m.jsx)(`div`,{className:`flex gap-1`,children:[`all`,`high`,`medium`,`low`].map(e=>(0,m.jsx)(`button`,{className:`rounded px-2 py-1 text-xs transition-colors ${w===e?`bg-blue-600 text-white`:`bg-slate-800 text-slate-400 hover:bg-slate-700`}`,onClick:()=>T(e),children:e},e))})]}),(0,m.jsx)(u,{children:v||S?(0,m.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,m.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-slate-700 border-t-blue-500`})}):j.length===0?(0,m.jsx)(f,{icon:(0,m.jsx)(r,{size:32}),title:`No memories`,description:b?`No results for this query`:`This agent has no memories yet`}):(0,m.jsxs)(`div`,{className:`space-y-3`,children:[(0,m.jsxs)(`p`,{className:`text-xs text-slate-500`,children:[j.length,` memories`]}),j.map(e=>(0,m.jsxs)(`div`,{className:`rounded border border-slate-800 p-3`,children:[(0,m.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2`,children:[(0,m.jsx)(l,{variant:e.type===`reflection`?`info`:e.type===`thought`?`warning`:`muted`,children:e.type}),(0,m.jsx)(l,{variant:`muted`,children:e.sourceType}),(0,m.jsx)(`span`,{className:`text-xs font-medium ${M(e.importance)}`,children:`*`.repeat(e.importance)}),e.score!=null&&(0,m.jsxs)(`span`,{className:`text-[10px] text-slate-600`,children:[`score: `,e.score.toFixed(3)]})]}),(0,m.jsx)(`p`,{className:`whitespace-pre-wrap text-sm text-slate-300`,children:e.content}),(0,m.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:e.keywords.map(e=>(0,m.jsx)(`span`,{className:`rounded bg-slate-800 px-1.5 py-0.5 text-[10px] text-slate-500`,children:e},e))}),e.type===`reflection`&&e.evidence&&e.evidence.length>0&&(0,m.jsxs)(`div`,{className:`mt-2`,children:[(0,m.jsxs)(`button`,{className:`text-[10px] text-blue-400 hover:text-blue-300`,onClick:()=>D(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:[E.has(e.id)?`Hide`:`Show`,` evidence (`,e.evidence.length,` memories)`]}),E.has(e.id)&&(0,m.jsx)(`div`,{className:`mt-1.5 space-y-1 border-l-2 border-slate-800 pl-2`,children:e.evidence.map(e=>{let t=g.find(t=>t.id===e);return(0,m.jsx)(`div`,{className:`text-xs text-slate-500`,children:t?t.content.slice(0,120)+(t.content.length>120?`...`:``):(0,m.jsxs)(`span`,{className:`italic`,children:[`Memory `,e.slice(0,8),` (not in current view)`]})},e)})})]}),(0,m.jsxs)(`p`,{className:`mt-1.5 text-[10px] text-slate-600`,children:[d(e.createdAt),` | accessed `,e.retrievedCount,`x | last: `,d(e.lastAccessed)]})]},e.id))]})})]})}export{h as Memories};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{E as t,K as n,M as r,U as i,W as a,Z as o,a as ee,g as te,h as s,p as c,t as l}from"./vendor-icons-ZPvC5PUS.js";import{t as u}from"./vendor-react--nRVf2Ep.js";import{r as d}from"./dist-HyCSN_hp.js";import{f,t as p,w as m}from"./index-Ds41VvOC.js";import{t as h}from"./Card-BecEmnPW.js";import{a as g}from"./format-DvtQjPZn.js";import{t as ne}from"./EmptyState-DBFJc4PL.js";import{a as _,i as v,n as y,o as b,r as x,t as S}from"./Table-tkJ-cuiE.js";var C=e(o(),1),w=u();function T({manifest:e}){if(!e)return null;let t=[];return e.skills.length>0&&t.push({label:`Skill(${e.skills.length})`,variant:`info`}),e.agents.length>0&&t.push({label:`Agent(${e.agents.length})`,variant:`success`}),e.mcpServers.length>0&&t.push({label:`MCP(${e.mcpServers.length})`,variant:`warning`}),e.hooks.length>0&&t.push({label:`Hook(${e.hooks.length})`,variant:`default`}),e.lspServers.length>0&&t.push({label:`LSP(${e.lspServers.length})`,variant:`default`}),(0,w.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,w.jsx)(p,{variant:e.variant,children:e.label},e.label))})}function E(){let[e,o]=(0,C.useState)([]),[u,E]=(0,C.useState)([]),[,D]=(0,C.useState)([]),[,O]=(0,C.useState)(new Set),[re,k]=(0,C.useState)(!0),[A,j]=(0,C.useState)(!1),[,M]=(0,C.useState)(null),[N,P]=(0,C.useState)(null),[F,I]=(0,C.useState)(!1),[L,R]=(0,C.useState)(``),[z,B]=(0,C.useState)([]),[V,H]=(0,C.useState)(!1),[U,W]=(0,C.useState)(new Set),[G,K]=(0,C.useState)(`all`),[q,J]=(0,C.useState)([]),Y=(0,C.useCallback)(async()=>{k(!0);try{o((await d(`/plugins`)).plugins)}catch(e){m.error(e instanceof Error?e.message:`Failed to load plugins`)}finally{k(!1)}},[]),X=(0,C.useCallback)(async()=>{j(!0),M(null);try{let[e,t]=await Promise.all([d(`/plugins/marketplace`).catch(()=>({available:[],installed:[]})),d(`/plugins/marketplaces`)]);D(e.available),O(new Set(e.installed.map(e=>e.id))),E(t.sources)}catch(e){M(e instanceof Error?e.message:`Failed to load marketplace`)}finally{j(!1)}},[]),ie=(0,C.useCallback)(async()=>{try{B((await d(`/plugins/stats?limit=20`)).stats)}catch{}},[]),Z=(0,C.useCallback)(async()=>{try{J((await d(`/roles`)).roles)}catch{}},[]);(0,C.useEffect)(()=>{Y(),X(),Z()},[Y,X,Z]);let ae=async(e,t)=>{P(e);try{await d(`/plugins/${encodeURIComponent(e)}/${t?`enable`:`disable`}`,{method:`POST`}),m.success(`${e} ${t?`enabled`:`disabled`} globally`),o(n=>n.map(n=>n.id===e?{...n,globalEnabled:t}:n))}catch(e){m.error(e instanceof Error?e.message:`Failed to ${t?`enable`:`disable`} plugin`)}finally{P(null)}},oe=async e=>{P(e);try{await d(`/plugins/uninstall/${encodeURIComponent(e)}`,{method:`POST`}),m.success(`Plugin uninstalled`),await Promise.all([Y(),X()])}catch(e){m.error(e instanceof Error?e.message:`Uninstall failed`)}finally{P(null)}},se=async(e,t,n)=>{P(e);try{await d(`/plugins/install/${encodeURIComponent(e)}`,{method:`POST`,body:JSON.stringify({scope:`project`,cwd:n})});let r=q.find(e=>e.id===t)?.name??t;m.success(`Installed ${e.split(`@`)[0]} for ${r}`),await Y()}catch(e){m.error(e instanceof Error?e.message:`Install to role failed`)}finally{P(null)}},Q=async()=>{if(L.trim())try{await d(`/plugins/install/${encodeURIComponent(L.trim())}`,{method:`POST`,body:JSON.stringify({})}),m.success(`Source added`),R(``),I(!1),await X()}catch(e){m.error(e instanceof Error?e.message:`Failed to add source`)}},ce=e=>{W(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},$=G===`all`?e:e.filter(e=>e.scope===G);return(0,w.jsxs)(`div`,{className:`space-y-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,w.jsx)(`h1`,{className:`text-lg font-semibold text-slate-100`,children:`Plugins`}),(0,w.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>void Y(),children:(0,w.jsx)(c,{size:14})})]}),(0,w.jsxs)(h,{children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,w.jsx)(r,{size:14,className:`text-slate-400 flex-shrink-0`}),(0,w.jsx)(`button`,{className:`rounded-full px-2 py-0.5 text-xs transition-colors ${G===`all`?`bg-blue-600 text-white`:`bg-slate-800 text-slate-400 hover:bg-slate-700`}`,onClick:()=>K(`all`),children:`All`}),(0,w.jsx)(`button`,{className:`rounded-full px-2 py-0.5 text-xs transition-colors ${G===`user`?`bg-blue-600 text-white`:`bg-slate-800 text-slate-400 hover:bg-slate-700`}`,onClick:()=>K(`user`),children:`User`}),(0,w.jsx)(`button`,{className:`rounded-full px-2 py-0.5 text-xs transition-colors ${G===`project`?`bg-blue-600 text-white`:`bg-slate-800 text-slate-400 hover:bg-slate-700`}`,onClick:()=>K(`project`),children:`Project`}),(0,w.jsx)(`span`,{className:`h-4 w-px bg-slate-700 mx-1`}),u.map(e=>(0,w.jsx)(p,{variant:`muted`,className:`text-xs`,children:e.name},e.name)),(0,w.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[A&&(0,w.jsx)(t,{size:12,className:`animate-spin text-slate-500`}),A?null:(0,w.jsx)(f,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>I(!F),children:F?(0,w.jsx)(l,{size:12}):(0,w.jsx)(te,{size:12})})]})]}),F&&(0,w.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,w.jsx)(`input`,{className:`flex-1 rounded border border-slate-700 bg-slate-900 px-2 py-1.5 text-sm text-slate-200 focus:border-blue-500 focus:outline-none`,value:L,onChange:e=>R(e.target.value),placeholder:`https://github.com/org/marketplace-repo`,onKeyDown:e=>{e.key===`Enter`&&Q()}}),(0,w.jsx)(f,{size:`sm`,onClick:()=>void Q(),disabled:!L.trim(),children:`Add`})]})]}),re?(0,w.jsx)(h,{children:(0,w.jsx)(`div`,{className:`py-8 text-center text-sm text-slate-500`,children:`Loading...`})}):$.length===0?(0,w.jsx)(h,{children:(0,w.jsx)(ne,{icon:(0,w.jsx)(s,{size:32}),title:`No plugins`,description:G===`all`?`No plugins installed. Browse the marketplace or install from a URL.`:`No ${G}-scope plugins installed.`})}):(0,w.jsx)(h,{padding:!1,children:(0,w.jsxs)(S,{children:[(0,w.jsx)(_,{children:(0,w.jsxs)(b,{children:[(0,w.jsx)(v,{className:`w-8`}),(0,w.jsx)(v,{children:`Name`}),(0,w.jsx)(v,{children:`Version`}),(0,w.jsx)(v,{children:`Scope`}),(0,w.jsx)(v,{children:`Type`}),(0,w.jsx)(v,{children:`Activation`}),(0,w.jsx)(v,{children:`Actions`})]})}),(0,w.jsx)(y,{children:$.map(e=>{let n=U.has(e.id),r=e.id.split(`@`)[0],o=N===e.id;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(b,{className:`group`,children:[(0,w.jsx)(x,{children:(0,w.jsx)(`button`,{onClick:()=>ce(e.id),className:`text-slate-500 hover:text-slate-300`,children:n?(0,w.jsx)(a,{size:12}):(0,w.jsx)(i,{size:12})})}),(0,w.jsx)(x,{className:`font-medium text-slate-200`,children:r}),(0,w.jsx)(x,{className:`text-xs text-slate-400`,children:e.version?`v${e.version}`:`—`}),(0,w.jsxs)(x,{children:[(0,w.jsx)(p,{variant:e.scope===`user`?`info`:`warning`,children:e.scope}),e.scope===`project`&&e.projectPath&&(0,w.jsx)(`div`,{className:`text-[10px] text-slate-600 truncate max-w-[120px]`,title:e.projectPath,children:e.projectPath.split(`/`).pop()})]}),(0,w.jsx)(x,{children:(0,w.jsx)(T,{manifest:e.manifest})}),(0,w.jsx)(x,{children:(0,w.jsx)(p,{variant:e.globalEnabled?`success`:`destructive`,children:e.globalEnabled?`User On`:`User Off`})}),(0,w.jsx)(x,{children:(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(f,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:o,onClick:()=>void ae(e.id,!e.globalEnabled),children:o?(0,w.jsx)(t,{size:10,className:`animate-spin`}):e.globalEnabled?`Disable`:`Enable`}),(0,w.jsx)(f,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs text-red-400`,disabled:o,onClick:()=>void oe(e.id),children:(0,w.jsx)(ee,{size:10})})]})})]},e.id),n&&(0,w.jsx)(b,{className:`bg-slate-900/50`,children:(0,w.jsx)(x,{colSpan:7,className:`px-6 py-3`,children:e.manifest?(0,w.jsxs)(`div`,{className:`space-y-3 text-xs`,children:[e.manifest.description&&(0,w.jsx)(`p`,{className:`text-slate-400`,children:e.manifest.description}),(0,w.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[e.manifest.skills.length>0&&(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`mb-1 font-semibold text-slate-300`,children:`Skills`}),e.manifest.skills.map(e=>(0,w.jsxs)(`div`,{className:`text-slate-400`,children:[(0,w.jsx)(`span`,{className:`text-slate-200`,children:e.name}),e.description&&(0,w.jsxs)(`span`,{className:`ml-1 text-slate-500`,children:[`— `,e.description]})]},e.name))]}),e.manifest.agents.length>0&&(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`mb-1 font-semibold text-slate-300`,children:`Agents`}),e.manifest.agents.map(e=>(0,w.jsxs)(`div`,{className:`text-slate-400`,children:[(0,w.jsx)(`span`,{className:`text-slate-200`,children:e.name}),e.description&&(0,w.jsxs)(`span`,{className:`ml-1 text-slate-500`,children:[`— `,e.description]})]},e.name))]}),e.manifest.mcpServers.length>0&&(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`mb-1 font-semibold text-slate-300`,children:`MCP Servers`}),e.manifest.mcpServers.map(e=>(0,w.jsx)(`div`,{className:`text-slate-400`,children:e},e))]}),e.manifest.hooks.length>0&&(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`mb-1 font-semibold text-slate-300`,children:`Hooks`}),e.manifest.hooks.map(e=>(0,w.jsx)(`div`,{className:`text-slate-400`,children:e},e))]})]}),(0,w.jsx)(`div`,{className:`text-slate-600 font-mono truncate mt-1`,title:e.installPath,children:e.installPath}),q.length>0&&e.scope===`user`&&(0,w.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-slate-800`,children:[(0,w.jsx)(`span`,{className:`text-slate-400 mr-2`,children:`Install to Role:`}),q.map(t=>(0,w.jsx)(f,{variant:`ghost`,size:`sm`,className:`h-5 px-2 text-[10px] mr-1`,disabled:N===e.id,onClick:()=>void se(e.id,t.id,t.workspacePath),children:t.name},t.id))]})]}):(0,w.jsx)(`p`,{className:`text-xs text-slate-500`,children:`Loading manifest...`})})},`${e.id}-detail`)]})})})]})}),(0,w.jsxs)(h,{children:[(0,w.jsxs)(`button`,{className:`flex w-full items-center gap-2 text-sm font-semibold text-slate-300`,onClick:()=>{!V&&z.length===0&&ie(),H(!V)},children:[(0,w.jsx)(n,{size:14,className:`text-slate-400`}),`Usage Stats`,V?(0,w.jsx)(a,{size:12,className:`ml-auto`}):(0,w.jsx)(i,{size:12,className:`ml-auto`})]}),V&&(0,w.jsx)(`div`,{className:`mt-3`,children:z.length===0?(0,w.jsx)(`p`,{className:`text-xs text-slate-500 text-center py-2`,children:`No usage data yet`}):(0,w.jsxs)(S,{children:[(0,w.jsx)(_,{children:(0,w.jsxs)(b,{children:[(0,w.jsx)(v,{children:`Plugin`}),(0,w.jsx)(v,{children:`Usage Count`}),(0,w.jsx)(v,{children:`Last Used`})]})}),(0,w.jsx)(y,{children:z.map(e=>(0,w.jsxs)(b,{children:[(0,w.jsx)(x,{className:`font-medium text-slate-200 text-xs`,children:e.pluginName}),(0,w.jsx)(x,{className:`font-mono text-xs text-slate-400`,children:e.usageCount}),(0,w.jsx)(x,{className:`text-xs text-slate-400`,children:e.lastUsed?g(e.lastUsed):`—`})]},e.pluginPath))})]})})]})]})}export{E as Plugins};
|