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
fix(llm): guard missing pricing in cost label, await async getAllModels in spec
Tomáš Adámek5c2afada3529
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.tsindex bf12bef5a3..b7eadbfeab 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts+++ b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts@@ -84,7 +84,7 @@ function getCostDescription(model: LlmModelInfo): string | undefined {if (model.costMultiplier) {return `${model.costMultiplier}x`;}- if (model.pricing.input === 0 && model.pricing.output === 0) {+ if (model.pricing && model.pricing.input === 0 && model.pricing.output === 0) {return t("llm_chat.free");}return undefined;diff --git a/apps/server/src/services/llm/index.spec.ts b/apps/server/src/services/llm/index.spec.tsindex 146eefd75a..f2c4d89ea8 100644--- a/apps/server/src/services/llm/index.spec.ts+++ b/apps/server/src/services/llm/index.spec.ts@@ -137,29 +137,29 @@ describe("llm/index provider registry", () => {});describe("getAllModels", () => {- it("aggregates models across provider types, tagged with the provider", () => {+ it("aggregates models across provider types, tagged with the provider", async () => {setProviders(TWO);- const models = getAllModels();+ const models = await getAllModels();expect(models).toEqual([{ id: "anthropic-model", name: "anthropic Model", provider: "anthropic" },{ id: "openai-model", name: "openai Model", provider: "openai" }]);});- it("includes each provider type only once even with duplicate configs", () => {+ it("includes each provider type only once even with duplicate configs", async () => {setProviders([{ id: "a1", name: "A1", provider: "anthropic", apiKey: "k1" },{ id: "a2", name: "A2", provider: "anthropic", apiKey: "k2" }]);- const models = getAllModels();+ const models = await getAllModels();expect(models).toHaveLength(1);expect(models[0].provider).toBe("anthropic");});- it("skips and logs a provider whose model lookup throws", () => {+ it("skips and logs a provider whose model lookup throws", async () => {setProviders([{ id: "x", name: "X", provider: "mystery", apiKey: "k" }]);// Unknown type → getProvider throws inside getAllModels and is caught.- expect(getAllModels()).toEqual([]);+ await expect(getAllModels()).resolves.toEqual([]);expect(errorMock).toHaveBeenCalled();});});