1 parent
43ddfce93d
commit
e9998e2806
21 files changed
+563
-7
No files matched your search
@@ -66,6 +66,7 @@ import { useSavedSqlStore } from "@/stores/savedSqlStore";
|
||||
import { usePromptTemplateStore } from "@/stores/promptTemplateStore";
|
||||
import { useUserSkillStore } from "@/stores/userSkillStore";
|
||||
import { buildSelectedSkillChips, capSkillsToCharLimit, removeSkillIds, userSkillSourceOfId } from "@/lib/ai/userSkillSelection";
|
||||
import { aiConversationTypographyCssVariables } from "@/lib/ai/aiTypography";
|
||||
import { ACTIVE_SKILLS_TOTAL_MAX, type ReadUserSkill, type ReadUserSkillFailure, type UserSkillFailureReason, type UserSkillRootSettings } from "@/types/userSkills";
|
||||
import { supportsAiAssistantContext } from "@/lib/database/databaseFeatureSupport";
|
||||
import ConnectionIcon from "@/components/icons/ConnectionIcon.vue";
|
||||
@@ -210,6 +211,12 @@ const AiHtmlPreview = defineAsyncComponent({
|
||||
loader: () => import("@/components/ai/rich/AiHtmlPreview.vue"),
|
||||
});
|
||||
const settings = useSettingsStore();
|
||||
const aiTypographyStyle = computed(() =>
|
||||
aiConversationTypographyCssVariables({
|
||||
fontFamily: settings.editorSettings.aiFontFamily,
|
||||
fontSize: settings.editorSettings.aiFontSize,
|
||||
}),
|
||||
);
|
||||
const connectionStore = useConnectionStore();
|
||||
const savedSqlStore = useSavedSqlStore();
|
||||
const promptTemplateStore = usePromptTemplateStore();
|
||||
@@ -5419,7 +5426,7 @@ async function openExternalUrl(url: string) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="assistantRootRef" data-ai-assistant-root class="flex h-full min-h-0 flex-col overflow-hidden" @dragenter="onAttachmentDragEnter" @dragover="onAttachmentDragOver" @dragleave="onAttachmentDragLeave" @drop="onAttachmentDrop">
|
||||
<div ref="assistantRootRef" data-ai-assistant-root class="flex h-full min-h-0 flex-col overflow-hidden" :style="aiTypographyStyle" @dragenter="onAttachmentDragEnter" @dragover="onAttachmentDragOver" @dragleave="onAttachmentDragLeave" @drop="onAttachmentDrop">
|
||||
<div class="flex items-center gap-2 border-b px-3 shrink-0" :class="settings.editorSettings.appLayout === 'classic' ? 'h-9' : 'h-10'">
|
||||
<span class="flex flex-1 self-stretch items-center truncate text-xs font-medium" data-tauri-drag-region>
|
||||
{{ chatTitle }}
|
||||
@@ -5655,7 +5662,7 @@ async function openExternalUrl(url: string) {
|
||||
data-edit-textarea
|
||||
v-model="editingContent"
|
||||
rows="3"
|
||||
class="w-full resize-none rounded-lg border bg-background px-3 py-2 text-xs outline-none focus:ring-1 focus:ring-primary"
|
||||
class="ai-conversation-text w-full resize-none rounded-lg border bg-background px-3 py-2 text-xs outline-none focus:ring-1 focus:ring-primary"
|
||||
@keydown="onEditKeydown($event, i)"
|
||||
@compositionstart="editCompositionActive = true"
|
||||
@compositionend="editCompositionActive = false"
|
||||
@@ -5707,7 +5714,7 @@ async function openExternalUrl(url: string) {
|
||||
class="w-44"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="messageReferenceMentions(msg).length || msg.content" class="min-w-0 rounded-lg bg-primary px-3 py-2 text-xs text-primary-foreground">
|
||||
<div v-if="messageReferenceMentions(msg).length || msg.content" class="ai-conversation-text min-w-0 rounded-lg bg-primary px-3 py-2 text-xs text-primary-foreground">
|
||||
<div v-if="messageReferenceMentions(msg).length" class="mb-1.5 flex flex-wrap justify-end gap-1">
|
||||
<button
|
||||
v-for="mention in messageReferenceMentions(msg)"
|
||||
@@ -5777,7 +5784,7 @@ async function openExternalUrl(url: string) {
|
||||
|
||||
<!-- Keep the metadata row as wide as the reply card so its export action stays right-aligned. -->
|
||||
<div v-else-if="msg.content || msg.reasoning || msg.isThinking" class="flex w-full max-w-[95%] min-w-0 flex-col">
|
||||
<div class="w-full rounded-lg bg-muted px-3 py-2 text-xs leading-relaxed [overflow-wrap:anywhere]">
|
||||
<div data-ai-assistant-message-content class="ai-conversation-text w-full rounded-lg bg-muted px-3 py-2 text-xs leading-relaxed [overflow-wrap:anywhere]">
|
||||
<div v-if="msg.reasoning || msg.isThinking" class="mb-2">
|
||||
<button class="flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground transition-colors" @click="toggleReasoning()">
|
||||
<ChevronRight class="h-3 w-3 transition-transform duration-200" :class="{ 'rotate-90': reasoningExpanded }" />
|
||||
@@ -6330,7 +6337,7 @@ async function openExternalUrl(url: string) {
|
||||
ref="promptTextareaRef"
|
||||
v-model="prompt"
|
||||
:style="{ height: `${textareaHeight}px`, maxHeight: `${maxTextareaHeight()}px` }"
|
||||
class="w-full resize-none bg-transparent text-xs outline-none placeholder:text-muted-foreground mb-1"
|
||||
class="ai-conversation-text w-full resize-none bg-transparent text-xs outline-none placeholder:text-muted-foreground mb-1"
|
||||
:placeholder="activePlaceholder"
|
||||
@input="refreshMentionState"
|
||||
@click="refreshMentionState"
|
||||
@@ -6675,6 +6682,11 @@ async function openExternalUrl(url: string) {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ai-conversation-text {
|
||||
font-family: var(--dbx-ai-content-font-family, inherit);
|
||||
font-size: var(--dbx-ai-content-font-size, 0.75rem);
|
||||
}
|
||||
|
||||
.ai-prompt-context-row--compact .ai-prompt-context-spacer {
|
||||
flex: 0 0 0;
|
||||
}
|
||||
@@ -6791,7 +6803,7 @@ async function openExternalUrl(url: string) {
|
||||
border-radius: 0.25rem;
|
||||
background: var(--muted);
|
||||
padding: 0.125rem 0.375rem;
|
||||
font-size: 11px;
|
||||
font-size: var(--dbx-ai-inline-code-font-size, 11px);
|
||||
font-family: ui-monospace, monospace;
|
||||
}
|
||||
.ai-markdown :deep(pre) {
|
||||
@@ -6873,6 +6885,11 @@ html.dbx-legacy-webview.dark .ai-markdown :deep(.ai-markdown-table-wrap:hover::-
|
||||
min-height: 1lh;
|
||||
}
|
||||
|
||||
.ai-code-block {
|
||||
font-family: ui-monospace, monospace;
|
||||
font-size: var(--dbx-ai-code-font-size, 0.75rem);
|
||||
}
|
||||
|
||||
.ai-message-scroll :deep([data-slot="scroll-area-viewport"]) {
|
||||
overflow-anchor: none;
|
||||
}
|
||||
|
||||
@@ -271,6 +271,16 @@ import { useSavedSqlStore } from "@/stores/savedSqlStore";
|
||||
import { usePromptTemplateStore } from "@/stores/promptTemplateStore";
|
||||
import { useTunnelProfileStore } from "@/stores/tunnelProfileStore";
|
||||
import { currentLocale, previewLocale, restoreLocalePreview, setLocale, type Locale } from "@/i18n";
|
||||
import {
|
||||
AI_CONVERSATION_FONT_FAMILY_DEFAULT,
|
||||
AI_CONVERSATION_FONT_SIZE_DEFAULT,
|
||||
AI_CONVERSATION_FONT_SIZE_MAX,
|
||||
AI_CONVERSATION_FONT_SIZE_MIN,
|
||||
aiConversationFontFamilyForName,
|
||||
normalizeAiConversationFontFamily,
|
||||
normalizeAiConversationFontFamilyInput,
|
||||
normalizeAiConversationFontSize,
|
||||
} from "@/lib/ai/aiTypography";
|
||||
import {
|
||||
SETTINGS_SEARCH_DEFINITIONS,
|
||||
TOOLBAR_VISIBILITY_ITEMS,
|
||||
@@ -592,6 +602,9 @@ function createEmptyTableColumnTemplateRow(): TableColumnTemplateGridRow {
|
||||
// Local edit state
|
||||
const editFontFamily = ref(settingsStore.editorSettings.fontFamily);
|
||||
const editFontSize = ref(settingsStore.editorSettings.fontSize);
|
||||
const editAiFontFamily = ref(settingsStore.editorSettings.aiFontFamily);
|
||||
const editAiFontSize = ref<number | string>(settingsStore.editorSettings.aiFontSize);
|
||||
const aiTypographySaving = ref(false);
|
||||
const editTableFontFamily = ref(settingsStore.editorSettings.tableFontFamily);
|
||||
const editUiFontFamily = ref(settingsStore.editorSettings.uiFontFamily);
|
||||
const editUiScale = ref(settingsStore.editorSettings.uiScale);
|
||||
@@ -1589,6 +1602,12 @@ const systemFontOptions = computed(() => {
|
||||
|
||||
const tableFontOptions = computed(() => buildFontFamilyOptions(systemFonts.value, [editTableFontFamily.value], [DEFAULT_DATA_GRID_FONT_FAMILY]));
|
||||
|
||||
const aiFontOptions = computed(() => {
|
||||
const options = new Set([DEFAULT_UI_FONT_FAMILY, SYSTEM_UI_FONT_FAMILY, ...systemFonts.value.map(aiConversationFontFamilyForName)]);
|
||||
if (editAiFontFamily.value) options.add(editAiFontFamily.value);
|
||||
return [...options];
|
||||
});
|
||||
|
||||
const uiFontOptions = computed(() => {
|
||||
const options = new Set([SYSTEM_UI_FONT_FAMILY, DEFAULT_UI_FONT_FAMILY, ...systemFontOptions.value]);
|
||||
if (editUiFontFamily.value) options.add(editUiFontFamily.value);
|
||||
@@ -1601,6 +1620,11 @@ function displayUiFontFamily(value: string): string {
|
||||
return displayFontFamily(value);
|
||||
}
|
||||
|
||||
function displayAiFontFamily(value: string): string {
|
||||
if (!value) return t("ai.conversationFontFollowInterface");
|
||||
return displayUiFontFamily(value);
|
||||
}
|
||||
|
||||
function fontOptionStyle(value: string, selectedValue = editFontFamily.value) {
|
||||
return isPresetFontFamily(value) || uiFontPreviewValues.has(value) || value === selectedValue ? { fontFamily: value } : undefined;
|
||||
}
|
||||
@@ -1630,6 +1654,8 @@ const hasImportedSettingsPendingApply = ref(false);
|
||||
function syncEditorSettingsDraftFromStore() {
|
||||
editFontFamily.value = settingsStore.editorSettings.fontFamily;
|
||||
editFontSize.value = settingsStore.editorSettings.fontSize;
|
||||
editAiFontFamily.value = settingsStore.editorSettings.aiFontFamily;
|
||||
editAiFontSize.value = settingsStore.editorSettings.aiFontSize;
|
||||
editTableFontFamily.value = settingsStore.editorSettings.tableFontFamily;
|
||||
editUiFontFamily.value = settingsStore.editorSettings.uiFontFamily;
|
||||
editUiScale.value = settingsStore.editorSettings.uiScale;
|
||||
@@ -2716,6 +2742,44 @@ function onUiFontFamilyChange(v: any) {
|
||||
}
|
||||
}
|
||||
|
||||
async function persistAiTypography(partial: Partial<Pick<EditorSettings, "aiFontFamily" | "aiFontSize">>) {
|
||||
aiTypographySaving.value = true;
|
||||
try {
|
||||
await settingsStore.updateEditorSettingsAndPersist(partial);
|
||||
} catch (error) {
|
||||
applySettingsErrorToast(error);
|
||||
} finally {
|
||||
editAiFontFamily.value = settingsStore.editorSettings.aiFontFamily;
|
||||
editAiFontSize.value = settingsStore.editorSettings.aiFontSize;
|
||||
aiTypographySaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onAiFontFamilyChange(value: unknown) {
|
||||
const fontFamily = normalizeAiConversationFontFamily(value);
|
||||
editAiFontFamily.value = fontFamily;
|
||||
if (fontFamily !== settingsStore.editorSettings.aiFontFamily) void persistAiTypography({ aiFontFamily: fontFamily });
|
||||
}
|
||||
|
||||
function commitAiFontSize() {
|
||||
const fontSize = normalizeAiConversationFontSize(editAiFontSize.value);
|
||||
editAiFontSize.value = fontSize;
|
||||
if (fontSize !== settingsStore.editorSettings.aiFontSize) void persistAiTypography({ aiFontSize: fontSize });
|
||||
}
|
||||
|
||||
function blurAiFontSizeInput(event: KeyboardEvent) {
|
||||
(event.target as HTMLInputElement | null)?.blur();
|
||||
}
|
||||
|
||||
function resetAiTypography() {
|
||||
editAiFontFamily.value = AI_CONVERSATION_FONT_FAMILY_DEFAULT;
|
||||
editAiFontSize.value = AI_CONVERSATION_FONT_SIZE_DEFAULT;
|
||||
void persistAiTypography({
|
||||
aiFontFamily: AI_CONVERSATION_FONT_FAMILY_DEFAULT,
|
||||
aiFontSize: AI_CONVERSATION_FONT_SIZE_DEFAULT,
|
||||
});
|
||||
}
|
||||
|
||||
const themeSelectValue = computed(() => {
|
||||
if (editTheme.value === "custom") {
|
||||
return `custom:${editActiveCustomThemeId.value}`;
|
||||
@@ -3144,6 +3208,7 @@ async function revealSettingsSearchTarget(result: SettingsSearchEntry) {
|
||||
async function selectSettingsSearchResult(result: SettingsSearchEntry) {
|
||||
pendingSettingsSearchResult = result;
|
||||
if (result.shortcutId) shortcutSearchQuery.value = result.title;
|
||||
if (result.category === "ai") aiConfigListMode.value = "list";
|
||||
applySettingsSearchRoute(result);
|
||||
settingsSearchQuery.value = "";
|
||||
settingsSearchOpen.value = false;
|
||||
@@ -9241,6 +9306,80 @@ LIMIT 100;</pre
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="aiConfigListMode === 'list'" data-settings-search-id="ai-typography" class="space-y-3">
|
||||
<Separator />
|
||||
<div class="settings-item space-y-3 rounded-md border bg-muted/20 px-3 py-2">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="space-y-1">
|
||||
<h3 class="text-sm font-medium">{{ t("ai.conversationTypography") }}</h3>
|
||||
<p class="text-xs text-muted-foreground">{{ t("ai.conversationTypographyDescription") }}</p>
|
||||
</div>
|
||||
<Button type="button" size="sm" variant="ghost" class="h-7 shrink-0 gap-1 px-2 text-xs" :disabled="aiTypographySaving || (editAiFontFamily === AI_CONVERSATION_FONT_FAMILY_DEFAULT && Number(editAiFontSize) === AI_CONVERSATION_FONT_SIZE_DEFAULT)" @click="resetAiTypography">
|
||||
<RotateCcw class="h-3.5 w-3.5" />
|
||||
{{ t("settings.reset") }}
|
||||
</Button>
|
||||
</div>
|
||||
<div class="grid gap-3 sm:grid-cols-[minmax(0,1fr)_9rem]">
|
||||
<div class="min-w-0 space-y-1.5">
|
||||
<Label>{{ t("ai.conversationFontFamily") }}</Label>
|
||||
<SearchableSelect
|
||||
:model-value="editAiFontFamily"
|
||||
:options="aiFontOptions"
|
||||
:placeholder="t('ai.conversationFontFollowInterface')"
|
||||
:search-placeholder="t('settings.searchFont')"
|
||||
:empty-text="t('settings.noFontsFound')"
|
||||
:loading-text="t('settings.loadingFonts')"
|
||||
:disabled="aiTypographySaving"
|
||||
allow-custom
|
||||
clearable
|
||||
:display-name="displayAiFontFamily"
|
||||
:normalize-custom="normalizeAiConversationFontFamilyInput"
|
||||
:trigger-class="appearanceFontSearchTriggerClass"
|
||||
:trigger-icon-class="appearanceFontSearchTriggerIconClass"
|
||||
content-class="w-[var(--reka-popover-trigger-width)] min-w-[260px]"
|
||||
@update:model-value="onAiFontFamilyChange"
|
||||
@update:open="(open: boolean) => open && loadSystemFontOptions()"
|
||||
>
|
||||
<template #trigger-label="{ label, loading }">
|
||||
<span class="truncate" :style="editAiFontFamily ? { fontFamily: editAiFontFamily } : undefined">
|
||||
{{ loading ? t("settings.loadingFonts") : label }}
|
||||
</span>
|
||||
</template>
|
||||
<template #option-label="{ option, label }">
|
||||
<span class="truncate" :style="fontOptionStyle(option, editAiFontFamily)">{{ label }}</span>
|
||||
</template>
|
||||
<template #custom-option-label="{ value }">
|
||||
<span class="truncate" :style="{ fontFamily: value }">
|
||||
{{ t("settings.useCustomFont", { font: readableFontFamily(value) }) }}
|
||||
</span>
|
||||
</template>
|
||||
</SearchableSelect>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label for="ai-conversation-font-size">{{ t("ai.conversationFontSize") }}</Label>
|
||||
<div class="flex items-center gap-2">
|
||||
<Input
|
||||
id="ai-conversation-font-size"
|
||||
v-model.number="editAiFontSize"
|
||||
type="number"
|
||||
:min="AI_CONVERSATION_FONT_SIZE_MIN"
|
||||
:max="AI_CONVERSATION_FONT_SIZE_MAX"
|
||||
step="1"
|
||||
class="h-8 text-xs"
|
||||
:disabled="aiTypographySaving"
|
||||
@change="commitAiFontSize"
|
||||
@keydown.enter="blurAiFontSizeInput"
|
||||
/>
|
||||
<span class="text-xs text-muted-foreground">px</span>
|
||||
</div>
|
||||
<p class="text-[11px] text-muted-foreground">
|
||||
{{ t("ai.conversationFontSizeRange", { min: AI_CONVERSATION_FONT_SIZE_MIN, max: AI_CONVERSATION_FONT_SIZE_MAX }) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Agent Turn Limit (list mode, global) -->
|
||||
<div v-if="aiConfigListMode === 'list'" class="space-y-3">
|
||||
<Separator />
|
||||
|
||||
@@ -16,13 +16,30 @@ import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
import type { PluginAiRecommendationHostUpdate } from "@/lib/plugins/pluginHostBridge";
|
||||
|
||||
const aiAssistantMountApi = vi.hoisted(() => ({
|
||||
conversations: [] as Array<Record<string, unknown>>,
|
||||
runAgentStream: undefined as undefined | ((onEvent: (event: { type: string; delta?: string }) => void) => Promise<string>),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/ai/ai", async (importOriginal) => {
|
||||
const actual = await importOriginal<Record<string, unknown>>();
|
||||
return {
|
||||
...actual,
|
||||
runAgentStream: async (...args: unknown[]) => {
|
||||
const onEvent = args[2] as (event: { type: string; delta?: string }) => void;
|
||||
return aiAssistantMountApi.runAgentStream?.(onEvent) ?? "";
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@/lib/backend/api", async (importOriginal) => {
|
||||
const actual = await importOriginal<Record<string, unknown>>();
|
||||
const empty = () => Promise.resolve([]);
|
||||
return {
|
||||
...actual,
|
||||
loadAiConversations: empty,
|
||||
loadAiConversations: () => Promise.resolve(aiAssistantMountApi.conversations),
|
||||
loadAiRuns: empty,
|
||||
saveAiConversation: () => Promise.resolve(),
|
||||
readUserSkills: empty,
|
||||
loadAiConfigs: empty,
|
||||
listPlugins: empty,
|
||||
@@ -36,6 +53,8 @@ vi.mock("@/lib/backend/api", async (importOriginal) => {
|
||||
const cleanups: Array<() => void> = [];
|
||||
|
||||
afterEach(() => {
|
||||
aiAssistantMountApi.conversations = [];
|
||||
aiAssistantMountApi.runAgentStream = undefined;
|
||||
while (cleanups.length) cleanups.pop()?.();
|
||||
});
|
||||
|
||||
@@ -64,6 +83,104 @@ async function mountPanel(aiConfigLoaded: boolean, connection?: ConnectionConfig
|
||||
}
|
||||
|
||||
describe("AiAssistant mount", () => {
|
||||
it("applies custom typography to restored message content and the prompt only", async () => {
|
||||
aiAssistantMountApi.conversations = [
|
||||
{
|
||||
id: "typography-conversation",
|
||||
title: "Typography",
|
||||
connectionName: "",
|
||||
connectionId: "",
|
||||
database: "",
|
||||
messages: [
|
||||
{ role: "user", content: "User message" },
|
||||
{ role: "assistant", content: "### Heading\n\nInline `value`.\n\n```sql\nSELECT 1\n```" },
|
||||
],
|
||||
createdAt: "2026-09-27T00:00:00.000Z",
|
||||
updatedAt: "2026-09-27T00:00:00.000Z",
|
||||
},
|
||||
];
|
||||
|
||||
const { container, errors } = await mountPanel(true, undefined, (settings) => {
|
||||
settings.restoreLastConversation = true;
|
||||
settings.editorSettings.aiFontFamily = "Georgia, serif";
|
||||
settings.editorSettings.aiFontSize = 18;
|
||||
});
|
||||
|
||||
const root = container.querySelector<HTMLElement>("[data-ai-assistant-root]");
|
||||
expect(root?.style.getPropertyValue("--dbx-ai-content-font-family")).toBe("Georgia, serif");
|
||||
expect(root?.style.getPropertyValue("--dbx-ai-content-font-size")).toBe("18px");
|
||||
expect(root?.style.getPropertyValue("--dbx-ai-code-font-size")).toBe("18px");
|
||||
expect(container.querySelector("[data-ai-user-message-content]")?.closest(".ai-conversation-text")).not.toBeNull();
|
||||
expect(container.querySelector("[data-ai-assistant-message-content]")?.classList.contains("ai-conversation-text")).toBe(true);
|
||||
expect(container.querySelector(".ai-markdown code")).not.toBeNull();
|
||||
expect(container.querySelector(".ai-code-block")).not.toBeNull();
|
||||
expect(container.querySelector("textarea.ai-conversation-text")).not.toBeNull();
|
||||
expect(container.firstElementChild?.firstElementChild?.classList.contains("ai-conversation-text")).toBe(false);
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps the same typography scope while an answer streams and after it completes", async () => {
|
||||
let finishStream!: () => void;
|
||||
const streamPending = new Promise<void>((resolve) => {
|
||||
finishStream = resolve;
|
||||
});
|
||||
aiAssistantMountApi.runAgentStream = async (onEvent) => {
|
||||
onEvent({ type: "text_delta", delta: "**Streaming answer**" });
|
||||
await streamPending;
|
||||
onEvent({ type: "agent_end" });
|
||||
return "Streaming answer";
|
||||
};
|
||||
|
||||
const recommendation = {
|
||||
pluginId: "sample.plugin",
|
||||
pluginName: "Sample",
|
||||
contributionId: "workbench",
|
||||
workbenchId: "cluster",
|
||||
context: { connectionId: "plugin-connection" },
|
||||
items: [{ id: "stream", label: "Stream answer", prompt: "Stream answer" }],
|
||||
};
|
||||
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.aiConfigs = [
|
||||
{
|
||||
id: "custom",
|
||||
name: "Custom",
|
||||
provider: "openai-compatible",
|
||||
apiKey: "test-key",
|
||||
authMethod: "api-key",
|
||||
endpoint: "https://example.com/v1",
|
||||
model: "test-model",
|
||||
apiStyle: "completions",
|
||||
isDefault: true,
|
||||
},
|
||||
];
|
||||
settings.activeModel = { configId: "custom", modelId: "test-model" };
|
||||
settings.editorSettings.aiFontFamily = "Georgia, serif";
|
||||
settings.editorSettings.aiFontSize = 18;
|
||||
},
|
||||
recommendation,
|
||||
);
|
||||
|
||||
container.querySelector<HTMLButtonElement>('button[title="Stream answer"]')!.click();
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
|
||||
const streamingContent = container.querySelector<HTMLElement>("[data-ai-assistant-message-content]");
|
||||
expect(streamingContent?.classList.contains("ai-conversation-text")).toBe(true);
|
||||
expect(streamingContent?.textContent).toContain("Streaming answer");
|
||||
expect(container.querySelector("[data-ai-generation-status]")).not.toBeNull();
|
||||
|
||||
finishStream();
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
|
||||
const completedContent = container.querySelector<HTMLElement>("[data-ai-assistant-message-content]");
|
||||
expect(completedContent?.classList.contains("ai-conversation-text")).toBe(true);
|
||||
expect(completedContent?.textContent).toContain("Streaming answer");
|
||||
expect(container.querySelector("[data-ai-generation-status]")).toBeNull();
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps the real Agent mode and an interactive picker after clicking a plugin recommendation", async () => {
|
||||
const { container, errors } = await mountPanel(
|
||||
true,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import assistantSource from "../AiAssistant.vue?raw";
|
||||
|
||||
describe("AiAssistant typography scope", () => {
|
||||
it("uses one scoped content wrapper for streaming and completed Markdown", () => {
|
||||
expect(assistantSource).toContain("messageRenderer.value.render(msg.content, { streaming: isStreamingMessage(msg) })");
|
||||
expect(assistantSource).toContain('data-ai-assistant-message-content class="ai-conversation-text');
|
||||
expect(assistantSource).toContain('data-ai-user-message-content class="whitespace-pre-wrap"');
|
||||
});
|
||||
|
||||
it("scopes typography to message and input text while preserving monospace code", () => {
|
||||
expect(assistantSource).toContain('data-ai-assistant-root class="flex h-full min-h-0 flex-col overflow-hidden" :style="aiTypographyStyle"');
|
||||
expect(assistantSource).toContain('data-edit-textarea\n v-model="editingContent"');
|
||||
expect(assistantSource).toContain('class="ai-conversation-text w-full resize-none rounded-lg');
|
||||
expect(assistantSource).toContain('class="ai-conversation-text w-full resize-none bg-transparent');
|
||||
expect(assistantSource).toMatch(/\.ai-markdown :deep\(code\)[\s\S]*font-family: ui-monospace, monospace;/);
|
||||
expect(assistantSource).toMatch(/\.ai-code-block \{[\s\S]*font-family: ui-monospace, monospace;/);
|
||||
expect(assistantSource).not.toContain("document.body.style.fontFamily");
|
||||
});
|
||||
});
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { SETTINGS_SEARCH_DEFINITIONS } from "@/lib/settings/settingsSearch";
|
||||
import dialogSource from "../EditorSettingsDialog.vue?raw";
|
||||
|
||||
describe("EditorSettingsDialog AI typography settings", () => {
|
||||
it("exposes the family and size controls through settings search", () => {
|
||||
const definitions = SETTINGS_SEARCH_DEFINITIONS.filter((definition) => definition.id.startsWith("ai-conversation-font-"));
|
||||
|
||||
expect(definitions).toEqual([expect.objectContaining({ id: "ai-conversation-font-family", category: "ai", targetId: "ai-typography" }), expect.objectContaining({ id: "ai-conversation-font-size", category: "ai", targetId: "ai-typography" })]);
|
||||
expect(dialogSource).toContain('data-settings-search-id="ai-typography"');
|
||||
expect(dialogSource).toContain('id="ai-conversation-font-size"');
|
||||
});
|
||||
|
||||
it("persists each control immediately and offers a dedicated reset", () => {
|
||||
expect(dialogSource).toContain('@update:model-value="onAiFontFamilyChange"');
|
||||
expect(dialogSource).toContain('@change="commitAiFontSize"');
|
||||
expect(dialogSource).toContain('@click="resetAiTypography"');
|
||||
expect(dialogSource).toContain("settingsStore.updateEditorSettingsAndPersist(partial)");
|
||||
});
|
||||
|
||||
it("keeps system and custom conversation fonts independent from editor fallbacks", () => {
|
||||
expect(dialogSource).toContain("systemFonts.value.map(aiConversationFontFamilyForName)");
|
||||
expect(dialogSource).toContain(':normalize-custom="normalizeAiConversationFontFamilyInput"');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user