feat(ai): add plugin recommendations and agent context
This commit is contained in:
43 files changed
+1210
-118
No files matched your search
+28
@@ -31,6 +31,34 @@ function bodyOf(fnSignature: string): string {
|
||||
}
|
||||
|
||||
describe("AI conversation owns its connection binding (#9902)", () => {
|
||||
it("renders plugin recommendation chips and sends the selected snapshot immediately", () => {
|
||||
expect(source).toContain("pluginRecommendations?: PluginAiRecommendationHostUpdate");
|
||||
expect(source).toContain('v-for="recommendation in pluginRecommendations.items"');
|
||||
expect(source).toContain('@click="sendPluginRecommendation(recommendation)"');
|
||||
expect(source).toContain("`history:${recommendation.id}`");
|
||||
const recommendationStart = source.indexOf("function sendPluginRecommendation(");
|
||||
expect(source.slice(recommendationStart, recommendationStart + 900)).toContain("send: true");
|
||||
expect(source.slice(recommendationStart, recommendationStart + 900)).toContain("context: update.context");
|
||||
});
|
||||
|
||||
it("keeps the connection selector available after a plugin recommendation is selected", () => {
|
||||
const contextStart = source.lastIndexOf("data-ai-composer-context-row");
|
||||
const contextEnd = source.indexOf("data-ai-composer-actions", contextStart);
|
||||
const contextMarkup = source.slice(contextStart, contextEnd);
|
||||
|
||||
expect(contextMarkup).toContain('v-if="pluginContext && !connectionStore.connections.length"');
|
||||
expect(contextMarkup).toContain("data-ai-plugin-context");
|
||||
expect(contextMarkup).toContain('v-if="connectionStore.connections.length"');
|
||||
expect(contextMarkup).toContain("<ConnectionTreeSelect");
|
||||
expect(contextMarkup).toContain('@update:model-value="(v) => changeConnection(v)"');
|
||||
});
|
||||
|
||||
it("does not expose Agent mode for a plugin conversation without a connection", () => {
|
||||
expect(source).toContain("function canUsePluginAgentMode");
|
||||
expect(source).toContain('if (mode === "agent" && !canUsePluginAgentMode()) return;');
|
||||
expect(source).toContain('request.mode === "agent" && !pluginConnection ? "ask"');
|
||||
});
|
||||
|
||||
it("rebinding the conversation never rewrites the editor tab or the global active connection", () => {
|
||||
const body = bodyOf("async function changeConnection(connectionId: string)");
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import AiAssistant from "@/components/editor/AiAssistant.vue";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
import type { PluginAiRecommendationHostUpdate } from "@/lib/plugins/pluginHostBridge";
|
||||
|
||||
vi.mock("@/lib/backend/api", async (importOriginal) => {
|
||||
const actual = await importOriginal<Record<string, unknown>>();
|
||||
@@ -38,10 +39,10 @@ afterEach(() => {
|
||||
while (cleanups.length) cleanups.pop()?.();
|
||||
});
|
||||
|
||||
async function mountPanel(aiConfigLoaded: boolean, connection?: ConnectionConfig, configureSettings?: (settings: ReturnType<typeof useSettingsStore>) => void) {
|
||||
async function mountPanel(aiConfigLoaded: boolean, connection?: ConnectionConfig, configureSettings?: (settings: ReturnType<typeof useSettingsStore>) => void, pluginRecommendations?: PluginAiRecommendationHostUpdate) {
|
||||
const pinia = createPinia();
|
||||
const errors: unknown[] = [];
|
||||
const app = createApp({ render: () => h(TooltipProvider, () => h(AiAssistant, { connection })) });
|
||||
const app = createApp({ render: () => h(TooltipProvider, () => h(AiAssistant, { connection, pluginRecommendations })) });
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.config.errorHandler = (error) => errors.push(error);
|
||||
@@ -63,6 +64,40 @@ async function mountPanel(aiConfigLoaded: boolean, connection?: ConnectionConfig
|
||||
}
|
||||
|
||||
describe("AiAssistant mount", () => {
|
||||
it("keeps the real Agent mode and an interactive picker after clicking a plugin recommendation", async () => {
|
||||
const { container, errors } = await mountPanel(
|
||||
true,
|
||||
{ id: "plugin-connection", name: "Sample", db_type: "plugin", plugin_id: "sample.plugin", host: "localhost", port: 22, username: "", password: "" },
|
||||
(settings) => {
|
||||
settings.defaultAiMode = "agent";
|
||||
},
|
||||
{
|
||||
pluginId: "sample.plugin",
|
||||
pluginName: "Sample",
|
||||
contributionId: "workbench",
|
||||
workbenchId: "cluster",
|
||||
context: { connectionId: "plugin-connection" },
|
||||
items: [{ id: "overview", label: "Inspect cluster", prompt: "Inspect cluster" }],
|
||||
},
|
||||
);
|
||||
expect(container.querySelector(".ai-mode-action-trigger")?.textContent).toContain(i18n.global.t("ai.modes.agent"));
|
||||
container.querySelector<HTMLButtonElement>('button[title="Inspect cluster"]')!.click();
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
const trigger = container.querySelector<HTMLButtonElement>(".ai-mode-action-trigger");
|
||||
expect(trigger).not.toBeNull();
|
||||
expect(trigger?.textContent).toContain(i18n.global.t("ai.modes.agent"));
|
||||
expect(container.querySelector(".ai-mode-static-trigger")).toBeNull();
|
||||
trigger!.click();
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
expect(trigger?.getAttribute("aria-expanded")).toBe("true");
|
||||
const askButton = Array.from(document.querySelectorAll<HTMLButtonElement>('[role="dialog"] button')).find((button) => button.textContent?.trim() === i18n.global.t("ai.modes.ask"));
|
||||
expect(askButton).toBeDefined();
|
||||
askButton!.click();
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
expect(trigger?.textContent).toContain(i18n.global.t("ai.modes.ask"));
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
});
|
||||
|
||||
it("opens when the AI config was loaded before the panel mounted", async () => {
|
||||
expect((await mountPanel(true)).errors.map(String)).toEqual([]);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user