This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IdentityDB, type Fact as IdentityFact } from 'identitydb';
|
||||
import { IdentityDB, extractFact, type Fact as IdentityFact, type FactExtractor } from 'identitydb';
|
||||
import type { BoxBrainMemoryStore, FactDraft, MemorySpace, ScheduleEntry, StoredFact } from './types';
|
||||
|
||||
function normalizeTopics(topics: string[]): string[] {
|
||||
@@ -74,6 +74,17 @@ export class InMemoryMemoryStore implements BoxBrainMemoryStore {
|
||||
this.schedules.set(spaceId, kept);
|
||||
return entries.length - kept.length;
|
||||
}
|
||||
|
||||
async ingestStatement(spaceId: string, statement: string, extractor: FactExtractor): Promise<StoredFact> {
|
||||
const extracted = await extractFact(statement, extractor);
|
||||
return this.addFact(spaceId, {
|
||||
statement: extracted.statement ?? statement,
|
||||
topics: extracted.topics.map((t) => t.name),
|
||||
...(typeof extracted.confidence === 'number' ? { confidence: extracted.confidence } : {}),
|
||||
...(typeof extracted.source === 'string' ? { source: extracted.source } : {}),
|
||||
...(extracted.metadata !== undefined && extracted.metadata !== null ? { metadata: extracted.metadata as Record<string, unknown> } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface IdentityDbMemoryStoreOptions {
|
||||
@@ -172,6 +183,11 @@ export class IdentityDbMemoryStore implements BoxBrainMemoryStore {
|
||||
return 0;
|
||||
}
|
||||
|
||||
async ingestStatement(spaceId: string, statement: string, extractor: FactExtractor): Promise<StoredFact> {
|
||||
const fact = await this.options.db.ingestStatement(statement, { extractor, spaceName: spaceId });
|
||||
return this.fromIdentityFact(fact);
|
||||
}
|
||||
|
||||
private fromIdentityFact(fact: IdentityFact): StoredFact {
|
||||
const metadata = typeof fact.metadata === 'object' && fact.metadata !== null && !Array.isArray(fact.metadata) ? fact.metadata as Record<string, unknown> : undefined;
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user