Merge pull request 'feat(chat): page-aware suggested prompts beside the composer, sent on click (#1905, #1906)' (#1911) from feat/1905-1906-chat-suggestions into main
ci/woodpecker/push/deploy Pipeline failed
deploy / plan (push) Successful in 10s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
deploy / gate (push) Canceled after 3m40s

Reviewed-on: #1911
This commit was merged in pull request #1911.
This commit is contained in:
sam committed 2026-11-12 13:26:20 +00:00
commit ea64d84696
6 files changed
+233 -30

No files matched your search

+5
View File
@@ -9,6 +9,7 @@ import { cn } from "@/lib/utils";
import { Textarea } from "@/components/ui/textarea";
import { isExactCommand, replaceToken } from "./commands";
import ChatSlashPalette from "./ChatSlashPalette.vue";
import ChatSuggestions from "./ChatSuggestions.vue";
import {
closeCommandMenu,
commandMatches,
@@ -242,6 +243,10 @@ function onKeydown(event: KeyboardEvent): void {
/></Button>
</li>
</ul>
<!-- Beside the field, not in the empty transcript, so the prompts stay
reachable without scrolling up; hidden in the collapsed bar on a
phone-width screen, where the strip would crowd the field. -->
<ChatSuggestions :class="flat ? 'max-md:hidden' : ''" />
<div
:class="
cn(
+3 -24
View File
@@ -1,21 +1,11 @@
<script setup lang="ts">
import Logo from "@/components/topbar/Logo.vue";
import { Button } from "@/components/ui/button";
/**
* What the panel opens on before there is a conversation: an invitation, and
* three prompts that fill the composer. The text is handed up rather than
* typed into the composer here, because the composer owns its own focus.
* What the panel opens on before there is a conversation: the mark. The
* suggested prompts live beside the composer (ChatSuggestions), where they
* are reachable whether or not the transcript is empty.
*/
const emit = defineEmits<{ prompt: [text: string] }>();
// Prompts an operator might actually ask, rather than demonstrations of the
// feature.
const PROMPTS = [
"Summarise active tasks",
"Show running agents",
"Check system status",
];
</script>
<template>
@@ -23,16 +13,5 @@ const PROMPTS = [
<div aria-hidden="true" class="mb-3 flex justify-center">
<Logo :open="false" />
</div>
<div class="flex flex-wrap justify-center gap-2">
<Button
v-for="prompt in PROMPTS"
:key="prompt"
variant="outline"
size="sm"
@click="emit('prompt', prompt)"
>
{{ prompt }}
</Button>
</div>
</div>
</template>
+42
View File
@@ -0,0 +1,42 @@
<script setup lang="ts">
import { computed } from "vue";
import { useRoute } from "vue-router";
import { Button } from "@/components/ui/button";
import { sendMessage } from "./state";
import { suggestionsForRoute } from "./suggestions";
/**
* The suggested prompts for the page the operator is on, rendered beside the
* composer so they stay reachable with a conversation already open, without
* scrolling to the top of the transcript. 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.
*/
const route = useRoute();
const prompts = computed(() => suggestionsForRoute(route));
function send(prompt: string): void {
void sendMessage({ textOverride: prompt });
}
</script>
<template>
<div
v-if="prompts.length"
class="mb-2 flex flex-wrap gap-1.5"
role="group"
aria-label="Suggested prompts"
>
<Button
v-for="prompt in prompts"
:key="prompt"
variant="outline"
size="sm"
class="h-auto max-w-full whitespace-normal text-left"
@click="send(prompt)"
>
{{ prompt }}
</Button>
</div>
</template>
+1 -6
View File
@@ -37,8 +37,6 @@ import {
* that set scrollTop by hand would have no "reader scrolled away" state and no
* way back down, so MessageScroller owns this.
*/
const emit = defineEmits<{ prompt: [text: string] }>();
function parts(message: ChatMessage, index: number) {
const from = message.from ?? message.From ?? "";
// Anything this browser's composer did not send is Archie's answer.
@@ -114,10 +112,7 @@ const rows = computed(() => {
<Button variant="outline" size="sm" @click="selectSession(currentSession)">Retry</Button>
</div>
<ChatEmptyState
v-else-if="!bubbles.length && !streamingTurn"
@prompt="emit('prompt', $event)"
/>
<ChatEmptyState v-else-if="!bubbles.length && !streamingTurn" />
<template v-else>
<MessageScrollerItem
+103
View File
@@ -0,0 +1,103 @@
/**
* The suggested prompts shown beside the chat composer, keyed off the page
* the operator is on. The page identity is the same one the composer's page
* tag uses: the route's name, with the task id on a task detail page.
*
* Prompts are questions an operator would actually ask on that page, not
* demonstrations of the feature.
*/
/** The route as the page tag reads it; only these fields are consulted. */
export interface SuggestionRoute {
name?: unknown;
path?: string;
params?: Record<string, unknown>;
meta?: Record<string, unknown>;
}
/** The pages that get their own prompt set. */
export type SuggestionPage =
| "task"
| "tasks"
| "events"
| "workflows"
| "schedules"
| "settings"
| "default";
/** Which prompt set a route gets, by route name like the page tag's. */
export function suggestionPage(route: SuggestionRoute): SuggestionPage {
const name = typeof route.name === "string" ? route.name : "";
switch (name) {
case "task-detail":
return "task";
case "tasks":
return "tasks";
case "events":
return "events";
case "workflows":
return "workflows";
case "schedules":
case "org-schedules":
case "org-schedule-runs":
return "schedules";
default:
break;
}
const path = route.path ?? "";
if (route.meta?.settings === true || name.startsWith("settings-") || path.startsWith("/settings")) {
return "settings";
}
return "default";
}
/** The prompts for a route; a task page names the task it is open on. */
export function suggestionsForRoute(route: SuggestionRoute): string[] {
switch (suggestionPage(route)) {
case "task": {
const id = route.params?.id;
const ref = id === undefined || id === "" ? "this task" : `task #${String(id)}`;
return [
`What is ${ref} doing right now?`,
`Summarise what ${ref} did`,
`Which files did ${ref} change?`,
];
}
case "tasks":
return [
"Which tasks are waiting on me?",
"What failed in the last hour?",
"Show tasks that need review",
];
case "events":
return [
"Which events fired today?",
"Why didn't my last event start a workflow?",
"Show recent event deliveries",
];
case "workflows":
return [
"Which workflow ran most recently?",
"What did the last run change?",
"Which workflows failed recently?",
];
case "schedules":
return [
"When is the next scheduled run?",
"Did the last scheduled run succeed?",
"Which schedules are enabled?",
];
case "settings":
return [
"Which model is Archie using right now?",
"How do I connect a new repository?",
"Show recent access denials",
];
default:
return [
"Summarise active tasks",
"Show running agents",
"Check system status",
];
}
}
+79
View File
@@ -0,0 +1,79 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
suggestionPage,
suggestionsForRoute,
type SuggestionRoute,
} from "../src/chat/suggestions.ts";
// One route per page the prompts distinguish, in the shape the page tag reads.
const pages: Array<[SuggestionRoute, string]> = [
[{ name: "task-detail", path: "/tasks/42", params: { id: "42" } }, "task"],
[{ name: "tasks", path: "/tasks" }, "tasks"],
[{ name: "events", path: "/events" }, "events"],
[{ name: "workflows", path: "/workflows" }, "workflows"],
[{ name: "schedules", path: "/schedules" }, "schedules"],
[{ name: "org-schedules", path: "/org/schedules" }, "schedules"],
[{ name: "org-schedule-runs", path: "/org/schedules/7/runs", params: { id: "7" } }, "schedules"],
[{ name: "system-models", path: "/settings/models", meta: { settings: true, label: "Models" } }, "settings"],
[{ name: "settings-tools", path: "/settings/tools" }, "settings"],
[{ path: "/settings/secret-engines" }, "settings"],
[{ name: "dashboard", path: "/" }, "default"],
[{ name: "org-members", path: "/org/members" }, "default"],
[{ name: "not-found", path: "/nope" }, "default"],
[{}, "default"],
];
test("each page route resolves to its own prompt set", () => {
for (const [route, page] of pages) {
assert.equal(suggestionPage(route), page, JSON.stringify(route));
}
});
test("the prompts follow the page", () => {
const byPage = new Map<string, string[]>();
for (const [route, page] of pages) {
const prompts = suggestionsForRoute(route);
const seen = byPage.get(page);
if (seen) assert.deepEqual(prompts, seen, page);
else byPage.set(page, prompts);
}
const sets = [...byPage.values()];
for (let i = 0; i < sets.length; i++) {
for (let j = i + 1; j < sets.length; j++) {
assert.notDeepEqual(sets[i], sets[j], `pages ${[...byPage.keys()][i]} and ${[...byPage.keys()][j]} share a prompt set`);
}
}
});
test("every route yields distinct, well-formed prompts", () => {
for (const [route] of pages) {
const prompts = suggestionsForRoute(route);
assert.ok(prompts.length >= 2, JSON.stringify(route));
assert.equal(new Set(prompts).size, prompts.length, JSON.stringify(route));
for (const prompt of prompts) {
assert.ok(prompt.trim().length > 0, JSON.stringify(route));
assert.ok(!prompt.includes("undefined"), prompt);
}
}
});
test("a task page names the task it is open on", () => {
const withId = suggestionsForRoute({ name: "task-detail", path: "/tasks/42", params: { id: "42" } });
assert.ok(withId.some((prompt) => prompt.includes("#42")));
assert.ok(withId.every((prompt) => !prompt.includes("undefined")));
const withoutId = suggestionsForRoute({ name: "task-detail", path: "/tasks" });
assert.ok(withoutId.some((prompt) => prompt.includes("this task")));
assert.ok(withoutId.every((prompt) => !prompt.includes("#")));
});
test("settings is recognised by flag, by name and by path alike", () => {
const byFlag = suggestionsForRoute({ name: "system-status", path: "/settings/status", meta: { settings: true } });
const byName = suggestionsForRoute({ name: "settings-plugins", path: "/settings/plugins" });
const byPath = suggestionsForRoute({ path: "/settings/container-runtime" });
assert.deepEqual(byName, byFlag);
assert.deepEqual(byPath, byFlag);
assert.notDeepEqual(byFlag, suggestionsForRoute({ name: "dashboard", path: "/" }));
});