@happyvertical/smrt-facts 0.51.30 → 0.51.33

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.
Files changed (44) hide show
  1. package/README.md +3 -1
  2. package/dist/__smrt-register__.d.ts +2 -0
  3. package/dist/__smrt-register__.d.ts.map +1 -0
  4. package/dist/__tests__/fixtures/decision-claim-support-3166.d.ts +33 -0
  5. package/dist/__tests__/fixtures/decision-claim-support-3166.d.ts.map +1 -0
  6. package/dist/catalog-search.d.ts +7 -0
  7. package/dist/catalog-search.d.ts.map +1 -0
  8. package/dist/fact-content.d.ts +39 -0
  9. package/dist/fact-content.d.ts.map +1 -0
  10. package/dist/fact-contents.d.ts +32 -0
  11. package/dist/fact-contents.d.ts.map +1 -0
  12. package/dist/fact-evidence.d.ts +37 -0
  13. package/dist/fact-evidence.d.ts.map +1 -0
  14. package/dist/fact-evidences.d.ts +32 -0
  15. package/dist/fact-evidences.d.ts.map +1 -0
  16. package/dist/fact-source.d.ts +29 -0
  17. package/dist/fact-source.d.ts.map +1 -0
  18. package/dist/fact-sources.d.ts +50 -0
  19. package/dist/fact-sources.d.ts.map +1 -0
  20. package/dist/fact-subject.d.ts +28 -0
  21. package/dist/fact-subject.d.ts.map +1 -0
  22. package/dist/fact-subjects.d.ts +56 -0
  23. package/dist/fact-subjects.d.ts.map +1 -0
  24. package/dist/fact-tag.d.ts +34 -0
  25. package/dist/fact-tag.d.ts.map +1 -0
  26. package/dist/fact-tags.d.ts +51 -0
  27. package/dist/fact-tags.d.ts.map +1 -0
  28. package/dist/fact.d.ts +77 -0
  29. package/dist/fact.d.ts.map +1 -0
  30. package/dist/facts.d.ts +173 -0
  31. package/dist/facts.d.ts.map +1 -0
  32. package/dist/index.d.ts +25 -847
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +31 -6
  35. package/dist/index.js.map +1 -1
  36. package/dist/manifest.json +1 -1
  37. package/dist/prompts.d.ts +5 -0
  38. package/dist/prompts.d.ts.map +1 -0
  39. package/dist/smrt-knowledge.json +4 -4
  40. package/dist/types.d.ts +258 -375
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/utils.d.ts +26 -0
  43. package/dist/utils.d.ts.map +1 -0
  44. package/package.json +11 -11
