1import{c as I,w as y,aJ as v,x as N,a as C,r as o,j as e,B as f,T as w,v as R,X as k,t as d,Y as D,aO as E,O as M}from"./index-Ch17I6sP.js";import{S,a as O,b as A,d as z,c as T}from"./sheet-CtzYbh1p.js";import{u as _}from"./use-project-CEEP6rWR.js";import{S as j}from"./sparkles-CJai1sY7.js";import{M as P}from"./message-circle-D8Q_QAUR.js";const L=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]],B=I("clipboard-copy",L),F=y({method:"POST"}).middleware([v]).handler(N("6b13249a1d8e9d0613f348a6fa7c8a83f4fb4eba5bb9ab2488776cbbc48ff64e")),H=[{id:"project_brief",label:"Project brief",description:"One-page executive brief of this engagement."},{id:"executive_summary",label:"Executive summary",description:"Board-ready 5-bullet read of where things stand."},{id:"map_to_vorta",label:"Map to VORTA",description:"Map inputs across the five VORTA stages."},{id:"follow_ups",label:"Follow-ups",description:"3â5 concrete client follow-ups for this week."},{id:"review_before_publish",label:"Review before publish",description:"Critical review pass against open items."},{id:"missing_evidence",label:"Missing evidence",description:"Walk the Evidence Chain and flag gaps."},{id:"draft_risk",label:"Draft a risk",description:"Draft a single risk register entry."},{id:"draft_decision",label:"Draft a decision",description:"Draft a single decision record."},{id:"analyze_inputs",label:"Analyze inputs",description:"Open-ended analytical draft scoped to this project."}];function q(){const{project:r}=_(),h=C(F),[g,b]=o.useState(!1),[n,l]=o.useState(null),[c,u]=o.useState(""),[t,m]=o.useState(null);async function p(s){if(!r){d.error("Select a project first.");return}l(s),m(null);try{const a=await h({data:{projectId:r.id,action:s,instruction:c.trim()||void 0}});m(a),a.ok||d.error(a.message)}catch(a){const i=a instanceof Error?a.message:"Copilot failed";d.error(i),m({ok:!1,status:"error",message:i})}finally{l(null)}}async function x(){if(t?.ok)try{await navigator.clipboard.writeText(t.draft),d.success("Draft copied. Paste it into the right tab.")}catch{d.error("Copy failed â select the text manually.")}}return e.jsxs(S,{open:g,onOpenChange:b,children:[e.jsx(O,{asChild:!0,children:e.jsxs(f,{size:"sm",className:"fixed bottom-6 end-6 z-50 gap-2 rounded-full shadow-lg bg-primary text-primary-foreground hover:bg-[var(--primary-hover)]","aria-label":"Open Consultant Copilot",children:[e.jsx(j,{className:"size-4"}),"Copilot"]})}),e.jsxs(A,{side:"right",className:"w-full sm:max-w-xl flex flex-col gap-4",children:[e.jsxs(z,{children:[e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(j,{className:"size-4 text-primary"}),"Consultant Copilot"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Scoped to ",e.jsx("span",{className:"font-medium",children:r?.name??"(no project)"}),". Every output is a draft for your review â never published automatically."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",htmlFor:"copilot-instruction",children:"Optional instruction (focuses the action on a sub-topic)"}),e.jsx(w,{id:"copilot-instruction",value:c,onChange:s=>u(s.target.value),rows:3,maxLength:2e3,placeholder:"e.g. focus on adoption blockers in the operations team"})]}),e.jsx("div",{className:"grid grid-cols-1 gap-2 overflow-y-auto pe-1",style:{maxHeight:"30vh"},children:H.map(s=>e.jsxs("button",{type:"button",disabled:!r||n!==null,onClick:()=>p(s.id),className:"text-left rounded-lg border border-[var(--color-border)] bg-card p-3 transition hover:border-primary disabled:opacity-50",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:s.label}),n===s.id&&e.jsx(R,{className:"size-3 animate-spin text-primary"})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s.description})]},s.id))}),e.jsxs("div",{className:"flex-1 overflow-y-auto rounded-lg border border-[var(--color-border)] bg-muted/30 p-3 text-sm",children:[!t&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose an action above. Context (deliverables, risks, decisions, use cases, file metadata, recent messages) is loaded server-side under RLS."}),t?.ok&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[t.model," · in ",t.tokensIn," / out ",t.tokensOut," tokens"]}),e.jsxs(f,{size:"sm",variant:"outline",onClick:x,className:"gap-1",children:[e.jsx(B,{className:"size-3"})," Copy draft"]})]}),t.guardrailNote&&e.jsxs("p",{className:"rounded border border-amber-500/40 bg-amber-500/10 p-2 text-xs",children:["Guardrail note: ",t.guardrailNote]}),e.jsx("pre",{className:"whitespace-pre-wrap font-sans text-sm leading-6",children:t.draft})]}),t&&!t.ok&&e.jsxs("div",{className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(k,{className:"size-4 mt-0.5"}),e.jsx("span",{children:t.message})]})]})]})]})}const G=y({method:"POST"}).middleware([v]).handler(N("f669af6b2ebb4e4c98dda5998971d36b329150d7796c443416913d01cec2af2c"));function V(){const{project:r}=_(),h=C(G),[g,b]=o.useState(!1),[n,l]=o.useState([]),[c,u]=o.useState(""),[t,m]=o.useState(!1),p=o.useRef(null);if(o.useEffect(()=>{p.current?.scrollTo({top:p.current.scrollHeight,behavior:"smooth"})},[n,t]),!r)return null;async function x(){const s=c.trim();if(!s||t||!r)return;const a=[...n,{role:"user",content:s}];l(a),u(""),m(!0);try{const i=await h({data:{projectId:r.id,messages:a}});i.ok?l([...a,{role:"assistant",content:i.reply}]):(d.error(i.message),l(a.slice(0,-1)),u(s))}catch(i){d.error(i instanceof Error?i.message:"Request failed"),l(a.slice(0,-1)),u(s)}finally{m(!1)}}return e.jsxs(S,{open:g,onOpenChange:b,children:[e.jsx(O,{asChild:!0,children:e.jsxs(f,{size:"sm",className:"fixed bottom-6 end-6 z-50 gap-2 rounded-full shadow-lg bg-primary text-primary-foreground hover:bg-[var(--primary-hover)]","aria-label":"Open project AI assistant","data-tour-id":"client-assistant",children:[e.jsx(j,{className:"size-4"}),"Ask AI"]})}),e.jsxs(A,{side:"right",className:"w-full sm:max-w-lg flex flex-col gap-3",children:[e.jsxs(z,{children:[e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(P,{className:"size-4 text-primary"})," Project AI assistant"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Grounded in ",e.jsx("span",{className:"font-medium",children:r.name}),". Drafts only â your Cognessa advisor remains the source of truth."]})]}),e.jsxs("div",{ref:p,"aria-live":"polite",className:"flex-1 overflow-y-auto rounded-lg border border-border bg-card/40 p-3 space-y-3",children:[n.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center px-4 py-8",children:"Ask about your deliverables, risks, decisions, or next VORTA stage."}),n.map((s,a)=>e.jsx("div",{className:s.role==="user"?"ms-auto max-w-[85%] rounded-xl rounded-se-sm bg-primary px-3 py-2 text-sm text-primary-foreground":"me-auto max-w-[90%] rounded-xl rounded-ss-sm border border-border bg-background px-3 py-2 text-sm whitespace-pre-wrap",children:s.content},a)),t&&e.jsx("div",{className:"me-auto rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Thinkingâ¦"})]}),e.jsxs("form",{className:"flex items-end gap-2",onSubmit:s=>{s.preventDefault(),x()},children:[e.jsx(w,{value:c,onChange:s=>u(s.target.value),placeholder:"Ask about this projectâ¦",rows:2,className:"min-h-[56px] resize-none text-sm",disabled:t,onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),x())}}),e.jsx(f,{type:"submit",disabled:t||!c.trim(),size:"sm",children:e.jsx(D,{className:"size-4"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"AI-generated draft â not a certification or legal opinion."}),n.length>0&&e.jsxs("button",{type:"button",onClick:()=>l([]),className:"inline-flex items-center gap-1 self-start text-[11px] text-muted-foreground hover:text-foreground",children:[e.jsx(k,{className:"size-3"})," Clear conversation"]})]})]})}function Q(){const{isStaff:r}=E();return e.jsxs(e.Fragment,{children:[e.jsx(M,{}),r?e.jsx(q,{}):e.jsx(V,{})]})}
1export{Q as component};
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.