PageSourceSearch

https://twocuriousminds.com/assets/PersonCommandPalette.CCHhWh8x.js

js twocuriousminds.com collected 2026-10-02 01:47:11 UTC 14,545 bytes, 1 lines download raw bytes

1import{j as e}from"./ui.C-TpFEx-.js";import{d as je,r as l}from"./router.b4tCI-Sp.js";import{u as L,a as O,s as se,e as _e,cM as we,F as ne,n as R,L as k,Y as H,q as ae,p as q,o as re,D as oe,U as ke}from"./index.Cx-ip9x_.js";import{g as Ne,a as Se,b as ve,d as N,f as j}from"./command.C07p_f-e.js";import{u as Ce}from"./useSearchPeople.Cl5iwDdo.js";import{a as be}from"./index.module.DVWINgdr.js";import{i as Y}from"./authenticatedFunctions.IFmIiX1d.js";import{A as Ie}from"./arrow-left.CYlXU83H.js";import"./vendor.CL6-1M4B.js";import"./supabase.BbAAlgwC.js";const Ae=new Set(["42P01","42703","PGRST204"]),Re=5*60*1e3,ie=5,Ee=300;function Pe(c){const{user:r}=L(),o=r?.id,i=c.trim(),d=!!o&&i.length>=ie&&i.length<=Ee,a=O({queryKey:["ask-network",o,i.toLowerCase()],enabled:d,staleTime:Re,retry:!1,queryFn:async()=>{if(!o)return{candidates:[],emptyReason:"error",intent:null};const{data:P,error:x}=await se.functions.invoke("ask-route",{body:{question:i}});if(x)return{candidates:[],emptyReason:"error",intent:null};const u=P??{};if(u.ok===!1&&u.code==="SPEND_CAP_EXCEEDED")return{candidates:[],emptyReason:"spend_cap",intent:null};if(u.error)return{candidates:[],emptyReason:"error",intent:null};const _=(u.candidates??[]).filter(n=>!!n?.external_person_id),m=u.intent??null;if(_.length===0){const n=u.empty_reason??"no_corpus_match";return{candidates:[],emptyReason:n,intent:m}}const S=Array.from(new Set(_.map(n=>n.external_person_id))),p=new Map,{data:I,error:g}=await se.from("insight_collections").select("id, person_id").eq("user_id",o).in("person_id",S).not("person_id","is",null);if(g){const n=g.code??"";if(!Ae.has(n))throw g}for(const n of I??[])n.person_id&&!p.has(n.person_id)&&p.set(n.person_id,n.id);const C=_.map(n=>({externalPersonId:n.external_person_id,collectionId:p.get(n.external_person_id)??null,name:n.name,email:n.email??null,citation:n.citation&&n.citation.text?{source:n.citation.source??"",text:n.citation.text,occurredAt:n.citation.occurred_at??null}:null}));return{candidates:C,emptyReason:C.length===0?"no_corpus_match":null,intent:m}}}),h=i.length>0&&i.length<ie;return{candidates:a.data?.candidates??[],emptyReason:d?a.data?.emptyReason??(a.isError?"error":null):h?"too_short":null,intent:a.data?.intent??null,isAsking:d&&a.isFetching,isError:a.isError}}const Q=5,Fe=/^(who|whom|whose|what|which|where|when|why|how|is\s+there|are\s+there|does\s+anyone|do\s+you\s+know|anyone\s|someone\s|find\s)/i;function Te(c){const r=c.trim();return r.length<Q?!1:r.endsWith("?")||Fe.test(r)?!0:r.split(/\s+/).filter(Boolean).length>=3}const Me=5*60*1e3,qe=2;function Qe(c){const{user:r}=L(),o=c.trim(),i=!!r?.id&&o.length>=qe,d=O({queryKey:["gmail-people-search",r?.id,o.toLowerCase()],enabled:i,staleTime:Me,retry:!1,queryFn:async()=>{const{data:a,error:h}=await Y("find-people-in-gmail",{body:{query:o}});return h||!a?{candidates:[],reason:"error"}:{candidates:Array.isArray(a.candidates)?a.candidates:[],reason:a.reason??null}}});return{candidates:d.data?.candidates??[],reason:d.data?.reason??null,isSearching:i&&d.isFetching}}const Le=5*60*1e3,Ge=2;function Ue(c){const{user:r}=L(),o=c.trim(),i=!!r?.id&&o.length>=Ge,d=O({queryKey:["slack-people-search",r?.id,o.toLowerCase()],enabled:i,staleTime:Le,retry:!1,queryFn:async()=>{const{data:a,error:h}=await Y("find-people-in-slack",{body:{query:o}});return h||!a?{candidates:[],reason:"error"}:{candidates:Array.isArray(a.candidates)?a.candidates:[],reason:a.reason??null}}});return{candidates:d.data?.candidates??[],reason:d.data?.reason??null,isSearching:i&&d.isFetching}}const le={no_corpus_match:{title:"No one in your circle has come up around that yet.",helper:"The more reads you build, the sharper this gets."},filtered_off_topic:{title:"Nothing in your circle clearly matches that topic.",helper:"Try naming the topic more directly."},filtered_non_human:{title:"No one in your circle has come up around that yet.",helper:"The more reads you build, the sharper this gets."},too_short:{title:"Add a little more to your question.",helper:"A few more words help find the right person."},spend_cap:{title:"Couldn’t check just now.",helper:"Give it a moment and ask again."},error:{title:"Couldn’t reach your circle just now.",helper:"Check your connection and try again."}},E=({title:c,helper:r,icon:o})=>e.jsxs("div",{className:"flex flex-col items-center justify-center px-6 py-10 text-center",children:[e.jsx("div",{className:"mb-2 text-muted-foreground
1/50",children:o??e.jsx(ke,{className:"h-5 w-5"})}),e.jsx("p",{className:"text-sm text-foreground",children:c}),r&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r})]}),ze=({open:c,onOpenChange:r})=>{const o=je(),{posthog:i}=_e(),{user:d}=L(),a=d?.id,[h,P]=l.useState(""),[x]=be(h,200),[u,_]=l.useState(""),[m,S]=l.useState(null),[p,I]=l.useState(""),[g,C]=l.useState(""),{recentDossiers:n,isLoading:B}=we(5),{results:G,isSearching:b}=Ce(x),{candidates:U,emptyReason:ce,isAsking:F}=Pe(u),{candidates:K,reason:W,isSearching:D}=Qe(p),{candidates:X,reason:V,isSearching:$}=Ue(g);l.useEffect(()=>{c||(P(""),_(""),I(""),C(""),S(null))},[c]),l.useEffect(()=>{u&&h.trim()!==u&&_("")},[h,u]),l.useEffect(()=>{p&&x.trim()!==p&&I("")},[x,p]),l.useEffect(()=>{g&&x.trim()!==g&&C("")},[x,g]);const v=l.useCallback(t=>{r(!1),o(`/person/${t}`)},[o,r]),de=l.useCallback(async(t,s,f)=>{if(!(!a||m)){S(t);try{const w=await ne.getOrCreateForAttendee(a,t,s,f);w?v(w):R({title:"Could not open this read — try again.",variant:"destructive"})}catch{R({title:"Could not open this read — try again.",variant:"destructive"})}finally{S(null)}}},[a,m,v]),me=l.useCallback(t=>{const s=t.trim();if(!(s.length<Q)){_(s);try{i?.capture("cmdk_ask_network_opened",{length:s.length})}catch{}}},[i]),ue=l.useCallback(t=>{const s=t.trim();if(!(s.length<2)){I(s);try{i?.capture("cmdk_gmail_people_search",{length:s.length})}catch{}}},[i]),he=l.useCallback(t=>{const s=t.trim();if(!(s.length<2)){C(s);try{i?.capture("cmdk_slack_people_search",{length:s.length})}catch{}}},[i]),z=l.useCallback(async t=>{if(!(!a||m)){S(t.email);try{const{data:s,error:f}=await Y("ensure-external-person",{body:{email:t.email,name:t.name}}),w=s?.external_person_id;if(f||!w){R({title:"Could not add this person — try again.",variant:"destructive"});return}const te=await ne.getOrCreateForAttendee(a,w,t.name,t.email);te?v(te):R({title:"Could not open this read — try again.",variant:"destructive"})}catch{R({title:"Could not add this person — try again.",variant:"destructive"})}finally{S(null)}}},[a,m,v]),xe=l.useCallback(()=>_(""),[]),y=x.trim(),J=y.length>=2,Z=u.trim().length>=Q,A=l.useMemo(()=>[...G].sort((t,s)=>{const f=t.collectionId?0:1,w=s.collectionId?0:1;return f!==w?f-w:(t.name??"").localeCompare(s.name??"")}),[G]),T=l.useMemo(()=>U.filter(t=>!!t.collectionId),[U]),M=l.useMemo(()=>n.filter(t=>!!t.collectionId),[n]),pe=Te(x),ge=!b&&G.length===0&&y.length>=Q,fe=!Z&&J&&(pe||ge),ye=!F&&U.length>0&&T.length===0,ee=le[ce??"no_corpus_match"]??le.no_corpus_match;return e.jsxs(Ne,{open:c,onOpenChange:r,shouldFilter:!1,children:[e.jsx(Se,{placeholder:"Find a person, or ask who knows about…",value:h,onValueChange:P}),e.jsx(ve,{children:Z?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:xe,className:"flex w-full items-center gap-2 border-b border-border/50 px-3 py-2 text-xs text-muted-foreground transition-colors hover:text-foreground",children:[e.jsx(Ie,{className:"h-3.5 w-3.5"}),"Back to search"]}),F&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-10 text-xs text-muted-foreground",children:[e.jsx(k,{className:"h-3.5 w-3.5 animate-spin"}),"Reading your circle…"]}),!F&&T.length>0&&e.jsx(N,{heading:"Who might know",children:T.map(t=>e.jsxs(j,{value:t.externalPersonId,onSelect:()=>t.collectionId&&v(t.collectionId),children:[e.jsx(H,{className:"mr-2 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate text-sm text-foreground",children:t.name}),t.citation?.text&&e.jsx("span",{className:"line-clamp-2 text-[11px] leading-snug text-muted-foreground",children:t.citation.text})]})]},t.externalPersonId))}),!F&&T.length===0&&(ye?e.jsx(E,{title:"A few people came up — but no open read yet.",helper:"Build a read on them and they’ll be one tap away."}):e.jsx(E,{title:ee.title,helper:ee.helper}))]}):J?e.jsxs(e.Fragment,{children:[fe&&e.jsx(N,{heading:"Find by topic",children:e.jsxs(j,{value:"__ask__",onSelect:()=>me(x),children:[e.jsx(ae,{className:"mr-2 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"text-sm text-foreground",children:"Find who in your circle knows about this"}),e.jsxs("span",{className:"truncate text-[11px] text-muted-foreground",children:["“",y,"”"]}
1)]})]})}),b&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-xs text-muted-foreground",children:[e.jsx(k,{className:"h-3.5 w-3.5 animate-spin"}),"Searching…"]}),!b&&A.length>0&&e.jsx(N,{heading:"People",children:A.map(t=>{const s=!!t.collectionId,f=m===t.externalPersonId;return e.jsxs(j,{value:t.externalPersonId,disabled:!!m&&!f,onSelect:()=>s?v(t.collectionId):void de(t.externalPersonId,t.name,t.email??void 0),children:[f?e.jsx(k,{className:"mr-2 h-4 w-4 shrink-0 animate-spin text-muted-foreground"}):s?e.jsx(H,{className:"mr-2 h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(q,{className:"mr-2 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate text-sm text-foreground",children:t.name}),s?t.email&&e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:t.email}):e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:f?"Starting a read…":t.email?`${t.email} · start a read`:"In your contacts · start a read"})]})]},t.externalPersonId)})}),!b&&A.length===0&&!p&&!g&&e.jsxs(N,{heading:"Not finding them?",children:[e.jsxs(j,{value:"__gmail__",onSelect:()=>ue(y),children:[e.jsx(re,{className:"mr-2 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"text-sm text-foreground",children:"Search your Gmail for this"}),e.jsxs("span",{className:"truncate text-[11px] text-muted-foreground",children:["“",y,"”"]})]})]}),e.jsxs(j,{value:"__slack__",onSelect:()=>he(y),children:[e.jsx(oe,{className:"mr-2 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"text-sm text-foreground",children:"Search your Slack for this"}),e.jsxs("span",{className:"truncate text-[11px] text-muted-foreground",children:["“",y,"”"]})]})]})]}),!b&&A.length===0&&p&&e.jsxs(N,{heading:"From your Gmail",children:[D&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-xs text-muted-foreground",children:[e.jsx(k,{className:"h-3.5 w-3.5 animate-spin"}),"Searching your Gmail…"]}),!D&&K.map(t=>{const s=m===t.email;return e.jsxs(j,{value:t.email,disabled:!!m&&!s,onSelect:()=>void z(t),children:[s?e.jsx(k,{className:"mr-2 h-4 w-4 shrink-0 animate-spin text-muted-foreground"}):e.jsx(q,{className:"mr-2 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate text-sm text-foreground",children:t.name}),e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:s?"Starting a read…":`${t.email} · start a read`})]})]},t.email)}),!D&&K.length===0&&e.jsx(E,{icon:e.jsx(re,{className:"h-5 w-5"}),title:W==="gmail_not_connected"?"Connect Gmail to find people you email.":`No one matching “${y}” in your Gmail.`,helper:W==="gmail_not_connected"?"Connect Gmail from your settings, then try again.":void 0})]}),!b&&A.length===0&&g&&e.jsxs(N,{heading:"From your Slack",children:[$&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-xs text-muted-foreground",children:[e.jsx(k,{className:"h-3.5 w-3.5 animate-spin"}),"Searching your Slack…"]}),!$&&X.map(t=>{const s=m===t.email;return e.jsxs(j,{value:t.email,disabled:!!m&&!s,onSelect:()=>void z(t),children:[s?e.jsx(k,{className:"mr-2 h-4 w-4 shrink-0 animate-spin text-muted-foreground"}):e.jsx(q,{className:"mr-2 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate text-sm text-foreground",children:t.name}),e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:s?"Starting a read…":`${t.email} · start a read`})]})]},t.email)}),!$&&X.length===0&&e.jsx(E,{icon:e.jsx(oe,{className:"h-5 w-5"}),title:V==="slack_not_connected"?"Connect Slack to find people you work with.":`No one matching “${y}” in your Slack.`,helper:V==="slack_not_connected"?"Connect Slack from your settings, then try again.":void 0})]})]}):e.jsxs(e.Fragment,{children:[B&&M.length===0&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-xs text-muted-foreground",children:[e.jsx(k,{className:"h-3.5 w-3.5 animate-spin"}),"Loading…"]}),!B&&M.length===0&&e.jsx(E,{title:"Find anyone you have a read on.",helper:"Type a name, or ask “who knows fundraising?”"}),M.length>0&&e.jsx(N,{heading:"Recently read",children:M.map(t=>e.jsxs(j,{value:t.externalPersonId,onSelect:()=>t.collectionId&&v(t.collectionId),children:[e.jsx(H,{className:"mr-2 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate text-sm text-foreground",children:t.personName}),t.topClaim&&e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:t.topClaim.label})]})]},t.dossierId))}),e.jsx(N,{heading:"Your circle",children:e.jsxs(j,{value:"__grow_circle__",onSelect:()=>{r(!1),o("/people?grow=1")},children:[e.jsx(q,{className:"mr-2 h-4 w-4 shrink-0 text-primary"}),e.jsxs("div",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"text-sm text-foreground",children:"Grow your circle"}),e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:"Invite someone — your reads on people you both know get sharper"})]})]})}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t border-border/50 px-3 py-2.5 text-[11px] text-muted-foreground",children:[e.jsx(ae,{className:"h-3 w-3 shrink-0 text-primary/70"}),e.jsx("span",{children:"Ask a question — like “who knows fundraising?” — to find who in your circle can help."})]})]})})]})};export{ze as PersonCommandPalette};

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.