contentoh-components-library 21.5.92 → 21.5.94

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 (70) hide show
  1. package/dist/components/atoms/GeneralButton/styles.js +1 -1
  2. package/dist/components/atoms/GeneralInput/index.js +54 -245
  3. package/dist/components/atoms/GeneralInput/styles.js +3 -7
  4. package/dist/components/atoms/InputFormatter/index.js +68 -223
  5. package/dist/components/atoms/InputFormatter/styles.js +4 -20
  6. package/dist/components/molecules/StatusAsignationInfo/index.js +1 -11
  7. package/dist/components/molecules/TabsMenu/index.js +12 -13
  8. package/dist/components/molecules/TagAndInput/index.js +24 -361
  9. package/dist/components/molecules/TagAndInput/styles.js +2 -2
  10. package/dist/components/organisms/FullProductNameHeader/index.js +22 -6
  11. package/dist/components/organisms/InputGroup/index.js +18 -22
  12. package/dist/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +337 -150
  13. package/dist/components/pages/ProviderProductEdition/context/provider-product-edition.context.js +15 -15
  14. package/dist/components/pages/ProviderProductEdition/index.js +379 -375
  15. package/dist/components/pages/ProviderProductEdition/utils.js +0 -1
  16. package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +196 -179
  17. package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.context.js +260 -59
  18. package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +38 -50
  19. package/dist/components/pages/RetailerProductEdition/index.js +2234 -1716
  20. package/dist/components/pages/RetailerProductEdition/styles.js +2 -4
  21. package/dist/components/pages/RetailerProductEdition/utils.js +2 -251
  22. package/dist/contexts/AiProductEdition.js +158 -230
  23. package/package.json +2 -4
  24. package/src/components/atoms/GeneralButton/styles.js +0 -4
  25. package/src/components/atoms/GeneralInput/index.js +60 -237
  26. package/src/components/atoms/GeneralInput/styles.js +0 -81
  27. package/src/components/atoms/InputFormatter/index.js +51 -200
  28. package/src/components/atoms/InputFormatter/styles.js +0 -284
  29. package/src/components/molecules/StatusAsignationInfo/index.js +1 -9
  30. package/src/components/molecules/TabsMenu/index.js +11 -12
  31. package/src/components/molecules/TagAndInput/index.js +21 -286
  32. package/src/components/molecules/TagAndInput/styles.js +17 -59
  33. package/src/components/organisms/FullProductNameHeader/index.js +28 -4
  34. package/src/components/organisms/FullTabsMenu/index.js +1 -1
  35. package/src/components/organisms/InputGroup/index.js +4 -12
  36. package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +202 -174
  37. package/src/components/pages/ProviderProductEdition/context/provider-product-edition.context.jsx +14 -14
  38. package/src/components/pages/ProviderProductEdition/index.js +470 -460
  39. package/src/components/pages/ProviderProductEdition/utils.js +2 -2
  40. package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +224 -201
  41. package/src/components/pages/RetailerProductEdition/index.js +1718 -1547
  42. package/src/components/pages/RetailerProductEdition/styles.js +2 -67
  43. package/src/components/pages/RetailerProductEdition/utils.js +0 -240
  44. package/dist/ai/utils/compare-strings.js +0 -45
  45. package/dist/components/organisms/ChangeStatusModal/index.js +0 -531
  46. package/dist/components/organisms/ChangeStatusModal/styles.js +0 -85
  47. package/dist/global-files/statusDictionary.js +0 -103
  48. package/src/ai/utils/compare-strings.js +0 -45
  49. package/src/assets/images/Icons/arrow.png +0 -0
  50. package/src/assets/images/Icons/cancel.png +0 -0
  51. package/src/assets/images/Icons/ia-icon.png +0 -0
  52. package/src/assets/images/Icons/loading.svg +0 -5
  53. package/src/assets/images/Icons/reload.png +0 -0
  54. package/src/components/atoms/RetailerSelector/RetailerSelector.stories.js +0 -10
  55. package/src/components/atoms/RetailerSelector/index.js +0 -3
  56. package/src/components/atoms/RetailerSelector/styles.js +0 -0
  57. package/src/components/organisms/ChangeStatusModal/index.jsx +0 -488
  58. package/src/components/organisms/ChangeStatusModal/styles.js +0 -333
  59. package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +0 -575
  60. package/src/components/pages/RetailerProductEdition/context/provider-product-edition.reducer.js +0 -62
  61. package/src/components/pages/RetailerProductEdition/context/reducers/active-state.js +0 -344
  62. package/src/components/pages/RetailerProductEdition/context/reducers/inputs.js +0 -155
  63. package/src/components/pages/RetailerProductEdition/context/reducers/product.js +0 -114
  64. package/src/components/pages/RetailerProductEdition/context/reducers/system.js +0 -60
  65. package/src/components/pages/RetailerProductEdition/index_old.js +0 -1979
  66. package/src/components/pages/RetailerProductEdition/stories/Auditor.stories.js +0 -101
  67. package/src/components/pages/RetailerProductEdition/stories/ImageEditor.stories.js +0 -115
  68. package/src/components/pages/RetailerProductEdition/stories/TextEditor.stories.js +0 -174
  69. package/src/contexts/AiProductEdition.jsx +0 -339
  70. package/src/global-files/statusDictionary.js +0 -103
