minerva-plexus-csd 1.0.7 → 1.0.8
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.
|
@@ -1025,8 +1025,8 @@ const K9 = (e) => {
|
|
|
1025
1025
|
children: e,
|
|
1026
1026
|
enableAutoCreate: t = !1,
|
|
1027
1027
|
enableAutoCreateCsd: n = !1,
|
|
1028
|
-
serviceTicketing: r = !
|
|
1029
|
-
serviceTicketingNoUSer: a = !
|
|
1028
|
+
serviceTicketing: r = !0,
|
|
1029
|
+
serviceTicketingNoUSer: a = !0
|
|
1030
1030
|
}) => {
|
|
1031
1031
|
const { service: i } = Iy(), [o, s] = ge({}), [l, u] = ge(null), c = async () => {
|
|
1032
1032
|
if (i)
|
|
@@ -27,7 +27,7 @@ Check the top-level render call using <`+Q+">.")}return j}}function vS(k,j){{if(
|
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,rd,Xt,fD,Xt),wS[Xt+rd]=!0}}return k===a?lD(Ne):sD(Ne),Ne}}function uD(k,j,Q){return TS(k,j,Q,!0)}function cD(k,j,Q){return TS(k,j,Q,!1)}var dD=cD,pD=uD;An.Fragment=a,An.jsx=dD,An.jsxs=pD}(),An}var kS={};kS.NODE_ENV==="production"?$r.exports=AS():$r.exports=_S();var f=$r.exports;const jr=({enableAutoCreate:e,enableAutoCreateCsd:t,addConversation:n,selectConversation:r,service:a,conversations:i})=>{const o=_.useRef(!1);return{autoCreateConversationCsd:_.useCallback(async()=>{if(t&&!o.current){o.current=!0;try{const l=await n("New Conversation",a);l&&r(l.id,a)}catch(l){console.error("Error creando la conversación:",l)}}},[t,a,n,r])}};var od=(e=>(e.minia="Minia",e.uxia="Uxía",e.helia="Helia",e.iria="Iria",e.flavia="Flavia",e))(od||{});const sd={API_URL:"http://dev-chatbot-drupal.plexus.tech:8311",API_KEY:"ai"};let Lt={apiUrl:"",apiKey:""};const RS=e=>{Lt={...Lt,...e}},Qe=()=>(Lt.apiUrl||(console.warn("[Minerva] apiUrl no configurado. Usando valor por defecto."),Lt.apiUrl=sd.API_URL),Lt.apiKey||(console.warn("[Minerva] apiKey no configurado. Usando valor por defecto."),Lt.apiKey=sd.API_KEY),Lt),IS=e=>{},Je=async(e,t={})=>{const{apiUrl:n}=Qe(),r={"Content-Type":"application/json",...t.headers||{}},a=e.startsWith("http")?e:`${n.replace(/\/$/,"")}/${e.replace(/^\//,"")}`;try{const i=await fetch(a,{...t,headers:r});if(i.status===401){console.warn("INVALID ACCESS");return}if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return i}catch(i){throw console.error("Fetch failed:",i),i}},Dt={CONVERSATIONS_CREATE:"/conversations",USER_CONVERSATIONS:"/conversations/user",CONVERSATION_MESSAGES:"/messages/conversation",DELETE_CONVERSATION:"/conversations/delete/",GET_MESSAGES_BY_CONVERSATION_ID:"/messages/conversation",SEND_MESSAGE:"/bot/user_request_stream"},nr={getMessagesByConversationId:async e=>{const{apiUrl:t}=Qe(),n=await Je(`${t}${Dt.GET_MESSAGES_BY_CONVERSATION_ID}/${e}?conversation_id=${e}`,{method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}});if(!n)throw new Error("Failed to fetch messages: No response from server (possible redirection).");if(!n.ok)throw new Error(`Failed to fetch messages. Status: ${n.status}`);return await n.json()},sendMessage:async(e,t)=>{const{apiUrl:n}=Qe(),r=await Je(`${n}${Dt.SEND_MESSAGE}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversation:{id:e},text:t})});if(!r)throw new Error("Failed to send message: No response from server.");if(!r.ok)throw new Error(`Failed to send message. Status: ${r.status}`);return await r.json()},stopBotStream:async e=>{const{apiUrl:t}=Qe(),n=`${t}/bot/stop_request_stream?conversation_id=${e}`;console.log("Enviando petición para detener el stream al endpoint:",n),console.log("Conversación ID:",e);try{const r=await Je(n,{method:"POST",headers:{"Content-Type":"application/json"}});if(!r)throw console.error("No se recibió respuesta del servidor"),new Error("No se recibió respuesta del servidor al intentar detener el stream");if(!r.ok){const a=await r.text().catch(()=>"No se pudo leer el error");throw console.error(`Error del servidor (${r.status}):`,a),new Error(`Error al detener el stream: ${r.status}`)}console.log("Backend confirmó detención del stream");return}catch(r){throw console.error("Error al detener el stream:",r),r}},sendMessageStreaming:async(e,t,n,r)=>{const{apiUrl:a}=Qe(),i={conversation:{id:e},text:t,service:n},o=await Je(`${a}${Dt.SEND_MESSAGE}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i),signal:r});if(!o)throw new Error("Failed to send message streaming: No response from server.");if(!o.ok){let s;try{s=await o.json()}catch{s="No JSON response available"}throw console.error("Error details from server:",s),new Error(`Failed to send message streaming. Status: ${o.status}`)}if(!o.body)throw new Error(" No body in response");return o.body},editMessageAndResend:async({conversationId:e,messageId:t,text:n})=>{const a=await Je("/bot/edit_request_stream",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversation:{id:e},message_id:t,text:n})});if(!a)throw new Error("Failed to send message streaming: No response from server.");if(!a.ok){let i;try{i=await a.json()}catch{i="No JSON response available"}throw console.error("Error details from server:",i),new Error(`Failed to send message streaming. Status: ${a.status}`)}if(!a.body)throw new Error(" No body in response");return a.body}},NS=async e=>(await nr.getMessagesByConversationId(e)).map(a=>({...a,conversation_id:e})).slice().sort((a,i)=>new Date(a.created_at).getTime()-new Date(i.created_at).getTime()),OS=async(e,t,n,r)=>await nr.sendMessageStreaming(e,t,n),ld=async e=>{console.log(`Solicitando detener el stream para la conversación: ${e}`);try{console.log("Enviando solicitud para detener el stream al backend..."),await nr.stopBotStream(e),console.log(`✅ Solicitud de detención enviada correctamente para conversación: ${e}`)}catch(t){throw console.error(`❌ Error al solicitar detención del stream para conversación ${e}:`,t),t}},LS=async(e,t,n)=>await nr.editMessageAndResend({conversationId:e,messageId:t,text:n}),ud=(e,t,n)=>new Promise(r=>{let a=0;const i=1,o=setInterval(()=>{if(a<e.length){const s=e.slice(a,a+i);n(s),a+=i}else clearInterval(o),r()},t)}),qr={createConversation:async(e,t)=>{if(!t)throw new Error("Service is required to create a conversation.");const{apiUrl:n}=Qe(),r=`${n}${Dt.CONVERSATIONS_CREATE}/?service=${encodeURIComponent(t)}${e?`&title=${encodeURIComponent(e)}`:""}`,a=await Je(r,{method:"POST",mode:"cors",headers:{"Content-Type":"application/x-www-form-urlencoded"}});if(!a)throw new Error("Failed to create conversation: No response from server.");if(!a.ok)throw new Error(`Failed to create conversation. Status: ${a.status}`);return await a.json()},getUserConversations:async e=>{const{apiUrl:t}=Qe(),n=await Je(`${t}${Dt.USER_CONVERSATIONS}?service=${e}`,{method:"GET"});if(!n)throw new Error("Failed to fetch user conversations: No response from server.");if(!n.ok)throw new Error(`Failed to fetch user conversations. Status: ${n.status}`);return await n.json()},getConversationById:async(e,t)=>{const{apiUrl:n}=Qe(),r=await Je(`${n}${Dt.CONVERSATION_MESSAGES}/${e}?service=${t}`,{method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}});if(!r)throw new Error("Failed to fetch conversation by ID: No response from server.");if(!r.ok)throw new Error(`Failed to fetch conversation by ID. Status: ${r.status}`);return await r.json()},deleteConversationById:async(e,t)=>{const{apiUrl:n}=Qe(),r=await Je(`${n}${Dt.DELETE_CONVERSATION}${e}?conversation_id=${e}&service=${t}`,{method:"POST"});if(!r)throw new Error("Failed to delete conversation: No response from server.");if(!r.ok)throw new Error(`Failed to delete conversation with ID: ${e}. Status: ${r.status}`)}},DS=async(e,t)=>{try{return await qr.createConversation(e,t)}catch(n){throw console.error("Error creating conversation:",n),n}},MS=async e=>await qr.getUserConversations(e),FS=async(e,t)=>await qr.deleteConversationById(e,t),cd=_.createContext(void 0),PS=({children:e,usedService:t})=>{const[n,r]=_.useState(t??"CsdInteraccion"),a=_.useMemo(()=>({service:n,setService:r}),[n]);return f.jsx(cd.Provider,{value:a,children:e})},Gr=()=>{const e=_.useContext(cd);if(!e)throw new Error("useService must be used within ServiceProvider");return e},dd=_.createContext(void 0),US=({children:e,enableAutoCreate:t=!1,enableAutoCreateCsd:n=!1,serviceTicketing:r=!
|
|
30
|
+
<%s key={someKey} {...props} />`,rd,Xt,fD,Xt),wS[Xt+rd]=!0}}return k===a?lD(Ne):sD(Ne),Ne}}function uD(k,j,Q){return TS(k,j,Q,!0)}function cD(k,j,Q){return TS(k,j,Q,!1)}var dD=cD,pD=uD;An.Fragment=a,An.jsx=dD,An.jsxs=pD}(),An}var kS={};kS.NODE_ENV==="production"?$r.exports=AS():$r.exports=_S();var f=$r.exports;const jr=({enableAutoCreate:e,enableAutoCreateCsd:t,addConversation:n,selectConversation:r,service:a,conversations:i})=>{const o=_.useRef(!1);return{autoCreateConversationCsd:_.useCallback(async()=>{if(t&&!o.current){o.current=!0;try{const l=await n("New Conversation",a);l&&r(l.id,a)}catch(l){console.error("Error creando la conversación:",l)}}},[t,a,n,r])}};var od=(e=>(e.minia="Minia",e.uxia="Uxía",e.helia="Helia",e.iria="Iria",e.flavia="Flavia",e))(od||{});const sd={API_URL:"http://dev-chatbot-drupal.plexus.tech:8311",API_KEY:"ai"};let Lt={apiUrl:"",apiKey:""};const RS=e=>{Lt={...Lt,...e}},Qe=()=>(Lt.apiUrl||(console.warn("[Minerva] apiUrl no configurado. Usando valor por defecto."),Lt.apiUrl=sd.API_URL),Lt.apiKey||(console.warn("[Minerva] apiKey no configurado. Usando valor por defecto."),Lt.apiKey=sd.API_KEY),Lt),IS=e=>{},Je=async(e,t={})=>{const{apiUrl:n}=Qe(),r={"Content-Type":"application/json",...t.headers||{}},a=e.startsWith("http")?e:`${n.replace(/\/$/,"")}/${e.replace(/^\//,"")}`;try{const i=await fetch(a,{...t,headers:r});if(i.status===401){console.warn("INVALID ACCESS");return}if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return i}catch(i){throw console.error("Fetch failed:",i),i}},Dt={CONVERSATIONS_CREATE:"/conversations",USER_CONVERSATIONS:"/conversations/user",CONVERSATION_MESSAGES:"/messages/conversation",DELETE_CONVERSATION:"/conversations/delete/",GET_MESSAGES_BY_CONVERSATION_ID:"/messages/conversation",SEND_MESSAGE:"/bot/user_request_stream"},nr={getMessagesByConversationId:async e=>{const{apiUrl:t}=Qe(),n=await Je(`${t}${Dt.GET_MESSAGES_BY_CONVERSATION_ID}/${e}?conversation_id=${e}`,{method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}});if(!n)throw new Error("Failed to fetch messages: No response from server (possible redirection).");if(!n.ok)throw new Error(`Failed to fetch messages. Status: ${n.status}`);return await n.json()},sendMessage:async(e,t)=>{const{apiUrl:n}=Qe(),r=await Je(`${n}${Dt.SEND_MESSAGE}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversation:{id:e},text:t})});if(!r)throw new Error("Failed to send message: No response from server.");if(!r.ok)throw new Error(`Failed to send message. Status: ${r.status}`);return await r.json()},stopBotStream:async e=>{const{apiUrl:t}=Qe(),n=`${t}/bot/stop_request_stream?conversation_id=${e}`;console.log("Enviando petición para detener el stream al endpoint:",n),console.log("Conversación ID:",e);try{const r=await Je(n,{method:"POST",headers:{"Content-Type":"application/json"}});if(!r)throw console.error("No se recibió respuesta del servidor"),new Error("No se recibió respuesta del servidor al intentar detener el stream");if(!r.ok){const a=await r.text().catch(()=>"No se pudo leer el error");throw console.error(`Error del servidor (${r.status}):`,a),new Error(`Error al detener el stream: ${r.status}`)}console.log("Backend confirmó detención del stream");return}catch(r){throw console.error("Error al detener el stream:",r),r}},sendMessageStreaming:async(e,t,n,r)=>{const{apiUrl:a}=Qe(),i={conversation:{id:e},text:t,service:n},o=await Je(`${a}${Dt.SEND_MESSAGE}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i),signal:r});if(!o)throw new Error("Failed to send message streaming: No response from server.");if(!o.ok){let s;try{s=await o.json()}catch{s="No JSON response available"}throw console.error("Error details from server:",s),new Error(`Failed to send message streaming. Status: ${o.status}`)}if(!o.body)throw new Error(" No body in response");return o.body},editMessageAndResend:async({conversationId:e,messageId:t,text:n})=>{const a=await Je("/bot/edit_request_stream",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversation:{id:e},message_id:t,text:n})});if(!a)throw new Error("Failed to send message streaming: No response from server.");if(!a.ok){let i;try{i=await a.json()}catch{i="No JSON response available"}throw console.error("Error details from server:",i),new Error(`Failed to send message streaming. Status: ${a.status}`)}if(!a.body)throw new Error(" No body in response");return a.body}},NS=async e=>(await nr.getMessagesByConversationId(e)).map(a=>({...a,conversation_id:e})).slice().sort((a,i)=>new Date(a.created_at).getTime()-new Date(i.created_at).getTime()),OS=async(e,t,n,r)=>await nr.sendMessageStreaming(e,t,n),ld=async e=>{console.log(`Solicitando detener el stream para la conversación: ${e}`);try{console.log("Enviando solicitud para detener el stream al backend..."),await nr.stopBotStream(e),console.log(`✅ Solicitud de detención enviada correctamente para conversación: ${e}`)}catch(t){throw console.error(`❌ Error al solicitar detención del stream para conversación ${e}:`,t),t}},LS=async(e,t,n)=>await nr.editMessageAndResend({conversationId:e,messageId:t,text:n}),ud=(e,t,n)=>new Promise(r=>{let a=0;const i=1,o=setInterval(()=>{if(a<e.length){const s=e.slice(a,a+i);n(s),a+=i}else clearInterval(o),r()},t)}),qr={createConversation:async(e,t)=>{if(!t)throw new Error("Service is required to create a conversation.");const{apiUrl:n}=Qe(),r=`${n}${Dt.CONVERSATIONS_CREATE}/?service=${encodeURIComponent(t)}${e?`&title=${encodeURIComponent(e)}`:""}`,a=await Je(r,{method:"POST",mode:"cors",headers:{"Content-Type":"application/x-www-form-urlencoded"}});if(!a)throw new Error("Failed to create conversation: No response from server.");if(!a.ok)throw new Error(`Failed to create conversation. Status: ${a.status}`);return await a.json()},getUserConversations:async e=>{const{apiUrl:t}=Qe(),n=await Je(`${t}${Dt.USER_CONVERSATIONS}?service=${e}`,{method:"GET"});if(!n)throw new Error("Failed to fetch user conversations: No response from server.");if(!n.ok)throw new Error(`Failed to fetch user conversations. Status: ${n.status}`);return await n.json()},getConversationById:async(e,t)=>{const{apiUrl:n}=Qe(),r=await Je(`${n}${Dt.CONVERSATION_MESSAGES}/${e}?service=${t}`,{method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}});if(!r)throw new Error("Failed to fetch conversation by ID: No response from server.");if(!r.ok)throw new Error(`Failed to fetch conversation by ID. Status: ${r.status}`);return await r.json()},deleteConversationById:async(e,t)=>{const{apiUrl:n}=Qe(),r=await Je(`${n}${Dt.DELETE_CONVERSATION}${e}?conversation_id=${e}&service=${t}`,{method:"POST"});if(!r)throw new Error("Failed to delete conversation: No response from server.");if(!r.ok)throw new Error(`Failed to delete conversation with ID: ${e}. Status: ${r.status}`)}},DS=async(e,t)=>{try{return await qr.createConversation(e,t)}catch(n){throw console.error("Error creating conversation:",n),n}},MS=async e=>await qr.getUserConversations(e),FS=async(e,t)=>await qr.deleteConversationById(e,t),cd=_.createContext(void 0),PS=({children:e,usedService:t})=>{const[n,r]=_.useState(t??"CsdInteraccion"),a=_.useMemo(()=>({service:n,setService:r}),[n]);return f.jsx(cd.Provider,{value:a,children:e})},Gr=()=>{const e=_.useContext(cd);if(!e)throw new Error("useService must be used within ServiceProvider");return e},dd=_.createContext(void 0),US=({children:e,enableAutoCreate:t=!1,enableAutoCreateCsd:n=!1,serviceTicketing:r=!0,serviceTicketingNoUSer:a=!0})=>{const{service:i}=Gr(),[o,s]=_.useState({}),[l,u]=_.useState(null),c=async()=>{if(i)try{const T=await MS(i);s(S=>({...S,[i]:T})),!l&&T.length>0&&!n&&u(T[T.length-1])}catch(T){console.error("❌ Error al obtener conversaciones:",T)}};_.useEffect(()=>{i&&c()},[i]);const d=async(T,S)=>{try{const E=await DS(T,S);return s(m=>({...m,[S]:[...m[S]||[],E]})),u(E),E}catch(E){throw console.error("Failed to create conversation:",E),E}},g=async(T,S)=>{if(S)try{await FS(T,S),s(E=>({...E,[S]:(E[S]||[]).filter(m=>m.id!==T)})),u(null)}catch(E){console.error("Failed to delete conversation:",E)}},p=async(T,S)=>{const m=(o[S??""]||[]).find(A=>A.id===T);m&&(l!=null&&l.id&&await ld(l==null?void 0:l.id),u(m))},{autoCreateConversationCsd:h}=jr({enableAutoCreate:t,enableAutoCreateCsd:n,addConversation:d,selectConversation:p,service:i,conversations:o[i]||[]});_.useEffect(()=>{n&&h()},[h]);const v=_.useMemo(()=>({conversations:o[i]||[],fetchConversations:c,addConversation:d,removeConversation:g,selectConversation:p,selectedConversation:l,selectedConversationId:(l==null?void 0:l.id)??null,service:i,serviceTicketing:r,serviceTicketingNoUSer:a}),[o,l,i,r,a]);return f.jsx(dd.Provider,{value:v,children:e})},Mt=()=>{const e=_.useContext(dd);if(!e)throw new Error("useConversation must be used within a ConversationProvider");return e};D.div.attrs({className:"row"})`
|
|
31
31
|
display: flex;
|
|
32
32
|
flex-wrap: wrap;
|
|
33
33
|
margin-right: -8px;
|
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.
|
|
5
|
+
"version": "1.0.8",
|
|
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",
|