@kwirthmagnify/kwirth-common-ai 0.5.36 → 0.5.38

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/front.js +24 -6
  2. package/package.json +1 -1
package/dist/front.js CHANGED
@@ -202,6 +202,7 @@ const AiConfigProvider = (props) => {
202
202
  const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
203
203
  const [showPassword, setShowPassword] = (0, react_1.useState)(false);
204
204
  const [loadingModels, setLoadingModels] = (0, react_1.useState)(false);
205
+ const loadedModelsRef = (0, react_1.useRef)([]);
205
206
  (0, react_1.useEffect)(() => {
206
207
  setProviders(JSON.parse(JSON.stringify(props.providers)));
207
208
  setSelectedIndex(null);
@@ -210,26 +211,37 @@ const AiConfigProvider = (props) => {
210
211
  const [providerType, setProviderType] = (0, react_1.useState)((_a = props.providersAvailable[0]) !== null && _a !== void 0 ? _a : '');
211
212
  const [providerKey, setProviderKey] = (0, react_1.useState)('');
212
213
  const [providerEndpoint, setProviderEndpoint] = (0, react_1.useState)('');
213
- const [pendingModels, setPendingModels] = (0, react_1.useState)([]);
214
+ const [pendingModels, setPendingModels] = (0, react_1.useState)([]); // solo para mostrar count en el botón
214
215
  const onProviderSelected = (p, index) => {
215
- var _a, _b, _c;
216
+ var _a, _b, _c, _d;
216
217
  setProviderName(p.name);
217
218
  setProviderType((_a = p.type) !== null && _a !== void 0 ? _a : p.name);
218
219
  setProviderKey(p.key);
219
220
  setProviderEndpoint((_b = p.endpoint) !== null && _b !== void 0 ? _b : '');
220
- setPendingModels((_c = p.models) !== null && _c !== void 0 ? _c : []);
221
+ loadedModelsRef.current = (_c = p.models) !== null && _c !== void 0 ? _c : [];
222
+ setPendingModels((_d = p.models) !== null && _d !== void 0 ? _d : []);
221
223
  setSelectedIndex(index);
222
224
  };
223
- const onNew = () => { var _a; setSelectedIndex(null); setProviderName(''); setProviderType((_a = props.providersAvailable[0]) !== null && _a !== void 0 ? _a : ''); setProviderKey(''); setProviderEndpoint(''); setPendingModels([]); };
225
+ const onNew = () => {
226
+ var _a;
227
+ setSelectedIndex(null);
228
+ setProviderName('');
229
+ setProviderType((_a = props.providersAvailable[0]) !== null && _a !== void 0 ? _a : '');
230
+ setProviderKey('');
231
+ setProviderEndpoint('');
232
+ loadedModelsRef.current = [];
233
+ setPendingModels([]);
234
+ };
224
235
  const onAdd = () => {
225
236
  if (!providerName.trim() || !providerType)
226
237
  return;
227
238
  const endpoint = providerType === 'openai-compat' ? providerEndpoint : undefined;
239
+ const models = loadedModelsRef.current;
228
240
  const updated = [...providers];
229
241
  if (selectedIndex !== null)
230
- updated[selectedIndex] = Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, type: providerType, key: providerKey, models: pendingModels, endpoint });
242
+ updated[selectedIndex] = Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, type: providerType, key: providerKey, models, endpoint });
231
243
  else
232
- updated.push({ name: providerName, type: providerType, key: providerKey, models: pendingModels, endpoint });
244
+ updated.push({ name: providerName, type: providerType, key: providerKey, models, endpoint });
233
245
  setProviders(updated);
234
246
  onNew();
235
247
  };
@@ -246,7 +258,13 @@ const AiConfigProvider = (props) => {
246
258
  try {
247
259
  const endpoint = providerType === 'openai-compat' ? providerEndpoint : undefined;
248
260
  const models = await props.onLoadModels({ name: providerName, type: providerType, key: providerKey, models: [], endpoint });
261
+ loadedModelsRef.current = models;
249
262
  setPendingModels(models);
263
+ if (selectedIndex !== null) {
264
+ const updated = [...providers];
265
+ updated[selectedIndex] = Object.assign(Object.assign({}, updated[selectedIndex]), { models });
266
+ setProviders(updated);
267
+ }
250
268
  }
251
269
  finally {
252
270
  setLoadingModels(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-ai",
3
- "version": "0.5.36",
3
+ "version": "0.5.38",
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",