truthguard-ai 0.2.0 → 0.4.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.
Potentially problematic release.
This version of truthguard-ai might be problematic. Click here for more details.
- package/dist-npm/Claims/index.d.ts +73 -0
- package/dist-npm/Claims/index.d.ts.map +1 -0
- package/dist-npm/Claims/index.js +1669 -0
- package/dist-npm/Claims/index.js.map +1 -0
- package/dist-npm/Config/index.d.ts +41 -0
- package/dist-npm/Config/index.d.ts.map +1 -0
- package/dist-npm/Config/index.js +129 -0
- package/dist-npm/Config/index.js.map +1 -0
- package/dist-npm/Grounding/index.d.ts +40 -0
- package/dist-npm/Grounding/index.d.ts.map +1 -0
- package/dist-npm/Grounding/index.js +1433 -0
- package/dist-npm/Grounding/index.js.map +1 -0
- package/dist-npm/L2/index.d.ts +93 -0
- package/dist-npm/L2/index.d.ts.map +1 -0
- package/dist-npm/L2/index.js +1773 -0
- package/dist-npm/L2/index.js.map +1 -0
- package/dist-npm/MCP/thin.d.ts +37 -0
- package/dist-npm/MCP/thin.d.ts.map +1 -0
- package/dist-npm/MCP/thin.js +542 -0
- package/dist-npm/MCP/thin.js.map +1 -0
- package/dist-npm/Matchers/index.d.ts +101 -0
- package/dist-npm/Matchers/index.d.ts.map +1 -0
- package/dist-npm/Matchers/index.js +690 -0
- package/dist-npm/Matchers/index.js.map +1 -0
- package/dist-npm/Mode/index.d.ts +87 -0
- package/dist-npm/Mode/index.d.ts.map +1 -0
- package/dist-npm/Mode/index.js +117 -0
- package/dist-npm/Mode/index.js.map +1 -0
- package/dist-npm/Policy/index.d.ts +89 -0
- package/dist-npm/Policy/index.d.ts.map +1 -0
- package/dist-npm/Policy/index.js +143 -0
- package/dist-npm/Policy/index.js.map +1 -0
- package/dist-npm/Registry/index.d.ts +93 -0
- package/dist-npm/Registry/index.d.ts.map +1 -0
- package/dist-npm/Registry/index.js +818 -0
- package/dist-npm/Registry/index.js.map +1 -0
- package/dist-npm/Rules/index.d.ts +587 -0
- package/dist-npm/Rules/index.d.ts.map +1 -0
- package/dist-npm/Rules/index.js +6236 -0
- package/dist-npm/Rules/index.js.map +1 -0
- package/dist-npm/Rules/intents.d.ts +22 -0
- package/dist-npm/Rules/intents.d.ts.map +1 -0
- package/dist-npm/Rules/intents.js +242 -0
- package/dist-npm/Rules/intents.js.map +1 -0
- package/dist-npm/TraceReadiness/index.d.ts +42 -0
- package/dist-npm/TraceReadiness/index.d.ts.map +1 -0
- package/dist-npm/TraceReadiness/index.js +169 -0
- package/dist-npm/TraceReadiness/index.js.map +1 -0
- package/dist-npm/cli-entry.d.ts +7 -0
- package/dist-npm/cli-entry.d.ts.map +1 -0
- package/dist-npm/cli-entry.js +23 -0
- package/dist-npm/cli-entry.js.map +1 -0
- package/dist-npm/i18n/index.d.ts +44 -0
- package/dist-npm/i18n/index.d.ts.map +1 -0
- package/dist-npm/i18n/index.js +124 -0
- package/dist-npm/i18n/index.js.map +1 -0
- package/package.json +6 -15
- package/dist/cli/index.d.ts +0 -15
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -807
- package/dist/cli/index.js.map +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matchers
|
|
3
|
+
*
|
|
4
|
+
* Matching strategies for comparing extracted claim values against
|
|
5
|
+
* values found in tool outputs.
|
|
6
|
+
*
|
|
7
|
+
* V1 supports:
|
|
8
|
+
* - NumericMatcher (relative tolerance)
|
|
9
|
+
* - CountMatcher (exact match)
|
|
10
|
+
* - DateMatcher (exact ISO-8601 match)
|
|
11
|
+
* - NameMatcher (fuzzy / Jaro-Winkler-like similarity)
|
|
12
|
+
*/
|
|
13
|
+
import type { ToleranceConfig, UnitType } from '../types';
|
|
14
|
+
export interface MatchResult {
|
|
15
|
+
matched: boolean;
|
|
16
|
+
/** Numeric deviation (absolute relative difference for numbers). */
|
|
17
|
+
deviation?: number;
|
|
18
|
+
/** Similarity score 0–1 (for name matching). */
|
|
19
|
+
similarity?: number;
|
|
20
|
+
/** Human-readable explanation of the match decision. */
|
|
21
|
+
explanation: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compare two numeric values using a configurable relative tolerance.
|
|
25
|
+
*/
|
|
26
|
+
export declare function matchNumeric(claimed: number, source: number, tolerances: Pick<ToleranceConfig, 'numericRelativeTolerance'>): MatchResult;
|
|
27
|
+
/** Normalise a unit string to its canonical form. */
|
|
28
|
+
export declare function normaliseUnit(raw: string): UnitType | string;
|
|
29
|
+
/**
|
|
30
|
+
* Try to convert `sourceValue` (in `sourceUnit`) to `claimUnit`.
|
|
31
|
+
* Returns the converted value, or null if no conversion path exists.
|
|
32
|
+
*/
|
|
33
|
+
export declare function tryUnitConversion(sourceValue: number, sourceUnit: string, claimUnit: string): number | null;
|
|
34
|
+
/**
|
|
35
|
+
* Compare two numbers with optional unit conversion.
|
|
36
|
+
* If units differ, attempts conversion before comparing.
|
|
37
|
+
*
|
|
38
|
+
* Special handling for percentages:
|
|
39
|
+
* - If claim is "45 percent" and source is 0.45 (or vice versa),
|
|
40
|
+
* normalises both to the same scale before comparing.
|
|
41
|
+
*/
|
|
42
|
+
export declare function matchNumericWithUnits(claimed: number, claimUnit: UnitType | string | undefined, source: number, sourceUnit: string | undefined, tolerances: Pick<ToleranceConfig, 'numericRelativeTolerance'>): MatchResult;
|
|
43
|
+
/**
|
|
44
|
+
* Check if two numbers differ only by a digit transposition.
|
|
45
|
+
* E.g. 23 vs 32, 1234 vs 1243, 156 vs 165.
|
|
46
|
+
* Returns true if swapping exactly one pair of adjacent digits in `claimed`
|
|
47
|
+
* produces `source`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function isTransposedDigits(claimed: number, source: number): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Compare two count values (exact or within 1 for approximate matches).
|
|
52
|
+
*
|
|
53
|
+
* Deviation is returned as a **relative** fraction (same scale as numeric matcher)
|
|
54
|
+
* so that downstream rules (e.g. data_ignored) can apply a uniform threshold.
|
|
55
|
+
* matched counts → deviation 0
|
|
56
|
+
* mismatched → |claimed - source| / max(|source|, 1)
|
|
57
|
+
*/
|
|
58
|
+
export declare function matchCount(claimed: number, source: number, tolerances: Pick<ToleranceConfig, 'countExactMatch'>): MatchResult;
|
|
59
|
+
/**
|
|
60
|
+
* Compare two ISO-8601 date strings (YYYY-MM-DD).
|
|
61
|
+
* Normalises both values before comparison.
|
|
62
|
+
*/
|
|
63
|
+
export declare function matchDate(claimed: string, source: string, _tolerances: Pick<ToleranceConfig, 'dateExactMatch'>): MatchResult;
|
|
64
|
+
/**
|
|
65
|
+
* Compute Jaro similarity between two strings.
|
|
66
|
+
* Returns a value in [0, 1].
|
|
67
|
+
*/
|
|
68
|
+
export declare function jaroSimilarity(s1: string, s2: string): number;
|
|
69
|
+
/**
|
|
70
|
+
* Compute Jaro-Winkler similarity (boosts prefix matches).
|
|
71
|
+
*/
|
|
72
|
+
export declare function jaroWinklerSimilarity(s1: string, s2: string, prefixScale?: number): number;
|
|
73
|
+
export declare function matchName(claimed: string, source: string, tolerances: Pick<ToleranceConfig, 'nameSimilarityThreshold'>): MatchResult;
|
|
74
|
+
/**
|
|
75
|
+
* Recursively extract all leaf values from a JSON-like tool output.
|
|
76
|
+
* Returns strings and numbers found anywhere in the output tree.
|
|
77
|
+
*/
|
|
78
|
+
export declare function extractValuesFromOutput(output: unknown): Array<number | string>;
|
|
79
|
+
/** A value extracted from tool output, optionally annotated with its field name. */
|
|
80
|
+
export interface ExtractedValue {
|
|
81
|
+
value: number | string;
|
|
82
|
+
/** The JSON key path (e.g. "total_minutes", "employee.hours_worked"). */
|
|
83
|
+
fieldName?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Recursively extract all leaf values with their field names.
|
|
87
|
+
*/
|
|
88
|
+
export declare function extractValuesWithKeys(output: unknown): ExtractedValue[];
|
|
89
|
+
/**
|
|
90
|
+
* Infer a unit from a JSON field name.
|
|
91
|
+
* E.g. "total_minutes" → "minutes", "hours_worked" → "hours"
|
|
92
|
+
*/
|
|
93
|
+
export declare function inferUnitFromFieldName(fieldName: string | undefined): UnitType | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Extracts the count of items from a tool output.
|
|
96
|
+
* If the output is an array, returns its length.
|
|
97
|
+
* If it has a "count" / "total" / "length" field, returns that.
|
|
98
|
+
* Otherwise returns null.
|
|
99
|
+
*/
|
|
100
|
+
export declare function extractCountFromOutput(output: unknown): number | null;
|
|
101
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Matchers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAO1D,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;CACrB;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,IAAI,CAAC,eAAe,EAAE,0BAA0B,CAAC,GAC5D,WAAW,CAyBb;AA8JD,qDAAqD;AACrD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAG5D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,IAAI,CAWf;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,QAAQ,GAAG,MAAM,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