truthguard-ai 0.1.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.

Files changed (199) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +363 -0
  3. package/dist/Advisor/index.d.ts +78 -0
  4. package/dist/Advisor/index.d.ts.map +1 -0
  5. package/dist/Advisor/index.js +539 -0
  6. package/dist/Advisor/index.js.map +1 -0
  7. package/dist/Alerting/index.d.ts +35 -0
  8. package/dist/Alerting/index.d.ts.map +1 -0
  9. package/dist/Alerting/index.js +76 -0
  10. package/dist/Alerting/index.js.map +1 -0
  11. package/dist/Auth/index.d.ts +82 -0
  12. package/dist/Auth/index.d.ts.map +1 -0
  13. package/dist/Auth/index.js +242 -0
  14. package/dist/Auth/index.js.map +1 -0
  15. package/dist/Baseline/index.d.ts +43 -0
  16. package/dist/Baseline/index.d.ts.map +1 -0
  17. package/dist/Baseline/index.js +195 -0
  18. package/dist/Baseline/index.js.map +1 -0
  19. package/dist/Claims/index.d.ts +73 -0
  20. package/dist/Claims/index.d.ts.map +1 -0
  21. package/dist/Claims/index.js +1669 -0
  22. package/dist/Claims/index.js.map +1 -0
  23. package/dist/Client/index.d.ts +90 -0
  24. package/dist/Client/index.d.ts.map +1 -0
  25. package/dist/Client/index.js +186 -0
  26. package/dist/Client/index.js.map +1 -0
  27. package/dist/Config/index.d.ts +41 -0
  28. package/dist/Config/index.d.ts.map +1 -0
  29. package/dist/Config/index.js +129 -0
  30. package/dist/Config/index.js.map +1 -0
  31. package/dist/Coverage/index.d.ts +28 -0
  32. package/dist/Coverage/index.d.ts.map +1 -0
  33. package/dist/Coverage/index.js +134 -0
  34. package/dist/Coverage/index.js.map +1 -0
  35. package/dist/Demo/index.d.ts +16 -0
  36. package/dist/Demo/index.d.ts.map +1 -0
  37. package/dist/Demo/index.js +189 -0
  38. package/dist/Demo/index.js.map +1 -0
  39. package/dist/Gate/index.d.ts +39 -0
  40. package/dist/Gate/index.d.ts.map +1 -0
  41. package/dist/Gate/index.js +207 -0
  42. package/dist/Gate/index.js.map +1 -0
  43. package/dist/Grounding/index.d.ts +40 -0
  44. package/dist/Grounding/index.d.ts.map +1 -0
  45. package/dist/Grounding/index.js +1433 -0
  46. package/dist/Grounding/index.js.map +1 -0
  47. package/dist/L2/index.d.ts +93 -0
  48. package/dist/L2/index.d.ts.map +1 -0
  49. package/dist/L2/index.js +1773 -0
  50. package/dist/L2/index.js.map +1 -0
  51. package/dist/MCP/index.d.ts +139 -0
  52. package/dist/MCP/index.d.ts.map +1 -0
  53. package/dist/MCP/index.js +1250 -0
  54. package/dist/MCP/index.js.map +1 -0
  55. package/dist/Matchers/index.d.ts +101 -0
  56. package/dist/Matchers/index.d.ts.map +1 -0
  57. package/dist/Matchers/index.js +690 -0
  58. package/dist/Matchers/index.js.map +1 -0
  59. package/dist/Middleware/index.d.ts +146 -0
  60. package/dist/Middleware/index.d.ts.map +1 -0
  61. package/dist/Middleware/index.js +239 -0
  62. package/dist/Middleware/index.js.map +1 -0
  63. package/dist/Mode/index.d.ts +87 -0
  64. package/dist/Mode/index.d.ts.map +1 -0
  65. package/dist/Mode/index.js +117 -0
  66. package/dist/Mode/index.js.map +1 -0
  67. package/dist/Policy/index.d.ts +89 -0
  68. package/dist/Policy/index.d.ts.map +1 -0
  69. package/dist/Policy/index.js +143 -0
  70. package/dist/Policy/index.js.map +1 -0
  71. package/dist/Proxy/SessionStore.d.ts +94 -0
  72. package/dist/Proxy/SessionStore.d.ts.map +1 -0
  73. package/dist/Proxy/SessionStore.js +225 -0
  74. package/dist/Proxy/SessionStore.js.map +1 -0
  75. package/dist/Proxy/index.d.ts +166 -0
  76. package/dist/Proxy/index.d.ts.map +1 -0
  77. package/dist/Proxy/index.js +531 -0
  78. package/dist/Proxy/index.js.map +1 -0
  79. package/dist/Registry/index.d.ts +93 -0
  80. package/dist/Registry/index.d.ts.map +1 -0
  81. package/dist/Registry/index.js +818 -0
  82. package/dist/Registry/index.js.map +1 -0
  83. package/dist/Reports/index.d.ts +38 -0
  84. package/dist/Reports/index.d.ts.map +1 -0
  85. package/dist/Reports/index.js +149 -0
  86. package/dist/Reports/index.js.map +1 -0
  87. package/dist/Rules/index.d.ts +587 -0
  88. package/dist/Rules/index.d.ts.map +1 -0
  89. package/dist/Rules/index.js +6236 -0
  90. package/dist/Rules/index.js.map +1 -0
  91. package/dist/Rules/intents.d.ts +22 -0
  92. package/dist/Rules/intents.d.ts.map +1 -0
  93. package/dist/Rules/intents.js +242 -0
  94. package/dist/Rules/intents.js.map +1 -0
  95. package/dist/Runner/index.d.ts +39 -0
  96. package/dist/Runner/index.d.ts.map +1 -0
  97. package/dist/Runner/index.js +185 -0
  98. package/dist/Runner/index.js.map +1 -0
  99. package/dist/SDK/anthropic.d.ts +102 -0
  100. package/dist/SDK/anthropic.d.ts.map +1 -0
  101. package/dist/SDK/anthropic.js +425 -0
  102. package/dist/SDK/anthropic.js.map +1 -0
  103. package/dist/SDK/openai.d.ts +164 -0
  104. package/dist/SDK/openai.d.ts.map +1 -0
  105. package/dist/SDK/openai.js +557 -0
  106. package/dist/SDK/openai.js.map +1 -0
  107. package/dist/Store/index.d.ts +72 -0
  108. package/dist/Store/index.d.ts.map +1 -0
  109. package/dist/Store/index.js +136 -0
  110. package/dist/Store/index.js.map +1 -0
  111. package/dist/Telemetry/index.d.ts +84 -0
  112. package/dist/Telemetry/index.d.ts.map +1 -0
  113. package/dist/Telemetry/index.js +239 -0
  114. package/dist/Telemetry/index.js.map +1 -0
  115. package/dist/Trace/index.d.ts +219 -0
  116. package/dist/Trace/index.d.ts.map +1 -0
  117. package/dist/Trace/index.js +763 -0
  118. package/dist/Trace/index.js.map +1 -0
  119. package/dist/TraceReadiness/index.d.ts +42 -0
  120. package/dist/TraceReadiness/index.d.ts.map +1 -0
  121. package/dist/TraceReadiness/index.js +169 -0
  122. package/dist/TraceReadiness/index.js.map +1 -0
  123. package/dist/cli/index.d.ts +15 -0
  124. package/dist/cli/index.d.ts.map +1 -0
  125. package/dist/cli/index.js +807 -0
  126. package/dist/cli/index.js.map +1 -0
  127. package/dist/i18n/index.d.ts +44 -0
  128. package/dist/i18n/index.d.ts.map +1 -0
  129. package/dist/i18n/index.js +124 -0
  130. package/dist/i18n/index.js.map +1 -0
  131. package/dist/index.d.ts +55 -0
  132. package/dist/index.d.ts.map +1 -0
  133. package/dist/index.js +218 -0
  134. package/dist/index.js.map +1 -0
  135. package/dist/thin.d.ts +39 -0
  136. package/dist/thin.d.ts.map +1 -0
  137. package/dist/thin.js +120 -0
  138. package/dist/thin.js.map +1 -0
  139. package/dist/types/index.d.ts +498 -0
  140. package/dist/types/index.d.ts.map +1 -0
  141. package/dist/types/index.js +17 -0
  142. package/dist/types/index.js.map +1 -0
  143. package/dist-npm/Alerting/index.d.ts +35 -0
  144. package/dist-npm/Alerting/index.d.ts.map +1 -0
  145. package/dist-npm/Alerting/index.js +76 -0
  146. package/dist-npm/Alerting/index.js.map +1 -0
  147. package/dist-npm/Auth/index.d.ts +82 -0
  148. package/dist-npm/Auth/index.d.ts.map +1 -0
  149. package/dist-npm/Auth/index.js +242 -0
  150. package/dist-npm/Auth/index.js.map +1 -0
  151. package/dist-npm/Client/index.d.ts +90 -0
  152. package/dist-npm/Client/index.d.ts.map +1 -0
  153. package/dist-npm/Client/index.js +186 -0
  154. package/dist-npm/Client/index.js.map +1 -0
  155. package/dist-npm/Demo/index.d.ts +16 -0
  156. package/dist-npm/Demo/index.d.ts.map +1 -0
  157. package/dist-npm/Demo/index.js +189 -0
  158. package/dist-npm/Demo/index.js.map +1 -0
  159. package/dist-npm/Middleware/index.d.ts +146 -0
  160. package/dist-npm/Middleware/index.d.ts.map +1 -0
  161. package/dist-npm/Middleware/index.js +239 -0
  162. package/dist-npm/Middleware/index.js.map +1 -0
  163. package/dist-npm/Proxy/SessionStore.d.ts +94 -0
  164. package/dist-npm/Proxy/SessionStore.d.ts.map +1 -0
  165. package/dist-npm/Proxy/SessionStore.js +225 -0
  166. package/dist-npm/Proxy/SessionStore.js.map +1 -0
  167. package/dist-npm/Proxy/index.d.ts +166 -0
  168. package/dist-npm/Proxy/index.d.ts.map +1 -0
  169. package/dist-npm/Proxy/index.js +531 -0
  170. package/dist-npm/Proxy/index.js.map +1 -0
  171. package/dist-npm/SDK/anthropic.d.ts +102 -0
  172. package/dist-npm/SDK/anthropic.d.ts.map +1 -0
  173. package/dist-npm/SDK/anthropic.js +425 -0
  174. package/dist-npm/SDK/anthropic.js.map +1 -0
  175. package/dist-npm/SDK/openai.d.ts +164 -0
  176. package/dist-npm/SDK/openai.d.ts.map +1 -0
  177. package/dist-npm/SDK/openai.js +557 -0
  178. package/dist-npm/SDK/openai.js.map +1 -0
  179. package/dist-npm/Store/index.d.ts +72 -0
  180. package/dist-npm/Store/index.d.ts.map +1 -0
  181. package/dist-npm/Store/index.js +136 -0
  182. package/dist-npm/Store/index.js.map +1 -0
  183. package/dist-npm/Telemetry/index.d.ts +84 -0
  184. package/dist-npm/Telemetry/index.d.ts.map +1 -0
  185. package/dist-npm/Telemetry/index.js +239 -0
  186. package/dist-npm/Telemetry/index.js.map +1 -0
  187. package/dist-npm/Trace/index.d.ts +219 -0
  188. package/dist-npm/Trace/index.d.ts.map +1 -0
  189. package/dist-npm/Trace/index.js +763 -0
  190. package/dist-npm/Trace/index.js.map +1 -0
  191. package/dist-npm/thin.d.ts +39 -0
  192. package/dist-npm/thin.d.ts.map +1 -0
  193. package/dist-npm/thin.js +120 -0
  194. package/dist-npm/thin.js.map +1 -0
  195. package/dist-npm/types/index.d.ts +498 -0
  196. package/dist-npm/types/index.d.ts.map +1 -0
  197. package/dist-npm/types/index.js +17 -0
  198. package/dist-npm/types/index.js.map +1 -0
  199. package/package.json +114 -0
