Skip to content

Build your personal knowledge base with Trilium Notes

feat(ckeditor): round out the AI quick actions and split the colliding ones

Elian Doranafe018d816f2
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 0289e69a4b..a67236815a 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2837,20 +2837,29 @@
"group_edit": "Edit or review",
"group_generate": "Generate",
"group_tone": "Change tone",
+ "group_reformat": "Reformat",
"group_translate": "Translate",
"command_tone": "Change tone to {{tone}}",
"command_translate": "Translate to {{language}}",
+ "command_bullet_list": "Turn into a bullet list",
+ "command_table": "Turn into a table",
+ "command_action_items": "Extract action items",
"action_fix_typos": "Fix typos",
"action_improve_writing": "Improve writing",
"action_make_shorter": "Make shorter",
"action_make_longer": "Make longer",
"action_simplify": "Simplify language",
"action_summarize": "Summarize",
+ "action_explain": "Explain",
"action_continue": "Continue writing",
+ "action_bullet_list": "Bullet list",
+ "action_table": "Table",
+ "action_action_items": "Action items",
"tone_professional": "Professional",
"tone_casual": "Casual",
"tone_direct": "Direct",
"tone_friendly": "Friendly",
+ "tone_confident": "Confident",
"lang_english": "English",
"lang_german": "German",
"lang_spanish": "Spanish",
diff --git a/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.spec.ts b/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.spec.ts
index 104f7e7bd8..973d7f6df8 100644
--- a/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.spec.ts
@@ -104,6 +104,38 @@ describe("buildAiAssistantQuickActions", () => {
expect(romanian?.prompt).toBe("Translate the content to Romanian.");
});
+ it("gives each reformat its own command label rather than composing one", () => {
+ // "Turn into a table" against "Extract action items": no single phrase composes both.
+ expect(actions("reformat").map((action) => [action.label, action.commandLabel])).toEqual([
+ ["ai_assistant.action_bullet_list", "ai_assistant.command_bullet_list"],
+ ["ai_assistant.action_table", "ai_assistant.command_table"],
+ ["ai_assistant.action_action_items", "ai_assistant.command_action_items"]
+ ]);
+ });
+
+ // Two entries one click apart must not carry the same instruction, or the menu offers the same
+ // rewrite twice under different names.
+ it("keeps the length actions and the tones from asking for the same thing", () => {
+ const promptOf = (groupId: string, id: string) =>
+ actions(groupId).find((action) => action.id === id)?.prompt ?? "";
+
+ // The direct tone is about voice, not length — length belongs to Make shorter.
+ expect(promptOf("tone", "direct")).toContain("active voice");
+ expect(promptOf("tone", "direct")).not.toMatch(/shorten|essential information|non-essential/i);
+
+ // Improve writing leaves the mechanics to Fix typos and the length to Make shorter.
+ expect(promptOf("edit", "improveWriting")).not.toMatch(/mistakes|tighten/i);
+ expect(promptOf("edit", "fixTypos")).toMatch(/spelling, grammar and punctuation/i);
+ });
+
+ it("inlines the groups whose actions already read as commands", () => {
+ const groups = buildAiAssistantQuickActions();
+ expect(groups.filter((group) => group.submenu).map((group) => group.id))
+ .toEqual(["tone", "reformat", "translate"]);
+ expect(groups.filter((group) => !group.submenu).map((group) => group.id))
+ .toEqual(["edit", "generate"]);
+ });
+
it("leaves the labels that already read as commands alone", () => {
for (const action of [ ...actions("edit"), ...actions("generate") ]) {
expect(action.commandLabel).toBeUndefined();
diff --git a/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.ts b/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.ts
index 6834638401..2223fa3060 100644
--- a/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.ts
+++ b/apps/client/src/widgets/type_widgets/text/ai_assistant_stream.ts
@@ -73,8 +73,10 @@ export function buildAiAssistantQuickActions(): AiQuickActionGroup[] {
actions: [
action("fixTypos", t("ai_assistant.action_fix_typos"),
"Fix all spelling, grammar and punctuation mistakes. Do not change the meaning, tone or formatting."),
+ // Deliberately not "fix mistakes and tighten the phrasing": that made this the same
+ // instruction as Fix typos and Make shorter, which are one click away either side.
action("improveWriting", t("ai_assistant.action_improve_writing"),
- "Improve the writing: fix mistakes, tighten the phrasing and apply good writing practices without changing the meaning."),
+ "Improve the clarity, flow and word choice of this content, keeping its meaning and roughly its length."),
action("makeShorter", t("ai_assistant.action_make_shorter"),
"Shorten this content by removing repetition and non-essential details, without losing key information."),
action("makeLonger", t("ai_assistant.action_make_longer"),
@@ -89,6 +91,8 @@ export function buildAiAssistantQuickActions(): AiQuickActionGroup[] {
actions: [
action("summarize", t("ai_assistant.action_summarize"),
"Summarize this content into one short paragraph containing only the key ideas and conclusions."),
+ action("explain", t("ai_assistant.action_explain"),
+ "Explain this content in plain language: what it says, and what it means for someone unfamiliar with it. Keep the explanation brief."),
action("continue", t("ai_assistant.action_continue"),
"Continue writing from the end of the provided content, staying on topic and matching its style. Keep the continuation brief.")
]
@@ -102,10 +106,29 @@ export function buildAiAssistantQuickActions(): AiQuickActionGroup[] {
"Rewrite this content in a polished, formal, professional tone without changing the meaning."),
toneAction("casual", t("ai_assistant.tone_casual"),
"Rewrite this content in a casual, conversational tone without changing the meaning."),
+ // A tone, not a length: "keeping only the essential information" made this Make
+ // shorter under another name.
toneAction("direct", t("ai_assistant.tone_direct"),
- "Rewrite this content in a direct tone, keeping only the essential information."),
+ "Rewrite this content in a direct tone: active voice, no hedging and no throat-clearing. Keep all of the information."),
toneAction("friendly", t("ai_assistant.tone_friendly"),
- "Rewrite this content in a warm, friendly tone without changing the meaning.")
+ "Rewrite this content in a warm, friendly tone without changing the meaning."),
+ toneAction("confident", t("ai_assistant.tone_confident"),
+ "Rewrite this content in a confident, assertive tone without changing the meaning.")
+ ]
+ },
+ {
+ id: "reformat",
+ label: t("ai_assistant.group_reformat"),
+ submenu: true,
+ actions: [
+ reformatAction("bulletList", t("ai_assistant.action_bullet_list"), t("ai_assistant.command_bullet_list"),
+ "Rewrite this content as a bulleted list, one point per item, without losing information."),
+ reformatAction("table", t("ai_assistant.action_table"), t("ai_assistant.command_table"),
+ "Reorganize this content into a table with a header row, choosing columns that fit what the content describes."),
+ // Kept to a plain list: the editor's task lists need CKEditor's own `todo-list`
+ // markup, which the system prompt does not describe to the model.
+ reformatAction("actionItems", t("ai_assistant.action_action_items"), t("ai_assistant.command_action_items"),
+ "Extract the action items from this content as a bulleted list, each one short and starting with a verb. Leave out anything that is not an action.")
]
},
{
@@ -144,6 +167,15 @@ function translateAction(id: string, language: string, prompt: string): AiQuickA
return { id, label: language, commandLabel: t("ai_assistant.command_translate", { language }), prompt };
}
+/**
+ * A reformat needs the same two labels as a tone or a language — a bare "Table" says nothing in the
+ * `/` palette — but its commands do not compose from a single phrase ("Turn into a table" against
+ * "Extract action items"), so each carries its own translated pair instead of a substitution.
+ */
+function reformatAction(id: string, label: string, commandLabel: string, prompt: string): AiQuickAction {
+ return { id, label, commandLabel, prompt };
+}
+
/**
* The assistant works HTML-in/HTML-out: the context is the selection's HTML and the response is
* committed through the editor's data pipeline, so anything but clean HTML (markdown, fences,