minerva-plexus-csd 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36278,7 +36278,7 @@ const X9 = ({
36278
36278
  } catch (t) {
36279
36279
  console.error("Error al cerrar sesión en el backend:", t);
36280
36280
  } finally {
36281
- Oe.remove("access_token", { path: "/" }), Oe.remove("auth_method", { path: "/" }), window.location.href = `${e}/login`;
36281
+ Oe.remove("access_token", { path: "/" }), Oe.remove("auth_method", { path: "/" });
36282
36282
  }
36283
36283
  }, or = {
36284
36284
  LOGIN: "/login",
@@ -36342,7 +36342,7 @@ const X9 = ({
36342
36342
  if (Oe.remove("access_token", { path: "/" }), Oe.remove("id_token", { path: "/" }), Oe.remove("auth_method", { path: "/" }), g(!1), C([]), j === "keycloak") {
36343
36343
  const V = B ? `${o}&id_token_hint=${encodeURIComponent(B)}` : o;
36344
36344
  window.location.replace(V);
36345
- } else j === "microsoft" ? window.location.replace(s) : (await Q9(), k(`${l}/login`));
36345
+ } else j === "microsoft" ? window.location.replace(s) : await Q9();
36346
36346
  } catch (j) {
36347
36347
  console.error("Logout failed", j);
36348
36348
  } finally {
@@ -1237,7 +1237,7 @@ Valid keys: `+JSON.stringify(Object.keys(L),null," "));var V=_e(ee,ae,Z,X,Q+"."
1237
1237
  padding-top: 19px;
1238
1238
  margin-bottom: 20px;
1239
1239
  box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.5);
1240
- `;const sD=({showHeader:e,customLogo:t,showDate:n,showCreateConversation:r,showControlButtons:a,className:i,showConversationTitle:o})=>{const s=!!t;return f.jsx(iD,{className:i,showHeader:e,hasCustomLogo:s,showCreateConversation:r,showDate:n,showConversationTitle:o,showControlButtons:a})},hS=R.createContext(void 0),bS=({children:e})=>{const[t,n]=R.useState([]),[r,a]=R.useState(!1),[i,o]=R.useState(!1),s=R.useRef(null),l=R.useRef(null),[u,c]=R.useState(!1),{preloadInteractions:d,typeWritterSpeed:g}=xf(),p=R.useRef(null),h=async m=>{try{a(!0);const b=(await p1(m)).map(v=>({...v}));d(b),n(v=>{const I=v.find(M=>M.pendingSync&&M.sender_type==="ai");if(!I)return b;const D=b.find(M=>M.sender_type==="ai"&&Math.abs(new Date(M.created_at).getTime()-new Date(I.created_at).getTime())<3e3);return D?b.map(M=>M.id===D.id?{...D,content:I.content}:M):b})}catch(x){console.error("Failed to fetch messages:",x)}finally{a(!1)}},y=async(m,x,b)=>{const v={id:`user-${new Date().toISOString()}`,content:x,sender_type:"user",conversation_id:m,created_at:new Date().toISOString()};n(M=>[...M,v].sort((P,B)=>new Date(P.created_at).getTime()-new Date(B.created_at).getTime()));const I=`bot-loading-${new Date().toISOString()}`;s.current=I;const D={id:I,content:"",loadingContent:f.jsx(ei,{}),sender_type:"ai",conversation_id:m,created_at:new Date().toISOString(),pendingSync:!0};n(M=>[...M,D].sort((P,B)=>new Date(P.created_at).getTime()-new Date(B.created_at).getTime())),a(!0),o(!0);const k=new AbortController;l.current=k,c(!0);try{const M=await f1(m,x,b,k.signal);if(!M)throw new Error("Error: La respuesta en streaming es nula.");const O=M.getReader();p.current=O;const P=new TextDecoder;let B="";for(;;){const{done:q,value:$}=await O.read();if(q)break;const W=P.decode($,{stream:!0});i&&o(!1),await Bd(W,g,H=>{B+=H,n(K=>K.map(w=>w.id===I?{...w,content:B,loadingContent:void 0}:w).sort((w,L)=>new Date(w.created_at).getTime()-new Date(L.created_at).getTime()))})}await h(m)}catch(M){M instanceof Error&&M.message.includes("cancel")?console.log("Stream cancelado por el usuario"):console.error("Error en el streaming del bot:",M)}finally{a(!1),c(!1),l.current=null,p.current=null,s.current=null}},A=async(m,x,b)=>{n(D=>{const k=D.findIndex(O=>O.id===x);return k===-1?D:[...D.slice(0,k),{...D[k],content:b,created_at:new Date().toISOString()}]});const v=`bot-edit-loading-${Date.now()}`;let I={id:v,content:"",loadingContent:f.jsx(ei,{}),sender_type:"ai",conversation_id:m,created_at:new Date().toISOString(),pendingSync:!0};n(D=>[...D,I]),a(!0);try{const k=(await g1(m,x,b)).getReader();p.current=k;const M=new TextDecoder;let O="";for(;;){const{done:P,value:B}=await k.read();if(P)break;const q=M.decode(B,{stream:!0});await Bd(q,g,$=>{O+=$,n(W=>W.map(H=>H.id===v?{...H,content:O,loadingContent:void 0}:H))})}await h(m)}catch(D){D instanceof Error&&D.message.includes("cancel")?console.log("Stream de edición cancelado por el usuario"):console.error("Error al editar mensaje y relanzar:",D)}finally{a(!1),c(!1),p.current=null,s.current=null}},T=async m=>{try{if(console.log("🔄 Intentando detener el stream desde MessageContext..."),l.current&&(l.current.abort(),l.current=null),s.current)try{await Tf.register(s.current,$t.STOP)}catch(x){console.warn("Error al cancelar el reader:",x)}return await Fd(m),console.log("AAA Stream detenido correctamente en el backend"),c(!1),a(!1),o(!1),console.log("✅ Stream detenido correctamente"),!0}catch(x){return console.error("❌ Error al detener el stream:",x),!1}},E=R.useMemo(()=>({messages:t,fetchMessages:h,addMessage:y,isBotWriting:r,isBotStreaming:u,isWaitingForFirstResponse:i,setIsWaitingForFirstResponse:o,currentBotMessageId:s.current,editAndReplayMessage:A,stopStreamingResponse:T}),[t,r,u,i]);return f.jsx(hS.Provider,{value:E,children:e})},oa=()=>{const e=R.useContext(hS);if(!e)throw new Error("useMessage must be used within a MessageProvider");return e},yS=R.createContext(void 0),lD=({children:e,initialConfig:t})=>{const[n]=R.useState({...ct(),...t});return f.jsx(yS.Provider,{value:n,children:e})},uD=()=>{const e=R.useContext(yS);if(!e)throw new Error("useApiConfig must be used within an ApiConfigProvider");return e},cD=async(e,t)=>{try{const n=await Md.login(e,t),r=n.access_token;if(!r)throw new Error("No access token found in response");return fe.set("access_token",r,{path:"/"}),n}catch(n){throw console.error("Error en la respuesta de login:",n),n}},dD=async()=>{const{loginRedirectPath:e}=At();try{await Md.logout()}catch(t){console.error("Error al cerrar sesión en el backend:",t)}finally{fe.remove("access_token",{path:"/"}),fe.remove("auth_method",{path:"/"}),window.location.href=`${e}/login`}},Er={LOGIN:"/login",DASHBOARD:"/",ONE_HELPER:"/minia",TWO_HELPER:"/uxia",THREE_HELPER:"/helia",FOUR_HELPER:"/iria",FIVE_HELPER:"/flavia",OPTIONS:"/options",DOCUMENTATION:"/documentation"},pD=async()=>await s1.getUserServices(),ES=R.createContext(void 0),fD=({children:e,callbackUrl:t,tokenUrl:n,clientId:r,clientSecret:a,keycloakUrl:i,keycloakLogoutUrl:o,microsoftLogoutUrl:s,loginRedirectPath:l=""})=>{const[u,c]=R.useState(!0),[d,g]=R.useState(!1),[p,h]=R.useState(!0),[y,A]=R.useState(!0),[T,E]=R.useState(!1),[m,x]=R.useState([]),[b,v]=R.useState(!1),I=kd.useNavigate(),D=`${i}/protocol/openid-connect/certs`,k=async()=>{c(!0);try{const q=await pD();if(!Array.isArray(q))throw new Error("Formato de datos incorrecto en fetchServices");x(q)}catch(q){console.error("Error en fetchServices:",q),x([])}finally{c(!1)}};R.useEffect(()=>{(async()=>{fe.get("access_token")?(g(!0),await k()):(g(!1),x([])),h(!1),A(!1)})()},[]);const M=async(q,$)=>{A(!0);try{const H=(await cD(q,$)).access_token;if(!H)throw new Error("No access token received");fe.set("access_token",H,{path:"/"}),fe.set("auth_method","both",{path:"/"}),g(!0),E(!0),await k(),I(`${l??""}${Er.DASHBOARD}`)}catch(W){console.error("Login failed:",W.message||W),g(!1),gn.fire({title:"Login Failed",text:W.message||"Ocurrió un problema al intentar iniciar sesión.",icon:"error",confirmButtonText:"OK"})}finally{A(!1)}},O=async()=>{v(!0);try{const q=fe.get("auth_method"),$=fe.get("id_token");if(fe.remove("access_token",{path:"/"}),fe.remove("id_token",{path:"/"}),fe.remove("auth_method",{path:"/"}),g(!1),x([]),q==="keycloak"){const W=$?`${o}&id_token_hint=${encodeURIComponent($)}`:o;window.location.replace(W)}else q==="microsoft"?window.location.replace(s):(await dD(),I(`${l}/login`))}catch(q){console.error("Logout failed",q)}finally{v(!1)}},P=async()=>{A(!0),fe.get("access_token")?(g(!0),await k()):(g(!1),x([])),h(!1),A(!1)},B=R.useMemo(()=>({isAuthenticated:d,loadingAuth:p,loadingData:y,login:M,logout:O,isManualLogin:T,setIsManualLogin:E,callbackUrl:t,tokenUrl:n,clientId:r,clientSecret:a,keycloakUrl:i,jwksUrl:D,updateAuth:P,keycloakLogoutUrl:o,microsoftLogoutUrl:s,services:m,fetchServices:k,loadingServices:u,isLoggingOut:b,loginRedirectPath:l}),[d,p,y,T,t,n,r,a,i,D,o,s,m,u,b,l]);return f.jsx(ES.Provider,{value:B,children:e})},At=()=>{const e=R.useContext(ES);if(!e)throw new Error("useAuth must be used within an AuthProvider");return e},gd=({enableAutoCreate:e,enableAutoCreateCsd:t,addConversation:n,selectConversation:r,service:a,conversations:i})=>{const{isAuthenticated:o,isManualLogin:s,setIsManualLogin:l}=At(),u=R.useRef(!1),c=async()=>{if(e&&o&&s&&i.length===0)try{const g=await n("New Conversation",a);g&&r(g.id,a),l(!1)}catch(g){console.error("Error creando la conversación:",g)}},d=R.useCallback(async()=>{if(t&&o&&!u.current){u.current=!0;try{const g=await n("New Conversation",a);g&&r(g.id,a)}catch(g){console.error("Error creando la conversación:",g)}}},[t,o,a,n,r]);return{autoCreateConversation:c,autoCreateConversationCsd:d}};var vS=(e=>(e.minia="Minia",e.uxia="Uxía",e.helia="Helia",e.iria="Iria",e.flavia="Flavia",e))(vS||{});const gD=({theme:e,customLogo:t,showDate:n=!0,showHeader:r=!0,createWhenLogin:a=!1,createWhenCsd:i=!1,showControlButtons:o=!0,chatVersion:s="full",className:l,showLogoutButton:u=!0,showCreateConversation:c=!0,showConversationTitle:d=!0,showPlexo:g=!0,showFeedbackButtons:p=!0,showeditIcon:h=!0})=>{const y=vS[e];console.log("theme que llega",e);const{addConversation:A,selectConversation:T,service:E,conversations:m}=hn();return gd({enableAutoCreate:a,enableAutoCreateCsd:i,addConversation:A,selectConversation:T,service:E,conversations:m}),f.jsx(bS,{children:s==="mini"?f.jsx(tD,{showeditIcon:h,showPlexo:g,showFeedbackButtons:p,showLogoutButton:u,showDate:n,customLogo:t,themeDisplayName:y,showHeader:r,showCreateConversation:c,showControlButtons:o,className:l,showConversationTitle:d}):f.jsx(sD,{showDate:n,customLogo:t,showHeader:r,showCreateConversation:c,showControlButtons:o,className:l,showConversationTitle:d})})},SS=`
1240
+ `;const sD=({showHeader:e,customLogo:t,showDate:n,showCreateConversation:r,showControlButtons:a,className:i,showConversationTitle:o})=>{const s=!!t;return f.jsx(iD,{className:i,showHeader:e,hasCustomLogo:s,showCreateConversation:r,showDate:n,showConversationTitle:o,showControlButtons:a})},hS=R.createContext(void 0),bS=({children:e})=>{const[t,n]=R.useState([]),[r,a]=R.useState(!1),[i,o]=R.useState(!1),s=R.useRef(null),l=R.useRef(null),[u,c]=R.useState(!1),{preloadInteractions:d,typeWritterSpeed:g}=xf(),p=R.useRef(null),h=async m=>{try{a(!0);const b=(await p1(m)).map(v=>({...v}));d(b),n(v=>{const I=v.find(M=>M.pendingSync&&M.sender_type==="ai");if(!I)return b;const D=b.find(M=>M.sender_type==="ai"&&Math.abs(new Date(M.created_at).getTime()-new Date(I.created_at).getTime())<3e3);return D?b.map(M=>M.id===D.id?{...D,content:I.content}:M):b})}catch(x){console.error("Failed to fetch messages:",x)}finally{a(!1)}},y=async(m,x,b)=>{const v={id:`user-${new Date().toISOString()}`,content:x,sender_type:"user",conversation_id:m,created_at:new Date().toISOString()};n(M=>[...M,v].sort((P,B)=>new Date(P.created_at).getTime()-new Date(B.created_at).getTime()));const I=`bot-loading-${new Date().toISOString()}`;s.current=I;const D={id:I,content:"",loadingContent:f.jsx(ei,{}),sender_type:"ai",conversation_id:m,created_at:new Date().toISOString(),pendingSync:!0};n(M=>[...M,D].sort((P,B)=>new Date(P.created_at).getTime()-new Date(B.created_at).getTime())),a(!0),o(!0);const k=new AbortController;l.current=k,c(!0);try{const M=await f1(m,x,b,k.signal);if(!M)throw new Error("Error: La respuesta en streaming es nula.");const O=M.getReader();p.current=O;const P=new TextDecoder;let B="";for(;;){const{done:q,value:$}=await O.read();if(q)break;const W=P.decode($,{stream:!0});i&&o(!1),await Bd(W,g,H=>{B+=H,n(K=>K.map(w=>w.id===I?{...w,content:B,loadingContent:void 0}:w).sort((w,L)=>new Date(w.created_at).getTime()-new Date(L.created_at).getTime()))})}await h(m)}catch(M){M instanceof Error&&M.message.includes("cancel")?console.log("Stream cancelado por el usuario"):console.error("Error en el streaming del bot:",M)}finally{a(!1),c(!1),l.current=null,p.current=null,s.current=null}},A=async(m,x,b)=>{n(D=>{const k=D.findIndex(O=>O.id===x);return k===-1?D:[...D.slice(0,k),{...D[k],content:b,created_at:new Date().toISOString()}]});const v=`bot-edit-loading-${Date.now()}`;let I={id:v,content:"",loadingContent:f.jsx(ei,{}),sender_type:"ai",conversation_id:m,created_at:new Date().toISOString(),pendingSync:!0};n(D=>[...D,I]),a(!0);try{const k=(await g1(m,x,b)).getReader();p.current=k;const M=new TextDecoder;let O="";for(;;){const{done:P,value:B}=await k.read();if(P)break;const q=M.decode(B,{stream:!0});await Bd(q,g,$=>{O+=$,n(W=>W.map(H=>H.id===v?{...H,content:O,loadingContent:void 0}:H))})}await h(m)}catch(D){D instanceof Error&&D.message.includes("cancel")?console.log("Stream de edición cancelado por el usuario"):console.error("Error al editar mensaje y relanzar:",D)}finally{a(!1),c(!1),p.current=null,s.current=null}},T=async m=>{try{if(console.log("🔄 Intentando detener el stream desde MessageContext..."),l.current&&(l.current.abort(),l.current=null),s.current)try{await Tf.register(s.current,$t.STOP)}catch(x){console.warn("Error al cancelar el reader:",x)}return await Fd(m),console.log("AAA Stream detenido correctamente en el backend"),c(!1),a(!1),o(!1),console.log("✅ Stream detenido correctamente"),!0}catch(x){return console.error("❌ Error al detener el stream:",x),!1}},E=R.useMemo(()=>({messages:t,fetchMessages:h,addMessage:y,isBotWriting:r,isBotStreaming:u,isWaitingForFirstResponse:i,setIsWaitingForFirstResponse:o,currentBotMessageId:s.current,editAndReplayMessage:A,stopStreamingResponse:T}),[t,r,u,i]);return f.jsx(hS.Provider,{value:E,children:e})},oa=()=>{const e=R.useContext(hS);if(!e)throw new Error("useMessage must be used within a MessageProvider");return e},yS=R.createContext(void 0),lD=({children:e,initialConfig:t})=>{const[n]=R.useState({...ct(),...t});return f.jsx(yS.Provider,{value:n,children:e})},uD=()=>{const e=R.useContext(yS);if(!e)throw new Error("useApiConfig must be used within an ApiConfigProvider");return e},cD=async(e,t)=>{try{const n=await Md.login(e,t),r=n.access_token;if(!r)throw new Error("No access token found in response");return fe.set("access_token",r,{path:"/"}),n}catch(n){throw console.error("Error en la respuesta de login:",n),n}},dD=async()=>{const{loginRedirectPath:e}=At();try{await Md.logout()}catch(t){console.error("Error al cerrar sesión en el backend:",t)}finally{fe.remove("access_token",{path:"/"}),fe.remove("auth_method",{path:"/"})}},Er={LOGIN:"/login",DASHBOARD:"/",ONE_HELPER:"/minia",TWO_HELPER:"/uxia",THREE_HELPER:"/helia",FOUR_HELPER:"/iria",FIVE_HELPER:"/flavia",OPTIONS:"/options",DOCUMENTATION:"/documentation"},pD=async()=>await s1.getUserServices(),ES=R.createContext(void 0),fD=({children:e,callbackUrl:t,tokenUrl:n,clientId:r,clientSecret:a,keycloakUrl:i,keycloakLogoutUrl:o,microsoftLogoutUrl:s,loginRedirectPath:l=""})=>{const[u,c]=R.useState(!0),[d,g]=R.useState(!1),[p,h]=R.useState(!0),[y,A]=R.useState(!0),[T,E]=R.useState(!1),[m,x]=R.useState([]),[b,v]=R.useState(!1),I=kd.useNavigate(),D=`${i}/protocol/openid-connect/certs`,k=async()=>{c(!0);try{const q=await pD();if(!Array.isArray(q))throw new Error("Formato de datos incorrecto en fetchServices");x(q)}catch(q){console.error("Error en fetchServices:",q),x([])}finally{c(!1)}};R.useEffect(()=>{(async()=>{fe.get("access_token")?(g(!0),await k()):(g(!1),x([])),h(!1),A(!1)})()},[]);const M=async(q,$)=>{A(!0);try{const H=(await cD(q,$)).access_token;if(!H)throw new Error("No access token received");fe.set("access_token",H,{path:"/"}),fe.set("auth_method","both",{path:"/"}),g(!0),E(!0),await k(),I(`${l??""}${Er.DASHBOARD}`)}catch(W){console.error("Login failed:",W.message||W),g(!1),gn.fire({title:"Login Failed",text:W.message||"Ocurrió un problema al intentar iniciar sesión.",icon:"error",confirmButtonText:"OK"})}finally{A(!1)}},O=async()=>{v(!0);try{const q=fe.get("auth_method"),$=fe.get("id_token");if(fe.remove("access_token",{path:"/"}),fe.remove("id_token",{path:"/"}),fe.remove("auth_method",{path:"/"}),g(!1),x([]),q==="keycloak"){const W=$?`${o}&id_token_hint=${encodeURIComponent($)}`:o;window.location.replace(W)}else q==="microsoft"?window.location.replace(s):await dD()}catch(q){console.error("Logout failed",q)}finally{v(!1)}},P=async()=>{A(!0),fe.get("access_token")?(g(!0),await k()):(g(!1),x([])),h(!1),A(!1)},B=R.useMemo(()=>({isAuthenticated:d,loadingAuth:p,loadingData:y,login:M,logout:O,isManualLogin:T,setIsManualLogin:E,callbackUrl:t,tokenUrl:n,clientId:r,clientSecret:a,keycloakUrl:i,jwksUrl:D,updateAuth:P,keycloakLogoutUrl:o,microsoftLogoutUrl:s,services:m,fetchServices:k,loadingServices:u,isLoggingOut:b,loginRedirectPath:l}),[d,p,y,T,t,n,r,a,i,D,o,s,m,u,b,l]);return f.jsx(ES.Provider,{value:B,children:e})},At=()=>{const e=R.useContext(ES);if(!e)throw new Error("useAuth must be used within an AuthProvider");return e},gd=({enableAutoCreate:e,enableAutoCreateCsd:t,addConversation:n,selectConversation:r,service:a,conversations:i})=>{const{isAuthenticated:o,isManualLogin:s,setIsManualLogin:l}=At(),u=R.useRef(!1),c=async()=>{if(e&&o&&s&&i.length===0)try{const g=await n("New Conversation",a);g&&r(g.id,a),l(!1)}catch(g){console.error("Error creando la conversación:",g)}},d=R.useCallback(async()=>{if(t&&o&&!u.current){u.current=!0;try{const g=await n("New Conversation",a);g&&r(g.id,a)}catch(g){console.error("Error creando la conversación:",g)}}},[t,o,a,n,r]);return{autoCreateConversation:c,autoCreateConversationCsd:d}};var vS=(e=>(e.minia="Minia",e.uxia="Uxía",e.helia="Helia",e.iria="Iria",e.flavia="Flavia",e))(vS||{});const gD=({theme:e,customLogo:t,showDate:n=!0,showHeader:r=!0,createWhenLogin:a=!1,createWhenCsd:i=!1,showControlButtons:o=!0,chatVersion:s="full",className:l,showLogoutButton:u=!0,showCreateConversation:c=!0,showConversationTitle:d=!0,showPlexo:g=!0,showFeedbackButtons:p=!0,showeditIcon:h=!0})=>{const y=vS[e];console.log("theme que llega",e);const{addConversation:A,selectConversation:T,service:E,conversations:m}=hn();return gd({enableAutoCreate:a,enableAutoCreateCsd:i,addConversation:A,selectConversation:T,service:E,conversations:m}),f.jsx(bS,{children:s==="mini"?f.jsx(tD,{showeditIcon:h,showPlexo:g,showFeedbackButtons:p,showLogoutButton:u,showDate:n,customLogo:t,themeDisplayName:y,showHeader:r,showCreateConversation:c,showControlButtons:o,className:l,showConversationTitle:d}):f.jsx(sD,{showDate:n,customLogo:t,showHeader:r,showCreateConversation:c,showControlButtons:o,className:l,showConversationTitle:d})})},SS=`
1241
1241
  <h2>POLÍTICA DE PRIVACIDAD PARA CHATBOT</h2>
1242
1242
 
1243
1243
  <h3>1. RESPONSABLE DEL TRATAMIENTO</h3>
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "minerva-plexus-csd",
3
3
  "private": false,
4
4
  "description": "A reusable chat logic library for React applications",
5
- "version": "1.0.0",
5
+ "version": "1.0.1",
6
6
  "main": "dist/minerva-plexus-csd.umd.js",
7
7
  "module": "dist/minerva-plexus-csd.es.js",
8
8
  "types": "dist/index.d.ts",
@@ -52,7 +52,6 @@
52
52
  "js-cookie": "^3.0.5",
53
53
  "jwt-decode": "^4.0.0",
54
54
  "minerva-components-library": "^2.1.19",
55
-
56
55
  "react-bootstrap": "^2.10.4",
57
56
  "react-i18next": "^15.0.1",
58
57
  "react-markdown": "^9.0.1",