Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mishig25 committed Sep 28, 2024
1 parent d60cfa3 commit fb52674
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 46 deletions.
6 changes: 5 additions & 1 deletion src/lib/components/chat/AssistantIntroduction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@
</div>
</div>

<div class="absolute right-3 top-3 md:right-4 md:top-4">
<div
class="absolute right-3 top-3 md:right-4 md:top-4"
class:hidden={$page.data.embeddedAssistantId}
>
<div class="flex flex-row items-center gap-1">
<button
class="flex h-7 items-center gap-1.5 rounded-full border bg-white px-2.5 py-1 text-gray-800 shadow-sm hover:shadow-inner dark:border-gray-700 dark:bg-gray-700 dark:text-gray-300/90 dark:hover:bg-gray-800 max-sm:px-1.5 md:text-sm"
Expand Down Expand Up @@ -161,6 +164,7 @@
goto(`${base}/`);
}}
class="absolute -bottom-6 right-2 inline-flex items-center justify-center text-xs text-gray-600 underline hover:brightness-50 dark:text-gray-400 dark:hover:brightness-110"
class:hidden={$page.data.embeddedAssistantId}
>
<CarbonRenew class="mr-1.5 text-xxs" /> Reset to default model
</button>
Expand Down
8 changes: 5 additions & 3 deletions src/lib/components/chat/ChatWindow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
on:drop|preventDefault={() => (onDrag = false)}
/>

