@kwirthmagnify/kwirth-common-ai 0.5.70 → 0.5.72

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/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/dist/front.js CHANGED
@@ -133,7 +133,7 @@ const UsageLimitsEditor = (props) => {
133
133
  // there IS usage, which is when it earns it.
134
134
  const spent = (amounts) => amounts ? `${formatSpent(of(amounts))} so far` : undefined;
135
135
  return (react_1.default.createElement(material_1.Stack, { key: unit, direction: 'row', spacing: 1, alignItems: 'flex-start' },
136
- react_1.default.createElement(material_1.FormControlLabel, { sx: { width: '150px', mr: 0, mt: 0.5 }, control: react_1.default.createElement(material_1.Checkbox, { size: 'small', checked: !!w.enabled, disabled: props.disabled, onChange: e => patch(unit, { enabled: e.target.checked }) }), label: react_1.default.createElement(material_1.Typography, { variant: 'body2' }, label) }),
136
+ react_1.default.createElement(material_1.FormControlLabel, { sx: { width: '150px', flexShrink: 0, mr: 0, mt: 0.5 }, control: react_1.default.createElement(material_1.Checkbox, { size: 'small', checked: !!w.enabled, disabled: props.disabled, onChange: e => patch(unit, { enabled: e.target.checked }) }), label: react_1.default.createElement(material_1.Typography, { variant: 'body2' }, label) }),
137
137
  react_1.default.createElement(material_1.TextField, { value: (_b = w.daily) !== null && _b !== void 0 ? _b : '', onChange: e => patch(unit, { daily: numberOrUndefined(e.target.value) }), label: 'Per day', variant: 'standard', type: 'number', fullWidth: true, size: 'small', disabled: props.disabled || !w.enabled, inputProps: { min: 0 }, placeholder: 'no limit', helperText: spent((_c = props.usage) === null || _c === void 0 ? void 0 : _c.daily), FormHelperTextProps: { sx: { mt: 0 } } }),
138
138
  react_1.default.createElement(material_1.TextField, { value: (_d = w.monthly) !== null && _d !== void 0 ? _d : '', onChange: e => patch(unit, { monthly: numberOrUndefined(e.target.value) }), label: 'Per month', variant: 'standard', type: 'number', fullWidth: true, size: 'small', disabled: props.disabled || !w.enabled, inputProps: { min: 0 }, placeholder: 'no limit', helperText: spent((_e = props.usage) === null || _e === void 0 ? void 0 : _e.monthly), FormHelperTextProps: { sx: { mt: 0 } } })));
139
139
  })));
@@ -248,10 +248,10 @@ const AiConfigLlm = (props) => {
248
248
  react_1.default.createElement(material_1.InputLabel, null, "Model"),
249
249
  react_1.default.createElement(material_1.Select, { value: model, onChange: e => setModel(e.target.value), variant: 'standard', fullWidth: true, displayEmpty: true }, (_b = props.providers.find(p => p.name === provider)) === null || _b === void 0 ? void 0 : _b.models.map((m, i) => (react_1.default.createElement(material_1.MenuItem, { key: i, value: m.id }, m.name))))))
250
250
  : (react_1.default.createElement(material_1.TextField, { value: model, onChange: e => setModel(e.target.value), label: 'Model ID', placeholder: 'e.g. claude-sonnet-4-5, glm-5.2', variant: 'standard', fullWidth: true })),
251
- react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
252
- react_1.default.createElement(material_1.TextField, { value: temperature, onChange: e => setTemperature(+e.target.value), label: 'Temperature', variant: 'standard', type: 'number', sx: { width: '28%' } }),
253
- react_1.default.createElement(material_1.TextField, { value: inputCostPerMillion, onChange: e => setInputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Input cost /M', variant: 'standard', type: 'number', fullWidth: true, inputProps: { min: 0, step: 0.01 } }),
254
- react_1.default.createElement(material_1.TextField, { value: outputCostPerMillion, onChange: e => setOutputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Output cost /M', variant: 'standard', type: 'number', fullWidth: true, inputProps: { min: 0, step: 0.01 } })),
251
+ react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: 'wrap' } },
252
+ react_1.default.createElement(material_1.TextField, { value: temperature, onChange: e => setTemperature(+e.target.value), label: 'Temperature', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: '110px' } }),
253
+ react_1.default.createElement(material_1.TextField, { value: inputCostPerMillion, onChange: e => setInputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Input cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: '110px' }, inputProps: { min: 0, step: 0.01 } }),
254
+ react_1.default.createElement(material_1.TextField, { value: outputCostPerMillion, onChange: e => setOutputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Output cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: '110px' }, inputProps: { min: 0, step: 0.01 } })),
255
255
  react_1.default.createElement(material_1.Stack, { direction: 'row', alignItems: 'center' },
256
256
  react_1.default.createElement(material_1.Typography, { flex: 1 }, "Use provider API Key (or enter a specific one)"),
257
257
  react_1.default.createElement(material_1.Checkbox, { checked: useProviderKey, onChange: e => setUseProviderKey(e.target.checked) })),
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.72",
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",