@runnerpro/backend 1.12.26 → 1.13.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.
@@ -38,6 +38,7 @@ const saveResponseTime_1 = require("../saveResponseTime");
38
38
  const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
39
39
  const ffmpeg_static_1 = __importDefault(require("ffmpeg-static"));
40
40
  const ffprobe_static_1 = __importDefault(require("ffprobe-static"));
41
+ const prompt_1 = require("../../prompt");
41
42
  fluent_ffmpeg_1.default.setFfmpegPath(ffmpeg_static_1.default);
42
43
  fluent_ffmpeg_1.default.setFfprobePath(ffprobe_static_1.default.path);
43
44
  const conversationRoute = (_a) => {
@@ -214,13 +215,17 @@ const getChatFile = ({ bucket, id, isClient, userid }) => __awaiter(void 0, void
214
215
  }
215
216
  });
216
217
  const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
217
- const { text, replyMessageId, new: newMessage } = req.body;
218
+ const { replyMessageId, new: newMessage } = req.body;
219
+ let { text } = req.body;
218
220
  const { userid } = req.session;
219
221
  const idCliente = isClient ? req.session.userid : req.body.idCliente;
220
222
  let idWorkout, type = 1;
221
- // Si es entrenador, se marca leído cuando se envía un mensaje
222
- if (!isClient)
223
+ if (!isClient) {
224
+ // Si es entrenador, se marca leído cuando se envía un mensaje
223
225
  yield markReadMessage({ isClient, idCliente });
226
+ // Cambiar el tono del texto a uno neutro y corregir la ortografía
227
+ text = cambiarTonoEntrenadorNeutro(text);
228
+ }
224
229
  // Devuelve el texto en el otro idioma si el cliente no habla español y el idioma del cliente
225
230
  const { textSpanish, textPreferredLanguage, preferredLanguage } = yield getPreferredLanguageForChat({
226
231
  text,
@@ -395,6 +400,14 @@ const markReadMessage = ({ isClient, idCliente }) => __awaiter(void 0, void 0, v
395
400
  if (!isClient)
396
401
  yield (0, saveResponseTime_1.saveResponseTime)(idCliente);
397
402
  });
403
+ const cambiarTonoEntrenadorNeutro = (text) => __awaiter(void 0, void 0, void 0, function* () {
404
+ const textCorregido = yield (0, prompt_1.sendPrompt)(`
405
+ Eres un asistente de IA que cambia el tono de los mensajes de un entrenador a uno neutro y corrige la ortografía.
406
+ El mensaje es: ${text}
407
+ El mensaje corregido es:
408
+ `);
409
+ return textCorregido;
410
+ });
398
411
  const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
399
412
  if (mimetype.includes('webp'))
400
413
  return data;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.sendPrompt = exports.getVertexChat = void 0;
13
+ const vertexai_1 = require("@google-cloud/vertexai");
14
+ const getVertexChat = () => {
15
+ const vertexAI = new vertexai_1.VertexAI({ project: process.env.GCP_PROYECT_ID, location: 'us-central1' });
16
+ const generativeModel = vertexAI.preview.getGenerativeModel({
17
+ model: 'gemini-2.5-flash',
18
+ });
19
+ return generativeModel.startChat({});
20
+ };
21
+ exports.getVertexChat = getVertexChat;
22
+ const sendPrompt = (message) => __awaiter(void 0, void 0, void 0, function* () {
23
+ var _a, _b;
24
+ const chat = getVertexChat();
25
+ const result = yield chat.sendMessage(message);
26
+ return ((_b = (_a = result.response.candidates[0].content) === null || _a === void 0 ? void 0 : _a.parts[0]) === null || _b === void 0 ? void 0 : _b.text) || '';
27
+ });
28
+ exports.sendPrompt = sendPrompt;
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAuBpD,CAAC;AAuZF,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;AAqaF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare const getVertexChat: () => import("@google-cloud/vertexai").ChatSessionPreview;
2
+ declare const sendPrompt: (message: any) => Promise<string>;
3
+ export { getVertexChat, sendPrompt };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,aAAa,2DAQlB,CAAC;AAEF,QAAA,MAAM,UAAU,mCAIf,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.12.26",
3
+ "version": "1.13.1",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"
@@ -64,6 +64,7 @@
64
64
  "dependencies": {
65
65
  "@google-cloud/storage": "^7.11.3",
66
66
  "@google-cloud/translate": "^8.3.0",
67
+ "@google-cloud/vertexai": "^1.10.0",
67
68
  "@notionhq/client": "^2.2.15",
68
69
  "exifr": "^7.1.3",
69
70
  "ffmpeg-static": "^5.2.0",