PageSourceSearch

https://fiftyoneai.com/js/ResearchModule.tsx-JdUCk_G0.js

js fiftyoneai.com collected 2026-10-10 02:45:10 UTC 19,592 bytes, 14 lines download raw bytes

1import{j as e,q as z,l as O,y as P,b4 as U,a4 as X,bh as K,aa as F,a1 as M,f as W,bB as Y,bC as Z,X as ee,S as se,h as te,a9 as ae,r as re,R as ne,s as ie,a5 as ce,a2 as oe}from"./chunk-CgdxW11o.js";import{r as l}from"./chunk-Dmsukp28.js";import{b as H,B as $,s as A}from"../assets/index-BrW_aWiG.js";import{T as le}from"./chunk-DC-WXiBv.js";import{I}from"./chunk-BWNQH_6X.js";import{P as E,H as B,T as S,F as de,a as ue}from"./chunk-DMI5n7DY.js";import{F as me}from"./chunk-Bp7zvfbx.js";import{A as xe}from"./chunk-t40V-mZK.js";import"./chunk-BqJbJ7gK.js";import"./chunk-0KF9c2-o.js";import"./chunk-D-qgE2qZ.js";function pe({onUseInResearch:t}){const[a,c]=l.useState(""),[i,h]=l.useState(""),[n,p]=l.useState(""),[m,b]=l.useState([]),[T,j]=l.useState(0),[g,y]=l.useState(!1),[v,R]=l.useState(!1),{toast:w}=H(),N=async()=>{const r=a.trim();if(r){y(!0),R(!0);try{const{data:u,error:k}=await A.functions.invoke("counsel-caselaw-search",{body:{query:r,court:i.trim()||void 0,dateAfter:n.trim()||void 0}});if(k)throw k;b(u?.results||[]),j(u?.total||0)}catch(u){w({title:"Search failed",description:u.message,variant:"destructive"}),b([]),j(0)}finally{y(!1)}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"border border-border/30 rounded-sm p-5 space-y-3 bg-muted/10",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground",children:"Search case law on CourtListener"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{placeholder:"e.g. qualified immunity excessive force",value:a,onChange:r=>c(r.target.value),onKeyDown:r=>{r.key==="Enter"&&N()},className:"text-sm"}),e.jsxs($,{onClick:N,disabled:g||!a.trim(),className:"text-xs uppercase tracking-[0.2em] gap-2 shrink-0",children:[g?e.jsx(z,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(O,{className:"w-3.5 h-3.5"}),g?"Searching":"Search"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(I,{placeholder:"Court ID (optional, e.g. ca9, scotus)",value:i,onChange:r=>h(r.target.value),className:"text-xs h-8 w-64"}),e.jsx(I,{type:"date",placeholder:"Filed after",value:n,onChange:r=>p(r.target.value),className:"text-xs h-8 w-44"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70 leading-relaxed",children:"9M+ federal & state opinions. Free. Always Shepardize results from a paid service before filing."})]}),v&&!g&&m.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground/60 italic text-center py-12",children:"No results. Try broader terms or a different court."}),m.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground",children:[m.length," of ",T.toLocaleString()," results"]}),e.jsx("div",{className:"space-y-3",children:m.map(r=>e.jsxs("article",{className:"border border-border/30 rounded-sm p-4 bg-background space-y-2",children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h4",{className:"text-sm font-medium leading-snug flex items-start gap-2",children:[e.jsx(P,{className:"w-3.5 h-3.5 text-muted-foreground mt-1 shrink-0"}),e.jsx("span",{children:r.case_name})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 mt-1.5 text-[11px] text-muted-foreground pl-5",children:[r.citation&&e.jsx("span",{className:"font-mono",children:r.citation}),r.court&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(U,{className:"w-3 h-3"})," ",r.court]}),r.date_filed&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(X,{className:"w-3 h-3"})," ",r.date_filed]}),typeof r.cite_count=="number"&&r.cite_count>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(K,{className:"w-3 h-3"})," Cited ",r.cite_count,"×"]})]})]})}),r.snippet&&e.jsxs("p",{className:"text-xs text-foreground/80 leading-relaxed pl-5 italic",children:['"',r.snippet,'"']}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-1 pl-5",children:[e.jsxs("a",{href:r.url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-foreground
1/80 hover:text-foreground underline-offset-2 hover:underline",children:["Read on CourtListener ",e.jsx(F,{className:"w-3 h-3"})]}),t&&e.jsx("button",{onClick:()=>t(r),className:"text-[11px] text-primary hover:text-primary/80 underline-offset-2 hover:underline",children:"Use in research →"})]})]},r.id))})]})]})}function fe({status:t}){return t==="verified"?e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] uppercase tracking-[0.18em] text-emerald-700 dark:text-emerald-400",children:[e.jsx(ie,{className:"w-3 h-3"})," Verified"]}):t==="not_found"?e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] uppercase tracking-[0.18em] text-destructive",children:[e.jsx(ce,{className:"w-3 h-3"})," Not found"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx(oe,{className:"w-3 h-3"})," Unverified"]})}function he({value:t,rationale:a}){if(t==null)return null;const c=t>=75?"bg-emerald-500":t>=50?"bg-amber-500":"bg-destructive",i=t>=75?"High":t>=50?"Moderate":"Low";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground",children:"Confidence"}),e.jsxs("p",{className:"text-xs tabular-nums text-muted-foreground",children:[e.jsx("span",{className:"text-foreground font-medium",children:i})," · ",t,"/100"]})]}),e.jsx("div",{className:"h-1 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full ${c} transition-all`,style:{width:`${t}%`}})}),a&&e.jsx("p",{className:"text-xs text-muted-foreground italic leading-relaxed",children:a})]})}function Ee({caseId:t}){const[a,c]=l.useState([]),[i,h]=l.useState(""),[n,p]=l.useState(""),[m,b]=l.useState(!1),[T,j]=l.useState(null),[g,y]=l.useState(0),[v,R]=l.useState(0),[w,N]=l.useState("analysis"),r=l.useRef(null),u=l.useRef(null),k=["Reading your case facts","Searching case law and statutes","Drafting legal analysis","Verifying citations on CourtListener","Checking against your evidence"],{toast:q}=H(),_=l.useCallback(async()=>{const{data:s}=await A.from("counsel_research_entries").select("*").eq("case_id",t).order("created_at",{ascending:!1});c(s||[])},[t]);l.useEffect(()=>{_()},[_]);const L=async(s,d)=>{const x=(s??i).trim();if(!x)return;b(!0),y(0),R(0);const C=Date.now();u.current=window.setInterval(()=>R(Math.floor((Date.now()-C)/1e3)),250),r.current=window.setInterval(()=>y(o=>Math.min(o+1,k.length-1)),6e3);try{const{data:o,error:f}=await A.functions.invoke("counsel-research",{body:{caseId:t,query:x,jurisdiction:(d??n).trim()||null}});if(f)throw f;q({title:"Research saved"}),s||h(""),_(),j(o?.entry?.id||null)}catch(o){q({title:"Research failed",description:o.message,variant:"destructive"})}finally{r.current&&window.clearInterval(r.current),u.current&&window.clearInterval(u.current),r.current=null,u.current=null,b(!1)}};l.useEffect(()=>()=>{r.current&&window.clearInterval(r.current),u.current&&window.clearInterval(u.current)},[]);const V=async s=>{await A.from("counsel_research_entries").update({pinned:!s.pinned}).eq("id",s.id),_()},G=async s=>{confirm("Delete this research entry?")&&(await A.from("counsel_research_entries").delete().eq("id",s),j(null),_())},J=async s=>{const d=je(s);await navigator.clipboard.writeText(d),q({title:"Copied as Markdown memo"})},Q=async s=>{const d=await Ne(s);me.saveAs(d,`research-${ge(s.query)}.docx`)},D=[...a].sort((s,d)=>Number(d.pinned)-Number(s.pinned));return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-6 border-b border-border/30",children:[e.jsxs("button",{onClick:()=>N("analysis"),className:`pb-2.5 text-[11px] uppercase tracking-[0.25em] transition-colors border-b-2 -mb-px flex items-center gap-2 ${w==="analysis"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[e.jsx(M,{className:"w-3 h-3"})," AI analysis"]}),e.jsxs("button",{onClick:()=>N("caselaw"),className:`pb-2.5 text-[11px] uppercase tracking-[0.25em] transition-colors border-b-2 -mb-px flex items-center gap-2 ${w==="caselaw"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[e.jsx(O,{className:"w-3 h-3"})," Case law search"]})]}),w==="caselaw"?e.jsx(pe,{onUseInResearch:s=>{const d=s.citation?` (${s.citation})`:"";h(`Analyze how ${s.case_name}${d} applies to this case.`),N("analysis")}}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border border-border/30 rounded-sm p-5 space-y-3 bg-muted/10",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground",children:"Ask a research question"}),e.jsx(le,{placeholder:"e.g. Is a non-compete enforceable in California against a remote employee hired by a Texas company?",value:i,onChange:s=>h(s.target.value),className:"text-sm min-h-[80px]"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(I,{placeholder:"Jurisdiction (optional)",value:n,onChange:s=>p(s.target.value),className:"text-sm h-9 w-56"}),e.jsx("div",{className:"flex-1"}),e.jsxs($,{onClick:()=>L(),disabled:m||!i.trim(),className:"text-xs uppercase tracking-[0.2em] gap-2",children:[e.jsx(M,{className:"w-3.5 h-3.5"}),m?"Researching…":"Run research"]})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 border border-amber-500/30 bg-amber-500/5 rounded-sm",children:[e.jsx(W,{className:"w-3.5 h-3.5 text-amber-600 dar
1k:text-amber-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-relaxed",children:"AI-assisted, not a substitute for Westlaw or Lexis. Citations are auto-checked against CourtListener but you must Shepardize before filing. The model can be wrong."})]})]}),m&&e.jsxs("div",{className:"border border-border/40 bg-muted/10 p-6 space-y-4 animate-in fade-in duration-300",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.3em] text-muted-foreground",children:"Researching · grounded in your case"}),e.jsxs("p",{className:"text-[10px] font-mono text-muted-foreground tabular-nums",children:[Math.floor(v/60).toString().padStart(2,"0"),":",(v%60).toString().padStart(2,"0"),v>0&&e.jsx("span",{className:"ml-2 text-muted-foreground/50",children:"/ ~30s"})]})]}),e.jsx("ol",{className:"space-y-2",children:k.map((s,d)=>{const x=d<g?"done":d===g?"active":"pending";return e.jsxs("li",{className:"flex items-center gap-3 text-sm",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 transition-all ${x==="done"?"bg-foreground
1/60":x==="active"?"bg-primary animate-pulse scale-125":"bg-muted-foreground/20"}`}),e.jsx("span",{className:`transition-colors ${x==="done"?"text-muted-foreground/60 line-through decoration-muted-foreground/30":x==="active"?"text-foreground":"text-muted-foreground/40"}`,children:s}),x==="active"&&e.jsx(z,{className:"w-3 h-3 animate-spin text-primary ml-1"})]},d)})}),e.jsx("p",{className:"text-[10px] text-muted-foreground/60 italic pt-2 border-t border-border/20",children:"Stay on this page. Citation verification adds a few seconds at the end."})]}),D.length===0&&!m&&e.jsx("p",{className:"text-sm text-muted-foreground/60 italic text-center py-12",children:"No research yet. Ask anything. Answers tie back to your case facts and parties."}),e.jsx("div",{className:"space-y-3",children:D.map(s=>{const d=(s.citations||[]).filter(o=>o.verified==="verified").length,x=(s.citations||[]).length,C=T===s.id;return e.jsxs("div",{className:`border rounded-sm bg-background ${s.pinned?"border-foreground/40":"border-border/30"}`,children:[e.jsxs("div",{className:"flex items-start gap-3 p-4",children:[e.jsx(P,{className:"w-4 h-4 text-muted-foreground mt-1 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium leading-snug",children:s.query}),e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.2em] text-muted-foreground mt-1.5",children:[s.jurisdiction||"any jurisdiction"," · ",new Date(s.created_at).toLocaleDateString()," · ",d,"/",x," citations verified"]}),s.key_holding&&e.jsx("p",{className:"text-sm mt-2 text-foreground/90 italic border-l-2 border-foreground
1/30 pl-3",children:s.key_holding})]}),e.jsx("button",{onClick:()=>V(s),className:"text-muted-foreground hover:text-foreground",title:s.pinned?"Unpin":"Pin",children:s.pinned?e.jsx(Y,{className:"w-4 h-4"}):e.jsx(Z,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>j(C?null:s.id),className:"text-[10px] uppercase tracking-[0.2em] text-muted-foreground hover:text-foreground",children:C?"Hide":"Open"}),e.jsx("button",{onClick:()=>G(s.id),className:"text-muted-foreground/40 hover:text-foreground",children:e.jsx(ee,{className:"w-4 h-4"})})]}),C&&e.jsxs("div",{className:"border-t border-border/20 p-5 space-y-6",children:[e.jsx(he,{value:s.confidence,rationale:s.confidence_rationale}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"xl:col-span-2 space-y-6",children:[s.summary&&e.jsxs("section",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground mb-2",children:"Analysis"}),e.jsx(xe,{content:s.summary,tone:"document",copyable:!0})]}),Array.isArray(s.fact_application)&&s.fact_application.length>0&&e.jsxs("section",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground mb-2",children:"Applied to your facts"}),e.jsx("ol",{className:"space-y-2 list-decimal list-inside marker:text-muted-foreground/50",children:s.fact_application.map((o,f)=>e.jsx("li",{className:"text-sm leading-relaxed pl-1",children:o},f))})]}),Array.isArray(s.counter_arguments)&&s.counter_arguments.length>0&&e.jsxs("section",{className:"border-l-2 border-destructive/40 pl-4 py-1",children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.25em] text-destructive/80 mb-2 flex items-center gap-1.5",children:[e.jsx(se,{className:"w-3 h-3"})," Opposing counsel will argue"]}),e.jsx("ul",{className:"space-y-2",children:s.counter_arguments.map((o,f)=>e.jsxs("li",{className:"text-sm leading-relaxed text-foreground/85",children:["— ",o]},f))})]})]}),e.jsxs("aside",{className:"space-y-5",children:[e.jsxs("section",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground mb-3",children:"Citations"}),e.jsx("ul",{className:"space-y-3",children:(s.citations||[]).map((o,f)=>e.jsxs("li",{className:"text-sm border border-border/30 rounded-sm p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("p",{className:"font-medium leading-tight",children:[o.name,o.jurisdiction&&e.jsxs("span",{className:"text-xs text-muted-foreground font-normal italic",children:[" (",o.jurisdiction,")"]})]}),e.jsx(fe,{status:o.verified})]}),o.cite&&e.jsx("p",{className:"text-xs font-mono text-muted-foreground",children:o.cite}),o.relevance&&e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:o.relevance}),o.treatment_note&&e.jsx("p",{className:"text-[11px] text-muted-foreground/80 italic",children:o.treatment_note}),o.verify_url&&e.jsxs("a",{href:o.verify_url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-foreground/70 hover:text-foreground underline-offset-2 hover:underline",children:["Open source ",e.jsx(F,{className:"w-3 h-3"})]}),o.verified==="not_found"&&e.jsxs("p",{className:"text-[11px] text-destructive flex items-center gap-1",children:[e.jsx(te,{className:"w-3 h-3"})," Could not confirm. Verify manually before relying."]})]},f))})]}),e.jsxs("section",{className:"space-y-2 pt-2 border-t border-border/20",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground",children:"Provenance"}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[s.model||"AI"," · ",new Date(s.created_at).toLocaleString()]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.jsxs($,{variant:"outline",size:"sm",className:"h-7 text-[10px] uppercase tracking-[0.18em] gap-1.5",onClick:()=>J(s),children:[e.jsx(ae,{className:"w-3 h-3"})," Copy memo"]}),e.jsxs($,{variant:"outline",size:"sm",className:"h-7 text-[10px] uppercase tracking-[0.18em] gap-1.5",onClick:()=>Q(s),children:[e.jsx(re,{className:"w-3 h-3"})," .docx"]}),e.jsxs($,{variant:"outline",size:"sm",className:"h-7 text-[10px] uppercase tracking-[0.18em] gap-1.5",disabled:m,onClick:()=>L(s.query,s.jurisdiction||""),children:[e.jsx(ne,{className:"w-3 h-3"})," Re-run"]})]})]})]})]})]})]},s.id)})})]})]})}function ge(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").slice(0,60).replace(/^-|-$/g,"")}function je(t){const a=[];return a.push("# Research Memo"),a.push(`**Question:** ${t.query}`),t.jurisdiction&&a.push(`**Jurisdiction:** ${t.jurisdiction}`),t.confidence!==null&&a.push(`**Confidence:** ${t.confidence}/100 — ${t.confidence_rationale||""}`),t.key_holding&&(a.push(`
2## Bottom line
3`),a.push(t.key_holding)),t.summary&&(a.push(`
4## Analysis
5`),a.push(t.summary)),t.fact_application?.length&&(a.push(`
6## Applied to your facts
7`),t.fact_application.forEach((c,i)=>a.push(`${i+1}. ${c}`))),t.counter_arguments?.length&&(a.push(`
8## Opposing counsel will argue
9`),t.counter_arguments.forEach(c=>a.push(`- ${c}`))),t.citations?.length&&(a.push(`
10## Citations
11`),t.citations.forEach(c=>{a.push(`- **${c.name}**${c.jurisdiction?` (${c.jurisdiction})`:""}${c.cite?` — ${c.cite}`:""} [${c.verified||"unknown"}]`),c.relevance&&a.push(`  - ${c.relevance}`),c.verify_url&&a.push(`  - Source: ${c.verify_url}`)})),a.push(`
12---
13_Generated by ${t.model||"AI"} on ${new Date(t.created_at).toLocaleString()}. Verify before filing._`),a.join(`
14`)}async function Ne(t){const a=(n,p={})=>new E({children:[new S({text:n,...p})],spacing:{after:120}}),c=(n,p=B.HEADING_2)=>new E({text:n,heading:p,spacing:{before:240,after:120}}),i=[new E({text:"Research Memo",heading:B.TITLE}),a(`Question: ${t.query}`,{bold:!0})];t.jurisdiction&&i.push(a(`Jurisdiction: ${t.jurisdiction}`)),t.confidence!==null&&i.push(a(`Confidence: ${t.confidence}/100 — ${t.confidence_rationale||""}`)),t.key_holding&&(i.push(c("Bottom line")),i.push(a(t.key_holding))),t.summary&&(i.push(c("Analysis")),t.summary.split(/\n+/).forEach(n=>i.push(a(n)))),t.fact_application?.length&&(i.push(c("Applied to your facts")),t.fact_application.forEach((n,p)=>i.push(a(`${p+1}. ${n}`)))),t.counter_arguments?.length&&(i.push(c("Opposing counsel will argue")),t.counter_arguments.forEach(n=>i.push(a(`• ${n}`)))),t.citations?.length&&(i.push(c("Citations")),t.citations.forEach(n=>{i.push(new E({spacing:{after:80},children:[new S({text:n.name,bold:!0}),new S({text:n.jurisdiction?` (${n.jurisdiction})`:"",italics:!0}),new S({text:n.cite?`  ${n.cite}`:""}),new S({text:`  [${n.verified||"unknown"}]`,color:n.verified==="verified"?"1f7a3a":n.verified==="not_found"?"a4262c":"707070"})]})),n.relevance&&i.push(a(n.relevance)),n.verify_url&&i.push(a(`Source: ${n.verify_url}`,{italics:!0,size:18}))})),i.push(a(`Generated by ${t.model||"AI"} on ${new Date(t.created_at).toLocaleString()}. Verify before filing.`,{italics:!0,size:18}));const h=new de({sections:[{children:i}]});return await ue.toBlob(h)}export{Ee as ResearchModule};

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.