@@ -0,0 +1,498 @@
1
+ /**
2
+ * AI Reliability Control Plane — Shared Domain Types
3
+ *
4
+ * These types define the core domain model for V1:
5
+ * Trace, Claims, Grounding Verdicts, Reports, and Tolerances.
6
+ */
7
+ /** A unique identifier string. */
8
+ export type TraceId = string;
9
+ /** Supported step roles within a trace. */
10
+ export type TraceStepRole = 'system_prompt' | 'user_input' | 'tool_call' | 'tool_output' | 'llm_call' | 'final_response';
11
+ /** A single tool call made during an agent step. */
12
+ export interface ToolCall {
13
+ /** Name of the tool / function called. */
14
+ toolName: string;
15
+ /** Parameters passed to the tool. */
16
+ parameters: Record<string, unknown>;
17
+ /** ISO-8601 timestamp when the call was made. */
18
+ calledAt?: string;
19
+ }
20
+ /** The output returned by a tool. */
21
+ export interface ToolOutput {
22
+ /** Name of the tool that produced this output. */
23
+ toolName: string;
24
+ /** The raw output value. May be any JSON-serialisable shape. */
25
+ output: unknown;
26
+ /** ISO-8601 timestamp when the output was received. */
27
+ receivedAt?: string;
28
+ }
29
+ /** One logical step within an agent execution trace. */
30
+ export interface TraceStep {
31
+ /** Unique identifier for this step (auto-assigned if not provided). */
32
+ stepId: string;
33
+ /** Role of the step. */
34
+ role: TraceStepRole;
35
+ /** The human-readable or LLM-generated content for this step. */
36
+ content: string;
37
+ /** Tool calls associated with this step (for tool_call steps). */
38
+ toolCalls?: ToolCall[];
39
+ /** Tool outputs associated with this step (for tool_output steps). */
40
+ toolOutputs?: ToolOutput[];
41
+ /** Latency in milliseconds for this step. */
42
+ latencyMs?: number;
43
+ /** Token usage for LLM steps. */
44
+ tokens?: {
45
+ prompt: number;
46
+ completion: number;
47
+ total: number;
48
+ /** Provider finish reason: 'stop' = natural, 'length' = token limit hit. */
49
+ finishReason?: string;
50
+ /** The max_tokens parameter sent in the API request. */
51
+ maxTokens?: number;
52
+ };
53
+ /** Rate limit info from provider response headers (if captured). */
54
+ rateLimitInfo?: {
55
+ /** Remaining requests in the current window. */
56
+ remainingRequests?: number;
57
+ /** Remaining tokens in the current window. */
58
+ remainingTokens?: number;
59
+ /** Seconds until the rate limit resets. */
60
+ resetSeconds?: number;
61
+ };
62
+ /** ISO-8601 timestamp when this step started. */
63
+ startedAt?: string;
64
+ /** ISO-8601 timestamp when this step ended. */
65
+ endedAt?: string;
66
+ /** Arbitrary metadata. */
67
+ metadata?: Record<string, unknown>;
68
+ }
69
+ /** A complete captured agent execution trace. */
70
+ export interface Trace {
71
+ /** Unique trace identifier. */
72
+ traceId: TraceId;
73
+ /** Ordered list of steps in this trace. */
74
+ steps: TraceStep[];
75
+ /** ISO-8601 timestamp when the trace started. */
76
+ startedAt?: string;
77
+ /** ISO-8601 timestamp when the trace ended. */
78
+ endedAt?: string;
79
+ /** Total latency in milliseconds for the full trace. */
80
+ totalLatencyMs?: number;
81
+ /** Arbitrary metadata (e.g., session ID, user ID, model version). */
82
+ metadata?: Record<string, unknown>;
83
+ }
84
+ /** Types of extractable claims. L1: number, date, name, count. L2: boolean, enum, list_items, key_value, aggregation, range. */
85
+ export type ClaimType = 'number' | 'date' | 'name' | 'count' | 'boolean' | 'enum' | 'list_items' | 'key_value' | 'aggregation' | 'range';
86
+ /**
87
+ * Canonical unit-of-measure values.
88
+ * Time · Distance · Mass · Data · Percentage · Angle.
89
+ * L1 extraction stores whichever UNIT_WORDS form was matched;
90
+ * the Matchers layer normalises aliases via `normaliseUnit()`.
91
+ */
92
+ export type UnitType = 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years' | 'mm' | 'cm' | 'meters' | 'km' | 'miles' | 'kg' | 'lbs' | 'bytes' | 'kb' | 'mb' | 'gb' | 'usd' | 'eur' | 'gbp' | 'rsd' | 'chf' | 'jpy' | 'cny' | 'rub' | 'inr' | 'brl' | 'percent' | 'degrees';
93
+ /** Where in the trace a claim was extracted from. */
94
+ export interface ClaimSource {
95
+ /** The step from which the claim was extracted. */
96
+ stepId: string;
97
+ /** Role of the source step. */
98
+ role: TraceStepRole;
99
+ /** Verbatim text segment containing the claim. */
100
+ rawText: string;
101
+ }
102
+ /** A single factual claim extracted from the agent's final response. */
103
+ export interface Claim {
104
+ /** Unique identifier for this claim within a report. */
105
+ claimId: string;
106
+ /** The type of the claim. */
107
+ type: ClaimType;
108
+ /** The normalised value of the claim (number, ISO date string, string). */
109
+ value: number | string;
110
+ /** Original text from which the claim was extracted. */
111
+ rawText: string;
112
+ /** Source location in the trace. */
113
+ source: ClaimSource;
114
+ /** Unit of measurement (e.g. "hours", "minutes") — set when a number is paired with a unit word. */
115
+ unit?: UnitType;
116
+ /** Entity/subject associated with the claim (e.g. "Danica") — the nearest proper noun. */
117
+ entity?: string;
118
+ /** JSON field name from tool output that this claim relates to (L2 structured context). */
119
+ fieldName?: string;
120
+ /** The original tool output value that this claim was extracted against (L2). */
121
+ sourceFieldValue?: unknown;
122
+ /** For list_items claims: the full set of expected items from tool output. */
123
+ expectedItems?: string[];
124
+ /** For list_items claims: items mentioned in the response. */
125
+ mentionedItems?: string[];
126
+ /** For aggregation claims: the operation performed (sum, avg, count, min, max). */
127
+ aggregationOp?: 'sum' | 'avg' | 'count' | 'count_distinct' | 'min' | 'max' | 'pct_of_total';
128
+ /** For aggregation claims: the computed correct value. */
129
+ computedValue?: number;
130
+ /** Metric/measure name derived from tool output field (e.g. "late_count", "overtime_hours"). */
131
+ metric?: string;
132
+ /** Time period context for this claim (e.g. "2024-01", "Q1 2024"), extracted from tool call params or text. */
133
+ period?: string;
134
+ /** Whether the claim is negated ("nema kašnjenja" → true, value implicitly 0). */
135
+ negated?: boolean;
136
+ /** Comparison operator when claim is a bound, not an exact ("više od 50" → ">"). */
137
+ comparisonOp?: '>' | '<' | '>=' | '<=' | '==' | '!=';
138
+ /** Direction of percentage/value change ("rast od 12%" → "increase"). */
139
+ changeDirection?: 'increase' | 'decrease';
140
+ /** Superlative rank claim ("najkritičniji" → 1, "top 3" → 3). */
141
+ rank?: number;
142
+ /** Status transition: the prior state before the change. */
143
+ transitionFrom?: string;
144
+ /** Status transition: the new state after the change. */
145
+ transitionTo?: string;
146
+ /**
147
+ * Scope classification from sibling-family relevance filtering.
148
+ * - `in_scope`: active sibling group, normal verification.
149
+ * - `weak_scope`: weakly activated sibling (single mention), reduced penalty on UNGROUNDED.
150
+ * - `suppressed`: dormant sibling when active siblings exist — verdict forced to GROUNDED.
151
+ * Only set on `list_items` claims from keyed containers.
152
+ */
153
+ siblingScope?: 'in_scope' | 'weak_scope' | 'suppressed';
154
+ /**
155
+ * Debug: the sibling family pattern this claim belongs to (e.g. "by_date.*.people").
156
+ * Only set when sibling-scope filtering was applied.
157
+ */
158
+ siblingFamilyPattern?: string;
159
+ }
160
+ /** Possible verdicts for a single claim grounding check. */
161
+ export type VerdictType = 'GROUNDED' | 'APPROXIMATE_MATCH' | 'UNGROUNDED' | 'UNVERIFIABLE' | 'MULTI_STEP';
162
+ /** Severity levels for claim verdicts. */
163
+ export type ClaimSeverity = 'HIGH' | 'MEDIUM' | 'LOW';
164
+ /** Grounding failure type codes (V1). */
165
+ export type FailureType = 'grounding.empty_fabrication' | 'grounding.no_tool_call' | 'grounding.unverified_value' | 'grounding.math_error' | 'grounding.data_ignored' | 'grounding.wrong_query' | 'grounding.incomplete_response' | 'grounding.contradictory_claims' | 'grounding.tool_error_ignored' | 'grounding.excessive_tool_calls' | 'grounding.stale_knowledge' | 'grounding.irrelevant_context' | 'reasoning.scope_mismatch' | 'reasoning.overconfident_language' | 'reasoning.language_mismatch' | 'grounding.hallucinated_entity' | 'grounding.question_not_answered' | 'orchestration.malformed_tool_input' | 'orchestration.raw_output_leak' | 'orchestration.intermediate_response_leak' | 'orchestration.token_limit_truncation' | 'orchestration.rate_limit_degradation' | 'orchestration.quota_exhaustion' | 'orchestration.model_fallback' | 'safety.prompt_leak' | 'safety.sensitive_data_exposure' | 'grounding.entity_value_swap' | 'reasoning.instruction_violation' | 'instrumentation.duplicate_user_input' | 'orchestration.tool_budget_exhaustion' | 'orchestration.tool_period_mismatch' | 'grounding.stale_cross_turn_reuse' | 'orchestration.tool_capability_gap' | 'grounding.period_label_mismatch' | 'grounding.aggregation_scope_error' | 'grounding.missing_grouping' | 'reasoning.transformational_intent' | 'grounding.metric_mismatch' | 'reasoning.partial_period_risk' | 'orchestration.ai_unavailable' | 'orchestration.answer_refusal' | 'orchestration.tool_selection_error' | 'orchestration.tool_output_error' | 'orchestration.fabricated_tool_input' | 'reasoning.percentage_error' | 'reasoning.ratio_error' | 'reasoning.multiplication_error';
166
+ /** The result of grounding a single claim against tool outputs. */
167
+ export interface ClaimVerdict {
168
+ /** The claim that was evaluated. */
169
+ claim: Claim;
170
+ /** The grounding verdict. */
171
+ verdict: VerdictType;
172
+ /** The tool output value that was matched against (if found). */
173
+ sourceValue?: unknown;
174
+ /** Which tool output step provided the evidence. */
175
+ sourceStepId?: string;
176
+ /** Numeric deviation (e.g., 0.02 = 2%). Populated for number/count claims. */
177
+ deviation?: number;
178
+ /** The grounding rule that produced this verdict. */
179
+ ruleUsed?: string;
180
+ /** Human-readable explanation. */
181
+ explanation: string;
182
+ /** Failure type, if the verdict is UNGROUNDED. */
183
+ failureType?: FailureType;
184
+ /** Severity of the verdict (HIGH = exact mismatch on count/date, MEDIUM = numeric deviation, LOW = approximate match or name). */
185
+ severity?: ClaimSeverity;
186
+ }
187
+ /** Configurable tolerances for grounding checks. */
188
+ export interface ToleranceConfig {
189
+ /** Relative tolerance for numeric values (e.g. 0.05 = 5%). Default: 0.05. */
190
+ numericRelativeTolerance: number;
191
+ /** Whether count claims require exact match. Default: true. */
192
+ countExactMatch: boolean;
193
+ /** Whether date claims require exact match. Default: true. */
194
+ dateExactMatch: boolean;
195
+ /**
196
+ * Threshold for fuzzy name matching (0–1, Jaro-Winkler-like score).
197
+ * Default: 0.85.
198
+ */
199
+ nameSimilarityThreshold: number;
200
+ }
201
+ /** Default tolerance configuration. */
202
+ export declare const DEFAULT_TOLERANCES: ToleranceConfig;
203
+ /** How much the user should trust the entire grounding report. */
204
+ export type ReportConfidenceLevel = 'high' | 'medium' | 'low';
205
+ /**
206
+ * Meta-assessment of the grounding report's own reliability.
207
+ *
208
+ * This is NOT the same as `groundingScore`:
209
+ * - `groundingScore` = how well the AI's claims match tool data
210
+ * - `reportConfidence` = how much we trust the analysis itself
211
+ *
212
+ * Example: groundingScore=0.95 on 1 claim with no tool_outputs → low confidence.
213
+ */
214
+ export interface ReportConfidence {
215
+ /** Tier for display: high = show normally, medium = show with caveat, low = hide or disclaimer. */
216
+ level: ReportConfidenceLevel;
217
+ /** Internal composite score (0–1). Do NOT display to end-users as a percentage. */
218
+ score: number;
219
+ /** Human-readable explanation for the confidence level. */
220
+ note: string;
221
+ /** Machine-readable reason codes for frontend badges, analytics, and future AI routing. */
222
+ reasons: string[];
223
+ }
224
+ /** Confidence level for a detected failure. */
225
+ export type FailureConfidence = 'high' | 'medium' | 'low';
226
+ /** Severity level assigned by the failure registry + confidence. */
227
+ export type FailureSeverity = 'critical' | 'high' | 'medium' | 'low';
228
+ /** Role of a failure within an orchestrated report. */
229
+ export type FailureRole = 'primary' | 'secondary' | 'suppressed';
230
+ /** Detected failure summary in a grounding report. */
231
+ export interface DetectedFailure {
232
+ /** The failure type code. */
233
+ type: FailureType;
234
+ /** Human-readable description. */
235
+ description: string;
236
+ /** Related claim IDs. */
237
+ claimIds: string[];
238
+ /**
239
+ * How confident the detection is.
240
+ * - high: deterministic / strong structural signal (date mismatch, empty output)
241
+ * - medium: plausible heuristic (math error proximity)
242
+ * - low: hypothesis only — may be a false positive (entity name not in params)
243
+ */
244
+ confidence: FailureConfidence;
245
+ /**
246
+ * Severity computed from failure type + confidence.
247
+ * Derived from the failure registry's defaultSeverity, demoted for lower confidence.
248
+ */
249
+ severity: FailureSeverity;
250
+ /**
251
+ * Role assigned by the orchestration layer.
252
+ * - primary: root-cause failure
253
+ * - secondary: consequence of a primary failure
254
+ * - suppressed: redundant, hidden from default view
255
+ */
256
+ role: FailureRole;
257
+ /**
258
+ * If this failure is secondary or suppressed, the primary failure type that caused it.
259
+ */
260
+ suppressedBy?: FailureType;
261
+ /**
262
+ * Root-cause diagnosis derived from trace structure analysis.
263
+ * Explains *why* this failure occurred (e.g., "Agent loop exhausted after 4 iterations").
264
+ */
265
+ diagnosis?: string;
266
+ /**
267
+ * Actionable fix suggestion for the agent developer.
268
+ * Explains what to change to prevent this failure pattern.
269
+ */
270
+ suggestedFix?: string;
271
+ }
272
+ /** The full grounding report for a single trace. */
273
+ export interface GroundingReport {
274
+ /** The trace that was evaluated. */
275
+ traceId: TraceId;
276
+ /** ISO-8601 timestamp when the report was generated. */
277
+ generatedAt: string;
278
+ /** Total number of claims found in the final response. */
279
+ claimsTotal: number;
280
+ /** Number of claims that were verified (GROUNDED or APPROXIMATE_MATCH). */
281
+ claimsVerified: number;
282
+ /** Number of claims that were skipped (UNVERIFIABLE or MULTI_STEP). */
283
+ claimsSkipped: number;
284
+ /** Number of claims that failed grounding (UNGROUNDED). */
285
+ claimsFailed: number;
286
+ /**
287
+ * Overall grounding score (0–1).
288
+ * Computed as claimsVerified / (claimsTotal - claimsSkipped),
289
+ * or 1.0 when there are no verifiable claims.
290
+ */
291
+ groundingScore: number;
292
+ /** Per-claim verdicts. */
293
+ verdicts: ClaimVerdict[];
294
+ /**
295
+ * Confirmed grounding failures (high/medium confidence).
296
+ * Suitable for CI gates and blocking decisions.
297
+ */
298
+ detectedFailures: DetectedFailure[];
299
+ /**
300
+ * Low-confidence hypotheses — possible issues that need human review.
301
+ * Should NOT block CI or trigger hard alerts.
302
+ */
303
+ hypotheses: DetectedFailure[];
304
+ /** Aggregate counts by confidence level. */
305
+ failureCounts: {
306
+ high: number;
307
+ medium: number;
308
+ low: number;
309
+ };
310
+ /** Tolerances used during evaluation. */
311
+ tolerancesUsed: ToleranceConfig;
312
+ /**
313
+ * Root cause — one-sentence explanation of the primary failure.
314
+ * Derived from the highest-severity primary detected failure.
315
+ * Undefined when there are no failures.
316
+ */
317
+ rootCause?: string;
318
+ /**
319
+ * Human-readable narrative summarising all detected issues,
320
+ * their causal relationships, and suggested remediations.
321
+ * Undefined when there are no failures.
322
+ */
323
+ summary?: string;
324
+ /**
325
+ * Ordered list of failure types to fix, root causes first.
326
+ * Derived from the suppression graph — fixing earlier items
327
+ * may automatically resolve later ones.
328
+ */
329
+ repairSequence?: {
330
+ type: FailureType;
331
+ reason: string;
332
+ }[];
333
+ /**
334
+ * Trace quality assessment — tells the user how complete their trace is
335
+ * and what CANNOT be verified given missing elements.
336
+ * Always populated by GroundingEngine.evaluate().
337
+ */
338
+ traceQuality?: import('../TraceReadiness').TraceQualityReport;
339
+ /**
340
+ * Whether the user's question was resolved.
341
+ * Derived from detected failures — false when critical completeness
342
+ * failures (answer_refusal, question_not_answered, etc.) are detected.
343
+ */
344
+ resolved?: boolean;
345
+ /**
346
+ * Short explanation of the resolution status.
347
+ * E.g. "AI explicitly refused to answer" or "All claims grounded".
348
+ */
349
+ resolutionNote?: string;
350
+ /**
351
+ * Meta-assessment of the report's own reliability.
352
+ * Combines trace completeness, claim coverage, and disabled-check penalties
353
+ * into a single tier + score that tells the frontend how to present results.
354
+ */
355
+ reportConfidence: ReportConfidence;
356
+ /** Number of conversation turns (1 = single-turn). Present when multi-turn. */
357
+ turnCount?: number;
358
+ /** Zero-based index of the turn that was evaluated. Present when multi-turn. */
359
+ activeTurnIndex?: number;
360
+ }
361
+ /** A single test case in a golden dataset (one line in a JSONL file). */
362
+ export interface DatasetEntry {
363
+ /** Human-readable label for this test case. */
364
+ name: string;
365
+ /** The trace to evaluate. */
366
+ trace: Trace;
367
+ /**
368
+ * Optional: expected grounding score (0–1).
369
+ * If provided, the runner checks that the actual score meets or beats this expectation.
370
+ */
371
+ expectedScore?: number;
372
+ /**
373
+ * Optional: failure types that MUST be detected.
374
+ * If provided, the runner verifies all listed types appear in detectedFailures.
375
+ */
376
+ expectedFailures?: FailureType[];
377
+ /**
378
+ * Optional: failure types that MUST NOT be detected.
379
+ * If provided, the runner verifies none of these types appear in detectedFailures.
380
+ */
381
+ forbiddenFailures?: FailureType[];
382
+ }
383
+ /** Result of evaluating a single dataset entry. */
384
+ export interface DatasetEntryResult {
385
+ /** Name from the dataset entry. */
386
+ name: string;
387
+ /** Whether all assertions passed. */
388
+ passed: boolean;
389
+ /** The full grounding report. */
390
+ report: GroundingReport;
391
+ /** Per-assertion results. */
392
+ assertions: AssertionResult[];
393
+ }
394
+ /** Result of a single assertion within a dataset entry. */
395
+ export interface AssertionResult {
396
+ /** What was checked. */
397
+ check: string;
398
+ /** Whether it passed. */
399
+ passed: boolean;
400
+ /** Human-readable detail on failure. */
401
+ detail?: string;
402
+ }
403
+ /** Aggregate result of running an entire dataset. */
404
+ export interface DatasetRunResult {
405
+ /** Total entries evaluated. */
406
+ totalEntries: number;
407
+ /** Entries where all assertions passed. */
408
+ passedEntries: number;
409
+ /** Entries where at least one assertion failed. */
410
+ failedEntries: number;
411
+ /** Average grounding score across all entries. */
412
+ averageScore: number;
413
+ /** Per-entry results. */
414
+ entries: DatasetEntryResult[];
415
+ }
416
+ /** A single assertion in a gate configuration. */
417
+ export interface GateAssertion {
418
+ /** The metric to check. */
419
+ metric: 'grounding_score' | 'failure_count' | 'pass_rate';
420
+ /** Comparison operator. */
421
+ operator: '>=' | '<=' | '==' | '>' | '<';
422
+ /** Threshold value. */
423
+ threshold: number;
424
+ }
425
+ /** Configuration for a CI quality gate. */
426
+ export interface GateConfig {
427
+ /** Human-readable name for the gate. */
428
+ name: string;
429
+ /** Assertions that must all pass for the gate to pass. */
430
+ assertions: GateAssertion[];
431
+ }
432
+ /** Result of evaluating a gate against a dataset run. */
433
+ export interface GateResult {
434
+ /** Gate name. */
435
+ name: string;
436
+ /** Whether the gate passed (all assertions met). */
437
+ passed: boolean;
438
+ /** Per-assertion evaluation. */
439
+ assertions: GateAssertionResult[];
440
+ }
441
+ /** Result of a single gate assertion. */
442
+ export interface GateAssertionResult {
443
+ /** The assertion that was evaluated. */
444
+ assertion: GateAssertion;
445
+ /** Actual value observed. */
446
+ actualValue: number;
447
+ /** Whether it passed. */
448
+ passed: boolean;
449
+ }
450
+ /** Snapshot of key metrics from a dataset run, saved as a baseline. */
451
+ export interface BaselineSnapshot {
452
+ /** ISO-8601 timestamp when the baseline was created. */
453
+ createdAt: string;
454
+ /** Label (e.g. branch name, commit SHA, "main"). */
455
+ label: string;
456
+ /** Average grounding score across the dataset. */
457
+ averageScore: number;
458
+ /** Total detected failures (high + medium confidence). */
459
+ totalFailures: number;
460
+ /** Dataset pass rate. */
461
+ passRate: number;
462
+ /** Per-entry scores for drill-down. */
463
+ entryScores: Array<{
464
+ name: string;
465
+ score: number;
466
+ failureCount: number;
467
+ }>;
468
+ }
469
+ /** Comparison between a current run and a baseline snapshot. */
470
+ export interface BaselineComparison {
471
+ /** The baseline label that was compared against. */
472
+ baselineLabel: string;
473
+ /** Delta in average grounding score (current - baseline). Positive = improvement. */
474
+ scoreDelta: number;
475
+ /** Delta in total failure count. Negative = improvement. */
476
+ failureDelta: number;
477
+ /** Delta in pass rate. Positive = improvement. */
478
+ passRateDelta: number;
479
+ /** Whether the run is within an acceptable tolerance of the baseline. */
480
+ withinTolerance: boolean;
481
+ /** The tolerance that was used. */
482
+ tolerance: number;
483
+ /** Per-entry regressions (entries that got worse). */
484
+ regressions: Array<{
485
+ name: string;
486
+ baselineScore: number;
487
+ currentScore: number;
488
+ delta: number;
489
+ }>;
490
+ /** Per-entry improvements (entries that got better). */
491
+ improvements: Array<{
492
+ name: string;
493
+ baselineScore: number;
494
+ currentScore: number;
495
+ delta: number;
496
+ }>;
497
+ }
498
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,kCAAkC;AAClC,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,2CAA2C;AAC3C,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,YAAY,GACZ,WAAW,GACX,aAAa,GACb,UAAU,GACV,gBAAgB,CAAC;AAErB,oDAAoD;AACpD,MAAM,WAAW,QAAQ;IACvB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,UAAU,EAA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WAAW,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC3E;AAED,gEAAgE;AAChE,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,YAAY,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,eAAe,EAAE,OAAO,CAAC;IACzB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,WAAW,EAAE,KAAK,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH,wDAAwD;IACxD,YAAY,EAAE,KAAK,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * AI Reliability Control Plane — Shared Domain Types
4
+ *
5
+ * These types define the core domain model for V1:
6
+ * Trace, Claims, Grounding Verdicts, Reports, and Tolerances.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DEFAULT_TOLERANCES = void 0;
10
+ /** Default tolerance configuration. */
11
+ exports.DEFAULT_TOLERANCES = {
12
+ numericRelativeTolerance: 0.05,
13
+ countExactMatch: true,
14
+ dateExactMatch: true,
15
+ nameSimilarityThreshold: 0.92,
16
+ };
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAgTH,uCAAuC;AAC1B,QAAA,kBAAkB,GAAoB;IACjD,wBAAwB,EAAE,IAAI;IAC9B,eAAe,EAAE,IAAI;IACrB,cAAc,EAAE,IAAI;IACpB,uBAAuB,EAAE,IAAI;CAC9B,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Alert Dispatchers — notify when grounding scores drop.
3
+ *
4
+ * Used by warn and block modes to send notifications
5
+ * through various channels (webhook, console, custom).
6
+ */
7
+ import type { GroundingReport, Trace } from '../types';
8
+ /** Abstract alert dispatcher. */
9
+ export interface AlertDispatcher {
10
+ /** Dispatch an alert for a low-scoring evaluation. */
11
+ dispatch(report: GroundingReport, trace: Trace): Promise<void>;
12
+ }
13
+ /** Logs alerts to stderr with color. */
14
+ export declare class ConsoleAlertDispatcher implements AlertDispatcher {
15
+ dispatch(report: GroundingReport, _trace: Trace): Promise<void>;
16
+ }
17
+ export interface WebhookConfig {
18
+ /** The URL to POST the alert payload to. */
19
+ url: string;
20
+ /** Optional headers (e.g., Authorization). */
21
+ headers?: Record<string, string>;
22
+ }
23
+ /** Posts alert payloads to a webhook URL (Slack, Discord, PagerDuty, custom). */
24
+ export declare class WebhookAlertDispatcher implements AlertDispatcher {
25
+ private readonly config;
26
+ constructor(config: WebhookConfig);
27
+ dispatch(report: GroundingReport, trace: Trace): Promise<void>;
28
+ }
29
+ /** Calls a user-provided function. */
30
+ export declare class CallbackAlertDispatcher implements AlertDispatcher {
31
+ private readonly fn;
32
+ constructor(fn: (report: GroundingReport, trace: Trace) => Promise<void> | void);
33
+ dispatch(report: GroundingReport, trace: Trace): Promise<void>;
34
+ }
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Alerting/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAMvD,iCAAiC;AACjC,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChE;AAMD,wCAAwC;AACxC,qBAAa,sBAAuB,YAAW,eAAe;IACtD,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAWtE;AAMD,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,iFAAiF;AACjF,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,MAAM,EAAE,aAAa;IAI3B,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAkCrE;AAMD,sCAAsC;AACtC,qBAAa,uBAAwB,YAAW,eAAe;IAC7D,OAAO,CAAC,QAAQ,CAAC,EAAE,CAGO;gBAGxB,EAAE,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAK/D,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrE"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /**
3
+ * Alert Dispatchers — notify when grounding scores drop.
4
+ *
5
+ * Used by warn and block modes to send notifications
6
+ * through various channels (webhook, console, custom).
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CallbackAlertDispatcher = exports.WebhookAlertDispatcher = exports.ConsoleAlertDispatcher = void 0;
10
+ // ---------------------------------------------------------------------------
11
+ // ConsoleAlertDispatcher
12
+ // ---------------------------------------------------------------------------
13
+ /** Logs alerts to stderr with color. */
14
+ class ConsoleAlertDispatcher {
15
+ async dispatch(report, _trace) {
16
+ const score = (report.groundingScore * 100).toFixed(0);
17
+ const failures = report.detectedFailures
18
+ .map((f) => f.type)
19
+ .join(', ');
20
+ console.error(`[TruthGuard WARN] Trace ${report.traceId} scored ${score}% | ` +
21
+ `${report.claimsFailed} ungrounded claims | ` +
22
+ `Failures: ${failures || 'none'}`);
23
+ }
24
+ }
25
+ exports.ConsoleAlertDispatcher = ConsoleAlertDispatcher;
26
+ /** Posts alert payloads to a webhook URL (Slack, Discord, PagerDuty, custom). */
27
+ class WebhookAlertDispatcher {
28
+ constructor(config) {
29
+ this.config = config;
30
+ }
31
+ async dispatch(report, trace) {
32
+ const payload = {
33
+ event: 'truthguard.grounding.alert',
34
+ timestamp: new Date().toISOString(),
35
+ traceId: report.traceId,
36
+ groundingScore: report.groundingScore,
37
+ claimsTotal: report.claimsTotal,
38
+ claimsFailed: report.claimsFailed,
39
+ detectedFailures: report.detectedFailures.map((f) => ({
40
+ type: f.type,
41
+ confidence: f.confidence,
42
+ description: f.description,
43
+ })),
44
+ trace: {
45
+ traceId: trace.traceId,
46
+ stepsCount: trace.steps.length,
47
+ },
48
+ };
49
+ const res = await fetch(this.config.url, {
50
+ method: 'POST',
51
+ headers: {
52
+ 'Content-Type': 'application/json',
53
+ ...this.config.headers,
54
+ },
55
+ body: JSON.stringify(payload),
56
+ });
57
+ if (!res.ok) {
58
+ console.error(`[TruthGuard] Webhook alert failed: ${res.status} ${res.statusText}`);
59
+ }
60
+ }
61
+ }
62
+ exports.WebhookAlertDispatcher = WebhookAlertDispatcher;
63
+ // ---------------------------------------------------------------------------
64
+ // CallbackAlertDispatcher — for custom integrations
65
+ // ---------------------------------------------------------------------------
66
+ /** Calls a user-provided function. */
67
+ class CallbackAlertDispatcher {
68
+ constructor(fn) {
69
+ this.fn = fn;
70
+ }
71
+ async dispatch(report, trace) {
72
+ await this.fn(report, trace);
73
+ }
74
+ }
75
+ exports.CallbackAlertDispatcher = CallbackAlertDispatcher;
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Alerting/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAcH,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA8E;AAE9E,wCAAwC;AACxC,MAAa,sBAAsB;IACjC,KAAK,CAAC,QAAQ,CAAC,MAAuB,EAAE,MAAa;QACnD,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,cAAc,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACvD,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB;aACrC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aAClB,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,CAAC,KAAK,CACX,2BAA2B,MAAM,CAAC,OAAO,WAAW,KAAK,MAAM;YAC7D,GAAG,MAAM,CAAC,YAAY,uBAAuB;YAC7C,aAAa,QAAQ,IAAI,MAAM,EAAE,CACpC,CAAC;IACJ,CAAC;CACF;AAZD,wDAYC;AAaD,iFAAiF;AACjF,MAAa,sBAAsB;IAGjC,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAuB,EAAE,KAAY;QAClD,MAAM,OAAO,GAAG;YACd,KAAK,EAAE,4BAA4B;YACnC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,WAAW,EAAE,MAAM,CAAC,WAAW;Y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