@runnerpro/backend 1.13.21 → 1.13.23

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.
@@ -33,7 +33,6 @@ const index_1 = require("../../index");
33
33
  const common_1 = require("@runnerpro/common");
34
34
  const index_2 = require("../../locale/index");
35
35
  const multer_1 = __importDefault(require("multer"));
36
- const axios_1 = __importDefault(require("axios"));
37
36
  const saveResponseTime_1 = require("../saveResponseTime");
38
37
  const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
39
38
  const ffmpeg_static_1 = __importDefault(require("ffmpeg-static"));
@@ -221,27 +220,34 @@ const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }
221
220
  const idCliente = isClient ? req.session.userid : req.body.idCliente;
222
221
  let idWorkout, type = 1;
223
222
  if (!isClient) {
223
+ console.time('markReadMessage');
224
224
  // Si es entrenador, se marca leído cuando se envía un mensaje
225
225
  yield markReadMessage({ isClient, idCliente });
226
+ console.timeEnd('markReadMessage');
226
227
  // Cambiar el tono del texto a uno neutro y corregir la ortografía
227
228
  if (idCliente === 'sJzhGqaJcddq96x80hZAlPJ6pET2' && process.env.NODE_ENV === 'PROD') {
228
- console.log('cambiarTonoEntrenadorNeutro');
229
+ console.time('cambiarTonoEntrenadorNeutro');
229
230
  text = yield cambiarTonoEntrenadorNeutro(text);
231
+ console.timeEnd('cambiarTonoEntrenadorNeutro');
230
232
  }
231
233
  }
232
234
  // Devuelve el texto en el otro idioma si el cliente no habla español y el idioma del cliente
235
+ console.time('getPreferredLanguageForChat');
233
236
  const { textSpanish, textPreferredLanguage, preferredLanguage } = yield getPreferredLanguageForChat({
234
237
  text,
235
238
  idCliente,
236
239
  isClient,
237
240
  });
241
+ console.timeEnd('getPreferredLanguageForChat');
238
242
  // Enviado cuando es un mensaje de comentario sobre intelligence
239
243
  if (newMessage) {
240
244
  type = 6;
241
245
  idWorkout = newMessage.idWorkout;
242
246
  }
247
+ console.time('query');
243
248
  const [message] = yield (0, index_1.query)('INSERT INTO [CHAT MESSAGE] ([ID CLIENTE], [ID SENDER], [TEXT], [TEXT PREFERRED LANGUAGE], [PREFERRED LANGUAGE], [REPLY MESSAGE ID], [ID WORKOUT], [TYPE]) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING [ID]', [isClient ? userid : idCliente, userid, textSpanish, textPreferredLanguage, preferredLanguage, replyMessageId, idWorkout, type]);
244
- res.send({ idMessage: message.id });
249
+ console.timeEnd('query');
250
+ res.send({ idMessage: message.id, text: textSpanish });
245
251
  if (!isClient) {
246
252
  sendNotification({
247
253
  firebaseMessaging,
@@ -250,13 +256,16 @@ const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }
250
256
  screen: common_1.NOTIFICATION_SCREEN_TYPES.CHAT,
251
257
  });
252
258
  // Enviar a N8N lo que ha escrito el entrenador
253
- const [lastSuggestionMsg] = yield (0, index_1.query)('SELECT [ID] FROM [CHAT MESSAGE] WHERE [ID CLIENTE] = ? AND [SUGGESTION TEXT] IS NOT NULL ORDER BY [ID] DESC LIMIT 1', [idCliente]);
254
- if (lastSuggestionMsg) {
255
- yield axios_1.default.put(`${process.env.N8N_URL}/edc2484f-7010-44c1-8c1d-82924496a2eb`, {
256
- id: lastSuggestionMsg.id,
257
- msg: textSpanish,
258
- });
259
- }
259
+ // const [lastSuggestionMsg] = await query(
260
+ // 'SELECT [ID] FROM [CHAT MESSAGE] WHERE [ID CLIENTE] = ? AND [SUGGESTION TEXT] IS NOT NULL ORDER BY [ID] DESC LIMIT 1',
261
+ // [idCliente]
262
+ // );
263
+ // if (lastSuggestionMsg) {
264
+ // await axios.put(`${process.env.N8N_URL}/edc2484f-7010-44c1-8c1d-82924496a2eb`, {
265
+ // id: lastSuggestionMsg.id,
266
+ // msg: textSpanish,
267
+ // });
268
+ // }
260
269
  }
261
270
  });
262
271
  const getPreferredLanguageForChat = ({ text, idCliente, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
@@ -13,10 +13,9 @@ exports.sendPrompt = void 0;
13
13
  const { VertexAI } = require('@google-cloud/vertexai');
14
14
  function sendPrompt(prompt) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- console.log(process.env.GOOGLE_APPLICATION_CREDENTIALS);
17
16
  // Inicializa el cliente de Vertex AI
18
17
  const vertex_ai = new VertexAI({
19
- project: 'glass-timing-393523', // Reemplaza con tu ID de proyecto de Google Cloud
18
+ project: process.env.PROJECT_ID, // Reemplaza con tu ID de proyecto de Google Cloud
20
19
  location: 'us-central1', // Reemplaza con tu región
21
20
  });
22
21
  // Selecciona el modelo de Gemini
@@ -25,19 +24,13 @@ function sendPrompt(prompt) {
25
24
  const generativeModel = vertex_ai.preview.getGenerativeModel({
26
25
  model: model,
27
26
  });
28
- console.log(`Enviando prompt: "${prompt}"`);
29
27
  try {
30
28
  const resp = yield generativeModel.generateContent(prompt);
31
29
  const content = resp.response.candidates[0].content;
32
30
  // Asumiendo que la respuesta es de tipo texto
33
- if (content.parts && content.parts.length > 0 && content.parts[0].text) {
34
- console.log('Respuesta de Gemini:');
35
- console.log(content.parts[0].text);
31
+ if (content.parts && content.parts.length > 0 && content.parts[0].text)
36
32
  return content.parts[0].text;
37
- }
38
- else {
39
- console.log('No se recibió una respuesta de texto válida.');
40
- }
33
+ return '';
41
34
  }
42
35
  catch (error) {
43
36
  console.error('Error al enviar el prompt:', error);
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAmBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAuBpD,CAAC;AAmbF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAmBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAuBpD,CAAC;AA0bF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":"AAEA,iBAAe,UAAU,CAAC,MAAM,KAAA,gBAiC/B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":"AAEA,iBAAe,UAAU,CAAC,MAAM,KAAA,gBA0B/B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.13.21",
3
+ "version": "1.13.23",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"