@openk9ui/openk9-chatbot 3.0.1

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 (39) hide show
  1. package/README.md +50 -0
  2. package/dist/SingleMessage-Dyc7W2JZ.js +13738 -0
  3. package/dist/assets/Chatbot.css +107 -0
  4. package/dist/components/Chatbot.js +399 -0
  5. package/dist/components/LanguageContext.js +53 -0
  6. package/dist/components/Search.js +91 -0
  7. package/dist/components/SingleMessage.js +9 -0
  8. package/dist/components/Translate.js +69 -0
  9. package/dist/components/client.js +119 -0
  10. package/dist/components/styled.js +21 -0
  11. package/dist/components/useFocusTrap.js +95 -0
  12. package/dist/components/useGenerateResponse.js +271 -0
  13. package/dist/components/useLanguage.js +12 -0
  14. package/dist/lib/components/Chatbot.js +168 -0
  15. package/dist/lib/components/LanguageContext.js +63 -0
  16. package/dist/lib/components/Search.js +56 -0
  17. package/dist/lib/components/SingleMessage.js +385 -0
  18. package/dist/lib/components/Translate.js +71 -0
  19. package/dist/lib/components/client.js +170 -0
  20. package/dist/lib/components/styled.js +14 -0
  21. package/dist/lib/components/useFocusTrap.js +85 -0
  22. package/dist/lib/components/useGenerateResponse.js +310 -0
  23. package/dist/lib/components/useLanguage.js +16 -0
  24. package/dist/lib/main.js +8 -0
  25. package/dist/main.js +4 -0
  26. package/dist/src/theme.js +52 -0
  27. package/dist/types/lib/components/Chatbot.d.ts +26 -0
  28. package/dist/types/lib/components/LanguageContext.d.ts +12 -0
  29. package/dist/types/lib/components/Search.d.ts +9 -0
  30. package/dist/types/lib/components/SingleMessage.d.ts +19 -0
  31. package/dist/types/lib/components/Translate.d.ts +5 -0
  32. package/dist/types/lib/components/client.d.ts +91 -0
  33. package/dist/types/lib/components/styled.d.ts +13 -0
  34. package/dist/types/lib/components/useFocusTrap.d.ts +5 -0
  35. package/dist/types/lib/components/useGenerateResponse.d.ts +33 -0
  36. package/dist/types/lib/components/useLanguage.d.ts +4 -0
  37. package/dist/types/lib/main.d.ts +2 -0
  38. package/dist/types/src/theme.d.ts +1 -0
  39. package/package.json +63 -0
