@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
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `defaultResponseDistiller` — rule-based filler stripper for agent
|
|
4
|
+
* output.
|
|
5
|
+
*
|
|
6
|
+
* Pattern: LLM responses routinely contain ~30-40% filler — "Sure,
|
|
7
|
+
* I'd be happy to help!", "Hope this helps!", chain-of-thought
|
|
8
|
+
* meta-commentary, repeated preambles. None of it is load-bearing
|
|
9
|
+
* for the caller. Stripping it
|
|
10
|
+
* saves tokens on the output side without touching what actually
|
|
11
|
+
* matters.
|
|
12
|
+
*
|
|
13
|
+
* **Code blocks are sacrosanct.** Anything between fenced code fences
|
|
14
|
+
* (``` … ```) is preserved verbatim, byte-for-byte. We also preserve
|
|
15
|
+
* indented code blocks (4-space indent) and inline single-backtick
|
|
16
|
+
* spans.
|
|
17
|
+
*
|
|
18
|
+
* Three intensity levels:
|
|
19
|
+
* - **`lite`**: strip only the lowest-risk preamble/closer phrases
|
|
20
|
+
* (e.g. "Sure!", "Hope this helps!"). Won't touch substance.
|
|
21
|
+
* - **`full`** (default): adds hedging (`I think`, `It seems`),
|
|
22
|
+
* filler intros ("Let me take a look", "Here's what I found"), and
|
|
23
|
+
* repeated "in summary" / "to conclude" closers.
|
|
24
|
+
* - **`ultra`**: also collapses repeated empty lines, strips
|
|
25
|
+
* standalone Markdown emphasis on filler phrases, and removes
|
|
26
|
+
* "Note:" / "FYI:" prefixes from individual sentences.
|
|
27
|
+
*
|
|
28
|
+
* False-positive guard: every pattern is anchored to either start-of-
|
|
29
|
+
* string, start-of-line, end-of-string, or a sentence boundary. We
|
|
30
|
+
* never strip mid-sentence content unless it's a standalone hedge
|
|
31
|
+
* (`, I think,`) — and even then only at intensity `full`+.
|
|
32
|
+
*/
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.defaultResponseDistiller = void 0;
|
|
35
|
+
exports.createResponseDistiller = createResponseDistiller;
|
|
36
|
+
// Conservative anchored patterns. Each is tested without --u flag to keep
|
|
37
|
+
// behaviour stable across Node versions.
|
|
38
|
+
//
|
|
39
|
+
// IMPORTANT: every pattern uses `g` (global) so a single text with
|
|
40
|
+
// multiple matches gets fully stripped, not just the first.
|
|
41
|
+
const PATTERNS = [
|
|
42
|
+
// ── PREAMBLE ──
|
|
43
|
+
// "Sure!", "Sure, I'd be happy to help.", "Of course!"
|
|
44
|
+
{
|
|
45
|
+
pattern: /(^|[.!?]\s+)(Sure|Of course|Certainly|Absolutely|Definitely)(,?\s*(I'?d be happy to help[!.]?|here you go[!.]?|let me help[!.]?))?[.!]?\s*/gi,
|
|
46
|
+
category: 'preamble',
|
|
47
|
+
minIntensity: 'lite',
|
|
48
|
+
},
|
|
49
|
+
// "Let me take a look at..." / "Let me check..." / "Let's look at..."
|
|
50
|
+
{
|
|
51
|
+
pattern: /(^|[.!?]\s+)(Let me|Let's|I'll|I will)\s+(take a look at|check|examine|look at|review|look into)\s+[^.!?]*[.!]?\s*/gi,
|
|
52
|
+
category: 'preamble',
|
|
53
|
+
minIntensity: 'full',
|
|
54
|
+
},
|
|
55
|
+
// "Here's what I found:" / "Here is the answer:"
|
|
56
|
+
{
|
|
57
|
+
pattern: /(^|[.!?]\s+)(Here'?s|Here is) (what I found|the answer|my analysis|my response)[:.]?\s*/gi,
|
|
58
|
+
category: 'preamble',
|
|
59
|
+
minIntensity: 'full',
|
|
60
|
+
},
|
|
61
|
+
// "I'd be happy to help" / "I'd be glad to help"
|
|
62
|
+
{
|
|
63
|
+
pattern: /(^|[.!?]\s+)I'?d be (happy|glad|delighted) to (help|assist)[!.]?\s*/gi,
|
|
64
|
+
category: 'preamble',
|
|
65
|
+
minIntensity: 'lite',
|
|
66
|
+
},
|
|
67
|
+
// ── HEDGING ──
|
|
68
|
+
// Standalone hedging sentences: "I think this is right.", "It seems that..."
|
|
69
|
+
// We only strip the hedge, not the whole sentence.
|
|
70
|
+
{
|
|
71
|
+
pattern: /\b(?:I think|I believe|It seems(?: like)?|It appears(?: that)?|It looks like)\s+/gi,
|
|
72
|
+
category: 'hedging',
|
|
73
|
+
minIntensity: 'full',
|
|
74
|
+
},
|
|
75
|
+
// "as far as I can tell" / "to my knowledge"
|
|
76
|
+
{
|
|
77
|
+
pattern: /,?\s*(?:as far as I (?:can tell|know)|to (?:my|the best of my) knowledge)\s*,?\s*/gi,
|
|
78
|
+
category: 'hedging',
|
|
79
|
+
minIntensity: 'full',
|
|
80
|
+
},
|
|
81
|
+
// ── META ──
|
|
82
|
+
// "Note:" / "FYI:" at the start of a sentence (intensity ultra only).
|
|
83
|
+
{
|
|
84
|
+
pattern: /(^|[.!?]\s+)(Note|FYI|PSA|Heads up)[:!]\s*/gi,
|
|
85
|
+
category: 'meta',
|
|
86
|
+
minIntensity: 'ultra',
|
|
87
|
+
},
|
|
88
|
+
// Standalone markdown emphasis around filler ("**Important:**")
|
|
89
|
+
{
|
|
90
|
+
pattern: /(^|[.!?]\s+)\*+(?:Important|Note|Warning)\*+:\s*/gi,
|
|
91
|
+
category: 'meta',
|
|
92
|
+
minIntensity: 'ultra',
|
|
93
|
+
},
|
|
94
|
+
// ── CLOSER ──
|
|
95
|
+
// "Hope this helps!" / "Hope that helps!"
|
|
96
|
+
// NOTE: `(^|[.!?]\s+)` is *capturing* so the replacement function
|
|
97
|
+
// gets the leading punctuation as $1 and preserves the sentence boundary.
|
|
98
|
+
{
|
|
99
|
+
pattern: /(^|[.!?]\s+)(?:I )?[Hh]ope (?:this|that|it)\s+(?:helps|makes sense|clarifies|is clear)[!.]?\s*/g,
|
|
100
|
+
category: 'closer',
|
|
101
|
+
minIntensity: 'lite',
|
|
102
|
+
},
|
|
103
|
+
// "Let me know if you have any questions"
|
|
104
|
+
{
|
|
105
|
+
pattern: /(^|[.!?]\s+)Let me know (?:if you (?:have any questions|need anything else|want me to (?:elaborate|continue))|how (?:I can help|else I can assist))[.!?]?\s*/gi,
|
|
106
|
+
category: 'closer',
|
|
107
|
+
minIntensity: 'lite',
|
|
108
|
+
},
|
|
109
|
+
// "In summary, ..." / "To summarise, ..." — strip the intro only.
|
|
110
|
+
{
|
|
111
|
+
pattern: /(^|[.!?]\s+)(In summary|To summarise|To summarize|In conclusion|To conclude)\s*,\s*/gi,
|
|
112
|
+
category: 'closer',
|
|
113
|
+
minIntensity: 'full',
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
const INTENSITY_ORDER = {
|
|
117
|
+
lite: 1,
|
|
118
|
+
full: 2,
|
|
119
|
+
ultra: 3,
|
|
120
|
+
};
|
|
121
|
+
function shouldApply(pattern, level) {
|
|
122
|
+
return INTENSITY_ORDER[pattern.minIntensity] <= INTENSITY_ORDER[level];
|
|
123
|
+
}
|
|
124
|
+
function segment(text) {
|
|
125
|
+
const out = [];
|
|
126
|
+
// Match fenced blocks: ``` ... ``` or ~~~ ... ~~~ (with optional language tag).
|
|
127
|
+
const re = /(```[\s\S]*?```|~~~[\s\S]*?~~~)/g;
|
|
128
|
+
let last = 0;
|
|
129
|
+
let m;
|
|
130
|
+
while ((m = re.exec(text)) !== null) {
|
|
131
|
+
if (m.index > last) {
|
|
132
|
+
out.push({ kind: 'prose', text: text.slice(last, m.index) });
|
|
133
|
+
}
|
|
134
|
+
out.push({ kind: 'code', text: m[0] });
|
|
135
|
+
last = m.index + m[0].length;
|
|
136
|
+
}
|
|
137
|
+
if (last < text.length) {
|
|
138
|
+
out.push({ kind: 'prose', text: text.slice(last) });
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
/** Char/4 token-count estimate so we can report `tokensRemoved`. */
|
|
143
|
+
function estTokens(text) {
|
|
144
|
+
return Math.ceil(text.length / 4);
|
|
145
|
+
}
|
|
146
|
+
function createResponseDistiller(intensity = 'full') {
|
|
147
|
+
return {
|
|
148
|
+
name: `default-distiller/${intensity}`,
|
|
149
|
+
distill(text) {
|
|
150
|
+
if (typeof text !== 'string' || text.length === 0) {
|
|
151
|
+
return { text: text ?? '', tokensRemoved: 0, charsRemoved: 0, removed: [] };
|
|
152
|
+
}
|
|
153
|
+
const segments = segment(text);
|
|
154
|
+
const removed = new Set();
|
|
155
|
+
let removedChars = 0;
|
|
156
|
+
const outSegments = [];
|
|
157
|
+
for (const seg of segments) {
|
|
158
|
+
if (seg.kind === 'code') {
|
|
159
|
+
outSegments.push(seg.text);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
let working = seg.text;
|
|
163
|
+
for (const p of PATTERNS) {
|
|
164
|
+
if (!shouldApply(p, intensity))
|
|
165
|
+
continue;
|
|
166
|
+
const before = working.length;
|
|
167
|
+
working = working.replace(p.pattern, (_match, lead = '') => lead);
|
|
168
|
+
const delta = before - working.length;
|
|
169
|
+
if (delta > 0) {
|
|
170
|
+
removed.add(p.category);
|
|
171
|
+
removedChars += delta;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// At `ultra` intensity, collapse 3+ consecutive blank lines to 2.
|
|
175
|
+
if (intensity === 'ultra') {
|
|
176
|
+
working = working.replace(/\n{3,}/g, '\n\n');
|
|
177
|
+
}
|
|
178
|
+
outSegments.push(working);
|
|
179
|
+
}
|
|
180
|
+
const distilled = outSegments.join('');
|
|
181
|
+
const tokensRemoved = Math.max(0, estTokens(text) - estTokens(distilled));
|
|
182
|
+
return {
|
|
183
|
+
text: distilled,
|
|
184
|
+
tokensRemoved,
|
|
185
|
+
charsRemoved: removedChars,
|
|
186
|
+
removed: Array.from(removed),
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/** Default `ResponseDistiller` at `full` intensity. Re-export for convenience. */
|
|
192
|
+
exports.defaultResponseDistiller = createResponseDistiller('full');
|
|
193
|
+
//# sourceMappingURL=response-distiller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-distiller.js","sourceRoot":"","sources":["../../src/agni/response-distiller.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;;AA8IH,0DA+CC;AA9KD,0EAA0E;AAC1E,yCAAyC;AACzC,EAAE;AACF,mEAAmE;AACnE,4DAA4D;AAC5D,MAAM,QAAQ,GAAuB;IACnC,iBAAiB;IACjB,uDAAuD;IACvD;QACE,OAAO,EAAE,8IAA8I;QACvJ,QAAQ,EAAE,UAAU;QACpB,YAAY,EAAE,MAAM;KACrB;IACD,0EAA0E;IAC1E;QACE,OAAO,EAAE,sHAAsH;QAC/H,QAAQ,EAAE,UAAU;QACpB,YAAY,EAAE,MAAM;KACrB;IACD,iDAAiD;IACjD;QACE,OAAO,EAAE,2FAA2F;QACpG,QAAQ,EAAE,UAAU;QACpB,YAAY,EAAE,MAAM;KACrB;IACD,iDAAiD;IACjD;QACE,OAAO,EAAE,uEAAuE;QAChF,QAAQ,EAAE,UAAU;QACpB,YAAY,EAAE,MAAM;KACrB;IAED,gBAAgB;IAChB,6EAA6E;IAC7E,mDAAmD;IACnD;QACE,OAAO,EAAE,oFAAoF;QAC7F,QAAQ,EAAE,SAAS;QACnB,YAAY,EAAE,MAAM;KACrB;IACD,6CAA6C;IAC7C;QACE,OAAO,EAAE,qFAAqF;QAC9F,QAAQ,EAAE,SAAS;QACnB,YAAY,EAAE,MAAM;KACrB;IAED,aAAa;IACb,sEAAsE;IACtE;QACE,OAAO,EAAE,8CAA8C;QACvD,QAAQ,EAAE,MAAM;QAChB,YAAY,EAAE,OAAO;KACtB;IACD,gEAAgE;IAChE;QACE,OAAO,EAAE,oDAAoD;QAC7D,QAAQ,EAAE,MAAM;QAChB,YAAY,EAAE,OAAO;KACtB;IAED,eAAe;IACf,0CAA0C;IAC1C,kEAAkE;IAClE,0EAA0E;IAC1E;QACE,OAAO,EAAE,iGAAiG;QAC1G,QAAQ,EAAE,QAAQ;QAClB,YAAY,EA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AC,MAAM,CAAC;oBAC9B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;oBAClE,MAAM,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;oBACtC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;wBACd,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;wBACxB,YAAY,IAAI,KAAK,CAAC;oBACxB,CAAC;gBACH,CAAC;gBACD,kEAAkE;gBAClE,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;oBAC1B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;gBAC/C,CAAC;gBACD,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;YAED,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACvC,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;YAE1E,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,aAAa;gBACb,YAAY,EAAE,YAAY;gBAC1B,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;aAC7B,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,kFAAkF;AACrE,QAAA,wBAAwB,GAAsB,uBAAuB,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional tiktoken adapter for `TokenEstimator`.
|
|
3
|
+
*
|
|
4
|
+
* Why this is in its own file
|
|
5
|
+
* ---------------------------
|
|
6
|
+
* `tiktoken` is intentionally **not** a dependency of Ojas (the SDK runs
|
|
7
|
+
* fine without it on the default `charBasedTokenEstimator`). We expose
|
|
8
|
+
* this adapter as a *factory* that only loads `tiktoken` lazily — so:
|
|
9
|
+
*
|
|
10
|
+
* - the Ojas SDK has zero runtime impact for users who don't need a
|
|
11
|
+
* real tokenizer;
|
|
12
|
+
* - users who *do* need one install `tiktoken` themselves and call
|
|
13
|
+
* `createTiktokenEstimator(...)`;
|
|
14
|
+
* - the factory throws a clear, actionable error if `tiktoken` isn't
|
|
15
|
+
* installed, instead of failing somewhere deep in Agni at first
|
|
16
|
+
* `assess()` call.
|
|
17
|
+
*
|
|
18
|
+
* Usage
|
|
19
|
+
* -----
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Agni, createTiktokenEstimator } from '@beingmartinbmc/ojas';
|
|
22
|
+
*
|
|
23
|
+
* const agni = new Agni({}, {
|
|
24
|
+
* tokenEstimator: createTiktokenEstimator('cl100k_base'),
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Encodings supported by `tiktoken` at time of writing:
|
|
29
|
+
* - `cl100k_base` (GPT-3.5, GPT-4 family)
|
|
30
|
+
* - `o200k_base` (GPT-4o family, o1 family)
|
|
31
|
+
* - `r50k_base` (legacy GPT-3)
|
|
32
|
+
* - `p50k_base` (Codex / older models)
|
|
33
|
+
*
|
|
34
|
+
* The factory passes the string through; if `tiktoken` doesn't recognise
|
|
35
|
+
* the encoding it will throw on first call and the adapter falls back to
|
|
36
|
+
* char/4 (with a single stderr warning) rather than crashing Agni.
|
|
37
|
+
*/
|
|
38
|
+
import type { TokenEstimator } from '../types';
|
|
39
|
+
/** Encoding names accepted by current `tiktoken`. Pass-through; not validated. */
|
|
40
|
+
export type TiktokenEncoding = 'cl100k_base' | 'o200k_base' | 'r50k_base' | 'p50k_base';
|
|
41
|
+
/**
|
|
42
|
+
* Build a `TokenEstimator` backed by the optional `tiktoken` package.
|
|
43
|
+
*
|
|
44
|
+
* Throws synchronously when `tiktoken` is not installed (or fails to load),
|
|
45
|
+
* with a message that includes the install command. This is intentional —
|
|
46
|
+
* a confusingly-silent fallback would let users believe they were getting
|
|
47
|
+
* real-tokenizer numbers when they weren't.
|
|
48
|
+
*
|
|
49
|
+
* Once constructed, the estimator itself does **not** throw: if an
|
|
50
|
+
* individual `encode()` call fails on hostile input, the adapter
|
|
51
|
+
* gracefully returns the `charBasedTokenEstimator` result for that call
|
|
52
|
+
* so a single bad string can't break health assessment.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createTiktokenEstimator(encoding?: TiktokenEncoding): TokenEstimator;
|
|
55
|
+
//# sourceMappingURL=tiktoken-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiktoken-adapter.d.ts","sourceRoot":"","sources":["../../src/agni/tiktoken-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAa/C,kFAAkF;AAClF,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,YAAY,GACZ,WAAW,GACX,WAAW,CAAC;AAEhB;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,GAAE,gBAAgC,GAAG,cAAc,CAmDlG"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Optional tiktoken adapter for `TokenEstimator`.
|
|
4
|
+
*
|
|
5
|
+
* Why this is in its own file
|
|
6
|
+
* ---------------------------
|
|
7
|
+
* `tiktoken` is intentionally **not** a dependency of Ojas (the SDK runs
|
|
8
|
+
* fine without it on the default `charBasedTokenEstimator`). We expose
|
|
9
|
+
* this adapter as a *factory* that only loads `tiktoken` lazily — so:
|
|
10
|
+
*
|
|
11
|
+
* - the Ojas SDK has zero runtime impact for users who don't need a
|
|
12
|
+
* real tokenizer;
|
|
13
|
+
* - users who *do* need one install `tiktoken` themselves and call
|
|
14
|
+
* `createTiktokenEstimator(...)`;
|
|
15
|
+
* - the factory throws a clear, actionable error if `tiktoken` isn't
|
|
16
|
+
* installed, instead of failing somewhere deep in Agni at first
|
|
17
|
+
* `assess()` call.
|
|
18
|
+
*
|
|
19
|
+
* Usage
|
|
20
|
+
* -----
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { Agni, createTiktokenEstimator } from '@beingmartinbmc/ojas';
|
|
23
|
+
*
|
|
24
|
+
* const agni = new Agni({}, {
|
|
25
|
+
* tokenEstimator: createTiktokenEstimator('cl100k_base'),
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Encodings supported by `tiktoken` at time of writing:
|
|
30
|
+
* - `cl100k_base` (GPT-3.5, GPT-4 family)
|
|
31
|
+
* - `o200k_base` (GPT-4o family, o1 family)
|
|
32
|
+
* - `r50k_base` (legacy GPT-3)
|
|
33
|
+
* - `p50k_base` (Codex / older models)
|
|
34
|
+
*
|
|
35
|
+
* The factory passes the string through; if `tiktoken` doesn't recognise
|
|
36
|
+
* the encoding it will throw on first call and the adapter falls back to
|
|
37
|
+
* char/4 (with a single stderr warning) rather than crashing Agni.
|
|
38
|
+
*/
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.createTiktokenEstimator = createTiktokenEstimator;
|
|
41
|
+
const module_1 = require("module");
|
|
42
|
+
const index_1 = require("./index");
|
|
43
|
+
/**
|
|
44
|
+
* Node's `createRequire` lets us perform an opaque-to-bundlers
|
|
45
|
+
* resolution of an *optional* peer dependency without using `eval`.
|
|
46
|
+
* Static-analysis tools / CSP-restricted environments flag `eval`
|
|
47
|
+
* even when the input is a constant string, so this is the
|
|
48
|
+
* preferred form for "load this module only if the host installed
|
|
49
|
+
* it" patterns.
|
|
50
|
+
*/
|
|
51
|
+
const requireOptional = (0, module_1.createRequire)(__filename);
|
|
52
|
+
/**
|
|
53
|
+
* Build a `TokenEstimator` backed by the optional `tiktoken` package.
|
|
54
|
+
*
|
|
55
|
+
* Throws synchronously when `tiktoken` is not installed (or fails to load),
|
|
56
|
+
* with a message that includes the install command. This is intentional —
|
|
57
|
+
* a confusingly-silent fallback would let users believe they were getting
|
|
58
|
+
* real-tokenizer numbers when they weren't.
|
|
59
|
+
*
|
|
60
|
+
* Once constructed, the estimator itself does **not** throw: if an
|
|
61
|
+
* individual `encode()` call fails on hostile input, the adapter
|
|
62
|
+
* gracefully returns the `charBasedTokenEstimator` result for that call
|
|
63
|
+
* so a single bad string can't break health assessment.
|
|
64
|
+
*/
|
|
65
|
+
function createTiktokenEstimator(encoding = 'cl100k_base') {
|
|
66
|
+
// We resolve `tiktoken` lazily via `createRequire` so users who do not
|
|
67
|
+
// need it pay zero install cost and never see a "Cannot find module"
|
|
68
|
+
// error in production. The require call is opaque to bundlers and
|
|
69
|
+
// does not use `eval`, which keeps the package clean for CSP-restricted
|
|
70
|
+
// hosts and static-analysis security scanners.
|
|
71
|
+
let tiktoken;
|
|
72
|
+
try {
|
|
73
|
+
tiktoken = requireOptional('tiktoken');
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
77
|
+
throw new Error(`createTiktokenEstimator: optional dependency 'tiktoken' is not installed. ` +
|
|
78
|
+
`Install it in your host project (\`npm install tiktoken\`), then call ` +
|
|
79
|
+
`createTiktokenEstimator(${JSON.stringify(encoding)}). ` +
|
|
80
|
+
`Underlying loader error: ${msg}`);
|
|
81
|
+
}
|
|
82
|
+
let enc;
|
|
83
|
+
try {
|
|
84
|
+
enc = tiktoken.get_encoding(encoding);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
88
|
+
throw new Error(`createTiktokenEstimator: tiktoken does not recognise encoding ${JSON.stringify(encoding)}. ` +
|
|
89
|
+
`Loader error: ${msg}`);
|
|
90
|
+
}
|
|
91
|
+
let warned = false;
|
|
92
|
+
return {
|
|
93
|
+
name: `tiktoken/${encoding}`,
|
|
94
|
+
estimate(text) {
|
|
95
|
+
if (typeof text !== 'string' || text.length === 0)
|
|
96
|
+
return 0;
|
|
97
|
+
try {
|
|
98
|
+
return enc.encode(text).length;
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
// Graceful degradation per the TokenEstimator contract: never throw.
|
|
102
|
+
// Surface the failure to stderr once, then mirror char/4 behaviour.
|
|
103
|
+
if (!warned) {
|
|
104
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
105
|
+
process.stderr.write(`tiktoken/${encoding}.encode() failed once (${msg}); falling back to char/4 for affected calls.\n`);
|
|
106
|
+
warned = true;
|
|
107
|
+
}
|
|
108
|
+
return index_1.charBasedTokenEstimator.estimate(text);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=tiktoken-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiktoken-adapter.js","sourceRoot":"","sources":["../../src/agni/tiktoken-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;;AAoCH,0DAmDC;AArFD,mCAAuC;AAEvC,mCAAkD;AAElD;;;;;;;GAOG;AACH,MAAM,eAAe,GAAG,IAAA,sBAAa,EAAC,UAAU,CAAC,CAAC;AASlD;;;;;;;;;;;;GAYG;AACH,SAAgB,uBAAuB,CAAC,WAA6B,aAAa;IAChF,uEAAuE;IACvE,qEAAqE;IACrE,kEAAkE;IAClE,wEAAwE;IACxE,+CAA+C;IAC/C,IAAI,QAAsF,CAAC;IAC3F,IAAI,CAAC;QACH,QAAQ,GAAG,eAAe,CAAC,UAAU,CAAoB,CAAC;IAC5D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,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AAiD,CACnG,CAAC;oBACF,MAAM,GAAG,IAAI,CAAC;gBAChB,CAAC;gBACD,OAAO,+BAAuB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ojas Chikitsa (ओजस चिकित्सा) — AI Repair & Rehabilitation System
|
|
3
|
+
*
|
|
4
|
+
* Diagnoses failures and creates structured repair protocols.
|
|
5
|
+
*/
|
|
6
|
+
import { HandoffSnapshot, HealthRecommendation, RehabilitationHealth, RehabilitationPolicy, RepairExecutionRecord, RepairExecutor, RepairProtocol, RepairVerifier, RuntimeFailure, TaskOutcomeRecord, VelocityStats } from '../types';
|
|
7
|
+
import type { ChikitsaStateSnapshot } from '../persistence/types';
|
|
8
|
+
export declare class Chikitsa {
|
|
9
|
+
private policy;
|
|
10
|
+
private protocols;
|
|
11
|
+
/**
|
|
12
|
+
* Rolling window of trailing task outcomes. Used by
|
|
13
|
+
* `getVelocityStats()` to compute success rate + duration percentiles
|
|
14
|
+
* + tasks/hour. Bounded by `policy.velocityWindowSize` so memory
|
|
15
|
+
* usage is stable across long-running agents.
|
|
16
|
+
*/
|
|
17
|
+
private taskOutcomes;
|
|
18
|
+
/**
|
|
19
|
+
* Set of protocol ids that `executeProtocol()` has already applied
|
|
20
|
+
* via a `RepairExecutor`. A second call with the same protocol id
|
|
21
|
+
* short-circuits to `status: 'already-applied'` regardless of the
|
|
22
|
+
* executor's idempotency — Chikitsa is the source of truth for
|
|
23
|
+
* "this protocol has been run".
|
|
24
|
+
*/
|
|
25
|
+
private appliedProtocolIds;
|
|
26
|
+
/** Audit log of every executeProtocol() invocation. Capped by `maxProtocols`. */
|
|
27
|
+
private executions;
|
|
28
|
+
constructor(policy?: Partial<RehabilitationPolicy>);
|
|
29
|
+
private validatePolicy;
|
|
30
|
+
/** Drop the oldest protocols when retention cap is exceeded. */
|
|
31
|
+
private enforceProtocolLimit;
|
|
32
|
+
/**
|
|
33
|
+
* Append a task outcome to the rolling velocity window. Rejects
|
|
34
|
+
* malformed entries (non-finite `durationMs`, unparseable
|
|
35
|
+
* `completedAt`) at the boundary so a buggy caller can't poison
|
|
36
|
+
* percentile math. Older entries past `velocityWindowSize` are
|
|
37
|
+
* evicted from the front.
|
|
38
|
+
*/
|
|
39
|
+
recordTaskOutcome(record: TaskOutcomeRecord): void;
|
|
40
|
+
/**
|
|
41
|
+
* Windowed velocity summary over the trailing `velocityWindowSize`
|
|
42
|
+
* outcomes (default 50). Returns a zero-valued struct for an empty
|
|
43
|
+
* window so callers don't need to null-check before rendering.
|
|
44
|
+
*/
|
|
45
|
+
getVelocityStats(): VelocityStats;
|
|
46
|
+
/** Read-only view of the current outcome window. Useful for tests + dashboards. */
|
|
47
|
+
getRecentOutcomes(): ReadonlyArray<TaskOutcomeRecord>;
|
|
48
|
+
/** Clear the velocity window. Useful for tests + cross-session boundaries. */
|
|
49
|
+
resetVelocityWindow(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Serialise a structured `HandoffSnapshot` into a Markdown document
|
|
52
|
+
* the next agent (or the same agent in a fresh session) can read at
|
|
53
|
+
* boot. The file becomes the single source of truth for "what was
|
|
54
|
+
* I doing and where am I in it" across sessions.
|
|
55
|
+
*
|
|
56
|
+
* Markdown is intentionally human-first; structured callers should
|
|
57
|
+
* pass the snapshot object around directly and only call this when
|
|
58
|
+
* they want a persistable artefact.
|
|
59
|
+
*/
|
|
60
|
+
generateHandoff(snapshot: HandoffSnapshot): string;
|
|
61
|
+
/**
|
|
62
|
+
* Run a `RepairProtocol` through a pluggable `RepairExecutor` and,
|
|
63
|
+
* optionally, a `RepairVerifier`. Closes the
|
|
64
|
+
* detect → diagnose → repair → **verify** loop so the agent has
|
|
65
|
+
* evidence the repair actually fixed the failure.
|
|
66
|
+
*
|
|
67
|
+
* Idempotency: Chikitsa is the source of truth for "has this
|
|
68
|
+
* protocol already run". A second call with the same `protocol.id`
|
|
69
|
+
* short-circuits to `status: 'already-applied'` without invoking
|
|
70
|
+
* the executor.
|
|
71
|
+
*
|
|
72
|
+
* Failure handling:
|
|
73
|
+
* - Executor throws → `status: 'failed'`, `error` set
|
|
74
|
+
* - Executor returns `failed` → `status: 'failed'`
|
|
75
|
+
* - No verifier configured → `status: 'applied'`
|
|
76
|
+
* - Verifier returns `false` → `status: 'unverified'`, then
|
|
77
|
+
* if `executor.rollback` is defined the rollback runs and
|
|
78
|
+
* status promotes to `'rolled-back'` (rollback errors are
|
|
79
|
+
* swallowed; the status is still `'rolled-back'` so the
|
|
80
|
+
* audit log captures the attempt).
|
|
81
|
+
* - Verifier returns `true` → `status: 'verified'`
|
|
82
|
+
*
|
|
83
|
+
* Pulse events emitted via the passed-in pulse, when provided, are
|
|
84
|
+
* the caller's job to wire — Chikitsa returns the record and lets
|
|
85
|
+
* Ojas's outer loop translate that to events.
|
|
86
|
+
*/
|
|
87
|
+
executeProtocol(protocol: RepairProtocol, executor: RepairExecutor, verifier?: RepairVerifier): Promise<RepairExecutionRecord>;
|
|
88
|
+
/** Read-only audit log of every `executeProtocol()` call. */
|
|
89
|
+
executionHistory(): ReadonlyArray<RepairExecutionRecord>;
|
|
90
|
+
/** Whether a protocol id has been successfully applied (and not rolled back). */
|
|
91
|
+
hasProtocolBeenApplied(protocolId: string): boolean;
|
|
92
|
+
/** Clear all execution / applied state. Useful for tests + cross-session boundaries. */
|
|
93
|
+
resetExecutionHistory(): void;
|
|
94
|
+
private recordExecution;
|
|
95
|
+
/**
|
|
96
|
+
* Build a repair protocol for a single failure. Encapsulates ALL the
|
|
97
|
+
* policy logic (severity mapping, criticalRequiresHuman) so preview and
|
|
98
|
+
* commit produce identical results for the same input.
|
|
99
|
+
*
|
|
100
|
+
* `idMode` controls the protocol id: `'random'` produces a unique id
|
|
101
|
+
* suitable for committed protocols (each diagnose() call mints a new
|
|
102
|
+
* one); `'deterministic'` produces a stable hash of the failure so
|
|
103
|
+
* preview output can be diffed and deduped across calls.
|
|
104
|
+
*/
|
|
105
|
+
private buildProtocol;
|
|
106
|
+
/**
|
|
107
|
+
* Pure: compute repair protocols for the given failures without appending
|
|
108
|
+
* them to internal state. Output is byte-identical to what `diagnose()`
|
|
109
|
+
* would produce *except* for the id, which is deterministic here so
|
|
110
|
+
* callers can diff or dedupe preview output across repeated calls.
|
|
111
|
+
*/
|
|
112
|
+
previewDiagnose(failures: RuntimeFailure[]): RepairProtocol[];
|
|
113
|
+
/**
|
|
114
|
+
* Compute repair protocols and record them in internal state. Honors
|
|
115
|
+
* `policy.criticalRequiresHuman` via the same shared path as preview,
|
|
116
|
+
* but uses random ids so each diagnose() commit can be tracked
|
|
117
|
+
* independently in history.
|
|
118
|
+
*/
|
|
119
|
+
diagnose(failures: RuntimeFailure[]): RepairProtocol[];
|
|
120
|
+
private diagnosisFor;
|
|
121
|
+
private actionsFor;
|
|
122
|
+
assess(): RehabilitationHealth;
|
|
123
|
+
recommend(): HealthRecommendation[];
|
|
124
|
+
getProtocols(): readonly Readonly<RepairProtocol>[];
|
|
125
|
+
exportState(): ChikitsaStateSnapshot;
|
|
126
|
+
importState(snapshot: Partial<ChikitsaStateSnapshot> | undefined): void;
|
|
127
|
+
getPolicy(): RehabilitationPolicy;
|
|
128
|
+
updatePolicy(updates: Partial<RehabilitationPolicy>): void;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chikitsa/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,eAAe,EACf,oBAAoB,EAEpB,oBAAoB,EACpB,oBAAoB,EAEpB,qBAAqB,EAErB,cAAc,EACd,cAAc,EAEd,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,aAAa,EACd,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBA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