contentoh-components-library 21.5.91 → 21.5.93

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