PageSourceSearch

https://fleck.ai/assets/MentorChat-BrrZRwqF.js

js fleck.ai collected 2026-10-05 14:01:27 UTC 17,699 bytes, 13 lines download raw bytes

1import{j as e}from"./vendor-query-CsHYnmF8.js";import{u as qe,r as a}from"./vendor-i18n-FzC2q7WE.js";import{A as He,a as Ke,b as Ve,c as Je,d as Qe,e as We,f as Ge,g as Xe}from"./alert-dialog-iacEWNOj.js";import{u as Ye,p as Ze,s as we,b as h,c as P,H as et,S as tt,X as rt,B as st,a0 as ot}from"./index-wKN3roZE.js";import{V as at}from"./VoiceDictateButton-0K4x8guw.js";import{T as nt,a as E,b as T,c as U}from"./tooltip-BNmJph-e.js";import{u as it,a as Ce,b as ke,d as lt}from"./InlineWhiteboard-D3Ckj3AQ.js";import{u as ct}from"./usePlanLimits-BFLkYYnf.js";import{u as mt,a as dt,n as re,t as ut,D as ft,Q as pt}from"./useMentorSkills-C08zVMtX.js";import{ProfileSetup as ht}from"./ProfileSetup-BmHIguHv.js";import{SkillRadar as xt}from"./SkillRadar-DzQ9zHdT.js";import{C as gt}from"./ChatMessages-DAJHVtYF.js";import{C as bt}from"./ChatArchive-1lZSBYRF.js";import{a as yt}from"./vendor-react-CmGg2B8n.js";import{G as jt}from"./graduation-cap-BzLtrikM.js";import{P as Se}from"./plus-Cqcmlt9Z.js";import{U as vt}from"./user-BitbI_GZ.js";import{C as wt}from"./chart-column-CHeGB_SG.js";import{M as Ne}from"./minimize-2-YOvaQ6JW.js";import{S as Ct}from"./send-B2lUsY1u.js";import"./vendor-ui-CakNjGXO.js";import"./vendor-supabase-DinKeC8L.js";import"./dropdown-menu-D8bgHbCS.js";import"./chevron-right-BRtSuzIm.js";import"./circle-CvUEJAxR.js";import"./file-search-DlyxlxNC.js";import"./layout-template-Cb3epujz.js";import"./ellipsis-D4saEoy8.js";import"./message-circle-DaXmqJUO.js";import"./popover-CYyDXlvw.js";import"./sheet-B6yB-pRG.js";import"./drawer-Dv3v9DcT.js";import"./use-mobile-D_eewZzL.js";import"./folder-open-B_1uu7S_.js";import"./undo-2-2cfrEQzj.js";import"./trash-2-QZEPj_-r.js";import"./pen-tool-pa1Gdsve.js";import"./chevron-left-hJ6aQjUt.js";import"./upload-D_cr-vv_.js";import"./figma-DQMc_gJK.js";import"./input-DRTLzLS0.js";import"./pdfToImage-B1JbVVZ6.js";import"./swatch-book-DjLcU8xB.js";import"./mic-DwnFAlDR.js";import"./authUtils-Cgc2MjYr.js";import"./timer-BvWpSjLF.js";import"./pause-B3SjSIkJ.js";import"./play-CHDBNpwD.js";import"./refresh-cw-CyU-OmHw.js";import"./brain-Ca8M_YSR.js";import"./index-Y6GVEUH8.js";function vr(){const{t:n}=qe(),{user:i}=Ye(),_e=yt(),{plan:De,checkFeature:Y,incrementUsage:se}=ct(),{showUpgrade:Ae}
1=Ze(),{profile:F,profileLoaded:oe,saveProfile:Ie}=mt(i==null?void 0:i.id),{skills:ae,updateSkills:ne,streak:Me}=dt(i==null?void 0:i.id),{stream:ie,abort:Re}=it(),[f,x]=a.useState([]),[C,Z]=a.useState(""),[y,le]=a.useState(!1),[N,O]=a.useState([]),[ce,me]=a.useState([]),[g,$]=a.useState(null),[_,ee]=a.useState(null),[L,z]=a.useState(!1),[B,k]=a.useState(!1),[te,q]=a.useState(!1),[D,de]=a.useState(!1),[ue,fe]=a.useState(0),[pe,he]=a.useState(!1),A=a.useRef(null),xe=a.useRef(null),I=a.useRef(null),H=a.useRef(null),[K,V]=a.useState(null);a.useEffect(()=>{var t;(t=xe.current)==null||t.scrollIntoView({behavior:"smooth"})},[f]),a.useEffect(()=>{I.current&&(I.current.style.height="auto",I.current.style.height=Math.min(I.current.scrollHeight,120)+"px")},[C]),a.useEffect(()=>(pe?A.current=setInterval(()=>fe(t=>t+1),1e3):A.current&&clearInterval(A.current),()=>{A.current&&clearInterval(A.current)}),[pe]);const M=a.useCallback(async()=>{if(i)try{const{data:t,error:o}=await we.from("mentor_chats").select("*").eq("user_id",i.id).order("updated_at",{ascending:!1});if(o)throw o;t&&me(t.map(r=>({id:typeof(r==null?void 0:r.id)=="string"?r.id:crypto.randomUUID(),title:typeof(r==null?void 0:r.title)=="string"&&r.title.trim()?r.title:"Untitled Chat",messages:(Array.isArray(r==null?void 0:r.messages)?r.messages:[]).map((m,c)=>re(m,c)),created_at:typeof(r==null?void 0:r.created_at)=="string"?r.created_at:new Date().toISOString(),updated_at:typeof(r==null?void 0:r.updated_at)=="string"?r.updated_at:new Date().toISOString(),summary:r!=null&&r.summary&&typeof r.summary=="object"?r.summary:null})))}catch{me([])}},[i]);a.useEffect(()=>{M()},[M]);const Pe=a.useCallback(t=>{const o=t.target.files;if(o){for(const r of Array.from(o)){if(!r.type.startsWith("image/")){h.error("Only image files allowed");continue}if(r.size>5*1024*1024){h.error("Image must be under 5MB");continue}const m=new FileReader;m.onload=c=>O(u=>{var d;return[...u,(d=c.target)==null?void 0:d.result]}),m.readAsDataURL(r)}H.current&&(H.current.value="")}},[]),Ee=a.useCallback(t=>{var r;const o=(r=t.clipboardData)==null?void 0:r.items;if(o){for(const m of Array.from(o))if(m.type.startsWith("image/")){t.preventDefault();const c=m.getAsFile();if(c&&c.size<=5*1024*1024){const u=new FileReader;u.onload=d=>O(l=>{var p;return[...l,(p=d.target)==null?void 0:p.result]}),u.readAsDataURL(c)}}}},[]),ge=a.useRef(f);ge.current=f;const w=a.useCallback(async(t,o=[])=>{var d;if(!t.trim()&&o.length===0)return;if(!i){const l=encodeURIComponent(window.location.pathname+window.location.search+window.location.hash);window.location.href=`/auth?redirectTo=${l}`;return}if(!Y("mentor_message").allowed){Ae("Mentor Messages");return}const m={id:crypto.randomUUID(),role:"user",content:t.trim(),images:o.length>0?o:void 0,timestamp:new Date},c=ge.current;x(l=>[...l,m]),Z(""),O([]),le(!0);const u=crypto.randomUUID();x(l=>[...l,{id:u,role:"assistant",content:"",timestamp:new Date}]);try{const l=[...c,m],p=await ie(l,g,s=>{x(v=>v.map(b=>b.id===u?{...b,content:s}:b))}),j=Object.values(p.toolCalls),W=j.find(s=>s.name==="score_exercise"),G=j.find(s=>s.name==="suggest_followups"),X=j.find(s=>s.name==="update_chat_summary");if(X!=null&&X.args)try{const s=JSON.parse(X.args);if(s&&typeof s=="object"){const v={...s,updated_at:new Date().toISOString()};ee(v),g&&Ce(g,v).catch(()=>{})}}catch(s){console.error("Failed to parse chat summary:",s)}if(W!=null&&W.args)try{const s=JSON.parse(W.args);if(s.skills_practiced&&s.overall_score!==void 0){await ne(s.skills_practiced,s.overall_score),i&&await we.from("mentor_exercises").insert({user_id:i.id,exercise_type:"design_exercise",difficulty:"mid",prompt:((d=c[0])==null?void 0:d.content)||t,response_summary:s.exercise_summary||"",score_rubric:s.rubric,overall_score:s.overall_score,skills_practiced:s.skills_practiced,time_spent_seconds:ue});const v=s.skill_scores&&typeof s.skill_scores=="object"?s.skill_scores:{},b=(s.skills_practiced||[]).map(R=>{const S=v[R];return typeof S=="number"?`${R}:${Math.round(S)}`:R}).join(", "),ze=`
2
3---
4**📊 Exercise Score: ${s.overall_score}/100**
5| Criteria | Score |
6|---|---|
7| Problem Framing | ${s.rubric.problem_framing}/100 |
8| Research & Empathy | ${s.rubric.research_empathy}/100 |
9| Ideation | ${s.rubric.ideation_exploration}/100 |
10| Solution Quality | ${s.rubric.solution_quality}/100 |
11| Communication | ${s.rubric.communication}/100 |
12
13*Skills tracked: ${b}*`,Be=p.content+ze;x(R=>R.map(S=>S.id===u?{...S,content:Be}:S)),he(!1),h.success("Exercise scored! Skills updated.")}}catch(s){console.error("Failed to parse exercise score:",s)}if(G!=null&&G.args)try{const s=JSON.parse(G.args);Array.isArray(s.suggestions)&&x(v=>v.map(b=>b.id===u?{...b,followUps:s.suggestions.slice(0,3)}:b))}catch(s){console.error("Failed to parse follow-ups:",s)}await se("mentor_message")}catch(l){if(l instanceof DOMException&&l.name==="AbortError")return;l instanceof Error&&(l.message==="rate_limited"||l.message==="credits_exhausted")||h.error(l instanceof Error?l.message:"Something went wrong"),x(p=>{const j=p[p.length-1];return(j==null?void 0:j.role)==="assistant"&&!j.content?p.slice(0,-1):p})}finally{le(!1)}},[i,Y,se,g,ie,ne,ue]),be=a.useRef(!1);a.useEffect(()=>{if(!(be.current||!i))try{const t=sessionStorage.getItem("fleck-mentor-pending-prompt");if(!t)return;sessionStorage.removeItem("fleck-mentor-pending-prompt"),be.current=!0,setTimeout(()=>w(t),50)}catch{}},[i,w]);const ye=a.useCallback(async(t,o=!1)=>{const r=t||f;if(!(!i||r.length===0))try{const m=r.find(d=>d.role==="user"),c=m?m.content.slice(0,60)+(m.content.length>60?"…":""):"Untitled Chat",u=r.map((d,l)=>({...re(d,l),timestamp:ut(d.timestamp).toISOString()}));if(g){const{error:d}=await ke({id:g,userId:i.id,title:c,messages:u,summary:_});if(d)throw d;o||h.success("Chat updated")}else{const{data:d,error:l}=await ke({id:null,userId:i.id,title:c,messages:u,summary:_});if(l)throw l;d&&($(d.id),_&&Ce(d.id,_).catch(()=>{})),o||h.success("Chat saved")}await M()}catch{o||h.error("Failed to save chat")}}
13,[f,i,g,_,M]),je=a.useRef(!1);a.useEffect(()=>{je.current&&!y&&f.length>=2&&ye(f,!0),je.current=y},[y,f,ye]);const Te=t=>{const o=(Array.isArray(t.messages)?t.messages:[]).map((r,m)=>re(r,m));x(o),$(t.id),ee(t.summary??null),z(!1),q(!1)},Ue=()=>{y&&Re(),x([]),$(null),ee(null),he(!1),fe(0)},Fe=async()=>{if(K)try{const{error:t}=await lt(K);if(t)throw t;g===K&&($(null),x([])),h.success("Chat deleted"),V(null),await M()}catch{h.error("Failed to delete"),V(null)}},Oe=async t=>{try{await Ie(t),k(!1)}catch{}},$e=f.length===0,J=te?"skills":L?"archive":B?"profile":"chat",Q=Y("mentor_message"),Le=De==="free"&&Q.limit!==null,ve=e.jsxs("div",{className:P("relative flex flex-col bg-card border border-border/60 rounded-2xl input-glow transition-all duration-300 focus-within:border-primary/50 w-full",D?"h-full border-0 rounded-none":"max-h-[500px]"),style:{overflowAnchor:"none"},children:[e.jsx("div",{className:"flex flex-col gap-1 px-4 pt-3 pb-1",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(jt,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold text-foreground tracking-tight",children:n("mentor.title")}),e.jsx("div",{className:"flex items-center ml-auto",children:e.jsx(nt,{delayDuration:300,children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[f.length>0&&e.jsxs(E,{children:[e.jsx(T,{asChild:!0,children:e.jsx("button",{onClick:Ue,className:"p-1.5 rounded-xl border border-border/60 hover:bg-secondary/50 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(Se,{className:"w-3.5 h-3.5"})})}),e.jsx(U,{side:"bottom",className:"text-xs",children:n("mentor.newChat")})]}),oe&&e.jsxs(E,{children:[e.jsx(T,{asChild:!0,children:e.jsx("button",{onClick:()=>{k(!B),z(!1),q(!1)},className:P("p-1.5 rounded-xl border transition-colors",B?"bg-primary/10 border-primary/30 text-primary":"border-border/60 hover:bg-secondary/50 text-muted-foreground hover:text-foreground"),children:e.jsx(vt,{className:P("w-3.5 h-3.5",F&&!B&&"text-primary")})})}),e.jsx(U,{side:"bottom",className:"text-xs",children:n(F?"mentor.editProfile":"mentor.setupProfileBtn")})]}),ae.length>0&&e.jsxs(E,{children:[e.jsx(T,{asChild:!0,children:e.jsx("button",{onClick:()=>{q(!te),z(!1),k(!1)},className:P("p-1.5 rounded-xl border transition-colors",te?"bg-primary/10 border-primary/30 text-primary":"border-border/60 hover:bg-secondary/50 text-muted-foreground hover:text-foreground"),children:e.jsx(wt,{className:"w-3.5 h-3.5"})})}),e.jsx(U,{side:"bottom",className:"text-xs",children:n("mentor.skillTracker")})]}),e.jsxs(E,{children:[e.jsx(T,{asChild:!0,children:e.jsx("button",{onClick:()=>{if(!i){h.info(n("mentor.loginHistory"));return}z(!L),k(!1),q(!1)},className:P("p-1.5 rounded-xl border transition-colors",i?L?"bg-primary/10 border-primary/30 text-primary":"border-border/60 hover:bg-secondary/50 text-muted-foreground hover:text-foreground":"border-border/40 text-muted-foreground/60"),children:e.jsx(et,{className:"w-3.5 h-3.5"})})}),e.jsx(U,{side:"bottom",className:"text-xs",children:n(i?"mentor.history":"mentor.loginHistory")})]}),e.jsxs(E,{children:[e.jsx(T,{asChild:!0,children:e.jsx("button",{onClick:()=>de(!D),className:"p-1.5 rounded-xl border border-border/60 hover:bg-secondary/50 text-muted-foreground hover:text-foreground transition-colors",children:D?e.jsx(Ne,{className:"w-3.5 h-3.5 rotate-180"}):e.jsx(Ne,{className:"w-3.5 h-3.5"})})}),e.jsx(U,{side:"bottom",className:"text-xs",children:n(D?"mentor.collapse":"mentor.expand")})]})]})})})]})}),Le&&e.jsxs("div",{className:"mx-4 mb-2 flex items-center justify-between gap-2 px-3 py-1.5 rounded-lg bg-primary/5 border border-primary/15 text-[11px]",children:[e.jsx("span",{className:"text-muted-foreground",children:Q.remaining===0?e.jsx("span",{className:"text-destructive font-medium",children:n("mentor.noMessagesLeft")}):e.jsx(e.Fragment,{children:n("mentor.messagesLeft",{remaining:Q.remaining,limit:Q.limit})})}),e.jsx("button",{onClick:()=>_e("/pricing"),className:"text-primary hover:underline font-medium flex-shrink-0",children:n("mentor.upgrade")})]}),e.jsxs("div",{className:"flex flex-col flex-1 min-h-0 px-4 pb-4 overflow-y-auto no-scrollbar",children:[J==="profile"?e.jsx(ht,{profile:F||ft,onSave:Oe,onCancel:()=>k(!1)}
13):J==="skills"?e.jsx(xt,{skills:ae,streak:Me}):J==="archive"?e.jsx(bt,{chats:ce,currentChatId:g,onLoad:Te,onDelete:V}):$e?e.jsxs("div",{className:"flex flex-col items-center text-center gap-3 py-4 flex-1 justify-center",children:[e.jsx("p",{className:"text-sm text-foreground font-medium",children:n("mentor.greeting","Ready to sharpen your design thinking?")}),e.jsx("p",{className:"text-xs text-muted-foreground max-w-sm leading-relaxed",children:n("mentor.subtitle")}),(()=>{const t=ce.find(c=>c.summary&&(c.summary.next_best_step||c.summary.last_focus||c.summary.headline));if(!t)return null;const o=t.summary,r=o.next_best_step||o.last_focus||o.headline||"",m=o.next_best_step?`Let's pick up from last session. You suggested I ${o.next_best_step.toLowerCase()} — let's do it now.`:o.last_focus?`Continue from where we left off: ${o.last_focus}.`:`Continue from last session: ${o.headline}.`;return e.jsxs("button",{onClick:()=>w(m),className:"group max-w-md w-full text-left px-3 py-2 rounded-xl border border-primary/25 bg-primary/[0.04] hover:bg-primary/[0.08] hover:border-primary/40 transition-all",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-primary/80 font-semibold mb-0.5",children:"Pick up where you left off"}),e.jsx("p",{className:"text-xs text-foreground line-clamp-2 leading-snug",children:r})]})})(),!F&&oe&&e.jsx("button",{onClick:()=>k(!0),className:"text-[11px] text-primary font-medium transition-colors hover:text-primary/80",children:n("mentor.setupProfile")}),e.jsx("div",{className:"flex flex-wrap gap-0.5 w-full justify-center",children:pt.map((t,o)=>{const r=["mentor.quickPrompts.reviewDesign","mentor.quickPrompts.careerAdvice","mentor.quickPrompts.interviewPrep","mentor.quickPrompts.designExercise","mentor.quickPrompts.portfolioReview"];return e.jsx("button",{onClick:()=>w(t.prompt),className:"px-2.5 py-1 rounded-full border border-border/30 hover:bg-secondary/50 transition-all text-[10px] font-medium text-muted-foreground hover:text-foreground hover:border-primary/30 group",children:e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(tt,{className:"w-2 h-2 text-primary opacity-40 group-hover:opacity-100 transition-opacity shrink-0"}),n(r[o])]})},t.label)})})]}):e.jsx(gt,{ref:xe,messages:f,isStreaming:y,onFollowUp:t=>w(t)}),N.length>0&&e.jsx("div",{className:"flex gap-2 pt-2",children:N.map((t,o)=>e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:t,alt:"Preview",className:"w-14 h-14 rounded-lg object-cover border border-border"}),e.jsx("button",{onClick:()=>O(r=>r.filter((m,c)=>c!==o)),className:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-destructive text-destructive-foreground flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(rt,{className:"w-2.5 h-2.5"})})]},o))}),J==="chat"&&!L&&e.jsx("div",{className:"border-t border-border/30 pt-3 mt-3",children:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:Pe,className:"hidden"}),e.jsx("button",{type:"button",onClick:()=>{var t;return(t=H.current)==null?void 0:t.click()},className:"flex items-center justify-center w-[34px] h-[34px] rounded-lg border border-border/60 bg-background text-muted-foreground hover:text-primary hover:border-primary/40 transition-colors","aria-label":"Attach image",children:e.jsx(Se,{className:"w-4 h-4"})}),e.jsx(at,{currentText:C,onAppend:Z}),e.jsx("textarea",{ref:I,value:C,onChange:t=>Z(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),y||w(C,N))},onPaste:Ee,placeholder:n("mentor.askAnything"),rows:1,className:"flex-1 resize-none bg-transparent border-0 rounded-lg px-2 py-2 text-sm focus:outline-none focus-visible:outline-none focus-visible:ring-0 min-h-[34px] max-h-[140px]",disabled:y}),e.jsx(st,{size:"sm",onClick:()=>w(C,N),disabled:y||!C.trim()&&N.length===0,className:"rounded-lg h-[34px] w-[34px] p-0 shrink-0",children:e.jsx(Ct,{className:"w-3.5 h-3.5"})})]})})]})]});return D?e.jsx("div",{className:"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm flex items-center justify-center p-4 md:px-8",onClick:t=>{t.target===t.currentTarget&&de(!1)},children:e.jsx("div",{className:"w-full max-w-3xl h-[85vh] flex flex-col rounded-2xl overflow-hidden shadow-2xl border border-border/60 bg-card",children:ve})}):e.jsxs("div",{className:"flex flex-col items-center w-full max-w-2xl",children:[ve,e.jsxs("div",{className:"flex items-center justify-center gap-1.5 pt-2",children:[e.jsx(ot,{className:"w-3 h-3 text-muted-foreground
13/60"}),e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n("mentor.allConversationsSafe")})]}),e.jsx(He,{open:!!K,onOpenChange:t=>!t&&V(null),children:e.jsxs(Ke,{children:[e.jsxs(Ve,{children:[e.jsx(Je,{children:n("mentor.deleteChat")}),e.jsx(Qe,{children:n("mentor.deleteChatConfirm")})]}),e.jsxs(We,{children:[e.jsx(Ge,{children:n("common.cancel")}),e.jsx(Xe,{onClick:Fe,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:n("common.delete")})]})]})})]})}export{vr 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.