@runnerpro/backend 1.22.1 → 1.22.3
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 +43 -5
- 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 +18 -2
- 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/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 = {
|
|
@@ -73,13 +73,19 @@ function llmCacheKey(opts) {
|
|
|
73
73
|
return (0, node_crypto_1.createHash)('sha256').update(payload).digest('hex');
|
|
74
74
|
}
|
|
75
75
|
exports.llmCacheKey = llmCacheKey;
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* HIT: incrementa USE COUNT + LAST USED y devuelve OUTPUT (atómico). null en MISS o ante error.
|
|
78
|
+
*
|
|
79
|
+
* El filtro `"OUTPUT" IS NOT NULL` excluye las filas podadas (la poda vacía los textos pero
|
|
80
|
+
* conserva la fila por su coste). Sin él, una fila podada contaría como uso e inflaría USE COUNT,
|
|
81
|
+
* blindándola contra futuras podas pese a no servir ya de caché.
|
|
82
|
+
*/
|
|
77
83
|
function lookup(key) {
|
|
78
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
85
|
if (!(yield ensureReady()))
|
|
80
86
|
return null;
|
|
81
87
|
try {
|
|
82
|
-
const rows = yield (0, db_1.query)('UPDATE "LLM CACHE" SET "USE COUNT" = "USE COUNT" + 1, "LAST USED AT" = now() WHERE "KEY" = ? RETURNING "OUTPUT"', [key]);
|
|
88
|
+
const rows = yield (0, db_1.query)('UPDATE "LLM CACHE" SET "USE COUNT" = "USE COUNT" + 1, "LAST USED AT" = now() WHERE "KEY" = ? AND "OUTPUT" IS NOT NULL RETURNING "OUTPUT"', [key]);
|
|
83
89
|
return rows && rows[0] ? rows[0].output : null;
|
|
84
90
|
}
|
|
85
91
|
catch (_a) {
|
|
@@ -88,14 +94,46 @@ function lookup(key) {
|
|
|
88
94
|
});
|
|
89
95
|
}
|
|
90
96
|
exports.lookup = lookup;
|
|
91
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* MISS: inserta (ON CONFLICT cubre la carrera y la regeneración de una fila podada).
|
|
99
|
+
* Fire-and-forget, nunca lanza.
|
|
100
|
+
*
|
|
101
|
+
* Solo se llama tras una generación REAL (un HIT no cuesta nada y no pasa por aquí), así que el
|
|
102
|
+
* ON CONFLICT ACUMULA tokens y coste en vez de descartarlos: si el mismo prompt se regenera —por
|
|
103
|
+
* una carrera, o porque la poda vació sus textos— ese gasto es real y debe sumarse. Restaura
|
|
104
|
+
* además los textos, devolviendo a la fila podada su capacidad de servir como caché.
|
|
105
|
+
*/
|
|
92
106
|
function store(key, data) {
|
|
93
107
|
void ensureReady()
|
|
94
108
|
.then((ok) => {
|
|
95
|
-
var _a, _b;
|
|
109
|
+
var _a, _b, _c, _d, _e, _f;
|
|
96
110
|
if (!ok)
|
|
97
111
|
return undefined;
|
|
98
|
-
return (0, db_1.query)(
|
|
112
|
+
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")
|
|
113
|
+
VALUES (?,?,?,?,?,?,?::jsonb,?,?,?,?)
|
|
114
|
+
ON CONFLICT ("KEY") DO UPDATE SET
|
|
115
|
+
"USE COUNT" = "LLM CACHE"."USE COUNT" + 1,
|
|
116
|
+
"LAST USED AT" = now(),
|
|
117
|
+
"MODEL" = EXCLUDED."MODEL",
|
|
118
|
+
"SYSTEM PROMPT" = EXCLUDED."SYSTEM PROMPT",
|
|
119
|
+
"INPUT PROMPT" = EXCLUDED."INPUT PROMPT",
|
|
120
|
+
"OUTPUT" = EXCLUDED."OUTPUT",
|
|
121
|
+
"INPUT TOKENS" = "LLM CACHE"."INPUT TOKENS" + EXCLUDED."INPUT TOKENS",
|
|
122
|
+
"OUTPUT TOKENS" = "LLM CACHE"."OUTPUT TOKENS" + EXCLUDED."OUTPUT TOKENS",
|
|
123
|
+
"INPUT COST" = "LLM CACHE"."INPUT COST" + EXCLUDED."INPUT COST",
|
|
124
|
+
"OUTPUT COST" = "LLM CACHE"."OUTPUT COST" + EXCLUDED."OUTPUT COST"`, [
|
|
125
|
+
key,
|
|
126
|
+
data.modelName || null,
|
|
127
|
+
data.system || null,
|
|
128
|
+
data.prompt || null,
|
|
129
|
+
data.schemaSig || null,
|
|
130
|
+
(_a = data.temperature) !== null && _a !== void 0 ? _a : null,
|
|
131
|
+
JSON.stringify((_b = data.output) !== null && _b !== void 0 ? _b : null),
|
|
132
|
+
((_c = data.cost) === null || _c === void 0 ? void 0 : _c.inputTokens) || 0,
|
|
133
|
+
((_d = data.cost) === null || _d === void 0 ? void 0 : _d.outputTokens) || 0,
|
|
134
|
+
((_e = data.cost) === null || _e === void 0 ? void 0 : _e.inputCost) || 0,
|
|
135
|
+
((_f = data.cost) === null || _f === void 0 ? void 0 : _f.outputCost) || 0,
|
|
136
|
+
]);
|
|
99
137
|
})
|
|
100
138
|
.catch(() => { });
|
|
101
139
|
}
|
|
@@ -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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;;;;;;;;;;;GAcG;AACH,iBAAS,aAAa,CAAC,CAAC,EAAE,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
|
/**
|
|
@@ -11,9 +12,23 @@ declare function llmCacheKey(opts: {
|
|
|
11
12
|
schemaSig?: string | null;
|
|
12
13
|
temperature?: number | null;
|
|
13
14
|
}): string;
|
|
14
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* HIT: incrementa USE COUNT + LAST USED y devuelve OUTPUT (atómico). null en MISS o ante error.
|
|
17
|
+
*
|
|
18
|
+
* El filtro `"OUTPUT" IS NOT NULL` excluye las filas podadas (la poda vacía los textos pero
|
|
19
|
+
* conserva la fila por su coste). Sin él, una fila podada contaría como uso e inflaría USE COUNT,
|
|
20
|
+
* blindándola contra futuras podas pese a no servir ya de caché.
|
|
21
|
+
*/
|
|
15
22
|
declare function lookup(key: string): Promise<any | null>;
|
|
16
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* MISS: inserta (ON CONFLICT cubre la carrera y la regeneración de una fila podada).
|
|
25
|
+
* Fire-and-forget, nunca lanza.
|
|
26
|
+
*
|
|
27
|
+
* Solo se llama tras una generación REAL (un HIT no cuesta nada y no pasa por aquí), así que el
|
|
28
|
+
* ON CONFLICT ACUMULA tokens y coste en vez de descartarlos: si el mismo prompt se regenera —por
|
|
29
|
+
* una carrera, o porque la poda vació sus textos— ese gasto es real y debe sumarse. Restaura
|
|
30
|
+
* además los textos, devolviendo a la fila podada su capacidad de servir como caché.
|
|
31
|
+
*/
|
|
17
32
|
declare function store(key: string, data: {
|
|
18
33
|
modelName?: string;
|
|
19
34
|
system?: string;
|
|
@@ -21,6 +36,7 @@ declare function store(key: string, data: {
|
|
|
21
36
|
schemaSig?: string | null;
|
|
22
37
|
temperature?: number | null;
|
|
23
38
|
output: any;
|
|
39
|
+
cost?: CostResult;
|
|
24
40
|
}): void;
|
|
25
41
|
export { schemaSignature, llmCacheKey, lookup, store };
|
|
26
42
|
//# 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;;;;;;GAMG;AACH,iBAAe,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAWtD;AAED;;;;;;;;GAQG;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,CAkCxL;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"}
|