agent-nuvira 2.5.0 → 2.5.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-nuvira",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Agent-Nuvira: Multi-agent AI coding CLI — plan, write, review, test, and publish code with local models (Ollama) or cloud APIs (Groq, NVIDIA NIM, Google Gemini, OpenRouter)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -203,5 +203,5 @@ ${r}`);return n&&t.push(n),t}function mge(e){return/(^|\n)\s*(PASS|FAIL|✅|❌|
|
|
|
203
203
|
`).map((p,h)=>{const g=p.startsWith("+")?"diff-add":p.startsWith("-")?"diff-del":p.startsWith("@@")?"diff-hunk":"";return s.jsx("div",{className:`chat-diff-line ${g}`,children:p||" "},h)})})]},d.path)})}),t&&n?s.jsxs("div",{className:"chat-diff-actions",children:[s.jsxs("button",{className:"admin-refresh-btn",type:"button",disabled:o.size===0,onClick:()=>n([...o]),children:["Commit accepted (",o.size,")"]}),s.jsx("span",{className:"admin-hint",children:"Only accepted files are committed — the agent re-confirms with a question card."})]}):r?s.jsx("div",{className:"chat-diff-actions",children:s.jsxs("span",{className:"admin-hint chat-diff-locked",children:["🔒 ",r]})}):null]})}function I0({text:e,label:t}){const[n,r]=E.useState(!1),i=async()=>{var a;try{await((a=navigator.clipboard)==null?void 0:a.writeText(e)),r(!0),setTimeout(()=>r(!1),1500)}catch{}};return s.jsx("button",{type:"button",className:"chat-card-copy",title:`Copy ${t}`,onClick:()=>void i(),children:n?"✓ Copied":"⧉ Copy"})}function _ge({result:e}){const t=e.verdict==="pass"?"✅":e.verdict==="fail"?"❌":"📋";return s.jsxs("div",{className:`chat-result-card chat-result-${e.verdict}`,children:[s.jsxs("div",{className:"chat-result-head",children:[s.jsx("span",{className:"chat-result-icon",children:t}),s.jsx("span",{className:"chat-result-title",children:e.title}),s.jsx("span",{className:"chat-result-meta",children:e.verdict}),s.jsx(I0,{text:e.body,label:"result output"})]}),s.jsx("pre",{className:"chat-result-body",children:e.body})]})}function Ege({deploy:e}){return s.jsxs("div",{className:"chat-deploy-card",children:[s.jsxs("div",{className:"chat-deploy-head",children:[s.jsx("span",{className:"chat-deploy-icon",children:"🚀"}),s.jsx("span",{className:"chat-deploy-title",children:e.title||"Deployment"}),s.jsx(I0,{text:e.url,label:"deployment URL"})]}),s.jsx("a",{className:"chat-deploy-url",href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.url})]})}function Nge({children:e}){const t=E.useRef(null),n=r=>{if(!t.current)return;const i=Array.from(t.current.querySelectorAll("[data-artifact-card]"));if(i.length===0)return;const a=i.indexOf(document.activeElement);let o=-1;r.key==="ArrowDown"?o=a+1>=i.length?0:a+1:r.key==="ArrowUp"?o=a-1<0?i.length-1:a-1:r.key==="Home"?o=0:r.key==="End"&&(o=i.length-1),o>=0&&o!==a&&(r.preventDefault(),i[o].focus())};return s.jsx("div",{className:"chat-artifacts",ref:t,role:"group","aria-label":"Artifacts",onKeyDown:n,children:e})}function jge({task:e,onCancel:t}){const n=e.status==="running",r=e.logs.map(i=>BN(i.text)).join(`
|
|
204
204
|
`);return s.jsxs("div",{className:`chat-task-card${n?" chat-task-running":e.status==="done"?" chat-task-ok":" chat-task-err"}`,children:[s.jsxs("div",{className:"chat-task-head",children:[s.jsx("span",{className:"chat-task-icon",children:"⚙️"}),s.jsx("code",{className:"chat-task-cmd",children:e.command}),s.jsx("span",{className:"chat-task-status",title:e.status,children:kge[e.status]}),!n&&e.exitCode!==null?s.jsxs("span",{className:"chat-task-exit",children:["exit ",e.exitCode]}):null,!n&&e.durationMs!==null?s.jsxs("span",{className:"chat-task-dur",children:[e.durationMs,"ms"]}):null,r?s.jsx(I0,{text:r,label:"task output"}):null,n&&t?s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:t,children:"⏹ Cancel"}):null]}),s.jsx("pre",{className:"chat-task-logs",role:"log",children:e.logs.length>0?e.logs.map((i,a)=>{const o=e.logs[a-1],l=o&&o.stream!==i.stream,c=BN(i.text)||" ";return s.jsxs("div",{children:[l?s.jsx("div",{className:`chat-task-log-sep chat-task-log-sep-${i.stream}`,"aria-hidden":"true",children:i.stream}):null,s.jsx("div",{className:`chat-task-log chat-task-log-${i.stream}`,children:c})]},a)}):s.jsx("div",{className:"admin-hint",children:n?"Waiting for output…":"(no output)"})})]})}function FN({draft:e,onAccept:t,onReject:n,onEdit:r}){const i=e.status??"pending",a=e.markdown.split(`
|
|
205
205
|
`),o=a.findIndex(c=>c.startsWith("# "))>=0?a.findIndex(c=>c.startsWith("# ")):0,l=a.slice(o,o+14).join(`
|
|
206
|
-
`);return s.jsxs("div",{className:`chat-draft-card${i==="saved"?" chat-draft-saved":""}${i==="rejected"?" chat-draft-rejected":""}`,children:[s.jsxs("div",{className:"chat-draft-head",children:[s.jsx("span",{className:"chat-draft-icon",children:"🧠"}),s.jsxs("span",{className:"chat-draft-title",children:["New skill draft: ",e.name]}),s.jsx("span",{className:"chat-draft-meta",children:"pending your review"})]}),s.jsx("p",{className:"chat-draft-desc",children:e.description}),s.jsx("pre",{className:"chat-draft-body",children:l}),i==="saving"?s.jsx("div",{className:"admin-hint",children:"Saving…"}):i==="saved"?s.jsx("div",{className:"admin-hint",children:"✅ Saved — the skill is live: load it in chat or see it in the Agent Hub Skills tab."}):i==="rejected"?s.jsx("div",{className:"admin-hint",children:"🗑️ Rejected — the draft was discarded, nothing was saved."}):s.jsxs("div",{className:"chat-draft-actions",children:[s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>t(e.name),children:"✅ Accept"}),s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:()=>r(e.name),children:"✏️ Edit"}),s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:()=>n(e.name),children:"↩ Reject"})]})]})}function Age({request:e,onSave:t}){const[n,r]=E.useState({}),[i,a]=E.useState(!1),o=e.missing.every(u=>{var d;return(d=n[u])==null?void 0:d.trim()}),l=e.missing.filter(u=>e.persisted[u]),c=e.missing.filter(u=>!e.persisted[u]);return s.jsxs("div",{className:"chat-secret-card",children:[s.jsxs("div",{className:"chat-secret-head",children:[s.jsx("span",{className:"chat-secret-icon",children:"🔐"}),s.jsxs("span",{className:"chat-secret-title",children:[e.skillName," needs environment variables"]})]}),l.length>0?s.jsxs("div",{className:"chat-secret-persisted",children:["Already configured: ",l.map(u=>s.jsx("code",{children:u},u)).join(", ")]}):null,c.length>0&&!i?s.jsxs("div",{className:"chat-secret-fields",children:[c.map(u=>s.jsxs("div",{className:"chat-secret-row",children:[s.jsxs("label",{className:"chat-secret-label",htmlFor:`secret-${u}`,children:[u,":"]}),s.jsx("input",{id:`secret-${u}`,className:"chat-secret-input",type:"password",placeholder:`Enter ${u} value…`,value:n[u]??"",onChange:d=>r(f=>({...f,[u]:d.target.value}))})]},u)),s.jsx("button",{className:"admin-refresh-btn",type:"button",disabled:!o,onClick:()=>{t(n),a(!0)},children:"💾 Save to ~/.buff/.env"})]}):i?s.jsx("div",{className:"admin-hint",children:"✅ Saved — the skill will pick up these values on next load."}):s.jsx("div",{className:"admin-hint",children:"All required env vars are already configured."})]})}function Tge({result:e}){const[t,n]=E.useState(!1),r=e.success?"✅":"❌",i=e.success?"Success":`Failed (exit ${e.exitCode})`,a=e.success?"chat-exec-success":"chat-exec-failure",o=new Date(e.timestamp).toLocaleTimeString();return s.jsxs("div",{className:`chat-exec-card ${a}`,children:[s.jsxs("div",{className:"chat-exec-head",onClick:()=>n(!t),style:{cursor:"pointer"},children:[s.jsx("span",{className:"chat-exec-icon",children:"📜"}),s.jsx("span",{className:"chat-exec-title",children:e.skillName}),s.jsxs("span",{className:"chat-exec-status",children:[r," ",i]}),s.jsxs("span",{className:"chat-exec-meta",children:[e.runtime," · ",e.durationMs,"ms · ",o]}),s.jsx("span",{className:"chat-exec-expand",children:t?"▼":"▶"})]}),t&&s.jsxs("div",{className:"chat-exec-body",children:[e.stdout&&s.jsxs("div",{className:"chat-exec-section",children:[s.jsx("div",{className:"chat-exec-section-title",children:"stdout"}),s.jsx("pre",{className:"chat-exec-output",children:e.stdout})]}),e.stderr&&s.jsxs("div",{className:"chat-exec-section chat-exec-stderr",children:[s.jsx("div",{className:"chat-exec-section-title",children:"stderr"}),s.jsx("pre",{className:"chat-exec-output",children:e.stderr})]}),s.jsxs("div",{className:"chat-exec-details",children:[s.jsxs("span",{children:["Runtime: ",e.runtime]}),s.jsxs("span",{children:["Exit code: ",e.exitCode]}),s.jsxs("span",{children:["Duration: ",e.durationMs,"ms"]})]})]})]})}function Cge(e){return e==="done"?"✅":e==="running"?"🔄":e==="blocked"?"⛔":"⬜"}function UN({plan:e}){const t=e.steps.filter(n=>n.status==="done").length;return s.jsxs("div",{className:"chat-plan-card",children:[s.jsxs("div",{className:"chat-plan-head",children:[s.jsx("span",{className:"chat-plan-icon",children:"🗂️"}),s.jsx("span",{className:"chat-plan-goal",children:e.goal}),s.jsxs("span",{className:"chat-plan-count",children:[t,"/",e.steps.length," done"]})]}),s.jsx("div",{className:"chat-plan-steps",children:e.steps.map(n=>s.jsxs("div",{className:`chat-plan-step chat-plan-step-${n.status}`,children:[s.jsx("span",{className:"chat-plan-step-icon",children:Cge(n.status)}),s.jsx("span",{className:"chat-plan-step-text",children:n.description}),s.jsx("span",{className:"chat-plan-step-status",children:n.status})]},n.id))})]})}function WN({tools:e,live:t}){return!e||e.length===0?null:s.jsx("div",{className:`chat-tool-cards${t?" chat-tool-cards-live":""}`,children:e.map(n=>{const r=n.phase==="started"||n.ok===void 0,i=n.ok===!1;return s.jsxs("div",{className:`chat-tool-card${r?" chat-tool-running":i?" chat-tool-err":" chat-tool-ok"}`,children:[s.jsxs("div",{className:"chat-tool-head",children:[s.jsx("span",{className:"chat-tool-icon",children:Sge(n.tool)}),s.jsx("span",{className:"chat-tool-name",children:n.tool}),n.args?s.jsx("code",{className:"chat-tool-args",children:n.args}):null,s.jsx("span",{className:"chat-tool-status",title:r?"running":i?"failed":"done",children:r?"⏳":i?"✗":"✓"}),n.durationMs!==void 0&&!r?s.jsxs("span",{className:"chat-tool-dur",children:[n.durationMs,"ms"]}):null]}),n.error||n.result?s.jsxs("details",{className:"chat-tool-detail",children:[s.jsx("summary",{children:i?"Error":"Result"}),s.jsx("pre",{className:"chat-tool-body",children:n.error||n.result})]}):null]},n.id)})})}function wg(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`chat-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Oge(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(u=>`${u.title} ${u.preview} ${u.firstUser}`.toLowerCase().includes(n)):e,i=[],a=new Date,o=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),l=864e5,c=[{label:"Today",match:u=>u>=o},{label:"Yesterday",match:u=>u>=o-l&&u<o},{label:"This week",match:u=>u>=o-7*l&&u<o-l},{label:"Older",match:()=>!0}];for(const u of c){const d=r.filter(f=>u.match(f.updatedAt));d.length>0&&i.push({label:u.label,items:d})}return i}function HN(){var Pu,Mu,Ru,xa,Iu;const[e,t]=E.useState(null),[n,r]=E.useState([]),[i,a]=E.useState(""),[o,l]=E.useState(!1),[c,u]=E.useState(""),[d,f]=E.useState(null),[p,h]=E.useState([]),[g,m]=E.useState([]),[v,y]=E.useState(null),[b,x]=E.useState(null),[_,S]=E.useState(null),[w,k]=E.useState([]),[N,j]=E.useState([]),[C,I]=E.useState(null),M=E.useRef([]),$=E.useRef([]),R=E.useRef(null),B=E.useRef(null),L=E.useRef(null),[U,O]=E.useState(""),z=E.useRef(""),T=E.useRef(null),[V,q]=E.useState(null),P=E.useRef(wg()),ce=E.useRef(""),[me,ue]=E.useState([]),[He,Ce]=E.useState(!0),[te,ye]=E.useState(""),[be,X]=E.useState(null),[Ae,we]=E.useState(""),[Se,ge]=E.useState([]),[De,le]=E.useState(null),[Tt,Fe]=E.useState(!1),Te=E.useRef(null),lt=E.useRef(null),[Me,Zt]=E.useState(null),[Ht,F]=E.useState(null),[K,ae]=E.useState([]),[de,_e]=E.useState(""),[Xe,yt]=E.useState(""),[It,Dn]=E.useState(!1),[pt,Nt]=E.useState(""),[H,oe]=E.useState([]),[Re,Oe]=E.useState(null),[ga,Pr]=E.useState(!1),[mr,vo]=E.useState([]),[_u,An]=E.useState([]),[bo,_i]=E.useState(""),sl=E.useRef(null),tt=E.useRef(null),xo=E.useRef(null),Mr=E.useRef(null),[Gt,ya]=E.useState(null),[va,Eu]=E.useState(new Set);E.useEffect(()=>{ee.fetchAdminAuthStatus().then(D=>{t(D?{configured:D.configured,authenticated:D.authenticated,role:D.role}:{configured:!1,authenticated:!1,role:null})})},[]),E.useEffect(()=>{var D,Z;try{(Z=(D=xo.current)==null?void 0:D.scrollTo)==null||Z.call(D,{top:xo.current.scrollHeight})}catch{}},[n,o,p]),E.useEffect(()=>()=>{var D;(D=tt.current)==null||D.call(tt),tt.current=null},[]);const Bh=E.useCallback(async D=>{var ke,Zr;(ke=tt.current)==null||ke.call(tt),tt.current=null;const Z=await ee.getChatSession(D);if(!Z)return;P.current=D,r(Z.turns.map($t=>({role:$t.role,content:$t.content,...$t.role==="assistant"?{followups:[],artifacts:DN($t.content)}:{}}))),h([]),M.current=[],m([]),$.current=[],y(null),R.current=null,x(null),B.current=null,S(null),L.current=null,z.current="",O(""),q(null),u(""),f(null),I(null),ya(null),Ce(!0);const Q=Z.projectPath;if(Q){if(F(Q),(Me==null?void 0:Me.path)===Q)return;(Zr=Mr.current)==null||Zr.call(Mr,Q)}else F(null)},[Me]),ll=E.useCallback(()=>{var D;(D=tt.current)==null||D.call(tt),tt.current=null,P.current=wg(),F(null),r([]),h([]),M.current=[],m([]),$.current=[],y(null),R.current=null,x(null),B.current=null,S(null),L.current=null,z.current="",O(""),q(null),u(""),f(null),I(null),ya(null),ge([]),le(null),a(""),Ce(!0)},[]),wo=E.useCallback(D=>{ge(Z=>[...Z,D].slice(-10))},[]),cl=E.useCallback(D=>{ge(Z=>Z.filter((Q,ke)=>ke!==D))},[]),Nu=E.useCallback(async D=>{if(!D)return;if(D.size>zN){u(`Attachment "${D.name}" is too large (max ${Math.round(zN/1024)} KB).`);return}const Z=await D.text();wo({name:D.name,content:Z,kind:"file"})},[wo]),ju=E.useCallback(D=>{const Z=D.currentTarget,Q=D.clipboardData.getData("text")||"";Q.length>=wge&&(lt.current={start:Z.selectionStart,end:Z.selectionEnd},le({text:Q}))},[]),zh=E.useCallback(()=>{const D=De;if(!D)return;const Z=lt.current;a(Q=>Z?Q.slice(0,Z.start)+Q.slice(Z.end):Q),wo({name:"pasted-text.txt",content:D.text,kind:"paste"}),le(null),lt.current=null},[De,wo]),Fh=E.useCallback(D=>{X(D.id),we(D.title==="(untitled conversation)"?"":D.title)},[]),Au=E.useCallback(async D=>{const Z=await ee.renameChatSession(D,Ae);Z.ok?ue(Q=>Q.map(ke=>ke.id===D?{...ke,title:Ae.trim()||ke.title}:ke)):u(Z.error||"Could not rename the session."),X(null),we("")},[Ae]),ul=E.useCallback(async D=>{const Z=await ee.deleteChatSession(D);Z.ok?(ue(Q=>Q.filter(ke=>ke.id!==D)),P.current===D&&ll()):u(Z.error||"Could not delete the session.")},[ll]),So=(e==null?void 0:e.authenticated)===!0&&(e.role==="admin"||e.role==="operator");E.useEffect(()=>{So&&(ee.listChatSessions().then(D=>{Array.isArray(D)&&ue(D)}),ee.listProjects().then(D=>{Array.isArray(D)&&ae(D)}))},[So]);const Bn=E.useCallback(async D=>{const Z=D.trim();if(!Z)return;yt("");const Q=await ee.attachProject(Z);if(Q.ok&&Q.project){Zt(Q.project),_e("");const ke=await ee.listProjects();Array.isArray(ke)&&ae(ke)}else yt(Q.error||"Could not attach that directory.")},[]);Mr.current=Bn;const Qt=E.useCallback(async D=>{Dn(!0),Pr(!0),_i("");const Z=await ee.browseDirectories(D,{showDrives:!D});Z.ok&&(Nt(Z.path),oe(Z.entries),Oe(Z.parent),Z.drives&&vo(Z.drives),Z.breadcrumbs&&An(Z.breadcrumbs)),Pr(!1)},[]),ba=E.useCallback(async D=>{Pr(!0),_i("");const Z=await ee.browseDirectories(D);Z.ok&&(Nt(Z.path),oe(Z.entries),Oe(Z.parent),Z.breadcrumbs&&An(Z.breadcrumbs)),Pr(!1)},[]),Ei=E.useCallback(async()=>{if(!pt)return;const D=await ee.browseDirectories(pt);D.ok&&oe(D.entries)},[pt]);E.useEffect(()=>(It&&pt&&(sl.current=setInterval(()=>{Ei()},5e3)),()=>{sl.current&&clearInterval(sl.current)}),[It,pt,Ei]);const Tu=E.useCallback(async()=>{const D=window;if(typeof D.showDirectoryPicker=="function")try{const Q=(await D.showDirectoryPicker()).name;if(!Q){Qt();return}yt(""),l(!0);const ke=await ee.resolveFolder(Q);l(!1),ke.ok&&ke.path?Bn(ke.path):(yt((ke.error||"Could not find folder.")+" Opening manual browser..."),Qt());return}catch(Z){if(Z instanceof DOMException&&Z.name==="AbortError")return}Qt()},[Qt,Bn]),Ct=E.useCallback(async(D,Z)=>{var gr,Jn;const Q=D.trim(),ke=Array.isArray(Z)?Z:Se,Zr=!Array.isArray(Z)&&(Z==null?void 0:Z.skipResolve)===!0;if(!Q&&ke.length===0||o)return;if(u(""),f(null),h([]),M.current=[],m([]),$.current=[],y(null),R.current=null,x(null),B.current=null,S(null),L.current=null,r(xe=>[...xe,{role:"user",content:Q,attachments:ke.length>0?ke:void 0}]),a(""),ge([]),le(null),ce.current=Q||`[${ke.length} attachment(s)]`,l(!0),Ce(!1),!Zr){const at=((await ee.chatResolve(Q)).matches??[])[0]??null;if(at&&at.command&&!at.ambiguous&&at.score>=.6){I({ask:Q,top:at}),l(!1);return}if(at&&at.ambiguous&&!C){I({ask:Q,top:at}),l(!1);return}}const $t=P.current,zn=new AbortController;T.current=zn,q(null),(gr=tt.current)==null||gr.call(tt),tt.current=ee.subscribeChat($t,{onToken:xe=>{z.current+=xe,O(z.current)},onProgress:xe=>{M.current=[...M.current,xe],h(M.current)},onQuestion:xe=>{ya(xe),Eu(new Set)},onTool:xe=>{const Be=[...$.current],at=Be.findIndex(en=>en.id===xe.id),jt={id:xe.id,tool:xe.tool,phase:xe.phase,args:xe.args,ok:xe.ok,result:xe.result,error:xe.error,durationMs:xe.durationMs};at>=0?Be[at]=jt:Be.push(jt),$.current=Be,m(Be)},onPlan:xe=>{const Be={goal:xe.goal,steps:xe.steps,revision:xe.revision};R.current=Be,y(Be)},onDiff:xe=>{const Be={files:xe.files,summary:xe.summary};B.current=Be,x(Be)},onSkillDraft:xe=>{const Be={name:xe.name,description:xe.description,markdown:xe.markdown,updatedAt:xe.updatedAt,status:"pending"};L.current=Be,S(Be)},onSecretRequest:xe=>{k(Be=>{const at=Be.findIndex(jt=>jt.skillName===xe.skillName);if(at>=0){const jt=[...Be];return jt[at]=xe,jt}return[...Be,xe]})},onExecutionResult:xe=>{j(Be=>[...Be,xe])}});const xn=await ee.chatSend($t,Q||`(see ${ke.length} attachment${ke.length===1?"":"s"})`,{projectPath:Me==null?void 0:Me.path,attachments:ke.map(xe=>({name:xe.name,content:xe.content,kind:xe.kind}))},zn.signal);if(T.current=null,(Jn=tt.current)==null||Jn.call(tt),tt.current=null,z.current="",O(""),xn.ok){f(xn.generationFailed?null:`${xn.provider??"provider"}${xn.model?` / ${xn.model}`:" (auto-routed)"}`),q(xn.generationFailed?Q:null);const xe=xn.content||"(the agent produced no text — try rephrasing)";r(Be=>[...Be,{role:"assistant",content:xe,error:xn.generationFailed,followups:xn.followups,steps:M.current,tools:$.current,plan:R.current,diff:B.current,draft:L.current,artifacts:DN(xe)}])}else zn.signal.aborted?(u(""),q(null)):xn.unauthorized?(t(xe=>xe&&{...xe,authenticated:!1}),u("Session expired — log in again to chat.")):(u(xn.error||"The agent could not answer — check that a provider API key is set for the dashboard process."),q(Q));l(!1),Ce(!0)},[o,Me,Se]),Ni=E.useCallback(()=>{var D;(D=T.current)==null||D.abort()},[]),ko=E.useCallback(async D=>{S(Q=>Q&&{...Q,status:"saving"});const Z=await ee.skillDraftAccept(D);S(Q=>Q&&{...Q,status:Z.ok?"saved":"error"}),Z.ok||u(Z.error||"Could not accept the draft.")},[]),Xr=E.useCallback(async D=>{const Z=await ee.skillDraftReject(D);Z.ok?S(Q=>Q&&{...Q,status:"rejected"}):u(Z.error||"Could not reject the draft.")},[]),_o=E.useCallback(D=>{Ct(`Revise the skill draft "${D}" — improve it per your best judgment and present it again.`)},[Ct]),Eo=E.useCallback(async D=>{const Z=await ee.saveSecrets(D);Z.ok||u(Z.error||"Could not save secrets.")},[]),Cu=E.useCallback(async D=>{const ke=((await ee.chatResolve(D)).matches??[])[0]??null;if(!(ke!=null&&ke.command)){I(null);return}I(null),l(!0);const Zr=ke.command.split(/\s+/),$t=await ee.startTask(Zr,6e4);if(!$t.ok||!$t.task){u($t.error||"The command could not be started."),l(!1);return}const zn=$t.task.id,xn={id:zn,command:ke.command,status:$t.task.status,exitCode:$t.task.exitCode,durationMs:$t.task.durationMs,logs:$t.task.logs??[]};r(at=>[...at,{role:"assistant",content:"",task:xn}]);const gr=at=>r(jt=>jt.map(en=>en.task&&en.task.id===zn?{...en,task:{...en.task,...at}}:en));let Jn=null;Jn=ee.subscribeTask(zn,{onLog:at=>r(jt=>jt.map(en=>en.task&&en.task.id===zn?{...en,task:{...en.task,logs:[...en.task.logs,at]}}:en)),onStatus:at=>{gr({status:at}),at!=="running"&&(ee.getTask(zn).then(jt=>{jt!=null&&jt.task&&gr({exitCode:jt.task.exitCode,durationMs:jt.task.durationMs,logs:jt.task.logs??[]})}),Jn==null||Jn(),l(!1))}});const xe=await ee.getTask(zn);xe!=null&&xe.task&&gr({status:xe.task.status,exitCode:xe.task.exitCode,durationMs:xe.task.durationMs,logs:xe.task.logs??[]});const Be=await ee.getTask(zn);Be!=null&&Be.task&&Be.task.status!=="running"&&(Jn==null||Jn(),gr({status:Be.task.status,exitCode:Be.task.exitCode,durationMs:Be.task.durationMs,logs:Be.task.logs??[]}),l(!1))},[]),ji=E.useCallback(D=>{I(null),Ct(D,{skipResolve:!0})},[Ct]),Ou=E.useCallback(D=>{if(D.length===0)return;const Z=Me?` in the attached project ${Me.path}`:"";Ct(`Commit exactly these files that I accepted on the diff card (and nothing else)${Z}: ${D.join(", ")}. Show me a short confirmation before finishing.`)},[Ct,Me]),Uh=E.useCallback(async D=>{await ee.cancelTask(D)},[]),bn=E.useCallback(async D=>{const Z=Gt;if(!Z)return;ya(null);const Q=await ee.chatRespond(P.current,Z.questionId,D);Q.ok||u(Q.error||"The question could not be answered — try sending your message again.")},[Gt]),Jt=E.useCallback(()=>{if(!Gt)return;const D=Gt.multiSelect?[...va]:[...va][0];Gt.multiSelect?bn({index:[...va]}):bn(D!==void 0?{index:D}:{index:-1})},[Gt,va,bn]),Wh=E.useCallback(()=>{Gt&&bn({index:-1})},[Gt,bn]),Hh=E.useCallback(D=>{Eu(Z=>{const Q=new Set(Z);return Gt!=null&&Gt.multiSelect?Q.has(D)?Q.delete(D):Q.add(D):(Q.clear(),Q.add(D)),Q})},[Gt]),Gh=E.useCallback(async()=>{var Z;(Z=tt.current)==null||Z.call(tt),tt.current=null,P.current=wg(),r([]),h([]),M.current=[],m([]),$.current=[],y(null),R.current=null,x(null),B.current=null,S(null),L.current=null,z.current="",O(""),q(null),u(""),f(null),I(null),ya(null);const D=await ee.listChatSessions();Array.isArray(D)&&ue(D)},[]),Ai=((Pu=[...n].reverse().find(D=>{var Z;return D.role==="assistant"&&!D.error&&(((Z=D.followups)==null?void 0:Z.length)??0)>0}))==null?void 0:Pu.followups)??[];return s.jsxs("div",{className:"panel",children:[s.jsxs("div",{className:"panel-header",children:[s.jsx("h2",{children:"💬 Chat with the agent"}),s.jsxs("div",{className:"chat-head-actions",children:[d?s.jsx("span",{className:"admin-hint",children:d}):null,s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void Gh(),disabled:o||n.length===0,children:"🗑 New conversation"})]})]}),e!=null&&e.authenticated?So?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"chat-project-bar",children:Me?s.jsxs("div",{className:"chat-project-attached",children:[s.jsx("span",{className:"chat-project-icon",children:"📁"}),s.jsx("span",{className:"chat-project-name",children:Me.name}),s.jsxs("span",{className:"chat-project-meta",children:[Me.fileCount," files · ",Me.symbolCount," symbols",Me.truncated?" · truncated map":""]}),s.jsx("span",{className:"chat-project-path",title:Me.path,children:Me.path}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>Zt(null),children:"✕ detach"})]}):s.jsxs("div",{className:"chat-project-pick",children:[s.jsx("span",{className:"chat-project-icon",children:"📁"}),s.jsx("span",{className:"chat-project-hint",children:"Select Project Folder"}),K.length>0?s.jsx("span",{className:"chat-project-chips",children:K.filter(D=>D.kind!=="cwd").slice(0,3).map(D=>s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Bn(D.path),children:D.name},D.path))}):null,s.jsx("input",{className:"chat-project-input",value:de,onChange:D=>_e(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.preventDefault(),Bn(de))},placeholder:"or type a path, e.g. ~/code/my-app",disabled:o}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void Bn(de),disabled:o||!de.trim(),children:"Attach"}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>void Tu(),title:"Open system folder picker",children:"🗂️ Browse"}),Xe?s.jsx("span",{className:"chat-project-error",children:Xe}):null,It?s.jsxs("div",{className:"chat-browse-popover",children:[s.jsxs("div",{className:"chat-browse-head",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>Dn(!1),title:"Close",children:"✕"}),s.jsx("div",{className:"chat-browse-breadcrumbs",children:mr.length>0&&!pt?s.jsx("span",{className:"admin-hint",children:"Select a drive or home folder:"}):s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",className:"chat-breadcrumb",onClick:()=>void Qt(),children:"🏠"}),_u.map((D,Z)=>s.jsxs("span",{children:[s.jsx("span",{className:"chat-breadcrumb-sep",children:"/"}),s.jsx("button",{type:"button",className:"chat-breadcrumb",onClick:()=>void ba(D.path),children:D.name})]},D.path))]})})]}),mr.length>0&&!pt?s.jsx("div",{className:"chat-browse-drives",children:mr.map(D=>s.jsx("button",{type:"button",className:"chat-browse-drive",onClick:()=>void ba(D.path),children:D.name},D.path))}):null,H.length>5?s.jsx("div",{className:"chat-browse-search",children:s.jsx("input",{type:"text",className:"chat-browse-filter",placeholder:"🔍 Filter folders…",value:bo,onChange:D=>_i(D.target.value),autoFocus:!0})}):null,s.jsx("div",{className:"chat-browse-list",children:ga?s.jsx("span",{className:"admin-hint",children:"Loading…"}):H.length===0?s.jsx("span",{className:"admin-hint",children:"No subdirectories found"}):H.filter(D=>!bo||D.name.toLowerCase().includes(bo.toLowerCase())).map(D=>s.jsxs("button",{type:"button",className:"chat-browse-entry",onClick:()=>void ba(D.path),children:[s.jsx("span",{className:"chat-browse-entry-icon",children:"📁"}),s.jsx("span",{className:"chat-browse-entry-name",children:D.name}),D.modified?s.jsx("span",{className:"chat-browse-entry-date",children:new Date(D.modified).toLocaleDateString()}):null]},D.path))}),s.jsxs("div",{className:"chat-browse-foot",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>void Ei(),title:"Refresh folder list",children:"🔄"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>{Dn(!1),Bn(pt)},disabled:!pt,children:"📁 Select this folder"})]})]}):null]})}),Ht&&(!Me||Me.path!==Ht)?s.jsxs("div",{className:"chat-session-project-banner",children:[s.jsxs("span",{children:["⚠️ This conversation was working in ",s.jsx("code",{children:Ht})]}),Me?s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void Bn(Ht),children:"📁 Switch to it"}):s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void Bn(Ht),children:"📁 Attach it"})]}):null,s.jsxs("div",{className:"chat-layout",children:[He?s.jsxs("div",{className:"chat-sidebar",children:[s.jsxs("div",{className:"chat-sidebar-head",children:[s.jsx("span",{children:"📁 Sessions"}),s.jsxs("div",{className:"chat-sidebar-head-actions",children:[s.jsx("button",{type:"button",className:"chat-mini-action",title:"New chat",onClick:ll,children:"+ New"}),s.jsx("button",{type:"button",className:"chat-mini-action",title:"Collapse history",onClick:()=>Ce(!1),children:"▸"})]})]}),s.jsx("input",{className:"chat-session-search",placeholder:"Search conversations…",value:te,onChange:D=>ye(D.target.value)}),me.length===0?s.jsx("div",{className:"chat-sidebar-empty",children:"No past conversations yet."}):s.jsx("div",{className:"chat-sidebar-list",children:Oge(me,te).map(({label:D,items:Z})=>s.jsxs("div",{className:"chat-session-group",children:[s.jsx("div",{className:"chat-session-group-label",children:D}),Z.map(Q=>s.jsx("div",{className:`chat-session-item${Q.id===P.current?" chat-session-active":""}`,children:be===Q.id?s.jsxs("div",{className:"chat-session-rename",children:[s.jsx("input",{autoFocus:!0,value:Ae,onChange:ke=>we(ke.target.value),onKeyDown:ke=>{ke.key==="Enter"&&Au(Q.id),ke.key==="Escape"&&X(null)},placeholder:"Session title"}),s.jsx("button",{type:"button",className:"chat-mini-action",onClick:()=>void Au(Q.id),children:"✓"})]}):s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",className:"chat-session-main",onClick:()=>void Bh(Q.id),title:Q.preview||Q.title,children:[s.jsx("span",{className:"chat-session-title",children:Q.title}),s.jsx("span",{className:"chat-session-preview",children:Q.firstUser||Q.preview}),s.jsxs("span",{className:"chat-session-meta",children:[Q.projectPath?`📁 ${Q.projectPath.split("/").pop()} · `:"",Q.turnCount," msg",Q.turnCount===1?"":"s"," · ",new Date(Q.updatedAt).toLocaleString()]})]}),s.jsxs("span",{className:"chat-session-actions",children:[s.jsx("button",{type:"button",className:"chat-mini-action",title:"Rename",onClick:()=>Fh(Q),children:"✏️"}),s.jsx("button",{type:"button",className:"chat-mini-action",title:"Delete",onClick:()=>void ul(Q.id),children:"🗑"})]})]})},Q.id))]},D))})]}):s.jsx("div",{className:"chat-rail",children:s.jsx("button",{type:"button",className:"chat-rail-btn",onClick:()=>Ce(!0),title:"Show history",children:"📁"})}),s.jsxs("div",{className:"chat-main",children:[s.jsxs("div",{className:"chat-thread",ref:xo,role:"log","aria-live":"polite",children:[n.length===0?s.jsxs("div",{className:"empty-state",children:[s.jsx("p",{className:"empty-state-title",children:"Say anything — the agent decides what to do (answer, fix code, plan, run the pipeline)."}),s.jsxs("div",{className:"empty-state-chips",children:[s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("what's the state of this project?"),children:"📋 assess this project"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("run the test suite"),children:"🧪 run the tests"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("stop the gateway"),children:"⏹ stop the gateway"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("load the code-assessment skill and assess this project"),children:"🧠 load the code-assessment skill"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("learn the workflow I just did as a skill"),children:"📚 learn a workflow as a skill"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("publish the current version"),children:"🚀 publish the release"})]})]}):n.map((D,Z)=>s.jsxs("div",{className:`chat-bubble chat-${D.role}${D.error?" chat-error":""}`,children:[s.jsx("div",{className:"chat-bubble-role",children:D.role==="user"?"You":"🤖 Agent"}),D.role==="assistant"?s.jsx("div",{className:"chat-bubble-text",children:s.jsx(RN,{text:D.content})}):s.jsx("div",{className:"chat-bubble-text",children:D.content}),D.role==="user"&&D.attachments&&D.attachments.length>0?s.jsxs("details",{className:"chat-steps",open:D.attachments.length===1,children:[s.jsxs("summary",{children:["📎 ",D.attachments.length," attachment",D.attachments.length===1?"":"s",":"," ",D.attachments.map(Q=>Q.name).join(", ")]}),D.attachments.map((Q,ke)=>s.jsxs("div",{className:"chat-attach-content",children:[s.jsxs("div",{className:"admin-hint",children:[Q.name," — ",Q.content.length.toLocaleString()," chars"]}),s.jsx("pre",{children:Q.content})]},ke))]}):null,D.role==="assistant"&&D.diff?s.jsxs("details",{className:"chat-steps",open:!0,children:[s.jsxs("summary",{children:["Changes: ",D.diff.summary]}),s.jsx(jd,{diff:D.diff,selectable:!0,onCommitAccepted:Ou})]}):null,D.role==="assistant"&&D.artifacts&&(D.artifacts.diffs.length>0||D.artifacts.results.length>0||D.artifacts.deploys.length>0)?s.jsxs(Nge,{children:[D.artifacts.diffs.map((Q,ke)=>s.jsx("div",{"data-artifact-card":!0,tabIndex:0,role:"group","aria-label":`Diff: ${Q.summary}`,className:"chat-artifact-item",children:Me?s.jsx(jd,{diff:Q,selectable:!0,onCommitAccepted:Ou}):s.jsx(jd,{diff:Q,lockedHint:"Attach a project to review and commit these changes."})},`diff-${ke}`)),D.artifacts.results.map((Q,ke)=>s.jsx("div",{"data-artifact-card":!0,tabIndex:0,role:"group","aria-label":`Result: ${Q.title}`,className:"chat-artifact-item",children:s.jsx(_ge,{result:Q})},`result-${ke}`)),D.artifacts.deploys.map((Q,ke)=>s.jsx("div",{"data-artifact-card":!0,tabIndex:0,role:"group","aria-label":`Deployment: ${Q.url}`,className:"chat-artifact-item",children:s.jsx(Ege,{deploy:Q})},`deploy-${ke}`))]}):null,D.role==="assistant"&&D.task?s.jsx(jge,{task:D.task,onCancel:D.task.status==="running"?()=>void Uh(D.task.id):void 0}):null,D.role==="assistant"&&D.draft?s.jsxs("details",{className:"chat-steps",open:!0,children:[s.jsxs("summary",{children:["Skill draft: ",D.draft.name]}),s.jsx(FN,{draft:D.draft,onAccept:ko,onReject:Xr,onEdit:_o})]}):null,D.role==="assistant"&&D.plan?s.jsxs("details",{className:"chat-steps",open:!0,children:[s.jsxs("summary",{children:["Plan: ",D.plan.goal]}),s.jsx(UN,{plan:D.plan})]}):null,D.role==="assistant"&&D.tools&&D.tools.length>0?s.jsxs("details",{className:"chat-steps",open:!0,children:[s.jsxs("summary",{children:[D.tools.length," tool call",D.tools.length===1?"":"s"]}),s.jsx(WN,{tools:D.tools})]}):null,D.role==="assistant"&&D.steps&&D.steps.length>0?s.jsxs("details",{className:"chat-steps",children:[s.jsxs("summary",{children:[D.steps.length," step",D.steps.length===1?"":"s"]}),s.jsx("div",{className:"chat-step-line",children:D.steps.map((Q,ke)=>s.jsx("div",{children:Q.trim()},ke))})]}):null]},Z)),o?s.jsxs("div",{className:"chat-bubble chat-assistant",children:[s.jsx("div",{className:"chat-bubble-role",children:"🤖 Agent"}),v?s.jsx(UN,{plan:v}):null,b?s.jsx(jd,{diff:b}):null,_?s.jsx(FN,{draft:_,onAccept:ko,onReject:Xr,onEdit:_o}):null,w.map(D=>s.jsx(Age,{request:D,onSave:Eo},D.skillName)),N.map((D,Z)=>s.jsx(Tge,{result:D},`${D.skillName}-${Z}`)),s.jsx(WN,{tools:g,live:!0}),U?s.jsx("div",{className:"chat-bubble-text chat-streaming",children:s.jsx(RN,{text:U})}):null,s.jsx("div",{className:"chat-working",children:p.length>0?s.jsx("span",{className:"chat-working-lines",children:p.map((D,Z)=>s.jsx("div",{className:"chat-step-line",children:D.trim()},Z))}):s.jsxs(s.Fragment,{children:["💭 thinking… ",s.jsx("span",{className:"chat-dots"})]})})]}):null]}),c?s.jsx("div",{className:"admin-row-msg admin-row-msg-err",children:c}):null,V&&!o?s.jsxs("div",{className:"chat-retry-row",children:[s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void Ct(V),children:"↻ Retry"}),s.jsx("span",{className:"admin-hint",children:"Re-send the last message — the turn failed."})]}):null,C&&!o?s.jsx("div",{className:"chat-resolve-card",children:(Mu=C.top)!=null&&Mu.ambiguous&&((Ru=C.top.options)!=null&&Ru.length)?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"chat-resolve-head",children:[s.jsx("strong",{children:"🤔 Which do you mean?"}),' — "',C.ask,'" maps to more than one action.']}),s.jsx("div",{className:"chat-resolve-options",children:C.top.options.map(D=>s.jsxs("button",{className:"chat-chip",type:"button",onClick:()=>void Ct(D.command),children:[D.summary," — ",s.jsx("code",{children:D.command})]},D.command))}),s.jsx("div",{className:"chat-resolve-foot",children:s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:()=>{I(null)},children:"✕ Not that — ask the agent"})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"chat-resolve-head",children:[s.jsx("strong",{children:"⚡ Run this command?"}),' — "',C.ask,'"']}),s.jsx("div",{className:"chat-resolve-cmd",children:s.jsx("code",{children:(xa=C.top)==null?void 0:xa.command})}),(Iu=C.top)!=null&&Iu.confirmation?s.jsx("div",{className:"admin-hint",children:"⚠ This changes running services/state."}):null,s.jsxs("div",{className:"chat-resolve-foot",children:[s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void Cu(C.ask),children:"▶ Run"}),s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:()=>ji(C.ask),children:"✕ No — ask the agent"})]})]})}):null,Gt?s.jsxs("div",{className:"chat-resolve-card chat-question-card",children:[s.jsx("div",{className:"chat-resolve-head",children:s.jsxs("strong",{children:["🤔 ",Gt.question]})}),s.jsx("div",{className:"chat-resolve-options",children:Gt.choices.map((D,Z)=>s.jsxs("button",{type:"button",className:`chat-chip${va.has(Z)?" chat-chip-selected":""}`,onClick:()=>Hh(Z),children:[D.label,D.description?s.jsxs("span",{className:"admin-hint",children:[" — ",D.description]}):null]},`${D.label}-${Z}`))}),s.jsxs("div",{className:"chat-resolve-foot",children:[s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:Jt,children:Gt.multiSelect?"Submit":"Choose"}),s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:Wh,children:"Skip — best judgment"})]})]}):null,Ai.length>0&&!o?s.jsxs("div",{className:"chat-followups",children:[s.jsx("span",{className:"admin-hint",children:"Next steps:"}),Ai.map((D,Z)=>s.jsx("button",{className:"chat-chip",type:"button",onClick:()=>void Ct(D.prompt),children:D.label||D.prompt},Z))]}):null,s.jsxs("form",{className:`chat-composer${Tt?" chat-composer-drag":""}`,onSubmit:D=>{D.preventDefault(),Ct(i)},onDragOver:D=>{D.preventDefault(),Fe(!0)},onDragLeave:()=>Fe(!1),onDrop:D=>{var Q;D.preventDefault(),Fe(!1);const Z=Array.from(((Q=D.dataTransfer)==null?void 0:Q.files)??[]);for(const ke of Z.slice(0,10))Nu(ke)},children:[De?s.jsxs("div",{className:"chat-paste-offer",children:[s.jsxs("span",{className:"admin-hint",children:["📄 You pasted ",De.text.length.toLocaleString()," characters. Attach it as a file instead?"]}),s.jsx("button",{type:"button",className:"chat-chip",onClick:zh,children:"Attach as text"}),s.jsx("button",{type:"button",className:"chat-mini-action",onClick:()=>{le(null),lt.current=null},children:"Keep inline"})]}):null,Se.length>0?s.jsx("div",{className:"chat-attach-row",children:Se.map((D,Z)=>s.jsxs("span",{className:"chat-attach-chip",title:`${D.name} (${D.content.length.toLocaleString()} chars)`,children:["📎 ",D.name,s.jsxs("span",{className:"admin-hint",children:[" ",D.content.length.toLocaleString(),"c"]}),s.jsx("button",{type:"button",className:"chat-mini-action",onClick:()=>cl(Z),children:"✕"})]},`${D.name}-${Z}`))}):null,s.jsxs("div",{className:"chat-input-row",children:[s.jsx("input",{ref:Te,type:"file",style:{display:"none"},onChange:D=>{var Q;const Z=(Q=D.target.files)==null?void 0:Q[0];Z&&Nu(Z),D.target.value=""}}),s.jsx("button",{type:"button",className:"chat-attach-btn",title:"Attach a file (up to 300 KB, text only)",disabled:o||Se.length>=10,onClick:()=>{var D;return(D=Te.current)==null?void 0:D.click()},children:"📎"}),s.jsx("textarea",{className:"chat-input-box",value:i,onChange:D=>a(D.target.value),onPaste:ju,onKeyDown:D=>{D.key==="Enter"&&!D.shiftKey?(D.preventDefault(),Ct(i)):D.key==="ArrowUp"&&i===""&&ce.current&&(D.preventDefault(),a(ce.current))},placeholder:"Message the agent… (Enter to send · Shift+Enter for a new line · ↑ recalls last · 📎 attach a file or paste a large document)",disabled:o,maxLength:8e3,rows:1,autoFocus:!0}),o?s.jsx("button",{className:"admin-mini-btn chat-cancel-btn",type:"button",onClick:Ni,children:"⏹ Cancel"}):null,s.jsx("button",{className:"admin-refresh-btn",type:"submit",disabled:o||!i.trim()&&Se.length===0,children:o?"⏳ Working…":"➤ Send"})]})]}),s.jsxs("p",{className:"admin-hint",children:["Each message runs the full agent loop in the dashboard process (same engine as"," ",s.jsx("code",{children:'buff chat "<prompt>"'}),") — the provider API keys must be configured in the dashboard process. Clarifications (",s.jsx("code",{children:"ask_user"}),") appear as a question card here — choose an answer or skip (best judgment)."]})]})]})]}):s.jsx("div",{className:"admin-login-hint",children:s.jsx("p",{children:"Your role can view the dashboard but not chat (requires admin or operator)."})}):s.jsxs("div",{className:"admin-login-hint",children:[s.jsx("p",{children:"Log in (admin or operator) to chat with the agent. Configure the dashboard admin credential first if this is a fresh setup."}),(e==null?void 0:e.configured)===!1?s.jsxs("p",{className:"admin-hint",children:["Run ",s.jsx("code",{children:"buff dashboard"})," once, or set ",s.jsx("code",{children:"BUFF_DASHBOARD_ADMIN_USER"})," / ",s.jsx("code",{children:"BUFF_DASHBOARD_ADMIN_PASSWORD"}),"."]}):null]})]})}const Pge={running:"⏳ running",done:"✅ done",failed:"❌ failed",cancelled:"⏹ cancelled",timeout:"⏰ timed out",error:"💥 error"};function ZR({presets:e,customPlaceholder:t,timeoutMs:n=3e5,hint:r}){const[i,a]=E.useState(null),[o,l]=E.useState(!1),[c,u]=E.useState(""),[d,f]=E.useState(""),[p,h]=E.useState(null),[g,m]=E.useState([]),v=E.useRef(null),y=E.useRef(null);E.useEffect(()=>{ee.fetchAdminAuthStatus().then(S=>{a(S?{authenticated:S.authenticated,role:S.role}:{authenticated:!1,role:null})})},[]),E.useEffect(()=>{var S,w;try{(w=(S=v.current)==null?void 0:S.scrollIntoView)==null||w.call(S,{block:"end"})}catch{}},[g]),E.useEffect(()=>()=>{var S;(S=y.current)==null||S.call(y)},[]);const b=(i==null?void 0:i.authenticated)===!0&&(i.role==="admin"||i.role==="operator"),x=E.useCallback(async(S,w)=>{var C;if(o)return;l(!0),u(""),m([]);const k=await ee.startTask(S,w??n);if(!k.ok||!k.task){u(k.error||"Could not start the command."),l(!1);return}const N=k.task;h(N);const j=await ee.getTask(N.id);j!=null&&j.task&&m(j.task.logs.map(I=>({stream:I.stream,text:I.text}))),(C=y.current)==null||C.call(y),y.current=ee.subscribeTask(N.id,{onLog:I=>m(M=>[...M,{stream:I.stream,text:I.text}]),onStatus:I=>{h(M=>M&&{...M,status:I}),I!=="running"&&l(!1)}})},[o,n]),_=E.useCallback(async()=>{p&&await ee.cancelTask(p.id)},[p]);return s.jsxs("div",{className:"ops-console",children:[i!=null&&i.authenticated?b?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ops-presets",children:e.map(S=>s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void x(S.args,S.timeoutMs),disabled:o,children:S.label},S.label))}),s.jsxs("div",{className:"ops-custom-row",children:[s.jsx("input",{type:"text",value:d,onChange:S=>f(S.target.value),placeholder:t,disabled:o,maxLength:160}),s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void x(d.trim().split(/\s+/)),disabled:o||!d.trim(),children:"Run"})]}),r?s.jsx("p",{className:"admin-hint",children:r}):null]}):s.jsx("div",{className:"admin-login-hint",children:"Your role can view but not run commands (requires admin or operator)."}):s.jsx("div",{className:"admin-login-hint",children:"Log in (admin or operator) to run commands."}),c?s.jsx("div",{className:"admin-row-msg admin-row-msg-err",children:c}):null,p?s.jsxs("div",{className:"ops-console-box",children:[s.jsxs("div",{className:"ops-console-head",children:[s.jsxs("span",{children:[p.command," · ",s.jsx("span",{className:p.status==="running"?"task-status-running":"",children:Pge[p.status]})]}),p.status==="running"?s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void _(),children:"⏹ Cancel"}):null]}),s.jsxs("pre",{className:"ops-console",role:"log",children:[g.length>0?g.map((S,w)=>s.jsx("div",{children:S.text},w)):s.jsx("div",{className:"admin-hint",children:"Waiting for output…"}),s.jsx("div",{ref:v})]})]}):null]})}const Mge=[{label:"⚡ Quick smoke",args:["eval","run","--tasks","quick","--format","text"]},{label:"⏱ Medium suite",args:["eval","run","--tasks","medium","--format","text"]},{label:"🐢 Slow suite",args:["eval","run","--tasks","slow","--format","text"]},{label:"🏆 M2B parity",args:["eval","run","--suite","m2b","--format","text"]},{label:"📦 Full suite",args:["eval","run","--suite","full","--format","text"]}];function GN(e){return typeof e!="number"?"—":`${Math.round(e*100)}%`}function Rge(e){return new Date(e).toLocaleString()}function Ige({data:e}){var n;const t=((n=e==null?void 0:e.evals)==null?void 0:n.runs)??[];return s.jsxs("div",{className:"panel",children:[s.jsx("div",{className:"panel-header",children:s.jsx("h2",{children:"🏆 Evals — run buff eval from the GUI"})}),s.jsx(ZR,{presets:Mge,customPlaceholder:"e.g. eval run --tasks my-task --provider groq --model llama",timeoutMs:9e5,hint:s.jsxs(s.Fragment,{children:["Runs the real ",s.jsx("code",{children:"buff eval run"})," as an isolated process — same engine, same ledger, same results as the CLI. Long suites can take minutes; you can cancel mid-run."]})}),s.jsx("h3",{className:"section-subtitle",children:"📜 Past runs (auto-refreshes)"}),t.length>0?s.jsx("div",{className:"admin-table-wrapper",children:s.jsxs("table",{className:"admin-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Started"}),s.jsx("th",{children:"Provider"}),s.jsx("th",{children:"Model"}),s.jsx("th",{children:"Tasks"}),s.jsx("th",{children:"Pass"}),s.jsx("th",{children:"Completion"}),s.jsx("th",{children:"Composite"}),s.jsx("th",{children:"Cost"})]})}),s.jsx("tbody",{children:t.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:Rge(r.startedAt)}),s.jsx("td",{className:"admin-provider-type",children:r.provider}),s.jsx("td",{children:r.model}),s.jsx("td",{children:r.summary.totalTasks}),s.jsxs("td",{children:[r.summary.tasksPassed,"/",r.summary.totalTasks]}),s.jsx("td",{children:GN(r.summary.completionRate)}),s.jsx("td",{children:GN(r.summary.avgCompositeScore)}),s.jsxs("td",{children:["$",(r.summary.totalCostUsd??0).toFixed(4)]})]},r.id))})]})}):s.jsx("div",{className:"empty-state",children:"No eval runs yet — start one above (or `buff eval run` from the CLI)."})]})}const $ge=[{label:"🌐 Gateway status",args:["gateway","status"]},{label:"📮 Delivery ledger",args:["gateway","delivery"]},{label:"▶️ Start gateway (foreground)",args:["gateway","start","--no-events"],timeoutMs:0},{label:"⏰ Cron jobs",args:["admin","cron","list"]}];function Lge(){return s.jsxs("div",{className:"panel",children:[s.jsx("div",{className:"panel-header",children:s.jsx("h2",{children:"🌐 Gateway ops — run buff gateway from the GUI"})}),s.jsx(ZR,{presets:$ge,customPlaceholder:"e.g. admin cron run nightly or gateway alias add ops email:team@example.com",timeoutMs:3e5,hint:s.jsxs(s.Fragment,{children:["Each command runs as the real CLI in an isolated process (the P1 task runner) — the same engine as your terminal. ",s.jsx("code",{children:"gateway start"})," runs in the foreground ",s.jsx("strong",{children:"with no timeout"}),": it keeps running even after you switch tabs (the process lives on the dashboard server, not the page) and streams platform events until you press ",s.jsx("strong",{children:"Cancel"}),". The delivery ledger also has its own view in"," ",s.jsx("strong",{children:"Agent Hub → Channels"}),"."]})})]})}const Sg={telegram:{icon:"✈️",category:"Chat",steps:["Open Telegram and search for @BotFather","Send /newbot and follow the prompts",'Give your bot a name (e.g. "My Agent Bot")','Give your bot a username ending in "bot"',"BotFather gives you a token — paste it in Step 2","Open your bot in Telegram and send /start"],testTarget:"telegram:"},discord:{icon:"🎮",category:"Chat",steps:["Go to discord.com/developers/applications",'Click "New Application" and give it a name','Go to Bot tab and click "Add Bot"',"Copy the bot token",'Enable "Message Content Intent"',"Invite bot to your server (OAuth2 URL generator)"],testTarget:"discord:"},slack:{icon:"💬",category:"Chat",steps:["Go to api.slack.com/apps","Create New App from scratch","Add Bot Token Scopes: chat:write, im:read, im:write","Install to workspace","Copy the Bot User OAuth Token (xoxb-...)"],testTarget:"slack:"},whatsapp:{icon:"📱",category:"Chat",steps:["Run: buff whatsapp pair (or from Gateway tab)","Scan the QR code with WhatsApp","Pairing completes automatically"],testTarget:""},whatsapp_cloud:{icon:"☁️",category:"Chat",steps:["Go to developers.facebook.com","Set up WhatsApp Cloud API","Copy token + Phone ID"],testTarget:"whatsapp_cloud:"},email:{icon:"📧",category:"Chat",steps:["Get SMTP credentials (Gmail, SendGrid, etc.)","For Gmail: use App Password at smtp.gmail.com:587","Paste SMTP host + user below"],testTarget:""},signal:{icon:"🔒",category:"Chat",steps:["Run signal-cli-rest-api Docker container","Register a Signal account","Paste account number below"],testTarget:""},dingtalk:{icon:"🔔",category:"Webhooks",steps:["Open DingTalk and create a group","Add custom robot and copy webhook URL","Paste URL below"],testTarget:""},feishu:{icon:"🐦",category:"Webhooks",steps:["Open Feishu and create a bot","Copy webhook URL and paste below"],testTarget:""},wecom:{icon:"🏢",category:"Webhooks",steps:["Open WeCom and create a group bot","Copy webhook URL and paste below"],testTarget:""},mattermost:{icon:"📋",category:"Webhooks",steps:["Open Mattermost, go to Integrations","Create incoming webhook and copy URL"],testTarget:""},matrix:{icon:"🔗",category:"Chat",steps:["Get your Matrix homeserver URL","Create a bot user and get access token","Paste URL + token below"],testTarget:""},webhook:{icon:"🪝",category:"Webhooks",steps:["Enter your webhook URL","The agent sends outbound webhooks to this URL"],testTarget:""},bluebubbles:{icon:"💙",category:"Chat",steps:["Set up BlueBubbles server","Copy server URL + password"],testTarget:""},ntfy:{icon:"📢",category:"Notifications",steps:["Choose an ntfy topic (or use ntfy.sh)","Paste the topic below"],testTarget:""},teams:{icon:"👥",category:"Webhooks",steps:["Open Microsoft Teams, go to channel","Connectors, Incoming Webhook, create","Copy webhook URL"],testTarget:""},google_chat:{icon:"💬",category:"Webhooks",steps:["Open Google Chat, space settings","Create webhook and copy URL"],testTarget:""},weixin:{icon:"🔴",category:"Chat",steps:["Get Weixin iLink bot token","Paste token below"],testTarget:""},sms:{icon:"📲",category:"Chat",steps:["Get Twilio account SID + auth token","Register a phone number","Paste credentials below"],testTarget:""},irc:{icon:"💻",category:"Chat",steps:["Choose an IRC server (e.g. irc.libera.chat)","Set nickname + channel and paste below"],testTarget:""},simplex:{icon:"📨",category:"Chat",steps:["Run local simplex-chat daemon","Paste WebSocket URL (ws://127.0.0.1:5225)"],testTarget:""},homeassistant:{icon:"🏠",category:"IoT",steps:["Open Home Assistant Profile","Create long-lived access token and paste below"],testTarget:""}};function Dge(){const[e,t]=E.useState(null),[n,r]=E.useState("all"),[i,a]=E.useState(null),[o,l]=E.useState(0),[c,u]=E.useState({}),[d,f]=E.useState(!1),[p,h]=E.useState(null),[g,m]=E.useState({status:"idle"}),[v,y]=E.useState(""),[b,x]=E.useState("Hello from agent-nuvira!"),[_,S]=E.useState(!1),[w,k]=E.useState(null),N=E.useRef(!0),j=E.useCallback(async()=>{const O=await ee.getPlatformConfigs();N.current&&t(O)},[]);E.useEffect(()=>(j(),()=>{N.current=!1}),[j]);const C=O=>{a(O),l(0),u(Object.fromEntries(O.envVars.map(T=>[T.varName,T.value]))),h(null),m({status:"idle"});const z=Sg[O.platform];y((z==null?void 0:z.testTarget)??""),x("Hello from agent-nuvira!"),k(null)},I=async()=>{if(!i)return;m({status:"checking"});const O=await ee.verifyPlatformConfig(i.platform,c);O.ok?(m({status:"ok",info:O.info}),h({kind:"ok",text:"Verified! "+(O.info?"Connected as "+O.info+".":"Token is valid.")})):(m({status:"err",error:O.error}),h({kind:"err",text:O.error||"Verification failed."}))},M=async()=>{if(!i)return;f(!0),h(null);const O=await ee.setPlatformConfig(i.platform,c);f(!1),O.ok?(h({kind:"ok",text:"Token saved! Verifying..."}),j(),l(2),I()):h({kind:"err",text:O.error||"Save failed."})},$=async()=>{if(!i||!v)return;S(!0),k(null);const O=await ee.sendChannelMessage(v,b);S(!1),O.ok?k({kind:"ok",text:"Message sent via "+O.platform+"! Check your "+i.label+" app."}):k({kind:"err",text:O.error||"Send failed. Make sure the gateway is running (Gateway tab)."})};if(e===null)return s.jsx("div",{className:"empty-state",children:"Loading platforms..."});const R=e.filter(O=>O.configured).length,B=e.filter(O=>n==="configured"?O.configured:n==="unconfigured"?!O.configured:!0),L=i?Sg[i.platform]:null;function U(O){return o===O?"wizard-step-dot active":"wizard-step-dot"}return s.jsxs("div",{className:"panel",children:[s.jsx("div",{className:"panel-header",children:s.jsx("h2",{children:"Platforms — Messaging Gateway Onboarding"})}),s.jsxs("div",{className:"platforms-summary",children:[s.jsxs("div",{className:"platforms-summary-stat",children:[s.jsx("span",{className:"platforms-summary-number",children:R}),s.jsx("span",{className:"platforms-summary-label",children:"configured"})]}),s.jsxs("div",{className:"platforms-summary-stat",children:[s.jsx("span",{className:"platforms-summary-number",children:e.length-R}),s.jsx("span",{className:"platforms-summary-label",children:"available"})]}),s.jsx("div",{className:"platforms-summary-filters",children:["all","configured","unconfigured"].map(O=>s.jsx("button",{type:"button",className:n===O?"platforms-filter-btn active":"platforms-filter-btn",onClick:()=>r(O),children:O==="all"?"All":O==="configured"?"Configured":"Not set up"},O))})]}),s.jsx("div",{className:"platforms-grid",children:B.map(O=>{const z=Sg[O.platform];return s.jsxs("div",{className:O.configured?"platform-card configured":"platform-card",children:[s.jsxs("div",{className:"platform-card-head",children:[s.jsx("span",{className:"platform-card-icon",children:(z==null?void 0:z.icon)??"🔌"}),s.jsxs("div",{className:"platform-card-info",children:[s.jsx("span",{className:"platform-card-name",children:O.label}),s.jsx("span",{className:"platform-card-category",children:(z==null?void 0:z.category)??"Platform"})]}),s.jsx("span",{className:O.configured?"status-dot connected":"status-dot reconnecting"})]}),s.jsx("div",{className:"platform-card-vars",children:O.envVars.map(T=>s.jsxs("span",{className:T.set?"platform-var-chip set":"platform-var-chip",children:[T.varName," ",T.set?"done":"--"]},T.varName))}),s.jsxs("div",{className:"platform-card-actions",children:[O.configured?s.jsx("span",{className:"platform-card-badge",children:"Active"}):s.jsx("button",{type:"button",className:"wizard-start-btn",onClick:()=>C(O),children:"Setup"}),O.setupUrl?s.jsx("a",{href:O.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"admin-mini-btn platform-docs-link",children:"Docs"}):null]}),!O.configured&&O.setupHint?s.jsx("div",{className:"platform-card-hint",children:O.setupHint}):null]},O.platform)})}),s.jsxs("div",{className:"platforms-cli-hint",children:[s.jsx("span",{className:"admin-hint",children:"Prefer the terminal? "}),s.jsx("code",{children:"buff gateway setup telegram"}),s.jsx("span",{className:"admin-hint",children:" — same wizard from your CLI"})]}),i&&L?s.jsx("div",{className:"wizard-overlay",onClick:()=>a(null),children:s.jsxs("div",{className:"wizard-modal",onClick:O=>O.stopPropagation(),children:[s.jsxs("div",{className:"wizard-header",children:[s.jsx("span",{className:"wizard-icon",children:L.icon}),s.jsxs("span",{className:"wizard-title",children:["Getting Started: ",i.label]}),s.jsxs("div",{className:"wizard-steps-indicator",children:[s.jsx("span",{className:U(0),children:"1"}),s.jsx("span",{className:U(1),children:"2"}),s.jsx("span",{className:U(2),children:"3"})]}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>a(null),children:"X"})]}),s.jsxs("div",{className:"wizard-body",children:[o===0&&s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"wizard-section-title",children:["Step 1: Create your bot on ",i.label]}),s.jsx("ol",{className:"wizard-steps",children:L.steps.map((O,z)=>s.jsx("li",{children:O},z))}),s.jsxs("div",{className:"wizard-nav",children:[s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>l(1),children:"I have my token — Step 2"}),i.setupUrl?s.jsx("a",{href:i.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"admin-mini-btn platform-docs-link",children:"Open docs"}):null]})]}),o===1&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"wizard-section-title",children:"Step 2: Paste your token"}),i.envVars.map(O=>s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:O.prompt}),s.jsx("input",{type:O.secret?"password":"text",value:c[O.varName]??"",onChange:z=>u(T=>({...T,[O.varName]:z.target.value})),placeholder:O.secret?"paste your token here":"value",autoComplete:"off",spellCheck:!1,autoFocus:!0})]},O.varName)),p?s.jsx("div",{className:p.kind==="ok"?"admin-row-msg":"admin-row-msg admin-row-msg-err",children:p.text}):null,s.jsxs("div",{className:"wizard-nav",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>l(0),children:"Back"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void M(),disabled:d,children:d?"Saving...":"Save & Verify"})]})]}),o===2&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"wizard-section-title",children:"Step 3: Verify and test"}),g.status==="checking"&&s.jsx("div",{className:"wizard-verify-status",children:"Verifying token..."}),g.status==="ok"&&s.jsxs("div",{className:"wizard-verify-status ok",children:["Connected as ",g.info]}),g.status==="err"&&s.jsx("div",{className:"wizard-verify-status err",children:g.error}),g.status==="idle"&&(p==null?void 0:p.kind)==="ok"&&s.jsx("div",{className:"wizard-verify-status ok",children:p.text}),v&&s.jsxs("div",{className:"wizard-test-section",children:[s.jsx("p",{className:"wizard-section-title",children:"Send a test message:"}),s.jsx("div",{className:"wizard-test-row",children:s.jsx("input",{className:"wizard-test-input",value:v,onChange:O=>y(O.target.value),placeholder:"telegram:YOUR_CHAT_ID"})}),s.jsxs("div",{className:"wizard-test-row",children:[s.jsx("input",{className:"wizard-test-input",value:b,onChange:O=>x(O.target.value),placeholder:"Hello from agent-nuvira!"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void $(),disabled:_||!v,children:_?"Sending...":"Send test"})]}),w?s.jsx("div",{className:w.kind==="ok"?"admin-row-msg":"admin-row-msg admin-row-msg-err",children:w.text}):null]}),s.jsxs("div",{className:"wizard-nav",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>l(1),children:"Edit token"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>a(null),children:"Done"})]}),!v&&s.jsxs("p",{className:"wizard-hint",children:["Token saved! Start the gateway from the Gateway tab, then send a message from your ",i.label," app."]})]})]})]})}):null]})}const Bge=[{value:"us-east-1",label:"us-east-1 (N. Virginia) — most models"},{value:"us-west-2",label:"us-west-2 (Oregon) — most models"},{value:"eu-west-1",label:"eu-west-1 (Ireland) — EU coverage"},{value:"ap-southeast-1",label:"ap-southeast-1 (Singapore)"},{value:"ap-northeast-1",label:"ap-northeast-1 (Tokyo)"}],qN=[{name:"Anthropic Claude",models:["claude-haiku-4.5","claude-sonnet-4.6","claude-fable-5","claude-opus-4.6"],checked:!0},{name:"Meta Llama",models:["llama3-1-8b","llama3-1-70b","llama3-3-70b","llama4-scout","llama4-maverick"],checked:!0},{name:"Mistral AI",models:["mistral-large-3","devstral-2","ministral-3"],checked:!1},{name:"DeepSeek",models:["deepseek-v3.2","deepseek-r1"],checked:!1},{name:"Amazon Nova",models:["nova-pro","nova-lite"],checked:!1},{name:"OpenAI on Bedrock",models:["gpt-5.6-terra","gpt-oss-120b"],checked:!1},{name:"Qwen",models:["qwen3-coder-next","qwen3-32b"],checked:!1},{name:"Google Gemma",models:["gemma-3-12b"],checked:!1},{name:"xAI",models:["grok-4.6"],checked:!1}];function zge({canWrite:e,sessionExpired:t}){const[n,r]=E.useState(null),[i,a]=E.useState(null),[o,l]=E.useState(!1),[c,u]=E.useState("overview"),d=E.useRef(!0),[f,p]=E.useState("bearer"),[h,g]=E.useState(""),[m,v]=E.useState(""),[y,b]=E.useState(""),[x,_]=E.useState("us-east-1"),[S,w]=E.useState(qN.filter(R=>R.checked).map(R=>R.name)),[k,N]=E.useState(!1),[j,C]=E.useState(null),I=E.useCallback(async()=>{const R=await ee.getBedrockStatus();d.current&&r(R)},[]);E.useEffect(()=>(I(),()=>{d.current=!1}),[I]);const M=async()=>{l(!0),a(null);try{const R=await ee.probeBedrock((n==null?void 0:n.region)||"us-east-1");if(!d.current)return;R.ok&&R.models&&(a(R.models),u("test"))}catch{}finally{d.current&&l(!1)}},$=async()=>{N(!0),C(null);try{const R={BEDROCK_REGION:x};f==="bearer"&&h?R.AWS_BEARER_TOKEN=h:f==="iam"&&(m&&(R.AWS_ACCESS_KEY_ID=m),y&&(R.AWS_SECRET_ACCESS_KEY=y));const B=await ee.setupBedrock(R);if(!d.current)return;B.ok?(C({kind:"ok",text:"✅ Configuration saved! Running connectivity test…"}),u("overview"),await I(),setTimeout(()=>void M(),500)):C({kind:"err",text:B.error||"Save failed"})}catch{d.current&&C({kind:"err",text:"Could not reach the dashboard server."})}finally{d.current&&N(!1)}};return n===null?s.jsx("div",{className:"empty-state",children:"Loading Bedrock status…"}):s.jsxs("div",{className:"bedrock-onboarding",children:[s.jsx("h2",{className:"section-title",children:"🟠 AWS Bedrock"}),s.jsxs("p",{className:"admin-subtitle",children:["Bedrock gives you access to Claude, Llama, Mistral, DeepSeek, and more — all through a single AWS account. Unlike other providers, Bedrock requires a ",s.jsx("strong",{children:"region"}),", ",s.jsx("strong",{children:"AWS credentials"}),", and explicit ",s.jsx("strong",{children:"model access approval"}),"."]}),j?s.jsx("div",{className:`admin-row-msg${j.kind==="ok"?"":" admin-row-msg-err"}`,children:j.text}):null,s.jsxs("div",{className:"bedrock-status-bar",children:[s.jsxs("div",{className:"bedrock-status-item",children:[s.jsx("span",{className:`status-dot ${n.configured?"connected":"reconnecting"}`}),s.jsx("span",{children:n.configured?"Configured":"Not configured"})]}),s.jsxs("div",{className:"bedrock-status-item",children:[s.jsx("span",{className:"bedrock-status-label",children:"Region:"}),s.jsx("code",{children:n.region})]}),s.jsxs("div",{className:"bedrock-status-item",children:[s.jsx("span",{className:"bedrock-status-label",children:"Auth:"}),s.jsx("code",{children:n.authMethod==="bearer"?"API Key":n.authMethod==="iam"?"IAM":"None"})]}),s.jsxs("div",{className:"bedrock-status-actions",children:[e?s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>u(c==="setup"?"overview":"setup"),children:c==="setup"?"✕ Cancel":"⚙ Setup Wizard"}):null,n.configured?s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void M(),disabled:o,children:o?"⏳ Probing…":"🔍 Test Models"}):null]})]}),c==="setup"&&s.jsxs("div",{className:"bedrock-setup-wizard",children:[s.jsx("h3",{className:"section-subtitle",children:"🚀 Bedrock Setup Wizard"}),s.jsxs("div",{className:"bedrock-wizard-step",children:[s.jsx("h4",{children:"Step 1: Authentication"}),s.jsxs("div",{className:"bedrock-auth-options",children:[s.jsxs("label",{className:`bedrock-auth-option ${f==="bearer"?"selected":""}`,children:[s.jsx("input",{type:"radio",name:"authMethod",checked:f==="bearer",onChange:()=>p("bearer")}),s.jsxs("div",{children:[s.jsx("strong",{children:"Bedrock API Key"}),s.jsx("span",{children:"Simpler — get from Bedrock → Settings → API keys"})]})]}),s.jsxs("label",{className:`bedrock-auth-option ${f==="iam"?"selected":""}`,children:[s.jsx("input",{type:"radio",name:"authMethod",checked:f==="iam",onChange:()=>p("iam")}),s.jsxs("div",{children:[s.jsx("strong",{children:"IAM Credentials"}),s.jsx("span",{children:"Full AWS SDK auth — AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY"})]})]})]}),f==="bearer"?s.jsxs("div",{className:"bedrock-wizard-fields",children:[s.jsxs("div",{className:"bedrock-setup-hint",children:[s.jsx("strong",{children:"How to get a Bedrock API key:"}),s.jsxs("ol",{children:[s.jsxs("li",{children:["Open ",s.jsx("a",{href:"https://console.aws.amazon.com/bedrock/",target:"_blank",rel:"noopener noreferrer",children:"AWS Bedrock Console"})]}),s.jsxs("li",{children:["Go to ",s.jsx("strong",{children:"Settings"})," → ",s.jsx("strong",{children:"API keys"})]}),s.jsx("li",{children:"Create a new key and paste it below"})]})]}),s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"Bedrock API Key (Bearer token)"}),s.jsx("input",{type:"password",value:h,onChange:R=>g(R.target.value),placeholder:"••••••••••••",autoComplete:"off",spellCheck:!1})]})]}):s.jsxs("div",{className:"bedrock-wizard-fields",children:[s.jsxs("div",{className:"bedrock-setup-hint",children:[s.jsx("strong",{children:"IAM credentials"})," give full AWS SDK access. Create an IAM user with Bedrock permissions."]}),s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"AWS_ACCESS_KEY_ID"}),s.jsx("input",{type:"text",value:m,onChange:R=>v(R.target.value),placeholder:"AKIA...",autoComplete:"off",spellCheck:!1})]}),s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"AWS_SECRET_ACCESS_KEY"}),s.jsx("input",{type:"password",value:y,onChange:R=>b(R.target.value),placeholder:"••••••••••••",autoComplete:"off",spellCheck:!1})]})]})]}),s.jsxs("div",{className:"bedrock-wizard-step",children:[s.jsx("h4",{children:"Step 2: AWS Region"}),s.jsxs("p",{className:"admin-hint",children:["Models vary by region. ",s.jsx("strong",{children:"us-east-1"})," and ",s.jsx("strong",{children:"us-west-2"})," have the most models. ⚠️ Do NOT use eu-north-1 unless models are explicitly enabled there."]}),s.jsx("select",{className:"bedrock-region-select",value:x,onChange:R=>_(R.target.value),children:Bge.map(R=>s.jsx("option",{value:R.value,children:R.label},R.value))})]}),s.jsxs("div",{className:"bedrock-wizard-step",children:[s.jsx("h4",{children:"Step 3: Model Access"}),s.jsx("p",{className:"admin-hint",children:"Bedrock requires you to request access for each model family."}),s.jsx("div",{className:"bedrock-model-access-hint",children:s.jsx("a",{href:`https://console.aws.amazon.com/bedrock/home?region=${x}#/modelaccess`,target:"_blank",rel:"noopener noreferrer",className:"admin-mini-btn",children:"📖 Open Model Access in AWS Console"})}),s.jsx("div",{className:"bedrock-family-grid",children:qN.map(R=>s.jsxs("label",{className:`bedrock-family-card ${S.includes(R.name)?"selected":""}`,children:[s.jsx("input",{type:"checkbox",checked:S.includes(R.name),onChange:B=>{B.target.checked?w(L=>[...L,R.name]):w(L=>L.filter(U=>U!==R.name))}}),s.jsxs("div",{children:[s.jsx("strong",{children:R.name}),s.jsxs("span",{children:[R.models.length," model(s)"]})]})]},R.name))}),s.jsx("p",{className:"admin-hint",style:{marginTop:8},children:"In the AWS Console, select the families above and submit. Approval is usually instant for Anthropic and Meta models."})]}),s.jsxs("div",{className:"bedrock-wizard-actions",children:[s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void $(),disabled:k||f==="bearer"&&!h||f==="iam"&&(!m||!y),children:k?"⏳ Saving…":"💾 Save & Test"}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>u("overview"),children:"Cancel"})]})]}),c==="test"&&i&&s.jsxs("div",{className:"bedrock-probe-results",children:[s.jsxs("h3",{className:"section-subtitle",children:["🔍 Model Probe Results (",n.region,")"]}),s.jsx("div",{className:"bedrock-probe-grid",children:i.map(R=>s.jsxs("div",{className:`bedrock-probe-card bedrock-probe-${R.status}`,children:[s.jsx("span",{className:"bedrock-probe-icon",children:R.status==="accessible"?"✅":R.status==="permission-denied"?"🔒":R.status==="not-found"?"⚫":"❌"}),s.jsx("span",{className:"bedrock-probe-id",children:R.modelId}),s.jsx("span",{className:"bedrock-probe-status",children:R.status==="accessible"?"Ready":R.status==="permission-denied"?`Need access (HTTP ${R.httpStatus})`:R.status==="not-found"?"Not in this region":"Error"})]},R.modelId))}),i.some(R=>R.status==="permission-denied")&&s.jsxs("div",{className:"bedrock-probe-action",children:[s.jsxs("p",{children:["Some models exist in ",n.region," but access is not approved."]}),s.jsx("a",{href:`https://console.aws.amazon.com/bedrock/home?region=${n.region}#/modelaccess`,target:"_blank",rel:"noopener noreferrer",className:"admin-mini-btn",children:"🔓 Request Model Access in AWS Console →"})]}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>u("overview"),style:{marginTop:12},children:"← Back"})]}),!n.configured&&c==="overview"&&s.jsxs("div",{className:"bedrock-getting-started",children:[s.jsx("h3",{className:"section-subtitle",children:"📋 Getting Started with Bedrock"}),s.jsxs("div",{className:"bedrock-steps",children:[s.jsxs("div",{className:"bedrock-step",children:[s.jsx("span",{className:"bedrock-step-num",children:"1"}),s.jsxs("div",{children:[s.jsx("strong",{children:"Create an AWS account"})," (or use existing)",s.jsxs("span",{children:["New to AWS? Sign up at ",s.jsx("a",{href:"https://aws.amazon.com/",target:"_blank",rel:"noopener noreferrer",children:"aws.amazon.com"})]})]})]}),s.jsxs("div",{className:"bedrock-step",children:[s.jsx("span",{className:"bedrock-step-num",children:"2"}),s.jsxs("div",{children:[s.jsx("strong",{children:"Get Bedrock API key"}),s.jsx("span",{children:"Bedrock → Settings → API keys → Create key"})]})]}),s.jsxs("div",{className:"bedrock-step",children:[s.jsx("span",{className:"bedrock-step-num",children:"3"}),s.jsxs("div",{children:[s.jsx("strong",{children:"Request model access"}),s.jsx("span",{children:"Bedrock → Model access → Select Claude, Llama, etc. → Submit"})]})]}),s.jsxs("div",{className:"bedrock-step",children:[s.jsx("span",{className:"bedrock-step-num",children:"4"}),s.jsxs("div",{children:[s.jsx("strong",{children:"Configure in this wizard"}),s.jsx("span",{children:'Click "Setup Wizard" above to enter your credentials'})]})]})]})]}),n.configured&&c==="overview"&&!i&&s.jsx("div",{className:"bedrock-quick-status",children:s.jsxs("p",{className:"admin-hint",children:["Bedrock is configured. Click ",s.jsx("strong",{children:"🔍 Test Models"})," to verify connectivity and discover which models are accessible in ",n.region,"."]})})]})}function Fge(){const[e,t]=E.useState([]),[n,r]=E.useState(!0),[i,a]=E.useState("all"),[o,l]=E.useState(null),[c,u]=E.useState(""),[d,f]=E.useState(""),[p,h]=E.useState(null),g=E.useCallback(async()=>{r(!0);const k=await ee.getContacts();k.ok&&k.contacts&&t(k.contacts),r(!1)},[]);E.useEffect(()=>{g()},[g]);const m=e.filter(k=>i==="all"||k.status===i),v=async k=>{h(null);const N=await ee.approveContact(k.platform,k.name);h(N.ok?{kind:"ok",text:`✅ ${k.name} approved.`}:{kind:"err",text:N.error||"Failed."}),g()},y=async k=>{h(null);const N=await ee.rejectContact(k.platform,k.name);h(N.ok?{kind:"ok",text:`🚫 ${k.name} rejected.`}:{kind:"err",text:N.error||"Failed."}),g()},b=async k=>{h(null);const N=await ee.deleteContact(k.platform,k.name);h(N.ok?{kind:"ok",text:`🗑️ ${k.name} deleted.`}:{kind:"err",text:N.error||"Failed."}),g()},x=async()=>{if(!o)return;h(null);const k=await ee.updateContact(o.platform,o.id,{name:c,phone:d});h(k.ok?{kind:"ok",text:`✅ ${c} updated.`}:{kind:"err",text:k.error||"Failed."}),l(null),g()},_=k=>k==="approved"?s.jsx("span",{className:"contact-status-badge approved",children:"✅ Approved"}):k==="pending"?s.jsx("span",{className:"contact-status-badge pending",children:"⏳ Pending"}):s.jsx("span",{className:"contact-status-badge rejected",children:"🚫 Rejected"}),S=k=>({telegram:"✈️",whatsapp:"📱",whatsapp_cloud:"📱",email:"📧",slack:"💬",discord:"🎮"})[k]||"🔌",w=k=>k?new Date(k).toLocaleString():"—";return s.jsxs("div",{className:"panel contacts-page",children:[s.jsxs("div",{className:"panel-header",children:[s.jsx("h2",{children:"📇 Contacts — Outbound Messaging Directory"}),s.jsx("p",{className:"admin-hint",children:"Manage who the bot can send messages to. Users auto-register on first Telegram message."})]}),p&&s.jsxs("div",{className:`admin-row-msg ${p.kind==="err"?"admin-row-msg-err":""}`,children:[p.text,s.jsx("button",{className:"admin-mini-btn",onClick:()=>h(null),children:"✕"})]}),s.jsxs("div",{className:"contacts-filters",children:[["all","approved","pending","rejected"].map(k=>s.jsx("button",{type:"button",className:i===k?"platforms-filter-btn active":"platforms-filter-btn",onClick:()=>a(k),children:k==="all"?`All (${e.length})`:k==="approved"?`✅ Approved (${e.filter(N=>N.status==="approved").length})`:k==="pending"?`⏳ Pending (${e.filter(N=>N.status==="pending").length})`:`🚫 Rejected (${e.filter(N=>N.status==="rejected").length})`},k)),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void g(),children:"🔄 Refresh"})]}),n?s.jsx("div",{className:"empty-state",children:"Loading contacts..."}):m.length===0?s.jsxs("div",{className:"empty-state",children:[s.jsxs("p",{children:["No contacts",i!=="all"?` with status "${i}"`:"","."]}),s.jsx("p",{className:"admin-hint",children:'Contacts auto-register when users message the bot on Telegram. They appear here as "Pending" until you approve them.'})]}):s.jsx("div",{className:"contacts-table-wrapper",children:s.jsxs("table",{className:"contacts-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Platform"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"ID"}),s.jsx("th",{children:"Phone"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Registered"}),s.jsx("th",{children:"Actions"})]})}),s.jsx("tbody",{children:m.map(k=>s.jsxs("tr",{className:`contact-row status-${k.status}`,children:[s.jsxs("td",{children:[S(k.platform)," ",k.platform]}),s.jsx("td",{className:"contact-name",children:k.name}),s.jsx("td",{className:"contact-id",children:s.jsx("code",{children:k.id})}),s.jsx("td",{className:"contact-phone",children:k.phone||"—"}),s.jsx("td",{children:_(k.status)}),s.jsx("td",{className:"contact-date",children:w(k.registeredAt||k.addedAt)}),s.jsxs("td",{className:"contact-actions",children:[k.status!=="approved"&&s.jsx("button",{className:"admin-mini-btn contact-approve-btn",onClick:()=>void v(k),children:"✅ Approve"}),k.status!=="rejected"&&s.jsx("button",{className:"admin-mini-btn contact-reject-btn",onClick:()=>void y(k),children:"🚫 Reject"}),s.jsx("button",{className:"admin-mini-btn",onClick:()=>{l(k),u(k.name),f(k.phone||"")},children:"✏️ Edit"}),s.jsx("button",{className:"admin-mini-btn contact-delete-btn",onClick:()=>void b(k),children:"🗑️"})]})]},`${k.platform}:${k.id}`))})]})}),o&&s.jsx("div",{className:"wizard-overlay",onClick:()=>l(null),children:s.jsxs("div",{className:"wizard-modal",onClick:k=>k.stopPropagation(),children:[s.jsxs("div",{className:"wizard-header",children:[s.jsx("span",{className:"wizard-icon",children:"✏️"}),s.jsxs("span",{className:"wizard-title",children:["Edit Contact: ",o.name]}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>l(null),children:"✕"})]}),s.jsxs("div",{className:"wizard-body",children:[s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"Name"}),s.jsx("input",{type:"text",value:c,onChange:k=>u(k.target.value)})]}),s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"Phone (optional, for flexible lookup)"}),s.jsx("input",{type:"text",value:d,onChange:k=>f(k.target.value),placeholder:"+918800123456"})]}),s.jsxs("p",{className:"admin-hint",children:["Platform: ",s.jsx("strong",{children:o.platform})," | ID: ",s.jsx("code",{children:o.id})]}),s.jsxs("div",{className:"wizard-nav",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>l(null),children:"Cancel"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void x(),children:"Save"})]})]})]})})]})}function cs(e){if(e<=0)return"never";const t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60),i=Math.floor(r/24);return i>30?`${i}d ago`:i>0?`${i}d ${r%24}h ago`:r>0?`${r}h ${n%60}m ago`:n>0?`${n}m ago`:`${t}s ago`}function Uge(e,t,n){if(e==="unavailable")return"#f85149";if(e==="unverified")return"#d29922";const i=(Date.now()-t)/(24*60*60*1e3);return i>30&&n>.5?"#f85149":i>7?"#d29922":"#3fb950"}function Wge(e,t,n){if(e==="unavailable")return"Unavailable";if(e==="unverified")return"Unverified";const i=(Date.now()-t)/(24*60*60*1e3);return i>30&&n>.5?"Likely Removed":i>7?"Stale":"Fresh"}function Hge({entry:e}){const t=Date.now(),n=t-e.lastProbedAt,r=t-e.lastVerifiedAt,i=t-e.lastUsedAt,a=Math.min(100,n/(30*24*60*60*1e3)*100),o=e.lastVerifiedAt>0?Math.min(100,r/(30*24*60*60*1e3)*100):-1,l=e.lastUsedAt>0?Math.min(100,i/(30*24*60*60*1e3)*100):-1;return s.jsxs("div",{className:"timeline-bar-container",children:[s.jsx("div",{className:"timeline-bar",title:`Last probed: ${cs(n)}`,children:s.jsx("div",{className:"timeline-bar-fill probe",style:{width:`${a}%`}})}),o>=0&&s.jsx("div",{className:"timeline-bar small",title:`Last verified: ${cs(r)}`,children:s.jsx("div",{className:"timeline-bar-fill verify",style:{width:`${o}%`}})}),l>=0&&s.jsx("div",{className:"timeline-bar small",title:`Last used: ${cs(i)}`,children:s.jsx("div",{className:"timeline-bar-fill use",style:{width:`${l}%`}})})]})}function Gge(){const[e,t]=E.useState(null),[n,r]=E.useState(!0),[i,a]=E.useState(null),[o,l]=E.useState("all"),[c,u]=E.useState("provider"),d=E.useRef(!0),f=E.useCallback(async()=>{try{const v=await fetch("/api/model-timeline");if(!v.ok)throw new Error("Failed to fetch timeline data");const y=await v.json();d.current&&(t(y),a(null))}catch(v){d.current&&a(v instanceof Error?v.message:"Failed to load timeline")}finally{d.current&&r(!1)}},[]);if(E.useEffect(()=>{d.current=!0,f();const v=setInterval(f,3e4);return()=>{d.current=!1,clearInterval(v)}},[f]),n)return s.jsxs("div",{className:"admin-header",children:[s.jsx("h2",{className:"section-title",children:"📅 Model Discovery Timeline"}),s.jsxs("div",{className:"loading-state",children:[s.jsx("div",{className:"loading-spinner"}),s.jsx("p",{children:"Loading timeline..."})]})]});if(i)return s.jsxs("div",{className:"admin-header",children:[s.jsx("h2",{className:"section-title",children:"📅 Model Discovery Timeline"}),s.jsx("div",{className:"admin-row-msg admin-row-msg-err",children:i})]});const h=((e==null?void 0:e.entries)??[]).filter(v=>{const b=(Date.now()-v.lastProbedAt)/(24*60*60*1e3),x=b>7,_=b>30&&v.errorRate>.5,S=!x&&!_;return o==="fresh"?S:o==="stale"?x&&!_:o==="removed"?_:!0}),g=[...h].sort((v,y)=>{if(c==="provider")return v.provider.localeCompare(y.provider)||v.model.localeCompare(y.model);if(c==="lastProbed")return y.lastProbedAt-v.lastProbedAt;if(c==="status"){const b={unavailable:0,unverified:1,verified:2};return(b[y.status]??0)-(b[v.status]??0)}return 0}),m=new Map;for(const v of g)m.has(v.provider)||m.set(v.provider,[]),m.get(v.provider).push(v);return s.jsxs("div",{className:"admin-header",children:[s.jsx("h2",{className:"section-title",children:"📅 Model Discovery Timeline"}),s.jsxs("div",{className:"stats-grid",style:{marginBottom:16},children:[s.jsxs("div",{className:"stat-card",children:[s.jsx("div",{className:"stat-value",children:(e==null?void 0:e.totalModels)??0}),s.jsx("div",{className:"stat-label",children:"Total Models"})]}),s.jsxs("div",{className:"stat-card",style:{borderColor:"#3fb950"},children:[s.jsx("div",{className:"stat-value",style:{color:"#3fb950"},children:(e==null?void 0:e.freshCount)??0}),s.jsx("div",{className:"stat-label",children:"Fresh (<7d)"})]}),s.jsxs("div",{className:"stat-card",style:{borderColor:"#d29922"},children:[s.jsx("div",{className:"stat-value",style:{color:"#d29922"},children:(e==null?void 0:e.staleCount)??0}),s.jsx("div",{className:"stat-label",children:"Stale (7-30d)"})]}),s.jsxs("div",{className:"stat-card",style:{borderColor:"#f85149"},children:[s.jsx("div",{className:"stat-value",style:{color:"#f85149"},children:(e==null?void 0:e.removedCount)??0}),s.jsx("div",{className:"stat-label",children:"Likely Removed (>30d)"})]})]}),s.jsxs("div",{style:{display:"flex",gap:8,marginBottom:16,flexWrap:"wrap"},children:[s.jsx("div",{style:{display:"flex",gap:4},children:["all","fresh","stale","removed"].map(v=>s.jsx("button",{className:`admin-refresh-btn ${o===v?"active":""}`,onClick:()=>l(v),style:{background:o===v?"#238636":"#21262d",border:`1px solid ${o===v?"#3fb950":"#30363d"}`,padding:"4px 12px",fontSize:12,cursor:"pointer"},children:v.charAt(0).toUpperCase()+v.slice(1)},v))}),s.jsx("div",{style:{display:"flex",gap:4},children:["provider","lastProbed","status"].map(v=>s.jsxs("button",{className:`admin-refresh-btn ${c===v?"active":""}`,onClick:()=>u(v),style:{background:c===v?"#238636":"#21262d",border:`1px solid ${c===v?"#3fb950":"#30363d"}`,padding:"4px 12px",fontSize:12,cursor:"pointer"},children:["Sort: ",v==="lastProbed"?"Last Seen":v.charAt(0).toUpperCase()+v.slice(1)]},v))}),s.jsx("button",{className:"admin-refresh-btn",onClick:f,style:{background:"#21262d",border:"1px solid #30363d",padding:"4px 12px",fontSize:12,cursor:"pointer"},children:"🔄 Refresh"})]}),s.jsxs("div",{style:{display:"flex",gap:16,marginBottom:12,fontSize:11,color:"#8b949e"},children:[s.jsxs("span",{children:[s.jsx("span",{style:{color:"#58a6ff"},children:"■"})," Probe (last seen)"]}),s.jsxs("span",{children:[s.jsx("span",{style:{color:"#3fb950"},children:"■"})," Verified (last success)"]}),s.jsxs("span",{children:[s.jsx("span",{style:{color:"#d29922"},children:"■"})," Used (last invocation)"]})]}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Array.from(m.entries()).map(([v,y])=>s.jsxs("div",{style:{background:"#161b22",borderRadius:8,border:"1px solid #30363d",overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid #30363d",display:"flex",alignItems:"center",gap:8},children:[s.jsx("span",{style:{fontSize:16},children:v==="groq"?"⚡":v==="gemini"?"🌀":v==="local"?"💻":"🤖"}),s.jsx("span",{style:{fontWeight:600,color:"#e6edf3"},children:v}),s.jsxs("span",{style:{fontSize:12,color:"#8b949e"},children:["(",y.length," models)"]})]}),s.jsx("div",{style:{padding:"8px 14px"},children:y.map(b=>{const x=Date.now();(x-b.lastProbedAt)/(24*60*60*1e3);const _=Uge(b.status,b.lastProbedAt,b.errorRate),S=Wge(b.status,b.lastProbedAt,b.errorRate);return s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"6px 0",borderBottom:"1px solid #21262d"},children:[s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{fontSize:13,color:"#e6edf3",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.model}),s.jsxs("div",{style:{fontSize:11,color:"#8b949e",display:"flex",gap:12},children:[s.jsxs("span",{children:["Probed: ",cs(x-b.lastProbedAt)]}),b.lastVerifiedAt>0&&s.jsxs("span",{children:["Verified: ",cs(x-b.lastVerifiedAt)]}),b.lastUsedAt>0&&s.jsxs("span",{children:["Used: ",cs(x-b.lastUsedAt)]}),b.latencyMs!==void 0&&s.jsxs("span",{children:[b.latencyMs,"ms"]})]})]}),s.jsx(Hge,{entry:b}),s.jsx("div",{style:{fontSize:11,padding:"2px 8px",borderRadius:4,background:`${_}20`,color:_,border:`1px solid ${_}40`,whiteSpace:"nowrap"},children:S})]},b.model)})})]},v))}),h.length===0&&s.jsx("div",{style:{textAlign:"center",padding:"40px 20px",color:"#8b949e"},children:"No models match the current filter"})]})}function qge(){const[e,t]=E.useState(null),[n,r]=E.useState(!1),[i,a]=E.useState("--"),o=E.useCallback(c=>{t(c),a(new Date().toLocaleTimeString())},[]),l=E.useCallback(c=>{r(c)},[]);return E.useEffect(()=>{ee.fetchAll().then(d=>{d&&o(d)});const c=ee.subscribe(o),u=ee.onConnectionChange(l);return ee.connect(),()=>{c(),u(),ee.disconnect()}},[o,l]),s.jsx($L,{connected:n,lastUpdated:i,children:s.jsxs(yL,{children:[s.jsx(vt,{path:"/",element:s.jsx(HN,{})}),s.jsx(vt,{path:"/overview",element:s.jsx(pie,{data:e})}),s.jsx(vt,{path:"/chat",element:s.jsx(r1,{to:"/",replace:!0})}),s.jsx(vt,{path:"/dag",element:s.jsx(Sie,{data:e})}),s.jsx(vt,{path:"/costs",element:s.jsx(_ie,{data:e})}),s.jsx(vt,{path:"/benchmarks",element:s.jsx(Nie,{data:e})}),s.jsx(vt,{path:"/models",element:s.jsx(cae,{})}),s.jsx(vt,{path:"/models/timeline",element:s.jsx(Gge,{})}),s.jsx(vt,{path:"/routing",element:s.jsx(Hae,{data:e})}),s.jsx(vt,{path:"/requests",element:s.jsx(Kae,{data:e})}),s.jsx(vt,{path:"/traces",element:s.jsx(noe,{})}),s.jsx(vt,{path:"/hub",element:s.jsx(hoe,{})}),s.jsx(vt,{path:"/tasks",element:s.jsx(yoe,{})}),s.jsx(vt,{path:"/chat",element:s.jsx(HN,{})}),s.jsx(vt,{path:"/evals",element:s.jsx(Ige,{data:e})}),s.jsx(vt,{path:"/platforms",element:s.jsx(Dge,{})}),s.jsx(vt,{path:"/bedrock",element:s.jsx(zge,{canWrite:!0,sessionExpired:c=>console.error(c)})}),s.jsx(vt,{path:"/contacts",element:s.jsx(Fge,{})}),s.jsx(vt,{path:"/gateway",element:s.jsx(Lge,{})}),s.jsx(vt,{path:"/system",element:s.jsx(jie,{data:e})}),s.jsx(vt,{path:"/admin",element:s.jsx(soe,{})}),s.jsx(vt,{path:"*",element:s.jsx(r1,{to:"/",replace:!0})})]})})}aT(document.getElementById("root")).render(s.jsx(E.StrictMode,{children:s.jsx(EL,{children:s.jsx(qge,{})})}));
|
|
207
|
-
//# sourceMappingURL=index-
|
|
206
|
+
`);return s.jsxs("div",{className:`chat-draft-card${i==="saved"?" chat-draft-saved":""}${i==="rejected"?" chat-draft-rejected":""}`,children:[s.jsxs("div",{className:"chat-draft-head",children:[s.jsx("span",{className:"chat-draft-icon",children:"🧠"}),s.jsxs("span",{className:"chat-draft-title",children:["New skill draft: ",e.name]}),s.jsx("span",{className:"chat-draft-meta",children:"pending your review"})]}),s.jsx("p",{className:"chat-draft-desc",children:e.description}),s.jsx("pre",{className:"chat-draft-body",children:l}),i==="saving"?s.jsx("div",{className:"admin-hint",children:"Saving…"}):i==="saved"?s.jsx("div",{className:"admin-hint",children:"✅ Saved — the skill is live: load it in chat or see it in the Agent Hub Skills tab."}):i==="rejected"?s.jsx("div",{className:"admin-hint",children:"🗑️ Rejected — the draft was discarded, nothing was saved."}):s.jsxs("div",{className:"chat-draft-actions",children:[s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>t(e.name),children:"✅ Accept"}),s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:()=>r(e.name),children:"✏️ Edit"}),s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:()=>n(e.name),children:"↩ Reject"})]})]})}function Age({request:e,onSave:t}){const[n,r]=E.useState({}),[i,a]=E.useState(!1),o=e.missing.every(u=>{var d;return(d=n[u])==null?void 0:d.trim()}),l=e.missing.filter(u=>e.persisted[u]),c=e.missing.filter(u=>!e.persisted[u]);return s.jsxs("div",{className:"chat-secret-card",children:[s.jsxs("div",{className:"chat-secret-head",children:[s.jsx("span",{className:"chat-secret-icon",children:"🔐"}),s.jsxs("span",{className:"chat-secret-title",children:[e.skillName," needs environment variables"]})]}),l.length>0?s.jsxs("div",{className:"chat-secret-persisted",children:["Already configured: ",l.map(u=>s.jsx("code",{children:u},u)).join(", ")]}):null,c.length>0&&!i?s.jsxs("div",{className:"chat-secret-fields",children:[c.map(u=>s.jsxs("div",{className:"chat-secret-row",children:[s.jsxs("label",{className:"chat-secret-label",htmlFor:`secret-${u}`,children:[u,":"]}),s.jsx("input",{id:`secret-${u}`,className:"chat-secret-input",type:"password",placeholder:`Enter ${u} value…`,value:n[u]??"",onChange:d=>r(f=>({...f,[u]:d.target.value}))})]},u)),s.jsx("button",{className:"admin-refresh-btn",type:"button",disabled:!o,onClick:()=>{t(n),a(!0)},children:"💾 Save to ~/.buff/.env"})]}):i?s.jsx("div",{className:"admin-hint",children:"✅ Saved — the skill will pick up these values on next load."}):s.jsx("div",{className:"admin-hint",children:"All required env vars are already configured."})]})}function Tge({result:e}){const[t,n]=E.useState(!1),r=e.success?"✅":"❌",i=e.success?"Success":`Failed (exit ${e.exitCode})`,a=e.success?"chat-exec-success":"chat-exec-failure",o=new Date(e.timestamp).toLocaleTimeString();return s.jsxs("div",{className:`chat-exec-card ${a}`,children:[s.jsxs("div",{className:"chat-exec-head",onClick:()=>n(!t),style:{cursor:"pointer"},children:[s.jsx("span",{className:"chat-exec-icon",children:"📜"}),s.jsx("span",{className:"chat-exec-title",children:e.skillName}),s.jsxs("span",{className:"chat-exec-status",children:[r," ",i]}),s.jsxs("span",{className:"chat-exec-meta",children:[e.runtime," · ",e.durationMs,"ms · ",o]}),s.jsx("span",{className:"chat-exec-expand",children:t?"▼":"▶"})]}),t&&s.jsxs("div",{className:"chat-exec-body",children:[e.stdout&&s.jsxs("div",{className:"chat-exec-section",children:[s.jsx("div",{className:"chat-exec-section-title",children:"stdout"}),s.jsx("pre",{className:"chat-exec-output",children:e.stdout})]}),e.stderr&&s.jsxs("div",{className:"chat-exec-section chat-exec-stderr",children:[s.jsx("div",{className:"chat-exec-section-title",children:"stderr"}),s.jsx("pre",{className:"chat-exec-output",children:e.stderr})]}),s.jsxs("div",{className:"chat-exec-details",children:[s.jsxs("span",{children:["Runtime: ",e.runtime]}),s.jsxs("span",{children:["Exit code: ",e.exitCode]}),s.jsxs("span",{children:["Duration: ",e.durationMs,"ms"]})]})]})]})}function Cge(e){return e==="done"?"✅":e==="running"?"🔄":e==="blocked"?"⛔":"⬜"}function UN({plan:e}){const t=e.steps.filter(n=>n.status==="done").length;return s.jsxs("div",{className:"chat-plan-card",children:[s.jsxs("div",{className:"chat-plan-head",children:[s.jsx("span",{className:"chat-plan-icon",children:"🗂️"}),s.jsx("span",{className:"chat-plan-goal",children:e.goal}),s.jsxs("span",{className:"chat-plan-count",children:[t,"/",e.steps.length," done"]})]}),s.jsx("div",{className:"chat-plan-steps",children:e.steps.map(n=>s.jsxs("div",{className:`chat-plan-step chat-plan-step-${n.status}`,children:[s.jsx("span",{className:"chat-plan-step-icon",children:Cge(n.status)}),s.jsx("span",{className:"chat-plan-step-text",children:n.description}),s.jsx("span",{className:"chat-plan-step-status",children:n.status})]},n.id))})]})}function WN({tools:e,live:t}){return!e||e.length===0?null:s.jsx("div",{className:`chat-tool-cards${t?" chat-tool-cards-live":""}`,children:e.map(n=>{const r=n.phase==="started"||n.ok===void 0,i=n.ok===!1;return s.jsxs("div",{className:`chat-tool-card${r?" chat-tool-running":i?" chat-tool-err":" chat-tool-ok"}`,children:[s.jsxs("div",{className:"chat-tool-head",children:[s.jsx("span",{className:"chat-tool-icon",children:Sge(n.tool)}),s.jsx("span",{className:"chat-tool-name",children:n.tool}),n.args?s.jsx("code",{className:"chat-tool-args",children:n.args}):null,s.jsx("span",{className:"chat-tool-status",title:r?"running":i?"failed":"done",children:r?"⏳":i?"✗":"✓"}),n.durationMs!==void 0&&!r?s.jsxs("span",{className:"chat-tool-dur",children:[n.durationMs,"ms"]}):null]}),n.error||n.result?s.jsxs("details",{className:"chat-tool-detail",children:[s.jsx("summary",{children:i?"Error":"Result"}),s.jsx("pre",{className:"chat-tool-body",children:n.error||n.result})]}):null]},n.id)})})}function wg(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`chat-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Oge(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(u=>`${u.title} ${u.preview} ${u.firstUser}`.toLowerCase().includes(n)):e,i=[],a=new Date,o=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),l=864e5,c=[{label:"Today",match:u=>u>=o},{label:"Yesterday",match:u=>u>=o-l&&u<o},{label:"This week",match:u=>u>=o-7*l&&u<o-l},{label:"Older",match:()=>!0}];for(const u of c){const d=r.filter(f=>u.match(f.updatedAt));d.length>0&&i.push({label:u.label,items:d})}return i}function HN(){var Pu,Mu,Ru,xa,Iu;const[e,t]=E.useState(null),[n,r]=E.useState([]),[i,a]=E.useState(""),[o,l]=E.useState(!1),[c,u]=E.useState(""),[d,f]=E.useState(null),[p,h]=E.useState([]),[g,m]=E.useState([]),[v,y]=E.useState(null),[b,x]=E.useState(null),[_,S]=E.useState(null),[w,k]=E.useState([]),[N,j]=E.useState([]),[C,I]=E.useState(null),M=E.useRef([]),$=E.useRef([]),R=E.useRef(null),B=E.useRef(null),L=E.useRef(null),[U,O]=E.useState(""),z=E.useRef(""),T=E.useRef(null),[V,q]=E.useState(null),P=E.useRef(wg()),ce=E.useRef(""),[me,ue]=E.useState([]),[He,Ce]=E.useState(!0),[te,ye]=E.useState(""),[be,X]=E.useState(null),[Ae,we]=E.useState(""),[Se,ge]=E.useState([]),[De,le]=E.useState(null),[Tt,Fe]=E.useState(!1),Te=E.useRef(null),lt=E.useRef(null),[Me,Zt]=E.useState(null),[Ht,F]=E.useState(null),[K,ae]=E.useState([]),[de,_e]=E.useState(""),[Xe,yt]=E.useState(""),[It,Dn]=E.useState(!1),[pt,Nt]=E.useState(""),[H,oe]=E.useState([]),[Re,Oe]=E.useState(null),[ga,Pr]=E.useState(!1),[mr,vo]=E.useState([]),[_u,An]=E.useState([]),[bo,_i]=E.useState(""),sl=E.useRef(null),tt=E.useRef(null),xo=E.useRef(null),Mr=E.useRef(null),[Gt,ya]=E.useState(null),[va,Eu]=E.useState(new Set);E.useEffect(()=>{ee.fetchAdminAuthStatus().then(D=>{t(D?{configured:D.configured,authenticated:D.authenticated,role:D.role}:{configured:!1,authenticated:!1,role:null})})},[]),E.useEffect(()=>{var D,Z;try{(Z=(D=xo.current)==null?void 0:D.scrollTo)==null||Z.call(D,{top:xo.current.scrollHeight})}catch{}},[n,o,p]),E.useEffect(()=>()=>{var D;(D=tt.current)==null||D.call(tt),tt.current=null},[]);const Bh=E.useCallback(async D=>{var ke,Zr;(ke=tt.current)==null||ke.call(tt),tt.current=null;const Z=await ee.getChatSession(D);if(!Z)return;P.current=D,r(Z.turns.map($t=>({role:$t.role,content:$t.content,...$t.role==="assistant"?{followups:[],artifacts:DN($t.content)}:{}}))),h([]),M.current=[],m([]),$.current=[],y(null),R.current=null,x(null),B.current=null,S(null),L.current=null,z.current="",O(""),q(null),u(""),f(null),I(null),ya(null),Ce(!0);const Q=Z.projectPath;if(Q){if(F(Q),(Me==null?void 0:Me.path)===Q)return;(Zr=Mr.current)==null||Zr.call(Mr,Q)}else F(null)},[Me]),ll=E.useCallback(()=>{var D;(D=tt.current)==null||D.call(tt),tt.current=null,P.current=wg(),F(null),r([]),h([]),M.current=[],m([]),$.current=[],y(null),R.current=null,x(null),B.current=null,S(null),L.current=null,z.current="",O(""),q(null),u(""),f(null),I(null),ya(null),ge([]),le(null),a(""),Ce(!0)},[]),wo=E.useCallback(D=>{ge(Z=>[...Z,D].slice(-10))},[]),cl=E.useCallback(D=>{ge(Z=>Z.filter((Q,ke)=>ke!==D))},[]),Nu=E.useCallback(async D=>{if(!D)return;if(D.size>zN){u(`Attachment "${D.name}" is too large (max ${Math.round(zN/1024)} KB).`);return}const Z=await D.text();wo({name:D.name,content:Z,kind:"file"})},[wo]),ju=E.useCallback(D=>{const Z=D.currentTarget,Q=D.clipboardData.getData("text")||"";Q.length>=wge&&(lt.current={start:Z.selectionStart,end:Z.selectionEnd},le({text:Q}))},[]),zh=E.useCallback(()=>{const D=De;if(!D)return;const Z=lt.current;a(Q=>Z?Q.slice(0,Z.start)+Q.slice(Z.end):Q),wo({name:"pasted-text.txt",content:D.text,kind:"paste"}),le(null),lt.current=null},[De,wo]),Fh=E.useCallback(D=>{X(D.id),we(D.title==="(untitled conversation)"?"":D.title)},[]),Au=E.useCallback(async D=>{const Z=await ee.renameChatSession(D,Ae);Z.ok?ue(Q=>Q.map(ke=>ke.id===D?{...ke,title:Ae.trim()||ke.title}:ke)):u(Z.error||"Could not rename the session."),X(null),we("")},[Ae]),ul=E.useCallback(async D=>{const Z=await ee.deleteChatSession(D);Z.ok?(ue(Q=>Q.filter(ke=>ke.id!==D)),P.current===D&&ll()):u(Z.error||"Could not delete the session.")},[ll]),So=(e==null?void 0:e.authenticated)===!0&&(e.role==="admin"||e.role==="operator");E.useEffect(()=>{So&&(ee.listChatSessions().then(D=>{Array.isArray(D)&&ue(D)}),ee.listProjects().then(D=>{Array.isArray(D)&&ae(D)}))},[So]);const Bn=E.useCallback(async D=>{const Z=D.trim();if(!Z)return;yt("");const Q=await ee.attachProject(Z);if(Q.ok&&Q.project){Zt(Q.project),_e("");const ke=await ee.listProjects();Array.isArray(ke)&&ae(ke)}else yt(Q.error||"Could not attach that directory.")},[]);Mr.current=Bn;const Qt=E.useCallback(async D=>{Dn(!0),Pr(!0),_i("");const Z=await ee.browseDirectories(D,{showDrives:!D});Z.ok&&(Nt(Z.path),oe(Z.entries),Oe(Z.parent),Z.drives&&vo(Z.drives),Z.breadcrumbs&&An(Z.breadcrumbs)),Pr(!1)},[]),ba=E.useCallback(async D=>{Pr(!0),_i("");const Z=await ee.browseDirectories(D);Z.ok&&(Nt(Z.path),oe(Z.entries),Oe(Z.parent),Z.breadcrumbs&&An(Z.breadcrumbs)),Pr(!1)},[]),Ei=E.useCallback(async()=>{if(!pt)return;const D=await ee.browseDirectories(pt);D.ok&&oe(D.entries)},[pt]);E.useEffect(()=>(It&&pt&&(sl.current=setInterval(()=>{Ei()},5e3)),()=>{sl.current&&clearInterval(sl.current)}),[It,pt,Ei]);const Tu=E.useCallback(async()=>{const D=window;if(typeof D.showDirectoryPicker=="function")try{const Q=(await D.showDirectoryPicker()).name;if(!Q){Qt();return}yt(""),l(!0);const ke=await ee.resolveFolder(Q);l(!1),ke.ok&&ke.path?(_e(ke.path),Bn(ke.path)):(yt((ke.error||"Could not find folder.")+" Opening manual browser..."),Qt());return}catch(Z){if(Z instanceof DOMException&&Z.name==="AbortError")return}Qt()},[Qt,Bn]),Ct=E.useCallback(async(D,Z)=>{var gr,Jn;const Q=D.trim(),ke=Array.isArray(Z)?Z:Se,Zr=!Array.isArray(Z)&&(Z==null?void 0:Z.skipResolve)===!0;if(!Q&&ke.length===0||o)return;if(u(""),f(null),h([]),M.current=[],m([]),$.current=[],y(null),R.current=null,x(null),B.current=null,S(null),L.current=null,r(xe=>[...xe,{role:"user",content:Q,attachments:ke.length>0?ke:void 0}]),a(""),ge([]),le(null),ce.current=Q||`[${ke.length} attachment(s)]`,l(!0),Ce(!1),!Zr){const at=((await ee.chatResolve(Q)).matches??[])[0]??null;if(at&&at.command&&!at.ambiguous&&at.score>=.6){I({ask:Q,top:at}),l(!1);return}if(at&&at.ambiguous&&!C){I({ask:Q,top:at}),l(!1);return}}const $t=P.current,zn=new AbortController;T.current=zn,q(null),(gr=tt.current)==null||gr.call(tt),tt.current=ee.subscribeChat($t,{onToken:xe=>{z.current+=xe,O(z.current)},onProgress:xe=>{M.current=[...M.current,xe],h(M.current)},onQuestion:xe=>{ya(xe),Eu(new Set)},onTool:xe=>{const Be=[...$.current],at=Be.findIndex(en=>en.id===xe.id),jt={id:xe.id,tool:xe.tool,phase:xe.phase,args:xe.args,ok:xe.ok,result:xe.result,error:xe.error,durationMs:xe.durationMs};at>=0?Be[at]=jt:Be.push(jt),$.current=Be,m(Be)},onPlan:xe=>{const Be={goal:xe.goal,steps:xe.steps,revision:xe.revision};R.current=Be,y(Be)},onDiff:xe=>{const Be={files:xe.files,summary:xe.summary};B.current=Be,x(Be)},onSkillDraft:xe=>{const Be={name:xe.name,description:xe.description,markdown:xe.markdown,updatedAt:xe.updatedAt,status:"pending"};L.current=Be,S(Be)},onSecretRequest:xe=>{k(Be=>{const at=Be.findIndex(jt=>jt.skillName===xe.skillName);if(at>=0){const jt=[...Be];return jt[at]=xe,jt}return[...Be,xe]})},onExecutionResult:xe=>{j(Be=>[...Be,xe])}});const xn=await ee.chatSend($t,Q||`(see ${ke.length} attachment${ke.length===1?"":"s"})`,{projectPath:Me==null?void 0:Me.path,attachments:ke.map(xe=>({name:xe.name,content:xe.content,kind:xe.kind}))},zn.signal);if(T.current=null,(Jn=tt.current)==null||Jn.call(tt),tt.current=null,z.current="",O(""),xn.ok){f(xn.generationFailed?null:`${xn.provider??"provider"}${xn.model?` / ${xn.model}`:" (auto-routed)"}`),q(xn.generationFailed?Q:null);const xe=xn.content||"(the agent produced no text — try rephrasing)";r(Be=>[...Be,{role:"assistant",content:xe,error:xn.generationFailed,followups:xn.followups,steps:M.current,tools:$.current,plan:R.current,diff:B.current,draft:L.current,artifacts:DN(xe)}])}else zn.signal.aborted?(u(""),q(null)):xn.unauthorized?(t(xe=>xe&&{...xe,authenticated:!1}),u("Session expired — log in again to chat.")):(u(xn.error||"The agent could not answer — check that a provider API key is set for the dashboard process."),q(Q));l(!1),Ce(!0)},[o,Me,Se]),Ni=E.useCallback(()=>{var D;(D=T.current)==null||D.abort()},[]),ko=E.useCallback(async D=>{S(Q=>Q&&{...Q,status:"saving"});const Z=await ee.skillDraftAccept(D);S(Q=>Q&&{...Q,status:Z.ok?"saved":"error"}),Z.ok||u(Z.error||"Could not accept the draft.")},[]),Xr=E.useCallback(async D=>{const Z=await ee.skillDraftReject(D);Z.ok?S(Q=>Q&&{...Q,status:"rejected"}):u(Z.error||"Could not reject the draft.")},[]),_o=E.useCallback(D=>{Ct(`Revise the skill draft "${D}" — improve it per your best judgment and present it again.`)},[Ct]),Eo=E.useCallback(async D=>{const Z=await ee.saveSecrets(D);Z.ok||u(Z.error||"Could not save secrets.")},[]),Cu=E.useCallback(async D=>{const ke=((await ee.chatResolve(D)).matches??[])[0]??null;if(!(ke!=null&&ke.command)){I(null);return}I(null),l(!0);const Zr=ke.command.split(/\s+/),$t=await ee.startTask(Zr,6e4);if(!$t.ok||!$t.task){u($t.error||"The command could not be started."),l(!1);return}const zn=$t.task.id,xn={id:zn,command:ke.command,status:$t.task.status,exitCode:$t.task.exitCode,durationMs:$t.task.durationMs,logs:$t.task.logs??[]};r(at=>[...at,{role:"assistant",content:"",task:xn}]);const gr=at=>r(jt=>jt.map(en=>en.task&&en.task.id===zn?{...en,task:{...en.task,...at}}:en));let Jn=null;Jn=ee.subscribeTask(zn,{onLog:at=>r(jt=>jt.map(en=>en.task&&en.task.id===zn?{...en,task:{...en.task,logs:[...en.task.logs,at]}}:en)),onStatus:at=>{gr({status:at}),at!=="running"&&(ee.getTask(zn).then(jt=>{jt!=null&&jt.task&&gr({exitCode:jt.task.exitCode,durationMs:jt.task.durationMs,logs:jt.task.logs??[]})}),Jn==null||Jn(),l(!1))}});const xe=await ee.getTask(zn);xe!=null&&xe.task&&gr({status:xe.task.status,exitCode:xe.task.exitCode,durationMs:xe.task.durationMs,logs:xe.task.logs??[]});const Be=await ee.getTask(zn);Be!=null&&Be.task&&Be.task.status!=="running"&&(Jn==null||Jn(),gr({status:Be.task.status,exitCode:Be.task.exitCode,durationMs:Be.task.durationMs,logs:Be.task.logs??[]}),l(!1))},[]),ji=E.useCallback(D=>{I(null),Ct(D,{skipResolve:!0})},[Ct]),Ou=E.useCallback(D=>{if(D.length===0)return;const Z=Me?` in the attached project ${Me.path}`:"";Ct(`Commit exactly these files that I accepted on the diff card (and nothing else)${Z}: ${D.join(", ")}. Show me a short confirmation before finishing.`)},[Ct,Me]),Uh=E.useCallback(async D=>{await ee.cancelTask(D)},[]),bn=E.useCallback(async D=>{const Z=Gt;if(!Z)return;ya(null);const Q=await ee.chatRespond(P.current,Z.questionId,D);Q.ok||u(Q.error||"The question could not be answered — try sending your message again.")},[Gt]),Jt=E.useCallback(()=>{if(!Gt)return;const D=Gt.multiSelect?[...va]:[...va][0];Gt.multiSelect?bn({index:[...va]}):bn(D!==void 0?{index:D}:{index:-1})},[Gt,va,bn]),Wh=E.useCallback(()=>{Gt&&bn({index:-1})},[Gt,bn]),Hh=E.useCallback(D=>{Eu(Z=>{const Q=new Set(Z);return Gt!=null&&Gt.multiSelect?Q.has(D)?Q.delete(D):Q.add(D):(Q.clear(),Q.add(D)),Q})},[Gt]),Gh=E.useCallback(async()=>{var Z;(Z=tt.current)==null||Z.call(tt),tt.current=null,P.current=wg(),r([]),h([]),M.current=[],m([]),$.current=[],y(null),R.current=null,x(null),B.current=null,S(null),L.current=null,z.current="",O(""),q(null),u(""),f(null),I(null),ya(null);const D=await ee.listChatSessions();Array.isArray(D)&&ue(D)},[]),Ai=((Pu=[...n].reverse().find(D=>{var Z;return D.role==="assistant"&&!D.error&&(((Z=D.followups)==null?void 0:Z.length)??0)>0}))==null?void 0:Pu.followups)??[];return s.jsxs("div",{className:"panel",children:[s.jsxs("div",{className:"panel-header",children:[s.jsx("h2",{children:"💬 Chat with the agent"}),s.jsxs("div",{className:"chat-head-actions",children:[d?s.jsx("span",{className:"admin-hint",children:d}):null,s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void Gh(),disabled:o||n.length===0,children:"🗑 New conversation"})]})]}),e!=null&&e.authenticated?So?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"chat-project-bar",children:Me?s.jsxs("div",{className:"chat-project-attached",children:[s.jsx("span",{className:"chat-project-icon",children:"📁"}),s.jsx("span",{className:"chat-project-name",children:Me.name}),s.jsxs("span",{className:"chat-project-meta",children:[Me.fileCount," files · ",Me.symbolCount," symbols",Me.truncated?" · truncated map":""]}),s.jsx("span",{className:"chat-project-path",title:Me.path,children:Me.path}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>Zt(null),children:"✕ detach"})]}):s.jsxs("div",{className:"chat-project-pick",children:[s.jsx("span",{className:"chat-project-icon",children:"📁"}),s.jsx("span",{className:"chat-project-hint",children:"Select Project Folder"}),K.length>0?s.jsx("span",{className:"chat-project-chips",children:K.filter(D=>D.kind!=="cwd").slice(0,3).map(D=>s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Bn(D.path),children:D.name},D.path))}):null,s.jsx("input",{className:"chat-project-input",value:de,onChange:D=>_e(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.preventDefault(),Bn(de))},placeholder:"or type a path, e.g. ~/code/my-app",disabled:o}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void Bn(de),disabled:o||!de.trim(),children:"Attach"}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>void Tu(),title:"Pick a project folder using your system's folder picker (Finder / Explorer)",children:"🗂️ Browse"}),Xe?s.jsx("span",{className:"chat-project-error",children:Xe}):null,It?s.jsxs("div",{className:"chat-browse-popover",children:[s.jsxs("div",{className:"chat-browse-head",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>Dn(!1),title:"Close",children:"✕"}),s.jsx("div",{className:"chat-browse-breadcrumbs",children:mr.length>0&&!pt?s.jsx("span",{className:"admin-hint",children:"Select a drive or home folder:"}):s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",className:"chat-breadcrumb",onClick:()=>void Qt(),children:"🏠"}),_u.map((D,Z)=>s.jsxs("span",{children:[s.jsx("span",{className:"chat-breadcrumb-sep",children:"/"}),s.jsx("button",{type:"button",className:"chat-breadcrumb",onClick:()=>void ba(D.path),children:D.name})]},D.path))]})})]}),mr.length>0&&!pt?s.jsx("div",{className:"chat-browse-drives",children:mr.map(D=>s.jsx("button",{type:"button",className:"chat-browse-drive",onClick:()=>void ba(D.path),children:D.name},D.path))}):null,H.length>5?s.jsx("div",{className:"chat-browse-search",children:s.jsx("input",{type:"text",className:"chat-browse-filter",placeholder:"🔍 Filter folders…",value:bo,onChange:D=>_i(D.target.value),autoFocus:!0})}):null,s.jsx("div",{className:"chat-browse-list",children:ga?s.jsx("span",{className:"admin-hint",children:"Loading…"}):H.length===0?s.jsx("span",{className:"admin-hint",children:"No subdirectories found"}):H.filter(D=>!bo||D.name.toLowerCase().includes(bo.toLowerCase())).map(D=>s.jsxs("button",{type:"button",className:"chat-browse-entry",onClick:()=>void ba(D.path),children:[s.jsx("span",{className:"chat-browse-entry-icon",children:"📁"}),s.jsx("span",{className:"chat-browse-entry-name",children:D.name}),D.modified?s.jsx("span",{className:"chat-browse-entry-date",children:new Date(D.modified).toLocaleDateString()}):null]},D.path))}),s.jsxs("div",{className:"chat-browse-foot",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>void Ei(),title:"Refresh folder list",children:"🔄"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>{Dn(!1),Bn(pt)},disabled:!pt,children:"📁 Select this folder"})]})]}):null]})}),Ht&&(!Me||Me.path!==Ht)?s.jsxs("div",{className:"chat-session-project-banner",children:[s.jsxs("span",{children:["⚠️ This conversation was working in ",s.jsx("code",{children:Ht})]}),Me?s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void Bn(Ht),children:"📁 Switch to it"}):s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void Bn(Ht),children:"📁 Attach it"})]}):null,s.jsxs("div",{className:"chat-layout",children:[He?s.jsxs("div",{className:"chat-sidebar",children:[s.jsxs("div",{className:"chat-sidebar-head",children:[s.jsx("span",{children:"📁 Sessions"}),s.jsxs("div",{className:"chat-sidebar-head-actions",children:[s.jsx("button",{type:"button",className:"chat-mini-action",title:"New chat",onClick:ll,children:"+ New"}),s.jsx("button",{type:"button",className:"chat-mini-action",title:"Collapse history",onClick:()=>Ce(!1),children:"▸"})]})]}),s.jsx("input",{className:"chat-session-search",placeholder:"Search conversations…",value:te,onChange:D=>ye(D.target.value)}),me.length===0?s.jsx("div",{className:"chat-sidebar-empty",children:"No past conversations yet."}):s.jsx("div",{className:"chat-sidebar-list",children:Oge(me,te).map(({label:D,items:Z})=>s.jsxs("div",{className:"chat-session-group",children:[s.jsx("div",{className:"chat-session-group-label",children:D}),Z.map(Q=>s.jsx("div",{className:`chat-session-item${Q.id===P.current?" chat-session-active":""}`,children:be===Q.id?s.jsxs("div",{className:"chat-session-rename",children:[s.jsx("input",{autoFocus:!0,value:Ae,onChange:ke=>we(ke.target.value),onKeyDown:ke=>{ke.key==="Enter"&&Au(Q.id),ke.key==="Escape"&&X(null)},placeholder:"Session title"}),s.jsx("button",{type:"button",className:"chat-mini-action",onClick:()=>void Au(Q.id),children:"✓"})]}):s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",className:"chat-session-main",onClick:()=>void Bh(Q.id),title:Q.preview||Q.title,children:[s.jsx("span",{className:"chat-session-title",children:Q.title}),s.jsx("span",{className:"chat-session-preview",children:Q.firstUser||Q.preview}),s.jsxs("span",{className:"chat-session-meta",children:[Q.projectPath?`📁 ${Q.projectPath.split("/").pop()} · `:"",Q.turnCount," msg",Q.turnCount===1?"":"s"," · ",new Date(Q.updatedAt).toLocaleString()]})]}),s.jsxs("span",{className:"chat-session-actions",children:[s.jsx("button",{type:"button",className:"chat-mini-action",title:"Rename",onClick:()=>Fh(Q),children:"✏️"}),s.jsx("button",{type:"button",className:"chat-mini-action",title:"Delete",onClick:()=>void ul(Q.id),children:"🗑"})]})]})},Q.id))]},D))})]}):s.jsx("div",{className:"chat-rail",children:s.jsx("button",{type:"button",className:"chat-rail-btn",onClick:()=>Ce(!0),title:"Show history",children:"📁"})}),s.jsxs("div",{className:"chat-main",children:[s.jsxs("div",{className:"chat-thread",ref:xo,role:"log","aria-live":"polite",children:[n.length===0?s.jsxs("div",{className:"empty-state",children:[s.jsx("p",{className:"empty-state-title",children:"Say anything — the agent decides what to do (answer, fix code, plan, run the pipeline)."}),s.jsxs("div",{className:"empty-state-chips",children:[s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("what's the state of this project?"),children:"📋 assess this project"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("run the test suite"),children:"🧪 run the tests"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("stop the gateway"),children:"⏹ stop the gateway"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("load the code-assessment skill and assess this project"),children:"🧠 load the code-assessment skill"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("learn the workflow I just did as a skill"),children:"📚 learn a workflow as a skill"}),s.jsx("button",{type:"button",className:"chat-chip",onClick:()=>void Ct("publish the current version"),children:"🚀 publish the release"})]})]}):n.map((D,Z)=>s.jsxs("div",{className:`chat-bubble chat-${D.role}${D.error?" chat-error":""}`,children:[s.jsx("div",{className:"chat-bubble-role",children:D.role==="user"?"You":"🤖 Agent"}),D.role==="assistant"?s.jsx("div",{className:"chat-bubble-text",children:s.jsx(RN,{text:D.content})}):s.jsx("div",{className:"chat-bubble-text",children:D.content}),D.role==="user"&&D.attachments&&D.attachments.length>0?s.jsxs("details",{className:"chat-steps",open:D.attachments.length===1,children:[s.jsxs("summary",{children:["📎 ",D.attachments.length," attachment",D.attachments.length===1?"":"s",":"," ",D.attachments.map(Q=>Q.name).join(", ")]}),D.attachments.map((Q,ke)=>s.jsxs("div",{className:"chat-attach-content",children:[s.jsxs("div",{className:"admin-hint",children:[Q.name," — ",Q.content.length.toLocaleString()," chars"]}),s.jsx("pre",{children:Q.content})]},ke))]}):null,D.role==="assistant"&&D.diff?s.jsxs("details",{className:"chat-steps",open:!0,children:[s.jsxs("summary",{children:["Changes: ",D.diff.summary]}),s.jsx(jd,{diff:D.diff,selectable:!0,onCommitAccepted:Ou})]}):null,D.role==="assistant"&&D.artifacts&&(D.artifacts.diffs.length>0||D.artifacts.results.length>0||D.artifacts.deploys.length>0)?s.jsxs(Nge,{children:[D.artifacts.diffs.map((Q,ke)=>s.jsx("div",{"data-artifact-card":!0,tabIndex:0,role:"group","aria-label":`Diff: ${Q.summary}`,className:"chat-artifact-item",children:Me?s.jsx(jd,{diff:Q,selectable:!0,onCommitAccepted:Ou}):s.jsx(jd,{diff:Q,lockedHint:"Attach a project to review and commit these changes."})},`diff-${ke}`)),D.artifacts.results.map((Q,ke)=>s.jsx("div",{"data-artifact-card":!0,tabIndex:0,role:"group","aria-label":`Result: ${Q.title}`,className:"chat-artifact-item",children:s.jsx(_ge,{result:Q})},`result-${ke}`)),D.artifacts.deploys.map((Q,ke)=>s.jsx("div",{"data-artifact-card":!0,tabIndex:0,role:"group","aria-label":`Deployment: ${Q.url}`,className:"chat-artifact-item",children:s.jsx(Ege,{deploy:Q})},`deploy-${ke}`))]}):null,D.role==="assistant"&&D.task?s.jsx(jge,{task:D.task,onCancel:D.task.status==="running"?()=>void Uh(D.task.id):void 0}):null,D.role==="assistant"&&D.draft?s.jsxs("details",{className:"chat-steps",open:!0,children:[s.jsxs("summary",{children:["Skill draft: ",D.draft.name]}),s.jsx(FN,{draft:D.draft,onAccept:ko,onReject:Xr,onEdit:_o})]}):null,D.role==="assistant"&&D.plan?s.jsxs("details",{className:"chat-steps",open:!0,children:[s.jsxs("summary",{children:["Plan: ",D.plan.goal]}),s.jsx(UN,{plan:D.plan})]}):null,D.role==="assistant"&&D.tools&&D.tools.length>0?s.jsxs("details",{className:"chat-steps",open:!0,children:[s.jsxs("summary",{children:[D.tools.length," tool call",D.tools.length===1?"":"s"]}),s.jsx(WN,{tools:D.tools})]}):null,D.role==="assistant"&&D.steps&&D.steps.length>0?s.jsxs("details",{className:"chat-steps",children:[s.jsxs("summary",{children:[D.steps.length," step",D.steps.length===1?"":"s"]}),s.jsx("div",{className:"chat-step-line",children:D.steps.map((Q,ke)=>s.jsx("div",{children:Q.trim()},ke))})]}):null]},Z)),o?s.jsxs("div",{className:"chat-bubble chat-assistant",children:[s.jsx("div",{className:"chat-bubble-role",children:"🤖 Agent"}),v?s.jsx(UN,{plan:v}):null,b?s.jsx(jd,{diff:b}):null,_?s.jsx(FN,{draft:_,onAccept:ko,onReject:Xr,onEdit:_o}):null,w.map(D=>s.jsx(Age,{request:D,onSave:Eo},D.skillName)),N.map((D,Z)=>s.jsx(Tge,{result:D},`${D.skillName}-${Z}`)),s.jsx(WN,{tools:g,live:!0}),U?s.jsx("div",{className:"chat-bubble-text chat-streaming",children:s.jsx(RN,{text:U})}):null,s.jsx("div",{className:"chat-working",children:p.length>0?s.jsx("span",{className:"chat-working-lines",children:p.map((D,Z)=>s.jsx("div",{className:"chat-step-line",children:D.trim()},Z))}):s.jsxs(s.Fragment,{children:["💭 thinking… ",s.jsx("span",{className:"chat-dots"})]})})]}):null]}),c?s.jsx("div",{className:"admin-row-msg admin-row-msg-err",children:c}):null,V&&!o?s.jsxs("div",{className:"chat-retry-row",children:[s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void Ct(V),children:"↻ Retry"}),s.jsx("span",{className:"admin-hint",children:"Re-send the last message — the turn failed."})]}):null,C&&!o?s.jsx("div",{className:"chat-resolve-card",children:(Mu=C.top)!=null&&Mu.ambiguous&&((Ru=C.top.options)!=null&&Ru.length)?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"chat-resolve-head",children:[s.jsx("strong",{children:"🤔 Which do you mean?"}),' — "',C.ask,'" maps to more than one action.']}),s.jsx("div",{className:"chat-resolve-options",children:C.top.options.map(D=>s.jsxs("button",{className:"chat-chip",type:"button",onClick:()=>void Ct(D.command),children:[D.summary," — ",s.jsx("code",{children:D.command})]},D.command))}),s.jsx("div",{className:"chat-resolve-foot",children:s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:()=>{I(null)},children:"✕ Not that — ask the agent"})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"chat-resolve-head",children:[s.jsx("strong",{children:"⚡ Run this command?"}),' — "',C.ask,'"']}),s.jsx("div",{className:"chat-resolve-cmd",children:s.jsx("code",{children:(xa=C.top)==null?void 0:xa.command})}),(Iu=C.top)!=null&&Iu.confirmation?s.jsx("div",{className:"admin-hint",children:"⚠ This changes running services/state."}):null,s.jsxs("div",{className:"chat-resolve-foot",children:[s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void Cu(C.ask),children:"▶ Run"}),s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:()=>ji(C.ask),children:"✕ No — ask the agent"})]})]})}):null,Gt?s.jsxs("div",{className:"chat-resolve-card chat-question-card",children:[s.jsx("div",{className:"chat-resolve-head",children:s.jsxs("strong",{children:["🤔 ",Gt.question]})}),s.jsx("div",{className:"chat-resolve-options",children:Gt.choices.map((D,Z)=>s.jsxs("button",{type:"button",className:`chat-chip${va.has(Z)?" chat-chip-selected":""}`,onClick:()=>Hh(Z),children:[D.label,D.description?s.jsxs("span",{className:"admin-hint",children:[" — ",D.description]}):null]},`${D.label}-${Z}`))}),s.jsxs("div",{className:"chat-resolve-foot",children:[s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:Jt,children:Gt.multiSelect?"Submit":"Choose"}),s.jsx("button",{className:"admin-mini-btn",type:"button",onClick:Wh,children:"Skip — best judgment"})]})]}):null,Ai.length>0&&!o?s.jsxs("div",{className:"chat-followups",children:[s.jsx("span",{className:"admin-hint",children:"Next steps:"}),Ai.map((D,Z)=>s.jsx("button",{className:"chat-chip",type:"button",onClick:()=>void Ct(D.prompt),children:D.label||D.prompt},Z))]}):null,s.jsxs("form",{className:`chat-composer${Tt?" chat-composer-drag":""}`,onSubmit:D=>{D.preventDefault(),Ct(i)},onDragOver:D=>{D.preventDefault(),Fe(!0)},onDragLeave:()=>Fe(!1),onDrop:D=>{var Q;D.preventDefault(),Fe(!1);const Z=Array.from(((Q=D.dataTransfer)==null?void 0:Q.files)??[]);for(const ke of Z.slice(0,10))Nu(ke)},children:[De?s.jsxs("div",{className:"chat-paste-offer",children:[s.jsxs("span",{className:"admin-hint",children:["📄 You pasted ",De.text.length.toLocaleString()," characters. Attach it as a file instead?"]}),s.jsx("button",{type:"button",className:"chat-chip",onClick:zh,children:"Attach as text"}),s.jsx("button",{type:"button",className:"chat-mini-action",onClick:()=>{le(null),lt.current=null},children:"Keep inline"})]}):null,Se.length>0?s.jsx("div",{className:"chat-attach-row",children:Se.map((D,Z)=>s.jsxs("span",{className:"chat-attach-chip",title:`${D.name} (${D.content.length.toLocaleString()} chars)`,children:["📎 ",D.name,s.jsxs("span",{className:"admin-hint",children:[" ",D.content.length.toLocaleString(),"c"]}),s.jsx("button",{type:"button",className:"chat-mini-action",onClick:()=>cl(Z),children:"✕"})]},`${D.name}-${Z}`))}):null,s.jsxs("div",{className:"chat-input-row",children:[s.jsx("input",{ref:Te,type:"file",style:{display:"none"},onChange:D=>{var Q;const Z=(Q=D.target.files)==null?void 0:Q[0];Z&&Nu(Z),D.target.value=""}}),s.jsx("button",{type:"button",className:"chat-attach-btn",title:"Attach a file (up to 300 KB, text only)",disabled:o||Se.length>=10,onClick:()=>{var D;return(D=Te.current)==null?void 0:D.click()},children:"📎"}),s.jsx("textarea",{className:"chat-input-box",value:i,onChange:D=>a(D.target.value),onPaste:ju,onKeyDown:D=>{D.key==="Enter"&&!D.shiftKey?(D.preventDefault(),Ct(i)):D.key==="ArrowUp"&&i===""&&ce.current&&(D.preventDefault(),a(ce.current))},placeholder:"Message the agent… (Enter to send · Shift+Enter for a new line · ↑ recalls last · 📎 attach a file or paste a large document)",disabled:o,maxLength:8e3,rows:1,autoFocus:!0}),o?s.jsx("button",{className:"admin-mini-btn chat-cancel-btn",type:"button",onClick:Ni,children:"⏹ Cancel"}):null,s.jsx("button",{className:"admin-refresh-btn",type:"submit",disabled:o||!i.trim()&&Se.length===0,children:o?"⏳ Working…":"➤ Send"})]})]}),s.jsxs("p",{className:"admin-hint",children:["Each message runs the full agent loop in the dashboard process (same engine as"," ",s.jsx("code",{children:'buff chat "<prompt>"'}),") — the provider API keys must be configured in the dashboard process. Clarifications (",s.jsx("code",{children:"ask_user"}),") appear as a question card here — choose an answer or skip (best judgment)."]})]})]})]}):s.jsx("div",{className:"admin-login-hint",children:s.jsx("p",{children:"Your role can view the dashboard but not chat (requires admin or operator)."})}):s.jsxs("div",{className:"admin-login-hint",children:[s.jsx("p",{children:"Log in (admin or operator) to chat with the agent. Configure the dashboard admin credential first if this is a fresh setup."}),(e==null?void 0:e.configured)===!1?s.jsxs("p",{className:"admin-hint",children:["Run ",s.jsx("code",{children:"buff dashboard"})," once, or set ",s.jsx("code",{children:"BUFF_DASHBOARD_ADMIN_USER"})," / ",s.jsx("code",{children:"BUFF_DASHBOARD_ADMIN_PASSWORD"}),"."]}):null]})]})}const Pge={running:"⏳ running",done:"✅ done",failed:"❌ failed",cancelled:"⏹ cancelled",timeout:"⏰ timed out",error:"💥 error"};function ZR({presets:e,customPlaceholder:t,timeoutMs:n=3e5,hint:r}){const[i,a]=E.useState(null),[o,l]=E.useState(!1),[c,u]=E.useState(""),[d,f]=E.useState(""),[p,h]=E.useState(null),[g,m]=E.useState([]),v=E.useRef(null),y=E.useRef(null);E.useEffect(()=>{ee.fetchAdminAuthStatus().then(S=>{a(S?{authenticated:S.authenticated,role:S.role}:{authenticated:!1,role:null})})},[]),E.useEffect(()=>{var S,w;try{(w=(S=v.current)==null?void 0:S.scrollIntoView)==null||w.call(S,{block:"end"})}catch{}},[g]),E.useEffect(()=>()=>{var S;(S=y.current)==null||S.call(y)},[]);const b=(i==null?void 0:i.authenticated)===!0&&(i.role==="admin"||i.role==="operator"),x=E.useCallback(async(S,w)=>{var C;if(o)return;l(!0),u(""),m([]);const k=await ee.startTask(S,w??n);if(!k.ok||!k.task){u(k.error||"Could not start the command."),l(!1);return}const N=k.task;h(N);const j=await ee.getTask(N.id);j!=null&&j.task&&m(j.task.logs.map(I=>({stream:I.stream,text:I.text}))),(C=y.current)==null||C.call(y),y.current=ee.subscribeTask(N.id,{onLog:I=>m(M=>[...M,{stream:I.stream,text:I.text}]),onStatus:I=>{h(M=>M&&{...M,status:I}),I!=="running"&&l(!1)}})},[o,n]),_=E.useCallback(async()=>{p&&await ee.cancelTask(p.id)},[p]);return s.jsxs("div",{className:"ops-console",children:[i!=null&&i.authenticated?b?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"ops-presets",children:e.map(S=>s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void x(S.args,S.timeoutMs),disabled:o,children:S.label},S.label))}),s.jsxs("div",{className:"ops-custom-row",children:[s.jsx("input",{type:"text",value:d,onChange:S=>f(S.target.value),placeholder:t,disabled:o,maxLength:160}),s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void x(d.trim().split(/\s+/)),disabled:o||!d.trim(),children:"Run"})]}),r?s.jsx("p",{className:"admin-hint",children:r}):null]}):s.jsx("div",{className:"admin-login-hint",children:"Your role can view but not run commands (requires admin or operator)."}):s.jsx("div",{className:"admin-login-hint",children:"Log in (admin or operator) to run commands."}),c?s.jsx("div",{className:"admin-row-msg admin-row-msg-err",children:c}):null,p?s.jsxs("div",{className:"ops-console-box",children:[s.jsxs("div",{className:"ops-console-head",children:[s.jsxs("span",{children:[p.command," · ",s.jsx("span",{className:p.status==="running"?"task-status-running":"",children:Pge[p.status]})]}),p.status==="running"?s.jsx("button",{className:"admin-refresh-btn",type:"button",onClick:()=>void _(),children:"⏹ Cancel"}):null]}),s.jsxs("pre",{className:"ops-console",role:"log",children:[g.length>0?g.map((S,w)=>s.jsx("div",{children:S.text},w)):s.jsx("div",{className:"admin-hint",children:"Waiting for output…"}),s.jsx("div",{ref:v})]})]}):null]})}const Mge=[{label:"⚡ Quick smoke",args:["eval","run","--tasks","quick","--format","text"]},{label:"⏱ Medium suite",args:["eval","run","--tasks","medium","--format","text"]},{label:"🐢 Slow suite",args:["eval","run","--tasks","slow","--format","text"]},{label:"🏆 M2B parity",args:["eval","run","--suite","m2b","--format","text"]},{label:"📦 Full suite",args:["eval","run","--suite","full","--format","text"]}];function GN(e){return typeof e!="number"?"—":`${Math.round(e*100)}%`}function Rge(e){return new Date(e).toLocaleString()}function Ige({data:e}){var n;const t=((n=e==null?void 0:e.evals)==null?void 0:n.runs)??[];return s.jsxs("div",{className:"panel",children:[s.jsx("div",{className:"panel-header",children:s.jsx("h2",{children:"🏆 Evals — run buff eval from the GUI"})}),s.jsx(ZR,{presets:Mge,customPlaceholder:"e.g. eval run --tasks my-task --provider groq --model llama",timeoutMs:9e5,hint:s.jsxs(s.Fragment,{children:["Runs the real ",s.jsx("code",{children:"buff eval run"})," as an isolated process — same engine, same ledger, same results as the CLI. Long suites can take minutes; you can cancel mid-run."]})}),s.jsx("h3",{className:"section-subtitle",children:"📜 Past runs (auto-refreshes)"}),t.length>0?s.jsx("div",{className:"admin-table-wrapper",children:s.jsxs("table",{className:"admin-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Started"}),s.jsx("th",{children:"Provider"}),s.jsx("th",{children:"Model"}),s.jsx("th",{children:"Tasks"}),s.jsx("th",{children:"Pass"}),s.jsx("th",{children:"Completion"}),s.jsx("th",{children:"Composite"}),s.jsx("th",{children:"Cost"})]})}),s.jsx("tbody",{children:t.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:Rge(r.startedAt)}),s.jsx("td",{className:"admin-provider-type",children:r.provider}),s.jsx("td",{children:r.model}),s.jsx("td",{children:r.summary.totalTasks}),s.jsxs("td",{children:[r.summary.tasksPassed,"/",r.summary.totalTasks]}),s.jsx("td",{children:GN(r.summary.completionRate)}),s.jsx("td",{children:GN(r.summary.avgCompositeScore)}),s.jsxs("td",{children:["$",(r.summary.totalCostUsd??0).toFixed(4)]})]},r.id))})]})}):s.jsx("div",{className:"empty-state",children:"No eval runs yet — start one above (or `buff eval run` from the CLI)."})]})}const $ge=[{label:"🌐 Gateway status",args:["gateway","status"]},{label:"📮 Delivery ledger",args:["gateway","delivery"]},{label:"▶️ Start gateway (foreground)",args:["gateway","start","--no-events"],timeoutMs:0},{label:"⏰ Cron jobs",args:["admin","cron","list"]}];function Lge(){return s.jsxs("div",{className:"panel",children:[s.jsx("div",{className:"panel-header",children:s.jsx("h2",{children:"🌐 Gateway ops — run buff gateway from the GUI"})}),s.jsx(ZR,{presets:$ge,customPlaceholder:"e.g. admin cron run nightly or gateway alias add ops email:team@example.com",timeoutMs:3e5,hint:s.jsxs(s.Fragment,{children:["Each command runs as the real CLI in an isolated process (the P1 task runner) — the same engine as your terminal. ",s.jsx("code",{children:"gateway start"})," runs in the foreground ",s.jsx("strong",{children:"with no timeout"}),": it keeps running even after you switch tabs (the process lives on the dashboard server, not the page) and streams platform events until you press ",s.jsx("strong",{children:"Cancel"}),". The delivery ledger also has its own view in"," ",s.jsx("strong",{children:"Agent Hub → Channels"}),"."]})})]})}const Sg={telegram:{icon:"✈️",category:"Chat",steps:["Open Telegram and search for @BotFather","Send /newbot and follow the prompts",'Give your bot a name (e.g. "My Agent Bot")','Give your bot a username ending in "bot"',"BotFather gives you a token — paste it in Step 2","Open your bot in Telegram and send /start"],testTarget:"telegram:"},discord:{icon:"🎮",category:"Chat",steps:["Go to discord.com/developers/applications",'Click "New Application" and give it a name','Go to Bot tab and click "Add Bot"',"Copy the bot token",'Enable "Message Content Intent"',"Invite bot to your server (OAuth2 URL generator)"],testTarget:"discord:"},slack:{icon:"💬",category:"Chat",steps:["Go to api.slack.com/apps","Create New App from scratch","Add Bot Token Scopes: chat:write, im:read, im:write","Install to workspace","Copy the Bot User OAuth Token (xoxb-...)"],testTarget:"slack:"},whatsapp:{icon:"📱",category:"Chat",steps:["Run: buff whatsapp pair (or from Gateway tab)","Scan the QR code with WhatsApp","Pairing completes automatically"],testTarget:""},whatsapp_cloud:{icon:"☁️",category:"Chat",steps:["Go to developers.facebook.com","Set up WhatsApp Cloud API","Copy token + Phone ID"],testTarget:"whatsapp_cloud:"},email:{icon:"📧",category:"Chat",steps:["Get SMTP credentials (Gmail, SendGrid, etc.)","For Gmail: use App Password at smtp.gmail.com:587","Paste SMTP host + user below"],testTarget:""},signal:{icon:"🔒",category:"Chat",steps:["Run signal-cli-rest-api Docker container","Register a Signal account","Paste account number below"],testTarget:""},dingtalk:{icon:"🔔",category:"Webhooks",steps:["Open DingTalk and create a group","Add custom robot and copy webhook URL","Paste URL below"],testTarget:""},feishu:{icon:"🐦",category:"Webhooks",steps:["Open Feishu and create a bot","Copy webhook URL and paste below"],testTarget:""},wecom:{icon:"🏢",category:"Webhooks",steps:["Open WeCom and create a group bot","Copy webhook URL and paste below"],testTarget:""},mattermost:{icon:"📋",category:"Webhooks",steps:["Open Mattermost, go to Integrations","Create incoming webhook and copy URL"],testTarget:""},matrix:{icon:"🔗",category:"Chat",steps:["Get your Matrix homeserver URL","Create a bot user and get access token","Paste URL + token below"],testTarget:""},webhook:{icon:"🪝",category:"Webhooks",steps:["Enter your webhook URL","The agent sends outbound webhooks to this URL"],testTarget:""},bluebubbles:{icon:"💙",category:"Chat",steps:["Set up BlueBubbles server","Copy server URL + password"],testTarget:""},ntfy:{icon:"📢",category:"Notifications",steps:["Choose an ntfy topic (or use ntfy.sh)","Paste the topic below"],testTarget:""},teams:{icon:"👥",category:"Webhooks",steps:["Open Microsoft Teams, go to channel","Connectors, Incoming Webhook, create","Copy webhook URL"],testTarget:""},google_chat:{icon:"💬",category:"Webhooks",steps:["Open Google Chat, space settings","Create webhook and copy URL"],testTarget:""},weixin:{icon:"🔴",category:"Chat",steps:["Get Weixin iLink bot token","Paste token below"],testTarget:""},sms:{icon:"📲",category:"Chat",steps:["Get Twilio account SID + auth token","Register a phone number","Paste credentials below"],testTarget:""},irc:{icon:"💻",category:"Chat",steps:["Choose an IRC server (e.g. irc.libera.chat)","Set nickname + channel and paste below"],testTarget:""},simplex:{icon:"📨",category:"Chat",steps:["Run local simplex-chat daemon","Paste WebSocket URL (ws://127.0.0.1:5225)"],testTarget:""},homeassistant:{icon:"🏠",category:"IoT",steps:["Open Home Assistant Profile","Create long-lived access token and paste below"],testTarget:""}};function Dge(){const[e,t]=E.useState(null),[n,r]=E.useState("all"),[i,a]=E.useState(null),[o,l]=E.useState(0),[c,u]=E.useState({}),[d,f]=E.useState(!1),[p,h]=E.useState(null),[g,m]=E.useState({status:"idle"}),[v,y]=E.useState(""),[b,x]=E.useState("Hello from agent-nuvira!"),[_,S]=E.useState(!1),[w,k]=E.useState(null),N=E.useRef(!0),j=E.useCallback(async()=>{const O=await ee.getPlatformConfigs();N.current&&t(O)},[]);E.useEffect(()=>(j(),()=>{N.current=!1}),[j]);const C=O=>{a(O),l(0),u(Object.fromEntries(O.envVars.map(T=>[T.varName,T.value]))),h(null),m({status:"idle"});const z=Sg[O.platform];y((z==null?void 0:z.testTarget)??""),x("Hello from agent-nuvira!"),k(null)},I=async()=>{if(!i)return;m({status:"checking"});const O=await ee.verifyPlatformConfig(i.platform,c);O.ok?(m({status:"ok",info:O.info}),h({kind:"ok",text:"Verified! "+(O.info?"Connected as "+O.info+".":"Token is valid.")})):(m({status:"err",error:O.error}),h({kind:"err",text:O.error||"Verification failed."}))},M=async()=>{if(!i)return;f(!0),h(null);const O=await ee.setPlatformConfig(i.platform,c);f(!1),O.ok?(h({kind:"ok",text:"Token saved! Verifying..."}),j(),l(2),I()):h({kind:"err",text:O.error||"Save failed."})},$=async()=>{if(!i||!v)return;S(!0),k(null);const O=await ee.sendChannelMessage(v,b);S(!1),O.ok?k({kind:"ok",text:"Message sent via "+O.platform+"! Check your "+i.label+" app."}):k({kind:"err",text:O.error||"Send failed. Make sure the gateway is running (Gateway tab)."})};if(e===null)return s.jsx("div",{className:"empty-state",children:"Loading platforms..."});const R=e.filter(O=>O.configured).length,B=e.filter(O=>n==="configured"?O.configured:n==="unconfigured"?!O.configured:!0),L=i?Sg[i.platform]:null;function U(O){return o===O?"wizard-step-dot active":"wizard-step-dot"}return s.jsxs("div",{className:"panel",children:[s.jsx("div",{className:"panel-header",children:s.jsx("h2",{children:"Platforms — Messaging Gateway Onboarding"})}),s.jsxs("div",{className:"platforms-summary",children:[s.jsxs("div",{className:"platforms-summary-stat",children:[s.jsx("span",{className:"platforms-summary-number",children:R}),s.jsx("span",{className:"platforms-summary-label",children:"configured"})]}),s.jsxs("div",{className:"platforms-summary-stat",children:[s.jsx("span",{className:"platforms-summary-number",children:e.length-R}),s.jsx("span",{className:"platforms-summary-label",children:"available"})]}),s.jsx("div",{className:"platforms-summary-filters",children:["all","configured","unconfigured"].map(O=>s.jsx("button",{type:"button",className:n===O?"platforms-filter-btn active":"platforms-filter-btn",onClick:()=>r(O),children:O==="all"?"All":O==="configured"?"Configured":"Not set up"},O))})]}),s.jsx("div",{className:"platforms-grid",children:B.map(O=>{const z=Sg[O.platform];return s.jsxs("div",{className:O.configured?"platform-card configured":"platform-card",children:[s.jsxs("div",{className:"platform-card-head",children:[s.jsx("span",{className:"platform-card-icon",children:(z==null?void 0:z.icon)??"🔌"}),s.jsxs("div",{className:"platform-card-info",children:[s.jsx("span",{className:"platform-card-name",children:O.label}),s.jsx("span",{className:"platform-card-category",children:(z==null?void 0:z.category)??"Platform"})]}),s.jsx("span",{className:O.configured?"status-dot connected":"status-dot reconnecting"})]}),s.jsx("div",{className:"platform-card-vars",children:O.envVars.map(T=>s.jsxs("span",{className:T.set?"platform-var-chip set":"platform-var-chip",children:[T.varName," ",T.set?"done":"--"]},T.varName))}),s.jsxs("div",{className:"platform-card-actions",children:[O.configured?s.jsx("span",{className:"platform-card-badge",children:"Active"}):s.jsx("button",{type:"button",className:"wizard-start-btn",onClick:()=>C(O),children:"Setup"}),O.setupUrl?s.jsx("a",{href:O.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"admin-mini-btn platform-docs-link",children:"Docs"}):null]}),!O.configured&&O.setupHint?s.jsx("div",{className:"platform-card-hint",children:O.setupHint}):null]},O.platform)})}),s.jsxs("div",{className:"platforms-cli-hint",children:[s.jsx("span",{className:"admin-hint",children:"Prefer the terminal? "}),s.jsx("code",{children:"buff gateway setup telegram"}),s.jsx("span",{className:"admin-hint",children:" — same wizard from your CLI"})]}),i&&L?s.jsx("div",{className:"wizard-overlay",onClick:()=>a(null),children:s.jsxs("div",{className:"wizard-modal",onClick:O=>O.stopPropagation(),children:[s.jsxs("div",{className:"wizard-header",children:[s.jsx("span",{className:"wizard-icon",children:L.icon}),s.jsxs("span",{className:"wizard-title",children:["Getting Started: ",i.label]}),s.jsxs("div",{className:"wizard-steps-indicator",children:[s.jsx("span",{className:U(0),children:"1"}),s.jsx("span",{className:U(1),children:"2"}),s.jsx("span",{className:U(2),children:"3"})]}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>a(null),children:"X"})]}),s.jsxs("div",{className:"wizard-body",children:[o===0&&s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"wizard-section-title",children:["Step 1: Create your bot on ",i.label]}),s.jsx("ol",{className:"wizard-steps",children:L.steps.map((O,z)=>s.jsx("li",{children:O},z))}),s.jsxs("div",{className:"wizard-nav",children:[s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>l(1),children:"I have my token — Step 2"}),i.setupUrl?s.jsx("a",{href:i.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"admin-mini-btn platform-docs-link",children:"Open docs"}):null]})]}),o===1&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"wizard-section-title",children:"Step 2: Paste your token"}),i.envVars.map(O=>s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:O.prompt}),s.jsx("input",{type:O.secret?"password":"text",value:c[O.varName]??"",onChange:z=>u(T=>({...T,[O.varName]:z.target.value})),placeholder:O.secret?"paste your token here":"value",autoComplete:"off",spellCheck:!1,autoFocus:!0})]},O.varName)),p?s.jsx("div",{className:p.kind==="ok"?"admin-row-msg":"admin-row-msg admin-row-msg-err",children:p.text}):null,s.jsxs("div",{className:"wizard-nav",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>l(0),children:"Back"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void M(),disabled:d,children:d?"Saving...":"Save & Verify"})]})]}),o===2&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"wizard-section-title",children:"Step 3: Verify and test"}),g.status==="checking"&&s.jsx("div",{className:"wizard-verify-status",children:"Verifying token..."}),g.status==="ok"&&s.jsxs("div",{className:"wizard-verify-status ok",children:["Connected as ",g.info]}),g.status==="err"&&s.jsx("div",{className:"wizard-verify-status err",children:g.error}),g.status==="idle"&&(p==null?void 0:p.kind)==="ok"&&s.jsx("div",{className:"wizard-verify-status ok",children:p.text}),v&&s.jsxs("div",{className:"wizard-test-section",children:[s.jsx("p",{className:"wizard-section-title",children:"Send a test message:"}),s.jsx("div",{className:"wizard-test-row",children:s.jsx("input",{className:"wizard-test-input",value:v,onChange:O=>y(O.target.value),placeholder:"telegram:YOUR_CHAT_ID"})}),s.jsxs("div",{className:"wizard-test-row",children:[s.jsx("input",{className:"wizard-test-input",value:b,onChange:O=>x(O.target.value),placeholder:"Hello from agent-nuvira!"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void $(),disabled:_||!v,children:_?"Sending...":"Send test"})]}),w?s.jsx("div",{className:w.kind==="ok"?"admin-row-msg":"admin-row-msg admin-row-msg-err",children:w.text}):null]}),s.jsxs("div",{className:"wizard-nav",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>l(1),children:"Edit token"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>a(null),children:"Done"})]}),!v&&s.jsxs("p",{className:"wizard-hint",children:["Token saved! Start the gateway from the Gateway tab, then send a message from your ",i.label," app."]})]})]})]})}):null]})}const Bge=[{value:"us-east-1",label:"us-east-1 (N. Virginia) — most models"},{value:"us-west-2",label:"us-west-2 (Oregon) — most models"},{value:"eu-west-1",label:"eu-west-1 (Ireland) — EU coverage"},{value:"ap-southeast-1",label:"ap-southeast-1 (Singapore)"},{value:"ap-northeast-1",label:"ap-northeast-1 (Tokyo)"}],qN=[{name:"Anthropic Claude",models:["claude-haiku-4.5","claude-sonnet-4.6","claude-fable-5","claude-opus-4.6"],checked:!0},{name:"Meta Llama",models:["llama3-1-8b","llama3-1-70b","llama3-3-70b","llama4-scout","llama4-maverick"],checked:!0},{name:"Mistral AI",models:["mistral-large-3","devstral-2","ministral-3"],checked:!1},{name:"DeepSeek",models:["deepseek-v3.2","deepseek-r1"],checked:!1},{name:"Amazon Nova",models:["nova-pro","nova-lite"],checked:!1},{name:"OpenAI on Bedrock",models:["gpt-5.6-terra","gpt-oss-120b"],checked:!1},{name:"Qwen",models:["qwen3-coder-next","qwen3-32b"],checked:!1},{name:"Google Gemma",models:["gemma-3-12b"],checked:!1},{name:"xAI",models:["grok-4.6"],checked:!1}];function zge({canWrite:e,sessionExpired:t}){const[n,r]=E.useState(null),[i,a]=E.useState(null),[o,l]=E.useState(!1),[c,u]=E.useState("overview"),d=E.useRef(!0),[f,p]=E.useState("bearer"),[h,g]=E.useState(""),[m,v]=E.useState(""),[y,b]=E.useState(""),[x,_]=E.useState("us-east-1"),[S,w]=E.useState(qN.filter(R=>R.checked).map(R=>R.name)),[k,N]=E.useState(!1),[j,C]=E.useState(null),I=E.useCallback(async()=>{const R=await ee.getBedrockStatus();d.current&&r(R)},[]);E.useEffect(()=>(I(),()=>{d.current=!1}),[I]);const M=async()=>{l(!0),a(null);try{const R=await ee.probeBedrock((n==null?void 0:n.region)||"us-east-1");if(!d.current)return;R.ok&&R.models&&(a(R.models),u("test"))}catch{}finally{d.current&&l(!1)}},$=async()=>{N(!0),C(null);try{const R={BEDROCK_REGION:x};f==="bearer"&&h?R.AWS_BEARER_TOKEN=h:f==="iam"&&(m&&(R.AWS_ACCESS_KEY_ID=m),y&&(R.AWS_SECRET_ACCESS_KEY=y));const B=await ee.setupBedrock(R);if(!d.current)return;B.ok?(C({kind:"ok",text:"✅ Configuration saved! Running connectivity test…"}),u("overview"),await I(),setTimeout(()=>void M(),500)):C({kind:"err",text:B.error||"Save failed"})}catch{d.current&&C({kind:"err",text:"Could not reach the dashboard server."})}finally{d.current&&N(!1)}};return n===null?s.jsx("div",{className:"empty-state",children:"Loading Bedrock status…"}):s.jsxs("div",{className:"bedrock-onboarding",children:[s.jsx("h2",{className:"section-title",children:"🟠 AWS Bedrock"}),s.jsxs("p",{className:"admin-subtitle",children:["Bedrock gives you access to Claude, Llama, Mistral, DeepSeek, and more — all through a single AWS account. Unlike other providers, Bedrock requires a ",s.jsx("strong",{children:"region"}),", ",s.jsx("strong",{children:"AWS credentials"}),", and explicit ",s.jsx("strong",{children:"model access approval"}),"."]}),j?s.jsx("div",{className:`admin-row-msg${j.kind==="ok"?"":" admin-row-msg-err"}`,children:j.text}):null,s.jsxs("div",{className:"bedrock-status-bar",children:[s.jsxs("div",{className:"bedrock-status-item",children:[s.jsx("span",{className:`status-dot ${n.configured?"connected":"reconnecting"}`}),s.jsx("span",{children:n.configured?"Configured":"Not configured"})]}),s.jsxs("div",{className:"bedrock-status-item",children:[s.jsx("span",{className:"bedrock-status-label",children:"Region:"}),s.jsx("code",{children:n.region})]}),s.jsxs("div",{className:"bedrock-status-item",children:[s.jsx("span",{className:"bedrock-status-label",children:"Auth:"}),s.jsx("code",{children:n.authMethod==="bearer"?"API Key":n.authMethod==="iam"?"IAM":"None"})]}),s.jsxs("div",{className:"bedrock-status-actions",children:[e?s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>u(c==="setup"?"overview":"setup"),children:c==="setup"?"✕ Cancel":"⚙ Setup Wizard"}):null,n.configured?s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void M(),disabled:o,children:o?"⏳ Probing…":"🔍 Test Models"}):null]})]}),c==="setup"&&s.jsxs("div",{className:"bedrock-setup-wizard",children:[s.jsx("h3",{className:"section-subtitle",children:"🚀 Bedrock Setup Wizard"}),s.jsxs("div",{className:"bedrock-wizard-step",children:[s.jsx("h4",{children:"Step 1: Authentication"}),s.jsxs("div",{className:"bedrock-auth-options",children:[s.jsxs("label",{className:`bedrock-auth-option ${f==="bearer"?"selected":""}`,children:[s.jsx("input",{type:"radio",name:"authMethod",checked:f==="bearer",onChange:()=>p("bearer")}),s.jsxs("div",{children:[s.jsx("strong",{children:"Bedrock API Key"}),s.jsx("span",{children:"Simpler — get from Bedrock → Settings → API keys"})]})]}),s.jsxs("label",{className:`bedrock-auth-option ${f==="iam"?"selected":""}`,children:[s.jsx("input",{type:"radio",name:"authMethod",checked:f==="iam",onChange:()=>p("iam")}),s.jsxs("div",{children:[s.jsx("strong",{children:"IAM Credentials"}),s.jsx("span",{children:"Full AWS SDK auth — AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY"})]})]})]}),f==="bearer"?s.jsxs("div",{className:"bedrock-wizard-fields",children:[s.jsxs("div",{className:"bedrock-setup-hint",children:[s.jsx("strong",{children:"How to get a Bedrock API key:"}),s.jsxs("ol",{children:[s.jsxs("li",{children:["Open ",s.jsx("a",{href:"https://console.aws.amazon.com/bedrock/",target:"_blank",rel:"noopener noreferrer",children:"AWS Bedrock Console"})]}),s.jsxs("li",{children:["Go to ",s.jsx("strong",{children:"Settings"})," → ",s.jsx("strong",{children:"API keys"})]}),s.jsx("li",{children:"Create a new key and paste it below"})]})]}),s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"Bedrock API Key (Bearer token)"}),s.jsx("input",{type:"password",value:h,onChange:R=>g(R.target.value),placeholder:"••••••••••••",autoComplete:"off",spellCheck:!1})]})]}):s.jsxs("div",{className:"bedrock-wizard-fields",children:[s.jsxs("div",{className:"bedrock-setup-hint",children:[s.jsx("strong",{children:"IAM credentials"})," give full AWS SDK access. Create an IAM user with Bedrock permissions."]}),s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"AWS_ACCESS_KEY_ID"}),s.jsx("input",{type:"text",value:m,onChange:R=>v(R.target.value),placeholder:"AKIA...",autoComplete:"off",spellCheck:!1})]}),s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"AWS_SECRET_ACCESS_KEY"}),s.jsx("input",{type:"password",value:y,onChange:R=>b(R.target.value),placeholder:"••••••••••••",autoComplete:"off",spellCheck:!1})]})]})]}),s.jsxs("div",{className:"bedrock-wizard-step",children:[s.jsx("h4",{children:"Step 2: AWS Region"}),s.jsxs("p",{className:"admin-hint",children:["Models vary by region. ",s.jsx("strong",{children:"us-east-1"})," and ",s.jsx("strong",{children:"us-west-2"})," have the most models. ⚠️ Do NOT use eu-north-1 unless models are explicitly enabled there."]}),s.jsx("select",{className:"bedrock-region-select",value:x,onChange:R=>_(R.target.value),children:Bge.map(R=>s.jsx("option",{value:R.value,children:R.label},R.value))})]}),s.jsxs("div",{className:"bedrock-wizard-step",children:[s.jsx("h4",{children:"Step 3: Model Access"}),s.jsx("p",{className:"admin-hint",children:"Bedrock requires you to request access for each model family."}),s.jsx("div",{className:"bedrock-model-access-hint",children:s.jsx("a",{href:`https://console.aws.amazon.com/bedrock/home?region=${x}#/modelaccess`,target:"_blank",rel:"noopener noreferrer",className:"admin-mini-btn",children:"📖 Open Model Access in AWS Console"})}),s.jsx("div",{className:"bedrock-family-grid",children:qN.map(R=>s.jsxs("label",{className:`bedrock-family-card ${S.includes(R.name)?"selected":""}`,children:[s.jsx("input",{type:"checkbox",checked:S.includes(R.name),onChange:B=>{B.target.checked?w(L=>[...L,R.name]):w(L=>L.filter(U=>U!==R.name))}}),s.jsxs("div",{children:[s.jsx("strong",{children:R.name}),s.jsxs("span",{children:[R.models.length," model(s)"]})]})]},R.name))}),s.jsx("p",{className:"admin-hint",style:{marginTop:8},children:"In the AWS Console, select the families above and submit. Approval is usually instant for Anthropic and Meta models."})]}),s.jsxs("div",{className:"bedrock-wizard-actions",children:[s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void $(),disabled:k||f==="bearer"&&!h||f==="iam"&&(!m||!y),children:k?"⏳ Saving…":"💾 Save & Test"}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>u("overview"),children:"Cancel"})]})]}),c==="test"&&i&&s.jsxs("div",{className:"bedrock-probe-results",children:[s.jsxs("h3",{className:"section-subtitle",children:["🔍 Model Probe Results (",n.region,")"]}),s.jsx("div",{className:"bedrock-probe-grid",children:i.map(R=>s.jsxs("div",{className:`bedrock-probe-card bedrock-probe-${R.status}`,children:[s.jsx("span",{className:"bedrock-probe-icon",children:R.status==="accessible"?"✅":R.status==="permission-denied"?"🔒":R.status==="not-found"?"⚫":"❌"}),s.jsx("span",{className:"bedrock-probe-id",children:R.modelId}),s.jsx("span",{className:"bedrock-probe-status",children:R.status==="accessible"?"Ready":R.status==="permission-denied"?`Need access (HTTP ${R.httpStatus})`:R.status==="not-found"?"Not in this region":"Error"})]},R.modelId))}),i.some(R=>R.status==="permission-denied")&&s.jsxs("div",{className:"bedrock-probe-action",children:[s.jsxs("p",{children:["Some models exist in ",n.region," but access is not approved."]}),s.jsx("a",{href:`https://console.aws.amazon.com/bedrock/home?region=${n.region}#/modelaccess`,target:"_blank",rel:"noopener noreferrer",className:"admin-mini-btn",children:"🔓 Request Model Access in AWS Console →"})]}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>u("overview"),style:{marginTop:12},children:"← Back"})]}),!n.configured&&c==="overview"&&s.jsxs("div",{className:"bedrock-getting-started",children:[s.jsx("h3",{className:"section-subtitle",children:"📋 Getting Started with Bedrock"}),s.jsxs("div",{className:"bedrock-steps",children:[s.jsxs("div",{className:"bedrock-step",children:[s.jsx("span",{className:"bedrock-step-num",children:"1"}),s.jsxs("div",{children:[s.jsx("strong",{children:"Create an AWS account"})," (or use existing)",s.jsxs("span",{children:["New to AWS? Sign up at ",s.jsx("a",{href:"https://aws.amazon.com/",target:"_blank",rel:"noopener noreferrer",children:"aws.amazon.com"})]})]})]}),s.jsxs("div",{className:"bedrock-step",children:[s.jsx("span",{className:"bedrock-step-num",children:"2"}),s.jsxs("div",{children:[s.jsx("strong",{children:"Get Bedrock API key"}),s.jsx("span",{children:"Bedrock → Settings → API keys → Create key"})]})]}),s.jsxs("div",{className:"bedrock-step",children:[s.jsx("span",{className:"bedrock-step-num",children:"3"}),s.jsxs("div",{children:[s.jsx("strong",{children:"Request model access"}),s.jsx("span",{children:"Bedrock → Model access → Select Claude, Llama, etc. → Submit"})]})]}),s.jsxs("div",{className:"bedrock-step",children:[s.jsx("span",{className:"bedrock-step-num",children:"4"}),s.jsxs("div",{children:[s.jsx("strong",{children:"Configure in this wizard"}),s.jsx("span",{children:'Click "Setup Wizard" above to enter your credentials'})]})]})]})]}),n.configured&&c==="overview"&&!i&&s.jsx("div",{className:"bedrock-quick-status",children:s.jsxs("p",{className:"admin-hint",children:["Bedrock is configured. Click ",s.jsx("strong",{children:"🔍 Test Models"})," to verify connectivity and discover which models are accessible in ",n.region,"."]})})]})}function Fge(){const[e,t]=E.useState([]),[n,r]=E.useState(!0),[i,a]=E.useState("all"),[o,l]=E.useState(null),[c,u]=E.useState(""),[d,f]=E.useState(""),[p,h]=E.useState(null),g=E.useCallback(async()=>{r(!0);const k=await ee.getContacts();k.ok&&k.contacts&&t(k.contacts),r(!1)},[]);E.useEffect(()=>{g()},[g]);const m=e.filter(k=>i==="all"||k.status===i),v=async k=>{h(null);const N=await ee.approveContact(k.platform,k.name);h(N.ok?{kind:"ok",text:`✅ ${k.name} approved.`}:{kind:"err",text:N.error||"Failed."}),g()},y=async k=>{h(null);const N=await ee.rejectContact(k.platform,k.name);h(N.ok?{kind:"ok",text:`🚫 ${k.name} rejected.`}:{kind:"err",text:N.error||"Failed."}),g()},b=async k=>{h(null);const N=await ee.deleteContact(k.platform,k.name);h(N.ok?{kind:"ok",text:`🗑️ ${k.name} deleted.`}:{kind:"err",text:N.error||"Failed."}),g()},x=async()=>{if(!o)return;h(null);const k=await ee.updateContact(o.platform,o.id,{name:c,phone:d});h(k.ok?{kind:"ok",text:`✅ ${c} updated.`}:{kind:"err",text:k.error||"Failed."}),l(null),g()},_=k=>k==="approved"?s.jsx("span",{className:"contact-status-badge approved",children:"✅ Approved"}):k==="pending"?s.jsx("span",{className:"contact-status-badge pending",children:"⏳ Pending"}):s.jsx("span",{className:"contact-status-badge rejected",children:"🚫 Rejected"}),S=k=>({telegram:"✈️",whatsapp:"📱",whatsapp_cloud:"📱",email:"📧",slack:"💬",discord:"🎮"})[k]||"🔌",w=k=>k?new Date(k).toLocaleString():"—";return s.jsxs("div",{className:"panel contacts-page",children:[s.jsxs("div",{className:"panel-header",children:[s.jsx("h2",{children:"📇 Contacts — Outbound Messaging Directory"}),s.jsx("p",{className:"admin-hint",children:"Manage who the bot can send messages to. Users auto-register on first Telegram message."})]}),p&&s.jsxs("div",{className:`admin-row-msg ${p.kind==="err"?"admin-row-msg-err":""}`,children:[p.text,s.jsx("button",{className:"admin-mini-btn",onClick:()=>h(null),children:"✕"})]}),s.jsxs("div",{className:"contacts-filters",children:[["all","approved","pending","rejected"].map(k=>s.jsx("button",{type:"button",className:i===k?"platforms-filter-btn active":"platforms-filter-btn",onClick:()=>a(k),children:k==="all"?`All (${e.length})`:k==="approved"?`✅ Approved (${e.filter(N=>N.status==="approved").length})`:k==="pending"?`⏳ Pending (${e.filter(N=>N.status==="pending").length})`:`🚫 Rejected (${e.filter(N=>N.status==="rejected").length})`},k)),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void g(),children:"🔄 Refresh"})]}),n?s.jsx("div",{className:"empty-state",children:"Loading contacts..."}):m.length===0?s.jsxs("div",{className:"empty-state",children:[s.jsxs("p",{children:["No contacts",i!=="all"?` with status "${i}"`:"","."]}),s.jsx("p",{className:"admin-hint",children:'Contacts auto-register when users message the bot on Telegram. They appear here as "Pending" until you approve them.'})]}):s.jsx("div",{className:"contacts-table-wrapper",children:s.jsxs("table",{className:"contacts-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Platform"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"ID"}),s.jsx("th",{children:"Phone"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Registered"}),s.jsx("th",{children:"Actions"})]})}),s.jsx("tbody",{children:m.map(k=>s.jsxs("tr",{className:`contact-row status-${k.status}`,children:[s.jsxs("td",{children:[S(k.platform)," ",k.platform]}),s.jsx("td",{className:"contact-name",children:k.name}),s.jsx("td",{className:"contact-id",children:s.jsx("code",{children:k.id})}),s.jsx("td",{className:"contact-phone",children:k.phone||"—"}),s.jsx("td",{children:_(k.status)}),s.jsx("td",{className:"contact-date",children:w(k.registeredAt||k.addedAt)}),s.jsxs("td",{className:"contact-actions",children:[k.status!=="approved"&&s.jsx("button",{className:"admin-mini-btn contact-approve-btn",onClick:()=>void v(k),children:"✅ Approve"}),k.status!=="rejected"&&s.jsx("button",{className:"admin-mini-btn contact-reject-btn",onClick:()=>void y(k),children:"🚫 Reject"}),s.jsx("button",{className:"admin-mini-btn",onClick:()=>{l(k),u(k.name),f(k.phone||"")},children:"✏️ Edit"}),s.jsx("button",{className:"admin-mini-btn contact-delete-btn",onClick:()=>void b(k),children:"🗑️"})]})]},`${k.platform}:${k.id}`))})]})}),o&&s.jsx("div",{className:"wizard-overlay",onClick:()=>l(null),children:s.jsxs("div",{className:"wizard-modal",onClick:k=>k.stopPropagation(),children:[s.jsxs("div",{className:"wizard-header",children:[s.jsx("span",{className:"wizard-icon",children:"✏️"}),s.jsxs("span",{className:"wizard-title",children:["Edit Contact: ",o.name]}),s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>l(null),children:"✕"})]}),s.jsxs("div",{className:"wizard-body",children:[s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"Name"}),s.jsx("input",{type:"text",value:c,onChange:k=>u(k.target.value)})]}),s.jsxs("label",{className:"hub-send-target",children:[s.jsx("span",{className:"admin-hint",children:"Phone (optional, for flexible lookup)"}),s.jsx("input",{type:"text",value:d,onChange:k=>f(k.target.value),placeholder:"+918800123456"})]}),s.jsxs("p",{className:"admin-hint",children:["Platform: ",s.jsx("strong",{children:o.platform})," | ID: ",s.jsx("code",{children:o.id})]}),s.jsxs("div",{className:"wizard-nav",children:[s.jsx("button",{type:"button",className:"admin-mini-btn",onClick:()=>l(null),children:"Cancel"}),s.jsx("button",{type:"button",className:"admin-refresh-btn",onClick:()=>void x(),children:"Save"})]})]})]})})]})}function cs(e){if(e<=0)return"never";const t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60),i=Math.floor(r/24);return i>30?`${i}d ago`:i>0?`${i}d ${r%24}h ago`:r>0?`${r}h ${n%60}m ago`:n>0?`${n}m ago`:`${t}s ago`}function Uge(e,t,n){if(e==="unavailable")return"#f85149";if(e==="unverified")return"#d29922";const i=(Date.now()-t)/(24*60*60*1e3);return i>30&&n>.5?"#f85149":i>7?"#d29922":"#3fb950"}function Wge(e,t,n){if(e==="unavailable")return"Unavailable";if(e==="unverified")return"Unverified";const i=(Date.now()-t)/(24*60*60*1e3);return i>30&&n>.5?"Likely Removed":i>7?"Stale":"Fresh"}function Hge({entry:e}){const t=Date.now(),n=t-e.lastProbedAt,r=t-e.lastVerifiedAt,i=t-e.lastUsedAt,a=Math.min(100,n/(30*24*60*60*1e3)*100),o=e.lastVerifiedAt>0?Math.min(100,r/(30*24*60*60*1e3)*100):-1,l=e.lastUsedAt>0?Math.min(100,i/(30*24*60*60*1e3)*100):-1;return s.jsxs("div",{className:"timeline-bar-container",children:[s.jsx("div",{className:"timeline-bar",title:`Last probed: ${cs(n)}`,children:s.jsx("div",{className:"timeline-bar-fill probe",style:{width:`${a}%`}})}),o>=0&&s.jsx("div",{className:"timeline-bar small",title:`Last verified: ${cs(r)}`,children:s.jsx("div",{className:"timeline-bar-fill verify",style:{width:`${o}%`}})}),l>=0&&s.jsx("div",{className:"timeline-bar small",title:`Last used: ${cs(i)}`,children:s.jsx("div",{className:"timeline-bar-fill use",style:{width:`${l}%`}})})]})}function Gge(){const[e,t]=E.useState(null),[n,r]=E.useState(!0),[i,a]=E.useState(null),[o,l]=E.useState("all"),[c,u]=E.useState("provider"),d=E.useRef(!0),f=E.useCallback(async()=>{try{const v=await fetch("/api/model-timeline");if(!v.ok)throw new Error("Failed to fetch timeline data");const y=await v.json();d.current&&(t(y),a(null))}catch(v){d.current&&a(v instanceof Error?v.message:"Failed to load timeline")}finally{d.current&&r(!1)}},[]);if(E.useEffect(()=>{d.current=!0,f();const v=setInterval(f,3e4);return()=>{d.current=!1,clearInterval(v)}},[f]),n)return s.jsxs("div",{className:"admin-header",children:[s.jsx("h2",{className:"section-title",children:"📅 Model Discovery Timeline"}),s.jsxs("div",{className:"loading-state",children:[s.jsx("div",{className:"loading-spinner"}),s.jsx("p",{children:"Loading timeline..."})]})]});if(i)return s.jsxs("div",{className:"admin-header",children:[s.jsx("h2",{className:"section-title",children:"📅 Model Discovery Timeline"}),s.jsx("div",{className:"admin-row-msg admin-row-msg-err",children:i})]});const h=((e==null?void 0:e.entries)??[]).filter(v=>{const b=(Date.now()-v.lastProbedAt)/(24*60*60*1e3),x=b>7,_=b>30&&v.errorRate>.5,S=!x&&!_;return o==="fresh"?S:o==="stale"?x&&!_:o==="removed"?_:!0}),g=[...h].sort((v,y)=>{if(c==="provider")return v.provider.localeCompare(y.provider)||v.model.localeCompare(y.model);if(c==="lastProbed")return y.lastProbedAt-v.lastProbedAt;if(c==="status"){const b={unavailable:0,unverified:1,verified:2};return(b[y.status]??0)-(b[v.status]??0)}return 0}),m=new Map;for(const v of g)m.has(v.provider)||m.set(v.provider,[]),m.get(v.provider).push(v);return s.jsxs("div",{className:"admin-header",children:[s.jsx("h2",{className:"section-title",children:"📅 Model Discovery Timeline"}),s.jsxs("div",{className:"stats-grid",style:{marginBottom:16},children:[s.jsxs("div",{className:"stat-card",children:[s.jsx("div",{className:"stat-value",children:(e==null?void 0:e.totalModels)??0}),s.jsx("div",{className:"stat-label",children:"Total Models"})]}),s.jsxs("div",{className:"stat-card",style:{borderColor:"#3fb950"},children:[s.jsx("div",{className:"stat-value",style:{color:"#3fb950"},children:(e==null?void 0:e.freshCount)??0}),s.jsx("div",{className:"stat-label",children:"Fresh (<7d)"})]}),s.jsxs("div",{className:"stat-card",style:{borderColor:"#d29922"},children:[s.jsx("div",{className:"stat-value",style:{color:"#d29922"},children:(e==null?void 0:e.staleCount)??0}),s.jsx("div",{className:"stat-label",children:"Stale (7-30d)"})]}),s.jsxs("div",{className:"stat-card",style:{borderColor:"#f85149"},children:[s.jsx("div",{className:"stat-value",style:{color:"#f85149"},children:(e==null?void 0:e.removedCount)??0}),s.jsx("div",{className:"stat-label",children:"Likely Removed (>30d)"})]})]}),s.jsxs("div",{style:{display:"flex",gap:8,marginBottom:16,flexWrap:"wrap"},children:[s.jsx("div",{style:{display:"flex",gap:4},children:["all","fresh","stale","removed"].map(v=>s.jsx("button",{className:`admin-refresh-btn ${o===v?"active":""}`,onClick:()=>l(v),style:{background:o===v?"#238636":"#21262d",border:`1px solid ${o===v?"#3fb950":"#30363d"}`,padding:"4px 12px",fontSize:12,cursor:"pointer"},children:v.charAt(0).toUpperCase()+v.slice(1)},v))}),s.jsx("div",{style:{display:"flex",gap:4},children:["provider","lastProbed","status"].map(v=>s.jsxs("button",{className:`admin-refresh-btn ${c===v?"active":""}`,onClick:()=>u(v),style:{background:c===v?"#238636":"#21262d",border:`1px solid ${c===v?"#3fb950":"#30363d"}`,padding:"4px 12px",fontSize:12,cursor:"pointer"},children:["Sort: ",v==="lastProbed"?"Last Seen":v.charAt(0).toUpperCase()+v.slice(1)]},v))}),s.jsx("button",{className:"admin-refresh-btn",onClick:f,style:{background:"#21262d",border:"1px solid #30363d",padding:"4px 12px",fontSize:12,cursor:"pointer"},children:"🔄 Refresh"})]}),s.jsxs("div",{style:{display:"flex",gap:16,marginBottom:12,fontSize:11,color:"#8b949e"},children:[s.jsxs("span",{children:[s.jsx("span",{style:{color:"#58a6ff"},children:"■"})," Probe (last seen)"]}),s.jsxs("span",{children:[s.jsx("span",{style:{color:"#3fb950"},children:"■"})," Verified (last success)"]}),s.jsxs("span",{children:[s.jsx("span",{style:{color:"#d29922"},children:"■"})," Used (last invocation)"]})]}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Array.from(m.entries()).map(([v,y])=>s.jsxs("div",{style:{background:"#161b22",borderRadius:8,border:"1px solid #30363d",overflow:"hidden"},children:[s.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid #30363d",display:"flex",alignItems:"center",gap:8},children:[s.jsx("span",{style:{fontSize:16},children:v==="groq"?"⚡":v==="gemini"?"🌀":v==="local"?"💻":"🤖"}),s.jsx("span",{style:{fontWeight:600,color:"#e6edf3"},children:v}),s.jsxs("span",{style:{fontSize:12,color:"#8b949e"},children:["(",y.length," models)"]})]}),s.jsx("div",{style:{padding:"8px 14px"},children:y.map(b=>{const x=Date.now();(x-b.lastProbedAt)/(24*60*60*1e3);const _=Uge(b.status,b.lastProbedAt,b.errorRate),S=Wge(b.status,b.lastProbedAt,b.errorRate);return s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"6px 0",borderBottom:"1px solid #21262d"},children:[s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{fontSize:13,color:"#e6edf3",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.model}),s.jsxs("div",{style:{fontSize:11,color:"#8b949e",display:"flex",gap:12},children:[s.jsxs("span",{children:["Probed: ",cs(x-b.lastProbedAt)]}),b.lastVerifiedAt>0&&s.jsxs("span",{children:["Verified: ",cs(x-b.lastVerifiedAt)]}),b.lastUsedAt>0&&s.jsxs("span",{children:["Used: ",cs(x-b.lastUsedAt)]}),b.latencyMs!==void 0&&s.jsxs("span",{children:[b.latencyMs,"ms"]})]})]}),s.jsx(Hge,{entry:b}),s.jsx("div",{style:{fontSize:11,padding:"2px 8px",borderRadius:4,background:`${_}20`,color:_,border:`1px solid ${_}40`,whiteSpace:"nowrap"},children:S})]},b.model)})})]},v))}),h.length===0&&s.jsx("div",{style:{textAlign:"center",padding:"40px 20px",color:"#8b949e"},children:"No models match the current filter"})]})}function qge(){const[e,t]=E.useState(null),[n,r]=E.useState(!1),[i,a]=E.useState("--"),o=E.useCallback(c=>{t(c),a(new Date().toLocaleTimeString())},[]),l=E.useCallback(c=>{r(c)},[]);return E.useEffect(()=>{ee.fetchAll().then(d=>{d&&o(d)});const c=ee.subscribe(o),u=ee.onConnectionChange(l);return ee.connect(),()=>{c(),u(),ee.disconnect()}},[o,l]),s.jsx($L,{connected:n,lastUpdated:i,children:s.jsxs(yL,{children:[s.jsx(vt,{path:"/",element:s.jsx(HN,{})}),s.jsx(vt,{path:"/overview",element:s.jsx(pie,{data:e})}),s.jsx(vt,{path:"/chat",element:s.jsx(r1,{to:"/",replace:!0})}),s.jsx(vt,{path:"/dag",element:s.jsx(Sie,{data:e})}),s.jsx(vt,{path:"/costs",element:s.jsx(_ie,{data:e})}),s.jsx(vt,{path:"/benchmarks",element:s.jsx(Nie,{data:e})}),s.jsx(vt,{path:"/models",element:s.jsx(cae,{})}),s.jsx(vt,{path:"/models/timeline",element:s.jsx(Gge,{})}),s.jsx(vt,{path:"/routing",element:s.jsx(Hae,{data:e})}),s.jsx(vt,{path:"/requests",element:s.jsx(Kae,{data:e})}),s.jsx(vt,{path:"/traces",element:s.jsx(noe,{})}),s.jsx(vt,{path:"/hub",element:s.jsx(hoe,{})}),s.jsx(vt,{path:"/tasks",element:s.jsx(yoe,{})}),s.jsx(vt,{path:"/chat",element:s.jsx(HN,{})}),s.jsx(vt,{path:"/evals",element:s.jsx(Ige,{data:e})}),s.jsx(vt,{path:"/platforms",element:s.jsx(Dge,{})}),s.jsx(vt,{path:"/bedrock",element:s.jsx(zge,{canWrite:!0,sessionExpired:c=>console.error(c)})}),s.jsx(vt,{path:"/contacts",element:s.jsx(Fge,{})}),s.jsx(vt,{path:"/gateway",element:s.jsx(Lge,{})}),s.jsx(vt,{path:"/system",element:s.jsx(jie,{data:e})}),s.jsx(vt,{path:"/admin",element:s.jsx(soe,{})}),s.jsx(vt,{path:"*",element:s.jsx(r1,{to:"/",replace:!0})})]})})}aT(document.getElementById("root")).render(s.jsx(E.StrictMode,{children:s.jsx(EL,{children:s.jsx(qge,{})})}));
|
|
207
|
+
//# sourceMappingURL=index-CXWJHhWs.js.map
|