PageSourceSearch

https://onconex.ai/_next/static/chunks/38-a5e789a890e71b2f.js

js onconex.ai collected 2026-10-05 12:20:58 UTC 31,012 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[38],{38:(e,t,n)=>{n.d(t,{Chat:()=>g});var r=n(95155),a=n(12115),i=n(64558),s=n(37621),o=n(97003),l=n(67001);function c(e){let{returnUrl:t,fleet:n="hadleylab",compact:i=!1}=e,[s,o]=(0,a.useState)(""),[l,c]=(0,a.useState)({kind:"idle"});async function d(e){e.preventDefault();let r=s.trim().toLowerCase();if(r){c({kind:"sending"});try{let e=null!=t?t:window.location.origin+window.location.pathname+window.location.search,a=await fetch("/api/auth/magic/send",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:r,fleet:n,return_url:e})});if(!a.ok){let e=await a.json().catch(()=>({}));c({kind:"error",message:(null==e?void 0:e.error)||"Send failed (HTTP ".concat(a.status,")")});return}let i=await a.json();c({kind:"sent",email:i.email,expiresAt:i.expires_at})}catch(e){c({kind:"error",message:e instanceof Error?e.message:"Network error"})}}}return"sent"===l.kind?(0,r.jsxs)("p",{className:i?"text-[10px]":"text-[11px]",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"✉ "}),"Magic link sent to ",(0,r.jsx)("strong",{children:l.email}),". Click it to return to this thread, already signed in."]}):(0,r.jsxs)("form",{onSubmit:d,className:"flex w-full flex-col gap-1",children:[(0,r.jsxs)("div",{className:"flex w-full items-stretch gap-1.5",children:[(0,r.jsx)("input",{type:"email",autoComplete:"email",required:!0,value:s,onChange:e=>o(e.target.value),placeholder:"[email protected]",disabled:"sending"===l.kind,className:i?"flex-1 min-w-0 rounded-md border border-warning/40 bg-white/80 px-2 py-1 text-[10px] text-warning placeholder:text-warning/60 focus:outline-none focus:ring-1 focus:ring-warning dark:bg-warning/30 dark:text-warning placeholder:dark:text-warning/60":"flex-1 min-w-0 rounded-md border border-warning/40 bg-white/80 px-2.5 py-1.5 text-[11px] text-warning placeholder:text-warning/60 focus:outline-none focus:ring-1 focus:ring-warning dark:bg-warning/30 dark:text-warning placeholder:dark:text-warning/60","aria-label":"Email for magic-link sign-in"}),(0,r.jsx)("button",{type:"submit",disabled:"sending"===l.kind||!s.trim(),className:i?"inline-flex items-center rounded-md bg-warning px-2 py-1 text-[10px] font-semibold text-warning-foreground no-underline transition hover:bg-warning/90 disabled:opacity-50":"inline-flex items-center rounded-md bg-warning px-2.5 py-1.5 text-[11px] font-semibold text-warning-foreground no-underline transition hover:bg-warning/90 disabled:opacity-50",children:"sending"===l.kind?"Sending…":"Send link"})]}),"error"===l.kind?(0,r.jsx)("span",{className:"text-[10px] text-destructive",children:l.message}):null]})}var d=n(28171),u=n(25016);let p={ar:"يستشهد",darija:"يستشهد",fr:"Cite",es:"Cita",en:"Cites"};function m(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en";if(!e)return"";if(e.startsWith("cite-v1:"))try{let n=JSON.parse(e.slice(8)).map(e=>{var t,n,r,a,i,s,o;return{source_doc:null!=(t=e.source_doc)?t:"",doc_id:null!=(r=null!=(n=e.doc_id)?n:e.guideline_id)?r:"",guideline_id:e.guideline_id,publisher:null!=(a=e.publisher)?a:"",domain:null!=(i=e.domain)?i:"",version:null!=(s=e.version)?s:"",published_at:e.published_at,superseded_by:e.superseded_by,section:e.section,page:e.page,doc_hash:null!=(o=e.doc_hash)?o:""}}),r=function(e){var t;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en";if(!Array.isArray(e)||0===e.length)return"";let r=null!=(t=p[n])?t:p.en,a=e.map(e=>{let t=(e.doc_hash||"").slice(0,8),n=t?" [".concat(t,"]"):"";if("community"===e.source_class){let t=[];e.contributor_vitae&&t.push(e.contributor_vitae),e.confidence_tier&&t.push(e.confidence_tier),e.region&&t.push(e.region);let r=t.length?" ".concat(t.join(" \xb7 ")):" ".concat(e.source_doc);return"Community:".concat(r).concat(n)}let r=[];e.version&&r.push(e.version),e.domain&&r.push(e.domain);let a=function(e){if(!e)return"";let t=String(e).match(/^(\d{4})/);return t?t[1]:""}(e.published_at);a&&r.push(a);let i=r.length?" \xb7 ".concat(r.join(" \xb7 ")):"",s=e.section?" ".concat(e.section):"";
1return"".concat(e.source_doc).concat(s).concat(i).concat(n)});return"".concat(r,": ").concat(a.join(", "))}(n,t);if(r)return r}catch(e){}return e}let h={casechat:{user:"bg-scope-accent text-scope-accent-foreground",send:"bg-scope-accent hover:bg-scope-accent/90 text-scope-accent-foreground",shell:"border-scope-accent/30",chip:"bg-scope-accent hover:bg-scope-accent/90 text-scope-accent-foreground"},laude:{user:"bg-laude text-white",send:"bg-laude hover:bg-laude-light text-white",shell:"border-laude/30",chip:"bg-laude hover:bg-laude-light text-white"},salutem:{user:"bg-salutem text-white",send:"bg-salutem hover:bg-salutem-hover text-white",shell:"border-salutem/30",chip:"bg-salutem hover:bg-salutem-hover text-white"}};function g(e){var t,n;let{scope:i,threadId:c,initialQuestion:p,systemPromptPreview:g=!1,className:f,demo:b,compact:y=!1,manuscriptContext:_,clientContext:v,queueConfig:w=null,emptyStateCopy:j=null,submitSignal:S,onTurnDone:N}=e,k=i.toLowerCase().includes("story"),{toast:C}=(0,d.d)(),[T,E]=(0,a.useState)(c),[A,R]=(0,a.useState)([]),[I,O]=(0,a.useState)(""),[M,D]=(0,a.useState)("idle"),[P,q]=(0,a.useState)(!1),[U,L]=(0,a.useState)(null),[F,z]=(0,a.useState)(!1),[G,H]=(0,a.useState)(""),J=(0,a.useRef)(null),W=(0,a.useRef)(null),Y=(0,a.useRef)(null),$=(0,a.useRef)(!1),B=(0,a.useRef)(!1),V=Array.isArray(b)&&b.length>0,K=h[i],[Q,X]=(0,a.useState)(void 0),[Z,ee]=(0,a.useState)(!0),[et,en]=(0,a.useState)(!1),[er,ea]=(0,a.useState)(null),[ei,es]=(0,a.useState)(void 0);(0,a.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get("q");e&&es(e)},[]);let eo=(0,a.useRef)(null);(0,a.useEffect)(()=>{if(V||!c||eo.current===c)return;eo.current=c;let e=!1;return(0,s.fG)(i,c).then(t=>{var n;e||R((null!=(n=t.messages)?n:[]).filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({id:e.id,role:e.role,content:e.content,serverId:e.id,streaming:!1})))}).catch(()=>{}),()=>{e=!0}},[i,c,V]),(0,a.useEffect)(()=>{if(!g||V)return;let e=!1;return s.Dh.scope(i).then(t=>{e||L(t)}).catch(()=>{}),()=>{e=!0}},[i,g,V]),(0,a.useEffect)(()=>{var e,t;if(!V)return;if(null==(e=(t=window).matchMedia)?void 0:e.call(t,"(prefers-reduced-motion: reduce)").matches){R(b.map((e,t)=>({id:"demo-".concat(t),role:"bot"===e.role?"assistant":"user",content:e.citation&&"bot"===e.role?"".concat(e.text,"\n\n_").concat(m(e.citation),"_"):e.text,streaming:!1}))),D("idle");return}let n=!1,r=null,a=e=>new Promise(t=>{let a=()=>{if(n)return t();if(B.current){r=setTimeout(a,120);return}t()};r=setTimeout(a,e)}),i=async(e,t,r)=>{for(let i=1;i<=t.length;i++){if(n)return;if(B.current){await a(4*r),i--;continue}R(n=>n.map(n=>n.id===e?{...n,content:t.slice(0,i)}:n));let s=r+(Math.random()-.5)*r*.6;await a(Math.max(8,s))}R(t=>t.map(t=>t.id===e?{...t,streaming:!1}:t))},s=async(e,t)=>{for(let r=1;r<=e.length;r++){if(n)return;if(B.current){await a(4*t),r--;continue}H(e.slice(0,r));let i=t+(Math.random()-.5)*t*.6;await a(Math.max(8,i))}};return(async()=>{for(;!n;){R([]),H(""),D("streaming");for(let e=0;e<b.length;e++){if(n)return;let t=b[e],r="bot"===t.role?"assistant":"user",o="demo-".concat(Date.now(),"-").concat(e),l=t.citation&&"bot"===t.role?"".concat(t.text,"\n\n_").concat(m(t.citation),"_"):t.text;if("user"===r){if(await a(350),n||(await s(l,55),n)||(await a(450),n))return;H(""),R(e=>[...e,{id:o,role:r,content:l,streaming:!1}])}else{if(await a(700),n)return;R(e=>[...e,{id:o,role:r,content:"",streaming:!0}]),await i(o,l,22)}await a(e===b.length-1?4200:600)}}})(),()=>{n=!0,r&&clearTimeout(r),D("idle")}},[b,V]),(0,a.useLayoutEffect)(()=>{let e=W.current;e&&(e.scrollTop=e.scrollHeight)},[A]),(0,a.useLayoutEffect)(()=>{if(y||V)return;let e=Y.current;e&&(e.style.height="auto",e.style.height="".concat(Math.min(e.scrollHeight,176),"px"))},[I,y,V]),(0,a.useEffect)(()=>{if(V||y||!w)return;let e=!1;return fetch("/api/".concat(i).concat(w.href),{credentials:"include"}).then(t=>e?void 0:401===t.status?void ee(!1):t.ok?t.json():void 0).then(t=>{if(e||!t)return;let n=Array.isArray(t.cases)?t.cases.length:"number"==typeof t.drafts?t.drafts:Array.isArray(t)?t.length:void 0;"number"==typeof n&&X(n)}).catch(()=>{}),()=>{e=!0}},[i,V,y]),(0,a.useEffect)(()=>()=>{var e;null==(e=J.current)||e.abort()},[]);let el=(0,a.useCallback)(async e=>{let t=e.trim();if(!t||$.current)return;$.current=!0;let n=T;n||E(n=(await (0,s.Nw)(i)).id);let r="".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,8)),a="u-".concat(r),o="a-".concat(r);R(e=>[...e,{id:a,role:"user",content:t},{id:o,role:"assistant",content:"",streaming:!0}]),O(""),D("streaming"),q(!1);let l=new AbortController;J.current=l;try{for await(let e of(0,s.cz)(i,n,t,l.signal,_,v))if("thread"===e.type)E(e.thread_id),R(t=>t.map(t=>
1t.id===a?{...t,serverId:e.user_message_id}:t));else if("delta"===e.type)R(t=>t.map(t=>t.id===o?{...t,content:t.content+e.text}:t));else if("truncation"===e.type)R(e=>e.map(e=>e.id===o?{...e,truncated:!0}:e));else if("tool_call"===e.type)("illustrate_story"===e.name||"create_spine"===e.name)&&q(!0);else if("tool_result"===e.type){Array.isArray(e.images)&&e.images.length&&q(!1);let t="t-".concat(r,"-").concat(e.tool_use_id||Math.random().toString(36).slice(2,6));R(n=>{let r=n.map(t=>!1===e.ok&&t.id===o?{...t,toolFailed:!0}:t),a={id:t,role:"system",content:e.message,streaming:!1,toolOk:e.ok};return"auth_required"===e.action&&e.sign_in_url&&(a.authRequired=!0,a.signInUrl=e.sign_in_url),Array.isArray(e.images)&&e.images.length&&(a.images=e.images.map(e=>({url:e.url,page_index:e.page_index}))),e.clip&&e.clip.url&&(a.clip={url:e.clip.url}),k&&"auth_required"===e.action&&!a.images||r.push(a),r})}else if("done"===e.type)R(t=>t.map(t=>t.id===o?{...t,serverId:e.assistant_message_id,streaming:!1}:t)),D("idle"),q(!1),null==N||N({cost_coin:e.cost_coin,balance_after:e.balance_after,needs_credits:e.needs_credits});else if("error"===e.type)throw Error(e.message)}catch(t){let e=t instanceof Error?t.message:String(t);D("error"),R(e=>e.map(e=>e.id===o?{...e,streaming:!1}:e)),C({title:"Chat error",description:e,variant:"destructive"})}finally{q(!1),J.current===l&&(J.current=null),$.current=!1}},[i,T,C,N]),ec=(0,a.useRef)(!1);(0,a.useEffect)(()=>{let e=null!=p?p:ei;!e||ec.current||V||(ec.current=!0,el(e))},[p,ei,el,V]);let ed=(0,a.useRef)(0);(0,a.useEffect)(()=>{var e;if(V)return;let t=null!=(e=null==S?void 0:S.nonce)?e:0;t<=0||t===ed.current||(ed.current=t,el(S.text))},[null==S?void 0:S.nonce,el,V]);let eu=(0,a.useCallback)(e=>{e.preventDefault(),el(I)},[I,el]),ep=(0,a.useCallback)(e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),el(I))},[I,el]),em="streaming"===M,eh=(0,a.useMemo)(()=>"chat-input-".concat(i),[i]),eg=(0,a.useCallback)(()=>{V&&(B.current=!0,z(!0))},[V]),ex=(0,a.useCallback)(()=>{V&&(B.current=!1,z(!1))},[V]);return(0,r.jsxs)("div",{className:(0,u.cn)("flex h-full min-h-0 flex-col overflow-hidden bg-background",y?"gap-1.5 rounded-md text-[10px]":"gap-3 rounded-lg border",!y&&(null==K?void 0:K.shell)?K.shell:null,f),"data-scope":i,"data-demo":V?"true":void 0,"data-paused":F?"true":void 0,onMouseEnter:eg,onMouseLeave:ex,children:[!y&&(0,r.jsx)("a",{href:"#".concat(eh),className:"sr-only focus:not-sr-only focus:absolute focus:left-2 focus:top-2 focus:z-50 focus:rounded focus:bg-primary focus:px-3 focus:py-2 focus:text-primary-foreground",children:"Skip to chat input"}),!y&&g&&U?(0,r.jsxs)("details",{className:"border-b px-4 py-2 text-xs text-muted-foreground",children:[(0,r.jsxs)("summary",{className:"cursor-pointer",children:[U.name," \xb7 ",U.model]}),(0,r.jsx)("pre",{className:"mt-2 whitespace-pre-wrap font-mono text-[11px]",children:U.system_prompt})]}):null,y||V||!w?null:(0,r.jsx)("div",{className:"flex justify-end px-4",children:Z?(0,r.jsxs)("a",{href:w.href,className:(0,u.cn)("inline-flex min-h-[28px] items-center gap-1.5 rounded-full px-3 py-1 text-xs font-medium no-underline transition",null!=(t=null==K?void 0:K.chip)?t:"bg-primary text-primary-foreground hover:opacity-90"),"aria-label":"Open your ".concat(w.label.toLowerCase()," queue"),children:[(0,r.jsx)("span",{children:"Your Queue"}),"number"==typeof Q?(0,r.jsxs)("span",{"aria-hidden":"true",children:["\xb7 ",Q," ",w.unit,1===Q?"":"s"]}):null,(0,r.jsx)("span",{"aria-hidden":"true",children:"→"})]}):(0,r.jsxs)("a",{href:s.j2.loginUrl(w.href),className:(0,u.cn)("inline-flex min-h-[28px] items-center gap-1.5 rounded-full px-3 py-1 text-xs font-medium no-underline transition",null!=(n=null==K?void 0:K.chip)?n:"bg-primary text-primary-foreground hover:opacity-90"),"aria-label":"Sign in to see your ".concat(w.label.toLowerCase()," queue"),children:[(0,r.jsx)("span",{children:"Sign in to see your queue"}),(0,r.jsx)("span",{"aria-hidden":"true",children:"→"})]})}),(0,r.jsxs)("div",{ref:W,role:"log","aria-live":"polite","aria-label":"Chat transcript for ".concat(i),"aria-busy":em?"true":"false",className:(0,u.cn)("flex-1 overflow-y-auto",y?"space-y-1.5 px-2 py-1.5":"space-y-3 px-4 py-2"),children:[0!==A.length||V?null:j?(0,r.jsxs)("div",{className:"flex items-start gap-2 text-sm italic text-muted-foreground",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:j.iconClass,children:j.icon}),(0,r.jsxs)("span",{children:[j.line1,j.line2?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("br",{}),j.line2]}):null]})]}):"laude"===i?(0,r.jsxs)("div",{className:"flex items-start gap-2 text-sm italic text-muted-foreground",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:"text-laude",children:"✦"}),(0,r.jsx)("span",{children:"What would you like to govern today?"})]}):(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"No messages yet. Start the conversation."}),A.map(e=>(0,r.jsx)(x,{message:e,compact:y,userBubbleClass:null==K?void 0:K.user,readAloud:i.toLowerCase().includes("story"),onContinue:e.truncated&&!em?()=>void el("Continue the previous response exactly where you stopped — no recap, no preamble."):void 0},e.id)),P?(0,r.jsx)("div",{role:"status","aria-live":"polite","aria-label":"Drawing the pictures",className:"flex w-full justify-center",children:(0,r.jsxs)("div",{className:(0,u.cn)("inline-flex items-center gap-2 rounded-md bg-primary/10 
1italic text-primary",y?"px-2 py-1 text-[10px]":"px-3 py-1.5 text-xs"),children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"\uD83C\uDFA8"}),(0,r.jsx)("span",{children:"Painting the pictures…"}),(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 py-0.5","aria-hidden":"true",children:[(0,r.jsx)("span",{className:"chat-dot"}),(0,r.jsx)("span",{className:"chat-dot"}),(0,r.jsx)("span",{className:"chat-dot"})]})]})}):null]}),y?(0,r.jsxs)("div",{"aria-hidden":"true",className:"flex items-end gap-1.5 border-t border-border bg-muted/40 px-2 py-1.5",children:[(0,r.jsx)("span",{"data-autogrow":"chat-input",className:"flex-1 whitespace-pre-wrap break-words rounded-2xl px-2.5 py-1 text-[9px] leading-snug "+(G?"bg-background text-foreground":"bg-muted text-muted-foreground"),children:G?(0,r.jsxs)(r.Fragment,{children:[G,(0,r.jsx)("span",{className:"ml-0.5 inline-block w-[1px] animate-pulse bg-foreground align-baseline","aria-hidden":"true",children:"|"})]}):(0,r.jsxs)(r.Fragment,{children:["Ask ",i,"…"]})}),(0,r.jsx)("span",{className:"grid h-4 w-4 place-items-center rounded-full bg-primary text-[8px] font-bold text-primary-foreground",children:"↑"})]}):(0,r.jsx)("div",{className:"sticky bottom-0 z-20 bg-background",style:{paddingBottom:"env(safe-area-inset-bottom, 0)"},children:(0,r.jsxs)("form",{"data-role":"chat-input",onSubmit:eu,className:"flex items-end gap-2 border-t p-3","aria-label":"Send a message",children:[(0,r.jsx)("label",{htmlFor:eh,className:"sr-only",children:"Message"}),(0,r.jsx)(l.T,{id:eh,ref:Y,value:I,onChange:e=>O(e.target.value),onKeyDown:ep,placeholder:"Type a message…",rows:2,disabled:em,"data-autogrow":"chat-input",className:"min-h-[44px] max-h-[176px] flex-1 resize-none overflow-y-auto"}),(0,r.jsx)(o.$,{type:"submit",disabled:em||0===I.trim().length,className:(0,u.cn)("min-h-[44px] min-w-[44px]",null==K?void 0:K.send),"aria-label":"Send message",children:em?"Sending…":"Send"})]})}),y||V||"laude"!==i||!T?null:(0,r.jsx)("div",{className:"flex items-center justify-between border-t border-laude/20 bg-laude/5 px-4 py-2",children:er?(0,r.jsx)("a",{href:er,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-medium text-laude hover:underline",children:"Session closed — PR opened ↗"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"End this session to open a PR in your canonic-galaxy."}),(0,r.jsx)(o.$,{type:"button",disabled:et||"streaming"===M,onClick:async()=>{en(!0);try{let e=await (0,s.nE)("laude",T);ea(e.pr_url),C({title:"Session closed",description:"PR opened in your canonic-galaxy."})}catch(e){C({title:"Close failed",description:"Could not open PR — try again.",variant:"destructive"})}finally{en(!1)}},className:(0,u.cn)("min-h-[36px] text-xs",null==K?void 0:K.send),"aria-label":"End session and open PR",children:et?"Closing…":"End Session"})]})})]})}function x(e){let{message:t,compact:n=!1,userBubbleClass:s,onContinue:o,readAloud:l=!1}=e,d="user"===t.role;if("system"===t.role){var p,m;let e=!1!==t.toolOk;if(t.authRequired&&t.signInUrl)return(0,r.jsx)("div",{className:"flex w-full justify-center",children:(0,r.jsxs)("div",{role:"status","aria-live":"polite",className:(0,u.cn)("flex max-w-[85%] flex-col items-center gap-2 rounded-md bg-primary/10 px-4 py-3 text-center text-primary",n?"text-[10px]":"text-xs"),children:[(0,r.jsx)("span",{className:"italic",children:t.content}),(0,r.jsx)("a",{href:t.signInUrl,className:(0,u.cn)("inline-flex min-h-[44px] items-center gap-2 rounded-md bg-primary px-4 py-2 font-semibold text-primary-foreground no-underline transition hover:opacity-90",n?"text-[10px]":"text-sm"),children:"Sign in to continue"})]})});let a=null!=(m=t.images)?m:[];return(0,r.jsx)("div",{className:"flex w-full justify-center",children:(0,r.jsxs)("div",{role:"status","aria-live":"polite",className:(0,u.cn)("flex max-w-[85%] flex-col gap-2 rounded-md px-3 py-1.5 text-center italic",n?"text-[10px]":"text-xs",e?"bg-primary/10 text-primary":"bg-warning/10 text-warning"),children:[a.length>0&&(0,r.jsx)("div",{className:(0,u.cn)("grid gap-2",a.length>1?"grid-cols-2":"grid-cols-1"),children:a.map((e,t)=>{var n;return(0,r.jsx)("img",{src:e.url,alt:"Story illustration ".concat((null!=(n=e.page_index)?n:t)+1),className:"w-full rounded-md border border-primary/20 object-cover",loading:"lazy"},t)})}),(null==(p=t.clip)?void 0:p.url)&&(0,r.jsx)("video",{src:t.clip.url,className:"w-full rounded-md border border-primary/20",autoPlay:!0,muted:!0,loop:!0,playsInl
1ine:!0,controls:!0}),(0,r.jsx)("span",{children:t.content})]})})}let h=!d&&t.streaming&&!t.content,g=(0,a.useMemo)(()=>d||h?null:i.xI.parse(t.content||""),[d,h,t.content]),[x,f]=(0,a.useState)(!1),b=(0,a.useCallback)(()=>{if(!window.speechSynthesis)return;let e=window.speechSynthesis;if(e.speaking||x){e.cancel(),f(!1);return}let n=(t.content||"").replace(/[#*_`>~]|^\s*[-•]\s*/gm," ").replace(/\s+/g," ").trim();if(!n)return;let r=new SpeechSynthesisUtterance(n);r.rate=.95,r.pitch=1.05,r.onend=()=>f(!1),r.onerror=()=>f(!1),e.cancel(),e.speak(r),f(!0)},[t.content,x]);return(0,r.jsxs)("div",{className:(0,u.cn)("flex w-full flex-col gap-1.5",d?"items-end":"items-start"),children:[(0,r.jsx)("div",{className:(0,u.cn)("max-w-[85%] rounded-lg",n?"px-2 py-1 text-[10px] leading-snug":"px-3 py-2 text-sm",d?null!=s?s:"bg-primary text-primary-foreground":"bg-muted font-mono text-muted-foreground"),children:h?(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 py-0.5","aria-label":"typing",children:[(0,r.jsx)("span",{className:"chat-dot"}),(0,r.jsx)("span",{className:"chat-dot"}),(0,r.jsx)("span",{className:"chat-dot"})]}):d?(0,r.jsxs)("p",{className:"whitespace-pre-wrap",children:[t.content,t.streaming&&(0,r.jsx)("span",{className:"chat-caret","aria-hidden":"true"})]}):n?(0,r.jsx)("div",{className:(0,u.cn)("max-w-none","[&>*:first-child]:mt-0 [&>*:last-child]:mb-0","[&_p]:my-0.5 [&_p+p]:mt-1","[&_ul]:my-1 [&_ul]:pl-3 [&_ul]:list-disc","[&_ol]:my-1 [&_ol]:pl-3 [&_ol]:list-decimal","[&_li]:my-0","[&_em]:italic [&_em]:opacity-80","[&_strong]:font-semibold","[&_code]:rounded [&_code]:bg-background/40 [&_code]:px-1 [&_code]:py-px [&_code]:text-[9px]","[&_a]:underline [&_a]:decoration-dotted"),dangerouslySetInnerHTML:{__html:null!=g?g:""}}):(0,r.jsx)("div",{className:(0,u.cn)("max-w-none leading-normal","[&>*:first-child]:mt-0 [&>*:last-child]:mb-0","[&_p]:my-1 [&_p+p]:mt-2","[&_ul]:my-1.5 [&_ul]:pl-4 [&_ul]:list-disc","[&_ol]:my-1.5 [&_ol]:pl-4 [&_ol]:list-decimal","[&_li]:my-0.5","[&_h1]:mt-3 [&_h1]:mb-1.5 [&_h1]:text-sm [&_h1]:font-semibold","[&_h2]:mt-3 [&_h2]:mb-1.5 [&_h2]:text-sm [&_h2]:font-semibold","[&_h3]:mt-2 [&_h3]:mb-1 [&_h3]:text-sm [&_h3]:font-semibold","[&_h4]:mt-2 [&_h4]:mb-1 [&_h4]:text-sm [&_h4]:font-semibold","[&_em]:italic [&_em]:opacity-80","[&_strong]:font-semibold","[&_code]:rounded [&_code]:bg-background/40 [&_code]:px-1 [&_code]:py-px [&_code]:text-[11px]","[&_pre]:my-2 [&_pre]:rounded [&_pre]:bg-background/40 [&_pre]:p-2 [&_pre]:text-[11px]","[&_a]:underline [&_a]:decoration-dotted","[&_table]:my-2 [&_table]:w-full [&_table]:border-collapse [&_table]:text-xs","[&_th]:border [&_th]:border-muted-foreground/20 [&_th]:px-1.5 [&_th]:py-1 [&_th]:text-left [&_th]:font-semibold","[&_td]:border [&_td]:border-muted-foreground/20 [&_td]:px-1.5 [&_td]:py-1","[&_hr]:my-3 [&_hr]:border-muted-foreground/20","[&_blockquote]:border-l-2 [&_blockquote]:border-muted-foreground/30 [&_blockquote]:pl-2 [&_blockquote]:italic [&_blockquote]:opacity-90"),dangerouslySetInnerHTML:{__html:null!=g?g:""}})}),l&&!d&&!h&&t.content?(0,r.jsxs)("button",{type:"button",onClick:b,"aria-pressed":x?"true":"false","aria-label":x?"Stop reading aloud":"Read the story aloud",className:(0,u.cn)("inline-flex min-h-[32px] items-center gap-1.5 self-start rounded-md border px-2.5 py-1 font-medium transition",n?"text-[10px]":"text-xs",x?"border-primary bg-primary/10 text-primary":"border-muted-foreground/30 text-muted-foreground hover:bg-muted"),children:[(0,r.jsx)("span",{"aria-hidden":"true",children:x?"⏹":"\uD83D\uDD0A"}),x?"Stop":"Read aloud"]}):null,!t.truncated||d||n?null:(0,r.jsxs)("div",{role:"status","aria-live":"polite",className:"flex max-w-[85%] items-center gap-2 rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-xs text-warning",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"⚠"}),(0,r.jsx)("span",{className:"flex-1",children:"Response truncated (max tokens). Sections below may be missing."}),o?(0,r.jsx)("button",{type:"button",onClick:o,className:"min-h-[28px] rounded border border-warning/50 px-2 py-0.5 font-semibold transition hover:bg-warning/20",children:"Continue ↻"}):null]}),!t.toolFailed||d||n?null:(0,r.jsxs)("div",{role:"status","aria-live":"polite",className:"flex w-full max-w-[420px] flex-col items-stretch gap-2 rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"⚠"}),(0,r.jsx)("span",{className:"flex-1",children:"Save didn’t land. Drop your email — we’ll send a one-click link to persist this thread."})]}),(0,r.jsx)(c,{returnUrl:window.location.pathname+window.location.search})]})]})}i.xI.setOptions({breaks:!0,gfm:!0})},25016:(e,t,n)=>{n.d(t,{cn:()=>i});var r=n(2821),a=n(75889);function i(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return(0,a.QP)((0,r.$)(t))}},28171:(e,t,n)=>{n.d(t,{d:()=>u});var r=n(12115);let a=0,i=new Map;function s(e){if(i.has(e))return;let t=setTimeout(()=>{i.delete(e),c({type:"REMOVE_TOAST",toastId:e})},5e3);i.set(e,t)}let o=[],l={toasts:[]};function c(e){l=((e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,1)};case"DISMISS_TOAST":{let{toastId:n}=t;
1return n?s(n):e.toasts.forEach(e=>s(e.id)),e}case"REMOVE_TOAST":if(void 0===t.toastId)return{...e,toasts:[]};return{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)};default:return e}})(l,e),o.forEach(e=>e(l))}function d(e){let{...t}=e,n=(a=(a+1)%Number.MAX_SAFE_INTEGER).toString();return c({type:"ADD_TOAST",toast:{...t,id:n}}),s(n),{id:n,dismiss:()=>c({type:"DISMISS_TOAST",toastId:n})}}function u(){let[e,t]=r.useState(l);return r.useEffect(()=>(o.push(t),()=>{let e=o.indexOf(t);e>-1&&o.splice(e,1)}),[e]),{...e,toast:d,dismiss:e=>c({type:"DISMISS_TOAST",toastId:e})}}},37621:(e,t,n)=>{n.d(t,{Dh:()=>b,Nw:()=>c,Y7:()=>p,YY:()=>f,bx:()=>x,cW:()=>g,cz:()=>u,fG:()=>d,j2:()=>s,kO:()=>m,nE:()=>y,w9:()=>h});let r="/api";async function a(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{body:n,method:a=n?"POST":"GET",auth:i=!0}=t,s=await fetch("".concat(r).concat(e),{method:a,headers:{"Content-Type":"application/json"},body:n?JSON.stringify(n):void 0,credentials:i?"include":"omit"});if(!s.ok)throw Error("API error: ".concat(s.status," ").concat(s.statusText));return s.json()}async function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"GET",n=await fetch("".concat("/api/auth").concat(e),{method:t,credentials:"same-origin"});if(!n.ok)throw Error("Auth proxy error: ".concat(n.status," ").concat(n.statusText));return n.json()}let s={me:()=>i("/me").then(e=>e.user),logout:()=>i("/logout","POST"),signInUrl:e=>"/auth/sign-in?return=".concat(encodeURIComponent(e)),loginUrl:e=>"".concat(r,"/auth/login?return=").concat(encodeURIComponent(e))};function o(e){return"/talk/".concat(encodeURIComponent(e),"/threads")}function l(e,t){return"".concat(o(e),"/").concat(encodeURIComponent(t))}async function c(e){return a(o(e),{method:"POST",body:{}})}async function d(e,t){return a(l(e,t))}async function*u(e,t,n,a,i,s){let o={content:n};i&&(o.manuscript_context=i),s&&(o.client_context=s);let c=await fetch("".concat(r).concat("".concat(l(e,t),"/messages")),{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(o),credentials:"include",signal:a});if(!c.ok||!c.body)throw Error("Stream error: ".concat(c.status," ").concat(c.statusText));let d=c.body.getReader(),u=new TextDecoder,p="";for(;;){let e,{value:t,done:n}=await d.read();if(n)break;for(p+=u.decode(t,{stream:!0});-1!==(e=p.indexOf("\n\n"));){let t=p.slice(0,e);p=p.slice(e+2);let n=function(e){var t,n,r,a,i,s,o,l,c;let d="",u="";for(let t of e.split("\n"))t.startsWith("event:")?d=t.slice(6).trim():t.startsWith("data:")&&(u+=t.slice(5).trim());if(!d||!u)return null;let p=JSON.parse(u);switch(d){case"thread":return{type:"thread",thread_id:String(p.thread_id),user_message_id:String(p.user_message_id)};case"delta":return{type:"delta",text:String(null!=(t=p.text)?t:"")};case"truncation":return{type:"truncation",reason:"max_tokens",tier:String(null!=(n=p.tier)?n:""),hint:String(null!=(r=p.hint)?r:"continue")};case"tool_call":return{type:"tool_call",tool_use_id:String(null!=(a=p.tool_use_id)?a:""),name:String(null!=(i=p.name)?i:"")};case"tool_result":return{type:"tool_result",tool_use_id:String(null!=(s=p.tool_use_id)?s:""),message:String(null!=(o=p.message)?o:""),ok:!0===p.ok,..."auth_required"===p.action?{action:"auth_required",sign_in_url:String(null!=(l=p.sign_in_url)?l:"")}:{},...Array.isArray(p.images)&&p.images.length?{images:p.images.map(e=>{var t;let n=null!=e?e:{};return{url:String(null!=(t=n.url)?t:""),page_index:"number"==typeof n.page_index?n.page_index:void 0,seed:"number"==typeof n.seed?n.seed:void 0,provider:n.provider?String(n.provider):void 0}}).filter(e=>e.url)}:{},...p.clip&&"string"==typeof p.clip.url?{clip:{url:String(p.clip.url),tier:p.clip.tier?Str
1ing(p.clip.tier):void 0,provider:p.clip.provider?String(p.clip.provider):void 0}}:{}};case"done":return{type:"done",thread_id:String(p.thread_id),assistant_message_id:String(p.assistant_message_id),ledger_id:String(p.ledger_id),ts:String(p.ts),..."number"==typeof p.cost_coin?{cost_coin:p.cost_coin}:{},..."number"==typeof p.balance_after?{balance_after:p.balance_after}:{},..."boolean"==typeof p.needs_credits?{needs_credits:p.needs_credits}:{}};case"error":return{type:"error",message:String(null!=(c=p.message)?c:"stream error")};default:return null}}(t);n&&(yield n)}}}async function p(){return(await a("/casechat/cases")).cases}async function m(){return(await a("/casenex/cases",{auth:!1})).cases}let h={balance:()=>a("/coin/balance"),ledger:()=>a("/coin/ledger")},g={onboard:(e,t)=>a("/coin/cashout/onboard",{body:{return_url:e,refresh_url:null!=t?t:e}}),status:()=>a("/coin/cashout/status"),initiate:e=>a("/coin/cashout/initiate",{body:void 0===e?{}:{amount_coin:e}}),history:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20;return a("/coin/cashout/history?limit=".concat(e))}},x={catalog:()=>a("/shop/catalog"),checkout:e=>a("/coin/checkout",{body:{product_id:e}})},f={signalDifficulty:e=>a("/anki/signal/difficulty",{body:e,auth:!1})},b={scope:e=>a("/config/".concat(e),{auth:!1})};async function y(e,t){return a("".concat(l(e,t),"/close"),{method:"POST",body:{}})}},67001:(e,t,n)=>{n.d(t,{T:()=>s});var r=n(95155),a=n(12115),i=n(25016);let s=a.forwardRef((e,t)=>{let{className:n,...a}=e;return(0,r.jsx)("textarea",{className:(0,i.cn)("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:t,...a})});s.displayName="Textarea"},97003:(e,t,n)=>{n.d(t,{$:()=>c});var r=n(95155),a=n(12115),i=n(32467),s=n(83101),o=n(25016);let l=(0,s.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"min-h-[44px] px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"min-h-[44px] rounded-md px-8",icon:"h-[44px] w-[44px]"}},defaultVariants:{variant:"default",size:"default"}}),c=a.forwardRef((e,t)=>{let{className:n,variant:a,size:s,asChild:c=!1,...d}=e,u=c?i.DX:"button";return(0,r.jsx)(u,{className:(0,o.cn)(l({variant:a,size:s,className:n})),ref:t,...d})});c.displayName="Button"}}]);

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.