@beingmartinbmc/ojas 0.2.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/LICENSE +21 -0
- package/README.md +308 -0
- package/dist/aahar/index.d.ts +179 -0
- package/dist/aahar/index.d.ts.map +1 -0
- package/dist/aahar/index.js +657 -0
- package/dist/aahar/index.js.map +1 -0
- package/dist/aahar/scoring.d.ts +85 -0
- package/dist/aahar/scoring.d.ts.map +1 -0
- package/dist/aahar/scoring.js +268 -0
- package/dist/aahar/scoring.js.map +1 -0
- package/dist/agni/index.d.ts +113 -0
- package/dist/agni/index.d.ts.map +1 -0
- package/dist/agni/index.js +328 -0
- package/dist/agni/index.js.map +1 -0
- package/dist/agni/model-router.d.ts +77 -0
- package/dist/agni/model-router.d.ts.map +1 -0
- package/dist/agni/model-router.js +163 -0
- package/dist/agni/model-router.js.map +1 -0
- package/dist/agni/response-distiller.d.ts +37 -0
- package/dist/agni/response-distiller.d.ts.map +1 -0
- package/dist/agni/response-distiller.js +193 -0
- package/dist/agni/response-distiller.js.map +1 -0
- package/dist/agni/tiktoken-adapter.d.ts +55 -0
- package/dist/agni/tiktoken-adapter.d.ts.map +1 -0
- package/dist/agni/tiktoken-adapter.js +113 -0
- package/dist/agni/tiktoken-adapter.js.map +1 -0
- package/dist/chikitsa/index.d.ts +130 -0
- package/dist/chikitsa/index.d.ts.map +1 -0
- package/dist/chikitsa/index.js +565 -0
- package/dist/chikitsa/index.js.map +1 -0
- package/dist/demo.d.ts +15 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/demo.js +278 -0
- package/dist/demo.js.map +1 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +588 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/audit.d.ts +39 -0
- package/dist/mcp/audit.d.ts.map +1 -0
- package/dist/mcp/audit.js +73 -0
- package/dist/mcp/audit.js.map +1 -0
- package/dist/mcp/contracts.d.ts +76 -0
- package/dist/mcp/contracts.d.ts.map +1 -0
- package/dist/mcp/contracts.js +44 -0
- package/dist/mcp/contracts.js.map +1 -0
- package/dist/mcp/envelope.d.ts +107 -0
- package/dist/mcp/envelope.d.ts.map +1 -0
- package/dist/mcp/envelope.js +162 -0
- package/dist/mcp/envelope.js.map +1 -0
- package/dist/mcp/registry.d.ts +110 -0
- package/dist/mcp/registry.d.ts.map +1 -0
- package/dist/mcp/registry.js +258 -0
- package/dist/mcp/registry.js.map +1 -0
- package/dist/mcp/server.d.ts +26 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +107 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/agent.d.ts +4 -0
- package/dist/mcp/tools/agent.d.ts.map +1 -0
- package/dist/mcp/tools/agent.js +300 -0
- package/dist/mcp/tools/agent.js.map +1 -0
- package/dist/mcp/tools/context.d.ts +4 -0
- package/dist/mcp/tools/context.d.ts.map +1 -0
- package/dist/mcp/tools/context.js +261 -0
- package/dist/mcp/tools/context.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +5 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +20 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/memory.d.ts +4 -0
- package/dist/mcp/tools/memory.d.ts.map +1 -0
- package/dist/mcp/tools/memory.js +220 -0
- package/dist/mcp/tools/memory.js.map +1 -0
- package/dist/mcp/tools/output.d.ts +4 -0
- package/dist/mcp/tools/output.d.ts.map +1 -0
- package/dist/mcp/tools/output.js +206 -0
- package/dist/mcp/tools/output.js.map +1 -0
- package/dist/mcp/tools/recovery.d.ts +4 -0
- package/dist/mcp/tools/recovery.d.ts.map +1 -0
- package/dist/mcp/tools/recovery.js +165 -0
- package/dist/mcp/tools/recovery.js.map +1 -0
- package/dist/mcp/tools/registrar.d.ts +4 -0
- package/dist/mcp/tools/registrar.d.ts.map +1 -0
- package/dist/mcp/tools/registrar.js +17 -0
- package/dist/mcp/tools/registrar.js.map +1 -0
- package/dist/mcp/tools/report.d.ts +4 -0
- package/dist/mcp/tools/report.d.ts.map +1 -0
- package/dist/mcp/tools/report.js +68 -0
- package/dist/mcp/tools/report.js.map +1 -0
- package/dist/mcp/tools/shared.d.ts +37 -0
- package/dist/mcp/tools/shared.d.ts.map +1 -0
- package/dist/mcp/tools/shared.js +214 -0
- package/dist/mcp/tools/shared.js.map +1 -0
- package/dist/mcp/trace.d.ts +47 -0
- package/dist/mcp/trace.d.ts.map +1 -0
- package/dist/mcp/trace.js +216 -0
- package/dist/mcp/trace.js.map +1 -0
- package/dist/nidra/index.d.ts +275 -0
- package/dist/nidra/index.d.ts.map +1 -0
- package/dist/nidra/index.js +889 -0
- package/dist/nidra/index.js.map +1 -0
- package/dist/persistence/migrations.d.ts +10 -0
- package/dist/persistence/migrations.d.ts.map +1 -0
- package/dist/persistence/migrations.js +77 -0
- package/dist/persistence/migrations.js.map +1 -0
- package/dist/persistence/sqlite.d.ts +30 -0
- package/dist/persistence/sqlite.d.ts.map +1 -0
- package/dist/persistence/sqlite.js +209 -0
- package/dist/persistence/sqlite.js.map +1 -0
- package/dist/persistence/types.d.ts +104 -0
- package/dist/persistence/types.d.ts.map +1 -0
- package/dist/persistence/types.js +5 -0
- package/dist/persistence/types.js.map +1 -0
- package/dist/pulse/index.d.ts +144 -0
- package/dist/pulse/index.d.ts.map +1 -0
- package/dist/pulse/index.js +453 -0
- package/dist/pulse/index.js.map +1 -0
- package/dist/raksha/classifiers/http-classifier.d.ts +26 -0
- package/dist/raksha/classifiers/http-classifier.d.ts.map +1 -0
- package/dist/raksha/classifiers/http-classifier.js +62 -0
- package/dist/raksha/classifiers/http-classifier.js.map +1 -0
- package/dist/raksha/classifiers/index.d.ts +5 -0
- package/dist/raksha/classifiers/index.d.ts.map +1 -0
- package/dist/raksha/classifiers/index.js +8 -0
- package/dist/raksha/classifiers/index.js.map +1 -0
- package/dist/raksha/classifiers/onnx-classifier.d.ts +41 -0
- package/dist/raksha/classifiers/onnx-classifier.d.ts.map +1 -0
- package/dist/raksha/classifiers/onnx-classifier.js +99 -0
- package/dist/raksha/classifiers/onnx-classifier.js.map +1 -0
- package/dist/raksha/hallucination-detectors.d.ts +106 -0
- package/dist/raksha/hallucination-detectors.d.ts.map +1 -0
- package/dist/raksha/hallucination-detectors.js +327 -0
- package/dist/raksha/hallucination-detectors.js.map +1 -0
- package/dist/raksha/index.d.ts +168 -0
- package/dist/raksha/index.d.ts.map +1 -0
- package/dist/raksha/index.js +597 -0
- package/dist/raksha/index.js.map +1 -0
- package/dist/raksha/prompt-injection-detectors.d.ts +30 -0
- package/dist/raksha/prompt-injection-detectors.d.ts.map +1 -0
- package/dist/raksha/prompt-injection-detectors.js +153 -0
- package/dist/raksha/prompt-injection-detectors.js.map +1 -0
- package/dist/types.d.ts +1115 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +71 -0
- package/dist/types.js.map +1 -0
- package/dist/util/calibration.d.ts +32 -0
- package/dist/util/calibration.d.ts.map +1 -0
- package/dist/util/calibration.js +108 -0
- package/dist/util/calibration.js.map +1 -0
- package/dist/util/id.d.ts +2 -0
- package/dist/util/id.d.ts.map +1 -0
- package/dist/util/id.js +9 -0
- package/dist/util/id.js.map +1 -0
- package/dist/vyayam/index.d.ts +76 -0
- package/dist/vyayam/index.d.ts.map +1 -0
- package/dist/vyayam/index.js +528 -0
- package/dist/vyayam/index.js.map +1 -0
- package/dist/vyayam/tool-fault-proxy.d.ts +95 -0
- package/dist/vyayam/tool-fault-proxy.d.ts.map +1 -0
- package/dist/vyayam/tool-fault-proxy.js +170 -0
- package/dist/vyayam/tool-fault-proxy.js.map +1 -0
- package/docs/ARCHITECTURE.md +162 -0
- package/docs/BACKLOG.md +342 -0
- package/docs/CONFIGURATION.md +305 -0
- package/docs/EVIDENCE.md +232 -0
- package/docs/EVIDENCE_MATRIX.md +293 -0
- package/docs/KNOWN_FAILURES.md +367 -0
- package/docs/MCP.md +614 -0
- package/docs/MODULES.md +368 -0
- package/docs/SECURITY.md +251 -0
- package/docs/TRUST.md +88 -0
- package/docs/assets/ojas-hero.png +0 -0
- package/package.json +101 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,1115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ojas — AI Health Infrastructure for Autonomous Agents
|
|
3
|
+
*
|
|
4
|
+
* Core type definitions shared across all modules:
|
|
5
|
+
* - Aahar (Cognitive Nutrition)
|
|
6
|
+
* - Nidra (Recovery & Consolidation)
|
|
7
|
+
* - Vyayam (Resilience & Stress Engineering)
|
|
8
|
+
*/
|
|
9
|
+
export type HealthScoreBasis = 'heuristic' | 'synthetic_calibrated' | 'empirical_calibrated';
|
|
10
|
+
export interface HealthScore {
|
|
11
|
+
/** 0.0 (critical) to 1.0 (optimal) */
|
|
12
|
+
value: number;
|
|
13
|
+
/** ISO timestamp of measurement */
|
|
14
|
+
timestamp: string;
|
|
15
|
+
/** What produced this score */
|
|
16
|
+
source: string;
|
|
17
|
+
/**
|
|
18
|
+
* Evidence basis for interpreting the score. Heuristic scores are advisory
|
|
19
|
+
* diagnostics; calibrated scores still need their sample provenance before
|
|
20
|
+
* anyone treats them as probabilities.
|
|
21
|
+
*/
|
|
22
|
+
basis?: HealthScoreBasis;
|
|
23
|
+
/** Number of calibration samples behind the score, when known. */
|
|
24
|
+
calibrationSampleSize?: number;
|
|
25
|
+
/** Short operator-facing interpretation of what the score can and cannot mean. */
|
|
26
|
+
interpretation?: string;
|
|
27
|
+
}
|
|
28
|
+
export type OjasModuleName = 'aahar' | 'nidra' | 'vyayam' | 'raksha' | 'agni' | 'pulse' | 'chikitsa';
|
|
29
|
+
export interface AgentHealthReport {
|
|
30
|
+
agentId: string;
|
|
31
|
+
timestamp: string;
|
|
32
|
+
overall: HealthScore;
|
|
33
|
+
/** Per-module breakdown of health scores on a 0–100 scale. */
|
|
34
|
+
moduleScores: ModuleScoreBreakdown;
|
|
35
|
+
nutrition: NutritionHealth;
|
|
36
|
+
recovery: RecoveryHealth;
|
|
37
|
+
resilience: ResilienceHealth;
|
|
38
|
+
defense: DefenseHealth;
|
|
39
|
+
metabolism: MetabolismHealth;
|
|
40
|
+
telemetry: TelemetryHealth;
|
|
41
|
+
rehabilitation: RehabilitationHealth;
|
|
42
|
+
recommendations: readonly HealthRecommendation[];
|
|
43
|
+
events: readonly HealthEvent[];
|
|
44
|
+
/**
|
|
45
|
+
* Repair protocols that Chikitsa would emit for the failures detected
|
|
46
|
+
* during this health check. These are previews — not stored — so the
|
|
47
|
+
* report stays idempotent. Call `ojas.chikitsa.diagnose(failures)`
|
|
48
|
+
* explicitly to persist them.
|
|
49
|
+
*/
|
|
50
|
+
previewRepairProtocols: readonly RepairProtocol[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Per-module 0–100 health scores in the canonical "Agent Health Score" format.
|
|
54
|
+
* Matches the Ojas spec example: Aahar 87, Nidra 78, Vyayam 74, etc.
|
|
55
|
+
*/
|
|
56
|
+
export interface ModuleScoreBreakdown {
|
|
57
|
+
aahar: number;
|
|
58
|
+
nidra: number;
|
|
59
|
+
vyayam: number;
|
|
60
|
+
raksha: number;
|
|
61
|
+
agni: number;
|
|
62
|
+
pulse: number;
|
|
63
|
+
chikitsa: number;
|
|
64
|
+
}
|
|
65
|
+
export interface HealthRecommendation {
|
|
66
|
+
module: OjasModuleName;
|
|
67
|
+
severity: 'info' | 'warning' | 'critical';
|
|
68
|
+
message: string;
|
|
69
|
+
action?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface HealthEvent<TDetails extends Record<string, unknown> = Record<string, unknown>> {
|
|
72
|
+
id: string;
|
|
73
|
+
eventType: string;
|
|
74
|
+
agentId: string;
|
|
75
|
+
timestamp: string;
|
|
76
|
+
severity: 'info' | 'warning' | 'critical';
|
|
77
|
+
detectedBy: OjasModuleName;
|
|
78
|
+
details: TDetails;
|
|
79
|
+
recommendedAction?: string;
|
|
80
|
+
}
|
|
81
|
+
export interface ContextItem {
|
|
82
|
+
id: string;
|
|
83
|
+
content: string;
|
|
84
|
+
source: string;
|
|
85
|
+
/**
|
|
86
|
+
* Optional on-demand content resolver. When provided, `content`
|
|
87
|
+
* acts as a placeholder used for sizing / scoring and the real
|
|
88
|
+
* payload is fetched only after `Aahar.filter()` decides to accept
|
|
89
|
+
* the item — surface it via `aahar.materialise(filtered)` to await
|
|
90
|
+
* resolution lazily. Useful when content is expensive to compute
|
|
91
|
+
* (DB queries, remote fetches) and you'd rather not pay the cost
|
|
92
|
+
* for items the budget might drop. The resolver MUST return a
|
|
93
|
+
* string; throwing rejects the item from the materialised output.
|
|
94
|
+
*/
|
|
95
|
+
resolveContent?: () => string | Promise<string>;
|
|
96
|
+
relevanceScore: number;
|
|
97
|
+
freshness: number;
|
|
98
|
+
tokenCount: number;
|
|
99
|
+
metadata?: Record<string, unknown>;
|
|
100
|
+
trustScore?: number;
|
|
101
|
+
sensitivity?: 'public' | 'internal' | 'confidential' | 'secret';
|
|
102
|
+
/**
|
|
103
|
+
* Loading tier hint for Aahar's progressive-loading filter.
|
|
104
|
+
* Three-tier split:
|
|
105
|
+
* - `'always'` — Tier 1: never dropped by tier filtering;
|
|
106
|
+
* - `'on-demand'` — Tier 2: dropped only when budget is tight;
|
|
107
|
+
* - `'rare'` — Tier 3: dropped first when budget is tight.
|
|
108
|
+
* Optional. When absent, Aahar treats the item as `'on-demand'`,
|
|
109
|
+
* which preserves the legacy single-pool behaviour.
|
|
110
|
+
*/
|
|
111
|
+
tier?: 'always' | 'on-demand' | 'rare';
|
|
112
|
+
}
|
|
113
|
+
export interface NutritionHealth {
|
|
114
|
+
contextQuality: HealthScore;
|
|
115
|
+
cognitiveLoad: HealthScore;
|
|
116
|
+
attentionFocus: HealthScore;
|
|
117
|
+
signalToNoise: number;
|
|
118
|
+
tokenEfficiency: number;
|
|
119
|
+
}
|
|
120
|
+
export interface NutritionPolicy {
|
|
121
|
+
/** Max tokens allowed in active context */
|
|
122
|
+
maxContextTokens: number;
|
|
123
|
+
/** Minimum relevance score to include (0-1) */
|
|
124
|
+
relevanceThreshold: number;
|
|
125
|
+
/** Max age in seconds before context is considered stale */
|
|
126
|
+
freshnessWindowSec: number;
|
|
127
|
+
/** Maximum number of context items */
|
|
128
|
+
maxContextItems: number;
|
|
129
|
+
/** Target signal-to-noise ratio */
|
|
130
|
+
targetSignalToNoise: number;
|
|
131
|
+
/** Hard cap on retained Aahar filter history. */
|
|
132
|
+
maxHistory?: number;
|
|
133
|
+
/**
|
|
134
|
+
* Temporal intent for ranking and the freshness gate.
|
|
135
|
+
* - `'recent'` (default when undefined): existing behaviour — exponential
|
|
136
|
+
* decay favours new items, and items older than `freshnessWindowSec`
|
|
137
|
+
* are rejected outright.
|
|
138
|
+
* - `'historical'`: invert the decay so older items rank competitively
|
|
139
|
+
* against new ones, AND disable the freshness rejection gate (callers
|
|
140
|
+
* are deliberately asking about old material).
|
|
141
|
+
* - `'any'`: neutralise freshness (constant 0.5) and disable the gate.
|
|
142
|
+
* The validity check on `freshness` itself (finite Unix-seconds) always
|
|
143
|
+
* applies regardless of intent — this knob only changes ranking weight
|
|
144
|
+
* and the staleness reject.
|
|
145
|
+
*/
|
|
146
|
+
temporalIntent?: 'recent' | 'historical' | 'any';
|
|
147
|
+
/**
|
|
148
|
+
* When true, near-duplicate items (Jaccard similarity over 5-shingle
|
|
149
|
+
* token sets ≥ `deduplicationThreshold`) are collapsed before token-budget
|
|
150
|
+
* packing — the highest-scored representative survives, the rest go to
|
|
151
|
+
* `rejected`. Default `false` for backwards compatibility; existing
|
|
152
|
+
* callers see no behavioural change.
|
|
153
|
+
*/
|
|
154
|
+
deduplicateNearDuplicates?: boolean;
|
|
155
|
+
/** Jaccard similarity threshold for `deduplicateNearDuplicates`. Default 0.85. */
|
|
156
|
+
deduplicationThreshold?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Maximal Marginal Relevance lambda for context packing. When `> 0`,
|
|
159
|
+
* Aahar selects items inside the token budget by balancing score against
|
|
160
|
+
* dissimilarity to already-picked items: `(1-λ)*score - λ*maxSim`. λ=0
|
|
161
|
+
* (default) keeps the existing greedy top-K behaviour. λ=1 picks purely
|
|
162
|
+
* for diversity. A typical value is 0.3–0.5 for coverage-aware retrieval.
|
|
163
|
+
*/
|
|
164
|
+
diversityWeight?: number;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Optional per-call inputs for `Aahar.filter` and `Aahar.prioritize`.
|
|
168
|
+
* When omitted, the call is byte-for-byte equivalent to the previous
|
|
169
|
+
* single-argument signature.
|
|
170
|
+
*/
|
|
171
|
+
export interface AaharFilterOptions {
|
|
172
|
+
/**
|
|
173
|
+
* The active task / user query the agent is trying to satisfy. When
|
|
174
|
+
* provided, Aahar augments the caller-supplied `relevanceScore` with
|
|
175
|
+
* on-the-fly BM25 + entity-overlap signals computed against this string
|
|
176
|
+
* and fuses them via Reciprocal Rank Fusion. The fused signal replaces
|
|
177
|
+
* the bare relevance term in the ranking score but does NOT bypass the
|
|
178
|
+
* `relevanceThreshold` gate — the caller's authoritative relevance still
|
|
179
|
+
* decides admission.
|
|
180
|
+
*/
|
|
181
|
+
query?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Whether to stamp a synthetic `[ojas:omitted N items: <reasons>]`
|
|
184
|
+
* marker into the returned `accepted` set so the agent has visible
|
|
185
|
+
* evidence of what was filtered. Default `false` — set `true` for
|
|
186
|
+
* diagnostics or when you want the agent to know it's looking at a
|
|
187
|
+
* curated subset (a single synthetic `[ojas:omitted N items: …]`
|
|
188
|
+
* entry appended to the tail of `accepted`).
|
|
189
|
+
*
|
|
190
|
+
* The marker is a synthetic `ContextItem` with
|
|
191
|
+
* `source: 'aahar/omission'` appended after the genuine accepted
|
|
192
|
+
* items. It is excluded from the `qualityScore` calculation.
|
|
193
|
+
*/
|
|
194
|
+
emitOmissionMarker?: boolean;
|
|
195
|
+
}
|
|
196
|
+
/** Tier marking. Per-item via `ContextItem.tier`. */
|
|
197
|
+
export type AaharContextTier = 'always' | 'on-demand' | 'rare';
|
|
198
|
+
export interface FilteredContext {
|
|
199
|
+
accepted: ContextItem[];
|
|
200
|
+
rejected: ContextItem[];
|
|
201
|
+
totalTokens: number;
|
|
202
|
+
qualityScore: number;
|
|
203
|
+
/**
|
|
204
|
+
* Per-tier diagnostic counts so callers can see how the tier filter
|
|
205
|
+
* affected the input. Only populated when at least one item carried a
|
|
206
|
+
* `tier` hint via `AaharFilterOptions.tier`.
|
|
207
|
+
*/
|
|
208
|
+
tierBreakdown?: Record<AaharContextTier, {
|
|
209
|
+
accepted: number;
|
|
210
|
+
rejected: number;
|
|
211
|
+
}>;
|
|
212
|
+
}
|
|
213
|
+
export type RuntimeFailureType = 'tool_error' | 'timeout' | 'hallucination' | 'policy_violation' | 'retrieval_noise' | 'loop' | 'prompt_injection' | 'unknown';
|
|
214
|
+
export interface RuntimeFailure {
|
|
215
|
+
type: RuntimeFailureType;
|
|
216
|
+
message: string;
|
|
217
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
218
|
+
metadata?: Record<string, unknown>;
|
|
219
|
+
}
|
|
220
|
+
export interface ExecutionTrace {
|
|
221
|
+
id: string;
|
|
222
|
+
agentId: string;
|
|
223
|
+
timestamp: string;
|
|
224
|
+
action: string;
|
|
225
|
+
input: unknown;
|
|
226
|
+
output: unknown;
|
|
227
|
+
success: boolean;
|
|
228
|
+
/** Authoritative wall-clock duration measured by the host (Ojas), not the agent. */
|
|
229
|
+
durationMs: number;
|
|
230
|
+
reasoning?: string;
|
|
231
|
+
error?: string;
|
|
232
|
+
failures?: RuntimeFailure[];
|
|
233
|
+
/** Total tokens consumed by this step (sum of input + output + reasoning). */
|
|
234
|
+
tokensUsed?: number;
|
|
235
|
+
/** Tokens consumed by the input/prompt portion if the agent reports it separately. */
|
|
236
|
+
inputTokens?: number;
|
|
237
|
+
/** Tokens consumed by the output portion if the agent reports it separately. */
|
|
238
|
+
outputTokens?: number;
|
|
239
|
+
/** Number of tool calls invoked during this step. */
|
|
240
|
+
toolCalls?: number;
|
|
241
|
+
/** Reported cost in USD when available (e.g. from a model gateway). */
|
|
242
|
+
costUsd?: number;
|
|
243
|
+
}
|
|
244
|
+
export type MemoryHealthStatus = 'active' | 'candidate' | 'quarantined' | 'expired' | 'rejected';
|
|
245
|
+
/**
|
|
246
|
+
* Memory kind taxonomy — a three-category split:
|
|
247
|
+
* - `'procedural'` — a learned rule or operating instruction
|
|
248
|
+
* (e.g. *"Action X is reliable, prefer for similar tasks"*). This is
|
|
249
|
+
* the default kind for cluster-derived memories produced by
|
|
250
|
+
* `Nidra.runRecoveryCycle()` because the heuristic encodes an
|
|
251
|
+
* action-level rule.
|
|
252
|
+
* - `'episodic'` — a specific past experience preserved as a learning
|
|
253
|
+
* example, with situation / reasoning / outcome. Reserved for a
|
|
254
|
+
* future hot-path `recordInsight()` API.
|
|
255
|
+
* - `'semantic'` — a fact about the world / user / domain. Reserved for
|
|
256
|
+
* opt-in LLM-extracted memories; no built-in producer today.
|
|
257
|
+
*/
|
|
258
|
+
export type ConsolidatedMemoryKind = 'procedural' | 'episodic' | 'semantic';
|
|
259
|
+
export interface ConsolidatedMemory {
|
|
260
|
+
id: string;
|
|
261
|
+
/**
|
|
262
|
+
* Memory kind. Defaults to `'procedural'` for cluster-derived memories.
|
|
263
|
+
* See `ConsolidatedMemoryKind` for the taxonomy and rationale.
|
|
264
|
+
*/
|
|
265
|
+
kind?: ConsolidatedMemoryKind;
|
|
266
|
+
/**
|
|
267
|
+
* Ingestion time: when consolidation produced this memory.
|
|
268
|
+
* Paired with `observedAt` (event time) to form a bi-temporal
|
|
269
|
+
* record (ingestion time + event time).
|
|
270
|
+
*/
|
|
271
|
+
createdAt: string;
|
|
272
|
+
/**
|
|
273
|
+
* Event time: the timestamp of the earliest source trace this memory
|
|
274
|
+
* was distilled from. `undefined` when the memory has no traceable
|
|
275
|
+
* source (e.g. injected by tests). Drift analysis and time-travel
|
|
276
|
+
* queries care about this clock; audit / replay cares about
|
|
277
|
+
* `createdAt`.
|
|
278
|
+
*/
|
|
279
|
+
observedAt?: string;
|
|
280
|
+
/**
|
|
281
|
+
* When this memory stopped being authoritative, in ISO-8601 UTC.
|
|
282
|
+
* `undefined` means it is still active. Set by `Nidra.commitAnalysis()`
|
|
283
|
+
* when a later memory with the same kind + overlapping applicability
|
|
284
|
+
* and a materially different confidence supersedes this one.
|
|
285
|
+
* Memories are *invalidated, not deleted* so the audit trail and
|
|
286
|
+
* historical queries survive. Use `Nidra.getActiveMemories()` or
|
|
287
|
+
* `Nidra.findMemories({ asOf })` to filter.
|
|
288
|
+
*/
|
|
289
|
+
invalidatedAt?: string;
|
|
290
|
+
/**
|
|
291
|
+
* ID of the `ConsolidatedMemory` that replaced this one. Only set
|
|
292
|
+
* when `invalidatedAt` is also set. Lets dashboards / auditors
|
|
293
|
+
* follow the chain of belief revision back to its current head.
|
|
294
|
+
*/
|
|
295
|
+
supersededBy?: string;
|
|
296
|
+
sourceTraces: string[];
|
|
297
|
+
heuristic: string;
|
|
298
|
+
confidence: number;
|
|
299
|
+
applicability: string[];
|
|
300
|
+
abstraction: string;
|
|
301
|
+
riskScore?: number;
|
|
302
|
+
verified?: boolean;
|
|
303
|
+
expiresAt?: string;
|
|
304
|
+
healthStatus?: MemoryHealthStatus;
|
|
305
|
+
source?: string;
|
|
306
|
+
lastUsedAt?: string;
|
|
307
|
+
freshness?: number;
|
|
308
|
+
usefulness?: number;
|
|
309
|
+
redundancyScore?: number;
|
|
310
|
+
expiryPolicy?: string;
|
|
311
|
+
allowedContexts?: string[];
|
|
312
|
+
/**
|
|
313
|
+
* Provenance quality. `'full'` means every entry in `sourceTraces` is
|
|
314
|
+
* still retained and inspectable via `Nidra.getTraces()`. `'degraded'`
|
|
315
|
+
* means one or more source traces were evicted by retention between
|
|
316
|
+
* analyse and commit — the memory itself is committed because the
|
|
317
|
+
* analysis already encoded what those traces meant, but operators
|
|
318
|
+
* cannot drill back into the raw evidence. `sourceTracesEvicted`
|
|
319
|
+
* lists exactly which IDs are no longer retrievable.
|
|
320
|
+
*/
|
|
321
|
+
provenance?: 'full' | 'degraded';
|
|
322
|
+
/** Subset of `sourceTraces` that had been evicted by retention at commit time. */
|
|
323
|
+
sourceTracesEvicted?: string[];
|
|
324
|
+
/**
|
|
325
|
+
* Optional structural type of the memory node. `text` is the
|
|
326
|
+
* default for free-form heuristics; the other values let callers
|
|
327
|
+
* index / scan memory faster by node kind. Additive — existing
|
|
328
|
+
* memories without a `nodeType` continue to work.
|
|
329
|
+
*/
|
|
330
|
+
nodeType?: MemoryNodeType;
|
|
331
|
+
/**
|
|
332
|
+
* Read-temperature in [0, 1]. Rises when the memory is accessed
|
|
333
|
+
* (e.g. via `Nidra.touchMemory(id)`) and decays exponentially over
|
|
334
|
+
* time. Hot memories rank higher in search; cold memories cross a
|
|
335
|
+
* threshold and trigger a `memory_cold` Pulse event so the agent can
|
|
336
|
+
* compact them. Optional — undefined means "untracked, treat as warm".
|
|
337
|
+
*/
|
|
338
|
+
temperature?: number;
|
|
339
|
+
/**
|
|
340
|
+
* UTC ISO timestamp of the most recent temperature update. Used to
|
|
341
|
+
* compute decay since the last read.
|
|
342
|
+
*/
|
|
343
|
+
temperatureUpdatedAt?: string;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Structural node types for `ConsolidatedMemory.nodeType`. We use
|
|
347
|
+
* plain strings rather than an enum so the JSON shape is
|
|
348
|
+
* human-readable and the field is easy to filter on. Add new types
|
|
349
|
+
* here when they're genuinely distinct from the existing ones —
|
|
350
|
+
* duplication forces a schema migration.
|
|
351
|
+
*/
|
|
352
|
+
export type MemoryNodeType = 'heading' | 'list' | 'kv' | 'table' | 'preamble' | 'text' | 'code' | 'embed';
|
|
353
|
+
/**
|
|
354
|
+
* Cursor handed back by `Nidra.getMemoryCursor()` and accepted by
|
|
355
|
+
* `Nidra.getMemoryDelta(cursor)`. Opaque to callers — treat it as a
|
|
356
|
+
* black-box token. The hash collapses the current memory-set
|
|
357
|
+
* fingerprint so the server can detect that nothing has changed
|
|
358
|
+
* since the cursor was issued.
|
|
359
|
+
*/
|
|
360
|
+
export interface MemoryCursor {
|
|
361
|
+
/** Hash over the current memory set (stable identifier of "where we were"). */
|
|
362
|
+
cursorHash: string;
|
|
363
|
+
/** UTC ISO timestamp when the cursor was issued. Informational, not enforced. */
|
|
364
|
+
issuedAt: string;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Delta returned by `Nidra.getMemoryDelta(cursor)`. The agent
|
|
368
|
+
* passes its last cursor, gets back only the memories that have
|
|
369
|
+
* been added or modified since, plus a new cursor for the next
|
|
370
|
+
* round. A whole-tree re-fetch is an explicit decision
|
|
371
|
+
* (`fullResync: true`).
|
|
372
|
+
*/
|
|
373
|
+
export interface MemoryDelta {
|
|
374
|
+
/** Memories newly committed since the supplied cursor. */
|
|
375
|
+
added: ConsolidatedMemory[];
|
|
376
|
+
/** Memories whose content / status changed since the supplied cursor. */
|
|
377
|
+
modified: ConsolidatedMemory[];
|
|
378
|
+
/** IDs of memories that have been pruned since the supplied cursor. */
|
|
379
|
+
removedIds: string[];
|
|
380
|
+
/** The new cursor — pass this to the next `getMemoryDelta` call. */
|
|
381
|
+
nextCursor: MemoryCursor;
|
|
382
|
+
/**
|
|
383
|
+
* `true` when the supplied cursor was so old (or never existed) that
|
|
384
|
+
* we cannot represent the delta accurately. Caller should treat
|
|
385
|
+
* `added` as the full memory set and discard any local cache.
|
|
386
|
+
*/
|
|
387
|
+
fullResync: boolean;
|
|
388
|
+
}
|
|
389
|
+
export interface RecoveryHealth {
|
|
390
|
+
memoryConsolidation: HealthScore;
|
|
391
|
+
cognitiveStability: HealthScore;
|
|
392
|
+
learningRate: HealthScore;
|
|
393
|
+
driftScore: number;
|
|
394
|
+
lastRecoveryCycle: string | null;
|
|
395
|
+
}
|
|
396
|
+
export interface RecoveryPolicy {
|
|
397
|
+
/** Minimum traces before consolidation triggers */
|
|
398
|
+
minTracesForConsolidation: number;
|
|
399
|
+
/** How often to run recovery cycles (seconds) */
|
|
400
|
+
recoveryIntervalSec: number;
|
|
401
|
+
/** Max drift score before forced recovery */
|
|
402
|
+
maxDriftThreshold: number;
|
|
403
|
+
/** Number of recent failures to analyze */
|
|
404
|
+
failureWindowSize: number;
|
|
405
|
+
/** Confidence threshold for memory retention */
|
|
406
|
+
retentionConfidence: number;
|
|
407
|
+
/**
|
|
408
|
+
* Minimum absolute change in `confidence` between a new memory and an
|
|
409
|
+
* existing active one (same kind + overlapping applicability) before
|
|
410
|
+
* the existing memory is treated as superseded and marked
|
|
411
|
+
* `invalidatedAt`. Defaults to `0.15` (15 percentage points). Set to
|
|
412
|
+
* `0` to supersede on ANY new same-pattern memory; set to `1` to
|
|
413
|
+
* disable supersession entirely.
|
|
414
|
+
*/
|
|
415
|
+
supersessionConfidenceDelta?: number;
|
|
416
|
+
/** Hard cap on retained trace count; oldest are evicted when exceeded. */
|
|
417
|
+
maxTraces?: number;
|
|
418
|
+
/** Hard cap on retained consolidated memories. */
|
|
419
|
+
maxMemories?: number;
|
|
420
|
+
/** Hard cap on retained processed-trace IDs (matches maxTraces by default). */
|
|
421
|
+
maxProcessedTraceIds?: number;
|
|
422
|
+
/** Hard cap on recovery cycles retained in history. */
|
|
423
|
+
maxCycleHistory?: number;
|
|
424
|
+
/**
|
|
425
|
+
* Memory-temperature half-life in seconds. After this much time
|
|
426
|
+
* without access, a memory's temperature halves. Default 7 days
|
|
427
|
+
* (`7 * 24 * 60 * 60`). Set very large to effectively disable
|
|
428
|
+
* decay, or very small to make memories cool aggressively.
|
|
429
|
+
*/
|
|
430
|
+
temperatureHalfLifeSec?: number;
|
|
431
|
+
/**
|
|
432
|
+
* Increment applied to a memory's temperature each time it is read
|
|
433
|
+
* via `Nidra.touchMemory(id)`. Default `0.25` (one read warms a
|
|
434
|
+
* memory by 25%, capped at 1.0). Set to 0 to disable touch-based
|
|
435
|
+
* heating entirely.
|
|
436
|
+
*/
|
|
437
|
+
temperatureBoostOnTouch?: number;
|
|
438
|
+
/**
|
|
439
|
+
* Threshold below which a memory is considered "cold". When a memory
|
|
440
|
+
* crosses this threshold on the next `assess()` pass, a
|
|
441
|
+
* `memory_cold` Pulse event is emitted once per crossing so the
|
|
442
|
+
* agent can choose to compact / summarise. Default `0.15`.
|
|
443
|
+
*/
|
|
444
|
+
coldTemperatureThreshold?: number;
|
|
445
|
+
}
|
|
446
|
+
export interface RecoveryCycleResult {
|
|
447
|
+
cycleId: string;
|
|
448
|
+
startedAt: string;
|
|
449
|
+
completedAt: string;
|
|
450
|
+
tracesProcessed: number;
|
|
451
|
+
memoriesConsolidated: ConsolidatedMemory[];
|
|
452
|
+
patternsIdentified: string[];
|
|
453
|
+
driftReduction: number;
|
|
454
|
+
healthBefore: RecoveryHealth;
|
|
455
|
+
healthAfter: RecoveryHealth;
|
|
456
|
+
/**
|
|
457
|
+
* Whether this is a pure preview (no state mutated) or a committed
|
|
458
|
+
* recovery cycle. **Required** — consumers must branch on this rather
|
|
459
|
+
* than treating `healthAfter` as ground truth in both cases.
|
|
460
|
+
*/
|
|
461
|
+
mode: 'preview' | 'committed';
|
|
462
|
+
/**
|
|
463
|
+
* True when `healthAfter` is an estimate (preview) rather than a
|
|
464
|
+
* post-mutation measurement (committed). **Required** so dashboards
|
|
465
|
+
* cannot accidentally graph preview numbers as real recovery deltas.
|
|
466
|
+
*/
|
|
467
|
+
healthAfterEstimated: boolean;
|
|
468
|
+
/**
|
|
469
|
+
* How many of the analysis's covered trace IDs were still in the trace
|
|
470
|
+
* store at commit time. Only meaningful on a `'committed'` result;
|
|
471
|
+
* undefined on previews. Useful for detecting that a long delay
|
|
472
|
+
* between analyse and commit caused some source traces to age out.
|
|
473
|
+
*/
|
|
474
|
+
coveredTracesRetained?: number;
|
|
475
|
+
/**
|
|
476
|
+
* How many covered trace IDs had been evicted by retention between
|
|
477
|
+
* analyse and commit. When non-zero, the consolidated memories may
|
|
478
|
+
* reference traces that no longer appear in `getTraces()`.
|
|
479
|
+
*/
|
|
480
|
+
coveredTracesEvicted?: number;
|
|
481
|
+
/**
|
|
482
|
+
* IDs of pre-existing memories that this cycle invalidated by
|
|
483
|
+
* supersession. Each such memory now has `invalidatedAt` set and
|
|
484
|
+
* `supersededBy` pointing into `memoriesConsolidated`. On `'preview'`
|
|
485
|
+
* results this lists what WOULD be invalidated if the analysis were
|
|
486
|
+
* committed — populated without any mutation. Empty / `undefined`
|
|
487
|
+
* when no candidate prior memory met the confidence-delta threshold.
|
|
488
|
+
*/
|
|
489
|
+
supersededMemoryIds?: string[];
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Output of `Nidra.analyseUnprocessed()`. A precomputed analysis envelope
|
|
493
|
+
* that can be inspected, used to inject memories into an agent, and then
|
|
494
|
+
* passed to `Nidra.commitAnalysis()` — yielding transactional recovery
|
|
495
|
+
* where Ojas's internal state only changes if the side-effecting steps
|
|
496
|
+
* (e.g. `agent.injectMemory()`) all succeeded.
|
|
497
|
+
*/
|
|
498
|
+
export interface RecoveryAnalysis {
|
|
499
|
+
cycleId: string;
|
|
500
|
+
startedAt: string;
|
|
501
|
+
tracesProcessed: number;
|
|
502
|
+
coveredTraceIds: string[];
|
|
503
|
+
memories: ConsolidatedMemory[];
|
|
504
|
+
patterns: string[];
|
|
505
|
+
healthBefore: RecoveryHealth;
|
|
506
|
+
estimatedHealthAfter: RecoveryHealth;
|
|
507
|
+
driftBefore: number;
|
|
508
|
+
}
|
|
509
|
+
export type ThreatType = 'prompt_injection' | 'instruction_override' | 'data_exfiltration' | 'tool_misuse' | 'memory_poisoning' | 'role_confusion' | 'unknown';
|
|
510
|
+
export interface ThreatAssessment {
|
|
511
|
+
itemId: string;
|
|
512
|
+
threatType: ThreatType;
|
|
513
|
+
riskScore: number;
|
|
514
|
+
quarantined: boolean;
|
|
515
|
+
reasons: string[];
|
|
516
|
+
detectedBy?: string;
|
|
517
|
+
}
|
|
518
|
+
export interface PromptInjectionDetectorInput {
|
|
519
|
+
item: ContextItem;
|
|
520
|
+
normalizedContent: string;
|
|
521
|
+
expandedContent?: string;
|
|
522
|
+
scanTarget: string;
|
|
523
|
+
}
|
|
524
|
+
export interface PromptInjectionAssessment {
|
|
525
|
+
threatType: ThreatType;
|
|
526
|
+
riskScore: number;
|
|
527
|
+
reasons: string[];
|
|
528
|
+
detectedBy: string;
|
|
529
|
+
}
|
|
530
|
+
export interface PromptInjectionDetector {
|
|
531
|
+
readonly name: string;
|
|
532
|
+
detect(input: PromptInjectionDetectorInput): PromptInjectionAssessment;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Async, ML-backed prompt injection classifier.
|
|
536
|
+
* Unlike the synchronous `PromptInjectionDetector` (regex/pattern),
|
|
537
|
+
* classifiers may call external services or run ONNX models.
|
|
538
|
+
* Raksha runs classifiers *after* its deterministic stack and merges
|
|
539
|
+
* the highest probability.
|
|
540
|
+
*/
|
|
541
|
+
export interface PromptInjectionClassifier {
|
|
542
|
+
readonly name: string;
|
|
543
|
+
classify(text: string, signal?: AbortSignal): Promise<ClassifierResult>;
|
|
544
|
+
}
|
|
545
|
+
export interface ClassifierResult {
|
|
546
|
+
injectionProbability: number;
|
|
547
|
+
label: 'safe' | 'injection' | 'unknown';
|
|
548
|
+
meta?: Record<string, unknown>;
|
|
549
|
+
}
|
|
550
|
+
export interface DefenseHealth {
|
|
551
|
+
threatResistance: HealthScore;
|
|
552
|
+
instructionIntegrity: HealthScore;
|
|
553
|
+
quarantineEffectiveness: HealthScore;
|
|
554
|
+
threatsDetected: number;
|
|
555
|
+
quarantinedItems: number;
|
|
556
|
+
}
|
|
557
|
+
export interface DefensePolicy {
|
|
558
|
+
quarantineThreshold: number;
|
|
559
|
+
warnThreshold: number;
|
|
560
|
+
protectInstructionHierarchy: boolean;
|
|
561
|
+
/** Hard cap on retained threat assessments. */
|
|
562
|
+
maxAssessments?: number;
|
|
563
|
+
/** Hard cap on retained Raksha events. */
|
|
564
|
+
maxEvents?: number;
|
|
565
|
+
}
|
|
566
|
+
export interface MetabolismHealth {
|
|
567
|
+
tokenEfficiency: HealthScore;
|
|
568
|
+
toolEconomy: HealthScore;
|
|
569
|
+
reasoningEfficiency: HealthScore;
|
|
570
|
+
latencyEfficiency: HealthScore;
|
|
571
|
+
costPressure: number;
|
|
572
|
+
}
|
|
573
|
+
export interface MetabolismPolicy {
|
|
574
|
+
targetTokensPerTask: number;
|
|
575
|
+
maxLatencyMs: number;
|
|
576
|
+
maxToolCallsPerTask: number;
|
|
577
|
+
highRiskReasoningBoost: number;
|
|
578
|
+
/** Hard cap on retained metabolism traces. */
|
|
579
|
+
maxTraces?: number;
|
|
580
|
+
/** Optional target cost per task in USD when cost telemetry is available. */
|
|
581
|
+
targetCostUsdPerTask?: number;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Pluggable hallucination detector. Plugs into Raksha to score the
|
|
585
|
+
* likelihood that an agent's **output** contains hallucination — i.e.
|
|
586
|
+
* claims not grounded in the supplied retrieval context, or claims
|
|
587
|
+
* that disagree across alternative samples of the same prompt.
|
|
588
|
+
*
|
|
589
|
+
* This is a deliberately small, dep-free interface. Built-in
|
|
590
|
+
* implementations include:
|
|
591
|
+
* - `BestOfNInconsistencyDetector` — black-box consistency via
|
|
592
|
+
* n-gram overlap across alternative samples of the same prompt.
|
|
593
|
+
* - `ClaimLevelDetector` — sentence-level grounding check against
|
|
594
|
+
* retrieved context, n-gram based, no ML.
|
|
595
|
+
* - `AbstentionDetector` — recognises "I don't know" / hedging
|
|
596
|
+
* patterns and surfaces them as *positive* (calibrated) signal.
|
|
597
|
+
*
|
|
598
|
+
* Heavier external adapters (encoder-grounding models, LLM judge
|
|
599
|
+
* panels, etc.) can implement this same interface; Ojas core does
|
|
600
|
+
* not depend on any of them.
|
|
601
|
+
*
|
|
602
|
+
* Implementations MUST NOT throw — return a low-confidence assessment
|
|
603
|
+
* with a clear `reason` on internal error. Raksha's wrapper guards
|
|
604
|
+
* against thrown errors but that's a defence-in-depth check.
|
|
605
|
+
*/
|
|
606
|
+
export interface HallucinationDetector {
|
|
607
|
+
/** Stable identifier for telemetry / report stamping (e.g. `bestofn/n-gram`). */
|
|
608
|
+
readonly name: string;
|
|
609
|
+
/** Score the likelihood that `output` contains hallucination. MUST NOT throw. */
|
|
610
|
+
detect(input: HallucinationDetectorInput): Promise<HallucinationAssessment>;
|
|
611
|
+
}
|
|
612
|
+
export interface HallucinationDetectorInput {
|
|
613
|
+
/** The agent's output text under evaluation. */
|
|
614
|
+
output: string;
|
|
615
|
+
/**
|
|
616
|
+
* Alternative responses sampled from the same prompt. Required for
|
|
617
|
+
* consistency-based scoring; ignored by claim-level / abstention
|
|
618
|
+
* detectors. Pass an empty array to indicate "single generation".
|
|
619
|
+
*/
|
|
620
|
+
samples?: string[];
|
|
621
|
+
/**
|
|
622
|
+
* Retrieved context the output was supposed to be grounded in. Used
|
|
623
|
+
* by claim-level detectors to check each sentence-claim against the
|
|
624
|
+
* provided context. Pass an empty array for "no grounding source".
|
|
625
|
+
*/
|
|
626
|
+
context?: string[];
|
|
627
|
+
/** Optional task / prompt for which this output was generated. */
|
|
628
|
+
prompt?: string;
|
|
629
|
+
}
|
|
630
|
+
export interface ClaimAssessment {
|
|
631
|
+
/** The claim text (typically a sentence). */
|
|
632
|
+
claim: string;
|
|
633
|
+
/** Risk in [0, 1]. 0 = well-grounded, 1 = unsupported by context. */
|
|
634
|
+
riskScore: number;
|
|
635
|
+
/** IDs / indices of context entries that grounded this claim, if any. */
|
|
636
|
+
groundedIn?: string[];
|
|
637
|
+
}
|
|
638
|
+
export interface HallucinationAssessment {
|
|
639
|
+
/** Overall risk score in [0, 1]. 0 = grounded / consistent, 1 = likely hallucinated. */
|
|
640
|
+
riskScore: number;
|
|
641
|
+
/**
|
|
642
|
+
* Detector's confidence in this score, in [0, 1]. Low when the
|
|
643
|
+
* detector lacked the inputs it needs (e.g. no samples for a
|
|
644
|
+
* consistency detector). Operators should weight risk by confidence.
|
|
645
|
+
*/
|
|
646
|
+
confidence: number;
|
|
647
|
+
/** Stable detector identifier (matches `HallucinationDetector.name`). */
|
|
648
|
+
detectedBy: string;
|
|
649
|
+
/** Short human-readable reasons that contributed to the score. */
|
|
650
|
+
reasons: string[];
|
|
651
|
+
/** Per-claim breakdown when the detector is claim-level. */
|
|
652
|
+
claims?: ClaimAssessment[];
|
|
653
|
+
/** Whether the output looks like an appropriate abstention (e.g. "I don't know"). */
|
|
654
|
+
abstention?: boolean;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Pluggable model router. Plugs into Agni to recommend cheaper /
|
|
658
|
+
* faster model routes for task classes where observed outcome data
|
|
659
|
+
* supports it. Pattern: observe pass/fail per task class, only route
|
|
660
|
+
* cheap when the lower bound of the 95% confidence interval on
|
|
661
|
+
* success rate exceeds a configured threshold (fail-closed under
|
|
662
|
+
* sparse data).
|
|
663
|
+
*
|
|
664
|
+
* Ojas ships `ConfidenceRoutingTable` as the default; it never calls
|
|
665
|
+
* an LLM itself. Callers wire the recommendation to their own provider
|
|
666
|
+
* gateway.
|
|
667
|
+
*/
|
|
668
|
+
export interface ModelRouter {
|
|
669
|
+
readonly name: string;
|
|
670
|
+
/** Record an observed outcome for a task class. */
|
|
671
|
+
recordOutcome(taskClass: string, succeeded: boolean): void;
|
|
672
|
+
/** Recommend a routing decision for `taskClass`. */
|
|
673
|
+
recommend(taskClass: string): ModelRouterDecision;
|
|
674
|
+
/** Stable snapshot of what the router has learned. */
|
|
675
|
+
report(): ReadonlyArray<ModelRouterTaskReport>;
|
|
676
|
+
}
|
|
677
|
+
export interface ModelRouterDecision {
|
|
678
|
+
/** `'cheap'` to route to the cheaper / faster model; `'flagship'` to keep the default. */
|
|
679
|
+
route: 'cheap' | 'flagship';
|
|
680
|
+
/** Why this decision was made (human-readable, for logging). */
|
|
681
|
+
reason: string;
|
|
682
|
+
/** Number of observations the decision is based on. */
|
|
683
|
+
n: number;
|
|
684
|
+
/** 95% CI on success rate for this task class, [lo, hi]. `null` for n=0. */
|
|
685
|
+
successCI?: {
|
|
686
|
+
lo: number;
|
|
687
|
+
hi: number;
|
|
688
|
+
} | null;
|
|
689
|
+
}
|
|
690
|
+
export interface ModelRouterTaskReport {
|
|
691
|
+
taskClass: string;
|
|
692
|
+
n: number;
|
|
693
|
+
successes: number;
|
|
694
|
+
successRate: number;
|
|
695
|
+
successCI: {
|
|
696
|
+
lo: number;
|
|
697
|
+
hi: number;
|
|
698
|
+
} | null;
|
|
699
|
+
currentRoute: 'cheap' | 'flagship';
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Pluggable response distiller. Plugs into Agni to strip filler from
|
|
703
|
+
* an agent's *output* (preserves code blocks). Default implementation:
|
|
704
|
+
* `defaultResponseDistiller` (rule-based, three intensity levels).
|
|
705
|
+
*
|
|
706
|
+
* Callers can swap in a learned distiller (e.g. a small LM trained on
|
|
707
|
+
* filler corpora) by implementing this interface.
|
|
708
|
+
*/
|
|
709
|
+
export interface ResponseDistiller {
|
|
710
|
+
readonly name: string;
|
|
711
|
+
/** Distill `text` to remove non-load-bearing content. Preserve code blocks. */
|
|
712
|
+
distill(text: string): ResponseDistillResult;
|
|
713
|
+
}
|
|
714
|
+
export interface ResponseDistillResult {
|
|
715
|
+
/** The distilled text. */
|
|
716
|
+
text: string;
|
|
717
|
+
/** Number of tokens removed (estimated). */
|
|
718
|
+
tokensRemoved: number;
|
|
719
|
+
/**
|
|
720
|
+
* Exact number of characters removed across the per-pattern passes.
|
|
721
|
+
* Useful for monitoring distiller aggressiveness without depending on
|
|
722
|
+
* the char/4 token estimate. Always `>= 0` and `<= text.length`.
|
|
723
|
+
*/
|
|
724
|
+
charsRemoved: number;
|
|
725
|
+
/** What kinds of removal happened (`preamble`, `hedging`, `meta`, `closer`). */
|
|
726
|
+
removed: string[];
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Pluggable token estimator. Used by Agni when a trace did not supply
|
|
730
|
+
* explicit `tokensUsed` / `inputTokens` / `outputTokens` telemetry — i.e.
|
|
731
|
+
* for the fallback path.
|
|
732
|
+
*
|
|
733
|
+
* Implementations must:
|
|
734
|
+
* - never throw (return a numeric fallback on internal error);
|
|
735
|
+
* - return a non-negative integer;
|
|
736
|
+
* - expose a stable `name` for telemetry / report stamping.
|
|
737
|
+
*
|
|
738
|
+
* The Ojas default is `charBasedTokenEstimator` (char/4, conservative,
|
|
739
|
+
* platform-stable). Real-tokenizer adapters live in `src/agni/`:
|
|
740
|
+
* - `createTiktokenEstimator('cl100k_base')` (requires the optional
|
|
741
|
+
* `tiktoken` package to be installed by the host project).
|
|
742
|
+
*/
|
|
743
|
+
export interface TokenEstimator {
|
|
744
|
+
/** Stable identifier for telemetry / report stamping (e.g. 'char/4'). */
|
|
745
|
+
readonly name: string;
|
|
746
|
+
/** Estimate tokens for a piece of text. MUST NOT throw. */
|
|
747
|
+
estimate(text: string): number;
|
|
748
|
+
}
|
|
749
|
+
export interface TelemetryHealth {
|
|
750
|
+
vitalSigns: HealthScore;
|
|
751
|
+
degradationRisk: HealthScore;
|
|
752
|
+
observabilityCoverage: HealthScore;
|
|
753
|
+
eventsEmitted: number;
|
|
754
|
+
activeAlerts: number;
|
|
755
|
+
}
|
|
756
|
+
export interface TelemetryPolicy {
|
|
757
|
+
maxRecentEvents: number;
|
|
758
|
+
degradationThreshold: number;
|
|
759
|
+
/**
|
|
760
|
+
* Trailing window size for latency percentile tracking, per
|
|
761
|
+
* `(agentId, taskClass)`. Default 100. Older samples are dropped so
|
|
762
|
+
* memory usage is stable in long-running processes.
|
|
763
|
+
*/
|
|
764
|
+
latencyWindowSize?: number;
|
|
765
|
+
/**
|
|
766
|
+
* Optional latency budget in ms. If set, `recordLatency()` emits a
|
|
767
|
+
* `latency_breach` event when the windowed p95 exceeds this value
|
|
768
|
+
* (idempotent per `(agentId, taskClass)` until the percentile drops
|
|
769
|
+
* back below the budget — clears the latch). Default unset (no
|
|
770
|
+
* automatic breach detection).
|
|
771
|
+
*/
|
|
772
|
+
latencyP95BreachMs?: number;
|
|
773
|
+
/**
|
|
774
|
+
* How long an agent can go without a `heartbeat()` before
|
|
775
|
+
* `detectStuckAgents()` flags it and Pulse emits `agent_stuck`.
|
|
776
|
+
* Default 60_000 (60 s).
|
|
777
|
+
*/
|
|
778
|
+
stuckAfterMs?: number;
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Windowed latency summary for one `(agentId, taskClass)` pair.
|
|
782
|
+
* Returned by `Pulse.getLatencyStats()`. All durations are in
|
|
783
|
+
* milliseconds.
|
|
784
|
+
*/
|
|
785
|
+
export interface LatencyStats {
|
|
786
|
+
agentId: string;
|
|
787
|
+
taskClass: string;
|
|
788
|
+
samples: number;
|
|
789
|
+
/** Average duration. */
|
|
790
|
+
meanMs: number;
|
|
791
|
+
/** 50th percentile (median). */
|
|
792
|
+
p50Ms: number;
|
|
793
|
+
/** 95th percentile. */
|
|
794
|
+
p95Ms: number;
|
|
795
|
+
/** Maximum observed in window. */
|
|
796
|
+
maxMs: number;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Snapshot of one stuck-agent flag, returned by
|
|
800
|
+
* `Pulse.detectStuckAgents()`. `agent_stuck` events are also emitted
|
|
801
|
+
* once per (agentId, idle-window) crossing.
|
|
802
|
+
*/
|
|
803
|
+
export interface StuckAgentReport {
|
|
804
|
+
agentId: string;
|
|
805
|
+
/** Last observed heartbeat in ISO-8601 UTC, if ever recorded. */
|
|
806
|
+
lastHeartbeatAt?: string;
|
|
807
|
+
/** Milliseconds since `lastHeartbeatAt` at the time of the call. */
|
|
808
|
+
idleMs: number;
|
|
809
|
+
}
|
|
810
|
+
export type RepairAction = 'context_reset' | 'memory_rollback' | 'tool_retry' | 'plan_regeneration' | 'retrieval_refresh' | 'instruction_regrounding' | 'safe_mode_activation' | 'human_escalation';
|
|
811
|
+
export interface RepairProtocol {
|
|
812
|
+
id: string;
|
|
813
|
+
diagnosis: string;
|
|
814
|
+
actions: RepairAction[];
|
|
815
|
+
severity: 'info' | 'warning' | 'critical';
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Pluggable executor for repair protocols. Chikitsa diagnoses
|
|
819
|
+
* failures and produces `RepairProtocol`s but does **not** execute
|
|
820
|
+
* them — execution is the caller's responsibility because the
|
|
821
|
+
* concrete action (resetting a context window, retrying a tool,
|
|
822
|
+
* activating safe mode) is runtime-specific.
|
|
823
|
+
*
|
|
824
|
+
* Implementations MUST be idempotent on `protocol.id`: calling
|
|
825
|
+
* `execute()` twice with the same id must not double-apply effects.
|
|
826
|
+
* Chikitsa tracks per-id state and short-circuits a second call, but
|
|
827
|
+
* a defensive implementation is recommended.
|
|
828
|
+
*
|
|
829
|
+
* Implementations MUST NOT throw — return `{ status: 'failed', … }`
|
|
830
|
+
* and let Chikitsa decide whether to attempt rollback. A thrown
|
|
831
|
+
* error is caught by Chikitsa and recorded as `status: 'failed'`.
|
|
832
|
+
*/
|
|
833
|
+
export interface RepairExecutor {
|
|
834
|
+
readonly name: string;
|
|
835
|
+
execute(protocol: RepairProtocol): Promise<RepairExecutionResult>;
|
|
836
|
+
/** Optional compensating action. Called by Chikitsa when verification fails. */
|
|
837
|
+
rollback?(protocol: RepairProtocol, executionDetails: Record<string, unknown>): Promise<void>;
|
|
838
|
+
}
|
|
839
|
+
export interface RepairExecutionResult {
|
|
840
|
+
status: 'applied' | 'failed';
|
|
841
|
+
/** Free-form executor-specific payload (e.g. tool retry count, reset hash). */
|
|
842
|
+
details: Record<string, unknown>;
|
|
843
|
+
/** Optional human-readable summary. */
|
|
844
|
+
message?: string;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Pluggable verifier called by Chikitsa after `RepairExecutor.execute()`
|
|
848
|
+
* succeeds. Closes the detect → diagnose → repair → verify loop so
|
|
849
|
+
* the agent has evidence the repair actually fixed the failure.
|
|
850
|
+
*
|
|
851
|
+
* Implementations MUST NOT throw — return `{ verified: false, … }`
|
|
852
|
+
* on any internal error.
|
|
853
|
+
*/
|
|
854
|
+
export interface RepairVerifier {
|
|
855
|
+
readonly name: string;
|
|
856
|
+
verify(protocol: RepairProtocol, executionResult: RepairExecutionResult): Promise<RepairVerificationResult>;
|
|
857
|
+
}
|
|
858
|
+
export interface RepairVerificationResult {
|
|
859
|
+
verified: boolean;
|
|
860
|
+
/** Why we believe the repair worked (or didn't). */
|
|
861
|
+
reason: string;
|
|
862
|
+
/** Confidence in `[0, 1]`. */
|
|
863
|
+
confidence: number;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Record of one execute-then-verify cycle. Returned by
|
|
867
|
+
* `Chikitsa.executeProtocol()` and retained in
|
|
868
|
+
* `Chikitsa.executionHistory()` for audit.
|
|
869
|
+
*/
|
|
870
|
+
export interface RepairExecutionRecord {
|
|
871
|
+
protocolId: string;
|
|
872
|
+
startedAt: string;
|
|
873
|
+
finishedAt: string;
|
|
874
|
+
/**
|
|
875
|
+
* Terminal status of the cycle:
|
|
876
|
+
* - `'verified'` — execute succeeded AND verifier returned true
|
|
877
|
+
* - `'applied'` — execute succeeded; no verifier configured
|
|
878
|
+
* - `'unverified'` — execute succeeded; verifier returned false
|
|
879
|
+
* - `'rolled-back'` — verifier returned false AND executor's `rollback()` ran
|
|
880
|
+
* - `'failed'` — execute returned `failed` or threw
|
|
881
|
+
* - `'already-applied'` — second call for an already-applied protocol id
|
|
882
|
+
*/
|
|
883
|
+
status: 'verified' | 'applied' | 'unverified' | 'rolled-back' | 'failed' | 'already-applied';
|
|
884
|
+
executor: string;
|
|
885
|
+
verifier?: string;
|
|
886
|
+
executionResult?: RepairExecutionResult;
|
|
887
|
+
verificationResult?: RepairVerificationResult;
|
|
888
|
+
/** Captured error message when status === 'failed' because of a throw. */
|
|
889
|
+
error?: string;
|
|
890
|
+
}
|
|
891
|
+
export interface RehabilitationHealth {
|
|
892
|
+
repairReadiness: HealthScore;
|
|
893
|
+
rollbackSafety: HealthScore;
|
|
894
|
+
recoveryPlaybooks: HealthScore;
|
|
895
|
+
protocolsAvailable: number;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* One observed agent task outcome, fed to Chikitsa via
|
|
899
|
+
* `recordTaskOutcome(...)`. Drives the velocity / success-rate
|
|
900
|
+
* windowed statistics surfaced in `getVelocityStats()`.
|
|
901
|
+
*/
|
|
902
|
+
export interface TaskOutcomeRecord {
|
|
903
|
+
/** Stable ID for the task. Deduping is *not* enforced. */
|
|
904
|
+
taskId: string;
|
|
905
|
+
/** When the task completed (or was abandoned). */
|
|
906
|
+
completedAt: string;
|
|
907
|
+
/** Whether the task ultimately succeeded. */
|
|
908
|
+
succeeded: boolean;
|
|
909
|
+
/** Wall-clock duration in ms; required for throughput. */
|
|
910
|
+
durationMs: number;
|
|
911
|
+
/** Optional category — e.g. `'investigation'`, `'feature'`, `'bug'`. */
|
|
912
|
+
category?: string;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Windowed velocity summary returned by `Chikitsa.getVelocityStats()`.
|
|
916
|
+
* Reflects only the trailing `velocityWindowSize` outcomes (default 50).
|
|
917
|
+
*/
|
|
918
|
+
export interface VelocityStats {
|
|
919
|
+
/** Number of outcomes in the rolling window. */
|
|
920
|
+
windowSize: number;
|
|
921
|
+
/** Fraction of those that succeeded (0 if window is empty). */
|
|
922
|
+
successRate: number;
|
|
923
|
+
/** Median duration over the window, in ms (0 if empty). */
|
|
924
|
+
medianDurationMs: number;
|
|
925
|
+
/** P90 duration over the window, in ms (0 if empty). */
|
|
926
|
+
p90DurationMs: number;
|
|
927
|
+
/**
|
|
928
|
+
* Tasks-per-hour computed from total successes / span between the
|
|
929
|
+
* oldest and newest `completedAt` in the window. Returns 0 if the
|
|
930
|
+
* span is undefined (single sample) or the window is empty.
|
|
931
|
+
*/
|
|
932
|
+
tasksPerHour: number;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Snapshot of agent state that Chikitsa serialises into a Markdown
|
|
936
|
+
* handoff document via `generateHandoff()`. Lets one agent / session
|
|
937
|
+
* pick up exactly where the previous left off (a structured
|
|
938
|
+
* `progress.txt`-style cross-session resume artefact).
|
|
939
|
+
*/
|
|
940
|
+
export interface HandoffSnapshot {
|
|
941
|
+
/** Agent identifier (`OjasConfig.agentId`). */
|
|
942
|
+
agentId: string;
|
|
943
|
+
/** When this snapshot was generated. */
|
|
944
|
+
generatedAt: string;
|
|
945
|
+
/** Free-text current focus / objective. */
|
|
946
|
+
focus?: string;
|
|
947
|
+
/** Open items the next agent should address. */
|
|
948
|
+
pendingTasks: string[];
|
|
949
|
+
/** Completed items, kept brief for context. */
|
|
950
|
+
completedTasks: string[];
|
|
951
|
+
/** Velocity stats embedded at the top of the document. */
|
|
952
|
+
velocity?: VelocityStats;
|
|
953
|
+
/** Optional cross-cutting notes. */
|
|
954
|
+
notes?: string[];
|
|
955
|
+
}
|
|
956
|
+
export interface RehabilitationPolicy {
|
|
957
|
+
autoRepairEnabled: boolean;
|
|
958
|
+
criticalRequiresHuman: boolean;
|
|
959
|
+
maxProtocolsPerCycle: number;
|
|
960
|
+
/** Hard cap on retained repair protocols. */
|
|
961
|
+
maxProtocols?: number;
|
|
962
|
+
/**
|
|
963
|
+
* Rolling-window size (number of trailing `TaskOutcomeRecord`s)
|
|
964
|
+
* `getVelocityStats()` summarises. Default 50. Older outcomes are
|
|
965
|
+
* dropped when this cap is exceeded.
|
|
966
|
+
*/
|
|
967
|
+
velocityWindowSize?: number;
|
|
968
|
+
}
|
|
969
|
+
export interface StressScenario {
|
|
970
|
+
id: string;
|
|
971
|
+
name: string;
|
|
972
|
+
type: StressType;
|
|
973
|
+
intensity: number;
|
|
974
|
+
description: string;
|
|
975
|
+
payload: unknown;
|
|
976
|
+
}
|
|
977
|
+
export type StressType = 'adversarial_input' | 'latency_spike' | 'conflicting_instructions' | 'memory_corruption' | 'tool_failure' | 'context_overflow' | 'prompt_injection' | 'ambiguous_goal';
|
|
978
|
+
export interface StressTestResult {
|
|
979
|
+
scenarioId: string;
|
|
980
|
+
agentId: string;
|
|
981
|
+
timestamp: string;
|
|
982
|
+
passed: boolean;
|
|
983
|
+
hallucinationDetected: boolean;
|
|
984
|
+
recoveryTimeMs: number;
|
|
985
|
+
stabilityScore: number;
|
|
986
|
+
adaptabilityScore: number;
|
|
987
|
+
details: string;
|
|
988
|
+
}
|
|
989
|
+
export interface ResilienceHealth {
|
|
990
|
+
overallResilience: HealthScore;
|
|
991
|
+
hallucinationResistance: HealthScore;
|
|
992
|
+
recoveryAbility: HealthScore;
|
|
993
|
+
planningStability: HealthScore;
|
|
994
|
+
weaknesses: string[];
|
|
995
|
+
}
|
|
996
|
+
export interface ResiliencePolicy {
|
|
997
|
+
/** How often to run stress tests (seconds) */
|
|
998
|
+
stressIntervalSec: number;
|
|
999
|
+
/** Number of scenarios per cycle */
|
|
1000
|
+
scenariosPerCycle: number;
|
|
1001
|
+
/** Minimum resilience score before alerting */
|
|
1002
|
+
minResilienceThreshold: number;
|
|
1003
|
+
/** Enable progressive difficulty */
|
|
1004
|
+
progressiveDifficulty: boolean;
|
|
1005
|
+
/** Max intensity for stress scenarios */
|
|
1006
|
+
maxIntensity: number;
|
|
1007
|
+
/** Hard cap on retained stress-test results. */
|
|
1008
|
+
maxResults?: number;
|
|
1009
|
+
/** Timeout budget per stress scenario in milliseconds. */
|
|
1010
|
+
maxScenarioDurationMs?: number;
|
|
1011
|
+
}
|
|
1012
|
+
export interface AgentAdapter {
|
|
1013
|
+
id: string;
|
|
1014
|
+
/**
|
|
1015
|
+
* Process input and return output — the agent's core function.
|
|
1016
|
+
* Implementations SHOULD respect the optional `signal` and abort
|
|
1017
|
+
* long-running work when it fires. Callers that do not supply a
|
|
1018
|
+
* signal get the same behaviour as before (backward-compatible).
|
|
1019
|
+
*/
|
|
1020
|
+
process(input: string, context: ContextItem[], signal?: AbortSignal): Promise<AgentResponse>;
|
|
1021
|
+
/** Get current memory/state for health evaluation */
|
|
1022
|
+
getState(): Promise<AgentState>;
|
|
1023
|
+
/** Inject consolidated memory back into agent */
|
|
1024
|
+
injectMemory(memory: ConsolidatedMemory): Promise<void>;
|
|
1025
|
+
}
|
|
1026
|
+
export interface AgentResponse {
|
|
1027
|
+
output: string;
|
|
1028
|
+
tokensUsed: number;
|
|
1029
|
+
reasoning?: string;
|
|
1030
|
+
confidence: number;
|
|
1031
|
+
durationMs: number;
|
|
1032
|
+
}
|
|
1033
|
+
export interface AgentState {
|
|
1034
|
+
activeContextSize: number;
|
|
1035
|
+
memoryCount: number;
|
|
1036
|
+
uptime: number;
|
|
1037
|
+
lastActivity: string;
|
|
1038
|
+
errorRate: number;
|
|
1039
|
+
}
|
|
1040
|
+
export interface OjasConfig {
|
|
1041
|
+
agentId: string;
|
|
1042
|
+
nutrition: NutritionPolicy;
|
|
1043
|
+
recovery: RecoveryPolicy;
|
|
1044
|
+
resilience: ResiliencePolicy;
|
|
1045
|
+
defense: DefensePolicy;
|
|
1046
|
+
metabolism: MetabolismPolicy;
|
|
1047
|
+
telemetry: TelemetryPolicy;
|
|
1048
|
+
rehabilitation: RehabilitationPolicy;
|
|
1049
|
+
/** Enable continuous health monitoring */
|
|
1050
|
+
continuousMonitoring: boolean;
|
|
1051
|
+
/** Health check interval (seconds) */
|
|
1052
|
+
healthCheckIntervalSec: number;
|
|
1053
|
+
/** Hard cap on retained health reports. */
|
|
1054
|
+
maxHealthHistory: number;
|
|
1055
|
+
/**
|
|
1056
|
+
* Pre-fitted calibration model for mapping raw health scores to
|
|
1057
|
+
* empirically calibrated probabilities. Load from an L3 benchmark
|
|
1058
|
+
* run via `deserializeCalibrationModel()`. When provided, the
|
|
1059
|
+
* overall health score uses `basis: 'empirical_calibrated'`.
|
|
1060
|
+
*/
|
|
1061
|
+
calibrationModel?: import('./util/calibration').IsotonicCalibrationModel;
|
|
1062
|
+
}
|
|
1063
|
+
export declare const DEFAULT_NUTRITION_POLICY: NutritionPolicy;
|
|
1064
|
+
export declare const DEFAULT_RECOVERY_POLICY: RecoveryPolicy;
|
|
1065
|
+
export declare const DEFAULT_RESILIENCE_POLICY: ResiliencePolicy;
|
|
1066
|
+
export declare const DEFAULT_DEFENSE_POLICY: DefensePolicy;
|
|
1067
|
+
export declare const DEFAULT_METABOLISM_POLICY: MetabolismPolicy;
|
|
1068
|
+
export declare const DEFAULT_TELEMETRY_POLICY: TelemetryPolicy;
|
|
1069
|
+
export declare const DEFAULT_REHABILITATION_POLICY: RehabilitationPolicy;
|
|
1070
|
+
export type KnownHealthEventType = 'context_overload_detected' | 'context_items_rejected' | 'recovery_cycle_completed' | 'memory_consolidated' | 'memory_pruned' | 'memory_cold' | 'context_budget_milestone' | 'prompt_injection_quarantined' | 'threat_detected' | 'hallucination_detected' | 'metabolism_pressure_high' | 'stress_test_failed' | 'stress_test_passed' | 'repair_protocol_generated' | 'repair_executed' | 'repair_verified' | 'repair_rolled_back' | 'agent_stuck' | 'latency_breach' | 'degradation_detected' | 'goal_drift_detected';
|
|
1071
|
+
export interface ContextOverloadDetectedDetails extends Record<string, unknown> {
|
|
1072
|
+
contextTokens: number;
|
|
1073
|
+
relevanceScore: number;
|
|
1074
|
+
duplicateContextRatio: number;
|
|
1075
|
+
}
|
|
1076
|
+
export interface RecoveryCycleCompletedDetails extends Record<string, unknown> {
|
|
1077
|
+
rawTracesProcessed: number;
|
|
1078
|
+
memoriesCreated: number;
|
|
1079
|
+
memoriesPruned: number;
|
|
1080
|
+
heuristicsUpdated: number;
|
|
1081
|
+
driftReduction: number;
|
|
1082
|
+
}
|
|
1083
|
+
export interface PromptInjectionQuarantinedDetails extends Record<string, unknown> {
|
|
1084
|
+
source: string;
|
|
1085
|
+
attackType: ThreatType;
|
|
1086
|
+
riskScore: number;
|
|
1087
|
+
reasons: string[];
|
|
1088
|
+
actionTaken: 'quarantined_from_agent_context' | 'down_ranked' | 'verified';
|
|
1089
|
+
}
|
|
1090
|
+
export interface MetabolismPressureDetails extends Record<string, unknown> {
|
|
1091
|
+
costPressure: number;
|
|
1092
|
+
avgTokens: number;
|
|
1093
|
+
avgLatencyMs: number;
|
|
1094
|
+
recommendation: 'compress_context' | 'reduce_tool_calls' | 'cap_reasoning_depth';
|
|
1095
|
+
}
|
|
1096
|
+
export interface StressTestFailedDetails extends Record<string, unknown> {
|
|
1097
|
+
scenarioId: string;
|
|
1098
|
+
stressType: StressType;
|
|
1099
|
+
intensity: number;
|
|
1100
|
+
hallucinationDetected: boolean;
|
|
1101
|
+
stabilityScore: number;
|
|
1102
|
+
}
|
|
1103
|
+
export interface RepairProtocolGeneratedDetails extends Record<string, unknown> {
|
|
1104
|
+
protocolId: string;
|
|
1105
|
+
diagnosis: string;
|
|
1106
|
+
actions: RepairAction[];
|
|
1107
|
+
failureType: RuntimeFailureType;
|
|
1108
|
+
}
|
|
1109
|
+
export type ContextOverloadDetectedEvent = HealthEvent<ContextOverloadDetectedDetails>;
|
|
1110
|
+
export type RecoveryCycleCompletedEvent = HealthEvent<RecoveryCycleCompletedDetails>;
|
|
1111
|
+
export type PromptInjectionQuarantinedEvent = HealthEvent<PromptInjectionQuarantinedDetails>;
|
|
1112
|
+
export type MetabolismPressureEvent = HealthEvent<MetabolismPressureDetails>;
|
|
1113
|
+
export type StressTestFailedEvent = HealthEvent<StressTestFailedDetails>;
|
|
1114
|
+
export type RepairProtocolGeneratedEvent = HealthEvent<RepairProtocolGeneratedDetails>;
|
|
1115
|
+
//# sourceMappingURL=types.d.ts.map
|