fix(ui): chat prompts hide until a model is connected and scroll as one row
This commit is contained in:
3 files changed
+31
-6
No files matched your search
@@ -3,7 +3,10 @@ import { computed } from "vue";
|
||||
|
||||
import { useAccountsStore } from "@/accounts/accounts";
|
||||
import Logo from "@/components/topbar/Logo.vue";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import ChatSuggestions from "./ChatSuggestions.vue";
|
||||
import { chatModelReady } from "./state";
|
||||
|
||||
/**
|
||||
* What the panel opens on before there is a conversation: the mark, a greeting
|
||||
@@ -23,6 +26,12 @@ const greeting = computed(() => {
|
||||
<Logo :open="false" class="text-[4rem]!" />
|
||||
</div>
|
||||
<h2 class="mb-5 text-center text-xl font-semibold tracking-tight">{{ greeting }}</h2>
|
||||
<ChatSuggestions list />
|
||||
<ChatSuggestions v-if="chatModelReady" list />
|
||||
<Alert v-else class="text-label">
|
||||
<AlertDescription class="flex flex-wrap items-center justify-between gap-2">
|
||||
No chat model connected.
|
||||
<Button as-child variant="outline" size="sm"><RouterLink to="/settings/models" class="no-underline">Choose a model</RouterLink></Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</div>
|
||||
</template>
|
||||
@@ -4,12 +4,13 @@ import { computed, onUnmounted } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { placeholderHint, sendMessage } from "./state";
|
||||
import { chatModelReady, placeholderHint, sendMessage } from "./state";
|
||||
import { suggestionsForRoute } from "./suggestions";
|
||||
|
||||
/**
|
||||
* The suggested prompts for the page the operator is on. The empty
|
||||
* conversation lists them (`list`); beside the composer they are chips. A click
|
||||
* conversation lists them (`list`); beside the composer they are a row of
|
||||
* chips that scrolls sideways. None show until a chat model is configured. A click
|
||||
* sends the prompt as its own message (sendMessage's textOverride path sends at
|
||||
* once while no turn runs) rather than filling the field, and resting on one
|
||||
* previews it as the composer's placeholder.
|
||||
@@ -17,7 +18,8 @@ import { suggestionsForRoute } from "./suggestions";
|
||||
defineProps<{ list?: boolean }>();
|
||||
|
||||
const route = useRoute();
|
||||
const prompts = computed(() => suggestionsForRoute(route));
|
||||
// No model, no prompts: one sent now could only fail.
|
||||
const prompts = computed(() => (chatModelReady.value ? suggestionsForRoute(route) : []));
|
||||
|
||||
function send(prompt: string): void {
|
||||
placeholderHint.value = "";
|
||||
@@ -26,6 +28,15 @@ function send(prompt: string): void {
|
||||
function preview(prompt: string): void {
|
||||
placeholderHint.value = prompt;
|
||||
}
|
||||
// A vertical wheel scrolls the row sideways; a trackpad's sideways swipe
|
||||
// already does.
|
||||
function scrollSideways(event: WheelEvent): void {
|
||||
if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
|
||||
const row = event.currentTarget as HTMLElement;
|
||||
if (row.scrollWidth <= row.clientWidth) return;
|
||||
event.preventDefault();
|
||||
row.scrollLeft += event.deltaY;
|
||||
}
|
||||
function clear(): void {
|
||||
placeholderHint.value = "";
|
||||
}
|
||||
@@ -51,18 +62,21 @@ onUnmounted(clear);
|
||||
</Button>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- One row that scrolls sideways, so the prompts never push the
|
||||
transcript up by more than a line. -->
|
||||
<div
|
||||
v-else-if="prompts.length"
|
||||
class="mb-2 flex flex-wrap gap-1.5"
|
||||
class="-mx-3 mb-2 flex snap-x snap-mandatory scroll-px-3 gap-1.5 overflow-x-auto px-3 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
|
||||
role="group"
|
||||
aria-label="Suggested prompts"
|
||||
@wheel="scrollSideways"
|
||||
>
|
||||
<Button
|
||||
v-for="prompt in prompts"
|
||||
:key="prompt"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="h-auto max-w-full whitespace-normal text-left"
|
||||
class="flex-none snap-start whitespace-nowrap"
|
||||
@click="send(prompt)"
|
||||
@pointerenter="preview(prompt)"
|
||||
@pointerleave="clear"
|
||||
|
||||
@@ -263,6 +263,8 @@ export const streamingTurn = ref<StreamingTurn | null>(null);
|
||||
|
||||
export const selectorData = ref<ChatSelectorData>({});
|
||||
export const selectedModel = ref("");
|
||||
/** Whether a chat model is configured, so a prompt sent now can be answered. */
|
||||
export const chatModelReady = computed(() => !!selectorData.value.active_model);
|
||||
|
||||
export const commandSpecs = ref<ChatCommandSpec[]>([]);
|
||||
export const commandMatches = ref<Completion[]>([]);
|
||||
|
||||
Reference in new issue
Block a user