@pikku/mongodb 0.12.15 → 0.12.17

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/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @pikku/mongodb
2
2
 
3
+ ## 0.12.17
4
+
5
+ ### Patch Changes
6
+
7
+ - fd9d834: Stop publishing internals that only their own package or file used. The declarations stay; only the entrypoint re-export is removed, so nothing that imported a name from where it is declared is affected.
8
+ - Updated dependencies [063f43a]
9
+ - Updated dependencies [ce66bf8]
10
+ - Updated dependencies [d0307a8]
11
+ - Updated dependencies [ce66bf8]
12
+ - Updated dependencies [3ad2131]
13
+ - Updated dependencies [b930dca]
14
+ - Updated dependencies [b95e77d]
15
+ - Updated dependencies [fd9d834]
16
+ - Updated dependencies [8978fbd]
17
+ - @pikku/core@0.12.82
18
+
19
+ ## 0.12.16
20
+
21
+ ### Patch Changes
22
+
23
+ - e110c55: Add runtime scoring for AI agents: `pikkuAIScorer` for heuristic grades and
24
+ `pikkuAIJudge` for LLM-judged ones, graded off the request path on two queue
25
+ lanes so a slow judge cannot starve the cheap checks. Grades are sampled
26
+ deterministically per `(run, scorer)` and persisted to `ai_run_score`.
27
+ - Updated dependencies [e110c55]
28
+ - Updated dependencies [e110c55]
29
+ - Updated dependencies [e110c55]
30
+ - Updated dependencies [acc8077]
31
+ - Updated dependencies [905f737]
32
+ - Updated dependencies [3cc6428]
33
+ - Updated dependencies [c524adf]
34
+ - Updated dependencies [e110c55]
35
+ - @pikku/core@0.12.81
36
+
3
37
  ## 0.12.15
4
38
 
5
39
  ### Patch Changes
@@ -7,7 +7,6 @@ export { MongoDBDeploymentService } from './mongodb-deployment-service.js';
7
7
  export { MongoDBAIStorageService } from './mongodb-ai-storage-service.js';
8
8
  export { MongoDBAgentRunService } from './mongodb-agent-run-service.js';
9
9
  export { MongoDBSecretService } from './mongodb-secret-service.js';
10
- export type { MongoDBSecretServiceConfig } from './mongodb-secret-service.js';
11
10
  export type { WorkflowRunService } from '@pikku/core/workflow';
12
11
  export type { AgentRunService, AgentRunRow } from '@pikku/core/ai-agent';
13
12
  export { MongoDBSessionStore } from './mongodb-session-store.js';
@@ -1,5 +1,6 @@
1
- import type { AIStorageService, AIRunStateService, CreateRunInput } from '@pikku/core/services';
1
+ import type { AIStorageService, AIRunStateService, CreateRunInput, SaveScoreInput } from '@pikku/core/services';
2
2
  import type { AIThread, AIMessage, AgentRunState } from '@pikku/core/ai-agent';
3
+ import type { AIRunScore } from '@pikku/core/ai-scorer';
3
4
  import type { Db } from 'mongodb';
