Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(llm): recommend the newest Claude model per family by default
Elian Doran470c165219c7
diff --git a/apps/server/src/services/llm/index.spec.ts b/apps/server/src/services/llm/index.spec.tsindex 23ae556248..41027f74e4 100644--- a/apps/server/src/services/llm/index.spec.ts+++ b/apps/server/src/services/llm/index.spec.ts@@ -161,11 +161,12 @@ describe("llm/index provider registry", () => {describe("listProviderModels", () => {it("lists models for ad-hoc credentials, tagged with the recommended flag", async () => {// No saved config needed — the add/edit flow passes raw credentials.- // (Provider-specific recommendation rules are covered in model_listing.spec.)- const models = await listProviderModels("anthropic", "k");+ // Uses "google" to exercise the generic non-preview fallback rule;+ // provider-specific recommendation rules are covered in model_listing.spec.+ const models = await listProviderModels("google", "k");expect(models).toEqual([- { id: "anthropic-model", name: "anthropic Model", recommended: true },- { id: "anthropic-preview", name: "anthropic Preview", recommended: false }+ { id: "google-model", name: "google Model", recommended: true },+ { id: "google-preview", name: "google Preview", recommended: false }]);});diff --git a/apps/server/src/services/llm/providers/model_listing.spec.ts b/apps/server/src/services/llm/providers/model_listing.spec.tsindex bfdbf54ec5..cdfbe04a10 100644--- a/apps/server/src/services/llm/providers/model_listing.spec.ts+++ b/apps/server/src/services/llm/providers/model_listing.spec.ts@@ -220,6 +220,25 @@ describe("recommendedModelIds", () => {expect(recommendedModelIds([{ id: "llama3.2" }, { id: "qwen2.5" }], "openai").size).toBe(0);});+ it("recommends the newest version of each Claude family for Anthropic", () => {+ const ids = recommendedModelIds([+ "claude-fable-5",+ "claude-opus-4-8", "claude-opus-4-7", "claude-opus-4-6", "claude-opus-4-20250514",+ "claude-sonnet-5", "claude-sonnet-4-6", "claude-sonnet-4-20250514",+ "claude-haiku-4-5-20251001"+ ].map(id => ({ id })), "anthropic");+ // One per family, newest each — Fable 5, Opus 4.8, Sonnet 5, Haiku 4.5.+ expect([...ids].sort()).toEqual([+ "claude-fable-5", "claude-haiku-4-5-20251001", "claude-opus-4-8", "claude-sonnet-5"+ ]);+ });++ it("treats an Anthropic snapshot date as the version, not a minor bump", () => {+ // sonnet-4-20250514 is 4.0, so sonnet-4-6 (4.6) must outrank it.+ const ids = recommendedModelIds([{ id: "claude-sonnet-4-20250514" }, { id: "claude-sonnet-4-6" }], "anthropic");+ expect([...ids]).toEqual(["claude-sonnet-4-6"]);+ });+it("falls back to non-preview, non-legacy models for other providers", () => {const ids = recommendedModelIds([{ id: "gemini-2.5-flash" },diff --git a/apps/server/src/services/llm/providers/model_listing.ts b/apps/server/src/services/llm/providers/model_listing.tsindex 264012fd96..0d0b6593e2 100644--- a/apps/server/src/services/llm/providers/model_listing.ts+++ b/apps/server/src/services/llm/providers/model_listing.ts@@ -138,12 +138,20 @@ export function isGoogleChatModel(id: string): boolean {* gpt-4 through 5.5 and o1/o3 models (which stay in the picker, unchecked).* When gpt-5.7 / o5 ship they win automatically.*+ * For Anthropic we recommend the newest version within each Claude family+ * (Opus, Sonnet, Haiku, Fable, and any future one) — one model per family,+ * so today's Opus 4.8, Sonnet 5, Haiku 4.5 and Fable 5. Older revisions and+ * dated snapshots stay in the picker, unchecked.+ ** Other providers fall back to "everything that isn't a preview or legacy".*/export function recommendedModelIds(models: RecommendCandidate[], provider: string): Set<string> {if (provider === "openai") {return openAiRecommendedIds(models);}+ if (provider === "anthropic") {+ return anthropicRecommendedIds(models);+ }return new Set(models.filter(m => !m.isLegacy && !/preview/i.test(m.id)).map(m => m.id));}@@ -184,3 +192,46 @@ function oSeriesVersion(id: string): number {const match = /^o(\d+)/.exec(id);return match ? parseInt(match[1], 10) : 0;}++/**+ * Anthropic model id shape: `claude-<family>-<major>[-<minor>][-<YYYYMMDD>]`.+ * The optional trailing 8-digit snapshot date is not part of the version —+ * `claude-sonnet-4-20250514` is Sonnet 4.0, not 4.20250514 — so the minor+ * group is capped at two digits to force the date into the snapshot group.+ */+const ANTHROPIC_MODEL = /^claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?:-\d{8})?$/;++/** Newest version within each Claude family (opus/sonnet/haiku/fable, and any future one) — one id per family. */+function anthropicRecommendedIds(models: RecommendCandidate[]): Set<string> {+ const byFamily = new Map<string, RecommendCandidate[]>();+ for (const model of models) {+ const family = anthropicFamily(model.id);+ if (!family) {+ continue;+ }+ const members = byFamily.get(family) ?? [];+ members.push(model);+ byFamily.set(family, members);+ }+ const recommended = new Set<string>();+ for (const members of byFamily.values()) {+ const newest = members.reduce((best, m) => (anthropicVersion(m.id) > anthropicVersion(best.id) ? m : best));+ recommended.add(newest.id);+ }+ return recommended;+}++/** `claude-opus-4-8` → "opus"; null for ids that aren't `claude-<family>-<version>`. */+function anthropicFamily(id: string): string | null {+ return ANTHROPIC_MODEL.exec(id)?.[1] ?? null;+}++/** `claude-opus-4-8` → 4.8, `claude-sonnet-5` → 5, `claude-sonnet-4-20250514` → 4 (the trailing date is not a minor). */+function anthropicVersion(id: string): number {+ const match = ANTHROPIC_MODEL.exec(id);+ if (!match) {+ return 0;+ }+ const [, , major, minor] = match;+ return parseFloat(minor ? `${major}.${minor}` : major);+}