AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(companion): require default model before enable
tianma-ifa076592076b4
diff --git a/apps/api/src/companion-routes.ts b/apps/api/src/companion-routes.tsindex 0ba59a76..0d8892cc 100644--- a/apps/api/src/companion-routes.ts+++ b/apps/api/src/companion-routes.ts@@ -38,8 +38,15 @@ export const registerCompanionRoutes = (parent: Hono<AppEnv>, dependencies: {app.get("/api/v1/companion/memories", async c => c.json({ memories: await listCompanionMemories(c.env.storage.db, scopeFor(c)) }));app.get("/api/v1/companion/discovery/settings", async c => c.json({ settings: await getDiscoverySettings(c.env.storage.db, scopeFor(c)) }));- app.put("/api/v1/companion/discovery/settings", zValidator("json", CompanionDiscoverySettingsInputSchema), async c =>- c.json({ settings: await saveDiscoverySettings(c.env.storage.db, scopeFor(c), c.req.valid("json")) }));+ app.put("/api/v1/companion/discovery/settings", zValidator("json", CompanionDiscoverySettingsInputSchema), async c => {+ const input = c.req.valid("json");+ // Validate the same default model used by an actual discovery check.+ // Turning Paw mode off must remain possible when a provider is unavailable.+ if (input.enabled) {+ await (dependencies.loadModel ?? loadDefaultAiModel)(c.env.storage.db, getWorkspaceId(c), c.env);+ }+ return c.json({ settings: await saveDiscoverySettings(c.env.storage.db, scopeFor(c), input) });+ });app.get("/api/v1/companion/discovery", async c => c.json({ items: await listDiscoveries(c.env.storage.db, scopeFor(c)) }));app.post("/api/v1/companion/discovery/check", async c => {const stop = new AbortController();diff --git a/apps/api/src/companion.test.mjs b/apps/api/src/companion.test.mjsindex 67f70b52..9876da05 100644--- a/apps/api/src/companion.test.mjs+++ b/apps/api/src/companion.test.mjs@@ -12,6 +12,7 @@ import { companionMessages, selectCompanionMemories, streamCompanion } from "./cimport { applyCompanionAction, proposeCompanionAction, listCompanionActions, dismissCompanionAction } from "./companion-actions.ts";import { createMemoRecord, getMemoDetail, updateMemoRecord } from "./memo-service.ts";import { COMPANION_MCP_TOOLS } from "./companion-tool-catalog.ts";+import { AppError } from "./app-error.ts";const databases = [];afterEach(() => { for (const db of databases.splice(0)) db.close(); });@@ -161,6 +162,26 @@ describe("companion organization proposals", () => {});describe("companion persistence and governance", () => {+ test("requires a usable default model to enable discovery but always allows disabling", async () => {+ let modelLoads = 0;+ const unavailable = fixture({ loadModel: async () => {+ modelLoads++;+ throw new AppError("ai_not_configured", "Choose a default AI model first.", 409);+ } });+ const disabled = await unavailable.request("discovery/settings", "PUT", { enabled: false, version: 0 });+ expect(disabled.status).toBe(200);+ expect(modelLoads).toBe(0);+ const rejected = await unavailable.request("discovery/settings", "PUT", { enabled: true, version: 1 });+ expect(rejected.status).toBe(409);+ expect(await rejected.json()).toMatchObject({ error: { code: "ai_not_configured" } });+ expect(modelLoads).toBe(1);++ const available = fixture({ loadModel: async () => { modelLoads++; return { modelId: "ready" }; } });+ const enabled = await available.request("discovery/settings", "PUT", { enabled: true, version: 0 });+ expect(enabled.status).toBe(200);+ expect((await enabled.json()).settings.enabled).toBe(true);+ expect(modelLoads).toBe(2);+ });test("stores, corrects, and forgets only within the owner/workspace pair", async () => {const { db } = fixture();const memory = await saveCompanionMemory(db, scope, { content: "Be concise" });diff --git a/apps/web/src/components/CompanionDiscoveryHub.test.mjs b/apps/web/src/components/CompanionDiscoveryHub.test.mjsindex 5514b1d0..f7ece139 100644--- a/apps/web/src/components/CompanionDiscoveryHub.test.mjs+++ b/apps/web/src/components/CompanionDiscoveryHub.test.mjs@@ -12,12 +12,14 @@ import Hub from "./CompanionDiscoveryHub.tsx";import { CompanionDiscoverySettingsCard } from "./settings/CompanionDiscoverySettingsCard.tsx";import { discoverySettingsKey, discoveryFeedKey } from "../hooks/useCompanionDiscovery.ts";-async function render(enabled, locale = "zh-CN", card = false, settings = {}, items = []) {+async function render(enabled, locale = "zh-CN", card = false, settings = {}, items = [], aiReady = true) {const client = new QueryClient({ defaultOptions: { queries: { gcTime: Infinity } } });client.setQueryData(discoverySettingsKey("test"), { enabled, version: 0, lastCheckAt: null, lastStatus: "quiet", ...settings });client.setQueryData(discoveryFeedKey("test"), items);+ client.setQueryData(["ai-settings", locale], { defaultModelId: aiReady ? "default" : null,+ providers: aiReady ? [{ isEnabled: true, models: [{ id: "default" }] }] : [], encryptionConfigured: true });const i18n = createInstance(); await i18n.init({ lng: locale, resources: { "zh-CN": { translation: zhCN }, "en-US": { translation: enUS } } });- const component = card ? createElement(CompanionDiscoverySettingsCard, { scope: "test", onOpenCompanion() {} })+ const component = card ? createElement(CompanionDiscoverySettingsCard, { scope: "test", onOpenCompanion() {}, onOpenAiSettings() {} }): createElement(Hub, { scope: "test", onOpenNote() {}, async onNotesChanged() {}, onOpenSettings() {} });const result = renderToStaticMarkup(createElement(I18nextProvider, { i18n }, createElement(QueryClientProvider, { client }, createElement(TooltipProvider, {}, component))));client.clear(); return result;@@ -58,6 +60,11 @@ describe("quiet discovery UI", () => {expect(html).toContain("最近发现"); expect(html).toContain("两个产品想法可以互相补充");expect(html).toContain("早期记录解释了新方案的取舍。"); expect(html).not.toContain("个性化偏好");});+ test("shows the AI model prerequisite before Paw mode can be enabled", async () => {+ const html = await render(false, "zh-CN", true, {}, [], false);+ expect(html).toContain("开启猫爪模式前,请先配置并启用默认 AI 模型。");+ expect(html).toContain("前往 AI 集成");+ });test("English settings have matching concise benefits and no raw translation keys", async () => {const html = await render(false, "en-US", true);expect(html).toContain("When enabled, EdgeEver quietly helps tuck scattered fragments together, append new ideas to existing notes, and surface relevant past insights like a gentle cat paw.");diff --git a/apps/web/src/components/SettingsPane.tsx b/apps/web/src/components/SettingsPane.tsxindex 6085aedd..426423b0 100644--- a/apps/web/src/components/SettingsPane.tsx+++ b/apps/web/src/components/SettingsPane.tsx@@ -237,7 +237,8 @@ export const SettingsPane = ({return (<SettingsGroup>{authRequired && user && !demoMode ? (- <CompanionDiscoverySettingsCard scope={companionScope} onOpenCompanion={onOpenCompanion} />+ <CompanionDiscoverySettingsCard scope={companionScope} onOpenCompanion={onOpenCompanion}+ onOpenAiSettings={() => setActiveTab("ai")} />) : (<Card className="shadow-none"><CardHeader className="p-4 sm:p-5">diff --git a/apps/web/src/components/settings/CompanionDiscoverySettingsCard.tsx b/apps/web/src/components/settings/CompanionDiscoverySettingsCard.tsxindex bc49328b..2d1274ba 100644--- a/apps/web/src/components/settings/CompanionDiscoverySettingsCard.tsx+++ b/apps/web/src/components/settings/CompanionDiscoverySettingsCard.tsx@@ -4,18 +4,23 @@ import { useTranslation } from "react-i18next";import { Sparkles, ShieldCheck, ChevronRight, Clock, Activity, MessageSquareText } from "lucide-react";import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/components/ui/card";import { Switch } from "@/components/ui/switch";-import { api } from "@/lib/api";+import { api, ApiRequestError } from "@/lib/api";import { discoveryFeedKey, discoverySettingsKey, useCompanionDiscoverySettings } from "@/hooks/useCompanionDiscovery";-export function CompanionDiscoverySettingsCard({ scope, onOpenCompanion }: {- scope: string; onOpenCompanion: () => void;+export function CompanionDiscoverySettingsCard({ scope, onOpenCompanion, onOpenAiSettings }: {+ scope: string; onOpenCompanion: () => void; onOpenAiSettings: () => void;}) {const { t, i18n } = useTranslation();const query = useCompanionDiscoverySettings(scope);const client = useQueryClient();const [busy, setBusy] = useState(false);- const [error, setError] = useState(false);+ const [error, setError] = useState<"settings" | "model" | null>(null);const settings = query.data;+ const locale = i18n.resolvedLanguage ?? i18n.language;+ const aiQuery = useQuery({ queryKey: ["ai-settings", locale], queryFn: () => api.getAiSettings(locale), staleTime: 60_000 });+ const aiSettings = aiQuery.data;+ const defaultModelReady = Boolean(aiSettings?.encryptionConfigured && aiSettings.providers.some(provider =>+ provider.isEnabled && provider.models.some(model => model.id === aiSettings.defaultModelId)));const enabled = settings?.enabled === true;const feed = useQuery({queryKey: discoveryFeedKey(scope),@@ -33,13 +38,19 @@ export function CompanionDiscoverySettingsCard({ scope, onOpenCompanion }: {const save = async (enabled: boolean) => {if (!settings || busy) return;setBusy(true);- setError(false);+ setError(null);try {+ if (enabled) {+ const current = aiSettings ?? (await aiQuery.refetch()).data;+ const ready = Boolean(current?.encryptionConfigured && current.providers.some(provider =>+ provider.isEnabled && provider.models.some(model => model.id === current.defaultModelId)));+ if (!ready) { setError("model"); return; }+ }const result = await api.saveCompanionDiscoverySettings({ enabled, version: settings.version });client.setQueryData(discoverySettingsKey(scope), result.settings);client.setQueryData(discoveryFeedKey(scope), []);- } catch {- setError(true);+ } catch (cause) {+ setError(cause instanceof ApiRequestError && cause.code?.startsWith("ai_") ? "model" : "settings");await query.refetch();} finally {setBusy(false);@@ -85,11 +96,20 @@ export function CompanionDiscoverySettingsCard({ scope, onOpenCompanion }: {</CardHeader><CardContent className="space-y-4 px-4 pb-5 sm:px-5">- {error || query.isError ? (+ {error === "settings" || query.isError ? (<p role="alert" className="text-sm text-destructive">{t("companion.discovery.settingsFailed")}</p>) : null}+ {error === "model" || (aiSettings && !defaultModelReady) ? (+ <div className="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-amber-200 bg-amber-50 p-3 dark:border-amber-900/50 dark:bg-amber-950/30">+ <p role="alert" className="text-sm text-amber-900 dark:text-amber-200">{t("companion.discovery.modelRequired")}</p>+ <button type="button" onClick={onOpenAiSettings}+ className="rounded-md border border-amber-300 bg-white px-3 py-1.5 text-xs font-medium text-amber-900 hover:bg-amber-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-600 dark:border-amber-800 dark:bg-amber-950 dark:text-amber-200">+ {t("companion.discovery.configureModel")}+ </button>+ </div>+ ) : null}<sectionclassName="space-y-3 rounded-lg border border-slate-200/80 bg-white p-4 dark:border-slate-800 dark:bg-slate-900"diff --git a/docs/personality-memory-agent.md b/docs/personality-memory-agent.mdindex 3a23d9f3..7c8100af 100644--- a/docs/personality-memory-agent.md+++ b/docs/personality-memory-agent.md@@ -14,7 +14,7 @@ The main flow is: normal note-taking → the Agent identifies an opportunity at## 2. Interaction rules-- Entry: Settings → Paw mode, off by default. Enabling covers all notes in the current account, including child notebooks and future notes, without notebook selection. This does not mean reading or sending the entire library at once.+- Entry: Settings → Paw mode, off by default. It can be enabled only after a default AI model is configured and enabled; the client links to model setup and the server enforces the same model-availability check. Paw mode can still be turned off while the model is unavailable. Enabling covers all notes in the current account, including child notebooks and future notes, without notebook selection. This does not mean reading or sending the entire library at once.- Use a small bell and unread dot, without primary navigation, automatic popups, or system notifications. Currently available to signed-in personal accounts on non-demo instances with login enabled; no native Android/iOS entry yet.- Informational notifications offer useful connections, explanations, and source links without requiring a task. Action notifications explain which notes will change, how, and with what consequences; confirmation invokes existing note capabilities.- Suggestions do not enter the normal note list or automatically become “AI suggestion drafts.” Notes are created or modified only after confirmation of the corresponding write.diff --git a/docs/personality-memory-agent.zh-CN.md b/docs/personality-memory-agent.zh-CN.mdindex b9deac64..5512d6c9 100644--- a/docs/personality-memory-agent.zh-CN.md+++ b/docs/personality-memory-agent.zh-CN.md@@ -14,7 +14,7 @@ Agent 是围绕用户知识工作的长期助手,不是一个熟悉笔记的## 2. 交互规则-- 入口为「设置 → 猫爪模式」,默认关闭。开启后,笔记访问范围覆盖当前账户的全部笔记,包括子笔记本和以后新建的笔记,无需选择笔记本;不代表一次读取或发送全库。+- 入口为「设置 → 猫爪模式」,默认关闭。只有已配置并启用默认 AI 模型时才能开启;前端给出配置入口,服务端执行同样的模型可用性校验,模型不可用时仍可随时关闭。开启后,笔记访问范围覆盖当前账户的全部笔记,包括子笔记本和以后新建的笔记,无需选择笔记本;不代表一次读取或发送全库。- 使用轻量铃铛和未读圆点,不占主导航、不自动弹窗、不发系统通知。当前仅向已登录的个人账户开放,要求非 Demo 且启用登录的实例;原生 Android/iOS 尚无入口。- 普通通知提供有价值的关联、解释和来源链接,无须执行任务。操作通知说明处理哪些笔记、如何处理及其后果,用户确认后调用现有笔记能力执行。- 建议不混入正常笔记,也不默认生成「AI 建议草稿」。只有确认了相应写入操作,才创建或修改笔记。diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex 9d1bfbb9..2d0db751 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -10,6 +10,8 @@ export const enUS = {tagline: "The longer you use it, the better Paw mode understands you.",enable: "Enable Paw mode",settingsFailed: "Settings were not saved. Check your connection or refresh and retry.",+ modelRequired: "Configure and enable a default AI model before turning on Paw mode.",+ configureModel: "Open AI integrations",openCompanion: "Conversation and personal memory",openCompanionDesc: "Manage memories and context preferences Paw mode learns from conversations.",panelDescription: "No need to process every item. Only approved operations change notes; discoveries disappear after 7 days.",diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex c6a5518f..e9f73241 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -10,6 +10,8 @@ export const zhCN = {tagline: "用得越久,猫爪越懂你。",enable: "启用猫爪模式",settingsFailed: "设置未保存。请检查连接或刷新后重试。",+ modelRequired: "开启猫爪模式前,请先配置并启用默认 AI 模型。",+ configureModel: "前往 AI 集成",openCompanion: "对话与个人记忆",openCompanionDesc: "管理猫爪在日常对话中沉淀的记忆与上下文偏好。",panelDescription: "不需要逐条处理。只有你确认的操作才会改变笔记;发现 7 天后自动隐藏。",