Skip to content

Build your personal knowledge base with Trilium Notes

refactor(server): consolidate imports

Elian Doranc7884d06c26f
diff --git a/apps/script-deployer/src/dev.ts b/apps/script-deployer/src/dev.ts
index 093778eded..5ab98b0f60 100644
--- a/apps/script-deployer/src/dev.ts
+++ b/apps/script-deployer/src/dev.ts
@@ -96,9 +96,7 @@ async function deployScripts() {
return;
}
- const becca = (await import("@triliumnext/core")).becca;
- const cls = (await import("@triliumnext/core")).cls;
- const { note_service: notesService } = await import("@triliumnext/core");
+ const { becca, cls, note_service: notesService } = await import("@triliumnext/core");
console.log(`Deploying ${files.length} script(s)…`);
diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts
index 31cc69e433..97be0ba1d3 100644
--- a/apps/server/src/main.ts
+++ b/apps/server/src/main.ts
@@ -50,8 +50,7 @@ async function startApplication() {
ws.sendTransactionEntityChangesToAllClients();
},
async onTransactionRollback() {
- const cls = (await import("@triliumnext/core")).cls;
- const { becca_loader, entity_changes } = await import("@triliumnext/core");
+ const { cls, becca_loader, entity_changes } = await import("@triliumnext/core");
const entityChangeIds = cls.getAndClearEntityChangeIds();
diff --git a/apps/server/src/routes/custom.ts b/apps/server/src/routes/custom.ts
index 1e5839ab9b..c7be8ec64e 100644
--- a/apps/server/src/routes/custom.ts
+++ b/apps/server/src/routes/custom.ts
@@ -1,10 +1,7 @@
-import { routeHelpers, scriptService, utils } from "@triliumnext/core";
+import { becca, cls, getLog, routeHelpers, scriptService, utils } from "@triliumnext/core";
import type { Request, Response, Router } from "express";
-import { becca } from "@triliumnext/core";
import { namespace } from "../cls_provider.js";
-import { cls } from "@triliumnext/core";
-import { getLog } from "@triliumnext/core";
import sql from "../services/sql.js";
function handleRequest(req: Request, res: Response) {
diff --git a/apps/server/src/services/image.ts b/apps/server/src/services/image.ts
index 158dd7b43c..7b099de9ba 100644
--- a/apps/server/src/services/image.ts
+++ b/apps/server/src/services/image.ts
@@ -3,8 +3,7 @@
* Re-exports core image service and adds OCR scheduling.
*/
-import { imageService, options as optionService } from "@triliumnext/core";
-import { getLog } from "@triliumnext/core";
+import { getLog, imageService, options as optionService } from "@triliumnext/core";
import ocrService from "./ocr/ocr_service.js";
function scheduleOcrForNote(noteId: string) {
diff --git a/apps/server/src/services/llm/chat_title.ts b/apps/server/src/services/llm/chat_title.ts
index 71dc59c810..2f45bd5385 100644
--- a/apps/server/src/services/llm/chat_title.ts
+++ b/apps/server/src/services/llm/chat_title.ts
@@ -1,8 +1,8 @@
-import { becca } from "@triliumnext/core";
-import { getProvider } from "./index.js";
-import { getLog } from "@triliumnext/core";
+import { becca, getLog } from "@triliumnext/core";
import { t } from "i18next";
+import { getProvider } from "./index.js";
+
/** Default title prefixes that indicate the note hasn't been manually renamed. */
function hasDefaultTitle(title: string): boolean {
// "Chat: <timestamp>" from sidebar/API-created chats
diff --git a/apps/server/src/services/llm/index.ts b/apps/server/src/services/llm/index.ts
index fb4d810ab8..d09b61ffd8 100644
--- a/apps/server/src/services/llm/index.ts
+++ b/apps/server/src/services/llm/index.ts
@@ -1,6 +1,5 @@
-import { options as optionService } from "@triliumnext/core";
+import { getLog, options as optionService } from "@triliumnext/core";
-import { getLog } from "@triliumnext/core";
import { AnthropicProvider } from "./providers/anthropic.js";
import { GoogleProvider } from "./providers/google.js";
import { OpenAiProvider } from "./providers/openai.js";
diff --git a/apps/server/src/services/llm/providers/base_provider.ts b/apps/server/src/services/llm/providers/base_provider.ts
index 8f0de6d6cf..bf684a6426 100644
--- a/apps/server/src/services/llm/providers/base_provider.ts
+++ b/apps/server/src/services/llm/providers/base_provider.ts
@@ -8,8 +8,7 @@ import { decodeUtf8 } from "@triliumnext/core/src/services/utils/binary.js";
import { type FilePart, generateText, type ImagePart, type LanguageModel, type ModelMessage, stepCountIs, streamText, type SystemModelMessage, type TextPart, type ToolSet } from "ai";
import yaml from "js-yaml";
-import { becca } from "@triliumnext/core";
-import { getLog } from "@triliumnext/core";
+import { becca, getLog } from "@triliumnext/core";
import { getNoteMeta,SYSTEM_PROMPT_LIMITS } from "../tools/helpers.js";
import { allToolRegistries } from "../tools/index.js";
import type { LlmProvider, LlmProviderConfig, ModelInfo, ModelPricing, StreamResult } from "../types.js";
diff --git a/apps/server/src/services/llm/tools/attribute_tools.ts b/apps/server/src/services/llm/tools/attribute_tools.ts
index 587967465f..25d8db5ecf 100644
--- a/apps/server/src/services/llm/tools/attribute_tools.ts
+++ b/apps/server/src/services/llm/tools/attribute_tools.ts
@@ -2,10 +2,9 @@
* LLM tools for attribute operations (get, set, delete labels/relations).
*/
-import { attributes as attributeService } from "@triliumnext/core";
+import { attributes as attributeService, becca } from "@triliumnext/core";
import { z } from "zod";
-import { becca } from "@triliumnext/core";
import { flag } from "./helpers.js";
import { defineTools } from "./tool_registry.js";
diff --git a/apps/server/src/services/llm/tools/hierarchy_tools.ts b/apps/server/src/services/llm/tools/hierarchy_tools.ts
index f230cfcd89..afa2983476 100644
--- a/apps/server/src/services/llm/tools/hierarchy_tools.ts
+++ b/apps/server/src/services/llm/tools/hierarchy_tools.ts
@@ -2,10 +2,9 @@
* LLM tools for navigating the note hierarchy (tree structure, branches).
*/
-import { type BNote, cloning as cloningService } from "@triliumnext/core";
+import { becca, type BNote, cloning as cloningService } from "@triliumnext/core";
import { z } from "zod";
-import { becca } from "@triliumnext/core";
import branchService from "../../branches.js";
import { PROTECTED_SYSTEM_NOTES } from "./helpers.js";
import { defineTools } from "./tool_registry.js";
diff --git a/apps/server/src/services/llm/tools/note_tools.ts b/apps/server/src/services/llm/tools/note_tools.ts
index 84f1a71662..afcd7339ac 100644
--- a/apps/server/src/services/llm/tools/note_tools.ts
+++ b/apps/server/src/services/llm/tools/note_tools.ts
@@ -2,10 +2,9 @@
* LLM tools for note operations (search, read, create, update, append).
*/
-import { markdownImportService as markdownImport, note_service as noteService, search as searchService, SearchContext, TaskContext } from "@triliumnext/core";
+import { becca, markdownImportService as markdownImport, note_service as noteService, search as searchService, SearchContext, TaskContext } from "@triliumnext/core";
import { z } from "zod";
-import { becca } from "@triliumnext/core";
import { applyTextEdits, getContentPreview, getNoteContentForLlm, getNoteMeta, PROTECTED_SYSTEM_NOTES, setNoteContentFromLlm,TOOL_LIMITS } from "./helpers.js";
import { defineTools } from "./tool_registry.js";
diff --git a/apps/server/src/services/ocr/ocr_service.ts b/apps/server/src/services/ocr/ocr_service.ts
index ed5ddb63ca..d29e2cf9dc 100644
--- a/apps/server/src/services/ocr/ocr_service.ts
+++ b/apps/server/src/services/ocr/ocr_service.ts
@@ -1,7 +1,6 @@
import { getTesseractCode } from '@triliumnext/commons';
-import { becca, blob as blobService, entity_changes as entityChangesService, options } from '@triliumnext/core';
+import { becca, blob as blobService, entity_changes as entityChangesService, getLog, options } from '@triliumnext/core';
-import { getLog } from "@triliumnext/core";
import sql from '../sql.js';
import { FileProcessor } from './processors/file_processor.js';
import { ImageProcessor } from './processors/image_processor.js';
diff --git a/apps/server/src/services/request.ts b/apps/server/src/services/request.ts
index b2b6d58d05..f416698dae 100644
--- a/apps/server/src/services/request.ts
+++ b/apps/server/src/services/request.ts
@@ -1,10 +1,8 @@
"use strict";
-import { type ExecOpts, type RequestProvider, sync_options as syncOptions } from "@triliumnext/core";
+import { type ExecOpts, getLog, type RequestProvider, sync_options as syncOptions } from "@triliumnext/core";
import url from "url";
-import { getLog } from "@triliumnext/core";
-
// this service provides abstraction over node's HTTP/HTTPS modules.
// Subclasses (e.g. apps/desktop's ElectronRequestProvider) can override
// `getClient` to plug in alternative transports such as `electron.net`
diff --git a/apps/server/src/services/search/services/search_benchmark.spec.ts b/apps/server/src/services/search/services/search_benchmark.spec.ts
index fcf13aad32..24129952d3 100644
--- a/apps/server/src/services/search/services/search_benchmark.spec.ts
+++ b/apps/server/src/services/search/services/search_benchmark.spec.ts
@@ -12,9 +12,8 @@
*
* All times are in-memory (monkeypatched getContent, no real SQL).
*/
-import { BBranch, becca_mocking, BNote, search as searchService, SearchContext } from "@triliumnext/core";
+import { BBranch, becca, becca_mocking, BNote, search as searchService, SearchContext } from "@triliumnext/core";
import { describe, it, expect, afterEach } from "vitest";
-import { becca } from "@triliumnext/core";
const { NoteBuilder, note } = becca_mocking;
diff --git a/apps/server/src/services/special_notes.ts b/apps/server/src/services/special_notes.ts
index 8ae56acf0e..c899002e58 100644
--- a/apps/server/src/services/special_notes.ts
+++ b/apps/server/src/services/special_notes.ts
@@ -1,9 +1,7 @@
import { SaveLlmChatResponse } from "@triliumnext/commons";
-import { type BNote, date_notes as dateNoteService, date_utils as dateUtils, hoisted_note as hoistedNoteService, note_service as noteService, search as searchService, SearchContext } from "@triliumnext/core";
+import { becca, type BNote, date_notes as dateNoteService, date_utils as dateUtils, hoisted_note as hoistedNoteService, note_service as noteService, search as searchService, SearchContext } from "@triliumnext/core";
import { t } from "i18next";
-import { becca } from "@triliumnext/core";
-
function createLlmChat() {
const { note } = noteService.createNewNote({
parentNoteId: getMonthlyParentNoteId("_llmChat", "llmChat"),
diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.ts
index b985cd967c..f1d7335baa 100644
--- a/apps/server/src/share/content_renderer.ts
+++ b/apps/server/src/share/content_renderer.ts
@@ -1,5 +1,5 @@
import { extractYouTubeVideoId, renderSpreadsheetToHtml, renderToHtml as renderMarkdownToHtml } from "@triliumnext/commons";
-import { type BAttachment, type BBranch, BNote, icon_packs as iconPackService, options, sanitize, task_states, utils } from "@triliumnext/core";
+import { type BAttachment, type BBranch, becca, BNote, getLog, icon_packs as iconPackService, options, sanitize, task_states, utils } from "@triliumnext/core";
import { highlightAuto } from "@triliumnext/highlightjs";
import ejs from "ejs";
import escapeHtml from "escape-html";
@@ -8,9 +8,7 @@ import { t } from "i18next";
import { HTMLElement, Options, parse, TextNode } from "node-html-parser";
import { join } from "path";
-import { becca } from "@triliumnext/core";
import assetPath, { assetUrlFragment } from "../services/asset_path.js";
-import { getLog } from "@triliumnext/core";
import { getResourceDir, isDev } from "../services/utils.js";
import SAttachment from "./shaca/entities/sattachment.js";
import SBranch from "./shaca/entities/sbranch.js";