PageSourceSearch

https://fiftyoneai.com/js/CoachingModule.tsx-CZb4ToEP.js

js fiftyoneai.com collected 2026-10-10 02:45:14 UTC 13,911 bytes, 1 lines download raw bytes

1import{j as e,q as h,b9 as te,a1 as O,R as se,bI as U,F as H,X as ae,a_ as ne,_ as re,b as J,a9 as V,bJ as ie,ab as le,bK as oe,l as ce,h as de}from"./chunk-CgdxW11o.js";import{r as i}from"./chunk-Dmsukp28.js";import{b as me,s as x,B as v}from"../assets/index-BrW_aWiG.js";import{A as ue}from"./chunk-t40V-mZK.js";import"./chunk-BqJbJ7gK.js";import"./chunk-0KF9c2-o.js";import"./chunk-D-qgE2qZ.js";const xe={analogy:{icon:le,label:"Jury analogy"},client_question:{icon:oe,label:"Ask the client"},evidence_gap:{icon:ce,label:"Evidence gap"},opposing_expert:{icon:de,label:"Opposing expert"}};function Ne({caseId:p}){const[X,R]=i.useState(!0),[b,T]=i.useState(!1),[c,$]=i.useState(null),[E,z]=i.useState([]),[I,M]=i.useState([]),[l,w]=i.useState(null),[o,g]=i.useState(null),[k,_]=i.useState(""),[f,D]=i.useState(!1),[S,P]=i.useState(!1),[W,F]=i.useState(null),[d,y]=i.useState([]),[G,C]=i.useState(!1),j=i.useRef(null),q=i.useRef(null),{toast:m}=me();i.useEffect(()=>{let t=!1;return(async()=>{R(!0);const[n,s]=await Promise.all([x.functions.invoke("counsel-sme-detect",{body:{case_id:p}}),x.from("counsel_sme_sessions").select("*").eq("case_id",p).order("updated_at",{ascending:!1}).limit(1)]);if(t)return;const r=n.data;r?.primary&&($(r.primary),z(r.secondary||[]),M(r.catalog||[]));const a=(s.data||[])[0];if(a){g(a);const u=(r?.catalog||[]).find(N=>N.key===a.sme_type)||{key:a.sme_type,label:a.sme_role_label,description:""};w({...u,rationale:a.sme_rationale||void 0})}else r?.primary&&w(r.primary);R(!1)})(),()=>{t=!0}},[p]),i.useEffect(()=>{q.current?.scrollTo({top:q.current.scrollHeight,behavior:"smooth"})},[o?.messages?.length]);const A=async t=>{w(t),g(null)},B=async()=>{T(!0);try{const{data:t,error:n}=await x.functions.invoke("counsel-sme-detect",{body:{case_id:p}});if(n)throw n;const s=t;s?.primary&&($(s.primary),z(s.secondary||[]),M(s.catalog||[]),m({title:"Re-detected",description:`Recommended expert: ${s.primary.label}`}))}catch(t){m({title:"Could not re-detect",description:t.message,variant:"destructive"})}finally{T(!1)}},Y=async t=>{if(!t||t.length===0)return;if(d.length+t.length>5){m({title:"Up to 5 files per message",variant:"destructive"});return}C(!0);const{data:n}=await x.auth.getUser(),s=n.user?.id;if(!s){C(!1);return}const r=[];for(const a of Array.from(t)){if(a.size>10*1024*1024){m({title:`${a.name} is over 10MB`,variant:"destructive"});continue}const u=a.name.replace(/[^a-zA-Z0-9._-]+/g,"_").slice(0,120),N=`${p}/${s}/${Date.now()}-${Math.random().toString(36).slice(2,7)}-${u}`,{error:L}=await x.storage.from("counsel-sme-attachments").upload(N,a,{contentType:a.type||"application/octet-stream",upsert:!1});if(L){m({title:`Could not upload ${a.name}`,description:L.message,variant:"destructive"});continue}r.push({name:a.name,mime:a.type||"application/octet-stream",size:a.size,storage_path:N})}y(a=>[...a,...r]),C(!1),j.current&&(j.current.value="")},Z=async t=>{const n=d[t];n&&await x.storage.from("counsel-sme-attachments").remove([n.storage_path]),y(s=>s.filter((r,a)=>a!==t))},K=async()=>{const t=k.trim();if(!t&&d.length===0||!l)return;const n=d;_(""),y([]),D(!0);const s={role:"user",content:t,attachments:n,at:new Date().toISOString()};g(r=>r?{...r,messages:[...r.messages||[],s]}:{id:"",sme_type:l.key,sme_role_label:l.label,sme_rationale:l.rationale||null,messages:[s],framing_snippets:[],intake_question_queue:[],created_at:new Date().toISOString()});try{const{data:r,error:a}=await x.functions.invoke("counsel-sme-chat",{body:{case_id:p,sme_type:l.key,sme_rationale:l.rationale,session_id:o?.id||null,user_message:t,attachments:n}});if(a)throw a;const u=r;if(u?.error)throw new Error(u.error);u?.session&&g(u.session)}catch(r){m({title:"The expert couldn't respond",description:r.message||"Try again.",variant:"destructive"}),g(a=>a&&{...a,messages:(a.messages||[]).slice(0,-1)}),_(t),y(n)}finally{D(!1)}},ee=async()=>{if(!(!l||!o?.id)){P(!0);try{const{data:t,error:n}=await x.functions.invoke("counsel-sme-intake-questions",{body:{case_id:p,sme_type:l.key,session_id:o.id}});if(n)throw n;const s=t;s?.questions&&(g(r=>r&&{...r,intake_question_queue:s.questions}),m({title:"Intake questions ready",description:`${s.questions.length} questions tailored by ${l.label}.`}))}catch(t){m({title:"Could not generate questions",description:t.message,variant:"destructive"})}finally{P(!1)}}},Q=async(t,n)=>{await navigator.clipboard.writeText(t),F(n),setTimeout(()=>F(s=>s===n?null:s),1200)};return X?e.jsx("div",{className:"px-6 py-12",children:e.jsx(h,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):!c&&!l?e.jsxs("div",{className:"px-6 py-16 max-w-2xl",children:[e.jsx(te,{className:"w-6 h-6 text-muted-foreground mb-4"}),e.jsx("h2",{className:"editorial-headline text-2xl mb-3",children:"Summon a subject-matter expert"}),e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed mb-6",children:"Consult a non-legal expert (engineer, physician, accountant, etc.) on how to frame this case for a jury or judge, and what questions to put to your client next."}),e.jsxs(v,{onClick:B,disabled:b,className:"gap-2",children:[b?e.jsx(h,{className:"w-4 h-4 animate-spin"}):e.jsx(O,{className:"w-4 h-4"}),"Detect the right expert"]})]}):e.jsxs("div",{className:"px-4 sm:px-6 lg:px-10 py-6 max-w-7xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.3em] text-muted-foreground mb-2",children:"Coaching"}),e.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[e.jsx("h1",{className:"editorial-headline text-2xl",children:"You're consulting:"}),e.jsx("span",{className:"text-2xl font-medium",children:l?.label||c?.label})]}),(l?.rationale||c?.rationale)&&e.jsx("p",{className:"text-sm text-muted-foreground italic mt-2 max-w-3xl leading-relaxed",children:l?.rationale||c?.rationale})]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:B,disabled:b,className:"shrink-0 gap-2",children:[b?e.jsx(h,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(se,{className:"w-3.5 h-3.5"}),"Re-detect"]})]}),(E.length>0||I.length>0)&&e.jsxs("div",{className:"mb-6 flex flex-wrap gap-1.5 items-center",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground
1/70 mr-2",children:"Switch:"}),c&&e.jsx("button",{onClick:()=>A(c),className:`text-[11px] px-2.5 py-1 border transition-colors ${l?.key===c.key?"border-foreground text-foreground":"border-border/40 text-muted-foreground hover:border-foreground/40 hover:text-foreground"}`,children:c.label}),E.map(t=>e.jsx("button",{onClick:()=>A(t),className:`text-[11px] px-2.5 py-1 border transition-colors ${l?.key===t.key?"border-foreground text-foreground":"border-border/40 text-muted-foreground hover:border-foreground/40 hover:text-foreground"}`,children:t.label},t.key)),e.jsxs("details",{className:"relative",children:[e.jsx("summary",{className:"text-[11px] px-2.5 py-1 border border-dashed border-border/40 text-muted-foreground hover:text-foreground cursor-pointer list-none",children:"More experts..."}),e.jsx("div",{className:"absolute z-10 mt-1 left-0 w-72 bg-background border border-border/60 shadow-lg p-2 max-h-72 overflow-auto",children:I.map(t=>e.jsxs("button",{onClick:()=>A(t),className:"block w-full text-left px-2 py-1.5 hover:bg-muted/40 text-xs",children:[e.jsx("div",{className:"font-medium",children:t.label}),e.jsx("div",{className:"text-[10px] text-muted-foreground leading-snug",children:t.description})]},t.key))})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-[minmax(0,1fr)_280px] xl:grid-cols-[minmax(0,1fr)_300px] gap-6",children:[e.jsxs("div",{className:"border border-border/40 flex flex-col",style:{height:"calc(100vh - 280px)",minHeight:500},children:[e.jsxs("div",{ref:q,className:"flex-1 overflow-y-auto p-5 space-y-5",children:[(!o||o.messages.length===0)&&e.jsxs("div",{className:"text-sm text-muted-foreground italic",children:["Ask the expert anything. Examples:",e.jsxs("ul",{className:"mt-3 space-y-1.5 text-xs not-italic",children:[e.jsx("li",{children:'• "Give me a jury analogy for what the defendant did."'}),e.jsx("li",{children:'• "What would confuse a juror most about this?"'}),e.jsx("li",{children:'• "What expert witness would I need, and what would they testify to?"'}),e.jsx("li",{children:'• "What evidence am I missing to prove this?"'})]})]}),o?.messages?.map((t,n)=>e.jsx("div",{className:t.role==="user"?"flex justify-end":"",children:e.jsxs("div",{className:t.role==="user"?"max-w-[88%] bg-muted/40 px-4 py-2.5":"max-w-[92%] w-full",children:[t.role==="assistant"&&e.jsx("p",{className:"text-[10px] uppercase tracking-[0.2em] text-muted-foreground mb-2 font-mono",children:l?.label||"Expert"}),t.role==="assistant"?e.jsx(ue,{content:t.content,tone:"chat",copyable:!0}):e.jsxs(e.Fragment,{children:[t.content&&e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap",children:t.content}),t.attachments&&t.attachments.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:t.attachments.map((s,r)=>{const a=s.mime?.startsWith("image/")?U:H;return e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] bg-background/60 border border-border/40 px-2 py-0.5 rounded",children:[e.jsx(a,{className:"w-3 h-3"}),s.name]},r)})})]})]})},n)),f&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(h,{className:"w-3 h-3 animate-spin"})," Thinking..."]})]}),e.jsxs("div",{className:"border-t border-border/40 p-3 space-y-2",children:[d.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.map((t,n)=>{const s=t.mime?.startsWith("image/")?U:H;return e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] bg-muted/40 border border-border/40 px-2 py-1 rounded",children:[e.jsx(s,{className:"w-3 h-3"}),e.jsx("span",{className:"max-w-[160px] truncate",children:t.name}),e.jsx("button",{onClick:()=>Z(n),className:"text-muted-foreground hover:text-foreground",title:"Remove",children:e.jsx(ae,{className:"w-3 h-3"})})]},n)})}),e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsx("input",{ref:j,type:"file",multiple:!0,accept:"image/*,application/pdf,text/*,.md,.csv,.json,.xml,.log,.yml,.yaml",className:"hidden",onChange:t=>Y(t.target.files)}),e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>j.current?.click(),disabled:G||f||d.length>=5,className:"self-end shrink-0",title:"Attach files (PDF, image, text — up to 5, 10MB each)",children:G?e.jsx(h,{className:"w-4 h-4 animate-spin"}):e.jsx(ne,{className:"w-4 h-4"})}),e.jsx("textarea",{value:k,onChange:t=>_(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.metaKey||t.ctrlKey)&&K()},placeholder:"Ask the expert... (Cmd/Ctrl+Enter to send)",rows:2,className:"flex-1 resize-none bg-transparent text-sm focus:outline-none",disabled:f}),e.jsxs(v,{onClick:K,disabled:f||!k.trim()&&d.length===0,size:"sm",className:"self-end gap-1.5",children:[f?e.jsx(h,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(re,{className:"w-3.5 h-3.5"}),"Send"]})]})]})]}),e.jsxs("aside",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.3em] text-muted-foreground mb-3",children:"Framing snippets"}),!o?.framing_snippets||o.framing_snippets.length===0?e.jsx("p",{className:"text-xs text-muted-foreground
1/70 italic",children:"As the expert speaks, jury analogies, evidence gaps, and client-question prompts will collect here."}):e.jsx("div",{className:"space-y-2.5",children:o.framing_snippets.slice().reverse().map((t,n)=>{const s=xe[t.kind]||{icon:O,label:t.kind},r=s.icon,a=`snip-${n}`;return e.jsxs("div",{className:"border border-border/40 p-3 group",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-[0.2em] text-muted-foreground",children:[e.jsx(r,{className:"w-3 h-3"}),e.jsx("span",{children:s.label})]}),e.jsx("button",{onClick:()=>Q(t.body,a),className:"opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground",title:"Copy",children:W===a?e.jsx(J,{className:"w-3 h-3"}):e.jsx(V,{className:"w-3 h-3"})})]}),e.jsx("p",{className:"text-xs leading-relaxed",children:t.body})]},n)})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.3em] text-muted-foreground",children:"Suggested client questions"}),e.jsxs("button",{onClick:ee,disabled:S||!o?.id,className:"text-[10px] uppercase tracking-[0.2em] text-primary hover:text-primary/80 disabled:text-muted-foreground/40 inline-flex items-center gap-1",title:o?.id?"Generate intake questions":"Send the expert a message first",children:[S?e.jsx(h,{className:"w-3 h-3 animate-spin"}):e.jsx(ie,{className:"w-3 h-3"}),S?"Working":"Generate"]})]}),!o?.intake_question_queue||o.intake_question_queue.length===0?e.jsx("p",{className:"text-xs text-muted-foreground/70 italic",children:"Ask this expert what to put to the client, then click Generate. The IntakeModule will surface them."}):e.jsx("ol",{className:"space-y-2.5",children:o.intake_question_queue.map((t,n)=>{const s=`q-${n}`;return e.jsxs("li",{className:"border border-border/40 p-3 group",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-1.5",children:[e.jsx("p",{className:"text-xs font-medium leading-snug flex-1",children:t.question}),e.jsx("button",{onClick:()=>Q(t.question,s),className:"opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground",title:"Copy",children:W===s?e.jsx(J,{className:"w-3 h-3"}):e.jsx(V,{className:"w-3 h-3"})})]}),t.why_it_matters&&e.jsxs("p",{className:"text-[10px] text-muted-foreground leading-relaxed italic",children:["Why: ",t.why_it_matters]})]},n)})})]})]})]})]})}export{Ne as CoachingModule};

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.