@@ -0,0 +1,385 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __assign = (this && this.__assign) || function () {
7
+ __assign = Object.assign || function(t) {
8
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9
+ s = arguments[i];
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
+ t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return __assign.apply(this, arguments);
16
+ };
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ exports.__esModule = true;
57
+ exports.SingleMessage = void 0;
58
+ var jsx_runtime_1 = require("react/jsx-runtime");
59
+ var styled_1 = __importDefault(require("@emotion/styled"));
60
+ var material_1 = require("@mui/material");
61
+ var react_markdown_1 = __importDefault(require("react-markdown"));
62
+ var Translate_1 = require("./Translate");
63
+ var Error_1 = __importDefault(require("@mui/icons-material/Error"));
64
+ var react_1 = require("react");
65
+ var Visibility_1 = __importDefault(require("@mui/icons-material/Visibility"));
66
+ var ContentCopy_1 = __importDefault(require("@mui/icons-material/ContentCopy"));
67
+ var Check_1 = __importDefault(require("@mui/icons-material/Check"));
68
+ var OpenInFull_1 = __importDefault(require("@mui/icons-material/OpenInFull"));
69
+ function SingleMessage(_a) {
70
+ var _this = this;
71
+ var contentMessage = _a.contentMessage, timeMessage = _a.timeMessage, isChatbot = _a.isChatbot, _b = _a.isLoading, isLoading = _b === void 0 ? false : _b, icon = _a.icon, nameChatbot = _a.nameChatbot, status = _a.status, sources = _a.sources, _c = _a.themeInfo, themeInfo = _c === void 0 ? "light" : _c;
72
+ sources = sources || [];
73
+ var theme = (0, material_1.useTheme)();
74
+ sources && console.log(sources);
75
+ var _d = (0, react_1.useState)(null), copiedSource = _d[0], setCopiedSource = _d[1];
76
+ var _e = (0, react_1.useState)(false), showAllSources = _e[0], setShowAllSources = _e[1];
77
+ var _f = (0, react_1.useState)(new Set()), expandedChips = _f[0], setExpandedChips = _f[1];
78
+ var maxVisibleSources = 8;
79
+ var visibleSources = sources.slice(0, maxVisibleSources);
80
+ var remainingSources = sources.length - maxVisibleSources;
81
+ var copySource = function (source) { return __awaiter(_this, void 0, void 0, function () {
82
+ var err_1;
83
+ return __generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0:
86
+ _a.trys.push([0, 2, , 3]);
87
+ return [4 /*yield*/, navigator.clipboard.writeText(source.url)];
88
+ case 1:
89
+ _a.sent();
90
+ setCopiedSource(source.url);
91
+ setTimeout(function () { return setCopiedSource(null); }, 2000);
92
+ return [3 /*break*/, 3];
93
+ case 2:
94
+ err_1 = _a.sent();
95
+ console.error("Errore durante la copia:", err_1);
96
+ return [3 /*break*/, 3];
97
+ case 3: return [2 /*return*/];
98
+ }
99
+ });
100
+ }); };
101
+ var toggleChipExpansion = function (url) {
102
+ var newSet = new Set(expandedChips);
103
+ if (newSet.has(url)) {
104
+ newSet["delete"](url);
105
+ if (newSet.size < sources.length) {
106
+ setShowAllSources(false);
107
+ }
108
+ }
109
+ else {
110
+ newSet.add(url);
111
+ if (newSet.size === sources.length) {
112
+ setShowAllSources(true);
113
+ }
114
+ }
115
+ setExpandedChips(newSet);
116
+ };
117
+ var getTypeColor = function (source) {
118
+ var baseColor = getStableColor(source, themeInfo);
119
+ var hexToRgb = function (hex) {
120
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
121
+ return result
122
+ ? {
123
+ r: parseInt(result[1], 16),
124
+ g: parseInt(result[2], 16),
125
+ b: parseInt(result[3], 16)
126
+ }
127
+ : { r: 200, g: 200, b: 200 };
128
+ };
129
+ var rgb = hexToRgb(baseColor);
130
+ var backgroundOpacity = themeInfo === "light" ? 0.1 : 0.2;
131
+ var borderOpacity = themeInfo === "light" ? 0.3 : 0.4;
132
+ var lightBackground = "rgba(".concat(rgb.r, ", ").concat(rgb.g, ", ").concat(rgb.b, ", ").concat(backgroundOpacity, ")");
133
+ var lightBorder = "rgba(".concat(rgb.r, ", ").concat(rgb.g, ", ").concat(rgb.b, ", ").concat(borderOpacity, ")");
134
+ return {
135
+ backgroundColor: lightBackground,
136
+ color: baseColor,
137
+ borderColor: lightBorder
138
+ };
139
+ };
140
+ var ariaLabel = (isChatbot
141
+ ? nameChatbot + " " + (0, Translate_1.Translate)({ label: "sendMessage" })
142
+ : (0, Translate_1.Translate)({ label: "youSendMessage" })) + timeMessage;
143
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ className: "openk9-single-message-container", display: "flex", flexDirection: "column", gap: "5px", width: "100%" }, { children: [(status === null || status === void 0 ? void 0 : status.toUpperCase()) === "ERROR" ? ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ className: "openk9-message-box", display: "flex", alignItems: "flex-end", gap: 4, sx: {
144
+ gap: "6px",
145
+ backgroundColor: "white",
146
+ flexDirection: isChatbot ? "row" : "row-reverse"
147
+ } }, { children: [icon && (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ className: "openk9-chatbot-icon" }, { children: icon })), (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ className: "openk9-error-message-container", sx: {
148
+ display: "flex",
149
+ alignItems: "center",
150
+ background: "#FCEAEA",
151
+ border: "1px solid #D32F2F",
152
+ borderRadius: "10px",
153
+ padding: "12px 16px",
154
+ gap: "10px",
155
+ width: "100%"
156
+ }, "aria-live": "polite" }, { children: [(0, jsx_runtime_1.jsx)(Error_1["default"], { sx: { color: "#D32F2F", fontSize: "20px" } }), (0, jsx_runtime_1.jsx)(ParagraphMessage, __assign({ className: "openk9-paragraph-message", "$font": theme.typography.fontFamily, "$color": "#D32F2F" }, { children: contentMessage }))] }))] }))) : ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ className: "openk9-message-box", display: "flex", alignItems: "flex-end", gap: 4, sx: {
157
+ gap: "6px",
158
+ backgroundColor: "white",
159
+ flexDirection: isChatbot ? "row" : "row-reverse"
160
+ } }, { children: [icon && (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ className: "openk9-chatbot-icon" }, { children: icon })), (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ className: "openk9-message-content-wrapper", sx: {
161
+ display: "flex",
162
+ flexDirection: "column",
163
+ width: ["-webkit-fill-available", "-moz-available", "100%"],
164
+ gap: "6px"
165
+ } }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ className: "openk9-message-content", sx: {
166
+ overflow: "auto",
167
+ display: "flex",
168
+ flexDirection: "column",
169
+ backgroundColor: isChatbot
170
+ ? theme.palette.background["default"]
171
+ : theme.palette.primary.main,
172
+ border: "1px solid",
173
+ borderColor: theme.palette.primary.main,
174
+ paddingInline: "16px",
175
+ color: !isChatbot ? "white" : "black",
176
+ borderRadius: isChatbot
177
+ ? "12px 12px 12px 2px"
178
+ : "12px 12px 2px 12px"
179
+ }, "aria-live": "polite" }, { children: [(0, jsx_runtime_1.jsx)(ParagraphMessage, __assign({ className: "openk9-paragraph-message", "$isLoading": isLoading, "$font": theme.typography.fontFamily }, { children: isLoading ? ((0, jsx_runtime_1.jsx)(material_1.Box, __assign({ className: "openk9-loading-icon-container", sx: {
180
+ display: "flex",
181
+ flexDirection: "column",
182
+ gap: "5px"
183
+ } }, { children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { className: "openk9-loader", disableShrink: true, size: 30, sx: { color: theme.palette.primary.main } }) }))) : ((0, jsx_runtime_1.jsxs)(FocusableSection, __assign({ className: "openk9-focusable-section", "$contraxtFocus": isChatbot ? "black" : "white", "aria-label": ariaLabel, tabIndex: 0 }, { children: [nameChatbot && ((0, jsx_runtime_1.jsx)(ParagraphName, __assign({ className: "openk9-paragraph-name", "$font": theme.typography.fontFamily || "" }, { children: nameChatbot }))), (0, jsx_runtime_1.jsx)(react_markdown_1["default"], { children: contentMessage })] }))) })), sources.length > 0 && ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ mb: 6 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2, sx: { overflowX: "hidden" } }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ variant: "body2", color: "text.secondary" }, { children: [sources.length, " sources"] })), (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ component: "button", onClick: function () {
184
+ var newState = !showAllSources;
185
+ setShowAllSources(newState);
186
+ if (newState) {
187
+ var allExpanded = new Set(sources.map(function (s) { return s.url || ""; }));
188
+ setExpandedChips(allExpanded);
189
+ }
190
+ else {
191
+ setExpandedChips(new Set());
192
+ }
193
+ }, sx: {
194
+ display: "flex",
195
+ alignItems: "center",
196
+ gap: 0.5,
197
+ color: "#12518f",
198
+ fontSize: "0.75rem",
199
+ background: "none",
200
+ border: "none",
201
+ cursor: "pointer",
202
+ "&:hover": { color: "#2782ea" }
203
+ } }, { children: [(0, jsx_runtime_1.jsx)(Visibility_1["default"], { sx: { fontSize: "0.75rem" } }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "caption" }, { children: showAllSources ? "Hide all" : "Show all" }))] }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: "flex", flexWrap: "wrap", gap: 1, sx: { overflowX: "hidden" } }, { children: [visibleSources.map(function (source, index) {
204
+ var typeColors = getTypeColor(source.url || "");
205
+ return ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: "flex", alignItems: "center", gap: 1, flex: 1, sx: {
206
+ width: expandedChips.has(source.url || "")
207
+ ? "230px"
208
+ : "170px",
209
+ overflow: "hidden",
210
+ textOverflow: expandedChips.has(source.url || "")
211
+ ? "unset"
212
+ : "ellipsis",
213
+ whiteSpace: "nowrap"
214
+ } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
215
+ flex: 1,
216
+ width: 8,
217
+ height: 8,
218
+ flexShrink: 0,
219
+ flexGrow: 0,
220
+ borderRadius: "50%",
221
+ backgroundColor: getStableColor(source.url, themeInfo)
222
+ } }), (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "caption", fontWeight: 500, overflow: "hidden", textOverflow: "ellipsis" }, { children: (source === null || source === void 0 ? void 0 : source.title) && source.title })), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ size: "small", onClick: function (e) {
223
+ e.stopPropagation();
224
+ copySource(source);
225
+ }, sx: {
226
+ p: 0.25,
227
+ ml: 0.5,
228
+ "&:hover": {
229
+ backgroundColor: "rgba(0,0,0,0.05)"
230
+ }
231
+ } }, { children: copiedSource === source.url ? ((0, jsx_runtime_1.jsx)(Check_1["default"], { sx: { fontSize: "0.75rem" } })) : ((0, jsx_runtime_1.jsx)(ContentCopy_1["default"], { sx: { fontSize: "0.75rem" } })) })), (0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ size: "small", onClick: function (e) {
232
+ e.stopPropagation();
233
+ toggleChipExpansion(source.url || "");
234
+ }, sx: {
235
+ p: 0.25,
236
+ "&:hover": {
237
+ backgroundColor: "rgba(0,0,0,0.05)"
238
+ }
239
+ } }, { children: (0, jsx_runtime_1.jsx)(OpenInFull_1["default"], { sx: { fontSize: "0.75rem" } }) }))] })] })), onClick: function () { return window.open(source.url, "_blank"); }, sx: {
240
+ backgroundColor: typeColors.backgroundColor,
241
+ color: typeColors.color,
242
+ border: "1px solid ".concat(typeColors.borderColor),
243
+ cursor: "pointer",
244
+ "&:hover": {
245
+ backgroundColor: typeColors.backgroundColor,
246
+ opacity: 0.8
247
+ }
248
+ }, size: "small" }, source.url || index));
249
+ }), remainingSources > 0 && ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: "flex", alignItems: "center", gap: 0.5 }, { children: [(0, jsx_runtime_1.jsx)(OpenInFull_1["default"], { sx: { fontSize: "0.75rem" } }), (0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ variant: "caption" }, { children: ["+", remainingSources] }))] })), sx: {
250
+ backgroundColor: themeInfo === "light" ? "#f5f5f5" : "#2d2d2d",
251
+ color: themeInfo === "light" ? "#616161" : "#b0b0b0",
252
+ cursor: "pointer",
253
+ "&:hover": {
254
+ backgroundColor: themeInfo === "light" ? "#e0e0e0" : "#404040"
255
+ }
256
+ }, size: "small" }))] }))] })))] })) }))] }))), (0, jsx_runtime_1.jsx)(ParagraphTime, __assign({ className: "openk9-paragraph-time", "$color": theme.palette.text.secondary, "$font": theme.typography.body2.font || "Roboto", style: { alignSelf: !isChatbot ? "start" : "end" } }, { children: timeMessage }))] })));
257
+ }
258
+ exports.SingleMessage = SingleMessage;
259
+ var ParagraphTime = styled_1["default"].p(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n color: ", ";\n margin: 0px;\n align-self: end;\n font-size: 10px;\n font-weight: 500;\n line-height: 1.5;\n letter-spacing: 1.2px;\n word-spacing: 1.6px;\n font-family: ", ";\n"], ["\n color: ", ";\n margin: 0px;\n align-self: end;\n font-size: 10px;\n font-weight: 500;\n line-height: 1.5;\n letter-spacing: 1.2px;\n word-spacing: 1.6px;\n font-family: ", ";\n"])), function (props) { return props.$color; }, function (props) { return props.$font; });
260
+ var ParagraphMessage = styled_1["default"].div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n color: ", ";\n margin: ", ";\n width: ", ";\n font-size: 12px;\n font-weight: 400;\n line-height: 1.5;\n text-align: left;\n font-family: ", ";\n padding-block: 3px;\n"], ["\n color: ", ";\n margin: ", ";\n width: ", ";\n font-size: 12px;\n font-weight: 400;\n line-height: 1.5;\n text-align: left;\n font-family: ", ";\n padding-block: 3px;\n"])), function (props) { return props.$color; }, function (props) { return (!props.$isLoading ? "0" : "16px"); }, function (props) { return !props.$width; }, function (props) { return props.$font; });
261
+ var ParagraphName = styled_1["default"].p(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n color: ", ";\n font-weight: 700;\n size: 10px;\n line-height: 15.21px;\n font-family: ", ";\n"], ["\n color: ", ";\n font-weight: 700;\n size: 10px;\n line-height: 15.21px;\n font-family: ", ";\n"])), function (props) { return props.$color; }, function (props) { return props.$font; });
262
+ var FocusableSection = styled_1["default"].section(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n padding-block: 0.2px;\n\n &:focus {\n outline: 2px solid ", ";\n }\n"], ["\n padding-block: 0.2px;\n\n &:focus {\n outline: 2px solid ", ";\n }\n"])), function (props) { return props.$contraxtFocus; });
263
+ function generateAccessibleColor(theme) {
264
+ var MAX_TRIES = 20;
265
+ var bgColor = theme === "light" ? "#ffffff" : "#000000";
266
+ for (var i = 0; i < MAX_TRIES; i++) {
267
+ var hue = Math.floor(Math.random() * 360);
268
+ var saturation = 80;
269
+ var lightness = theme === "light" ? 20 + Math.random() * 30 : 60 + Math.random() * 30;
270
+ var hex = hslToHex(hue, saturation, lightness);
271
+ if (hasGoodContrast(hex, bgColor, 6.0)) {
272
+ return hex;
273
+ }
274
+ }
275
+ return theme === "light" ? "#111111" : "#eeeeee";
276
+ }
277
+ function hexToRgb(hex) {
278
+ hex = hex.replace(/^#/, "");
279
+ if (hex.length === 3) {
280
+ hex = hex
281
+ .split("")
282
+ .map(function (c) { return c + c; })
283
+ .join("");
284
+ }
285
+ var num = parseInt(hex, 16);
286
+ return {
287
+ r: (num >> 16) & 255,
288
+ g: (num >> 8) & 255,
289
+ b: num & 255
290
+ };
291
+ }
292
+ function luminance(hex) {
293
+ var rgb = hexToRgb(hex);
294
+ var srgb = [rgb.r, rgb.g, rgb.b].map(function (c) {
295
+ var c_ = c / 255;
296
+ return c_ <= 0.03928 ? c_ / 12.92 : Math.pow((c_ + 0.055) / 1.055, 2.4);
297
+ });
298
+ return 0.2126 * srgb[0] + 0.7152 * srgb[1] + 0.0722 * srgb[2];
299
+ }
300
+ function contrastRatio(fg, bg) {
301
+ var L1 = luminance(fg);
302
+ var L2 = luminance(bg);
303
+ return (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05);
304
+ }
305
+ function hasGoodContrast(fg, bg, minRatio) {
306
+ if (minRatio === void 0) { minRatio = 6.0; }
307
+ return contrastRatio(fg, bg) >= minRatio;
308
+ }
309
+ function hslToHex(h, s, l) {
310
+ l /= 100;
311
+ var a = (s * Math.min(l, 1 - l)) / 100;
312
+ var f = function (n) {
313
+ var k = (n + h / 30) % 12;
314
+ var color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
315
+ return Math.round(255 * color)
316
+ .toString(16)
317
+ .padStart(2, "0");
318
+ };
319
+ return "#".concat(f(0)).concat(f(8)).concat(f(4));
320
+ }
321
+ var sourceColorMap = new Map();
322
+ function getStableColor(source, theme) {
323
+ if (!source)
324
+ return theme === "light" ? "#666" : "#999";
325
+ if (!sourceColorMap.has(source)) {
326
+ var mappedColor = mappingColors(source, theme);
327
+ if (mappedColor) {
328
+ sourceColorMap.set(source, { light: mappedColor, dark: mappedColor });
329
+ }
330
+ else {
331
+ sourceColorMap.set(source, {
332
+ light: generateAccessibleColor("light"),
333
+ dark: generateAccessibleColor("dark")
334
+ });
335
+ }
336
+ }
337
+ return sourceColorMap.get(source)[theme];
338
+ }
339
+ function mappingColors(source, theme) {
340
+ switch (source === null || source === void 0 ? void 0 : source.toLowerCase()) {
341
+ case "ansa.it":
342
+ return theme === "light" ? "#1976d2" : "#42a5f5";
343
+ case "eurosport.it":
344
+ return theme === "light" ? "#d32f2f" : "#ef5350";
345
+ case "ilpost.it":
346
+ return theme === "light" ? "#388e3c" : "#66bb6a";
347
+ case "corriere.it":
348
+ return theme === "light" ? "#f57c00" : "#ffa726";
349
+ case "techreport.com":
350
+ return theme === "light" ? "#1976d2" : "#42a5f5";
351
+ case "openai.com":
352
+ return theme === "light" ? "#7b1fa2" : "#ab47bc";
353
+ case "meta.ai":
354
+ return theme === "light" ? "#1976d2" : "#42a5f5";
355
+ case "kaggle.com":
356
+ return theme === "light" ? "#f57c00" : "#ffa726";
357
+ case "ethics.ai":
358
+ return theme === "light" ? "#1976d2" : "#42a5f5";
359
+ case "coursera.org":
360
+ return theme === "light" ? "#d32f2f" : "#ef5350";
361
+ case "spotify.com":
362
+ return "#1dd15d";
363
+ case "arxiv.org":
364
+ return theme === "light" ? "#7b1fa2" : "#ab47bc";
365
+ case "github.com":
366
+ return theme === "light" ? "#24292e" : "#f0f6fc";
367
+ case "stackoverflow.com":
368
+ return theme === "light" ? "#f48024" : "#f69c3d";
369
+ case "medium.com":
370
+ return theme === "light" ? "#000000" : "#ffffff";
371
+ case "youtube.com":
372
+ return theme === "light" ? "#ff0000" : "#ff4444";
373
+ case "x.com":
374
+ return theme === "light" ? "#1da1f2" : "#1d9bf0";
375
+ case "linkedin.com":
376
+ return theme === "light" ? "#0077b5" : "#0a66c2";
377
+ case "reddit.com":
378
+ return theme === "light" ? "#ff4500" : "#ff6314";
379
+ case "wikipedia.org":
380
+ return theme === "light" ? "#000000" : "#ffffff";
381
+ default:
382
+ return undefined;
383
+ }
384
+ }
385
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.Translate = void 0;
4
+ var useLanguage_1 = require("./useLanguage");
5
+ function Translate(_a) {
6
+ var _b;
7
+ var label = _a.label;
8
+ var language = (0, useLanguage_1.useLanguage)().language;
9
+ var htmlLang = language;
10
+ var translation = (_b = translations[label]) === null || _b === void 0 ? void 0 : _b[htmlLang];
11
+ return translation || label;
12
+ }
13
+ exports.Translate = Translate;
14
+ var translations = {
15
+ closeChatbot: {
16
+ it_IT: "Chiudi il chatbot",
17
+ en_US: "Close the chatbot",
18
+ fr_FR: "Fermez le chatbot",
19
+ es_ES: "Cerrar el chatbot",
20
+ de_DE: "Schließen Sie den Chatbot"
21
+ },
22
+ openChatbot: {
23
+ it_IT: "Apri il chatbot",
24
+ en_US: "Open the chatbot",
25
+ fr_FR: "Ouvrir le chatbot",
26
+ es_ES: "Abrir el chatbot",
27
+ de_DE: "Öffnen Sie den Chatbot"
28
+ },
29
+ clearChat: {
30
+ it_IT: "Svuota la chat",
31
+ en_US: "Clear the chat",
32
+ fr_FR: "Effacer le chat",
33
+ es_ES: "Borrar el chat",
34
+ de_DE: "Leeren Sie den Chat"
35
+ },
36
+ startQuestion: {
37
+ it_IT: "Fai partire una domanda",
38
+ en_US: "Start a question",
39
+ fr_FR: "Commencez une question",
40
+ es_ES: "Iniciar una pregunta",
41
+ de_DE: "Starten Sie eine Frage"
42
+ },
43
+ youSendMessage: {
44
+ it_IT: "tu hai mandato un messaggio alle ",
45
+ en_US: "you sent a message at ",
46
+ fr_FR: "vous avez envoyé un message à ",
47
+ es_ES: "tú enviaste un mensaje a las ",
48
+ de_DE: "du hast eine Nachricht um "
49
+ },
50
+ sendMessage: {
51
+ it_IT: "ha mandato un messaggio alle ",
52
+ en_US: "sent a message at ",
53
+ fr_FR: "a envoyé un message à ",
54
+ es_ES: "envió un mensaje a las ",
55
+ de_DE: "hat eine Nachricht um "
56
+ },
57
+ customPlaceholder: {
58
+ it_IT: "scrivi il tuo messaggio...",
59
+ en_US: "write your message...",
60
+ fr_FR: "écris ton message...",
61
+ es_ES: "escribe tu mensaje...",
62
+ de_DE: "Schreiben Sie Ihre Nachricht..."
63
+ },
64
+ searchLabel: {
65
+ it_IT: "Cerca nel chatbot",
66
+ en_US: "Search in the chatbot",
67
+ fr_FR: "Rechercher dans le chatbot",
68
+ es_ES: "Buscar en el chatbot",
69
+ de_DE: "Im Chatbot suchen"
70
+ }
71
+ };
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ exports.__esModule = true;
53
+ exports.OpenK9Client = exports.OpenK9ClientContext = void 0;
54
+ var react_1 = __importDefault(require("react"));
55
+ exports.OpenK9ClientContext = react_1["default"].createContext(null /* must break app if not provided */);
56
+ function Client() {
57
+ return null;
58
+ }
59
+ exports["default"] = Client;
60
+ function OpenK9Client(_a) {
61
+ var callbackAuthorization = _a.callbackAuthorization;
62
+ function authFetch(route, init) {
63
+ if (init === void 0) { init = {}; }
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var authorization, headers;
66
+ return __generator(this, function (_a) {
67
+ authorization = callbackAuthorization && callbackAuthorization();
68
+ headers = __assign(__assign({}, init.headers), (authorization ? { authorization: authorization } : {}));
69
+ return [2 /*return*/, fetch(route, __assign(__assign({}, init), { headers: headers }))];
70
+ });
71
+ });
72
+ }
73
+ return {
74
+ // authInit: keycloakInit,
75
+ // async authenticate() {
76
+ // await keycloak.login();
77
+ // },
78
+ // async deauthenticate() {
79
+ // await keycloak.logout();
80
+ // },
81
+ // async getUserProfile(): Promise<{ name?: string } | undefined | null> {
82
+ // if (!keycloak.authenticated) {
83
+ // throw new Error("User is not authenticated");
84
+ // }
85
+ // try {
86
+ // const userInfo = await keycloak.loadUserInfo();
87
+ // return userInfo as { name: string };
88
+ // } catch (error) {
89
+ // throw error;
90
+ // }
91
+ // },
92
+ getInitialMessages: function (chatId) {
93
+ return __awaiter(this, void 0, void 0, function () {
94
+ var response, data;
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0: return [4 /*yield*/, authFetch("/api/rag/chat/".concat(chatId))];
98
+ case 1:
99
+ response = _a.sent();
100
+ if (!response.ok)
101
+ throw new Error("Network response was not ok");
102
+ return [4 /*yield*/, response.json()];
103
+ case 2:
104
+ data = _a.sent();
105
+ return [2 /*return*/, data || []];
106
+ }
107
+ });
108
+ });
109
+ },
110
+ // async getUserInfo(): Promise<getUserInfo> {
111
+ // const response = await fetch(`/api/datasource/buckets/current`);
112
+ // if (!response.ok) throw new Error("Network response was not ok");
113
+ // const data = await response.json();
114
+ // return data;
115
+ // },
116
+ getHistoryChat: function (searchQuery) {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var response, result;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ //se refresha pagina browser, la chat riprende dal punto precedente
123
+ console.log("Calling getHistoryChat with URL:", "/api/rag/user-chats");
124
+ return [4 /*yield*/, authFetch("/api/rag/user-chats", {
125
+ method: "POST",
126
+ headers: {
127
+ accept: "application/json",
128
+ "Content-Type": "application/json"
129
+ },
130
+ body: JSON.stringify(searchQuery)
131
+ })];
132
+ case 1:
133
+ response = _a.sent();
134
+ if (!response.ok) {
135
+ console.error("Response not ok:", response.status, response.statusText);
136
+ throw new Error("Network response was not ok");
137
+ }
138
+ return [4 /*yield*/, response.json()];
139
+ case 2:
140
+ result = _a.sent();
141
+ return [2 /*return*/, result];
142
+ }
143
+ });
144
+ });
145
+ },
146
+ GenerateResponse: function (_a) {
147
+ var url = _a.url, searchQuery = _a.searchQuery, controller = _a.controller;
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ var response;
150
+ return __generator(this, function (_b) {
151
+ switch (_b.label) {
152
+ case 0: return [4 /*yield*/, authFetch(url, {
153
+ method: "POST",
154
+ headers: {
155
+ accept: "application/json",
156
+ "Content-Type": "application/json"
157
+ },
158
+ body: JSON.stringify(searchQuery),
159
+ signal: controller.signal
160
+ })];
161
+ case 1:
162
+ response = _b.sent();
163
+ return [2 /*return*/, response];
164
+ }
165
+ });
166
+ });
167
+ }
168
+ };
169
+ }
170
+ exports.OpenK9Client = OpenK9Client;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ exports.__esModule = true;
10
+ exports.ParagraphMessage = exports.ParagraphTime = void 0;
11
+ var styled_1 = __importDefault(require("@emotion/styled"));
12
+ exports.ParagraphTime = styled_1["default"].p(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n color: ", ";\n margin: 0px;\n align-self: end;\n font-size: 10px;\n font-weight: 500;\n line-height: 11.72px;\n"], ["\n color: ", ";\n margin: 0px;\n align-self: end;\n font-size: 10px;\n font-weight: 500;\n line-height: 11.72px;\n"])), function (props) { return props.$color; });
13
+ exports.ParagraphMessage = styled_1["default"].p(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n color:", ";\n margin: 0px;\n fontSize: \"12px\",\n fontWeight: \"400\",\n lineHeight: \"18.25px\",\n textAlign: \"left\",\n "], ["\n color:", ";\n margin: 0px;\n fontSize: \"12px\",\n fontWeight: \"400\",\n lineHeight: \"18.25px\",\n textAlign: \"left\",\n "])), function (props) { return props.$color; });
14
+ var templateObject_1, templateObject_2;