feat(ui): show the page context tag above the chat composer (#1854)
ci/woodpecker/pr/quality Pipeline was successful
Quality / check (pull_request) Successful in 4m23s

This commit is contained in:
sam committed 2026-11-12 22:57:21 +11:00
1 parent 864240fd61
commit 1c5915f521
2 files changed
+47 -5

No files matched your search

+12 -1
View File
@@ -15,6 +15,8 @@ import {
commandSelection,
commandSpecs,
addTaskTag,
clearPageTag,
pageTag,
composerText,
editQueued,
menuTrigger,
@@ -219,7 +221,16 @@ function onKeydown(event: KeyboardEvent): void {
</Tooltip>
</li>
</ul>
<ul v-if="taskTags.length" aria-label="Attached tasks" class="mb-2 flex flex-wrap gap-1">
<ul v-if="pageTag || taskTags.length" aria-label="Message context" class="mb-2 flex flex-wrap gap-1">
<li
v-if="pageTag"
class="flex max-w-full items-center gap-1 rounded-md border border-border bg-muted px-2 py-0.5 text-label"
>
<span class="truncate">{{ pageTag.label }}</span>
<Button variant="ghost" size="icon" class="size-5" aria-label="Remove page context" @click="clearPageTag"
><X
/></Button>
</li>
<li
v-for="tag in taskTags"
:key="tag.id"
+35 -4
View File
@@ -1,6 +1,7 @@
import { computed, onMounted, onUnmounted, ref, watch, type Ref } from "vue";
import { api } from "@/lib/api";
import { router } from "@/router";
import { randomUUID } from "@/lib/uuid";
import { channelID } from "./channel";
import { commandCompletions, detectTrigger, taskCompletions, type Completion, type Trigger } from "./commands";
@@ -335,7 +336,7 @@ async function sendCommand(
channel_id: channelID(),
source_id: randomUUID(),
text,
page: currentPage(),
page: sentPage(),
});
if (!response.body) throw new Error("the chat stream returned no body");
const reader = response.body.getReader();
@@ -631,9 +632,39 @@ export function moveCommandSelection(delta: number): void {
commandSelection.value = (commandSelection.value + delta + length) % length;
}
/** The page the operator asked from, so an answer can be about what they saw. */
/** The page the operator is on, without the hash the server never sees. */
function currentPage(): string {
return location.pathname + location.search || "/";
return router.currentRoute.value.fullPath.split("#")[0] || "/";
}
// The page whose tag the operator removed. Navigating elsewhere shows the tag
// again, so the dismissal never outlives the page it was made on.
const clearedPage = ref("");
watch(currentPage, () => {
clearedPage.value = "";
});
/** What the next message is about, named for the tag above the composer. */
export const pageTag = computed(() => {
const page = currentPage();
if (page === clearedPage.value) return null;
const route = router.currentRoute.value;
const label =
route.name === "task-detail"
? `Task #${route.params.id}`
: typeof route.meta.label === "string"
? route.meta.label
: page;
return { page, label };
});
export function clearPageTag(): void {
clearedPage.value = currentPage();
}
/** The page sent with a message: the tag's page, or none once it is cleared. */
function sentPage(): string | undefined {
return pageTag.value?.page;
}
export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
@@ -731,7 +762,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
channel_id: channelID(),
source_id: turn.sourceID,
text: turn.text,
page: currentPage(),
page: sentPage(),
voice: turn.voice,
},
{ signal: ctrl.signal },