contentoh-components-library 21.5.78 → 21.5.81
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/ai/utils/compare-strings.js +43 -0
- package/dist/components/atoms/GeneralInput/index.js +64 -36
- package/dist/components/atoms/GeneralInput/styles.js +1 -1
- package/dist/components/atoms/InputFormatter/index.js +45 -21
- package/dist/components/atoms/InputFormatter/styles.js +1 -1
- package/dist/components/molecules/StatusAsignationInfo/index.js +11 -1
- package/dist/components/molecules/TagAndInput/index.js +110 -29
- package/dist/components/molecules/TagAndInput/styles.js +2 -2
- package/dist/components/organisms/InputGroup/index.js +22 -18
- package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +92 -785
- package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.context.js +59 -260
- package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +3 -41
- package/dist/components/pages/RetailerProductEdition/index.js +191 -123
- package/dist/contexts/AiProductEdition.js +179 -155
- package/package.json +1 -1
- package/src/ai/utils/compare-strings.js +43 -0
- package/src/components/atoms/GeneralInput/index.js +63 -42
- package/src/components/atoms/GeneralInput/styles.js +7 -0
- package/src/components/atoms/InputFormatter/index.js +51 -23
- package/src/components/atoms/InputFormatter/styles.js +62 -10
- package/src/components/molecules/StatusAsignationInfo/index.js +9 -1
- package/src/components/molecules/TagAndInput/index.js +113 -28
- package/src/components/molecules/TagAndInput/styles.js +48 -17
- package/src/components/organisms/FullTabsMenu/index.js +1 -1
- package/src/components/organisms/InputGroup/index.js +4 -0
- package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +111 -832
- package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +3 -221
- package/src/components/pages/RetailerProductEdition/context/reducers/product.js +3 -43
- package/src/components/pages/RetailerProductEdition/index.js +17 -15
- package/src/contexts/AiProductEdition.jsx +138 -96
- package/src/ai/prompts/attribute.prompt.js +0 -46
- package/src/ai/prompts/description.prompt.js +0 -52
- package/src/ai/schemas/attribute.schema.js +0 -23
- package/src/ai/schemas/description.schema.js +0 -19
|
@@ -21,19 +21,10 @@ var _react = require("react");
|
|
|
21
21
|
|
|
22
22
|
var _axios = _interopRequireDefault(require("axios"));
|
|
23
23
|
|
|
24
|
-
var
|
|
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");
|
|
24
|
+
var _providerProductEditionContext = require("../components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx");
|
|
33
25
|
|
|
34
26
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
35
27
|
|
|
36
|
-
var GeminiApiKey = process.env.REACT_APP_GEMINI_API_KEY;
|
|
37
28
|
var AiProductEdition = /*#__PURE__*/(0, _react.createContext)();
|
|
38
29
|
exports.AiProductEdition = AiProductEdition;
|
|
39
30
|
|
|
@@ -46,38 +37,64 @@ var useAiProductEdition = function useAiProductEdition() {
|
|
|
46
37
|
exports.useAiProductEdition = useAiProductEdition;
|
|
47
38
|
|
|
48
39
|
var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
40
|
+
var _state$datasheets_inp;
|
|
41
|
+
|
|
49
42
|
var children = _ref.children,
|
|
50
43
|
_ref$isCreatorsEditio = _ref.isCreatorsEdition,
|
|
51
|
-
isCreatorsEdition = _ref$isCreatorsEditio === void 0 ?
|
|
52
|
-
_ref$
|
|
53
|
-
|
|
54
|
-
|
|
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;
|
|
55
49
|
var isCreators = isCreatorsEdition;
|
|
56
50
|
|
|
51
|
+
var _useProviderProductEd = (0, _providerProductEditionContext.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
|
+
|
|
57
59
|
var _useState = (0, _react.useState)(null),
|
|
58
60
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
59
61
|
product = _useState2[0],
|
|
60
62
|
setProduct = _useState2[1];
|
|
61
63
|
|
|
62
|
-
var _useState3 = (0, _react.useState)(
|
|
64
|
+
var _useState3 = (0, _react.useState)([]),
|
|
63
65
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
parsedDatasheet = _useState4[0],
|
|
67
|
+
setParsedDatasheet = _useState4[1];
|
|
66
68
|
|
|
67
|
-
var _useState5 = (0, _react.useState)(
|
|
69
|
+
var _useState5 = (0, _react.useState)([]),
|
|
68
70
|
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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];
|
|
81
98
|
|
|
82
99
|
function setCurrentSuggestionValue(_ref2) {
|
|
83
100
|
var inputId = _ref2.inputId,
|
|
@@ -101,14 +118,14 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
101
118
|
|
|
102
119
|
function _regenerateProductSuggestions() {
|
|
103
120
|
_regenerateProductSuggestions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref3) {
|
|
104
|
-
var
|
|
121
|
+
var inputName, currentValue, description, maxChar, type, articleId, versionId, descriptionId, attributeId, newSuggestions;
|
|
105
122
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
106
123
|
while (1) {
|
|
107
124
|
switch (_context.prev = _context.next) {
|
|
108
125
|
case 0:
|
|
109
|
-
|
|
126
|
+
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;
|
|
110
127
|
|
|
111
|
-
if (!(!
|
|
128
|
+
if (!(!description || !maxChar || !type)) {
|
|
112
129
|
_context.next = 3;
|
|
113
130
|
break;
|
|
114
131
|
}
|
|
@@ -122,7 +139,11 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
122
139
|
currentValue: currentValue,
|
|
123
140
|
description: description,
|
|
124
141
|
maxChar: maxChar,
|
|
125
|
-
type: type
|
|
142
|
+
type: type,
|
|
143
|
+
articleId: articleId,
|
|
144
|
+
versionId: versionId,
|
|
145
|
+
descriptionId: descriptionId,
|
|
146
|
+
attributeId: attributeId
|
|
126
147
|
});
|
|
127
148
|
|
|
128
149
|
case 5:
|
|
@@ -158,175 +179,125 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
158
179
|
|
|
159
180
|
function generateProductSuggestions(_x2) {
|
|
160
181
|
return _generateProductSuggestions.apply(this, arguments);
|
|
161
|
-
}
|
|
182
|
+
} // Verificamos si los servicios de ficha técnica e imágenes estan completos
|
|
183
|
+
|
|
162
184
|
|
|
163
185
|
function _generateProductSuggestions() {
|
|
164
186
|
_generateProductSuggestions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref4) {
|
|
165
|
-
var _ref4$inputName, inputName, _ref4$currentValue, currentValue, _ref4$description, description, _ref4$maxChar, maxChar, _ref4$type, type, upc, productName, retailer, category,
|
|
187
|
+
var _ref4$inputName, inputName, _ref4$currentValue, currentValue, _ref4$description, description, _ref4$maxChar, maxChar, _ref4$type, type, articleId, versionId, descriptionId, attributeId, _JSON$parse$data, _JSON$parse, upc, productName, retailer, category, payload, _yield$axios$post, data, results, _error$message;
|
|
166
188
|
|
|
167
189
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
168
190
|
while (1) {
|
|
169
191
|
switch (_context2.prev = _context2.next) {
|
|
170
192
|
case 0:
|
|
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 ?
|
|
193
|
+
_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;
|
|
172
194
|
_context2.prev = 1;
|
|
173
195
|
|
|
174
|
-
if (
|
|
196
|
+
if (isAiAvailable) {
|
|
175
197
|
_context2.next = 4;
|
|
176
198
|
break;
|
|
177
199
|
}
|
|
178
200
|
|
|
179
|
-
|
|
201
|
+
return _context2.abrupt("return");
|
|
180
202
|
|
|
181
203
|
case 4:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
maxChar: maxChar,
|
|
187
|
-
type: type
|
|
188
|
-
});
|
|
189
|
-
upc = product.upc, productName = product.productName, retailer = product.retailer, category = product.category;
|
|
204
|
+
if (product) {
|
|
205
|
+
_context2.next = 6;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
190
208
|
|
|
191
|
-
|
|
209
|
+
throw new Error("El producto no está definido");
|
|
210
|
+
|
|
211
|
+
case 6:
|
|
212
|
+
if (!(!Array.isArray(parsedDatasheet) || parsedDatasheet.length === 0)) {
|
|
192
213
|
_context2.next = 8;
|
|
193
214
|
break;
|
|
194
215
|
}
|
|
195
216
|
|
|
196
|
-
throw new Error("
|
|
217
|
+
throw new Error("No es encontró la ficha técnica");
|
|
197
218
|
|
|
198
219
|
case 8:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
220
|
+
if (!(!Array.isArray(parsedImages) || parsedImages.length === 0)) {
|
|
221
|
+
_context2.next = 10;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
throw new Error("No se encontraron imágenes para la cadena seleccionada");
|
|
226
|
+
|
|
227
|
+
case 10:
|
|
228
|
+
upc = product.upc, productName = product.productName, retailer = product.retailer, category = product.category;
|
|
229
|
+
|
|
230
|
+
if (!(!upc || !description || !productName || !category || !retailer || !articleId || !versionId || !descriptionId && !attributeId)) {
|
|
231
|
+
_context2.next = 13;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
throw new Error("Faltan parámetros obligatorios para generar sugerencias de IA");
|
|
236
|
+
|
|
237
|
+
case 13:
|
|
238
|
+
payload = {
|
|
209
239
|
upc: upc,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
category: category,
|
|
240
|
+
attributeTitle: inputName,
|
|
241
|
+
attributeDescription: description,
|
|
242
|
+
productName: productName,
|
|
214
243
|
currentValue: currentValue,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
responseSchema: schema,
|
|
231
|
-
temperature: 0.1
|
|
244
|
+
categoryName: category,
|
|
245
|
+
retailerName: retailer,
|
|
246
|
+
datasheet: parsedDatasheet,
|
|
247
|
+
images: parsedImages,
|
|
248
|
+
maxChar: maxChar,
|
|
249
|
+
articleId: articleId,
|
|
250
|
+
retailerId: activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer,
|
|
251
|
+
versionId: versionId,
|
|
252
|
+
descriptionId: descriptionId,
|
|
253
|
+
attributeId: attributeId
|
|
254
|
+
};
|
|
255
|
+
_context2.next = 16;
|
|
256
|
+
return _axios.default.post(process.env.REACT_APP_GENERATE_AI_ATTRIBUTES, payload, {
|
|
257
|
+
headers: {
|
|
258
|
+
Authorization: token
|
|
232
259
|
}
|
|
233
260
|
});
|
|
234
261
|
|
|
235
|
-
case
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
results =
|
|
262
|
+
case 16:
|
|
263
|
+
_yield$axios$post = _context2.sent;
|
|
264
|
+
data = _yield$axios$post.data;
|
|
265
|
+
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 : [];
|
|
266
|
+
console.log({
|
|
267
|
+
results: results
|
|
268
|
+
});
|
|
239
269
|
|
|
240
270
|
if (results) {
|
|
241
|
-
_context2.next =
|
|
271
|
+
_context2.next = 22;
|
|
242
272
|
break;
|
|
243
273
|
}
|
|
244
274
|
|
|
245
275
|
throw new Error("No se encontraron resultados");
|
|
246
276
|
|
|
247
|
-
case
|
|
277
|
+
case 22:
|
|
248
278
|
return _context2.abrupt("return", results);
|
|
249
279
|
|
|
250
|
-
case
|
|
251
|
-
_context2.prev =
|
|
280
|
+
case 25:
|
|
281
|
+
_context2.prev = 25;
|
|
252
282
|
_context2.t0 = _context2["catch"](1);
|
|
253
283
|
console.log("Error generating AI suggestions:", _context2.t0);
|
|
254
284
|
return _context2.abrupt("return", {
|
|
255
285
|
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"
|
|
256
286
|
});
|
|
257
287
|
|
|
258
|
-
case
|
|
288
|
+
case 29:
|
|
259
289
|
case "end":
|
|
260
290
|
return _context2.stop();
|
|
261
291
|
}
|
|
262
292
|
}
|
|
263
|
-
}, _callee2, null, [[1,
|
|
293
|
+
}, _callee2, null, [[1, 25]]);
|
|
264
294
|
}));
|
|
265
295
|
return _generateProductSuggestions.apply(this, arguments);
|
|
266
296
|
}
|
|
267
297
|
|
|
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
|
-
}
|
|
328
|
-
|
|
329
298
|
(0, _react.useEffect)(function () {
|
|
299
|
+
var _productSelected$perc;
|
|
300
|
+
|
|
330
301
|
if (!productSelected) return;
|
|
331
302
|
var productName = productSelected.name,
|
|
332
303
|
upc = productSelected.upc,
|
|
@@ -337,23 +308,76 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
337
308
|
});
|
|
338
309
|
if (!currentCategory) return console.log("Error: No se encontro la categoría");
|
|
339
310
|
var retailer = currentCategory.retailer,
|
|
340
|
-
category = currentCategory.category;
|
|
311
|
+
category = currentCategory.category; //Checamos si el servicio de ficha técnica e imagenes esta completo
|
|
312
|
+
|
|
313
|
+
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) {
|
|
314
|
+
return (retailer === null || retailer === void 0 ? void 0 : retailer.id_retailer) === (activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer);
|
|
315
|
+
});
|
|
316
|
+
if (!currentRetailerPercentages) return console.log("Error: No hay porcentajes disponibles");
|
|
317
|
+
|
|
318
|
+
var _currentRetailerPerce = currentRetailerPercentages === null || currentRetailerPercentages === void 0 ? void 0 : currentRetailerPercentages.datasheet,
|
|
319
|
+
datasheetRequiredPercent = _currentRetailerPerce.required;
|
|
320
|
+
|
|
321
|
+
var _currentRetailerPerce2 = currentRetailerPercentages === null || currentRetailerPercentages === void 0 ? void 0 : currentRetailerPercentages.images,
|
|
322
|
+
imagesRequiredPercent = _currentRetailerPerce2.required;
|
|
323
|
+
|
|
324
|
+
var aiServiceAvailable = datasheetRequiredPercent >= 100 && imagesRequiredPercent >= 100 && (user === null || user === void 0 ? void 0 : user.id_role) === 7;
|
|
325
|
+
setIsAiAvailable(aiServiceAvailable);
|
|
341
326
|
setProduct({
|
|
342
327
|
upc: upc,
|
|
343
328
|
productName: productName,
|
|
344
329
|
retailer: retailer,
|
|
345
330
|
category: category
|
|
346
331
|
});
|
|
347
|
-
}, [productSelected]);
|
|
332
|
+
}, [productSelected]); // Inicializamos la ficha técnica con el objetivo de posteriormente pasarlo a la generación con IA
|
|
333
|
+
|
|
334
|
+
(0, _react.useEffect)(function () {
|
|
335
|
+
if (!datasheetInputs) return;
|
|
336
|
+
var datasheetToArray = Object.values(datasheetInputs);
|
|
337
|
+
var normalizedDatasheet = datasheetToArray.map(function (attribute) {
|
|
338
|
+
return {
|
|
339
|
+
description: attribute === null || attribute === void 0 ? void 0 : attribute.description,
|
|
340
|
+
name: attribute === null || attribute === void 0 ? void 0 : attribute.name,
|
|
341
|
+
type: attribute === null || attribute === void 0 ? void 0 : attribute.type,
|
|
342
|
+
value: attribute === null || attribute === void 0 ? void 0 : attribute.value
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
setParsedDatasheet(normalizedDatasheet);
|
|
346
|
+
}, [datasheetInputs]); // Inicializamos las imágenes con el objetivo de posteriormente pasarlo a la generación con IA
|
|
347
|
+
|
|
348
|
+
(0, _react.useEffect)(function () {
|
|
349
|
+
var _imagesData$inputsByR, _imagesData$inputsByR2;
|
|
350
|
+
|
|
351
|
+
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) {
|
|
352
|
+
return (input === null || input === void 0 ? void 0 : input.id_retailer) === (activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer);
|
|
353
|
+
});
|
|
354
|
+
if (!Array.isArray(currentRetailerImageInputs) || currentRetailerImageInputs.length === 0) return console.log('No existen imágenes para la cadena seleccionada');
|
|
355
|
+
var allProductImages = imagesData === null || imagesData === void 0 ? void 0 : imagesData.values;
|
|
356
|
+
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
|
|
357
|
+
|
|
358
|
+
var currentParsedImages = allProductImages.filter(function (image) {
|
|
359
|
+
var imageId = image === null || image === void 0 ? void 0 : image.image_id;
|
|
360
|
+
var foundedImage = currentRetailerImageInputs.some(function (retailerImage) {
|
|
361
|
+
return (retailerImage === null || retailerImage === void 0 ? void 0 : retailerImage.id_image) === imageId;
|
|
362
|
+
});
|
|
363
|
+
return foundedImage;
|
|
364
|
+
});
|
|
365
|
+
setParsedImages(currentParsedImages);
|
|
366
|
+
}, [imagesData]);
|
|
348
367
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(AiProductEdition.Provider, {
|
|
349
368
|
value: {
|
|
350
369
|
isCreators: isCreators,
|
|
351
370
|
suggestions: suggestions,
|
|
352
371
|
currentSuggestion: currentSuggestion,
|
|
353
|
-
|
|
354
|
-
|
|
372
|
+
isAiAvailable: isAiAvailable,
|
|
373
|
+
inputsGeneratedWithAi: inputsGeneratedWithAi,
|
|
374
|
+
inputsUsingAi: inputsUsingAi,
|
|
375
|
+
setInputsUsingAi: setInputsUsingAi,
|
|
376
|
+
setInputsGeneratedWithAi: setInputsGeneratedWithAi,
|
|
355
377
|
setSuggestions: setSuggestions,
|
|
356
378
|
setCurrentSuggestionValue: setCurrentSuggestionValue,
|
|
379
|
+
generateProductSuggestions: generateProductSuggestions,
|
|
380
|
+
regenerateProductSuggestions: regenerateProductSuggestions,
|
|
357
381
|
clearCurrentSuggestions: clearCurrentSuggestions
|
|
358
382
|
},
|
|
359
383
|
children: children
|
package/package.json
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
//Calcula el porcentaje de similitud entre la descripción generada por IA y la versión editada por el usuario.
|
|
3
|
+
|
|
4
|
+
export function getTextSimilarityPercentage(originalText, candidateText) {
|
|
5
|
+
|
|
6
|
+
const normalize = (text) => {
|
|
7
|
+
return text
|
|
8
|
+
.trim()
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.replace(/\s+/g, ' ');
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const source = normalize(originalText);
|
|
14
|
+
const target = normalize(candidateText);
|
|
15
|
+
|
|
16
|
+
if (source === target) return 100;
|
|
17
|
+
if (source.length === 0 || target.length === 0) return 0;
|
|
18
|
+
|
|
19
|
+
const sourceLength = source.length;
|
|
20
|
+
const targetLength = target.length;
|
|
21
|
+
const distanceMatrix = Array(targetLength + 1).fill(null).map(() => []);
|
|
22
|
+
|
|
23
|
+
for (let i = 0; i <= sourceLength; i++) distanceMatrix[0][i] = i;
|
|
24
|
+
for (let j = 0; j <= targetLength; j++) distanceMatrix[j][0] = j;
|
|
25
|
+
|
|
26
|
+
for (let j = 1; j <= targetLength; j++) {
|
|
27
|
+
for (let i = 1; i <= sourceLength; i++) {
|
|
28
|
+
const substitutionCost = (source[i - 1] === target[j - 1]) ? 0 : 1;
|
|
29
|
+
|
|
30
|
+
distanceMatrix[j][i] = Math.min(
|
|
31
|
+
distanceMatrix[j - 1][i] + 1,
|
|
32
|
+
distanceMatrix[j][i - 1] + 1,
|
|
33
|
+
distanceMatrix[j - 1][i - 1] + substitutionCost
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const editDistance = distanceMatrix[targetLength][sourceLength];
|
|
39
|
+
const maxLength = Math.max(sourceLength, targetLength);
|
|
40
|
+
const similarityScore = 1 - (editDistance / maxLength);
|
|
41
|
+
|
|
42
|
+
return similarityScore * 100;
|
|
43
|
+
}
|