The suggestion strip moves out of the empty transcript into the composer,
above the field, so prompts stay reachable without scrolling to the top and
show in the collapsed bar where there is room (hidden below the md breakpoint
in the collapsed bar, wrapping when expanded on a phone). Clicking a prompt
calls sendMessage({ textOverride }), which sends at once while no turn runs
instead of filling the composer. Prompt sets are keyed off the current route
name, the same identity the page tag uses: task detail (naming the open task),
tasks, events, workflows, schedules, settings, and a default set. The empty
transcript keeps its logo and no longer owns the fixed prompt list; the dead
prompt re-emit in ChatTranscript is removed.
80 lines
3.4 KiB
TypeScript
80 lines
3.4 KiB
TypeScript
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: "/" }));
|
|
});
|