@kwirthmagnify/kwirth-common-ai 0.5.76 → 0.5.78
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 +54 -9
- package/dist/front.js +108 -81
- package/package.json +3 -3
package/dist/back.js
CHANGED
|
@@ -294,6 +294,7 @@ const usageRecord = (options, result) => {
|
|
|
294
294
|
}).catch(err => logUsage(`AI usage: could not record ${tokensIn + tokensOut} token(s) of a call that DID happen (${err}) — the counters are now short`));
|
|
295
295
|
};
|
|
296
296
|
const runWithUsageGuard = async (options, call) => {
|
|
297
|
+
var _a, _b, _c, _d;
|
|
297
298
|
await usageGuardCheck(options);
|
|
298
299
|
/* 🔴 En `finally`, no después del `await`. La primera versión medía solo el camino feliz, que es
|
|
299
300
|
justo el que no hacía falta medir: cuando una llamada se aborta por tiempo —el caso que se estaba
|
|
@@ -301,21 +302,65 @@ const runWithUsageGuard = async (options, call) => {
|
|
|
301
302
|
contabilidad de aquí arriba (2026-10-14). Un tramo instrumentado solo cuando va bien no está
|
|
302
303
|
instrumentado. */
|
|
303
304
|
const callStarted = Date.now();
|
|
304
|
-
let ok = false;
|
|
305
|
-
let result;
|
|
306
305
|
try {
|
|
307
|
-
result = await call();
|
|
308
|
-
|
|
306
|
+
const result = await call();
|
|
307
|
+
const callMs = Date.now() - callStarted;
|
|
308
|
+
if (callMs > 30000)
|
|
309
|
+
logUsage(`AI usage: the model took ${Math.round(callMs / 1000)} s`);
|
|
310
|
+
usageRecord(options, result);
|
|
311
|
+
return result;
|
|
309
312
|
}
|
|
310
|
-
|
|
313
|
+
catch (err) {
|
|
314
|
+
/* 🔴 Una llamada que LANZA puede haber gastado igual, y hasta aquí ese gasto se tiraba.
|
|
315
|
+
|
|
316
|
+
`generateObject` lanza cuando lo que devuelve el modelo no valida contra el esquema, pero
|
|
317
|
+
para entonces el modelo ya ha contestado y ya ha cobrado: el error del SDK
|
|
318
|
+
(`NoObjectGeneratedError`) trae su `usage` dentro. Como `usageRecord` vivía DESPUÉS del
|
|
319
|
+
`await`, no llegaba a ejecutarse y esos tokens no contaban contra ningún tope — y no es un
|
|
320
|
+
caso raro: un canal cuyo modelo devuelve algo que no casa el ejemplo lo hace en cada
|
|
321
|
+
llamada, así que podía gastar sin límite y sin dejar rastro en los contadores.
|
|
322
|
+
|
|
323
|
+
Y entonces tampoco se llama FAILED: el modelo respondió. Decir que falló mandaba a mirar al
|
|
324
|
+
sitio equivocado —la conexión, el tiempo— cuando lo que hay que mirar es el esquema. */
|
|
311
325
|
const callMs = Date.now() - callStarted;
|
|
312
|
-
|
|
313
|
-
|
|
326
|
+
const gastado = usageOfRejected(err);
|
|
327
|
+
if (gastado) {
|
|
328
|
+
const total = ((_b = (_a = gastado.usage) === null || _a === void 0 ? void 0 : _a.inputTokens) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = gastado.usage) === null || _c === void 0 ? void 0 : _c.outputTokens) !== null && _d !== void 0 ? _d : 0);
|
|
329
|
+
logUsage(`AI usage: the model answered in ${Math.round(callMs / 1000)} s but its answer was rejected (${errorName(err)}) — the ${total} token(s) it spent are counted anyway`);
|
|
330
|
+
usageRecord(options, gastado);
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
logUsage(`AI usage: the model FAILED after ${Math.round(callMs / 1000)} s`);
|
|
334
|
+
}
|
|
335
|
+
throw err;
|
|
314
336
|
}
|
|
315
|
-
usageRecord(options, result);
|
|
316
|
-
return result;
|
|
317
337
|
};
|
|
318
338
|
exports.runWithUsageGuard = runWithUsageGuard;
|
|
339
|
+
/** El nombre del error del SDK (`NoObjectGeneratedError`, `AI_TypeValidationError`…), para decir POR QUÉ. */
|
|
340
|
+
const errorName = (err) => typeof err === 'object' && err !== null && typeof err.name === 'string'
|
|
341
|
+
? err.name
|
|
342
|
+
: 'unknown error';
|
|
343
|
+
/*
|
|
344
|
+
Lo que gastó una llamada que el SDK dio por fallida, si es que lo dice.
|
|
345
|
+
|
|
346
|
+
Se lee a mano en vez de con `NoObjectGeneratedError.isInstance`: el error puede venir de otra copia
|
|
347
|
+
del SDK —cada canal trae la suya— y entonces el `instanceof` falla aunque el error sea exactamente
|
|
348
|
+
ese. Lo que importa son los números, y los números están o no están.
|
|
349
|
+
*/
|
|
350
|
+
const usageOfRejected = (err) => {
|
|
351
|
+
if (typeof err !== 'object' || err === null)
|
|
352
|
+
return undefined;
|
|
353
|
+
const usage = err.usage;
|
|
354
|
+
if (typeof usage !== 'object' || usage === null)
|
|
355
|
+
return undefined;
|
|
356
|
+
const { inputTokens, outputTokens } = usage;
|
|
357
|
+
const entrada = typeof inputTokens === 'number' ? inputTokens : undefined;
|
|
358
|
+
const salida = typeof outputTokens === 'number' ? outputTokens : undefined;
|
|
359
|
+
// sin ninguna de las dos cifras no hay nada que apuntar, y apuntar ceros falsearia los contadores
|
|
360
|
+
if (entrada === undefined && salida === undefined)
|
|
361
|
+
return undefined;
|
|
362
|
+
return { usage: { inputTokens: entrada, outputTokens: salida } };
|
|
363
|
+
};
|
|
319
364
|
// Generic MULTIMODAL call: sends an image plus a prompt to an LLM and returns STRUCTURED output validated by
|
|
320
365
|
// a Zod schema (the Output.object pattern). Reusable across the whole platform (Iter uses it to extract a map
|
|
321
366
|
// from a diagram). It never throws: errors come back in `error`.
|
package/dist/front.js
CHANGED
|
@@ -49,27 +49,22 @@ const material_1 = require("@mui/material");
|
|
|
49
49
|
That is why the "no deep imports" rule is only for PLUGINS — there it breaks @emotion, which loads a
|
|
50
50
|
copy of its own — and common-front and common-ai are the documented exception.
|
|
51
51
|
*/
|
|
52
|
-
const Download_1 = __importDefault(require("@mui/icons-material/Download"));
|
|
53
|
-
const Upload_1 = __importDefault(require("@mui/icons-material/Upload"));
|
|
54
52
|
const Visibility_1 = __importDefault(require("@mui/icons-material/Visibility"));
|
|
55
53
|
const VisibilityOff_1 = __importDefault(require("@mui/icons-material/VisibilityOff"));
|
|
56
|
-
const downloadJson = async (data, filename) => {
|
|
57
|
-
var _a;
|
|
58
|
-
const json = JSON.stringify(data, null, 2);
|
|
59
|
-
const tauri = window.__TAURI__;
|
|
60
|
-
if ((_a = tauri === null || tauri === void 0 ? void 0 : tauri.core) === null || _a === void 0 ? void 0 : _a.invoke) {
|
|
61
|
-
await tauri.core.invoke('save_file_dialog', { filename, content: json });
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const blob = new Blob([json], { type: 'application/json' });
|
|
65
|
-
const url = URL.createObjectURL(blob);
|
|
66
|
-
const a = document.createElement('a');
|
|
67
|
-
a.href = url;
|
|
68
|
-
a.download = filename;
|
|
69
|
-
a.click();
|
|
70
|
-
URL.revokeObjectURL(url);
|
|
71
|
-
};
|
|
72
54
|
const index_1 = require("./index");
|
|
55
|
+
/*
|
|
56
|
+
🔴 These dialogs HAVE NO Import/Export of their own, and that is deliberate — do not add them back.
|
|
57
|
+
|
|
58
|
+
Both lists travel in the core's configuration bundle, under `core/sharedAi` ('AI providers and
|
|
59
|
+
models'), which is reached from ☰ → Kwirth export / Kwirth import. It writes to the very same
|
|
60
|
+
configmap and secret these dialogs do, so a second door onto the same store could only diverge from
|
|
61
|
+
it — and it had: the local export emitted a hand-written subset of the provider, so the prices and
|
|
62
|
+
the limits added on 2026-10-26 were silently dropped, and the local import replaced the whole list
|
|
63
|
+
from an unvalidated file, with a `catch {}` that said nothing when the file was not one.
|
|
64
|
+
|
|
65
|
+
The bundle also honours the 'Include credentials' tick (see `redactSharedAi` in the core), which a
|
|
66
|
+
plain download of the list in clear could not.
|
|
67
|
+
*/
|
|
73
68
|
/*
|
|
74
69
|
The height of the content of BOTH config dialogs, and the one number that keeps them still.
|
|
75
70
|
|
|
@@ -135,7 +130,9 @@ const UsageLimitsEditor = (props) => {
|
|
|
135
130
|
model has answered — is still said, in one line, where the limit is set.
|
|
136
131
|
*/
|
|
137
132
|
return (react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 0.5, sx: { mt: 0.5 } },
|
|
138
|
-
react_1.default.createElement(material_1.Typography, { variant: 'caption',
|
|
133
|
+
react_1.default.createElement(material_1.Typography, { variant: 'caption', sx: {
|
|
134
|
+
color: 'text.secondary'
|
|
135
|
+
} },
|
|
139
136
|
"Stop spending on ",
|
|
140
137
|
react_1.default.createElement("b", null, props.subject),
|
|
141
138
|
": a call goes out only if ",
|
|
@@ -150,7 +147,9 @@ const UsageLimitsEditor = (props) => {
|
|
|
150
147
|
react_1.default.createElement("b", null, "next"),
|
|
151
148
|
" one."),
|
|
152
149
|
props.usage && props.durable === false &&
|
|
153
|
-
react_1.default.createElement(material_1.Typography, { variant: 'caption',
|
|
150
|
+
react_1.default.createElement(material_1.Typography, { variant: 'caption', sx: {
|
|
151
|
+
color: 'warning.main'
|
|
152
|
+
} },
|
|
154
153
|
"\u26A0\uFE0F Counters kept ",
|
|
155
154
|
react_1.default.createElement("b", null, "in memory"),
|
|
156
155
|
" (no SQL): they reset on every restart, and so do these limits."),
|
|
@@ -164,10 +163,16 @@ const UsageLimitsEditor = (props) => {
|
|
|
164
163
|
salta bajo el cursor. Un diálogo que se mueve mientras lo lees cuesta más que el dato
|
|
165
164
|
que daba, y el dato está en el panel de consumo.
|
|
166
165
|
*/
|
|
167
|
-
return (react_1.default.createElement(material_1.Stack, { key: unit, direction: 'row', spacing: 1,
|
|
166
|
+
return (react_1.default.createElement(material_1.Stack, { key: unit, direction: 'row', spacing: 1, sx: {
|
|
167
|
+
alignItems: 'flex-start'
|
|
168
|
+
} },
|
|
168
169
|
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) }),
|
|
169
|
-
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,
|
|
170
|
-
|
|
170
|
+
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, placeholder: 'no limit', slotProps: {
|
|
171
|
+
htmlInput: { min: 0 }
|
|
172
|
+
} }),
|
|
173
|
+
react_1.default.createElement(material_1.TextField, { value: (_c = w.monthly) !== null && _c !== void 0 ? _c : '', 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, placeholder: 'no limit', slotProps: {
|
|
174
|
+
htmlInput: { min: 0 }
|
|
175
|
+
} })));
|
|
171
176
|
})));
|
|
172
177
|
};
|
|
173
178
|
const LlmSelector = ({ llms, value, onChange, label = 'LLM', size = 'small', fullWidth = true }) => {
|
|
@@ -185,7 +190,6 @@ exports.LlmSelector = LlmSelector;
|
|
|
185
190
|
const AiConfigLlm = (props) => {
|
|
186
191
|
var _a, _b, _c;
|
|
187
192
|
const [llms, setLlms] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.llms)));
|
|
188
|
-
const importLlmRef = (0, react_1.useRef)(null);
|
|
189
193
|
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
|
|
190
194
|
const [showPassword, setShowPassword] = (0, react_1.useState)(false);
|
|
191
195
|
const [id, setId] = (0, react_1.useState)('');
|
|
@@ -268,7 +272,9 @@ const AiConfigLlm = (props) => {
|
|
|
268
272
|
Add/Update button below the fold on a short screen: the form grew, the dialog did not, and the
|
|
269
273
|
control that applies the form to the list scrolled out of sight.
|
|
270
274
|
*/
|
|
271
|
-
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined),
|
|
275
|
+
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), maxWidth: false, slotProps: {
|
|
276
|
+
paper: { sx: { width: 'auto', height: 'auto' } }
|
|
277
|
+
} },
|
|
272
278
|
react_1.default.createElement(material_1.DialogTitle, { sx: { pb: 1 } }, "AI \u2014 LLM config"),
|
|
273
279
|
react_1.default.createElement(material_1.DialogContent, { style: { display: 'flex' } },
|
|
274
280
|
react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px', boxSizing: 'border-box', position: 'relative' } },
|
|
@@ -276,10 +282,16 @@ const AiConfigLlm = (props) => {
|
|
|
276
282
|
react_1.default.createElement(material_1.List, { sx: { flexGrow: 1, mr: 2, width: '100%' } }, llms.map((llm, index) => (react_1.default.createElement(material_1.ListItemButton, { key: index, selected: selectedIndex === index, onClick: () => onLlmSelected(index) },
|
|
277
283
|
react_1.default.createElement(material_1.Stack, { direction: 'column' },
|
|
278
284
|
react_1.default.createElement(material_1.Typography, { sx: { fontWeight: selectedIndex === index ? 'bold' : 'normal' } }, llm.id),
|
|
279
|
-
react_1.default.createElement(material_1.Typography, { color: 'darkgray',
|
|
285
|
+
react_1.default.createElement(material_1.Typography, { color: 'darkgray', sx: {
|
|
286
|
+
fontSize: 12
|
|
287
|
+
} }, llm.provider)))))))),
|
|
280
288
|
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', flexDirection: 'column', padding: '16px', minWidth: 0 } },
|
|
281
289
|
react_1.default.createElement(material_1.Stack, { spacing: 2, style: { width: '100%' } },
|
|
282
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 3,
|
|
290
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 3, sx: {
|
|
291
|
+
alignItems: 'stretch',
|
|
292
|
+
flexWrap: 'nowrap',
|
|
293
|
+
height: '100%'
|
|
294
|
+
} },
|
|
283
295
|
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
|
|
284
296
|
react_1.default.createElement(material_1.TextField, { value: id, onChange: e => setId(e.target.value), placeholder: 'Enter LLM id', label: 'LLM ID', variant: 'standard', fullWidth: true }),
|
|
285
297
|
react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
|
|
@@ -295,41 +307,44 @@ const AiConfigLlm = (props) => {
|
|
|
295
307
|
: (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 })),
|
|
296
308
|
react_1.default.createElement(material_1.TextField, { value: temperature, onChange: e => setTemperature(+e.target.value), label: 'Temperature', variant: 'standard', type: 'number', fullWidth: true }),
|
|
297
309
|
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: 'nowrap' } },
|
|
298
|
-
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: 0 },
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
310
|
+
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: 0 }, placeholder: providerCost(provider, 'inputCostPerMillion'), slotProps: {
|
|
311
|
+
htmlInput: { min: 0, step: 0.01 },
|
|
312
|
+
inputLabel: { shrink: true }
|
|
313
|
+
} }),
|
|
314
|
+
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: 0 }, placeholder: providerCost(provider, 'outputCostPerMillion'), slotProps: {
|
|
315
|
+
htmlInput: { min: 0, step: 0.01 },
|
|
316
|
+
inputLabel: { shrink: true }
|
|
317
|
+
} })),
|
|
318
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', sx: {
|
|
319
|
+
alignItems: 'center'
|
|
320
|
+
} },
|
|
321
|
+
react_1.default.createElement(material_1.Typography, { sx: {
|
|
322
|
+
flex: 1
|
|
323
|
+
} }, "Use provider API Key"),
|
|
302
324
|
react_1.default.createElement(material_1.Checkbox, { checked: useProviderKey, onChange: e => setUseProviderKey(e.target.checked) })),
|
|
303
|
-
react_1.default.createElement(material_1.TextField, { value: key, onChange: e => setKey(e.target.value), disabled: useProviderKey, label: 'API Key', placeholder: 'Enter API Key', variant: 'standard', fullWidth: true, type: showPassword ? 'text' : 'password',
|
|
304
|
-
|
|
305
|
-
react_1.default.createElement(material_1.
|
|
325
|
+
react_1.default.createElement(material_1.TextField, { value: key, onChange: e => setKey(e.target.value), disabled: useProviderKey, label: 'API Key', placeholder: 'Enter API Key', variant: 'standard', fullWidth: true, type: showPassword ? 'text' : 'password', slotProps: {
|
|
326
|
+
input: {
|
|
327
|
+
endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
|
|
328
|
+
react_1.default.createElement(material_1.IconButton, { onClick: () => setShowPassword(!showPassword), edge: 'end' }, showPassword ? react_1.default.createElement(VisibilityOff_1.default, null) : react_1.default.createElement(Visibility_1.default, null))))
|
|
329
|
+
}
|
|
306
330
|
} })),
|
|
307
331
|
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
|
|
308
332
|
react_1.default.createElement(material_1.Typography, { variant: 'subtitle2' }, "Usage limits"),
|
|
309
333
|
react_1.default.createElement(UsageLimitsEditor, { value: limits, onChange: setLimits, subject: `the key this model uses`, usage: (_c = props.usage) === null || _c === void 0 ? void 0 : _c[id], durable: props.usageDurable }),
|
|
310
|
-
react_1.default.createElement(material_1.Typography, { variant: 'caption',
|
|
334
|
+
react_1.default.createElement(material_1.Typography, { variant: 'caption', sx: {
|
|
335
|
+
color: 'text.secondary'
|
|
336
|
+
} }, "Left empty, the provider's limits apply. Spending is counted per API key.")))),
|
|
311
337
|
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { pt: 2 } },
|
|
312
338
|
react_1.default.createElement(material_1.Button, { variant: 'outlined', size: 'small', onClick: onNew }, "New"),
|
|
313
|
-
react_1.default.createElement(material_1.Typography, {
|
|
339
|
+
react_1.default.createElement(material_1.Typography, { sx: {
|
|
340
|
+
flex: 1
|
|
341
|
+
} }),
|
|
314
342
|
react_1.default.createElement(material_1.Button, { color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
|
|
315
343
|
react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !id || !model }, selectedIndex !== null ? 'Update' : 'Add')))),
|
|
316
344
|
react_1.default.createElement(material_1.DialogActions, null,
|
|
317
|
-
react_1.default.createElement(
|
|
318
|
-
|
|
319
|
-
const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
320
|
-
if (!f)
|
|
321
|
-
return;
|
|
322
|
-
const reader = new FileReader();
|
|
323
|
-
reader.onload = ev => { try {
|
|
324
|
-
setLlms(JSON.parse(ev.target.result));
|
|
325
|
-
}
|
|
326
|
-
catch (_a) { } };
|
|
327
|
-
reader.readAsText(f);
|
|
328
|
-
e.target.value = '';
|
|
345
|
+
react_1.default.createElement(material_1.Box, { sx: {
|
|
346
|
+
flex: 1
|
|
329
347
|
} }),
|
|
330
|
-
react_1.default.createElement(material_1.Button, { variant: 'outlined', startIcon: react_1.default.createElement(Upload_1.default, { fontSize: 'small' }), onClick: () => { var _a; return (_a = importLlmRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }, "Import"),
|
|
331
|
-
react_1.default.createElement(material_1.Button, { variant: 'outlined', startIcon: react_1.default.createElement(Download_1.default, { fontSize: 'small' }), onClick: () => downloadJson(llms, 'kwirth-llms.json') }, "Export"),
|
|
332
|
-
react_1.default.createElement(material_1.Box, { flex: 1 }),
|
|
333
348
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(llms), variant: 'contained' }, "OK"),
|
|
334
349
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), variant: 'outlined' }, "Cancel"))));
|
|
335
350
|
};
|
|
@@ -337,7 +352,6 @@ exports.AiConfigLlm = AiConfigLlm;
|
|
|
337
352
|
const AiConfigProvider = (props) => {
|
|
338
353
|
var _a, _b;
|
|
339
354
|
const [providers, setProviders] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.providers)));
|
|
340
|
-
const importProvRef = (0, react_1.useRef)(null);
|
|
341
355
|
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
|
|
342
356
|
const [showPassword, setShowPassword] = (0, react_1.useState)(false);
|
|
343
357
|
const [loadingModels, setLoadingModels] = (0, react_1.useState)(false);
|
|
@@ -422,7 +436,9 @@ const AiConfigProvider = (props) => {
|
|
|
422
436
|
setLoadingModels(false);
|
|
423
437
|
}
|
|
424
438
|
};
|
|
425
|
-
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined),
|
|
439
|
+
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), maxWidth: false, slotProps: {
|
|
440
|
+
paper: { sx: { width: 'auto', height: 'auto' } }
|
|
441
|
+
} },
|
|
426
442
|
react_1.default.createElement(material_1.DialogTitle, { sx: { pb: 1 } }, "AI \u2014 Provider config"),
|
|
427
443
|
react_1.default.createElement(material_1.DialogContent, { style: { display: 'flex' } },
|
|
428
444
|
react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px', boxSizing: 'border-box', position: 'relative' } },
|
|
@@ -432,60 +448,68 @@ const AiConfigProvider = (props) => {
|
|
|
432
448
|
return (react_1.default.createElement(material_1.ListItemButton, { key: index, selected: selectedIndex === index, onClick: () => onProviderSelected(p, index) },
|
|
433
449
|
react_1.default.createElement(material_1.Stack, { direction: 'column' },
|
|
434
450
|
react_1.default.createElement(material_1.Typography, { sx: { fontWeight: selectedIndex === index ? 'bold' : 'normal' } }, p.name),
|
|
435
|
-
react_1.default.createElement(material_1.Typography, { color: 'darkgray',
|
|
451
|
+
react_1.default.createElement(material_1.Typography, { color: 'darkgray', sx: {
|
|
452
|
+
fontSize: 11
|
|
453
|
+
} },
|
|
436
454
|
((_a = p.models) === null || _a === void 0 ? void 0 : _a.length) || 0,
|
|
437
455
|
" models loaded"))));
|
|
438
456
|
})))),
|
|
439
457
|
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', flexDirection: 'column', padding: '16px', minWidth: 0 } },
|
|
440
458
|
react_1.default.createElement(material_1.Stack, { spacing: 2, style: { width: '100%' } },
|
|
441
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 3,
|
|
459
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 3, sx: {
|
|
460
|
+
alignItems: 'flex-start',
|
|
461
|
+
flexWrap: 'nowrap'
|
|
462
|
+
} },
|
|
442
463
|
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
|
|
443
464
|
react_1.default.createElement(material_1.TextField, { label: 'Name', variant: 'standard', fullWidth: true, placeholder: 'e.g. huawei-maas, openai-prod', value: providerName, onChange: e => setProviderName(e.target.value), helperText: 'Unique identifier for this provider instance' }),
|
|
444
465
|
react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
|
|
445
466
|
react_1.default.createElement(material_1.InputLabel, null, "Type"),
|
|
446
467
|
react_1.default.createElement(material_1.Select, { value: providerType, onChange: e => { setProviderType(e.target.value); if (!providerName)
|
|
447
468
|
setProviderName(e.target.value); }, variant: 'standard', fullWidth: true }, props.providersAvailable.map(t => (react_1.default.createElement(material_1.MenuItem, { key: t, value: t }, t))))),
|
|
448
|
-
react_1.default.createElement(material_1.TextField, { label: 'API Key / Token', type: showPassword ? 'text' : 'password', variant: 'standard', fullWidth: true, value: providerKey, onChange: e => setProviderKey(e.target.value), helperText: 'This key can be afterwards linked to specific uses.',
|
|
449
|
-
|
|
450
|
-
react_1.default.createElement(material_1.
|
|
469
|
+
react_1.default.createElement(material_1.TextField, { label: 'API Key / Token', type: showPassword ? 'text' : 'password', variant: 'standard', fullWidth: true, value: providerKey, onChange: e => setProviderKey(e.target.value), helperText: 'This key can be afterwards linked to specific uses.', slotProps: {
|
|
470
|
+
input: {
|
|
471
|
+
endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
|
|
472
|
+
react_1.default.createElement(material_1.IconButton, { onClick: () => setShowPassword(!showPassword), edge: 'end' }, showPassword ? react_1.default.createElement(VisibilityOff_1.default, null) : react_1.default.createElement(Visibility_1.default, null))))
|
|
473
|
+
}
|
|
451
474
|
} }),
|
|
452
475
|
react_1.default.createElement(material_1.TextField, { label: 'Base URL', variant: 'standard', fullWidth: true, placeholder: 'https://your-maas-host/v1', value: providerEndpoint, onChange: e => setProviderEndpoint(e.target.value), disabled: providerType !== 'openai-compat' }),
|
|
453
476
|
react_1.default.createElement(material_1.Typography, { variant: 'subtitle2', sx: { pt: 1 } }, "Default model costs"),
|
|
454
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: '
|
|
455
|
-
react_1.default.createElement(material_1.TextField, { value: providerInputCost, onChange: e => setProviderInputCost(e.target.value === '' ? '' : +e.target.value), label: 'Input cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth:
|
|
456
|
-
|
|
457
|
-
|
|
477
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: 'nowrap' } },
|
|
478
|
+
react_1.default.createElement(material_1.TextField, { value: providerInputCost, onChange: e => setProviderInputCost(e.target.value === '' ? '' : +e.target.value), label: 'Input cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: 0 }, slotProps: {
|
|
479
|
+
htmlInput: { min: 0, step: 0.01 }
|
|
480
|
+
} }),
|
|
481
|
+
react_1.default.createElement(material_1.TextField, { value: providerOutputCost, onChange: e => setProviderOutputCost(e.target.value === '' ? '' : +e.target.value), label: 'Output cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: 0 }, slotProps: {
|
|
482
|
+
htmlInput: { min: 0, step: 0.01 }
|
|
483
|
+
} })),
|
|
484
|
+
react_1.default.createElement(material_1.Typography, { variant: 'caption', sx: {
|
|
485
|
+
color: 'text.secondary'
|
|
486
|
+
} }, "Used by models that declare no cost of their own.")),
|
|
458
487
|
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
|
|
459
488
|
react_1.default.createElement(material_1.Typography, { variant: 'subtitle2' }, "Usage limits"),
|
|
460
489
|
react_1.default.createElement(UsageLimitsEditor, { value: providerLimits, onChange: setProviderLimits, subject: `this provider's key`, disabled: !providerName.trim(), usage: (_b = props.usage) === null || _b === void 0 ? void 0 : _b[providerName], durable: props.usageDurable })))),
|
|
461
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1,
|
|
490
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: {
|
|
491
|
+
alignItems: 'center',
|
|
492
|
+
pt: 2
|
|
493
|
+
} },
|
|
462
494
|
react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onNew }, "New"),
|
|
463
495
|
props.onLoadModels && (react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onLoadModels, disabled: !providerType || !providerKey || loadingModels, startIcon: loadingModels ? react_1.default.createElement(material_1.CircularProgress, { size: 14 }) : undefined }, loadingModels ? 'Loading...' : `Load models${pendingModels.length ? ` (${pendingModels.length})` : ''}`)),
|
|
464
|
-
react_1.default.createElement(material_1.Typography, {
|
|
496
|
+
react_1.default.createElement(material_1.Typography, { sx: {
|
|
497
|
+
flex: 1
|
|
498
|
+
} }),
|
|
465
499
|
react_1.default.createElement(material_1.Button, { variant: 'text', color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
|
|
466
500
|
react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !providerName.trim() || !providerType }, selectedIndex !== null ? 'Update' : 'Add')))),
|
|
467
501
|
react_1.default.createElement(material_1.DialogActions, { sx: { p: 2 } },
|
|
468
|
-
react_1.default.createElement(
|
|
469
|
-
|
|
470
|
-
const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
471
|
-
if (!f)
|
|
472
|
-
return;
|
|
473
|
-
const reader = new FileReader();
|
|
474
|
-
reader.onload = ev => { try {
|
|
475
|
-
setProviders(JSON.parse(ev.target.result));
|
|
476
|
-
}
|
|
477
|
-
catch (_a) { } };
|
|
478
|
-
reader.readAsText(f);
|
|
479
|
-
e.target.value = '';
|
|
502
|
+
react_1.default.createElement(material_1.Box, { sx: {
|
|
503
|
+
flex: 1
|
|
480
504
|
} }),
|
|
481
|
-
react_1.default.createElement(material_1.Button, { variant: 'outlined', startIcon: react_1.default.createElement(Upload_1.default, { fontSize: 'small' }), onClick: () => { var _a; return (_a = importProvRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }, "Import"),
|
|
482
|
-
react_1.default.createElement(material_1.Button, { variant: 'outlined', startIcon: react_1.default.createElement(Download_1.default, { fontSize: 'small' }), onClick: () => downloadJson(providers.map(p => { var _a; return (Object.assign({ name: p.name, type: (_a = p.type) !== null && _a !== void 0 ? _a : p.name, key: p.key }, (p.endpoint ? { endpoint: p.endpoint } : {}))); }), 'kwirth-providers.json') }, "Export"),
|
|
483
|
-
react_1.default.createElement(material_1.Box, { flex: 1 }),
|
|
484
505
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(providers), variant: 'contained' }, "Save"),
|
|
485
506
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), variant: 'outlined' }, "Cancel"))));
|
|
486
507
|
};
|
|
487
508
|
exports.AiConfigProvider = AiConfigProvider;
|
|
488
|
-
const ToolSelector = ({ tools, selected, autoTools, disabled, onChange }) => (react_1.default.createElement(material_1.Stack, { direction: 'row',
|
|
509
|
+
const ToolSelector = ({ tools, selected, autoTools, disabled, onChange }) => (react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: {
|
|
510
|
+
alignItems: 'flex-end',
|
|
511
|
+
width: '100%'
|
|
512
|
+
} },
|
|
489
513
|
react_1.default.createElement(material_1.FormControlLabel, { control: react_1.default.createElement(material_1.Switch, { size: 'small', checked: autoTools, onChange: e => onChange(selected, e.target.checked), disabled: disabled }), label: react_1.default.createElement(material_1.Typography, { variant: 'caption' }, "Auto"), sx: { ml: 1, mr: 0, flexShrink: 0 } }),
|
|
490
514
|
react_1.default.createElement(material_1.FormControl, { variant: 'standard', fullWidth: true },
|
|
491
515
|
react_1.default.createElement(material_1.InputLabel, null, "Tools"),
|
|
@@ -493,5 +517,8 @@ const ToolSelector = ({ tools, selected, autoTools, disabled, onChange }) => (re
|
|
|
493
517
|
react_1.default.createElement(material_1.Checkbox, { size: 'small', checked: selected.includes(t.name) }),
|
|
494
518
|
react_1.default.createElement(material_1.Stack, { direction: 'column' },
|
|
495
519
|
react_1.default.createElement(material_1.Typography, { variant: 'body2' }, t.name),
|
|
496
|
-
t.description && react_1.default.createElement(material_1.Typography, { variant: 'caption',
|
|
520
|
+
t.description && react_1.default.createElement(material_1.Typography, { variant: 'caption', sx: {
|
|
521
|
+
color: 'text.secondary',
|
|
522
|
+
fontSize: '0.65rem'
|
|
523
|
+
} }, t.description)))))))));
|
|
497
524
|
exports.ToolSelector = ToolSelector;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kwirthmagnify/kwirth-common-ai",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.78",
|
|
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",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@kwirthmagnify/kwirth-common": "^0.5.76",
|
|
64
|
-
"@mui/icons-material": "
|
|
65
|
-
"@mui/material": "
|
|
64
|
+
"@mui/icons-material": "9.5.0",
|
|
65
|
+
"@mui/material": "9.5.0",
|
|
66
66
|
"@types/node": "^25.9.1",
|
|
67
67
|
"@types/react": "^18.3.0",
|
|
68
68
|
"typescript": "^5.4.0",
|