@kwirthmagnify/kwirth-common-ai 0.5.70 → 0.5.71

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.
Files changed (2) hide show
  1. package/dist/back.js +16 -4
  2. package/package.json +1 -1
package/dist/back.js CHANGED
@@ -222,11 +222,23 @@ const runWithUsageGuard = async (options, call) => {
222
222
  throw new UsageLimitError(exceeded);
223
223
  }
224
224
  }
225
+ /* 🔴 En `finally`, no después del `await`. La primera versión medía solo el camino feliz, que es
226
+ justo el que no hacía falta medir: cuando una llamada se aborta por tiempo —el caso que se estaba
227
+ investigando— el log no se ejecutaba y seguíamos sin saber si el tiempo era del modelo o de la
228
+ contabilidad de aquí arriba (2026-10-14). Un tramo instrumentado solo cuando va bien no está
229
+ instrumentado. */
225
230
  const callStarted = Date.now();
226
- const result = await call();
227
- const callMs = Date.now() - callStarted;
228
- if (callMs > 30000)
229
- logUsage(`AI usage: the model took ${Math.round(callMs / 1000)} s to answer (counters read in ${readMs} ms)`);
231
+ let ok = false;
232
+ let result;
233
+ try {
234
+ result = await call();
235
+ ok = true;
236
+ }
237
+ finally {
238
+ const callMs = Date.now() - callStarted;
239
+ if (callMs > 30000 || !ok)
240
+ logUsage(`AI usage: the model ${ok ? 'took' : 'FAILED after'} ${Math.round(callMs / 1000)} s (counters read in ${readMs} ms)`);
241
+ }
230
242
  const tokensIn = (_c = (_b = result.usage) === null || _b === void 0 ? void 0 : _b.inputTokens) !== null && _c !== void 0 ? _c : 0;
231
243
  const tokensOut = (_e = (_d = result.usage) === null || _d === void 0 ? void 0 : _d.outputTokens) !== null && _e !== void 0 ? _e : 0;
232
244
  /* Sin `await`: la respuesta ya está. Esperar al apunte solo añade el tiempo de la base a lo que el
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-ai",
3
- "version": "0.5.70",
3
+ "version": "0.5.71",
4
4
  "description": "Shared AI/LLM types and utilities for Kwirth AI plugins",
5
5
  "scripts": {
6
6
  "build": "del .\\dist\\* /s /q 2>nul & tsc",