package/dist/index.d.ts CHANGED
@@ -1,847 +1,25 @@
1
- import { PromptConfigOverrideInput } from '@happyvertical/smrt-prompts';
2
- import { PromptDefinition } from '@happyvertical/smrt-prompts';
3
- import { SmrtCollection } from '@happyvertical/smrt-core';
4
- import { SmrtJunction } from '@happyvertical/smrt-core';
5
- import { SmrtObject } from '@happyvertical/smrt-core';
6
- import { SmrtObjectOptions } from '@happyvertical/smrt-core';
7
-
8
- /**
9
- * Utility functions for @happyvertical/smrt-facts
10
- */
11
- /**
12
- * Calculate confidence score for a fact based on multiple signals.
13
- *
14
- * Formula (v1, simple weighted):
15
- * base = 0.5
16
- * + min(sourceCount/10, 0.3) source volume boost
17
- * + avgSourceCredibility * 0.2 credibility boost
18
- * + max(0, 0.1 - days*0.01) recency boost (decays over 10 days)
19
- * + corroborationScore * 0.1 agreement boost
20
- * = clamped to [0, 1]
21
- */
22
- export declare function calculateConfidence(params: {
23
- sourceCount: number;
24
- avgSourceCredibility?: number;
25
- daysSinceLastSource?: number;
26
- corroborationScore?: number;
27
- }): number;
28
-
29
- export declare function createFactEvidenceKey(input: Pick<FactEvidenceOptions, 'sourceKind' | 'sourceId' | 'sourceUrl' | 'locator' | 'quote'>): string;
30
-
31
- /**
32
- * Entity briefing - summary of all facts about an entity
33
- */
34
- export declare interface EntityBriefing {
35
- entityType: string;
36
- entityId: string;
37
- facts: Fact[];
38
- totalCount: number;
39
- byType: Record<string, number>;
40
- byStatus: Record<string, number>;
41
- }
42
-
43
- /**
44
- * How a fact evolved from its predecessor in the evolution chain.
45
- */
46
- export declare type EvolutionType = 'original' | 'correction' | 'refinement' | 'contradiction' | 'extension' | 'merge';
47
-
48
- export declare class Fact extends SmrtObject {
49
- textRefined: string;
50
- textRaw: string;
51
- /** Derived search storage. NULL requires the explicit catalog backfill. */
52
- catalogSearch: string | null;
53
- type: string;
54
- status: string;
55
- domain: string;
56
- /**
57
- * Self-referencing pointer to the predecessor fact in an evolution chain.
58
- *
59
- * This is NOT a structural hierarchy edge — Fact does not extend
60
- * SmrtHierarchical. The chain represents knowledge evolution: an original
61
- * fact, then corrections, refinements, contradictions, or extensions of
62
- * that fact. See `evolutionType` for the kind of step.
63
- */
64
- previousFactId: string;
65
- evolutionType: string;
66
- sourceCount: number;
67
- confidence: number;
68
- metadata: string;
69
- tenantId: string | null;
70
- createdAt: Date;
71
- updatedAt: Date;
72
- constructor(options?: FactOptions);
73
- protected getPersistenceDerivedColumns(): readonly string[];
74
- protected normalizePersistenceData(data: Readonly<Record<string, unknown>>): Record<string, unknown>;
75
- getMetadata(): FactMetadata;
76
- setMetadata(data: FactMetadata): void;
77
- updateMetadata(updates: Partial<FactMetadata>): void;
78
- getType(): FactType;
79
- getStatus(): FactStatus;
80
- getEvolutionType(): EvolutionType;
81
- isActive(): boolean;
82
- isSuperseded(): boolean;
83
- /**
84
- * Whether this fact has a predecessor in the evolution chain.
85
- *
86
- * Returns false for the framework default (`''`) and for any nullish
87
- * value — defensive against rows whose `previous_fact_id` column is
88
- * NULL (e.g. after a migration that left root facts un-backfilled).
89
- */
90
- hasPredecessor(): boolean;
91
- /**
92
- * Get the predecessor fact (the prior version in the evolution chain).
93
- */
94
- getPredecessor(): Promise<Fact | null>;
95
- /**
96
- * Get successor facts (facts that evolved directly from this one).
97
- */
98
- getSuccessors(): Promise<Fact[]>;
99
- /**
100
- * Get all sources for this fact
101
- */
102
- getSources(): Promise< FactSource[]>;
103
- /**
104
- * Get all subjects linked to this fact
105
- */
106
- getSubjects(): Promise< FactSubject[]>;
107
- }
108
-
109
- export declare interface FactClaimSupportAssessment {
110
- status: FactClaimSupportStatus;
111
- matchedFactIds: string[];
112
- matchedEvidenceIds: string[];
113
- rationale: string;
114
- confidence?: number;
115
- }
116
-
117
- export declare interface FactClaimSupportCandidate {
118
- id?: string | null;
119
- statement: string;
120
- evidence?: Array<{
121
- id?: string | null;
122
- status?: FactEvidenceStatus | null;
123
- quote?: string | null;
124
- sourceTitle?: string | null;
125
- sourceUrl?: string | null;
126
- locator?: string | null;
127
- }>;
128
- }
129
-
130
- export declare interface FactClaimSupportOptions {
131
- tenantId?: string | null;
132
- promptOverride?: PromptConfigOverrideInput;
133
- }
134
-
135
- export declare type FactClaimSupportStatus = 'supported' | 'unsupported' | 'contradicted' | 'needs_review';
136
-
137
- export declare class FactCollection extends SmrtCollection<Fact> {
138
- static readonly _itemClass: typeof Fact;
139
- /**
140
- * Fetch one catalog page in SQL. The recursive branch walk may inspect more
141
- * rows inside the database, but the outer query only materializes the page.
142
- */
143
- private listCatalogPage;
144
- /**
145
- * Get all active facts
146
- */
147
- getActive(): Promise<Fact[]>;
148
- /**
149
- * Get all pending facts
150
- */
151
- getPending(): Promise<Fact[]>;
152
- /**
153
- * Get facts by type
154
- */
155
- getByType(type: FactType): Promise<Fact[]>;
156
- /**
157
- * Get facts by domain
158
- */
159
- getByDomain(domain: string): Promise<Fact[]>;
160
- /**
161
- * Get facts by status
162
- */
163
- getByStatus(status: FactStatus): Promise<Fact[]>;
164
- /**
165
- * Get successor facts for a given predecessor (facts that evolved
166
- * directly from `previousFactId`).
167
- */
168
- getSuccessors(previousFactId: string): Promise<Fact[]>;
169
- /**
170
- * Find all facts belonging to a specific tenant
171
- */
172
- findByTenant(tenantId: string): Promise<Fact[]>;
173
- /**
174
- * Find all global (tenant-less) facts.
175
- *
176
- * Routes through the shared tenant-global helper so it does not throw under
177
- * an active tenant context (an explicit `tenant_id IS NULL` filter would be
178
- * flagged as an isolation violation). (#1600)
179
- */
180
- findGlobal(): Promise<Fact[]>;
181
- /**
182
- * Find facts for a tenant including global facts.
183
- *
184
- * Fails closed if an active tenant context requests a different tenant's
185
- * rows; the admin/system path keeps the cross-tenant capability. (#1600)
186
- */
187
- findWithGlobals(tenantId: string): Promise<Fact[]>;
188
- /**
189
- * Browse active facts for editorial association.
190
- * Uses semantic search when a query is provided and falls back to text filtering
191
- * if embeddings are unavailable.
192
- */
193
- browseCatalog(query?: string, options?: {
194
- tenantId?: string | null;
195
- limit?: number;
196
- offset?: number;
197
- minSimilarity?: number;
198
- includeSuperseded?: boolean;
199
- latestOnly?: boolean;
200
- }): Promise<Fact[]>;
201
- /**
202
- * Explicit data migration after db:migrate adds catalog_search. Run under
203
- * withSystemContext with old writers stopped. Repeating a batch is safe;
204
- * concurrent source changes are protected by compare-and-set predicates.
205
- * A subtype collection backfills only its STI discriminator.
206
- */
207
- backfillCatalogSearch(batchSize?: number): Promise<{
208
- remaining: number;
209
- }>;
210
- /**
211
- * Get all facts linked to a content item.
212
- */
213
- getForContent(contentId: string, options?: {
214
- relationship?: FactContentRelationship;
215
- includeSuperseded?: boolean;
216
- latestOnly?: boolean;
217
- }): Promise<Fact[]>;
218
- /**
219
- * Reconcile raw input against existing facts using semantic search + AI.
220
- * Determines whether to create, merge, or branch.
221
- *
222
- * Algorithm:
223
- * 1. semanticSearch(rawInput) against existing facts
224
- * 2. Decision:
225
- * - No match above conflictThreshold (0.60) -> CREATE new fact
226
- * - Top match >= similarityThreshold (0.85) -> MERGE (add source, bump sourceCount)
227
- * - Ambiguous zone (0.60-0.85) -> AI disambiguation via this.ai.message()
228
- * - AI says "merge" -> MERGE
229
- * - AI says "branch" -> BRANCH (new fact as successor, predecessor marked superseded)
230
- * 3. Record FactSource if source metadata provided
231
- * 4. Return { action, fact, source?, similarity?, matchedFact? }
232
- */
233
- reconcile(options: ReconcileOptions): Promise<ReconcileResult>;
234
- /**
235
- * Extract atomic factual statements from unstructured source text using AI.
236
- *
237
- * This method is intentionally non-persistent: callers can review, reconcile,
238
- * link, or discard the returned candidates according to their app workflow.
239
- */
240
- extractCandidatesFromText(text: string, options?: FactExtractionOptions): Promise<FactExtractionCandidate[]>;
241
- /**
242
- * Extract material factual claims made by an article.
243
- *
244
- * This is intentionally separate from source extraction: source extraction
245
- * finds evidence-backed facts, while claim extraction finds statements the
246
- * draft itself needs to justify.
247
- */
248
- extractArticleClaims(text: string, options?: FactExtractionOptions): Promise<FactExtractionCandidate[]>;
249
- /**
250
- * Classify whether a claim is supported by candidate facts/evidence.
251
- */
252
- assessClaimSupport(claim: string, candidateFacts: FactClaimSupportCandidate[], options?: FactClaimSupportOptions): Promise<FactClaimSupportAssessment>;
253
- /**
254
- * Use AI to determine whether new input should be merged with
255
- * or branched from an existing fact.
256
- */
257
- private _disambiguateWithAI;
258
- /**
259
- * Create a branched fact from an existing predecessor.
260
- *
261
- * For 'correction' and 'contradiction' evolution types, the
262
- * predecessor is marked as superseded.
263
- *
264
- * @param previousFactId ID of the predecessor fact this branches from.
265
- * @param data Partial fact options for the new successor.
266
- * @param evolutionType How the successor relates to the predecessor.
267
- */
268
- branch(previousFactId: string, data: Partial<FactOptions>, evolutionType?: EvolutionType): Promise<Fact>;
269
- /**
270
- * Walk up the evolution chain via previousFactId, returning the
271
- * predecessors followed by the current fact in order.
272
- *
273
- * @returns Array ordered from root (original) → current fact.
274
- */
275
- getEvolutionChain(factId: string): Promise<Fact[]>;
276
- /**
277
- * Walk down successors to find the latest (highest confidence) leaf.
278
- * At each level, picks the successor with the highest confidence score.
279
- */
280
- getLatestInChain(factId: string): Promise<Fact>;
281
- /**
282
- * Find the root of the chain via `getEvolutionChain`, then collect every
283
- * successor iteratively via BFS (queue-based, with a `visited` set for
284
- * cycle protection). Returns the full tree as a flat array in BFS
285
- * order — root first, then each level of successors.
286
- */
287
- getEvolutionTree(factId: string): Promise<Fact[]>;
288
- /**
289
- * Recalculate confidence score for a fact based on its sources.
290
- * Uses calculateConfidence from utils.ts with data from FactSourceCollection.
291
- */
292
- recalculateConfidence(factId: string): Promise<number>;
293
- /**
294
- * Get a briefing of all facts related to a given entity.
295
- * Finds all FactSubject links for the entity, loads corresponding facts,
296
- * and returns summary statistics.
297
- */
298
- getEntityBriefing(entityType: string, entityId: string): Promise<EntityBriefing>;
299
- }
300
-
301
- export declare class FactContent extends SmrtObject {
302
- factId: string;
303
- contentId: string;
304
- relationship: string;
305
- metadata: string;
306
- tenantId: string | null;
307
- createdAt: Date;
308
- updatedAt: Date;
309
- constructor(options?: FactContentOptions);
310
- /**
311
- * Get the relationship type as a typed value
312
- */
313
- getRelationship(): FactContentRelationship;
314
- /**
315
- * Get metadata as parsed object
316
- */
317
- getMetadata(): Record<string, unknown>;
318
- /**
319
- * Set metadata from object
320
- */
321
- setMetadata(data: Record<string, unknown>): void;
322
- /**
323
- * Update metadata by merging with existing values
324
- */
325
- updateMetadata(updates: Record<string, unknown>): void;
326
- /**
327
- * Get the fact this content link belongs to
328
- */
329
- getFact(): Promise< Fact | null>;
330
- }
331
-
332
- export declare class FactContentCollection extends SmrtJunction<FactContent> {
333
- static readonly _itemClass: typeof FactContent;
334
- protected leftField: string;
335
- protected rightField: string;
336
- protected sortField: string | null;
337
- protected positionField: string | null;
338
- findByTenant(tenantId: string): Promise<FactContent[]>;
339
- /**
340
- * Find all global (tenant-less) fact-content links.
341
- *
342
- * Routes through the shared tenant-global helper so it does not throw under
343
- * an active tenant context (an explicit `tenant_id IS NULL` filter would be
344
- * flagged as an isolation violation). (#1600)
345
- */
346
- findGlobal(): Promise<FactContent[]>;
347
- /**
348
- * Find fact-content links for a tenant including global links.
349
- *
350
- * Fails closed if an active tenant context requests a different tenant's
351
- * rows; the admin/system path keeps the cross-tenant capability. (#1600)
352
- */
353
- findWithGlobals(tenantId: string): Promise<FactContent[]>;
354
- }
355
-
356
- /**
357
- * Options for creating a FactContent join
358
- */
359
- export declare interface FactContentOptions extends SmrtObjectOptions {
360
- id?: string;
361
- factId?: string;
362
- contentId?: string;
363
- relationship?: FactContentRelationship;
364
- metadata?: string | Record<string, unknown>;
365
- tenantId?: string | null;
366
- }
367
-
368
- /**
369
- * Relationship between a fact and content
370
- */
371
- export declare type FactContentRelationship = 'extracted_from' | 'referenced_in' | 'supports' | 'contradicts' | 'related';
372
-
373
- export declare class FactEvidence extends SmrtObject {
374
- factId: string;
375
- evidenceKey: string;
376
- status: FactEvidenceStatus;
377
- sourceKind: string;
378
- sourceId: string;
379
- sourceUrl: string;
380
- sourceTitle: string;
381
- quote: string;
382
- locator: string;
383
- extractionMethod: string;
384
- /**
385
- * Extraction confidence in `[0, 1]`. The `0.0` initializer is load-bearing:
386
- * SMRT maps `= 0` to INTEGER and `= 0.0` to DECIMAL, so an INTEGER column
387
- * would truncate every meaningful score to 0 or 1 and PostgreSQL would
388
- * reject the save outright (`22P02`). Matches `Fact.confidence` and
389
- * `FactSource.credibility` (#2361).
390
- */
391
- confidence: number;
392
- metadata: string;
393
- tenantId: string | null;
394
- createdAt: Date;
395
- updatedAt: Date;
396
- constructor(options?: FactEvidenceOptions);
397
- getMetadata(): Record<string, unknown>;
398
- setMetadata(data: Record<string, unknown>): void;
399
- updateMetadata(updates: Record<string, unknown>): void;
400
- }
401
-
402
- export declare class FactEvidenceCollection extends SmrtCollection<FactEvidence> {
403
- static readonly _itemClass: typeof FactEvidence;
404
- getForFact(factId: string): Promise<FactEvidence[]>;
405
- getForSource(sourceKind: string, sourceId: string): Promise<FactEvidence[]>;
406
- getForSources(sources: Array<{
407
- sourceKind: string;
408
- sourceId: string;
409
- }>): Promise<FactEvidence[]>;
410
- bulkUpdateStatus(evidenceIds: string[], status: FactEvidenceStatus, options?: {
411
- reason?: string;
412
- reviewedBy?: string | null;
413
- }): Promise<FactEvidence[]>;
414
- replaceGeneratedForSources(sources: Array<{
415
- sourceKind: string;
416
- sourceId: string;
417
- }>, options?: {
418
- generatedBy?: string;
419
- contentId?: string;
420
- tenantId?: string | null;
421
- }): Promise<{
422
- deletedEvidenceIds: string[];
423
- }>;
424
- upsertEvidence(options: FactEvidenceOptions): Promise<FactEvidence>;
425
- }
426
-
427
- /**
428
- * Options for creating concrete evidence for a fact.
429
- */
430
- export declare interface FactEvidenceOptions extends SmrtObjectOptions {
431
- id?: string;
432
- factId?: string;
433
- evidenceKey?: string;
434
- status?: FactEvidenceStatus;
435
- sourceKind?: string;
436
- sourceId?: string;
437
- sourceUrl?: string;
438
- sourceTitle?: string;
439
- quote?: string;
440
- locator?: string;
441
- extractionMethod?: string;
442
- confidence?: number;
443
- metadata?: string | Record<string, unknown>;
444
- tenantId?: string | null;
445
- createdAt?: Date;
446
- updatedAt?: Date;
447
- }
448
-
449
- /**
450
- * Review status for a concrete evidence excerpt.
451
- */
452
- export declare type FactEvidenceStatus = 'supports' | 'contradicts' | 'unclear' | 'irrelevant' | 'invalid';
453
-
454
- /**
455
- * A candidate factual statement extracted from unstructured source text.
456
- */
457
- export declare interface FactExtractionCandidate {
458
- /** Concise, atomic factual statement suitable for audit */
459
- statement: string;
460
- /** Fact type classification */
461
- type?: FactType;
462
- /** Short source excerpt that supports the statement */
463
- sourceExcerpt?: string;
464
- /** Optional extraction confidence from 0 to 1 */
465
- confidence?: number;
466
- /** Optional extraction metadata */
467
- metadata?: Record<string, unknown>;
468
- }
469
-
470
- /**
471
- * Options for AI-assisted fact extraction from source text.
472
- */
473
- export declare interface FactExtractionOptions {
474
- /** Domain to guide extraction and later reconciliation */
475
- domain?: string;
476
- /** Source type, e.g. agenda, minutes, article, transcript */
477
- sourceType?: string;
478
- /** Human-readable context for the source text */
479
- context?: string;
480
- /** Maximum number of facts to extract */
481
- maxFacts?: number;
482
- /** Fact types the extractor may return */
483
- allowedTypes?: FactType[];
484
- /** Tenant id used when resolving stored prompt overrides */
485
- tenantId?: string | null;
486
- /** Runtime prompt override for a single extraction call */
487
- promptOverride?: PromptConfigOverrideInput;
488
- }
489
-
490
- /**
491
- * Fact metadata structure (flexible, application-specific)
492
- */
493
- export declare interface FactMetadata {
494
- /** Original extraction context */
495
- extractionContext?: string;
496
- /** AI model used for refinement */
497
- refinedBy?: string;
498
- /** Tags for categorization */
499
- tags?: string[];
500
- /** Related fact IDs */
501
- relatedFactIds?: string[];
502
- /** Corroboration score from cross-referencing */
503
- corroborationScore?: number;
504
- /** Allow any other properties */
505
- [key: string]: unknown;
506
- }
507
-
508
- /**
509
- * Options for creating a Fact instance
510
- */
511
- export declare interface FactOptions extends SmrtObjectOptions {
512
- id?: string;
513
- slug?: string;
514
- type?: FactType;
515
- status?: FactStatus;
516
- domain?: string;
517
- textRaw?: string;
518
- textRefined?: string;
519
- /**
520
- * Self-referencing pointer to the predecessor fact in the evolution
521
- * chain. NOT a structural hierarchy edge — see Fact.previousFactId.
522
- */
523
- previousFactId?: string;
524
- evolutionType?: EvolutionType;
525
- sourceCount?: number;
526
- confidence?: number;
527
- metadata?: string | Record<string, unknown>;
528
- tenantId?: string | null;
529
- }
530
-
531
- export declare class FactSource extends SmrtObject {
532
- factId: string;
533
- sourceType: string;
534
- sourceUrl: string;
535
- sourceTitle: string;
536
- credibility: number;
537
- extractedAt: Date;
538
- metadata: string;
539
- tenantId: string | null;
540
- createdAt: Date;
541
- updatedAt: Date;
542
- constructor(options?: FactSourceOptions);
543
- getMetadata(): Record<string, unknown>;
544
- setMetadata(data: Record<string, unknown>): void;
545
- updateMetadata(updates: Record<string, unknown>): void;
546
- /**
547
- * Get the fact this source belongs to
548
- */
549
- getFact(): Promise< Fact | null>;
550
- }
551
-
552
- export declare class FactSourceCollection extends SmrtCollection<FactSource> {
553
- static readonly _itemClass: typeof FactSource;
554
- /**
555
- * Get all sources for a given fact
556
- */
557
- getForFact(factId: string): Promise<FactSource[]>;
558
- /**
559
- * Count sources for a given fact
560
- */
561
- countForFact(factId: string): Promise<number>;
562
- /**
563
- * Get sources by type
564
- */
565
- getByType(sourceType: string): Promise<FactSource[]>;
566
- /**
567
- * Get sources with credibility above a threshold
568
- */
569
- getHighCredibility(minCredibility?: number): Promise<FactSource[]>;
570
- /**
571
- * Get average credibility for a fact's sources
572
- */
573
- getAverageCredibility(factId: string): Promise<number>;
574
- /**
575
- * Find all sources belonging to a specific tenant
576
- */
577
- findByTenant(tenantId: string): Promise<FactSource[]>;
578
- /**
579
- * Find all global (tenant-less) sources.
580
- *
581
- * Routes through the shared tenant-global helper so it does not throw under
582
- * an active tenant context (an explicit `tenant_id IS NULL` filter would be
583
- * flagged as an isolation violation). (#1600)
584
- */
585
- findGlobal(): Promise<FactSource[]>;
586
- /**
587
- * Find sources for a tenant including global sources.
588
- *
589
- * Fails closed if an active tenant context requests a different tenant's
590
- * rows; the admin/system path keeps the cross-tenant capability. (#1600)
591
- */
592
- findWithGlobals(tenantId: string): Promise<FactSource[]>;
593
- }
594
-
595
- /**
596
- * Options for creating a FactSource instance
597
- */
598
- export declare interface FactSourceOptions extends SmrtObjectOptions {
599
- id?: string;
600
- factId?: string;
601
- sourceType?: string;
602
- sourceUrl?: string;
603
- sourceTitle?: string;
604
- credibility?: number;
605
- extractedAt?: Date;
606
- metadata?: string | Record<string, unknown>;
607
- tenantId?: string | null;
608
- }
609
-
610
- /**
611
- * Fact lifecycle status
612
- */
613
- export declare type FactStatus = 'pending' | 'active' | 'disputed' | 'superseded' | 'archived' | 'retracted';
614
-
615
- export declare class FactSubject extends SmrtObject {
616
- factId: string;
617
- entityType: string;
618
- entityId: string;
619
- role: string;
620
- metadata: string;
621
- tenantId: string | null;
622
- createdAt: Date;
623
- updatedAt: Date;
624
- constructor(options?: FactSubjectOptions);
625
- getRole(): SubjectRole;
626
- getMetadata(): Record<string, unknown>;
627
- setMetadata(data: Record<string, unknown>): void;
628
- updateMetadata(updates: Record<string, unknown>): void;
629
- /**
630
- * Get the fact this subject is linked to
631
- */
632
- getFact(): Promise< Fact | null>;
633
- }
634
-
635
- export declare class FactSubjectCollection extends SmrtCollection<FactSubject> {
636
- static readonly _itemClass: typeof FactSubject;
637
- /**
638
- * Get all subjects linked to a fact
639
- */
640
- getForFact(factId: string): Promise<FactSubject[]>;
641
- /**
642
- * Get all fact-subject links for a given entity
643
- */
644
- getForEntity(entityType: string, entityId: string): Promise<FactSubject[]>;
645
- /**
646
- * Link an entity to a fact
647
- */
648
- linkEntity(factId: string, entityType: string, entityId: string, role?: SubjectRole): Promise<FactSubject>;
649
- /**
650
- * Unlink an entity from a fact
651
- */
652
- unlinkEntity(factId: string, entityType: string, entityId: string): Promise<void>;
653
- /**
654
- * Get subjects by role for a fact
655
- */
656
- getByRole(factId: string, role: SubjectRole): Promise<FactSubject[]>;
657
- /**
658
- * Count entities linked to a fact
659
- */
660
- countForFact(factId: string): Promise<number>;
661
- /**
662
- * Find all subjects belonging to a specific tenant
663
- */
664
- findByTenant(tenantId: string): Promise<FactSubject[]>;
665
- /**
666
- * Find all global (tenant-less) subjects.
667
- *
668
- * Routes through the shared tenant-global helper so it does not throw under
669
- * an active tenant context (an explicit `tenant_id IS NULL` filter would be
670
- * flagged as an isolation violation). (#1600)
671
- */
672
- findGlobal(): Promise<FactSubject[]>;
673
- /**
674
- * Find subjects for a tenant including global subjects.
675
- *
676
- * Fails closed if an active tenant context requests a different tenant's
677
- * rows; the admin/system path keeps the cross-tenant capability. (#1600)
678
- */
679
- findWithGlobals(tenantId: string): Promise<FactSubject[]>;
680
- }
681
-
682
- /**
683
- * Options for creating a FactSubject instance
684
- */
685
- export declare interface FactSubjectOptions extends SmrtObjectOptions {
686
- id?: string;
687
- factId?: string;
688
- entityType?: string;
689
- entityId?: string;
690
- role?: SubjectRole;
691
- metadata?: string | Record<string, unknown>;
692
- tenantId?: string | null;
693
- }
694
-
695
- export declare class FactTag extends SmrtObject {
696
- factId: string;
697
- tagSlug: string;
698
- metadata: string;
699
- tenantId: string | null;
700
- createdAt: Date;
701
- updatedAt: Date;
702
- constructor(options?: FactTagOptions);
703
- /**
704
- * Get metadata as parsed object
705
- */
706
- getMetadata(): Record<string, unknown>;
707
- /**
708
- * Set metadata from object
709
- */
710
- setMetadata(data: Record<string, unknown>): void;
711
- /**
712
- * Update metadata by merging with existing values
713
- */
714
- updateMetadata(updates: Record<string, unknown>): void;
715
- /**
716
- * Get the fact this tag link belongs to
717
- */
718
- getFact(): Promise< Fact | null>;
719
- }
720
-
721
- export declare class FactTagCollection extends SmrtCollection<FactTag> {
722
- static readonly _itemClass: typeof FactTag;
723
- /**
724
- * Get all tag links for a fact
725
- */
726
- getForFact(factId: string): Promise<FactTag[]>;
727
- /**
728
- * Get all fact links for a tag slug
729
- */
730
- getForTag(tagSlug: string): Promise<FactTag[]>;
731
- /**
732
- * Add a tag to a fact
733
- */
734
- addTag(factId: string, tagSlug: string): Promise<FactTag>;
735
- /**
736
- * Remove a tag from a fact
737
- */
738
- removeTag(factId: string, tagSlug: string): Promise<void>;
739
- /**
740
- * Get all tag slugs for a fact
741
- */
742
- getTagSlugs(factId: string): Promise<string[]>;
743
- /**
744
- * Find all fact-tag links belonging to a specific tenant
745
- */
746
- findByTenant(tenantId: string): Promise<FactTag[]>;
747
- /**
748
- * Find all global (tenant-less) fact-tag links.
749
- *
750
- * Routes through the shared tenant-global helper so it does not throw under
751
- * an active tenant context (an explicit `tenant_id IS NULL` filter would be
752
- * flagged as an isolation violation). (#1600)
753
- */
754
- findGlobal(): Promise<FactTag[]>;
755
- /**
756
- * Find fact-tag links for a tenant including global links.
757
- *
758
- * Fails closed if an active tenant context requests a different tenant's
759
- * rows; the admin/system path keeps the cross-tenant capability. (#1600)
760
- */
761
- findWithGlobals(tenantId: string): Promise<FactTag[]>;
762
- }
763
-
764
- /**
765
- * Options for creating a FactTag join
766
- */
767
- export declare interface FactTagOptions extends SmrtObjectOptions {
768
- id?: string;
769
- factId?: string;
770
- tagSlug?: string;
771
- metadata?: string | Record<string, unknown>;
772
- tenantId?: string | null;
773
- }
774
-
775
- /**
776
- * Fact type classification
777
- */
778
- export declare type FactType = 'assertion' | 'observation' | 'measurement' | 'definition' | 'relationship' | 'event' | 'opinion' | 'prediction';
779
-
780
- /**
781
- * Normalize text for comparison and storage.
782
- * Trims whitespace, collapses multiple spaces, and lowercases.
783
- */
784
- export declare function normalizeText(text: string): string;
785
-
786
- /**
787
- * Reconcile action taken
788
- */
789
- export declare type ReconcileAction = 'created' | 'merged' | 'branched';
790
-
791
- /**
792
- * Options for the reconcile() operation
793
- */
794
- export declare interface ReconcileOptions {
795
- /** Raw text input to reconcile */
796
- rawInput: string;
797
- /** Similarity threshold for automatic merge (default: 0.85) */
798
- similarityThreshold?: number;
799
- /** Minimum similarity to consider a conflict (default: 0.60) */
800
- conflictThreshold?: number;
801
- /** Fact type classification */
802
- type?: FactType;
803
- /** Domain for the fact */
804
- domain?: string;
805
- /** Source metadata */
806
- source?: {
807
- sourceType?: string;
808
- sourceUrl?: string;
809
- sourceTitle?: string;
810
- credibility?: number;
811
- metadata?: Record<string, unknown>;
812
- };
813
- tenantId?: string | null;
814
- /** Runtime prompt override for AI-assisted ambiguous reconciliation */
815
- promptOverride?: PromptConfigOverrideInput;
816
- }
817
-
818
- /**
819
- * Result of the reconcile() operation
820
- */
821
- export declare interface ReconcileResult {
822
- /** Action taken: created, merged, or branched */
823
- action: ReconcileAction;
824
- /** The resulting fact (created, updated, or branched) */
825
- fact: Fact;
826
- /** Source record if source metadata was provided */
827
- source?: FactSource;
828
- /** Cosine similarity score of the best match */
829
- similarity?: number;
830
- /** The existing fact that was matched (for merge/branch) */
831
- matchedFact?: Fact;
832
- }
833
-
834
- export declare const smrtFactsAssessClaimSupportPrompt: PromptDefinition;
835
-
836
- export declare const smrtFactsExtractArticleClaimsPrompt: PromptDefinition;
837
-
838
- export declare const smrtFactsExtractCandidatesPrompt: PromptDefinition;
839
-
840
- export declare const smrtFactsReconcilePrompt: PromptDefinition;
841
-
842
- /**
843
- * Role of a subject entity in relation to a fact
844
- */
845
- export declare type SubjectRole = 'subject' | 'object' | 'source' | 'location' | 'participant' | 'related';
846
-
847
- export { }
1
+ /**
2
+ * @happyvertical/smrt-facts
3
+ *
4
+ * Distributed memory and knowledge management with provenance tracking
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import './__smrt-register__.js';
9
+ import './prompts.js';
10
+ export { Fact } from './fact';
11
+ export { FactContent } from './fact-content';
12
+ export { FactContentCollection } from './fact-contents';
13
+ export { FactEvidence } from './fact-evidence';
14
+ export { createFactEvidenceKey, FactEvidenceCollection, } from './fact-evidences';
15
+ export { FactSource } from './fact-source';
16
+ export { FactSourceCollection } from './fact-sources';
17
+ export { FactSubject } from './fact-subject';
18
+ export { FactSubjectCollection } from './fact-subjects';
19
+ export { FactTag } from './fact-tag';
20
+ export { FactTagCollection } from './fact-tags';
21
+ export { FactCollection } from './facts';
22
+ export { smrtFactsAssessClaimSupportPrompt, smrtFactsExtractArticleClaimsPrompt, smrtFactsExtractCandidatesPrompt, smrtFactsReconcilePrompt, } from './prompts';
23
+ export type { EntityBriefing, EvolutionType, FactClaimSupportAssessment, FactClaimSupportCandidate, FactClaimSupportOptions, FactClaimSupportStatus, FactContentOptions, FactContentRelationship, FactEvidenceOptions, FactEvidenceStatus, FactExtractionCandidate, FactExtractionOptions, FactMetadata, FactOptions, FactSourceOptions, FactStatus, FactSubjectOptions, FactTagOptions, FactType, ReconcileAction, ReconcileOptions, ReconcileResult, SubjectRole, } from './types';
24
+ export { calculateConfidence, normalizeText } from './utils';
25
+ //# sourceMappingURL=index.d.ts.map