这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions embed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ REQUIRED data attributes:

- `data-assistant-icon` - Set the icon of the chat assistant.

- `data-window-height` - Set the chat window height. **must include CSS suffix:** `px`,`%`,`rem`

- `data-window-width` - Set the chat window width. **must include CSS suffix:** `px`,`%`,`rem`

- `data-text-size` - Set the text size of the chats in pixels.

**Behavior Overrides**

- `data-open-on-load` — Once loaded, open the chat as default. It can still be closed by the user.
Expand Down
4 changes: 3 additions & 1 deletion embed/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!doctype html>
<html lang="en">

<body>
<h1>This is an example testing page for embedded AnythingLLM.</h1>
<!--
Expand All @@ -8,4 +9,5 @@ <h1>This is an example testing page for embedded AnythingLLM.</h1>
</script>
-->
</body>
</html>

</html>
8 changes: 7 additions & 1 deletion embed/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ export default function App() {
};

const position = embedSettings.position || "bottom-right";
const windowWidth = embedSettings.windowWidth
? `md:max-w-[${embedSettings.windowWidth}]`
: "md:max-w-[400px]";
const windowHeight = embedSettings.windowHeight
? `md:max-h-[${embedSettings.windowHeight}]`
: "md:max-h-[700px]";

return (
<>
<Head />
<div className={`fixed inset-0 z-50 ${isChatOpen ? "block" : "hidden"}`}>
<div
className={`w-full h-full bg-white md:max-w-[400px] md:max-h-[700px] md:fixed md:bottom-0 md:right-0 md:mb-4 md:mr-4 md:rounded-2xl md:border md:border-gray-300 md:shadow-[0_4px_14px_rgba(0,0,0,0.25)] ${positionClasses[position]}`}
className={`${windowHeight} ${windowWidth} h-full w-full bg-white md:fixed md:bottom-0 md:right-0 md:mb-4 md:mr-4 md:rounded-2xl md:border md:border-gray-300 md:shadow-[0_4px_14px_rgba(0,0,0,0.25)] ${positionClasses[position]}`}
id="anything-llm-chat"
>
{isChatOpen && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const HistoricalMessage = forwardRef(
{ uuid = v4(), message, role, sources = [], error = false, sentAt },
ref
) => {
const textSize = !!embedderSettings.settings.textSize
? `text-[${embedderSettings.settings.textSize}px]`
: "text-sm";

return (
<div className="py-[5px]">
{role === "assistant" && (
Expand Down Expand Up @@ -61,7 +65,7 @@ const HistoricalMessage = forwardRef(
</div>
) : (
<span
className={`whitespace-pre-line font-medium flex flex-col gap-y-1 text-sm leading-[20px]`}
className={`whitespace-pre-line font-medium flex flex-col gap-y-1 ${textSize} leading-[20px]`}
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(renderMarkdown(message)),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function ChatHistory({ settings = {}, history = [] }) {

return (
<div
className="pb-[30px] pt-[5px] rounded-lg px-2 h-full gap-y-2 overflow-y-scroll flex flex-col justify-start no-scroll md:max-h-[500px] max-h-[calc(100vh-200px)]"
className="pb-[30px] pt-[5px] rounded-lg px-2 h-full gap-y-2 overflow-y-scroll flex flex-col justify-start no-scroll md:max-h-[500px]"
id="chat-history"
ref={chatHistoryRef}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function PromptInput({
};

return (
<div className="w-full absolute left-0 bottom-[25px] z-10 flex justify-center items-center px-5">
<div className="w-full sticky bottom-0 z-10 flex justify-center items-center px-5 bg-white">
<form
onSubmit={handleSubmit}
className="flex flex-col gap-y-1 rounded-t-lg w-full items-center justify-center"
Expand Down
9 changes: 6 additions & 3 deletions embed/src/components/ChatWindow/ChatContainer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function ChatContainer({

const handleSubmit = async (event) => {
event.preventDefault();

if (!message || message === "") return false;

const prevChatHistory = [
Expand All @@ -39,7 +40,6 @@ export default function ChatContainer({
animate: true,
},
];

setChatHistory(prevChatHistory);
setMessage("");
setLoadingResponse(true);
Expand Down Expand Up @@ -72,12 +72,15 @@ export default function ChatContainer({
);
return;
}

loadingResponse === true && fetchReply();
}, [loadingResponse, chatHistory]);

return (
<div className="h-full w-full relative">
<ChatHistory settings={settings} history={chatHistory} />
<div className="h-full w-full flex flex-col">
<div className="flex-grow overflow-y-auto">
<ChatHistory settings={settings} history={chatHistory} />
</div>
<PromptInput
message={message}
submit={handleSubmit}
Expand Down
17 changes: 11 additions & 6 deletions embed/src/components/ChatWindow/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function ChatWindow({ closeChat, settings, sessionId }) {
}

setEventDelegatorForCodeSnippets();

return (
<div className="flex flex-col h-full">
<ChatWindowHeader
Expand All @@ -41,12 +42,14 @@ export default function ChatWindow({ closeChat, settings, sessionId }) {
closeChat={closeChat}
setChatHistory={setChatHistory}
/>
<ChatContainer
sessionId={sessionId}
settings={settings}
knownHistory={chatHistory}
/>
<div className="-mt-2 pb-6 h-fit gap-y-2 z-10">
<div className="flex-grow overflow-y-auto">
<ChatContainer
sessionId={sessionId}
settings={settings}
knownHistory={chatHistory}
/>
</div>
<div className="mt-4 pb-4 h-fit gap-y-2 z-10">
<Sponsor settings={settings} />
<ResetChat
setChatHistory={setChatHistory}
Expand All @@ -64,13 +67,15 @@ export default function ChatWindow({ closeChat, settings, sessionId }) {
function copyCodeSnippet(uuid) {
const target = document.querySelector(`[data-code="${uuid}"]`);
if (!target) return false;

const markdown =
target.parentElement?.parentElement?.querySelector(
"pre:first-of-type"
)?.innerText;
if (!markdown) return false;

window.navigator.clipboard.writeText(markdown);

target.classList.add("text-green-500");
const originalText = target.innerHTML;
target.innerText = "Copied!";
Expand Down
3 changes: 3 additions & 0 deletions embed/src/hooks/useScriptAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const DEFAULT_SETTINGS = {
position: "bottom-right", // position of chat button/window
assistantName: "AnythingLLM Chat Assistant", // default assistant name
assistantIcon: null, // default assistant icon
windowHeight: null, // height of chat window in number:css-prefix
windowWidth: null, // width of chat window in number:css-prefix
textSize: null, // text size in px (number only)

// behaviors
openOnLoad: "off", // or "on"
Expand Down
6 changes: 3 additions & 3 deletions frontend/public/embed/anythingllm-chat-widget.min.js

Large diffs are not rendered by default.