1import{j as e,o as ye,q as st,m as Le,g as qe,C as zt,s as Ot,bH as be,bK as Bt,T as Ye,bJ as xe,N as G,bG as Ft,r as a,S as ve,bM as It,f as Re,bN as Mt,B as T,bw as Ut,bz as Je,e as ut,a3 as We,a as de,y as ht,Z as mt,a9 as Dt,aL as Pt,bO as qt,aD as Ee,bI as ke,bE as Yt,bP as nt,aN as Jt,bQ as Wt,x as Ht,z as Vt,bq as Gt,bF as Qt,J as Kt,L as Xt,K as Zt,bR as es,bS as at,bT as ts,bU as Te,bL as ss}from"./index-_Ci2S7BU.js";import{C as ns}from"./circle-DjktqpJb.js";import{W as as}from"./WorkspaceArtifactLayer-G83mLcCZ.js";import{a as rs}from"./agentsReturnTo-CNNdLGGY.js";import{S as is}from"./settings-2-DQDfz0qk.js";function pt(t){return Array.isArray(t)?t.join(", "):typeof t=="string"?t:""}function ls(t){return String(t||"").split(",").map(r=>r.trim()).filter(Boolean)}function rt(t,r,{pastKey:i=""}={}){const n={};for(const s of t){const d=r[s.key];if(s.key!==i&&!(d==null||d===""))if(s.type==="companies"){const m=be(d);m.length&&(n[s.key]=m)}else if(s.type==="geography"){const m=ls(d);m.length&&(n[s.key]=m)}else if(s.type==="number")n[s.key]=Number(d);else if(s.type==="people_constraints")try{n[s.key]=JSON.parse(d)}catch{n[s.key]=d}else n[s.key]=d}if(i){const s=t.filter(m=>m.type==="companies"&&m.key!==i).map(m=>r[m.key]||""),d=Bt(r[i]||"",s);d.length&&(n[i]=d)}return n}function os(t,r={}){const i={};for(const n of t){const s=r[n.key];s!==void 0&&(n.type==="companies"?i[n.key]=Ft(s):n.type==="geography"?i[n.key]=pt(s):n.type==="people_constraints"?i[n.key]=JSON.stringify(s,null,2):i[n.key]=s)}return i}function it(t){return t.key.replace(/_/g," ").replace(/^\w/,r=>r.toUpperCase())}const cs=t=>t.length<=1?t.join(""):`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`,ds=5;function us({text:t,pastLabel:r="",pastField:i=!1}){const n=xe(t),s=i?[]:n.past_only,{sentences:d}=n;if(!s.length&&!d.length)return null;const m=s.length===1,b=d.slice(0,ds).map(U=>`"${U}"`),v=d.length-b.length;return e.jsxs("div",{className:"mt-2 space-y-2",children:[s.length?e.jsxs(G,{tone:"warning","data-companies-past-only":"",children:[cs(s)," ",m?"is marked as a past employer":"are marked as past employers"," only. ",r?`The run maps ${m?"it":"them"} under ${r}: the people who held the seat there and have since left.`:`A run maps the people each company has now, so ${m?"it is":"they are"} left off the companies and passed to the agent as a note.`]}):null,d.length?e.jsx(G,{tone:"warning","data-companies-sentences":"",children:d.length===1?`This line reads like a sentence rather than a company name, and the run researches it as a company: ${b[0]}. Remove it if it is not a company.`:`These lines read like sentences rather than company names, and the run researches each as a company: ${b.join(", ")}${v?` and ${v} more`:""}. Remove any that are not companies.`}):null]})}function hs({components:t,draft:r,onChange:i,errors:n={},disabled:s=!1,pastKey:d="",pastLabel:m=""}){const b=(c,y)=>i({...r,[c]:y}),v=d?t.find(c=>c.key===d):null,U=v?it(v):m;return e.jsx("div",{className:"space-y-5",children:t.map(c=>{const y=`${it(c)}${c.required?" *":""}`,x=c.description||"",_=r[c.key]??"",w=n[c.key],O=c.default_value!==void 0?`Default: ${pt(c.default_value)||String(c.default_value)}`:void 0;let p;return c.type==="companies"?p=e.jsx(ye,{label:y,hint:x||`One company per line: a name, a domain, or "Name, domain.com"; "Alphabet (also Google), abc.xyz" for one company known by two names; end a line with [divisions] to map that company's division, segment or site leaders instead of its company-wide seat; a line "# Big Tech" names the kind of company the lines under it are.`,rows:8,value:_,disabled:s,error:w,textareaClassName:"font-mono text-[12.5px]",onChange:h=>b(c.key,h.target.value)}):c.type==="text"||c.type==="people_constraints"?p=e.jsx(ye,{label:y,hint:x,rows:c.type==="text"?3:5,value:_,disabled:s,error:w,placeholder:O,textareaClassName:c.type==="people_constraints"?"font-mono text-[12.5px]":"",onChange:h=>b(c.key,h.target.value)}):c.type==="number"&&c.choice_labels?p=e.jsxs(st,{label:y,hint:x,value:_===""?"":String(_),disabled:s,error:w,onChange:h=>b(c.key,h.target.value),children:[e.jsx("option",{value:"",children:c.default_value!==void 0?`Default: ${c.choice_labels[c.default_value]||c.default_value}`:"Chooseâ¦"}),Object.entries(c.choice_labels).map(([h,M])=>e.jsx("option",{value:h,children:M},h))]}):c.type==="number"?p=e.jsx(Le,{label:y,hint:x,type:"number",value:_,disabled:s,error:w,placeholder:O,min:c.minimum,max:c.maximum,onChange:h=>b(c.key,h.target.value)}):c.type==="boolean"?p=e.jsx(Ye,{label:y,checked:_===!0,disabled:s,onChange:h=>b(c.key,h)}):c.type==="enum"?p=e.jsxs(st,{label:y,hint:x,value:_,disabled:s,error:w,onChange:h=>b(c.key,h.target.value),children:[e.jsx("option",{value:"",children:c.default_value!==void 0?`Default (${c.default_value})`:"Chooseâ¦"}),(c.enum_values||[]).map(h=>e.jsx("option",{value:h,children:h},h))]}):c.type==="geography"?p=e.jsx(Le,{label:y,hint:x||"Separate places with commas.",value:_,disabled:s,error:w,placeholder:O,onChange:h=>b(c.key,h.target.value)}):p=e.jsx(Le,{label:y,hint:x,value:_,disabled:s,error:w,placeholder:O,onChange:h=>b(c.key,h.target.value)}),e.jsxs("div",{"data-mandate-field":c.key,children:[e.jsxs("div",{className:"mb-1 flex flex-wrap gap-1.5",children:[e.jsx(qe,{tone:c.class==="advisory"?"neutral":c.class==="checkable"?"violet":"brand",children:zt[c.class]||c.class}),e.jsx(qe,{tone:"neutral",children:Ot[c.bind]||c.bind})]}),p,c.type==="companies"?e.jsx(us,{text:_,pastLabel:U,pastField:c.key===d}):null]},c.key)})})}const ms=".txt,.md,.pdf,.docx,.pptx,.vtt,.srt",ps=50*1024*1024,lt=280,Ue=t=>t.replace(/_/g," ").replace(/^\w/,r=>r.toUpperCase()),ee=t=>t.length<=1?t.join(""):`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`,De=t=>
1Number(t||0).toLocaleString("en-US");function fs(t,{fileName:r="",applied:i=null,kept:n=[],added:s=[],removed:d=[],missing:m=[],marked:b=[],aside:v=[],change:U=!1,opened:c=!0}={}){const y=t?.source||{},x=[r,y.pages?`${De(y.pages)} ${y.pages===1?"page":"pages"}`:"",y.scanned?"read from its page images":""].filter(Boolean).join(", "),_=r?` (${x})`:"",w=(Array.isArray(i)?i:t?.filled||[]).map(Ue),O=w.length||n.length||s.length||d.length||b.length||v.length||t?.filled?.length,p=U?[w.length?`I changed ${ee(w)}.`:s.length||d.length||b.length?"Done.":"I did not find anything on the card to change from that."]:[w.length?`I read your notes${_} and filled in ${ee(w)}.`:O?`I read your notes${_}.`:`I could not find mandate details in your notes${_}.`];s.length&&p.push(`I added ${ee(s)} to the companies.`),d.length&&p.push(`I took ${ee(d)} off the companies.`),m.length&&p.push(`I could not find ${ee(m)} in the companies.`);const h=t?.past_employers_key?Ue(t.past_employers_key):"";if(v.length){const u=v.length===1;p.push(h?`${ee(v)} ${u?"goes":"go"} under ${h}, not the companies: the card marks ${u?"it a past employer":"them past employers"} only.`:`${ee(v)} ${u?"stays":"stay"} off the companies: the card marks ${u?"it a past employer":"them past employers"} only. To map the people there now, take the mark off ${u?"its line":"their lines"}.`)}const M=Object.entries(t?.values||{}).filter(([u,P])=>Array.isArray(P)&&(!Array.isArray(i)||i.includes(u))).flatMap(([,u])=>u).filter(u=>u&&typeof u=="object"&&u.level==="division").map(u=>u.name),Y=(t?.add_companies||[]).filter(u=>u?.level==="division"&&s.includes(u.name)).map(u=>u.name),R=[...new Set([...M,...b,...Y])];R.length&&p.push(`I marked ${ee(R)} [divisions], so ${R.length===1?"it is":"they are"} mapped at ${R.length===1?"its":"their"} divisions, segments or sites rather than company-wide; change the marks on the card if that is wrong.`),n.length&&p.push(`I kept your own edits to ${ee(n.map(Ue))}.`),y.condensed&&p.push(`They were long, so I kept only the passages about the search (${De(y.read_chars)} of ${De(y.cleaned_chars)} characters).`),p.push(...t?.warnings||[]),t?.companies_description&&c&&p.push(`Your notes describe the companies rather than name them, so I opened Find companies with that description${t.leave_out?.length?`, leaving out ${ee(t.leave_out)}`:""}: press Suggest companies to see them.`);const z=Array.isArray(t?.past_employers)?t.past_employers:[];if(z.length){const u=z.length===1;p.push(h?`${ee(z)} ${u?"is a past employer":"are past employers"} only, so I put ${u?"it":"them"} under ${h}: the run maps who held the seat there and has since left.`:`${ee(z)} ${u?"is a past employer":"are past employers"} only, so I left ${u?"it":"them"} off the companies and put ${u?"it":"them"} in the note for the agent.`)}return t?.note_to_lead&&p.push("I added the rest of the context to the note for the agent."),t?.refused?.length&&p.push(`I could not use: ${t.refused.join("; ")}.`),p.push(t?.questions?.length?"Before you start, I need:":"Check the launch card below, change anything, and start the run when it is right."),p.join(" ")}function gs(t,r){const i=t.map(s=>typeof s=="string"?s:s?.name).map(s=>String(s||"").replace(/\s*\([^()]*\)\s*$/,"").trim()).filter(Boolean),n=String(r?.companies_description||"").trim();return{count:t.length,described:!!n,description:n||`Companies like ${ee(i.slice(0,8))}`,exclude:Array.isArray(r?.leave_out)?r.leave_out:[]}}const ot=t=>t===1?"Only this one":`Only these ${t}`;function xs(t){const r=t.count===1,i=`The launch card lists ${t.count} ${r?"company":"companies"}${t.described?", and your notes describe more":""}.`,n=t.described?"like the notes describe":`like ${r?"it":"them"}`;return`${i} Should I map only ${r?"that one":`these ${t.count}`}, or first find more companies ${n}? Finding more costs extra: the search uses a few credits for each kind of company it finds, and every company you add raises the run's estimate.`}function ys(t,r){return t==="more"?"I am finding more companies under Find companies. When the search is done, tick the ones to add; the estimate below updates as you add them.":r.count===1?"I will map only the company on the launch card.":`I will map only the ${r.count} companies on the launch card.`}const js="What should change on the launch card?";function bs({definitionId:t,currentValues:r,onApply:i,onMessages:n,onScopeChoice:s,rate:d=0,disabled:m=!1,initialNotes:b="",readOnArrival:v=!1,mcpScopeId:U=""}){const[c,y]=a.useState(()=>String(b||"")),[x,_]=a.useState(null),[w,O]=a.useState(0),[p,h]=a.use
1State({notes:"",answers:[]}),[M,Y]=a.useState([]),[R,z]=a.useState([]),[u,P]=a.useState(""),[g,f]=a.useState(""),[k,F]=a.useState([]),[H,K]=a.useState(""),J=a.useRef(null),oe=a.useRef(!1);a.useEffect(()=>()=>J.current?.abort(),[]),a.useEffect(()=>{n?.(M)},[M,n]);const te=async({notes:j,upload:l,answers:C,ownerMessage:E,action:S,asked:D,change:L=!1})=>{J.current?.abort();const Q=new AbortController;J.current=Q,f(S),F([]),K("");try{const ie=r(),V=await de.readIntake(t,{notes:j,answers:C,current:ie,file:l},{signal:Q.signal,mcpScopeId:U,onProgress:he=>{Q.signal.aborted||F(he)}});if(Q.signal.aborted)return!1;const I=i(V,{asked:D,current:ie})||{};return h({notes:typeof V.notes_read=="string"?V.notes_read:j,answers:C}),z(Array.isArray(V.questions)?V.questions:[]),Y(he=>[...he,{role:"owner",text:E},{role:"agent",text:fs(V,{fileName:l?.name||"",...I,applied:I.applied||null,change:L}),questions:V.questions||[]},...I.scope?[{role:"agent",text:xs(I.scope),scope:I.scope}]:[]]),!0}catch(ie){return Q.signal.aborted||K(ie.message||"The notes could not be read. Try again, or fill in the launch card."),!1}finally{J.current===Q&&(J.current=null,f(""),F([]))}},ae=j=>{const l=j.target.files?.[0]||null;if(K(""),l&&l.size>ps){_(null),O(C=>C+1),K(`${l.name} is larger than 50 MB. Upload a smaller export, or paste the notes.`);return}_(l)},X=async()=>{const j=c.trim();if(!j&&!x)return;const l=[p.notes,j].filter(Boolean).join(` 2 3`),C=j?`${j.slice(0,lt)}${j.length>lt?"â¦":""}`:"",E=[x?`Uploaded ${x.name}.`:"",C].filter(Boolean).join(" ");await te({notes:l,upload:x,answers:p.answers,ownerMessage:E,action:"notes",asked:[]})&&(y(""),_(null),O(S=>S+1))};a.useEffect(()=>{if(!v||oe.current||m||!c.trim())return;const j=setTimeout(()=>{oe.current=!0,X()},0);return()=>clearTimeout(j)},[v,m]);const se=(j,l)=>{const C=M[j]?.scope;!C||C.choice||(Y(E=>[...E.map((S,D)=>D===j?{...S,scope:{...S.scope,choice:l}}:S),{role:"owner",text:l==="more"?"Find more companies.":`${ot(C.count)}.`},{role:"agent",text:ys(l,C)}]),s?.(l,C))},N=async()=>{const j=u.trim();if(!j)return;const l=R.length>0,C=[...p.answers,{question:l?R.map(E=>E.question).join(" "):js,answer:j}];await te({notes:p.notes,upload:null,answers:C,ownerMessage:j,action:"answer",asked:l?R.map(E=>E.key):"*",change:!l})&&P("")},ce=g?e.jsx("div",{className:"space-y-1.5",role:"status","aria-live":"polite","aria-label":"Reading your notes",children:k.length?k.map((j,l)=>e.jsxs("p",{className:"flex items-start gap-2 text-xs text-slate-600",children:[l===k.length-1?e.jsx(ve,{size:"sm",label:"",className:"mt-px shrink-0"}):e.jsx(It,{size:14,className:"mt-px shrink-0 text-emerald-600","aria-hidden":"true"}),e.jsx("span",{children:j.text})]},`${j.step}-${l}`)):e.jsxs("p",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx(ve,{size:"sm",label:"",className:"shrink-0"}),e.jsx("span",{children:g==="notes"&&x?`Uploading ${x.name} and reading itâ¦`:"Reading your notesâ¦"})]})}):null;return e.jsxs("div",{className:"space-y-4","aria-label":"Intake notes",children:[e.jsxs(Re,{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-slate-900",children:"Start from your intake notes"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Paste the notes from your intake call or upload them, and the agent fills in the launch card and asks for anything required that is missing."})]}),e.jsx(ye,{label:"Intake notes",rows:5,value:c,disabled:m||!!g,placeholder:"The role and who it reports to, the hiring company, the companies or kind of companies to map, must-haves, preferences, locationâ¦",onChange:j=>y(j.target.value)}),e.jsx(Mt,{label:"Or upload a file",accept:ms,disabled:m||!!g,hint:"TXT, MD, PDF, DOCX, PPTX, VTT or SRT, up to 50 MB. Only the text is read; images are skipped, and long notes are cut to the parts about the search.",selectedLabel:x?x.name:"No file chosen",buttonLabel:"Choose file",onChange:ae},w),e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:e.jsx(T,{variant:"primary",iconLeft:e.jsx(Ut,{size:15}),loading:g==="notes",disabled:m||!!g||!c.trim()&&!x,onClick:X,children:p.notes?"Read these notes too":"Read my notes"})}),g==="notes"?ce:null,H?e.jsx(G,{tone:"danger",children:H}):null]}),M.map((j,l)=>j.role==="owner"?e.jsx("div",{className:"flex justify-end",children:e.jsx("p",{className:`max-w-[80%] whitespace-pre-wrap break-words rounded-lg bg-stone-100 px-3 py-2 ${Je.body} text-slate-900`,children:j.text})},l):e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"mt-1 flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-stone-100 text-slate-600",children:e.jsx(ut,{size:14,"aria-hidden":"true"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:`whitespace-pre-wrap break-words ${Je.body} text-slate-900`,children:j.text}),j.questions?.length?e.jsx("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-slate-800",children:j.questions.map(C=>e.jsx("li",{children:C.question},C.key))}):null,j.scope&&!j.scope.choice?e.jsxs("div",{className:"mt-2 space-y-1.5","data-company-scope":"",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(T,{size:"sm",variant:"subtle",disabled:m||!!g,onClick:()=>
3se(l,"listed"),children:ot(j.scope.count)}),e.jsx(T,{size:"sm",variant:"subtle",iconLeft:e.jsx(We,{size:14}),disabled:m||!!g,onClick:()=>se(l,"more"),children:"Find more companies"})]}),d>0?e.jsx("p",{className:"text-xs text-slate-500",children:`Mapping costs about ${d} credits a company.`}):null]}):null]})]},l)),M.length?e.jsxs(Re,{className:"space-y-3",children:[e.jsx(ye,{label:R.length?"Your answer":"Anything to change?",rows:3,value:u,disabled:m||!!g,placeholder:R.length?"Answer the questions above in your own words.":"For example: two people per company, add Adobe, and drop Nokia and Ericsson.",onChange:j=>P(j.target.value)}),e.jsx(T,{variant:"primary",loading:g==="answer",disabled:m||!!g||!u.trim(),onClick:N,children:R.length?"Send answer":"Send"}),g==="answer"?ce:null]}):null]})}function ft(){let t=null;try{t=ht()}catch{return!0}return t?.isFindemEmployee===!0}const vs=(t,r)=>Math.max(0,Math.round(((r||Date.now())-t)/1e3)),ks=t=>t<60?`${t} s`:`${Math.floor(t/60)} min ${t%60} s`;function ws({state:t,live:r}){return t==="done"?e.jsx(Dt,{size:16,className:"mt-0.5 shrink-0 text-emerald-600","aria-label":"Done"}):t==="failed"?e.jsx(Pt,{size:16,className:"mt-0.5 shrink-0 text-rose-600","aria-label":"Did not finish"}):r?e.jsx(mt,{size:16,className:"mt-0.5 shrink-0 animate-spin text-sky-600","aria-label":"In progress"}):e.jsx(ns,{size:16,className:"mt-0.5 shrink-0 text-slate-400","aria-hidden":"true"})}function Ns({search:t}){const r=ft(),i=t?.status==="running",[,n]=a.useState(0);if(a.useEffect(()=>{if(!i)return;const m=setInterval(()=>n(b=>b+1),1e3);return()=>clearInterval(m)},[i]),!t)return null;const s=t.started_at?ks(vs(t.started_at,t.finished_at)):"",d=Array.isArray(t.steps)?t.steps:[];return e.jsxs("div",{className:"space-y-4 p-4","data-finder-progress":"",children:[e.jsxs("p",{className:"text-sm text-slate-600","aria-live":"polite",children:[i?`Reading the list you named, or searching companies kind by kind and checking each against your description${s?` (${s} so far)`:""}. This can take a few minutes.`:null,t.status==="done"?`Done in ${s}: ${Number(t.count||0).toLocaleString("en-US")} ${t.count===1?"company":"companies"} proposed. Tick the ones that belong on the launch card.`:null,t.status==="failed"?`The search stopped${s?` after ${s}`:""}.`:null]}),t.status==="failed"&&t.error?e.jsx(G,{tone:"danger",children:t.error}):null,d.length?e.jsx("ol",{className:"space-y-3","aria-label":"Search steps",children:d.map(m=>e.jsxs("li",{className:"flex items-start gap-2.5",children:[e.jsx(ws,{state:m.state,live:i}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-slate-900",children:m.label}),e.jsx("p",{className:"text-xs text-slate-600",children:m.text})]})]},m.key))}):i?e.jsxs("p",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx(mt,{size:14,className:"animate-spin","aria-hidden":"true"})," Starting the searchâ¦"]}):null,t.status==="done"&&t.credits&&r?e.jsx("p",{className:"text-xs text-slate-500",children:`This search used ${Number(t.credits).toLocaleString("en-US")} ${t.credits===1?"credit":"credits"}.`}):null]})}const Ss=["Documents","Presentations","Data export"],$s=(t,r)=>[...t].sort().join("|")===[...r].sort().join("|");function _s({definitionId:t,value:r,touched:i=!1,onChange:n,disabled:s=!1}){const[d,m]=a.useState(null),[b,v]=a.useState(""),[U,c]=a.useState(""),[y,x]=a.useState(""),[_,w]=a.useState(""),[O,p]=a.useState(!0),h=(g,{keepPick:f=!1}={})=>{m(g),p(g?.org?g.org.allow_member_override!==!1:!0),f||n(g?.effective?.renderers||[],!1)};if(a.useEffect(()=>{let g=!0;return de.getOutputSettings(t).then(f=>{g&&h(f,{keepPick:i})}).catch(f=>{g&&v(f?.message||"Could not load the output settings.")}),()=>{g=!1}},[t]),b)return e.jsx(G,{tone:"danger",children:b});if(!d)return null;const M=r||[],Y=d.locked_by_org===!0,R=d.effective&&!$s(M,d.effective.renderers),z=(g,f)=>n(k=>{const F=k||[];return f?[...new Set([...F,g])]:F.filter(H=>H!==g)},!0),u=async g=>{x(g),w(""),c("");try{const f=await de.saveOutputSettings(t,{scope:g,renderers:M,allowMemberOverride:O});h(f),w(g==="org"?`Saved for ${d.org_name||"your organization"}.`:"Saved as your default for this agent.")}catch(f){c(f?.message||"Could not save the output settings.")}finally{x("")}},P=async g=>{x(g),w("");try{h(await de.resetOutputSettings(t,g)),w(g==="org"?"Your organization now uses the agent's defaults.":"Your default is cleared.")}catch(f){c(f?.message||"Could not reset the output settings.")}finally{x("")}};return e.jsxs(Re,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-slate-900",children:"Deliverables"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[R?"Your choice for this run.":`From ${qt[d.effective?.source]||"the agent's defaults"}.`,Y?` ${d.org_name||"Your organization"} set these for everyone.`:""]})]}),e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:Ss.map(g=>{const f=(d.deliverables||[]).filter(k=>k.group===g);return f.length?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-slate-500",children:g}),f.map(k=>e.jsxs("div",{children:[e.jsx(Ye,{label:k.label,checked:M.includes(k.id),disabled:s||Y&&!d.can_set_org,onChange:F=>z(k.id,F)}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:k.description})]},k.id))]},g):null})}),_?e.jsx(G,{tone:"success",children:_}):null,U?e.jsx(G,{tone:"danger",children:U}):null,Y?null:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(T,{size:"sm",disabled:s||!!y,onClick:()=>u("user"),children:y==="user"?"Savingâ¦":"Save as my default"}),d.personal?e.jsx(T,{size:"sm",variant:"ghost",disabled:s||!!y,onClick:()=>P("user"),children:"Clear my default"}):null]}),d.can_set_org?e.jsxs("div",{className:"flex flex-wrap items-center gap-3 border-t border-slate-100 pt-3",children:[e.jsx(qe,{tone:"neutral",children:d.org_name||"Your organization"}),e.jsx(Ye,{label:"Members may change it",checked:O,disabled:s||!!y,onChange:p}),e.jsx(T,{size:"sm",disabled:s||!!y,onClick:()=>u("org"),children:y==="org"?"Savingâ¦":"Save for my organization"}),d.org?e.jsx(T,{size:"sm",variant:"ghost",disabled:s||!!y,onClick:()=>P("org"),children:"Use the agent's defaults"}):null]}):null]})}const ct=t=>t.split(/[,\n]/).map(r=>
3r.trim()).filter(Boolean),Cs=t=>{try{return new URL(t).hostname.replace(/^www\./,"")}catch{return""}};function dt(t){const r=t.ranks?`ranks 1 to ${t.ranks}`:t.kept===t.read?`all ${t.read} members`:`${t.kept} of its ${t.read} members`,i=t.filter?`${t.ranks?r:`its ${t.read} members`} checked, ${t.kept} ${t.filter}`:r,n=Cs(t.source_url),s=t.method==="web_search"||!n?"read from web sources":`read from ${n}`;return`From the ${t.label}: ${i}, ${s}.`}function As(t,r){const i=(r||[]).map(n=>({...n,companies:[]}));for(const n of t){let s=i.find(d=>d.label===n.archetype);s||(s={label:n.archetype||"Companies",thesis:"",quota:0,companies:[]},i.push(s)),s.companies.push(n)}return i.filter(n=>n.companies.length)}function Es({definitionId:t,companiesText:r,onCompaniesText:i,disabled:n=!1,prefill:s=null,onSearchState:d,onShowProgress:m,onShowList:b,mcpScopeId:v=""}){const U=ft(),[c,y]=a.useState(!1),[x,_]=a.useState(""),[w,O]=a.useState(""),[p,h]=a.useState(!1),[M,Y]=a.useState(""),[R,z]=a.useState(null),[u,P]=a.useState(null),[g,f]=a.useState(()=>new Set),[k,F]=a.useState(null),H=a.useRef(null),K=()=>{H.current?.abort(),H.current=null},J=l=>{try{d?.(l)}catch{}};a.useEffect(()=>K,[]),a.useEffect(()=>{s?.description&&(y(!0),_(s.description),O((s.exclude||[]).join(", ")),s.search&&oe(s.description,(s.exclude||[]).join(", ")))},[s]);const oe=async(l=x,C=w)=>{if(!l.trim()||p)return;K();const E=new AbortController;H.current=E,h(!0),Y(""),F(null);const S=Date.now();let D=[];J({status:"running",steps:D,started_at:S});try{const L=await de.proposeCompanies(t,{description:l.trim(),exclude:ct(C)},{signal:E.signal,mcpScopeId:v,onProgress:I=>{E.signal.aborted||(D=I,J({status:"running",steps:D,started_at:S}))}});if(E.signal.aborted)return;const Q=Array.isArray(L.companies)?L.companies:[],ie=L.judged!==!1,V=new Set((L.archetypes||[]).filter(I=>I.judged===!1).map(I=>I.label));z(Q),P({groups:As(Q,L.archetypes),fallbackKinds:new Set((L.archetypes||[]).filter(I=>I.fallback).map(I=>I.label)),leftOut:Array.isArray(L.left_out)?L.left_out:[],warnings:Array.isArray(L.warnings)?L.warnings:[],lists:Array.isArray(L.lists)?L.lists:[],sourceNote:typeof L.source_note=="string"?L.source_note:"",judged:ie,credits:Number(L.credits)||0}),f(new Set(Q.filter(I=>!ie||V.has(I.archetype)||I.verdict==="yes").map(Ee))),J({status:"done",steps:Array.isArray(L.progress)?L.progress:D,started_at:S,finished_at:Date.now(),count:Q.length,credits:Number(L.credits)||0})}catch(L){E.signal.aborted||(Y(L.message||"Unable to find companies."),J({status:"failed",steps:D,started_at:S,finished_at:Date.now(),error:L.message||"Unable to find companies."}))}finally{H.current===E&&(H.current=null,h(!1))}},te=(l,C)=>{F(null),f(E=>{const S=new Set(E);for(const D of l)C?S.add(D):S.delete(D);return S})},ae=(R||[]).filter(l=>g.has(Ee(l))).map(l=>u?.fallbackKinds?.has(l.archetype)?{...l,archetype:""}:l),X=xe(r).companies.length,se=ke(r,ae),N=xe(se).companies.length-X,ce=l=>{const C=l?ke(r,ae,{replace:!0}):se,E=xe(C).companies.length;i(C,{description:x.trim(),exclude:ct(w),replace:l,sourceNote:u?.sourceNote||""}),F({replace:l,added:l?E:E-X,total:E})},j=l=>`${l} ${l===1?"company":"companies"}`;return c?e.jsxs("section",{className:"w-full basis-full space-y-3 rounded-lg border border-stone-200 bg-stone-50 p-3","aria-label":"Find companies",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-900",children:"Find companies"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Describe the companies to map, or name a published list (the Fortune 500's top 50, the S&P 500, the Dow 30). A list is read from where it is published and grouped into kinds; a description is split into the kinds of company it covers, with the most relevant of each: up to 25 a kind, 100 in all. You keep the ones that belong."})]}),e.jsx(ye,{label:"Describe the companies",rows:2,value:x,disabled:n||p,placeholder:"Large-cap enterprise software, cloud and infrastructure companies comparable to Oracle",onChange:l=>_(l.target.value)}),e.jsx(Le,{label:"Leave out",hint:"Names or domains, separated by commas: the hiring company, for example.",value:w,disabled:n||p,onChange:l=>O(l.target.value)}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(T,{size:"sm",variant:"primary",iconLeft:e.jsx(We,{size:14}),loading:p,disabled:n||!x.trim(),onClick:()=>oe(),children:"Suggest companies"}),e.jsx(T,{size:"sm",variant:"ghost",onClick:()=>{K(),h(!1),y(!1),J({status:"idle"})},children:"Close"}),p?e.jsx("span",{className:"text-xs text-slate-500","aria-live":"polite",children:"Reading the list you named, or searching companies kind by kind; this can take a few minutes."}):null,(p||R)&&m?e.jsx(T,{size:"sm",variant:"ghost",onClick:m,children:p?"Watch it work":"How it searched"}):null,!p&&!R?e.jsx("span",{className:"text-xs text-slate-500",children:"A search uses a few credits for each kind of company it finds."}):null]}),M?e.jsx(G,{tone:"danger",children:M}):null,R?R.length?e.jsxs("div",{className:"space-y-2",children:[(u?.lists||[]).map(l
3=>e.jsx("p",{className:"text-xs text-slate-600",children:l.source_url?e.jsx("a",{className:"underline decoration-stone-300 underline-offset-2 hover:text-slate-900",href:l.source_url,target:"_blank",rel:"noreferrer",children:dt(l)}):dt(l)},l.label)),u?.leftOut?.length?e.jsx("p",{className:"text-xs text-slate-500",children:`Left out: ${u.leftOut.join(", ")}.`}):null,u?.credits&&U?e.jsx("p",{className:"text-xs text-slate-500",children:`This search used ${u.credits.toLocaleString("en-US")} ${u.credits===1?"credit":"credits"}.`}):null,u&&!u.judged?e.jsx("p",{className:"text-xs text-amber-700",children:"These have not been checked against your description; review them before adding."}):null,(u?.warnings||[]).map(l=>e.jsx("p",{className:"text-xs text-amber-700",children:l},l)),e.jsx("div",{className:"max-h-[28rem] space-y-3 overflow-y-auto","aria-label":"Proposed companies",children:(u?.groups||[]).map(l=>{const C=l.companies.map(Ee),E=C.filter(S=>g.has(S)).length;return e.jsxs("div",{role:"group","aria-label":l.label,className:"rounded-md border border-stone-200 bg-white",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2 border-b border-stone-200 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-900",children:`${l.label} · ${E} of ${l.companies.length} chosen`}),l.thesis&&l.thesis!==l.label?e.jsx("p",{className:"text-xs text-slate-500",children:l.thesis}):null,u?.judged&&l.judged===!1?e.jsx("p",{className:"text-xs text-amber-700",children:"Not checked against your description; review these before adding them."}):null]}),e.jsxs("div",{className:"flex shrink-0 gap-1",children:[e.jsx(T,{size:"sm",variant:"ghost",disabled:n||E===C.length,onClick:()=>te(C,!0),children:"Select all"}),e.jsx(T,{size:"sm",variant:"ghost",disabled:n||!E,onClick:()=>te(C,!1),children:"Clear"})]})]}),e.jsx("ul",{className:"divide-y divide-stone-200",children:l.companies.map(S=>{const D=Ee(S);return e.jsx("li",{className:"px-3 py-2",children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5",children:[e.jsx(Yt,{className:"mt-1",checked:g.has(D),disabled:n,onChange:L=>te([D],L.target.checked)}),e.jsxs("span",{className:"min-w-0 text-sm",children:[S.rank?e.jsx("span",{className:"tabular-nums text-slate-500",children:`#${S.rank} `}):null,e.jsx("span",{className:"font-medium text-slate-900",children:S.name}),S.also_known_as?.length?e.jsx("span",{className:"text-slate-600",children:` (also ${S.also_known_as.join(", ")})`}):null,S.domain?e.jsx("span",{className:"text-slate-500",children:` · ${S.domain}`}):null,S.size?e.jsx("span",{className:"text-slate-500",children:` · ${S.size}`}):null,u?.judged&&l.judged!==!1&&S.verdict!=="yes"?e.jsx("span",{className:"text-amber-700",children:" · possible fit"}):null,S.why?e.jsx("span",{className:"block text-xs text-slate-500",children:S.why}):null]})]})},D)})})]},l.label)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(T,{size:"sm",variant:"primary",disabled:n||!N,onClick:()=>ce(!1),children:N||!ae.length?`Add ${N} to the list`:`All ${ae.length} on the list`}),e.jsx(T,{size:"sm",variant:"subtle",disabled:n||!ae.length,onClick:()=>ce(!0),children:"Replace the list"}),k?e.jsxs("span",{role:"status",className:"text-xs text-emerald-700","data-finder-applied":"",children:[k.replace?`Replaced the list: ${j(k.total)}.`:`Added ${k.added} to the list: ${j(k.total)} in all.`,b?e.jsxs(e.Fragment,{children:[" ",e.jsx(T,{unstyled:!0,onClick:b,className:"font-medium underline decoration-emerald-300 underline-offset-2 hover:
3decoration-emerald-700",children:"Show the list"})]}):null]}):null,e.jsx("span",{className:"text-xs text-slate-500",children:"You confirm the list when you start the run."})]})]}):e.jsx("p",{className:"text-sm text-slate-600",children:"No companies matched that description. Try describing the industry, size or business model differently."}):null]}):e.jsx(T,{size:"sm",variant:"subtle",iconLeft:e.jsx(We,{size:14}),disabled:n,onClick:()=>y(!0),children:"Find companies for me"})}const gt=1e3,Ts=200,Ls=t=>{const r=String(t||"").trim();if(!r.includes("%"))return r;try{return decodeURIComponent(r)}catch{return r}};function Rs(t){return(Array.isArray(t?.company_lists)?t.company_lists:[]).flatMap(i=>{const n=String(i?.kind||"").trim(),s=String(i?.ref||i?.list_ref||"").trim();if(n!=="company_list"||!s||i?.origin==="system")return[];const d=String(i.studio_list_id||i.id||`${n}:${encodeURIComponent(s)}`).trim(),m=Number(i.count??i.row_count);return[{id:d,name:Ls(i.name||i.title||s)||"Untitled list",count:Number.isFinite(m)&&m>=0?Math.round(m):null}]})}async function zs(t,{max:r=gt}={}){const i=[];let n=0;for(;;){const s=await t(n,Ts),d=Array.isArray(s?.members)?s.members:[];for(const b of d){const v=String(b?.name||"").trim();v&&i.length<r&&i.push({name:v,domain:String(b?.domain||"").trim()})}if(n+=d.length,!(s?.page?.has_more===!0&&d.length>0))return{companies:i,truncated:!1};if(i.length>=r)return{companies:i,truncated:!0}}}const Os=300,Pe=8;function Bs({companiesText:t,onCompaniesText:r,disabled:i=!1}){const[n,s]=a.useState(!1),[d,m]=a.useState(""),[b,v]=a.useState(null),[U,c]=a.useState(""),[y,x]=a.useState(null),[_,w]=a.useState(!1),[O,p]=a.useState(""),h=a.useRef(0);a.useEffect(()=>{if(!n)return;const f=h.current+1;h.current=f;const k=setTimeout(()=>{nt.listOwnerCompanyLists(d.trim()?{q:d.trim()}:{}).then(F=>{h.current===f&&(v(Rs(F)),c(""))}).catch(F=>{h.current===f&&(v([]),c(F.message||"Unable to load your company lists."))})},b===null?0:Os);return()=>clearTimeout(k)},[n,d]);const M=async f=>{const k=h.current+1;h.current=k,x({list:f,companies:null,truncated:!1}),w(!0),p("");try{const{companies:F,truncated:H}=await zs((K,J)=>nt.listMembers(f.id,{start:K,count:J}));h.current===k&&x({list:f,companies:F,truncated:H})}catch(F){h.current===k&&p(F.message||"Unable to read that list.")}finally{h.current===k&&w(!1)}},Y=()=>{h.current+=1,s(!1),x(null),w(!1)},R=f=>{r(ke(t,y.companies,{replace:f}),{listName:y.list.name,replace:f}),Y()};if(!n)return e.jsx(T,{size:"sm",variant:"subtle",iconLeft:e.jsx(Jt,{size:14}),disabled:i,onClick:()=>s(!0),children:"Use a saved company list"});const z=y?.companies||[],u=z.slice(0,Pe).map(f=>f.name).join(", "),P=be(t).length,g=z.length?be(ke(t,z)).length:P;return e.jsxs("section",{className:"w-full basis-full space-y-3 rounded-lg border border-stone-200 bg-stone-50 p-3","aria-label":"Use a saved company list",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-900",children:"Use a saved company list"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Its companies join the list above; you confirm them when you start the run."})]}),y?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-slate-900",children:y.list.name}),_?e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(ve,{size:"sm",label:""})," Reading the listâ¦"]}):null,O?e.jsx(G,{tone:"danger",children:O}):null,!_&&!O?z.length?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-slate-600",children:`${z.length} ${z.length===1?"company":"companies"}: ${u}${z.length>Pe?` and ${z.length-Pe} more`:""}.`}),P?e.jsx("p",{className:"text-sm text-slate-600",children:`The card already has ${P} companies. Add keeps them (${g} companies in total); Replace removes them before applying this saved list.`}):null,y.truncated?e.jsx(G,{tone:"warning",children:`This list has more companies than a run can take; only the first ${gt} are used.`}):null]}):e.jsx("p",{className:"text-sm text-slate-600",children:"This list has no companies yet."}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(T,{size:"sm",variant:"primary",disabled:i||_||!z.length,onClick:()=>R(!1),children:`Add ${z.length} to the list`}),e.jsx(T,{size:"sm",variant:"subtle",disabled:i||_||!z.length,onClick:()=>R(!0),children:"Replace the list"}),e.jsx(T,{size:"sm",variant:"ghost",onClick:()=>{h.current+=1,x(null),w(!1),p("")},children:"Choose another list"})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(Wt,{"aria-label":"Find a list",placeholder:"Find a list by name",value:d,disabled:i,onChange:f=>m(f.target.value)}),U?e.jsx(G,{tone:"danger",children:U}):null,b===null?e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(ve,{size:"sm",label:""})," Loading your listsâ¦"]}):null,b&&!b.length&&!U?e.jsx("p",{className:"text-sm text-slate-600",children:d.trim()?"No lists match that name.":"You have no saved company lists yet."}):null,b?.length?e.jsx("ul",{className:"max-h-64 divide-y divide-stone-200 overflow-y-auto rounded-md border border-stone-200 bg-white","aria-label":"Your company lists",children:b.map(f=>e.jsx("li",{children:e.jsxs(T,{unstyled:!0,disabled:i,onClick:()=>M(f),className:"flex w-full items-center justify-between gap-3 px-3 py-2 text-left text-sm hover:bg-stone-50",children:[e.jsx("span",{className:"min-w-0 truncate font-medium text-slate-900",children:f.name}),f.count!==null?e.jsx("span",{className:"shrink-0 text-xs text-slate-500",children:`${f.count} ${f.count===1?"company":"companies"}`}):null]})},f.id))}):null]}),e.jsx("div",{children:e.jsx(T,{size:"sm",variant:"ghost",onClick:Y,children:"Close"})})]})}const Fs="mx-auto w-full max-w-4xl",Is=500,Ms=["Companies found from: ","Companies from the saved list "];function xt(t){const r=t?.mandate?.components||[],i=(t?.objectives||[]).map(s=>s.unit_source).find(Boolean),n=r.find(s=>
3s.key===i)?.type;return n==="companies"||n==="company_list"||!i?["company","companies"]:["item","items"]}function yt(t,[r,i]=["company","companies"]){if(!t||!t.units)return"";const n=Array.isArray(t.unit_labels)&&t.unit_labels.length===t.units?t.unit_labels:null,s=n?new Set(n.map(d=>String(d).trim().toLowerCase())).size:t.units;return`About ${t.credits?.about??0} credits for ${s} ${s===1?r:i}.`}const Us=new Set(["org_required","org_access_required","org_unavailable","workspace_changed","billing_unavailable","INSUFFICIENT_CREDIT_BALANCE","PAYMENT_REQUIRED"]);function jt(t){return t?.status===402||Us.has(String(t?.code||""))}function He({message:t,tone:r,lead:i}){const n=String(t||"").split(` 4`).map(s=>s.trim()).filter(Boolean);return n.length?e.jsx(G,{tone:r,children:n.length===1?`${i} ${n[0]}`:e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-medium",children:i}),e.jsx("ul",{className:"mt-1 list-disc pl-5",children:n.map(s=>e.jsx("li",{children:s},s))})]})}):null}function Ds(){const{definitionId:t}=Ht();return e.jsx(Ps,{definitionId:t},t)}function Ps({definitionId:t}){const r=Vt(),{canOpenAgentWorkflows:i,mcpScopeId:n}=ht(),s=Gt(),[d]=a.useState(()=>typeof s.state?.intake_notes=="string"?s.state.intake_notes.slice(0,6e4):""),[m]=a.useState(()=>!!d&&s.state?.read_intake_notes===!0);a.useEffect(()=>{s.state?.read_intake_notes===!0&&r(`${s.pathname}${s.search}`,{replace:!0,state:{...s.state,read_intake_notes:!1}})},[]);const[b]=a.useState(()=>String(new URLSearchParams(s.search).get("project_id")||s.state?.project_id||"").trim().slice(0,200)),[v,U]=a.useState(null),[c,y]=a.useState(""),[x,_]=a.useState({}),[w,O]=a.useState(""),[p,h]=a.useState([]),[M,Y]=a.useState(!1),[R,z]=a.useState(null),[u,P]=a.useState(""),[g,f]=a.useState(!1),[k,F]=a.useState(!1),[H,K]=a.useState(""),[J,oe]=a.useState(""),[te,ae]=a.useState(null);a.useEffect(()=>{const o=new AbortController;return de.getDefinition(t,{signal:o.signal}).then(A=>{o.signal.aborted||U(A.definition||A)}).catch(A=>{o.signal.aborted||y(A.message||"Unable to load the agent.")}),()=>o.abort()},[t]);const X=a.useMemo(()=>v?.mandate?.components||[],[v]),se=a.useMemo(()=>Qt(v),[v]),N=X.find(o=>o.type==="companies"&&o.key!==se)?.key||"",ce=a.useRef(new Set),j=(o,A)=>{O(B=>{const q=A?B.split(` 5`).filter(W=>!Ms.some(ne=>W.startsWith(ne))&&!ce.current.has(W)).join(` 6`):B;return q.includes(o)?q:[q.trim(),o].filter(Boolean).join(` 7`)}),ce.current.add(o)},l=({description:o,exclude:A,replace:B=!1,sourceNote:q=""})=>{const W=A.length?` (left out: ${A.join(", ")})`:"";q?j(`${q.replace(/\.$/,"")}${W}.`,B):o&&j(`Companies found from: ${o}${W}.`,B)},C=o=>_(A=>({...A,[N]:o})),[E,S]=a.useState(0),D=()=>{me(!1),S(o=>o+1)};a.useEffect(()=>{if(!E)return;const o=document.querySelector(`[data-mandate-field="${N}"] textarea`);o?.scrollIntoView({block:"center",behavior:"smooth"}),o?.focus({preventScroll:!0})},[E,N]);const[L,Q]=a.useState(null),ie="The mandate was read from the owner's intake notes.",V=a.useRef(x);a.useEffect(()=>{V.current=x},[x]);const I=a.useRef({}),he=a.useRef(""),Ve=a.useRef(!1),[bt,vt]=a.useState([]),kt=(o,{asked:A=[],current:B}={})=>{const q=A==="*",W=os(X,o?.values||{});for(const $ of X)Array.isArray(W[$.key])&&$.type!=="companies"&&(W[$.key]=W[$.key].join(` 8`));const ne={},ue=[],Ne=rt(X,V.current,{pastKey:se}),Be=$=>
8B!==void 0&&JSON.stringify(Ne[$])!==JSON.stringify(B[$]);for(const[$,le]of Object.entries(W)){const Z=V.current[$],Ie=Z==null||String(Z).trim()===""?I.current[$]!==void 0:JSON.stringify(Z)!==I.current[$];if(Be($)||Ie&&!q&&!A.includes($)){JSON.stringify(Z)!==JSON.stringify(le)&&ue.push($);continue}ne[$]=le,I.current[$]=JSON.stringify(le)}let Se=[],$e=[],_e=[],Ce=[],Xe=[];const Ze=o?.add_companies?.length||o?.remove_companies?.length;if(N&&Ze&&Be(N)&&!ue.includes(N)&&ue.push(N),N&&Ze&&!Be(N)){let $=ne[N]??V.current[N]??"";o.remove_companies?.length&&({text:$,removed:$e,missing:_e}=es($,o.remove_companies));const le=new Set((o.past_employers||[]).map(at));if(_e=_e.filter(Z=>!le.has(at(Z))),o.add_companies?.length){({text:$,marked:Ce}=ts($,o.add_companies));const Z=xe($),ge=new Set(Z.set_aside.flatMap(Te)),Ie=new Set([...Z.companies.flatMap(re=>Te(typeof re=="string"?{name:re}:re)),...ge]);Se=o.add_companies.filter(re=>!Te(re).some(Me=>Ie.has(Me))).map(re=>re.name),Xe=o.add_companies.filter(re=>Te(re).some(Me=>ge.has(Me))).map(re=>re.name),$=ke($,o.add_companies)}(Se.length||$e.length||Ce.length)&&(ne[N]=$,I.current[N]=JSON.stringify($))}Object.keys(ne).length&&_($=>({...$,...ne}));const Fe=N?be(ne[N]??V.current[N]??""):[],Lt=N in W&&N in ne,et=Fe.length&&!Ve.current&&(Lt||o?.companies_description)?gs(Fe,o):null;et&&(Ve.current=!0);const tt=!!(N&&o?.companies_description&&!Fe.length);tt&&Q({description:o.companies_description,exclude:o.leave_out||[]});const fe=o?.note_to_lead||"",Ae=he.current;fe&&(he.current=fe),O($=>{const le=fe&&Ae&&Ae!==fe&&$.includes(Ae)?$.replace(Ae,fe):$,Z=[ie,fe].filter(ge=>ge&&!le.includes(ge));return Z.length?[le.trim(),...Z].filter(Boolean).join(` 9`):le});const Rt=(Se.length||$e.length||Ce.length)&&!(N in W);return{applied:Object.keys(ne).filter($=>!(Rt&&$===N)),kept:ue,added:Se,removed:$e,missing:_e,marked:Ce,aside:Xe,scope:et,opened:tt}},wt=(o,A)=>{o==="more"&&Q({description:A.description,exclude:A.exclude,search:!0})},[we,Ge]=a.useState(null),[Nt,me]=a.useState(!1),St=a.useCallback(o=>{if(o?.status==="idle"){Ge(null),me(!1);return}Ge(o),o?.status==="running"&&!o.steps?.length&&me(!0)},[]),$t=Nt&&we?[{id:"finder",title:"Finding companies",subtitle:we.status==="running"?"Searchingâ¦":we.status==="done"?"Done":"Stopped",content:e.jsx(Ns,{search:we})}]:[],pe=a.useMemo(()=>rt(X,x,{pastKey:se}),[X,x,se]),Qe=a.useMemo(()=>be(te?.text||""),[te?.text]),je=!!(te&&JSON.stringify(pe[N]||[])!==JSON.stringify(Qe)),_t=()=>{const o=new Set(te.notes);O(A=>A.split(` 10`).filter(B=>!o.has(B)).join(` 11`).trim()),ae(null)},Ke=Object.values(x).some(o=>Array.isArray(o)?o.length:o===!0||typeof o!="boolean"&&String(o??"").trim());a.useEffect(()=>{if(!v||!Ke){z(null),P(""),f(!1);return}f(!0);const o=new AbortController,A=setTimeout(()=>{de.estimateRun(t,{mandateValues:pe},{signal:o.signal}).then(B=>{o.signal.aborted||(z(B),P(""),f(!1))}).catch(B=>{o.signal.aborted||(z(null),f(!1),P(String(B.message||"")))})},Is);return()=>{clearTimeout(A),o.abort()}},[v,t,pe,Ke]);const Ct=async o=>{if(o.preventDefault(),je||k)return;F(!0),K(""),oe("");const A=N&&!se?ss(xe(x[N]||"").past_only):"",B=A&&!w.includes(A)?[w.trim(),A].filter(Boolean).join(` 12`):w;try{const q=await de.createRun({definitionId:t,mandateValues:pe,requestText:B,...M?{outputRenderers:p}:{},...b?{projectId:b}:{},mcpScopeId:n,intakeMessages:bt.map(({role:W,text:ne,questions:ue})=>({role:W,text:ne,...ue?.length?{questions:ue.map(Ne=>Ne.question||String(Ne))}:{}}))});r(`/agent-workflows/runs/${q.run.run_id}`,{replace:!0})}catch(q){jt(q)?oe(q.message||"This run could not be charged. No work started."):K(q.message||"Unable to start the run."),F(!1)}},ze=new URLSearchParams(s.search).get("return_to")||"",Oe=rs(ze,i?"/agent-workflows":"/agents"),At=()=>s.key!=="default"&&!s.state?.redirected?r(-1):r(Oe),Et=xt(v),Tt=Math.round(Number(R?.credits?.per_unit)||0);return c&&!v?e.jsx("div",{className:"p-6",children:e.jsx(G,{tone:"danger",children:c})}):v?e.jsx(as,{entries:$t,onClose:()=>me(!1),onBack:()=>me(!1),children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col bg-white",children:[e.jsxs("div",{className:"relative z-40 flex min-w-0 shrink-0 items-center gap-2.5 border-b border-stone-200 bg-white px-4 py-2.5 sm:px-5",children:[e.jsx(T,{unstyled:!0,onClick:At,title:"Back","aria-label":"Back",className:"inline-flex shrink-0 items-center text-slate-600 transition hover:text-slate-900",children:e.jsx(Kt,{size:18})}),e.jsx("h1",{className:"min-w-0 flex-1 truncate text-base font-semibold text-slate-900",children:`Run ${v.name}`}),i?e.jsx(T,{as:Xt,to:`/agent-workflows/${encodeURIComponent(t)}?tab=definition${ze&&Oe===ze?`&return_to=${encodeURIComponent(Oe)}`:""}`,size:"sm",variant:"ghost",iconLeft:e.jsx(is,{size:14}),className:"whitespace-nowrap",children:"Configure agent"}):null]}),e.jsx("div",{className:"studio-scrollbar-thin min-h-0 flex-1 overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:`${Fs} space-y-5`,children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"mt-1 flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-stone-100 text-slate-600",children:e.jsx(ut,{size:14,"aria-hidden":"true"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-slate-500",children:v.name}),e.jsxs("p",{className:`whitespace-pre-wrap break-words ${Je.body} text-slate-900`,children:[v.description||"Tell me what to work on."," Paste or upload your intake notes and I will fill in the launch card, or fill it in yourself; what you confirm is the mandate the run is held to."]})]})]}),e.jsx(bs,{definitionId:t,currentValues:()=>pe,onApply:kt,onMessages:vt,onScopeChoice:wt,rate:Tt,disabled:k,initialNotes:d,readOnArrival:m,mcpScopeId:n}),e.jsx("form",{onSubmit:Ct,"aria-label":"Launch card",children:e.jsxs(Re,{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-slate-900",children:"Mandate"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Hard constraints are enforced by the server; checked fields are independently verified."})]}),H?e.jsx(He,{message:H,tone:"danger",lead:"Fix these and try again:"}):null,e.jsx(hs,{components:X,draft:x,onChange:_,disabled:k,pastKey:se}),je?e.jsxs(G,{tone:"warning","data-saved-company-scope-conflict":"",children:[e.jsx("p",{children:`The companies changed after you applied the saved lists: ${Qe.length} companies were confirmed; the card now has ${pe[N]?.length||0}. Restore that selection, or use the edited companies and remove the saved-list notes before starting.`}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[e.jsx(T,{size:"sm",variant:"subtle",disabled:k,onClick:()=>C(te.text),children:"Restore confirmed companies"}),e.jsx(T,{size:"sm",variant:"ghost",disabled:k,onClick:_t,children:"Use edited companies"})]})]}):null,N?e.jsxs("div",{className:"flex flex-wrap items-start gap-2",children:[e.jsx(Es,{definitionId:t,companiesText:
12x[N]||"",disabled:k||je,prefill:L,mcpScopeId:n,onSearchState:St,onShowProgress:()=>me(!0),onShowList:D,onCompaniesText:(o,A)=>{C(o),ae(B=>A?.replace?null:B?{...B,text:o}:null),A&&l(A)}}),e.jsx(Bs,{companiesText:x[N]||"",disabled:k||je,onCompaniesText:(o,{listName:A,replace:B})=>{C(o);const q=`Companies from the saved list "${A}".`;ae(W=>({text:o,notes:[...new Set([...B?[]:W?.notes||[],q])]})),j(q,B)}})]}):null,e.jsx(ye,{label:"Anything else the agent should know",hint:"Context only: it cannot change the mandate.",rows:3,value:w,disabled:k,onChange:o=>O(o.target.value)}),e.jsx(_s,{definitionId:t,value:p,touched:M,disabled:k,onChange:(o,A)=>{h(B=>typeof o=="function"?o(B):o),Y(A)}}),u&&!g?e.jsx(He,{message:u,tone:"warning",lead:"Before an estimate:"}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-3 border-t border-stone-100 pt-4",children:[e.jsx(T,{type:"submit",variant:"primary",iconLeft:e.jsx(Zt,{size:15}),disabled:je,loading:k,children:"Start run"}),e.jsx("p",{className:"text-sm text-slate-600","aria-live":"polite","data-launch-estimate":"",children:g?"Updating the estimateâ¦":R?yt(R,Et):"Credits are charged as the agent works, within its budget."})]}),b?e.jsx("p",{className:"text-sm text-slate-600","data-launch-project":"",children:"Its People List and files are saved to the Project you opened it from."}):null,J?e.jsx(G,{tone:"warning","data-launch-refused":"",children:J}):null]})})]})})]})}):e.jsxs("div",{role:"status",className:"flex items-center gap-2 p-6 text-sm text-slate-500",children:[e.jsx(ve,{size:"sm",label:""})," Loading the agentâ¦"]})}const Vs=Object.freeze(Object.defineProperty({__proto__:null,ProblemList:He,billingRefusal:jt,default:Ds,estimateSentence:yt,unitNoun:xt},Symbol.toStringTag,{value:"Module"}));export{Vs as A,Ns as F,hs as M,He as P,_s as R,jt as b,os as d,yt as e,rt as m,xt as u};
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.