PageSourceSearch

https://app.functionalmind.ai/_next/static/chunks/3802-506aada143ee5639.js

js functionalmind.ai collected 2026-10-05 12:00:47 UTC 86,626 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3802],{97030:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e,t){for(var s in t)Object.defineProperty(e,s,{enumerable:!0,get:t[s]})}(t,{default:function(){return r},noSSR:function(){return i}});let n=s(42430);s(52676),s(75271);let l=n._(s(32338));function a(e){return{default:(null==e?void 0:e.default)||e}}function i(e,t){return delete t.webpack,delete t.modules,e(t)}function r(e,t){let s=l.default,n={loading:e=>{let{error:t,isLoading:s,pastDelay:n}=e;return null}};e instanceof Promise?n.loader=()=>e:"function"==typeof e?n.loader=e:"object"==typeof e&&(n={...n,...e});let r=(n={...n,...t}).loader;return(n.loadableGenerated&&(n={...n,...n.loadableGenerated},delete n.loadableGenerated),"boolean"!=typeof n.ssr||n.ssr)?s({...n,loader:()=>null!=r?r().then(a):Promise.resolve(a(()=>null))}):(delete n.webpack,delete n.modules,i(s,n))}("function"==typeof t.default||"object"==typeof t.default&&null!==t.default)&&void 0===t.default.__esModule&&(Object.defineProperty(t.default,"__esModule",{value:!0}),Object.assign(t.default,t),e.exports=t.default)},53097:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"LoadableContext",{enumerable:!0,get:function(){return n}});let n=s(42430)._(s(75271)).default.createContext(null)},32338:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"default",{enumerable:!0,get:function(){return m}});let n=s(42430)._(s(75271)),l=s(53097),a=[],i=[],r=!1;function o(e){let t=e(),s={loading:!0,loaded:null,error:null};return s.promise=t.then(e=>(s.loading=!1,s.loaded=e,e)).catch(e=>{throw s.loading=!1,s.error=e,e}),s}class c{promise(){return this._res.promise}retry(){this._clearTimeouts(),this._res=this._loadFn(this._opts.loader),this._state={pastDelay:!1,timedOut:!1};let{_res:e,_opts:t}=this;e.loading&&("number"==typeof t.delay&&(0===t.delay?this._state.pastDelay=!0:this._delay=setTimeout(()=>{this._update({pastDelay:!0})},t.delay)),"number"==typeof t.timeout&&(this._timeout=setTimeout(()=>{this._update({timedOut:!0})},t.timeout))),this._res.promise.then(()=>{this._update({}),this._clearTimeouts()}).catch(e=>{this._update({}),this._clearTimeouts()}),this._update({})}_update(e){this._state={...this._state,error:this._res.error,loaded:this._res.loaded,loading:this._res.loading,...e},this._callbacks.forEach(e=>e())}_clearTimeouts(){clearTimeout(this._delay),clearTimeout(this._timeout)}getCurrentValue(){return this._state}subscribe(e){return this._callbacks.add(e),()=>{this._callbacks.delete(e)}}constructor(e,t){this._loadFn=e,this._opts=t,this._callbacks=new Set,this._delay=null,this._timeout=null,this.retry()}}function d(e){return function(e,t){let s=Object.assign({loader:null,loading:null,delay:200,timeout:null,webpack:null,modules:null},t),a=null;function o(){if(!a){let t=new c(e,s);a={getCurrentValue:t.getCurrentValue.bind(t),subscribe:t.subscribe.bind(t),retry:t.retry.bind(t),promise:t.promise.bind(t)}}return a.promise()}if(!r){let e=s.webpack?s.webpack():s.modules;e&&i.push(t=>{for(let s of e)if(t.includes(s))return o()})}function d(e,t){!function(){o();let e=n.default.useContext(l.LoadableContext);e&&Array.isArray(s.modules)&&s.modules.forEach(t=>{e(t)})}();let i=n.default.useSyncExternalStore(a.subscribe,a.getCurrentValue,a.getCurrentValue);return n.default.useImperativeHandle(t,()=>({retry:a.retry}),[]),n.default.useMemo(()=>{var t;return i.loading||i.error?n.default.createElement(s.loading,{isLoading:i.loading,pastDelay:i.pastDelay,timedOut:i.timedOut,error:i.error,retry:a.retry}):i.loaded?n.default.createElement((t=i.loaded)&&t.default?t.default:t,e):null},[e,i])}return d.preload=()=>o(),d.displayName="LoadableComponent",n.default.forwardRef(d)}(o,e)}function u(e,t){let s=[];for(;e.length;){let n=e.pop();s.push(n(t))}return Promise.all(s).then(()=>{if(e.length)return u(e,t)})}d.preloadAll=()=>new Promise((e,t)=>{u(a).then(e,t)}),d.preloadReady=e=>(void 0===e&&(e=[]),new Promise(t=>{let s=()=>(r=!0,t());u(i,e).then(s,s)})),window.__NEXT_PRELOADREADY=d.preloadReady;let m=d},63802:function(e,t,s){"use strict";s.d(t,{Z:function(){return e1}});var n=s(52676),l=s(75271),a=s(16727),i=s.n(a),r=s(23600),o=s(34774),c=s.n(o),d=s(18327),u=s(43743),m=s(73513),x=s(34547),p=s(53678),h=s(84034),f=s(24695),g=s(99839),b=s(50084),v=s(19),j=s(63557),y=s(31670),w=s(56881),N=s(20664),k=s(92666),_=s(16624),C=s(4940),S=e=>{let{isOpen:t,onClose:s,copyToClipboard:a,align:i="left"}=e,{t:r}=(0,g.$G)("chat"),o=(0,l.useRef)(null);return((0,l.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&s()};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[s]),t)?(0,n.jsx)(n.Fragment,{children:(0,n.jsx)("div",{ref:o,style:{position:"absolute",bottom:25,..."left"===i?{left:0}:{right:0}
1,boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.15)"},className:"w-48 bg-white rounded-lg border z-50",onClick:e=>e.stopPropagation(),children:(0,n.jsx)("div",{children:(0,n.jsxs)("div",{children:[(0,n.jsx)("button",{className:"w-full py-2 pl-5 pr-3 hover:bg-iron-100 cursor-pointer transition-colors text-black font-medium text-left flex items-center justify-between",onClick:()=>{a(),s()},children:(0,n.jsx)("span",{children:r("asMarkdown")})}),(0,n.jsx)("button",{className:"w-full py-2 pl-5 pr-3 hover:bg-iron-100 cursor-pointer transition-colors text-black font-medium text-left flex items-center justify-between",onClick:()=>{a("apa"),s()},children:(0,n.jsx)("span",{children:r("asHtmlAPA")})}),(0,n.jsx)("button",{className:"w-full py-2 pl-5 pr-3 hover:bg-iron-100 cursor-pointer transition-colors text-black font-medium text-left flex items-center justify-between",onClick:()=>{a("vancouver"),s()},children:(0,n.jsx)("span",{children:r("asHtmlVancouver")})})]})})})}):null},Z=s(97489),I=e=>{var t,s,a;let{messages:i,currentMessage:r,preprocessedMessage:o,preprocessedCopyVancouverMessage:c,setMessageDisplayed:I,sourcesReferences:T,sourcesText:F}=e,{updateMessage:E,sendMessage:P}=(0,l.useContext)(x.p5),{selectedConversationId:M,handleCloneConversation:R}=(0,l.useContext)(Z.L),[z,A]=(0,l.useState)(!1),[O,L]=(0,l.useState)(!1),{setIsHimChatDisplayed:U,setIsHimChatOpen:D,hasHimActive:G,selectedHimMessage:B,setSelectedHimMessage:$}=(0,l.useContext)(b.n),[q,H]=(0,l.useState)(!1),{sources:V,openSources:K}=(0,w._)(),{subscriptionData:W,subscription:X}=(0,l.useContext)(m.J),Y=(null==W?void 0:W.tier)!=="freemium"&&!!(null==X?void 0:null===(t=X.planId)||void 0===t?void 0:t.endsWith("Yearly")),{user:J}=(0,l.useContext)(u.V),Q=(0,l.useSyncExternalStore)(p.Ld,p.y0,()=>p.WM),ee=null!==(s=r.id)&&void 0!==s?s:"live",et=Q.messageId===ee,[es,en]=(0,l.useState)(!1),el=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(!es)return;let e=e=>{var t;(null===(t=el.current)||void 0===t?void 0:t.contains(e.target))||en(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[es]),(0,l.useEffect)(()=>{et||en(!1)},[et]);let ea=(0,l.useRef)(null),{citationStyle:ei}=(0,y.Di)(),{t:er}=(0,g.$G)("chat"),eo=(0,C.useRouter)(),ec="/try"===eo.pathname,ed=i.findIndex(e=>e.id===r.id),eu=async e=>{let t=e?"vancouver"===e?c:o:"numbered"===ei?c:"hidden"===ei?(0,_.FU)(c):o;try{let e=await (0,v.TU)(t);await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([e],{type:"text/html"}),"text/plain":new Blob([t],{type:"text/plain"})})]),H(!0),setTimeout(()=>H(!1),1e3)}catch(e){(0,N._)(e.message)}},em=async()=>{if(!O&&M){L(!0);try{let e=await R(M,{branch:!0,...r.id?{upToMessageId:r.id}:{}});if(e){let t=eo.query["case-folder-id"];t?await eo.push("/folder/".concat(t,"?chat=").concat(e.id)):await eo.push({query:{...eo.query,chat:e.id}})}}finally{L(!1)}}},ex=(0,l.useMemo)(()=>(0,k.SG)(r.message,er("output.defaultTitle")),[r.message,er]);return(0,n.jsxs)("div",{className:"flex items-center justify-end space-x-2 pt-2 text-iron-400",children:[i.length>1?(0,n.jsxs)("div",{className:"flex items-center space-x-2 mr-1",onClick:()=>{},children:[(0,n.jsx)(j.Z,{name:"chevron_left",className:"hover:text-iron-800 cursor-pointer",onClick:()=>{ed>0&&I(i[ed-1])}}),(0,n.jsxs)("div",{className:"font-medium text-sm select-none",children:[ed+1,"/",i.length]}),(0,n.jsx)(j.Z,{name:"chevron_right",className:"hover:text-iron-800 cursor-pointer",onClick:()=>{ed<i.length-1&&I(i[ed+1])}})]}):(0,n.jsx)(n.Fragment,{}),(null!==(a=null==T?void 0:T.length)&&void 0!==a?a:0)>0&&(0,n.jsx)(f.Z,{content:er("sources.title"),children:(0,n.jsx)(j.Z,{name:"menu_book",fill:(null==V?void 0:V.messageId)===r.id,className:"hover:text-iron-800 cursor-pointer",onClick:()=>{var e;return K({messageId:null!==(e=r.id)&&void 0!==e?e:"",message:null!=F?F:"",references:null!=T?T:[]})}})}),(0,n.jsx)(f.Z,{content:er("like"),children:(0,n.jsx)(j.Z,{name:"thumb_up",fill:"LIKE"===r.likeStatus,className:"hover:text-iron-800 cursor-pointer",onClick:()=>{var e;E(null!==(e=r.id)&&void 0!==e?e:"",{likeStatus:"LIKE"})}})}),(0,n.jsx)(f.Z,{content:er("dislike"),children:(0,n.jsx)(j.Z,{name:"thumb_down",fill:"DISLIKE"===r.likeStatus,className:"hover:text-iron-800 cursor-pointer",onClick:()=>{var e;E(null!==(e=r.id)&&void 0!==e?e:"",{likeStatus:"DISLIKE"})}})}),(0,n.jsx)(f.Z,{content:er("tts.listen"),children:(0,n.jsxs)("div",{className:"relative flex items-center",children:[et&&"loading"===Q.status?(0,n.jsx)("span",{className:"cursor-pointer",onClick:()=>en(e=>!e),children:(0,n.jsx)(d.Z,{type:"black",size:"xs"})}):(0,n.jsx)(j.Z,{name:"volume_up",fill:et,className:"hover:text-iron-800 cursor-pointer",onClick:()=>{var e,t;if(et){en(e=>!e);return}let s=null!==(t=null==J?void 0:null===(e=J.preferences)||void 0===e?void 0:e.tts_voice)&&void 0!==t?t:"eve",n=(0,h.F)(c);n&&(p.De(ee,n,s),en(!0))}}),es&&et&&(0,n.jsxs)("div",{ref:el,style:{position:"absolute",bottom:25,right:0,boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.15)"},className:"z-50 w-48 rounded-lg border bg-white p-2 text-black",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,n.jsx)("button",{type:"button","aria-label":"paused"===Q.status?er("tts.resume"):er("tts.pause"),className:"flex h-8 w-8 items-center justify-center rounded-full hover:bg-iron-100",onClick:()=>"paused"===Q.status?p.v4():p.wO(),children:(0,n.jsx)(j.Z,{name:"paused"===Q.status?"play_arrow":"pause",size:20})}),(0,n.jsx)("button",{type:"button","aria-label":er("tts.stop"),className:"flex h-8 w-8 items-center justify-center rounded-full hover:bg-iron-100",onClick:()=>{p.sT(),en(!1)},children:(0,n.jsx)(j.Z,{name:"stop",size:20})})]}),(0,n.jsx)("div",{className:"mt-2 flex items-center justify-center gap-1",children:p.dF.map(e=>(0,n.jsxs)("button",{type:"button",className:"rounded px-1.5 py-0.5 text-[11px] font-medium transition-colors ".concat(Q.rate===e?"bg-iron-800 text-white":"text-iron-600 hover:bg-iron-100"),onClick:()=>p.FY(e),children:[e,"x"]},e))})]})]})}),(0,n.jsx)(f.Z,{content:er("copy"),children:(0,n.jsxs)("div",{ref:ea,className:"relative flex items-center cursor-pointer hover:text-iron-800",onClick:()=>A(e=>!e),children:[q?(0,n.jsx)(j.Z,{name:"check"}):(0,n.jsx)(j.Z,{name:"content_copy"}),(0,n.jsx)(S,{isOpen:z,onClose:()=>A(!1),copyToClipboard:eu})]})}),!ec&&M&&(0,n.jsx)(f.Z,{content:er("branchFromHere"),children:O?(0,n.jsx)(d.Z,{type:"black",size:"xs"}):(0,n.jsx)(j.Z,{name:"alt_route",className:"hover:text-iron-800 cursor-pointer",onClick:()=>void em()})}),ex&&(0,n.jsx)(f.Z,{content:er("turnIntoOutput"),children:(0,n.jsx)(j.Z,{name:"note_add",className:"hover:text-iron-800 cursor-pointer",onClick:()=>{ex&&r.id&&E(r.id,{message:ex})}})}),Y&&(0,n.jsx)(f.Z,{content:ec?er("try.onlyAfterRegister"):er("him"),children:(0,n.jsx)(j.Z,{name:"psych
1ology_alt",fill:r.id===(null==B?void 0:B.id),size:20,className:"".concat(G||ec?"cursor-not-allowed":"hover:text-iron-800 cursor-pointer transition-colors "),onClick:()=>{G||ec||($(r),U(!0),D(!0))}})}),(0,n.jsx)(f.Z,{content:er("regenerate"),children:(0,n.jsx)(j.Z,{name:"autorenew",className:"hover:text-iron-800 cursor-pointer",onClick:()=>{var e;P("",{regenerateMsgId:null!==(e=r.id)&&void 0!==e?e:""})}})})]})},T=e=>{let{followupQuestions:t}=e,{t:s}=(0,g.$G)("chat"),{sendMessage:a}=(0,l.useContext)(x.p5),i=e=>{a(e)};return(0,n.jsxs)("div",{className:"mt-6",children:[(0,n.jsx)("h4",{className:"font-semibold text-black select-none",children:s("related")}),(0,n.jsx)("ul",{className:"",children:t.map((e,t)=>(0,n.jsxs)("li",{className:"flex items-center justify-between py-4 border-b border-iron-800 border-opacity-40 hover:bg-gray-100 focus-within:bg-gray-100",role:"button",tabIndex:0,"aria-label":"Follow-up question: ".concat(e),onClick:()=>i(e),children:[(0,n.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,n.jsx)(j.Z,{name:"prompt_suggestion",className:"text-iron-600 flex-shrink-0"}),(0,n.jsx)("p",{className:"text-iron-800",children:e})]}),(0,n.jsx)(j.Z,{name:"add_2",className:"text-iron-600 flex-shrink-0"})]},t))})]})},F=s(89196),E=s(4210),P=s(40715),M=s(58124),R=s(68834);let z={assistant:{icon:"assistant",label:"Assistant"},fm:{icon:"menu_book",label:"FxM clinical agent"}},A=e=>(null==e?void 0:e.agent)==="assistant"?"assistant":"fm",O=e=>z[A(e)];var L=s(12709),U=s(36087),D=s(93453),G=s(59415),B=s(85549),$=s(5005),q=s(38710),H=s(840),V=s(23370),K=s(85624),W=s(85295),X=s(31071);let Y=new Map;var J=e=>{var t,s,a;let{title:i,content:o,rawContent:c,isIncomplete:u,isTruncated:m=!1,messageId:x,onSaveContent:p,renderView:h,copySource:f,references:b}=e,{t:w}=(0,g.$G)("chat"),k=(0,C.useRouter)(),{citationStyle:I,setCitationStyle:T}=(0,y.Di)(),F=(0,l.useContext)(V.CO),{selectedConversationId:M,selectedConversation:R}=(0,l.useContext)(Z.L),z=(0,l.useContext)(K.B),A=null==z?void 0:z.refetchCaseFolderFiles,O=null==z?void 0:z.showIncomingFolderFile,L="".concat(x,":").concat(null!=i?i:""),U=null!==(s=Y.get(L))&&void 0!==s?s:null,[D,J]=(0,l.useState)("view"),Q=(0,l.useRef)(null),ee=(0,l.useRef)(null),[et,es]=(0,l.useState)(null),en=(0,l.useRef)(null),el=(0,l.useRef)(null),[ea,ei]=(0,l.useState)(c),[er,eo]=(0,l.useState)(""),ec=e=>{var t,s,n,l;let a=null===(t=Q.current)||void 0===t?void 0:t.closest(".overflow-y-auto");a&&(el.current={el:a,top:a.scrollTop}),es(null!==(l=null===(s=ee.current)||void 0===s?void 0:s.offsetHeight)&&void 0!==l?l:null);let i=e=>(e.textContent||"").replace(/\s+/g,"").slice(0,32),r=null,o=null===(n=ee.current)||void 0===n?void 0:n.querySelectorAll("p, li, h1, h2, h3");if(o)for(let e of Array.from(o)){let t=e.getBoundingClientRect();if(t.bottom>140&&t.height>4){let s=i(e);if(s.length>=12){r={text:s,top:t.top};break}}}"edit"===e&&eo((0,E.Ul)(ea)),J(e);let c=el.current;if(c&&r){let e=()=>{var e;let t=null===(e=ee.current)||void 0===e?void 0:e.querySelectorAll("p, li, h1, h2, h3");if(t){for(let e of Array.from(t))if(i(e)===r.text){let t=e.getBoundingClientRect().top-r.top;Math.abs(t)>2&&(c.el.scrollTop+=t);return}}};requestAnimationFrame(e),setTimeout(e,80),setTimeout(e,200),setTimeout(e,400)}},[ed,eu]=(0,l.useState)(c),[em,ex]=(0,l.useState)(!1),[ep,eh]=(0,l.useState)(!1),[ef,eg]=(0,l.useState)(U),[eb,ev]=(0,l.useState)(!!U),[ej,ey]=(0,l.useState)(!1),[ew,eN]=(0,l.useState)(null),[ek,e_]=(0,l.useState)(null),[eC,eS]=(0,l.useState)(!1),eZ=(0,l.useRef)(null),[eI,eT]=(0,l.useState)(!0);(0,l.useEffect)(()=>{let e=eZ.current;if(!e)return;let t=new IntersectionObserver(e=>{let[t]=e;return eT(t.isIntersecting)});return t.observe(e),()=>t.disconnect()},[u,eb]);let[eF,eE]=(0,l.useState)(null),eP=(0,l.useRef)(u);(0,l.useEffect)(()=>{u?(eP.current=!0,ei(c),eu(c)):eP.current&&(eP.current=!1,ei(c),eu(c))},[u,c]),(0,l.useEffect)(()=>{if("edit"!==D)return;let e=e=>{var t;(null===(t=Q.current)||void 0===t?void 0:t.contains(e.target))||ec("view")};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[D]);let eM=ea!==ed,[eR,ez]=(0,l.useState)("idle"),eA=(0,l.useRef)(ea);eA.current=ea,(0,l.useEffect)(()=>
1{if(u||!eM||!p)return;let e=setTimeout(async()=>{let e=eA.current;ez("saving");try{await p(e),eu(e),ez("saved")}catch(e){ez("idle"),(0,N._)(w("output.saveFailed"))}},1500);return()=>clearTimeout(e)},[ea,eM,u]);let eO=null==z?void 0:z.caseFolderUploadingFiles;(0,l.useEffect)(()=>{if("edit"!==D&&!ef&&x&&(null==eO?void 0:eO.length)){for(let t of eO)if("completed"===t.status&&t.fileMetadata)try{let s=JSON.parse(t.fileMetadata);if("chat_output"===s.origin&&s.message_id===x&&(!s.output_title||!i||s.output_title===i)){var e;let n={output:null,fileId:t.fileId,content:null!==(e=t.parsedText)&&void 0!==e?e:eA.current,revision:1,history:[{action:s.replaces_file_id?"replaced":"added",at:t.createdAt}]};Y.set(L,n),eg(n);return}}catch(e){}}},[eO,ef,x,i,D]);let eL=k.pathname.includes("/folder/[case-folder-id]")?k.query["case-folder-id"]:null!==(a=null==R?void 0:null===(t=R.caseFolder)||void 0===t?void 0:t.id)&&void 0!==a?a:void 0,eU=i||w("output.defaultTitle"),eD=!!ef&&ea!==ef.content,eG=async e=>{(0,X.q)("OUTPUT_COPIED",{message_id:x});try{if(e){let t=f&&(null==b?void 0:b.length)?"vancouver"===e?(0,_.aZ)(f,b):(0,_.Bo)(f,b,!1):ea,s=await (0,v.TU)(t);await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([s],{type:"text/html"}),"text/plain":new Blob([t],{type:"text/plain"})})])}else await navigator.clipboard.writeText(ea);(0,N.x)(w("output.copied"))}catch(e){(0,N._)(w("output.copyFailed"))}},eB=async e=>{(0,X.q)("OUTPUT_DOWNLOADED",{message_id:x,format:e}),eS(!0);try{await (0,H.bx)(e,eU,ea)}catch(e){(0,N._)(w("download.failed"))}finally{eS(!1)}},e$=async()=>{(0,X.q)("OUTPUT_PRINTED",{message_id:x});let e=await (0,v.TU)(ea),t=await (0,G.yG)(),s=window.open("","_blank");s&&(s.document.write("<html><head><title>".concat(eU,"</title><style>\n        body { font-family: sans-serif; max-width: 720px; margin: 40px auto; line-height: 1.5; }\n        table { border-collapse: collapse; } td, th { border: 1px solid #ccc; padding: 6px 10px; }\n      </style></head><body>").concat(t,"<h1>").concat(eU,"</h1>").concat(e,"</body></html>")),s.document.close(),s.focus(),s.print())},eq=async e=>{var t,s,n,l,a;if(!eL||!F)return null;let i="".concat(eU).concat(null!==(t=null==e?void 0:e.titleSuffix)&&void 0!==t?t:"");eh(!0),null==O||O(eL,"".concat(i,".md"));try{let t=await F.createOutput({caseFolderId:eL,conversationId:M,messageId:x,title:i,contentText:ea,replaceFileId:null!==(s=null==e?void 0:e.replaceFileId)&&void 0!==s?s:null}),r={output:t,fileId:null!==(n=t.file_id)&&void 0!==n?n:null,content:ea,revision:(null!==(l=null==ef?void 0:ef.revision)&&void 0!==l?l:0)+1,history:[...null!==(a=null==ef?void 0:ef.history)&&void 0!==a?a:[],{action:(null==e?void 0:e.replaceFileId)?"replaced":(null==e?void 0:e.titleSuffix)?"newFile":"added",at:new Date().toISOString()}]};return Y.set(L,r),eg(r),null==A||A(),t}catch(e){return(0,N._)(w("output.attachFailed")),null==A||A(),null}finally{eh(!1)}},eH=async()=>{await eq()&&(ev(!0),(0,N.x)(w("output.attached")))},eV=async()=>{ey(!1),await eq({replaceFileId:null==ef?void 0:ef.fileId})&&(0,N.x)(w("output.fileReplaced"))},eK=async()=>{var e;ey(!1),await eq({titleSuffix:" (rev ".concat((null!==(e=null==ef?void 0:ef.revision)&&void 0!==e?e:1)+1,")")})&&(0,N.x)(w("output.attached"))},[eW,eX]=(0,l.useState)(!1),eY=async()=>{if(null==ef?void 0:ef.output){eE(ef.output);return}eX(!0)},eJ=async()=>{eX(!1);let e=await eq();e&&((0,N.x)(w("output.attached")),eE(e))};if(eb&&ef)return(0,n.jsxs)("div",{className:"my-4 flex w-full items-center justify-between gap-3 border border-iron-200 rounded-lg bg-white shadow-sm px-3 py-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-700 min-w-0",children:[(0,n.jsx)(j.Z,{name:"task",size:18,className:"shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:w("output.savedToFolder",{title:eU})})]}),(0,n.jsx)("button",{type:"button",className:"text-xs font-semibold text-iron-600 hover:text-black shrink-0",onClick:()=>ev(!1),children:w("output.openInline")})]});let eQ="flex items-center gap-1 px-2 py-1 rounded-none text-xs font-medium text-iron-600 hover:text-black hover:bg-gray-100 disabled:opacity-50",e0=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"footer";return(0,n.jsxs)(n.Fragment,{children:[ef?(0,n.jsxs)("button",{type:"button",className:"".concat(eQ," ").concat(eD?"font-semibold text-black":""," ").concat(ep?"animate-pulse":""),disabled:!eD||ep,onClick:()=>ey(!0),children:[ep?(0,n.jsx)(d.Z,{type:"black",size:"xs"}):(0,n.jsx)(j.Z,{name:"sync",size:16}),ep?w("output.attaching"):eD?w("output.attach"):w("output.attachedBadge")]}):(0,n.jsxs)("div",{className:"relative group",children:[(0,n.jsxs)("button",{type:"button",className:"".concat(eQ," ").concat(eL?"":"cursor-not-allowed"," ").concat(ep?"animate-pulse":""),disabled:!eL||ep,onClick:()=>void eH(),children:[ep?(0,n.jsx)(d.Z,{type:"black",size:"xs"}):(0,n.jsx)(j.Z,{name:"create_new_folder",size:16}),ep?w("output.attaching"):w("output.attach")]}),!eL&&(0,n.jsx)("div",{className:"absolute bottom-full left-0 mb-1 hidden group-hover:block whitespace-nowrap rounded bg-black px-2 py-1 text-[11px] text-white",children:w("output.attachRequiresFolder")})]}),(null==ef?void 0:ef.fileId)&&(0,n.jsxs)("button",{type:"button",className:eQ,onClick:()=>ef.fileId&&(0,W.sk)(ef.fileId),children:[(0,n.jsx)(j.Z,{name:"folder_open",size:16}),w("output.showInFiles")]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("button",{type:"button",className:eQ,onClick:()=>eN(t=>t===e?null:e),children:[(0,n.jsx)(j.Z,{name:"content_copy",size:16}),w("output.copy")]}),(0,n.jsx)(S,{isOpen:ew===e,onClose:()=>eN(null),copyToClipboard:eG,align:"right"})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("button",{type:"button",className:eQ,disabled:eC,onClick:()=>e_(t=>t===e?null:e),children:[eC?(0,n.jsx)(d.Z,{type:"black",size:"xs"}):(0,n.jsx)(j.Z,{name:"download",size:16}),w("download.action")]}),(0,n.jsx)(q.Z,{isOpen:ek===e,onClose:()=>e_(null),placement:"above",items:[{key:"md",label:w("download.markdown"),ext:".md",icon:"markdown"},{key:"pdf",label:w("download.pdf"),ext:".pdf",icon:"picture_as_pdf"},{key:"docx",label:w("download.word"),ext:".docx",icon:"docs"}],onSelect:e=>void eB(e)})]}),(0,n.jsxs)("button",{type:"button",className:eQ,onClick:()=>void e$(),children:[(0,n.jsx)(j.Z,{name:"print",size:16}),w("output.print")]}),(0,n.jsxs)("button",{type:"button",className:eQ,disabled:!eL||ep,onClick:()=>void eY(),children:[(0,n.jsx)(j.Z,{name:"mail",size:16}),w("output.email")]}),(0,n.jsx)("button",{type:"button",title:"author"===I?w("citationStyleToggle.toNumbered"):"numbered"===I?w("citationStyleToggle.toHidden"):w("citationStyleToggle.toAuthor"),"aria-label":"Citation style",className:eQ,onClick:()=>T("author"===I?"numbered":"numbered"===I?"hidden":"author"),children:(0,n.jsx)(j.Z,{name:"author"===I?"badge":"numbered"===I?"format_list_numbered":"visibility_off",size:16})})]})},e1=em?ea:o;return(0,n.jsxs)("div",{ref:Q,className:"output-block my-4 border border-iron-200 rounded-lg bg-white max-w-full shadow-sm",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 flex items-center justify-between gap-2 rounded-t-lg px-3 py-2 bg-white border-b border-gray-200 text-xs font-semibold",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(j.Z,{name:"description",size:16,className:"shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:w("output.header",{title:eU})}),u&&(0,n.jsx)(d.Z,{type:"black",size:"xs"}),m&&(0,n.jsx)("span",{className:"shrink-0 text-[11px] font-medium text-amber-700 bg-amber-100 px-1.5 py-0.5 rounded",children:w("output.truncatedBadge")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[!u&&!eI&&(0,n.jsx)("div",{className:"flex items-center gap-0.5",onMouseDown:e=>e.preventDefault(),children:e0("header")}),!u&&ef&&(0,n.jsx)("span",{className:"text-[11px] text-iron-600",children:eD?w("output.f
1ileOutdated"):w("output.attachedBadge")}),ef&&(0,n.jsx)("button",{type:"button","aria-label":w("output.collapse"),className:"text-iron-500 hover:text-black",onClick:()=>ev(!0),children:(0,n.jsx)(j.Z,{name:"collapse_all",size:16})})]})]}),(0,n.jsx)("div",{ref:ee,className:"px-4 py-3",style:et?{minHeight:et}:void 0,children:u?(0,n.jsx)(r.UG,{remarkPlugins:[P.Z],children:o}):"edit"===D?(0,n.jsx)("div",{onBlur:e=>{var t;let s=e.relatedTarget;!s||(null===(t=Q.current)||void 0===t?void 0:t.contains(s))||ec("view")},children:(0,n.jsx)(B.Z,{value:er,inline:!0,onChange:e=>{eo(e),ei((0,E.Ad)(e)),ex(!0)},onEditorReady:e=>{requestAnimationFrame(()=>{var t;if(!e)return;let s=en.current,n=s?null===(t=e.view.posAtCoords({left:s.x,top:s.y}))||void 0===t?void 0:t.pos:void 0;e.chain().focus(null!=n?n:"start",{scrollIntoView:!1}).run();let l=el.current;l&&(l.el.scrollTop=l.top)})}})}):(0,n.jsx)("div",{className:"cursor-text output-view",onClick:e=>{e.target.closest("a, [role='tooltip']")||(en.current={x:e.clientX,y:e.clientY},ec("edit"))},children:h?h(e1):(0,n.jsx)(r.UG,{remarkPlugins:[P.Z],children:e1})})}),!u&&ef&&ef.history.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap justify-end gap-x-4 gap-y-0.5 px-4 pb-2 text-[11px] text-iron-500",children:ef.history.map((e,t)=>(0,n.jsxs)("span",{children:[w("output.history_".concat(e.action))," \xb7 ",new Date(e.at).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})]},t))}),!u&&(0,n.jsxs)("div",{ref:eZ,className:"flex flex-wrap items-center justify-end gap-1 border-t border-gray-200 bg-gray-50 rounded-b-lg px-3 py-2",onMouseDown:e=>e.preventDefault(),children:[(0,n.jsx)("span",{className:"mr-auto text-[11px] text-iron-500 select-none",children:"saving"===eR?w("output.autoSaving"):"saved"!==eR||eM?"":w("output.autoSaved")}),e0()]}),eW&&(0,n.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/40",children:(0,n.jsxs)("div",{className:"bg-white rounded-lg shadow-xl p-6 w-[420px]",children:[(0,n.jsx)("div",{className:"font-semibold text-lg mb-2",children:w("output.emailConfirmTitle")}),(0,n.jsx)("p",{className:"text-sm text-iron-700 mb-4",children:w("output.emailConfirmBody",{title:eU})}),(0,n.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,n.jsx)("button",{type:"button",className:"px-4 py-2 rounded-none border border-iron-300 text-sm font-medium hover:bg-iron-50",onClick:()=>eX(!1),children:w("output.cancel")}),(0,n.jsx)("button",{type:"button",className:"px-4 py-2 rounded-none bg-black text-white text-sm font-medium hover:bg-iron-800",onClick:()=>void eJ(),children:w("output.emailConfirmAction")})]})]})}),ej&&(0,n.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/40",children:(0,n.jsxs)("div",{className:"bg-white rounded-lg shadow-xl p-6 w-[420px]",children:[(0,n.jsx)("div",{className:"font-semibold text-lg mb-2",children:w("output.updatePromptTitle")}),(0,n.jsx)("p",{className:"text-sm text-iron-700 mb-4",children:w("output.updatePromptBody",{title:eU})}),(0,n.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,n.jsx)("button",{type:"button",className:"px-4 py-2 rounded-none border border-iron-300 text-sm font-medium hover:bg-iron-50",onClick:()=>ey(!1),children:w("output.cancel")}),(0,n.jsx)("button",{type:"button",className:"px-4 py-2 rounded-none border border-black text-sm font-medium hover:bg-iron-50",onClick:()=>void eK(),children:w("output.saveAsNew")}),(0,n.jsx)("button",{type:"button",className:"px-4 py-2 rounded-none bg-black text-white text-sm font-medium hover:bg-iron-800",onClick:()=>void eV(),children:w("output.replaceFile")})]})]})}),eF&&(0,n.jsx)($.Z,{output:eF,onClose:()=>eE(null)})]})},Q=s(31101),ee=s(30967),et=s(29749),es=s(86723),en=s(91907),el=e=>{let{disabled:t=!1,label:s,className:a="ml-auto"}=e,{t:i}=(0,g.$G)("onboarding"),{state:r,refresh:o}=(0,et.Dm)(),[c,d]=(0,l.useState)(null),u=(null==r?void 0:r.state)==="completed"||!!(null==r?void 0:r.exited),m=async()=>{d("explained"),await (0,es.Lb)(),o()};return u&&!c?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button","data-onboarding-exit":!0,disabled:t,onClick:()=>d("confirm"),className:"text-sm font-medium text-iron-600 transition-colors hover:text-black disabled:opacity-50 ".concat(a),children:null!=s?s:i("exit.link",{defaultValue:"Skip onboarding"})}),c&&"undefined"!=typeof document&&(0,ee.createPortal)((0,n.jsx)("div",{"data-onboarding-exit":!0,className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50 p-4",children:(0,n.jsx)("div",{role:"dialog","aria-modal":"true",className:"w-full max-w-md bg-white p-6 shadow-2xl",children:"confirm"===c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("h2",{className:"font-title text-lg font-bold text-black",children:i("exit.title",{defaultValue:"Finish setting up first?"})}),(0,n.jsx)("p",{className:"mt-2 text-sm leading-relaxed text-iron-900",children:i("exit.body",{defaultValue:"This takes about five minutes and it is the fastest way to learn what FunctionalMind can do. You can stop at any point and pick it up later."})}),(0,n.jsxs)("div",{className:"mt-6 flex items-center justify-end gap-4",children:[(0,n.jsx)("button",{type:"button",onClick:()=>void m(),className:"text-sm font-medium text-iron-600 transition-colors hover:text-black",children:i("exit.explore",{defaultValue:"Explore on my own"})}),(0,n.jsx)(Q.Z,{autoFocus:!0,variant:"primary",classNameT:"!py-2 text-sm",onClick:()=>d(null),children:i("exit.continue",{defaultValue:"Continue onboarding"})})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("h2",{className:"font-title text-lg font-bold text-black",children:i("exit.doneTitle",{defaultValue:"Go ahead and explore"})}),(0,n.jsx)("p",{className:"mt-2 text-sm leading-relaxed text-iron-900",children:i("exit.doneBody",{defaultValue:"Onboarding stays where you left it. Use the Resume onboarding button at the top right to come back to it, or click the gear icon at the bottom left of the sidebar, open Settings, and under Guided tour choose Start to begin again."})}),(0,n.jsx)("div",{className:"mt-6 flex",children:(0,n.jsx)(Q.Z,{autoFocus:!0,variant:"primary",classNameT:"!py-2 text-sm",onClick:()=>{d(null),window.location.assign("/chat?new=1")},children:i("exit.gotIt",{defaultValue:"Got it"})})})]})})}),(0,en.$)())]})};class ea extends l.Component{static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?(0,n.jsx)(ec,{label:this.props.fallbackLabel}):this.props.children}constructor(e){super(e),this.state={hasError:!1}}}let ei=e=>{let{children:t}=e,{refresh:s,resume:a}=(0,et.Dm)();return(0,l.useEffect)(()=>{s()},[s]),(0,n.jsx)("div",{onClickCapture:e=>{var t;let s=e.target;null!=s&&null!==(t=s.closest)&&void 0!==t&&t.call(s,"[data-onboarding-exit]")||a()},className:"my-4 border border-gray-200 rounded-lg bg-gray-50 max-w-xl",children:t})},er=e=>{let{icon:t,title:s,right:l}=e;return(0,n.jsxs)("div",{className:"flex justify-between items-center px-3 py-2 border-b border-gray-200 rounded-t-lg text-xs font-semibold",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(j.Z,{name:t,size:16}),(0,n.jsx)("span",{children:s})]}),l]})},eo=e=>{let{children:t}=e;return(0,n.jsx)("div",{className:"px-3 py-3",children:t})},ec=e=>{let{label:t}=e;return(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-red-600",children:[(0,n.jsx)(j.Z,{name:"error",size:18}),(0,n.jsx)("span",{children:t})]})})})};var ed=s(19300),eu=s(34155);let em=new Set;var ex=s(58468);let ep=new Set;var eh=s(80980),ef=s(14875),eg=s(17957),eb=s(9746),ev=s(24851);let ej=new Set;var ey=s(39962);let ew=e=>{var t;return(null==e?void 0:null===(t=e.response)||void 0===t?void 0:t.status)===403};var eN=s(87982),ek=s(97431),e_=s(48534);
1let eC={"file-upload":e=>{let{data:t,isLast:s}=e,{t:a}=(0,g.$G)("chat"),{sendCardEvent:i}=(0,l.useContext)(x.p5),{handleUploadFile:r,uploadingFiles:o,caseFolderUploadingFiles:c}=(0,l.useContext)(K.B),u="string"==typeof t.caseFolderId?t.caseFolderId:void 0,m=!0===t.onboarding,p=(0,l.useRef)(null),[h,f]=(0,l.useState)(!1),[b,v]=(0,l.useState)(!1),[y,w]=(0,l.useState)([]),[k,_]=(0,l.useState)(!1),C=(0,l.useRef)(!1),S=s&&!C.current&&!k,Z=async e=>{if(!e.length)return;let t=(u?c:o).length,{validFiles:s,errors:n}=await (0,ed.ox)(e,t,ed.CI.CASE_FOLDER_MAX_FILES);for(let e of n)e.startsWith("max_files:")?(0,N._)(a("maxFilesExceededHint",{max:ed.CI.CASE_FOLDER_MAX_FILES})):"file_type_not_allowed"===e?(0,N._)(a("fileNotAllowed")):e.startsWith("file_too_large:")?(0,N._)("".concat(a("fileTooLarge")," ").concat(e.split(":")[1],"MB.")):"pdf_password"===e?(0,N._)(a("pdfPasswordProtected")):(0,N._)(a("fileNotAllowed"));if(s.length){f(!0);try{let e=(await r(s,u)).filter(e=>e.ok);e.length>0&&!C.current&&(C.current=!0,w(e.map(e=>e.fileName)),await i("Files uploaded and processed: ".concat(e.map(e=>{var t;return"".concat(e.fileName," (").concat(null!==(t=e.fileType)&&void 0!==t?t:"doc",")")}).join(", "))))}finally{f(!1)}}},I=async()=>{if(S&&!b){v(!0);try{let e=await fetch("/onboarding-samples/SAMPLE-case-summary-51F.txt");if(!e.ok)throw Error("status ".concat(e.status));let t=await e.blob(),s=new File([t],"SAMPLE-case-summary-51F.txt",{type:"text/plain"}),n=(await r([s],u)).find(e=>e.ok);n&&!C.current?(C.current=!0,w([n.fileName]),await i("The clinician used the sample case summary: ".concat(n.fileName," (doc). ")+"It is a generated sample document for a 51-year-old woman with fatigue and a borderline A1c, now in this folder's Files.")):n||(0,N._)(a("fileUploadFailed",{fileName:s.name,error:""}))}catch(e){(0,N._)(a("fileUploadFailed",{fileName:"SAMPLE-case-summary-51F.txt",error:e.message}))}finally{v(!1)}}},T=async()=>{!C.current&&(C.current=!0,_(!0),m&&await i("The user skipped the upload for now."))};return y.length>0?(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-700",children:[(0,n.jsx)(j.Z,{name:"check",size:18}),(0,n.jsx)("span",{children:a("cards.fileUpload.done",{files:y.join(", ")})})]})})}):!k&&(s||h)?(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:"upload_file",title:a("cards.fileUpload.title")}),(0,n.jsxs)(eo,{children:[(0,n.jsx)("p",{className:"text-xs text-iron-600 mb-3",children:a("cards.fileUpload.hint")}),h||b?(0,n.jsxs)("div",{className:"flex items-center gap-3 text-sm text-iron-600",children:[(0,n.jsx)(d.Z,{type:"black",size:"xs"}),(0,n.jsx)("span",{children:b?a("cards.fileUpload.generatingSample"):a("cards.fileUpload.uploading")})]}):(0,n.jsxs)("div",{className:"flex w-full flex-wrap items-center gap-3",children:[(0,n.jsx)(Q.Z,{variant:"primary",disabled:!S,classNameT:"!py-2 text-sm",onClick:()=>{var e;return null===(e=p.current)||void 0===e?void 0:e.click()},children:a("cards.fileUpload.choose")}),m&&(0,n.jsx)(Q.Z,{variant:"white",disabled:!S,classNameT:"!py-2 text-sm",onClick:()=>void I(),children:a("cards.fileUpload.sample")}),m?(0,n.jsx)(el,{disabled:!S,className:"ml-auto"}):(0,n.jsx)(Q.Z,{variant:"white",disabled:!S,classNameT:"!py-2 text-sm",onClick:()=>void T(),children:a("cards.fileUpload.cancel")})]}),(0,n.jsx)("input",{multiple:!0,type:"file",accept:ed.oD,ref:p,className:"hidden",onChange:e=>{var t;let s=Array.from(null!==(t=e.target.files)&&void 0!==t?t:[]);e.target.value="",Z(s)}})]})]}):(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-500",children:[(0,n.jsx)(j.Z,{name:"upload_file",size:18}),(0,n.jsx)("span",{children:a("cards.fileUpload.title")})]})})})},"navigate-folder":e=>{let{data:t,messageId:s,isLast:a,isLive:i}=e,{t:r}=(0,g.$G)("chat"),o=(0,C.useRouter)(),{isLoadingSendMsg:c}=(0,l.useContext)(x.p5),{selectedConversationId:d}=(0,l.useContext)(Z.L),u="string"==typeof t.caseFolderId?t.caseFolderId:null,m="string"==typeof t.title?t.title:"",p="number"==typeof t.conversationId?t.conversationId:d,h=o.query["case-folder-id"]===u,f=u?"/folder/".concat(u).
1concat(p?"?chat=".concat(p):""):null;return((0,l.useEffect)(()=>{if(!f||!i||!a||c||h)return;let e="".concat(s,":").concat(u);em.has(e)||(em.add(e),(0,eu.t)(m),o.push(f))},[f,i,a,c,h,s,u,o,m]),u)?(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,n.jsx)(j.Z,{name:"folder",size:18}),(0,n.jsx)("span",{children:r("cards.navigateFolder.created",{title:m||"…"})})]}),!h&&f&&(0,n.jsx)(Q.Z,{variant:"black",classNameT:"!py-1.5 !px-3 text-xs shrink-0",onClick:()=>void o.push(f),children:r("cards.navigateFolder.open")})]})})}):null},"fm-handoff":e=>{let{data:t,messageId:s,isLast:a,isLive:i}=e,{t:r}=(0,g.$G)("chat"),{sendMessage:o,isLoadingSendMsg:c,chatMessages:u,awaitingReplyTo:m}=(0,l.useContext)(x.p5),[p,h]=(0,l.useState)(!1),[f,b]=(0,l.useState)(!1),v="string"==typeof t.prompt?t.prompt:"",y="".concat(s,":fm-handoff"),w=u.findIndex(e=>e.id===s),N=w<0?[]:u.slice(w+1),k=N.findIndex(e=>"AI"===e.type?"assistant"===A(e.metadata):!(0,ex.IA)(e)),_=(k<0?N:N.slice(0,k)).filter(e=>"AI"===e.type),C=_.some(e=>{var t;return!!(null===(t=e.message)||void 0===t?void 0:t.trim())}),S=_.length>0&&!C,Z=l.useCallback(async()=>{ep.add(y),b(!1);try{await o(v,{agent:"fm",suppressBubble:!0})}catch(e){ep.delete(y),b(!0)}},[y,v,o]);if((0,l.useEffect)(()=>{v&&i&&a&&!c&&(ep.has(y)||Z())},[v,i,a,c,y,Z]),!v)return null;let I=!!m&&(k<0?N:N.slice(0,k)).some(e=>e.id===m),T=ep.has(y)&&c||I,F=f||S,E=!c&&!I&&!C&&(F||!i||!ep.has(y));return(0,n.jsx)(ei,{children:(0,n.jsxs)(eo,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-700",children:[T?(0,n.jsx)(d.Z,{type:"black",size:"xs"}):(0,n.jsx)(j.Z,{name:"science",size:18}),(0,n.jsx)("span",{children:r(T?"cards.fmHandoff.working":E&&(F||!i)?"cards.fmHandoff.failed":"cards.fmHandoff.label")})]}),E&&(0,n.jsxs)("button",{type:"button",onClick:()=>void Z(),className:"mt-3 inline-flex items-center gap-1.5 rounded-none bg-black px-3 py-1.5 text-xs font-semibold text-white hover:bg-iron-800",children:[(0,n.jsx)(j.Z,{name:"send",size:14}),(0,n.jsx)("span",{children:r("cards.fmHandoff.run")})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),className:"flex items-center gap-1 mt-2 text-xs text-iron-600 hover:text-black",children:[(0,n.jsx)(j.Z,{name:p?"expand_less":"expand_more",size:16}),(0,n.jsx)("span",{children:r("cards.fmHandoff.viewRequest")})]}),p&&(0,n.jsx)("p",{className:"mt-2 text-xs text-iron-600 bg-gray-100 rounded-md p-2 whitespace-pre-wrap",children:v})]})})},"create-folder":e=>{let{data:t,isLast:s}=e,{t:a}=(0,g.$G)("chat"),i=(0,C.useRouter)(),{user:r,guest:o}=(0,l.useContext)(u.V),{sendCardEvent:c}=(0,l.useContext)(x.p5),{selectedConversationId:d,moveConversationToFolderLocally:m}=(0,l.useContext)(Z.L),{handleAddCaseFolder:p}=(0,l.useContext)(eh.E),h="string"==typeof t.suggestedTitle?t.suggestedTitle:"",f="number"==typeof t.conversationId?t.conversationId:d,[b,v]=(0,l.useState)(h),[y,w]=(0,l.useState)(!1),[k,_]=(0,l.useState)(null),S=(0,l.useRef)(!1),I=s&&!S.current,T=!0===t.onboarding,F=async()=>{let e=b.trim();if(e&&!S.current&&f){S.current=!0,w(!0);try{var t,s;let n=await (0,ef.jf)({title:e,conversation_id:f,account_id:null!==(s=null!==(t=null==r?void 0:r.accountId)&&void 0!==t?t:o.accountId)&&void 0!==s?s:0});_(n.title),null==p||p({id:n.case_folder_id,title:n.title,updatedAt:new Date().toISOString(),createdAt:new Date().toISOString()}),(0,eu.t)(n.title),null===n.conversation_id?await i.push("/folder/".concat(n.case_folder_id)):(m(n.conversation_id,{id:n.case_folder_id,title:n.title}),await i.push("/folder/".concat(n.case_folder_id,"?chat=").concat(n.conversation_id)),await c('Case folder "'.concat(n.title,'" created; we are now inside it.'),{caseFolderId:n.case_folder_id}))}catch(e){S.current=!1,(0,N._)(a("cards.createFolder.failed"))}finally{w(!1)}}};return!k&&(s||y)?(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:"create_new_folder",title:a("cards.createFolder.title")}),(0,n.jsxs)(eo,{children:[(0,n.jsx)("p",{className:"text-xs text-iron-600 mb-3",children:a("cards.createFolder.hint")}),(0,n.jsxs)("form",{className:"flex items-center gap-3",onSubmit:e=>{e.preventDefault(),F()},children:[(0,n.jsx)("input",{type:"text",value:b,onChange:e=>v(e.target.value),placeholder:a("cards.createFolder.placeholder"),disabled:!I||y,autoFocus:!0,className:"flex-1 border-b border-gray-300 bg-transparent px-1 py-2 text-sm focus:outline-none focus:border-gray-500"}),(0,n.jsx)(Q.Z,{variant:"black",classNameT:"!py-2 text-sm shrink-0",disabled:!I||!b.trim(),isLoading:y,children:a("cards.createFolder.create")})]}),T&&I&&(0,n.jsx)("div",{className:"mt-3 flex w-full",children:(0,n.jsx)(el,{})})]})]}):(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-700",children:[(0,n.jsx)(j.Z,{name:"folder",size:18}),(0,n.jsx)("span",{children:k?a("cards.navigateFolder.created",{title:k}):a("cards.createFolder.title")})]})})})},"create-protocol":e=>{let{data:t,isLast:s}=e,{t:a}=(0,g.$G)("chat"),{sendCardEvent:i}=(0,l.useContext)(x.p5),r="string"==typeof t.suggestedName?t.suggestedName:"",o="str
1ing"==typeof t.brief&&t.brief.trim()?t.brief.trim():void 0,c=!0===t.onboarding,[u,m]=(0,l.useState)(r),[p,h]=(0,l.useState)(!1),[f,b]=(0,l.useState)(null),[v,y]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),_=(0,l.useRef)(!1),C=s&&!_.current&&!w,S=C&&!!u.trim()&&!p,Z=async()=>{if(S){h(!0);try{b(await (0,ef.ck)(u.trim(),void 0,o))}catch(e){(0,N._)(a("cards.createProtocol.draftFailed"))}finally{h(!1)}}},I=async e=>{e&&!_.current&&(_.current=!0,y(e),await i('Protocol "'.concat(e.name,'" created.')))},T=async()=>{!_.current&&(_.current=!0,k(!0),c&&await i("The user skipped creating a protocol for now."))};return v?(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-700",children:[(0,n.jsx)(j.Z,{name:"check",size:18}),(0,n.jsx)("span",{children:a("cards.createProtocol.done",{name:v.name})})]})})}):!w&&(s||f||p)?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:"clinical_notes",title:a("cards.createProtocol.title")}),(0,n.jsxs)(eo,{children:[!c&&(0,n.jsx)("p",{className:"text-xs text-iron-600 mb-3",children:a("cards.createProtocol.hint")}),(0,n.jsx)("input",{type:"text",value:u,onChange:e=>m(e.target.value),placeholder:a("cards.createProtocol.namePlaceholder"),disabled:!C,autoFocus:!0,className:"w-full border-b border-gray-300 bg-transparent px-1 py-2 text-sm focus:outline-none focus:border-gray-500"}),p?(0,n.jsxs)("div",{className:"mt-3 flex items-center gap-3 text-sm text-iron-600",children:[(0,n.jsx)(d.Z,{type:"black",size:"xs"}),(0,n.jsx)("span",{children:a("cards.createProtocol.drafting")})]}):(0,n.jsxs)("div",{className:"mt-3 flex w-full flex-wrap items-center gap-2",children:[(0,n.jsx)(Q.Z,{variant:"primary",disabled:!S,classNameT:"!py-2 text-sm",onClick:()=>b({pickFile:!0}),children:a("cards.createProtocol.upload")}),(0,n.jsx)(Q.Z,{variant:"white",disabled:!S,classNameT:"!py-2 text-sm",onClick:()=>b({}),children:a("cards.createProtocol.write")}),(0,n.jsx)(Q.Z,{variant:"white",disabled:!S,classNameT:"!py-2 text-sm",onClick:()=>void Z(),children:a("cards.createProtocol.draft")}),c?(0,n.jsx)(el,{disabled:!C}):(0,n.jsx)(Q.Z,{variant:"white",disabled:!C,classNameT:"!py-2 text-sm",onClick:()=>void T(),children:a("cards.fileUpload.cancel")})]})]})]}),(0,n.jsx)(eg.Z,{isOpen:!!f,onClose:()=>b(null),prefill:{name:u.trim(),instructions:null==f?void 0:f.instructions,content:null==f?void 0:f.content},autoPickFile:null==f?void 0:f.pickFile,onSuccess:e=>void I(e)})]}):(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-500",children:[(0,n.jsx)(j.Z,{name:"clinical_notes",size:18}),(0,n.jsx)("span",{children:a("cards.createProtocol.title")})]})})})},"use-protocol":e=>{let{data:t,isLast:s}=e,{t:a}=(0,g.$G)("chat"),i=(0,C.useRouter)(),r="string"==typeof t.protocolId?t.protocolId:null,o="string"==typeof t.protocolName?t.protocolName:"",[c,d]=(0,l.useState)(!1),u=(0,l.useRef)(!1),m=s&&!c&&!u.current,x=!0===t.onboarding,p=x?a("cards.useProtocol.title",{name:o}):a("cards.useProtocol.savedTitle",{name:o});return c||!s?(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-500",children:[(0,n.jsx)(j.Z,{name:"clinical_notes",size:18}),(0,n.jsx)("span",{children:p})]})})}):(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:"clinical_notes",title:p}),(0,n.jsxs)(eo,{children:[(0,n.jsx)("p",{className:"text-xs text-iron-600 mb-3",children:x?a("cards.useProtocol.hint"):a("cards.useProtocol.savedHint")}),(0,n.jsxs)("div",{className:"flex w-full flex-wrap items-center gap-2",children:[!x&&(0,n.jsx)(Q.Z,{variant:"primary",classNameT:"!py-2 text-sm",onClick:()=>void i.push("/protocol"),children:a("cards.useProtocol.view")}),(0,n.jsx)(Q.Z,{variant:x?"primary":"white",classNameT:"!py-2 text-sm",disabled:!r,onClick:()=>{r&&m&&(d(!0),window.dispatchEvent(new CustomEvent("fm-onboarding-fill-prompt",{detail:{text:a("cards.useProtocol.starterPrompt"),protocol:{id:r,name:o}}})))},children:a("cards.useProtocol.use")}),x&&(0,n.jsx)(el,{})]})]})]})},"protocol-revision":e=>{let{data:t,isLast:s}=e,{t:a}=(0,g.$G)("chat"),{sendCardEvent:i}=(0,l.useContext)(x.p5),r="string"==typeof t.protocolId?t.protocolId:null,o="string"==typeof t.protocolName?t.protocolName:"",c="string"==typeof t.content?t.content:"",d="str
1ing"==typeof t.instructions?t.instructions:"",u=Array.isArray(t.addedSections)?t.addedSections.filter(e=>"string"==typeof e):[],[m,p]=(0,l.useState)(null),[h,f]=(0,l.useState)(!1),b=(0,l.useRef)(!1),{protocol:v}=(0,eb.PW)(s&&!m?r:null),y=(0,l.useMemo)(()=>v?{...v,content:c,instructions:d}:null,[v,c,d]),w=async e=>{b.current||(b.current=!0,p(e),await i("saved"===e?'The user saved the proposed changes to protocol "'.concat(o,'".'):'The user discarded the proposed changes to protocol "'.concat(o,'"; it was not changed.')))};return m||!s?(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-600",children:[(0,n.jsx)(j.Z,{name:"saved"===m?"check":"clinical_notes",size:18}),(0,n.jsx)("span",{children:a("saved"===m?"cards.protocolRevision.saved":"discarded"===m?"cards.protocolRevision.discarded":"cards.protocolRevision.title",{name:o})})]})})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:"clinical_notes",title:a("cards.protocolRevision.title",{name:o})}),(0,n.jsxs)(eo,{children:[u.length>0&&(0,n.jsx)("p",{className:"text-sm text-iron-800 mb-2",children:a("cards.protocolRevision.added",{sections:u.join(", ")})}),(0,n.jsx)("p",{className:"text-xs text-iron-600 mb-3",children:a("cards.protocolRevision.hint")}),(0,n.jsxs)("div",{className:"flex w-full flex-wrap items-center gap-2",children:[(0,n.jsx)(Q.Z,{variant:"primary",classNameT:"!py-2 text-sm",disabled:!y,onClick:()=>f(!0),children:a("cards.protocolRevision.review")}),(0,n.jsx)(Q.Z,{variant:"white",classNameT:"!py-2 text-sm",onClick:()=>void w("discarded"),children:a("cards.protocolRevision.discard")})]})]})]}),(0,n.jsx)(eg.Z,{isOpen:h,onClose:()=>f(!1),protocolToEdit:y,onSuccess:()=>void w("saved")})]})},"try-fm":e=>{let{data:t,isLast:s}=e,{t:a}=(0,g.$G)("chat"),i="string"==typeof t.suggestedPrompt?t.suggestedPrompt:"",[r,o]=(0,l.useState)(!1),c=(0,l.useRef)(!1),d=s&&!r&&!c.current,u=!0===t.onboarding;return r||!s?(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-500",children:[(0,n.jsx)(j.Z,{name:"science",size:18}),(0,n.jsx)("span",{children:a("cards.tryFm.title")})]})})}):(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:"science",title:a("cards.tryFm.title")}),(0,n.jsxs)(eo,{children:[(0,n.jsx)("p",{className:"text-xs text-iron-600 mb-3",children:a("cards.tryFm.hint")}),(0,n.jsxs)("p",{className:"mb-3 rounded-md bg-gray-100 p-2 text-sm text-iron-700",children:["@fxm ",i]}),(0,n.jsxs)("div",{className:"flex w-full flex-wrap items-center gap-2",children:[(0,n.jsx)(Q.Z,{variant:"primary",classNameT:"!py-2 text-sm",disabled:!i,onClick:()=>{i&&d&&(o(!0),window.dispatchEvent(new CustomEvent("fm-onboarding-fill-prompt",{detail:{text:"@fxm ".concat(i),send:!0}})))},children:a("cards.tryFm.try")}),u&&(0,n.jsx)(el,{})]})]})]})},"style-set":e=>{let{data:t,messageId:s,isLive:a}=e,{t:i}=(0,g.$G)("chat"),{defaultPositioning:r,defaultTone:o,handlePositioningOption:c,handleToneOption:d}=(0,l.useContext)(ev.g),u="string"==typeof t.roleId?t.roleId:null,m="string"==typeof t.toneId?t.toneId:null,x=u?r.find(e=>e.id===u):void 0,p=m?o.find(e=>e.id===m):void 0;return((0,l.useEffect)(()=>{if(!a||!s)return;let e="".concat(s,":").concat(null!=u?u:"",":").concat(null!=m?m:"");!ej.has(e)&&(ej.add(e),x&&c(x),p&&d(p))},[a,s,u,m]),x||p)?(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-sm text-iron-700",children:[(0,n.jsx)(j.Z,{name:"tune",size:18}),(0,n.jsx)("span",{children:i("responseStyle.updated")}),x&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-iron-100 px-2 py-0.5 text-[11px] font-medium text-iron-800",children:[x.icon&&(0,n.jsx)(j.Z,{name:x.icon,size:12}),x.label]}),p&&(0,n.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full bg-iron-100 px-2 py-0.5 text-[11px] font-medium text-iron-800",children:p.label})]})})}):null},"template-setup":e=>{var t,s;let{data:a,isLast:i}=e,{t:r}=(0,g.$G)("settings"),{t:o}=(0,g.$G)("chat"),{sendCardEvent:c}=(0,l.useContext)(x.p5),u=!0===a.onboarding,[m,p]=(0,l.useState)(null),[h,f]=(0,l.useState)(!1),[b,v]=(0,l.useState)(!1),[y,w]=(0,l.useState)(null),[k,_]=(0,l.useState)(null),C=(0,l.useRef)(!1),S=(0,l.useRef)(!1),Z=(0,l.useRef)(null),I=(0,l.useRef)(null),T=i&&!C.current&&!k;(0,l.useEffect)(()=>{T&&!m&&(0,ey.wN)().then(p).catch(()=>f(!0))},[T]);let F=async(e,t)=>{p({...e,...t});try{p(await (0,ey.O$)(t)),S.current=!0}catch(t){p(e),ew(t)?v(!0):(0,N._)(r("templates.saveFailed"))}},E=async(e,t)=>{var s;let n=null===(s=t.files)||void 0===s?void 0:s[0];if(t.value="",!n)return;let l=(0,ed.VM)(n,e);if(l){(0,N._)(l);return}w(e);try{let t=await (0,ey.b1)(e,n);p(t),S.current=!0,t.enabled&&t.mode===e||await F(t,{enabled:!0,mode:e})}catch(e){ew(e)?v(!0):(0,N._)(r("templates.uploadFailed"))}finally{w(null)}},P=async()=>
1{if(m&&!C.current){if(C.current=!0,_("done"),u&&!S.current)try{await (0,ey.O$)({enabled:m.enabled,mode:m.mode})}catch(e){}await c("Template setup completed: enabled=".concat(m.enabled," mode=").concat(m.mode," ")+"logo=".concat(m.logo_url?"set":"missing"," ")+"header=".concat(m.header_url?"set":"missing","."))}},M=async()=>{!C.current&&(C.current=!0,_("skipped"),u&&await c("The user skipped the logo and header for now."))};if("done"===k)return(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-700",children:[(0,n.jsx)(j.Z,{name:"check",size:18}),(0,n.jsx)("span",{children:o("cards.templateSetup.saved")})]})})});if("skipped"===k||!i&&!y)return(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-500",children:[(0,n.jsx)(j.Z,{name:"branding_watermark",size:18}),(0,n.jsx)("span",{children:r("templates.title")})]})})});let R={logo:null!==(t=null==m?void 0:m.logo_url)&&void 0!==t?t:null,header:null!==(s=null==m?void 0:m.header_url)&&void 0!==s?s:null},z={logo:Z,header:I},A=!!(R.logo||R.header),O=!T||null!==y;return(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:"branding_watermark",title:r("templates.title")}),(0,n.jsxs)(eo,{children:[b?(0,n.jsx)("p",{className:"text-sm text-iron-900",children:o("cards.templateSetup.adminOnly")}):h?(0,n.jsx)("p",{className:"text-sm text-iron-900",children:r("templates.loadFailed")}):m?(0,n.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,n.jsx)("p",{className:"text-xs text-iron-800",children:r("templates.subtitle")}),["logo","header"].map(e=>(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-3",children:[(0,n.jsx)("span",{className:"text-sm font-semibold text-black",children:r("templates.".concat(e))}),(0,n.jsx)("span",{className:"text-[11px] text-iron-800",children:m.recommended[e]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("div",{className:"flex h-16 w-40 shrink-0 items-center justify-center overflow-hidden rounded-md border border-dashed border-iron-300 bg-white",children:R[e]?(0,n.jsx)("img",{src:R[e],alt:r("templates.".concat(e)),className:"max-h-full max-w-full object-contain"}):(0,n.jsx)(j.Z,{name:"image",size:22,className:"text-iron-600"})}),(0,n.jsxs)("button",{type:"button",disabled:O,onClick:()=>{var t;return null===(t=z[e].current)||void 0===t?void 0:t.click()},className:"flex items-center gap-2 rounded-none border border-iron-300 bg-white px-3 py-1.5 text-xs font-medium hover:bg-iron-50 disabled:opacity-50",children:[y===e?(0,n.jsx)(d.Z,{type:"black",size:"xs"}):(0,n.jsx)(j.Z,{name:"upload",size:14}),"".concat(R[e]?r("templates.replace"):r("templates.upload")," ").concat(r("templates.".concat(e)))]}),(0,n.jsx)("input",{ref:z[e],type:"file",accept:".png,.jpg,.jpeg",className:"hidden","data-testid":"template-".concat(e,"-input"),onChange:t=>void E(e,t.target)})]})]},e)),A&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,n.jsx)("input",{type:"checkbox",checked:m.enabled,disabled:O,onChange:e=>void F(m,{enabled:e.target.checked,mode:m.mode})}),r("templates.enable")]}),R.logo&&R.header&&(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-4 text-sm",children:[(0,n.jsx)("span",{className:"font-medium",children:r("templates.modeLabel")}),["logo","header"].map(e=>(0,n.jsxs)("label",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("input",{type:"radio",name:"template-setup-mode",checked:m.mode===e,disabled:O,onChange:()=>void F(m,{enabled:m.enabled,mode:e})}),r("templates.".concat(e))]},e))]}),(0,n.jsx)("p",{className:"text-[11px] text-iron-800",children:o("cards.templateSetup.modeHint")})]})]}):(0,n.jsx)("div",{className:"flex justify-center py-4",children:(0,n.jsx)(d.Z,{type:"black",size:"sm"})}),!u&&(0,n.jsx)("p",{className:"mt-4 text-xs text-iron-800",children:o("cards.templateSetup.settingsNote")}),(0,n.jsxs)("div",{className:"mt-3 flex w-full flex-wrap items-center gap-2",children:[m&&!b&&(0,n.jsx)(Q.Z,{variant:"primary",disabled:O||!A,classNameT:"!py-2 text-sm",onClick:()=>void P(),children:o("cards.templateSetup.done")}),u?(0,n.jsx)(el,{disabled:O}):(0,n.jsx)(Q.Z,{variant:"white",disabled:O,classNameT:"!py-2 text-sm",onClick:()=>void M(),children:o("cards.fileUpload.cancel")})]})]})]})},"feature-survey":e=>{let{data:t,isLast:s}=e,{t:a}=(0,g.$G)("chat"),{t:i}=(0,g.$G)("survey"),{sendCardEvent:r}=(0,l.useContext)(x.p5),{submit:o,loading:c}=(0,e_.X)(),[d,u]=(0,l.useState)({}),[m,p]=(0,l.useState)(""),[h,f]=(0,l.useState)(null),b=(0,l.useRef)(!1),v=(0,l.useRef)(!1),y=!0===t.onboarding,w=s&&!h&&!b.current,k=ek.h6.some(e=>!!d[e.key]);(0,l.useEffect)(()=>{w&&!v.current&&(v.current=!0,o({surveyKey:ek.Zt,status:"seen"}))},[w]);let _=async()=>
1{if(w&&k&&!c){if(!await o({surveyKey:ek.Zt,answers:{feature_ratings:d,other_text:m.trim()||null},status:"answered"})){(0,N._)(a("cards.featureSurvey.submitFailed"));return}b.current||(b.current=!0,f("answered"),await r("The clinician answered the feature survey."))}};return"answered"===h?(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-start gap-2 text-sm text-iron-700",children:[(0,n.jsx)(j.Z,{name:"check",size:18}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"font-semibold",children:i("thankyouTitle")}),(0,n.jsx)("p",{className:"text-xs text-iron-600",children:i("thankyouBody")})]})]})})}):w?(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:"poll",title:a("cards.featureSurvey.title")}),(0,n.jsxs)(eo,{children:[!y&&(0,n.jsx)("p",{className:"text-xs text-iron-600 mb-1",children:i("fp_intro")}),(0,n.jsx)("p",{className:"text-xs text-iron-600 mb-2",children:a("cards.featureSurvey.instructions")}),(0,n.jsx)("div",{className:"flex flex-col",children:ek.h6.map(e=>(0,n.jsx)(eN.Z,{labelKey:e.labelKey,value:d[e.key],loading:c,onSelect:t=>u(s=>({...s,[e.key]:t}))},e.key))}),(0,n.jsx)("label",{className:"block mt-3 mb-1 text-xs font-medium text-iron-700",children:i("fp_other_label")}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>p(e.target.value),placeholder:i("fp_other_placeholder"),disabled:c,className:"w-full border-b border-iron-300 bg-transparent px-1 py-2 text-sm focus:outline-none focus:border-iron-600"}),(0,n.jsxs)("div",{className:"mt-3 flex w-full flex-wrap items-center gap-2",children:[(0,n.jsx)(Q.Z,{variant:"primary",disabled:!k||c,classNameT:"!py-2 text-sm",onClick:()=>void _(),children:i("fp_submit")}),(0,n.jsx)(el,{disabled:c})]})]})]}):(0,n.jsx)(ei,{children:(0,n.jsx)(eo,{children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-iron-600",children:[(0,n.jsx)(j.Z,{name:"poll",size:18}),(0,n.jsx)("span",{children:a("cards.featureSurvey.title")})]})})})},"onboarding-complete":e=>{let{data:t}=e,{t:s}=(0,g.$G)("chat"),l=(0,C.useRouter)(),a=!0===t.earlyExit;return(0,n.jsx)(ei,{children:(0,n.jsxs)("div",{className:"rounded-lg bg-white px-6 pb-5 pt-2 text-center",children:[(0,n.jsx)("img",{src:"/onboarding/celebrate.png",alt:"",className:"mx-auto block w-full max-w-[220px]"}),(0,n.jsx)("h3",{className:"mb-1 font-title text-xl font-semibold text-black",children:s("cards.onboardingComplete.title")}),(0,n.jsx)("p",{className:"text-sm leading-relaxed text-iron-600",children:s(a?"cards.onboardingComplete.bodyExited":"cards.onboardingComplete.body")}),!a&&(0,n.jsx)("div",{className:"mt-4 flex flex-col items-center gap-2",children:(0,n.jsx)(Q.Z,{variant:"primary",classNameT:"!py-2 text-sm",leftIcon:(0,n.jsx)(j.Z,{name:"create_new_folder",size:18}),onClick:()=>void l.push("/folder?new=1"),children:s("cards.onboardingComplete.nextFolder")})})]})})}};var eS=s(8007),eZ=e=>{let{chips:t}=e,{sendMessage:s,sendCardEvent:a,isLoadingSendMsg:i}=(0,l.useContext)(x.p5),{handleUploadFile:r,uploadingFiles:o,caseFolderUploadingFiles:c}=(0,l.useContext)(K.B),{t:u}=(0,g.$G)("chat"),m=(0,C.useRouter)().query["case-folder-id"]||void 0,p=(0,l.useRef)(null),[h,f]=(0,l.useState)(!1),b=async e=>{if(!e.length)return;let t=(m?c:o).length,{validFiles:s,errors:n}=await (0,ed.ox)(e,t,ed.CI.CASE_FOLDER_MAX_FILES);for(let e of n)e.startsWith("max_files:")?(0,N._)(u("maxFilesExceededHint",{max:ed.CI.CASE_FOLDER_MAX_FILES})):e.startsWith("file_too_large:")?(0,N._)("".concat(u("fileTooLarge")," ").concat(e.split(":")[1],"MB.")):"pdf_password"===e?(0,N._)(u("pdfPasswordProtected")):(0,N._)(u("fileNotAllowed"));if(s.length){f(!0);try{let e=(await r(s,m)).filter(e=>e.ok);e.length>0&&await a("Files uploaded and processed: ".concat(e.map(e=>{var t;return"".concat(e.fileName," (").concat(null!==(t=e.fileType)&&void 0!==t?t:"doc",")")}).join(", ")),{caseFolderId:m})}finally{f(!1)}}},v=e=>{if("upload"===e.action){var t;null===(t=p.current)||void 0===t||t.click();return}s(e.label)};return t.length?(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 mt-3",children:[t.map(e=>{var t;return(0,n.jsxs)("button",{type:"button",disabled:i||h,onClick:()=>v(e),className:"flex items-center gap-2 px-4 py-2 rounded-none border border-black bg-white text-sm font-medium hover:bg-primary transition-colors disabled:opacity-50",children:["upload"===e.action&&(h?(0,n.jsx)(d.Z,{type:"black",size:"xs"}):(0,n.jsx)(j.Z,{name:"upload_file",size:16})),(0,n.jsx)("span",{children:e.label})]},"".concat(e.label,"-").concat(null!==(t=e.action)&&void 0!==t?t:"send"))}),(0,n.jsx)("input",{multiple:!0,type:"file",accept:ed.oD,ref:p,className:"hidden",onChange:e=>{var t;let s=Array.from(null!==(t=e.target.files)&&void 0!==t?t:[]);e.target.value="",b(s)}})]}):null},eI=s(77251);let eT={follow_up_question:"help",deepen_analysis:"search",draft_communication:"mail",generate_document:"description",workflow_step:"checklist"},eF=new Set,eE=new Set,eP=new Set;var eM=e=>{var t,s;let{messageId:a,onboardingPick:i=!1}
1=e,{chipBatch:r,clearChipBatch:o,chipDismissedIndices:c,dismissChipSuggestion:d,logEvent:u}=(0,V.cD)(),{sendMessage:m,isLoadingSendMsg:p}=(0,l.useContext)(x.p5),{t:h}=(0,g.$G)("copilot"),[f,b]=(0,l.useState)(null),[v,y]=(0,l.useState)(""),w=(0,l.useRef)(null),N=null!==(t=null==r?void 0:r.batch)&&void 0!==t?t:null;if((0,l.useEffect)(()=>{!N||eF.has(N.batch_id)||(eF.add(N.batch_id),N.suggestions.forEach((e,t)=>u({batchId:N.batch_id,suggestionIndex:t,actionTypeKey:e.action_type_key,event:"shown"})))},[N,u]),(0,l.useEffect)(()=>{var e;null!==f&&(null===(e=w.current)||void 0===e||e.focus())},[f]),!r||!a||r.messageId!==a)return null;if(r.isLoading)return(0,n.jsx)("div",{className:"flex flex-wrap gap-2 mt-3",children:[0,1,2].map(e=>(0,n.jsx)("span",{className:"h-9 w-32 bg-gray-200 animate-pulse rounded-none"},e))});if(!N)return null;let k=(0,eI.cm)(N.suggestions.map((e,t)=>({suggestion:e,index:t})).filter(e=>{let{index:t}=e;return!c.has(t)}));if(!k.length)return null;let _=(e,t)=>{u({batchId:N.batch_id,suggestionIndex:t,actionTypeKey:e.action_type_key,event:"accepted"}),m((0,eI.Tj)(e),{agent:"fm"}),o()},C=(e,t,s)=>{var n,l;b(t),y(null!==(l=null!==(n=null!=s?s:e.editable_prompt)&&void 0!==n?n:e.description)&&void 0!==l?l:"");let a="".concat(N.batch_id,":").concat(t);eE.has(a)||(eE.add(a),u({batchId:N.batch_id,suggestionIndex:t,actionTypeKey:e.action_type_key,event:"expanded"}))},S=(e,t)=>{(0,eI.mS)(e)?_(e,t):C(e,t)},Z=(e,t)=>{u({batchId:N.batch_id,suggestionIndex:t,actionTypeKey:e.action_type_key,event:"dismissed"}),d(t),f===t&&b(null)},I=(e,t,s)=>{y(s);let n="".concat(N.batch_id,":").concat(t);eP.has(n)||(eP.add(n),u({batchId:N.batch_id,suggestionIndex:t,actionTypeKey:e.action_type_key,event:"edited",editedPrompt:s}))},T=(e,t)=>{let s=v.trim();s&&(u({batchId:N.batch_id,suggestionIndex:t,actionTypeKey:e.action_type_key,event:"accepted",editedPrompt:s}),m(s,{agent:"fm"}),o())},F=null===f||c.has(f)?void 0:k.find(e=>{let{index:t}=e;return t===f}),E=[];for(let e of k){let t=e.suggestion.action_type_key,s=E[E.length-1];s&&s.key===t?s.items.push(e):E.push({key:t,items:[e]})}return(0,n.jsxs)("div",{className:"mt-3",children:[i&&(0,n.jsxs)("div",{className:"relative mb-4 flex max-w-xl items-start gap-3 bg-black px-4 py-3 text-white",children:[(0,n.jsx)(j.Z,{name:"touch_app",size:22,className:"mt-0.5 shrink-0"}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("p",{className:"text-sm font-semibold leading-snug",children:h("chips.onboardingPickTitle")}),(0,n.jsx)("p",{className:"mt-1 text-[13px] leading-relaxed text-white/85",children:h("chips.onboardingPick")})]}),(0,n.jsx)("span",{className:"absolute -bottom-1.5 left-6 h-3 w-3 rotate-45 bg-black"})]}),(0,n.jsx)("div",{className:"flex flex-wrap items-end gap-x-6 gap-y-2",children:E.map(e=>(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[eI.HP.includes(e.key)&&(0,n.jsx)("span",{className:"text-[10px] uppercase tracking-wide text-gray-400",children:h("chips.category.".concat(e.key))}),(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:e.items.map(e=>{var t;let{suggestion:s,index:a}=e;return(0,n.jsx)(l.Fragment,{children:(0,n.jsxs)("button",{type:"button",disabled:p,onClick:()=>S(s,a),title:s.description,className:"group/chip flex items-center gap-2 px-4 py-2 rounded-none border border-black bg-white text-sm font-medium hover:bg-primary transition-colors disabled:opacity-50",children:[(0,n.jsx)(j.Z,{name:null!==(t=eT[s.action_type_key])&&void 0!==t?t:"auto_awesome",size:16}),(0,n.jsx)("span",{children:s.label}),(0,eI.mS)(s)&&(0,n.jsx)("span",{role:"button",tabIndex:-1,"aria-label":h("chips.editPrompt"),title:h("chips.editPrompt"),onClick:e=>{e.stopPropagation(),C(s,a,(0,eI.Tj)(s))},className:"text-gray-300 hover:text-gray-600 opacity-0 group-hover/chip:opacity-100 transition-opacity",children:(0,n.jsx)(j.Z,{name:"edit",size:16})}),(0,n.jsx)("span",{role:"button",tabIndex:-1,"aria-label":h("chips.dismiss"),title:h("chips.dismiss"),onClick:e=>{e.stopPropagation(),Z(s,a)},className:"text-gray-300 hover:text-gray-600 opacity-0 group-hover/chip:opacity-100 transition-opacity",children:(0,n.jsx)(j.Z,{name:"close",size:16})})]})},"".concat(N.batch_id,"-").concat(a))})})]},"".concat(N.batch_id,"-").concat(e.key,"-").concat(e.items[0].index)))}),F&&(0,n.jsxs)(ei,{children:[(0,n.jsx)(er,{icon:null!==(s=eT[F.suggestion.action_type_key])&&void 0!==s?s:"auto_awesome",title:F.suggestion.label,right:(0,n.jsx)("button",{type:"button","aria-label":h("chips.cancel"),onClick:()=>b(null),className:"text-iron-600 hover:text-black",children:(0,n.jsx)(j.Z,{name:"expand_less",size:18})})}),(0,n.jsxs)(eo,{children:[(0,n.jsx)("p",{className:"text-xs text-gray-500 mb-2",children:F.suggestion.description}),(0,n.jsx)("label",{className:"block text-xs font-medium text-iron-700 mb-1",children:h("chips.editTitle")}
1),(0,n.jsx)("textarea",{ref:w,rows:4,value:v,onChange:e=>I(F.suggestion,F.index,e.target.value),className:"w-full text-xs bg-gray-50 border border-gray-200 rounded-md resize-none p-2 focus:outline-none focus:border-gray-500"}),(0,n.jsxs)("div",{className:"flex justify-between items-center mt-2",children:[(0,n.jsx)("button",{type:"button",onClick:()=>b(null),className:"text-xs underline text-iron-600 hover:text-black",children:h("chips.cancel")}),(0,n.jsx)("button",{type:"button",disabled:p||!v.trim(),onClick:()=>T(F.suggestion,F.index),className:"px-4 py-2 rounded-none bg-black text-white text-xs font-medium hover:bg-iron-800 disabled:opacity-50",children:p?h("chips.sending"):h("chips.send")})]})]})]})]})},eR=s(37793),ez=s(76539),eA=s(95569);let eO=null,eL=null;var eU=()=>{var e,t,s;let{chatMessages:n,sendCardEvent:a,isLoadingSendMsg:i}=(0,l.useContext)(x.p5),r=null===(e=(0,l.useContext)(ez.em))||void 0===e?void 0:e.state,o=(0,l.useMemo)(()=>(0,eA.u6)(n),[n]),c=null!==(s=null===(t=n[n.length-1])||void 0===t?void 0:t.id)&&void 0!==s?s:null;(0,l.useEffect)(()=>{o&&!i&&c&&eL!==c&&(eL=c,a(o))},[o,i,c,a]);let d=!!(null==r?void 0:r.chatOnboardingStartedAt)&&!(null==r?void 0:r.chatOnboardingCompletedAt),u=(0,l.useMemo)(()=>{var e,t,s;return d&&(null===(e=n[n.length-1])||void 0===e?void 0:e.type)==="AI"&&(0,eA.mF)(n,eR.JM)?null!==(s=null===(t=n[n.length-1])||void 0===t?void 0:t.id)&&void 0!==s?s:"n-".concat(n.length):null},[d,n]);return(0,l.useEffect)(()=>{u&&u!==eO&&(eO=u,a(ex.XW))},[u,a]),null};let eD=e=>{let t,{href:s,mergedReferences:l,isLoadingSendMsg:a,styles:i}=e,r=new URL(s,"http://x"),o=r.searchParams.get("referenceId"),c=r.searchParams.get("referenceIndex");if(o)t=l.find(e=>e.id===o||e.paper_id===o);else if(c){let e=Number(c);t=!isNaN(e)&&e>=0&&e<l.length?l[e]:l.find(e=>e.id===c||e.paper_id===c)}else t=l[0];if(!t)return(0,n.jsx)("a",{className:i.link,href:s});let d=Number(r.searchParams.get("cn")),u=d>0?d:l.indexOf(t)+1;return(0,n.jsx)("span",{className:"inline",children:(0,n.jsx)(M.Z,{reference:t,href:s,showTooltipModal:!a,citationNumber:u>0?u:void 0})})};var eG=e=>{var t,s,a,i;let{messages:o,disableOptions:d=!1}=e,{isLoadingSendMsg:u,chatMessages:m,followupQuestions:p,conversationReferences:h,referenceToMessageIdMap:f,updateMessage:g,isLiveMessageId:b}=(0,l.useContext)(x.p5),{selectedConversationId:v}=(0,l.useContext)(Z.L),[y,w]=(0,l.useState)(o[o.length-1]),N=(0,l.useMemo)(()=>O(y.metadata),[y.metadata]),C=(0,l.useMemo)(()=>m.length>0&&m[m.length-1].id===y.id,[m,y.id]),S=(0,l.useMemo)(()=>{let e=(0,F.n9)(m);return e.length>0&&e[e.length-1].id===y.id},[m,y]),M=(0,l.useMemo)(()=>{let e=(0,eI.mN)(m);return!!e&&e.id===y.id},[m,y.id]),z=u&&C,{normalizedMessage:A,quickReplies:G}=(0,l.useMemo)(()=>{let e=z?(0,_.DX)(y.message):(0,_.sO)(y.message),{text:t,chips:s}=(0,eS._)(e);return{normalizedMessage:t,quickReplies:s}},[y.message,z]);(0,l.useEffect)(()=>{o.length>0&&w(e=>e&&o.find(t=>t.id===e.id)||o[o.length-1])},[o]);let B=(0,l.useMemo)(()=>null===v?[]:h.get(v)||[],[v,h]),$=l.useRef(new Map),q=(0,l.useMemo)(()=>null===v?$.current:f.get(v)||$.current,[v,f]),H=(0,l.useMemo)(()=>{var e,t,s;let n=null!==(t=null==y?void 0:null===(e=y.metadata)||void 0===e?void 0:e.references)&&void 0!==t?t:[];return(0,_.Dh)(A,n,B,q,null!==(s=null==y?void 0:y.id)&&void 0!==s?s:void 0)},[y,A,B,q]),V=H.references,K=H.refToOriginalMessageId,W=(0,l.useMemo)(()=>{var e;return(0,_.lZ)(A,V,null!==(e=null==y?void 0:y.id)&&void 0!==e?e:"",K)},[A,y,V,K]),Y=(0,l.useMemo)(()=>(0,_.Bo)(A,V),[A,V]),Q=(0,l.useMemo)(()=>(0,_.aZ)(A,V),[A,V]),ee=(0,l.useMemo)(()=>(0,k.Ue)(W),[W]),et=(0,l.useMemo)(()=>(0,k.Ue)(y.message).filter(e=>"output"===e.kind).map(e=>(0,E.AC)(e.content,V)),[y.message,V]),es=(0,l.useMemo)(()=>(0,k.Ue)(y.message).filter(e=>"output"===e.kind).map(e=>e.content),[y.message]),en=(0,l.useMemo)(()=>(0,k.Ue)(y.message).filter(e=>"output"===e.kind).map(e=>(0,E.AC)(e.content,V,{interactive:!0})),[y.message,V]),el=(0,l.useMemo)(()=>(function(e,t){let s=(0,k.Ue)(e).filter(e=>"text"===e.kind||"output"===e.kind).map(e=>e.content).join("\n");return{text:s,hasCitations:(0,E.PE)(s,t)}})(A,V),[A,V]),ei=(0,l.useMemo)(()=>{let e=[];return(0,k.Ue)(A).forEach(t=>{"text"===t.kind&&(0,_.wB)(t.content).forEach(t=>{t.isTable&&e.push(t.content)})}),e},[A]),er=(0,l.useMemo)(()=>{let e=0,t=0,s=0,n=[];return ee.forEach(l=>{if("protocols"===l.kind){n.push({kind:"protocol",segment:l,ordinal:s}),s+=1;return}if("output"===l.kind){n.push({kind:"output",segment:l,ordinal:t}),t+=1;return}if("card"===l.kind){n.push({kind:"card",segment:l});return}
1(0,_.wB)(l.content).forEach(t=>{if(t.isTable){var s;let l=null!==(s=ei[e])&&void 0!==s?s:t.content;e+=1,n.push({kind:"table",displayContent:t.content,rawContent:l})}else n.push({kind:"markdown",content:t.content})})}),n},[ee,ei]),eo=e=>{let{...t}=e;if(!t.href||"undefined"===t.href){let e={...t};return delete e.href,(0,n.jsx)("a",{className:c().link,...e})}return t.href.includes("/chat/reference")?(0,n.jsx)(eD,{href:t.href,mergedReferences:V,isLoadingSendMsg:u,styles:c()}):/^https?:\/\//i.test(t.href)?(0,n.jsx)("a",{className:c().link,...t,target:"_blank",rel:"noopener noreferrer"}):(0,n.jsx)("a",{className:c().link,...t})},ed={h1:e=>{let{...t}=e;return(0,n.jsx)("h1",{className:c().heading1,...t})},h2:e=>{let{...t}=e;return(0,n.jsx)("h2",{className:c().heading2,...t})},h3:e=>{let{...t}=e;return(0,n.jsx)("h3",{className:c().heading3,...t})},h4:e=>{let{...t}=e;return(0,n.jsx)("h4",{className:c().heading4,...t})},h5:e=>{let{...t}=e;return(0,n.jsx)("h5",{className:c().heading5,...t})},h6:e=>{let{...t}=e;return(0,n.jsx)("h6",{className:c().heading6,...t})},p:e=>{let{...t}=e;return(0,n.jsx)("p",{className:c().paragraph,...t})},ul:e=>{let{...t}=e;return(0,n.jsx)("ul",{className:c().unorderedList,...t})},ol:e=>{let{...t}=e;return(0,n.jsx)("ol",{className:c().orderedList,...t,start:1})},li:e=>{let{...t}=e;return(0,n.jsx)("li",{className:c().listItem,...t})},a:eo,table:e=>{let{...t}=e;return(0,n.jsx)("div",{className:"overflow-x-auto w-full",children:(0,n.jsx)("table",{...t})})},blockquote:e=>{let{...t}=e;return(0,n.jsx)("blockquote",{className:c().blockquote,...t})},pre:e=>{let{children:t}=e;return(0,n.jsx)(D.Z,{children:t})},code:e=>{let{...t}=e;return(0,n.jsx)("code",{className:c().inlineCode,...t})}};return(0,n.jsxs)("div",{children:[null!==(a=null===(t=y.thinkingMessages)||void 0===t?void 0:t.length)&&void 0!==a&&a?(0,n.jsx)(R.Z,{label:"Thought Process",children:(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsx)("div",{className:"border-l border-iron-100"}),(0,n.jsx)("ul",{className:"text-sm text-iron-600 mt-2 list-disc list-inside space-y-1 ml-3",children:null==y?void 0:null===(s=y.thinkingMessages)||void 0===s?void 0:s.map((e,t)=>(0,n.jsx)("li",{children:e},t))})]})}):(0,n.jsx)(n.Fragment,{}),(0,n.jsxs)("div",{className:"group flex items-start space-x-3 pb-10",children:[(0,n.jsx)("div",{className:"w-8 h-8 rounded-full bg-primary mt-1 flex-shrink-0 flex items-center justify-center",title:N.label,"aria-label":N.label,children:(0,n.jsx)(j.Z,{name:N.icon,size:16,className:"text-black"})}),(0,n.jsxs)("div",{className:"flex flex-col pt-1 pl-1 flex-1 min-w-0 ".concat(c().markdownContent),children:[(()=>{var e,t;let s=y.metadata,l=[null==s?void 0:null===(e=s.style_positioning)||void 0===e?void 0:e.label,null==s?void 0:null===(t=s.style_tone)||void 0===t?void 0:t.label].filter(Boolean);return l.length?(0,n.jsx)("div",{className:"mb-2 flex flex-wrap items-center gap-1.5",children:l.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-iron-100 px-2 py-0.5 text-[11px] font-medium text-iron-700",children:[(0,n.jsx)(j.Z,{name:"tune",size:12}),e]},e))}):null})(),er.map((e,t)=>{var s,l,a,i,o,c,d,m;if("protocol"===e.kind)return(0,n.jsx)(L.I2,{content:e.segment.content,isIncomplete:e.segment.isIncomplete,protocolName:e.segment.name,onOpenAsDocument:y.id?async t=>{let s=(0,k.ej)(y.message,e.ordinal,t);s&&y.id&&((0,X.q)("PROTOCOL_OPENED_AS_DOCUMENT",{message_id:y.id}),await g(y.id,{message:s}))}:void 0},t);if("output"===e.kind)return(0,n.jsx)(J,{title:e.segment.name,content:null!==(a=null===(s=en[e.ordinal])||void 0===s?void 0:s.text)&&void 0!==a?a:e.segment.content,rawContent:null!==(i=null===(l=et[e.ordinal])||void 0===l?void 0:l.text)&&void 0!==i?i:e.segment.content,isIncomplete:e.segment.isIncomplete&&u&&C,isTruncated:e.segment.isIncomplete&&!(u&&C),messageId:null!==(o=y.id)&&void 0!==o?o:null,copySource:es[e.ordinal],references:V,renderView:e=>(0,n.jsx)(r.UG,{remarkPlugins:[P.Z],rehypePlugins:_.WH,components:ed,children:(0,E.uU)(e,V)}),onSaveContent:async t=>{if(!y.id)return;let s=(0,k.iT)(y.message,e.ordinal,t);await g(y.id,{message:s})}},"output-".concat(null!==(c=y.id)&&void 0!==c?c:"live","-").concat(e.ordinal));if("card"===e.kind){let s=e.segment.name?eC[e.segment.name]:void 0;return e.segment.isIncomplete?null:s?(0,n.jsx)(ea,{fallbackLabel:"Card failed",children:(0,n.jsx)(s,{data:null!==(d=e.segment.data)&&void 0!==d?d:{},isIncomplete:e.segment.isIncomplete,messageId:null!==(m=y.id)&&void 0!==m?m:null,isLast:C,isLive:b(y.id)})},t):(0,n.jsx)(ec,{label:"Unsupported card"},t)}return"table"===e.kind?(0,n.jsx)(U.Z,{displayContent:e.displayContent,rawContent:e.rawContent,references:V,renderLink:eo},t):(0,n.jsx)(r.UG,{remarkPlugins:[P.Z],rehypePlugins:_.WH,components:ed,children:e.content},t)}),!u&&C&&G.length>0&&(0,n.jsx)(eZ,{chips:G}),d||u&&C?(0,n.jsx)(n.Fragment,{}):(0,n.jsx)("div",{className:"md:opacity-0 md:group-hover:opacity-40 md:hover:!opacity-100 md:focus-within:opacity-100 transition-opacity",children:(0,n.jsx)(I,{messages:o,currentMessage:y,preprocessedMessage:Y,preprocessedCopyVancouverMessage:Q,setMessageDisplayed:w,sourcesReferences:el.hasCitations?V:[],sourcesText:el.text})}),!d&&!u&&M&&(0,n.jsx)(eU,{}),eR.QD&&!d&&!u&&M&&(0,n.jsx)(eM,{messageId:null!==(i=y.id)&&void 0!==i?i:null,onboardingPick:"pick"===(0,eA.Eh)(m)}),d&&(0,n.jsx)("div",{className:"border-t border-iron-800 border-opacity-30"}),!d&&!u&&S&&p.length?(0,n.jsx)(T,{followupQuestions:p}):(0,n.jsx)(n.Fragment,{})]})]})]})},eB=s(48620),e$=e=>{let{message:t,disableOptions:s=!1}
1=e,{t:a}=(0,g.$G)("chat"),[i,r]=(0,l.useState)(!1),[o,c]=(0,l.useState)(!1),d=async()=>{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),1e3)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"group flex flex-col items-end mb-10 w-full min-w-0",children:[(0,n.jsx)("div",{className:"inline-flex max-w-xl p-5 rounded-xl bg-primary text-iron-800 whitespace-pre-wrap break-words",children:t}),s?(0,n.jsx)(n.Fragment,{}):(0,n.jsxs)("div",{className:"flex items-center space-x-2 pt-2 text-iron-400 opacity-0 invisible group-hover:visible group-hover:opacity-100 transition-opacity duration-200",children:[(0,n.jsx)(f.Z,{content:a("Add to My Prompts"),children:(0,n.jsx)("div",{className:"flex items-center cursor-pointer",onClick:e=>{e.stopPropagation(),c(!0)},children:(0,n.jsx)(j.Z,{name:"wand_stars"})})}),(0,n.jsx)(f.Z,{content:a("Copy"),children:(0,n.jsx)("div",{className:"flex items-center cursor-pointer",onClick:d,children:i?(0,n.jsx)(j.Z,{name:"check"}):(0,n.jsx)(j.Z,{name:"content_copy"})})})]})]}),(0,n.jsx)(eB.Z,{isOpen:o,onClose:()=>c(!1),isEdit:!1,addPromptMsg:t,categories:[]})]})},eq=s(65149);let eH={doc:"description",lab:"science",img:"image","img-lab":"science","img-doc":"description",scribe_note:"clinical_notes"},eV={doc:"Document",lab:"Lab",img:"Image","img-lab":"Lab image","img-doc":"Document image",scribe_note:"Clinical note"};function eK(e){var t,s;let{title:l,fileType:a,onClick:i}=e;return(0,n.jsxs)("div",{className:"inline-flex items-center gap-2.5 bg-white border border-gray-300 text-gray-800 pl-2.5 pr-3 py-2 rounded-xl text-sm max-w-[280px] shrink-0 group",children:[(0,n.jsx)("span",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-iron-400 shrink-0",children:(0,n.jsx)(j.Z,{name:null!==(t=eH[a])&&void 0!==t?t:"description",size:18,className:"text-white"})}),(0,n.jsxs)("button",{type:"button",onClick:i,disabled:!i,className:"flex flex-col min-w-0 flex-1 text-left",title:l,children:[(0,n.jsx)("span",{className:"truncate",children:l}),(0,n.jsx)("span",{className:"text-xs text-gray-500",children:null!==(s=eV[a])&&void 0!==s?s:"File"})]})]})}var eW=s(25383);let eX=i()(()=>Promise.all([s.e(4671),s.e(7822),s.e(872),s.e(67)]).then(s.bind(s,25821)),{loadableGenerated:{webpack:()=>[25821]},ssr:!1}),eY=i()(()=>Promise.all([s.e(4671),s.e(8158),s.e(7822),s.e(872),s.e(67),s.e(6321)]).then(s.bind(s,86321)),{loadableGenerated:{webpack:()=>[86321]},ssr:!1}),eJ=i()(()=>Promise.all([s.e(4671),s.e(8158),s.e(7822),s.e(872),s.e(67),s.e(8880)]).then(s.bind(s,48880)),{loadableGenerated:{webpack:()=>[48880]},ssr:!1}),eQ=i()(()=>Promise.all([s.e(4671),s.e(7822),s.e(872),s.e(67),s.e(1365)]).then(s.bind(s,1365)),{loadableGenerated:{webpack:()=>[1365]},ssr:!1});function e0(e){var t;let s=e.file_name||"".concat(e.title||"note",".txt");return{fileId:e.file_id||"scribe-note-preview",fileName:s,fileType:"scribe_note",status:"completed",statusMessages:[],fileRaw:new File([null!==(t=e.content)&&void 0!==t?t:""],s,{type:"text/plain"})}}var e1=e=>{let{disableOptions:t=!1}=e,[s,a]=(0,l.useState)(null),{chatMessages:i,preparingMessages:r,messageStatus:o,isLoadingSendMsg:c,isLoadingMsgs:u,isLiveMessageId:m,sendMessage:p,awaitingReplyTo:h}=(0,l.useContext)(x.p5),{uploadingFiles:f}=(0,l.useContext)(K.B),{t:b}=(0,g.$G)("chat"),{t:v}=(0,g.$G)("common"),y=e=>{var t;return"AI"===e.type&&!(null!==(t=e.message)&&void 0!==t?t:"").trim()&&!m(e.id)&&!c},w=e=>{var t,s,n;let l=i.find(t=>t.id===e.parentMessageId);if(!l||"USER"!==l.type||!(null===(t=l.message)||void 0===t?void 0:t.trim()))return;let a=(null===(s=l.metadata)||void 0===s?void 0:s.agent)==="assistant"?"assistant":"fm";p(l.message,{agent:a,suppressBubble:!!(null===(n=l.metadata)||void 0===n?void 0:n.hidden),protocolId:(0,x.r_)(l)})},N=(0,l.useMemo)(()=>(0,F.NL)(i),[i]),k=(0,l.useMemo)(()=>{let e=new Map;return(0,eW.LW)(N).forEach(t=>{e.set(t.groupIndex,{key:t.key,label:(0,eW.pT)(t.date,b)})}),e.size>1?e:new Map},[N,b]),_=(0,l.useMemo)(()=>{for(let t of N){var e;if("USER"===t[0].type&&(null===(e=t[0].metadata)||void 0===e?void 0:e.scribe_session))return t[0].id}return null},[N]),C=e=>{if("scribe_note"===e.file_type){if(e.content){a(e0(e));return}let t=f.find(t=>t.fileId===e.file_id);a(null!=t?t:e0(e));return}let t=f.find(t=>t.fileId===e.file_id);t&&a(t)};return(0,n.jsxs)(n.Fragment,{children:[N.map((e,s)=>{var a,i,r;return(0,n.jsxs)(l.Fragment,{children:[(0,n.jsx)("div",{className:"h-0","data-message-ids":e.map(e=>
1e.id).filter(Boolean).join(",")}),k.has(s)&&(0,n.jsxs)("div",{className:"flex items-center gap-3 my-4","data-day-anchor":k.get(s).key,"data-day":k.get(s).label,children:[(0,n.jsx)("div",{className:"flex-1 border-t border-iron-200"}),(0,n.jsx)("span",{className:"text-xs text-iron-500 font-medium",children:k.get(s).label}),(0,n.jsx)("div",{className:"flex-1 border-t border-iron-200"})]}),"AI"===e[0].type&&e.every(y)?(0,n.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:[(0,n.jsx)(j.Z,{name:"error_outline",size:18,className:"shrink-0"}),(0,n.jsx)("span",{className:"flex-1",children:v("chatTurnFailedInline")}),(0,n.jsx)("button",{type:"button",onClick:()=>w(e[e.length-1]),className:"shrink-0 rounded-none bg-black px-3 py-1.5 text-xs font-semibold text-white hover:bg-iron-800",children:v("tryAgain")})]}):"AI"===e[0].type?(0,n.jsx)(eG,{messages:e,disableOptions:t}):(0,n.jsxs)("div",{className:"w-full flex flex-col items-end min-w-0",children:[e[0].id===_&&(null===(a=e[0].metadata)||void 0===a?void 0:a.scribe_session)&&(0,n.jsx)("div",{className:"mb-2",children:(0,n.jsx)(eq.Z,{sessionId:e[0].metadata.scribe_session.id,title:e[0].metadata.scribe_session.title,createdAt:null!==(r=e[0].metadata.scribe_session.createdAt)&&void 0!==r?r:void 0})}),"USER"===e[0].type&&Array.isArray(null===(i=e[0].metadata)||void 0===i?void 0:i.message_files)&&e[0].metadata.message_files.length>0&&(0,n.jsx)("div",{className:"mb-2 flex flex-wrap gap-2 justify-end items-end",children:e[0].metadata.message_files.map(e=>{if("scribe_note"===e.file_type)return(0,n.jsx)(eK,{title:e.title||e.file_name,fileType:e.file_type,onClick:()=>C(e)},e.file_id);let t=f.find(t=>t.fileId===e.file_id);if(e.file_type.startsWith("img")){var s;return(0,n.jsx)(eQ,{file:null!=t?t:{fileId:e.file_id,fileName:e.file_name,fileType:"img",status:"completed",statusMessages:[],url:null!==(s=e.url)&&void 0!==s?s:null}},e.file_id)}return t?"lab"===e.file_type?(0,n.jsx)(eJ,{file:t},e.file_id):(0,n.jsx)(eY,{uploadingFile:t},e.file_id):(0,n.jsx)(eK,{title:e.title||e.file_name,fileType:e.file_type},e.file_id)})}),(0,n.jsx)(e$,{message:e[0].message,disableOptions:t})]})]},s)}),(!c||o)&&("preparing"!==o||u)&&("referencing"!==o||u)?(0,n.jsx)(n.Fragment,{}):(0,n.jsxs)("div",{className:"flex items-start",children:[(0,n.jsxs)("span",{className:"relative flex h-8 w-8 mr-4 justify-center flex-shrink-0",children:[(0,n.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-primary opacity-75"}),(0,n.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-primary self-center"})]}),(0,n.jsx)("span",{className:"flex flex-col space-y-1 animate-pulse text-iron-700 font-medium",children:r.map((e,t)=>(0,n.jsx)("span",{className:"animate-fade-in",children:""===e?"FunctionalMind":e},t))})]}),h&&(0,n.jsxs)("div",{className:"flex items-center gap-3 text-sm text-iron-700",children:[(0,n.jsx)(d.Z,{type:"black",size:"xs"}),(0,n.jsx)("span",{children:b("replyStillWorking")})]}),s&&(0,n.jsx)(eX,{file:s,onClose:()=>a(null)})]})}},65149:function(e,t,s){"use strict";s.d(t,{Z:function(){return o}});var n=s(52676);s(75271);var l=s(63557),a=s(18327),i=s(60413),r=s.n(i);function o(e){let{sessionId:t,title:s,createdAt:i,isProcessing:o=!1,onRemove:c}=e;return(0,n.jsxs)("div",{className:"inline-flex items-center gap-2.5 bg-white border border-gray-300 text-gray-800 pl-2.5 pr-3 py-2 rounded-xl text-sm max-w-[280px] shrink-0 group",children:[(0,n.jsx)("span",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-iron-400 shrink-0",children:o?(0,n.jsx)(a.Z,{size:"xs",type:"white"}):(0,n.jsx)(l.Z,{name:"adaptive_audio_mic",size:18,className:"text-white"})}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsxs)(r(),{href:"/scribe/".concat(t),className:"flex items-center gap-0.5 min-w-0",title:s,target:"_blank",rel:"noopener noreferrer",children:[(0,n.jsx)("span",{className:"truncate group-hover:underline",children:s}),(0,n.jsx)(l.Z,{name:"open_in_new",size:12,className:"text-gray-400 opacity-0 group-hover:opacity-100 transition-opacity shrink-0 no-underline"})]}),i&&(0,n.jsx)("span",{className:"text-xs text-gray-500 truncate",children:new Date(i).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})})]}),c&&(0,n.jsx)("button",{onClick:c,className:"text-gray-400 hover:text-gray-700 transition-colors shrink-0 ml-0.5","aria-label":"Remove scribe session",children:(0,n.jsx)(l.Z,{name:"close",size:12})})]})}},95569:function(e,t,s){"use strict";s.d(t,{Eh:function(){return i},mF:function(){return o},u6:function(){return r}});var n=s(58468),l=s(92666);let a=e=>{var t;return(null===(t=e.metadata)||void 0===t?void 0:t.agent)==="assistant"},i=e=>{let t=0,s=0,i=!1;for(let d=e.length-1;d>=0;d--){var r,o,c;let u=e[d];if("USER"===u.type){if((0,n.IA)(u))return null;s++;continue}if("AI"!==u.type)continue;if(!a(u)){(null===(o=u.message)||void 0===o?void 0:o.trim())?1==++t&&s>0&&(i=!0):0===t&&0===s&&(i=!0),s=0;continue}let m=(0,l.Ue)(null!==(c=u.message)&&void 0!==c?c:"").find(e=>"card"===e.kind&&"try-fm"===e.name);if(!m||(null===(r=m.data)||void 0===r?void 0:r.onboarding)!==!0||i)break;if(t>=2)return"report";if(1===t)return"pick";break}return null},r=e=>"report"===i(e)?"The clinician tried @fxm, picked a suggestion, read the FxM answer and wants to continue."
1:null,o=(e,t)=>{let s=0,i=null;for(let o=e.length-1;o>=0;o--){var r;let c=e[o];if("USER"===c.type){(0,n.IA)(c)?null===i&&(i=s):s++;continue}if("AI"!==c.type||!a(c))continue;let d=(0,l.Ue)(null!==(r=c.message)&&void 0!==r?r:"").filter(e=>"card"===e.kind);if(d.some(e=>"onboarding-complete"===e.name))break;if(d.some(e=>{var t;return(null===(t=e.data)||void 0===t?void 0:t.onboarding)===!0}))return(null!=i?i:s)>=t}return!1}},77251:function(e,t,s){"use strict";s.d(t,{Ee:function(){return a},HP:function(){return d},Tj:function(){return c},cm:function(){return m},mN:function(){return i},mS:function(){return o}});var n=s(58468);let l=new RegExp('<card\\s+type="('.concat("create-folder|create-protocol|use-protocol|protocol-revision|try-fm|file-upload|fm-handoff|template-setup|feature-survey|onboarding-complete",')"')),a=e=>!!e&&l.test(e),i=e=>{for(let t=e.length-1;t>=0;t--){let s=e[t];if(!("USER"===s.type&&(0,n.IA)(s)))return s}},r=new Set(["follow_up_question","workflow_step"]),o=e=>r.has(e.action_type_key),c=e=>{var t;return(null===(t=e.editable_prompt)||void 0===t?void 0:t.trim())||e.label},d=["follow_up_question","deepen_analysis","draft_communication","generate_document","workflow_step"],u=e=>{let t=d.indexOf(null!=e?e:"");return -1===t?d.length:t},m=e=>[...e].sort((e,t)=>u(e.suggestion.action_type_key)-u(t.suggestion.action_type_key))},16727:function(e,t,s){e.exports=s(97030)}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.