limixbot 0.3.77 → 0.3.79
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/assets/{ActivityPanel-DvjbofFf.js → ActivityPanel-BVNkqBIC.js} +1 -1
- package/dist/assets/{App-Bq2f15VQ.js → App-CvsehEe_.js} +109 -109
- package/dist/assets/{AppEventEditor-DuUsE0me.js → AppEventEditor-BYguwqDN.js} +1 -1
- package/dist/assets/BotSettingsDialog-Be44NFrp.js +16 -0
- package/dist/assets/{BrowserPanel-BlSlDJd0.js → BrowserPanel-BTCGczPf.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-Bke7bcsA.js → BrowserProfilesManager-DZ2gX0y2.js} +1 -1
- package/dist/assets/{CloudAddDialog-B-ThQKNT.js → CloudAddDialog-DuhiNoO8.js} +1 -1
- package/dist/assets/{ComputerFilesPane-CJIv0RBY.js → ComputerFilesPane-CGP2MSqh.js} +1 -1
- package/dist/assets/{ComputerPanel-DdSgRsMm.js → ComputerPanel-C3jYTvzh.js} +2 -2
- package/dist/assets/{DataPanel-BMIlIpiO.js → DataPanel-B5sek_0y.js} +1 -1
- package/dist/assets/{FilesView-CsT6EBdu.js → FilesView-CGdJc4B8.js} +1 -1
- package/dist/assets/{GrokMoveDialog-C1MGpM8U.js → GrokMoveDialog-BxE7bO-C.js} +1 -1
- package/dist/assets/{InspectorPanel-BS1sziMt.js → InspectorPanel-CKLUT8oB.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-CnhpB8f8.js → KeyboardShortcutsModal-DxL0bhz0.js} +1 -1
- package/dist/assets/{LiveDesktop-BrTG84o7.js → LiveDesktop-DZHAgYhr.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-BRF5EHFx.js → LocalVmWorkspace-5FdM1GcK.js} +1 -1
- package/dist/assets/{MacLocalControl-abjG5Wtn.js → MacLocalControl-COa2bTeU.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-BoPePVFr.js → MarkdownFilePreview-wV4LMjz6.js} +1 -1
- package/dist/assets/{NewBotDialog-v-QPVJ3q.js → NewBotDialog-BTHPAm-H.js} +1 -1
- package/dist/assets/{PhoneAppDialog-bvRPZ50C.js → PhoneAppDialog-Dqcmnx_B.js} +1 -1
- package/dist/assets/{PluginsPanel-BHz-VU8Q.js → PluginsPanel-XaOSjVze.js} +1 -1
- package/dist/assets/{ProIntroduction-DV4hvJRT.js → ProIntroduction-BlMy0JGo.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-9-C0tDRw.js → RemoteAgentSettingsPanel-BYE04c1Y.js} +1 -1
- package/dist/assets/{RoomPanel-C7lvUBM6.js → RoomPanel-Dlzb2mxc.js} +1 -1
- package/dist/assets/{RoutinesPage-DuQVahmB.js → RoutinesPage-esNzRfID.js} +1 -1
- package/dist/assets/{SettingsModal-B6rqdCRG.js → SettingsModal-_yGtX6l0.js} +1 -1
- package/dist/assets/{ShareTeamDialog-_j6OIcg6.js → ShareTeamDialog-NiBljKHE.js} +1 -1
- package/dist/assets/{SignedInSites-Csjrua1R.js → SignedInSites-L4aSrXYW.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-Cv6xUF7r.js → TeamLibraryPanel-CXiA_ll-.js} +1 -1
- package/dist/assets/{TeamMapPage-gkI3aH_U.js → TeamMapPage-C-qti0hy.js} +1 -1
- package/dist/assets/{TriggersPage-6gx2tWhb.js → TriggersPage-C497fuYj.js} +1 -1
- package/dist/assets/{VisibilitySection-DgtWRDhU.js → VisibilitySection-BGZ0rqTi.js} +1 -1
- package/dist/assets/{WebhookTrigger-Cluk2duZ.js → WebhookTrigger-BH1BByzy.js} +1 -1
- package/dist/assets/{WorksOnGrid-R_CuH-yN.js → WorksOnGrid-DWH93kqg.js} +1 -1
- package/dist/assets/{core-BaWX6J0i.js → core-D_78Ynu8.js} +1 -1
- package/dist/assets/{import-name-BNO45DQO.js → import-name-k9CSvERS.js} +1 -1
- package/dist/assets/{index-DfVacFHA.js → index-BMsqhtYl.js} +2 -2
- package/dist/assets/{index-CtBv71Zs.js → index-C3-UCB9t.js} +1 -1
- package/dist/assets/{mcp-servers-C371jWwd.js → mcp-servers-R17O9xFq.js} +1 -1
- package/dist/assets/{new-bot-8Jy_XeCs.js → new-bot-D4-p5E80.js} +1 -1
- package/dist/assets/{org-library-BekGWsad.js → org-library-IoJj_iDs.js} +1 -1
- package/dist/assets/{package-format-Bkx-hoUc.js → package-format-Dek_P3eO.js} +1 -1
- package/dist/assets/{remote-desktop-panel-DvOif4uX.js → remote-desktop-panel-CmslCBxy.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/index.js +3657 -3626
- package/dist-server/package.json +1 -1
- package/dist-server/server/bot-api-host.js +59 -1
- package/dist-server/server/index.js +6 -0
- package/dist-server/server/limix-telegram.js +329 -0
- package/package.json +1 -1
- package/dist/assets/BotSettingsDialog-BtlJN-e1.js +0 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,t as s,j as t,X as $,a as X}from"./styles-1Sa7mQdy.js";import{c as ee,B as te,L as G}from"./PlacesRail-CRmtzh8u.js";import{u as ae,z as F,D as L}from"./App-
|
|
1
|
+
import{r as l,t as s,j as t,X as $,a as X}from"./styles-1Sa7mQdy.js";import{c as ee,B as te,L as G}from"./PlacesRail-CRmtzh8u.js";import{u as ae,z as F,D as L}from"./App-CvsehEe_.js";import{suggestedName as H}from"./WebhookTrigger-BH1BByzy.js";import"./monitor-76fhlY80.js";import"./index-BMsqhtYl.js";import"./MenuMotion-CcuJn489.js";import"./remote-desktop-DDRRx8uY.js";const N="w-full rounded-xl border border-hairline/60 bg-panel px-3.5 py-2.5 text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/70",m="mb-1.5 block text-[12px] font-medium text-ink-secondary";function de({trigger:a,bots:x,initialBotId:y,onClose:h,onSaved:J}){const{dispatch:K}=ae(),[i,Q]=l.useState(a?.botId??(y&&x.some(e=>e.id===y)?y:x[0]?.id)??""),[r,O]=l.useState(null),[v,B]=l.useState(a?.app??""),[b,k]=l.useState(a?.event??""),[g,U]=l.useState(a?.accountId??""),[D,V]=l.useState(a?.filter??{}),[f,E]=l.useState({}),[u,W]=l.useState(a?.prompt??""),[w,Y]=l.useState(a?.name??""),[I,P]=l.useState(!1),[S,C]=l.useState(""),R=l.useRef(null);ee(R,h),l.useEffect(()=>{if(a||!i)return;let e=!0;return O(null),F.events(i).then(n=>{if(!e)return;O(n);const o=n.apps.find(d=>d.events.length);B(d=>n.apps.some(A=>A.app===d)?d:o?.app??"")}).catch(n=>{e&&C(n instanceof Error?n.message:String(n))}),()=>{e=!1}},[i,a]);const p=r?.apps.find(e=>e.app===v),z=p?.events??[],c=z.find(e=>e.event===b)??(a?void 0:z[0]);l.useEffect(()=>{!a&&c&&c.event!==b&&k(c.event)},[c,b,a]);const q=(c?.configFields??[]).filter(e=>e.required),Z=v==="gmail",M=a?.delivery??c?.delivery,_=async()=>{const e=x.find(o=>o.id===i),n=Object.fromEntries(Object.entries(D).filter(([,o])=>typeof o=="string"&&o.trim()));P(!0),C("");try{const o=a?await F.update(a.id,{name:w.trim()||a.name,prompt:u.trim(),filter:Object.keys(n).length?n:null}):await F.create({botId:i,app:v,event:c?.event??b,prompt:u.trim(),name:w.trim()||H(u,e),...g?{account:g}:{},...Object.keys(n).length?{filter:n}:{},...Object.keys(f).length?{config:f}:{}});J?.(o),h()}catch(o){C(o instanceof Error?o.message:String(o))}finally{P(!1)}},j=(e,n,o)=>t.jsxs("label",{className:"block",children:[t.jsx("span",{className:m,children:n}),t.jsx("input",{value:D[e]??"",onChange:d=>V(A=>({...A,[e]:d.target.value})),placeholder:o,className:N})]},e),T=a?s("automations.editor.app.editTitle"):s("automations.editor.appEvent.title");return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-5",onMouseDown:e=>e.stopPropagation(),children:t.jsxs("div",{ref:R,role:"dialog","aria-modal":"true","aria-label":T,tabIndex:-1,className:"flex max-h-[90vh] w-full max-w-[560px] flex-col overflow-hidden rounded-2xl border border-hairline/60 bg-panel shadow-2xl",children:[t.jsxs("div",{className:"flex items-start justify-between border-b border-hairline/40 px-5 py-4",children:[t.jsx("div",{className:"text-[17px] font-semibold text-ink",children:T}),t.jsx("button",{type:"button",onClick:h,"aria-label":s("automations.newBox.cancel"),className:"rounded-lg p-2 text-ink-secondary hover:bg-raised hover:text-ink",children:t.jsx($,{size:18})})]}),t.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-5",children:[!a&&t.jsxs("div",{children:[t.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:s("automations.editor.app.who")}),t.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:x.map(e=>t.jsxs("button",{type:"button",onClick:()=>Q(e.id),className:X("flex min-w-0 items-center gap-2 rounded-xl border px-3 py-2 text-left",i===e.id?"border-accent/70 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised/60"),children:[t.jsx(te,{bot:e,state:i===e.id?"happy":"idle",size:32,animated:!1}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium text-ink",children:e.name})]},e.id))})]}),!a&&!r&&!S&&t.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[t.jsx(G,{size:14,className:"animate-spin"}),s("automations.editor.appEvent.loading")]}),!a&&r&&(r.unavailable||!r.apps.some(e=>e.events.length))&&t.jsxs("div",{className:"rounded-xl border border-hairline/45 bg-inset/50 p-3.5 text-[13px] text-ink-secondary",children:[t.jsx("p",{children:r.unavailable??s("automations.editor.appEvent.noApps")}),!r.unavailable&&t.jsx("button",{type:"button",onClick:()=>K({type:"togglePlugins",open:!0,surface:"apps"}),className:"mt-2.5 rounded-lg bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink hover:brightness-110",children:s("automations.editor.appEvent.connect")})]}),!a&&r&&p&&t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.jsxs("label",{className:"block",children:[t.jsx("span",{className:m,children:s("automations.editor.appEvent.app")}),t.jsx(L,{value:v,onChange:e=>{B(e.target.value),k(""),E({})},"aria-label":s("automations.editor.appEvent.app"),className:"w-full",children:r.apps.filter(e=>e.events.length).map(e=>t.jsx("option",{value:e.app,children:e.name},e.app))})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:m,children:s("automations.editor.appEvent.event")}),t.jsx(L,{value:c?.event??"",onChange:e=>{k(e.target.value),E({})},"aria-label":s("automations.editor.appEvent.event"),className:"w-full",children:z.map(e=>t.jsx("option",{value:e.event,children:e.name},e.event))})]}),p.accounts.length>1&&t.jsxs("label",{className:"block sm:col-span-2",children:[t.jsx("span",{className:m,children:s("automations.editor.appEvent.account")}),t.jsxs(L,{value:g,onChange:e=>U(e.target.value),"aria-label":s("automations.editor.appEvent.account"),className:"w-full",children:[t.jsx("option",{value:""}),p.accounts.map(e=>t.jsx("option",{value:e.id,children:e.alias??e.id},e.id))]})]}),q.map(e=>t.jsxs("label",{className:"block sm:col-span-2",children:[t.jsx("span",{className:m,children:e.name}),t.jsx("input",{value:f[e.name]??"",onChange:n=>E(o=>({...o,[e.name]:n.target.value})),placeholder:e.description,className:N})]},e.name))]}),(a||p)&&t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[Z?[j("from",s("automations.editor.appEvent.from"),"acme.com"),j("subject",s("automations.editor.appEvent.subject"),"order"),j("label",s("automations.editor.appEvent.label"),"Customers")]:j("text",s("automations.editor.appEvent.text"),"urgent"),M&&t.jsx("p",{className:"self-end text-[12px] text-ink-secondary sm:col-span-2",children:M==="poll"?s("automations.editor.appEvent.checks"):s("automations.editor.appEvent.instant")})]}),(a||p)&&t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"mb-2 block text-[13px] font-medium text-ink",children:s("automations.editor.app.what")}),t.jsx("textarea",{value:u,onChange:e=>W(e.target.value),rows:3,placeholder:s("automations.editor.appEvent.whatPlaceholder"),className:X(N,"resize-y py-3 leading-relaxed")})]}),(a||p)&&t.jsxs("details",{className:"rounded-xl border border-hairline/45 bg-inset/45 px-4 py-3",children:[t.jsx("summary",{className:"cursor-pointer text-[13px] font-medium text-ink",children:s("automations.more")}),t.jsxs("label",{className:"mt-4 block",children:[t.jsx("span",{className:m,children:s("automations.editor.app.name")}),t.jsx("input",{value:w,onChange:e=>Y(e.target.value),placeholder:H(u,x.find(e=>e.id===i)),className:N})]})]}),S&&t.jsx("div",{role:"alert",className:"rounded-xl border border-danger/30 bg-danger/10 px-3.5 py-3 text-[12px] text-danger",children:S})]}),t.jsxs("div",{className:"flex justify-end gap-2 border-t border-hairline/40 px-5 py-4",children:[t.jsx("button",{type:"button",onClick:h,className:"rounded-xl px-4 py-2 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:s("automations.newBox.cancel")}),t.jsxs("button",{type:"button",disabled:I||!i||!a&&!c||q.some(e=>!f[e.name]?.trim()),onClick:()=>{_()},className:"flex items-center gap-2 rounded-xl bg-accent px-4 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110 disabled:opacity-40",children:[I&&t.jsx(G,{size:14,className:"animate-spin"}),a?s("automations.editor.app.save"):s("automations.editor.app.create")]})]})]})})}export{de as AppEventEditor};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{c as Ie,t as s,b as se,aF as Ds,j as e,i as Be,ae as he,a as O,r as u,S as Xe,ah as Ut,X as Ze,f as ct}from"./styles-1Sa7mQdy.js";import{fg as Fs,fh as zs,a2 as et,bB as Hs,dj as qt,w as _s,fi as Ks,fj as Us,K as Wt,fk as qs,R as Vt,eu as Ws,x as Vs,fl as dt,bv as mt,fm as Gt,n as Q,u as $,fn as Gs,aj as tt,F as Yt,A as Jt,S as Pe,af as Te,T as Qt,W as Ys,fo as Js,fp as Qs,fq as Xs,fr as Zs,fs as ea,ft as pt,fu as ta,fv as sa,fw as aa,fx as na,bb as ra,fy as ia,fz as la,fA as oa,I as ca,fB as Se,bR as st,fC as da,aK as A,aQ as ee,ee as ma,dL as pa,fD as ua,aL as We,cq as xa,d_ as ha,d$ as fa,fE as ga,fF as Xt,fG as Zt,fH as ya,fI as ba,fJ as va,fK as ka,dO as Ve,at as ut,fL as $e,fM as ja,fN as Oe,ax as wa,fO as es,fP as xt,am as Ge,fQ as Na,fR as Sa,fS as Ca,fT as ts,fU as Pa,fV as Oa,fW as Ea,fX as Ra,fY as Z,aZ as ae,a$ as X,fZ as Ia,f_ as Ta,f$ as La,d6 as Aa,d as Ma,G as Ba,d4 as ss,al as $a,g0 as V,aY as de,g1 as me,by as R,g2 as Da,dq as Fa,g3 as Le,a_ as ie,g4 as za,g5 as Ha,g6 as _a,ei as Ka,g7 as ht,g8 as Ua,g9 as qa,ga as Wa,gb as Va,gc as Ga,gd as Ya,aE as Ja,ge as as,gf as Qa,gg as Xa,gh as Za,gi as en,gj as tn,gk as sn,gl as an,gm as nn,gn as rn,go as ln,gp as on,gq as cn,gr as at,k as dn,B as Ye,gs as mn,gt as pn,gu as un,gv as xn,b_ as hn,gw as ns,J as ft,eY as fn,gx as gt,gy as gn,gz as yn,cN as yt,bz as bn,d3 as vn,gA as kn,gB as rs,gC as je,gD as bt,gE as jn,aO as De,e0 as wn,gF as Nn,aT as Sn,C as Cn,cr as Pn,gG as On,gH as En,gI as Rn,aV as In}from"./App-CvsehEe_.js";import{v as is,d as be,a1 as Ee,a2 as Tn,a3 as Ln,a4 as vt,a5 as Fe,a6 as An,a7 as Mn,a8 as Bn,a9 as $n,aa as Dn,ab as kt,ac as Fn,ad as zn,L as Ce,N as Hn,B as Je,P as ve,r as ls,ae as _n,a0 as Kn,u as os}from"./PlacesRail-CRmtzh8u.js";import{C as Un}from"./coins-2Ipg9jSL.js";import{C as ye,a as qn}from"./MenuMotion-CcuJn489.js";import{b as te,m as cs,i as Qe,f as nt,c as xe,d as jt,e as Re,o as Wn,g as Vn,h as ce,n as ze,t as ds,s as rt,j as ms,k as Gn,l as Yn,p as Jn,r as ps,q as Qn,u as Xn,w as Zn,x as us,y as xs,z as wt,B as er,C as hs,R as Nt,D as tr,E as sr,F as ar,G as nr,H as rr,J as ir,O as lr,K as or,L as fs,N as St,V as cr,P as dr,M as mr,A as pr,a as ur,S as xr,I as hr}from"./VisibilitySection-BGZ0rqTi.js";import{s as fr,r as gr,a as yr,R as br}from"./ComputerFilesPane-CGP2MSqh.js";import{M as Ct}from"./monitor-76fhlY80.js";import{a as gs,m as ys,b as vr,c as kr}from"./mcp-servers-R17O9xFq.js";import{R as jr}from"./RoutinesPage-esNzRfID.js";import{S as wr}from"./SignedInSites-L4aSrXYW.js";import"./index-BMsqhtYl.js";import"./org-library-IoJj_iDs.js";import"./package-format-Dek_P3eO.js";import"./WorksOnGrid-DWH93kqg.js";import"./ProIntroduction-BlMy0JGo.js";import"./remote-desktop-DDRRx8uY.js";const Nr=[["path",{d:"M16 19h6",key:"xwg31i"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M21 12.598V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8.5",key:"1glfrc"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}]],Sr=Ie("calendar-plus",Nr);const Cr=[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]],Pr=Ie("library",Cr);const Or=[["rect",{width:"3",height:"8",x:"13",y:"2",rx:"1.5",key:"diqz80"}],["path",{d:"M19 8.5V10h1.5A1.5 1.5 0 1 0 19 8.5",key:"183iwg"}],["rect",{width:"3",height:"8",x:"8",y:"14",rx:"1.5",key:"hqg7r1"}],["path",{d:"M5 15.5V14H3.5A1.5 1.5 0 1 0 5 15.5",key:"76g71w"}],["rect",{width:"8",height:"3",x:"14",y:"13",rx:"1.5",key:"1kmz0a"}],["path",{d:"M15.5 19H14v1.5a1.5 1.5 0 1 0 1.5-1.5",key:"jc4sz0"}],["rect",{width:"8",height:"3",x:"2",y:"8",rx:"1.5",key:"1omvl4"}],["path",{d:"M8.5 5H10V3.5A1.5 1.5 0 1 0 8.5 5",key:"16f3cl"}]],bs=Ie("slack",Or);const Er=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],Rr=Ie("tag",Er),Ir=[{id:"overview",label:"Overview",labelKey:"botSettings.sections.overview",icon:Fs,keywords:["summary","status","what it does","won't","prompt","what the model sees"]},{id:"identity",label:"Identity",labelKey:"botSettings.sections.identity",icon:zs,keywords:["name","title","avatar","blurb","instructions"]},{id:"slack",label:"Slack",icon:bs,keywords:["slack","slack app","admin","message","direct messages","mentions"]},{id:"soul",label:"Soul",labelKey:"botSettings.sections.soul",icon:et,keywords:["standing instructions","instructions","persona","rules","soul.md"]},{id:"skills",label:"Skills",labelKey:"botSettings.sections.skills",icon:Hs,keywords:["skills","learned","procedures","teach"]},{id:"memory",label:"Memory",labelKey:"botSettings.sections.memory",icon:qt,keywords:["memory","notes","remember","topics"]},{id:"library",label:"Library",labelKey:"botPanel.tab.library",icon:Pr,keywords:["library","made","pages","apps","files","published"]},{id:"routines",label:"Routines",labelKey:"botSettings.sections.routines",icon:_s,keywords:["schedule","routines","cron","tasks"]},{id:"access",label:"Access",labelKey:"botSettings.sections.access",icon:Ks,keywords:["works on","computer","vm","cloud","vps","folder","workspace","browser","connected apps","composio","webhooks","always allow","grants","tool selection","tools","mcp","allow","exclude"]},{id:"model",label:"Model",labelKey:"botSettings.sections.model",icon:Us,keywords:["engine","model","provider","cli","effort"]},{id:"permissions",label:"Permissions",labelKey:"botSettings.sections.permissions",icon:Wt,keywords:["auto mode","approve","auto approve","review","routine approvals","coordination","chief of staff","section"]},{id:"voice",label:"Voice & alerts",labelKey:"botSettings.sections.voice",icon:qs,keywords:["voice","alerts","notifications","speak"]},{id:"visibility",label:"Who can see it",labelKey:"botSettings.visibility.title",icon:Vt,keywords:["visibility","who can see","private","people","admins","members","access","hide"]},{id:"history",label:"History",labelKey:"botSettings.sections.history",icon:Ws,keywords:["history","changes","undo","rollback","log"]},{id:"usage",label:"Usage",labelKey:"botSettings.sections.usage",icon:Un,keywords:["tokens","cost","billing"]}],Pt={completed:"botOverview.routine.last.completed",failed:"botOverview.routine.last.failed",missed:"botOverview.routine.last.missed",cancelled:"botOverview.routine.last.cancelled",running:"botOverview.routine.last.running",queued:"botOverview.routine.last.queued",waiting:"botOverview.routine.last.waiting"};function Tr(t,a=se()){if(!t||a==="en")return null;if(t.paused)return s("botOverview.routine.paused",{name:t.name});const n=t.lastRun;if(n&&!Object.hasOwn(Pt,n.status))return null;try{return[s("botOverview.routine.line",{schedule:Vs(t.schedule),name:t.name}),...t.nextRunAt!=null?[s("botOverview.routine.next",{time:dt(t.nextRunAt)})]:[],...n?[s(Pt[n.status],{time:dt(n.at)})]:[]].join(" ")}catch{return null}}const Ot={"Works in its private workspace.":"botOverview.line.privateWorkspace","Has the built-in browser.":"botOverview.line.browser","Has no connected apps.":"botOverview.line.noApps","Won't act on a schedule.":"botOverview.line.noSchedule","Can talk to the other bot.":"botOverview.line.talksToOne","Talks only to the bots chosen for it.":"botOverview.line.talksToChosen","Cannot initiate contact with other bots.":"botOverview.line.noPeerContact","Command approvals use Ask mode; saved permissions and provider rules still apply.":"botOverview.line.askMode","Command approvals follow the provider's custom configuration.":"botOverview.line.customApprovals","Asks before contacting other bots.":"botOverview.line.asksPeers","Can't use a computer.":"botOverview.line.noComputer","Profile proposal cards require your approval.":"botOverview.line.profileApproval","Connected apps could not be checked.":"botOverview.line.appsUnchecked"},Et={"Auto; availability is checked when a task starts":"botOverview.preference.auto","cloud computer":"botOverview.preference.cloud","Local VM":"botOverview.preference.vm","this computer":"botOverview.preference.local","browser only":"botOverview.preference.browser"};function Rt(t,a){return!a||a.map(n=>n||"General").join(", ")!==t?t:a.map(n=>n||s("botAccess.teams.general")).join(", ")}const It=t=>Object.hasOwn(Et,t)?s(Et[t]):t,Tt=(t,a,n)=>Number(t)===1?a:n,Lr=[{line:/^Can talk to all (\d+) other bots, in any department\.$/,key:()=>"botOverview.line.talksToAll",params:([,t])=>({count:Number(t)})},{line:/^Also in charge of these departments: (.+)\.$/,key:()=>"botOverview.line.alsoInCharge",params:([,t],a)=>({departments:Rt(t,a)})},{line:/^Can talk to (\d+) other bots? in its (?:section|department)\.$/,key:([,t])=>Tt(t,"botOverview.line.peersSectionOne","botOverview.line.peersSectionMany"),params:([,t])=>({count:Number(t)})},{line:/^Can talk to (\d+) other bots? in its allowed (?:teams|departments)\.$/,key:([,t])=>Tt(t,"botOverview.line.peersTeamsOne","botOverview.line.peersTeamsMany"),params:([,t])=>({count:Number(t)})},{line:/^Coordinates its (?:section|department) as Chief of Staff\.$/,key:()=>"botOverview.line.chief",params:()=>({role:s("sidebar.bot.chiefOfStaff")})},{line:/^May also coordinate these (?:teams|departments): (.+)\.$/,key:()=>"botOverview.line.alsoTeams",params:([,t],a)=>({teams:Rt(t,a)})}],Ar=t=>se()!=="en"&&Object.hasOwn(Ds[se()]??{},t);function Mr(t,a){for(const n of Lr){const i=n.line.exec(t);if(!i)continue;const r=n.key(i);return Ar(r)?s(r,n.params(i,a)):t}return null}function He(t,a){if(Object.hasOwn(Ot,t))return s(Ot[t]);const n=Mr(t,a);if(n!==null)return n;const i=/^Can use (\d+) connected apps?: (.+)\.$/.exec(t);if(i)return s(i[1]==="1"?"botOverview.line.appsOne":"botOverview.line.appsMany",{count:Number(i[1]),apps:i[2]});const r=se()==="en"?null:/^Computer preference: (.+), which isn't available on My Cloud\.$/.exec(t);if(r)return s("botOverview.line.computerNotOnCloud",{preference:It(r[1])});const l=/^Computer preference: (.+)\.$/.exec(t);if(l)return s("botOverview.line.computer",{preference:It(l[1])});const c=/^Works in (.+)\.$/.exec(t);if(c)return s("botOverview.line.folder",{folder:c[1]});const m=/^Knows how to (.+)\.$/.exec(t);if(m)return s("botOverview.line.skill",{skill:m[1]});const o=/^Listens for “(.+)” webhooks\.$/.exec(t);return o?s("botOverview.line.webhook",{name:o[1]}):t}const Lt={name:"approval.applied.field.name",title:"approval.applied.field.title",description:"approval.applied.field.description",soul:"approval.applied.field.soul",cwd:"approval.applied.field.cwd",notifications:"approval.applied.field.notifications",speakReplies:"approval.applied.field.speakReplies"};function Br(t,a=se()){const n=/^(\w+): /.exec(t)?.[1];return a==="en"||!n||!Object.hasOwn(Lt,n)?t:`${s(Lt[n])}: ${t.slice(n.length+2)}`}function $r({data:t,error:a,open:n,onToggle:i}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("button",{type:"button",onClick:i,"aria-expanded":n,className:"flex w-full items-center justify-between gap-3 text-left",children:[e.jsx("span",{className:"text-[15px] font-medium text-ink",children:t?s("botOverview.promptPreviewCount",{bytes:t.totalBytes.toLocaleString(Be()),tokens:t.approxTokens.toLocaleString(Be())}):s("botOverview.promptPreview")}),e.jsx(he,{size:16,className:O("shrink-0 text-ink-secondary transition-transform",n&&"rotate-180")})]}),n&&!t&&a&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.promptError")}),n&&!t&&!a&&e.jsx("div",{className:"mt-3 text-[13px] text-ink-secondary",children:s("botOverview.loading")}),n&&t&&e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[t.sections.map(r=>e.jsxs("details",{className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center justify-between gap-3 text-[13px] text-ink",children:[e.jsx("span",{children:r.label}),e.jsx("span",{className:"shrink-0 tabular-nums text-ink-secondary",children:s("botOverview.bytes",{count:r.bytes.toLocaleString(Be())})})]}),e.jsx("pre",{className:"mt-2 max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-relaxed text-ink",children:r.text})]},r.id)),t.note&&e.jsx("div",{className:"text-[11px] text-ink-secondary",children:t.note})]})]})}function Dr({overview:t,refreshError:a,prompt:n,promptError:i,onOpen:r,onSetup:l}){const[c,m]=u.useState(!1);if(!t)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("botOverview.loading")});const d=(t.setup??[]).filter(f=>!f.done),p=(f,j)=>s(`botOverview.setup.${f}`)||j;return e.jsxs("div",{className:"flex flex-col gap-4",children:[a&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary",children:s("botOverview.refreshError")}),d.length>0&&e.jsxs("div",{className:"rounded-xl border border-accent/30 bg-accent/[0.06] p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botSetup.ideas")}),e.jsx("p",{className:"mt-1 text-[13px] text-ink-secondary",children:s("botSetup.optional")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1",children:d.map(f=>e.jsx("li",{children:f.section?e.jsxs("button",{type:"button",onClick:()=>r(f.section),className:"flex w-full items-center gap-2.5 rounded-lg px-1 py-1 text-left text-[13px] text-ink hover:bg-inset",children:[e.jsx(mt,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"flex-1",children:p(f.id,f.label)}),e.jsx(ye,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-secondary rtl:-scale-x-100"})]}):e.jsxs("div",{className:"flex items-center gap-2.5 px-1 py-1 text-[13px] text-ink",children:[e.jsx(mt,{"aria-hidden":"true",size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{children:p(f.id,f.label)})]})},f.id))}),l&&e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110",children:[e.jsx(et,{size:14})," ",s("botSetup.withBot")]}),e.jsx("span",{className:"text-[12px] text-ink-secondary",children:s("botSetup.help")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t.who.name}),t.who.title&&e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t.who.title}),t.who.blurb&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink",children:t.who.blurb}),t.who.soulLead&&e.jsxs("div",{className:"mt-3 rounded-lg bg-inset px-3 py-2.5",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t.who.soulLead}),e.jsx("button",{type:"button",onClick:()=>r("soul"),className:"mt-1.5 rounded-md text-[12px] font-medium text-accent-text hover:underline",children:s("botOverview.readAll")})]})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.does")}),t.does.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.doesEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.does.map((f,j)=>e.jsx("li",{children:Tr(t.doesRoutines?.[j])??He(f)},j))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.canReach")}),t.reaches.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.reachEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.reaches.map((f,j)=>e.jsx("li",{children:He(f,t.managedSections)},j))})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.wont")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] leading-relaxed text-ink",children:t.wont.map((f,j)=>e.jsx("li",{children:He(f,t.managedSections)},j))})]}),e.jsx($r,{data:n,error:i,open:c,onToggle:()=>m(f=>!f)}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("botOverview.recentChanges")}),e.jsxs("button",{type:"button",onClick:()=>r("history"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink",children:[s("botOverview.viewAll")," ",e.jsx(ye,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]})]}),t.recent.length===0?e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("botOverview.recentEmpty")}):e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] text-ink",children:t.recent.map((f,j)=>e.jsxs("li",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("span",{className:"min-w-0 truncate",children:Br(f.summary)}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:["· ",Gt(f.at)]})]},j))})]})]})}function Fr({managementUrl:t}){return e.jsxs("div",{className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:s("botSlack.body")}),e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"flex w-fit items-center gap-2 rounded-lg bg-control px-3 py-2 font-medium text-ink hover:bg-control/70",children:[s("botSlack.manage")," ",e.jsx(is,{size:14,"aria-hidden":"true"})]})]})}function zr(t){if(!t||typeof t!="object")return null;const{available:a,managementUrl:n}=t;if(a!==!0||typeof n!="string")return null;try{return new URL(n).protocol==="https:"?n:null}catch{return null}}function vs(t){const[a,n]=u.useState(null);return u.useEffect(()=>{const i=new AbortController;return Q(`/api/bots/${encodeURIComponent(t)}/slack-management`,{signal:i.signal,timeoutMs:1e4}).then(r=>{i.signal.aborted||n({botId:t,url:zr(r)})}).catch(()=>{i.signal.aborted||n({botId:t,url:null})}),()=>i.abort()},[t]),a?.botId===t?a.url:null}const re="rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",_e="rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",ne=t=>t instanceof Error?t.message:String(t);function ks(t){const a=[],n=(r,l,c)=>{r&&a.push(s(r===1?l:c,{count:r}))};n(t.expired,"memory.upkeep.summary.archived.one","memory.upkeep.summary.archived.many"),n(t.duplicates,"memory.upkeep.summary.merged.one","memory.upkeep.summary.merged.many"),n(t.superseded,"memory.upkeep.summary.crossed.one","memory.upkeep.summary.crossed.many"),n(t.organized,"memory.upkeep.summary.filed.one","memory.upkeep.summary.filed.many");const i=a.length?a.join(", "):s("memory.upkeep.summary.none");return i.charAt(0).toUpperCase()+i.slice(1)}function Hr(t,a){const n=t.via==="team-setup"?s("memory.journal.actor.teamSetup"):t.actor==="bot"?a:t.actor==="import"?s("memory.journal.actor.import"):t.actor==="upkeep"?s("memory.journal.actor.upkeep"):s("memory.journal.actor.you"),i=Qn(t.path),r=t.path===te?i:t.path===Xn?s("memory.journal.instructions"):t.path.startsWith("memory/log/")?s("memory.journal.log",{file:i}):s("memory.journal.topic",{file:i}),l=c=>s(c===1?"memory.journal.line.one":"memory.journal.line.many",{count:c});return t.kind==="created"?s("memory.journal.created",{who:n,topic:r,detail:t.added?s("memory.journal.withLines",{lines:l(t.added)}):""}):t.kind==="deleted"?s("memory.journal.deleted",{who:n,topic:r}):t.added&&!t.removed?s("memory.journal.added",{who:n,lines:l(t.added),topic:r}):t.removed&&!t.added?s("memory.journal.removed",{who:n,lines:l(t.removed),topic:r}):s("memory.journal.rewrote",{who:n,lines:l(Math.max(t.added,t.removed)),topic:r})}function js({changed:t,stale:a,busy:n,onReviewed:i}){return e.jsxs("div",{role:"status",className:"rounded-xl border border-danger/40 bg-card p-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink",children:s(a?"memory.lendingReviewStale":"memory.lendingReview")}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.lendingReviewChanged")}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:t.map(r=>e.jsx("li",{className:"break-all font-mono text-[12px] text-ink",children:r},r))})]}),e.jsx("button",{type:"button",className:O(re,"mt-3"),disabled:n,onClick:i,children:s("memory.lendingReviewed")})]})}function _r({bot:t,active:a=!0,onToggle:n}){const{capabilities:i}=be(),[r,l]=u.useState(null),[c,m]=u.useState(null),[o,d]=u.useState(null),[p,f]=u.useState(null),[j,g]=u.useState(null),[v,k]=u.useState(null),[C,b]=u.useState(null),[w,x]=u.useState(!1),[S,M]=u.useState(null),[F,B]=u.useState(""),[T,H]=u.useState(null),[L,h]=u.useState(!1),[I,D]=u.useState(null),[_,K]=u.useState(!1),[J,Y]=u.useState(!1),{state:U,dispatch:y}=$(),z=Gs(U.config),[le,pe]=u.useState(!1),[fe,P]=u.useState(""),q=async N=>{const[E,Ae,$s]=await Promise.all([nt(t.id),xe(t.id),jt(t.id).catch(()=>null)]);if(l(E),D(E.lendingReview??null),m(Ae),H($s),N){const Me=await Re(t.id,N);d({path:Me.path,text:Me.text,hash:Me.hash,dirty:!1,readOnly:N.startsWith("memory/log/")})}};u.useEffect(()=>{if(!a)return;let N=!1;k(null);const E=o?.dirty===!0;return q(E?void 0:o?.path??te).catch(Ae=>{N||k(ne(Ae))}),()=>{N=!0}},[a,t.id]);const G=async N=>{k(null),f(null);try{const E=await Re(t.id,N);d({path:E.path,text:E.text,hash:E.hash,dirty:!1,readOnly:N.startsWith("memory/log/")})}catch(E){k(ne(E))}},W=async N=>{if(o){x(!0),k(null);try{const E=await rt(t.id,o.path,o.text,N);if(!E.ok){f({path:o.path,current:E.current,currentHash:E.currentHash});return}f(null),g(null),d({...o,text:E.doc.text,hash:E.doc.hash,dirty:!1}),l(E.overview),m(await xe(t.id))}catch(E){k(ne(E))}finally{x(!1)}}},oe=()=>{!p||!o||(g(o.text),d({...o,text:p.current,hash:p.currentHash,dirty:!1}),f(null))},ke=async N=>{if(window.confirm(s("memory.confirmDelete",{name:N.name}))){k(null);try{const{overview:E}=await ms(t.id,N.path);l(E),m(await xe(t.id)),o?.path===N.path&&d(null)}catch(E){k(ne(E))}}},lt=async()=>{const N=Gn(F);if(!N){k(s("memory.topicNameError"));return}B(""),await G(`memory/${N}`),d(E=>E&&{...E,dirty:!0,text:E.text||Kr(N)})},Ts=async N=>{M(N.id),k(null);try{const E=await ps(t.id,N.id);l(E.overview),m(await xe(t.id)),o?.path===N.path&&!o.dirty&&d({...o,text:E.text,hash:E.hash}),b(s("memory.restored",{path:N.path}))}catch(E){k(ne(E))}finally{M(null)}},ot=async N=>{k(null),b(null);try{await Wn(t.id,N)}catch(E){k(ne(E))}},Ls=()=>{const N=t.memoryUpkeep===!1;y({type:"updateBot",botId:t.id,patch:{memoryUpkeep:N}}),H(E=>E&&{...E,enabled:N})},As=async()=>{if(!le){pe(!0),P("");try{const N=await Q("/api/config",{method:"PATCH",body:JSON.stringify({features:{roomMemoryCapture:!z}})});y({type:"configStatus",config:N})}catch(N){P(N instanceof Error?N.message:s("memory.learnFromRooms.error"))}finally{pe(!1)}}},Ms=async()=>{h(!0),k(null),b(null);try{const{report:N,overview:E}=await ds(t.id);l(E),m(await xe(t.id)),H(await jt(t.id)),o&&!o.dirty&&await G(o.path),b(`${ks(N)}.${N.note?` ${N.note}`:""}`)}catch(N){k(ne(N))}finally{h(!1)}},Bs=i.host.homeDir;return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.title")}),e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:t.memoryEnabled!==!1,disabled:t.busy,onChange:N=>n(N.target.checked)}),s("memory.enable")]}),e.jsxs("p",{className:"mt-1 text-[13px] text-ink-secondary",children:[s("memory.enableHelp"),t.busy?` ${s("memory.busyHelp")}`:""]}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.notesHelp")}),r&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink-secondary",title:r.workspacePath,children:tt(r.workspacePath,Bs)}),e.jsx("button",{type:"button",className:re,onClick:()=>{ot("obsidian")},children:s("memory.openObsidian")}),e.jsxs("button",{type:"button",className:O(re,"inline-flex items-center gap-1.5"),onClick:()=>{ot("folder")},children:[e.jsx(Yt,{size:14}),s("memory.showFileManager")]})]})]}),I&&e.jsx(js,{changed:I.changed,stale:_,busy:J,onReviewed:()=>{Y(!0),cs(t.id,I.token).then(()=>{D(null),K(!1)}).catch(N=>{if(N instanceof Jt&&N.status===409)return K(!0),q();k(ne(N))}).finally(()=>Y(!1))}}),r&&e.jsx(qr,{index:r.index}),t.memoryEnabled!==!1&&e.jsx(Ur,{enabled:t.memoryUpkeep!==!1,status:T,tidying:L,onToggle:Ls,onTidy:()=>{Ms()},rooms:{enabled:z,saving:le,error:fe,onToggle:()=>{As()}}}),o&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate font-mono text-[13px] text-ink",children:o.path}),o.path!==te&&e.jsx("button",{type:"button",className:_e,onClick:()=>{G(te)},children:s("memory.backToIndex")})]}),p&&e.jsx(ws,{botName:t.name,busy:w,onReload:oe,onOverwrite:()=>{W(p.currentHash)}}),e.jsx("textarea",{className:O(Qe,"mt-2 min-h-[200px] resize-y font-mono text-[13px] leading-relaxed"),value:o.text,readOnly:o.readOnly,placeholder:o.path===te?s("memory.indexPlaceholder"):s("memory.notePlaceholder"),"aria-label":o.path===te?s("memory.botMemory"):s("memory.fileLabel",{path:o.path}),onChange:N=>d({...o,text:N.target.value,dirty:!0})}),o.readOnly?e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:s("memory.logsReadOnly")}):e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{W(o.hash)},disabled:w||!o.dirty,className:re,children:w?s("memory.saving"):s("memory.save")}),o.dirty&&e.jsx("button",{type:"button",className:_e,disabled:w,onClick:()=>{G(o.path)},children:s("memory.discard")})]}),j!==null&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"mb-1 text-[12px] text-ink-secondary",children:s("memory.unsavedDraft")}),e.jsx("pre",{className:"max-h-[160px] overflow-auto whitespace-pre-wrap rounded-lg border border-hairline/40 bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:j}),e.jsx("button",{type:"button",className:O(_e,"mt-1"),onClick:()=>g(null),children:s("memory.dismissDraft")})]})]}),r&&e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx(Mt,{title:s("memory.topicFiles"),hint:s("memory.topicFilesHint"),files:r.topics,selected:o?.path,onOpen:N=>{G(N.path)},onDelete:N=>{ke(N)}}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("input",{className:O(Qe,"py-1.5 text-[13px]"),value:F,placeholder:s("memory.newTopicPlaceholder"),"aria-label":s("memory.newTopicLabel"),onChange:N=>B(N.target.value),onKeyDown:N=>{N.key==="Enter"&<()}}),e.jsx("button",{type:"button",className:re,disabled:!F.trim(),onClick:()=>{lt()},children:s("memory.newTopic")})]}),r.logs.length>0&&e.jsx("div",{className:"mt-4",children:e.jsx(Mt,{title:s("memory.dailyLogs"),hint:s("memory.dailyLogsHint"),files:r.logs,selected:o?.path,onOpen:N=>{G(N.path)},onDelete:N=>{ke(N)}})})]}),e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.changes")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.changesHelp")}),e.jsx("div",{className:"mt-3",children:e.jsx(it,{rows:c,botName:t.name,reverting:S,onRevert:N=>{Ts(N)}})})]}),C&&e.jsx("div",{className:"text-[13px] text-ink-secondary",children:C}),v&&e.jsx("div",{className:"text-[13px] text-danger",children:v})]})}function Kr(t){return`---
|
|
2
|
+
title: ${t.replace(/\.md$/,"")}
|
|
3
|
+
description:
|
|
4
|
+
aliases: []
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`}function Ur({enabled:t,status:a,tidying:n,onToggle:i,onTidy:r,rooms:l}){return e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("memory.upkeep.title")}),e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.upkeep.help")})]}),e.jsx(Pe,{checked:t,"aria-label":s("memory.upkeep.title"),onClick:i})]}),t&&l&&e.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3 border-t border-hairline/40 pt-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:s("memory.learnFromRooms.title")}),e.jsx("p",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.learnFromRooms.subtitle")}),a&&!a.modelSteps&&e.jsx("p",{className:"mt-1 text-[13px] leading-relaxed text-ink-secondary",children:s("memory.learnFromRooms.noModelSteps")}),l.error&&e.jsx("p",{role:"alert",className:"mt-1 text-[13px] text-danger",children:l.error})]}),e.jsx(Pe,{checked:l.enabled,"aria-label":s("memory.learnFromRooms.title"),disabled:l.saving,onClick:l.onToggle,className:"disabled:cursor-wait disabled:opacity-50"})]}),t&&a&&!a.modelSteps&&e.jsx("p",{className:"mt-2 text-[13px] text-ink-secondary",children:s("memory.upkeep.noModelSteps")}),t&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",className:re,disabled:n,onClick:r,children:n?s("memory.upkeep.tidying"):s("memory.upkeep.tidyNow")}),e.jsxs("span",{className:"text-[13px] text-ink-secondary",children:[a?.lastTidy?s("memory.upkeep.lastTidy",{time:Ee(a.lastTidy.at,se()),summary:ks(a.lastTidy).toLowerCase()}):s("memory.upkeep.notTidied"),a?.lastCapture&&ze(a.lastCapture)?` ${s(ze(a.lastCapture)===1?"memory.upkeep.lastNoticed.one":"memory.upkeep.lastNoticed.many",{count:ze(a.lastCapture),time:Ee(a.lastCapture.at,se())})}`:""]})]})]})}function qr({index:t}){const a=Vn(t),n=a.level==="over"?"bg-danger":a.level==="near"?"bg-warning":"bg-accent";return e.jsxs("div",{className:O("rounded-xl p-4",a.level==="over"?"border border-danger/30 bg-danger/10":"bg-card"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[13px]",children:[e.jsx("span",{className:"font-medium text-ink",children:s("memory.capacity.title")}),e.jsx("span",{className:O("text-[12px]",a.level==="over"?"text-danger":"text-ink-secondary"),children:s("memory.capacity.summary",{lines:t.lines,maxLines:t.maxLines,bytes:ce(t.bytes),maxBytes:ce(t.maxBytes)})})]}),e.jsx(At,{label:s("memory.capacity.lines"),share:a.lineShare,fill:n}),e.jsx(At,{label:s("memory.capacity.size"),share:a.byteShare,fill:n}),e.jsx("p",{className:O("mt-2 text-[13px] leading-relaxed",a.level==="over"?"text-danger":"text-ink-secondary"),children:a.warning??s("memory.capacity.sentence",{lines:t.lines,maxLines:t.maxLines,bytes:ce(t.bytes),maxBytes:ce(t.maxBytes),maxLoaded:t.maxLines})}),a.warning&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s("memory.capacity.sentence",{lines:t.lines,maxLines:t.maxLines,bytes:ce(t.bytes),maxBytes:ce(t.maxBytes),maxLoaded:t.maxLines})})]})}function At({label:t,share:a,fill:n}){const i=`${Math.min(100,Math.round(a*100))}%`;return e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("span",{className:"w-10 shrink-0",children:t}),e.jsx("div",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-inset",role:"meter","aria-label":s("memory.capacity.used",{label:t}),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(100,Math.round(a*100)),children:e.jsx("div",{className:O("h-full rounded-full",n),style:{width:i}})})]})}function ws({botName:t,busy:a,onReload:n,onOverwrite:i}){return e.jsxs("div",{className:"mt-2 rounded-lg border border-warning/25 bg-warning/10 p-3 text-[13px] leading-relaxed text-ink",children:[e.jsx("div",{className:"font-medium",children:s("memory.conflict.title",{name:t})}),e.jsx("div",{className:"mt-0.5 text-ink-secondary",children:s("memory.conflict.help",{name:t})}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx("button",{type:"button",className:re,disabled:a,onClick:n,children:s("memory.reload")}),e.jsx("button",{type:"button",className:re,disabled:a,onClick:i,children:s("memory.overwrite")})]})]})}function Mt({title:t,hint:a,files:n,selected:i,onOpen:r,onDelete:l}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium uppercase tracking-[0.08em] text-ink-secondary",children:t}),e.jsx("div",{className:"mt-0.5 text-[12px] text-ink-secondary",children:a}),n.length===0?e.jsx("div",{className:"mt-2 text-[13px] text-ink-secondary",children:s("memory.noneYet")}):e.jsx("div",{className:"mt-2 overflow-hidden rounded-lg border border-hairline/40",children:n.map(c=>e.jsxs("div",{className:O("flex items-center gap-2 border-b border-hairline/40 px-3 py-2 last:border-b-0",i===c.path?"bg-control/60":"hover:bg-control/40"),children:[e.jsxs("button",{type:"button",onClick:()=>r(c),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx(Te,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate font-mono text-[13px] text-ink",children:c.name}),e.jsxs("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:[ce(c.bytes)," · ",Ee(c.modifiedAt,se())]})]}),e.jsx("button",{type:"button",onClick:()=>l(c),"aria-label":s("memory.deleteFile",{name:c.name}),title:s("memory.delete"),className:"shrink-0 rounded-md p-1 text-ink-secondary hover:bg-control hover:text-danger",children:e.jsx(Qt,{size:14})})]},c.path))})]})}function it({rows:t,botName:a,reverting:n,onRevert:i,now:r=Date.now()}){return t?t.length===0?e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("memory.noChanges")}):e.jsx("div",{className:"flex flex-col gap-2",children:t.map(l=>{const c=Yn(l),m=Jn(l);return e.jsxs("div",{className:"rounded-lg bg-inset px-3 py-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink",children:[e.jsx("span",{children:Hr(l,a)})," · ",e.jsx("span",{className:"text-ink-secondary",children:Ee(l.at,se(),r)}),c&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"text-ink-secondary",children:m?s(m,l.threadTitle?{title:l.threadTitle}:void 0):c})]})]}),l.canRevert?e.jsxs("button",{type:"button",disabled:n!==null,onClick:()=>i(l),className:"inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] font-medium text-accent-text hover:bg-accent/10 disabled:opacity-50",children:[e.jsx(Ys,{size:12}),n===l.id?s("memory.undoing"):s("memory.undo")]}):e.jsx("span",{className:"shrink-0 text-[12px] text-ink-secondary",title:l.revertUnavailableReason,children:s("memory.cantUndo")})]}),l.diff&&e.jsxs("details",{className:"mt-1",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:["+",l.added," −",l.removed," · ",s("memory.showChanged")]}),e.jsx("pre",{className:"mt-1 max-h-[240px] overflow-auto whitespace-pre-wrap rounded-md bg-card p-2 font-mono text-[12px] leading-relaxed text-ink",children:l.diff})]})]},l.id)})}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("memory.loading")})}function Wr({bot:t,rows:a,refreshError:n,onRollback:i,rollingBack:r}){if(!a)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("history.loading")});if(a.length===0)return e.jsx("div",{className:"text-[13px] text-ink-secondary",children:s("history.empty")});const l=[...a].sort((c,m)=>m.at-c.at);return e.jsxs("div",{className:"flex flex-col gap-2",children:[n&&e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[13px] text-ink-secondary",children:s("history.refreshError")}),l.map(c=>e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink",children:[e.jsx("span",{className:"text-ink-secondary",children:Gt(c.at)})," · ",e.jsxs("span",{children:[c.actor," via ",c.via]})," · ",e.jsx("span",{children:c.summary})]}),c.field==="soul"&&c.canRestore===!0&&e.jsx("button",{type:"button",disabled:r,onClick:()=>i(c.id),className:"shrink-0 rounded-md px-2 py-1 text-[12px] font-medium text-accent-text hover:bg-accent/10 disabled:opacity-50",children:s("history.undo")})]}),c.field==="soul"&&c.canRestore!==!0&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:c.restoreUnavailableReason??s("history.restoreUnavailable")})]},`${t.id}-${c.id}`))]})}function Vr({bot:t,bare:a=!1}){const{state:n,dispatch:i}=$(),r=Js(t),l=n.instances.find(c=>c.instanceId===t.modelSelection.instanceId);return r.turns===0?e.jsx("div",{className:O(a?"":"rounded-xl bg-card p-4","text-[13px] text-ink-secondary"),children:s("usage.bot.empty")}):e.jsxs("div",{className:a?void 0:"rounded-xl bg-card p-4",children:[!a&&e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:s("usage.title")}),e.jsxs("button",{onClick:()=>i({type:"toggleAppSettings",open:!0,section:"usage"}),className:"text-[12px] text-ink-secondary hover:text-ink",children:[s("usage.allBots")," ",e.jsx(ye,{size:14,"aria-hidden":"true",className:"inline align-[-2px] rtl:-scale-x-100"})]})]}),e.jsxs("div",{className:O("grid grid-cols-3 gap-3 text-[13px]",!a&&"mt-3"),children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:s("usage.colTurns")}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",children:r.turns})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:Qs(r)}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",title:ea(r),children:Xs(Zs(r))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] uppercase tracking-wide text-ink-secondary",children:s("usage.colCost")}),e.jsx("div",{className:"mt-0.5 tabular-nums text-ink",children:pt(r.costUsd)?ta(r.costUsd):"—"})]})]}),e.jsx("div",{className:"mt-2 text-[12px] text-ink-secondary",children:pt(r.costUsd)?s("usage.costLine",{caption:sa(l?.snapshot.billing)}):s("usage.bot.unpriced")})]})}const Gr=[["bot","botPanel.avatar.tabBot"],["generate","botPanel.avatar.tabGenerate"],["upload","botPanel.avatar.tabUpload"]],Yr=["circle","rounded","square"],Jr={circle:"botPanel.avatar.circle",rounded:"botPanel.avatar.rounded",square:"botPanel.avatar.square"},Qr={idle:"botPanel.face.idle",happy:"botPanel.face.happy",curious:"botPanel.face.curious",drowsy:"botPanel.face.drowsy",working:"botPanel.face.working",thinking:"botPanel.face.thinking",listening:"botPanel.face.listening",sleeping:"botPanel.face.sleeping",suspicious:"botPanel.face.suspicious",proud:"botPanel.face.proud"},Xr=t=>{const a=Qr[t];return a?s(a):t};function Zr({bot:t,activeState:a,onPatch:n,onClose:i}){const r=aa(t,n),{fileRef:l,crop:c,uploading:m,generating:o,busy:d,error:p,upload:f,removeImage:j,generate:g}=r,v=c!=="mascot"&&!!t.avatarUrl,[k,C]=u.useState(v?"upload":"bot"),b=u.useRef(null);u.useEffect(()=>{b.current?.querySelector('[aria-selected="true"]')?.focus()},[]);const w=h=>n(c==="mascot"?h:{...h,avatarCrop:"mascot"}),x=t.mascotBody??"cursor",S=Tn(),M=Ln(t.mascotBody,t.color,S),[F,B]=u.useState(()=>!!S||vt(x)||!!(t.mascotExpression&&t.mascotExpression!=="idle")),T=S&&M!==x&&vt(M)?Fe(M):null,H=(h,I)=>e.jsx("button",{type:"button",disabled:d,"aria-pressed":!v&&x===h,"aria-label":s("mascot.useBody",{name:I}),title:I,onClick:()=>w({mascotBody:h}),className:O("flex h-[58px] items-center justify-center rounded-xl disabled:opacity-50",!v&&x===h?"bg-ink/[0.08] ring-[1.5px] ring-inset ring-ink/25":"hover:bg-ink/[0.05]"),children:e.jsx(Hn,{color:t.color,faceColor:t.mascotFaceColor,bodyId:h,size:40,animated:!1,trackPointer:!1})},h),L=h=>{h.key==="Escape"&&(h.preventDefault(),h.stopPropagation(),i())};return e.jsxs("div",{role:"dialog","aria-label":s("botPanel.avatar.edit"),"data-panel-avatar-editor":!0,"data-look":"popover",onKeyDown:L,className:"popover-surface absolute inset-x-[-5px] top-[80px] z-30 overflow-hidden rounded-2xl border border-ink/[0.08] bg-menu text-left shadow-2xl shadow-black/50",children:[e.jsxs("div",{ref:b,className:"flex items-center gap-0.5 border-b border-ink/[0.06] p-2",children:[Gr.map(([h,I])=>e.jsx("button",{type:"button",role:"tab","aria-selected":k===h,"data-avatar-tab":h,onClick:()=>C(h),className:O("rounded-lg px-[11px] py-[5px] text-[13px]",k===h?"bg-ink/[0.08] font-medium text-ink":"text-ink-secondary hover:text-ink"),children:s(I)},h)),e.jsx("button",{type:"button","data-avatar-reset":!0,disabled:d,onClick:()=>n(na),className:"ml-auto rounded-lg px-[11px] py-[5px] text-[13px] text-ink-secondary hover:text-ink disabled:opacity-50",children:s("botPanel.avatar.reset")})]}),e.jsxs("div",{className:"p-3",children:[k==="bot"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:An.map(h=>H(h,Fe(h)))}),e.jsx("div",{className:"flex flex-wrap justify-center gap-2 px-1 pb-1 pt-3.5",children:ra.map(h=>e.jsx("button",{type:"button",disabled:d,"aria-pressed":t.color===h,"aria-label":s("mascot.useColor",{color:$n(h)}),title:s(Bn[h]),onClick:()=>w({color:h}),className:O("size-6 rounded-full disabled:opacity-50",t.color===h&&"ring-2 ring-ink/80 ring-offset-2 ring-offset-menu"),style:{background:Mn(h)}},h))}),e.jsx(Zn,{bot:t,disabled:d,onPatch:w}),e.jsxs("button",{type:"button","data-avatar-more":!0,"aria-expanded":F,onClick:()=>B(h=>!h),className:"mx-auto mt-2.5 flex items-center gap-1 rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[s("botPanel.avatar.more"),e.jsx(he,{size:13,"aria-hidden":"true",className:O("transition-transform",F&&"rotate-180")})]}),F&&e.jsxs("div",{"data-avatar-more-looks":!0,children:[Dn.map(h=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 px-1 pb-1.5 pt-2 text-[12px] text-ink-tertiary",children:[e.jsx("span",{children:kt(h)}),h===S&&T&&e.jsx("span",{"data-avatar-costume":!0,children:s("botPanel.avatar.costume",{name:T,skin:kt(h)})})]}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5","data-festival-bodies":h,children:Fn[h].bodies.map(I=>H(I,Fe(I)))})]},h)),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-1.5 pt-2.5",role:"group","aria-label":s("botPanel.avatar.face"),children:[e.jsx("span",{className:"mr-0.5 text-[12px] text-ink-tertiary",children:s("botPanel.avatar.face")}),zn.map(h=>e.jsx("button",{type:"button",disabled:d,"data-avatar-face":h,"aria-pressed":a===h,onClick:()=>w({mascotExpression:h}),className:O("rounded-full px-2.5 py-1 text-[12px] disabled:opacity-50",a===h?"bg-ink/[0.15] text-ink":"bg-ink/[0.04] text-ink-secondary hover:text-ink"),children:Xr(h)},h))]})]})]}),k==="generate"&&e.jsx("div",{className:"[&>div:first-child]:mt-0 [&>div:first-child]:border-0 [&>div:first-child]:pt-0",children:e.jsx(ia,{botLabel:t.title||t.name,disabled:m,generating:o,onGenerate:g})}),k==="upload"&&e.jsxs(e.Fragment,{children:[e.jsx(la,{busy:d,onUpload:h=>{f(h)}}),v&&e.jsx(oa,{bot:t,disabled:d,onPatch:n}),e.jsx("input",{ref:l,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",onChange:h=>{f(h.target.files?.[0])}}),e.jsxs("button",{type:"button","data-avatar-drop":!0,disabled:d,onClick:()=>l.current?.click(),onDragOver:h=>h.preventDefault(),onDrop:h=>{h.preventDefault(),f(h.dataTransfer.files?.[0])},className:"flex w-full flex-col items-center gap-1.5 rounded-xl border-[1.5px] border-dashed border-ink/15 px-3 py-6 text-center text-[13px] text-ink-secondary hover:border-ink/25 hover:text-ink disabled:opacity-50",children:[m?e.jsx(Ce,{size:22,className:"animate-spin"}):e.jsx(ca,{size:22}),e.jsx("span",{children:s("botPanel.avatar.drop")}),e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:s("botPanel.avatar.types")})]}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-2.5",children:[e.jsx("span",{className:"shrink-0 text-[12px] text-ink-secondary",children:s("botPanel.avatar.shape")}),e.jsx(Se,{attr:"data-avatar-crop",label:s("botPanel.avatar.shape"),value:v?c:null,onChange:h=>n({avatarCrop:h}),options:Yr.map(h=>({value:h,label:s(Jr[h]),disabled:d||!t.avatarUrl}))}),t.avatarUrl&&e.jsx("button",{type:"button",onClick:j,disabled:d,"aria-label":s("botIdentity.removeAvatar"),title:s("botPanel.avatar.remove"),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(Qt,{size:14})})]}),!v&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-tertiary",children:s("botPanel.avatar.uploadHint")})]}),p&&e.jsx("div",{role:"alert",className:"mt-3 text-[12px] text-danger",children:p})]})]})}const ei=()=>s("place.off");function Ns(t){const{dispatch:a}=$();return(n="computer")=>{pa(t.id,n),a({type:"toggleSettings",open:!1}),a({type:"toggleComputer",open:!0})}}function ti(t,a){const[n,i]=u.useState(null);return u.useEffect(()=>{if(!a)return;let r=!1;return Q(`/api/browser-sites?bot=${encodeURIComponent(t.id)}`).then(l=>{r||i({botId:t.id,count:l.sites?.length??0})}).catch(()=>{}),()=>{r=!0}},[t.id,a]),n?.botId===t.id?n.count:null}function Ss(t){const{state:a}=$(),{capabilities:n}=be(),i=n.host?.platform??"other",r=ua(t),l=t.computer??"auto",c=a.config?.browserEngine?.myChrome===!0&&(a.config?.browserProfiles??[]).some(g=>g.id===t.browserProfile&&g.browser==="chrome"),m=g=>g==="browser"&&c?s("settings.profiles.myChrome"):fa(g,i),o=g=>{const{view:v,reachable:k}=r[g];return{value:g,label:m(g),disabled:!k,hint:!k||ha(v)?v.line:void 0}},d=[{value:"auto",label:s("computer.simple.dest.letItChoose")},...r.local.policy?[o("local")]:[],...r.browser.policy||l==="browser"?[o("browser")]:[],...r.cloud.policy?[o("cloud")]:[],...r.vm.policy||l==="vm"?[o("vm")]:[],...l==="off"?[{value:l,label:ei(),disabled:!0}]:[]],p=t.tasks?.find(g=>g.threadId===t.threadId)?.surface,f=p&&p!==l?m(p):null,j=d.find(g=>g.value===l)?.label??(l==="auto"||l==="off"?void 0:m(l));return{options:d,current:l,currentLabel:j,usingNow:f}}function si({bot:t,derived:a}){const{dispatch:n}=$(),{options:i,current:r,usingNow:l}=Ss(t),[c,m]=u.useState(null),{patch:o,approvalMode:d}=a,p=f=>{if(!(f===r||f==="off")){if(f==="local"&&d==="auto"){m({botId:t.id,patch:{computer:"local",acknowledgeLocalAuto:!0}});return}o(f==="browser"?{computer:"browser",browser:!0}:{computer:f==="auto"?null:f})}};return e.jsxs(e.Fragment,{children:[e.jsx(A,{children:e.jsx("div",{role:"radiogroup","aria-label":s("computer.simple.whereWorks",{name:t.name}),className:"flex flex-col divide-y divide-ink/[0.05]",children:i.map(f=>e.jsx(We,{"data-panel-choice":f.value,title:f.label,hint:f.hint,checked:r===f.value,disabled:f.disabled,onClick:()=>p(f.value)},f.value))})}),l&&e.jsx("p",{"data-panel-using-now":!0,className:"mx-1 text-[13px] text-ink-secondary",children:s("computer.simple.usingNow",{place:l})}),e.jsx(xa,{open:c!==null,onCancel:()=>m(null),onConfirm:()=>{const f=c;m(null),f&&n({type:"updateBot",botId:f.botId,patch:f.patch})}})]})}function ai({bot:t,derived:a,onOpen:n}){const i=Ns(t),r=st(),{browserEnabled:l}=a,c=ti(t,l&&t.computer!=="off"&&r!==!1),{currentLabel:m,usingNow:o}=Ss(t),d=s("computer.screenOf",{name:t.name}),p=[...t.messages].reverse().find(j=>j.kind==="screen"&&(j.hasImage||j.png)),f=p?da({threadId:t.threadId,messageId:p.id},p.mime).src:null;return e.jsxs("div",{"data-panel-tabpanel":"computer",children:[e.jsxs("button",{type:"button","data-panel-action":"open-computer","aria-label":`${s("place.action.watch")}: ${d}`,onClick:()=>i(),className:"group relative mt-2.5 flex aspect-[16/10] w-full flex-col items-center justify-center gap-2 overflow-hidden rounded-xl bg-composer ring-1 ring-inset ring-ink/[0.06] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-border",children:[f?e.jsx("img",{src:f,alt:"",className:"absolute inset-0 size-full object-cover"}):t.busy?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-55",children:e.jsx(Je,{bot:t,size:52,animated:!1})}),e.jsx("span",{className:"max-w-[80%] text-center text-[13px] text-ink-secondary",children:s("botPanel.screen.working")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-60",children:e.jsx(Je,{bot:t,size:44,state:"sleeping",animated:!1})}),e.jsx("span",{className:"max-w-[80%] text-center text-[13px] font-medium text-ink",children:s("botPanel.screen.resting")})]}),e.jsxs("span",{"aria-hidden":"true",className:"absolute bottom-2.5 right-2.5 flex h-7 items-center gap-1.5 rounded-full border border-ink/10 bg-panel/80 px-2.5 text-[12px] text-ink opacity-0 backdrop-blur-sm transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 touch:opacity-100",children:[e.jsx(Ct,{size:13,"aria-hidden":"true"}),s("place.action.watch")]})]}),e.jsx("div",{className:"mt-3 text-center text-[13px] text-ink-tertiary",children:d}),e.jsxs(A,{anchor:"where",children:[e.jsx(ee,{"data-panel-page":"where",icon:Ct,title:s("computer.simple.whereWorks",{name:t.name}),hint:o?s("computer.simple.usingNow",{place:o}):void 0,value:m,onClick:()=>n("where")}),e.jsx(ee,{"data-panel-page":"browser",icon:ma,title:s("settings.sites.title"),value:c??void 0,onClick:()=>n("browser")})]})]})}const ni=3,Bt="[&_.font-semibold]:font-medium [&_time]:text-[12px] [&_time]:text-ink-tertiary [&_span.bg-accent]:size-2",ri=8,ii=200,ue=new Map,Ke=new Set,$t=t=>`${t.threadId}@${ts(t)}`;function li(t,a){const[,n]=u.useState(0),r=a.filter(m=>m.threadId!==t.threadId).map($t).filter(m=>!ue.has(m)&&!Ke.has(m)).join(",");u.useEffect(()=>{if(r)for(const m of r.split(",")){Ke.add(m);const o=m.slice(0,m.lastIndexOf("@"));Q(`/api/threads/${encodeURIComponent(o)}/messages?limit=${ri}`,{background:!0}).then(d=>{ue.set(m,Ge({messages:d.messages??[],activeLeafId:d.activeLeafId??void 0})),ue.size>ii&&ue.delete(ue.keys().next().value),n(p=>p+1)}).catch(()=>{}).finally(()=>Ke.delete(m))}},[r]);const l=Ge(t),c=new Map(a.map(m=>[m.threadId,$t(m)]));return m=>m===t.threadId?l:ue.get(c.get(m)??"")}function oi({bot:t}){const{state:a,dispatch:n}=$(),i=ga(),r=!Xt(Zt,!0),[l,c]=u.useState(""),[m,o]=u.useState(!1),[d,p]=u.useState(!1),[f,j]=u.useState(!1),g=ya(a.config),v=u.useMemo(()=>{const{onRename:y,onRegenerateTitle:z,onDelete:le,onMove:pe,onPin:fe,onArchive:P}=ba(t.id,n,g);return{onRename:y,onRegenerateTitle:z,onDelete:le,onMove:pe,onPin:fe,onArchive:P}},[t.id,n,g]),k=va(t),C=t.tasks??[{threadId:t.threadId,title:s("task.newShort"),createdAt:0}],b=(k?ka({...t,tasks:C},k):C).filter(y=>!y.routineRunId).map(y=>{const z=Ve(t,y.threadId);return{...y,busy:z.busy,activity:z.activity,waitingForTeammates:z.waitingForTeammates,turnStartedAt:z.turnStartedAt??void 0,queued:!!a.pendingQueued[y.threadId]?.length}}),w=ut(b.filter(y=>!$e(y)||y.threadId===t.threadId)),x=ut(b.filter(y=>$e(y)&&y.threadId!==t.threadId)),S=l.trim(),M=w.filter((y,z)=>z<ni||y.threadId===t.threadId),F=li(t,[...S||d?w:M,...f?x:[]]),B=y=>{const z=F(y);return z?Na(Ve(t,y),z,a.instances,!1):void 0},T=ja(w,S),H=S?[...T,...w.filter(y=>!T.includes(y)&&B(y.threadId)?.toLowerCase().includes(S.toLowerCase()))]:w,L=S?H:d?w:M,h=w.length-M.length,I=t.projects?.find(y=>y.id===t.tasks?.find(z=>z.threadId===t.threadId)?.projectId),D=()=>{r&&n({type:"toggleSettings",open:!1})},_=y=>{y.threadId!==t.threadId&&Pa(n,t,y.threadId,!1),D()},K=()=>{n({type:"newTask",botId:t.id,...I?{projectId:I.id}:{}}),D()},J=()=>{c(""),o(!1)},Y=w.length>=2||m||w.some(y=>y.threadId===t.threadId&&$e(y)),U=y=>e.jsx("div",{role:"listitem","data-conversation":y.threadId,children:e.jsx(Sa,{panel:!0,preview:B(y.threadId),task:y,ownerId:t.id,current:y.threadId===t.threadId,folders:t.projects,now:Ca(ts(y),i),locale:se(),onSelect:_,...v})},y.threadId);return e.jsxs("section",{"data-panel-card":"conversations","aria-label":s("botPanel.conversations.title"),children:[e.jsx(Oe,{action:Y&&e.jsx("button",{type:"button","data-conversations-search":!0,"aria-label":s("botPanel.conversations.search"),title:s("botPanel.conversations.search"),"aria-pressed":m,onClick:()=>m?J():o(!0),className:O("-me-1 flex size-6 shrink-0 items-center justify-center rounded-[6px] text-ink-secondary transition-colors hover:bg-ink/[0.06] hover:text-ink",m&&"bg-ink/[0.06] text-ink"),children:e.jsx(Xe,{size:14,"aria-hidden":"true"})}),children:s("botPanel.conversations.title")}),e.jsx("div",{className:O("flex items-center gap-2",Y&&"mb-2"),children:t.yourAccess!=="view"&&k!=="team"&&e.jsxs("button",{type:"button","data-conversations-new":!0,"aria-label":s("botPanel.conversations.new"),onClick:K,className:O(es,"flex-1"),children:[e.jsx(wa,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate",children:s("botPanel.conversations.new")})]})}),Y&&m&&e.jsx("input",{autoFocus:!0,type:"search","data-conversations-query":!0,value:l,onChange:y=>c(y.target.value),onKeyDown:y=>{y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),J())},placeholder:s("botPanel.conversations.searchPlaceholder",{name:t.name}),"aria-label":s("botPanel.conversations.searchPlaceholder",{name:t.name}),className:"mb-1.5 w-full rounded-[8px] border border-hairline/60 bg-inset px-3 py-1.5 text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-focus"}),Y&&e.jsx("div",{role:"list","aria-label":s("botPanel.conversations.title"),className:O("flex flex-col gap-px",Bt),children:L.map(U)}),Y&&S&&L.length===0&&e.jsx("p",{className:"px-3 py-3 text-[13px] text-ink-secondary",children:s("task.noMatch",{query:S})}),Y&&!S&&h>0&&e.jsxs("button",{type:"button","data-conversations-more":!0,"aria-expanded":d,onClick:()=>p(y=>!y),className:"mt-0.5 flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[d?e.jsx(xt,{size:14,"aria-hidden":"true"}):e.jsx(he,{size:14,"aria-hidden":"true"}),d?s("botPanel.conversations.showFewer"):s("botPanel.conversations.showMore",{count:h})]}),!S&&x.length>0&&e.jsxs("button",{type:"button","data-conversations-archived":!0,"aria-expanded":f,onClick:()=>j(y=>!y),className:"mt-0.5 flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-ink/[0.04] hover:text-ink",children:[f?e.jsx(xt,{size:14,"aria-hidden":"true"}):e.jsx(he,{size:14,"aria-hidden":"true"}),s("task.archivedList",{count:x.length})]}),!S&&f&&x.length>0&&e.jsx("div",{role:"list","aria-label":s("task.archivedList",{count:x.length}),className:O("flex flex-col gap-px",Bt),children:x.map(U)})]})}function ci({bot:t}){const{dispatch:a}=$();return Ut()||!t.defaultBot?null:e.jsx(A,{label:s("botPanel.tryAsking"),anchor:"try-asking",children:Oa.map(i=>e.jsx("button",{type:"button","data-panel-ask":i,onClick:()=>a({type:"send",botId:t.id,text:s(i),threadId:t.threadId}),className:"flex h-9 w-full items-center px-3.5 text-left text-[14px] text-ink transition-colors hover:bg-ink/[0.03]",children:e.jsx("span",{className:"truncate",children:s(i)})},i))})}const di=["find","start-fresh","usage","activity","inspector"];function mi({item:t}){const a=t.key==="usage";return e.jsxs("button",{type:"button","data-panel-item":t.key,disabled:t.disabled,title:t.title,"aria-pressed":t.active||void 0,onClick:t.onSelect,className:O(X,"w-full rounded-[8px] text-left enabled:hover:bg-ink/[0.04] disabled:cursor-default disabled:opacity-45"),children:[e.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center text-ink-secondary [&_svg]:size-4","aria-hidden":"true",children:t.icon}),e.jsx("span",{className:O("min-w-0 truncate text-[14px] font-medium",!a&&"flex-1",t.active?"text-accent-text":"text-ink"),children:t.label}),t.trailing&&e.jsx("span",{className:O("flex items-center",a?"min-w-0 flex-1 justify-end text-right":"shrink-0"),children:t.trailing}),t.key!=="find"&&t.key!=="start-fresh"&&e.jsx(ye,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary rtl:-scale-x-100"})]})}function pi({bot:t,derived:a,onOpen:n}){const{items:i}=Ea(t),{dispatch:r}=$(),l=a.botRoutines.filter(m=>m.enabled).length,c=di.flatMap(m=>i.filter(o=>o.key===m));return e.jsxs("div",{"data-panel-tabpanel":"details",children:[e.jsx("section",{"data-panel-card":"model",className:"pt-2",children:e.jsx("div",{"data-panel-row":"model",className:O(X,"rounded-[8px]"),children:e.jsx(Ra,{bot:t,contained:!0,threadId:t.threadId,label:e.jsxs("span",{className:"flex shrink-0 items-center gap-2.5",children:[e.jsx(Z,{icon:et}),e.jsx(ae,{title:s("model.simple.model")})]})})})}),e.jsx(oi,{bot:t}),e.jsx(ci,{bot:t}),c.length>0&&e.jsxs("section",{"data-panel-card":"conversation",children:[e.jsx(Oe,{children:s("botPanel.section.conversation")}),c.map(m=>e.jsx(mi,{item:m},m.key))]}),a.botRoutines.length===0?e.jsxs("section",{"data-panel-empty":"routines",children:[e.jsx(Oe,{action:e.jsx(Ia,{"data-panel-automations":"",onClick:()=>r({type:"showRoutines",view:"list"}),children:s("sidebar.nav.automations")}),children:s("botSettings.simple.routines")}),e.jsxs("button",{type:"button","data-panel-page":"routines",title:s("botPanel.routines.emptyHint"),onClick:()=>n("routines"),className:O(es,"w-full"),children:[e.jsx(Sr,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"truncate",children:s("botPanel.routines.add")})]})]}):e.jsx(A,{label:s("botSettings.simple.routines"),anchor:"routines",children:e.jsx(ee,{"data-panel-page":"routines",icon:Ta,title:s("botSettings.simple.routines"),value:l>0?s("botPanel.routinesOn",{count:l}):s("botPanel.none"),onClick:()=>n("routines")})})]})}const Cs=/^\s*[-*]\s+(.+?)\s*$/;function ui(t){return t.split(`
|
|
8
|
+
`).flatMap((a,n)=>{const i=Cs.exec(a)?.[1];return i?[{line:n,text:i}]:[]})}function xi(t,a){const n=t.split(`
|
|
9
|
+
`);return Cs.test(n[a]??"")?(n.splice(a,1),n.join(`
|
|
10
|
+
`)):t}function hi(t,a){const n=t.replace(/\s+$/,""),i=`- ${a.trim().replace(/\s*\n\s*/g," ")}`;return n?`${n}
|
|
11
|
+
${i}
|
|
12
|
+
`:`${i}
|
|
13
|
+
`}function Ps(t){return t.flatMap(a=>{const n=ui(a.text).map(r=>({path:a.path,...r}));if(n.length||a.path===te)return n;const i=a.text.split(`
|
|
14
|
+
`).map(r=>r.replace(/^#+\s*/,"").trim()).filter(Boolean).join(" ");return i?[{path:a.path,line:null,text:i}]:[]})}async function fi(t,a){if(!a)return[await Re(t,te)];const n=await nt(t,!0);return Promise.all([te,...n.topics.map(i=>i.path)].map(i=>Re(t,i,!0)))}function Os(t){const a=!!$().state.config?.team,[n,i]=u.useState({botId:t.id,docs:null,error:!1}),r=t.memoryEnabled!==!1,l=async(o,d)=>{try{const p=await fi(o,a);d?.()||i({botId:o,docs:p,error:!1})}catch{d?.()||i({botId:o,docs:null,error:!0})}},c=!!t.busy;u.useEffect(()=>{if(!r)return;let o=!1;return l(t.id,()=>o),()=>{o=!0}},[t.id,r,c,a]);const m=n.botId===t.id;return{docs:m?n.docs:null,error:m&&n.error,mine:a,setDoc:o=>i(d=>({botId:t.id,docs:(d.botId===t.id?d.docs??[]:[]).map(p=>p.path===o.path?o:p),error:!1})),reload:()=>l(t.id)}}function gi(t,a=Ge(t)){const n=[],i=[],r=new Set;for(const d of[...a].reverse()){const p=d.publishedPage;p?.state==="live"&&p.url&&!r.has(p.url)&&(r.add(p.url),n.push({messageId:d.id,title:p.title||p.url,url:p.url})),d.kind==="app"&&d.app?.doc&&i.push({messageId:d.id,title:d.app.title})}const l=fr(t),c=[],m=new Set;for(const d of l.values())m.has(d.file.path)||(m.add(d.file.path),c.push(d));const o=gr(t).filter(d=>!l.has(d));return{pages:n,apps:i,shared:c,unshared:o}}const yi=t=>t.slice(Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"))+1);function Es({bot:t,onOpen:a}){const{dispatch:n}=$(),{capabilities:i}=be(),r=La(),l=!Xt(Zt,!0),c=us(t),m=Os(t),{pages:o,apps:d,shared:p,unshared:f}=u.useMemo(()=>gi(t),[t]),j=b=>{n({type:"focusMessage",threadId:t.threadId,messageId:b}),l&&n({type:"toggleSettings",open:!1})},g=c.skills.filter(xs).length,v=m.docs?Ps(m.docs).length:null,k=t.memoryEnabled===!1?s("botPanel.memory.off"):v===null?m.error?s("botPanel.memory.nothingYet"):void 0:v===0?s("botPanel.memory.nothingYet"):v===1?s("botPanel.memory.note"):s("botPanel.memory.notes",{count:v}),C=e.jsxs(A,{anchor:"keeps",children:[e.jsx(ee,{"data-panel-page":"memory",icon:qt,title:s("botPanel.memoryRow"),value:k,onClick:()=>a("memory")}),e.jsx(ee,{"data-panel-page":"skills",icon:Aa,title:s("botSettings.simple.skills"),value:c.loading?void 0:g>0?g:s("botPanel.none"),onClick:()=>a("skills")}),e.jsx(ee,{"data-panel-page":"folder",icon:Ma,title:s("computer.files.folder"),value:t.cwd?tt(t.cwd,i.host?.homeDir):s("botPanel.folder.private"),onClick:()=>a("folder")})]});return o.length+d.length+p.length+f.length===0?e.jsxs("div",{"data-panel-tabpanel":"library",children:[e.jsx("p",{"data-panel-empty":"library",className:"px-3 py-7 text-center text-[13px] leading-[18px] text-ink-tertiary",children:s("botPanel.library.empty")}),C]}):e.jsxs("div",{"data-panel-tabpanel":"library",children:[o.length>0&&e.jsx(A,{label:s("botPanel.library.pages"),anchor:"pages",children:o.map(b=>e.jsx(ee,{"data-panel-row":"page",icon:Ba,title:e.jsx("span",{className:"block truncate",children:b.title}),hint:e.jsx("span",{className:"block truncate",children:b.url}),onClick:()=>r(b.url)},b.url))}),d.length>0&&e.jsx(A,{label:s("botPanel.library.apps"),anchor:"apps",children:d.map(b=>e.jsx(ee,{"data-panel-row":"app",icon:ss,title:e.jsx("span",{className:"block truncate",children:b.title}),onClick:()=>j(b.messageId)},b.messageId))}),p.length+f.length>0&&e.jsxs("section",{"data-panel-card":"files",children:[e.jsx(Oe,{children:s("botPanel.library.files")}),e.jsxs("ul",{className:"flex flex-col gap-1.5",children:[p.map(b=>e.jsx("li",{className:"min-w-0",children:e.jsx($a,{file:b.file,message:b.message,linked:b.file.linked,className:"w-full max-w-none"})},`${b.message.messageId}:${b.file.path}`)),f.map(b=>e.jsxs("li",{title:s("computer.files.notSharedHint"),className:"flex min-w-0 items-center gap-2 rounded-lg border border-hairline/40 px-2.5 py-2",children:[e.jsx(Te,{size:14,className:"shrink-0 text-ink-secondary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-ink",children:yi(b)}),e.jsx("span",{className:"shrink-0 text-[11px] text-ink-tertiary",children:s("computer.files.notShared")})]},b))]})]}),e.jsx("p",{className:"mt-3 text-center text-[12px] text-ink-tertiary",children:s("botPanel.library.scope")}),C]})}function bi({bot:t,browserEnabled:a,onOpenBrowser:n}){const{state:i}=$(),r=st(),l=t.browserProfile??"",c=(i.config?.browserProfiles??[]).find(p=>p.id===l),m=l==="guest",o=c?.browser==="chrome"&&i.config?.browserEngine?.myChrome===!0,d=l&&!m?i.bots.filter(p=>p.browserProfile===l).map(p=>p.name):[t.name];return e.jsx(A,{anchor:"logins",children:a?m?e.jsx(V,{children:s("settings.profiles.temporaryHint")}):o?e.jsx(V,{children:s("settings.profiles.myChromeHint")}):e.jsxs(e.Fragment,{children:[r!==!1&&(l===""||c)&&e.jsx(de,{children:e.jsx(wr,{bare:!0,target:{bot:t.id},sharedBy:d,disabled:!!t.busy},`${t.id}:${l}`)}),e.jsx(V,{children:s("botSettings.simple.loginsHint",{name:t.name})}),e.jsx(me,{"data-panel-action":"add-login",icon:ve,onClick:n,children:s("botSettings.simple.addLogin")})]}):e.jsx(V,{children:s("botSettings.simple.loginsOff",{name:t.name})})})}const vi=[["all",()=>R("Tất cả","All")],["added",()=>R("Bot đang có","On this bot")],["more",()=>R("Chưa thêm","Not added")]],ki=t=>({bundled:R("Có sẵn","Built in"),library:R("Đã tải về","Downloaded"),imported:R("Từ máy tính","From this computer")})[t],Ue="inline-flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/60 bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50";async function Dt(t,a){const n=await fetch(t,a===void 0?void 0:{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(a)}),i=await n.json().catch(()=>({}));if(!n.ok)throw new Error(i.error??R(`Lỗi ${n.status}`,`Error ${n.status}`));return i.skills??[]}function ji({botId:t,botName:a,onClose:n,onOpenSettings:i}){const[r,l]=u.useState(null),[c,m]=u.useState(""),[o,d]=u.useState("all"),[p,f]=u.useState(""),[j,g]=u.useState(""),v=`/api/limix/skill-store/${encodeURIComponent(t)}`;u.useEffect(()=>{let x=!1;return Dt(v).then(S=>{x||l(S)}).catch(S=>{x||(l([]),g(S.message))}),()=>{x=!0}},[v]),u.useEffect(()=>{const x=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[n]);const k=u.useMemo(()=>{const x=c.trim().toLowerCase();return(r??[]).filter(S=>(o==="all"||(o==="added"?S.added:!S.added))&&(!x||`${S.name} ${S.description}`.toLowerCase().includes(x)))},[r,c,o]),C=async(x,S)=>{if(!p){f(x.name),g("");try{l(await Dt(v,{name:x.name,kind:x.kind,add:S}))}catch(M){g(M instanceof Error?M.message:R("Không đổi được kĩ năng này.","Couldn't change this skill."))}finally{f("")}}},b=(r??[]).filter(x=>x.added).length,w=e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6",onMouseDown:x=>x.stopPropagation(),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"limix-skill-store-title",className:"flex max-h-full w-full max-w-[640px] flex-col rounded-2xl border border-hairline/50 bg-panel shadow-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-6 pb-3 pt-5",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"limix-skill-store-title",className:"text-[17px] font-semibold text-ink",children:R("Kho Kĩ Năng (Skills)","Skills Store")}),e.jsx("p",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:R(`Chọn kĩ năng riêng cho ${a}. Chỉ những kĩ năng được thêm mới nằm trong lời nhắc của bot, nên bot không bị quá tải. Gõ /tên-kĩ-năng trong chat để gọi.`,`Pick skills just for ${a}. Only added skills go into the bot's prompt, so it never gets overloaded. Type /skill-name in chat to call one.`)})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":R("Đóng","Close"),className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(Ze,{size:16})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-6 pb-3",children:[e.jsxs("label",{className:"flex min-w-[200px] flex-1 items-center gap-2 rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx(Xe,{size:14,className:"text-ink-tertiary"}),e.jsx("input",{value:c,onChange:x=>m(x.target.value),placeholder:R("Tìm kĩ năng…","Search skills…"),"aria-label":R("Tìm kĩ năng","Search skills"),className:"w-full bg-transparent text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsx("div",{className:"flex gap-1",role:"tablist","aria-label":R("Lọc kĩ năng","Filter skills"),children:vi.map(([x,S])=>e.jsxs("button",{type:"button",role:"tab","aria-selected":o===x,onClick:()=>d(x),className:`rounded-lg px-2.5 py-1.5 text-[13px] ${o===x?"bg-raised text-ink":"text-ink-secondary hover:bg-raised"}`,children:[S(),x==="added"&&r?` ${b}`:""]},x))})]}),j&&e.jsx("p",{role:"alert",className:"mx-6 mb-2 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:j}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6",children:r===null?e.jsxs("p",{className:"flex items-center gap-2 py-6 text-[13px] text-ink-secondary",children:[e.jsx(Ce,{size:14,className:"animate-spin"}),R("Đang tải kho…","Loading the store…")]}):k.length===0?e.jsx("p",{className:"py-6 text-[13px] text-ink-secondary",children:r.length===0?R("Kho chưa có kĩ năng nào.","The store has no skills yet."):R("Không có kĩ năng khớp.","No matching skills.")}):e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-xl border border-hairline/40",children:k.map(x=>e.jsxs("li",{className:"flex items-start gap-3 px-3 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"font-mono text-[13px] text-ink",children:x.name}),e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:x.core?R("Kĩ năng gốc","Core skill"):ki(x.kind)}),x.warnings>0&&e.jsxs("span",{className:"text-[12px] text-warning",children:[x.warnings," ",R("cảnh báo","warnings")]})]}),e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[12px] leading-relaxed text-ink-secondary",children:x.description})]}),x.core?e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 px-1 py-1.5 text-[12px] text-ink-secondary",children:[e.jsx(ct,{size:14}),R("Luôn bật","Always on")]}):x.added?e.jsxs("button",{type:"button",className:Ue,disabled:!!p,onClick:()=>{C(x,!1)},"aria-label":R(`Bỏ ${x.name} khỏi bot`,`Remove ${x.name} from this bot`),children:[p===x.name?e.jsx(Ce,{size:14,className:"animate-spin"}):e.jsx(ct,{size:14}),R("Đã thêm","Added")]}):e.jsxs("button",{type:"button",className:Ue,disabled:!!p||!x.ready,onClick:()=>{C(x,!0)},"aria-label":R(`Thêm ${x.name} cho bot`,`Add ${x.name} to this bot`),children:[p===x.name?e.jsx(Ce,{size:14,className:"animate-spin"}):e.jsx(ve,{size:14}),R("Thêm","Add")]})]},`${x.kind}:${x.name}`))})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 px-6 pb-5 pt-3",children:[e.jsx("p",{className:"text-[12px] text-ink-tertiary",children:R('Bấm "Đã thêm" để bỏ kĩ năng khỏi bot này.','Press "Added" to remove a skill from this bot.')}),e.jsx("button",{type:"button",className:Ue,onClick:i,children:R("Tải thêm kĩ năng","Get more skills")})]})]})});return typeof document>"u"?w:ls.createPortal(w,document.body)}const we="rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50";function wi({bot:t,className:a}){const n=`/api/bots/${t.id}/telegram`,[i,r]=u.useState(null),[l,c]=u.useState(""),[m,o]=u.useState(null),[d,p]=u.useState(!1),[f,j]=u.useState(null);u.useEffect(()=>{let k=!0;return r(null),o(null),c(""),Q(n).then(C=>{k&&r(C)}).catch(C=>{k&&j(C instanceof Error?C.message:String(C))}),()=>{k=!1}},[n]);const g=async k=>{p(!0),j(null);try{const{code:C,...b}=await k();r(b),C&&o(C)}catch(C){j(C instanceof Error?C.message:String(C))}finally{p(!1)}},v=(k,C="")=>g(()=>Q(`${n}${C}`,{method:"POST",body:JSON.stringify(k??{})}));return e.jsxs("div",{className:O("rounded-xl bg-card p-4",a),"data-testid":"telegram-card",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:"Telegram"}),e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:i?.connected?R(`${t.name} trả lời tin nhắn gửi tới @${i.username}.`,`${t.name} answers messages sent to @${i.username}.`):R(`Cho ${t.name} trả lời trên Telegram: tạo bot với @BotFather (lệnh /newbot), rồi dán token vào đây.`,`Let ${t.name} answer on Telegram: make a bot with @BotFather (/newbot), then paste its token here.`)})]}),i?.connected&&e.jsx(Pe,{"aria-label":R("Bật Telegram","Telegram on"),checked:i.enabled===!0,disabled:d,onClick:()=>{v({enabled:!i.enabled})},"data-testid":"telegram-switch"})]}),i&&!i.connected&&e.jsxs("form",{className:"mt-3 flex gap-2",onSubmit:k=>{k.preventDefault(),l.trim()&&v({token:l.trim()}).then(()=>c(""))},children:[e.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:l,onChange:k=>c(k.target.value),placeholder:"123456789:AA…","aria-label":R("Token bot Telegram","Telegram bot token"),className:"min-w-0 flex-1 rounded-lg bg-inset px-3 py-1.5 font-mono text-[13px] text-ink outline-none","data-testid":"telegram-token"}),e.jsx("button",{type:"submit",disabled:d||!l.trim(),className:we,"data-testid":"telegram-connect",children:R("Kết nối","Connect")})]}),i?.connected&&e.jsxs("div",{className:"mt-3 flex flex-col gap-2.5 text-[13px]",children:[i.owner?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-ink-secondary",children:[e.jsx("span",{children:R(`Chủ bot trên Telegram: ${i.owner}. Bạn nhắn ở đó như nhắn trong app, toàn quyền.`,`Owner on Telegram: ${i.owner}. You write there as in the app, with full access.`)}),e.jsx("button",{type:"button",className:we,disabled:d,onClick:()=>{v({},"/unlink")},children:R("Bỏ liên kết","Unlink")})]}):e.jsxs("div",{className:"flex flex-col gap-1.5 text-ink-secondary",children:[e.jsx("span",{children:R("Liên kết Telegram của bạn để nhắn với bot như trong app:","Link your own Telegram to talk to the bot as in the app:")}),m?e.jsxs("span",{className:"text-ink","data-testid":"telegram-code",children:[R(`Nhắn cho @${i.username}: `,`Send @${i.username}: `),e.jsxs("code",{className:"rounded bg-inset px-1.5 py-0.5 font-mono",children:["/link ",m]}),R(" (hết hạn sau 15 phút)"," (expires in 15 minutes)")]}):e.jsx("button",{type:"button",className:O(we,"self-start"),disabled:d,onClick:()=>{v({},"/link")},"data-testid":"telegram-link",children:R("Tạo mã liên kết","Make a link code")})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-ink",children:[e.jsxs("span",{children:[R("Trả lời cả người khác","Answer other people too"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:R("Người khác nhắn được bot ở chế độ an toàn: không dùng công cụ, không thấy cuộc trò chuyện của bạn.","Others can write to the bot in safe mode: no tools, none of your conversations.")})]}),e.jsx(Pe,{"aria-label":R("Trả lời cả người khác","Answer other people too"),checked:i.access==="everyone",disabled:d,onClick:()=>{v({access:i.access==="everyone"?"owner":"everyone"})},"data-testid":"telegram-everyone"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",className:we,disabled:d,onClick:()=>{g(()=>Q(n,{method:"DELETE"}))},"data-testid":"telegram-remove",children:R("Gỡ kết nối","Disconnect")})})]}),(f||i?.error)&&e.jsx("div",{role:"alert",className:"mt-2 text-[13px] text-danger",children:f??i?.error})]})}const Ni=5,Si={instanceId:"",model:""},Rs=(t,a)=>`${t}\0${a}`,Ci=new Set;function Ft({bot:t,current:a,exclude:n,onPick:i,label:r,title:l,buttonRef:c,className:m,children:o,...d}){const{state:p,dispatch:f,refreshInstances:j,refreshModels:g}=$(),[v,k]=u.useState(!1),[C,b]=u.useState(""),[w,x]=u.useState(()=>new Set),[S,M]=u.useState(!1),[F,B]=u.useState(null),[T,H]=u.useState(null),L=u.useRef(null),h=c??L,I=u.useRef(null),D=u.useRef(null),_=u.useRef(!1),K=u.useId(),J=qn(v),Y=u.useRef({contains:P=>[h.current,I.current].some(q=>q?.contains(P))});Ka(v,Y,()=>k(!1)),u.useLayoutEffect(()=>{if(!v)return;const P=q=>{if(q?.type==="scroll"&&q.target instanceof Node&&I.current?.contains(q.target))return;const G=h.current?.getBoundingClientRect(),W=I.current;!G||!W||H(oe=>Wa(G,{width:ht,height:W.offsetHeight},{width:window.innerWidth,height:window.innerHeight},oe??void 0))};return P(),window.addEventListener("resize",P),window.addEventListener("scroll",P,!0),()=>{window.removeEventListener("resize",P),window.removeEventListener("scroll",P,!0)}},[v,h]),u.useEffect(()=>{if(!v||!T||!_.current)return;_.current=!1;const P=I.current;(P?.querySelector("[data-menu-search]")??P?.querySelector("[data-current-model]")??P?.querySelector("[data-menu-row]:not(:disabled)")??P)?.focus({preventScroll:!0})},[v,T]);const U=P=>{k(!1),P&&h.current?.focus({preventScroll:!0})},y=()=>{b(""),x(new Set),H(null),_.current=!0,k(!0),M(!0),j().catch(()=>{}).finally(()=>M(!1))},z=P=>{F||(B(P.instanceId),g(P.instanceId).catch(()=>{}).finally(()=>B(null)))},le=()=>{U(!1),f({type:"toggleAppSettings",open:!0,section:"engines"})},pe=()=>{const P=Ga(p.instances,a?.instanceId).flatMap(W=>{const oe=W.models.options.filter(ke=>!n.has(Rs(W.instanceId,ke.id)));return oe.length===W.models.options.length?[W]:oe.length?[{...W,models:{...W.models,options:oe}}]:[]}),q=Ya({instances:p.instances,listed:P,selection:a??Si,bot:{name:t.name,selection:t.modelSelection},query:C,expanded:w,probing:Ci,loading:S,refreshing:F}),G=q.groups.map(W=>W.instance.instanceId===t.modelSelection.instanceId?{...W,note:s("botPanel.backups.sameAccount")}:W);return{...q,groups:G,...a?{}:{current:null}}},fe=P=>{if(!(P.nativeEvent.isComposing||P.defaultPrevented)){if(P.key!=="Escape")return Va(P,{query:C,typed:D,close:()=>U(!0)});P.preventDefault(),P.stopPropagation(),C?b(""):U(!0)}};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:h,type:"button",...d,"aria-label":r,title:l,"aria-haspopup":"dialog","aria-expanded":v,"aria-controls":v?K:void 0,onClick:()=>v?U(!1):y(),onKeyDown:P=>{P.key==="Escape"&&v?(P.preventDefault(),P.stopPropagation(),U(!1)):(P.key==="ArrowDown"||P.key==="ArrowUp")&&!v&&(P.preventDefault(),y())},className:m,children:o}),J.shown&&ls.createPortal(e.jsx("div",{ref:I,id:K,"data-backup-menu":!0,role:"dialog","aria-label":s("botPanel.backups.choose"),"aria-modal":"false",tabIndex:-1,...J.exitProps,onKeyDown:fe,onPointerMove:Ua,style:{position:"fixed",left:T?.left??0,top:T?.top,bottom:T?.bottom,width:T?.width??ht,maxHeight:T?.maxHeight,transformOrigin:T?.origin,visibility:T?void 0:"hidden"},className:O("menu-surface z-[80] flex flex-col overflow-hidden",J.className),children:e.jsx(qa,{menu:pe(),query:C,bot:t,botModel:{label:"",title:""},idPrefix:K,onQuery:b,onPick:(P,q)=>{P.policy||(i({instanceId:P.instanceId,model:q}),U(!0))},onPickCurrent:()=>U(!0),onFollowBot:()=>U(!0),onToggle:P=>x(q=>{const G=new Set(q);return G.delete(P.instanceId)||G.add(P.instanceId),G}),onSetUp:le,onCheckAgain:z,onManage:le})}),document.body)]})}function Pi({bot:t,onChange:a}){const{state:n}=$(),i=t.fallback??[],r=u.useRef(null),l=m=>new Set([t.modelSelection,...i.filter((o,d)=>d!==m)].map(o=>Rs(o.instanceId,o.model))),c=m=>{const o=n.instances.find(f=>f.instanceId===m.instanceId),d=o?.models.options.find(f=>f.id===m.model),p=za(o,m.model);return{instance:o,name:p,short:o&&d?Ha(d.label,_a(o)):p}};return e.jsx(A,{anchor:"backups",children:e.jsxs(de,{"data-panel-row":"backups",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Z,{icon:Da}),e.jsx(ae,{title:s("botPanel.backups.title")})]}),e.jsx("p",{className:"-mt-1 pl-[38px] text-[13px] leading-[1.35] text-ink-secondary",children:s("botPanel.backups.hint",{name:t.name})}),i.length>0&&e.jsx("ol",{"aria-label":s("botPanel.backups.title"),className:"flex flex-col gap-1 pl-[38px]",children:i.map((m,o)=>{const{instance:d,name:p,short:f}=c(m);return e.jsxs("li",{"data-backup":m.instanceId,className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"w-3 shrink-0 text-[12px] tabular-nums text-ink-tertiary","aria-hidden":"true",children:o+1}),e.jsxs(Ft,{bot:t,current:m,exclude:l(o),onPick:j=>a(i.map((g,v)=>v===o?j:g)),label:s("botPanel.backups.row",{position:o+1,model:p}),title:d?`${d.displayName} · ${p}`:p,"data-panel-action":"backup-change",className:"group flex h-8 min-w-0 flex-1 items-center gap-2 rounded-[8px] bg-ink/[0.04] pl-2.5 pr-2 text-left text-[13px] text-ink hover:bg-ink/[0.07] aria-expanded:bg-ink/[0.08]",children:[d?e.jsx(Fa,{instance:d,size:14,subtle:!0}):e.jsx("span",{className:"size-3.5 shrink-0 rounded-full bg-ink/[0.08]","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:f}),!d&&e.jsx("span",{className:"shrink-0 text-[12px] text-warning",children:s("model.simple.unavailable")}),e.jsx(he,{size:12,strokeWidth:2,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary group-hover:text-ink-secondary"})]}),e.jsx(Le,{"data-panel-action":"backup-remove",label:s("botPanel.backups.remove",{model:p}),onClick:()=>{a(i.filter((j,g)=>g!==o)),r.current?.focus({preventScroll:!0})}})]},o)})}),i.length<Ni&&e.jsx("div",{className:"pl-[38px]",children:e.jsxs(Ft,{bot:t,current:null,exclude:l(null),onPick:m=>a([...i,m]),label:s("model.fallback.add"),buttonRef:r,"data-panel-action":"backup-add",className:O(ie,"aria-expanded:bg-raised-hover"),children:[e.jsx(ve,{size:14,"aria-hidden":"true"}),s("model.fallback.add")]})})]})})}function Oi({bot:t}){const{dispatch:a}=$(),[n,i]=u.useState(!1),[r,l]=u.useState(!1),[c,m]=u.useState(0),o=t.memoryEnabled!==!1&&t.memoryUpkeep!==!1;if(u.useEffect(()=>{if(!o)return;let p=!0;return Q(`/api/bots/${t.id}/system-prompt`).then(f=>{p&&i(f.heavy===!0)},()=>{}),()=>{p=!1}},[t.id,o,c]),!o||!n)return null;const d=async()=>{l(!0);try{await ds(t.id)}catch(p){a({type:"error",message:p instanceof Error&&p.message?p.message:s("common.tryAgain")})}finally{l(!1),m(p=>p+1)}};return e.jsx(A,{anchor:"heavy",children:e.jsxs("div",{"data-panel-row":"heavy",className:X,children:[e.jsx(Z,{icon:Ja}),e.jsx(ae,{title:s("botPanel.heavy")}),e.jsx("button",{type:"button","data-panel-action":"tidy-memory",disabled:r,onClick:()=>{d()},className:ie,children:r?s("memory.upkeep.tidying"):s("botPanel.tidyMemory")})]})})}const Ei=5;function Ri({bot:t}){const{dispatch:a,flushBotPatches:n}=$(),[i,r]=u.useState([]),[l,c]=u.useState(null),m=u.useCallback(()=>wt(t.id).then(d=>r(d.rows.slice(0,Ei)),()=>{}),[t.id]);if(u.useEffect(()=>{m()},[m,t.soul]),!i.length)return null;const o=async d=>{if(!l){c(d.id);try{await n(t.id);const{revision:p}=await wt(t.id);await er(t.id,d.id,p)}catch(p){a({type:"error",message:p instanceof Error&&p.message?p.message:s("botOverview.undoFailed")})}finally{c(null),await m()}}};return e.jsxs("div",{"data-panel-row":"soul-changes",className:"flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:s("memory.changes")}),e.jsx(it,{rows:i,botName:t.name,reverting:l,onRevert:d=>{o(d)}})]})}const qe={ask:()=>s("botSettings.simple.ask"),full:()=>s("botSettings.simple.justDoIt"),auto:()=>s("botSettings.simple.decide"),edits:()=>s("approvalMode.edits.label"),custom:()=>s("botPanel.acts.custom")};function Ii({bot:t,derived:a,onOpen:n,editingInstructions:i=!1,onEditInstructions:r}){const{state:l,dispatch:c,flushBotPatches:m}=$(),{capabilities:o,ready:d}=be(),p=as(t),{servers:f}=gs(),j=Qa(Ve(t)),g=Xa(),v=vs(t.id),k=hs(),[C,b]=u.useState(null),{patch:w,approvalMode:x,engine:S}=a,M=t.name,F=()=>{C!==null&&C.trim()!==t.title.trim()&&w({title:C.trim()}),b(null)},B=S?.driverKind==="antigravityAgent"&&x==="auto"?"ask":x,T=[{value:"ask",label:qe.ask(),tooltip:s("botSettings.simple.askHint")},{value:"full",label:qe.full(),tooltip:s("botSettings.simple.fullHint")},...B==="ask"||B==="full"?[]:[{value:B,label:qe[B](),disabled:!0,tooltip:B==="custom"?s("botPanel.acts.customHint"):void 0}]],H=y=>{y===x||y!=="ask"&&y!=="full"||c({type:"updateBot",botId:t.id,patch:{approvalMode:y,applyToAllThreads:!0}})},L=!d||Za(o,l.config),h=pn(g,{turnsHere:L,canLive:!0}),I=L?null:en(o,!!sn()?.speechStart,tn(l.config)),D=an.map(y=>({value:y.id,label:s(y.label),disabled:y.id==="turns"&&I!==null,tooltip:y.id==="turns"&&I?`${I.label}. ${I.reason}`:y.id==="live"?s("call.mode.liveHint"):nn("turns")})),_=rn.map(y=>({value:y,label:s(Nt[y][0]),tooltip:s(Nt[y][1])})),K=()=>{const y=!t.notifications;y&&un(),w({notifications:y})},J=t.alwaysAllow??[],Y=i||!!t.soulDrift,U=[...p.apps.filter(y=>y.scope!==null).map(y=>y.label),...f?ys(f,t.mcpServers,t.id).map(y=>y.name):[]];return e.jsxs("div",{"data-panel-settings":!0,children:[e.jsx(tr,{bot:t}),e.jsx(A,{anchor:"instructions",children:Y?e.jsxs(de,{"data-panel-row":"soul",children:[e.jsx(sr,{bot:t,onPatch:w,simple:{label:s("botSettings.simple.instructions"),placeholder:s("botSettings.simple.instructionsPlaceholder",{name:M})}}),e.jsx(Ri,{bot:t}),i&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-panel-done":"soul",onClick:()=>{m(t.id),r?.(!1)},className:ie,children:s("botSettings.simple.done")})})]}):e.jsxs("button",{type:"button","data-panel-edit":"soul","aria-label":`${s("botSettings.simple.edit")}: ${s("botSettings.simple.instructions")}`,onClick:()=>r?.(!0),className:O(X,"w-full text-left hover:bg-ink/[0.03]"),children:[e.jsx(Z,{icon:Te}),e.jsx(ae,{title:s("botSettings.simple.instructions"),hint:e.jsx("span",{className:"line-clamp-1",children:ar(t.soul??"")||s("botPanel.instructionsHint",{name:M})})}),e.jsx(ye,{size:15,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"})]})}),e.jsx(Oi,{bot:t}),e.jsx(A,{anchor:"approval",children:e.jsxs(de,{"data-panel-row":"approval",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Z,{icon:Wt}),e.jsx(ae,{title:s("botSettings.simple.beforeActs",{name:M}),hint:t.busy?s("approvalMode.whileWorking"):void 0})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Se,{attr:"data-approval-choice",label:s("botSettings.simple.beforeActs",{name:M}),value:B,onChange:H,options:T})}),j.choice&&e.jsxs("div",{"data-panel-row":"thread-approval",className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 pl-[38px]",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:s("botPanel.thisConversation")}),e.jsx("span",{className:"ms-auto flex",children:e.jsx(ln,{choice:j.choice})})]}),J.length>0&&e.jsxs("div",{"data-panel-row":"always-allow",className:"flex min-w-0 flex-col gap-1 pl-[38px]",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:s("botAccess.always.title")}),J.map(y=>e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink",children:y}),e.jsx(Le,{"data-panel-action":`always-allow:${y}`,label:s("botAccess.always.remove",{entry:y}),onClick:()=>w({alwaysAllow:J.filter(z=>z!==y)})})]},y))]})]})}),e.jsx(Pi,{bot:t,onChange:y=>w({fallback:y})}),e.jsx(A,{anchor:"call",children:e.jsxs(de,{"data-panel-row":"call-mode",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Z,{icon:_n}),e.jsx(ae,{title:s("call.mode.menu")})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Se,{attr:"data-call-mode",label:s("call.mode.menu"),value:h,onChange:on,options:D})})]})}),e.jsxs(A,{anchor:"replies",children:[e.jsxs(de,{"data-panel-row":"reply-style",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Z,{icon:cn}),e.jsx(ae,{title:s("botSettings.replyStyle.title")})]}),e.jsx("div",{className:"pl-[38px]",children:e.jsx(Se,{attr:"data-reply-style",label:s("botSettings.replyStyle.title"),value:t.replyStyle??"default",onChange:y=>w({replyStyle:y}),options:_})})]}),e.jsx(at,{"data-panel-row":"notifications",icon:dn,title:s("voice.notifications.title"),color:t.color,checked:t.notifications,onChange:K})]}),e.jsxs(A,{anchor:"uses",children:[e.jsx(ee,{"data-panel-page":"apps",icon:ss,title:s("botPanel.appsRow"),value:U.length>0?U.join(", "):s("botPanel.appsNoneYet"),onClick:()=>n?.("apps")}),e.jsxs("label",{"data-panel-row":"job",className:O(X,"cursor-text"),children:[e.jsx(Z,{icon:Rr}),e.jsx("span",{className:"shrink-0 text-[14px] font-medium text-ink",children:s("botSettings.simple.job")}),e.jsx("input",{"data-panel-job":!0,value:C??t.title,placeholder:s("botSettings.simple.jobPlaceholder"),"aria-label":s("botSettings.simple.job"),maxLength:Ye.title,onChange:y=>b(y.target.value),onBlur:F,onKeyDown:y=>{y.key==="Enter"?(y.preventDefault(),y.currentTarget.blur()):y.key==="Escape"&&C!==null&&(y.preventDefault(),y.stopPropagation(),b(null))},className:"min-w-0 flex-1 bg-transparent text-right text-[13px] text-ink-secondary outline-none placeholder:text-ink-tertiary focus:text-ink"})]}),v&&e.jsxs("a",{"data-panel-row":"slack",href:v,target:"_blank",rel:"noopener noreferrer",className:O(X,"hover:bg-ink/[0.03]"),children:[e.jsx(Z,{icon:bs}),e.jsx(ae,{title:s("botPanel.page.slack"),hint:s("botSlack.manage")}),e.jsx(is,{size:14,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"})]}),k&&e.jsx(ee,{"data-panel-page":"visibility",icon:Vt,title:s("botSettings.visibility.title"),value:nr(t.visibility),onClick:()=>n?.("visibility")})]}),t.yourAccess!=="view"&&!t.defaultBot&&e.jsx(wi,{bot:t,className:"mt-3.5"}),e.jsx(rr,{bot:t,webhooksLink:!0,className:"mt-3.5"}),e.jsx(mn,{bot:t}),j.dialogs]})}const Ti=5;function Li({bot:t,onChanged:a}){const{dispatch:n}=$(),[i,r]=u.useState([]),[l,c]=u.useState(null),[m,o]=u.useState(null),d=u.useCallback(async()=>{const[g,v]=await Promise.all([nt(t.id),xe(t.id)]);c(k=>g.lendingReview?{value:g.lendingReview,stale:k?.stale??!1}:null),r(v.slice(0,Ti))},[t.id]);u.useEffect(()=>{d().catch(()=>{})},[d,t.busy]);const p=g=>n({type:"error",message:g instanceof Error&&g.message?g.message:s("common.tryAgain")}),f=async g=>{o(g.id);try{await ps(t.id,g.id),await a()}catch(v){p(v)}finally{o(null),await d().catch(()=>{})}},j=async g=>{o("review");try{await cs(t.id,g.value.token),c(null)}catch(v){v instanceof Jt&&v.status===409?(c({...g,stale:!0}),await d().catch(()=>{})):p(v)}finally{o(null)}};return e.jsxs(e.Fragment,{children:[l&&e.jsx(js,{changed:l.value.changed,stale:l.stale,busy:m!==null,onReviewed:()=>{j(l)}}),e.jsx(A,{children:e.jsx(at,{"data-panel-row":"memory-upkeep",title:s("memory.upkeep.title"),checked:t.memoryUpkeep!==!1,color:t.color,onChange:()=>n({type:"updateBot",botId:t.id,patch:{memoryUpkeep:t.memoryUpkeep===!1}})})}),i.length>0&&e.jsx(A,{label:s("memory.changes"),children:e.jsx("div",{"data-panel-row":"memory-changes",className:"px-3.5 py-3",children:e.jsx(it,{rows:i,botName:t.name,reverting:m,onRevert:g=>{f(g)}})})})]})}const Ai="flex flex-col gap-3",zt="https://www.skills.sh";function ge(t,a){return t instanceof Error&&t.message?t.message:a}function Mi({bot:t,derived:a}){const{dispatch:n}=$(),i=as(t),{servers:r,error:l}=gs(),{patch:c,canUseConnectedApps:m}=a,o=r?vr(r,t.id):[],d=new Set(ys(o,t.mcpServers,t.id).map(g=>g.name)),p=g=>{const v=yn(t,i.connectedSlugs,g.slug,g.scope===null);Object.keys(v).length>0&&c(v)},f=g=>{t.busy||l||c({mcpServers:kr(o,t.mcpServers,g)})},j=m?i.phase==="loading"?s("common.checking"):i.phase==="unknown"?s("botSettings.simple.appsUnknown"):i.apps.length===0?s("botSettings.simple.appsNone"):null:s("botSettings.simple.appsCannot",{name:t.name});return e.jsxs(e.Fragment,{children:[e.jsxs(A,{children:[j&&e.jsx(V,{children:j}),m&&i.apps.map(g=>e.jsxs("div",{"data-simple-app":g.slug,className:X,children:[e.jsx(fn,{card:g.card,className:"size-7 shrink-0"},`${g.card.logo}:${g.card.domain}`),e.jsx("div",{className:"min-w-0 flex-1 truncate text-[14px] font-medium text-ink",children:g.label}),e.jsx(gt,{color:t.color,checked:g.scope!==null,"aria-label":s("botSettings.simple.appToggle",{name:t.name,app:g.label}),disabled:!!t.busy,onClick:()=>p(g),className:"disabled:cursor-not-allowed"})]},g.slug))]}),(o.length>0||l)&&e.jsxs(A,{label:s("connectors.tab.mcp"),children:[l&&e.jsx(V,{children:s("botAccess.mcpRefreshError")}),o.map(g=>e.jsxs("div",{"data-simple-mcp":g.name,className:X,children:[e.jsx(Z,{icon:Kn}),e.jsx(ae,{title:e.jsx("span",{className:"block truncate",children:g.name}),hint:g.enabled?g.offFor?.includes(t.id)?s("mcp.offFor",{bots:t.name}):void 0:s("botAccess.mcpDisabled")}),e.jsx(gt,{color:t.color,checked:d.has(g.name),"aria-label":s("botSettings.simple.appToggle",{name:t.name,app:g.name}),disabled:!g.enabled||!!t.busy||l,onClick:()=>f(g.name),className:"disabled:cursor-not-allowed"})]},g.name))]}),e.jsx(A,{children:e.jsx(me,{"data-panel-link":"add-app",icon:ve,onClick:()=>gn(n,t.id),children:s("botPanel.apps.connectAnother")})})]})}function Bi({bot:t,derived:a}){const{state:n,dispatch:i}=$(),[r,l]=u.useState(()=>a.botRoutines.length===0?"new":null);return e.jsxs(e.Fragment,{children:[e.jsx(yr,{routines:a.botRoutines,runs:n.routineRuns,pausedBots:n.config?.pausedBots,heldBots:n.config?.heldBots,loading:n.routinesLoadState==="loading"&&a.botRoutines.length===0,error:n.routinesLoadState==="error",onOpen:l,onLogs:c=>i({type:"showRoutines",section:"logs",botId:t.id,routineId:c.id}),onToggle:c=>i({type:"updateRoutine",routineId:c.id,patch:{enabled:!c.enabled}})}),e.jsx(A,{children:e.jsx(me,{"data-panel-action":"new-routine",icon:ve,onClick:()=>l("new"),children:s("botPanel.routines.add")})}),e.jsx("p",{className:"mx-1 text-[13px] leading-normal text-ink-secondary",children:s("botPanel.routines.ask",{name:t.name})}),r&&e.jsx(jr,{routine:r==="new"?void 0:r,bots:[t],lockedBotId:t.id,onClose:()=>l(null)},t.id)]})}function $i({bot:t}){const a=Os(t),[n,i]=u.useState(""),[r,l]=u.useState(null),[c,m]=u.useState(!1),[o,d]=u.useState(null),p=t.memoryEnabled!==!1,f=a.docs?Ps(a.docs):null,j=a.docs?.find(b=>b.path===te)??null;u.useEffect(()=>l(null),[t.id,p]);const g=async b=>{if(c)return!1;m(!0),d(null);try{return await b()}catch(w){return d(ge(w,s("botPanel.library.memoryError"))),!1}finally{m(!1)}},v=(b,w)=>g(async()=>{const x=await rt(t.id,b.path,w,b.exists?b.hash:void 0,a.mine);return x.ok?(a.setDoc(x.doc),!0):(await a.reload(),d(s("memory.conflict.title",{name:t.name})),!1)}),k=b=>{const w=a.docs?.find(x=>x.path===b.path);w&&(b.line!==null?v(w,xi(w.text,b.line)):g(async()=>(await ms(t.id,w.path,a.mine),await a.reload(),!0)))},C=async()=>{!j||!n.trim()||await v(j,hi(j.text,n))&&i("")};return p&&r?.botId===t.id?e.jsx(Di,{bot:t,doc:r.doc,mine:a.mine,onDone:b=>{b&&a.setDoc(b),l(null),d(null)}}):e.jsxs(e.Fragment,{children:[e.jsxs(A,{children:[p?a.error?e.jsx(V,{tone:"warn",children:s("botPanel.library.memoryError")}):f===null?e.jsx(V,{children:s("common.checking")}):f.length===0?e.jsx(V,{children:s("botPanel.memory.empty")}):f.map(b=>e.jsxs("div",{"data-memory-note":b.line??b.path,className:X,children:[e.jsx("div",{className:"min-w-0 flex-1 text-[13px] leading-[1.45] text-ink",children:b.text}),e.jsx(Le,{label:s("botPanel.memory.forget"),disabled:c,onClick:()=>k(b)})]},`${b.path}:${b.line}:${b.text}`)):e.jsx(V,{children:s("botPanel.library.memoryOff",{name:t.name})}),o&&e.jsx(V,{tone:"warn",children:o})]}),p&&e.jsxs(A,{children:[e.jsx(ns,{"data-panel-form":"memory-add",value:n,placeholder:s("botPanel.memory.addPlaceholder",{name:t.name}),label:s("botPanel.memory.addPlaceholder",{name:t.name}),action:s("common.add"),disabled:c||j===null,onChange:i,onSubmit:()=>{C()}}),j&&e.jsx(me,{"data-panel-link":"memory-text",icon:Te,onClick:()=>l({botId:t.id,doc:j}),children:s("botPanel.memory.editText")})]}),p&&!a.mine&&e.jsx(Li,{bot:t,onChanged:a.reload})]})}function Di({bot:t,doc:a,mine:n,onDone:i}){const[r,l]=u.useState({text:a.text,hash:a.hash}),[c,m]=u.useState(a.text),[o,d]=u.useState(null),[p,f]=u.useState(null),[j,g]=u.useState(!1),[v,k]=u.useState(null),C=u.useRef(!0);u.useEffect(()=>(C.current=!0,()=>{C.current=!1}),[]);const b=async x=>{g(!0),k(null);try{const S=await rt(t.id,a.path,c,x,n);if(!C.current)return;S.ok?i(S.doc):d({current:S.current,currentHash:S.currentHash})}catch(S){k(ge(S,s("botPanel.library.memoryError")))}finally{g(!1)}},w=()=>{o&&(f(x=>x===null||x===c?c:`${x}
|
|
15
|
+
|
|
16
|
+
${c}`),l({text:o.current,hash:o.currentHash}),m(o.current),d(null))};return e.jsx(A,{children:e.jsxs(de,{"data-panel-row":"memory-text",children:[o&&e.jsx(ws,{botName:t.name,busy:j,onReload:w,onOverwrite:()=>{b(o.currentHash)}}),e.jsx("textarea",{"data-memory-text":"",className:O(Qe,"min-h-[280px] resize-y font-mono text-[13px] leading-relaxed"),value:c,placeholder:s("memory.indexPlaceholder"),"aria-label":s("memory.botMemory"),readOnly:j,onChange:x=>m(x.target.value)}),v&&e.jsx("div",{className:"text-[13px] text-warning",children:v}),p!==null&&e.jsxs("div",{"data-memory-draft":"",children:[e.jsx("div",{className:"mb-1 text-[12px] text-ink-secondary",children:s("memory.unsavedDraft")}),e.jsx("pre",{className:"max-h-[160px] overflow-auto whitespace-pre-wrap rounded-lg border border-hairline/40 bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:p}),e.jsx("button",{type:"button",className:O(ie,"mt-1"),onClick:()=>f(null),children:s("memory.dismissDraft")})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",className:ie,disabled:j,onClick:()=>i(null),children:s("common.cancel")}),e.jsx("button",{type:"button","data-panel-done":"memory-text",className:ie,disabled:j||c===r.text,onClick:()=>{b(r.hash)},children:j?s("memory.saving"):s("memory.save")})]})]})})}function Fi({bot:t}){const{request:a}=xn(),{state:n,dispatch:i}=$(),r=us(t),[l,c]=u.useState(""),[m,o]=u.useState(!1),[d,p]=u.useState([]),f=hn(n.config),j=async x=>{if(!r.working&&window.confirm(s(x.origin==="library"?"skills.unassignConfirm":"botPanel.skills.removeConfirm",{name:x.name}))){r.setWorking(x.name),r.setError("");try{await a(`/api/bots/${t.id}/skills/${encodeURIComponent(x.name)}`,{method:"DELETE"}),await r.refresh()}catch(S){r.setError(ge(S,s("botPanel.skills.removeFailed")))}finally{r.setWorking("")}}},g=async()=>{const x=l.trim();if(!(!x||m)){o(!0),r.setError(""),p([]);try{const S=await a(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:x})});p(St(S.imported??[])),c(""),await r.refresh()}catch(S){r.setError(ge(S,s("botPanel.skills.importFailed")))}finally{o(!1)}}},v=async()=>{const x=await window.ogb?.pickFolder?.();if(!(!x||m)){o(!0),r.setError(""),p([]);try{const S=await a(`/api/bots/${t.id}/skills`,{method:"POST",body:JSON.stringify({source:`local-folder:${x}`})});p(St(S.imported??[])),await r.refresh()}catch(S){r.setError(ge(S,s("botPanel.skills.importFailed")))}finally{o(!1)}}},[k,C]=u.useState(!1),b=()=>{C(!1),i({type:"toggleSettings",open:!1}),i({type:"toggleAppSettings",open:!0,section:"skills"})},w=()=>{if(f){C(!0);return}ft(zt)};return e.jsxs(e.Fragment,{children:[e.jsxs(A,{children:[r.loading?e.jsx(V,{children:s("skills.loading")}):r.skills.length===0?e.jsx(V,{children:s("botSettings.simple.noSkills")}):r.skills.map(x=>e.jsx(at,{"data-panel-row":`skill:${x.name}`,title:x.name,hint:x.description||x.source,label:s("botSettings.simple.skillToggle",{name:x.name}),color:t.color,checked:xs(x),disabled:!!r.working||x.core===!0,onChange:()=>{r.toggle(x)},extra:x.origin==="imported"||x.origin==="native"||x.origin==="bundled"?void 0:e.jsx(Le,{"data-panel-action":`remove-skill:${x.name}`,label:s("botPanel.skills.remove",{name:x.name}),disabled:!!r.working,onClick:()=>{j(x)}})},x.name)),r.error&&!r.reviewing&&e.jsx(V,{tone:"warn",children:r.error})]}),e.jsx(lr,{bot:t,onAdded:()=>{r.refresh()}}),e.jsxs(A,{children:[e.jsx(ns,{"data-panel-form":"skill-import",value:l,placeholder:s("botPanel.skills.importPlaceholder"),label:s("skills.import.label"),action:m?s("skills.import.importing"):s("common.add"),disabled:m,onChange:c,onSubmit:()=>{g()}}),d.map(x=>e.jsx(V,{children:x},x)),e.jsx(me,{"data-panel-link":"skills-sh",onClick:()=>{ft(zt)},children:s("botPanel.skills.skillsSh")}),e.jsx(me,{"data-panel-link":"browse-skills",onClick:w,children:s("botPanel.skills.bundled")}),window.ogb?.pickFolder&&e.jsx(me,{"data-panel-link":"skills-folder",onClick:()=>{v()},children:s("botPanel.skills.fromFolder")})]}),k&&e.jsx(ji,{botId:t.id,botName:t.name,onOpenSettings:b,onClose:()=>{C(!1),r.refresh()}}),r.reviewing&&e.jsx(or,{skill:r.reviewing.skill,text:r.reviewing.text,error:r.error,working:r.working===r.reviewing.skill.name,onCancel:()=>r.setReviewing(null),onEnable:()=>{r.enableReviewed()}})]})}function zi({bot:t}){const{capabilities:a}=be(),n=a.host?.homeDir,{draft:i,setDraft:r,error:l,saving:c,canPick:m,save:o,pick:d}=ir(t),[p,f]=u.useState(!1),j=!!t.cwd||p,g=()=>{if(m){d();return}f(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(A,{children:[e.jsx(We,{"data-panel-choice":"private",title:s("botPanel.folder.own"),hint:s("botPanel.folder.ownHint"),checked:!j,disabled:c,onClick:()=>{f(!1),t.cwd&&o(null)}}),e.jsx(We,{"data-panel-choice":"pick",title:s("botPanel.folder.pick"),hint:s("botPanel.folder.pickHint"),checked:j,disabled:c,onClick:()=>{t.cwd||g()}})]}),j&&e.jsxs(A,{children:[m?e.jsxs("div",{className:X,children:[e.jsx("div",{className:"min-w-0 flex-1 truncate rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[13px] text-ink",title:t.cwd,children:t.cwd?tt(t.cwd,n):e.jsx("span",{className:"text-ink-secondary",children:s("botAccess.folder.private")})}),e.jsxs("button",{type:"button","data-panel-action":"pick-folder",disabled:c,onClick:()=>{d()},className:ie,children:[e.jsx(Yt,{size:14,"aria-hidden":"true"}),s("botAccess.folder.choose")]})]}):e.jsxs("form",{"data-panel-form":"folder-path",className:X,onSubmit:v=>{v.preventDefault();const k=(i??t.cwd??"").trim();k&&o(k)},children:[e.jsx("input",{value:i??t.cwd??"",placeholder:s("botAccess.folder.placeholder"),"aria-label":s("botAccess.folder.title"),onChange:v=>r(v.target.value),className:"h-8 min-w-0 flex-1 rounded-lg border border-hairline bg-inset px-2.5 font-mono text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent-border"}),e.jsx("button",{type:"submit",disabled:c||i===null,className:ie,children:s("botAccess.folder.save")})]}),l&&e.jsx(V,{tone:"warn",children:l})]})]})}function Hi({bot:t,derived:a}){const n=Ns(t);return e.jsx(bi,{bot:t,browserEnabled:a.browserEnabled,onOpenBrowser:()=>n("browser")})}function _i({bot:t}){return hs()?e.jsx(fs,{bot:t}):null}function Ki({page:t,onOpen:a,editingInstructions:n,onEditInstructions:i,...r}){switch(t){case"settings":return e.jsx(Ii,{...r,onOpen:a,editingInstructions:n,onEditInstructions:i});case"where":return e.jsx(si,{...r});case"apps":return e.jsx(Mi,{...r});case"routines":return e.jsx(Bi,{...r});case"visibility":return e.jsx(_i,{...r});case"memory":return e.jsx($i,{...r});case"skills":return e.jsx(Fi,{...r});case"folder":return e.jsx(zi,{...r});case"browser":return e.jsx(Hi,{...r})}}const Ht="rounded-lg border border-accent-border bg-inset px-2 py-[3px] text-center text-ink outline-none placeholder:text-ink-tertiary";function _t(t){const[a,n]=u.useState(null),i=u.useRef(!1),r=u.useRef(!1),l=u.useRef(null);u.useEffect(()=>{a!==null||!r.current||(r.current=!1,l.current?.focus())},[a]);const c=p=>{i.current=!1,n(p)},m=()=>{a!==null&&t(a),n(null)};return{draft:a,setDraft:n,start:c,onKeyDown:p=>{if(vn(p.nativeEvent)){p.stopPropagation();return}p.key==="Enter"?(p.preventDefault(),i.current=!0,r.current=!0,m()):p.key==="Escape"&&(p.preventDefault(),p.stopPropagation(),i.current=!0,r.current=!0,n(null))},onBlur:()=>{i.current||m()},buttonRef:l}}function Ui({bot:t,activeState:a,patch:n,editorOpen:i,onToggleEditor:r}){const l=_t(o=>{const d=o.trim();d&&d!==t.name&&n({name:d})}),c=_t(o=>{const d=o.trim();d!==t.title.trim()&&n({title:d})}),m=t.title.trim();return e.jsxs("div",{className:"group/hero flex flex-col items-center text-center",children:[e.jsxs("button",{type:"button","data-panel-avatar":!0,"aria-label":s("botPanel.avatar.edit"),"aria-expanded":i,onClick:r,className:"group relative rounded-[18px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-border",children:[e.jsx(Je,{bot:t,size:64,state:a}),e.jsx("span",{"aria-hidden":"true",className:"absolute inset-0 flex items-center justify-center rounded-[18px] bg-black/0 text-white opacity-0 transition-[opacity,background-color] group-hover:bg-black/40 group-hover:opacity-100 group-focus-visible:bg-black/40 group-focus-visible:opacity-100 group-focus-within:opacity-100 touch:opacity-100 motion-reduce:transition-none",children:e.jsx(yt,{size:20})}),t.chiefOfStaff&&e.jsxs("span",{"data-panel-chief":!0,title:s("chat.chiefOfStaff"),className:"absolute -bottom-0.5 -right-0.5 flex size-[22px] items-center justify-center rounded-full bg-accent text-accent-ink ring-[3px] ring-app",children:[e.jsx(bn,{size:12,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:s("chat.chiefOfStaff")})]}),e.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute left-1/2 top-[calc(100%+4px)] z-10 -translate-x-1/2 whitespace-nowrap rounded-md border border-hairline bg-menu px-[7px] py-0.5 text-[12px] text-ink opacity-0 transition-opacity group-hover:opacity-100",children:s("botPanel.avatar.edit")})]}),e.jsx("div",{"data-panel-name-row":!0,className:"mt-2 flex max-w-full items-center justify-center",children:e.jsx("h2",{id:"bot-settings-title",className:"flex min-w-0 justify-center",children:l.draft!==null?e.jsx("input",{autoFocus:!0,"data-panel-rename-input":!0,"aria-label":s("botSettings.simple.name"),maxLength:Ye.name,value:l.draft,onChange:o=>l.setDraft(o.target.value),onKeyDown:l.onKeyDown,onBlur:l.onBlur,className:O(Ht,"w-[220px] max-w-full text-[17px] font-medium leading-6")}):e.jsxs("button",{ref:l.buttonRef,type:"button","data-panel-rename":!0,title:s("botPanel.rename"),onClick:()=>l.start(t.name),className:"group/name relative inline-flex max-w-full items-center rounded-[8px] px-1.5 text-[17px] font-medium leading-6 text-ink hover:bg-ink/[0.04]",children:[e.jsx("span",{className:"min-w-0 truncate",children:t.name}),e.jsx(yt,{size:13,"aria-hidden":"true",className:"absolute -right-4 shrink-0 text-ink-tertiary opacity-0 transition-opacity group-hover/name:opacity-100 group-focus-visible/name:opacity-100 group-focus-within/name:opacity-100 touch:opacity-100"})]})})}),c.draft!==null?e.jsx("input",{autoFocus:!0,"data-panel-label-input":!0,"aria-label":s("botSettings.simple.job"),placeholder:s("botSettings.simple.jobPlaceholder"),maxLength:Ye.title,value:c.draft,onChange:o=>c.setDraft(o.target.value),onKeyDown:c.onKeyDown,onBlur:c.onBlur,className:O(Ht,"mt-[3px] w-[200px] max-w-full text-[13px]")}):m&&e.jsx("button",{ref:c.buttonRef,type:"button","data-panel-label":!0,onClick:()=>c.start(t.title),className:"mt-px max-w-full truncate rounded-md px-1.5 py-px text-[13px] text-ink-secondary hover:bg-ink/[0.04]",children:m})]})}function Ne(t,a){return t?rs(t,a):{tab:"details"}}function qi({bot:t,derived:a,linkedSection:n,onClose:i}){const{dragProps:r}=os(),l=kn(),[c,m]=u.useState(()=>Ne(n,l).tab),[o,d]=u.useState(()=>{const h=Ne(n,l).page;return h?[h]:[]}),[p,f]=u.useState(()=>Ne(n,l).anchor??null),[j,g]=u.useState(!1),[v,k]=u.useState(()=>!!Ne(n,l).editInstructions),C=u.useRef(null),b=u.useRef(null),w=o.at(-1)??null,x=()=>C.current?.scrollTo({top:0}),S=h=>{m(h.tab),d(h.page?[h.page]:[]),f(h.anchor??null),g(!1),k(!!h.editInstructions),x()},M=h=>S({tab:h}),F=h=>{d(I=>[...I,h]),g(!1),x()},B=()=>{g(!1),b.current?.querySelector("[data-panel-avatar]")?.focus()},T=()=>{d(h=>h.slice(0,-1)),x()};u.useEffect(()=>{n&&S(rs(n,l))},[n,l]),u.useEffect(()=>{p&&(C.current?.querySelector(`[data-panel-card="${p}"]`)?.scrollIntoView({block:"start"}),f(null))},[p,w,c]);const H=h=>{if(h.key!=="Escape"||h.defaultPrevented)return;const I=h.target,D=typeof I?.closest=="function"?I.closest('[role="dialog"], [role="alertdialog"]'):null;if(!(D&&!D.contains(h.currentTarget)&&D!==b.current&&!b.current?.contains(D))){if(j)B();else if(o.length>0)T();else return;h.preventDefault(),h.stopPropagation()}},L=o.length>1?s(je[o[o.length-2]].title,{name:t.name}):s(bt[c]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",onKeyDown:H,children:[e.jsxs("div",{...r,className:"flex h-[50px] shrink-0 items-start justify-end gap-2.5 px-[13px] pt-[13px]",children:[e.jsx(jn,{bot:t,className:De}),e.jsx("button",{type:"button","data-panel-gear":!0,"aria-label":s("botPanel.page.settings"),title:s("botPanel.page.settings"),"aria-current":w==="settings"?"page":void 0,onClick:()=>S({tab:"details",page:"settings"}),className:De,children:e.jsx(wn,{size:16,className:"pointer-events-none"})}),e.jsx("button",{type:"button",onClick:i,"aria-label":s("botSettings.simple.close"),className:De,children:e.jsx(Ze,{size:16,className:"pointer-events-none"})})]}),e.jsx("div",{ref:C,className:"@container relative min-h-0 flex-1 overflow-y-auto px-4 pb-7",children:w===null?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mt-3.5",ref:b,children:[e.jsx(Ui,{bot:t,activeState:a.activeState,patch:a.patch,editorOpen:j,onToggleEditor:()=>g(h=>!h)}),j&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-20","aria-hidden":"true","data-panel-scrim":!0,onClick:B}),e.jsx(Zr,{bot:t,activeState:a.activeState,onPatch:a.patch,onClose:B})]})]}),e.jsx("div",{role:"tablist","aria-label":s("botSettings.simple.tabs"),className:"sticky top-0 z-[1] -mx-4 mt-[15px] flex justify-center bg-app px-4 pb-2.5 pt-1 after:pointer-events-none after:absolute after:inset-x-0 after:top-full after:h-3 after:bg-linear-to-b after:from-app after:to-transparent",children:e.jsx("div",{className:"flex min-w-0 gap-0.5 rounded-full bg-ink/[0.05] p-[3px]",children:Nn.map(h=>e.jsx("button",{type:"button",role:"tab","aria-selected":c===h,"data-panel-tab":h,onClick:()=>M(h),className:O("h-[26px] min-w-0 shrink truncate rounded-full px-3 text-[13px] leading-[18px] transition-colors",c===h?"bg-ink/[0.1] font-medium text-ink":"text-ink-secondary hover:text-ink"),children:s(bt[h])},h))})}),e.jsxs("div",{role:"tabpanel",children:[c==="details"&&e.jsx(pi,{bot:t,derived:a,onOpen:F}),c==="library"&&e.jsx(Es,{bot:t,onOpen:F}),c==="computer"&&e.jsx(ai,{bot:t,derived:a,onOpen:F})]})]}):e.jsxs("div",{"data-panel-page-view":w,children:[e.jsx("span",{id:"bot-settings-title",className:"sr-only",children:t.name}),e.jsx(Sn,{back:L,title:s(je[w].title,{name:t.name}),intro:je[w].intro?s(je[w].intro,{name:t.name}):void 0,onBack:T}),e.jsx("div",{className:O("mt-4",Ai),children:e.jsx(Ki,{page:w,bot:t,derived:a,onOpen:F,editingInstructions:v,onEditInstructions:k})})]})})]})}function Wi(t,a){const{state:n,flushBotPatches:i}=$(),[r,l]=u.useState(null),[c,m]=u.useState(!1),[o,d]=u.useState(null),[p,f]=u.useState(!1),j=u.useMemo(()=>JSON.stringify([t.name,t.title,t.description,t.soul,t.computer,t.cloudBackend,t.cwd,t.autoApprove,t.section,t.composio,t.browser,t.mcpServers,t.chiefOfStaff,t.managedSections,t.modelSelection]),[t.name,t.title,t.description,t.soul,t.computer,t.cloudBackend,t.cwd,t.autoApprove,t.section,t.composio,t.browser,t.mcpServers,t.chiefOfStaff,t.managedSections,t.modelSelection]),g=a.followEdits??!0,v=g?j:null,k=g?n.routines:null,C=g?n.webhooks:null;return u.useEffect(()=>{if(!a.overview&&!a.prompt)return;let b=!1;return(async()=>(await i(t.id),!b&&(a.overview&&Q(`/api/bots/${t.id}/overview`).then(x=>{b||(l(x),m(!1))}).catch(()=>{b||m(!0)}),a.prompt&&Q(`/api/bots/${t.id}/system-prompt`).then(x=>{b||(d(x),f(!1))}).catch(()=>{b||f(!0)}))))(),()=>{b=!0}},[t.id,a.overview,a.prompt,v,k,C,i]),{overview:r,overviewError:c,prompt:o,promptError:p}}function Vi(t,a){const{dispatch:n,flushBotPatches:i}=$(),[r,l]=u.useState(null),[c,m]=u.useState(!1),[o,d]=u.useState(null),p=u.useRef(0),[f,j]=u.useState(!1),[g,v]=u.useState(null),k=u.useCallback(()=>{const w=++p.current;return m(!1),i(t.id).then(()=>Q(`/api/bots/${t.id}/history?limit=100`)).then(x=>{w===p.current&&(l(x.rows),d(x.revision))}).catch(()=>{w===p.current&&m(!0)})},[t.id,i]);return u.useEffect(()=>{if(a)return k(),()=>{p.current++}},[a,k]),{rows:r,error:c,revision:o,rollingBack:f,rollbackTarget:g,setRollbackTarget:v,rollback:async w=>{if(!f){v(null),j(!0);try{await i(t.id),await Q(`/api/bots/${t.id}/history/rollback`,{method:"POST",body:JSON.stringify(w)})}catch(x){n({type:"error",message:x instanceof Error?x.message:s("botOverview.undoFailed")})}finally{await k(),j(!1)}}},requestRollback:w=>{o&&v({id:w,expectedRevision:o})}}}function Gi({history:t,returnFocusRef:a}){const{rollbackTarget:n,setRollbackTarget:i,rollback:r}=t;return e.jsx(Cn,{open:n!==null,title:s("botOverview.restoreSoul.title"),body:s("botOverview.restoreSoul.body"),confirmLabel:s("botOverview.restoreSoul.confirm"),tone:"neutral",returnFocusRef:a,onCancel:()=>i(null),onConfirm:()=>{n&&r(n)}})}const Yi={memory:"memory",skills:"skills",folder:"access"},Is=t=>t.labelKey?s(t.labelKey):t.label;function Kt(t,a){return a?[t.label,Is(t),...t.keywords].some(n=>n.toLowerCase().includes(a)):!0}function ul({bot:t,overlay:a=!1}){const{state:n,dispatch:i}=$(),r=n.botSettingsSection,l=Pn(t),c=u.useRef(null),{dragProps:m}=os(),[o,d]=u.useState(""),p=!n.botSettingsExpandAccordion,f=o.trim().toLowerCase(),g=!Ut(),v=!p&&!n.botSettingsExpandRemembered?r:null,k=vs(t.id),C=st(),b=On(),w=Ir.filter(L=>L.id!=="slack"||k!==null).filter(L=>L.id!=="visibility"||!window.ogb&&C===!0&&!b),x=w.filter(L=>Kt(L,f)),{overview:S,overviewError:M,prompt:F,promptError:B}=Wi(t,{overview:r==="overview"&&!g,prompt:r==="overview"&&!g}),T=Vi(t,r==="history"&&!g);u.useEffect(()=>{if(!p){if(f){d("");return}c.current?.querySelector(`[data-bot-settings-section="${r}"]`)?.scrollIntoView({block:"nearest"})}},[p,r,f]),u.useEffect(()=>{const L=document.activeElement instanceof HTMLElement?document.activeElement:null,h=c.current;h?.focus();const I=D=>{const _=h?.querySelector('[role="dialog"], [role="alertdialog"]');_&&_.getClientRects().length>0||h&&D.target instanceof Node&&!h.contains(D.target)||D.key==="Escape"&&!D.defaultPrevented&&(D.preventDefault(),i({type:"toggleSettings",open:!1}))};return window.addEventListener("keydown",I),()=>{window.removeEventListener("keydown",I),L?.focus()}},[i]);const H=L=>{switch(L){case"overview":return S===null&&M?e.jsx("div",{className:"rounded-xl bg-card p-4 text-[13px] text-ink-secondary",children:s("botSettings.overviewFailed")}):e.jsx(Dr,{overview:S,refreshError:S!==null&&M,prompt:F,promptError:B,onOpen:h=>i({type:"toggleSettings",open:!0,section:h}),onSetup:l.canCoordinate&&!t.busy?()=>{i({type:"toggleSettings",open:!1}),i({type:"send",botId:t.id,text:"/setup",threadId:t.threadId})}:void 0});case"identity":return e.jsx(hr,{bot:t,patch:l.patch,activeState:l.activeState,mascotMotion:l.mascotMotion});case"soul":return e.jsx(xr,{bot:t,patch:l.patch});case"slack":return k?e.jsx(Fr,{managementUrl:k}):null;case"skills":return e.jsx(ur,{bot:t});case"memory":return e.jsx(_r,{bot:t,active:!p&&r==="memory",onToggle:h=>l.patch({memoryEnabled:h})});case"library":return e.jsx(Es,{bot:t,onOpen:h=>i({type:"toggleSettings",open:!0,section:Yi[h]??"overview"})});case"routines":return e.jsx(br,{bot:t,routines:l.botRoutines,runs:n.routineRuns});case"access":return e.jsx(pr,{bot:t,derived:l});case"model":return e.jsx(mr,{bot:t});case"permissions":return e.jsx(dr,{bot:t,derived:l});case"voice":return e.jsx(cr,{bot:t,derived:l});case"visibility":return e.jsx(fs,{bot:t});case"history":return T.rows===null&&T.error?e.jsx("div",{className:"rounded-xl bg-card p-4 text-[13px] text-ink-secondary",children:s("botSettings.historyFailed")}):e.jsx(Wr,{bot:t,rows:T.rows,refreshError:T.rows!==null&&T.error,onRollback:T.requestRollback,rollingBack:T.rollingBack||!T.revision});case"usage":return e.jsx(Vr,{bot:t});default:return null}};return e.jsxs(e.Fragment,{children:[e.jsx("aside",{ref:c,id:g?En:void 0,role:"dialog","aria-labelledby":"bot-settings-title",tabIndex:-1,className:In(a,g),children:g?e.jsx(qi,{bot:t,derived:l,linkedSection:v,onClose:()=>i({type:"toggleSettings",open:!1})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{...m,className:"flex shrink-0 items-center justify-between px-4 py-3",children:[e.jsx("span",{id:"bot-settings-title",className:"truncate text-[15px] font-semibold text-ink",children:t.name}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Rn,{bot:t,className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink"}),e.jsx("button",{type:"button",onClick:()=>i({type:"toggleSettings",open:!1}),"aria-label":s("botSettings.simple.close"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(Ze,{size:18,className:"pointer-events-none"})})]})]}),e.jsxs("div",{className:"mx-4 mb-2 flex shrink-0 items-center gap-2 rounded-lg border border-transparent bg-control/70 px-2.5 py-2 focus-within:border-focus",children:[e.jsx(Xe,{size:14,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{value:o,onChange:L=>{d(L.target.value),i({type:"toggleSettings",open:!0})},onKeyDown:L=>{L.key==="Escape"&&(L.stopPropagation(),o?d(""):i({type:"toggleSettings",open:!1}))},placeholder:s("botSettings.search"),"aria-label":s("botSettings.searchAria"),className:"w-full bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto",children:[x.length===0&&e.jsx("div",{className:"px-4 py-4 text-[13px] leading-relaxed text-ink-secondary",children:s("botSettings.searchNone",{query:o.trim()})}),w.map(L=>{const{id:h,icon:I}=L,D=Is(L),_=Kt(L,f);if(!_&&h!=="memory")return null;const K=!p&&r===h;return e.jsxs("div",{"data-bot-settings-section":h,className:"border-b border-hairline/30",hidden:!_,children:[e.jsxs("button",{type:"button",onClick:()=>{if(r===h&&!p){i({type:"toggleSettings",open:!0});return}i({type:"toggleSettings",open:!0,section:h})},"aria-expanded":K,className:O("flex w-full shrink-0 items-center gap-2.5 px-4 py-2.5 text-left text-[14px]",K?"bg-control/60 text-ink":"text-ink-secondary hover:bg-control/40 hover:text-ink"),children:[e.jsx(I,{size:15,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:D}),e.jsx(he,{size:16,className:O("shrink-0 text-ink-secondary transition-transform",K&&"rotate-180")})]}),h==="memory"?e.jsx("div",{hidden:!K,className:"px-4 pb-4 pt-1",children:H("memory")}):K&&e.jsx("div",{className:"px-4 pb-4 pt-1",children:H(h)})]},h)})]})]})}),e.jsx(Gi,{history:T,returnFocusRef:c})]})}export{ul as BotSettingsDialog};
|