<div class="relative min-h-0 min-w-0">
<div class="relative min-w-0" class:min-h-[400px]={$page.data.embeddedAssistantId}>
{#if loginModalOpen}
<LoginModal
on:close={() => {
Expand All @@ -238,11 +238,12 @@
class="scrollbar-custom mr-1 h-full overflow-y-auto"
use:snapScrollToBottom={messages.length ? [...messages] : false}
bind:this={chatContainer}
id="chat-container"
>
<div
class="mx-auto flex h-full max-w-3xl flex-col gap-6 px-5 pt-6 sm:gap-8 xl:max-w-4xl xl:pt-10"
>
{#if $page.data?.assistant && !!messages.length}
{#if $page.data?.assistant && !!messages.length && !$page.data.embeddedAssistantId}
<a
class="mx-auto flex items-center gap-1.5 rounded-full border border-gray-100 bg-gray-50 py-1 pl-1 pr-3 text-sm text-gray-800 hover:bg-gray-100 dark:border-gray-800 dark:bg-gray-800 dark:text-gray-200 dark:hover:bg-gray-700"
href="{base}/settings/assistants/{$page.data.assistant._id}"
Expand All @@ -264,7 +265,7 @@

{$page.data.assistant.name}
</a>
{:else if preprompt && preprompt != currentModel.preprompt}
{:else if preprompt && preprompt != currentModel.preprompt && !$page.data.embeddedAssistantId}
<SystemPromptModal preprompt={preprompt ?? ""} />
{/if}

Expand Down Expand Up @@ -455,6 +456,7 @@
</form>
<div
class="mt-2 flex justify-between self-stretch px-1 text-xs text-gray-400/90 max-md:mb-2 max-sm:gap-2"
class:hidden={$page.data.embeddedAssistantId}
>
<p>
Model:
Expand Down
17 changes: 15 additions & 2 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import type { ConvSidebar } from "$lib/types/ConvSidebar";
import { toolFromConfigs } from "$lib/server/tools";
import { MetricsServer } from "$lib/server/metrics";
import type { ToolFront, ToolInputFile } from "$lib/types/Tool";
import { error } from "@sveltejs/kit";

export const load: LayoutServerLoad = async ({ locals, depends, request }) => {
export const load: LayoutServerLoad = async ({ locals, depends, request, url }) => {
depends(UrlDependency.ConversationList);

const settings = await collections.settings.findOne(authCondition(locals));
Expand Down Expand Up @@ -44,7 +45,7 @@ export const load: LayoutServerLoad = async ({ locals, depends, request }) => {

const assistantActive = !models.map(({ id }) => id).includes(settings?.activeModel ?? "");

const assistant = assistantActive
let assistant = assistantActive
? JSON.parse(
JSON.stringify(
await collections.assistants.findOne({
Expand All @@ -54,6 +55,17 @@ export const load: LayoutServerLoad = async ({ locals, depends, request }) => {
)
: null;

const embeddedAssistantId = url.searchParams.get("embeddedAssistantId");
if (embeddedAssistantId) {
const embeddedAssistant = await collections.assistants.findOne({
_id: new ObjectId(embeddedAssistantId),
});
if (!embeddedAssistant) {
error(404, "Embedded Assistant not found.");
}
assistant = JSON.parse(JSON.stringify(embeddedAssistant));
}

const conversations = await collections.conversations
.find(authCondition(locals))
.sort({ updatedAt: -1 })
Expand Down Expand Up @@ -245,5 +257,6 @@ export const load: LayoutServerLoad = async ({ locals, depends, request }) => {
loginRequired,
loginEnabled: requiresUser,
guestMode: requiresUser && messagesBeforeLogin > 0,
embeddedAssistantId: url.searchParams.get("embeddedAssistantId"),
};
};
98 changes: 59 additions & 39 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -203,49 +203,69 @@
{#if envPublic.PUBLIC_APPLE_APP_ID}
<meta name="apple-itunes-app" content={`app-id=${envPublic.PUBLIC_APPLE_APP_ID}`} />
{/if}
<!-- TODO: remove -->
{#if !$page.data.embeddedAssistantId}
<script
src="http://localhost:5173/chat/api/assistant/{$page.data.assistants.at(-1)
._id}/embed-snippet"
defer
></script>
{/if}
</svelte:head>

{#if !$settings.ethicsModalAccepted && $page.url.pathname !== `${base}/privacy` && PUBLIC_APP_DISCLAIMER === "1"}
<DisclaimerModal />
{/if}

<ExpandNavigation
isCollapsed={isNavCollapsed}
on:click={() => (isNavCollapsed = !isNavCollapsed)}
classNames="absolute inset-y-0 z-10 my-auto {!isNavCollapsed
? 'left-[280px]'
: 'left-0'} *:transition-transform"
/>

<div
class="grid h-full w-screen grid-cols-1 grid-rows-[auto,1fr] overflow-hidden text-smd {!isNavCollapsed
? 'md:grid-cols-[280px,1fr]'
: 'md:grid-cols-[0px,1fr]'} transition-[300ms] [transition-property:grid-template-columns] dark:text-gray-300 md:grid-rows-[1fr]"
>
<MobileNav isOpen={isNavOpen} on:toggle={(ev) => (isNavOpen = ev.detail)} title={mobileNavTitle}>
<NavMenu
conversations={data.conversations}
user={data.user}
canLogin={data.user === undefined && data.loginEnabled}
on:shareConversation={(ev) => shareConversation(ev.detail.id, ev.detail.title)}
on:deleteConversation={(ev) => deleteConversation(ev.detail)}
on:editConversationTitle={(ev) => editConversationTitle(ev.detail.id, ev.detail.title)}
/>
</MobileNav>
<nav
class=" grid max-h-screen grid-cols-1 grid-rows-[auto,1fr,auto] overflow-hidden *:w-[280px] max-md:hidden"
{#if !$page.data.embeddedAssistantId}
<ExpandNavigation
isCollapsed={isNavCollapsed}
on:click={() => (isNavCollapsed = !isNavCollapsed)}
classNames="absolute inset-y-0 z-10 my-auto {!isNavCollapsed
? 'left-[280px]'
: 'left-0'} *:transition-transform"
/>

<div
class="grid h-full w-screen grid-cols-1 grid-rows-[auto,1fr] overflow-hidden text-smd {!isNavCollapsed
? 'md:grid-cols-[280px,1fr]'
: 'md:grid-cols-[0px,1fr]'} transition-[300ms] [transition-property:grid-template-columns] dark:text-gray-300 md:grid-rows-[1fr]"
>
<NavMenu
conversations={data.conversations}
user={data.user}
canLogin={data.user === undefined && data.loginEnabled}
on:shareConversation={(ev) => shareConversation(ev.detail.id, ev.detail.title)}
on:deleteConversation={(ev) => deleteConversation(ev.detail)}
on:editConversationTitle={(ev) => editConversationTitle(ev.detail.id, ev.detail.title)}
/>
</nav>
{#if currentError}
<Toast message={currentError} />
{/if}
<slot />
</div>
<MobileNav
isOpen={isNavOpen}
on:toggle={(ev) => (isNavOpen = ev.detail)}
title={mobileNavTitle}
>
<NavMenu
conversations={data.conversations}
user={data.user}
canLogin={data.user === undefined && data.loginEnabled}
on:shareConversation={(ev) => shareConversation(ev.detail.id, ev.detail.title)}
on:deleteConversation={(ev) => deleteConversation(ev.detail)}
on:editConversationTitle={(ev) => editConversationTitle(ev.detail.id, ev.detail.title)}
/>
</MobileNav>
<nav
class=" grid max-h-screen grid-cols-1 grid-rows-[auto,1fr,auto] overflow-hidden *:w-[280px] max-md:hidden"
>
<NavMenu
conversations={data.conversations}
user={data.user}
canLogin={data.user === undefined && data.loginEnabled}
on:shareConversation={(ev) => shareConversation(ev.detail.id, ev.detail.title)}
on:deleteConversation={(ev) => deleteConversation(ev.detail)}
on:editConversationTitle={(ev) => editConversationTitle(ev.detail.id, ev.detail.title)}
/>
</nav>
{#if currentError}
<Toast message={currentError} />
{/if}
<slot />
</div>
{:else}
<div
class="grid h-full w-screen grid-cols-1 grid-rows-[auto,1fr] overflow-hidden text-smd dark:text-gray-300"
>
<slot />
</div>
{/if}
13 changes: 12 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
body: JSON.stringify({
model,
preprompt: $settings.customPrompts[$settings.activeModel],
assistantId: data.assistant?._id,
assistantId: data.embeddedAssistantId ?? data.assistant?._id,
// todo: embeddedAssistantId should be an actual field so that it can check
}),
});
Expand All @@ -63,6 +64,16 @@
files,
});
// embedded assistant
if (data.embeddedAssistantId) {
await goto(
`${base}/conversation/${conversationId}/?embeddedAssistantId=${encodeURIComponent(
data.embeddedAssistantId
)}`
);
return;
}
// invalidateAll to update list of conversations
await goto(`${base}/conversation/${conversationId}`, { invalidateAll: true });
} catch (err) {
Expand Down
Loading

0 comments on commit fb52674

Please sign in to comment.