@runnerpro/backend 1.22.0 → 1.22.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.
- package/lib/cjs/prompt/ai.js +9 -3
- package/lib/cjs/prompt/constants.js +16 -8
- package/lib/cjs/prompt/llmCacheStore.js +21 -3
- package/lib/cjs/prompt/modelPricing.js +36 -0
- package/lib/cjs/types/prompt/ai.d.ts.map +1 -1
- package/lib/cjs/types/prompt/constants.d.ts +2 -1
- package/lib/cjs/types/prompt/constants.d.ts.map +1 -1
- package/lib/cjs/types/prompt/llmCacheStore.d.ts +9 -1
- package/lib/cjs/types/prompt/llmCacheStore.d.ts.map +1 -1
- package/lib/cjs/types/prompt/modelPricing.d.ts +4 -0
- package/lib/cjs/types/prompt/modelPricing.d.ts.map +1 -1
- package/lib/cjs/types/workout/saveWorkoutAplication.d.ts.map +1 -1
- package/lib/cjs/workout/saveWorkoutAplication.js +16 -0
- package/package.json +1 -1
package/lib/cjs/prompt/ai.js
CHANGED
|
@@ -214,7 +214,7 @@ function generateObject(options) {
|
|
|
214
214
|
cacheKey = (0, llmCacheStore_1.llmCacheKey)({ system: co.system, prompt: co.prompt, schemaSig, temperature: co.temperature });
|
|
215
215
|
const hit = yield (0, llmCacheStore_1.lookup)(cacheKey);
|
|
216
216
|
if (hit !== null && hit !== undefined)
|
|
217
|
-
return { object: hit, cost: { inputTokens: 0, outputTokens: 0, cost: 0 } };
|
|
217
|
+
return { object: hit, cost: { inputTokens: 0, outputTokens: 0, inputCost: 0, outputCost: 0, cost: 0 } };
|
|
218
218
|
}
|
|
219
219
|
const fallbackNames = ((_a = currentOptions.model) === null || _a === void 0 ? void 0 : _a._fallbackModelNames) || [];
|
|
220
220
|
const maxAttempts = (1 + fallbackNames.length) * (1 + MIN_RETRIES);
|
|
@@ -229,7 +229,7 @@ function generateObject(options) {
|
|
|
229
229
|
if (tracker)
|
|
230
230
|
tracker.push(cost);
|
|
231
231
|
if (useCache && cacheKey)
|
|
232
|
-
(0, llmCacheStore_1.store)(cacheKey, { modelName, system: co.system, prompt: co.prompt, schemaSig, temperature: co.temperature, output: object });
|
|
232
|
+
(0, llmCacheStore_1.store)(cacheKey, { modelName, system: co.system, prompt: co.prompt, schemaSig, temperature: co.temperature, output: object, cost });
|
|
233
233
|
return { object, cost };
|
|
234
234
|
}
|
|
235
235
|
catch (error) {
|
|
@@ -365,6 +365,8 @@ function ensureNoChainOfThought(params) {
|
|
|
365
365
|
const retryCost = (0, modelPricing_1.calculateCost)(retryModelLabel, retryUsage === null || retryUsage === void 0 ? void 0 : retryUsage.inputTokens, retryUsage === null || retryUsage === void 0 ? void 0 : retryUsage.outputTokens);
|
|
366
366
|
accumulatedCost.inputTokens = (accumulatedCost.inputTokens || 0) + (retryCost.inputTokens || 0);
|
|
367
367
|
accumulatedCost.outputTokens = (accumulatedCost.outputTokens || 0) + (retryCost.outputTokens || 0);
|
|
368
|
+
accumulatedCost.inputCost = (accumulatedCost.inputCost || 0) + (retryCost.inputCost || 0);
|
|
369
|
+
accumulatedCost.outputCost = (accumulatedCost.outputCost || 0) + (retryCost.outputCost || 0);
|
|
368
370
|
accumulatedCost.cost = (accumulatedCost.cost || 0) + (retryCost.cost || 0);
|
|
369
371
|
const retryTrimmed = (retryText || '').trim();
|
|
370
372
|
if (retryTrimmed && !looksLikeChainOfThought(retryTrimmed)) {
|
|
@@ -380,6 +382,8 @@ function ensureNoChainOfThought(params) {
|
|
|
380
382
|
if (sanitized) {
|
|
381
383
|
accumulatedCost.inputTokens = (accumulatedCost.inputTokens || 0) + (sanitized.cost.inputTokens || 0);
|
|
382
384
|
accumulatedCost.outputTokens = (accumulatedCost.outputTokens || 0) + (sanitized.cost.outputTokens || 0);
|
|
385
|
+
accumulatedCost.inputCost = (accumulatedCost.inputCost || 0) + (sanitized.cost.inputCost || 0);
|
|
386
|
+
accumulatedCost.outputCost = (accumulatedCost.outputCost || 0) + (sanitized.cost.outputCost || 0);
|
|
383
387
|
accumulatedCost.cost = (accumulatedCost.cost || 0) + (sanitized.cost.cost || 0);
|
|
384
388
|
if (sanitized.text && !looksLikeChainOfThought(sanitized.text)) {
|
|
385
389
|
return { text: sanitized.text, cost: accumulatedCost };
|
|
@@ -415,8 +419,10 @@ function runWithCostTracking(fn) {
|
|
|
415
419
|
const totalCost = costs.reduce((acc, c) => ({
|
|
416
420
|
inputTokens: acc.inputTokens + (c.inputTokens || 0),
|
|
417
421
|
outputTokens: acc.outputTokens + (c.outputTokens || 0),
|
|
422
|
+
inputCost: (acc.inputCost || 0) + (c.inputCost || 0),
|
|
423
|
+
outputCost: (acc.outputCost || 0) + (c.outputCost || 0),
|
|
418
424
|
cost: acc.cost + (c.cost || 0),
|
|
419
|
-
}), { inputTokens: 0, outputTokens: 0, cost: 0 });
|
|
425
|
+
}), { inputTokens: 0, outputTokens: 0, inputCost: 0, outputCost: 0, cost: 0 });
|
|
420
426
|
return { result, totalCost, callCount: costs.length };
|
|
421
427
|
});
|
|
422
428
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runWithModels = exports.AISTUDIO_PREFIX = exports.MODEL_TIER = exports.BEDROCK_CLAUDE_HAIKU = exports.BEDROCK_CLAUDE_SONNET_4 = exports.BEDROCK_CLAUDE_SONNET_4_5 = exports.BEDROCK_CLAUDE_OPUS_4_1 = exports.BEDROCK_CLAUDE_OPUS_4_5 = exports.BEDROCK_CLAUDE_SONNET = exports.BEDROCK_CLAUDE_OPUS = exports.FALLBACK_MODELS = exports.TRIAL_MODELS = exports.FAST_MODELS = exports.SEMI_MODELS = exports.PRODUCTION_MODELS = exports.AZURE_PRIMARY_MODELS = exports.AZURE_GPT_5_4_NANO = exports.AZURE_GPT_5_4_MINI = exports.AZURE_GPT_5_5 = exports.AZURE_GPT_5_4_NANO_DEPLOYMENT = exports.AZURE_GPT_5_4_MINI_DEPLOYMENT = exports.AZURE_GPT_5_5_DEPLOYMENT = exports.AZURE_PREFIX = exports.GOOGLE_MODELS = exports.AI_MODELS = void 0;
|
|
3
|
+
exports.runWithModels = exports.AISTUDIO_PREFIX = exports.MODEL_TIER = exports.BEDROCK_CLAUDE_HAIKU = exports.BEDROCK_CLAUDE_SONNET_4 = exports.BEDROCK_CLAUDE_SONNET_4_5 = exports.BEDROCK_CLAUDE_OPUS_4_1 = exports.BEDROCK_CLAUDE_OPUS_4_5 = exports.BEDROCK_CLAUDE_SONNET = exports.BEDROCK_CLAUDE_OPUS = exports.FALLBACK_MODELS = exports.TRIAL_MODELS = exports.FAST_MODELS = exports.SEMI_MODELS = exports.PRODUCTION_MODELS = exports.AZURE_PRIMARY_MODELS = exports.AZURE_GPT_5_4_NANO = exports.AZURE_GPT_5_4_MINI = exports.AZURE_GPT_5_5 = exports.AZURE_GPT_5_4_NANO_DEPLOYMENT = exports.AZURE_GPT_5_4_MINI_DEPLOYMENT = exports.AZURE_GPT_5_5_DEPLOYMENT = exports.AZURE_PREFIX = exports.GOOGLE_LEGACY_MODELS = exports.GOOGLE_MODELS = exports.AI_MODELS = void 0;
|
|
4
4
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
5
|
const modelContextStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
6
6
|
const BEDROCK_CLAUDE_OPUS = 'us.anthropic.claude-opus-4-6-v1';
|
|
@@ -86,24 +86,32 @@ const TRIAL_MODELS = {
|
|
|
86
86
|
exports.TRIAL_MODELS = TRIAL_MODELS;
|
|
87
87
|
const AISTUDIO_PREFIX = 'aistudio:';
|
|
88
88
|
exports.AISTUDIO_PREFIX = AISTUDIO_PREFIX;
|
|
89
|
+
// Generación anterior, usada solo como escalón de fallback cuando la 3.x no está disponible.
|
|
90
|
+
// Fuente única para que MODEL_PRICING pueda tarifarlos (si no, su coste se calcularía como 0).
|
|
91
|
+
const GOOGLE_LEGACY_MODELS = {
|
|
92
|
+
FLASH: 'gemini-2.5-flash',
|
|
93
|
+
PRO: 'gemini-2.5-pro',
|
|
94
|
+
LITE: 'gemini-2.5-flash-lite',
|
|
95
|
+
};
|
|
96
|
+
exports.GOOGLE_LEGACY_MODELS = GOOGLE_LEGACY_MODELS;
|
|
89
97
|
const FALLBACK_MODELS = {
|
|
90
98
|
FLASH: [
|
|
91
99
|
`${AISTUDIO_PREFIX}${GOOGLE_MODELS.FLASH}`,
|
|
92
|
-
|
|
93
|
-
`${AISTUDIO_PREFIX}
|
|
100
|
+
GOOGLE_LEGACY_MODELS.FLASH,
|
|
101
|
+
`${AISTUDIO_PREFIX}${GOOGLE_LEGACY_MODELS.FLASH}`,
|
|
94
102
|
GOOGLE_MODELS.LITE,
|
|
95
103
|
],
|
|
96
104
|
PRO: [
|
|
97
105
|
`${AISTUDIO_PREFIX}${GOOGLE_MODELS.PRO}`,
|
|
98
|
-
|
|
99
|
-
`${AISTUDIO_PREFIX}
|
|
106
|
+
GOOGLE_LEGACY_MODELS.PRO,
|
|
107
|
+
`${AISTUDIO_PREFIX}${GOOGLE_LEGACY_MODELS.PRO}`,
|
|
100
108
|
GOOGLE_MODELS.FLASH,
|
|
101
109
|
`${AISTUDIO_PREFIX}${GOOGLE_MODELS.FLASH}`,
|
|
102
|
-
|
|
103
|
-
`${AISTUDIO_PREFIX}
|
|
110
|
+
GOOGLE_LEGACY_MODELS.FLASH,
|
|
111
|
+
`${AISTUDIO_PREFIX}${GOOGLE_LEGACY_MODELS.FLASH}`,
|
|
104
112
|
GOOGLE_MODELS.LITE,
|
|
105
113
|
],
|
|
106
|
-
LITE: [`${AISTUDIO_PREFIX}${GOOGLE_MODELS.LITE}`,
|
|
114
|
+
LITE: [`${AISTUDIO_PREFIX}${GOOGLE_MODELS.LITE}`, GOOGLE_LEGACY_MODELS.LITE, `${AISTUDIO_PREFIX}${GOOGLE_LEGACY_MODELS.LITE}`],
|
|
107
115
|
};
|
|
108
116
|
exports.FALLBACK_MODELS = FALLBACK_MODELS;
|
|
109
117
|
const MODEL_TIER = {
|
|
@@ -88,14 +88,32 @@ function lookup(key) {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
exports.lookup = lookup;
|
|
91
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* MISS: inserta (ON CONFLICT cubre la carrera). Fire-and-forget, nunca lanza.
|
|
93
|
+
*
|
|
94
|
+
* Los tokens y el coste desglosado corresponden a la generación que creó la entrada; un HIT
|
|
95
|
+
* posterior no cuesta nada, así que el ON CONFLICT solo toca USE COUNT/LAST USED y NUNCA
|
|
96
|
+
* sobrescribe el coste original.
|
|
97
|
+
*/
|
|
92
98
|
function store(key, data) {
|
|
93
99
|
void ensureReady()
|
|
94
100
|
.then((ok) => {
|
|
95
|
-
var _a, _b;
|
|
101
|
+
var _a, _b, _c, _d, _e, _f;
|
|
96
102
|
if (!ok)
|
|
97
103
|
return undefined;
|
|
98
|
-
return (0, db_1.query)('INSERT INTO "LLM CACHE" ("KEY","MODEL","SYSTEM PROMPT","INPUT PROMPT","SCHEMA SIG","TEMPERATURE","OUTPUT") VALUES (?,?,?,?,?,?,?::jsonb) ON CONFLICT ("KEY") DO UPDATE SET "USE COUNT" = "LLM CACHE"."USE COUNT" + 1, "LAST USED AT" = now()', [
|
|
104
|
+
return (0, db_1.query)('INSERT INTO "LLM CACHE" ("KEY","MODEL","SYSTEM PROMPT","INPUT PROMPT","SCHEMA SIG","TEMPERATURE","OUTPUT","INPUT TOKENS","OUTPUT TOKENS","INPUT COST","OUTPUT COST") VALUES (?,?,?,?,?,?,?::jsonb,?,?,?,?) ON CONFLICT ("KEY") DO UPDATE SET "USE COUNT" = "LLM CACHE"."USE COUNT" + 1, "LAST USED AT" = now()', [
|
|
105
|
+
key,
|
|
106
|
+
data.modelName || null,
|
|
107
|
+
data.system || null,
|
|
108
|
+
data.prompt || null,
|
|
109
|
+
data.schemaSig || null,
|
|
110
|
+
(_a = data.temperature) !== null && _a !== void 0 ? _a : null,
|
|
111
|
+
JSON.stringify((_b = data.output) !== null && _b !== void 0 ? _b : null),
|
|
112
|
+
((_c = data.cost) === null || _c === void 0 ? void 0 : _c.inputTokens) || 0,
|
|
113
|
+
((_d = data.cost) === null || _d === void 0 ? void 0 : _d.outputTokens) || 0,
|
|
114
|
+
((_e = data.cost) === null || _e === void 0 ? void 0 : _e.inputCost) || 0,
|
|
115
|
+
((_f = data.cost) === null || _f === void 0 ? void 0 : _f.outputCost) || 0,
|
|
116
|
+
]);
|
|
99
117
|
})
|
|
100
118
|
.catch(() => { });
|
|
101
119
|
}
|
|
@@ -32,6 +32,22 @@ const MODEL_PRICING = {
|
|
|
32
32
|
inputTokenPrice: 0.25,
|
|
33
33
|
outputTokenPrice: 1.5,
|
|
34
34
|
},
|
|
35
|
+
// Generación 2.5 — solo se alcanza vía fallback, pero sin tarifa su coste se registraría como 0.
|
|
36
|
+
// Tarifa estándar de la Gemini API (verificada 2026-07-20).
|
|
37
|
+
// ⚠️ gemini-2.5-pro tiene precio escalonado ($2.50/$15 por encima de 200k tokens de prompt);
|
|
38
|
+
// aquí se aplica el tramo <=200k, que cubre el tamaño real de los prompts de RunnerPro.
|
|
39
|
+
[constants_1.GOOGLE_LEGACY_MODELS.FLASH]: {
|
|
40
|
+
inputTokenPrice: 0.3,
|
|
41
|
+
outputTokenPrice: 2.5,
|
|
42
|
+
},
|
|
43
|
+
[constants_1.GOOGLE_LEGACY_MODELS.PRO]: {
|
|
44
|
+
inputTokenPrice: 1.25,
|
|
45
|
+
outputTokenPrice: 10,
|
|
46
|
+
},
|
|
47
|
+
[constants_1.GOOGLE_LEGACY_MODELS.LITE]: {
|
|
48
|
+
inputTokenPrice: 0.1,
|
|
49
|
+
outputTokenPrice: 0.4,
|
|
50
|
+
},
|
|
35
51
|
[constants_1.BEDROCK_CLAUDE_OPUS]: {
|
|
36
52
|
inputTokenPrice: 5,
|
|
37
53
|
outputTokenPrice: 25,
|
|
@@ -62,6 +78,21 @@ const MODEL_PRICING = {
|
|
|
62
78
|
},
|
|
63
79
|
};
|
|
64
80
|
exports.MODEL_PRICING = MODEL_PRICING;
|
|
81
|
+
// Modelos ya avisados, para no repetir el log en cada llamada.
|
|
82
|
+
const missingPricingWarned = new Set();
|
|
83
|
+
/**
|
|
84
|
+
* Avisa (una vez por modelo) de que un modelo no tiene tarifa registrada.
|
|
85
|
+
*
|
|
86
|
+
* Sin esto, un modelo nuevo o un escalón de fallback sin tarifar registraría coste 0 en
|
|
87
|
+
* silencio y el gasto medido saldría por debajo del real sin que nada lo delate.
|
|
88
|
+
*/
|
|
89
|
+
function warnMissingPricing(modelName) {
|
|
90
|
+
if (!modelName || missingPricingWarned.has(modelName))
|
|
91
|
+
return;
|
|
92
|
+
missingPricingWarned.add(modelName);
|
|
93
|
+
// eslint-disable-next-line no-console
|
|
94
|
+
console.error(`[modelPricing] Sin tarifa para "${modelName}": su coste se registra como 0. Añádelo a MODEL_PRICING.`);
|
|
95
|
+
}
|
|
65
96
|
/**
|
|
66
97
|
* Calcula el costo de una llamada a IA basado en tokens de entrada y salida
|
|
67
98
|
*
|
|
@@ -79,9 +110,12 @@ exports.MODEL_PRICING = MODEL_PRICING;
|
|
|
79
110
|
function calculateCost(modelName, promptTokens, completionTokens) {
|
|
80
111
|
const pricing = MODEL_PRICING[modelName];
|
|
81
112
|
if (!pricing) {
|
|
113
|
+
warnMissingPricing(modelName);
|
|
82
114
|
return {
|
|
83
115
|
inputTokens: promptTokens || 0,
|
|
84
116
|
outputTokens: completionTokens || 0,
|
|
117
|
+
inputCost: 0,
|
|
118
|
+
outputCost: 0,
|
|
85
119
|
cost: 0,
|
|
86
120
|
};
|
|
87
121
|
}
|
|
@@ -90,6 +124,8 @@ function calculateCost(modelName, promptTokens, completionTokens) {
|
|
|
90
124
|
return {
|
|
91
125
|
inputTokens: promptTokens || 0,
|
|
92
126
|
outputTokens: completionTokens || 0,
|
|
127
|
+
inputCost,
|
|
128
|
+
outputCost,
|
|
93
129
|
cost: inputCost + outputCost,
|
|
94
130
|
};
|
|
95
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../../../src/prompt/ai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,IAAI,sBAAsB,EAAE,YAAY,IAAI,oBAAoB,EAAE,MAAM,IAAI,CAAC;AAEpG,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAwKhE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAe,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAoD/H;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAe,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CA0C5H;
|
|
1
|
+
{"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../../../src/prompt/ai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,IAAI,sBAAsB,EAAE,YAAY,IAAI,oBAAoB,EAAE,MAAM,IAAI,CAAC;AAEpG,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAwKhE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAe,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAoD/H;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAe,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CA0C5H;AA+ED;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAe,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,SAAS,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB5H;AAED,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -20,6 +20,7 @@ declare const SEMI_MODELS: Record<ModelKey, string>;
|
|
|
20
20
|
declare const FAST_MODELS: Record<ModelKey, string>;
|
|
21
21
|
declare const TRIAL_MODELS: Record<ModelKey, string>;
|
|
22
22
|
declare const AISTUDIO_PREFIX = "aistudio:";
|
|
23
|
+
declare const GOOGLE_LEGACY_MODELS: Record<ModelKey, string>;
|
|
23
24
|
declare const FALLBACK_MODELS: Record<ModelKey, string[]>;
|
|
24
25
|
declare const MODEL_TIER: {
|
|
25
26
|
readonly PRODUCTION: "PRODUCTION";
|
|
@@ -54,5 +55,5 @@ declare const AI_MODELS: Record<ModelKey, string>;
|
|
|
54
55
|
* ```
|
|
55
56
|
*/
|
|
56
57
|
declare function runWithModels<T>(modelTier: ModelTierValue, fn: () => Promise<T>): Promise<T>;
|
|
57
|
-
export { ModelKey, ModelTierValue, AI_MODELS, GOOGLE_MODELS, AZURE_PREFIX, AZURE_GPT_5_5_DEPLOYMENT, AZURE_GPT_5_4_MINI_DEPLOYMENT, AZURE_GPT_5_4_NANO_DEPLOYMENT, AZURE_GPT_5_5, AZURE_GPT_5_4_MINI, AZURE_GPT_5_4_NANO, AZURE_PRIMARY_MODELS, PRODUCTION_MODELS, SEMI_MODELS, FAST_MODELS, TRIAL_MODELS, FALLBACK_MODELS, BEDROCK_CLAUDE_OPUS, BEDROCK_CLAUDE_SONNET, BEDROCK_CLAUDE_OPUS_4_5, BEDROCK_CLAUDE_OPUS_4_1, BEDROCK_CLAUDE_SONNET_4_5, BEDROCK_CLAUDE_SONNET_4, BEDROCK_CLAUDE_HAIKU, MODEL_TIER, AISTUDIO_PREFIX, runWithModels, };
|
|
58
|
+
export { ModelKey, ModelTierValue, AI_MODELS, GOOGLE_MODELS, GOOGLE_LEGACY_MODELS, AZURE_PREFIX, AZURE_GPT_5_5_DEPLOYMENT, AZURE_GPT_5_4_MINI_DEPLOYMENT, AZURE_GPT_5_4_NANO_DEPLOYMENT, AZURE_GPT_5_5, AZURE_GPT_5_4_MINI, AZURE_GPT_5_4_NANO, AZURE_PRIMARY_MODELS, PRODUCTION_MODELS, SEMI_MODELS, FAST_MODELS, TRIAL_MODELS, FALLBACK_MODELS, BEDROCK_CLAUDE_OPUS, BEDROCK_CLAUDE_SONNET, BEDROCK_CLAUDE_OPUS_4_5, BEDROCK_CLAUDE_OPUS_4_1, BEDROCK_CLAUDE_SONNET_4_5, BEDROCK_CLAUDE_SONNET_4, BEDROCK_CLAUDE_HAIKU, MODEL_TIER, AISTUDIO_PREFIX, runWithModels, };
|
|
58
59
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/prompt/constants.ts"],"names":[],"mappings":"AAEA,KAAK,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAIzC,QAAA,MAAM,mBAAmB,oCAAoC,CAAC;AAC9D,QAAA,MAAM,qBAAqB,mCAAmC,CAAC;AAC/D,QAAA,MAAM,uBAAuB,+CAA+C,CAAC;AAC7E,QAAA,MAAM,uBAAuB,+CAA+C,CAAC;AAC7E,QAAA,MAAM,yBAAyB,iDAAiD,CAAC;AACjF,QAAA,MAAM,uBAAuB,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AAE,SAAS,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAErF;AAED,OAAO,EACL,QAAQ,EACR,cAAc,EACd,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,wBAAwB,EACxB,6BAA6B,EAC7B,6BAA6B,EAC7B,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,aAAa,GACd,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CostResult } from './modelPricing';
|
|
1
2
|
/** Firma ligera del schema (zod) para distinguir llamadas con el mismo prompt pero distinta forma. */
|
|
2
3
|
declare function schemaSignature(schema: any): string;
|
|
3
4
|
/**
|
|
@@ -13,7 +14,13 @@ declare function llmCacheKey(opts: {
|
|
|
13
14
|
}): string;
|
|
14
15
|
/** HIT: incrementa USE COUNT + LAST USED y devuelve OUTPUT (atómico). null en MISS o ante error. */
|
|
15
16
|
declare function lookup(key: string): Promise<any | null>;
|
|
16
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* MISS: inserta (ON CONFLICT cubre la carrera). Fire-and-forget, nunca lanza.
|
|
19
|
+
*
|
|
20
|
+
* Los tokens y el coste desglosado corresponden a la generación que creó la entrada; un HIT
|
|
21
|
+
* posterior no cuesta nada, así que el ON CONFLICT solo toca USE COUNT/LAST USED y NUNCA
|
|
22
|
+
* sobrescribe el coste original.
|
|
23
|
+
*/
|
|
17
24
|
declare function store(key: string, data: {
|
|
18
25
|
modelName?: string;
|
|
19
26
|
system?: string;
|
|
@@ -21,6 +28,7 @@ declare function store(key: string, data: {
|
|
|
21
28
|
schemaSig?: string | null;
|
|
22
29
|
temperature?: number | null;
|
|
23
30
|
output: any;
|
|
31
|
+
cost?: CostResult;
|
|
24
32
|
}): void;
|
|
25
33
|
export { schemaSignature, llmCacheKey, lookup, store };
|
|
26
34
|
//# sourceMappingURL=llmCacheStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llmCacheStore.d.ts","sourceRoot":"","sources":["../../../../src/prompt/llmCacheStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"llmCacheStore.d.ts","sourceRoot":"","sources":["../../../../src/prompt/llmCacheStore.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAejD,sGAAsG;AACtG,iBAAS,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,CAW5C;AAED;;;;GAIG;AACH,iBAAS,WAAW,CAAC,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,MAAM,CAQ/H;AAED,oGAAoG;AACpG,iBAAe,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAQtD;AAED;;;;;;GAMG;AACH,iBAAS,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAE,GAAG,IAAI,CAsBxL;AAED,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -5,6 +5,10 @@ interface ModelPrice {
|
|
|
5
5
|
interface CostResult {
|
|
6
6
|
inputTokens: number;
|
|
7
7
|
outputTokens: number;
|
|
8
|
+
/** Coste en USD de los tokens de entrada (0 si el modelo no tiene pricing registrado) */
|
|
9
|
+
inputCost?: number;
|
|
10
|
+
/** Coste en USD de los tokens de salida (0 si el modelo no tiene pricing registrado) */
|
|
11
|
+
outputCost?: number;
|
|
8
12
|
cost: number;
|
|
9
13
|
}
|
|
10
14
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelPricing.d.ts","sourceRoot":"","sources":["../../../../src/prompt/modelPricing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"modelPricing.d.ts","sourceRoot":"","sources":["../../../../src/prompt/modelPricing.ts"],"names":[],"mappings":"AAeA,UAAU,UAAU;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,UAAU,UAAU;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wFAAwF;IACxF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,QAAA,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAsE7C,CAAC;AAkBF;;;;;;;;;;;;;GAaG;AACH,iBAAS,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,UAAU,CAwBtG;AAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saveWorkoutAplication.d.ts","sourceRoot":"","sources":["../../../../src/workout/saveWorkoutAplication.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"saveWorkoutAplication.d.ts","sourceRoot":"","sources":["../../../../src/workout/saveWorkoutAplication.ts"],"names":[],"mappings":"AAuTA;;;;;;;;;;GAUG;AACH,QAAA,MAAM,qBAAqB,SACnB,GAAG,UAED,GAAG,KACV,QAAQ,MAAM,GAAG,IAAI,CA6EvB,CAAC;AAuEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -160,6 +160,16 @@ const VENTANA_INICIO_MS = 30 * 60 * 1000;
|
|
|
160
160
|
// terminar, o redondea la duración). 2h la absorben; si aun así no solapan, son
|
|
161
161
|
// dos entrenos distintos y se respetan como dobles.
|
|
162
162
|
const VENTANA_INICIO_MANUAL_MS = 2 * 60 * 60 * 1000;
|
|
163
|
+
// Duración mínima de un entreno importado (anti "entrenos residuales"). Un
|
|
164
|
+
// arranque accidental del reloj/app (p.ej. re-lanzar la rutina al acabar y
|
|
165
|
+
// pararla al minuto) genera en el proveedor una actividad REAL de segundos con
|
|
166
|
+
// UUID propio: el dedup no puede fusionarla (es otra actividad, no solapa) y
|
|
167
|
+
// acababa como "hecho" duplicado del día con el mismo título de rutina, o
|
|
168
|
+
// completando un planificado con 60 s. Por debajo de 2 min no existe una
|
|
169
|
+
// sesión de entrenamiento legítima; se descarta en este embudo común para
|
|
170
|
+
// cubrir TODAS las fuentes (Apple/Strava/Garmin). El completado MANUAL de la
|
|
171
|
+
// app NO pasa por aquí, así que no se ve afectado.
|
|
172
|
+
const DURACION_MINIMA_INGESTA_S = 120;
|
|
163
173
|
const inicioSolapa = (a, b, ventanaMs = VENTANA_INICIO_MS) => {
|
|
164
174
|
if (!a || !b)
|
|
165
175
|
return false;
|
|
@@ -298,6 +308,12 @@ const aplicarMerge = (q, idWorkout, opts, esFilaNueva) => __awaiter(void 0, void
|
|
|
298
308
|
const saveWorkoutAplication = (opts,
|
|
299
309
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
300
310
|
_data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
311
|
+
// Entreno residual: se ignora ANTES de traducir y de abrir la tx. Sólo aplica
|
|
312
|
+
// cuando la fuente informa duración; sin ella no se puede juzgar y se deja pasar.
|
|
313
|
+
const duracionIngesta = Number(opts.duration);
|
|
314
|
+
if (Number.isFinite(duracionIngesta) && duracionIngesta > 0 && duracionIngesta < DURACION_MINIMA_INGESTA_S) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
301
317
|
const dateStr = (0, moment_1.default)(opts.date).format('YYYY-MM-DD');
|
|
302
318
|
const pt = predicadoTipo(opts);
|
|
303
319
|
// Traducción FUERA de la sección crítica. getTitleDescriptionTranslated hace
|