PageSourceSearch

https://www.chargeops.net/assets/assistant-shell-CQqESgeW.js

js chargeops.net collected 2026-10-02 02:01:25 UTC 42,818 bytes, 5 lines download raw bytes

1import{r as m,b as Ue,j as t}from"./vendor-react-QE7wLE3r.js";import{a as X,hO as rt,bc as ze,b as H,hP as Fe,h as z,E as A,hQ as ot,aY as Ie,m as re,n as je,o as S,p as q,bS as ct,aA as lt,b7 as dt,T as ut,aM as pt,aN as mt,aO as ht,aP as ft,aQ as xt,aR as gt,aS as yt,aT as jt,aj as bt,c6 as K,c9 as Q,c8 as vt,ca as He,c7 as wt,hR as Nt,bL as Z,hS as Ke,b6 as kt,hT as Ce,hU as Se,cF as It,cf as Ct,am as St,ac as Et,I as le,x as Tt,r as Rt,s as _t,t as At,v as Dt,w as Ot,hV as Lt,hW as $t,hv as Pt,f1 as Mt,G as Ut,O as zt,fK as Ft,d5 as Ht,X as Kt,L as Vt,az as Bt,aJ as qt,hX as Wt,dD as Xt,hY as Ee}from"./index-C5UqyXey.js";import{A as Yt,i as Ve,r as Be}from"./ai-assistant-DImXPeoE.js";import{A as Gt}from"./arrow-up-Dns0bipl.js";import{E as Jt}from"./eye-off-CeD5jRrp.js";import{E as Qt}from"./eye-EEZr_Crl.js";import{C as Zt}from"./copy-CPHUILFm.js";import{K as es}from"./key-round-HUSX_5kK.js";import{T as ts}from"./textarea-m8PrGo4r.js";import{t as ss}from"./local-date-rAzDVC7d.js";import{u as ns}from"./unqualified-assignment-dialog-BKoYQV82.js";import{E as qe}from"./external-link-CBRXh9M2.js";import{R as as}from"./rotate-ccw-BUSrY0yl.js";import{H as is}from"./history-DCGbv7Po.js";import"./vendor-radix-C7HJG0re.js";import"./vendor-motion-DpnOviVe.js";import"./credentials-CE2xU--c.js";import"./qualification-mark-CdOfHgSu.js";const rs="data-assistant-layer",os=`[${rs}]`,Te="--co-assistant-launcher-h",be=`var(${rt}, 0px)`,cs=`calc(68px + ${be})`,ls=Fe("1rem",be),We=Fe("1rem + 64px",be),ds=m.forwardRef(function({open:e,pending:a,hidden:n=!1,onToggle:o,controls:c},l){const{language:i}=X(),d=r=>z(i,r);return m.useEffect(()=>{const r=document.documentElement;return r.style.setProperty(Te,cs),()=>{r.style.removeProperty(Te)}},[]),Ue.createPortal(t.jsxs("button",{ref:l,type:"button",onClick:o,"aria-label":d(e?"assistant.close":"assistant.open"),title:d(e?"assistant.close":"assistant.open"),"aria-expanded":e,"aria-controls":e?c:void 0,style:{bottom:ls},className:H("fixed right-4 z-[65] h-[52px] w-[52px] items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg ring-1 ring-black/5 transition-transform hover:scale-105 hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-reduce:transition-none motion-reduce:hover:scale-100",n?"hidden":"flex"),"data-testid":"assistant-launcher",children:[t.jsx(ze,{className:"h-6 w-6","aria-hidden":!0}),a&&t.jsx("span",{className:"absolute right-1 top-1 h-3 w-3 rounded-full bg-amber-400 ring-2 ring-white","data-testid":"assistant-launcher-badge",children:t.jsx("span",{className:"sr-only",children:d("assistant.pendingProposal")})})]}),document.body)}),ge=Yt.maxInputChars,us=ge-500,ps=6,ms=m.forwardRef(function({streaming:e,disabled:a,sending:n,onSend:o,onStop:c},l){const{language:i}=X(),d=(f,N)=>z(i,f,N),[r,j]=m.useState(""),p=m.useRef(null);m.useLayoutEffect(()=>{const f=p.current;if(!f)return;f.style.height="auto";const x=(parseFloat(getComputedStyle(f).lineHeight)||20)*ps+16;f.style.height=`${Math.min(f.scrollHeight,x)}px`,f.style.overflowY=f.scrollHeight>x?"auto":"hidden"},[r]);const b=r.length>ge,u=!a&&!n&&!e&&r.trim().length>0&&!b,g=async()=>{if(!u)return;await o(r)&&j("")},I=f=>{f.key!=="Enter"||f.shiftKey||f.nativeEvent.isComposing||(f.preventDefault(),g())};return t.jsxs("div",{className:"border-t border-border px-3 pb-2 pt-3",children:[t.jsxs("div",{className:"co-field flex items-end gap-2 px-2 py-1.5 focus-within:ring-2 focus-within:ring-ring",children:[t.jsx("textarea",{ref:f=>{p.current=f,typeof l=="function"?l(f):l&&(l.current=f)},value:r,onChange:f=>j(f.target.value),onKeyDown:I,rows:1,disabled:a,placeholder:d("assistant.placeholder"),"aria-label":d("assistant.placeholder"),className:"max-h-40 min-h-[2rem] flex-1 resize-none bg-transparent py-1 text-sm leading-5 outline-none placeholder:text-muted-foreground focus-visible:outline-none disabled:opacity-50","data-testid":"assistant-input"}),e?t.jsx(A,{type:"button",size:"icon",variant:"outline",onClick:c,"aria-label":d("assistant.stop"),title:d("assistant.stop"),"data-testid":"assistant-stop",children:t.jsx(ot,{"aria-hidden":!0})}):t.jsx(A,{type:"button",size:"icon",onClick:()=>{g()},disabled:!u,"aria-label":d("assistant.send"),title:d("assistant.send"),"data-testid":"assistant-send",children:t.jsx(Gt,{"aria-hidden":!0})})]}),t.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2",children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:d("assistant.footer")}),r.length>=us&&t.jsx("p",{className:H("co-nums shrink-0 text-2xs",b?"co-text-negative":"text-muted-foreground"),children:d("assistant.charCount",{count:Ie(r.length,void 0,i),max:Ie(ge,void 0,i)})})]})]})});
1function hs({surface:s,currentThreadId:e,onSelect:a,onDeleted:n,onClose:o}){const{language:c}=X(),{toast:l}=re(),i=(u,g)=>z(c,u,g),d=je(S.assistant.threads.list)?.filter(u=>u.surface===s),r=q(S.assistant.threads.remove),[j,p]=m.useState(null),b=async()=>{if(!j)return;const{id:u}=j;p(null);try{await r({threadId:u}),n(u)}catch{l({title:i("assistant.errors.internal"),variant:"destructive"})}};return t.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col bg-card","data-testid":"assistant-history",children:[t.jsxs("div",{className:"co-card-head flex items-center gap-2 px-3 py-2.5",children:[t.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:o,"aria-label":i("assistant.back"),title:i("assistant.back"),children:t.jsx(ct,{"aria-hidden":!0})}),t.jsx("h3",{className:"text-sm font-semibold",children:i("assistant.history")})]}),t.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:d===void 0?null:d.length===0?t.jsx("p",{className:"co-empty m-2 px-4 py-6 text-center text-sm text-muted-foreground",children:i("assistant.historyEmpty")}):t.jsx("ul",{className:"space-y-1",children:d.map(u=>t.jsxs("li",{className:H("co-row flex items-center gap-1 rounded-lg",u._id===e&&"bg-accent"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 px-2 py-2 text-left",onClick:()=>a(u._id),"aria-current":u._id===e?"true":void 0,children:[t.jsx(lt,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":!0}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block truncate text-sm font-medium",children:u.title}),t.jsx("span",{className:"block text-2xs text-muted-foreground",children:dt(u.lastMessageAt,{dateStyle:"medium",timeStyle:"short"},c)})]})]}),t.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:()=>p({id:u._id,title:u.title}),"aria-label":i("assistant.deleteThreadNamed",{title:u.title}),title:i("assistant.deleteThread"),children:t.jsx(ut,{"aria-hidden":!0})})]},u._id))})}),t.jsx(pt,{open:j!==null,onOpenChange:u=>!u&&p(null),children:t.jsxs(mt,{className:"z-[70]",overlayClassName:"z-[70]","data-assistant-layer":"",children:[t.jsxs(ht,{children:[t.jsx(ft,{children:i("assistant.deleteThread")}),t.jsx(xt,{children:i("assistant.deleteThreadConfirm",{title:j?.title??""})})]}),t.jsxs(gt,{children:[t.jsx(yt,{children:i("assistant.cancel")}),t.jsx(jt,{variant:"destructive",onClick:()=>{b()},children:i("assistant.deleteThread")})]})]})})]})}const ae="/documentation";function Xe(s){return s===ae||s.startsWith(`${ae}#`)||s.startsWith(`${ae}/`)}function Ye(s){try{const e=new URL(s);return e.protocol==="https:"||e.protocol==="http:"}catch{return!1}}function fs(s,e){const a=e==="app",n=new Set;for(const c of s.links??[])Ve(c.route)&&(!a&&Xe(c.route)||n.add(c.route));const o=new Set;for(const c of s.citations??[])Ye(c.url)&&o.add(c.url);return{internalRoutes:n,externalUrls:o,allowDocumentation:a}}function xs(s,e){return s.startsWith("/")?Ve(s)?Xe(s)?e.allowDocumentation&&(s.startsWith(`${ae}#`)||e.internalRoutes.has(s))?{kind:"internal",route:s}:null:e.internalRoutes.has(s)?{kind:"internal",route:s}:null:null:e.externalUrls.has(s)&&Ye(s)?{kind:"external",url:s}:null}function Re(s,e,a){const n=a.bracket(e+1);if(n===-1||s[n+1]!=="(")return null;const o=a.paren(n+2);if(o===-1)return null;const c=s.slice(e+1,n);let l=s.slice(n+2,o).trim();return l.startsWith("<")&&l.endsWith(">")&&(l=l.slice(1,-1).trim()),l.length===0?null:{label:c,href:l,end:o+1}}function se(s,e){let a=Number.POSITIVE_INFINITY,n=-1;return o=>(o>=a&&(n===-1||o<=n)||(a=o,n=s.indexOf(e,o)),n)}function gs(s){const e=s.length,a=new Int32Array(e+2).fill(-1);for(let n=e-1;n>=0;n--)s[n]!=="*"?a[n]=a[n+1]:s[n+1]==="*"?a[n]=a[n+2]:n>0&&/\s/.test(s[n-1])?a[n]=a[n+1]:a[n]=n;return a}function ys(s){let e=null;return{backtick:se(s,"`"),bracket:se(s,"]"),paren:se(s,")"),doubleStar:se(s,"**"),italicClose:a=>(e??=gs(s),a<s.length?e[a]:-1)}}const _e="inline p-0 m-0 bg-transparent border-0 font-medium text-brand-700 dark:text-brand-300 underline underline-offset-2 hover:text-brand-800 dark:hover:text-brand-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm cursor-pointer";function te(s,e,a){const n=[];let o="",c=0;const l=()=>`${a}-${c++}`,i=()=>{o&&n.push(o),o=""},d=ys(s);let r=0;for(;r<s.length;){const j=s[r];if(j==="`"){const p=d.backtick(r+1);if(p>r+1){i(),n.push(t.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-[0.85em]",children:s.slice(r+1,p)},l())),r=p+1;continue}}if(j==="!"&&s[r+1]==="["){const p=Re(s,r+1,d);if(p){o+=p.label,r=p.end;continue}}if(j==="["){const p=Re(s,r,d);if(p){i();const b=te(p.label,{...e,inLink:!0},`${a}-l${c}`),u=e.inLink?null:xs(p.href,e.policy);if(u?.kind==="internal"){const g=u.route;n.push(t.jsx("button",{type:"button",className:_e,onClick:()=>e.onNavigate(g),children:b},l()))}else u?.kind==="external"?n.push(t.jsx("a",{href:u.url,target:"_blank",rel:"noopener noreferrer",className:_e,children:b},l())):n.push(t.jsx(m.Fragment,{children:b},l()));r=p.end;continue}}if(j==="*"&&s[r+1]==="*"){const p=d.doubleStar(r+2);if(p>r+2){i(),n.push(t.jsx("strong",{className:"font-semibold",children:te(s.slice(r+2,p),e,`${a}-b${c}`)},l())),r=p+2;continue}}if(j==="*"&&s[r+1]!==void 0&&!/\s|\*/.test(s[r+1])){const p=d.italicClose(r+1);if(p>r+1){i(),n.push(t.jsx("em",{children:te(s.slice(r+1,p),e,`${a}-i${c}`)},l())),r=p+1;continue}}
1o+=j,r++}return i(),n}function de(s,e,a){const n=[];return s.forEach((o,c)=>{c>0&&n.push(t.jsx("br",{},`${a}-br${c}`)),n.push(...te(o,e,`${a}-${c}`))}),n}const ue=/^\s*[-*]\s+(.*)$/s,pe=/^\s*(\d{1,9})[.)]\s+(.*)$/s,Ae=/^\s{0,3}#{1,6}\s+(.*)$/s,me=/^\s*```/;function js(s){const e=s.trimEnd();let a=e.length;for(;a>0&&e[a-1]==="#";)a--;return a===0?"":a===e.length||!/\s/.test(e[a-1])?e:e.slice(0,a).trimEnd()}function bs(s){const e=s.replace(/\r\n?/g,`
2`).split(`
3`),a=[];let n=0;for(;n<e.length;){const o=e[n];if(o.trim()===""){n++;continue}if(me.test(o)){const r=[];for(n++;n<e.length&&!me.test(e[n]);)r.push(e[n++]);n++,a.push({kind:"code",text:r.join(`
4`)});continue}const c=Ae.exec(o);if(c){a.push({kind:"heading",text:js(c[1])}),n++;continue}const l=ue.exec(o),i=pe.exec(o);if(l||i){const r=l?"ul":"ol",j=l?ue:pe,p=[],b=i?Number(i[1]):1;for(;n<e.length;){const u=e[n],g=j.exec(u);if(g){p.push([l?g[1]:g[2]]),n++;continue}if(u.trim()!==""&&/^\s+/.test(u)&&p.length>0){p[p.length-1].push(u.trim()),n++;continue}break}a.push({kind:r,items:p,start:b});continue}const d=[];for(;n<e.length&&e[n].trim()!==""&&!me.test(e[n])&&!Ae.test(e[n])&&!ue.test(e[n])&&!pe.test(e[n]);)d.push(e[n++]);a.push({kind:"p",lines:d})}return a}function vs({text:s,policy:e,onNavigate:a}){const n={policy:e,onNavigate:a},o=bs(s);return t.jsx("div",{className:"space-y-2 break-words text-sm leading-relaxed",children:o.map((c,l)=>{const i=`b${l}`;switch(c.kind){case"p":return t.jsx("p",{children:de(c.lines,n,i)},i);case"heading":return t.jsx("p",{className:"font-semibold",children:te(c.text,n,i)},i);case"code":return t.jsx("pre",{className:"overflow-x-auto rounded-md bg-muted p-2 font-mono text-xs",children:t.jsx("code",{children:c.text})},i);case"ul":return t.jsx("ul",{className:"list-disc space-y-1 pl-5",children:c.items.map((d,r)=>t.jsx("li",{children:de(d,n,`${i}-${r}`)},`${i}-${r}`))},i);case"ol":return t.jsx("ol",{start:c.start,className:"list-decimal space-y-1 pl-5",children:c.items.map((d,r)=>t.jsx("li",{children:de(d,n,`${i}-${r}`)},`${i}-${r}`))},i)}})})}function ws(){const{language:s}=X();return(e,a)=>z(s,e,a)}const Ns="••••••••";function ye({t:s,subtitle:e,children:a}){return t.jsxs("div",{className:"co-card-inset space-y-3 p-3","data-testid":"assistant-ocpp-card",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("span",{className:"co-chip flex h-7 w-7 shrink-0 items-center justify-center","aria-hidden":!0,children:t.jsx(es,{className:"h-4 w-4"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h3",{className:"text-sm font-semibold leading-tight",children:s("ocppCredentials")}),e&&t.jsx("p",{className:"break-words text-xs text-muted-foreground",children:e})]})]}),a]})}function Ge({t:s}){return t.jsx(ye,{t:s,children:t.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"assistant-ocpp-unavailable",children:s("assistant.ocppCard.notAvailable")})})}function he({label:s,children:e}){return t.jsxs("div",{className:"flex items-start gap-3 px-1 py-1.5",children:[t.jsx("dt",{className:"w-28 shrink-0 text-xs text-muted-foreground",children:s}),t.jsx("dd",{className:"flex min-w-0 flex-1 items-center gap-1 text-sm",children:e})]})}function ks({chargerId:s,t:e}){const{toast:a}=re(),[n,o]=m.useState(!1),c=m.useId(),l=je(S.chargers.queries.getOcppCredentials,{id:s});if(l===null)return t.jsx(Ge,{t:e});if(l===void 0)return t.jsx(ye,{t:e,children:t.jsx("p",{className:"text-sm text-muted-foreground",children:e("loading")})});const i=t.jsx("span",{className:"text-muted-foreground",children:e("ocppNotConfigured")}),d=l.ocppPassword??"",r=async()=>{try{await navigator.clipboard.writeText(d),a({title:e("copied"),description:e("assistant.ocppCard.passwordCopied")})}catch{a({title:e("assistant.ocppCard.copyFailed"),variant:"destructive"})}};return t.jsxs(ye,{t:e,subtitle:l.name,children:[t.jsxs("dl",{className:"divide-y divide-border",children:[t.jsx(he,{label:e("ocppUrl"),children:l.ocppUrl?t.jsx("span",{className:"break-all font-mono text-xs",children:l.ocppUrl}):i}),t.jsx(he,{label:e("chargerCredentials.username"),children:l.ocppUsername?t.jsx("span",{className:"break-all font-mono text-xs",children:l.ocppUsername}):i}),t.jsx(he,{label:e("chargerCredentials.password"),children:d?t.jsxs(t.Fragment,{children:[t.jsx("span",{id:c,className:"min-w-0 flex-1 break-all font-mono text-xs","data-testid":"assistant-ocpp-password",children:n?d:t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true","data-testid":"assistant-ocpp-mask",children:Ns}),t.jsx("span",{className:"sr-only",children:e("assistant.ocppCard.masked")})]})}),t.jsx(A,{type:"button",variant:"ghost",size:"icon",className:"-my-2 shrink-0",onClick:()=>o(j=>!j),"aria-label":e("chargerEditDialog.showPassword"),"aria-pressed":n,"aria-controls":c,"data-testid":"assistant-ocpp-reveal",children:n?t.jsx(Jt,{"aria-hidden":!0}):t.jsx(Qt,{"aria-hidden":!0})}),t.jsx(A,{type:"button",variant:"ghost",size:"icon",className:"-my-2 shrink-0",onClick:r,"aria-label":e("assistant.ocppCard.copyPassword"),"data-testid":"assistant-ocpp-copy",children:t.jsx(Zt,{"aria-hidden":!0})})]}):i})]}),t.jsx("p",{className:"text-xs text-muted-foreground",children:e("assistant.ocppCard.neverSent")}
4)]})}function Is({card:s}){const e=ws();return t.jsx(bt,{level:"component",fallback:t.jsx(Ge,{t:e}),children:t.jsx(ks,{chargerId:s.chargerId,t:e})},s.chargerId)}const Cs=["case.create","case.comment","case.status","case.priority","case.assign","maintenance.scheduleVisit","maintenance.resolveDefect","site.note","charger.note"],L=Q().min(1).max(64),ee=s=>Q().trim().min(1).max(s),fe=s=>Nt(e=>typeof e=="string"&&e.trim()===""?void 0:e,Q().trim().max(s).optional()),Ss=Q().regex(/^\d{4}-\d{2}-\d{2}$/),De=He(["low","medium","high","critical"]),Je={"case.create":K({siteId:L,chargerIds:wt(L).max(20).optional(),title:ee(200),description:ee(5e3),priority:De,category:fe(100)}),"case.comment":K({caseId:L,text:ee(5e3),visibility:He(["public","internal"])}),"case.status":K({caseId:L,newStatus:Q().min(1).max(64),resolutionNote:fe(5e3)}).superRefine((s,e)=>{s.newStatus==="closed"&&!s.resolutionNote&&e.addIssue({code:vt.custom,path:["resolutionNote"],message:"required to close"})}),"case.priority":K({caseId:L,priority:De}),"case.assign":K({caseId:L,assigneeUserId:L.nullable()}),"maintenance.scheduleVisit":K({siteId:L,visitId:L.optional(),scheduledDate:Ss,startTime:Q().regex(/^\d{2}:\d{2}$/).optional(),assignedUserId:L.optional(),notes:fe(2e3)}),"maintenance.resolveDefect":K({defectId:L,siteId:L}),"site.note":K({siteId:L,text:ee(5e3)}
4),"charger.note":K({chargerId:L,line:ee(1e3)})},Es={"case.create":["title","description","priority"],"case.comment":["text","visibility"],"case.status":["newStatus","resolutionNote"],"case.priority":["priority"],"case.assign":[],"maintenance.scheduleVisit":["scheduledDate","startTime","notes"],"maintenance.resolveDefect":[],"site.note":["text"],"charger.note":["line"]};function Ts(s,e){return Je[s].parse(e)}function Rs(s){return Cs.includes(s)}function ne(s){return Object.fromEntries(Object.entries(s).filter(([,e])=>e!==void 0))}function V(s,e){try{return Ts(s,JSON.parse(e))}catch{throw new Z({code:"assistant_proposal_invalid"})}}function _s(s){if(!(s instanceof Z))return null;const e=s.data;return e&&typeof e=="object"&&e.code==="OPEN_VISIT_EXISTS"&&typeof e.visitId=="string"?e.visitId:null}async function As(s,e,a,n=()=>new Date,o=()=>crypto.randomUUID(),c={}){const l=c.acknowledgeMissingCredentials===!0?{acknowledgeMissingCredentials:!0}:{};switch(e){case"case.create":{const i=V(e,a),d=await s.mutation(S.tickets.mutations.create,ne({siteId:i.siteId,chargerIds:i.chargerIds,title:i.title,description:i.description,priority:i.priority,category:i.category}));if(typeof d=="string")return{resultRef:{kind:"case",id:d}};const r=d;return r?.submittedForReview===!0&&typeof r.submissionId=="string"?{resultRef:{kind:"submission",id:r.submissionId}}:{}}case"case.comment":{const i=V(e,a);return await s.mutation(S.tickets.mutations.addComment,{id:i.caseId,text:i.text,visibility:i.visibility}
4),{resultRef:{kind:"case",id:i.caseId}}}case"case.status":{const i=V(e,a);return await s.mutation(S.tickets.mutations.updateStatus,ne({id:i.caseId,newStatus:i.newStatus,resolutionNote:i.resolutionNote})),{resultRef:{kind:"case",id:i.caseId}}}case"case.priority":{const i=V(e,a);return await s.mutation(S.tickets.mutations.update,{id:i.caseId,priority:i.priority}),{resultRef:{kind:"case",id:i.caseId}}}case"case.assign":{const i=V(e,a);return await s.mutation(S.tickets.mutations.assign,i.assigneeUserId===null?{id:i.caseId}:{id:i.caseId,assigneeUserId:i.assigneeUserId,...l}),{resultRef:{kind:"case",id:i.caseId}}}case"maintenance.scheduleVisit":{const i=V(e,a);let d=i.visitId;if(d===void 0)try{d=await s.mutation(S.maintenance.visits.createVisit,ne({siteId:i.siteId,notes:i.notes}))}catch(r){const j=_s(r);if(j===null)throw r;d=j}return await s.mutation(S.maintenance.visits.scheduleVisit,ne({visitId:d,scheduledDate:i.scheduledDate,startTime:i.startTime,assignedUserId:i.assignedUserId,notes:i.notes,...i.assignedUserId!==void 0?l:{}}
4)),{resultRef:{kind:"visit",id:d}}}case"maintenance.resolveDefect":{const i=V(e,a);return await s.mutation(S.maintenance.mutations.resolveDefect,{defectId:i.defectId,resolved:!0}),{}}case"site.note":{const i=V(e,a);return await s.mutation(S.sites.mutations.addNote,{siteId:i.siteId,note:{id:o(),text:i.text,timestamp:n().toISOString()}}),{resultRef:{kind:"site",id:i.siteId}}}case"charger.note":{const i=V(e,a),d=await s.query(S.chargers.queries.getById,{id:i.chargerId});if(!d)throw new Z({code:"assistant_apply_not_found"});const r=`${ss(n())} — ${i.line}`;return await s.mutation(S.chargers.mutations.update,{id:i.chargerId,notes:d.notes?`${d.notes}
5${r}`:r}),{resultRef:{kind:"charger",id:i.chargerId}}}default:{const i=e;throw new Z({code:"assistant_apply_unknown_action",action:String(i)})}}}function ie(s){if(!(s instanceof Z))return null;const e=s.data;return e&&typeof e=="object"&&typeof e.code=="string"?e.code:null}function W(s,e,a){const n=`assistant.errors.${e}`,o=z(s,n,a);return o===n?z(s,"assistant.errors.internal"):o}function Ds(s,e){if(e instanceof Z){const a=e.data;if(typeof a=="string")return W(s,"gate");const n=ie(e);if(n==="assistant_limit"){const o=a&&typeof a=="object"&&typeof a.resetAt=="number"?It(a.resetAt,{hour:"2-digit",minute:"2-digit"},s):"",c=a&&typeof a=="object"&&a.scope==="tenant"?"assistant_limit_tenant":n;return W(s,c,{time:o})}if(n)return W(s,n)}return W(s,"internal")}const Os=new Set(["assistant_thread_missing","assistant_surface"]);function Ls(s,e){const{language:a}=X(),{toast:n}=re(),o=Ke(),c=q(S.assistant.threads.startTurn),l=q(S.assistant.threads.cancel),i=kt(S.assistant.agent.respond),[d,r]=m.useState(()=>Ce(s)),[j,p]=m.useState(!1),b=m.useRef(s);m.useEffect(()=>{b.current!==s&&(b.current=s,r(Ce(s)))},[s]);const u=m.useCallback(N=>{r(x=>{const h={...x,...N};return Se(s,h),h})},[s]),g=m.useRef(d.threadId);g.current=d.threadId;const I=m.useCallback(async N=>{const x=N.trim();if(!x||j)return!1;p(!0);try{const h={text:x,surface:e,language:a,pageContext:o};let k;const T=g.current;try{k=await c(T?{...h,threadId:T}:h)}catch(U){if(!T||!Os.has(ie(U)??""))throw U;k=await c(h)}return u({threadId:k.threadId}),i({messageId:k.assistantMessageId}).catch(()=>{n({title:z(a,"assistant.errors.internal"),variant:"destructive"})}),!0}catch(h){return n({title:Ds(a,h),variant:"destructive"}),!1}finally{p(!1)}},[j,e,a,o,c,i,u,n]),f=m.useCallback(async N=>{try{await l({messageId:N})}catch{n({title:z(a,"assistant.errors.internal"),variant:"destructive"})}},[l,a,n]);return{...d,setOpen:m.useCallback(N=>u({open:N}),[u]),toggle:m.useCallback(()=>r(N=>{const x={...N,open:!N.open};return Se(s,x),x}),[s]),setExpanded:m.useCallback(N=>u({expanded:N}),[u]),setThreadId:m.useCallback(N=>u({threadId:N}),[u]),send:I,stop:f,sending:j}}function $s(s,e){switch(s.status){case"applied":case"applying":case"cancelled":case"expired":return s.status;case"pending":case"failed":return s.expiresAt<=e?"expired":s.status==="failed"?"failed":"open"}}const Ps=new Set(["site","charger","case","serviceReport","maintenanceReport","visit"]);function Ms(s,e){return!s||!Ps.has(s.kind)?null:Be(s.kind,s.id,e)}function Us(s,e,a){const n=c=>typeof e[c]=="string"?e[c]:null,o=(c,l)=>l?Be(c,l,a):null;switch(s){case"case.comment":case"case.status":case"case.priority":case"case.assign":return o("case",n("caseId"));case"maintenance.scheduleVisit":return n("visitId")?o("visit",n("visitId")):o("site",n("siteId"));case"maintenance.resolveDefect":case"site.note":return o("site",n("siteId"));case"charger.note":return o("charger",n("chargerId"));case"case.create":return null}}const zs=new Set(["title","description","text","notes","line","resolutionNote"]),xe="assistant.proposal.",Oe="h-[38px] px-4 text-[13px]",Fs=/^[a-z0-9_.:-]{1,64}$/;function Hs(s){try{const e=JSON.parse(s);return e&&typeof e=="object"?e:{}}catch{return{}}}const Ks=s=>new Promise(e=>setTimeout(e,s));function Vs(s,e){let a=Je[s];for(;a instanceof Lt;)a=a.innerType();if(!(a instanceof $t))return!1;const n=a.shape[e];return n?n.isOptional():!1}function Bs(s,e,a){const n={...e};for(const[o,c]of Object.entries(a))c.trim()===""&&Vs(s,o)?delete n[o]:n[o]=c;return n}function qs({proposal:s,surface:e,now:a,onNavigate:n}){const{language:o}=X(),{toast:c}=re(),l=Ct(),i=q(S.assistant.proposals.beginApply),d=q(S.assistant.proposals.markApplied),r=q(S.assistant.proposals.markFailed),j=q(S.assistant.proposals.edit),p=q(S.assistant.proposals.cancel),{confirmFromError:b,dialog:u}=ns(),g=(y,w)=>z(o,y,w),I=(y,w)=>{const _=g(y);return _===y?w:_},[f,N]=m.useState(!1),[x,h]=m.useState(!1),[k,T]=m.useState({}),[U,F]=m.useState(null),D=$s(s,a),$=D==="open"||D==="failed";if(m.useEffect(()=>{$||h(!1)},[$]),!Rs(s.action))return null;const E=s.action,P=Hs(s.args),O=x&&$,v=(y,w)=>{switch(y){case"priority":case"currentPriority":return I(`tickets.priority_${w}`,w);case"newStatus":case"currentStatus":return I(`tickets.status_${w}`,w);case"category":return I(`tickets.category_${w}`,w);case"visibility":return I(`assistant.visibility.${w}`,w);case"severity":return I(`maintenanceReports.severity.${w}`,w);case"scheduledDate":case"currentScheduledDate":return/^\d{4}-\d{2}-\d{2}$/.test(w)?Et(w,{dateStyle:"medium"},o):w;default:return w}},M=y=>{const w=ie(y);c({title:w?W(o,w):g("assistant.errors.apply_failed"),variant:"destructive"})},B=async(y=!1)=>{N(!0),F(null);let w;try{w=await i({proposalId:s._id})}catch(R){M(R),N(!1);return}let _;try{_=await As(l,w.action,w.args,void 0,void 0,y?{acknowledgeMissingCredentials:!0}:{})}catch(R){const C=ie(R),G=C?I(`assistant.errors.${C}`,""):"";F(G||Tt(R));try{await r({proposalId:s._id,error:C&&Fs.test(C)?C:"apply_failed"})}catch{}N(!1),b(R,()=>B(!0));return}for(let R=0;R<3;
5R++)try{await d({proposalId:s._id,resultRef:_.resultRef});break}catch{R<2&&await Ks(400*(R+1))}N(!1)},Y=async()=>{N(!0);try{await p({proposalId:s._id})}catch(y){M(y)}finally{N(!1)}},oe=Es[E].filter(y=>!(e==="portal"&&y==="visibility")),Ze=()=>{const y={};for(const w of oe)y[w]=typeof P[w]=="string"?P[w]:"";T(y),h(!0)},et=async()=>{N(!0);try{await j({proposalId:s._id,args:JSON.stringify(Bs(E,P,k))}),h(!1)}catch(y){M(y)}finally{N(!1)}},tt=y=>I(`${xe}${y}`,y),J=y=>`assistant-proposal-${s._id}-${y}`,st=y=>{const w=k[y]??"",_=C=>T(G=>({...G,[y]:C})),R=(C,G)=>t.jsxs(Rt,{value:w,onValueChange:_,children:[t.jsx(_t,{id:J(y),className:"h-9",children:t.jsx(At,{})}),t.jsx(Dt,{className:"z-[70]","data-assistant-layer":"",children:C.map(ce=>t.jsx(Ot,{value:ce,children:G(ce)},ce))})]});switch(y){case"priority":return R(Mt,C=>v("priority",C));case"visibility":return R(["public","internal"],C=>v("visibility",C));case"newStatus":{const C=[...Pt];return w&&!C.includes(w)&&C.push(w),R(C,G=>v("newStatus",G))}case"scheduledDate":return t.jsx(le,{id:J(y),type:"date",value:w,onChange:C=>_(C.target.value)});case"startTime":return t.jsx(le,{id:J(y),type:"time",value:w,onChange:C=>_(C.target.value)});case"title":case"line":return t.jsx(le,{id:J(y),value:w,onChange:C=>_(C.target.value)});default:return t.jsx(ts,{id:J(y),rows:3,value:w,onChange:C=>_(C.target.value)})}},ve=f&&D==="applying",nt=(()=>{if(ve)return t.jsx("span",{className:"co-pill is-pending px-2 py-0.5 text-xs font-medium",children:g("assistant.applying")});switch(D){case"applied":return t.jsx("span",{className:"co-pill is-ok px-2 py-0.5 text-xs font-medium",children:g("assistant.applied")});case"applying":return t.jsx("span",{className:"co-pill is-pending px-2 py-0.5 text-xs font-medium",children:g("assistant.outcomeUnknown")});case"cancelled":return t.jsx("span",{className:"co-pill px-2 py-0.5 text-xs font-medium",children:g("assistant.cancelled")});case"expired":return t.jsx("span",{className:"co-pill px-2 py-0.5 text-xs font-medium",children:g("assistant.expired")});default:return null}})(),at=s.error&&s.error!=="apply_failed"?I(`assistant.errors.${s.error}`,""):"",we=U??(at||null),Ne=D==="applied"?Ms(s.resultRef,e):null,ke=D==="applying"?Us(E,P,e):null,it=E==="case.status"&&P.newStatus==="closed";return t.jsxs("div",{className:"co-card-inset space-y-3 p-3","data-testid":"assistant-proposal","data-state":D,children:[u,t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("span",{className:"co-chip flex h-7 w-7 shrink-0 items-center justify-center","aria-hidden":!0,children:t.jsx(St,{className:"h-4 w-4"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h3",{className:"text-sm font-semibold leading-tight",children:g(`assistant.actions.${E}.title`)}),$&&t.jsx("p",{className:"text-xs text-muted-foreground",children:g("assistant.awaitingApproval")})]}),nt]}),!O&&t.jsx("dl",{className:"divide-y divide-border",children:s.summary.map((y,w)=>{const _=y.labelKey.startsWith(xe)?y.labelKey.slice(xe.length):y.labelKey,R=zs.has(_)&&typeof P[_]=="string"?P[_]:null;return t.jsxs("div",{className:H("px-1 py-1.5",R?"block":"flex gap-3"),children:[t.jsx("dt",{className:H("text-xs text-muted-foreground",R?"mb-0.5":"w-28 shrink-0"),children:I(y.labelKey,_)}),t.jsx("dd",{className:H("min-w-0 text-sm",R?"whitespace-pre-wrap break-words":"break-words"),children:R??v(_,y.value)})]},`${y.labelKey}-${w}`)})}),O&&t.jsx("div",{className:"space-y-2",children:oe.map(y=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{htmlFor:J(y),className:"text-xs font-medium text-muted-foreground",children:tt(y)}),st(y)]},y))}),$&&it&&t.jsx("p",{className:"text-xs text-muted-foreground",children:g("assistant.notice.closeCase")}),$&&E==="maintenance.scheduleVisit"&&t.jsx("p",{className:"text-xs text-muted-foreground",children:g("assistant.notice.scheduleVisit")}),D==="failed"&&t.jsxs("div",{role:"alert",className:"co-text-negative text-xs",children:[t.jsx("p",{className:"font-medium",children:g("assistant.errors.apply_failed")}),we&&t.jsx("p",{children:we})]}),D==="applying"&&!ve&&t.jsxs("p",{className:"text-xs text-muted-foreground",children:[g("assistant.outcomeUnknownBody")," ",ke&&t.jsx("button",{type:"button",className:"co-link-chip inline-flex items-center gap-1 px-1.5 py-0.5 text-xs",onClick:()=>n(ke),children:g("assistant.openRecord")})]}),Ne&&t.jsxs("button",{type:"button",className:"co-link-chip inline-flex items-center gap-1 px-2 py-1 text-xs font-medium",onClick:()=>n(Ne),children:[t.jsx(qe,{className:"h-3 w-3","aria-hidden":!0}),g("assistant.openRecord")]}),$&&!O&&t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(A,{type:"button",size:"sm",onClick:()=>{B()}
5,disabled:f,children:g("assistant.apply")}),oe.length>0&&t.jsx(A,{type:"button",size:"sm",variant:"outline",onClick:Ze,disabled:f,children:g("assistant.edit")}),t.jsx(A,{type:"button",size:"sm",variant:"ghost",className:Oe,onClick:Y,disabled:f,children:g("assistant.cancel")})]}),O&&t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(A,{type:"button",size:"sm",onClick:et,disabled:f,children:g("assistant.save")}),t.jsx(A,{type:"button",size:"sm",variant:"ghost",className:Oe,onClick:()=>h(!1),disabled:f,children:g("assistant.discardEdit")})]})]})}const Ws=new Set(["timeout","network","http"]);function Xs(s){try{const e=new URL(s);return e.protocol!=="https:"&&e.protocol!=="http:"?null:e.hostname.replace(/^www\./,"")}catch{return null}}const Le=[];function Ys({messages:s,proposals:e,surface:a,now:n,busy:o,onNavigate:c,onSend:l,empty:i}){const d=m.useMemo(()=>{const h=new Map;for(const k of e){const T=h.get(k.messageId)??[];T.push(k),h.set(k.messageId,T)}return h},[e]),r=m.useRef(c);r.current=c;const j=m.useRef(l);j.current=l;const p=m.useCallback(h=>r.current(h),[]),b=m.useCallback(h=>j.current(h),[]),u=m.useRef(null),g=m.useRef(!0),I=m.useRef(s.length),f=s[s.length-1];if(m.useLayoutEffect(()=>{s.slice(I.current).some(k=>k.role==="user")&&(g.current=!0),I.current=s.length;const h=u.current;h&&g.current&&(h.scrollTop=h.scrollHeight)},[s,f?.text.length,f?.status,e.length]),s.length===0)return t.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain px-4 py-4",children:i});const N=h=>{for(let k=h-1;k>=0;k--)if(s[k].role==="user")return s[k].text;return null};let x=null;for(let h=s.length-1;h>=0;h--){const k=s[h];if(k.role==="assistant"&&k.status==="error"){x=k._id;break}}return t.jsx("div",{ref:u,onScroll:h=>{const k=h.currentTarget;g.current=k.scrollHeight-k.scrollTop-k.clientHeight<48},className:"flex-1 space-y-4 overflow-y-auto overscroll-contain px-4 py-4",role:"log","aria-live":"polite","aria-relevant":"additions","data-testid":"assistant-messages",children:s.map((h,k)=>{const T=h.status==="done"?d.get(h._id)??Le:Le;return t.jsx(Js,{message:h,cards:T,surface:a,now:T.length>0?n:0,busy:o,latestError:h._id===x,question:h.role==="assistant"?N(k):null,onNavigate:p,onSend:b},h._id)})})}function Gs(s,e){return s.message._id===e.message._id&&s.message.updatedAt===e.message.updatedAt&&s.message.text===e.message.text&&s.message.status===e.message.status&&s.cards===e.cards&&s.surface===e.surface&&s.now===e.now&&s.busy===e.busy&&s.latestError===e.latestError&&s.question===e.question&&s.onNavigate===e.onNavigate&&s.onSend===e.onSend}const Js=m.memo(function({message:e,cards:a,surface:n,now:o,busy:c,latestError:l,question:i,onNavigate:d,onSend:r}){const{language:j}=X(),p=(x,h)=>z(j,x,h),b=m.useMemo(()=>e.text?t.jsx(vs,{text:e.text,policy:fs(e,n),onNavigate:d}):null,[e._id,e.updatedAt,e.text,n,d]);if(e.role==="user")return t.jsx("div",{className:"flex justify-end",children:t.jsx("p",{className:"max-w-[85%] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-primary px-3 py-2 text-sm text-primary-foreground",children:e.text})});const u=e.status==="streaming",g=(e.toolChips??[]).filter(x=>x.count!==0),I=(e.citations??[]).map(x=>({...x,host:Xs(x.url)})).filter(x=>x.host!==null),f=e.errorKind,N=e.status==="done"?e.cards??[]:[];return t.jsxs("div",{className:"space-y-2","aria-busy":u,"data-testid":"assistant-message",children:[g.length>0&&t.jsx("ul",{className:"flex flex-wrap gap-1.5","aria-label":p("assistant.toolsUsed"),children:g.map(x=>{const h=p(x.labelKey,{count:x.count??1});return t.jsx("li",{className:"co-chip px-2 py-0.5 text-xs font-medium",children:h===x.labelKey?x.tool:h},x.tool)})}),e.text&&t.jsxs("div",{className:"text-foreground",children:[b,u&&t.jsx("span",{className:"ml-0.5 inline-block h-4 w-1.5 animate-pulse rounded-sm bg-current align-text-bottom","aria-hidden":!0,"data-testid":"assistant-caret"})]}),u&&!e.text&&t.jsxs("p",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx(Ut,{className:"h-4 w-4 animate-spin","aria-hidden":!0}),p("assistant.thinking"),t.jsx("span",{className:"inline-block h-4 w-1.5 animate-pulse rounded-sm bg-current","aria-hidden":!0,"data-testid":"assistant-caret"})]}),I.length>0&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"text-2xs font-medium uppercase tracking-wide text-muted-foreground",children:p("assistant.sources")}),t.jsx("ul",{className:"flex flex-wrap gap-1.5",children:I.map(x=>t.jsx("li",{children:t.jsxs("a",{href:x.url,target:"_blank",rel:"noopener noreferrer",title:x.title,className:"co-link-chip inline-flex items-center gap-1 px-2 py-0.5 text-xs",children:[x.host,t.jsx(qe,{className:"h-3 w-3","aria-hidden":!0})]})},x.url))})]}),e.status==="error"&&t.jsxs("div",{role:l?"alert":void 0,className:"flex flex-wrap items-center gap-2 text-sm","data-testid":"assistant-error",children:[t.jsx("span",{className:"co-text-negative",children:W(j,f??"internal")}),l&&f&&Ws.has(f)&&i&&t.jsxs(A,{type:"button",size:"xs",variant:"outline",disabled:c,onClick:()=>r(i),children:[t.jsx(as,{className:"mr-1","aria-hidden":!0}),p("assistant.retry")]})]}),e.status==="done"&&f==="max_tokens"&&t.jsx("p",{className:"text-xs text-muted-foreground",children:p("assistant.truncated")}),e.status==="done"&&f==="refusal"&&t.jsx("p",{className:"text-xs text-muted-foreground",children:W(j,"refusal")}),e.status==="done"&&f==="rounds"&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[t.jsx("span",{children:W(j,"rounds")}),t.jsx(A,{type:"button",size:"xs",variant:"outline",disabled:c,onClick:()=>r(p("assistant.continuePrompt")),children:p("assistant.continue")})]}),e.status==="cancelled"&&t.jsx("p",{className:"text-xs text-muted-foreground",children:p("assistant.stopped")}),N.length>0&&t.jsx("div",{className:H("space-y-2",e.text&&"pt-1"),children:N.map(x=>t.jsx(Is,{card:x},`${x.kind}:${x.chargerId}`))}),a.length>0&&t.jsx("div",{className:H("space-y-2",e.text&&"pt-1"),children:a.map(x=>t.jsx(qs,{proposal:x,surface:n,now:o,onNavigate:d},x._id))})]})},Gs),Qs={app:["assistant.suggest.summarizePage","assistant.suggest.openCases","assistant.suggest.howToVisit"],portal:["assistant.suggest.portalCases","assistant.suggest.portalReports","assistant.suggest.portalHowTo"]};function Qe(s){const[e,a]=m.useState(()=>Date.now());return m.useEffect(()=>{const n=window.setInterval(()=>a(Date.now()),s);return()=>window.clearInterval(n)},[s]),e}const $e="--co-assistant-panel-w",Pe=`min(640px, calc(100dvh - ${We} - 1rem))`,Zs='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not
5([tabindex="-1"])';function en({id:s,session:e,availability:a,surface:n,messages:o,proposals:c,isPhone:l,lowered:i=!1,launcherRef:d,autoFocus:r,onNavigate:j}){const{language:p}=X(),b=(v,M)=>z(p,v,M),u=Ke(),g=Qe(15e3),[I,f]=m.useState(!1),N=m.useRef(null),x=m.useRef(null),h=a.state==="ready",k=[...o].reverse().find(v=>v.role==="assistant"&&v.status==="streaming"),T=e.sending||k!==void 0,U=e.expanded&&!l;m.useEffect(()=>{r&&x.current?.focus();const v=d.current;return()=>{(N.current?.contains(document.activeElement)||document.activeElement===document.body)&&v?.focus()}},[d]),m.useLayoutEffect(()=>{const v=N.current;if(l||!v)return;const M=document.documentElement,B=()=>{M.style.setProperty($e,`calc(${Math.ceil(v.getBoundingClientRect().width)}px + 1rem)`)};B();const Y=typeof ResizeObserver>"u"?null:new ResizeObserver(B);return Y?.observe(v),()=>{Y?.disconnect(),M.style.removeProperty($e)}},[l]);const F=m.useCallback(()=>e.setOpen(!1),[e]),D=v=>{if(v.key==="Escape"&&!v.defaultPrevented){v.preventDefault(),I?f(!1):F();return}if(v.key==="Tab"&&l&&N.current){const M=Array.from(N.current.querySelectorAll(Zs));if(M.length===0)return;const B=M[0],Y=M[M.length-1];v.shiftKey&&document.activeElement===B?(v.preventDefault(),Y.focus()):!v.shiftKey&&document.activeElement===Y&&(v.preventDefault(),B.focus())}},$=v=>e.send(v),E=t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"text-sm font-medium",children:b("assistant.emptyTitle")}),t.jsx("p",{className:"text-sm text-muted-foreground",children:b("assistant.emptyBody")})]}),t.jsx("ul",{className:"flex flex-col items-start gap-2","aria-label":b("assistant.suggestions"),children:Qs[n].map(v=>t.jsx("li",{children:t.jsx("button",{type:"button",disabled:T,onClick:()=>{$(b(v))},className:"co-link-chip px-3 py-1.5 text-left text-sm disabled:opacity-50",children:b(v)})},v))})]}),P=v=>t.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:t.jsxs("div",{className:"co-empty space-y-3 px-4 py-6 text-center text-sm",children:[t.jsx("p",{children:b(v)}),a.canConfigure&&t.jsx(Vt,{href:"/configuration?tab=ai",onClick:()=>l&&F(),className:"co-link-chip inline-flex px-3 py-1.5 text-sm font-medium",children:b("assistant.states.openSettings")})]})}),O=u.title||u.route;return Ue.createPortal(t.jsxs("div",{ref:N,id:s,role:"dialog","aria-modal":l?"true":"false","aria-labelledby":`${s}-title`,onKeyDown:D,style:l?void 0:{bottom:We,height:Pe,maxHeight:Pe},className:H("co-card is-static fixed flex flex-col overflow-hidden",i?"z-40":"z-[65]",l?"is-sheet inset-0 pb-[var(--safe-bottom)] pl-[var(--safe-left)] pr-[var(--safe-right)] pt-[var(--safe-top)]":H("is-floating right-4 max-w-[calc(100vw-2rem)]",U?"w-[720px]":"w-[400px]")),"data-testid":"assistant-panel",children:[t.jsxs("div",{className:"co-card-head flex items-center gap-2 px-3 py-2.5",children:[t.jsx("span",{className:"co-chip flex h-8 w-8 shrink-0 items-center justify-center","aria-hidden":!0,children:t.jsx(ze,{className:"h-4 w-4"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h2",{id:`${s}-title`,className:"co-card-title truncate leading-tight",children:b("assistant.title")}),a.modelLabel&&t.jsx("p",{className:"truncate text-2xs text-muted-foreground",children:a.modelLabel})]}),h&&t.jsxs(t.Fragment,{children:[t.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:()=>f(v=>!v),"aria-label":b("assistant.history"),title:b("assistant.history"),"aria-pressed":I,children:t.jsx(is,{"aria-hidden":!0})}),t.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:()=>{f(!1),e.setThreadId(null),x.current?.focus()},"aria-label":b("assistant.newChat"),title:b("assistant.newChat"),children:t.jsx(zt,{"aria-hidden":!0})})]}),!l&&t.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:()=>e.setExpanded(!e.expanded),"aria-label":b(U?"assistant.collapse":"assistant.expand"),title:b(U?"assistant.collapse":"assistant.expand"),children:U?t.jsx(Ft,{"aria-hidden":!0}):t.jsx(Ht,{"aria-hidden":!0})}),t.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:F,"aria-label":b("assistant.close"),title:b("assistant.close"),children:t.jsx(Kt,{"aria-hidden":!0})})]}),t.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[a.state==="needs-consent"&&P("assistant.states.needsConsent"),a.state==="needs-key"&&P("assistant.states.needsKey"),h&&t.jsxs(t.Fragment,{children:[O&&t.jsx("div",{className:"px-4 pt-3",children:t.jsx("span",{className:"co-pill inline-flex max-w-full items-center px-2.5 py-0.5 text-xs font-medium",children:t.jsx("span",{className:"truncate",children:b("assistant.onPage",{page:O})})})}),t.jsx(Ys,{messages:o,proposals:c,surface:n,now:g,busy:T,onNavigate:j,onSend:v=>{$(v)},empty:E}),t.jsx(ms,{ref:x,streaming:k!==void 0,sending:e.sending,onSend:$,onStop:()=>k&&void e.stop(k._id)}
5),I&&t.jsx(hs,{surface:n,currentThreadId:e.threadId,onSelect:v=>{e.setThreadId(v),f(!1)},onDeleted:v=>{v===e.threadId&&e.setThreadId(null)},onClose:()=>f(!1)})]})]})]}),document.body)}const Me="chargeops-assistant-panel";function bn({userId:s,surface:e,availability:a}){const n=Ls(s,e),[,o]=Bt(),c=qt(),l=m.useRef(null),i=a.state==="ready",d=Wt(os),{windowExpanded:r}=Xt(),j=je(S.assistant.threads.get,i&&n.threadId?{threadId:n.threadId}:"skip"),{threadId:p,setThreadId:b}=n,u=j!=null&&j.thread.surface!==e;m.useEffect(()=>{p&&(j===null||u)&&b(null)},[p,j,u,b]);const g=u?void 0:j,I=g?.messages??[],f=g?.proposals??[],N=Qe(15e3),x=new Set(I.filter(E=>E.status==="done").map(E=>E._id)),h=f.some(E=>(E.status==="pending"||E.status==="failed")&&E.expiresAt>N&&x.has(E.messageId)),{toggle:k,setOpen:T}=n,U=m.useRef(n.open),F=m.useRef(n.open&&c);m.useEffect(()=>{F.current&&T(!1)},[]),n.open||(U.current=!1,F.current=!1);const D=m.useRef(d);D.current=d,m.useEffect(()=>{const E=()=>T(!0),P=O=>{D.current||(O.ctrlKey||O.metaKey)&&!O.altKey&&!O.shiftKey&&O.key.toLowerCase()==="j"&&(O.preventDefault(),k())};return window.addEventListener(Ee,E),window.addEventListener("keydown",P),()=>{window.removeEventListener(Ee,E),window.removeEventListener("keydown",P)}},[k,T]);const $=m.useCallback(E=>{o(E),c&&T(!1)},[o,c,T]);return t.jsxs(t.Fragment,{children:[t.jsx(ds,{ref:l,open:n.open,pending:h,hidden:d||r,onToggle:k,controls:Me}),n.open&&!F.current&&t.jsx(en,{id:Me,session:n,availability:a,surface:e,messages:I,proposals:f,isPhone:c,lowered:d,launcherRef:l,autoFocus:!U.current,onNavigate:$})]})}export{bn 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.