Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): adapt to ai-sdk v7 usage type, keep officeparser at 7.2.2

Elian Dorana64863cb57e2
diff --git a/apps/server/package.json b/apps/server/package.json
index 04b752565e..7d255f17df 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -93,7 +93,7 @@
"mime-types": "3.0.2",
"multer": "2.2.0",
"normalize-strings": "1.1.1",
- "officeparser": "7.2.1",
+ "officeparser": "7.2.2",
"rand-token": "1.0.1",
"safe-compare": "1.1.4",
"serve-favicon": "2.5.1",
diff --git a/apps/server/src/services/llm/stream.spec.ts b/apps/server/src/services/llm/stream.spec.ts
index cc7e3302fb..73b96732b7 100644
--- a/apps/server/src/services/llm/stream.spec.ts
+++ b/apps/server/src/services/llm/stream.spec.ts
@@ -252,20 +252,20 @@ describe("streamToChunks", () => {
expect(usage.usage.model).toBe("m");
});
- it("falls back to cachedInputTokens and derives no-cache input when details are absent", async () => {
+ it("treats all input as no-cache when token details are absent", async () => {
const pricing: ModelPricing = { input: 2, output: 6 };
const chunks = await collect(fakeResult(
[],
Promise.resolve({
inputTokens: 1_000_000,
- outputTokens: 0,
- cachedInputTokens: 400_000
+ outputTokens: 0
})
), { pricing });
- // noCache = max(0, 1_000_000 - 400_000 - 0) = 600_000
- // 0.6*2 + 0.4*2*0.1 (read) + 0 (write) + 0 (output)
- const expected = 0.6 * 2 + 0.4 * 2 * 0.1;
+ // No inputTokenDetails => cacheRead = cacheWrite = 0,
+ // noCache = max(0, 1_000_000 - 0 - 0) = 1_000_000
+ // 1*2 + 0 (read) + 0 (write) + 0 (output)
+ const expected = 1 * 2;
expect(usageOf(chunks).usage.cost).toBeCloseTo(expected, 6);
});
@@ -281,7 +281,7 @@ describe("streamToChunks", () => {
})
), { pricing });
- // cacheRead = 0 (details.cacheReadTokens ?? cachedInputTokens ?? 0)
+ // cacheRead = 0 (details.cacheReadTokens ?? 0)
// noCache = max(0, 1_000_000 - 0 - 250_000) = 750_000
const expected = 0.75 * 3 + 0.25 * 3 * 1.25;
expect(usageOf(chunks).usage.cost).toBeCloseTo(expected, 6);
diff --git a/apps/server/src/services/llm/stream.ts b/apps/server/src/services/llm/stream.ts
index 893280d310..a48416784a 100644
--- a/apps/server/src/services/llm/stream.ts
+++ b/apps/server/src/services/llm/stream.ts
@@ -22,7 +22,7 @@ function calculateCost(usage: LanguageModelUsage, pricing?: ModelPricing): numbe
if (!pricing) return undefined;
const details = usage.inputTokenDetails;
- const cacheReadTokens = details?.cacheReadTokens ?? usage.cachedInputTokens ?? 0;
+ const cacheReadTokens = details?.cacheReadTokens ?? 0;
const cacheWriteTokens = details?.cacheWriteTokens ?? 0;
// The sole caller only invokes calculateCost once it has type-guarded both
// inputTokens and outputTokens as numbers, so the `?? 0` fallbacks here are
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 19efb88af7..32297223b5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -775,8 +775,8 @@ importers:
specifier: 1.1.1
version: 1.1.1
officeparser:
- specifier: 7.2.1
- version: 7.2.1([email protected])
+ specifier: 7.2.2
+ version: 7.2.2([email protected])
rand-token:
specifier: 1.0.1
version: 1.0.1
@@ -10976,8 +10976,8 @@ packages:
resolution: {integrity: sha512-2W4oUZlVaqAPAil6FUg/difl6YhqhUR7x2eZY4bQCko22UXg3hptq9KLQdqFClV+Wu85UX7hNtdGTngi/1BxcA==}
- resolution: {integrity: sha512-l9v4ygeUAZGjNlmXhQNIOaPpxAbLNHzcN32Mwyad/HfGOxLcMGrz8aXMVCGICxtE0s8Mq5MwAEkO9gdliK7hZw==}
+ resolution: {integrity: sha512-W49PyMsOebNsEVEh6jYerNDakK+Se0YdUMwfTjTRQD7qFJqrEuSB7oEagLSnB7YOmZmvpKKz7wJEgeUeJzw5vg==}
engines: {node: '>=18.0.0'}
hasBin: true
peerDependencies:
@@ -25745,7 +25745,7 @@ snapshots:
node-fetch-native: 1.6.7
ufo: 1.6.4
dependencies:
'@xmldom/xmldom': 0.9.10
fflate: 0.8.3