Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): point the price-table script at core, where the table now lives

Elian Doran485c99f1ae90
diff --git a/.github/workflows/update-model-prices.yml b/.github/workflows/update-model-prices.yml
index d3b7f33268..2765b55107 100644
--- a/.github/workflows/update-model-prices.yml
+++ b/.github/workflows/update-model-prices.yml
@@ -1,6 +1,6 @@
name: Update model prices
-# Refreshes the committed LLM price table (apps/server/src/services/llm/providers/model_prices.json)
+# Refreshes the committed LLM price table (packages/trilium-core/src/services/llm/providers/model_prices.json)
# from LiteLLM's upstream data. Runs weekly and on demand; opens a PR only when the
# pruned output actually changes, so a human reviews price movements before they ship.
# The build never fetches this itself — it imports the committed JSON and stays hermetic.
@@ -30,19 +30,19 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Regenerate the price table
- run: pnpm --filter server update-model-prices
+ run: pnpm --filter @triliumnext/core update-model-prices
- name: Open a PR if the table changed
uses: peter-evans/create-pull-request@v8
with:
- add-paths: apps/server/src/services/llm/providers/model_prices.json
+ add-paths: packages/trilium-core/src/services/llm/providers/model_prices.json
branch: chore/update-model-prices
commit-message: "chore(llm): refresh model price table from LiteLLM"
title: "chore(llm): refresh model price table"
body: |
Automated refresh of the committed LLM price/context table
- (`apps/server/src/services/llm/providers/model_prices.json`) from
+ (`packages/trilium-core/src/services/llm/providers/model_prices.json`) from
[LiteLLM](https://github.com/BerriAI/litellm)'s upstream data, via
- `pnpm --filter server update-model-prices`.
+ `pnpm --filter @triliumnext/core update-model-prices`.
Review the diff for notable price movements before merging.
labels: dependencies
diff --git a/apps/server/package.json b/apps/server/package.json
index d020737723..b837d5d476 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -28,7 +28,6 @@
"docker-start-rootless-debian": "pnpm docker-build-rootless-debian && docker run -p 8081:8080 triliumnext-rootless-debian",
"docker-start-rootless-alpine": "pnpm docker-build-rootless-alpine && docker run -p 8081:8080 triliumnext-rootless-alpine",
"generate-document": "cross-env TRILIUM_ENV=dev TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=src tsx ./scripts/generate_document.ts",
- "update-model-prices": "tsx ./scripts/update-model-prices.ts",
"proxy-traefik": "docker run --name trilium-traefik --rm --network=host -v ./docker/traefik/traefik.yml:/etc/traefik/traefik.yml:ro -v ./docker/traefik/dynamic:/etc/traefik/dynamic traefik:latest",
"proxy-nginx-subdir": "docker run --name trilium-nginx-subdir --rm --network=host -v ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro nginx:latest"
},
diff --git a/packages/trilium-core/package.json b/packages/trilium-core/package.json
index e987456f65..9cbfcc514a 100644
--- a/packages/trilium-core/package.json
+++ b/packages/trilium-core/package.json
@@ -4,7 +4,8 @@
"description": "",
"main": "src/index.ts",
"scripts": {
- "test": "echo \"Note: Core tests are run either through apps/server or apps/standalone, since they have different runtime environments.\""
+ "test": "echo \"Note: Core tests are run either through apps/server or apps/standalone, since they have different runtime environments.\"",
+ "update-model-prices": "tsx ./scripts/update-model-prices.ts"
},
"dependencies": {
"@ai-sdk/anthropic": "4.0.30",
diff --git a/apps/server/scripts/update-model-prices.ts b/packages/trilium-core/scripts/update-model-prices.ts
similarity index 89%
rename from apps/server/scripts/update-model-prices.ts
rename to packages/trilium-core/scripts/update-model-prices.ts
index c61873709a..b466041b47 100644
--- a/apps/server/scripts/update-model-prices.ts
+++ b/packages/trilium-core/scripts/update-model-prices.ts
@@ -12,10 +12,10 @@
* hermetic. This runs on demand (or from the weekly `update-model-prices.yml`
* workflow, which opens a PR when the output changes). Usage:
*
- * pnpm --filter server update-model-prices
+ * pnpm --filter @triliumnext/core update-model-prices
*/
-import { writeFileSync } from "node:fs";
+import { existsSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import type { ModelPrice, ModelPriceTable, ProviderPrices } from "../src/services/llm/providers/base_provider.js";
@@ -73,6 +73,14 @@ interface LiteLlmEntry {
}
async function main() {
+ // The output is a committed file we overwrite, never one we create. If it is
+ // missing, the table has moved and this script is writing into a dead path --
+ // which is silent otherwise, since the write itself still succeeds and the
+ // workflow's `add-paths` then sees no change and opens no PR.
+ if (!existsSync(OUTPUT_PATH)) {
+ throw new Error(`${OUTPUT_PATH} does not exist; the price table has moved. Update OUTPUT_PATH (and the workflow's add-paths) to follow it.`);
+ }
+
const response = await fetch(SOURCE_URL);
if (!response.ok) {
throw new Error(`Failed to fetch LiteLLM price list: HTTP ${response.status}`);
diff --git a/packages/trilium-core/tsconfig.json b/packages/trilium-core/tsconfig.json
index 62ebbd9464..e3368d6513 100644
--- a/packages/trilium-core/tsconfig.json
+++ b/packages/trilium-core/tsconfig.json
@@ -8,6 +8,9 @@
},
{
"path": "./tsconfig.spec.json"
+ },
+ {
+ "path": "./tsconfig.scripts.json"
}
]
}
diff --git a/packages/trilium-core/tsconfig.scripts.json b/packages/trilium-core/tsconfig.scripts.json
new file mode 100644
index 0000000000..ce65188100
--- /dev/null
+++ b/packages/trilium-core/tsconfig.scripts.json
@@ -0,0 +1,26 @@
+// Maintenance scripts that regenerate committed sources (see scripts/). They are
+// Node-only and never bundled, so they get their own project rather than joining
+// tsconfig.lib.json, whose rootDir is `src` and whose `types` are deliberately empty.
+// They are typechecked all the same: a script that references a source file which
+// has since moved must fail `pnpm typecheck` rather than rot silently.
+{
+ "extends": "../../tsconfig.base.json",
+ "compilerOptions": {
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "target": "ES2020",
+ "outDir": "./out-tsc/scripts",
+ "tsBuildInfoFile": "./out-tsc/scripts/tsconfig.scripts.tsbuildinfo",
+ "types": [
+ "node"
+ ]
+ },
+ "include": [
+ "scripts/**/*.ts"
+ ],
+ "references": [
+ {
+ "path": "./tsconfig.lib.json"
+ }
+ ]
+}