@happyvertical/smrt-facts 0.51.32 → 0.51.34

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 (42) hide show
  1. package/dist/__smrt-register__.d.ts +2 -0
  2. package/dist/__smrt-register__.d.ts.map +1 -0
  3. package/dist/__tests__/fixtures/decision-claim-support-3166.d.ts +33 -0
  4. package/dist/__tests__/fixtures/decision-claim-support-3166.d.ts.map +1 -0
  5. package/dist/catalog-search.d.ts +7 -0
  6. package/dist/catalog-search.d.ts.map +1 -0
  7. package/dist/fact-content.d.ts +39 -0
  8. package/dist/fact-content.d.ts.map +1 -0
  9. package/dist/fact-contents.d.ts +32 -0
  10. package/dist/fact-contents.d.ts.map +1 -0
  11. package/dist/fact-evidence.d.ts +37 -0
  12. package/dist/fact-evidence.d.ts.map +1 -0
  13. package/dist/fact-evidences.d.ts +32 -0
  14. package/dist/fact-evidences.d.ts.map +1 -0
  15. package/dist/fact-source.d.ts +29 -0
  16. package/dist/fact-source.d.ts.map +1 -0
  17. package/dist/fact-sources.d.ts +50 -0
  18. package/dist/fact-sources.d.ts.map +1 -0
  19. package/dist/fact-subject.d.ts +28 -0
  20. package/dist/fact-subject.d.ts.map +1 -0
  21. package/dist/fact-subjects.d.ts +56 -0
  22. package/dist/fact-subjects.d.ts.map +1 -0
  23. package/dist/fact-tag.d.ts +34 -0
  24. package/dist/fact-tag.d.ts.map +1 -0
  25. package/dist/fact-tags.d.ts +51 -0
  26. package/dist/fact-tags.d.ts.map +1 -0
  27. package/dist/fact.d.ts +77 -0
  28. package/dist/fact.d.ts.map +1 -0
  29. package/dist/facts.d.ts +173 -0
  30. package/dist/facts.d.ts.map +1 -0
  31. package/dist/index.d.ts +25 -854
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +1 -1
  34. package/dist/manifest.json +1 -1
  35. package/dist/prompts.d.ts +5 -0
  36. package/dist/prompts.d.ts.map +1 -0
  37. package/dist/smrt-knowledge.json +4 -4
  38. package/dist/types.d.ts +258 -382
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/utils.d.ts +26 -0
  41. package/dist/utils.d.ts.map +1 -0
  42. package/package.json +6 -6
