fix(core): misc fixes

This commit is contained in:
2026-07-12 12:28:14 +05:30
parent 01b2e650f3
commit 0dcb968670
8 changed files with 42 additions and 41 deletions

View File

@@ -106,7 +106,9 @@ Guidelines:
if (this.bufferRepo) {
try {
recentEntries = this.bufferRepo.listForOwner(entity.id);
} catch {}
} catch {
// bufferRepo may not be available
}
}
// --- Recent memory ---

View File

@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import Database from "better-sqlite3";
import { WorldState, Entity, AttributeVisibility } from "@omnia/core";
import { WorldState, Entity } from "@omnia/core";
import { BufferRepository, LedgerRepository } from "@omnia/memory";
import { ActorPromptBuilder } from "../src/actor-prompt-builder";

View File

@@ -154,7 +154,7 @@ export function splitBufferForHandoff(
"several minutes ago",
]);
let watermarkStartIndex = sorted.length;
let watermarkStartIndex: number;
// 1. Mark last K entries as watermark
if (sorted.length > K) {
@@ -243,7 +243,7 @@ ${candidatesList}
const ledgerEntries: LedgerEntry[] = [];
for (const chunk of result.chunks) {
let embedding: number[] = [];
let embedding: number[];
try {
embedding = await this.embedProvider.embed(chunk.content);
} catch (err) {

View File

@@ -92,28 +92,27 @@ export class LedgerRepository {
})();
}
private mapRowToEntry(row: any, involvedEntityIds: string[]): LedgerEntry {
let embedding: number[] = [];
if (row.embedding) {
const buffer = row.embedding as Buffer;
const floatArray = new Float32Array(
buffer.buffer,
buffer.byteOffset,
buffer.byteLength / Float32Array.BYTES_PER_ELEMENT
);
embedding = Array.from(floatArray);
}
private mapRowToEntry(row: Record<string, unknown>, involvedEntityIds: string[]): LedgerEntry {
const embedding: number[] = row.embedding
? Array.from(
new Float32Array(
(row.embedding as Buffer).buffer,
(row.embedding as Buffer).byteOffset,
(row.embedding as Buffer).byteLength / Float32Array.BYTES_PER_ELEMENT
)
)
: [];
return {
id: row.id,
ownerId: row.owner_id,
timestamp: row.timestamp,
locationId: row.location_id,
id: row.id as string,
ownerId: row.owner_id as string,
timestamp: row.timestamp as string,
locationId: row.location_id as string | null,
involvedEntityIds,
content: row.content,
quotes: JSON.parse(row.quotes_json || "[]"),
importance: row.importance,
embedding: embedding,
content: row.content as string,
quotes: JSON.parse((row.quotes_json as string) || "[]"),
importance: row.importance as number,
embedding,
};
}
@@ -126,7 +125,7 @@ export class LedgerRepository {
WHERE id = ?
`
)
.get(id) as any;
.get(id) as Record<string, unknown> | undefined;
if (!row) return null;
@@ -163,7 +162,7 @@ export class LedgerRepository {
le.importance >= 8
`;
const params: any[] = [ownerId];
const params: (string | number)[] = [ownerId];
if (currentLocationId) {
query += ` OR le.location_id = ?`;
@@ -183,7 +182,7 @@ export class LedgerRepository {
`;
params.push(limit);
const rows = this.db.prepare(query).all(...params) as any[];
const rows = this.db.prepare(query).all(...params) as Record<string, any>[];
if (rows.length === 0) return [];
@@ -223,7 +222,7 @@ export class LedgerRepository {
LIMIT 1
`
)
.get(ownerId, timestamp) as any;
.get(ownerId, timestamp) as Record<string, unknown> | undefined;
if (preceding) {
neighbors.push(this.mapRowToEntry(preceding, []));
@@ -240,7 +239,7 @@ export class LedgerRepository {
LIMIT 1
`
)
.get(ownerId, timestamp) as any;
.get(ownerId, timestamp) as Record<string, unknown> | undefined;
if (succeeding) {
neighbors.push(this.mapRowToEntry(succeeding, []));
@@ -310,7 +309,7 @@ export class LedgerRepository {
scored.sort((a, b) => b.score - a.score);
const selected = scored.slice(0, limit).map((s) => s.entry);
let finalEntries = [...selected];
const finalEntries = [...selected];
// Optionally retrieve associative neighbors
if (includeAssociativeNeighbors && selected.length > 0) {

View File

@@ -152,7 +152,7 @@ describe("Memory Handoff Tests (Tier 1)", () => {
const success = await engine.runHandoff(entity, entries, now);
expect(success).toBe(true);
const ledgerRows = db.prepare("SELECT * FROM ledger_entries WHERE owner_id = ?").all("alice") as any[];
const ledgerRows = db.prepare("SELECT * FROM ledger_entries WHERE owner_id = ?").all("alice") as Record<string, unknown>[];
expect(ledgerRows.length).toBe(1);
expect(ledgerRows[0].content).toBe("Alice initiated dialogue and performed various tasks.");
expect(JSON.parse(ledgerRows[0].quotes_json)).toEqual(["Event 0"]);