@kybernesis/brain-contracts 0.1.6 → 0.5.0
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/dist/entity.d.ts +135 -135
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +66 -43
- package/dist/entity.js.map +1 -1
- package/dist/fact.d.ts +94 -94
- package/dist/fact.d.ts.map +1 -1
- package/dist/fact.js +17 -15
- package/dist/fact.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sleep.d.ts +77 -77
- package/dist/sleep.d.ts.map +1 -1
- package/dist/sleep.js +27 -25
- package/dist/sleep.js.map +1 -1
- package/dist/storage.d.ts +222 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +28 -0
- package/dist/storage.js.map +1 -0
- package/dist/timeline.d.ts +76 -76
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +12 -10
- package/dist/timeline.js.map +1 -1
- package/package.json +1 -1
package/dist/sleep.js
CHANGED
|
@@ -1,62 +1,64 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { MemoryEdgeRelationSchema, MemoryEdgeMethodSchema, SleepStatusSchema } from './constants.js';
|
|
3
|
+
// Field names are snake_case to match the DB columns / KAD's brain object shapes.
|
|
4
|
+
// This is deliberate and load-bearing — see the header note in `entity.ts`.
|
|
3
5
|
// Maps to sleep_runs table in sleep.db.
|
|
4
6
|
export const SleepRunSchema = z.object({
|
|
5
7
|
id: z.number().int(),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
started_at: z.string(),
|
|
9
|
+
completed_at: z.string().optional(),
|
|
8
10
|
status: SleepStatusSchema,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
checkpoint_step: z.string().optional(),
|
|
12
|
+
checkpoint_data: z.string().optional(),
|
|
11
13
|
metrics: z.string().optional(),
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
error_message: z.string().optional(),
|
|
15
|
+
created_at: z.string(),
|
|
14
16
|
});
|
|
15
17
|
// Maps to memory_edges table in sleep.db.
|
|
16
18
|
export const MemoryEdgeSchema = z.object({
|
|
17
19
|
id: z.number().int(),
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
from_path: z.string(),
|
|
21
|
+
to_path: z.string(), // UNIQUE(from_path, to_path)
|
|
20
22
|
relation: MemoryEdgeRelationSchema,
|
|
21
23
|
weight: z.number(),
|
|
22
24
|
confidence: z.number(),
|
|
23
|
-
|
|
25
|
+
shared_tags: z.string().optional(),
|
|
24
26
|
rationale: z.string().optional(),
|
|
25
27
|
method: MemoryEdgeMethodSchema,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
created_at: z.string(),
|
|
29
|
+
last_verified: z.string().optional(),
|
|
28
30
|
});
|
|
29
31
|
// Maps to maintenance_queue table in sleep.db.
|
|
30
32
|
export const MaintenanceItemTypeSchema = z.enum(['timeline', 'entity', 'file']);
|
|
31
33
|
export const MaintenanceQueueItemSchema = z.object({
|
|
32
34
|
id: z.number().int(),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
item_type: MaintenanceItemTypeSchema,
|
|
36
|
+
item_id: z.string(),
|
|
35
37
|
task: z.string(),
|
|
36
38
|
priority: z.number().int(),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
created_at: z.string(),
|
|
40
|
+
processed_at: z.string().optional(),
|
|
41
|
+
error_message: z.string().optional(),
|
|
40
42
|
});
|
|
41
43
|
// Maps to sleep_telemetry table in sleep.db.
|
|
42
44
|
export const SleepTelemetrySchema = z.object({
|
|
43
45
|
id: z.number().int(),
|
|
44
|
-
|
|
46
|
+
run_id: z.number().int().optional(),
|
|
45
47
|
step: z.string(),
|
|
46
|
-
|
|
48
|
+
event_type: z.string(),
|
|
47
49
|
count: z.number().int(),
|
|
48
|
-
|
|
50
|
+
duration_ms: z.number().int().optional(),
|
|
49
51
|
metadata: z.string().optional(),
|
|
50
|
-
|
|
52
|
+
created_at: z.string(),
|
|
51
53
|
});
|
|
52
54
|
// Maps to tier_transitions table in sleep.db (created lazily).
|
|
53
55
|
export const TierTransitionSchema = z.object({
|
|
54
56
|
id: z.number().int(),
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
item_id: z.number().int(),
|
|
58
|
+
from_tier: z.string().optional(),
|
|
59
|
+
to_tier: z.string(),
|
|
58
60
|
reason: z.string().optional(),
|
|
59
|
-
|
|
61
|
+
created_at: z.string(),
|
|
60
62
|
});
|
|
61
63
|
// Maps to chunk_meta table in vectors.db.
|
|
62
64
|
export const VectorChunkMetaSchema = z.object({
|
|
@@ -64,6 +66,6 @@ export const VectorChunkMetaSchema = z.object({
|
|
|
64
66
|
ts: z.string(),
|
|
65
67
|
source: z.string().optional(),
|
|
66
68
|
content: z.string(),
|
|
67
|
-
|
|
69
|
+
origin_id: z.string().optional(),
|
|
68
70
|
});
|
|
69
71
|
//# sourceMappingURL=sleep.js.map
|
package/dist/sleep.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../src/sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAErG,wCAAwC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IACpB,
|
|
1
|
+
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../src/sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,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CAAC,CAAC,MAAM,CAAC;IAC3C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IACzB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAGH,0CAA0C;AAC1C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IACvB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage provider interfaces — the swappable seam (Stage 1).
|
|
3
|
+
*
|
|
4
|
+
* `brain-core` business logic depends ONLY on these interfaces, obtained via
|
|
5
|
+
* the `setStorageProvider`/`getStorage` seam in brain-core (which mirrors
|
|
6
|
+
* `setLLMProvider`). Each backend package (brain-storage-sqlite today; a
|
|
7
|
+
* libsql impl in Stage 3) implements them with its own dialect.
|
|
8
|
+
*
|
|
9
|
+
* DESIGN RULES (load-bearing — see docs/specs/storage-provider-di-spec.md):
|
|
10
|
+
* - Every method is async. Inserts return `Promise<number>` (the new id), so
|
|
11
|
+
* the impl owns `RETURNING` vs `lastInsertRowid` internally.
|
|
12
|
+
* - No method ever exposes a driver handle (`better-sqlite3.Database`, a libsql
|
|
13
|
+
* client, …). The seam speaks domain operations, never SQL.
|
|
14
|
+
* - Returned object fields are snake_case, matching the v0.2.0 realignment and
|
|
15
|
+
* guarded by schema-naming.test.ts.
|
|
16
|
+
* - The 3 within-kind transactions (mergeEntities, deleteEntity, the vector
|
|
17
|
+
* chunk insert) are IMPL-INTERNAL to their methods — no public transaction
|
|
18
|
+
* primitive is exposed in Stage 1 (decision ①: keep per-kind best-effort
|
|
19
|
+
* semantics; cross-kind unit-of-work is a reserved Stage-3 addition).
|
|
20
|
+
* - Param names stay camelCase at the input edge (unchanged public surface);
|
|
21
|
+
* only RETURNED fields are snake_case.
|
|
22
|
+
*
|
|
23
|
+
* NOTE: this interface establishes the 5-store decomposition + shape. Methods
|
|
24
|
+
* are added as each brain-core module migrates (G1–G6); the surface is complete
|
|
25
|
+
* by the time the conformance suite (G7) runs against it.
|
|
26
|
+
*/
|
|
27
|
+
import type { TenantContext } from './tenant.js';
|
|
28
|
+
import type { TimelineEvent, TimelineEventInput } from './timeline.js';
|
|
29
|
+
import type { Entity, EntityMention, Contradiction, EntityInsight } from './entity.js';
|
|
30
|
+
import type { Fact } from './fact.js';
|
|
31
|
+
import type { EntityType, RelationshipType, InsightType, EventType, FactCategory } from './constants.js';
|
|
32
|
+
export interface TimelineQuery {
|
|
33
|
+
start?: string;
|
|
34
|
+
end?: string;
|
|
35
|
+
type?: EventType;
|
|
36
|
+
search?: string;
|
|
37
|
+
entities?: string[];
|
|
38
|
+
topics?: string[];
|
|
39
|
+
limit?: number;
|
|
40
|
+
offset?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface TimelineStats {
|
|
43
|
+
totalEvents: number;
|
|
44
|
+
byType: Record<EventType, number>;
|
|
45
|
+
dateRange: {
|
|
46
|
+
earliest: string | null;
|
|
47
|
+
latest: string | null;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface VectorChunkInput {
|
|
51
|
+
/** Embedding vector; impl marshals to its own binding format. */
|
|
52
|
+
embedding: number[];
|
|
53
|
+
ts: string;
|
|
54
|
+
source?: string;
|
|
55
|
+
content: string;
|
|
56
|
+
origin_id?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface VectorSearchRow {
|
|
59
|
+
ts: string;
|
|
60
|
+
source: string | null;
|
|
61
|
+
content: string;
|
|
62
|
+
origin_id: string | null;
|
|
63
|
+
distance: number;
|
|
64
|
+
}
|
|
65
|
+
export interface TimelineStore {
|
|
66
|
+
ensureSchema(t: TenantContext): Promise<void>;
|
|
67
|
+
addEvent(t: TenantContext, event: TimelineEventInput): Promise<number>;
|
|
68
|
+
removeEventByPath(t: TenantContext, sourcePath: string): Promise<boolean>;
|
|
69
|
+
updateEvent(t: TenantContext, id: number, updates: Partial<Omit<TimelineEventInput, 'source_path'>>): Promise<void>;
|
|
70
|
+
deleteEventById(t: TenantContext, id: number): Promise<boolean>;
|
|
71
|
+
getEventById(t: TenantContext, id: number): Promise<TimelineEvent | null>;
|
|
72
|
+
getEventByPath(t: TenantContext, sourcePath: string): Promise<TimelineEvent | null>;
|
|
73
|
+
query(t: TenantContext, query: TimelineQuery): Promise<TimelineEvent[]>;
|
|
74
|
+
findRecentDuplicate(t: TenantContext, title: string, withinHours: number): Promise<{
|
|
75
|
+
id: number;
|
|
76
|
+
title: string;
|
|
77
|
+
} | null>;
|
|
78
|
+
incrementEventCount(t: TenantContext, eventId: number): Promise<void>;
|
|
79
|
+
stats(t: TenantContext): Promise<TimelineStats>;
|
|
80
|
+
/** DISTINCT source_paths whose title/tags/entities LIKE the (lowercased) term. (ops.ts recall) */
|
|
81
|
+
findSourcePathsMatching(t: TenantContext, termLower: string, limit: number): Promise<string[]>;
|
|
82
|
+
}
|
|
83
|
+
export interface EntityRelatedHit {
|
|
84
|
+
entity: Entity;
|
|
85
|
+
relationship: string;
|
|
86
|
+
strength: number;
|
|
87
|
+
}
|
|
88
|
+
export interface TypedRelationship {
|
|
89
|
+
entity: Entity;
|
|
90
|
+
relationship: RelationshipType;
|
|
91
|
+
direction: 'outgoing' | 'incoming';
|
|
92
|
+
confidence: number;
|
|
93
|
+
rationale?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface EntityGraphStats {
|
|
96
|
+
totalEntities: number;
|
|
97
|
+
totalMentions: number;
|
|
98
|
+
totalRelations: number;
|
|
99
|
+
byType: Record<EntityType, number>;
|
|
100
|
+
}
|
|
101
|
+
export interface EntityGraphStore {
|
|
102
|
+
ensureSchema(t: TenantContext): Promise<void>;
|
|
103
|
+
findOrCreateEntity(t: TenantContext, name: string, type: EntityType, timestamp: string): Promise<Entity>;
|
|
104
|
+
addEntityAlias(t: TenantContext, entityId: number, alias: string): Promise<void>;
|
|
105
|
+
addEntityMention(t: TenantContext, entityId: number, conversationId: string, sourcePath: string, context: string, timestamp: string, sourceType?: string, confidence?: number): Promise<void>;
|
|
106
|
+
linkEntities(t: TenantContext, sourceId: number, targetId: number, relationship?: RelationshipType): Promise<void>;
|
|
107
|
+
linkEntitiesWithType(t: TenantContext, sourceId: number, targetId: number, options: {
|
|
108
|
+
relationship: RelationshipType;
|
|
109
|
+
confidence?: number;
|
|
110
|
+
rationale?: string;
|
|
111
|
+
method?: string;
|
|
112
|
+
}): Promise<void>;
|
|
113
|
+
getTypedRelationships(t: TenantContext, entityId: number): Promise<TypedRelationship[]>;
|
|
114
|
+
getEntityContext(t: TenantContext, nameOrId: string | number): Promise<{
|
|
115
|
+
entity: Entity;
|
|
116
|
+
mentions: EntityMention[];
|
|
117
|
+
relatedEntities: EntityRelatedHit[];
|
|
118
|
+
} | null>;
|
|
119
|
+
searchEntities(t: TenantContext, query: string, options?: {
|
|
120
|
+
type?: EntityType;
|
|
121
|
+
limit?: number;
|
|
122
|
+
}): Promise<Entity[]>;
|
|
123
|
+
getRecentEntities(t: TenantContext, limit?: number): Promise<Entity[]>;
|
|
124
|
+
getMostMentionedEntities(t: TenantContext, options?: {
|
|
125
|
+
type?: EntityType;
|
|
126
|
+
limit?: number;
|
|
127
|
+
}): Promise<Entity[]>;
|
|
128
|
+
stats(t: TenantContext): Promise<EntityGraphStats>;
|
|
129
|
+
detectEntitiesInQuery(t: TenantContext, query: string): Promise<{
|
|
130
|
+
entities: string[];
|
|
131
|
+
remainingQuery: string;
|
|
132
|
+
}>;
|
|
133
|
+
mergeEntities(t: TenantContext, keepId: number, removeId: number, reason: string, confidence?: number, aiRationale?: string, mergedBy?: string): Promise<{
|
|
134
|
+
mentions_moved: number;
|
|
135
|
+
relations_moved: number;
|
|
136
|
+
}>;
|
|
137
|
+
deleteEntity(t: TenantContext, entityId: number, reason: string, mergedBy?: string): Promise<void>;
|
|
138
|
+
getEntityProfile(t: TenantContext, entityId: number): Promise<{
|
|
139
|
+
profile: string;
|
|
140
|
+
generated_at: string;
|
|
141
|
+
fact_count: number;
|
|
142
|
+
} | null>;
|
|
143
|
+
saveEntityProfile(t: TenantContext, entityId: number, profile: string, factCount: number): Promise<void>;
|
|
144
|
+
createContradiction(t: TenantContext, entityId: number, factAId: number, factBId: number, factA: string, factB: string, description: string): Promise<number>;
|
|
145
|
+
getOpenContradictions(t: TenantContext, entityId: number): Promise<Contradiction[]>;
|
|
146
|
+
resolveContradiction(t: TenantContext, contradictionId: number, resolvedBy: string): Promise<void>;
|
|
147
|
+
applyContradictions(t: TenantContext, entityId: number, factIds: number[]): Promise<void>;
|
|
148
|
+
saveEntityInsight(t: TenantContext, entityId: number, insightType: InsightType, insight: string, reasoning: string, confidence: number, sourceEntityIds?: number[], expiresAt?: string): Promise<number>;
|
|
149
|
+
getEntityInsights(t: TenantContext, entityId: number, minConfidence?: number): Promise<EntityInsight[]>;
|
|
150
|
+
markInsightsStale(t: TenantContext, entityId: number): Promise<void>;
|
|
151
|
+
getEntitiesForReasoning(t: TenantContext, limit?: number, staleDays?: number, recencyDays?: number): Promise<Array<{
|
|
152
|
+
id: number;
|
|
153
|
+
name: string;
|
|
154
|
+
type: string;
|
|
155
|
+
}>>;
|
|
156
|
+
markEntityReasoned(t: TenantContext, entityId: number): Promise<void>;
|
|
157
|
+
pinEntity(t: TenantContext, entityId: number, pinned?: boolean): Promise<void>;
|
|
158
|
+
listPinned(t: TenantContext, type?: EntityType): Promise<Entity[]>;
|
|
159
|
+
/** Bump access_count + last_accessed for an entity. (ops.ts recall tracking) */
|
|
160
|
+
trackAccess(t: TenantContext, entityId: number): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
/** Insert shape for storeFact — server fills id/created_at/is_latest/access_count/is_retracted. */
|
|
163
|
+
export type StoreFactInput = Omit<Fact, 'id' | 'created_at' | 'is_latest' | 'access_count' | 'is_retracted'>;
|
|
164
|
+
export interface FactStore {
|
|
165
|
+
ensureFactsTable(t: TenantContext): Promise<void>;
|
|
166
|
+
storeFact(t: TenantContext, fact: StoreFactInput): Promise<number>;
|
|
167
|
+
retractFact(t: TenantContext, factId: number, retractedBy?: string): Promise<void>;
|
|
168
|
+
reinforceFact(t: TenantContext, factId: number): Promise<void>;
|
|
169
|
+
getFactById(t: TenantContext, factId: number): Promise<Fact | null>;
|
|
170
|
+
getFactsForEntity(t: TenantContext, entity: string, options?: {
|
|
171
|
+
latestOnly?: boolean;
|
|
172
|
+
limit?: number;
|
|
173
|
+
category?: FactCategory;
|
|
174
|
+
}): Promise<Fact[]>;
|
|
175
|
+
markFactSuperseded(t: TenantContext, oldFactId: number, newFactId: number): Promise<void>;
|
|
176
|
+
factsCount(t: TenantContext): Promise<number>;
|
|
177
|
+
listFacts(t: TenantContext, options?: {
|
|
178
|
+
limit?: number;
|
|
179
|
+
offset?: number;
|
|
180
|
+
latestOnly?: boolean;
|
|
181
|
+
category?: FactCategory;
|
|
182
|
+
}): Promise<Fact[]>;
|
|
183
|
+
listTemporalFacts(t: TenantContext, options?: {
|
|
184
|
+
includeExpired?: boolean;
|
|
185
|
+
limit?: number;
|
|
186
|
+
}): Promise<Fact[]>;
|
|
187
|
+
searchFactsFts(t: TenantContext, query: string, limit?: number): Promise<Fact[]>;
|
|
188
|
+
/**
|
|
189
|
+
* Active (latest, non-expired) fact CONTENTS for a category. (user-profile.ts)
|
|
190
|
+
* order 'frecency' = confidence DESC, access_count DESC (fallback confidence-only
|
|
191
|
+
* if access_count column is absent); 'recent' = timestamp DESC.
|
|
192
|
+
*/
|
|
193
|
+
getFactContentsByCategory(t: TenantContext, category: string, limit: number, order: 'frecency' | 'recent'): Promise<string[]>;
|
|
194
|
+
}
|
|
195
|
+
export interface MemoryEdgeHit {
|
|
196
|
+
related_path: string;
|
|
197
|
+
confidence: number;
|
|
198
|
+
shared_tags: string;
|
|
199
|
+
}
|
|
200
|
+
export interface SleepStore {
|
|
201
|
+
/** memory_edges neighbours of a source path. Returns [] if the table doesn't exist yet. */
|
|
202
|
+
getRelatedEdges(t: TenantContext, sourcePath: string, limit: number): Promise<MemoryEdgeHit[]>;
|
|
203
|
+
}
|
|
204
|
+
export interface VectorStore {
|
|
205
|
+
/** Can the vector backend be opened for this tenant? (loads sqlite-vec) */
|
|
206
|
+
available(t: TenantContext): Promise<boolean>;
|
|
207
|
+
hasOrigin(t: TenantContext, originId: string): Promise<boolean>;
|
|
208
|
+
insertChunk(t: TenantContext, chunk: VectorChunkInput): Promise<number>;
|
|
209
|
+
search(t: TenantContext, embedding: number[], limit: number): Promise<VectorSearchRow[]>;
|
|
210
|
+
stats(t: TenantContext): Promise<{
|
|
211
|
+
count: number;
|
|
212
|
+
available: boolean;
|
|
213
|
+
}>;
|
|
214
|
+
}
|
|
215
|
+
export interface StorageProvider {
|
|
216
|
+
timeline: TimelineStore;
|
|
217
|
+
entities: EntityGraphStore;
|
|
218
|
+
facts: FactStore;
|
|
219
|
+
sleep: SleepStore;
|
|
220
|
+
vectors: VectorStore;
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK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AC;CAC/H;AASD,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,2FAA2F;IAC3F,eAAe,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;CAChG;AAMD,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,SAAS,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAChE,WAAW,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxE,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IACzF,KAAK,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACzE;AAID,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,aAAa,CAAC;IACxB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC;CACtB"}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage provider interfaces — the swappable seam (Stage 1).
|
|
3
|
+
*
|
|
4
|
+
* `brain-core` business logic depends ONLY on these interfaces, obtained via
|
|
5
|
+
* the `setStorageProvider`/`getStorage` seam in brain-core (which mirrors
|
|
6
|
+
* `setLLMProvider`). Each backend package (brain-storage-sqlite today; a
|
|
7
|
+
* libsql impl in Stage 3) implements them with its own dialect.
|
|
8
|
+
*
|
|
9
|
+
* DESIGN RULES (load-bearing — see docs/specs/storage-provider-di-spec.md):
|
|
10
|
+
* - Every method is async. Inserts return `Promise<number>` (the new id), so
|
|
11
|
+
* the impl owns `RETURNING` vs `lastInsertRowid` internally.
|
|
12
|
+
* - No method ever exposes a driver handle (`better-sqlite3.Database`, a libsql
|
|
13
|
+
* client, …). The seam speaks domain operations, never SQL.
|
|
14
|
+
* - Returned object fields are snake_case, matching the v0.2.0 realignment and
|
|
15
|
+
* guarded by schema-naming.test.ts.
|
|
16
|
+
* - The 3 within-kind transactions (mergeEntities, deleteEntity, the vector
|
|
17
|
+
* chunk insert) are IMPL-INTERNAL to their methods — no public transaction
|
|
18
|
+
* primitive is exposed in Stage 1 (decision ①: keep per-kind best-effort
|
|
19
|
+
* semantics; cross-kind unit-of-work is a reserved Stage-3 addition).
|
|
20
|
+
* - Param names stay camelCase at the input edge (unchanged public surface);
|
|
21
|
+
* only RETURNED fields are snake_case.
|
|
22
|
+
*
|
|
23
|
+
* NOTE: this interface establishes the 5-store decomposition + shape. Methods
|
|
24
|
+
* are added as each brain-core module migrates (G1–G6); the surface is complete
|
|
25
|
+
* by the time the conformance suite (G7) runs against it.
|
|
26
|
+
*/
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG"}
|
package/dist/timeline.d.ts
CHANGED
|
@@ -3,134 +3,134 @@ export declare const TimelineEventSchema: z.ZodObject<{
|
|
|
3
3
|
id: z.ZodNumber;
|
|
4
4
|
type: z.ZodEnum<["conversation", "idea", "file", "transcript", "note", "intake"]>;
|
|
5
5
|
timestamp: z.ZodString;
|
|
6
|
-
|
|
6
|
+
end_timestamp: z.ZodOptional<z.ZodString>;
|
|
7
7
|
title: z.ZodString;
|
|
8
8
|
summary: z.ZodOptional<z.ZodString>;
|
|
9
|
-
|
|
9
|
+
source_path: z.ZodString;
|
|
10
10
|
entities: z.ZodArray<z.ZodString, "many">;
|
|
11
11
|
topics: z.ZodArray<z.ZodString, "many">;
|
|
12
12
|
priority: z.ZodNumber;
|
|
13
|
-
|
|
13
|
+
decay_score: z.ZodNumber;
|
|
14
14
|
tier: z.ZodEnum<["hot", "warm", "archive"]>;
|
|
15
15
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
last_enriched: z.ZodOptional<z.ZodString>;
|
|
17
|
+
access_count: z.ZodNumber;
|
|
18
|
+
is_pinned: z.ZodBoolean;
|
|
19
|
+
last_accessed: z.ZodOptional<z.ZodString>;
|
|
20
|
+
project_id: z.ZodOptional<z.ZodString>;
|
|
21
21
|
classification: z.ZodOptional<z.ZodString>;
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
connection_id: z.ZodOptional<z.ZodString>;
|
|
23
|
+
source_did: z.ZodOptional<z.ZodString>;
|
|
24
24
|
}, "strip", z.ZodTypeAny, {
|
|
25
25
|
id: number;
|
|
26
26
|
type: "conversation" | "idea" | "file" | "transcript" | "note" | "intake";
|
|
27
|
+
priority: number;
|
|
28
|
+
decay_score: number;
|
|
29
|
+
tier: "hot" | "warm" | "archive";
|
|
30
|
+
access_count: number;
|
|
31
|
+
is_pinned: boolean;
|
|
32
|
+
source_path: string;
|
|
27
33
|
timestamp: string;
|
|
28
|
-
title: string;
|
|
29
|
-
sourcePath: string;
|
|
30
34
|
entities: string[];
|
|
35
|
+
title: string;
|
|
31
36
|
topics: string[];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
tier: "hot" | "warm" | "archive";
|
|
35
|
-
accessCount: number;
|
|
36
|
-
isPinned: boolean;
|
|
37
|
-
endTimestamp?: string | undefined;
|
|
38
|
-
summary?: string | undefined;
|
|
37
|
+
last_accessed?: string | undefined;
|
|
38
|
+
project_id?: string | undefined;
|
|
39
39
|
tags?: string[] | undefined;
|
|
40
|
-
lastEnriched?: string | undefined;
|
|
41
|
-
lastAccessed?: string | undefined;
|
|
42
|
-
projectId?: string | undefined;
|
|
43
40
|
classification?: string | undefined;
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
connection_id?: string | undefined;
|
|
42
|
+
source_did?: string | undefined;
|
|
43
|
+
end_timestamp?: string | undefined;
|
|
44
|
+
summary?: string | undefined;
|
|
45
|
+
last_enriched?: string | undefined;
|
|
46
46
|
}, {
|
|
47
47
|
id: number;
|
|
48
48
|
type: "conversation" | "idea" | "file" | "transcript" | "note" | "intake";
|
|
49
|
+
priority: number;
|
|
50
|
+
decay_score: number;
|
|
51
|
+
tier: "hot" | "warm" | "archive";
|
|
52
|
+
access_count: number;
|
|
53
|
+
is_pinned: boolean;
|
|
54
|
+
source_path: string;
|
|
49
55
|
timestamp: string;
|
|
50
|
-
title: string;
|
|
51
|
-
sourcePath: string;
|
|
52
56
|
entities: string[];
|
|
57
|
+
title: string;
|
|
53
58
|
topics: string[];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
tier: "hot" | "warm" | "archive";
|
|
57
|
-
accessCount: number;
|
|
58
|
-
isPinned: boolean;
|
|
59
|
-
endTimestamp?: string | undefined;
|
|
60
|
-
summary?: string | undefined;
|
|
59
|
+
last_accessed?: string | undefined;
|
|
60
|
+
project_id?: string | undefined;
|
|
61
61
|
tags?: string[] | undefined;
|
|
62
|
-
lastEnriched?: string | undefined;
|
|
63
|
-
lastAccessed?: string | undefined;
|
|
64
|
-
projectId?: string | undefined;
|
|
65
62
|
classification?: string | undefined;
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
connection_id?: string | undefined;
|
|
64
|
+
source_did?: string | undefined;
|
|
65
|
+
end_timestamp?: string | undefined;
|
|
66
|
+
summary?: string | undefined;
|
|
67
|
+
last_enriched?: string | undefined;
|
|
68
68
|
}>;
|
|
69
69
|
export type TimelineEvent = z.infer<typeof TimelineEventSchema>;
|
|
70
70
|
export declare const TimelineEventInputSchema: z.ZodObject<Omit<{
|
|
71
71
|
id: z.ZodNumber;
|
|
72
72
|
type: z.ZodEnum<["conversation", "idea", "file", "transcript", "note", "intake"]>;
|
|
73
73
|
timestamp: z.ZodString;
|
|
74
|
-
|
|
74
|
+
end_timestamp: z.ZodOptional<z.ZodString>;
|
|
75
75
|
title: z.ZodString;
|
|
76
76
|
summary: z.ZodOptional<z.ZodString>;
|
|
77
|
-
|
|
77
|
+
source_path: z.ZodString;
|
|
78
78
|
entities: z.ZodArray<z.ZodString, "many">;
|
|
79
79
|
topics: z.ZodArray<z.ZodString, "many">;
|
|
80
80
|
priority: z.ZodNumber;
|
|
81
|
-
|
|
81
|
+
decay_score: z.ZodNumber;
|
|
82
82
|
tier: z.ZodEnum<["hot", "warm", "archive"]>;
|
|
83
83
|
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
last_enriched: z.ZodOptional<z.ZodString>;
|
|
85
|
+
access_count: z.ZodNumber;
|
|
86
|
+
is_pinned: z.ZodBoolean;
|
|
87
|
+
last_accessed: z.ZodOptional<z.ZodString>;
|
|
88
|
+
project_id: z.ZodOptional<z.ZodString>;
|
|
89
89
|
classification: z.ZodOptional<z.ZodString>;
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
connection_id: z.ZodOptional<z.ZodString>;
|
|
91
|
+
source_did: z.ZodOptional<z.ZodString>;
|
|
92
92
|
}, "id">, "strip", z.ZodTypeAny, {
|
|
93
93
|
type: "conversation" | "idea" | "file" | "transcript" | "note" | "intake";
|
|
94
|
+
priority: number;
|
|
95
|
+
decay_score: number;
|
|
96
|
+
tier: "hot" | "warm" | "archive";
|
|
97
|
+
access_count: number;
|
|
98
|
+
is_pinned: boolean;
|
|
99
|
+
source_path: string;
|
|
94
100
|
timestamp: string;
|
|
95
|
-
title: string;
|
|
96
|
-
sourcePath: string;
|
|
97
101
|
entities: string[];
|
|
102
|
+
title: string;
|
|
98
103
|
topics: string[];
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
tier: "hot" | "warm" | "archive";
|
|
102
|
-
accessCount: number;
|
|
103
|
-
isPinned: boolean;
|
|
104
|
-
endTimestamp?: string | undefined;
|
|
105
|
-
summary?: string | undefined;
|
|
104
|
+
last_accessed?: string | undefined;
|
|
105
|
+
project_id?: string | undefined;
|
|
106
106
|
tags?: string[] | undefined;
|
|
107
|
-
lastEnriched?: string | undefined;
|
|
108
|
-
lastAccessed?: string | undefined;
|
|
109
|
-
projectId?: string | undefined;
|
|
110
107
|
classification?: string | undefined;
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
connection_id?: string | undefined;
|
|
109
|
+
source_did?: string | undefined;
|
|
110
|
+
end_timestamp?: string | undefined;
|
|
111
|
+
summary?: string | undefined;
|
|
112
|
+
last_enriched?: string | undefined;
|
|
113
113
|
}, {
|
|
114
114
|
type: "conversation" | "idea" | "file" | "transcript" | "note" | "intake";
|
|
115
|
+
priority: number;
|
|
116
|
+
decay_score: number;
|
|
117
|
+
tier: "hot" | "warm" | "archive";
|
|
118
|
+
access_count: number;
|
|
119
|
+
is_pinned: boolean;
|
|
120
|
+
source_path: string;
|
|
115
121
|
timestamp: string;
|
|
116
|
-
title: string;
|
|
117
|
-
sourcePath: string;
|
|
118
122
|
entities: string[];
|
|
123
|
+
title: string;
|
|
119
124
|
topics: string[];
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
tier: "hot" | "warm" | "archive";
|
|
123
|
-
accessCount: number;
|
|
124
|
-
isPinned: boolean;
|
|
125
|
-
endTimestamp?: string | undefined;
|
|
126
|
-
summary?: string | undefined;
|
|
125
|
+
last_accessed?: string | undefined;
|
|
126
|
+
project_id?: string | undefined;
|
|
127
127
|
tags?: string[] | undefined;
|
|
128
|
-
lastEnriched?: string | undefined;
|
|
129
|
-
lastAccessed?: string | undefined;
|
|
130
|
-
projectId?: string | undefined;
|
|
131
128
|
classification?: string | undefined;
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
connection_id?: string | undefined;
|
|
130
|
+
source_did?: string | undefined;
|
|
131
|
+
end_timestamp?: string | undefined;
|
|
132
|
+
summary?: string | undefined;
|
|
133
|
+
last_enriched?: string | undefined;
|
|
134
134
|
}>;
|
|
135
135
|
export type TimelineEventInput = z.infer<typeof TimelineEventInputSchema>;
|
|
136
136
|
//# sourceMappingURL=timeline.d.ts.map
|
package/dist/timeline.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuB9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAGhE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAyC,CAAC;AAC/E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
package/dist/timeline.js
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { EventTypeSchema, TierSchema } from './constants.js';
|
|
3
|
+
// Field names are snake_case to match KAD's canonical brain object interfaces.
|
|
4
|
+
// This is deliberate and load-bearing — see the header note in `entity.ts`.
|
|
3
5
|
// Maps to timeline_events table in timeline.db.
|
|
4
6
|
export const TimelineEventSchema = z.object({
|
|
5
7
|
id: z.number().int(),
|
|
6
8
|
type: EventTypeSchema,
|
|
7
9
|
timestamp: z.string(),
|
|
8
|
-
|
|
10
|
+
end_timestamp: z.string().optional(),
|
|
9
11
|
title: z.string(),
|
|
10
12
|
summary: z.string().optional(),
|
|
11
|
-
|
|
13
|
+
source_path: z.string(), // UNIQUE
|
|
12
14
|
entities: z.array(z.string()),
|
|
13
15
|
topics: z.array(z.string()),
|
|
14
16
|
priority: z.number(),
|
|
15
|
-
|
|
17
|
+
decay_score: z.number(),
|
|
16
18
|
tier: TierSchema,
|
|
17
19
|
tags: z.array(z.string()).optional(),
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
last_enriched: z.string().optional(),
|
|
21
|
+
access_count: z.number().int(),
|
|
22
|
+
is_pinned: z.boolean(),
|
|
23
|
+
last_accessed: z.string().optional(),
|
|
22
24
|
// 4 flat scope columns (no nested scopes object — matches KAD wire shape)
|
|
23
|
-
|
|
25
|
+
project_id: z.string().optional(),
|
|
24
26
|
classification: z.string().optional(),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
connection_id: z.string().optional(),
|
|
28
|
+
source_did: z.string().optional(),
|
|
27
29
|
});
|
|
28
30
|
// Input shape for addToTimeline — id is assigned by the DB.
|
|
29
31
|
export const TimelineEventInputSchema = TimelineEventSchema.omit({ id: true });
|