Correspondents/.next/static/chunks/app/page-42c3373a58d86608.js
2025-11-13 22:33:26 -07:00

1 line
28 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{4465:(e,t,a)=>{Promise.resolve().then(a.bind(a,8726))},8726:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>T});var r=a(4248),s=a(4564),n=a(395),i=a(306),l=a(1495),o=a(6635),d=a(7235),c=a(7697);function m(){for(var e=arguments.length,t=Array(e),a=0;a<e;a++)t[a]=arguments[a];return(0,c.QP)((0,d.$)(t))}let h=(0,o.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function x(e){let{className:t,variant:a,size:s,asChild:n=!1,...i}=e,o=n?l.DX:"button";return(0,r.jsx)(o,{"data-slot":"button",className:m(h({variant:a,size:s,className:t})),...i})}var u=a(6670),p=a(2414),g=a(297),f=a(6749),b=a(2375),w=a(9617),v=a(3337),y=a(4428),N=a(1557),j=a(9425),k=a(1567);let _=y.bL,S=y.l9;y.YJ,y.ZL,y.Pb,y.z6,s.forwardRef((e,t)=>{let{className:a,inset:s,children:n,...i}=e;return(0,r.jsxs)(y.ZP,{ref:t,className:m("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s&&"pl-8",a),...i,children:[n,(0,r.jsx)(N.A,{className:"ml-auto"})]})}).displayName=y.ZP.displayName,s.forwardRef((e,t)=>{let{className:a,...s}=e;return(0,r.jsx)(y.G5,{ref:t,className:m("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...s})}).displayName=y.G5.displayName;let C=s.forwardRef((e,t)=>{let{className:a,sideOffset:s=4,...n}=e;return(0,r.jsx)(y.ZL,{children:(0,r.jsx)(y.UC,{ref:t,sideOffset:s,className:m("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",a),...n})})});C.displayName=y.UC.displayName;let L=s.forwardRef((e,t)=>{let{className:a,inset:s,...n}=e;return(0,r.jsx)(y.q7,{ref:t,className:m("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s&&"pl-8",a),...n})});L.displayName=y.q7.displayName,s.forwardRef((e,t)=>{let{className:a,children:s,checked:n,...i}=e;return(0,r.jsxs)(y.H_,{ref:t,className:m("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),checked:n,...i,children:[(0,r.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,r.jsx)(y.VF,{children:(0,r.jsx)(j.A,{className:"h-4 w-4"})})}),s]})}).displayName=y.H_.displayName,s.forwardRef((e,t)=>{let{className:a,children:s,...n}=e;return(0,r.jsxs)(y.hN,{ref:t,className:m("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...n,children:[(0,r.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,r.jsx)(y.VF,{children:(0,r.jsx)(k.A,{className:"h-2 w-2 fill-current"})})}),s]})}).displayName=y.hN.displayName,s.forwardRef((e,t)=>{let{className:a,inset:s,...n}=e;return(0,r.jsx)(y.JU,{ref:t,className:m("px-2 py-1.5 text-sm font-semibold",s&&"pl-8",a),...n})}).displayName=y.JU.displayName,s.forwardRef((e,t)=>{let{className:a,...s}=e;return(0,r.jsx)(y.wv,{ref:t,className:m("-mx-1 my-1 h-px bg-muted",a),...s})}).displayName=y.wv.displayName;var A=a(7923),z=a(1271),O=a(9784);function E(e){let{oldText:t,newText:a,title:n="Code Diff",language:i="text"}=e,[l,o]=(0,s.useState)(!1),[d,c]=(0,s.useState)(!1),m=(()=>{let e=t.split("\n"),r=a.split("\n"),s=[],n=0,i=0,l=1,o=1;for(;n<e.length||i<r.length;){let t=e[n],a=r[i];if(n>=e.length)s.push({type:"added",content:a,newLineNumber:o}),i++,o++;else if(i>=r.length)s.push({type:"removed",content:t,oldLineNumber:l}),n++,l++;else if(t===a)s.push({type:"unchanged",content:t,oldLineNumber:l,newLineNumber:o}),n++,i++,l++,o++;else{let d=e[n+1],c=r[i+1];d===a?(s.push({type:"removed",content:t,oldLineNumber:l}),n++,l++):(c===t?(s.push({type:"added",content:a,newLineNumber:o}),i++):(s.push({type:"removed",content:t,oldLineNumber:l}),s.push({type:"added",content:a,newLineNumber:o}),n++,i++,l++),o++)}}return s})(),h=m.some(e=>"unchanged"!==e.type),u=async()=>{let e=m.map(e=>{let t="added"===e.type?"+":"removed"===e.type?"-":" ",a=e.oldLineNumber?e.oldLineNumber.toString().padStart(3):" ",r=e.newLineNumber?e.newLineNumber.toString().padStart(3):" ";return"".concat(t," ").concat(a,"|").concat(r," ").concat(e.content)}).join("\n");try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3)}catch(e){console.error("Failed to copy diff:",e)}};return h?(0,r.jsxs)("div",{className:"rounded-lg border border-neutral-800 bg-neutral-900/50 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 bg-neutral-800/50 border-b border-neutral-800",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(x,{variant:"ghost",size:"sm",onClick:()=>o(!l),className:"h-6 w-6 p-0 text-neutral-400 hover:text-white",children:l?(0,r.jsx)(f.A,{className:"h-4 w-4"}):(0,r.jsx)(N.A,{className:"h-4 w-4"})}),(0,r.jsx)("span",{className:"text-sm font-medium text-white",children:n}),(0,r.jsxs)("span",{className:"text-xs text-neutral-500",children:["(",i,")"]})]}),(0,r.jsx)(x,{variant:"ghost",size:"sm",onClick:u,className:"h-6 w-6 p-0 text-neutral-400 hover:text-white",children:d?(0,r.jsx)(j.A,{className:"h-4 w-4 text-green-500"}):(0,r.jsx)(p.A,{className:"h-4 w-4"})})]}),l&&(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsx)("div",{className:"font-mono text-sm",children:m.map((e,t)=>(0,r.jsxs)("div",{className:"flex items-start gap-2 px-4 py-1 ".concat("added"===e.type?"bg-green-500/10 border-l-4 border-green-500":"removed"===e.type?"bg-red-500/10 border-l-4 border-red-500":"bg-transparent"),children:[(0,r.jsx)("div",{className:"flex-shrink-0 w-12 text-xs text-neutral-500 select-none",children:e.oldLineNumber&&e.newLineNumber?"".concat(e.oldLineNumber,"|").concat(e.newLineNumber):e.oldLineNumber?"".concat(e.oldLineNumber,"| "):e.newLineNumber?" |".concat(e.newLineNumber):" | "}),(0,r.jsx)("div",{className:"flex-shrink-0 w-4 text-center text-xs select-none",children:"added"===e.type?(0,r.jsx)("span",{className:"text-green-500",children:"+"}):"removed"===e.type?(0,r.jsx)("span",{className:"text-red-500",children:"-"}):(0,r.jsx)("span",{className:"text-neutral-500",children:" "})}),(0,r.jsx)("div",{className:"flex-1 ".concat("added"===e.type?"text-green-400":"removed"===e.type?"text-red-400":"text-neutral-300"),children:(0,r.jsx)("code",{children:e.content||" "})})]},t))})})]}):(0,r.jsx)("div",{className:"rounded-lg border border-neutral-800 bg-neutral-900/50 p-4",children:(0,r.jsxs)("div",{className:"flex items-center gap-2 text-sm text-neutral-400",children:[(0,r.jsx)(j.A,{className:"h-4 w-4 text-green-500"}),(0,r.jsx)("span",{children:"No changes detected"})]})})}function D(e){let{oldCode:t,newCode:a,title:s,language:n}=e;return(0,r.jsx)("div",{className:"my-4",children:(0,r.jsx)(E,{oldText:t,newText:a,title:s||"Code Changes",language:n||"text"})})}function I(e){let{content:t,className:a="",tone:s="default"}=e,n=function(e){let t,a=/```diff-tool\n([\s\S]*?)\n```/g,r=[];for(;null!==(t=a.exec(e));)try{let e=JSON.parse(t[1]);r.push({match:t[0],props:e})}catch(e){console.error("Failed to parse diff tool:",e)}return r}(t),i=t;n.forEach((e,t)=>{i=i.replace(e.match,"__DIFF_TOOL_".concat(t,"__"))});let l="bubble"===s?"text-charcoal dark:text-white":"text-charcoal dark:text-foreground",o="bubble"===s?"text-charcoal/80 dark:text-white/80":"text-charcoal/80 dark:text-foreground/75";return(0,r.jsx)("div",{className:m("markdown-glass space-y-3 text-sm leading-relaxed",l,a),children:(0,r.jsx)(A.oz,{remarkPlugins:[z.A],rehypePlugins:[O.A],components:{p:e=>{let{children:t}=e,a=("string"==typeof t?t:(null==t?void 0:t.toString())||"").match(/^__DIFF_TOOL_(\d+)__$/);if(a){let e=n[parseInt(a[1])];if(e)return(0,r.jsx)(D,{oldCode:e.props.oldCode,newCode:e.props.newCode,title:e.props.title,language:e.props.language})}return(0,r.jsx)("p",{className:m("mb-2 text-sm leading-relaxed last:mb-0",l),children:t})},h1:e=>{let{children:t}=e;return(0,r.jsx)("h1",{className:m("text-[2rem] font-semibold tracking-tight",l),children:t})},h2:e=>{let{children:t}=e;return(0,r.jsx)("h2",{className:m("text-[1.75rem] font-semibold tracking-tight",l),children:t})},h3:e=>{let{children:t}=e;return(0,r.jsx)("h3",{className:m("text-[1.5rem] font-semibold",l),children:t})},ul:e=>{let{children:t}=e;return(0,r.jsx)("ul",{className:m("mb-2 list-disc space-y-1 pl-4 text-sm",o),children:t})},ol:e=>{let{children:t}=e;return(0,r.jsx)("ol",{className:m("mb-2 list-decimal space-y-1 pl-4 text-sm",o),children:t})},li:e=>{let{children:t}=e;return(0,r.jsx)("li",{className:m("text-sm",o),children:t})},code:e=>{let{children:t,className:a}=e;return a?(0,r.jsx)("code",{className:a,children:t}):(0,r.jsx)("code",{className:"rounded bg-white/60 px-1.5 py-0.5 font-mono text-xs text-charcoal dark:bg-white/10 dark:text-foreground",children:t})},pre:e=>{let{children:t,className:a}=e;return(0,r.jsx)(F,{className:a,children:t})},blockquote:e=>{let{children:t}=e;return(0,r.jsx)("blockquote",{className:"border-l-2 border-burnt/70 pl-4 text-sm italic text-muted-foreground dark:text-foreground/80",children:t})},a:e=>{let{children:t,href:a}=e;return(0,r.jsx)("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"underline decoration-burnt/40 decoration-2 underline-offset-4 text-burnt hover:text-terracotta dark:text-white dark:hover:text-burnt",children:t})},strong:e=>{let{children:t}=e;return(0,r.jsx)("strong",{className:"font-semibold text-charcoal dark:text-white",children:t})},em:e=>{let{children:t}=e;return(0,r.jsx)("em",{className:m("italic",o),children:t})},table:e=>{let{children:t}=e;return(0,r.jsx)("div",{className:"overflow-x-auto mb-3",children:(0,r.jsx)("table",{className:"min-w-full rounded-lg border border-border/50",children:t})})},thead:e=>{let{children:t}=e;return(0,r.jsx)("thead",{className:"bg-white/70 text-charcoal dark:bg-white/10 dark:text-foreground",children:t})},tbody:e=>{let{children:t}=e;return(0,r.jsx)("tbody",{className:"bg-white/40 text-charcoal dark:bg-white/5 dark:text-foreground",children:t})},tr:e=>{let{children:t}=e;return(0,r.jsx)("tr",{className:"border-b border-border/40",children:t})},th:e=>{let{children:t}=e;return(0,r.jsx)("th",{className:"px-4 py-2 text-left text-sm font-semibold text-charcoal dark:text-foreground",children:t})},td:e=>{let{children:t}=e;return(0,r.jsx)("td",{className:"px-4 py-2 text-sm text-charcoal dark:text-foreground",children:t})}},children:t})})}function F(e){let{children:t,className:a}=e,[n,i]=(0,s.useState)(!1),l=function e(t){return"string"==typeof t?t:Array.isArray(t)?t.map(e).join(""):(0,s.isValidElement)(t)?e(t.props.children):""}(t),o=async()=>{try{await navigator.clipboard.writeText(l.trimEnd()),i(!0),setTimeout(()=>i(!1),1200)}catch(e){console.error("[markdown] Code copy failed",e)}};return(0,r.jsxs)("div",{className:"relative mb-3",children:[(0,r.jsx)("pre",{className:m("overflow-x-auto rounded-xl border border-border/50 p-4 text-sm text-charcoal shadow-sm dark:border-white/10 dark:text-foreground",a),children:t}),(0,r.jsx)("button",{type:"button",onClick:o,className:m("absolute right-3 top-3 inline-flex h-5 w-5 items-center justify-center rounded border border-white/25 bg-white/8 text-white/70 shadow-[0_2px_4px_rgba(0,0,0,0.06)] backdrop-blur transition-transform duration-150 hover:bg-white/18",n&&"scale-90 bg-white/30 text-white"),"aria-label":"Copy code",children:(0,r.jsx)(p.A,{className:"h-2.5 w-2.5"})})]})}function P(e){var t;let{agent:a,agents:l,onAgentSelected:o,isAgentsLoading:d}=e,[c,h]=(0,s.useState)([]),[y,N]=(0,s.useState)(""),[j,k]=(0,s.useState)(!1),[A,z]=(0,s.useState)(""),[O,E]=(0,s.useState)([]),[D,F]=(0,s.useState)(null),P=(0,s.useRef)(null),T=(0,s.useRef)(null),R=(0,s.useRef)(null),[J,H]=(0,s.useState)(null);(0,s.useEffect)(()=>{let e="chat-session-".concat(a.id),t=localStorage.getItem(e);t||(t="session-".concat(a.id,"-").concat(Date.now(),"-").concat(Math.random().toString(36).substring(2,15)),localStorage.setItem(e,t)),z(t);let r="chat-messages-".concat(a.id),s=localStorage.getItem(r);if(s)try{let e=JSON.parse(s).map(e=>({...e,timestamp:new Date(e.timestamp)}));h(e)}catch(e){console.error("[chat] Failed to load saved messages:",e)}},[a.id]),(0,s.useEffect)(()=>{P.current&&(P.current.scrollTop=P.current.scrollHeight)},[c,j]),(0,s.useEffect)(()=>{let e="chat-messages-".concat(a.id);localStorage.setItem(e,JSON.stringify(c))},[c,a.id]),(0,s.useEffect)(()=>{T.current&&(T.current.style.height="auto",T.current.style.height=Math.min(T.current.scrollHeight,160)+"px")},[y]),(0,s.useEffect)(()=>{c.length>0&&D!==a.id&&F(a.id)},[c.length,a.id]);let q=async e=>{let t=e.currentTarget.files;if(!t)return;let a=[];for(let e=0;e<t.length;e++){let r=t[e];if(!r.type.startsWith("image/")){console.warn("[chat] Skipping non-image file:",r.name);continue}try{let e=await U(r);a.push(e)}catch(e){console.error("[chat] Failed to convert image:",e)}}E(e=>[...e,...a]),R.current&&(R.current.value="")},U=e=>new Promise((t,a)=>{let r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result),r.onerror=a}),G=async e=>{if(e&&e.preventDefault(),!y.trim()||j)return;let t={id:Date.now().toString(),role:"user",content:y.trim(),timestamp:new Date,images:O.length>0?O:void 0};h(e=>[...e,t]),N(""),E([]),k(!0);try{let e=await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t.content,timestamp:t.timestamp.toISOString(),sessionId:A,agentId:a.id,images:O.length>0?O:void 0})}),r=await e.json();if(e.ok){let e={id:(Date.now()+1).toString(),role:"assistant",content:r.response||r.message||JSON.stringify(r),timestamp:new Date};h(t=>[...t,e])}else{let e={id:(Date.now()+1).toString(),role:"assistant",content:r.error||"Failed to communicate with the webhook.",timestamp:new Date,isError:!0,hint:r.hint};h(t=>[...t,e])}}catch(t){console.error("[v0] Error sending message:",t);let e={id:(Date.now()+1).toString(),role:"assistant",content:"Sorry, I encountered an error processing your message. Please try again.",timestamp:new Date,isError:!0};h(t=>[...t,e])}finally{var r;k(!1),null==(r=T.current)||r.focus()}},M=async(e,t)=>{try{await navigator.clipboard.writeText(t),H(e),setTimeout(()=>{H(t=>t===e?null:t)},1200)}catch(e){console.error("[chat] Failed to copy message",e)}},V=e=>{F(e.id),o(e)},Z=l.length>0&&!d,K=c.length>0,W=null!=D?D:K?a.id:null,$=W?null!=(t=l.find(e=>e.id===W))?t:a:null,Q=$?$.name:"Select a correspondent";return(0,r.jsxs)(n.P.div,{initial:{opacity:0,y:35},animate:{opacity:1,y:0},transition:{duration:.85,ease:"easeOut"},className:"relative flex h-full w-full flex-col overflow-hidden rounded-[2.5rem] bg-gradient-to-b from-white/0 via-white/15 to-white/45 px-4 py-8 shadow-[0_15px_35px_rgba(45,45,45,0.1),0_0_0_1px_rgba(255,255,255,0.25)_inset,0_15px_25px_rgba(255,255,255,0.12)_inset] backdrop-blur-xl dark:bg-gradient-to-b dark:from-transparent dark:via-white/5 dark:to-white/20 dark:shadow-[0_12px_25px_rgba(0,0,0,0.35),0_0_0_1px_rgba(255,255,255,0.06)_inset,0_12px_20px_rgba(255,255,255,0.04)_inset] sm:px-8 sm:py-10",children:[c.length>0&&(0,r.jsx)("div",{className:"absolute left-8 top-8 z-10",children:(0,r.jsx)(x,{onClick:()=>{var e;h([]);let t="session-".concat(a.id,"-").concat(Date.now(),"-").concat(Math.random().toString(36).substring(2,15));z(t);let r="chat-session-".concat(a.id);localStorage.setItem(r,t),N(""),E([]),F(null),null==(e=T.current)||e.focus()},variant:"ghost",size:"icon",className:"group h-11 w-11 rounded-2xl border border-white/25 bg-white/15 text-white shadow-[0_2px_6px_rgba(0,0,0,0.12)] backdrop-blur transition hover:bg-white/25",title:"Start a fresh conversation",children:(0,r.jsx)(u.A,{className:"h-4 w-4"})})}),(0,r.jsx)("div",{ref:P,className:m("px-1 pt-4 sm:px-0",K?"flex-1 overflow-y-auto pb-10":"pb-6"),children:(0,r.jsx)("div",{className:"mx-auto max-w-[52rem] space-y-10 px-2 sm:px-4",children:(0,r.jsx)(i.N,{mode:"wait",children:K?(0,r.jsxs)(n.P.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.6,ease:"easeOut"},className:"space-y-10",children:[c.map(e=>{let t="user"===e.role;return(0,r.jsxs)(n.P.div,{layout:!0,initial:{opacity:0,y:15},animate:{opacity:1,y:0},transition:{duration:.35,ease:"easeOut"},className:m("message-frame flex flex-col gap-3",t?"items-end text-right":""),children:[t?(0,r.jsx)("div",{className:"message-bubble user",children:(0,r.jsx)(I,{content:e.content,tone:"bubble"})}):e.isError?(0,r.jsx)("div",{className:"text-sm font-medium text-destructive",children:(0,r.jsx)("p",{className:"whitespace-pre-wrap break-words leading-relaxed",children:e.content})}):(0,r.jsxs)("div",{className:"relative text-sm text-charcoal dark:text-foreground",children:[(0,r.jsx)(I,{content:e.content}),(0,r.jsx)("div",{className:"mt-4 flex items-center justify-end gap-3 border-t border-white/10 pt-3 opacity-50 transition hover:opacity-100",children:(0,r.jsx)("button",{type:"button",onClick:()=>M(e.id,e.content),className:"inline-flex h-7 w-7 items-center justify-center rounded border border-white/20 bg-white/8 text-white/70 shadow-[0_2px_5px_rgba(0,0,0,0.07)] backdrop-blur transition-transform duration-150 hover:bg-white/18 ".concat(J===e.id?"scale-90 bg-white/20 text-white":""),"aria-label":"Copy response",children:(0,r.jsx)(p.A,{className:"h-2.5 w-2.5"})})})]}),e.hint&&(0,r.jsx)("div",{className:"rounded-lg border border-accent/60 bg-accent/40 px-3 py-2 text-xs text-charcoal",children:e.hint})]},e.id)}),j&&(0,r.jsx)("div",{className:"message-frame flex flex-col gap-3",children:(0,r.jsxs)("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:[(0,r.jsx)("span",{className:"uppercase tracking-[0.25em] text-white/70",children:"Correspondent"}),(0,r.jsx)("span",{className:"relative flex h-3 w-24 overflow-hidden rounded-full bg-white/10",children:(0,r.jsx)("span",{className:"absolute inset-y-0 w-1/2 animate-[shimmer_1.4s_infinite] bg-white/40"})})]})})]},"conversation"):(0,r.jsxs)(n.P.div,{initial:{opacity:0,y:60},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.65,ease:"easeOut"},className:"flex min-h-[40vh] flex-col items-center justify-center gap-6 text-center",children:[(0,r.jsx)("div",{className:"text-center",children:(0,r.jsx)("h1",{className:"font-heading text-[7rem] lowercase tracking-tight text-white/85 drop-shadow-[0_12px_30px_rgba(0,0,0,0.4)]",children:"hello, user".split("").map((e,t)=>(0,r.jsx)(n.P.span,{initial:{opacity:0,y:18},animate:{opacity:1,y:0},transition:{delay:.15+.05*t,duration:.35,ease:"easeOut"},className:"inline-block",children:" "===e?"\xa0":e},"".concat(e,"-").concat(t)))})}),(0,r.jsxs)("div",{className:"w-full max-w-3xl space-y-4",children:[(0,r.jsx)("p",{className:"text-sm uppercase tracking-[0.35em] text-white/80",children:"Select a correspondent to begin"}),l.length>0?(0,r.jsx)("div",{className:"flex flex-wrap items-center justify-center gap-3",children:l.map(e=>{let t=W===e.id;return(0,r.jsx)("button",{onClick:()=>V(e),className:m("rounded-full border px-4 py-2 text-[0.65rem] uppercase tracking-[0.35em] transition",t?"border-white/25 bg-white/25 text-white shadow-[0_5px_20px_rgba(0,0,0,0.35)]":"border-white/10 bg-white/5 text-white/70 hover:border-white/30 hover:text-white"),children:e.name},e.id)})}):(0,r.jsx)("p",{className:"text-sm text-white/60",children:"No agents available yet."})]}),(0,r.jsx)("div",{className:"grid w-full max-w-2xl gap-4 sm:grid-cols-2",children:["Help me brainstorm ideas for a new mobile app","Generate creative writing prompts for a fantasy novel","Suggest innovative marketing strategies for a startup","Create a list of unique product names for a tech company"].map((e,t)=>(0,r.jsx)("button",{onClick:()=>N(e),className:"scroll-reveal rounded-2xl border border-border/30 bg-white/80 p-4 text-left text-sm text-charcoal shadow-sm transition hover:border-ring/60 hover:bg-white",style:{animationDelay:"".concat(50*t,"ms")},children:e},e))})]},"empty-state")})})}),(0,r.jsx)(n.P.div,{layout:!0,className:"relative mt-auto pt-6 pb-4 transition-all duration-500",animate:{y:K?0:-140,scale:K?1:1.05},transition:{type:"spring",stiffness:160,damping:24},children:(0,r.jsxs)("form",{onSubmit:G,className:"relative flex justify-center",children:[O.length>0&&(0,r.jsx)("div",{className:"mb-3 flex flex-wrap gap-3 px-3 pt-2",children:O.map((e,t)=>(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("img",{src:e,alt:"Selected ".concat(t),className:"h-16 w-16 rounded-lg border border-border/40 object-cover shadow-md"}),(0,r.jsx)("button",{type:"button",onClick:()=>{E(e=>e.filter((e,a)=>a!==t))},className:"absolute -right-2 -top-2 flex h-5 w-5 items-center justify-center rounded-full text-white shadow-md hover:opacity-80",style:{backgroundColor:"var(--charcoal-ink)"},children:(0,r.jsx)(g.A,{className:"h-3 w-3"})})]},t))}),(0,r.jsx)("div",{className:"manuscript-panel w-[85%] max-w-2xl p-5",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsx)("textarea",{ref:T,value:y,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),G())},placeholder:"Write a note, share a hunch, or paste a brief…",disabled:j,rows:1,className:"min-h-[32px] max-h-32 w-full resize-none border-0 bg-transparent text-lg text-foreground placeholder:text-muted-foreground/80 focus:outline-none",style:{overflow:"hidden",height:"auto"},onInput:e=>{let t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,160)+"px"}}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[(0,r.jsxs)(_,{children:[(0,r.jsx)(S,{asChild:!0,children:(0,r.jsxs)("button",{type:"button",className:m("inline-flex max-w-[12rem] items-center gap-2 rounded-2xl border border-white/20 bg-white/30 px-3 py-2 text-left text-[0.55rem] uppercase tracking-[0.3em] shadow-[0_10px_25px_rgba(0,0,0,0.2)] backdrop-blur transition hover:bg-white/40 hover:text-white disabled:opacity-50",W||K?"text-white":"agent-picker-prompt text-white"),disabled:!Z,children:[(0,r.jsx)("span",{className:"truncate text-xs font-heading normal-case tracking-normal text-white",children:Q}),(0,r.jsx)(f.A,{className:"h-3.5 w-3.5 text-white/70"})]})}),(0,r.jsx)(C,{align:"start",className:"min-w-[12rem] rounded-2xl border border-white/15 bg-white/10 p-2 text-white shadow-[0_20px_40px_rgba(0,0,0,0.3)] backdrop-blur",children:d?(0,r.jsx)(L,{disabled:!0,className:"text-white/50",children:"Gathering correspondents…"}):0===l.length?(0,r.jsx)(L,{disabled:!0,className:"text-white/50",children:"No agents configured"}):l.map(e=>{let t=W===e.id;return(0,r.jsxs)(L,{onClick:()=>V(e),className:"flex w-full items-center justify-between rounded-xl px-3 py-2 text-xs transition ".concat(t?"bg-white/15 text-white":"text-white/90 hover:bg-white/5 hover:text-white"),children:[(0,r.jsx)("span",{className:"font-heading text-sm",children:e.name}),t&&(0,r.jsx)("span",{className:"text-[0.55rem] uppercase tracking-[0.3em]",children:"Active"})]},e.id)})})]}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-3 text-xs uppercase tracking-[0.25em] text-muted-foreground",children:[(0,r.jsx)(x,{type:"submit",disabled:!y.trim()||j,size:"icon",className:"group h-12 w-12 flex-shrink-0 rounded-2xl border border-white/20 bg-white/30 text-white shadow-[0_10px_25px_rgba(0,0,0,0.2)] backdrop-blur transition hover:bg-white/40 disabled:opacity-50",children:j?(0,r.jsx)(b.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(w.A,{className:"h-4 w-4"})}),(0,r.jsx)("input",{ref:R,type:"file",multiple:!0,accept:"image/*",onChange:q,className:"hidden",disabled:j}),(0,r.jsx)(x,{type:"button",variant:"ghost",size:"icon",onClick:()=>{var e;return null==(e=R.current)?void 0:e.click()},disabled:j,className:"h-11 w-11 rounded-2xl border border-white/20 bg-white/10 text-white/80 transition hover:bg-white/20 hover:text-white",title:"Attach image",children:(0,r.jsx)(v.A,{className:"h-4 w-4"})})]})]})]})})]})})]})}function T(){let[e,t]=(0,s.useState)(null),[a,i]=(0,s.useState)(!0),[l,o]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[m,h]=(0,s.useState)(!0);return((0,s.useEffect)(()=>{let e=localStorage.getItem("selected-agent");if(e)try{let a=JSON.parse(e);t(a)}catch(e){console.error("[home] Failed to load saved agent:",e)}i(!1)},[]),(0,s.useEffect)(()=>{(async()=>{try{h(!0),c(null);let e=await fetch("/api/agents"),t=await e.json();if(!e.ok||!t.agents)throw Error(t.error||"Failed to load agents");o(t.agents)}catch(e){o([]),c(e instanceof Error?e.message:"Failed to load agents")}finally{h(!1)}})()},[]),(0,s.useEffect)(()=>{if(!e||0===l.length)return;let a=l.find(t=>t.id===e.id);if(!a){t(null),localStorage.removeItem("selected-agent"),localStorage.removeItem("selected-agent-id");return}(a.name!==e.name||a.description!==e.description)&&(t(a),localStorage.setItem("selected-agent-id",a.id),localStorage.setItem("selected-agent",JSON.stringify(a)))},[l,e]),a)?null:(0,r.jsx)(n.P.div,{className:"gallery-shell h-screen",initial:{opacity:0,y:25},animate:{opacity:1,y:0},transition:{duration:.9,ease:"easeOut"},children:(0,r.jsx)("div",{className:"flex h-full flex-col",children:(0,r.jsx)("main",{className:"flex-1 overflow-hidden px-3 py-4 sm:px-6 sm:py-6",children:e?(0,r.jsx)("div",{className:"mx-auto flex h-full max-w-5xl justify-center",children:(0,r.jsx)("div",{className:"h-full w-full",children:(0,r.jsx)(P,{agent:e,agents:l,onAgentSelected:e=>{t(e),localStorage.setItem("selected-agent-id",e.id),localStorage.setItem("selected-agent",JSON.stringify(e))},isAgentsLoading:m})})}):(0,r.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-4 px-6 text-center",children:[(0,r.jsx)("p",{className:"max-w-sm text-sm uppercase tracking-[0.2em] text-muted-foreground",children:"Select a correspondent from the switcher to begin"}),d&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:d})]})})})})}a(6664)}},e=>{e.O(0,[79,225,647,516,358],()=>e(e.s=4465)),_N_E=e.O()}]);