@@ -0,0 +1,173 @@
1
+ /**
2
+ * FactCollection - Collection manager for Fact objects
3
+ *
4
+ * Provides query methods for facts by status, type, domain, and tenant.
5
+ * Implements reconcile(), branch(), evolution tree, and confidence methods.
6
+ */
7
+ import { SmrtCollection } from '@happyvertical/smrt-core';
8
+ import { Fact } from './fact';
9
+ import type { EntityBriefing, EvolutionType, FactClaimSupportAssessment, FactClaimSupportCandidate, FactClaimSupportOptions, FactContentRelationship, FactExtractionCandidate, FactExtractionOptions, FactOptions, FactStatus, FactType, ReconcileOptions, ReconcileResult } from './types';
10
+ export declare class FactCollection extends SmrtCollection<Fact> {
11
+ static readonly _itemClass: typeof Fact;
12
+ /**
13
+ * Fetch one catalog page in SQL. The recursive branch walk may inspect more
14
+ * rows inside the database, but the outer query only materializes the page.
15
+ */
16
+ private listCatalogPage;
17
+ /**
18
+ * Get all active facts
19
+ */
20
+ getActive(): Promise<Fact[]>;
21
+ /**
22
+ * Get all pending facts
23
+ */
24
+ getPending(): Promise<Fact[]>;
25
+ /**
26
+ * Get facts by type
27
+ */
28
+ getByType(type: FactType): Promise<Fact[]>;
29
+ /**
30
+ * Get facts by domain
31
+ */
32
+ getByDomain(domain: string): Promise<Fact[]>;
33
+ /**
34
+ * Get facts by status
35
+ */
36
+ getByStatus(status: FactStatus): Promise<Fact[]>;
37
+ /**
38
+ * Get successor facts for a given predecessor (facts that evolved
39
+ * directly from `previousFactId`).
40
+ */
41
+ getSuccessors(previousFactId: string): Promise<Fact[]>;
42
+ /**
43
+ * Find all facts belonging to a specific tenant
44
+ */
45
+ findByTenant(tenantId: string): Promise<Fact[]>;
46
+ /**
47
+ * Find all global (tenant-less) facts.
48
+ *
49
+ * Routes through the shared tenant-global helper so it does not throw under
50
+ * an active tenant context (an explicit `tenant_id IS NULL` filter would be
51
+ * flagged as an isolation violation). (#1600)
52
+ */
53
+ findGlobal(): Promise<Fact[]>;
54
+ /**
55
+ * Find facts for a tenant including global facts.
56
+ *
57
+ * Fails closed if an active tenant context requests a different tenant's
58
+ * rows; the admin/system path keeps the cross-tenant capability. (#1600)
59
+ */
60
+ findWithGlobals(tenantId: string): Promise<Fact[]>;
61
+ /**
62
+ * Browse active facts for editorial association.
63
+ * Uses semantic search when a query is provided and falls back to text filtering
64
+ * if embeddings are unavailable.
65
+ */
66
+ browseCatalog(query?: string, options?: {
67
+ tenantId?: string | null;
68
+ limit?: number;
69
+ offset?: number;
70
+ minSimilarity?: number;
71
+ includeSuperseded?: boolean;
72
+ latestOnly?: boolean;
73
+ }): Promise<Fact[]>;
74
+ /**
75
+ * Explicit data migration after db:migrate adds catalog_search. Run under
76
+ * withSystemContext with old writers stopped. Repeating a batch is safe;
77
+ * concurrent source changes are protected by compare-and-set predicates.
78
+ * A subtype collection backfills only its STI discriminator.
79
+ */
80
+ backfillCatalogSearch(batchSize?: number): Promise<{
81
+ remaining: number;
82
+ }>;
83
+ /**
84
+ * Get all facts linked to a content item.
85
+ */
86
+ getForContent(contentId: string, options?: {
87
+ relationship?: FactContentRelationship;
88
+ includeSuperseded?: boolean;
89
+ latestOnly?: boolean;
90
+ }): Promise<Fact[]>;
91
+ /**
92
+ * Reconcile raw input against existing facts using semantic search + AI.
93
+ * Determines whether to create, merge, or branch.
94
+ *
95
+ * Algorithm:
96
+ * 1. semanticSearch(rawInput) against existing facts
97
+ * 2. Decision:
98
+ * - No match above conflictThreshold (0.60) -> CREATE new fact
99
+ * - Top match >= similarityThreshold (0.85) -> MERGE (add source, bump sourceCount)
100
+ * - Ambiguous zone (0.60-0.85) -> optional typed decision, otherwise AI
101
+ * text disambiguation. A typed merge must meet its separate confidence
102
+ * probability threshold; uncertainty and failures branch conservatively.
103
+ * 3. Record FactSource if source metadata provided
104
+ * 4. Return { action, fact, source?, similarity?, matchedFact? }
105
+ */
106
+ reconcile(options: ReconcileOptions): Promise<ReconcileResult>;
107
+ /**
108
+ * Extract atomic factual statements from unstructured source text using AI.
109
+ *
110
+ * This method is intentionally non-persistent: callers can review, reconcile,
111
+ * link, or discard the returned candidates according to their app workflow.
112
+ */
113
+ extractCandidatesFromText(text: string, options?: FactExtractionOptions): Promise<FactExtractionCandidate[]>;
114
+ /**
115
+ * Extract material factual claims made by an article.
116
+ *
117
+ * This is intentionally separate from source extraction: source extraction
118
+ * finds evidence-backed facts, while claim extraction finds statements the
119
+ * draft itself needs to justify.
120
+ */
121
+ extractArticleClaims(text: string, options?: FactExtractionOptions): Promise<FactExtractionCandidate[]>;
122
+ /**
123
+ * Classify whether a claim is supported by candidate facts/evidence.
124
+ */
125
+ assessClaimSupport(claim: string, candidateFacts: FactClaimSupportCandidate[], options?: FactClaimSupportOptions): Promise<FactClaimSupportAssessment>;
126
+ /**
127
+ * Use AI to determine whether new input should be merged with
128
+ * or branched from an existing fact.
129
+ */
130
+ private _disambiguateWithAI;
131
+ /**
132
+ * Create a branched fact from an existing predecessor.
133
+ *
134
+ * For 'correction' and 'contradiction' evolution types, the
135
+ * predecessor is marked as superseded.
136
+ *
137
+ * @param previousFactId ID of the predecessor fact this branches from.
138
+ * @param data Partial fact options for the new successor.
139
+ * @param evolutionType How the successor relates to the predecessor.
140
+ */
141
+ branch(previousFactId: string, data: Partial<FactOptions>, evolutionType?: EvolutionType): Promise<Fact>;
142
+ /**
143
+ * Walk up the evolution chain via previousFactId, returning the
144
+ * predecessors followed by the current fact in order.
145
+ *
146
+ * @returns Array ordered from root (original) → current fact.
147
+ */
148
+ getEvolutionChain(factId: string): Promise<Fact[]>;
149
+ /**
150
+ * Walk down successors to find the latest (highest confidence) leaf.
151
+ * At each level, picks the successor with the highest confidence score.
152
+ */
153
+ getLatestInChain(factId: string): Promise<Fact>;
154
+ /**
155
+ * Find the root of the chain via `getEvolutionChain`, then collect every
156
+ * successor iteratively via BFS (queue-based, with a `visited` set for
157
+ * cycle protection). Returns the full tree as a flat array in BFS
158
+ * order — root first, then each level of successors.
159
+ */
160
+ getEvolutionTree(factId: string): Promise<Fact[]>;
161
+ /**
162
+ * Recalculate confidence score for a fact based on its sources.
163
+ * Uses calculateConfidence from utils.ts with data from FactSourceCollection.
164
+ */
165
+ recalculateConfidence(factId: string): Promise<number>;
166
+ /**
167
+ * Get a briefing of all facts related to a given entity.
168
+ * Finds all FactSubject links for the entity, loads corresponding facts,
169
+ * and returns summary statistics.
170
+ */
171
+ getEntityBriefing(entityType: string, entityId: string): Promise<EntityBriefing>;
172
+ }
173
+ //# sourceMappingURL=facts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts.d.ts","sourceRoot":"","sources":["../src/facts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAGL,cAAc,EAEf,MAAM,0BAA0B,CAAC;AAiBlC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAS9B,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,0BAA0B,EAC1B,yBAAyB,EACzB,uBAAuB,EAEvB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,eAAe,EAChB,MAAM,SAAS,CAAC;AAuKjB,qBAAa,cAAe,SAAQ,cAAc,CAAC,IAAI,CAAC;IACtD,MAAM,CAAC,QAAQ,CAAC,UAAU,cAAQ;IAElC;;;OAGG;YACW,eAAe;IA2M7B;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAIlC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAInC;;OAEG;IACG,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAIhD;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAIlD;;OAE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