feat(ai): add select-all controls to skill picker
This commit is contained in:
1 parent
ee9f7cd77e
commit
46f7e95dc3
14 files changed
+158
-1
No files matched your search
@@ -643,6 +643,8 @@ const skillFailures = ref<ReadUserSkillFailure[]>([]);
|
||||
// vanished from discovery must keep a removable chip (prd.md:37) instead of
|
||||
// silently becoming an id the user can no longer drop.
|
||||
const selectedSkillChips = computed(() => buildSelectedSkillChips(selectedSkillIds.value, (id) => userSkillStore.metaFor(id)));
|
||||
const selectableSkillIds = computed(() => userSkillStore.groupedSkills.flatMap((group) => group.skills.map((skill) => skill.id)));
|
||||
const canSelectAllSkills = computed(() => !userSkillStore.isLoading && !userSkillStore.lastError && selectableSkillIds.value.some((id) => !selectedSkillIds.value.includes(id)));
|
||||
// Selector retry-on-open mirrors the template selector above.
|
||||
watch(showSkillSelector, (open) => {
|
||||
if (open) void userSkillStore.refresh(skillRootSettings());
|
||||
@@ -666,6 +668,17 @@ function toggleSkillSelected(id: string) {
|
||||
selectedSkillIds.value = selectedSkillIds.value.includes(id) ? selectedSkillIds.value.filter((skillId) => skillId !== id) : [...selectedSkillIds.value, id];
|
||||
}
|
||||
|
||||
function selectAllSkills() {
|
||||
if (!canSelectAllSkills.value) return;
|
||||
selectedSkillIds.value = [...new Set([...selectedSkillIds.value, ...selectableSkillIds.value])];
|
||||
skillFailures.value = [];
|
||||
}
|
||||
|
||||
function deselectAllSkills() {
|
||||
selectedSkillIds.value = [];
|
||||
skillFailures.value = [];
|
||||
}
|
||||
|
||||
function removeSelectedSkill(id: string) {
|
||||
selectedSkillIds.value = removeSkillIds(selectedSkillIds.value, [id]);
|
||||
skillFailures.value = [];
|
||||
@@ -6380,7 +6393,7 @@ async function openExternalUrl(url: string) {
|
||||
{{ t(group.source === "custom" ? "ai.skillsGroupCustom" : "ai.skillsGroupDefault") }}
|
||||
</div>
|
||||
<template v-for="skill in group.skills" :key="skill.id">
|
||||
<button type="button" class="flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-xs hover:bg-muted" @click="toggleSkillSelected(skill.id)">
|
||||
<button type="button" class="flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-xs hover:bg-muted" :aria-pressed="selectedSkillIds.includes(skill.id)" @click="toggleSkillSelected(skill.id)">
|
||||
<div class="flex h-4 w-4 shrink-0 items-center justify-center rounded-sm border" :class="selectedSkillIds.includes(skill.id) ? 'border-primary bg-primary text-primary-foreground' : ''">
|
||||
<Check v-if="selectedSkillIds.includes(skill.id)" class="h-3 w-3" />
|
||||
</div>
|
||||
@@ -6394,6 +6407,16 @@ async function openExternalUrl(url: string) {
|
||||
</template>
|
||||
</div>
|
||||
<div class="border-t mt-1 px-1 pt-1">
|
||||
<div class="flex gap-1">
|
||||
<button type="button" class="flex min-w-0 flex-1 items-center gap-2 rounded-sm px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-50" :disabled="!canSelectAllSkills" @click="selectAllSkills">
|
||||
<Check class="h-3 w-3 shrink-0" />
|
||||
{{ t("ai.skillsSelectAll") }}
|
||||
</button>
|
||||
<button type="button" class="flex min-w-0 flex-1 items-center gap-2 rounded-sm px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-50" :disabled="selectedSkillIds.length === 0" @click="deselectAllSkills">
|
||||
<X class="h-3 w-3 shrink-0" />
|
||||
{{ t("ai.skillsDeselectAll") }}
|
||||
</button>
|
||||
</div>
|
||||
<button type="button" class="flex w-full items-center gap-2 rounded-sm px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground" :disabled="userSkillStore.isLoading" @click="refreshSkills">
|
||||
<Loader2 v-if="userSkillStore.isLoading" class="h-3 w-3 animate-spin" />
|
||||
{{ t("ai.skillsRefresh") }}
|
||||
|
||||
@@ -21,8 +21,10 @@ import type { AiExternalContextRequest } from "@/lib/ai/aiExternalContext";
|
||||
import type { AiContext, AiRequestInput } from "@/lib/ai/ai";
|
||||
import { buildAgentRequest } from "@/lib/ai/ai";
|
||||
import { AI_SELECTION_CONTEXT_MAX_CHARS } from "@/lib/ai/aiAttachments";
|
||||
import type { UserSkillsListResult } from "@/types/userSkills";
|
||||
|
||||
const aiAssistantMountApi = vi.hoisted(() => ({
|
||||
listUserSkills: vi.fn<() => Promise<UserSkillsListResult>>(),
|
||||
conversations: [] as Array<Record<string, unknown>>,
|
||||
runAgentStream: undefined as undefined | ((onEvent: (event: { type: string; delta?: string }) => void) => Promise<string>),
|
||||
// #10058: the request the panel actually hands to the backend, and every
|
||||
@@ -74,6 +76,7 @@ vi.mock("@/lib/backend/api", async (importOriginal) => {
|
||||
return Promise.resolve();
|
||||
},
|
||||
readUserSkills: empty,
|
||||
listUserSkills: aiAssistantMountApi.listUserSkills,
|
||||
loadAiConfigs: empty,
|
||||
listPlugins: empty,
|
||||
loadPromptTemplates: empty,
|
||||
@@ -102,6 +105,7 @@ afterEach(() => {
|
||||
aiAssistantMountApi.runAgentStreamHistories = [];
|
||||
aiAssistantMountApi.savedConversations = [];
|
||||
aiAssistantMountApi.codeHighlighterDelayMs = 0;
|
||||
aiAssistantMountApi.listUserSkills.mockReset();
|
||||
while (cleanups.length) cleanups.pop()?.();
|
||||
});
|
||||
|
||||
@@ -155,6 +159,114 @@ async function mountPanel(aiConfigLoaded: boolean, connection?: ConnectionConfig
|
||||
}
|
||||
|
||||
describe("AiAssistant mount", () => {
|
||||
function skillButton(label: string): HTMLButtonElement {
|
||||
const button = [...document.querySelectorAll<HTMLButtonElement>("button")].find((item) => item.textContent?.trim() === label);
|
||||
expect(button, label).toBeDefined();
|
||||
return button!;
|
||||
}
|
||||
|
||||
const skillCatalog: UserSkillsListResult = {
|
||||
defaultRoot: {
|
||||
status: "ok",
|
||||
skills: [
|
||||
{ id: "d-one", name: "Default one", description: "" },
|
||||
{ id: "d-two", name: "Default two", description: "" },
|
||||
],
|
||||
},
|
||||
customRoot: { status: "ok", skills: [{ id: "c-one", name: "Custom one", description: "" }] },
|
||||
};
|
||||
|
||||
it("selects all discovered skills without duplicates and keeps unavailable selections removable after refresh", async () => {
|
||||
// happy-dom focus events can dismiss a newly teleported Reka popover.
|
||||
const focus = vi.spyOn(HTMLElement.prototype, "focus").mockImplementation(() => {});
|
||||
cleanups.push(() => focus.mockRestore());
|
||||
aiAssistantMountApi.listUserSkills.mockResolvedValue(skillCatalog);
|
||||
const { container, errors } = await mountPanel(true);
|
||||
container.querySelector<HTMLButtonElement>(".ai-skills-selector-trigger")!.click();
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
expect(aiAssistantMountApi.listUserSkills).toHaveBeenCalled();
|
||||
await vi.waitFor(() => expect(document.querySelectorAll('[data-slot="popover-content"] button[aria-pressed="false"]')).toHaveLength(3));
|
||||
|
||||
const count = () => container.querySelector(".ai-skills-selector-count")?.textContent?.trim();
|
||||
const selectAll = () => skillButton(i18n.global.t("ai.skillsSelectAll"));
|
||||
const clear = () => skillButton(i18n.global.t("ai.skillsDeselectAll"));
|
||||
expect(clear().disabled).toBe(true);
|
||||
skillButton("Default one").click();
|
||||
selectAll().click();
|
||||
await vi.waitFor(() => expect(count()).toBe("3"));
|
||||
expect(document.querySelectorAll('[data-slot="popover-content"] button[aria-pressed="true"]')).toHaveLength(3);
|
||||
expect(selectAll().disabled).toBe(true);
|
||||
selectAll().click();
|
||||
expect(count()).toBe("3");
|
||||
|
||||
skillButton("Default one").click();
|
||||
await vi.waitFor(() => expect(selectAll().disabled).toBe(false));
|
||||
selectAll().click();
|
||||
await vi.waitFor(() => expect(count()).toBe("3"));
|
||||
|
||||
aiAssistantMountApi.listUserSkills.mockResolvedValue({
|
||||
defaultRoot: {
|
||||
status: "ok",
|
||||
skills: [
|
||||
{ id: "d-two", name: "Default two", description: "" },
|
||||
{ id: "d-three", name: "Default three", description: "" },
|
||||
],
|
||||
},
|
||||
customRoot: null,
|
||||
});
|
||||
skillButton(i18n.global.t("ai.skillsRefresh")).click();
|
||||
await vi.waitFor(() => expect(selectAll().disabled).toBe(false));
|
||||
selectAll().click();
|
||||
await vi.waitFor(() => expect(count()).toBe("4"));
|
||||
expect(container.textContent).toContain("c-one");
|
||||
expect(container.textContent).toContain("d-one");
|
||||
|
||||
aiAssistantMountApi.listUserSkills.mockResolvedValue({ defaultRoot: { status: "missing", skills: [] }, customRoot: null });
|
||||
skillButton(i18n.global.t("ai.skillsRefresh")).click();
|
||||
await vi.waitFor(() => expect(document.body.textContent).toContain(i18n.global.t("ai.skillsEmpty")));
|
||||
expect(selectAll().disabled).toBe(true);
|
||||
expect(clear().disabled).toBe(false);
|
||||
clear().click();
|
||||
await vi.waitFor(() => expect(count()).toBeUndefined());
|
||||
expect(clear().disabled).toBe(true);
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
});
|
||||
|
||||
it("disables select-all during loading and errors but still allows clearing selected skills and retrying", async () => {
|
||||
const focus = vi.spyOn(HTMLElement.prototype, "focus").mockImplementation(() => {});
|
||||
cleanups.push(() => focus.mockRestore());
|
||||
aiAssistantMountApi.listUserSkills.mockResolvedValue(skillCatalog);
|
||||
const { container, errors } = await mountPanel(true);
|
||||
container.querySelector<HTMLButtonElement>(".ai-skills-selector-trigger")!.click();
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
const selectAll = () => skillButton(i18n.global.t("ai.skillsSelectAll"));
|
||||
await vi.waitFor(() => expect(selectAll().disabled).toBe(false));
|
||||
selectAll().click();
|
||||
await vi.waitFor(() => expect(container.querySelector(".ai-skills-selector-count")?.textContent).toBe("3"));
|
||||
|
||||
let rejectRefresh!: (error: Error) => void;
|
||||
aiAssistantMountApi.listUserSkills.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((_, reject) => {
|
||||
rejectRefresh = reject;
|
||||
}),
|
||||
);
|
||||
skillButton(i18n.global.t("ai.skillsRefresh")).click();
|
||||
await vi.waitFor(() => expect(selectAll().disabled).toBe(true));
|
||||
skillButton(i18n.global.t("ai.skillsDeselectAll")).click();
|
||||
await vi.waitFor(() => expect(container.querySelector(".ai-skills-selector-count")).toBeNull());
|
||||
rejectRefresh(new Error("QA catalog unavailable"));
|
||||
await vi.waitFor(() => expect(document.body.textContent).toContain(i18n.global.t("ai.skillsLoadError")));
|
||||
expect(selectAll().disabled).toBe(true);
|
||||
skillButton(i18n.global.t("ai.skillsRetry")).click();
|
||||
await vi.waitFor(() => expect(selectAll().disabled).toBe(false));
|
||||
selectAll().click();
|
||||
await vi.waitFor(() => expect(container.querySelector(".ai-skills-selector-count")?.textContent).toBe("3"));
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
});
|
||||
|
||||
it("applies custom typography to restored message content and the prompt only", async () => {
|
||||
aiAssistantMountApi.conversations = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user