@runnerpro/backend 1.19.0 → 1.19.2

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.
@@ -592,17 +592,20 @@ const markReadMessage = ({ isClient, idCliente }) => __awaiter(void 0, void 0, v
592
592
  */
593
593
  const corregirOrtografia = (text) => __awaiter(void 0, void 0, void 0, function* () {
594
594
  try {
595
- let textCorregido = yield (0, prompt_1.sendPrompt)(`Actúa como un corrector de estilo nativo de España (castellano).
595
+ let { text: textCorregido } = yield (0, prompt_1.generateText)({
596
+ model: (0, prompt_1.createGoogleModel)('LITE'),
597
+ system: `Actúa como un corrector de estilo nativo de España (castellano).
596
598
  Instrucciones estrictas:
597
599
  - Vocabulario: Sustituye términos latinos por sus equivalentes en España (ej: celular -> móvil, computadora -> ordenador, video -> vídeo, costo -> coste, chequear -> comprobar, entreno -> entrenamiento).
598
600
  - Ortografía: Corrige cualquier falta ortográfica o de acentuación.
599
601
  - URLs: Copia los links exactos. NO los abras, NO los leas y NO añadas resúmenes.
600
602
  - Formato: Entrega texto plano y limpio. NO uses asteriscos (*), negritas, ni símbolos de Markdown. Solo texto y emojis.
601
603
  - Tono: Mantén la energía y la intención del entrenador, pero asegúrate de que suene 100% nativo de España.
604
+ - Emojis: Mantén los emojis tal cual, no añadas ni quites ninguno.
602
605
 
603
- Devuelve SOLO el texto corregido final.
604
-
605
- Texto: ${text}`, 'LITE');
606
+ Devuelve SOLO el texto corregido final.`,
607
+ prompt: text,
608
+ });
606
609
  textCorregido = textCorregido.replace(/[¡¿]/g, '');
607
610
  textCorregido = textCorregido.trim().replace(/\.$/, '');
608
611
  return textCorregido;
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reprocessRecentMedia = exports.processMediaFile = exports.describeImage = exports.transcribeAudio = exports.updateSenderView = exports.sendPrompt = exports.saveResponseTime = exports.getPlanificacionPrueba7dias = exports.sendWorkoutToWatch = exports.getDefaultWorkoutImage = exports.generateShareMap = exports.reduceSizeImage = exports.getLetter = exports.getNumberByLetter = exports.appendSheet = exports.writeSheet = exports.findCellByValue = exports.readSheet = exports.NOTION_DATABASES_ID = exports.notionEditPage = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.CHANNEL_SLACK = exports.notifySlack = exports.fetchIA = exports.err = exports.sendMail = exports.pool = exports.toPgArray = exports.batchQuery = exports.longRunningQuery = exports.queryWithClient = exports.query = exports.sleep = exports.sendNotification = void 0;
3
+ exports.reprocessRecentMedia = exports.processMediaFile = exports.describeImage = exports.transcribeAudio = exports.updateSenderView = exports.createGoogleModel = exports.generateText = exports.saveResponseTime = exports.getPlanificacionPrueba7dias = exports.sendWorkoutToWatch = exports.getDefaultWorkoutImage = exports.generateShareMap = exports.reduceSizeImage = exports.getLetter = exports.getNumberByLetter = exports.appendSheet = exports.writeSheet = exports.findCellByValue = exports.readSheet = exports.NOTION_DATABASES_ID = exports.notionEditPage = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.CHANNEL_SLACK = exports.notifySlack = exports.fetchIA = exports.err = exports.sendMail = exports.pool = exports.toPgArray = exports.batchQuery = exports.longRunningQuery = exports.queryWithClient = exports.query = exports.sleep = exports.sendNotification = void 0;
4
4
  const sendNotification_1 = require("./sendNotification");
5
5
  Object.defineProperty(exports, "sendNotification", { enumerable: true, get: function () { return sendNotification_1.sendNotification; } });
6
6
  const sleep_1 = require("./sleep");
@@ -57,7 +57,8 @@ Object.defineProperty(exports, "getPlanificacionPrueba7dias", { enumerable: true
57
57
  const saveResponseTime_1 = require("./chat/saveResponseTime");
58
58
  Object.defineProperty(exports, "saveResponseTime", { enumerable: true, get: function () { return saveResponseTime_1.saveResponseTime; } });
59
59
  const prompt_1 = require("./prompt");
60
- Object.defineProperty(exports, "sendPrompt", { enumerable: true, get: function () { return prompt_1.sendPrompt; } });
60
+ Object.defineProperty(exports, "generateText", { enumerable: true, get: function () { return prompt_1.generateText; } });
61
+ Object.defineProperty(exports, "createGoogleModel", { enumerable: true, get: function () { return prompt_1.createGoogleModel; } });
61
62
  const conversation_1 = require("./chat/api/conversation");
62
63
  Object.defineProperty(exports, "updateSenderView", { enumerable: true, get: function () { return conversation_1.updateSenderView; } });
63
64
  const mediaProcessing_1 = require("./mediaProcessing");
@@ -86,7 +86,7 @@ const transcribeAudio = (fileBuffer, mimetype) => __awaiter(void 0, void 0, void
86
86
  });
87
87
  exports.transcribeAudio = transcribeAudio;
88
88
  /**
89
- * Genera una descripción de una imagen usando Gemini (Vertex AI)
89
+ * Genera una descripción de una imagen usando Gemini (Vercel AI SDK)
90
90
  * Contextualizada para una aplicación de fitness/entrenamiento
91
91
  *
92
92
  * @param fileBuffer - Buffer del archivo de imagen
@@ -101,11 +101,19 @@ exports.transcribeAudio = transcribeAudio;
101
101
  */
102
102
  const describeImage = (fileBuffer, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
103
103
  try {
104
- const result = yield (0, index_1.sendPrompt)(IMAGE_DESCRIPTION_PROMPT, 'PRO', undefined, {
105
- buffer: fileBuffer,
106
- mimetype,
104
+ const { text } = yield (0, index_1.generateText)({
105
+ model: (0, index_1.createGoogleModel)('PRO'),
106
+ messages: [
107
+ {
108
+ role: 'user',
109
+ content: [
110
+ { type: 'file', data: fileBuffer, mediaType: mimetype },
111
+ { type: 'text', text: IMAGE_DESCRIPTION_PROMPT },
112
+ ],
113
+ },
114
+ ],
107
115
  });
108
- return result || '[Imagen no analizable]';
116
+ return text || '[Imagen no analizable]';
109
117
  }
110
118
  catch (error) {
111
119
  // eslint-disable-next-line no-console
@@ -9,110 +9,81 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.sendPrompt = void 0;
13
- const vertexai_1 = require("@google-cloud/vertexai");
12
+ exports.createGoogleModel = exports.generateText = void 0;
13
+ const ai_1 = require("ai");
14
+ const google_1 = require("@ai-sdk/google");
15
+ const AI_MODELS = {
16
+ LITE: 'gemini-3.1-flash-lite-preview',
17
+ FLASH: 'gemini-3-flash-preview',
18
+ PRO: 'gemini-3.1-pro-preview',
19
+ };
20
+ const MAX_RETRIES = 1;
21
+ /**
22
+ * Crea una instancia del modelo de Google Gemini con la API key configurada
23
+ *
24
+ * @param modelKey - Clave del modelo: 'LITE' (rápido/barato), 'FLASH' (equilibrado), 'PRO' (potente)
25
+ * @returns Instancia del modelo configurado para usar con generateText
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const model = createGoogleModel('LITE');
30
+ * const { text } = await generateText({ model, prompt: 'Hola' });
31
+ * ```
32
+ */
33
+ function createGoogleModel(modelKey = 'FLASH') {
34
+ return (0, google_1.google)(AI_MODELS[modelKey]);
35
+ }
36
+ exports.createGoogleModel = createGoogleModel;
14
37
  /**
15
- * Envía un prompt a Gemini (Vertex AI) y retorna la respuesta
16
- * Soporta contenido multimodal (texto + audio/imagen)
38
+ * Wrapper de generateText del Vercel AI SDK con retry automático (1 reintento)
39
+ * Soporta texto simple, system prompt y contenido multimodal (imágenes, audio)
17
40
  *
18
- * @param prompt - Texto del prompt a enviar
19
- * @param model - Modelo a usar: 'LITE', 'FLASH' (default), 'PRO'
20
- * @param systemPrompt - Instrucciones de sistema opcionales
21
- * @param media - Contenido multimedia opcional (audio o imagen)
22
- * @returns Promise<string> - Respuesta generada por la IA
41
+ * @param options - Opciones del Vercel AI SDK: model, system, prompt, messages, temperature, etc.
42
+ * @returns Promise<{ text: string }> - Texto generado por la IA
23
43
  *
24
44
  * @example
25
45
  * ```typescript
26
46
  * // Solo texto
27
- * const response = await sendPrompt('Traduce esto al inglés: Hola mundo');
47
+ * const { text } = await generateText({
48
+ * model: createGoogleModel('LITE'),
49
+ * prompt: 'Traduce al inglés: Hola mundo',
50
+ * });
28
51
  *
29
- * // Con imagen
30
- * const description = await sendPrompt(
31
- * 'Describe esta imagen',
32
- * 'FLASH',
33
- * undefined,
34
- * { buffer: imageBuffer, mimetype: 'image/jpeg' }
35
- * );
52
+ * // Con system prompt
53
+ * const { text } = await generateText({
54
+ * model: createGoogleModel('FLASH'),
55
+ * system: 'Eres un corrector ortográfico',
56
+ * prompt: 'ola como estas',
57
+ * });
36
58
  *
37
- * // Con audio
38
- * const transcription = await sendPrompt(
39
- * 'Transcribe este audio en español',
40
- * 'FLASH',
41
- * undefined,
42
- * { buffer: audioBuffer, mimetype: 'audio/mpeg' }
43
- * );
59
+ * // Multimodal (imagen)
60
+ * const { text } = await generateText({
61
+ * model: createGoogleModel('PRO'),
62
+ * messages: [{
63
+ * role: 'user',
64
+ * content: [
65
+ * { type: 'file', data: imageBuffer, mimeType: 'image/jpeg' },
66
+ * { type: 'text', text: 'Describe esta imagen' },
67
+ * ],
68
+ * }],
69
+ * });
44
70
  * ```
45
71
  */
46
- function sendPrompt(prompt, model = 'FLASH', systemPrompt = undefined, media = undefined, region = 'europe-west8') {
47
- var _a, _b, _c, _d;
72
+ function generateText(options) {
48
73
  return __awaiter(this, void 0, void 0, function* () {
49
- // Inicializa el cliente de Vertex AI
50
- const vertex_ai = new vertexai_1.VertexAI({
51
- project: process.env.PROJECT_ID,
52
- location: region,
53
- });
54
- // Selecciona el modelo de Gemini
55
- let modelGemini;
56
- if (model === 'LITE')
57
- modelGemini = 'gemini-3.1-flash-lite-preview';
58
- else if (model === 'PRO')
59
- modelGemini = 'gemini-3.1-pro-preview'; // Modelo más potente y estable
60
- else
61
- modelGemini = 'gemini-3-flash-preview';
62
- // Configura el modelo generativo
63
- const generativeModel = vertex_ai.preview.getGenerativeModel({
64
- model: modelGemini,
65
- generationConfig: {
66
- temperature: media ? 0.1 : 0.3, // Menor temperatura para transcripciones
67
- topP: 0.8,
68
- topK: 20,
69
- },
70
- systemInstruction: systemPrompt
71
- ? {
72
- role: 'system',
73
- parts: [{ text: systemPrompt }],
74
- }
75
- : undefined,
76
- });
77
- // ✅ Construir contenido según si hay media o no
78
- let content;
79
- if (media) {
80
- // Contenido multimodal (audio/imagen + texto)
81
- content = {
82
- contents: [
83
- {
84
- role: 'user',
85
- parts: [
86
- {
87
- inlineData: {
88
- mimeType: media.mimetype,
89
- data: media.buffer.toString('base64'),
90
- },
91
- },
92
- {
93
- text: prompt,
94
- },
95
- ],
96
- },
97
- ],
98
- };
99
- }
100
- else {
101
- // Solo texto
102
- content = prompt;
74
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
75
+ try {
76
+ const { text } = yield (0, ai_1.generateText)(options);
77
+ return { text: text.trim() };
78
+ }
79
+ catch (error) {
80
+ if (attempt < MAX_RETRIES)
81
+ continue;
82
+ throw error;
83
+ }
103
84
  }
104
- // @ts-ignore - Vertex AI types son complejos para contenido multimodal
105
- const resp = yield generativeModel.generateContent(content);
106
- // Early return si no hay candidates
107
- const candidate = (_a = resp.response.candidates) === null || _a === void 0 ? void 0 : _a[0];
108
- if (!candidate)
109
- return '';
110
- // Early return si no hay parts
111
- const parts = (_b = candidate.content) === null || _b === void 0 ? void 0 : _b.parts;
112
- if (!parts || parts.length === 0)
113
- return '';
114
- // Return del texto si existe
115
- return ((_d = (_c = parts[0]) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d.trim()) || '';
85
+ // Fallback (nunca debería llegar aquí)
86
+ throw new Error('generateText: reintentos agotados');
116
87
  });
117
88
  }
118
- exports.sendPrompt = sendPrompt;
89
+ exports.generateText = generateText;
@@ -15,8 +15,8 @@ import { getDefaultWorkoutImage } from './image/getDefaultWorkoutImage';
15
15
  import { sendWorkoutToWatch } from './workout/sendToWatch';
16
16
  import { getPlanificacionPrueba7dias } from './workout/planificacionPrueba7dias';
17
17
  import { saveResponseTime } from './chat/saveResponseTime';
18
- import { sendPrompt } from './prompt';
18
+ import { generateText, createGoogleModel } from './prompt';
19
19
  import { updateSenderView } from './chat/api/conversation';
20
20
  import { transcribeAudio, describeImage, processMediaFile, reprocessRecentMedia } from './mediaProcessing';
21
- export { sendNotification, sleep, query, queryWithClient, longRunningQuery, batchQuery, toPgArray, pool, sendMail, err, fetchIA, notifySlack, CHANNEL_SLACK, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID, readSheet, findCellByValue, writeSheet, appendSheet, getNumberByLetter, getLetter, reduceSizeImage, generateShareMap, getDefaultWorkoutImage, sendWorkoutToWatch, getPlanificacionPrueba7dias, saveResponseTime, sendPrompt, updateSenderView, transcribeAudio, describeImage, processMediaFile, reprocessRecentMedia, };
21
+ export { sendNotification, sleep, query, queryWithClient, longRunningQuery, batchQuery, toPgArray, pool, sendMail, err, fetchIA, notifySlack, CHANNEL_SLACK, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID, readSheet, findCellByValue, writeSheet, appendSheet, getNumberByLetter, getLetter, reduceSizeImage, generateShareMap, getDefaultWorkoutImage, sendWorkoutToWatch, getPlanificacionPrueba7dias, saveResponseTime, generateText, createGoogleModel, updateSenderView, transcribeAudio, describeImage, processMediaFile, reprocessRecentMedia, };
22
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,eAAe,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,gBAAgB,EAChB,oBAAoB,GACrB,CAAC"}
@@ -15,7 +15,7 @@
15
15
  */
16
16
  declare const transcribeAudio: (fileBuffer: Buffer, mimetype: string) => Promise<string>;
17
17
  /**
18
- * Genera una descripción de una imagen usando Gemini (Vertex AI)
18
+ * Genera una descripción de una imagen usando Gemini (Vercel AI SDK)
19
19
  * Contextualizada para una aplicación de fitness/entrenamiento
20
20
  *
21
21
  * @param fileBuffer - Buffer del archivo de imagen
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mediaProcessing/index.ts"],"names":[],"mappings":";AA2BA;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,eAAe,eAAsB,MAAM,YAAY,MAAM,KAAG,QAAQ,MAAM,CA0CnF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,aAAa,eAAsB,MAAM,YAAY,MAAM,KAAG,QAAQ,MAAM,CAajF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,QAAA,MAAM,gBAAgB,cAAqB,MAAM,cAAc,MAAM,YAAY,MAAM,KAAG,QAAQ,IAAI,CAkBrG,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,oBAAoB,WAAkB,GAAG;eAAwB,MAAM;YAAU,MAAM;EAwD5F,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/mediaProcessing/index.ts"],"names":[],"mappings":";AA2BA;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,eAAe,eAAsB,MAAM,YAAY,MAAM,KAAG,QAAQ,MAAM,CA0CnF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,aAAa,eAAsB,MAAM,YAAY,MAAM,KAAG,QAAQ,MAAM,CAqBjF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,QAAA,MAAM,gBAAgB,cAAqB,MAAM,cAAc,MAAM,YAAY,MAAM,KAAG,QAAQ,IAAI,CAkBrG,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,oBAAoB,WAAkB,GAAG;eAAwB,MAAM;YAAU,MAAM;EAwD5F,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,45 +1,55 @@
1
- /// <reference types="node" />
1
+ import { generateText as originalGenerateText } from 'ai';
2
+ type ModelKey = 'LITE' | 'FLASH' | 'PRO';
2
3
  /**
3
- * Contenido multimedia opcional para enviar junto con el prompt
4
+ * Crea una instancia del modelo de Google Gemini con la API key configurada
5
+ *
6
+ * @param modelKey - Clave del modelo: 'LITE' (rápido/barato), 'FLASH' (equilibrado), 'PRO' (potente)
7
+ * @returns Instancia del modelo configurado para usar con generateText
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const model = createGoogleModel('LITE');
12
+ * const { text } = await generateText({ model, prompt: 'Hola' });
13
+ * ```
4
14
  */
5
- interface MediaContent {
6
- /** Buffer del archivo (audio o imagen) */
7
- buffer: Buffer;
8
- /** Tipo MIME del archivo (ej: 'audio/mpeg', 'image/jpeg') */
9
- mimetype: string;
10
- }
15
+ declare function createGoogleModel(modelKey?: ModelKey): import("@ai-sdk/provider").LanguageModelV3;
11
16
  /**
12
- * Envía un prompt a Gemini (Vertex AI) y retorna la respuesta
13
- * Soporta contenido multimodal (texto + audio/imagen)
17
+ * Wrapper de generateText del Vercel AI SDK con retry automático (1 reintento)
18
+ * Soporta texto simple, system prompt y contenido multimodal (imágenes, audio)
14
19
  *
15
- * @param prompt - Texto del prompt a enviar
16
- * @param model - Modelo a usar: 'LITE', 'FLASH' (default), 'PRO'
17
- * @param systemPrompt - Instrucciones de sistema opcionales
18
- * @param media - Contenido multimedia opcional (audio o imagen)
19
- * @returns Promise<string> - Respuesta generada por la IA
20
+ * @param options - Opciones del Vercel AI SDK: model, system, prompt, messages, temperature, etc.
21
+ * @returns Promise<{ text: string }> - Texto generado por la IA
20
22
  *
21
23
  * @example
22
24
  * ```typescript
23
25
  * // Solo texto
24
- * const response = await sendPrompt('Traduce esto al inglés: Hola mundo');
26
+ * const { text } = await generateText({
27
+ * model: createGoogleModel('LITE'),
28
+ * prompt: 'Traduce al inglés: Hola mundo',
29
+ * });
25
30
  *
26
- * // Con imagen
27
- * const description = await sendPrompt(
28
- * 'Describe esta imagen',
29
- * 'FLASH',
30
- * undefined,
31
- * { buffer: imageBuffer, mimetype: 'image/jpeg' }
32
- * );
31
+ * // Con system prompt
32
+ * const { text } = await generateText({
33
+ * model: createGoogleModel('FLASH'),
34
+ * system: 'Eres un corrector ortográfico',
35
+ * prompt: 'ola como estas',
36
+ * });
33
37
  *
34
- * // Con audio
35
- * const transcription = await sendPrompt(
36
- * 'Transcribe este audio en español',
37
- * 'FLASH',
38
- * undefined,
39
- * { buffer: audioBuffer, mimetype: 'audio/mpeg' }
40
- * );
38
+ * // Multimodal (imagen)
39
+ * const { text } = await generateText({
40
+ * model: createGoogleModel('PRO'),
41
+ * messages: [{
42
+ * role: 'user',
43
+ * content: [
44
+ * { type: 'file', data: imageBuffer, mimeType: 'image/jpeg' },
45
+ * { type: 'text', text: 'Describe esta imagen' },
46
+ * ],
47
+ * }],
48
+ * });
41
49
  * ```
42
50
  */
43
- declare function sendPrompt(prompt: string, model?: string, systemPrompt?: string | undefined, media?: MediaContent | undefined, region?: string): Promise<string>;
44
- export { sendPrompt };
51
+ declare function generateText(options: Parameters<typeof originalGenerateText>[0]): Promise<{
52
+ text: string;
53
+ }>;
54
+ export { generateText, createGoogleModel };
45
55
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":";AAEA;;GAEG;AACH,UAAU,YAAY;IACpB,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,iBAAe,UAAU,CACvB,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAgB,EACvB,YAAY,GAAE,MAAM,GAAG,SAAqB,EAC5C,KAAK,GAAE,YAAY,GAAG,SAAqB,EAC3C,MAAM,GAAE,MAAuB,mBAsEhC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,oBAAoB,EAAE,MAAM,IAAI,CAAC;AAG1D,KAAK,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAUzC;;;;;;;;;;;GAWG;AACH,iBAAS,iBAAiB,CAAC,QAAQ,GAAE,QAAkB,8CAEtD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,iBAAe,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAa1G;AAED,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.19.0",
3
+ "version": "1.19.2",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"
@@ -65,11 +65,12 @@
65
65
  "uuidv4": "^6.2.13"
66
66
  },
67
67
  "dependencies": {
68
+ "@ai-sdk/google": "^3.0.43",
68
69
  "@google-cloud/speech": "^7.2.1",
69
70
  "@google-cloud/storage": "^7.11.3",
70
71
  "@google-cloud/translate": "^8.3.0",
71
- "@google-cloud/vertexai": "^1.4.0",
72
72
  "@notionhq/client": "^2.2.15",
73
+ "ai": "^6.0.116",
73
74
  "exifr": "^7.1.3",
74
75
  "ffmpeg-static": "^5.2.0",
75
76
  "ffprobe-static": "^3.1.0",