@nekzus/liop 2.2.0 → 2.3.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 +201 -21
- package/NOTICE +5 -0
- package/README.md +61 -5
- package/dist/bin/agent.js +7 -5
- package/dist/bin/agent.js.map +1 -1
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +2 -1
- package/dist/{chunk-UVO7DII3.js → chunk-4LQPDN3W.js} +108 -15
- package/dist/chunk-4LQPDN3W.js.map +1 -0
- package/dist/{chunk-NJRSFFD7.js → chunk-74CISO2I.js} +60 -22
- package/dist/chunk-74CISO2I.js.map +1 -0
- package/dist/{chunk-E5QBDD5E.js → chunk-CRZBVFDV.js} +169 -22
- package/dist/chunk-CRZBVFDV.js.map +1 -0
- package/dist/chunk-GKV6M2PQ.js +208106 -0
- package/dist/chunk-GKV6M2PQ.js.map +1 -0
- package/dist/chunk-JIJPZFR2.js +51 -0
- package/dist/chunk-JIJPZFR2.js.map +1 -0
- package/dist/chunk-OIMJZ64E.js +441 -0
- package/dist/chunk-OIMJZ64E.js.map +1 -0
- package/dist/chunk-PYKRQAER.js +77 -0
- package/dist/chunk-PYKRQAER.js.map +1 -0
- package/dist/{chunk-J3WPBMJ5.js → chunk-SONUORBT.js} +95 -6
- package/dist/chunk-SONUORBT.js.map +1 -0
- package/dist/{chunk-2JLG4DET.js → chunk-UBOQZVV5.js} +261 -107
- package/dist/chunk-UBOQZVV5.js.map +1 -0
- package/dist/chunk-UCJEK75U.js +714 -0
- package/dist/chunk-UCJEK75U.js.map +1 -0
- package/dist/chunk-WSW6YJNY.js +168 -0
- package/dist/chunk-WSW6YJNY.js.map +1 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.js +4 -3
- package/dist/gateway.d.ts +5 -110
- package/dist/gateway.js +5 -4
- package/dist/hybrid-CF__0YnC.d.ts +170 -0
- package/dist/{index-BlGc0iym.d.ts → index-BW95kAL4.d.ts} +63 -2
- package/dist/index-cMV0_yD9.d.ts +200 -0
- package/dist/index.d.ts +273 -18
- package/dist/index.js +266 -13
- package/dist/index.js.map +1 -1
- package/dist/mesh.d.ts +14 -0
- package/dist/mesh.js +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +5 -4
- package/dist/{types-sKeUxuky.d.ts → types-lJIxBlWF.d.ts} +71 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/workers/logic-execution.d.ts +1 -0
- package/dist/workers/logic-execution.js +17 -1
- package/dist/workers/logic-execution.js.map +1 -1
- package/package.json +53 -33
- package/dist/chunk-2JLG4DET.js.map +0 -1
- package/dist/chunk-CT6NHSYP.js +0 -30
- package/dist/chunk-CT6NHSYP.js.map +0 -1
- package/dist/chunk-E5QBDD5E.js.map +0 -1
- package/dist/chunk-HB5DXX3Q.js +0 -1976
- package/dist/chunk-HB5DXX3Q.js.map +0 -1
- package/dist/chunk-IJHTRIZC.js +0 -56
- package/dist/chunk-IJHTRIZC.js.map +0 -1
- package/dist/chunk-J3WPBMJ5.js.map +0 -1
- package/dist/chunk-NJRSFFD7.js.map +0 -1
- package/dist/chunk-PHTWUTY7.js +0 -300
- package/dist/chunk-PHTWUTY7.js.map +0 -1
- package/dist/chunk-RDWCGZ2A.js +0 -87
- package/dist/chunk-RDWCGZ2A.js.map +0 -1
- package/dist/chunk-UVO7DII3.js.map +0 -1
- package/dist/index-qM8ZH8sC.d.ts +0 -101
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/server/output-sanitizer.ts
|
|
2
|
+
var DEFAULT_CONFIG = {
|
|
3
|
+
maxDecimalPlaces: 4,
|
|
4
|
+
clampNonNegative: true
|
|
5
|
+
};
|
|
6
|
+
function sanitizeOutput(output, config) {
|
|
7
|
+
const merged = { ...DEFAULT_CONFIG, ...config };
|
|
8
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
9
|
+
function walk(node) {
|
|
10
|
+
if (node === null || node === void 0) {
|
|
11
|
+
return node;
|
|
12
|
+
}
|
|
13
|
+
if (typeof node === "number") {
|
|
14
|
+
if (!Number.isFinite(node)) {
|
|
15
|
+
return node;
|
|
16
|
+
}
|
|
17
|
+
let value = node;
|
|
18
|
+
if (merged.clampNonNegative && value < 0) {
|
|
19
|
+
value = 0;
|
|
20
|
+
}
|
|
21
|
+
const factor = 10 ** merged.maxDecimalPlaces;
|
|
22
|
+
value = Math.round(value * factor) / factor;
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
if (typeof node === "string" || typeof node === "boolean") {
|
|
26
|
+
return node;
|
|
27
|
+
}
|
|
28
|
+
if (typeof node === "object") {
|
|
29
|
+
if (seen.has(node)) {
|
|
30
|
+
return node;
|
|
31
|
+
}
|
|
32
|
+
seen.add(node);
|
|
33
|
+
if (Array.isArray(node)) {
|
|
34
|
+
return node.map((item) => walk(item));
|
|
35
|
+
}
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const [key, val] of Object.entries(
|
|
38
|
+
node
|
|
39
|
+
)) {
|
|
40
|
+
result[key] = walk(val);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
return walk(output);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { sanitizeOutput };
|
|
50
|
+
//# sourceMappingURL=chunk-JIJPZFR2.js.map
|
|
51
|
+
//# sourceMappingURL=chunk-JIJPZFR2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/output-sanitizer.ts"],"names":[],"mappings":";AAeA,IAAM,cAAA,GAAkD;AAAA,EACvD,gBAAA,EAAkB,CAAA;AAAA,EAClB,gBAAA,EAAkB;AACnB,CAAA;AASO,SAAS,cAAA,CACf,QACA,MAAA,EACU;AACV,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,cAAA,EAAgB,GAAG,MAAA,EAAO;AAC9C,EAAA,MAAM,IAAA,uBAAW,OAAA,EAAgB;AA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A,GAAI,IAAA,CAAK,GAAG,CAAA;AAAA,MACvB;AACA,MAAA,OAAO,MAAA;AAAA,IACR;AAEA,IAAA,OAAO,IAAA;AAAA,EACR;AAEA,EAAA,OAAO,KAAK,MAAM,CAAA;AACnB","file":"chunk-JIJPZFR2.js","sourcesContent":["/**\n * LIOP Egress Shield Output Sanitizer (NIST SP 800-226 and OWASP DLP 2025 compliant)\n * Recursively sanitizes execution outputs by rounding floating-point numbers\n * and clamping negative values to zero floor where appropriate.\n *\n * Implements absolute immutability, returning a fresh copy of the data.\n */\n\nexport interface OutputSanitizerConfig {\n\t/** Maximum decimal places for floating-point values (default: 4) */\n\tmaxDecimalPlaces?: number;\n\t/** Clamp negative values to zero floor (default: true) */\n\tclampNonNegative?: boolean;\n}\n\nconst DEFAULT_CONFIG: Required<OutputSanitizerConfig> = {\n\tmaxDecimalPlaces: 4,\n\tclampNonNegative: true,\n};\n\n/**\n * Recursively walks a JSON-like tree, rounding floats and clamping negative values.\n *\n * @param output - The raw or DP-modified output object/value to sanitize\n * @param config - Sanitization parameters (rounding depth, negative clamping)\n * @returns A sanitized deep copy of the output\n */\nexport function sanitizeOutput(\n\toutput: unknown,\n\tconfig?: OutputSanitizerConfig,\n): unknown {\n\tconst merged = { ...DEFAULT_CONFIG, ...config };\n\tconst seen = new WeakSet<object>();\n\n\tfunction walk(node: unknown): unknown {\n\t\tif (node === null || node === undefined) {\n\t\t\treturn node;\n\t\t}\n\n\t\tif (typeof node === \"number\") {\n\t\t\tif (!Number.isFinite(node)) {\n\t\t\t\treturn node;\n\t\t\t}\n\n\t\t\tlet value = node;\n\n\t\t\t// 1. Clamp negative values to 0 if configured\n\t\t\tif (merged.clampNonNegative && value < 0) {\n\t\t\t\tvalue = 0;\n\t\t\t}\n\n\t\t\t// 2. Round to maximum decimal places\n\t\t\tconst factor = 10 ** merged.maxDecimalPlaces;\n\t\t\tvalue = Math.round(value * factor) / factor;\n\n\t\t\treturn value;\n\t\t}\n\n\t\tif (typeof node === \"string\" || typeof node === \"boolean\") {\n\t\t\treturn node;\n\t\t}\n\n\t\tif (typeof node === \"object\") {\n\t\t\t// Circular reference protection\n\t\t\tif (seen.has(node as object)) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t\tseen.add(node as object);\n\n\t\t\tif (Array.isArray(node)) {\n\t\t\t\treturn node.map((item) => walk(item));\n\t\t\t}\n\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, val] of Object.entries(\n\t\t\t\tnode as Record<string, unknown>,\n\t\t\t)) {\n\t\t\t\tresult[key] = walk(val);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\treturn node;\n\t}\n\n\treturn walk(output);\n}\n"]}
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';
|
|
2
|
+
|
|
3
|
+
// src/observability/metrics.ts
|
|
4
|
+
function formatLabels(labels) {
|
|
5
|
+
if (!labels || Object.keys(labels).length === 0) {
|
|
6
|
+
return "";
|
|
7
|
+
}
|
|
8
|
+
const entries = Object.entries(labels).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}="${String(v).replace(/"/g, '\\"')}"`);
|
|
9
|
+
return `{${entries.join(",")}}`;
|
|
10
|
+
}
|
|
11
|
+
function labelsToKey(labels) {
|
|
12
|
+
if (!labels) return "";
|
|
13
|
+
return Object.entries(labels).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${k}:${v}`).join("|");
|
|
14
|
+
}
|
|
15
|
+
var Counter = class {
|
|
16
|
+
constructor(name, help) {
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.help = help;
|
|
19
|
+
}
|
|
20
|
+
values = /* @__PURE__ */ new Map();
|
|
21
|
+
inc(labels, value = 1) {
|
|
22
|
+
if (value < 0) {
|
|
23
|
+
throw new Error("Counter increments must be non-negative");
|
|
24
|
+
}
|
|
25
|
+
const key = labelsToKey(labels);
|
|
26
|
+
const current = this.values.get(key) || { value: 0, labels };
|
|
27
|
+
current.value += value;
|
|
28
|
+
this.values.set(key, current);
|
|
29
|
+
}
|
|
30
|
+
get(labels) {
|
|
31
|
+
const key = labelsToKey(labels);
|
|
32
|
+
return this.values.get(key)?.value || 0;
|
|
33
|
+
}
|
|
34
|
+
reset() {
|
|
35
|
+
this.values.clear();
|
|
36
|
+
}
|
|
37
|
+
toPrometheus() {
|
|
38
|
+
const lines = [
|
|
39
|
+
`# HELP ${this.name} ${this.help}`,
|
|
40
|
+
`# TYPE ${this.name} counter`
|
|
41
|
+
];
|
|
42
|
+
if (this.values.size === 0) {
|
|
43
|
+
lines.push(`${this.name} 0`);
|
|
44
|
+
return lines;
|
|
45
|
+
}
|
|
46
|
+
for (const entry of this.values.values()) {
|
|
47
|
+
lines.push(`${this.name}${formatLabels(entry.labels)} ${entry.value}`);
|
|
48
|
+
}
|
|
49
|
+
return lines;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var Gauge = class {
|
|
53
|
+
constructor(name, help) {
|
|
54
|
+
this.name = name;
|
|
55
|
+
this.help = help;
|
|
56
|
+
}
|
|
57
|
+
values = /* @__PURE__ */ new Map();
|
|
58
|
+
set(labelsOrValue, maybeValue) {
|
|
59
|
+
if (typeof labelsOrValue === "number") {
|
|
60
|
+
this.values.set("", { value: labelsOrValue });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const labels = labelsOrValue;
|
|
64
|
+
const val = typeof maybeValue === "number" ? maybeValue : 0;
|
|
65
|
+
const key = labelsToKey(labels);
|
|
66
|
+
this.values.set(key, { value: val, labels });
|
|
67
|
+
}
|
|
68
|
+
inc(labels, value = 1) {
|
|
69
|
+
const key = labelsToKey(labels);
|
|
70
|
+
const current = this.values.get(key) || { value: 0, labels };
|
|
71
|
+
current.value += value;
|
|
72
|
+
this.values.set(key, current);
|
|
73
|
+
}
|
|
74
|
+
dec(labels, value = 1) {
|
|
75
|
+
const key = labelsToKey(labels);
|
|
76
|
+
const current = this.values.get(key) || { value: 0, labels };
|
|
77
|
+
current.value -= value;
|
|
78
|
+
this.values.set(key, current);
|
|
79
|
+
}
|
|
80
|
+
get(labels) {
|
|
81
|
+
const key = labelsToKey(labels);
|
|
82
|
+
return this.values.get(key)?.value || 0;
|
|
83
|
+
}
|
|
84
|
+
reset() {
|
|
85
|
+
this.values.clear();
|
|
86
|
+
}
|
|
87
|
+
toPrometheus() {
|
|
88
|
+
const lines = [
|
|
89
|
+
`# HELP ${this.name} ${this.help}`,
|
|
90
|
+
`# TYPE ${this.name} gauge`
|
|
91
|
+
];
|
|
92
|
+
if (this.values.size === 0) {
|
|
93
|
+
lines.push(`${this.name} 0`);
|
|
94
|
+
return lines;
|
|
95
|
+
}
|
|
96
|
+
for (const entry of this.values.values()) {
|
|
97
|
+
lines.push(`${this.name}${formatLabels(entry.labels)} ${entry.value}`);
|
|
98
|
+
}
|
|
99
|
+
return lines;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var Histogram = class {
|
|
103
|
+
constructor(name, help, buckets = [5, 10, 25, 50, 100, 250, 500, 1e3, 2500, 5e3, 1e4]) {
|
|
104
|
+
this.name = name;
|
|
105
|
+
this.help = help;
|
|
106
|
+
this.buckets = [...buckets].sort((a, b) => a - b);
|
|
107
|
+
}
|
|
108
|
+
buckets;
|
|
109
|
+
observations = /* @__PURE__ */ new Map();
|
|
110
|
+
observe(labelsOrValue, maybeValue) {
|
|
111
|
+
let labels;
|
|
112
|
+
let val;
|
|
113
|
+
if (typeof labelsOrValue === "number") {
|
|
114
|
+
val = labelsOrValue;
|
|
115
|
+
} else {
|
|
116
|
+
labels = labelsOrValue;
|
|
117
|
+
val = typeof maybeValue === "number" ? maybeValue : 0;
|
|
118
|
+
}
|
|
119
|
+
const key = labelsToKey(labels);
|
|
120
|
+
let state = this.observations.get(key);
|
|
121
|
+
if (!state) {
|
|
122
|
+
state = {
|
|
123
|
+
count: 0,
|
|
124
|
+
sum: 0,
|
|
125
|
+
bucketCounts: new Map(this.buckets.map((b) => [b, 0])),
|
|
126
|
+
labels
|
|
127
|
+
};
|
|
128
|
+
this.observations.set(key, state);
|
|
129
|
+
}
|
|
130
|
+
state.count += 1;
|
|
131
|
+
state.sum += val;
|
|
132
|
+
for (const bound of this.buckets) {
|
|
133
|
+
if (val <= bound) {
|
|
134
|
+
const cur = state.bucketCounts.get(bound) || 0;
|
|
135
|
+
state.bucketCounts.set(bound, cur + 1);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
reset() {
|
|
140
|
+
this.observations.clear();
|
|
141
|
+
}
|
|
142
|
+
toPrometheus() {
|
|
143
|
+
const lines = [
|
|
144
|
+
`# HELP ${this.name} ${this.help}`,
|
|
145
|
+
`# TYPE ${this.name} histogram`
|
|
146
|
+
];
|
|
147
|
+
if (this.observations.size === 0) {
|
|
148
|
+
lines.push(`${this.name}_count 0`);
|
|
149
|
+
lines.push(`${this.name}_sum 0`);
|
|
150
|
+
return lines;
|
|
151
|
+
}
|
|
152
|
+
for (const state of this.observations.values()) {
|
|
153
|
+
const baseLabels = state.labels || {};
|
|
154
|
+
for (const bound of this.buckets) {
|
|
155
|
+
const bucketLabels = { ...baseLabels, le: String(bound) };
|
|
156
|
+
lines.push(
|
|
157
|
+
`${this.name}_bucket${formatLabels(bucketLabels)} ${state.bucketCounts.get(bound) || 0}`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
const infLabels = { ...baseLabels, le: "+Inf" };
|
|
161
|
+
lines.push(
|
|
162
|
+
`${this.name}_bucket${formatLabels(infLabels)} ${state.count}`
|
|
163
|
+
);
|
|
164
|
+
lines.push(`${this.name}_sum${formatLabels(baseLabels)} ${state.sum}`);
|
|
165
|
+
lines.push(
|
|
166
|
+
`${this.name}_count${formatLabels(baseLabels)} ${state.count}`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return lines;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var MetricsRegistry = class {
|
|
173
|
+
counters = /* @__PURE__ */ new Map();
|
|
174
|
+
gauges = /* @__PURE__ */ new Map();
|
|
175
|
+
histograms = /* @__PURE__ */ new Map();
|
|
176
|
+
counter(name, help) {
|
|
177
|
+
let c = this.counters.get(name);
|
|
178
|
+
if (!c) {
|
|
179
|
+
c = new Counter(name, help);
|
|
180
|
+
this.counters.set(name, c);
|
|
181
|
+
}
|
|
182
|
+
return c;
|
|
183
|
+
}
|
|
184
|
+
gauge(name, help) {
|
|
185
|
+
let g = this.gauges.get(name);
|
|
186
|
+
if (!g) {
|
|
187
|
+
g = new Gauge(name, help);
|
|
188
|
+
this.gauges.set(name, g);
|
|
189
|
+
}
|
|
190
|
+
return g;
|
|
191
|
+
}
|
|
192
|
+
histogram(name, help, buckets) {
|
|
193
|
+
let h = this.histograms.get(name);
|
|
194
|
+
if (!h) {
|
|
195
|
+
h = new Histogram(name, help, buckets);
|
|
196
|
+
this.histograms.set(name, h);
|
|
197
|
+
}
|
|
198
|
+
return h;
|
|
199
|
+
}
|
|
200
|
+
collectProcessMetrics() {
|
|
201
|
+
const uptime = this.gauge(
|
|
202
|
+
"liop_process_uptime_seconds",
|
|
203
|
+
"Process uptime in seconds"
|
|
204
|
+
);
|
|
205
|
+
uptime.set(Math.floor(process.uptime()));
|
|
206
|
+
if (typeof process.memoryUsage === "function") {
|
|
207
|
+
const mem = process.memoryUsage();
|
|
208
|
+
const rss = this.gauge(
|
|
209
|
+
"liop_process_memory_rss_bytes",
|
|
210
|
+
"Resident set size memory in bytes"
|
|
211
|
+
);
|
|
212
|
+
rss.set(mem.rss);
|
|
213
|
+
const heapUsed = this.gauge(
|
|
214
|
+
"liop_process_memory_heap_used_bytes",
|
|
215
|
+
"Heap memory used in bytes"
|
|
216
|
+
);
|
|
217
|
+
heapUsed.set(mem.heapUsed);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exportPrometheusText() {
|
|
221
|
+
this.collectProcessMetrics();
|
|
222
|
+
const lines = [];
|
|
223
|
+
for (const c of this.counters.values()) {
|
|
224
|
+
lines.push(...c.toPrometheus());
|
|
225
|
+
}
|
|
226
|
+
for (const g of this.gauges.values()) {
|
|
227
|
+
lines.push(...g.toPrometheus());
|
|
228
|
+
}
|
|
229
|
+
for (const h of this.histograms.values()) {
|
|
230
|
+
lines.push(...h.toPrometheus());
|
|
231
|
+
}
|
|
232
|
+
lines.push("");
|
|
233
|
+
return lines.join("\n");
|
|
234
|
+
}
|
|
235
|
+
resetAll() {
|
|
236
|
+
for (const c of this.counters.values()) c.reset();
|
|
237
|
+
for (const g of this.gauges.values()) g.reset();
|
|
238
|
+
for (const h of this.histograms.values()) h.reset();
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var protocolMetrics = new MetricsRegistry();
|
|
242
|
+
var toolCallsTotal = protocolMetrics.counter(
|
|
243
|
+
"liop_tool_calls_total",
|
|
244
|
+
"Total number of tool logic-injection executions"
|
|
245
|
+
);
|
|
246
|
+
var fuelConsumed = protocolMetrics.histogram(
|
|
247
|
+
"liop_fuel_consumed_total",
|
|
248
|
+
"Deterministic fuel units consumed by injected logic",
|
|
249
|
+
[100, 500, 1e3, 2500, 5e3, 1e4, 5e4, 1e5]
|
|
250
|
+
);
|
|
251
|
+
var meshPeersConnected = protocolMetrics.gauge(
|
|
252
|
+
"liop_mesh_peers_connected",
|
|
253
|
+
"Active peer connections in the P2P mesh"
|
|
254
|
+
);
|
|
255
|
+
var manifestCacheSize = protocolMetrics.gauge(
|
|
256
|
+
"liop_manifest_cache_size",
|
|
257
|
+
"Number of verified remote tool manifests in cache"
|
|
258
|
+
);
|
|
259
|
+
var egressBlocksTotal = protocolMetrics.counter(
|
|
260
|
+
"liop_egress_blocks_total",
|
|
261
|
+
"Total number of outputs blocked by Egress Shield"
|
|
262
|
+
);
|
|
263
|
+
var zkVerificationDurationMs = protocolMetrics.histogram(
|
|
264
|
+
"liop_zk_verification_duration_ms",
|
|
265
|
+
"Duration of ZK-Receipt and HMAC cryptographic attestation in ms",
|
|
266
|
+
[1, 2, 5, 10, 25, 50, 100]
|
|
267
|
+
);
|
|
268
|
+
var DILITHIUM65_CONSTANTS = {
|
|
269
|
+
PUBLIC_KEY_BYTES: 1952,
|
|
270
|
+
SECRET_KEY_BYTES: 4032,
|
|
271
|
+
SIGNATURE_BYTES: 3309,
|
|
272
|
+
DEFAULT_CONTEXT: new TextEncoder().encode("LIOP-FIPS204-ML-DSA-65")
|
|
273
|
+
};
|
|
274
|
+
function normalizeMessage(message) {
|
|
275
|
+
if (typeof message === "string") {
|
|
276
|
+
return new TextEncoder().encode(message);
|
|
277
|
+
}
|
|
278
|
+
return message;
|
|
279
|
+
}
|
|
280
|
+
function canonicalizeJson(obj) {
|
|
281
|
+
if (obj === null || typeof obj !== "object") {
|
|
282
|
+
return JSON.stringify(obj);
|
|
283
|
+
}
|
|
284
|
+
if (Array.isArray(obj)) {
|
|
285
|
+
return `[${obj.map(canonicalizeJson).join(",")}]`;
|
|
286
|
+
}
|
|
287
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
288
|
+
const entries = sortedKeys.map(
|
|
289
|
+
(key) => `${JSON.stringify(key)}:${canonicalizeJson(obj[key])}`
|
|
290
|
+
);
|
|
291
|
+
return `{${entries.join(",")}}`;
|
|
292
|
+
}
|
|
293
|
+
var Dilithium65Wrapper = {
|
|
294
|
+
/** Constants */
|
|
295
|
+
PUBLIC_KEY_BYTES: DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES,
|
|
296
|
+
SECRET_KEY_BYTES: DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES,
|
|
297
|
+
SIGNATURE_BYTES: DILITHIUM65_CONSTANTS.SIGNATURE_BYTES,
|
|
298
|
+
/**
|
|
299
|
+
* Generates a new ML-DSA-65 (FIPS 204) key pair.
|
|
300
|
+
* Optionally accepts a 32-byte seed for deterministic key generation.
|
|
301
|
+
*/
|
|
302
|
+
generateKeyPair(seed) {
|
|
303
|
+
if (seed && seed.length !== 32) {
|
|
304
|
+
throw new Error(
|
|
305
|
+
`ML-DSA-65 seed must be exactly 32 bytes (Received: ${seed.length})`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
const keys = ml_dsa65.keygen(seed);
|
|
309
|
+
return {
|
|
310
|
+
publicKey: keys.publicKey,
|
|
311
|
+
secretKey: keys.secretKey
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
/**
|
|
315
|
+
* Validates and imports a raw ML-DSA-65 public key.
|
|
316
|
+
*/
|
|
317
|
+
importPublicKey(buffer) {
|
|
318
|
+
if (buffer.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {
|
|
319
|
+
throw new Error(
|
|
320
|
+
`ML-DSA-65 Public Key must be exactly ${DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES} bytes (Received: ${buffer.length})`
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
return buffer;
|
|
324
|
+
},
|
|
325
|
+
/**
|
|
326
|
+
* Signs a message using the post-quantum secret key.
|
|
327
|
+
* Supports optional domain separation context (up to 255 bytes).
|
|
328
|
+
*/
|
|
329
|
+
sign(message, secretKey, context) {
|
|
330
|
+
if (secretKey.length !== DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES) {
|
|
331
|
+
throw new Error(
|
|
332
|
+
`ML-DSA-65 Secret Key must be exactly ${DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES} bytes (Received: ${secretKey.length})`
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
const msgBytes = normalizeMessage(message);
|
|
336
|
+
const ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;
|
|
337
|
+
return ml_dsa65.sign(msgBytes, secretKey, { context: ctx });
|
|
338
|
+
},
|
|
339
|
+
/**
|
|
340
|
+
* Verifies an ML-DSA-65 post-quantum digital signature.
|
|
341
|
+
*/
|
|
342
|
+
verify(signature, message, publicKey, context) {
|
|
343
|
+
if (signature.length !== DILITHIUM65_CONSTANTS.SIGNATURE_BYTES) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
if (publicKey.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
const msgBytes = normalizeMessage(message);
|
|
351
|
+
const ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;
|
|
352
|
+
return ml_dsa65.verify(signature, msgBytes, publicKey, { context: ctx });
|
|
353
|
+
} catch {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
/**
|
|
358
|
+
* Signs a structured manifest (LiopManifest) using canonical JSON serialization.
|
|
359
|
+
* Returns base64-encoded signature and public key for transport over gRPC/MCP.
|
|
360
|
+
*/
|
|
361
|
+
signManifest(manifest, secretKey, publicKey) {
|
|
362
|
+
const { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;
|
|
363
|
+
const canonicalStr = canonicalizeJson(unsigned);
|
|
364
|
+
const sig = this.sign(canonicalStr, secretKey);
|
|
365
|
+
return {
|
|
366
|
+
signature: Buffer.from(sig).toString("base64"),
|
|
367
|
+
publicKey: Buffer.from(publicKey).toString("base64")
|
|
368
|
+
};
|
|
369
|
+
},
|
|
370
|
+
/**
|
|
371
|
+
* Verifies the post-quantum signature of a structured manifest.
|
|
372
|
+
*/
|
|
373
|
+
verifyManifest(manifest, signatureBase64, publicKeyBase64) {
|
|
374
|
+
try {
|
|
375
|
+
const sig = Buffer.from(signatureBase64, "base64");
|
|
376
|
+
const pub = Buffer.from(publicKeyBase64, "base64");
|
|
377
|
+
const { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;
|
|
378
|
+
const canonicalStr = canonicalizeJson(unsigned);
|
|
379
|
+
return this.verify(sig, canonicalStr, pub);
|
|
380
|
+
} catch {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/security/rbac.ts
|
|
387
|
+
var SCOPE_MAP = {
|
|
388
|
+
// Protocol lifecycle — unauthenticated (MCP spec compliance)
|
|
389
|
+
initialize: [],
|
|
390
|
+
"notifications/initialized": [],
|
|
391
|
+
"notifications/cancelled": [],
|
|
392
|
+
ping: [],
|
|
393
|
+
// Tool operations — require explicit authorization
|
|
394
|
+
"tools/list": ["liop:tools:list"],
|
|
395
|
+
"tools/call": ["liop:tools:call"],
|
|
396
|
+
// Resource operations — read-level access
|
|
397
|
+
"resources/list": ["liop:resources:read"],
|
|
398
|
+
"resources/read": ["liop:resources:read"],
|
|
399
|
+
// Prompt/schema operations — schema-level access
|
|
400
|
+
"prompts/list": ["liop:schema:read"],
|
|
401
|
+
"prompts/get": ["liop:schema:read"]
|
|
402
|
+
};
|
|
403
|
+
function authorizeRequest(method, auth, additionalScopes) {
|
|
404
|
+
const methodScopes = SCOPE_MAP[method];
|
|
405
|
+
if (methodScopes !== void 0 && methodScopes.length === 0) {
|
|
406
|
+
return { allowed: true };
|
|
407
|
+
}
|
|
408
|
+
if (!auth) {
|
|
409
|
+
return {
|
|
410
|
+
allowed: false,
|
|
411
|
+
reason: `Authentication required for method: ${method}`
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
const needed = [...methodScopes ?? [], ...additionalScopes ?? []];
|
|
415
|
+
if (needed.length === 0) {
|
|
416
|
+
return {
|
|
417
|
+
allowed: false,
|
|
418
|
+
reason: `Unknown method: ${method}. Access denied (fail-closed).`
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
const clientScopes = new Set(auth.scopes);
|
|
422
|
+
const missing = needed.filter((s) => !clientScopes.has(s));
|
|
423
|
+
if (missing.length > 0) {
|
|
424
|
+
return {
|
|
425
|
+
allowed: false,
|
|
426
|
+
reason: `Insufficient scopes for ${method}. Missing: ${missing.join(", ")}`
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
return { allowed: true };
|
|
430
|
+
}
|
|
431
|
+
var LIOP_SCOPES = [
|
|
432
|
+
"liop:tools:list",
|
|
433
|
+
"liop:tools:call",
|
|
434
|
+
"liop:resources:read",
|
|
435
|
+
"liop:schema:read",
|
|
436
|
+
"liop:mesh:query"
|
|
437
|
+
];
|
|
438
|
+
|
|
439
|
+
export { Counter, DILITHIUM65_CONSTANTS, Dilithium65Wrapper, Gauge, Histogram, LIOP_SCOPES, MetricsRegistry, authorizeRequest, egressBlocksTotal, fuelConsumed, manifestCacheSize, meshPeersConnected, protocolMetrics, toolCallsTotal, zkVerificationDurationMs };
|
|
440
|
+
//# sourceMappingURL=chunk-OIMJZ64E.js.map
|
|
441
|
+
//# sourceMappingURL=chunk-OIMJZ64E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/observability/metrics.ts","../src/rpc/crypto/dilithium.ts","../src/security/rbac.ts"],"names":[],"mappings":";;;AAeA,SAAS,aAAa,MAAA,EAA+B;AACpD,EAAA,IAAI,CAAC,MAAA,IAAU,MAAA,CAAO,KAAK,MAAM,CAAA,CAAE,WAAW,CAAA,EAAG;AAChD,IAAA,OAAO,EAAA;AAAA,EACR;AACA,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,MAAM,EACnC,IAAA,CAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA,KAAM,CAAA,CAAE,cAAc,CAAC,CAAC,CAAA,CACrC,GAAA,CAAI,CAAC,CAAC,CAAA,EAAG,CAAC,MAAM,CAAA,EAAG,CAAC,CAAA,EAAA,EAAK,MAAA,CAAO,CAAC,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,KAAK,CAAC,CAAA,CAAA,CAAG,CAAA;AAC5D,EAAA,OAAO,CAAA,CAAA,EAAI,OAAA,CAAQ,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAA;AAC7B;AAEA,SAAS,YAAY,MAAA,EAA+B;AACnD,EAAA,IAAI,CAAC,QAAQ,OAAO,EAAA;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ACT,MAAA,EAAQ,uCAAuC,MAAM,CAAA;AAAA,KACtD;AAAA,EACD;AAGA,EAAA,MAAM,MAAA,GAAS,CAAC,GAAI,YAAA,IAAgB,EAAC,EAAI,GAAI,gBAAA,IAAoB,EAAG,CAAA;AAGpE,EAAA,IAAI,MAAA,CAAO,WAAW,CAAA,EAAG;AACxB,IAAA,OAAO;AAAA,MACN,OAAA,EAAS,KAAA;AAAA,MACT,MAAA,EAAQ,mBAAmB,MAAM,CAAA,8BAAA;AAAA,KAClC;AAAA,EACD;AAGA,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,IAAA,CAAK,MAAM,CAAA;AACxC,EAAA,MAAM,OAAA,GAAU,OAAO,MAAA,CAAO,CAAC,MAAM,CAAC,YAAA,CAAa,GAAA,CAAI,CAAC,CAAC,CAAA;AAEzD,EAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG;AACvB,IAAA,OAAO;AAAA,MACN,OAAA,EAAS,KAAA;AAAA,MACT,QAAQ,CAAA,wBAAA,EAA2B,MAAM,cAAc,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KAC1E;AAAA,EACD;AAEA,EAAA,OAAO,EAAE,SAAS,IAAA,EAAK;AACxB;AAMO,IAAM,WAAA,GAAc;AAAA,EAC1B,iBAAA;AAAA,EACA,iBAAA;AAAA,EACA,qBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACD","file":"chunk-OIMJZ64E.js","sourcesContent":["/**\n * LIOP Prometheus Metrics Registry (Phase Beta-3)\n * Lightweight, zero-dependency, high-performance metrics collector\n * complying with Prometheus and OpenMetrics exposition format.\n */\n\nexport type MetricLabels = Record<string, string | number>;\n\nexport interface MetricDefinition {\n\tname: string;\n\thelp: string;\n\ttype: \"counter\" | \"gauge\" | \"histogram\";\n\tbuckets?: number[];\n}\n\nfunction formatLabels(labels?: MetricLabels): string {\n\tif (!labels || Object.keys(labels).length === 0) {\n\t\treturn \"\";\n\t}\n\tconst entries = Object.entries(labels)\n\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t.map(([k, v]) => `${k}=\"${String(v).replace(/\"/g, '\\\\\"')}\"`);\n\treturn `{${entries.join(\",\")}}`;\n}\n\nfunction labelsToKey(labels?: MetricLabels): string {\n\tif (!labels) return \"\";\n\treturn Object.entries(labels)\n\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t.map(([k, v]) => `${k}:${v}`)\n\t\t.join(\"|\");\n}\n\nexport class Counter {\n\tprivate values = new Map<string, { value: number; labels?: MetricLabels }>();\n\n\tconstructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly help: string,\n\t) {}\n\n\tinc(labels?: MetricLabels, value = 1): void {\n\t\tif (value < 0) {\n\t\t\tthrow new Error(\"Counter increments must be non-negative\");\n\t\t}\n\t\tconst key = labelsToKey(labels);\n\t\tconst current = this.values.get(key) || { value: 0, labels };\n\t\tcurrent.value += value;\n\t\tthis.values.set(key, current);\n\t}\n\n\tget(labels?: MetricLabels): number {\n\t\tconst key = labelsToKey(labels);\n\t\treturn this.values.get(key)?.value || 0;\n\t}\n\n\treset(): void {\n\t\tthis.values.clear();\n\t}\n\n\ttoPrometheus(): string[] {\n\t\tconst lines: string[] = [\n\t\t\t`# HELP ${this.name} ${this.help}`,\n\t\t\t`# TYPE ${this.name} counter`,\n\t\t];\n\t\tif (this.values.size === 0) {\n\t\t\tlines.push(`${this.name} 0`);\n\t\t\treturn lines;\n\t\t}\n\t\tfor (const entry of this.values.values()) {\n\t\t\tlines.push(`${this.name}${formatLabels(entry.labels)} ${entry.value}`);\n\t\t}\n\t\treturn lines;\n\t}\n}\n\nexport class Gauge {\n\tprivate values = new Map<string, { value: number; labels?: MetricLabels }>();\n\n\tconstructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly help: string,\n\t) {}\n\n\tset(labelsOrValue: MetricLabels | number, maybeValue?: number): void {\n\t\tif (typeof labelsOrValue === \"number\") {\n\t\t\tthis.values.set(\"\", { value: labelsOrValue });\n\t\t\treturn;\n\t\t}\n\t\tconst labels = labelsOrValue;\n\t\tconst val = typeof maybeValue === \"number\" ? maybeValue : 0;\n\t\tconst key = labelsToKey(labels);\n\t\tthis.values.set(key, { value: val, labels });\n\t}\n\n\tinc(labels?: MetricLabels, value = 1): void {\n\t\tconst key = labelsToKey(labels);\n\t\tconst current = this.values.get(key) || { value: 0, labels };\n\t\tcurrent.value += value;\n\t\tthis.values.set(key, current);\n\t}\n\n\tdec(labels?: MetricLabels, value = 1): void {\n\t\tconst key = labelsToKey(labels);\n\t\tconst current = this.values.get(key) || { value: 0, labels };\n\t\tcurrent.value -= value;\n\t\tthis.values.set(key, current);\n\t}\n\n\tget(labels?: MetricLabels): number {\n\t\tconst key = labelsToKey(labels);\n\t\treturn this.values.get(key)?.value || 0;\n\t}\n\n\treset(): void {\n\t\tthis.values.clear();\n\t}\n\n\ttoPrometheus(): string[] {\n\t\tconst lines: string[] = [\n\t\t\t`# HELP ${this.name} ${this.help}`,\n\t\t\t`# TYPE ${this.name} gauge`,\n\t\t];\n\t\tif (this.values.size === 0) {\n\t\t\tlines.push(`${this.name} 0`);\n\t\t\treturn lines;\n\t\t}\n\t\tfor (const entry of this.values.values()) {\n\t\t\tlines.push(`${this.name}${formatLabels(entry.labels)} ${entry.value}`);\n\t\t}\n\t\treturn lines;\n\t}\n}\n\nexport class Histogram {\n\tpublic readonly buckets: number[];\n\tprivate observations = new Map<\n\t\tstring,\n\t\t{\n\t\t\tcount: number;\n\t\t\tsum: number;\n\t\t\tbucketCounts: Map<number, number>;\n\t\t\tlabels?: MetricLabels;\n\t\t}\n\t>();\n\n\tconstructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly help: string,\n\t\tbuckets: number[] = [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],\n\t) {\n\t\tthis.buckets = [...buckets].sort((a, b) => a - b);\n\t}\n\n\tobserve(labelsOrValue: MetricLabels | number, maybeValue?: number): void {\n\t\tlet labels: MetricLabels | undefined;\n\t\tlet val: number;\n\n\t\tif (typeof labelsOrValue === \"number\") {\n\t\t\tval = labelsOrValue;\n\t\t} else {\n\t\t\tlabels = labelsOrValue;\n\t\t\tval = typeof maybeValue === \"number\" ? maybeValue : 0;\n\t\t}\n\n\t\tconst key = labelsToKey(labels);\n\t\tlet state = this.observations.get(key);\n\t\tif (!state) {\n\t\t\tstate = {\n\t\t\t\tcount: 0,\n\t\t\t\tsum: 0,\n\t\t\t\tbucketCounts: new Map(this.buckets.map((b) => [b, 0])),\n\t\t\t\tlabels,\n\t\t\t};\n\t\t\tthis.observations.set(key, state);\n\t\t}\n\n\t\tstate.count += 1;\n\t\tstate.sum += val;\n\n\t\tfor (const bound of this.buckets) {\n\t\t\tif (val <= bound) {\n\t\t\t\tconst cur = state.bucketCounts.get(bound) || 0;\n\t\t\t\tstate.bucketCounts.set(bound, cur + 1);\n\t\t\t}\n\t\t}\n\t}\n\n\treset(): void {\n\t\tthis.observations.clear();\n\t}\n\n\ttoPrometheus(): string[] {\n\t\tconst lines: string[] = [\n\t\t\t`# HELP ${this.name} ${this.help}`,\n\t\t\t`# TYPE ${this.name} histogram`,\n\t\t];\n\t\tif (this.observations.size === 0) {\n\t\t\tlines.push(`${this.name}_count 0`);\n\t\t\tlines.push(`${this.name}_sum 0`);\n\t\t\treturn lines;\n\t\t}\n\n\t\tfor (const state of this.observations.values()) {\n\t\t\tconst baseLabels = state.labels || {};\n\t\t\tfor (const bound of this.buckets) {\n\t\t\t\tconst bucketLabels = { ...baseLabels, le: String(bound) };\n\t\t\t\tlines.push(\n\t\t\t\t\t`${this.name}_bucket${formatLabels(bucketLabels)} ${state.bucketCounts.get(bound) || 0}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst infLabels = { ...baseLabels, le: \"+Inf\" };\n\t\t\tlines.push(\n\t\t\t\t`${this.name}_bucket${formatLabels(infLabels)} ${state.count}`,\n\t\t\t);\n\t\t\tlines.push(`${this.name}_sum${formatLabels(baseLabels)} ${state.sum}`);\n\t\t\tlines.push(\n\t\t\t\t`${this.name}_count${formatLabels(baseLabels)} ${state.count}`,\n\t\t\t);\n\t\t}\n\t\treturn lines;\n\t}\n}\n\nexport class MetricsRegistry {\n\tprivate counters = new Map<string, Counter>();\n\tprivate gauges = new Map<string, Gauge>();\n\tprivate histograms = new Map<string, Histogram>();\n\n\tcounter(name: string, help: string): Counter {\n\t\tlet c = this.counters.get(name);\n\t\tif (!c) {\n\t\t\tc = new Counter(name, help);\n\t\t\tthis.counters.set(name, c);\n\t\t}\n\t\treturn c;\n\t}\n\n\tgauge(name: string, help: string): Gauge {\n\t\tlet g = this.gauges.get(name);\n\t\tif (!g) {\n\t\t\tg = new Gauge(name, help);\n\t\t\tthis.gauges.set(name, g);\n\t\t}\n\t\treturn g;\n\t}\n\n\thistogram(name: string, help: string, buckets?: number[]): Histogram {\n\t\tlet h = this.histograms.get(name);\n\t\tif (!h) {\n\t\t\th = new Histogram(name, help, buckets);\n\t\t\tthis.histograms.set(name, h);\n\t\t}\n\t\treturn h;\n\t}\n\n\tcollectProcessMetrics(): void {\n\t\tconst uptime = this.gauge(\n\t\t\t\"liop_process_uptime_seconds\",\n\t\t\t\"Process uptime in seconds\",\n\t\t);\n\t\tuptime.set(Math.floor(process.uptime()));\n\n\t\tif (typeof process.memoryUsage === \"function\") {\n\t\t\tconst mem = process.memoryUsage();\n\t\t\tconst rss = this.gauge(\n\t\t\t\t\"liop_process_memory_rss_bytes\",\n\t\t\t\t\"Resident set size memory in bytes\",\n\t\t\t);\n\t\t\trss.set(mem.rss);\n\n\t\t\tconst heapUsed = this.gauge(\n\t\t\t\t\"liop_process_memory_heap_used_bytes\",\n\t\t\t\t\"Heap memory used in bytes\",\n\t\t\t);\n\t\t\theapUsed.set(mem.heapUsed);\n\t\t}\n\t}\n\n\texportPrometheusText(): string {\n\t\tthis.collectProcessMetrics();\n\n\t\tconst lines: string[] = [];\n\t\tfor (const c of this.counters.values()) {\n\t\t\tlines.push(...c.toPrometheus());\n\t\t}\n\t\tfor (const g of this.gauges.values()) {\n\t\t\tlines.push(...g.toPrometheus());\n\t\t}\n\t\tfor (const h of this.histograms.values()) {\n\t\t\tlines.push(...h.toPrometheus());\n\t\t}\n\t\tlines.push(\"\"); // Trailing newline\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\tresetAll(): void {\n\t\tfor (const c of this.counters.values()) c.reset();\n\t\tfor (const g of this.gauges.values()) g.reset();\n\t\tfor (const h of this.histograms.values()) h.reset();\n\t}\n}\n\n// ── Global Standard Protocol Metrics Instance ──────────────────────────────────\n\nexport const protocolMetrics = new MetricsRegistry();\n\nexport const toolCallsTotal = protocolMetrics.counter(\n\t\"liop_tool_calls_total\",\n\t\"Total number of tool logic-injection executions\",\n);\n\nexport const fuelConsumed = protocolMetrics.histogram(\n\t\"liop_fuel_consumed_total\",\n\t\"Deterministic fuel units consumed by injected logic\",\n\t[100, 500, 1000, 2500, 5000, 10000, 50000, 100000],\n);\n\nexport const meshPeersConnected = protocolMetrics.gauge(\n\t\"liop_mesh_peers_connected\",\n\t\"Active peer connections in the P2P mesh\",\n);\n\nexport const manifestCacheSize = protocolMetrics.gauge(\n\t\"liop_manifest_cache_size\",\n\t\"Number of verified remote tool manifests in cache\",\n);\n\nexport const egressBlocksTotal = protocolMetrics.counter(\n\t\"liop_egress_blocks_total\",\n\t\"Total number of outputs blocked by Egress Shield\",\n);\n\nexport const zkVerificationDurationMs = protocolMetrics.histogram(\n\t\"liop_zk_verification_duration_ms\",\n\t\"Duration of ZK-Receipt and HMAC cryptographic attestation in ms\",\n\t[1, 2, 5, 10, 25, 50, 100],\n);\n","/**\n * LIOP Post-Quantum Digital Signature Wrapper\n * Implements ML-DSA-65 (CRYSTALS-Dilithium, NIST FIPS 204) for quantum-resistant\n * manifest attestation, node revocation receipts, and cryptographic integrity.\n *\n * Characteristics:\n * - Security Category: NIST Level 3 (~AES-192 equivalent quantum resistance)\n * - Public Key Length: 1952 bytes\n * - Secret Key Length: 4032 bytes\n * - Signature Length: 3309 bytes\n * - Implementation: Pure TypeScript/JS via @noble/post-quantum\n */\n\nimport { ml_dsa65 } from \"@noble/post-quantum/ml-dsa.js\";\n\nexport const DILITHIUM65_CONSTANTS = {\n\tPUBLIC_KEY_BYTES: 1952,\n\tSECRET_KEY_BYTES: 4032,\n\tSIGNATURE_BYTES: 3309,\n\tDEFAULT_CONTEXT: new TextEncoder().encode(\"LIOP-FIPS204-ML-DSA-65\"),\n} as const;\n\n/**\n * Deterministically normalizes a message into a Uint8Array.\n */\nfunction normalizeMessage(message: Uint8Array | string): Uint8Array {\n\tif (typeof message === \"string\") {\n\t\treturn new TextEncoder().encode(message);\n\t}\n\treturn message;\n}\n\n/**\n * Deterministic canonical JSON serializer to ensure stable cryptographic hashing\n * regardless of key ordering in JavaScript objects.\n */\nfunction canonicalizeJson(obj: unknown): string {\n\tif (obj === null || typeof obj !== \"object\") {\n\t\treturn JSON.stringify(obj);\n\t}\n\tif (Array.isArray(obj)) {\n\t\treturn `[${obj.map(canonicalizeJson).join(\",\")}]`;\n\t}\n\tconst sortedKeys = Object.keys(obj as Record<string, unknown>).sort();\n\tconst entries = sortedKeys.map(\n\t\t(key) =>\n\t\t\t`${JSON.stringify(key)}:${canonicalizeJson((obj as Record<string, unknown>)[key])}`,\n\t);\n\treturn `{${entries.join(\",\")}}`;\n}\n\nexport const Dilithium65Wrapper = {\n\t/** Constants */\n\tPUBLIC_KEY_BYTES: DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES,\n\tSECRET_KEY_BYTES: DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES,\n\tSIGNATURE_BYTES: DILITHIUM65_CONSTANTS.SIGNATURE_BYTES,\n\n\t/**\n\t * Generates a new ML-DSA-65 (FIPS 204) key pair.\n\t * Optionally accepts a 32-byte seed for deterministic key generation.\n\t */\n\tgenerateKeyPair(seed?: Uint8Array): {\n\t\tpublicKey: Uint8Array;\n\t\tsecretKey: Uint8Array;\n\t} {\n\t\tif (seed && seed.length !== 32) {\n\t\t\tthrow new Error(\n\t\t\t\t`ML-DSA-65 seed must be exactly 32 bytes (Received: ${seed.length})`,\n\t\t\t);\n\t\t}\n\t\tconst keys = ml_dsa65.keygen(seed);\n\t\treturn {\n\t\t\tpublicKey: keys.publicKey,\n\t\t\tsecretKey: keys.secretKey,\n\t\t};\n\t},\n\n\t/**\n\t * Validates and imports a raw ML-DSA-65 public key.\n\t */\n\timportPublicKey(buffer: Uint8Array): Uint8Array {\n\t\tif (buffer.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {\n\t\t\tthrow new Error(\n\t\t\t\t`ML-DSA-65 Public Key must be exactly ${DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES} bytes (Received: ${buffer.length})`,\n\t\t\t);\n\t\t}\n\t\treturn buffer;\n\t},\n\n\t/**\n\t * Signs a message using the post-quantum secret key.\n\t * Supports optional domain separation context (up to 255 bytes).\n\t */\n\tsign(\n\t\tmessage: Uint8Array | string,\n\t\tsecretKey: Uint8Array,\n\t\tcontext?: Uint8Array,\n\t): Uint8Array {\n\t\tif (secretKey.length !== DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES) {\n\t\t\tthrow new Error(\n\t\t\t\t`ML-DSA-65 Secret Key must be exactly ${DILITHIUM65_CONSTANTS.SECRET_KEY_BYTES} bytes (Received: ${secretKey.length})`,\n\t\t\t);\n\t\t}\n\t\tconst msgBytes = normalizeMessage(message);\n\t\tconst ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;\n\t\treturn ml_dsa65.sign(msgBytes, secretKey, { context: ctx });\n\t},\n\n\t/**\n\t * Verifies an ML-DSA-65 post-quantum digital signature.\n\t */\n\tverify(\n\t\tsignature: Uint8Array,\n\t\tmessage: Uint8Array | string,\n\t\tpublicKey: Uint8Array,\n\t\tcontext?: Uint8Array,\n\t): boolean {\n\t\tif (signature.length !== DILITHIUM65_CONSTANTS.SIGNATURE_BYTES) {\n\t\t\treturn false;\n\t\t}\n\t\tif (publicKey.length !== DILITHIUM65_CONSTANTS.PUBLIC_KEY_BYTES) {\n\t\t\treturn false;\n\t\t}\n\t\ttry {\n\t\t\tconst msgBytes = normalizeMessage(message);\n\t\t\tconst ctx = context ?? DILITHIUM65_CONSTANTS.DEFAULT_CONTEXT;\n\t\t\treturn ml_dsa65.verify(signature, msgBytes, publicKey, { context: ctx });\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t},\n\n\t/**\n\t * Signs a structured manifest (LiopManifest) using canonical JSON serialization.\n\t * Returns base64-encoded signature and public key for transport over gRPC/MCP.\n\t */\n\tsignManifest(\n\t\tmanifest: Record<string, unknown>,\n\t\tsecretKey: Uint8Array,\n\t\tpublicKey: Uint8Array,\n\t): { signature: string; publicKey: string } {\n\t\tconst { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;\n\t\tconst canonicalStr = canonicalizeJson(unsigned);\n\t\tconst sig = this.sign(canonicalStr, secretKey);\n\t\treturn {\n\t\t\tsignature: Buffer.from(sig).toString(\"base64\"),\n\t\t\tpublicKey: Buffer.from(publicKey).toString(\"base64\"),\n\t\t};\n\t},\n\n\t/**\n\t * Verifies the post-quantum signature of a structured manifest.\n\t */\n\tverifyManifest(\n\t\tmanifest: Record<string, unknown>,\n\t\tsignatureBase64: string,\n\t\tpublicKeyBase64: string,\n\t): boolean {\n\t\ttry {\n\t\t\tconst sig = Buffer.from(signatureBase64, \"base64\");\n\t\t\tconst pub = Buffer.from(publicKeyBase64, \"base64\");\n\t\t\tconst { pqcSignature: _sig, pqcPublicKey: _pub, ...unsigned } = manifest;\n\t\t\tconst canonicalStr = canonicalizeJson(unsigned);\n\t\t\treturn this.verify(sig, canonicalStr, pub);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t},\n};\n","/**\n * LIOP RBAC Engine — Scope-Based Authorization\n *\n * Maps MCP JSON-RPC methods to required LIOP OAuth scopes.\n * Enforces least-privilege access at the router level before\n * any tool execution or resource read occurs.\n *\n * Standards: NIST SP 800-207 §4.3 (least privilege), OWASP LLM06 (Excessive Agency),\n * OWASP API-A01 (Broken Access Control)\n */\n\nimport type { AuthInfo } from \"./jwt-validator.js\";\n\n/**\n * Maps MCP JSON-RPC methods to the LIOP scopes required to invoke them.\n * Empty array = no authentication required (public endpoints).\n */\nconst SCOPE_MAP: Readonly<Record<string, readonly string[]>> = {\n\t// Protocol lifecycle — unauthenticated (MCP spec compliance)\n\tinitialize: [],\n\t\"notifications/initialized\": [],\n\t\"notifications/cancelled\": [],\n\tping: [],\n\n\t// Tool operations — require explicit authorization\n\t\"tools/list\": [\"liop:tools:list\"],\n\t\"tools/call\": [\"liop:tools:call\"],\n\n\t// Resource operations — read-level access\n\t\"resources/list\": [\"liop:resources:read\"],\n\t\"resources/read\": [\"liop:resources:read\"],\n\n\t// Prompt/schema operations — schema-level access\n\t\"prompts/list\": [\"liop:schema:read\"],\n\t\"prompts/get\": [\"liop:schema:read\"],\n};\n\n/**\n * Authorization result with optional denial reason for audit logging.\n */\nexport interface AuthorizationResult {\n\tallowed: boolean;\n\treason?: string;\n}\n\n/**\n * Evaluates whether a request is authorized based on JWT scopes.\n *\n * Decision logic:\n * 1. Methods with no required scopes (initialize, ping) → always allowed.\n * 2. Methods with required scopes but no auth → denied.\n * 3. Methods with required scopes → all scopes must be present in the JWT.\n * 4. Unknown methods with no auth → denied (fail-closed per NIST SP 800-207).\n *\n * @param method - MCP JSON-RPC method name (e.g., \"tools/call\")\n * @param auth - Validated JWT context, or null if unauthenticated\n * @param additionalScopes - Extra scopes required by specific node configuration\n */\nexport function authorizeRequest(\n\tmethod: string,\n\tauth: AuthInfo | null,\n\tadditionalScopes?: readonly string[],\n): AuthorizationResult {\n\tconst methodScopes = SCOPE_MAP[method];\n\n\t// Methods explicitly marked as public (empty scope array) pass freely\n\tif (methodScopes !== undefined && methodScopes.length === 0) {\n\t\treturn { allowed: true };\n\t}\n\n\t// If no auth context and method requires scopes → deny\n\tif (!auth) {\n\t\treturn {\n\t\t\tallowed: false,\n\t\t\treason: `Authentication required for method: ${method}`,\n\t\t};\n\t}\n\n\t// Merge method-level scopes with node-level additional scopes\n\tconst needed = [...(methodScopes ?? []), ...(additionalScopes ?? [])];\n\n\t// If no scopes needed (unknown method, no additional) → fail-closed\n\tif (needed.length === 0) {\n\t\treturn {\n\t\t\tallowed: false,\n\t\t\treason: `Unknown method: ${method}. Access denied (fail-closed).`,\n\t\t};\n\t}\n\n\t// Verify all required scopes are present in the JWT\n\tconst clientScopes = new Set(auth.scopes);\n\tconst missing = needed.filter((s) => !clientScopes.has(s));\n\n\tif (missing.length > 0) {\n\t\treturn {\n\t\t\tallowed: false,\n\t\t\treason: `Insufficient scopes for ${method}. Missing: ${missing.join(\", \")}`,\n\t\t};\n\t}\n\n\treturn { allowed: true };\n}\n\n/**\n * All LIOP OAuth scopes supported by the protocol.\n * Used for PRM metadata and client registration.\n */\nexport const LIOP_SCOPES = [\n\t\"liop:tools:list\",\n\t\"liop:tools:call\",\n\t\"liop:resources:read\",\n\t\"liop:schema:read\",\n\t\"liop:mesh:query\",\n] as const;\n\nexport type LiopScope = (typeof LIOP_SCOPES)[number];\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/types.ts
|
|
4
|
+
|
|
5
|
+
// src/gateway/mcp-compat.ts
|
|
6
|
+
var MCP_LEGACY_SUPPORT_ENABLED = true;
|
|
7
|
+
var MCP_PROTOCOL_VERSION_LEGACY = "2025-11-25";
|
|
8
|
+
function buildLegacyInitializeResponse(serverInfo, id) {
|
|
9
|
+
return {
|
|
10
|
+
jsonrpc: "2.0",
|
|
11
|
+
id: id ?? null,
|
|
12
|
+
result: {
|
|
13
|
+
protocolVersion: MCP_PROTOCOL_VERSION_LEGACY,
|
|
14
|
+
capabilities: {
|
|
15
|
+
tools: { listChanged: true },
|
|
16
|
+
resources: { listChanged: true },
|
|
17
|
+
prompts: { listChanged: true }
|
|
18
|
+
},
|
|
19
|
+
serverInfo
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function isLegacyRequest(request) {
|
|
24
|
+
if (request.method === "initialize" || request.method === "notifications/initialized") {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
const params = request.params;
|
|
28
|
+
const meta = params?._meta;
|
|
29
|
+
const version = meta?.["io.modelcontextprotocol/protocolVersion"];
|
|
30
|
+
if (!version || version === MCP_PROTOCOL_VERSION_LEGACY) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
function adaptResponseForLegacyClient(response) {
|
|
36
|
+
if (!response.result || typeof response.result !== "object") {
|
|
37
|
+
return response;
|
|
38
|
+
}
|
|
39
|
+
const rawResult = { ...response.result };
|
|
40
|
+
delete rawResult.resultType;
|
|
41
|
+
delete rawResult.ttlMs;
|
|
42
|
+
delete rawResult.cacheScope;
|
|
43
|
+
return {
|
|
44
|
+
...response,
|
|
45
|
+
result: rawResult
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/types.ts
|
|
50
|
+
var MCP_PROTOCOL_VERSION = "2026-07-28";
|
|
51
|
+
var ToolSchema = z.object({
|
|
52
|
+
name: z.string(),
|
|
53
|
+
description: z.string().optional(),
|
|
54
|
+
inputSchema: z.record(z.string(), z.unknown())
|
|
55
|
+
// Represents a JSON Schema
|
|
56
|
+
});
|
|
57
|
+
var ResourceSchema = z.object({
|
|
58
|
+
uri: z.string(),
|
|
59
|
+
name: z.string(),
|
|
60
|
+
description: z.string().optional(),
|
|
61
|
+
mimeType: z.string().optional()
|
|
62
|
+
});
|
|
63
|
+
var PromptSchema = z.object({
|
|
64
|
+
name: z.string(),
|
|
65
|
+
description: z.string().optional(),
|
|
66
|
+
arguments: z.array(
|
|
67
|
+
z.object({
|
|
68
|
+
name: z.string(),
|
|
69
|
+
description: z.string().optional(),
|
|
70
|
+
required: z.boolean().optional()
|
|
71
|
+
})
|
|
72
|
+
).optional()
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export { MCP_LEGACY_SUPPORT_ENABLED, MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION_LEGACY, PromptSchema, ResourceSchema, ToolSchema, adaptResponseForLegacyClient, buildLegacyInitializeResponse, isLegacyRequest };
|
|
76
|
+
//# sourceMappingURL=chunk-PYKRQAER.js.map
|
|
77
|
+
//# sourceMappingURL=chunk-PYKRQAER.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gateway/mcp-compat.ts","../src/types.ts"],"names":[],"mappings":";;;;;AAcO,IAAM,0BAAA,GAA6B;AAKnC,IAAM,2BAAA,GAA8B;AAKpC,SAAS,6BAAA,CACf,YACA,EAAA,EACc;AACd,EAAA,OAAO;AAAA,IACN,OAAA,EAAS,KAAA;AAAA,IACT,IAAI,EAAA,IAAM,IAAA;AAAA,IACV,MAAA,EAAQ;AAAA,MACP,eAAA,EAAiB,2BAAA;AAAA,MACjB,YAAA,EAAc;AAAA,QACb,KAAA,EAAO,EAAE,WAAA,EAAa,IAAA,EAAK;AAAA,QAC3B,SAAA,EAAW,EAAE,WAAA,EAAa,IAAA,EAAK;AAAA,QAC/B,OAAA,EAAS,EAAE,WAAA,EAAa,IAAA;AAAK,OAC9B;AAAA,MACA;AAAA;AACD,GACD;AACD;AAOO,SAAS,gBAAgB,OAAA,EAA8B;AAC7D,EAAA,IACC,OAAA,CAAQ,MAAA,KAAW,YAAA,IACnB,OAAA,CAAQ,WAAW,2BAAA,EAClB;AACD,IAAA,OAAO,IAAA;AAAA,EACR;AAEA,EAAA,MAAM,SAAS,OAAA,CAAQ,MAAA;AACvB,EAAA,MAAM,OAAO,MAAA,EAAQ,KAAA;AACrB,EAAA,MAAM,OAAA,GAAU,OAAO,yCAAyC,CAAA;AAEhE,EAAA,IAAI,CAAC,OAAA,IAAW,OAAA,KAAY,2BAAA,EAA6B;AACx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A,MACR,IAAA,EAAM,EAAE,MAAA,EAAO;AAAA,MACf,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,MACjC,QAAA,EAAU,CAAA,CAAE,OAAA,EAAQ,CAAE,QAAA;AAAS,KAC/B;AAAA,IAED,QAAA;AACH,CAAC","file":"chunk-PYKRQAER.js","sourcesContent":["import type { McpRequest, McpResponse, ServerInfo } from \"../types.js\";\n\n/**\n * @mcp-legacy ENTIRE FILE — MCP 2025-era backward compatibility layer.\n * Remove this file when MCP v1 (2025-11-25) reaches EOL.\n *\n * SUNSET INSTRUCTION: Delete this file, then grep for \"@mcp-legacy\" in the\n * codebase to find and remove all remaining legacy seams.\n */\n\n/**\n * @mcp-legacy Master kill switch for MCP 2025-era backward compatibility.\n * Set to `false` when MCP v1 reaches End-of-Life (EOL) to disable all legacy seams.\n */\nexport const MCP_LEGACY_SUPPORT_ENABLED = true;\n\n/**\n * @mcp-legacy Legacy protocol version constant.\n */\nexport const MCP_PROTOCOL_VERSION_LEGACY = \"2025-11-25\" as const;\n\n/**\n * @mcp-legacy Build the legacy initialize handshake response.\n */\nexport function buildLegacyInitializeResponse(\n\tserverInfo: ServerInfo,\n\tid?: string | number | null,\n): McpResponse {\n\treturn {\n\t\tjsonrpc: \"2.0\",\n\t\tid: id ?? null,\n\t\tresult: {\n\t\t\tprotocolVersion: MCP_PROTOCOL_VERSION_LEGACY,\n\t\t\tcapabilities: {\n\t\t\t\ttools: { listChanged: true },\n\t\t\t\tresources: { listChanged: true },\n\t\t\t\tprompts: { listChanged: true },\n\t\t\t},\n\t\t\tserverInfo,\n\t\t},\n\t};\n}\n\n/**\n * @mcp-legacy Detect if a request is strictly from a 2025-era legacy client.\n * Legacy requests either invoke 'initialize', 'notifications/initialized',\n * or lack modern '_meta' protocol envelopes.\n */\nexport function isLegacyRequest(request: McpRequest): boolean {\n\tif (\n\t\trequest.method === \"initialize\" ||\n\t\trequest.method === \"notifications/initialized\"\n\t) {\n\t\treturn true;\n\t}\n\n\tconst params = request.params as Record<string, unknown> | undefined;\n\tconst meta = params?._meta as Record<string, unknown> | undefined;\n\tconst version = meta?.[\"io.modelcontextprotocol/protocolVersion\"];\n\n\tif (!version || version === MCP_PROTOCOL_VERSION_LEGACY) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n/**\n * @mcp-legacy Wrap and strip modern-era fields (resultType, ttlMs, cacheScope, etc.)\n * from a response to ensure 100% wire-compatibility with strict 2025 MCP clients.\n */\nexport function adaptResponseForLegacyClient(\n\tresponse: McpResponse,\n): McpResponse {\n\tif (!response.result || typeof response.result !== \"object\") {\n\t\treturn response;\n\t}\n\n\tconst rawResult = { ...(response.result as Record<string, unknown>) };\n\n\t// Strip modern-only envelope tags\n\tdelete rawResult.resultType;\n\tdelete rawResult.ttlMs;\n\tdelete rawResult.cacheScope;\n\n\treturn {\n\t\t...response,\n\t\tresult: rawResult,\n\t};\n}\n","import { z } from \"zod\";\n\n/**\n * Protocol Version Identifiers\n */\nexport const MCP_PROTOCOL_VERSION = \"2026-07-28\" as const;\n\nexport {\n\tMCP_LEGACY_SUPPORT_ENABLED,\n\tMCP_PROTOCOL_VERSION_LEGACY,\n} from \"./gateway/mcp-compat.js\";\n\n/**\n * Protocol Era Classification\n */\nexport type McpEra = \"legacy\" | \"modern\";\n\n/**\n * Caching Hints for MCP 2026-07-28 Spec\n */\nexport interface CacheableResult {\n\tttlMs?: number;\n\tcacheScope?: \"public\" | \"private\";\n}\n\n/**\n * Multi-Round-Trip Requests (MRTR) Specification Types\n */\nexport interface InputRequest {\n\tid: string;\n\tmessage: string;\n\tschema?: Record<string, unknown>;\n}\n\nexport interface InputResponse {\n\tid: string;\n\tvalue: unknown;\n}\n\nexport interface InputRequiredResult {\n\tresultType: \"input_required\";\n\tinputRequests: InputRequest[];\n\trequestState?: string;\n}\n\n/**\n * Modern Envelope Metadata (_meta)\n */\nexport interface McpRequestMeta {\n\t\"io.modelcontextprotocol/protocolVersion\"?: string;\n\t\"io.modelcontextprotocol/clientInfo\"?: {\n\t\tname: string;\n\t\tversion: string;\n\t};\n\t\"io.modelcontextprotocol/clientCapabilities\"?: Record<string, unknown>;\n\t[key: string]: unknown;\n}\n\n/**\n * Base Protocol Types representing parity with Model Context Protocol\n */\n\nexport const ToolSchema = z.object({\n\tname: z.string(),\n\tdescription: z.string().optional(),\n\tinputSchema: z.record(z.string(), z.unknown()), // Represents a JSON Schema\n});\n\nexport type Tool = z.infer<typeof ToolSchema>;\n\nexport const ResourceSchema = z.object({\n\turi: z.string(),\n\tname: z.string(),\n\tdescription: z.string().optional(),\n\tmimeType: z.string().optional(),\n});\n\nexport type Resource = z.infer<typeof ResourceSchema>;\n\nexport const PromptSchema = z.object({\n\tname: z.string(),\n\tdescription: z.string().optional(),\n\targuments: z\n\t\t.array(\n\t\t\tz.object({\n\t\t\t\tname: z.string(),\n\t\t\t\tdescription: z.string().optional(),\n\t\t\t\trequired: z.boolean().optional(),\n\t\t\t}),\n\t\t)\n\t\t.optional(),\n});\n\nexport type Prompt = z.infer<typeof PromptSchema>;\n\nexport interface CallToolRequest {\n\tname: string;\n\targuments?: Record<string, unknown>;\n}\n\nexport interface CallToolResult {\n\tcontent: Array<{\n\t\ttype: \"text\" | \"image\" | \"resource\";\n\t\ttext?: string;\n\t\tdata?: string;\n\t\tmimeType?: string;\n\t\tresource?: {\n\t\t\turi: string;\n\t\t\ttext?: string;\n\t\t\tblob?: string;\n\t\t};\n\t}>;\n\tisError?: boolean;\n}\n\nexport interface GetPromptRequest {\n\tname: string;\n\targuments?: Record<string, string>;\n}\n\nexport interface GetPromptResult {\n\tdescription?: string;\n\tmessages: Array<{\n\t\trole: \"user\" | \"assistant\";\n\t\tcontent:\n\t\t\t| { type: \"text\"; text: string }\n\t\t\t| { type: \"image\"; data: string; mimeType: string }\n\t\t\t| {\n\t\t\t\t\ttype: \"resource\";\n\t\t\t\t\tresource: { uri: string; text?: string; blob?: string };\n\t\t\t };\n\t}>;\n}\n\nexport interface ServerInfo {\n\tname: string;\n\tversion: string;\n\tcapabilities?: {\n\t\tprompts?: { listChanged?: boolean };\n\t\tresources?: { subscribe?: boolean; listChanged?: boolean };\n\t\ttools?: { listChanged?: boolean };\n\t\t/** @mcp-legacy @deprecated Deprecated in MCP 2026-07-28 spec */\n\t\tlogging?: Record<string, unknown>;\n\t};\n}\n\nexport interface DiscoverResult {\n\tresultType: \"complete\";\n\tsupportedVersions: string[];\n\tcapabilities: ServerInfo[\"capabilities\"];\n\tserverInfo: ServerInfo;\n\tinstructions?: string;\n}\n\nexport interface McpRequest {\n\tmethod: string;\n\tparams?: unknown;\n\tid?: string | number | null;\n\tjsonrpc?: \"2.0\";\n}\n\nexport interface McpResponse {\n\tjsonrpc: \"2.0\";\n\tid?: string | number | null;\n\tresult?: unknown;\n\terror?: {\n\t\tcode: number;\n\t\tmessage: string;\n\t\tdata?: unknown;\n\t};\n}\n\n/**\n * Re-export AuthInfo from the security module for convenience.\n * Compatible with MCP TypeScript SDK AuthInfo interface shape.\n */\nexport type { AuthInfo } from \"./security/jwt-validator.js\";\n"]}
|