minerva-plexus-csd 1.1.25 → 1.1.27
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.
|
@@ -690,36 +690,32 @@ const BD = (e) => {
|
|
|
690
690
|
}, Qn = async (e, t = {}) => {
|
|
691
691
|
const { apiUrl: n } = it(), r = jb.get("access_token"), a = {
|
|
692
692
|
...t.headers || {}
|
|
693
|
-
// "Content-Type": "application/json", // Comenta temporalmente; ajusta a Postman (quizá sin o form)
|
|
694
693
|
};
|
|
695
694
|
r ? (a.Authorization = `Bearer ${r}`, console.log(
|
|
696
|
-
"
|
|
697
|
-
a.Authorization.
|
|
698
|
-
)) : console.warn("
|
|
695
|
+
"Authorization header OK:",
|
|
696
|
+
a.Authorization.slice(0, 30) + "..."
|
|
697
|
+
)) : console.warn("Token no encontrado en cookies.");
|
|
699
698
|
const i = e.startsWith("http") ? e : `${n.replace(/\/$/, "")}/${e.replace(/^\//, "")}`;
|
|
700
699
|
try {
|
|
701
700
|
const o = await fetch(i, {
|
|
702
701
|
...t,
|
|
703
|
-
credentials: "include",
|
|
704
|
-
// Añade para cookies cross-origin si necesario
|
|
705
702
|
headers: a
|
|
706
703
|
});
|
|
707
|
-
if (console.log("
|
|
704
|
+
if (console.log("Response:", {
|
|
708
705
|
status: o.status,
|
|
709
|
-
url:
|
|
710
|
-
|
|
706
|
+
url: o.url,
|
|
707
|
+
ok: o.ok
|
|
711
708
|
}), o.status === 401) {
|
|
712
|
-
console.warn("Token expired or invalid according to server.");
|
|
713
709
|
const s = await o.text();
|
|
714
|
-
console.
|
|
710
|
+
console.warn("401 Unauthorized:", s);
|
|
715
711
|
}
|
|
716
712
|
if (!o.ok) {
|
|
717
713
|
const s = await o.text();
|
|
718
|
-
throw
|
|
714
|
+
throw new Error(`HTTP error ${o.status}: ${s}`);
|
|
719
715
|
}
|
|
720
716
|
return o;
|
|
721
717
|
} catch (o) {
|
|
722
|
-
throw console.error("Fetch failed
|
|
718
|
+
throw console.error("Fetch failed:", o), o;
|
|
723
719
|
}
|
|
724
720
|
}, at = async (e, t = {}) => {
|
|
725
721
|
const { apiUrl: n } = it(), r = {
|
|
@@ -731,12 +727,19 @@ const BD = (e) => {
|
|
|
731
727
|
...t,
|
|
732
728
|
headers: r
|
|
733
729
|
});
|
|
734
|
-
if (
|
|
735
|
-
|
|
730
|
+
if (console.log("Response:", {
|
|
731
|
+
status: i.status,
|
|
732
|
+
url: i.url,
|
|
733
|
+
ok: i.ok
|
|
734
|
+
}), i.status === 401) {
|
|
735
|
+
const o = await i.text();
|
|
736
|
+
console.warn("401 Unauthorized (fetchWithoutAuth):", o);
|
|
736
737
|
return;
|
|
737
738
|
}
|
|
738
|
-
if (!i.ok)
|
|
739
|
-
|
|
739
|
+
if (!i.ok) {
|
|
740
|
+
const o = await i.text();
|
|
741
|
+
throw new Error(`HTTP error ${i.status}: ${o}`);
|
|
742
|
+
}
|
|
740
743
|
return i;
|
|
741
744
|
} catch (i) {
|
|
742
745
|
throw console.error("Fetch failed:", i), i;
|
|
@@ -967,31 +970,25 @@ const BD = (e) => {
|
|
|
967
970
|
createConversation: async (e, t, n) => {
|
|
968
971
|
if (!t)
|
|
969
972
|
throw new Error("Service is required to create a conversation.");
|
|
970
|
-
const { apiUrl: r } = it(), a = `${r}${Wt.CONVERSATIONS_CREATE}/?service=${encodeURIComponent(t)}${e ? `&title=${encodeURIComponent(e)}` : ""}`,
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
s ? `Sí (token: ${s.substring(0, 20)}...)` : "No (token no encontrado)"
|
|
974
|
-
);
|
|
975
|
-
const u = await (n ? Qn : at)(a, {
|
|
973
|
+
const { apiUrl: r } = it(), a = `${r}${Wt.CONVERSATIONS_CREATE}/?service=${encodeURIComponent(t)}${e ? `&title=${encodeURIComponent(e)}` : ""}`, i = n ? Qn : at, o = {};
|
|
974
|
+
n || (o["Content-Type"] = "application/x-www-form-urlencoded");
|
|
975
|
+
const s = await i(a, {
|
|
976
976
|
method: "POST",
|
|
977
|
-
|
|
978
|
-
headers: {
|
|
979
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
980
|
-
}
|
|
977
|
+
headers: o
|
|
981
978
|
});
|
|
982
979
|
if (console.log("Respuesta al crear conversación:", {
|
|
983
|
-
status:
|
|
984
|
-
ok:
|
|
985
|
-
url:
|
|
986
|
-
}), !
|
|
980
|
+
status: s.status,
|
|
981
|
+
ok: s.ok,
|
|
982
|
+
url: s.url
|
|
983
|
+
}), !s)
|
|
987
984
|
throw new Error(
|
|
988
985
|
"Failed to create conversation: No response from server."
|
|
989
986
|
);
|
|
990
|
-
if (!
|
|
987
|
+
if (!s.ok)
|
|
991
988
|
throw new Error(
|
|
992
|
-
`Failed to create conversation. Status: ${
|
|
989
|
+
`Failed to create conversation. Status: ${s.status}`
|
|
993
990
|
);
|
|
994
|
-
return await
|
|
991
|
+
return await s.json();
|
|
995
992
|
},
|
|
996
993
|
/**
|
|
997
994
|
* Obtiene todas las conversaciones del usuario con opción de paginación.
|
|
@@ -1001,32 +998,28 @@ const BD = (e) => {
|
|
|
1001
998
|
* @returns {Promise<Conversation[]>} Promesa que resuelve con una lista de conversaciones.
|
|
1002
999
|
*/
|
|
1003
1000
|
getUserConversations: async (e, t) => {
|
|
1004
|
-
const { apiUrl: n } = it();
|
|
1005
|
-
|
|
1006
|
-
const
|
|
1007
|
-
console.log(
|
|
1008
|
-
"Intentando obtener conversaciones de usuario con token de cookies:",
|
|
1009
|
-
i ? `Sí (token: ${i.substring(0, 20)}...)` : "No (token no encontrado)"
|
|
1010
|
-
);
|
|
1011
|
-
const s = await (t ? Qn : at)(
|
|
1001
|
+
const { apiUrl: n } = it(), r = t ? Qn : at, a = {};
|
|
1002
|
+
t || (a["Content-Type"] = "application/x-www-form-urlencoded");
|
|
1003
|
+
const i = await r(
|
|
1012
1004
|
`${n}${Wt.USER_CONVERSATIONS}?service=${e}`,
|
|
1013
1005
|
{
|
|
1014
|
-
method: "GET"
|
|
1006
|
+
method: "GET",
|
|
1007
|
+
headers: a
|
|
1015
1008
|
}
|
|
1016
1009
|
);
|
|
1017
1010
|
if (console.log("Respuesta al obtener conversaciones de usuario:", {
|
|
1018
|
-
status:
|
|
1019
|
-
ok:
|
|
1020
|
-
url:
|
|
1021
|
-
}), !
|
|
1011
|
+
status: i.status,
|
|
1012
|
+
ok: i.ok,
|
|
1013
|
+
url: i.url
|
|
1014
|
+
}), !i)
|
|
1022
1015
|
throw new Error(
|
|
1023
1016
|
"Failed to fetch user conversations: No response from server."
|
|
1024
1017
|
);
|
|
1025
|
-
if (!
|
|
1018
|
+
if (!i.ok)
|
|
1026
1019
|
throw new Error(
|
|
1027
|
-
`Failed to fetch user conversations. Status: ${
|
|
1020
|
+
`Failed to fetch user conversations. Status: ${i.status}`
|
|
1028
1021
|
);
|
|
1029
|
-
return await
|
|
1022
|
+
return await i.json();
|
|
1030
1023
|
},
|
|
1031
1024
|
/**
|
|
1032
1025
|
* Obtiene una conversación específica por ID.
|
|
@@ -1037,33 +1030,28 @@ const BD = (e) => {
|
|
|
1037
1030
|
* @returns {Promise<Conversation>} Promesa que resuelve con la conversación obtenida.
|
|
1038
1031
|
*/
|
|
1039
1032
|
getConversationById: async (e, t, n) => {
|
|
1040
|
-
const { apiUrl: r } = it(),
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
o ? `Sí (token: ${o.substring(0, 20)}...)` : "No (token no encontrado)"
|
|
1044
|
-
);
|
|
1045
|
-
const l = await (n ? Qn : at)(
|
|
1033
|
+
const { apiUrl: r } = it(), a = n ? Qn : at, i = {};
|
|
1034
|
+
n || (i["Content-Type"] = "application/x-www-form-urlencoded");
|
|
1035
|
+
const o = await a(
|
|
1046
1036
|
`${r}${Wt.CONVERSATION_MESSAGES}/${e}?service=${t}`,
|
|
1047
1037
|
{
|
|
1048
1038
|
method: "GET",
|
|
1049
|
-
headers:
|
|
1050
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
1051
|
-
}
|
|
1039
|
+
headers: i
|
|
1052
1040
|
}
|
|
1053
1041
|
);
|
|
1054
1042
|
if (console.log("Respuesta al obtener conversación por ID:", {
|
|
1055
|
-
status:
|
|
1056
|
-
ok:
|
|
1057
|
-
url:
|
|
1058
|
-
}), !
|
|
1043
|
+
status: o.status,
|
|
1044
|
+
ok: o.ok,
|
|
1045
|
+
url: o.url
|
|
1046
|
+
}), !o)
|
|
1059
1047
|
throw new Error(
|
|
1060
1048
|
"Failed to fetch conversation by ID: No response from server."
|
|
1061
1049
|
);
|
|
1062
|
-
if (!
|
|
1050
|
+
if (!o.ok)
|
|
1063
1051
|
throw new Error(
|
|
1064
|
-
`Failed to fetch conversation by ID. Status: ${
|
|
1052
|
+
`Failed to fetch conversation by ID. Status: ${o.status}`
|
|
1065
1053
|
);
|
|
1066
|
-
return await
|
|
1054
|
+
return await o.json();
|
|
1067
1055
|
},
|
|
1068
1056
|
/**
|
|
1069
1057
|
* Elimina una conversación por ID.
|
|
@@ -1075,28 +1063,26 @@ const BD = (e) => {
|
|
|
1075
1063
|
* @throws {Error}
|
|
1076
1064
|
*/
|
|
1077
1065
|
deleteConversationById: async (e, t, n) => {
|
|
1078
|
-
const { apiUrl: r } = it(),
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
o ? `Sí (token: ${o.substring(0, 20)}...)` : "No (token no encontrado)"
|
|
1082
|
-
);
|
|
1083
|
-
const l = await (n ? Qn : at)(
|
|
1066
|
+
const { apiUrl: r } = it(), a = n ? Qn : at, i = {};
|
|
1067
|
+
n || (i["Content-Type"] = "application/x-www-form-urlencoded");
|
|
1068
|
+
const o = await a(
|
|
1084
1069
|
`${r}${Wt.DELETE_CONVERSATION}${e}?conversation_id=${e}&service=${t}`,
|
|
1085
1070
|
{
|
|
1086
|
-
method: "POST"
|
|
1071
|
+
method: "POST",
|
|
1072
|
+
headers: i
|
|
1087
1073
|
}
|
|
1088
1074
|
);
|
|
1089
1075
|
if (console.log("Respuesta al eliminar conversación:", {
|
|
1090
|
-
status:
|
|
1091
|
-
ok:
|
|
1092
|
-
url:
|
|
1093
|
-
}), !
|
|
1076
|
+
status: o.status,
|
|
1077
|
+
ok: o.ok,
|
|
1078
|
+
url: o.url
|
|
1079
|
+
}), !o)
|
|
1094
1080
|
throw new Error(
|
|
1095
1081
|
"Failed to delete conversation: No response from server."
|
|
1096
1082
|
);
|
|
1097
|
-
if (!
|
|
1083
|
+
if (!o.ok)
|
|
1098
1084
|
throw new Error(
|
|
1099
|
-
`Failed to delete conversation with ID: ${e}. Status: ${
|
|
1085
|
+
`Failed to delete conversation with ID: ${e}. Status: ${o.status}`
|
|
1100
1086
|
);
|
|
1101
1087
|
}
|
|
1102
1088
|
}, Zv = async (e, t, n) => {
|
|
@@ -27,7 +27,7 @@ Check the top-level render call using <`+J+">.")}return j}}function wv(_,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} />`,Nc,Wt,xL,Wt),Tv[Wt+Nc]=!0}}return _===a?vL(Re):yL(Re),Re}}function SL(_,j,J){return xv(_,j,J,!0)}function wL(_,j,J){return xv(_,j,J,!1)}var CL=wL,TL=SL;En.Fragment=a,En.jsx=CL,En.jsxs=TL}(),En}var Rv={};Rv.NODE_ENV==="production"?_r.exports=_v():_r.exports=kv();var g=_r.exports;const kr=({enableAutoCreate:e,enableAutoCreateCsd:t,addConversation:n,selectConversation:r,service:a,conversations:i})=>{const o=I.useRef(!1);return{autoCreateConversationCsd:I.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 Mc=(e=>(e.minia="Minia",e.uxia="Uxía",e.helia="Helia",e.iria="Iria",e.flavia="Flavia",e))(Mc||{});const Pc={API_URL:"http://dev-chatbot-dad.plexus.tech:8311",API_KEY:"ai"};var Fc={};let it={apiUrl:"",apiKey:""};const Iv=e=>{it={...it,...e},Fc.NODE_ENV!=="production"&&console.log("apiConfig seteada desde host:",it)},Ve=()=>{if(it.apiUrl=it.apiUrl||void 0||Pc.API_URL,it.apiKey=it.apiKey||void 0||Pc.API_KEY,Fc.NODE_ENV!=="production"&&console.log("API URL retornada por getApiConfig:",it.apiUrl),!it.apiUrl){const e="[Minerva] apiUrl no configurado. Requerido para operación.";throw console.error(e),new Error(e)}return it.apiKey||console.warn("[Minerva] apiKey no configurado. Usando valor por defecto."),it},Nv=e=>{},Vn=async(e,t={})=>{const{apiUrl:n}=Ve(),r=Oc.get("access_token"),a={...t.headers||{}};r?(a.Authorization=`Bearer ${r}`,console.log("Header Authorization agregado:",a.Authorization.substring(0,30)+"...")):console.warn("No token encontrado en cookies para fetchWithAuth");const i=e.startsWith("http")?e:`${n.replace(/\/$/,"")}/${e.replace(/^\//,"")}`;try{const o=await fetch(i,{...t,credentials:"include",headers:a});if(console.log("Respuesta raw de fetchWithAuth:",{status:o.status,url:i,headersSent:JSON.stringify(a)}),o.status===401){console.warn("Token expired or invalid according to server.");const s=await o.text();console.error("Error body from server:",s)}if(!o.ok){const s=await o.text();throw console.error("Error body:",s),new Error(`HTTP error! status: ${o.status} - ${s}`)}return o}catch(o){throw console.error("Fetch failed (network or CORS?):",o),o}},Xe=async(e,t={})=>{const{apiUrl:n}=Ve(),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}},Lt={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"},Wn={getMessagesByConversationId:async e=>{const{apiUrl:t}=Ve(),n=await Xe(`${t}${Lt.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}=Ve(),r=await Xe(`${n}${Lt.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}`);if(r.status===201)debugger;return await r.json()},stopBotStream:async e=>{const{apiUrl:t}=Ve(),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 Xe(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")}catch(r){throw console.error("Error al detener el stream:",r),r}},sendMessageStreaming:async(e,t,n,r)=>{const{apiUrl:a}=Ve(),i={conversation:{id:e},text:t,service:n},o=await Xe(`${a}${Lt.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.status!==200&&o.status!==201){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}, Details: ${JSON.stringify(s)}`)}if(!o.body)throw new Error("No body in response");return o},editMessageAndResend:async({conversationId:e,messageId:t,text:n})=>{const a=await Xe("/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}, Details: ${JSON.stringify(i)}`)}if(!a.body)throw new Error("No body in response");return a}},Ov=async e=>(await Wn.getMessagesByConversationId(e)).map(a=>({...a,conversation_id:e})).slice().sort((a,i)=>new Date(a.created_at).getTime()-new Date(i.created_at).getTime()),Lv=async(e,t,n,r)=>await Wn.sendMessageStreaming(e,t,n,r),Uc=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 Wn.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}},Dv=async(e,t,n)=>await Wn.editMessageAndResend({conversationId:e,messageId:t,text:n}),Bc=(e,t,n)=>new Promise(r=>{let a=0;const i=10,o=setInterval(()=>{if(a<e.length){const s=e.slice(a,a+i);n(s),a+=i}else clearInterval(o),r()},t)}),Rr={createConversation:async(e,t,n)=>{if(!t)throw new Error("Service is required to create a conversation.");const{apiUrl:r}=Ve(),a=`${r}${Lt.CONVERSATIONS_CREATE}/?service=${encodeURIComponent(t)}${e?`&title=${encodeURIComponent(e)}`:""}`,o=document.cookie.split("; ").find(d=>d.startsWith("access_token=")),s=o?o.split("=")[1]:null;console.log("Intentando crear conversación con token de cookies:",s?`Sí (token: ${s.substring(0,20)}...)`:"No (token no encontrado)");const u=await(n?Vn:Xe)(a,{method:"POST",mode:"cors",headers:{"Content-Type":"application/x-www-form-urlencoded"}});if(console.log("Respuesta al crear conversación:",{status:u.status,ok:u.ok,url:u.url}),!u)throw new Error("Failed to create conversation: No response from server.");if(!u.ok)throw new Error(`Failed to create conversation. Status: ${u.status}`);return await u.json()},getUserConversations:async(e,t)=>{const{apiUrl:n}=Ve();console.log("isNotDrupal:",t);const a=document.cookie.split("; ").find(u=>u.startsWith("access_token=")),i=a?a.split("=")[1]:null;console.log("Intentando obtener conversaciones de usuario con token de cookies:",i?`Sí (token: ${i.substring(0,20)}...)`:"No (token no encontrado)");const s=await(t?Vn:Xe)(`${n}${Lt.USER_CONVERSATIONS}?service=${e}`,{method:"GET"});if(console.log("Respuesta al obtener conversaciones de usuario:",{status:s.status,ok:s.ok,url:s.url}),!s)throw new Error("Failed to fetch user conversations: No response from server.");if(!s.ok)throw new Error(`Failed to fetch user conversations. Status: ${s.status}`);return await s.json()},getConversationById:async(e,t,n)=>{const{apiUrl:r}=Ve(),i=document.cookie.split("; ").find(c=>c.startsWith("access_token=")),o=i?i.split("=")[1]:null;console.log("Intentando obtener conversación por ID con token de cookies:",o?`Sí (token: ${o.substring(0,20)}...)`:"No (token no encontrado)");const l=await(n?Vn:Xe)(`${r}${Lt.CONVERSATION_MESSAGES}/${e}?service=${t}`,{method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}});if(console.log("Respuesta al obtener conversación por ID:",{status:l.status,ok:l.ok,url:l.url}),!l)throw new Error("Failed to fetch conversation by ID: No response from server.");if(!l.ok)throw new Error(`Failed to fetch conversation by ID. Status: ${l.status}`);return await l.json()},deleteConversationById:async(e,t,n)=>{const{apiUrl:r}=Ve(),i=document.cookie.split("; ").find(u=>u.startsWith("access_token=")),o=i?i.split("=")[1]:null;console.log("Intentando eliminar conversación con token de cookies:",o?`Sí (token: ${o.substring(0,20)}...)`:"No (token no encontrado)");const l=await(n?Vn:Xe)(`${r}${Lt.DELETE_CONVERSATION}${e}?conversation_id=${e}&service=${t}`,{method:"POST"});if(console.log("Respuesta al eliminar conversación:",{status:l.status,ok:l.ok,url:l.url}),!l)throw new Error("Failed to delete conversation: No response from server.");if(!l.ok)throw new Error(`Failed to delete conversation with ID: ${e}. Status: ${l.status}`)}},Mv=async(e,t,n)=>{try{return await Rr.createConversation(e,t)}catch(r){throw console.error("Error creating conversation:",r),r}},Pv=async(e,t)=>await Rr.getUserConversations(e,t),Fv=async(e,t,n)=>await Rr.deleteConversationById(e,t),$c=I.createContext(void 0),Uv=({children:e,usedService:t})=>{const[n,r]=I.useState(t??"CsdInteraccion"),a=I.useMemo(()=>({service:n,setService:r}),[n]);return g.jsx($c.Provider,{value:a,children:e})},Ir=()=>{const e=I.useContext($c);if(!e)throw new Error("useService must be used within ServiceProvider");return e},jc=I.createContext(void 0),Bv=({children:e,enableAutoCreate:t=!1,enableAutoCreateCsd:n=!1,serviceTicketing:r=!0,isNotDrupal:a=!0,serviceTicketingNoUSer:i=!0})=>{const{service:o}=Ir(),[s,l]=I.useState({}),[u,c]=I.useState(null),d=async()=>{if(o)try{const T=await Pv(o,a);l(E=>({...E,[o]:T})),!u&&T.length>0&&!n&&c(T[T.length-1])}catch(T){console.error("❌ Error al obtener conversaciones:",T)}};I.useEffect(()=>{o&&d()},[o]);const f=async(T,E)=>{try{const m=await Mv(T,E,a);return l(x=>({...x,[E]:[...x[E]||[],m]})),c(m),m}catch(m){throw console.error("Failed to create conversation:",m),m}},p=async(T,E)=>{if(E)try{await Fv(T,E,a),l(m=>({...m,[E]:(m[E]||[]).filter(x=>x.id!==T)})),c(null)}catch(m){console.error("Failed to delete conversation:",m)}},y=async(T,E)=>{const x=(s[E??""]||[]).find(h=>h.id===T);x&&(u!=null&&u.id&&await Uc(u==null?void 0:u.id),c(x))},{autoCreateConversationCsd:S}=kr({enableAutoCreate:t,enableAutoCreateCsd:n,addConversation:f,selectConversation:y,service:o,conversations:s[o]||[]});I.useEffect(()=>{n&&S()},[S]);const A=I.useMemo(()=>({conversations:s[o]||[],fetchConversations:d,addConversation:f,removeConversation:p,selectConversation:y,selectedConversation:u,selectedConversationId:(u==null?void 0:u.id)??null,service:o,serviceTicketing:r,isNotDrupal:a,serviceTicketingNoUSer:i}),[s,u,o,r,a,i]);return g.jsx(jc.Provider,{value:A,children:e})},Yt=()=>{const e=I.useContext(jc);if(!e)throw new Error("useConversation must be used within a ConversationProvider");return e};L.div.attrs({className:"row"})`
|
|
30
|
+
<%s key={someKey} {...props} />`,Nc,Wt,xL,Wt),Tv[Wt+Nc]=!0}}return _===a?vL(Re):yL(Re),Re}}function SL(_,j,J){return xv(_,j,J,!0)}function wL(_,j,J){return xv(_,j,J,!1)}var CL=wL,TL=SL;En.Fragment=a,En.jsx=CL,En.jsxs=TL}(),En}var Rv={};Rv.NODE_ENV==="production"?_r.exports=_v():_r.exports=kv();var g=_r.exports;const kr=({enableAutoCreate:e,enableAutoCreateCsd:t,addConversation:n,selectConversation:r,service:a,conversations:i})=>{const o=I.useRef(!1);return{autoCreateConversationCsd:I.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 Mc=(e=>(e.minia="Minia",e.uxia="Uxía",e.helia="Helia",e.iria="Iria",e.flavia="Flavia",e))(Mc||{});const Pc={API_URL:"http://dev-chatbot-dad.plexus.tech:8311",API_KEY:"ai"};var Fc={};let it={apiUrl:"",apiKey:""};const Iv=e=>{it={...it,...e},Fc.NODE_ENV!=="production"&&console.log("apiConfig seteada desde host:",it)},Ve=()=>{if(it.apiUrl=it.apiUrl||void 0||Pc.API_URL,it.apiKey=it.apiKey||void 0||Pc.API_KEY,Fc.NODE_ENV!=="production"&&console.log("API URL retornada por getApiConfig:",it.apiUrl),!it.apiUrl){const e="[Minerva] apiUrl no configurado. Requerido para operación.";throw console.error(e),new Error(e)}return it.apiKey||console.warn("[Minerva] apiKey no configurado. Usando valor por defecto."),it},Nv=e=>{},Vn=async(e,t={})=>{const{apiUrl:n}=Ve(),r=Oc.get("access_token"),a={...t.headers||{}};r?(a.Authorization=`Bearer ${r}`,console.log("Authorization header OK:",a.Authorization.slice(0,30)+"...")):console.warn("Token no encontrado en cookies.");const i=e.startsWith("http")?e:`${n.replace(/\/$/,"")}/${e.replace(/^\//,"")}`;try{const o=await fetch(i,{...t,headers:a});if(console.log("Response:",{status:o.status,url:o.url,ok:o.ok}),o.status===401){const s=await o.text();console.warn("401 Unauthorized:",s)}if(!o.ok){const s=await o.text();throw new Error(`HTTP error ${o.status}: ${s}`)}return o}catch(o){throw console.error("Fetch failed:",o),o}},Xe=async(e,t={})=>{const{apiUrl:n}=Ve(),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(console.log("Response:",{status:i.status,url:i.url,ok:i.ok}),i.status===401){const o=await i.text();console.warn("401 Unauthorized (fetchWithoutAuth):",o);return}if(!i.ok){const o=await i.text();throw new Error(`HTTP error ${i.status}: ${o}`)}return i}catch(i){throw console.error("Fetch failed:",i),i}},Lt={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"},Wn={getMessagesByConversationId:async e=>{const{apiUrl:t}=Ve(),n=await Xe(`${t}${Lt.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}=Ve(),r=await Xe(`${n}${Lt.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}`);if(r.status===201)debugger;return await r.json()},stopBotStream:async e=>{const{apiUrl:t}=Ve(),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 Xe(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")}catch(r){throw console.error("Error al detener el stream:",r),r}},sendMessageStreaming:async(e,t,n,r)=>{const{apiUrl:a}=Ve(),i={conversation:{id:e},text:t,service:n},o=await Xe(`${a}${Lt.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.status!==200&&o.status!==201){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}, Details: ${JSON.stringify(s)}`)}if(!o.body)throw new Error("No body in response");return o},editMessageAndResend:async({conversationId:e,messageId:t,text:n})=>{const a=await Xe("/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}, Details: ${JSON.stringify(i)}`)}if(!a.body)throw new Error("No body in response");return a}},Ov=async e=>(await Wn.getMessagesByConversationId(e)).map(a=>({...a,conversation_id:e})).slice().sort((a,i)=>new Date(a.created_at).getTime()-new Date(i.created_at).getTime()),Lv=async(e,t,n,r)=>await Wn.sendMessageStreaming(e,t,n,r),Uc=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 Wn.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}},Dv=async(e,t,n)=>await Wn.editMessageAndResend({conversationId:e,messageId:t,text:n}),Bc=(e,t,n)=>new Promise(r=>{let a=0;const i=10,o=setInterval(()=>{if(a<e.length){const s=e.slice(a,a+i);n(s),a+=i}else clearInterval(o),r()},t)}),Rr={createConversation:async(e,t,n)=>{if(!t)throw new Error("Service is required to create a conversation.");const{apiUrl:r}=Ve(),a=`${r}${Lt.CONVERSATIONS_CREATE}/?service=${encodeURIComponent(t)}${e?`&title=${encodeURIComponent(e)}`:""}`,i=n?Vn:Xe,o={};n||(o["Content-Type"]="application/x-www-form-urlencoded");const s=await i(a,{method:"POST",headers:o});if(console.log("Respuesta al crear conversación:",{status:s.status,ok:s.ok,url:s.url}),!s)throw new Error("Failed to create conversation: No response from server.");if(!s.ok)throw new Error(`Failed to create conversation. Status: ${s.status}`);return await s.json()},getUserConversations:async(e,t)=>{const{apiUrl:n}=Ve(),r=t?Vn:Xe,a={};t||(a["Content-Type"]="application/x-www-form-urlencoded");const i=await r(`${n}${Lt.USER_CONVERSATIONS}?service=${e}`,{method:"GET",headers:a});if(console.log("Respuesta al obtener conversaciones de usuario:",{status:i.status,ok:i.ok,url:i.url}),!i)throw new Error("Failed to fetch user conversations: No response from server.");if(!i.ok)throw new Error(`Failed to fetch user conversations. Status: ${i.status}`);return await i.json()},getConversationById:async(e,t,n)=>{const{apiUrl:r}=Ve(),a=n?Vn:Xe,i={};n||(i["Content-Type"]="application/x-www-form-urlencoded");const o=await a(`${r}${Lt.CONVERSATION_MESSAGES}/${e}?service=${t}`,{method:"GET",headers:i});if(console.log("Respuesta al obtener conversación por ID:",{status:o.status,ok:o.ok,url:o.url}),!o)throw new Error("Failed to fetch conversation by ID: No response from server.");if(!o.ok)throw new Error(`Failed to fetch conversation by ID. Status: ${o.status}`);return await o.json()},deleteConversationById:async(e,t,n)=>{const{apiUrl:r}=Ve(),a=n?Vn:Xe,i={};n||(i["Content-Type"]="application/x-www-form-urlencoded");const o=await a(`${r}${Lt.DELETE_CONVERSATION}${e}?conversation_id=${e}&service=${t}`,{method:"POST",headers:i});if(console.log("Respuesta al eliminar conversación:",{status:o.status,ok:o.ok,url:o.url}),!o)throw new Error("Failed to delete conversation: No response from server.");if(!o.ok)throw new Error(`Failed to delete conversation with ID: ${e}. Status: ${o.status}`)}},Mv=async(e,t,n)=>{try{return await Rr.createConversation(e,t)}catch(r){throw console.error("Error creating conversation:",r),r}},Pv=async(e,t)=>await Rr.getUserConversations(e,t),Fv=async(e,t,n)=>await Rr.deleteConversationById(e,t),$c=I.createContext(void 0),Uv=({children:e,usedService:t})=>{const[n,r]=I.useState(t??"CsdInteraccion"),a=I.useMemo(()=>({service:n,setService:r}),[n]);return g.jsx($c.Provider,{value:a,children:e})},Ir=()=>{const e=I.useContext($c);if(!e)throw new Error("useService must be used within ServiceProvider");return e},jc=I.createContext(void 0),Bv=({children:e,enableAutoCreate:t=!1,enableAutoCreateCsd:n=!1,serviceTicketing:r=!0,isNotDrupal:a=!0,serviceTicketingNoUSer:i=!0})=>{const{service:o}=Ir(),[s,l]=I.useState({}),[u,c]=I.useState(null),d=async()=>{if(o)try{const T=await Pv(o,a);l(E=>({...E,[o]:T})),!u&&T.length>0&&!n&&c(T[T.length-1])}catch(T){console.error("❌ Error al obtener conversaciones:",T)}};I.useEffect(()=>{o&&d()},[o]);const f=async(T,E)=>{try{const m=await Mv(T,E,a);return l(x=>({...x,[E]:[...x[E]||[],m]})),c(m),m}catch(m){throw console.error("Failed to create conversation:",m),m}},p=async(T,E)=>{if(E)try{await Fv(T,E,a),l(m=>({...m,[E]:(m[E]||[]).filter(x=>x.id!==T)})),c(null)}catch(m){console.error("Failed to delete conversation:",m)}},y=async(T,E)=>{const x=(s[E??""]||[]).find(h=>h.id===T);x&&(u!=null&&u.id&&await Uc(u==null?void 0:u.id),c(x))},{autoCreateConversationCsd:S}=kr({enableAutoCreate:t,enableAutoCreateCsd:n,addConversation:f,selectConversation:y,service:o,conversations:s[o]||[]});I.useEffect(()=>{n&&S()},[S]);const A=I.useMemo(()=>({conversations:s[o]||[],fetchConversations:d,addConversation:f,removeConversation:p,selectConversation:y,selectedConversation:u,selectedConversationId:(u==null?void 0:u.id)??null,service:o,serviceTicketing:r,isNotDrupal:a,serviceTicketingNoUSer:i}),[s,u,o,r,a,i]);return g.jsx(jc.Provider,{value:A,children:e})},Yt=()=>{const e=I.useContext(jc);if(!e)throw new Error("useConversation must be used within a ConversationProvider");return e};L.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.1.
|
|
5
|
+
"version": "1.1.27",
|
|
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",
|