4
5
  export declare class MongoDBAIStorageService implements AIStorageService, AIRunStateService {
5
6
  private db;
@@ -9,6 +10,7 @@ export declare class MongoDBAIStorageService implements AIStorageService, AIRunS
9
10
  private toolCalls;
10
11
  private workingMemory;
11
12
  private aiRuns;
13
+ private aiRunScores;
12
14
  constructor(db: Db);
13
15
  init(): Promise<void>;
14
16
  createThread(resourceId: string, options?: {
@@ -37,5 +39,7 @@ export declare class MongoDBAIStorageService implements AIStorageService, AIRunS
37
39
  approval: NonNullable<AgentRunState['pendingApprovals']>[number];
38
40
  } | null>;
39
41
  resolveApproval(toolCallId: string, status: 'approved' | 'denied'): Promise<boolean>;
42
+ saveScore(score: SaveScoreInput): Promise<void>;
43
+ getScores(runId: string): Promise<AIRunScore[]>;
40
44
  close(): Promise<void>;
41
45
  }
@@ -6,6 +6,7 @@ export class MongoDBAIStorageService {
6
6
  toolCalls;
7
7
  workingMemory;
8
8
  aiRuns;
9
+ aiRunScores;
9
10
  constructor(db) {
10
11
  this.db = db;
11
12
  }
@@ -18,12 +19,14 @@ export class MongoDBAIStorageService {
18
19
  this.workingMemory =
19
20
  this.db.collection('ai_working_memory');
20
21
  this.aiRuns = this.db.collection('ai_run');
22
+ this.aiRunScores = this.db.collection('ai_run_score');
21
23
  await this.threads.createIndex({ resourceId: 1 });
22
24
  await this.aiMessages.createIndex({ threadId: 1, createdAt: 1 });
23
25
  await this.toolCalls.createIndex({ threadId: 1 });
24
26
  await this.toolCalls.createIndex({ messageId: 1 });
25
27
  await this.workingMemory.createIndex({ id: 1, scope: 1 }, { unique: true });
26
28
  await this.aiRuns.createIndex({ threadId: 1, createdAt: 1 });
29
+ await this.aiRunScores.createIndex({ runId: 1, createdAt: 1 });
27
30
  this.initialized = true;
28
31
  }
29
32
  async createThread(resourceId, options) {
@@ -406,5 +409,30 @@ export class MongoDBAIStorageService {
406
409
  const result = await this.toolCalls.updateOne({ _id: toolCallId, approvalStatus: 'pending' }, { $set: { approvalStatus: status } });
407
410
  return result.modifiedCount > 0;
408
411
  }
412
+ async saveScore(score) {
413
+ await this.aiRunScores.insertOne({
414
+ _id: crypto.randomUUID(),
415
+ runId: score.runId,
416
+ scorerName: score.scorerName,
417
+ score: score.score,
418
+ reason: score.reason ?? null,
419
+ metadata: score.metadata ?? null,
420
+ createdAt: new Date(),
421
+ });
422
+ }
423
+ async getScores(runId) {
424
+ const rows = await this.aiRunScores
425
+ .find({ runId })
426
+ .sort({ createdAt: 1 })
427
+ .toArray();
428
+ return rows.map((row) => ({
429
+ runId: row.runId,
430
+ scorerName: row.scorerName,
431
+ score: row.score,
432
+ reason: row.reason ?? undefined,
433
+ metadata: row.metadata ?? undefined,
434
+ createdAt: row.createdAt,
435
+ }));
436
+ }
409
437
  async close() { }
410
438
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/mongodb",
3
- "version": "0.12.15",
3
+ "version": "0.12.17",
4
4
  "description": "MongoDB services for Pikku — workflow state, agent runs, secrets and channel stores",
5
5
  "author": "yasser.fadl@gmail.com",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  "prepublishOnly": "yarn build"
19
19
  },
20
20
  "peerDependencies": {
21
- "@pikku/core": "^0.12.80"
21
+ "@pikku/core": "^0.12.82"
22
22
  },
23
23
  "dependencies": {
24
24
  "mongodb": "^6.12.0"
package/src/index.ts CHANGED
@@ -8,7 +8,6 @@ export { MongoDBDeploymentService } from './mongodb-deployment-service.js'
8
8
  export { MongoDBAIStorageService } from './mongodb-ai-storage-service.js'
9
9
  export { MongoDBAgentRunService } from './mongodb-agent-run-service.js'
10
10
  export { MongoDBSecretService } from './mongodb-secret-service.js'
11
- export type { MongoDBSecretServiceConfig } from './mongodb-secret-service.js'
12
11
 
13
12
  export type { WorkflowRunService } from '@pikku/core/workflow'
14
13
  export type { AgentRunService, AgentRunRow } from '@pikku/core/ai-agent'
@@ -2,8 +2,10 @@ import type {
2
2
  AIStorageService,
3
3
  AIRunStateService,
4
4
  CreateRunInput,
5
+ SaveScoreInput,
5
6
  } from '@pikku/core/services'
6
7
  import type { AIThread, AIMessage, AgentRunState } from '@pikku/core/ai-agent'
8
+ import type { AIRunScore } from '@pikku/core/ai-scorer'
7
9
  import type { Db, Collection } from 'mongodb'
8
10
 
9
11
  interface AIThreadDoc {
@@ -46,6 +48,16 @@ interface AIWorkingMemoryDoc {
46
48
  updatedAt: Date
47
49
  }
48
50
 
51
+ interface AIRunScoreDoc {
52
+ _id: string
53
+ runId: string
54
+ scorerName: string
55
+ score: number
56
+ reason: string | null
57
+ metadata: any | null
58
+ createdAt: Date
59
+ }
60
+
49
61
  interface AIRunDoc {
50
62
  _id: string
51
63
  agentName: string
@@ -71,6 +83,7 @@ export class MongoDBAIStorageService
71
83
  private toolCalls!: Collection<AIToolCallDoc>
72
84
  private workingMemory!: Collection<AIWorkingMemoryDoc>
73
85
  private aiRuns!: Collection<AIRunDoc>
86
+ private aiRunScores!: Collection<AIRunScoreDoc>
74
87
 
75
88
  constructor(private db: Db) {}
76
89
 
@@ -83,6 +96,7 @@ export class MongoDBAIStorageService
83
96
  this.workingMemory =
84
97
  this.db.collection<AIWorkingMemoryDoc>('ai_working_memory')
85
98
  this.aiRuns = this.db.collection<AIRunDoc>('ai_run')
99
+ this.aiRunScores = this.db.collection<AIRunScoreDoc>('ai_run_score')
86
100
 
87
101
  await this.threads.createIndex({ resourceId: 1 })
88
102
 
@@ -95,6 +109,8 @@ export class MongoDBAIStorageService
95
109
 
96
110
  await this.aiRuns.createIndex({ threadId: 1, createdAt: 1 })
97
111
 
112
+ await this.aiRunScores.createIndex({ runId: 1, createdAt: 1 })
113
+
98
114
  this.initialized = true
99
115
  }
100
116
 
@@ -574,5 +590,32 @@ export class MongoDBAIStorageService
574
590
  return result.modifiedCount > 0
575
591
  }
576
592
 
593
+ async saveScore(score: SaveScoreInput): Promise<void> {
594
+ await this.aiRunScores.insertOne({
595
+ _id: crypto.randomUUID(),
596
+ runId: score.runId,
597
+ scorerName: score.scorerName,
598
+ score: score.score,
599
+ reason: score.reason ?? null,
600
+ metadata: score.metadata ?? null,
601
+ createdAt: new Date(),
602
+ })
603
+ }
604
+
605
+ async getScores(runId: string): Promise<AIRunScore[]> {
606
+ const rows = await this.aiRunScores
607
+ .find({ runId })
608
+ .sort({ createdAt: 1 })
609
+ .toArray()
610
+ return rows.map((row) => ({
611
+ runId: row.runId,
612
+ scorerName: row.scorerName,
613
+ score: row.score,
614
+ reason: row.reason ?? undefined,
615
+ metadata: row.metadata ?? undefined,
616
+ createdAt: row.createdAt,
617
+ }))
618
+ }
619
+
577
620
  public async close(): Promise<void> {}
578
621
  }