Skip to content

Commit

Permalink
Fix issue with the sent message history order
Browse files Browse the repository at this point in the history
  • Loading branch information
annmirosh committed Dec 13, 2024
1 parent be1e9ec commit c60629e
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 57 deletions.
153 changes: 98 additions & 55 deletions dist/alan_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -35706,7 +35706,7 @@
function replaceUnsafeChar(ch) {
return HTML_REPLACEMENTS[ch];
}
function escapeHtml2(str) {
function escapeHtml(str) {
if (HTML_ESCAPE_TEST_RE.test(str)) {
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
}
Expand Down Expand Up @@ -35801,7 +35801,7 @@
__proto__: null,
arrayReplaceAt,
assign,
escapeHtml: escapeHtml2,
escapeHtml,
escapeRE,
fromCodePoint,
has,
Expand Down Expand Up @@ -35975,11 +35975,11 @@
var default_rules = {};
default_rules.code_inline = function(tokens, idx, options, env, slf) {
const token = tokens[idx];
return "<code" + slf.renderAttrs(token) + ">" + escapeHtml2(token.content) + "</code>";
return "<code" + slf.renderAttrs(token) + ">" + escapeHtml(token.content) + "</code>";
};
default_rules.code_block = function(tokens, idx, options, env, slf) {
const token = tokens[idx];
return "<pre" + slf.renderAttrs(token) + "><code>" + escapeHtml2(tokens[idx].content) + "</code></pre>\n";
return "<pre" + slf.renderAttrs(token) + "><code>" + escapeHtml(tokens[idx].content) + "</code></pre>\n";
};
default_rules.fence = function(tokens, idx, options, env, slf) {
const token = tokens[idx];
Expand All @@ -35993,9 +35993,9 @@
}
let highlighted;
if (options.highlight) {
highlighted = options.highlight(token.content, langName, langAttrs) || escapeHtml2(token.content);
highlighted = options.highlight(token.content, langName, langAttrs) || escapeHtml(token.content);
} else {
highlighted = escapeHtml2(token.content);
highlighted = escapeHtml(token.content);
}
if (highlighted.indexOf("<pre") === 0) {
return highlighted + "\n";
Expand Down Expand Up @@ -36030,7 +36030,7 @@
return options.breaks ? options.xhtmlOut ? "<br />\n" : "<br>\n" : "\n";
};
default_rules.text = function(tokens, idx) {
return escapeHtml2(tokens[idx].content);
return escapeHtml(tokens[idx].content);
};
default_rules.html_block = function(tokens, idx) {
return tokens[idx].content;
Expand All @@ -36048,7 +36048,7 @@
}
result = "";
for (i = 0, l = token.attrs.length; i < l; i++) {
result += " " + escapeHtml2(token.attrs[i][0]) + '="' + escapeHtml2(token.attrs[i][1]) + '"';
result += " " + escapeHtml(token.attrs[i][0]) + '="' + escapeHtml(token.attrs[i][1]) + '"';
}
return result;
};
Expand Down Expand Up @@ -89509,12 +89509,53 @@
<path d="M17.2915 17.7085L29.3026 5.69727M17.4375 18.0837L20.4438 25.8143C20.7086 26.4954 20.8411 26.8358 21.0319 26.9352C21.1973 27.0215 21.3944 27.0216 21.5598 26.9356C21.7507 26.8364 21.8836 26.4961 22.1493 25.8153L29.688 6.4971C29.9279 5.88261 30.0478 5.57536 29.9821 5.37903C29.9252 5.20853 29.7914 5.07473 29.6209 5.01777C29.4246 4.95219 29.1173 5.07209 28.5028 5.31188L9.18467 12.8507C8.50392 13.1164 8.16361 13.2492 8.06444 13.4401C7.97841 13.6056 7.97852 13.8027 8.06477 13.9681C8.16418 14.1589 8.50473 14.2913 9.18571 14.5562L16.9163 17.5625C17.0545 17.6163 17.1236 17.6432 17.1818 17.6847C17.2334 17.7214 17.2784 17.7666 17.3153 17.8182C17.3568 17.8763 17.3837 17.9455 17.4375 18.0837Z" stroke="#4A515D" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
`,
msgLoader: `<svg xmlns="http://www.w3.org/2000/svg" class="alan-text-chat__msg-loader-svg" viewBox="0 0 200 200">
<radialGradient id="a12" cx=".66" fx=".66" cy=".3125" fy=".3125" gradientTransform="scale(1.5)">
<stop offset="0" stop-color="currentColor"></stop>
<stop offset=".3" stop-color="currentColor" stop-opacity=".9"></stop>
<stop offset=".6" stop-color="currentColor" stop-opacity=".6"></stop>
<stop offset=".8" stop-color="currentColor" stop-opacity=".3"></stop>
<stop offset="1" stop-color="currentColor" stop-opacity="0"></stop>
</radialGradient>
<circle
transform-origin="center"
fill="none"
stroke="url(#a12)"
stroke-width="15"
stroke-linecap="round"
stroke-dasharray="200 1000"
stroke-dashoffset="0"
cx="100"
cy="100"
r="70"
>
<animateTransform
type="rotate"
attributeName="transform"
calcMode="spline"
dur="2"
values="360;0"
keyTimes="0;1"
keySplines="0 0 1 1"
repeatCount="indefinite"
></animateTransform>
</circle>
<circle
transform-origin="center"
fill="none"
opacity=".2"
stroke="currentColor"
stroke-width="15"
stroke-linecap="round"
cx="100"
cy="100"
r="70"
></circle>
</svg>`,
stopResponse: `
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6.38461 8.38458C6.38461 7.28001 7.28004 6.38458 8.38461 6.38458H13.6154C14.72 6.38458 15.6154 7.28001 15.6154 8.38458V13.6154C15.6154 14.7199 14.72 15.6154 13.6154 15.6154H8.38461C7.28004 15.6154 6.38461 14.7199 6.38461 13.6154V8.38458Z" stroke="black"/>
<circle cx="11" cy="11" r="10" stroke="black"/>
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="6" y="6" width="8" height="8" rx="1" fill="#64AED5"/>
</svg>

`,
mic: `
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
Expand Down Expand Up @@ -89608,7 +89649,8 @@
const isQueryProgressEnabled = textChatOptions?.bubbles?.waitingResponse?.queryProgress?.enabled;
const waitingResponseBubbleLayout = textChatOptions?.bubbles?.waitingResponse?.layout || "default";
const isDefaultLayout = waitingResponseBubbleLayout === "default";
let waitingResponseBubbleLabel = !isDefaultLayout || isQueryProgressEnabled ? isDefaultLayout ? "" : textChatOptions?.bubbles?.waitingResponse?.label || "Generating result" : "";
const hasCustomLoaderSvg = textChatOptions?.bubbles?.waitingResponse?.icon?.svg;
let waitingResponseBubbleLabel = textChatOptions?.bubbles?.waitingResponse?.label || "Generating result";
if (message?.queryProgress) {
const unshownStatuses = message?.queryProgress?.filter((s) => s.isShown === false);
waitingResponseBubbleLabel = unshownStatuses?.length > 0 ? unshownStatuses[0].text : message?.queryProgress[message?.queryProgress?.length - 1].text || "";
Expand All @@ -89617,18 +89659,15 @@
if (onlyLoader) {
waitingResponseBubbleLabel = "";
}
const content = isDefaultLayout ? `<span class="alan-btn__chat-incomming-msg-loader-label-default ${waitingResponseBubbleLabel?.length > 0 ? "with-text" : ""}">
${getMsgStopBtn(textChatOptions, true)}
${waitingResponseBubbleLabel || ""}</span>
<div class="alan-btn__chat-incomming-msg-inner-wrapper ${waitingResponseBubbleLabel === "" ? "" : "with-text"}"><div class="alan-btn__chat-incomming-msg msg-1">&nbsp;</div> <div class="alan-btn__chat-incomming-msg msg-2">&nbsp;</div> <div class="alan-btn__chat-incomming-msg msg-3">&nbsp;</div></div>` : `<span class="alan-btn__chat-incomming-msg-loader-icon alan-btn__chat-stop-response-holder">
${getMsgStopBtn(textChatOptions, false)}
const content = `<span class="alan-btn__chat-incomming-msg-loader-icon alan-btn__chat-stop-response-holder">
${!hasCustomLoaderSvg ? chatIcons.msgLoader : ""}${getMsgStopBtn(textChatOptions)}
</span>
<span class="alan-btn__chat-incomming-msg-loader-label">${waitingResponseBubbleLabel}</span>`;
<span class="alan-btn__chat-incomming-msg-loader-label">${waitingResponseBubbleLabel}</span>`;
return `<div class="alan-btn__chat-incomming-msg-wrapper">${content}</div>`;
}
function getMsgStopBtn(textChatOptions, shouldBeWrapped) {
const content = `<div class="alan-btn__stop-response-btn">${getStopChatIcon(textChatOptions)}</div>`;
return shouldBeWrapped ? `<div class="alan-btn__chat-stop-response-holder">${content}</div>` : content;
function getMsgStopBtn(textChatOptions) {
const content = `<div style="position:absolute;" class="alan-btn__stop-response-btn" title="Stop response generation">${getStopChatIcon(textChatOptions)}</div>`;
return content;
}
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.substring(1);
Expand Down Expand Up @@ -91247,6 +91286,9 @@
keyFrames += getStyleSheetMarker() + `.alan-btn__chat .alan-btn__chat-stop-response-holder {
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
poisiton: relative;
}`;
keyFrames += getStyleSheetMarker() + `.alan-btn__chat .alan-btn__chat-stop-response-holder .alan-btn__stop-response-btn svg path {
stroke: ${stopResponseIconDefaultColor};
Expand Down Expand Up @@ -92177,6 +92219,15 @@
const responseBubbleBg = textChatOptions?.bubbles?.response?.backgroundColor || `#ffffff`;
const responseBubbleFontColor = textChatOptions?.bubbles?.response?.color || `#171717`;
const [responseLabelWidth, responseLabelHeight] = parseSvgSize(waitingResponseBubbleLoaderIcon);
keyFrames += styleSheetMarker + `.alan-text-chat__msg-loader-svg {
color: ${responseBubbleFontColor};
min-width: 22px;
max-width: 22px;
width: 22px;
min-height: 22px;
max-height: 22px;
height: 22px;
}`;
keyFrames += styleSheetMarker + `.alan-btn__chat-incomming-msg-wrapper {
display: flex;
max-width: 100%;
Expand Down Expand Up @@ -92349,21 +92400,26 @@
// alan_btn/src/textChat/alanMarkdown.ts
var iterator = require_index_cjs();
var markdownItScrollTable = require_markdown_it_scrolltable();
var ESCAPE_TAG_MAP = {
"<script": "&lt;script",
"<link": "&lt;link",
"<title": "&lt;title",
"<meta": "&lt;meta",
"<thinking>": '<span class="alan-special-markdown-tag-hl-green">&lt;thinking&gt;</span>',
"</thinking>": '<span class="alan-special-markdown-tag-hl-green">&lt;/thinking&gt;</span>',
"<reasoning>": '<span class="alan-special-markdown-tag-hl-green">&lt;reasoning&gt;</span>',
"</reasoning>": '<span class="alan-special-markdown-tag-hl-green">&lt;/reasoning&gt;</span>'
var ESCAPE_CUSTOM_TAG_MAP = {
"<thinking>": '<div class="alan-special-markdown-tag-wrapper"><span class="alan-special-markdown-tag-hl-green">&lt;thinking&gt;</span>',
"</thinking>": '<span class="alan-special-markdown-tag-hl-green">&lt;/thinking&gt;</span></div>',
"<reasoning>": '<div class="alan-special-markdown-tag-wrapper"><span class="alan-special-markdown-tag-hl-green">&lt;reasoning&gt;</span>',
"</reasoning>": '<span class="alan-special-markdown-tag-hl-green">&lt;/reasoning&gt;</span></div>'
};
function alanMarkdown(str = "") {
var md = require_index_cjs5()({ html: true }).use(require_index_cjs6()).use(markdownItScrollTable).use(iterator, "url_new_win", "link_open", function(tokens, idx) {
tokens[idx].attrSet("target", "_blank");
});
return sanitize(md.render(str || ""));
return sanitize(md.render(sanitizeCustomTags(str || "")));
}
function sanitizeCustomTags(str) {
let result = str;
for (const [tag, replacement] of Object.entries(ESCAPE_CUSTOM_TAG_MAP)) {
const tagRegex = new RegExp(tag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g");
result = result.replace(tagRegex, replacement);
}
console.info("result", result);
return result;
}
function sanitize(str) {
let tag = "";
Expand All @@ -92378,16 +92434,6 @@
break;
}
}
for (const escapedTag in ESCAPE_TAG_MAP) {
if (tag.startsWith(escapedTag)) {
result += escapeHtml(tag);
tag = "";
if (str[i + 1] === "\n" && str[i + 2] === "<") {
result += "<br/>";
}
break;
}
}
if (tag !== "") {
result += tag;
tag = "";
Expand All @@ -92398,14 +92444,6 @@
}
return result;
}
function escapeHtml(text) {
let resultStr = text;
for (const key in ESCAPE_TAG_MAP) {
var r = new RegExp(`${key}`, "gi");
resultStr = String(resultStr).replace(r, ESCAPE_TAG_MAP[key]);
}
return resultStr;
}

// alan_btn/src/textChat/helpers/getLinkIcon.ts
function getLinkIcon(link) {
Expand Down Expand Up @@ -93924,9 +93962,14 @@ code.hljs {
;
}

// alan_btn/src/textChat/helpers/shouldTextBeSavedInChatHistory.ts
function shouldTextBeSavedInChatHistory(text, sentMessages) {
return sentMessages?.at(-1) !== text;
}

// alan_btn/alan_btn.ts
(function(ns) {
uiState.lib.version = "alan-version.1.8.72".replace("alan-version.", "");
uiState.lib.version = "alan-version.1.8.73".replace("alan-version.", "");
if (window.alanBtn) {
console.warn("Alan: the Alan Button source code has already added (v." + uiState.lib.version + ")");
}
Expand Down Expand Up @@ -95826,7 +95869,7 @@ code.hljs {
logosToHide[i2].style.opacity = 0;
}
}
function escapeHtml2(text) {
function escapeHtml(text) {
let resultStr = text;
var entityMap = {
"<script>": "&lt;script&gt;",
Expand Down Expand Up @@ -96092,7 +96135,7 @@ code.hljs {
if (msg.ctx?.format === "markdown") {
result = alanMarkdown(msg.text || "");
} else {
result = escapeHtml2(msg.text);
result = escapeHtml(msg.text);
}
return result ? `<span class="alan-btn__chat-response-text-wrapper">${fixTargetForLinks(result)}</span>` : "";
}
Expand Down Expand Up @@ -96202,7 +96245,7 @@ ${LEARN_MORE_LABEL}
} else {
if (msg.name === "text" || msg.name === "parsed" || msg.name === "recognized") {
if (msg.type === "request") {
innerMsgPart = escapeHtml2(msg.text);
innerMsgPart = escapeHtml(msg.text);
} else {
innerMsgPart = buildMsgContent(msg);
}
Expand Down Expand Up @@ -96663,7 +96706,7 @@ ${LEARN_MORE_LABEL}
if (isLocalStorageAvailable) {
const maxSavedForHistoryMsgCount = 25;
const key = getRestoreMsgsLsKey();
if (sentMessages?.indexOf(text) > -1)
if (!shouldTextBeSavedInChatHistory(text, sentMessages))
return;
sentMessages.push(text);
if (sentMessages.length > 50) {
Expand Down
2 changes: 1 addition & 1 deletion dist/alan_lib.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alan-ai/alan-sdk-web",
"version": "1.8.72",
"version": "1.8.73",
"description": "Alan Web SDK: a lightweight JavaScript library for adding a voice experience to your website or web application",
"keywords": [
"alan sdk web",
Expand Down

0 comments on commit c60629e

Please sign in to comment.