@agentic-kit/ollama 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.js CHANGED
@@ -265,6 +265,7 @@ export class OllamaAdapter {
265
265
  output.usage.input = payload.prompt_eval_count ?? output.usage.input;
266
266
  output.usage.output = payload.eval_count ?? output.usage.output;
267
267
  output.usage.totalTokens = output.usage.input + output.usage.output;
268
+ calculateUsageCost(model, output.usage);
268
269
  output.stopReason = payload.done_reason === 'length' ? 'length' : 'stop';
269
270
  if (thinkingIndex !== undefined) {
270
271
  stream.push({
@@ -408,6 +409,7 @@ function createAssistantMessage(model) {
408
409
  usage: {
409
410
  input: 0,
410
411
  output: 0,
412
+ reasoning: 0,
411
413
  cacheRead: 0,
412
414
  cacheWrite: 0,
413
415
  totalTokens: 0,
@@ -417,6 +419,14 @@ function createAssistantMessage(model) {
417
419
  timestamp: Date.now(),
418
420
  };
419
421
  }
422
+ function calculateUsageCost(model, usage) {
423
+ usage.cost.input = ((model.cost?.input ?? 0) / 1_000_000) * usage.input;
424
+ usage.cost.output = ((model.cost?.output ?? 0) / 1_000_000) * usage.output;
425
+ usage.cost.cacheRead = ((model.cost?.cacheRead ?? 0) / 1_000_000) * usage.cacheRead;
426
+ usage.cost.cacheWrite = ((model.cost?.cacheWrite ?? 0) / 1_000_000) * usage.cacheWrite;
427
+ usage.cost.total =
428
+ usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
429
+ }
420
430
  function legacyInputToContext(input) {
421
431
  const messages = input.messages
422
432
  ? input.messages
@@ -431,6 +441,7 @@ function legacyInputToContext(input) {
431
441
  usage: {
432
442
  input: 0,
433
443
  output: 0,
444
+ reasoning: 0,
434
445
  cacheRead: 0,
435
446
  cacheWrite: 0,
436
447
  totalTokens: 0,
package/index.d.ts CHANGED
@@ -14,6 +14,12 @@ interface ModelDescriptor {
14
14
  tools?: boolean;
15
15
  contextWindow?: number;
16
16
  maxOutputTokens?: number;
17
+ cost?: {
18
+ input?: number;
19
+ output?: number;
20
+ cacheRead?: number;
21
+ cacheWrite?: number;
22
+ };
17
23
  headers?: Record<string, string>;
18
24
  }
19
25
  interface TextContent {
@@ -38,6 +44,7 @@ interface ToolCallContent {
38
44
  interface Usage {
39
45
  input: number;
40
46
  output: number;
47
+ reasoning: number;
41
48
  cacheRead: number;
42
49
  cacheWrite: number;
43
50
  totalTokens: number;
package/index.js CHANGED
@@ -269,6 +269,7 @@ class OllamaAdapter {
269
269
  output.usage.input = payload.prompt_eval_count ?? output.usage.input;
270
270
  output.usage.output = payload.eval_count ?? output.usage.output;
271
271
  output.usage.totalTokens = output.usage.input + output.usage.output;
272
+ calculateUsageCost(model, output.usage);
272
273
  output.stopReason = payload.done_reason === 'length' ? 'length' : 'stop';
273
274
  if (thinkingIndex !== undefined) {
274
275
  stream.push({
@@ -413,6 +414,7 @@ function createAssistantMessage(model) {
413
414
  usage: {
414
415
  input: 0,
415
416
  output: 0,
417
+ reasoning: 0,
416
418
  cacheRead: 0,
417
419
  cacheWrite: 0,
418
420
  totalTokens: 0,
@@ -422,6 +424,14 @@ function createAssistantMessage(model) {
422
424
  timestamp: Date.now(),
423
425
  };
424
426
  }
427
+ function calculateUsageCost(model, usage) {
428
+ usage.cost.input = ((model.cost?.input ?? 0) / 1_000_000) * usage.input;
429
+ usage.cost.output = ((model.cost?.output ?? 0) / 1_000_000) * usage.output;
430
+ usage.cost.cacheRead = ((model.cost?.cacheRead ?? 0) / 1_000_000) * usage.cacheRead;
431
+ usage.cost.cacheWrite = ((model.cost?.cacheWrite ?? 0) / 1_000_000) * usage.cacheWrite;
432
+ usage.cost.total =
433
+ usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
434
+ }
425
435
  function legacyInputToContext(input) {
426
436
  const messages = input.messages
427
437
  ? input.messages
@@ -436,6 +446,7 @@ function legacyInputToContext(input) {
436
446
  usage: {
437
447
  input: 0,
438
448
  output: 0,
449
+ reasoning: 0,
439
450
  cacheRead: 0,
440
451
  cacheWrite: 0,
441
452
  totalTokens: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentic-kit/ollama",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "Ollama",
6
6
  "main": "index.js",
@@ -40,5 +40,5 @@
40
40
  "test:watch": "jest --watch"
41
41
  },
42
42
  "keywords": [],
43
- "gitHead": "d4f3f660be621267efe12671c22db202ccdb3f0b"
43
+ "gitHead": "af045fe54e55e593a3e4292335faa28fdb878619"
44
44
  }