93 lines
3.3 KiB
Vue
93 lines
3.3 KiB
Vue
<script setup lang="ts">
|
|
import { ChevronDown, ChevronUp } from "@lucide/vue";
|
|
import { onUnmounted, ref, watch } from "vue";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import ChatBar from "./ChatBar.vue";
|
|
import ChatComposer from "./ChatComposer.vue";
|
|
import ChatTranscript from "./ChatTranscript.vue";
|
|
import { composerText, escapeOwnedByLayer, isSending, useChat } from "./state";
|
|
|
|
/**
|
|
* Chat is a bar docked at the bottom of every page, not a route: the operator
|
|
* asks Archie about the page they are already on, so navigating must not reset
|
|
* it, and it must not replace the work that prompted the question. The agent
|
|
* is told which page that is.
|
|
*
|
|
* It is the composer alone until the operator focuses it or a turn starts, then
|
|
* the conversation opens above it. Hiding the conversation leaves the bar. It is
|
|
* deliberately not a modal: no scrim, no scroll lock, no focus trap.
|
|
*
|
|
* It stays mounted, so the session and any turn in flight survive a navigation.
|
|
* It is mounted outside the app shell: `.shell`'s backdrop-filter makes it a
|
|
* containing block for `position: fixed`, so a bar nested inside would anchor to
|
|
* the shell and ride off the bottom of a long page.
|
|
*/
|
|
useChat();
|
|
|
|
const expanded = ref(false);
|
|
const composer = ref<InstanceType<typeof ChatComposer> | null>(null);
|
|
|
|
watch(isSending, (sending) => {
|
|
if (sending) expanded.value = true;
|
|
});
|
|
|
|
function onKeydown(event: KeyboardEvent): void {
|
|
// A focused control (the composer dismissing its palette, or the topbar
|
|
// search) already handled Escape via preventDefault; collapsing too would
|
|
// make that menu impossible to dismiss on its own. A popover portalled out
|
|
// of the bar owns Escape by being open, which the flag reports.
|
|
if (event.defaultPrevented || event.key !== "Escape" || escapeOwnedByLayer()) return;
|
|
expanded.value = false;
|
|
}
|
|
watch(expanded, (open) => {
|
|
if (open) document.addEventListener("keydown", onKeydown);
|
|
else document.removeEventListener("keydown", onKeydown);
|
|
});
|
|
onUnmounted(() => document.removeEventListener("keydown", onKeydown));
|
|
|
|
function usePrompt(text: string): void {
|
|
composerText.value = text;
|
|
composer.value?.focus();
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="pointer-events-none fixed inset-x-0 bottom-4 z-40 flex justify-center px-3 max-md:bottom-2">
|
|
<aside
|
|
aria-label="Chat with Archie"
|
|
class="pointer-events-auto flex w-full max-w-xl flex-col rounded-lg border bg-popover shadow-[var(--shadow-md)]"
|
|
>
|
|
<ChatBar v-if="expanded">
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
class="flex-none"
|
|
aria-label="Hide conversation"
|
|
title="Hide conversation"
|
|
@click="expanded = false"
|
|
>
|
|
<ChevronDown />
|
|
</Button>
|
|
</ChatBar>
|
|
<div v-if="expanded" class="flex h-[min(28rem,55dvh)] min-h-0 flex-col">
|
|
<ChatTranscript @prompt="usePrompt" />
|
|
</div>
|
|
<div class="relative" @focusin="expanded = true">
|
|
<ChatComposer ref="composer" :open="false" :class="!expanded && 'border-t-0!'" />
|
|
<Button
|
|
v-if="!expanded"
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
class="absolute top-1.5 right-1.5"
|
|
aria-label="Show conversation"
|
|
title="Show conversation"
|
|
@click="expanded = true"
|
|
>
|
|
<ChevronUp />
|
|
</Button>
|
|
</div>
|
|
</aside>
|
|
</div>
|
|
</template>
|