PageSourceSearch

https://www.politeianet.gr/assets/AssistantWidget.yb8MCRQd.js

js politeianet.gr collected 2026-09-24 09:27:58 UTC 14,028 bytes, 3 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/assistant-api.pSD5qG5h.js","assets/axios.MS0w9iSV.js","assets/common--ubEBI-f.ivqnILd6.js"])))=>i.map(i=>d[i]);
2import{_ as J,a as z,b as X,U as Y,r as c,u as tt,P as f,d as H,j as n,L as et,e as st,f as O,S as at}from"./index-KDcLenRU.js";import{u as nt}from"./useEscapeKey.4T-pTQ7a.js";import{t as rt}from"./toGreekCaps.1t_UCRL0.js";const it=e=>{let t="",s="",a=[];const l=()=>{a.length>0&&e({event:s||"message",data:a.join(`
3`)}),s="",a=[]},r=d=>{if(d===""){l();return}if(d.startsWith(":"))return;const p=d.indexOf(":"),x=p===-1?d:d.slice(0,p);let v=p===-1?"":d.slice(p+1);switch(v.startsWith(" ")&&(v=v.slice(1)),x){case"event":s=v;break;case"data":a.push(v);break}};return{push:d=>{t+=d;const p=t.split(/\r\n|\r|\n/);t=p.pop()??"",p.forEach(r)},end:()=>{t="",s="",a=[]}}};class L extends Error{constructor(t,s){super(`Assistant request failed: ${t} ${s}`),this.name="AssistantHttpError",this.status=t,this.code=s}}class D extends Error{constructor(t){super(t||"assistant_unavailable"),this.name="AssistantStreamError"}}const Q=e=>{switch(e){case 503:return"assistant_unavailable";case 429:return"rate_limited";case 400:return"bad_request";case 404:return"conversation_not_found";default:return"http_error"}},ot=()=>{const e={"Content-Type":"application/json"},t=Y.getAccessToken();return t&&(e.Authorization="Bearer "+t),e},ct=async(e,t)=>{var l;const{AssistantApi:s}=await J(async()=>{const{AssistantApi:r}=await import("./assistant-api.pSD5qG5h.js");return{AssistantApi:r}},__vite__mapDeps([0,1,2])),a=new s(void 0,void 0,z);try{const r=await a.chat(e,{signal:t,doNotParseError:!0}),d=(r==null?void 0:r.data)??{};return{text:d.text??"",conversationId:d.conversationId??null,incomplete:d.incomplete===!0,toolTrace:d.toolTrace??[]}}catch(r){throw(l=r==null?void 0:r.response)!=null&&l.status?new L(r.response.status,Q(r.response.status)):r}},B=async(e,{signal:t,onConversation:s,onToken:a,onTool:l}={})=>{const r=await fetch(X()+"/assistant/chatstream",{method:"POST",headers:ot(),body:JSON.stringify(e),signal:t});if(!r.ok)throw new L(r.status,Q(r.status));if(!(r.headers.get("content-type")??"").includes("text/event-stream")){const h=await r.json(),A=(h==null?void 0:h.text)??"",o=(h==null?void 0:h.conversationId)??null;return o&&(s==null||s(o)),A&&(a==null||a(A)),{text:A,incomplete:(h==null?void 0:h.incomplete)===!0,conversationId:o}}let p="",x=!1,v=null,S=!1,w=null;const k=it(({event:h,data:A})=>{let o;try{o=JSON.parse(A)}catch{return}switch(h){case"conversation":o!=null&&o.conversationId&&(v=o.conversationId,s==null||s(o.conversationId));break;case"token":typeof(o==null?void 0:o.text)=="string"&&o.text&&(p+=o.text,a==null||a(o.text));break;case"tool":o!=null&&o.tool&&(l==null||l(o.tool,o.outcome??""));break;case"done":S=!0,x=(o==null?void 0:o.incomplete)===!0;break;case"error":w=new D(o==null?void 0:o.error);break}});if(r.body){const h=r.body.getReader(),A=new TextDecoder;try{for(;;){const{value:o,done:R}=await h.read();if(R||(k.push(A.decode(o,{stream:!0})),w))break}}finally{h.cancel().catch(()=>{})}}else k.push(await r.text());if(k.end(),w)throw w;if(!S)throw new D("stream_interrupted");return{text:p,incomplete:x,conversationId:v}},lt=new Set(["add_to_cart","update_cart_item","remove_cart_item"]),ut=20,dt=15e3;let ht=1;const K=()=>`am-${ht++}`,pt=e=>{let s=e.filter(a=>{var l;return(a.role==="user"||a.role==="assistant")&&((l=a.text)==null?void 0:l.trim())}).map(a=>({role:a.role,text:a.text})).slice(-ut);for(;s.length>0&&s[0].role!=="user";)s=s.slice(1);return s},ft=()=>{const[e,t]=c.useState([]),[s,a]=c.useState("idle"),[l,r]=c.useState(null),[d,p]=c.useState(null),[x,v]=c.useState(null),S=tt(),w=c.useRef(null),k=c.useRef(!1),h=c.useRef(null),A=c.useRef(e);c.useEffect(()=>{A.current=e},[e]),c.useEffect(()=>()=>{var u;(u=w.current)==null||u.abort(),h.current&&clearTimeout(h.current)},[]);const o=c.useCallback((u,N)=>{t(i=>i.map(m=>m.id===u?{...m,...N}:m))},[]),R=c.useCallback(u=>{t(N=>N.filter(i=>i.id!==u))},[]),T=c.useCallback(()=>{r("rate_limited"),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>r(u=>u==="rate_limited"?null:u),dt)},[]),I=c.useCallback(u=>{const N=u==null?void 0:u.trim();if(!N||k.current)return;k.current=!0,r(null),p(null),a("busy");const i={id:K(),role:"user",text:N},m=K(),G=[...A.current,i];t(g=>[...g,i,{id:m,role:"assistant",text:"",pending:!0}]);const P=new AbortController;w.current=P;let W=!1;(async()=>{const g={signal:P.signal,onConversation:_=>v(_),onToken:_=>{p(null),a("streaming"),t(b=>b.map(E=>E.id===m?{...E,text:E.text+_,pending:!1}:E))},onTool:(_,b)=>{p(_),b==="Executed"&&(_==="place_order"&&(W=!0),lt.has(_)&&(S.invalidateQueries({queryKey:["sync-auth-cart"]}
3),S.invalidateQueries({queryKey:["cart"]}),S.invalidateQueries({queryKey:["cart-totals"]})))}},j=pt(G);try{return await B({messages:j,conversationId:x},g)}catch(_){if(_ instanceof L&&_.code==="bad_request"&&j.length>1){const b=[{role:"user",text:N}];if(x)try{return await B({messages:b,conversationId:x,useServerHistory:!0},g)}catch(E){if(!(E instanceof L)||E.code!=="conversation_not_found"&&E.code!=="bad_request")throw E}return await B({messages:b,conversationId:x},g)}if(_ instanceof L&&_.code==="http_error"){const b=await ct({messages:j,conversationId:x},P.signal);return b.conversationId&&v(b.conversationId),b.text&&g.onToken(b.text),b}throw _}})().then(g=>{var j;if(!((j=g.text)!=null&&j.trim())){R(m),r("unavailable");return}o(m,{pending:!1,incomplete:g.incomplete===!0}),W&&t(_=>[..._,{id:K(),role:"notice",noticeType:"order_email",text:""}])}).catch(g=>{t(j=>{const _=j.find(y=>y.id===m),b=!!(_!=null&&_.text);if((g==null?void 0:g.name)==="AbortError"||P.signal.aborted)return b?j.map(y=>y.id===m?{...y,pending:!1,incomplete:!0,stopped:!0}:y):j.filter(y=>y.id!==m);if(g instanceof L)return g.code==="rate_limited"?T():g.code==="assistant_unavailable"?r("unavailable"):g.code==="bad_request"?r("too_long"):r("network"),j.filter(y=>y.id!==m);const E=g instanceof D&&g.message!=="stream_interrupted";return r(E?"unavailable":"network"),b?j.map(y=>y.id===m?{...y,pending:!1,incomplete:!0}:y):j.filter(y=>y.id!==m)})}).finally(()=>{k.current=!1,w.current=null,p(null),a("idle")})},[x,T,o,R,S]),q=c.useCallback(()=>{var u;return(u=w.current)==null?void 0:u.abort()},[]),C=c.useCallback(()=>{r(u=>u==="rate_limited"?u:null)},[]),M=c.useCallback(()=>{var u;(u=w.current)==null||u.abort(),t([]),v(null),r(null),p(null)},[]);return{messages:e,status:s,error:l,toolActivity:d,conversationId:x,send:I,stop:q,clearError:C,restart:M}},mt=e=>c.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round",...e},c.createElement("path",{d:"M12 3a8.6 8.6 0 0 1 8.7 8.5c0 4.7-3.9 8.5-8.7 8.5a8.9 8.9 0 0 1-3.3-.63L3.6 20.7l1.3-3.77A8.36 8.36 0 0 1 3.3 11.5 8.6 8.6 0 0 1 12 3Z"}),c.createElement("path",{d:"M12 8.4c-.95-.85-2.45-1-3.6-.42v5.6c1.15-.58 2.65-.43 3.6.42.95-.85 2.45-1 3.6-.42v-5.6c-1.15-.58-2.65-.43-3.6.42Z"}),c.createElement("path",{d:"M12 8.4v5.6"})),gt=e=>c.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round",...e},c.createElement("path",{d:"M20.5 3.5 10 14"}),c.createElement("path",{d:"M20.5 3.5 13.7 20.5l-3.7-6.5L3.5 10.3Z"})),_t=/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,xt=/https?:\/\/[^\s<>()"']+/g,bt=e=>{let t=e.length;for(;t>0&&".,;:!?»”’".includes(e[t-1]);)t-=1;return{href:e.slice(0,t),rest:e.slice(t)}},U=(e,t)=>{if(!t)return;let s=0;for(const a of t.matchAll(xt)){a.index>s&&e.push({type:"text",text:t.slice(s,a.index)});const{href:l,rest:r}=bt(a[0]);e.push({type:"link",label:l,href:l}),r&&e.push({type:"text",text:r}),s=a.index+a[0].length}s<t.length&&e.push({type:"text",text:t.slice(s)})},yt=e=>{if(!e)return[];const t=[];let s=0;for(const a of e.matchAll(_t))U(t,e.slice(s,a.index)),t.push({type:"link",label:a[1],href:a[2]}),s=a.index+a[0].length;return U(t,e.slice(s)),t},F=["localhost","127.0.0.1"],vt=()=>{var t;const e=new Set([window.location.host]);for(const s of["VITE_APP_BIZWEB_FRONT_URL","VITE_APP_URL"]){const a=(t=globalThis.__BW_ENV__)==null?void 0:t[s];if(a)try{e.add(new URL(a).host)}catch{}}return e},wt=(e,t=vt())=>{try{const s=new URL(e);if(s.protocol!=="http:"&&s.protocol!=="https:")return null;const a=F.includes(s.hostname)&&F.includes(window.location.hostname);return!t.has(s.host)&&!a?null:s.pathname+s.search+s.hash}catch{return null}},V=({segment:e})=>{const t=wt(e.href);return t?n.jsx(et,{to:t,children:e.label}):n.jsx("a",{href:e.href,target:"_blank",rel:"noopener noreferrer",children:e.label})};V.propTypes={segment:f.shape({href:f.string.isRequired,label:f.string.isRequired}).isRequired};const Z=({message:e,isStreaming:t})=>{const{t:s}=H();return e.role==="notice"?n.jsx("div",{className:"assistant-entry notice",role:"note",children:e.noticeType==="order_email"?s("assistant.order_email_notice"):e.text}):e.role==="user"?n.jsx("div",{className:"assistant-entry user",children:e.text}):n.jsx("div",{className:"assistant-entry assistant",children:e.pending?n.jsxs("span",{className:"assistant-thinking","aria-label":s("assistant.thinking"),children:[n.jsx("span",{}),n.jsx("span",{}),n.jsx("span",{})]}):n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"entry-text",children:[yt(e.text).map((a,l)=>a.type==="link"?n.jsx(V,{segment:a},l):n.jsx(c.Fragment,{children:a.text},l)),t&&n.jsx("span",{className:"assistant-caret","aria-hidden":"true"})]}),e.incomplete&&!t&&n.jsx("span",{className:"entry-flag",children:e.stopped?s("assistant.stopped"):s("assistant.incomplete")}
3)]})})};Z.propTypes={message:f.shape({id:f.string.isRequired,role:f.oneOf(["user","assistant","notice"]).isRequired,text:f.string,pending:f.bool,incomplete:f.bool,stopped:f.bool,noticeType:f.string}).isRequired,isStreaming:f.bool};const jt=e=>{switch(e){case"search_products":return"assistant.tool_search";case"get_product":case"get_category":case"get_categories_tree":case"get_content_page":return"assistant.tool_lookup";case"get_cart":case"add_to_cart":case"update_cart_item":case"remove_cart_item":return"assistant.tool_cart";case"place_order":return"assistant.tool_order";case"get_my_orders":case"get_order_detail":return"assistant.tool_orders";default:return"assistant.tool_generic"}},At=e=>{switch(e){case"unavailable":return"assistant.err_unavailable";case"rate_limited":return"assistant.err_rate_limited";case"too_long":return"assistant.err_too_long";default:return"assistant.err_network"}},$=({chat:e})=>{const{t}=H(),s=st(),a=O(i=>i.closeAssistant),l=O(i=>i.openLoginModal),{messages:r,status:d,error:p,toolActivity:x,send:v,stop:S,restart:w}=e,[k,h]=c.useState(""),[A,o]=c.useState(""),R=c.useRef(null),T=c.useRef(null),I=c.useRef(d);nt(a),c.useEffect(()=>{var i;(i=R.current)==null||i.focus()},[]),c.useEffect(()=>{const i=T.current;i&&(i.scrollTop=i.scrollHeight)},[r,x,p]),c.useEffect(()=>{if(I.current!=="idle"&&d==="idle"){const i=[...r].reverse().find(m=>m.role==="assistant"&&m.text);i&&o(i.text)}I.current=d},[d,r]);const q=d!=="idle",C=!k.trim()||q||p==="rate_limited",M=()=>{C||(v(k),h(""),R.current&&(R.current.style.height="auto",R.current.focus()))},u=i=>{h(i.target.value),i.target.style.height="auto",i.target.style.height=`${Math.min(i.target.scrollHeight,96)}px`},N=i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),M())};return n.jsxs("section",{className:"assistant-panel",role:"dialog","aria-label":t("assistant.title"),children:[n.jsxs("header",{className:"assistant-header",children:[n.jsxs("div",{className:"heading",children:[n.jsx("h2",{children:rt(t("assistant.title"))}),n.jsx("p",{children:t("assistant.subtitle")})]}),r.length>0&&n.jsx("button",{type:"button",className:"assistant-restart",onClick:w,children:t("assistant.restart")}),n.jsx("button",{type:"button",className:"assistant-close",onClick:a,"aria-label":t("assistant.close"),children:n.jsx(at,{})})]}),n.jsxs("div",{className:"assistant-messages",ref:T,tabIndex:-1,children:[r.length===0&&n.jsxs("div",{className:"assistant-empty",children:[n.jsx("p",{className:"greeting",children:t("assistant.greeting")}),!s&&n.jsxs("p",{className:"guest-hint",children:[t("assistant.guest_hint")," ",n.jsx("button",{type:"button",onClick:()=>l("assistant"),children:t("assistant.guest_login")})]})]}),r.map((i,m)=>n.jsx(Z,{message:i,isStreaming:d==="streaming"&&m===r.length-1&&i.role==="assistant"},i.id)),x&&n.jsx("p",{className:"assistant-activity",role:"status",children:t(jt(x))}),p&&n.jsxs("div",{className:"assistant-error",role:"alert",children:[n.jsx("span",{children:t(At(p))}),p==="too_long"&&n.jsx("button",{type:"button",onClick:w,children:t("assistant.restart")})]})]}),n.jsxs("form",{className:"assistant-composer",onSubmit:i=>{i.preventDefault(),M()},children:[n.jsx("textarea",{ref:R,rows:1,value:k,placeholder:t("assistant.placeholder"),"aria-label":t("assistant.placeholder"),onChange:u,onKeyDown:N}),q?n.jsx("button",{type:"button",className:"assistant-stop",onClick:S,"aria-label":t("assistant.stop"),children:n.jsx("span",{className:"stop-square","aria-hidden":"true"})}):n.jsx("button",{type:"submit",className:"assistant-send",disabled:C,"aria-label":t("assistant.send"),children:n.jsx(gt,{})})]}),n.jsx("p",{className:"assistant-disclaimer",children:t("assistant.disclaimer")}),n.jsx("div",{className:"visually-hidden",role:"status","aria-live":"polite",children:A})]})};$.propTypes={chat:f.shape({messages:f.array.isRequired,status:f.string.isRequired,error:f.string,toolActivity:f.string,send:f.func.isRequired,stop:f.func.isRequired,restart:f.func.isRequired}).isRequired};const Nt=()=>{const{t:e}=H(),t=O(l=>l.assistantOpen),s=O(l=>l.toggleAssistant),a=ft();return n.jsxs("div",{className:"assistant-widget",children:[t&&n.jsx($,{chat:a}),n.jsx("button",{type:"button",className:"assistant-launcher",onClick:s,"aria-expanded":t,"aria-label":e("assistant.title"),children:n.jsx(mt,{})})]})};export{Nt 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.