@@ -21,8 +21,19 @@ var _react = require("react");
21
21
 
22
22
  var _axios = _interopRequireDefault(require("axios"));
23
23
 
24
+ var _attributeSchema = _interopRequireDefault(require("../ai/schemas/attribute.schema.js"));
25
+
26
+ var _descriptionSchema = _interopRequireDefault(require("../ai/schemas/description.schema.js"));
27
+
28
+ var _genai = require("@google/genai");
29
+
30
+ var _description = require("../ai/prompts/description.prompt");
31
+
32
+ var _attribute = require("../ai/prompts/attribute.prompt");
33
+
24
34
  var _jsxRuntime = require("react/jsx-runtime");
25
35
 
36
+ var GeminiApiKey = process.env.REACT_APP_GEMINI_API_KEY;
26
37
  var AiProductEdition = /*#__PURE__*/(0, _react.createContext)();
27
38
  exports.AiProductEdition = AiProductEdition;
28
39
 
@@ -35,90 +46,37 @@ var useAiProductEdition = function useAiProductEdition() {
35
46
  exports.useAiProductEdition = useAiProductEdition;
36
47
 
37
48
  var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
38
- var _state$datasheets_inp;
39
-
40
49
  var children = _ref.children,
41
50
  _ref$isCreatorsEditio = _ref.isCreatorsEdition,
42
- isCreatorsEdition = _ref$isCreatorsEditio === void 0 ? false : _ref$isCreatorsEditio,
43
- _ref$user = _ref.user,
44
- user = _ref$user === void 0 ? {} : _ref$user,
45
- _ref$token = _ref.token,
46
- token = _ref$token === void 0 ? "" : _ref$token,
47
- state = _ref.state;
51
+ isCreatorsEdition = _ref$isCreatorsEditio === void 0 ? true : _ref$isCreatorsEditio,
52
+ _ref$productSelected = _ref.productSelected,
53
+ productSelected = _ref$productSelected === void 0 ? null : _ref$productSelected,
54
+ activeRetailer = _ref.activeRetailer;
48
55
  var isCreators = isCreatorsEdition;
49
- var productSelected = state.product;
50
- var activeRetailer = state.active_retailer;
51
- var datasheetInputs = (_state$datasheets_inp = state.datasheets_inputs) === null || _state$datasheets_inp === void 0 ? void 0 : _state$datasheets_inp[1];
52
- var imagesData = state.images_values;
53
56
 
54
57
  var _useState = (0, _react.useState)(null),
55
58
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
56
59
  product = _useState2[0],
57
60
  setProduct = _useState2[1];
58
61
 
59
- var _useState3 = (0, _react.useState)([]),
62
+ var _useState3 = (0, _react.useState)({}),
60
63
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
61
- parsedDatasheet = _useState4[0],
62
- setParsedDatasheet = _useState4[1];
64
+ suggestions = _useState4[0],
65
+ setSuggestions = _useState4[1];
63
66
 
64
- var _useState5 = (0, _react.useState)([]),
67
+ var _useState5 = (0, _react.useState)({}),
65
68
  _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
66
- parsedImages = _useState6[0],
67
- setParsedImages = _useState6[1];
68
-
69
- var _useState7 = (0, _react.useState)({}),
70
- _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
71
- suggestions = _useState8[0],
72
- setSuggestions = _useState8[1];
73
-
74
- var _useState9 = (0, _react.useState)({}),
75
- _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
76
- currentSuggestion = _useState10[0],
77
- setCurrentSuggestion = _useState10[1];
78
-
79
- var _useState11 = (0, _react.useState)(false),
80
- _useState12 = (0, _slicedToArray2.default)(_useState11, 2),
81
- isAiAvailable = _useState12[0],
82
- setIsAiAvailable = _useState12[1];
83
-
84
- var _useState13 = (0, _react.useState)({}),
85
- _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
86
- inputsGeneratedWithAi = _useState14[0],
87
- setInputsGeneratedWithAi = _useState14[1];
88
-
89
- var _useState15 = (0, _react.useState)({}),
90
- _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
91
- inputsUsingAi = _useState16[0],
92
- setInputsUsingAi = _useState16[1];
93
-
94
- var MAX_CREDITS = 10;
95
- var COOLDOWN_MS = 5 * 60 * 1000;
96
- var RATE_LIMIT_KEY = "ai_generation_limit_data";
97
-
98
- var checkAndManageRateLimit = function checkAndManageRateLimit(currentArticleId) {
99
- var now = Date.now();
100
- var storedData = localStorage.getItem(RATE_LIMIT_KEY);
101
- var allRateData = storedData ? JSON.parse(storedData) : {};
102
- var productTimestamps = allRateData[currentArticleId] || [];
103
- productTimestamps = productTimestamps.filter(function (timestamp) {
104
- return now - timestamp < COOLDOWN_MS;
105
- });
69
+ currentSuggestion = _useState6[0],
70
+ setCurrentSuggestion = _useState6[1];
106
71
 
107
- if (productTimestamps.length >= MAX_CREDITS) {
108
- allRateData[currentArticleId] = productTimestamps;
109
- localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
110
- return {
111
- allowed: false,
112
- message: "Has alcanzado el limite de intentos frecuentes para este producto. Por favor, espera unos minutos."
113
- };
114
- }
115
-
116
- productTimestamps.push(now);
117
- allRateData[currentArticleId] = productTimestamps;
118
- localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
119
- return {
120
- allowed: true
121
- };
72
+ var ai = new _genai.GoogleGenAI({
73
+ apiKey: GeminiApiKey
74
+ });
75
+
76
+ var delay = function delay(ms) {
77
+ return new Promise(function (resolve) {
78
+ return setTimeout(resolve, ms);
79
+ });
122
80
  };
123
81
 
124
82
  function setCurrentSuggestionValue(_ref2) {
@@ -143,14 +101,14 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
143
101
 
144
102
  function _regenerateProductSuggestions() {
145
103
  _regenerateProductSuggestions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref3) {
146
- var inputName, currentValue, description, maxChar, type, articleId, versionId, descriptionId, attributeId, newSuggestions;
104
+ var inputId, inputName, currentValue, description, maxChar, type, newSuggestions;
147
105
  return _regenerator.default.wrap(function _callee$(_context) {
148
106
  while (1) {
149
107
  switch (_context.prev = _context.next) {
150
108
  case 0:
151
- inputName = _ref3.inputName, currentValue = _ref3.currentValue, description = _ref3.description, maxChar = _ref3.maxChar, type = _ref3.type, articleId = _ref3.articleId, versionId = _ref3.versionId, descriptionId = _ref3.descriptionId, attributeId = _ref3.attributeId;
109
+ inputId = _ref3.inputId, inputName = _ref3.inputName, currentValue = _ref3.currentValue, description = _ref3.description, maxChar = _ref3.maxChar, type = _ref3.type;
152
110
 
153
- if (!(!description || !maxChar || !type)) {
111
+ if (!(!inputId || !description || !maxChar || !type)) {
154
112
  _context.next = 3;
155
113
  break;
156
114
  }
@@ -164,45 +122,31 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
164
122
  currentValue: currentValue,
165
123
  description: description,
166
124
  maxChar: maxChar,
167
- type: type,
168
- articleId: articleId,
169
- versionId: versionId,
170
- descriptionId: descriptionId,
171
- attributeId: attributeId
125
+ type: type
172
126
  });
173
127
 
174
128
  case 5:
175
129
  newSuggestions = _context.sent;
176
130
 
177
- if (!(newSuggestions !== null && newSuggestions !== void 0 && newSuggestions.error)) {
178
- _context.next = 8;
179
- break;
180
- }
181
-
182
- return _context.abrupt("return", {
183
- error: newSuggestions.error
184
- });
185
-
186
- case 8:
187
131
  if (!(!Array.isArray(newSuggestions) || newSuggestions.length === 0)) {
188
- _context.next = 10;
132
+ _context.next = 8;
189
133
  break;
190
134
  }
191
135
 
192
136
  return _context.abrupt("return", console.log("Error: No se obtuvieron nuevas sugerencias"));
193
137
 
194
- case 10:
138
+ case 8:
195
139
  if (newSuggestions) {
196
- _context.next = 12;
140
+ _context.next = 10;
197
141
  break;
198
142
  }
199
143
 
200
144
  return _context.abrupt("return", console.log("Error: No exiten resultados nuevos"));
201
145
 
202
- case 12:
146
+ case 10:
203
147
  return _context.abrupt("return", newSuggestions);
204
148
 
205
- case 13:
149
+ case 11:
206
150
  case "end":
207
151
  return _context.stop();
208
152
  }
@@ -214,136 +158,175 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
214
158
 
215
159
  function generateProductSuggestions(_x2) {
216
160
  return _generateProductSuggestions.apply(this, arguments);
217
- } // Verificamos si los servicios de ficha técnica e imágenes estan completos
218
-
161
+ }
219
162
 
220
163
  function _generateProductSuggestions() {
221
164
  _generateProductSuggestions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref4) {
222
- var _ref4$inputName, inputName, _ref4$currentValue, currentValue, _ref4$description, description, _ref4$maxChar, maxChar, _ref4$type, type, articleId, versionId, descriptionId, attributeId, _state$product, _JSON$parse$data, _JSON$parse, rateLimitStatus, upc, productName, retailer, category, version, payload, _yield$axios$post, data, results, _error$message;
165
+ var _ref4$inputName, inputName, _ref4$currentValue, currentValue, _ref4$description, description, _ref4$maxChar, maxChar, _ref4$type, type, upc, productName, retailer, category, prompt, schema, response, normalizedResponse, results, _error$message;
223
166
 
224
167
  return _regenerator.default.wrap(function _callee2$(_context2) {
225
168
  while (1) {
226
169
  switch (_context2.prev = _context2.next) {
227
170
  case 0:
228
- _ref4$inputName = _ref4.inputName, inputName = _ref4$inputName === void 0 ? "" : _ref4$inputName, _ref4$currentValue = _ref4.currentValue, currentValue = _ref4$currentValue === void 0 ? "" : _ref4$currentValue, _ref4$description = _ref4.description, description = _ref4$description === void 0 ? "" : _ref4$description, _ref4$maxChar = _ref4.maxChar, maxChar = _ref4$maxChar === void 0 ? 100 : _ref4$maxChar, _ref4$type = _ref4.type, type = _ref4$type === void 0 ? 'description' : _ref4$type, articleId = _ref4.articleId, versionId = _ref4.versionId, descriptionId = _ref4.descriptionId, attributeId = _ref4.attributeId;
171
+ _ref4$inputName = _ref4.inputName, inputName = _ref4$inputName === void 0 ? "" : _ref4$inputName, _ref4$currentValue = _ref4.currentValue, currentValue = _ref4$currentValue === void 0 ? "" : _ref4$currentValue, _ref4$description = _ref4.description, description = _ref4$description === void 0 ? "" : _ref4$description, _ref4$maxChar = _ref4.maxChar, maxChar = _ref4$maxChar === void 0 ? 100 : _ref4$maxChar, _ref4$type = _ref4.type, type = _ref4$type === void 0 ? "description" : _ref4$type;
229
172
  _context2.prev = 1;
230
173
 
231
- if (isAiAvailable) {
174
+ if (product) {
232
175
  _context2.next = 4;
233
176
  break;
234
177
  }
235
178
 
236
- return _context2.abrupt("return");
179
+ throw new Error("El producto no está definido");
237
180
 
238
181
  case 4:
239
- rateLimitStatus = checkAndManageRateLimit(articleId);
240
-
241
- if (rateLimitStatus.allowed) {
242
- _context2.next = 7;
243
- break;
244
- }
245
-
246
- return _context2.abrupt("return", {
247
- error: rateLimitStatus.message,
248
- isRateLimitInfo: true
182
+ console.log({
183
+ inputName: inputName,
184
+ currentValue: currentValue,
185
+ description: description,
186
+ maxChar: maxChar,
187
+ type: type
249
188
  });
250
-
251
- case 7:
252
- if (product) {
253
- _context2.next = 9;
254
- break;
255
- }
256
-
257
- throw new Error("El producto no está definido");
258
-
259
- case 9:
260
- if (!(!Array.isArray(parsedDatasheet) || parsedDatasheet.length === 0)) {
261
- _context2.next = 11;
262
- break;
263
- }
264
-
265
- throw new Error("No es encontró la ficha técnica");
266
-
267
- case 11:
268
- if (!(!Array.isArray(parsedImages) || parsedImages.length === 0)) {
269
- _context2.next = 13;
270
- break;
271
- }
272
-
273
- throw new Error("No se encontraron imágenes para la cadena seleccionada");
274
-
275
- case 13:
276
189
  upc = product.upc, productName = product.productName, retailer = product.retailer, category = product.category;
277
- version = state === null || state === void 0 ? void 0 : (_state$product = state.product) === null || _state$product === void 0 ? void 0 : _state$product.version;
278
190
 
279
- if (!(!upc || !description || !productName || !category || !retailer || !articleId || !version || !descriptionId && !attributeId)) {
280
- _context2.next = 17;
191
+ if (!(!upc || !description || !productName || !category || !retailer)) {
192
+ _context2.next = 8;
281
193
  break;
282
194
  }
283
195
 
284
196
  throw new Error("Faltan parámetros obligatorios para generar sugerencias de IA");
285
197
 
286
- case 17:
287
- payload = {
198
+ case 8:
199
+ prompt = type === "description" ? (0, _description.generateDescriptionPrompt)({
288
200
  upc: upc,
289
- attributeTitle: inputName,
290
- attributeDescription: description,
291
- productName: productName,
201
+ inputName: inputName,
202
+ description: description,
203
+ name: productName,
204
+ category: category,
292
205
  currentValue: currentValue,
293
- categoryName: category,
294
- retailerName: retailer,
295
- datasheet: parsedDatasheet,
296
- images: parsedImages,
297
- maxChar: maxChar,
298
- articleId: articleId,
299
- retailerId: activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer,
300
- versionId: version,
301
- descriptionId: descriptionId,
302
- attributeId: attributeId
303
- };
304
- _context2.next = 20;
305
- return _axios.default.post(process.env.REACT_APP_GENERATE_AI_ATTRIBUTES, payload, {
306
- headers: {
307
- Authorization: token
206
+ retailer: retailer,
207
+ maxChar: maxChar
208
+ }) : (0, _attribute.generateAttributePrompt)({
209
+ upc: upc,
210
+ inputName: inputName,
211
+ description: description,
212
+ name: productName,
213
+ category: category,
214
+ currentValue: currentValue,
215
+ retailer: retailer,
216
+ maxChar: maxChar
217
+ });
218
+ schema = type === "description" ? _descriptionSchema.default : _attributeSchema.default;
219
+ _context2.next = 12;
220
+ return generateContentWithRetry({
221
+ model: "gemini-2.5-flash",
222
+ contents: [{
223
+ role: "user",
224
+ parts: [{
225
+ text: prompt
226
+ }]
227
+ }],
228
+ config: {
229
+ responseMimeType: "application/json",
230
+ responseSchema: schema,
231
+ temperature: 0.1
308
232
  }
309
233
  });
310
234
 
311
- case 20:
312
- _yield$axios$post = _context2.sent;
313
- data = _yield$axios$post.data;
314
- results = (_JSON$parse$data = (_JSON$parse = JSON.parse(data === null || data === void 0 ? void 0 : data.body)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.data) !== null && _JSON$parse$data !== void 0 ? _JSON$parse$data : [];
235
+ case 12:
236
+ response = _context2.sent;
237
+ normalizedResponse = JSON.parse(response.text);
238
+ results = normalizedResponse === null || normalizedResponse === void 0 ? void 0 : normalizedResponse["results"];
315
239
 
316
240
  if (results) {
317
- _context2.next = 25;
241
+ _context2.next = 17;
318
242
  break;
319
243
  }
320
244
 
321
245
  throw new Error("No se encontraron resultados");
322
246
 
323
- case 25:
247
+ case 17:
324
248
  return _context2.abrupt("return", results);
325
249
 
326
- case 28:
327
- _context2.prev = 28;
250
+ case 20:
251
+ _context2.prev = 20;
328
252
  _context2.t0 = _context2["catch"](1);
329
253
  console.log("Error generating AI suggestions:", _context2.t0);
330
254
  return _context2.abrupt("return", {
331
255
  error: (_error$message = _context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.message) !== null && _error$message !== void 0 ? _error$message : "Error generating AI suggestions"
332
256
  });
333
257
 
334
- case 32:
258
+ case 24:
335
259
  case "end":
336
260
  return _context2.stop();
337
261
  }
338
262
  }
339
- }, _callee2, null, [[1, 28]]);
263
+ }, _callee2, null, [[1, 20]]);
340
264
  }));
341
265
  return _generateProductSuggestions.apply(this, arguments);
342
266
  }
343
267
 
344
- (0, _react.useEffect)(function () {
345
- var _productSelected$perc;
268
+ function generateContentWithRetry(_x3) {
269
+ return _generateContentWithRetry.apply(this, arguments);
270
+ }
271
+
272
+ function _generateContentWithRetry() {
273
+ _generateContentWithRetry = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(modelParams) {
274
+ var retries,
275
+ backoff,
276
+ failoverModel,
277
+ model,
278
+ _error$message2,
279
+ isOverloaded,
280
+ _args3 = arguments;
281
+
282
+ return _regenerator.default.wrap(function _callee3$(_context3) {
283
+ while (1) {
284
+ switch (_context3.prev = _context3.next) {
285
+ case 0:
286
+ retries = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : 5;
287
+ backoff = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : 1000;
288
+ _context3.prev = 2;
289
+ failoverModel = "gemini-2.5-flash";
290
+ model = retries > 3 ? "gemini-2.5-flash-lite" : failoverModel;
291
+ _context3.next = 7;
292
+ return ai.models.generateContent((0, _objectSpread3.default)((0, _objectSpread3.default)({}, modelParams), {}, {
293
+ model: model
294
+ }));
295
+
296
+ case 7:
297
+ return _context3.abrupt("return", _context3.sent);
298
+
299
+ case 10:
300
+ _context3.prev = 10;
301
+ _context3.t0 = _context3["catch"](2);
302
+ isOverloaded = _context3.t0.status === 503 || ((_error$message2 = _context3.t0.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.includes("overloaded"));
303
+
304
+ if (!(retries > 0 && isOverloaded)) {
305
+ _context3.next = 18;
306
+ break;
307
+ }
308
+
309
+ console.warn("\u26A0\uFE0F Modelo saturado (503). Reintentando en ".concat(backoff, "ms... (Quedan ").concat(retries, " intentos)"));
310
+ _context3.next = 17;
311
+ return delay(backoff);
312
+
313
+ case 17:
314
+ return _context3.abrupt("return", generateContentWithRetry(modelParams, retries - 1, backoff * 2));
315
+
316
+ case 18:
317
+ throw _context3.t0;
318
+
319
+ case 19:
320
+ case "end":
321
+ return _context3.stop();
322
+ }
323
+ }
324
+ }, _callee3, null, [[2, 10]]);
325
+ }));
326
+ return _generateContentWithRetry.apply(this, arguments);
327
+ }
346
328
 
329
+ (0, _react.useEffect)(function () {
347
330
  if (!productSelected) return;
348
331
  var productName = productSelected.name,
349
332
  upc = productSelected.upc,
@@ -354,78 +337,23 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
354
337
  });
355
338
  if (!currentCategory) return console.log("Error: No se encontro la categoría");
356
339
  var retailer = currentCategory.retailer,
357
- category = currentCategory.category; //Checamos si el servicio de ficha técnica e imagenes esta completo
358
-
359
- var currentRetailerPercentages = productSelected === null || productSelected === void 0 ? void 0 : (_productSelected$perc = productSelected.percentages) === null || _productSelected$perc === void 0 ? void 0 : _productSelected$perc.find(function (retailer) {
360
- return (retailer === null || retailer === void 0 ? void 0 : retailer.id_retailer) === (activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer);
361
- });
362
- if (!currentRetailerPercentages) return console.log("Error: No hay porcentajes disponibles");
363
-
364
- var _currentRetailerPerce = currentRetailerPercentages === null || currentRetailerPercentages === void 0 ? void 0 : currentRetailerPercentages.datasheet,
365
- datasheetRequiredPercent = _currentRetailerPerce.required;
366
-
367
- var _currentRetailerPerce2 = currentRetailerPercentages === null || currentRetailerPercentages === void 0 ? void 0 : currentRetailerPercentages.images,
368
- imagesRequiredPercent = _currentRetailerPerce2.required;
369
-
370
- var aiServiceAvailable = datasheetRequiredPercent >= 100 && imagesRequiredPercent >= 100 && [1, 4, 6, 7].some(function (allowed) {
371
- return allowed = user === null || user === void 0 ? void 0 : user.id_role;
372
- });
373
- setIsAiAvailable(aiServiceAvailable);
340
+ category = currentCategory.category;
374
341
  setProduct({
375
342
  upc: upc,
376
343
  productName: productName,
377
344
  retailer: retailer,
378
345
  category: category
379
346
  });
380
- }, [productSelected]); // Inicializamos la ficha técnica con el objetivo de posteriormente pasarlo a la generación con IA
381
-
382
- (0, _react.useEffect)(function () {
383
- if (!datasheetInputs) return;
384
- var datasheetToArray = Object.values(datasheetInputs);
385
- var normalizedDatasheet = datasheetToArray.map(function (attribute) {
386
- return {
387
- description: attribute === null || attribute === void 0 ? void 0 : attribute.description,
388
- name: attribute === null || attribute === void 0 ? void 0 : attribute.name,
389
- type: attribute === null || attribute === void 0 ? void 0 : attribute.type,
390
- value: attribute === null || attribute === void 0 ? void 0 : attribute.value
391
- };
392
- });
393
- setParsedDatasheet(normalizedDatasheet);
394
- }, [datasheetInputs]); // Inicializamos las imágenes con el objetivo de posteriormente pasarlo a la generación con IA
395
-
396
- (0, _react.useEffect)(function () {
397
- var _imagesData$inputsByR, _imagesData$inputsByR2;
398
-
399
- var currentRetailerImageInputs = imagesData === null || imagesData === void 0 ? void 0 : (_imagesData$inputsByR = imagesData.inputsByRetailer) === null || _imagesData$inputsByR === void 0 ? void 0 : (_imagesData$inputsByR2 = _imagesData$inputsByR[0]) === null || _imagesData$inputsByR2 === void 0 ? void 0 : _imagesData$inputsByR2.filter(function (input) {
400
- return (input === null || input === void 0 ? void 0 : input.id_retailer) === (activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer);
401
- });
402
- if (!Array.isArray(currentRetailerImageInputs) || currentRetailerImageInputs.length === 0) return console.log('No existen imágenes para la cadena seleccionada');
403
- var allProductImages = imagesData === null || imagesData === void 0 ? void 0 : imagesData.values;
404
- if (!Array.isArray(allProductImages) || allProductImages.length === 0) return console.log("No existen imágenes para el producto"); //Obtenemos las imágenes para el retailer seleccionado
405
-
406
- var currentParsedImages = allProductImages.filter(function (image) {
407
- var imageId = image === null || image === void 0 ? void 0 : image.image_id;
408
- var foundedImage = currentRetailerImageInputs.some(function (retailerImage) {
409
- return (retailerImage === null || retailerImage === void 0 ? void 0 : retailerImage.id_image) === imageId;
410
- });
411
- return foundedImage;
412
- });
413
- setParsedImages(currentParsedImages);
414
- }, [imagesData]);
347
+ }, [productSelected]);
415
348
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(AiProductEdition.Provider, {
416
349
  value: {
417
350
  isCreators: isCreators,
418
351
  suggestions: suggestions,
419
352
  currentSuggestion: currentSuggestion,
420
- isAiAvailable: isAiAvailable,
421
- inputsGeneratedWithAi: inputsGeneratedWithAi,
422
- inputsUsingAi: inputsUsingAi,
423
- setInputsUsingAi: setInputsUsingAi,
424
- setInputsGeneratedWithAi: setInputsGeneratedWithAi,
425
- setSuggestions: setSuggestions,
426
- setCurrentSuggestionValue: setCurrentSuggestionValue,
427
353
  generateProductSuggestions: generateProductSuggestions,
428
354
  regenerateProductSuggestions: regenerateProductSuggestions,
355
+ setSuggestions: setSuggestions,
356
+ setCurrentSuggestionValue: setCurrentSuggestionValue,
429
357
  clearCurrentSuggestions: clearCurrentSuggestions
430
358
  },
431
359
  children: children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.5.92",
3
+ "version": "21.5.94",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -12,7 +12,6 @@
12
12
  "@fortawesome/free-regular-svg-icons": "^6.2.0",
13
13
  "@fortawesome/free-solid-svg-icons": "^6.2.0",
14
14
  "@fortawesome/react-fontawesome": "^0.2.0",
15
- "@google/genai": "^1.35.0",
16
15
  "@mui/icons-material": "^5.11.16",
17
16
  "@mui/material": "^5.12.0",
18
17
  "@mui/styled-engine-sc": "^5.12.0",
@@ -52,8 +51,7 @@
52
51
  "styled-components": "^5.3.9",
53
52
  "swiper": "^8.4.4",
54
53
  "uuid": "^8.3.2",
55
- "web-vitals": "^1.0.1",
56
- "zod": "^4.3.5"
54
+ "web-vitals": "^1.0.1"
57
55
  },
58
56
  "scripts": {
59
57
  "start": "start-storybook -p 6006",
@@ -38,10 +38,6 @@ export const Container = styled.button`
38
38
  background-color: #603888;
39
39
  }
40
40
 
41
- &.general-pink-button {
42
- background-color: #E33AA9;
43
- }
44
-
45
41
  &.general-transparent-button {
46
42
  background-color: transparent;
47
43
  border: 1px solid #503d66;