1import{r,j as e,bE as K,B as f,bD as ie,F as oe,J as ce,O as le,u as ue,e as de,V as pe,jR as m,g6 as he,L as B,k1 as me,dg as fe,gz as X,A as ke}from"./index-C-_Qp0pL.js";import{r as ge,f as xe}from"./studioAppInvite-AaobvTet.js";import{A as je,a as ye}from"./AppActionReview-DqDlC0h5.js";import{A as we}from"./AppFrame-BCpNSTi-.js";import{W as ve}from"./WorkflowIntakeConversation-B5s-kvcr.js";/* empty css */import"./workflowLaunchHandoff-O3uYSikj.js";import"./oauthPopup-U7ZIp_nH.js";import"./connectorsCatalog-CHbtS30t.js";import"./RemoteMcpModal-BYfUPW3M.js";import"./link-2-DNOdglon.js";import"./remoteConnector-CbyIUuDD.js";import"./arrow-up-bj_rMNnY.js";const be="Tell me about the role youâre hiring for â in your own words, or paste the job description. Iâll help turn it into a clear brief before anything is sent.",F=4e3,J=2e3;function Se({intake:c,onTurn:l,onSubmit:R}){const P=r.useMemo(()=>(Array.isArray(c?.questions)?c.questions:[]).map(a=>({...a,question:a.label})),[c]),[u,N]=r.useState(""),[_,D]=r.useState(""),[T,E]=r.useState({}),[C,k]=r.useState(""),[n,I]=r.useState(!1),[h,x]=r.useState("opening"),[L,j]=r.useState(""),[w,v]=r.useState(!1),[g,y]=r.useState("");function q(a){a.preventDefault();const d=u.trim();if(d){if(d.length>F){y(`Please shorten the role description to ${F.toLocaleString()} characters.`);return}D(d),k(d),x("chat"),y("")}}async function b(a,d,p){return l({seed_text:a,transcript:d,values:p?.inputs||{}})}function o(a,d){E(p=>({...p,...a})),d&&k(d)}function S(a,d){E(p=>({...p,[a]:d}))}async function O(a){if(a.preventDefault(),!w){y(""),v(!0);try{await R({email:L,answers:T,context:C||_}),x("submitted")}catch(d){y(d?.message||"The intake could not be sent. Please try again.")}finally{v(!1)}}}return e.jsxs("section",{className:"studio-public-intake",children:[e.jsxs("div",{className:"studio-public-intake-heading",children:[e.jsx("p",{className:"studio-apps-eyebrow",children:"ROLE INTAKE AGENT"}),e.jsx("h2",{children:h==="review"?"Review the hiring brief":h==="submitted"?"Intake sent":"Letâs shape the role together"}),e.jsx("p",{children:h==="opening"?be:h==="chat"?"Share what you know. If youâre unsure, the agent will help you narrow it down.":h==="review"?"Correct anything the conversation misunderstood, then add your work email.":"Your answers are with the recruiting team."})]}),e.jsxs("div",{className:"studio-public-intake-body",children:[h==="opening"&&e.jsxs("form",{className:"studio-public-intake-composer",onSubmit:q,children:[e.jsx(K,{id:"public-intake-opening",label:"Role or job description",maxLength:F,value:u,onChange:a=>N(a.target.value.slice(0,F)),placeholder:"Describe the role, paste a job description, or say what youâre unsure aboutâ¦"}),e.jsx(f,{variant:"primary",type:"submit",disabled:!u.trim(),children:"Start intake"})]}),h==="chat"&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{inputs:[],questions:P,values:T,answers:{},initialPrompt:_,displayPrompt:_,requestTurn:b,onUpdate:o,onReadyChange:I,useSharedComposer:!1,disabled:w,maxReplyLength:2e3}),n&&e.jsx("div",{className:"studio-public-intake-continue",children:e.jsx(f,{variant:"primary",type:"button",onClick:()=>x("review"),children:"Review intake"})})]}),h==="review"&&e.jsxs("form",{className:"studio-public-intake-review",onSubmit:O,children:[P.map(a=>e.jsx(K,{label:`${a.label}${a.required?" *":""}`,maxLength:J,value:T[a.key]||"",onChange:d=>S(a.key,d.target.value.slice(0,J)),required:a.required},a.key)),e.jsx(ie,{label:"Work email *",type:"email",value:L,onChange:a=>j(a.target.value),required:!0,placeholder:"[email protected]"}),e.jsx("div",{className:"studio-apps-actions",children:e.jsx(f,{variant:"primary",type:"submit",disabled:w,children:w?"Sendingâ¦":"Send intake"})})]}),h==="submitted"&&e.jsxs("div",{className:"studio-public-intake-complete",role:"status",children:[e.jsx("strong",{children:"Thank you."}),e.jsx("p",{children:"The calibration workflow is preparing the brief for review."})]}),g&&e.jsx("p",{role:"alert",className:"studio-apps-error",children:g})]})]})}function Oe({invitation:c=!1}){const{appId:l}=oe(),[R]=ce(),P=le(),{user:u,loading:N,loginWithFindem:_,openGetStarted:D,logout:T}=ue(),E=de(),C=pe.useMemo(()=>c?ge():"",[c,E.key]),k=R.get("app")&&R.get("grant")?{app_id:R.get("app"),grant_id:R.get("grant")}:null,[n,I]=r.useState(null),[h,x]=r.useState(""),[L,j]=r.useState(!1),[w,v]=r.useState(null),g=r.useRef(null),[y,q]=r.useState(null),b=r.useRef(null),[o,S]=r.useState(null),[O,a]=r.useState(!1),[d,p]=r.useState(""),U=r.useRef(0);function Q(t){return u?b.current?Promise.reject(Error("Finish choosing the current list first.")):new Promise((s,i)=>{b.current={resolve:s,reject:i},q({kind:t})}):Promise.reject(Error("Sign in to Studio to choose a list."))}function Z(t,s){s?b.current?.reject(s):b.current?.resolve(t),b.current=null,q(null)}const z=async()=>
1{if(!u)return m.publicRuntime(l);try{return await m.runtime(l)}catch(t){if(![403,404].includes(t.status))throw t;try{return await m.publicRuntime(l)}catch{throw t}}};r.useEffect(()=>()=>{g.current?.reject(Error("The app changed or closed.")),g.current=null,v(null)},[l,u?.id,n?.version]);function ee(t){return u?g.current?Promise.reject(Error("Finish or cancel the current action review first.")):new Promise((s,i)=>{g.current={resolve:s,reject:i},v(t)}):Promise.reject(Error("Sign in to Studio to run connected actions."))}function te(t,s){s?g.current?.reject(s):g.current?.resolve(t),g.current=null,v(null)}async function M(t){const s=await m.intakeResult(l,t);return S(i=>i?.token&&i.token!==t?i:{token:t,result:s.result}),s}async function V(t){const s=await m.submitIntake(l,t);return s?.token&&(U.current=Date.now(),S({token:s.token,result:{state:"received"}}),p(""),M(s.token).catch(i=>p(i.message))),s}async function se(t){return m.intakeTurn(l,t)}r.useEffect(()=>{const t=o?.result?.state;if(!o?.token||["ready","revoked","expired","failed"].includes(t))return;let s=!1,i,A=0;const G=async()=>{if(Date.now()-U.current>=15*6e4){s||p("Updates paused after 15 minutes. Check your email, or reload this page to check again.");return}try{const $=await m.intakeResult(l,o.token);s||S(H=>H?.token===o.token?{token:o.token,result:$.result}:H)}catch($){s||p($.message)}s||(A+=1,i=window.setTimeout(G,document.hidden?3e4:Math.min(5e3*2**Math.min(A,3),3e4)))};return i=window.setTimeout(G,5e3),()=>{s=!0,window.clearTimeout(i)}},[l,o?.token,o?.result?.state]),r.useEffect(()=>{S(null),p(""),U.current=0},[l]);async function re(){a(!0),p("");try{const t=await m.createIntakeAccount(l,o.token);S(s=>({...s,result:{...s.result,account:t.account}}))}catch(t){p(t.message)}finally{a(!1)}}const[ne,W]=r.useState("");r.useEffect(()=>{let t=!1;if(I(null),x(""),j(!1),W(""),v(null),N)return;if(j(!0),c&&k&&!u){j(!1);return}return(c?k?m.previewInviteClaim(k):m.previewInvite(C):z()).then(i=>{t||(I(c?i:i.app),W(u?.id||""))}).catch(i=>{t||x(i.message)}).finally(()=>{t||j(!1)}),()=>{t=!0}},[l,C,c,u?.id,N,k?.app_id,k?.grant_id]),r.useEffect(()=>{if(c)return;let t=!0;const s=()=>z().then(i=>{t&&I(A=>A?.app_id===i.app.app_id&&A?.version===i.app.version&&A?.role===i.app.role?A:i.app)}).catch(i=>{t&&(I(null),x(i.message))});return window.addEventListener("focus",s),()=>{t=!1,window.removeEventListener("focus",s)}},[l,c,u?.id]);function Y(){const t=n?.claim_path?new URL(n.claim_path,window.location.origin).href:window.location.href;if(c){X(t),_();return}D({returnTo:t})}async function ae(){j(!0),x("");try{const t=k?await m.acceptInviteClaim(k):await m.acceptInvite(C);xe(),P(t.app_path,{replace:!0})}catch(t){x(t.message)}finally{j(!1)}}return e.jsxs("main",{className:"studio-app-visitor",children:[e.jsxs("header",{children:[e.jsx(he,{compact:!0}),e.jsxs("div",{className:"studio-apps-actions",children:[u&&e.jsx("span",{children:u.email}),e.jsx(f,{as:B,to:"/apps",size:"sm",children:"Open Studio"}),u?e.jsx(f,{size:"sm",onClick:T,children:"Sign out"}):e.jsx(f,{size:"sm",onClick:Y,children:"Sign in"})]})]}),!c&&ne===(u?.id||"")&&n?.app_id===l&&n?.source?e.jsxs("div",{className:"studio-app-live",children:[e.jsx("h1",{children:n.name}),n.intake?.conversational?e.jsx(Se,{intake:n.intake,onTurn:se,onSubmit:V}):e.jsx(we,{source:n.source,title:n.name,onAction:ee,onPick:Q,onSubmit:n.intake?V:void 0,onLookup:n.intake?M:void 0,actions:n.actions||[],journey:n.journey||null,outcome:n.outcome||null,intake:n.intake||null}),o&&e.jsxs("section",{className:"studio-app-intake-result","aria-live":"polite",children:[e.jsxs("div",{children:[e.jsx("strong",{children:o.result?.state==="ready"?"Your brief is ready":o.result?.state==="in_review"?"Your brief is being prepared":o.result?.state==="revoked"?"This result was revoked":o.result?.state==="expired"?"This result link expired":o.result?.state==="failed"?"This brief could not be prepared":"Your intake was received"}),e.jsx("span",{children:["ready","revoked","expired","failed"].includes(o.result?.state)?"This is the latest status for your intake.":"Keep this page open to see updates."})]}),e.jsxs("div",{className:"studio-apps-actions",children:[o.result?.brief_path&&e.jsx(f,{as:"a",href:me(o.result.brief_path),target:"_blank",rel:"noreferrer",variant:"primary",children:"View brief"}),["available","delivery_failed"].includes(o.result?.account?.state)&&e.jsx(f,{onClick:re,disabled:O,children:o.result?.account?.state==="delivery_failed"?"Retry account invite":"Create account"}),o.result?.account?.state==="invited"&&e.jsxs("span",{children:["Account invitation sent to ",o.result.email||"
1your email","."]}),o.result?.account?.state==="delivery_failed"&&e.jsx("span",{children:"The account invitation could not be sent."})]}),d&&e.jsx("p",{role:"alert",className:"studio-apps-error",children:d})]})]}):e.jsxs("section",{className:"studio-app-signin",children:[e.jsx(fe,{size:30}),e.jsx("p",{className:"studio-apps-eyebrow",children:c?"APP INVITATION":"STUDIO APP"}),e.jsx("h1",{children:c?"Youâve been invited to Studio":"Access this app"}),n?.app_name&&e.jsxs("p",{children:["Youâve been invited to access ",e.jsx("strong",{children:n.app_name}),"."]}),h&&(u||c)&&e.jsx("p",{role:"alert",className:"studio-apps-error",children:h}),N||L?e.jsx("p",{role:"status",children:"Loadingâ¦"}):u?c&&n?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[n.role==="edit"?"Can edit":"Can use"," · ",n.status==="pending"?`Invitation expires ${new Date(n.expires_at).toLocaleDateString()}`:"Invitation accepted"]}),e.jsx(f,{variant:"primary",onClick:ae,iconRight:e.jsx(ke,{size:15}),children:"Accept invitation"})]}):null:e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"Sign in with your invited email. Studio will return you to this app."}),e.jsx(f,{variant:"primary",onClick:Y,children:"Continue with Studio"}),c&&n?.signup_allowed?e.jsx(f,{as:B,to:"/app-register",children:"Create an account for this app"}):!c&&e.jsx(f,{as:B,to:"/register",onClick:()=>X(window.location.href),children:"Create a Studio account"})]}),e.jsx("p",{className:"studio-apps-note",children:"This invitation grants access to an app. Workspace membership and tool connections require separate permissions."})]}),w&&e.jsx(je,{appId:l,request:w,settle:te},`${l}:${u?.id}`),y&&e.jsx(ye,{orgId:n?.mcp_org_id,kind:y.kind,settle:Z},`${l}:${y.kind}`)]})}export{Oe as default};
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.