feat: add isolated memory spaces
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { createHash, randomUUID } from 'node:crypto';
|
||||
|
||||
import type { Fact, FactTopic, Topic } from '../types/api';
|
||||
import type { FactRecord, TopicRecord } from '../types/domain';
|
||||
import type { Fact, FactTopic, Space, Topic } from '../types/api';
|
||||
import type { FactRecord, SpaceRecord, TopicRecord } from '../types/domain';
|
||||
|
||||
export function normalizeTopicName(name: string): string {
|
||||
return name.trim().replace(/\s+/g, ' ').toLowerCase();
|
||||
@@ -11,6 +11,14 @@ export function canonicalizeTopicName(name: string): string {
|
||||
return name.trim().replace(/\s+/g, ' ');
|
||||
}
|
||||
|
||||
export function normalizeSpaceName(name: string): string {
|
||||
return normalizeTopicName(name);
|
||||
}
|
||||
|
||||
export function canonicalizeSpaceName(name: string): string {
|
||||
return canonicalizeTopicName(name);
|
||||
}
|
||||
|
||||
export function nowIsoString(): string {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
@@ -71,9 +79,22 @@ export function cosineSimilarity(left: number[], right: number[]): number {
|
||||
return dot / (Math.sqrt(leftMagnitude) * Math.sqrt(rightMagnitude));
|
||||
}
|
||||
|
||||
export function mapSpaceRow(record: SpaceRecord): Space {
|
||||
return {
|
||||
id: record.id,
|
||||
name: record.name,
|
||||
normalizedName: record.normalized_name,
|
||||
description: record.description,
|
||||
metadata: deserializeMetadata(record.metadata) as Space['metadata'],
|
||||
createdAt: record.created_at,
|
||||
updatedAt: record.updated_at,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapTopicRow(record: TopicRecord): Topic {
|
||||
return {
|
||||
id: record.id,
|
||||
spaceId: record.space_id,
|
||||
name: record.name,
|
||||
normalizedName: record.normalized_name,
|
||||
category: record.category,
|
||||
@@ -88,6 +109,7 @@ export function mapTopicRow(record: TopicRecord): Topic {
|
||||
export function mapFactRow(record: FactRecord, topics: FactTopic[]): Fact {
|
||||
return {
|
||||
id: record.id,
|
||||
spaceId: record.space_id,
|
||||
statement: record.statement,
|
||||
summary: record.summary,
|
||||
source: record.source,
|
||||
|
||||
Reference in New Issue
Block a user