@happyvertical/smrt-facts 0.30.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.
@@ -0,0 +1,371 @@
1
+ import { PromptConfigOverrideInput } from '@happyvertical/smrt-prompts';
2
+ import { SmrtObject } from '@happyvertical/smrt-core';
3
+ import { SmrtObjectOptions } from '@happyvertical/smrt-core';
4
+
5
+ /**
6
+ * Entity briefing - summary of all facts about an entity
7
+ */
8
+ export declare interface EntityBriefing {
9
+ entityType: string;
10
+ entityId: string;
11
+ facts: Fact[];
12
+ totalCount: number;
13
+ byType: Record<string, number>;
14
+ byStatus: Record<string, number>;
15
+ }
16
+
17
+ /**
18
+ * How a fact evolved from its predecessor in the evolution chain.
19
+ */
20
+ export declare type EvolutionType = 'original' | 'correction' | 'refinement' | 'contradiction' | 'extension' | 'merge';
21
+
22
+ declare class Fact extends SmrtObject {
23
+ textRefined: string;
24
+ textRaw: string;
25
+ type: string;
26
+ status: string;
27
+ domain: string;
28
+ /**
29
+ * Self-referencing pointer to the predecessor fact in an evolution chain.
30
+ *
31
+ * This is NOT a structural hierarchy edge — Fact does not extend
32
+ * SmrtHierarchical. The chain represents knowledge evolution: an original
33
+ * fact, then corrections, refinements, contradictions, or extensions of
34
+ * that fact. See `evolutionType` for the kind of step.
35
+ */
36
+ previousFactId: string;
37
+ evolutionType: string;
38
+ sourceCount: number;
39
+ confidence: number;
40
+ metadata: string;
41
+ tenantId: string | null;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ constructor(options?: FactOptions);
45
+ getMetadata(): FactMetadata;
46
+ setMetadata(data: FactMetadata): void;
47
+ updateMetadata(updates: Partial<FactMetadata>): void;
48
+ getType(): FactType;
49
+ getStatus(): FactStatus;
50
+ getEvolutionType(): EvolutionType;
51
+ isActive(): boolean;
52
+ isSuperseded(): boolean;
53
+ /**
54
+ * Whether this fact has a predecessor in the evolution chain.
55
+ *
56
+ * Returns false for the framework default (`''`) and for any nullish
57
+ * value — defensive against rows whose `previous_fact_id` column is
58
+ * NULL (e.g. after a migration that left root facts un-backfilled).
59
+ */
60
+ hasPredecessor(): boolean;
61
+ /**
62
+ * Get the predecessor fact (the prior version in the evolution chain).
63
+ */
64
+ getPredecessor(): Promise<Fact | null>;
65
+ /**
66
+ * Get successor facts (facts that evolved directly from this one).
67
+ */
68
+ getSuccessors(): Promise<Fact[]>;
69
+ /**
70
+ * Get all sources for this fact
71
+ */
72
+ getSources(): Promise<FactSource[]>;
73
+ /**
74
+ * Get all subjects linked to this fact
75
+ */
76
+ getSubjects(): Promise<FactSubject[]>;
77
+ }
78
+
79
+ export declare interface FactClaimSupportAssessment {
80
+ status: FactClaimSupportStatus;
81
+ matchedFactIds: string[];
82
+ matchedEvidenceIds: string[];
83
+ rationale: string;
84
+ confidence?: number;
85
+ }
86
+
87
+ export declare interface FactClaimSupportCandidate {
88
+ id?: string | null;
89
+ statement: string;
90
+ evidence?: Array<{
91
+ id?: string | null;
92
+ status?: FactEvidenceStatus | null;
93
+ quote?: string | null;
94
+ sourceTitle?: string | null;
95
+ sourceUrl?: string | null;
96
+ locator?: string | null;
97
+ }>;
98
+ }
99
+
100
+ export declare interface FactClaimSupportOptions {
101
+ tenantId?: string | null;
102
+ promptOverride?: PromptConfigOverrideInput;
103
+ }
104
+
105
+ export declare type FactClaimSupportStatus = 'supported' | 'unsupported' | 'contradicted' | 'needs_review';
106
+
107
+ /**
108
+ * Options for creating a FactContent join
109
+ */
110
+ export declare interface FactContentOptions extends SmrtObjectOptions {
111
+ id?: string;
112
+ factId?: string;
113
+ contentId?: string;
114
+ relationship?: FactContentRelationship;
115
+ metadata?: string | Record<string, any>;
116
+ tenantId?: string | null;
117
+ }
118
+
119
+ /**
120
+ * Relationship between a fact and content
121
+ */
122
+ export declare type FactContentRelationship = 'extracted_from' | 'referenced_in' | 'supports' | 'contradicts' | 'related';
123
+
124
+ /**
125
+ * Options for creating concrete evidence for a fact.
126
+ */
127
+ export declare interface FactEvidenceOptions extends SmrtObjectOptions {
128
+ id?: string;
129
+ factId?: string;
130
+ evidenceKey?: string;
131
+ status?: FactEvidenceStatus;
132
+ sourceKind?: string;
133
+ sourceId?: string;
134
+ sourceUrl?: string;
135
+ sourceTitle?: string;
136
+ quote?: string;
137
+ locator?: string;
138
+ extractionMethod?: string;
139
+ confidence?: number;
140
+ metadata?: string | Record<string, any>;
141
+ tenantId?: string | null;
142
+ createdAt?: Date;
143
+ updatedAt?: Date;
144
+ }
145
+
146
+ /**
147
+ * Review status for a concrete evidence excerpt.
148
+ */
149
+ export declare type FactEvidenceStatus = 'supports' | 'contradicts' | 'unclear' | 'irrelevant' | 'invalid';
150
+
151
+ /**
152
+ * A candidate factual statement extracted from unstructured source text.
153
+ */
154
+ export declare interface FactExtractionCandidate {
155
+ /** Concise, atomic factual statement suitable for audit */
156
+ statement: string;
157
+ /** Fact type classification */
158
+ type?: FactType;
159
+ /** Short source excerpt that supports the statement */
160
+ sourceExcerpt?: string;
161
+ /** Optional extraction confidence from 0 to 1 */
162
+ confidence?: number;
163
+ /** Optional extraction metadata */
164
+ metadata?: Record<string, any>;
165
+ }
166
+
167
+ /**
168
+ * Options for AI-assisted fact extraction from source text.
169
+ */
170
+ export declare interface FactExtractionOptions {
171
+ /** Domain to guide extraction and later reconciliation */
172
+ domain?: string;
173
+ /** Source type, e.g. agenda, minutes, article, transcript */
174
+ sourceType?: string;
175
+ /** Human-readable context for the source text */
176
+ context?: string;
177
+ /** Maximum number of facts to extract */
178
+ maxFacts?: number;
179
+ /** Fact types the extractor may return */
180
+ allowedTypes?: FactType[];
181
+ /** Tenant id used when resolving stored prompt overrides */
182
+ tenantId?: string | null;
183
+ /** Runtime prompt override for a single extraction call */
184
+ promptOverride?: PromptConfigOverrideInput;
185
+ }
186
+
187
+ /**
188
+ * Fact metadata structure (flexible, application-specific)
189
+ */
190
+ export declare interface FactMetadata {
191
+ /** Original extraction context */
192
+ extractionContext?: string;
193
+ /** AI model used for refinement */
194
+ refinedBy?: string;
195
+ /** Tags for categorization */
196
+ tags?: string[];
197
+ /** Related fact IDs */
198
+ relatedFactIds?: string[];
199
+ /** Corroboration score from cross-referencing */
200
+ corroborationScore?: number;
201
+ /** Allow any other properties */
202
+ [key: string]: any;
203
+ }
204
+
205
+ /**
206
+ * Options for creating a Fact instance
207
+ */
208
+ export declare interface FactOptions extends SmrtObjectOptions {
209
+ id?: string;
210
+ slug?: string;
211
+ type?: FactType;
212
+ status?: FactStatus;
213
+ domain?: string;
214
+ textRaw?: string;
215
+ textRefined?: string;
216
+ /**
217
+ * Self-referencing pointer to the predecessor fact in the evolution
218
+ * chain. NOT a structural hierarchy edge — see Fact.previousFactId.
219
+ */
220
+ previousFactId?: string;
221
+ evolutionType?: EvolutionType;
222
+ sourceCount?: number;
223
+ confidence?: number;
224
+ metadata?: string | Record<string, any>;
225
+ tenantId?: string | null;
226
+ }
227
+
228
+ declare class FactSource extends SmrtObject {
229
+ factId: string;
230
+ sourceType: string;
231
+ sourceUrl: string;
232
+ sourceTitle: string;
233
+ credibility: number;
234
+ extractedAt: Date;
235
+ metadata: string;
236
+ tenantId: string | null;
237
+ createdAt: Date;
238
+ updatedAt: Date;
239
+ constructor(options?: FactSourceOptions);
240
+ getMetadata(): Record<string, any>;
241
+ setMetadata(data: Record<string, any>): void;
242
+ updateMetadata(updates: Record<string, any>): void;
243
+ /**
244
+ * Get the fact this source belongs to
245
+ */
246
+ getFact(): Promise<Fact | null>;
247
+ }
248
+
249
+ /**
250
+ * Options for creating a FactSource instance
251
+ */
252
+ export declare interface FactSourceOptions extends SmrtObjectOptions {
253
+ id?: string;
254
+ factId?: string;
255
+ sourceType?: string;
256
+ sourceUrl?: string;
257
+ sourceTitle?: string;
258
+ credibility?: number;
259
+ extractedAt?: Date;
260
+ metadata?: string | Record<string, any>;
261
+ tenantId?: string | null;
262
+ }
263
+
264
+ /**
265
+ * Fact lifecycle status
266
+ */
267
+ export declare type FactStatus = 'pending' | 'active' | 'disputed' | 'superseded' | 'archived' | 'retracted';
268
+
269
+ declare class FactSubject extends SmrtObject {
270
+ factId: string;
271
+ entityType: string;
272
+ entityId: string;
273
+ role: string;
274
+ metadata: string;
275
+ tenantId: string | null;
276
+ createdAt: Date;
277
+ updatedAt: Date;
278
+ constructor(options?: FactSubjectOptions);
279
+ getRole(): SubjectRole;
280
+ getMetadata(): Record<string, any>;
281
+ setMetadata(data: Record<string, any>): void;
282
+ updateMetadata(updates: Record<string, any>): void;
283
+ /**
284
+ * Get the fact this subject is linked to
285
+ */
286
+ getFact(): Promise<Fact | null>;
287
+ }
288
+
289
+ /**
290
+ * Options for creating a FactSubject instance
291
+ */
292
+ export declare interface FactSubjectOptions extends SmrtObjectOptions {
293
+ id?: string;
294
+ factId?: string;
295
+ entityType?: string;
296
+ entityId?: string;
297
+ role?: SubjectRole;
298
+ metadata?: string | Record<string, any>;
299
+ tenantId?: string | null;
300
+ }
301
+
302
+ /**
303
+ * Options for creating a FactTag join
304
+ */
305
+ export declare interface FactTagOptions extends SmrtObjectOptions {
306
+ id?: string;
307
+ factId?: string;
308
+ tagSlug?: string;
309
+ metadata?: string | Record<string, any>;
310
+ tenantId?: string | null;
311
+ }
312
+
313
+ /**
314
+ * Fact type classification
315
+ */
316
+ export declare type FactType = 'assertion' | 'observation' | 'measurement' | 'definition' | 'relationship' | 'event' | 'opinion' | 'prediction';
317
+
318
+ /**
319
+ * Reconcile action taken
320
+ */
321
+ export declare type ReconcileAction = 'created' | 'merged' | 'branched';
322
+
323
+ /**
324
+ * Options for the reconcile() operation
325
+ */
326
+ export declare interface ReconcileOptions {
327
+ /** Raw text input to reconcile */
328
+ rawInput: string;
329
+ /** Similarity threshold for automatic merge (default: 0.85) */
330
+ similarityThreshold?: number;
331
+ /** Minimum similarity to consider a conflict (default: 0.60) */
332
+ conflictThreshold?: number;
333
+ /** Fact type classification */
334
+ type?: FactType;
335
+ /** Domain for the fact */
336
+ domain?: string;
337
+ /** Source metadata */
338
+ source?: {
339
+ sourceType?: string;
340
+ sourceUrl?: string;
341
+ sourceTitle?: string;
342
+ credibility?: number;
343
+ metadata?: Record<string, any>;
344
+ };
345
+ tenantId?: string | null;
346
+ /** Runtime prompt override for AI-assisted ambiguous reconciliation */
347
+ promptOverride?: PromptConfigOverrideInput;
348
+ }
349
+
350
+ /**
351
+ * Result of the reconcile() operation
352
+ */
353
+ export declare interface ReconcileResult {
354
+ /** Action taken: created, merged, or branched */
355
+ action: ReconcileAction;
356
+ /** The resulting fact (created, updated, or branched) */
357
+ fact: Fact;
358
+ /** Source record if source metadata was provided */
359
+ source?: FactSource;
360
+ /** Cosine similarity score of the best match */
361
+ similarity?: number;
362
+ /** The existing fact that was matched (for merge/branch) */
363
+ matchedFact?: Fact;
364
+ }
365
+
366
+ /**
367
+ * Role of a subject entity in relation to a fact
368
+ */
369
+ export declare type SubjectRole = 'subject' | 'object' | 'source' | 'location' | 'participant' | 'related';
370
+
371
+ export { }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@happyvertical/smrt-facts",
3
+ "version": "0.30.0",
4
+ "description": "Distributed memory and knowledge management with provenance tracking for SMRT framework",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "CLAUDE.md",
11
+ "AGENTS.md"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ },
18
+ "./manifest": "./dist/manifest.json",
19
+ "./manifest.json": "./dist/manifest.json"
20
+ },
21
+ "dependencies": {
22
+ "@happyvertical/ai": "^0.74.7",
23
+ "@happyvertical/files": "^0.74.7",
24
+ "@happyvertical/logger": "^0.74.7",
25
+ "@happyvertical/sql": "^0.74.7",
26
+ "@happyvertical/utils": "^0.74.7",
27
+ "@happyvertical/smrt-core": "0.30.0",
28
+ "@happyvertical/smrt-prompts": "0.30.0",
29
+ "@happyvertical/smrt-tenancy": "0.30.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "25.0.9",
33
+ "typescript": "^5.9.3",
34
+ "vite": "^7.3.1",
35
+ "vitest": "^4.0.17",
36
+ "@happyvertical/smrt-vitest": "0.30.0"
37
+ },
38
+ "keywords": [
39
+ "ai",
40
+ "agents",
41
+ "facts",
42
+ "knowledge",
43
+ "memory",
44
+ "provenance",
45
+ "smrt"
46
+ ],
47
+ "author": "HappyVertical",
48
+ "license": "MIT",
49
+ "publishConfig": {
50
+ "registry": "https://registry.npmjs.org",
51
+ "access": "public"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "https://github.com/happyvertical/smrt.git",
56
+ "directory": "packages/facts"
57
+ },
58
+ "scripts": {
59
+ "build": "vite build --mode library",
60
+ "build:watch": "vite build --mode library --watch",
61
+ "clean": "rm -rf dist",
62
+ "dev": "vite dev",
63
+ "pretest": "[ -f ../cli/dist/index.js ] && node ../cli/dist/index.js test --manifest-only || true",
64
+ "test": "vitest run",
65
+ "test:watch": "vitest",
66
+ "typecheck": "tsc --noEmit -p tsconfig.json",
67
+ "verify:pack": "node ../../scripts/verify-package-types-exports.js ."
68
+ }
69
+ }