Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: improve AI assistant behavior

tianma-if277ff7cafd23
diff --git a/apps/api/src/ai-service.test.mjs b/apps/api/src/ai-service.test.mjs
index 6cf48994..10e6b683 100644
--- a/apps/api/src/ai-service.test.mjs
+++ b/apps/api/src/ai-service.test.mjs
@@ -29,6 +29,9 @@ describe("AI model service", () => {
"simplify-language",
"summarize",
]);
+ expect(aiActionInstructions.summarize).toContain("genuinely condensed summary");
+ expect(aiActionInstructions.summarize).toContain("20–30% of the source length");
+ expect(aiActionInstructions.summarize).toContain("Do not reproduce long passages verbatim");
expect(aiActionInstructions["extract-todos"]).toContain("- [ ]");
expect(resolveAiGenerationSystemInstruction({ action: "change-tone", tone: "friendly" }))
.toContain("friendly tone");
diff --git a/apps/api/src/ai-service.ts b/apps/api/src/ai-service.ts
index 6a3303a5..dac1c182 100644
--- a/apps/api/src/ai-service.ts
+++ b/apps/api/src/ai-service.ts
@@ -328,7 +328,14 @@ export const testAiModel = async (config: {
});
export const aiActionInstructions: Record<Exclude<AiAction, "translate" | "change-tone" | "custom">, string> = {
- summarize: "Summarize the note clearly and concisely. Preserve its language. Return Markdown only.",
+ summarize: [
+ "Create a genuinely condensed summary of the note rather than rewriting, paraphrasing line by line, or echoing it.",
+ "Identify the central topic, main claims, essential conclusions, and actionable outcomes.",
+ "Omit repetition, rhetorical phrasing, examples, quotations, and minor details unless they are necessary to understand a key conclusion.",
+ "For a substantial note, target roughly 20–30% of the source length and use 3–7 concise Markdown bullet points; for a short note, use 1–3 concise sentences.",
+ "Do not reproduce long passages verbatim or add facts that are not present in the source.",
+ "Preserve the note's language and return only the summary in Markdown.",
+ ].join(" "),
"extract-key-points": "Extract the note's most important points as a concise Markdown bullet list. Preserve its language and do not add information that is not present in the note.",
"extract-todos": "Extract explicit or implied actionable tasks from the note as a Markdown task list using '- [ ]'. Preserve its language and do not invent tasks. If there are no actionable tasks, say so briefly in the note's language.",
"rewrite-proofread": "Rewrite and proofread the complete note. Correct spelling, grammar, punctuation, clarity, and structure without changing its meaning. Preserve its language and Markdown formatting. Return the complete revised note only.",
diff --git a/apps/mobile/src/components/LocalTiptapEditor.tsx b/apps/mobile/src/components/LocalTiptapEditor.tsx
index a3e29daa..934d2c7a 100644
--- a/apps/mobile/src/components/LocalTiptapEditor.tsx
+++ b/apps/mobile/src/components/LocalTiptapEditor.tsx
@@ -56,6 +56,7 @@ import {
isMobileImageUploadPlaceholderSource,
stripMobileImageUploadPlaceholders,
} from "../lib/mobile-image-upload-placeholder";
+import { getMobileAiSourceRange } from "../lib/mobile-ai-selection";
import { toProtectedResourceLoadPath } from "../lib/mobile-protected-resources";
type EditorDoc = TiptapDoc;
@@ -130,6 +131,7 @@ const ignoreAiRequest = async () => undefined;
type MobileAiSelection = {
from: number;
to: number;
+ wholeNote: boolean;
markdown: string;
documentFingerprint: string;
};
@@ -681,19 +683,21 @@ function LocalTiptapEditorImpl(props: LocalTiptapEditorProps) {
}, [editor]);
const openAiForSelection = useCallback(() => {
- if (isViewer || !editor || editor.isDestroyed || !onAiRequestRef.current) return;
- const { from, to, empty } = editor.state.selection;
- if (empty || from >= to) return;
+ if (isViewer || !editor || editor.isDestroyed || !onAiRequestRef.current) return false;
+ const sourceRange = getMobileAiSourceRange(editor.state.selection, editor.state.doc.content.size);
+ if (!sourceRange) return false;
+ const { from, to, wholeNote } = sourceRange;
const selectionDoc = getPersistableEditorDoc({
type: "doc",
content: editor.state.doc.slice(from, to).content.toJSON(),
} as EditorDoc, props.baseUrl);
const markdown = docToMarkdown(selectionDoc).trim();
- if (!markdown) return;
+ if (!markdown) return false;
setAiPanel({
selection: {
from,
to,
+ wholeNote,
markdown,
documentFingerprint: getAiDocumentFingerprint(getPersistableEditorDoc(editor.getJSON() as EditorDoc, props.baseUrl)),
},
@@ -708,6 +712,7 @@ function LocalTiptapEditorImpl(props: LocalTiptapEditorProps) {
requestId: null,
});
editor.commands.blur();
+ return true;
}, [editor, isViewer, props.baseUrl, props.locale]);
const closeAiPanel = useCallback(() => {
@@ -717,7 +722,11 @@ function LocalTiptapEditorImpl(props: LocalTiptapEditorProps) {
setAiPanel(null);
window.requestAnimationFrame(() => {
if (editor.isDestroyed) return;
- editor.chain().focus().setTextSelection({ from, to }).run();
+ if (aiPanel.selection.wholeNote) {
+ editor.chain().focus().selectAll().run();
+ } else {
+ editor.chain().focus().setTextSelection({ from, to }).run();
+ }
});
}, [aiPanel, editor]);
@@ -914,14 +923,13 @@ function LocalTiptapEditorImpl(props: LocalTiptapEditorProps) {
(activeEditor?.isActive("taskList") ? MOBILE_EDITOR_ACTIVE_FLAGS.taskList : 0) |
(activeEditor?.isActive("blockquote") ? MOBILE_EDITOR_ACTIVE_FLAGS.blockquote : 0),
});
- const hasAiSelection = useEditorState({
- editor,
- selector: ({ editor: activeEditor }) => Boolean(activeEditor && !activeEditor.state.selection.empty),
- });
-
const requestOpenAiForSelection = () => {
- if (hasAiSelection) {
- openAiForSelection();
+ if (openAiForSelection()) {
+ setAiSelectionHint(false);
+ if (aiSelectionHintTimerRef.current !== null) {
+ window.clearTimeout(aiSelectionHintTimerRef.current);
+ aiSelectionHintTimerRef.current = null;
+ }
return;
}
setAiSelectionHint(true);
@@ -993,7 +1001,7 @@ function LocalTiptapEditorImpl(props: LocalTiptapEditorProps) {
))}
{onAiRequestRef.current ? (
<button
- aria-label={props.locale === "en-US" ? "Use AI on selected text" : "用 AI 处理选中内容"}
+ aria-label={props.locale === "en-US" ? "Use AI on the note or selected text" : "用 AI 处理正文或选中内容"}
className="edgeever-ai-toolbar-button"
onClick={requestOpenAiForSelection}
onMouseDown={(event) => event.preventDefault()}
@@ -1008,7 +1016,7 @@ function LocalTiptapEditorImpl(props: LocalTiptapEditorProps) {
<EditorContent className="edgeever-editor-scroll" editor={editor} />
{aiSelectionHint ? (
<div aria-live="polite" className="edgeever-ai-selection-hint" role="status">
- {props.locale === "en-US" ? "Select text in the note first." : "请先在正文中选择一段文字。"}
+ {props.locale === "en-US" ? "Add some note content first." : "请先输入正文内容。"}
</div>
) : null}
{aiUndoFingerprint && !aiPanel ? (
@@ -1106,11 +1114,22 @@ const MobileSelectionAiPanel = ({
const replaceDisabled = panel.generating || !panel.output || !canReplaceAiSource(panel.action);
return (
- <section aria-label={english ? "AI selection assistant" : "AI 选区助手"} aria-modal="true" className="edgeever-ai-panel" role="dialog">
+ <section
+ aria-label={panel.selection.wholeNote
+ ? (english ? "AI whole-note assistant" : "AI 全文助手")
+ : (english ? "AI selection assistant" : "AI 选区助手")}
+ aria-modal="true"
+ className="edgeever-ai-panel"
+ role="dialog"
+ >
<header className="edgeever-ai-panel-header">
<div>
- <strong>{english ? "AI selection assistant" : "AI 选区助手"}</strong>
- <small>{english ? "Only the selected text will be processed." : "只处理当前选中的正文。"}</small>
+ <strong>{panel.selection.wholeNote
+ ? (english ? "AI whole-note assistant" : "AI 全文助手")
+ : (english ? "AI selection assistant" : "AI 选区助手")}</strong>
+ <small>{panel.selection.wholeNote
+ ? (english ? "No text selected; the whole note will be processed." : "未选择文字,将处理整篇正文。")
+ : (english ? "Only the selected text will be processed." : "只处理当前选中的正文。")}</small>
</div>
<button aria-label={english ? "Close" : "关闭"} onClick={onClose} type="button">×</button>
</header>
@@ -2218,7 +2237,7 @@ const getEditorStyles = (theme: "light" | "dark", options?: { viewer?: boolean }
.edgeever-ai-panel select:focus, .edgeever-ai-panel input:focus, .edgeever-ai-panel textarea:focus { border-color: #16a06e; box-shadow: 0 0 0 2px rgb(22 160 110 / 14%); }
.edgeever-ai-result-heading { display: flex; align-items: center; justify-content: space-between; color: ${theme === "dark" ? "#e2e8f0" : "#334155"}; font-size: 13px; font-weight: 750; }
.edgeever-ai-result-heading small { color: #16a06e; }
- .edgeever-ai-result { min-height: 170px; padding: 12px; border: 1px solid ${theme === "dark" ? "#334155" : "#dbe4df"}; border-radius: 10px; background: ${theme === "dark" ? "#17251f" : "#fff"}; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55; }
+ .edgeever-ai-result { min-height: 170px; max-height: min(42vh, 360px); overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 12px; border: 1px solid ${theme === "dark" ? "#334155" : "#dbe4df"}; border-radius: 10px; background: ${theme === "dark" ? "#17251f" : "#fff"}; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55; }
.edgeever-ai-result > span { color: ${theme === "dark" ? "#94a3b8" : "#64748b"}; }
.edgeever-ai-refine-row { display: flex; gap: 8px; }
.edgeever-ai-refine-row input { min-width: 0; flex: 1; }
diff --git a/apps/mobile/src/lib/mobile-ai-selection.test.ts b/apps/mobile/src/lib/mobile-ai-selection.test.ts
index 37db3098..4fd1e755 100644
--- a/apps/mobile/src/lib/mobile-ai-selection.test.ts
+++ b/apps/mobile/src/lib/mobile-ai-selection.test.ts
@@ -1,7 +1,20 @@
import { describe, expect, test } from "bun:test";
-import { buildMobileAiStreamBridgePayload, parseMobileSelectionAiRequest } from "./mobile-ai-selection";
+import { buildMobileAiStreamBridgePayload, getMobileAiSourceRange, parseMobileSelectionAiRequest } from "./mobile-ai-selection";
describe("mobile AI selection bridge", () => {
+ test("uses the selected range when text is selected and the whole note otherwise", () => {
+ expect(getMobileAiSourceRange({ from: 4, to: 12, empty: false }, 20)).toEqual({
+ from: 4,
+ to: 12,
+ wholeNote: false,
+ });
+ expect(getMobileAiSourceRange({ from: 8, to: 8, empty: true }, 20)).toEqual({
+ from: 0,
+ to: 20,
+ wholeNote: true,
+ });
+ });
+
test("accepts semantic selection actions and normalized options", () => {
expect(parseMobileSelectionAiRequest(JSON.stringify({
requestId: "request-1",
diff --git a/apps/mobile/src/lib/mobile-ai-selection.ts b/apps/mobile/src/lib/mobile-ai-selection.ts
index 137ad05c..47e19471 100644
--- a/apps/mobile/src/lib/mobile-ai-selection.ts
+++ b/apps/mobile/src/lib/mobile-ai-selection.ts
@@ -15,6 +15,26 @@ export type MobileSelectionAiRequest = {
instruction?: string;
};
+export type MobileAiSourceRange = {
+ from: number;
+ to: number;
+ wholeNote: boolean;
+};
+
+export const getMobileAiSourceRange = (
+ selection: { from: number; to: number; empty: boolean },
+ documentSize: number,
+): MobileAiSourceRange | null => {
+ if (!Number.isInteger(documentSize) || documentSize <= 0) return null;
+ if (selection.empty || selection.from >= selection.to) {
+ return { from: 0, to: documentSize, wholeNote: true };
+ }
+ const from = Math.max(0, Math.min(selection.from, documentSize));
+ const to = Math.max(from, Math.min(selection.to, documentSize));
+ if (from >= to) return null;
+ return { from, to, wholeNote: from === 0 && to === documentSize };
+};
+
export const parseMobileSelectionAiRequest = (requestJson: string): MobileSelectionAiRequest | null => {
try {
const raw = JSON.parse(requestJson) as Record<string, unknown>;
diff --git a/apps/web/src/components/MemoListPane.tsx b/apps/web/src/components/MemoListPane.tsx
index 4a5466b2..cfdd3ccc 100644
--- a/apps/web/src/components/MemoListPane.tsx
+++ b/apps/web/src/components/MemoListPane.tsx
@@ -44,6 +44,7 @@ import {
FileCode2,
Printer,
Pencil,
+ Copy,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
@@ -71,6 +72,7 @@ import type {
import { contentEnterMotion, paneEnterMotion } from "@/lib/motion";
import type { SyncQueueSummary } from "@/lib/sync-queue";
import { isLocalMemoId } from "@/lib/local-mirror";
+import { copyTextToClipboard } from "@/lib/clipboard";
import {
getMemoFilterOptions,
getMemoSortOptions,
@@ -465,6 +467,7 @@ export const MemoListPane = ({
const [listDensity, setListDensity] = useState<MemoListDensity>(() => readMemoListDensityPreference());
const [lastSelectedMemoId, setLastSelectedMemoId] = useState<string | null>(null);
const [moveTargetNotebookId, setMoveTargetNotebookId] = useState("");
+ const [memoIdCopyNotice, setMemoIdCopyNotice] = useState<{ status: "copied" | "error"; id: string } | null>(null);
const filterOptions = useMemo(() => getMemoFilterOptions(t), [t]);
const memoSortOptions = useMemo(() => getMemoSortOptions(t), [t]);
@@ -544,6 +547,15 @@ export const MemoListPane = ({
onRequestDocumentAction(memo.id, action, printWindow);
};
+ const handleCopyContextMemoId = async () => {
+ const memo = memoContextMenu?.memo;
+ if (!memo || isLocalMemoId(memo.id)) return;
+ setMemoContextMenu(null);
+ const copied = await copyTextToClipboard(memo.id);
+ setMemoIdCopyNotice({ status: copied ? "copied" : "error", id: memo.id });
+ window.setTimeout(() => setMemoIdCopyNotice(null), copied ? 2200 : 3000);
+ };
+
useEffect(() => {
if (notebook?.id) {
setMoveTargetNotebookId(notebook.id);
@@ -760,7 +772,7 @@ export const MemoListPane = ({
// Keep enough room for the full action list. Radix can still adjust the
// final position, but this prevents the initial placement from starting
// below the viewport on short or zoomed desktop viewports.
- const menuHeight = view === "trash" ? 180 : 320;
+ const menuHeight = view === "trash" ? 216 : 356;
const x = Math.min(clientX, Math.max(12, window.innerWidth - menuWidth - 12));
const y = Math.min(clientY, Math.max(12, window.innerHeight - menuHeight - 12));
@@ -1461,6 +1473,14 @@ export const MemoListPane = ({
{memoContextMenu.memo.isPinned ? t("memoList.unpin") : t("memoList.pinMemo")}
</DropdownMenuItem>
)}
+ <DropdownMenuItem
+ className="flex h-9 w-full items-center gap-2 px-3 text-left text-sm text-slate-700 hover:bg-slate-50 cursor-pointer outline-none"
+ disabled={isLocalMemoId(memoContextMenu.memo.id)}
+ onClick={() => void handleCopyContextMemoId()}
+ >
+ <Copy className="h-4 w-4 text-slate-500" />
+ {t(isLocalMemoId(memoContextMenu.memo.id) ? "editor.copyNoteIdAfterSync" : "editor.copyNoteId")}
+ </DropdownMenuItem>
<DropdownMenuSeparator className="my-1 h-px bg-slate-100" />
{view === "trash" ? (
<>
@@ -1579,6 +1599,18 @@ export const MemoListPane = ({
</div>
)}
+ {memoIdCopyNotice && (
+ <div
+ className={cn(
+ "fixed bottom-5 left-1/2 z-[120] max-w-[calc(100vw-2rem)] -translate-x-1/2 truncate rounded-md px-3 py-2 text-sm font-medium text-white shadow-lg",
+ memoIdCopyNotice.status === "copied" ? "bg-emerald-700" : "bg-rose-600",
+ )}
+ role={memoIdCopyNotice.status === "copied" ? "status" : "alert"}
+ >
+ {t(memoIdCopyNotice.status === "copied" ? "editor.noteIdCopied" : "editor.noteIdCopyFailed", { id: memoIdCopyNotice.id })}
+ </div>
+ )}
+
{selectionMode && (
<MobileSelectionActionBar
canDelete={selectedMemoIds.size > 0 && !isDeleting}