diff --git a/src/lib/components/chat/AssistantIntroduction.svelte b/src/lib/components/chat/AssistantIntroduction.svelte index 24f57ef62e6..2f079f30ca0 100644 --- a/src/lib/components/chat/AssistantIntroduction.svelte +++ b/src/lib/components/chat/AssistantIntroduction.svelte @@ -124,7 +124,10 @@ -
+
diff --git a/src/lib/components/chat/ChatWindow.svelte b/src/lib/components/chat/ChatWindow.svelte index 7ce3ef950b1..3475f72cf4e 100644 --- a/src/lib/components/chat/ChatWindow.svelte +++ b/src/lib/components/chat/ChatWindow.svelte @@ -241,7 +241,7 @@
- {#if $page.data?.assistant && !!messages.length} + {#if $page.data?.assistant && !!messages.length && !$page.data.embeddedAssistantId} - {:else if preprompt && preprompt != currentModel.preprompt} + {:else if preprompt && preprompt != currentModel.preprompt && !$page.data.embeddedAssistantId} {/if} @@ -448,6 +448,7 @@

Model: diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 64de8f23f62..90b4134e2c4 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -244,5 +244,6 @@ export const load: LayoutServerLoad = async ({ locals, depends, request }) => { loginRequired, loginEnabled: requiresUser, guestMode: requiresUser && messagesBeforeLogin > 0, + embeddedAssistantId: "5555", }; }; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 17259c17e5f..85e2f5576e3 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -203,49 +203,63 @@ {#if envPublic.PUBLIC_APPLE_APP_ID} {/if} + + {#if !$settings.ethicsModalAccepted && $page.url.pathname !== `${base}/privacy` && PUBLIC_APP_DISCLAIMER === "1"} {/if} - (isNavCollapsed = !isNavCollapsed)} - classNames="absolute inset-y-0 z-10 my-auto {!isNavCollapsed - ? 'left-[280px]' - : 'left-0'} *:transition-transform" -/> - -

- (isNavOpen = ev.detail)} title={mobileNavTitle}> - shareConversation(ev.detail.id, ev.detail.title)} - on:deleteConversation={(ev) => deleteConversation(ev.detail)} - on:editConversationTitle={(ev) => editConversationTitle(ev.detail.id, ev.detail.title)} - /> - - - {#if currentError} - - {/if} - -
+ (isNavOpen = ev.detail)} + title={mobileNavTitle} + > + shareConversation(ev.detail.id, ev.detail.title)} + on:deleteConversation={(ev) => deleteConversation(ev.detail)} + on:editConversationTitle={(ev) => editConversationTitle(ev.detail.id, ev.detail.title)} + /> + + + {#if currentError} + + {/if} + +
+{:else} +
+ +
+{/if} diff --git a/src/routes/api/assistant/[id]/embed-snippet/+server.ts b/src/routes/api/assistant/[id]/embed-snippet/+server.ts new file mode 100644 index 00000000000..5958a1c5646 --- /dev/null +++ b/src/routes/api/assistant/[id]/embed-snippet/+server.ts @@ -0,0 +1,103 @@ +export async function GET() { + const script = `(function() { + function resizeIframeToContentSize(iframe) { + if (iframe.contentWindow) { + const maxHeight = window.innerHeight * 0.8; // 80% of window height + const contentHeight = iframe.contentWindow.document.body.scrollHeight; + console.log("contentHeight", contentHeight); + iframe.style.height = Math.min(contentHeight, maxHeight) + "px"; + } + } + + document.addEventListener('DOMContentLoaded', function() { + const button = document.createElement('button'); + button.innerHTML = 'AI Chat'; + button.className = 'fixed bottom-5 left-5 z-50 px-5 py-2.5 bg-blue-500 text-white rounded cursor-pointer hover:bg-blue-600 transition-colors'; + + const modal = document.createElement('div'); + modal.className = 'hidden fixed inset-0 z-[1001] overflow-auto bg-black bg-opacity-50'; + + const modalContent = document.createElement('div'); + modalContent.className = 'bg-transparent mx-auto my-[5%] max-w-2xl rounded'; + + const closeButton = document.createElement('span'); + closeButton.innerHTML = '×'; + closeButton.className = 'text-gray-500 float-right text-2xl font-bold cursor-pointer hover:text-gray-700'; + + const iframe = document.createElement('iframe'); + iframe.className = 'w-full rounded-xl'; + iframe.style.height = '500px'; // Set an initial height + iframe.src = \`http://localhost:5173/chat/\`; + + iframe.onload = function() { + const iframeWindow = this.contentWindow; + iframeWindow.parent = { + resizeIframeToContentSize: resizeIframeToContentSize.bind(null, iframe) + }; + + const script = iframeWindow.document.createElement('script'); + script.textContent = \` + this.container = this.frameElement.contentWindow.document.body; + this.lastScrollHeight = 0; + + this.watch = () => { + cancelAnimationFrame(this.watcher); + + if (this.lastScrollHeight !== container.scrollHeight) { + parent.resizeIframeToContentSize(); + } + this.lastScrollHeight = container.scrollHeight; + this.watcher = requestAnimationFrame(this.watch); + }; + this.watcher = window.requestAnimationFrame(this.watch); + \`; + iframeWindow.document.body.appendChild(script); + }; + + modalContent.appendChild(closeButton); + modalContent.appendChild(iframe); + modal.appendChild(modalContent); + + function closeModal() { + modal.classList.add('hidden'); + } + + button.onclick = function() { + modal.classList.remove('hidden'); + resizeIframeToContentSize(iframe); // Resize on opening to ensure correct initial size + }; + + closeButton.onclick = closeModal; + + window.onclick = function(event) { + if (event.target == modal) { + closeModal(); + } + }; + + document.addEventListener('keydown', function(event) { + if (event.key === 'Escape') { + closeModal(); + } + }); + + // Add resize event listener to adjust iframe height when window is resized + window.addEventListener('resize', function() { + if (!modal.classList.contains('hidden')) { + resizeIframeToContentSize(iframe); + } + }); + + document.body.appendChild(button); + document.body.appendChild(modal); + }); +})(); +`; + + return new Response(script, { + headers: { + "Content-Type": "application/javascript", + "Access-Control-Allow-Origin": "*", + }, + }); +}