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