@nekzus/liop 2.5.0-beta.2 → 2.5.0-beta.3
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/README.md +87 -40
- package/dist/bin/agent.js +27 -894
- package/dist/bridge.d.ts +4 -3
- package/dist/bridge.js +1 -4
- package/dist/chunk-2XHSALII.js +3 -0
- package/dist/chunk-2ZYX736J.js +2 -0
- package/dist/chunk-3WRKTVOF.js +2 -0
- package/dist/chunk-6KFKO6ZX.js +2 -0
- package/dist/chunk-6VK2XALI.js +2 -0
- package/dist/chunk-AYDF3IFZ.js +2 -0
- package/dist/chunk-CTTTLCGL.js +31 -0
- package/dist/chunk-ECRS6N33.js +4 -0
- package/dist/chunk-FDJMH4CB.js +2 -0
- package/dist/chunk-FTF6AMF6.js +0 -1
- package/dist/chunk-GWVSCZUS.js +2 -0
- package/dist/chunk-LEXMMIQI.js +15 -0
- package/dist/chunk-LM26HOJ6.js +31 -0
- package/dist/chunk-MQ5SU26J.js +2 -0
- package/dist/chunk-N35BC62H.js +2 -0
- package/dist/chunk-P6IJ3VBD.js +3 -0
- package/dist/chunk-TKLRW52V.js +2 -0
- package/dist/chunk-V35CXJQN.js +2 -0
- package/dist/chunk-WP5ER7RH.js +3 -0
- package/dist/chunk-XLVEDKM6.js +2 -0
- package/dist/chunk-Y675R34Z.js +2 -0
- package/dist/chunk-YD2AF2M6.js +46 -0
- package/dist/chunk-YLCNV764.js +3 -0
- package/dist/chunk-ZZMSFCJP.js +3 -0
- package/dist/client.d.ts +5 -4
- package/dist/client.js +1 -11
- package/dist/gateway.d.ts +6 -5
- package/dist/gateway.js +1 -11
- package/dist/{hybrid-DWe1bMoV.d.ts → hybrid-BZpCiUaV.d.ts} +4 -4
- package/dist/{index-BuEQtBHD.d.ts → index-BYDtRGue.d.ts} +8 -4
- package/dist/{index-CdW8j8Bn.d.ts → index-ByzjpRCk.d.ts} +30 -2
- package/dist/index.d.ts +57 -10
- package/dist/index.js +4 -317
- package/dist/kyber-PULV7PQX.js +2 -0
- package/dist/mesh.d.ts +1 -1
- package/dist/mesh.js +1 -5
- package/dist/{node-B0b2vUFS.d.ts → node-Djzm6UYd.d.ts} +8 -0
- package/dist/protocol/liop_core.proto +22 -6
- package/dist/server.d.ts +4 -3
- package/dist/server.js +1 -8
- package/dist/{types-CzRSOlOo.d.ts → types-29zv9X1V.d.ts} +3 -0
- package/dist/types.d.ts +2 -1
- package/dist/types.js +1 -2
- package/dist/verifier-DqZ9MQ9l.d.ts +82 -0
- package/dist/verifier-J4NQYZX5.js +2 -0
- package/dist/workers/logic-execution.d.ts +7 -0
- package/dist/workers/logic-execution.js +1 -271
- package/dist/workers/zk-verifier.d.ts +9 -0
- package/dist/workers/zk-verifier.js +1 -173
- package/dist/zk-DzYNWBgo.d.ts +104 -0
- package/package.json +7 -2
- package/dist/bin/agent.js.map +0 -1
- package/dist/bridge.js.map +0 -1
- package/dist/chunk-2KSO3W4A.js +0 -77
- package/dist/chunk-2KSO3W4A.js.map +0 -1
- package/dist/chunk-2STZHJ24.js +0 -114
- package/dist/chunk-2STZHJ24.js.map +0 -1
- package/dist/chunk-3QH44NKZ.js +0 -115
- package/dist/chunk-3QH44NKZ.js.map +0 -1
- package/dist/chunk-5SWHE62F.js +0 -3683
- package/dist/chunk-5SWHE62F.js.map +0 -1
- package/dist/chunk-7BSCUYUE.js +0 -421
- package/dist/chunk-7BSCUYUE.js.map +0 -1
- package/dist/chunk-7PITYWOV.js +0 -68
- package/dist/chunk-7PITYWOV.js.map +0 -1
- package/dist/chunk-EJ426URA.js +0 -818
- package/dist/chunk-EJ426URA.js.map +0 -1
- package/dist/chunk-FCFTYOAS.js +0 -793
- package/dist/chunk-FCFTYOAS.js.map +0 -1
- package/dist/chunk-FTF6AMF6.js.map +0 -1
- package/dist/chunk-IK7CGWAZ.js +0 -24
- package/dist/chunk-IK7CGWAZ.js.map +0 -1
- package/dist/chunk-K3DGJLUY.js +0 -106
- package/dist/chunk-K3DGJLUY.js.map +0 -1
- package/dist/chunk-PAICJCKJ.js +0 -332
- package/dist/chunk-PAICJCKJ.js.map +0 -1
- package/dist/chunk-PUDETPL4.js +0 -279
- package/dist/chunk-PUDETPL4.js.map +0 -1
- package/dist/chunk-UJFWPRDM.js +0 -206884
- package/dist/chunk-UJFWPRDM.js.map +0 -1
- package/dist/chunk-VRB5HUYU.js +0 -1492
- package/dist/chunk-VRB5HUYU.js.map +0 -1
- package/dist/chunk-VRDZ5IKE.js +0 -558
- package/dist/chunk-VRDZ5IKE.js.map +0 -1
- package/dist/chunk-WPTOJYN5.js +0 -181
- package/dist/chunk-WPTOJYN5.js.map +0 -1
- package/dist/chunk-XRDN232O.js +0 -877
- package/dist/chunk-XRDN232O.js.map +0 -1
- package/dist/chunk-Y62GORQF.js +0 -51
- package/dist/chunk-Y62GORQF.js.map +0 -1
- package/dist/chunk-ZP3VVXOI.js +0 -66
- package/dist/chunk-ZP3VVXOI.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/gateway.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/kyber-CGOA7Q6A.js +0 -3
- package/dist/kyber-CGOA7Q6A.js.map +0 -1
- package/dist/mesh.js.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/verifier-COnid_dg.d.ts +0 -31
- package/dist/verifier-XFU7ZB2W.js +0 -6
- package/dist/verifier-XFU7ZB2W.js.map +0 -1
- package/dist/workers/logic-execution.js.map +0 -1
- package/dist/workers/zk-verifier.js.map +0 -1
package/dist/bin/agent.js
CHANGED
|
@@ -1,896 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
properties: {},
|
|
30
|
-
additionalProperties: false
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
async function resolveBootstrapFromUrl(url) {
|
|
34
|
-
try {
|
|
35
|
-
const healthUrl = url.endsWith("/health") ? url : `${url}/health`;
|
|
36
|
-
const response = await fetch(healthUrl, {
|
|
37
|
-
headers: { Accept: "application/json" },
|
|
38
|
-
signal: AbortSignal.timeout(1e4)
|
|
39
|
-
});
|
|
40
|
-
if (!response.ok) return null;
|
|
41
|
-
const data = await response.json();
|
|
42
|
-
if (!data.mesh?.multiaddrs?.length || !data.mesh?.peerId) return null;
|
|
43
|
-
const tcpAddr = data.mesh.multiaddrs.find(
|
|
44
|
-
(a) => a.includes("/tcp/") && !a.includes("/ws") && !a.includes("/ip4/127.0.0.1/")
|
|
45
|
-
);
|
|
46
|
-
if (!tcpAddr) return null;
|
|
47
|
-
let resolved = shouldEnableDockerMap() ? industrialAddressMapper(tcpAddr) : tcpAddr;
|
|
48
|
-
if (!resolved || resolved === tcpAddr) {
|
|
49
|
-
const urlHost = new URL(url).hostname;
|
|
50
|
-
resolved = tcpAddr.replace(/\/ip4\/[^/]+/, `/ip4/${urlHost}`);
|
|
51
|
-
}
|
|
52
|
-
if (!resolved) return null;
|
|
53
|
-
resolved += resolved.includes("/p2p/") ? "" : `/p2p/${data.mesh.peerId}`;
|
|
54
|
-
return resolved;
|
|
55
|
-
} catch {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function normalizeBootstrap(addr) {
|
|
60
|
-
const trimmed = addr.trim();
|
|
61
|
-
const dockerIpRegex = /\/ip4\/172\.(1[6-9]|2[0-9]|3[0-1])\.[0-9]{1,3}\.[0-9]{1,3}/;
|
|
62
|
-
const loopbackRegex = /\/ip4\/127\.0\.0\.1/;
|
|
63
|
-
const physicalIpRegex = /\/ip4\/192\.168\.[0-9]{1,3}\.[0-9]{1,3}/;
|
|
64
|
-
if (dockerIpRegex.test(trimmed) || loopbackRegex.test(trimmed) || physicalIpRegex.test(trimmed)) {
|
|
65
|
-
const targetIp = "127.0.0.1";
|
|
66
|
-
const normalized = trimmed.replace(dockerIpRegex, `/ip4/${targetIp}`).replace(loopbackRegex, `/ip4/${targetIp}`).replace(physicalIpRegex, `/ip4/${targetIp}`);
|
|
67
|
-
if (normalized !== trimmed) {
|
|
68
|
-
log.info(
|
|
69
|
-
`[LIOP-Agent] \u{1F504} Local Routing Hack \u2192 Forced 127.0.0.1: ${normalized}`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
return normalized;
|
|
73
|
-
}
|
|
74
|
-
return trimmed;
|
|
75
|
-
}
|
|
76
|
-
function industrialAddressMapper(addr) {
|
|
77
|
-
if (addr.includes("/ip4/172.23.0.10"))
|
|
78
|
-
return addr.replace(
|
|
79
|
-
/\/ip4\/172\.23\.0\.10\/tcp\/[0-9]+/,
|
|
80
|
-
"/ip4/127.0.0.1/tcp/15001"
|
|
81
|
-
);
|
|
82
|
-
if (addr.includes("/ip4/172.23.0.20"))
|
|
83
|
-
return addr.replace(
|
|
84
|
-
/\/ip4\/172\.23\.0\.20\/tcp\/[0-9]+/,
|
|
85
|
-
"/ip4/127.0.0.1/tcp/15011"
|
|
86
|
-
);
|
|
87
|
-
if (addr.includes("/ip4/172.21.0.13"))
|
|
88
|
-
return addr.replace(
|
|
89
|
-
/\/ip4\/172\.21\.0\.13\/tcp\/[0-9]+/,
|
|
90
|
-
"/ip4/127.0.0.1/tcp/15031"
|
|
91
|
-
);
|
|
92
|
-
if (addr.includes("/ip4/172.21.0.14"))
|
|
93
|
-
return addr.replace(
|
|
94
|
-
/\/ip4\/172\.21\.0\.14\/tcp\/[0-9]+/,
|
|
95
|
-
"/ip4/127.0.0.1/tcp/15041"
|
|
96
|
-
);
|
|
97
|
-
if (addr.includes("/ip4/172.20.0.10"))
|
|
98
|
-
return addr.replace(
|
|
99
|
-
/\/ip4\/172\.20\.0\.10\/tcp\/[0-9]+/,
|
|
100
|
-
"/ip4/127.0.0.1/tcp/13001"
|
|
101
|
-
);
|
|
102
|
-
if (addr.includes("/ip4/172.20.0.11"))
|
|
103
|
-
return addr.replace(
|
|
104
|
-
/\/ip4\/172\.20\.0\.11\/tcp\/[0-9]+/,
|
|
105
|
-
"/ip4/127.0.0.1/tcp/13003"
|
|
106
|
-
);
|
|
107
|
-
if (addr.includes("/ip4/172.20.0.12"))
|
|
108
|
-
return addr.replace(
|
|
109
|
-
/\/ip4\/172\.20\.0\.12\/tcp\/[0-9]+/,
|
|
110
|
-
"/ip4/127.0.0.1/tcp/13004"
|
|
111
|
-
);
|
|
112
|
-
if (addr.includes("/ip4/172.20.0.13"))
|
|
113
|
-
return addr.replace(
|
|
114
|
-
/\/ip4\/172\.20\.0\.13\/tcp\/[0-9]+/,
|
|
115
|
-
"/ip4/127.0.0.1/tcp/13005"
|
|
116
|
-
);
|
|
117
|
-
if (addr.includes("/ip4/127.0.0.1/tcp/4000") || addr.includes("/ip4/127.0.0.1/tcp/3000")) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
return addr;
|
|
121
|
-
}
|
|
122
|
-
function isDockerDemoHost(urlStr) {
|
|
123
|
-
try {
|
|
124
|
-
const u = new URL(urlStr);
|
|
125
|
-
return (u.hostname === "127.0.0.1" || u.hostname === "localhost") && (u.port === "13000" || u.port === "13001" || u.port === "15000" || u.port === "15018");
|
|
126
|
-
} catch {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function shouldEnableDockerMap() {
|
|
131
|
-
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.LIOP_DOCKER_MAP === "true" || process.env.LIOP_DEV_MODE === "true" || !!process.env.LIOP_NEXUS_URL && isDockerDemoHost(process.env.LIOP_NEXUS_URL);
|
|
132
|
-
}
|
|
133
|
-
async function resolveBootstrapNodes(liopDir) {
|
|
134
|
-
let bootstrapNodes = [];
|
|
135
|
-
const args = process.argv.slice(2);
|
|
136
|
-
if (args.length > 0) {
|
|
137
|
-
bootstrapNodes = args.filter((a) => a.startsWith("/"));
|
|
138
|
-
}
|
|
139
|
-
if (bootstrapNodes.length === 0) {
|
|
140
|
-
const searchDirs = [
|
|
141
|
-
process.cwd(),
|
|
142
|
-
path.join(process.cwd(), "tests/infra/nexus-data"),
|
|
143
|
-
liopDir,
|
|
144
|
-
path.join(
|
|
145
|
-
path.dirname(new URL(import.meta.url).pathname).replace(/^\/([A-Z]:)/, "$1"),
|
|
146
|
-
"../../tests/infra/nexus-data"
|
|
147
|
-
)
|
|
148
|
-
];
|
|
149
|
-
for (const dir of searchDirs) {
|
|
150
|
-
try {
|
|
151
|
-
if (fs.existsSync(dir)) {
|
|
152
|
-
const files = fs.readdirSync(dir);
|
|
153
|
-
const multiaddrFiles = files.filter((f) => f.endsWith(".multiaddr"));
|
|
154
|
-
for (const file of multiaddrFiles) {
|
|
155
|
-
const filePath = path.join(dir, file);
|
|
156
|
-
const addr = fs.readFileSync(filePath, "utf8").trim();
|
|
157
|
-
if (addr) {
|
|
158
|
-
const normalized = normalizeBootstrap(addr);
|
|
159
|
-
if (!bootstrapNodes.includes(normalized)) {
|
|
160
|
-
bootstrapNodes.push(normalized);
|
|
161
|
-
log.info(`[LIOP-Agent] \u2705 Loaded beacon: ${file} from ${dir}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (bootstrapNodes.length > 0) break;
|
|
166
|
-
}
|
|
167
|
-
} catch {
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (process.env.LIOP_NEXUS_URL) {
|
|
172
|
-
const nexusUrl = process.env.LIOP_NEXUS_URL;
|
|
173
|
-
const resolved = await resolveBootstrapFromUrl(nexusUrl);
|
|
174
|
-
if (resolved) {
|
|
175
|
-
const normalized = normalizeBootstrap(resolved);
|
|
176
|
-
if (!bootstrapNodes.includes(normalized)) {
|
|
177
|
-
bootstrapNodes.push(normalized);
|
|
178
|
-
log.info(
|
|
179
|
-
`[LIOP-Agent] \u2705 Added bootstrap from URL discovery: ${normalized}`
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (bootstrapNodes.length === 0 && process.env.LIOP_BOOTSTRAP) {
|
|
185
|
-
bootstrapNodes.push(process.env.LIOP_BOOTSTRAP.trim());
|
|
186
|
-
}
|
|
187
|
-
return bootstrapNodes.filter((addr) => {
|
|
188
|
-
try {
|
|
189
|
-
multiaddr(addr);
|
|
190
|
-
return true;
|
|
191
|
-
} catch {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
async function forwardToGateway(mcpEndpoint, request, tokenManager) {
|
|
197
|
-
const send = async (token2) => {
|
|
198
|
-
const headers = {
|
|
199
|
-
"Content-Type": "application/json"
|
|
200
|
-
};
|
|
201
|
-
if (token2) {
|
|
202
|
-
headers.Authorization = `Bearer ${token2}`;
|
|
203
|
-
}
|
|
204
|
-
if (request.method) {
|
|
205
|
-
headers["Mcp-Method"] = request.method;
|
|
206
|
-
}
|
|
207
|
-
const params = request.params;
|
|
208
|
-
if (params?.name) {
|
|
209
|
-
headers["Mcp-Name"] = params.name;
|
|
210
|
-
}
|
|
211
|
-
return await fetch(mcpEndpoint, {
|
|
212
|
-
method: "POST",
|
|
213
|
-
headers,
|
|
214
|
-
body: JSON.stringify(request),
|
|
215
|
-
signal: AbortSignal.timeout(3e4)
|
|
216
|
-
});
|
|
217
|
-
};
|
|
218
|
-
let token;
|
|
219
|
-
try {
|
|
220
|
-
token = await tokenManager.getToken();
|
|
221
|
-
} catch (err) {
|
|
222
|
-
log.warn(
|
|
223
|
-
`[LIOP-Agent] Token acquisition warning: ${err instanceof Error ? err.message : String(err)}`
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
let response = await send(token);
|
|
227
|
-
if (response.status === 401 && token) {
|
|
228
|
-
log.info(
|
|
229
|
-
"[LIOP-Agent] \u{1F504} 401 received from Gateway. Refreshing token and retrying..."
|
|
230
|
-
);
|
|
231
|
-
tokenManager.invalidate();
|
|
232
|
-
try {
|
|
233
|
-
token = await tokenManager.getToken();
|
|
234
|
-
response = await send(token);
|
|
235
|
-
} catch {
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (!response.ok) {
|
|
239
|
-
const errorBody = await response.text();
|
|
240
|
-
let parsedError = null;
|
|
241
|
-
try {
|
|
242
|
-
parsedError = JSON.parse(errorBody);
|
|
243
|
-
} catch {
|
|
244
|
-
}
|
|
245
|
-
const errorObj = parsedError?.error;
|
|
246
|
-
return {
|
|
247
|
-
jsonrpc: "2.0",
|
|
248
|
-
id: request.id,
|
|
249
|
-
error: {
|
|
250
|
-
code: errorObj?.code ?? -32603,
|
|
251
|
-
message: errorObj?.message ?? `Gateway returned HTTP ${response.status}: ${errorBody}`
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
return await response.json();
|
|
256
|
-
}
|
|
257
|
-
async function runGatewayMode(gateway, tokenManager, routingTable) {
|
|
258
|
-
log.info(
|
|
259
|
-
`[LIOP-Agent] \u{1F6E1}\uFE0F Running in ADAPTIVE GATEWAY MODE -> ${gateway.mcpEndpoint}`
|
|
260
|
-
);
|
|
261
|
-
routingTable.registerLocalTool(LIOP_MESH_STATUS_TOOL);
|
|
262
|
-
routingTable.registerGatewayTools(
|
|
263
|
-
gateway.tools.map((t) => ({ name: t })),
|
|
264
|
-
gateway.mcpEndpoint
|
|
265
|
-
);
|
|
266
|
-
let lastToolCount = gateway.tools.length;
|
|
267
|
-
const pollInterval = setInterval(async () => {
|
|
268
|
-
try {
|
|
269
|
-
const res = await fetch(gateway.healthEndpoint, {
|
|
270
|
-
headers: { Accept: "application/json" },
|
|
271
|
-
signal: AbortSignal.timeout(4e3)
|
|
272
|
-
});
|
|
273
|
-
if (res.ok) {
|
|
274
|
-
const data = await res.json();
|
|
275
|
-
if (data.tools && data.tools.length !== lastToolCount) {
|
|
276
|
-
log.info(
|
|
277
|
-
`[LIOP-Agent] Gateway tools topology updated (${lastToolCount} -> ${data.tools.length})`
|
|
278
|
-
);
|
|
279
|
-
lastToolCount = data.tools.length;
|
|
280
|
-
routingTable.registerGatewayTools(
|
|
281
|
-
data.tools.map((t) => ({ name: t })),
|
|
282
|
-
gateway.mcpEndpoint
|
|
283
|
-
);
|
|
284
|
-
process.stdout.write(
|
|
285
|
-
`{"jsonrpc":"2.0","method":"notifications/tools/list_changed"}
|
|
286
|
-
`
|
|
287
|
-
);
|
|
288
|
-
process.stdout.write(
|
|
289
|
-
`{"jsonrpc":"2.0","method":"notifications/resources/list_changed"}
|
|
290
|
-
`
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
} catch {
|
|
295
|
-
}
|
|
296
|
-
}, 15e3);
|
|
297
|
-
const rl = readline.createInterface({
|
|
298
|
-
input: process.stdin,
|
|
299
|
-
terminal: false
|
|
300
|
-
});
|
|
301
|
-
process.stdout.on("error", (err) => {
|
|
302
|
-
if (err.code === "EPIPE") {
|
|
303
|
-
clearInterval(pollInterval);
|
|
304
|
-
process.exit(0);
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
rl.on("line", async (line) => {
|
|
308
|
-
const trimmed = line.trim();
|
|
309
|
-
if (!trimmed) return;
|
|
310
|
-
let request;
|
|
311
|
-
try {
|
|
312
|
-
request = JSON.parse(trimmed);
|
|
313
|
-
} catch {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
const { id, method } = request;
|
|
317
|
-
if (method === "server/discover") {
|
|
318
|
-
const discoverResponse = {
|
|
319
|
-
jsonrpc: "2.0",
|
|
320
|
-
id,
|
|
321
|
-
result: {
|
|
322
|
-
resultType: "complete",
|
|
323
|
-
supportedVersions: ["2026-07-28", "2025-11-25"],
|
|
324
|
-
capabilities: {
|
|
325
|
-
tools: { listChanged: true },
|
|
326
|
-
resources: { listChanged: true, subscribe: true },
|
|
327
|
-
prompts: { listChanged: true }
|
|
328
|
-
},
|
|
329
|
-
serverInfo: {
|
|
330
|
-
name: "liop-adaptive-agent",
|
|
331
|
-
version: "2.5.0"
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
process.stdout.write(`${JSON.stringify(discoverResponse)}
|
|
336
|
-
`);
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
if (method === "initialize") {
|
|
340
|
-
const clientVersion = request.params?.protocolVersion ?? request.params?._meta?.["io.modelcontextprotocol/protocolVersion"];
|
|
341
|
-
const protocolVersion = clientVersion === "2026-07-28" ? "2026-07-28" : "2025-11-25";
|
|
342
|
-
const initResponse = {
|
|
343
|
-
jsonrpc: "2.0",
|
|
344
|
-
id,
|
|
345
|
-
result: {
|
|
346
|
-
protocolVersion,
|
|
347
|
-
capabilities: {
|
|
348
|
-
tools: { listChanged: true },
|
|
349
|
-
resources: { listChanged: true, subscribe: true },
|
|
350
|
-
prompts: { listChanged: true }
|
|
351
|
-
},
|
|
352
|
-
serverInfo: {
|
|
353
|
-
name: "liop-adaptive-agent",
|
|
354
|
-
version: "2.5.0"
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
process.stdout.write(`${JSON.stringify(initResponse)}
|
|
359
|
-
`);
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
if (method === "notifications/initialized" || method === "notifications/cancelled") {
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
if (method === "ping") {
|
|
366
|
-
process.stdout.write(
|
|
367
|
-
`${JSON.stringify({ jsonrpc: "2.0", id, result: {} })}
|
|
368
|
-
`
|
|
369
|
-
);
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
if (method === "resources/templates/list") {
|
|
373
|
-
const templatesResponse = {
|
|
374
|
-
jsonrpc: "2.0",
|
|
375
|
-
id,
|
|
376
|
-
result: {
|
|
377
|
-
resultType: "complete",
|
|
378
|
-
ttlMs: 3e5,
|
|
379
|
-
cacheScope: "public",
|
|
380
|
-
resourceTemplates: []
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
process.stdout.write(`${JSON.stringify(templatesResponse)}
|
|
384
|
-
`);
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
if (method === "subscriptions/listen") {
|
|
388
|
-
const listenResponse = {
|
|
389
|
-
jsonrpc: "2.0",
|
|
390
|
-
id,
|
|
391
|
-
result: {
|
|
392
|
-
resultType: "complete"
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
process.stdout.write(`${JSON.stringify(listenResponse)}
|
|
396
|
-
`);
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
if (method === "tools/call") {
|
|
400
|
-
const params = request.params;
|
|
401
|
-
if (params?.name === "LiopMeshStatus") {
|
|
402
|
-
const statusResponse = {
|
|
403
|
-
jsonrpc: "2.0",
|
|
404
|
-
id,
|
|
405
|
-
result: {
|
|
406
|
-
content: [
|
|
407
|
-
{
|
|
408
|
-
type: "text",
|
|
409
|
-
text: JSON.stringify({
|
|
410
|
-
mode: "adaptive-gateway",
|
|
411
|
-
gatewayUrl: gateway.baseUrl,
|
|
412
|
-
tier: gateway.tier,
|
|
413
|
-
toolsAvailable: routingTable.getAllToolDefinitions().length,
|
|
414
|
-
authenticated: true,
|
|
415
|
-
status: "ONLINE"
|
|
416
|
-
})
|
|
417
|
-
}
|
|
418
|
-
]
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
process.stdout.write(`${JSON.stringify(statusResponse)}
|
|
422
|
-
`);
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
try {
|
|
427
|
-
const response = await forwardToGateway(
|
|
428
|
-
gateway.mcpEndpoint,
|
|
429
|
-
request,
|
|
430
|
-
tokenManager
|
|
431
|
-
);
|
|
432
|
-
if (method === "tools/list" && response.result && typeof response.result === "object") {
|
|
433
|
-
const resObj = response.result;
|
|
434
|
-
const toolsList = resObj.tools;
|
|
435
|
-
if (Array.isArray(toolsList)) {
|
|
436
|
-
const hasStatus = toolsList.some((t) => t.name === "LiopMeshStatus");
|
|
437
|
-
if (!hasStatus) {
|
|
438
|
-
toolsList.unshift(LIOP_MESH_STATUS_TOOL);
|
|
439
|
-
}
|
|
440
|
-
routingTable.registerGatewayTools(toolsList, gateway.mcpEndpoint);
|
|
441
|
-
}
|
|
442
|
-
if (!isLegacyRequest(request)) {
|
|
443
|
-
if (!resObj.resultType) {
|
|
444
|
-
resObj.resultType = "complete";
|
|
445
|
-
}
|
|
446
|
-
if (!resObj.ttlMs) {
|
|
447
|
-
resObj.ttlMs = 3e5;
|
|
448
|
-
}
|
|
449
|
-
if (!resObj.cacheScope) {
|
|
450
|
-
resObj.cacheScope = "public";
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
process.stdout.write(`${JSON.stringify(response)}
|
|
455
|
-
`);
|
|
456
|
-
} catch (err) {
|
|
457
|
-
if (method === "tools/list") {
|
|
458
|
-
const isLegacy = isLegacyRequest(request);
|
|
459
|
-
const fallbackResult = isLegacy ? { tools: routingTable.getAllToolDefinitions() } : {
|
|
460
|
-
resultType: "complete",
|
|
461
|
-
ttlMs: 3e5,
|
|
462
|
-
cacheScope: "public",
|
|
463
|
-
tools: routingTable.getAllToolDefinitions()
|
|
464
|
-
};
|
|
465
|
-
const fallbackResponse = {
|
|
466
|
-
jsonrpc: "2.0",
|
|
467
|
-
id,
|
|
468
|
-
result: fallbackResult
|
|
469
|
-
};
|
|
470
|
-
process.stdout.write(`${JSON.stringify(fallbackResponse)}
|
|
471
|
-
`);
|
|
472
|
-
} else {
|
|
473
|
-
const errResponse = {
|
|
474
|
-
jsonrpc: "2.0",
|
|
475
|
-
id,
|
|
476
|
-
error: {
|
|
477
|
-
code: -32603,
|
|
478
|
-
message: `Forwarding failed: ${err instanceof Error ? err.message : String(err)}`
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
process.stdout.write(`${JSON.stringify(errResponse)}
|
|
482
|
-
`);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
rl.on("close", () => {
|
|
487
|
-
clearInterval(pollInterval);
|
|
488
|
-
process.exit(0);
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
async function runMeshMode(mesh) {
|
|
492
|
-
log.info(
|
|
493
|
-
`[LIOP-Agent] \u{1F310} Running in P2P MESH MODE (${mesh.bootstrapNodes.length} bootstraps)`
|
|
494
|
-
);
|
|
495
|
-
const liopServer = new LiopServer({
|
|
496
|
-
name: "@nekzus/liop",
|
|
497
|
-
version: "2.5.0"
|
|
498
|
-
});
|
|
499
|
-
liopServer.enableZeroShotAutonomy();
|
|
500
|
-
const meshNode = new MeshNode({
|
|
501
|
-
identityPath: mesh.identityPath,
|
|
502
|
-
bootstrapNodes: mesh.bootstrapNodes,
|
|
503
|
-
addressMapper: shouldEnableDockerMap() ? industrialAddressMapper : void 0
|
|
504
|
-
});
|
|
505
|
-
await meshNode.start();
|
|
506
|
-
const router = new LiopMcpRouter(liopServer, meshNode);
|
|
507
|
-
router.onToolsChanged = () => {
|
|
508
|
-
process.stdout.write(
|
|
509
|
-
`{"jsonrpc":"2.0","method":"notifications/tools/list_changed"}
|
|
510
|
-
`
|
|
511
|
-
);
|
|
512
|
-
process.stdout.write(
|
|
513
|
-
`{"jsonrpc":"2.0","method":"notifications/resources/list_changed"}
|
|
514
|
-
`
|
|
515
|
-
);
|
|
516
|
-
};
|
|
517
|
-
setTimeout(() => {
|
|
518
|
-
router.refreshManifestCache(true).catch(() => {
|
|
519
|
-
});
|
|
520
|
-
}, 2e3);
|
|
521
|
-
const POLL_BASE_MS = 1e4;
|
|
522
|
-
const POLL_MAX_MS = 12e4;
|
|
523
|
-
let pollIntervalMs = POLL_BASE_MS;
|
|
524
|
-
const scheduleAdaptivePoll = () => {
|
|
525
|
-
setTimeout(async () => {
|
|
526
|
-
const prevSize = router.getCacheSize();
|
|
527
|
-
await router.refreshManifestCache(true).catch(() => {
|
|
528
|
-
});
|
|
529
|
-
const newSize = router.getCacheSize();
|
|
530
|
-
if (newSize !== prevSize) {
|
|
531
|
-
pollIntervalMs = POLL_BASE_MS;
|
|
532
|
-
} else {
|
|
533
|
-
pollIntervalMs = Math.min(
|
|
534
|
-
Math.round(pollIntervalMs * 1.5),
|
|
535
|
-
POLL_MAX_MS
|
|
536
|
-
);
|
|
537
|
-
}
|
|
538
|
-
scheduleAdaptivePoll();
|
|
539
|
-
}, pollIntervalMs);
|
|
540
|
-
};
|
|
541
|
-
scheduleAdaptivePoll();
|
|
542
|
-
const rl = readline.createInterface({
|
|
543
|
-
input: process.stdin,
|
|
544
|
-
terminal: false
|
|
545
|
-
});
|
|
546
|
-
process.stdout.on("error", (err) => {
|
|
547
|
-
if (err.code === "EPIPE") process.exit(0);
|
|
548
|
-
});
|
|
549
|
-
rl.on("line", async (line) => {
|
|
550
|
-
const trimmed = line.trim();
|
|
551
|
-
if (!trimmed) return;
|
|
552
|
-
try {
|
|
553
|
-
const request = JSON.parse(trimmed);
|
|
554
|
-
if (request.method) {
|
|
555
|
-
const response = await router.dispatch(request);
|
|
556
|
-
if (response) {
|
|
557
|
-
process.stdout.write(`${JSON.stringify(response)}
|
|
558
|
-
`);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
} catch {
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
rl.on("close", () => process.exit(0));
|
|
565
|
-
process.on("SIGINT", async () => {
|
|
566
|
-
await meshNode.stop();
|
|
567
|
-
process.exit(0);
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
async function runHybridMode(topology, tokenManager, routingTable) {
|
|
571
|
-
const gateway = topology.gateway;
|
|
572
|
-
const mesh = topology.mesh;
|
|
573
|
-
if (!gateway || !mesh) {
|
|
574
|
-
if (gateway) return runGatewayMode(gateway, tokenManager, routingTable);
|
|
575
|
-
if (mesh) return runMeshMode(mesh);
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
log.info(
|
|
579
|
-
`[LIOP-Agent] \u26A1 Running in HYBRID MODE (Gateway: ${gateway.baseUrl} + Mesh P2P)`
|
|
580
|
-
);
|
|
581
|
-
routingTable.registerLocalTool(LIOP_MESH_STATUS_TOOL);
|
|
582
|
-
routingTable.registerGatewayTools(
|
|
583
|
-
gateway.tools.map((t) => ({ name: t })),
|
|
584
|
-
gateway.mcpEndpoint
|
|
585
|
-
);
|
|
586
|
-
let meshNode = null;
|
|
587
|
-
let router = null;
|
|
588
|
-
const initMeshPromise = (async () => {
|
|
589
|
-
try {
|
|
590
|
-
const liopServer = new LiopServer({
|
|
591
|
-
name: "@nekzus/liop-hybrid",
|
|
592
|
-
version: "2.5.0"
|
|
593
|
-
});
|
|
594
|
-
liopServer.enableZeroShotAutonomy();
|
|
595
|
-
meshNode = new MeshNode({
|
|
596
|
-
identityPath: mesh.identityPath,
|
|
597
|
-
bootstrapNodes: mesh.bootstrapNodes,
|
|
598
|
-
addressMapper: shouldEnableDockerMap() ? industrialAddressMapper : void 0
|
|
599
|
-
});
|
|
600
|
-
await meshNode.start();
|
|
601
|
-
router = new LiopMcpRouter(liopServer, meshNode);
|
|
602
|
-
router.onToolsChanged = () => {
|
|
603
|
-
process.stdout.write(
|
|
604
|
-
`{"jsonrpc":"2.0","method":"notifications/tools/list_changed"}
|
|
605
|
-
`
|
|
606
|
-
);
|
|
607
|
-
process.stdout.write(
|
|
608
|
-
`{"jsonrpc":"2.0","method":"notifications/resources/list_changed"}
|
|
609
|
-
`
|
|
610
|
-
);
|
|
611
|
-
};
|
|
612
|
-
await router.refreshManifestCache(true).catch(() => {
|
|
613
|
-
});
|
|
614
|
-
log.info("[LIOP-Agent] \u2705 Background P2P Mesh initialization completed.");
|
|
615
|
-
} catch (err) {
|
|
616
|
-
log.warn(
|
|
617
|
-
`[LIOP-Agent] Background Mesh init warning: ${err instanceof Error ? err.message : String(err)}`
|
|
618
|
-
);
|
|
619
|
-
}
|
|
620
|
-
})();
|
|
621
|
-
const rl = readline.createInterface({
|
|
622
|
-
input: process.stdin,
|
|
623
|
-
terminal: false
|
|
624
|
-
});
|
|
625
|
-
process.stdout.on("error", (err) => {
|
|
626
|
-
if (err.code === "EPIPE") process.exit(0);
|
|
627
|
-
});
|
|
628
|
-
rl.on("line", async (line) => {
|
|
629
|
-
const trimmed = line.trim();
|
|
630
|
-
if (!trimmed) return;
|
|
631
|
-
let request;
|
|
632
|
-
try {
|
|
633
|
-
request = JSON.parse(trimmed);
|
|
634
|
-
} catch {
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
const { id, method } = request;
|
|
638
|
-
if (method === "server/discover") {
|
|
639
|
-
const discoverResponse = {
|
|
640
|
-
jsonrpc: "2.0",
|
|
641
|
-
id,
|
|
642
|
-
result: {
|
|
643
|
-
resultType: "complete",
|
|
644
|
-
supportedVersions: ["2026-07-28", "2025-11-25"],
|
|
645
|
-
capabilities: {
|
|
646
|
-
tools: { listChanged: true },
|
|
647
|
-
resources: { listChanged: true, subscribe: true },
|
|
648
|
-
prompts: { listChanged: true }
|
|
649
|
-
},
|
|
650
|
-
serverInfo: {
|
|
651
|
-
name: "liop-hybrid-agent",
|
|
652
|
-
version: "2.5.0"
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
process.stdout.write(`${JSON.stringify(discoverResponse)}
|
|
657
|
-
`);
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
if (method === "initialize") {
|
|
661
|
-
const clientVersion = request.params?.protocolVersion ?? request.params?._meta?.["io.modelcontextprotocol/protocolVersion"];
|
|
662
|
-
const protocolVersion = clientVersion === "2026-07-28" ? "2026-07-28" : "2025-11-25";
|
|
663
|
-
const initResponse = {
|
|
664
|
-
jsonrpc: "2.0",
|
|
665
|
-
id,
|
|
666
|
-
result: {
|
|
667
|
-
protocolVersion,
|
|
668
|
-
capabilities: {
|
|
669
|
-
tools: { listChanged: true },
|
|
670
|
-
resources: { listChanged: true, subscribe: true },
|
|
671
|
-
prompts: { listChanged: true }
|
|
672
|
-
},
|
|
673
|
-
serverInfo: {
|
|
674
|
-
name: "liop-hybrid-agent",
|
|
675
|
-
version: "2.5.0"
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
process.stdout.write(`${JSON.stringify(initResponse)}
|
|
680
|
-
`);
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
if (method === "notifications/initialized" || method === "notifications/cancelled") {
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
if (method === "ping") {
|
|
687
|
-
process.stdout.write(
|
|
688
|
-
`${JSON.stringify({ jsonrpc: "2.0", id, result: {} })}
|
|
689
|
-
`
|
|
690
|
-
);
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
if (method === "resources/templates/list") {
|
|
694
|
-
const templatesResponse = {
|
|
695
|
-
jsonrpc: "2.0",
|
|
696
|
-
id,
|
|
697
|
-
result: {
|
|
698
|
-
resultType: "complete",
|
|
699
|
-
ttlMs: 3e5,
|
|
700
|
-
cacheScope: "public",
|
|
701
|
-
resourceTemplates: []
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
process.stdout.write(`${JSON.stringify(templatesResponse)}
|
|
705
|
-
`);
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
if (method === "subscriptions/listen") {
|
|
709
|
-
const listenResponse = {
|
|
710
|
-
jsonrpc: "2.0",
|
|
711
|
-
id,
|
|
712
|
-
result: {
|
|
713
|
-
resultType: "complete"
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
process.stdout.write(`${JSON.stringify(listenResponse)}
|
|
717
|
-
`);
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
if (method === "tools/call") {
|
|
721
|
-
const params = request.params;
|
|
722
|
-
const toolName = params?.name || "";
|
|
723
|
-
const route = routingTable.resolve(toolName);
|
|
724
|
-
if (route?.provider === "http-gateway") {
|
|
725
|
-
const start = Date.now();
|
|
726
|
-
try {
|
|
727
|
-
const res = await forwardToGateway(
|
|
728
|
-
gateway.mcpEndpoint,
|
|
729
|
-
request,
|
|
730
|
-
tokenManager
|
|
731
|
-
);
|
|
732
|
-
routingTable.recordSuccess(toolName, Date.now() - start);
|
|
733
|
-
process.stdout.write(`${JSON.stringify(res)}
|
|
734
|
-
`);
|
|
735
|
-
return;
|
|
736
|
-
} catch (_err) {
|
|
737
|
-
routingTable.recordFailure(toolName);
|
|
738
|
-
log.warn(
|
|
739
|
-
`[LIOP-Agent] Gateway call failed for '${toolName}'. Checking P2P fallback...`
|
|
740
|
-
);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
await initMeshPromise;
|
|
744
|
-
if (router) {
|
|
745
|
-
const res = await router.dispatch(request);
|
|
746
|
-
if (res) process.stdout.write(`${JSON.stringify(res)}
|
|
747
|
-
`);
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
if (method === "tools/list") {
|
|
752
|
-
let gatewayTools = [];
|
|
753
|
-
try {
|
|
754
|
-
const gwRes = await forwardToGateway(
|
|
755
|
-
gateway.mcpEndpoint,
|
|
756
|
-
request,
|
|
757
|
-
tokenManager
|
|
758
|
-
);
|
|
759
|
-
const resObj = gwRes.result;
|
|
760
|
-
if (Array.isArray(resObj?.tools)) {
|
|
761
|
-
gatewayTools = resObj.tools;
|
|
762
|
-
routingTable.registerGatewayTools(gatewayTools, gateway.mcpEndpoint);
|
|
763
|
-
}
|
|
764
|
-
} catch {
|
|
765
|
-
gatewayTools = routingTable.getAllToolDefinitions();
|
|
766
|
-
}
|
|
767
|
-
let meshTools = [];
|
|
768
|
-
if (router) {
|
|
769
|
-
const meshRes = await router.dispatch(request);
|
|
770
|
-
const meshObj = meshRes?.result;
|
|
771
|
-
if (Array.isArray(meshObj?.tools)) {
|
|
772
|
-
meshTools = meshObj.tools;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
const toolMap = /* @__PURE__ */ new Map();
|
|
776
|
-
toolMap.set("LiopMeshStatus", LIOP_MESH_STATUS_TOOL);
|
|
777
|
-
for (const t of gatewayTools) toolMap.set(t.name, t);
|
|
778
|
-
for (const t of meshTools)
|
|
779
|
-
if (!toolMap.has(t.name)) toolMap.set(t.name, t);
|
|
780
|
-
const merged = Array.from(toolMap.values()).sort(
|
|
781
|
-
(a, b) => a.name.localeCompare(b.name)
|
|
782
|
-
);
|
|
783
|
-
const isLegacy = isLegacyRequest(request);
|
|
784
|
-
const toolsResult = isLegacy ? { tools: merged } : {
|
|
785
|
-
resultType: "complete",
|
|
786
|
-
ttlMs: 3e5,
|
|
787
|
-
cacheScope: "public",
|
|
788
|
-
tools: merged
|
|
789
|
-
};
|
|
790
|
-
process.stdout.write(
|
|
791
|
-
`${JSON.stringify({ jsonrpc: "2.0", id, result: toolsResult })}
|
|
792
|
-
`
|
|
793
|
-
);
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
try {
|
|
797
|
-
const res = await forwardToGateway(
|
|
798
|
-
gateway.mcpEndpoint,
|
|
799
|
-
request,
|
|
800
|
-
tokenManager
|
|
801
|
-
);
|
|
802
|
-
if (!isLegacyRequest(request) && res.result && typeof res.result === "object") {
|
|
803
|
-
const resObj = res.result;
|
|
804
|
-
if (!resObj.resultType) {
|
|
805
|
-
resObj.resultType = "complete";
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
process.stdout.write(`${JSON.stringify(res)}
|
|
809
|
-
`);
|
|
810
|
-
} catch {
|
|
811
|
-
await initMeshPromise;
|
|
812
|
-
if (router) {
|
|
813
|
-
const res = await router.dispatch(request);
|
|
814
|
-
if (res) process.stdout.write(`${JSON.stringify(res)}
|
|
815
|
-
`);
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
rl.on("close", async () => {
|
|
820
|
-
if (meshNode) await meshNode.stop();
|
|
821
|
-
process.exit(0);
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
|
-
async function main() {
|
|
825
|
-
if ((process.platform === "win32" || process.platform === "darwin") && !process.execArgv.includes("--use-system-ca") && !(process.env.NODE_OPTIONS ?? "").includes("--use-system-ca")) {
|
|
826
|
-
const { spawn } = await import('child_process');
|
|
827
|
-
const child = spawn(
|
|
828
|
-
process.execPath,
|
|
829
|
-
["--use-system-ca", ...process.argv.slice(1)],
|
|
830
|
-
{ stdio: "inherit", env: process.env }
|
|
831
|
-
);
|
|
832
|
-
child.on("exit", (code) => process.exit(code ?? 1));
|
|
833
|
-
child.on("error", () => process.exit(1));
|
|
834
|
-
await new Promise(() => {
|
|
835
|
-
});
|
|
836
|
-
return;
|
|
837
|
-
}
|
|
838
|
-
const buildTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
839
|
-
log.info(
|
|
840
|
-
`[LIOP-Agent] \u{1F680} Version 2.5.0 (Adaptive Zero-Config) | Build: ${buildTime}`
|
|
841
|
-
);
|
|
842
|
-
const liopDir = path.join(os.homedir(), ".liop");
|
|
843
|
-
const identityPath = path.join(liopDir, "identity.json");
|
|
844
|
-
if (!fs.existsSync(liopDir)) {
|
|
845
|
-
fs.mkdirSync(liopDir, { recursive: true });
|
|
846
|
-
}
|
|
847
|
-
const bootstrapNodes = await resolveBootstrapNodes(liopDir);
|
|
848
|
-
const blgUrl = process.env.LIOP_BLG_URL;
|
|
849
|
-
const nexusUrl = process.env.LIOP_NEXUS_URL;
|
|
850
|
-
const clientId = process.env.LIOP_CLIENT_ID || process.env.LIOP_OAUTH_CLIENT_ID || "liop-agent";
|
|
851
|
-
const clientSecret = process.env.LIOP_CLIENT_SECRET || process.env.LIOP_OAUTH_CLIENT_SECRET || "dev-secret-change-me";
|
|
852
|
-
const staticToken = process.env.LIOP_TOKEN || process.env.LIOP_OAUTH_TOKEN;
|
|
853
|
-
const topology = await probeTopology({
|
|
854
|
-
blgUrl,
|
|
855
|
-
nexusUrl,
|
|
856
|
-
clientId,
|
|
857
|
-
clientSecret,
|
|
858
|
-
staticToken,
|
|
859
|
-
bootstrapNodes,
|
|
860
|
-
identityPath
|
|
861
|
-
});
|
|
862
|
-
const routingTable = new RoutingTable();
|
|
863
|
-
const tokenManager = new TokenManager({
|
|
864
|
-
tokenEndpoint: topology.gateway?.tokenEndpoint || `${nexusUrl || "http://127.0.0.1:15000"}/oidc/token`,
|
|
865
|
-
clientId,
|
|
866
|
-
clientSecret,
|
|
867
|
-
audience: topology.gateway?.audience,
|
|
868
|
-
scopes: topology.gateway?.scopes,
|
|
869
|
-
staticToken
|
|
870
|
-
});
|
|
871
|
-
switch (topology.mode) {
|
|
872
|
-
case "gateway":
|
|
873
|
-
if (!topology.gateway)
|
|
874
|
-
throw new Error(
|
|
875
|
-
"Topology probe indicated gateway mode without gateway info."
|
|
876
|
-
);
|
|
877
|
-
await runGatewayMode(topology.gateway, tokenManager, routingTable);
|
|
878
|
-
break;
|
|
879
|
-
case "mesh":
|
|
880
|
-
if (!topology.mesh)
|
|
881
|
-
throw new Error(
|
|
882
|
-
"Topology probe indicated mesh mode without mesh info."
|
|
883
|
-
);
|
|
884
|
-
await runMeshMode(topology.mesh);
|
|
885
|
-
break;
|
|
886
|
-
case "hybrid":
|
|
887
|
-
await runHybridMode(topology, tokenManager, routingTable);
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
main().catch((err) => {
|
|
892
|
-
log.error(`[LIOP-Agent] Fatal Error: ${err.message}`);
|
|
893
|
-
process.exit(1);
|
|
894
|
-
});
|
|
895
|
-
//# sourceMappingURL=agent.js.map
|
|
2
|
+
import {b as b$2,a as a$3}from'../chunk-2XHSALII.js';import {a as a$4}from'../chunk-N35BC62H.js';import {m}from'../chunk-YD2AF2M6.js';import'../chunk-MQ5SU26J.js';import {a as a$2}from'../chunk-LM26HOJ6.js';import'../chunk-6KFKO6ZX.js';import'../chunk-TKLRW52V.js';import'../chunk-Y675R34Z.js';import'../chunk-XLVEDKM6.js';import'../chunk-2ZYX736J.js';import'../chunk-ECRS6N33.js';import'../chunk-ZZMSFCJP.js';import {g,f,d}from'../chunk-GWVSCZUS.js';import'../chunk-6VK2XALI.js';import'../chunk-FTF6AMF6.js';import'../chunk-YLCNV764.js';import {a as a$1}from'../chunk-V35CXJQN.js';import {b as b$1}from'../chunk-3WRKTVOF.js';import {a}from'../chunk-AYDF3IFZ.js';import*as L from'fs';import*as G from'os';import*as R from'path';import*as N from'readline';import {multiaddr}from'@multiformats/multiaddr';var b={name:"LiopMeshStatus",description:"LiopMeshStatus: Returns the current dynamic diagnostic status of the Zero-Trust Neural Mesh.",inputSchema:{type:"object",properties:{},additionalProperties:false}};async function F(e){try{let s=e.endsWith("/health")?e:`${e}/health`,a=await fetch(s,{headers:{Accept:"application/json"},signal:AbortSignal.timeout(1e4)});if(!a.ok)return null;let n=await a.json();if(!n.mesh?.multiaddrs?.length||!n.mesh?.peerId)return null;let c=n.mesh.multiaddrs.find(t=>t.includes("/tcp/")&&!t.includes("/ws")&&!t.includes("/ip4/127.0.0.1/"));if(!c)return null;let i=C()?k(c):c;if(!i||i===c){let t=new URL(e).hostname;i=c.replace(/\/ip4\/[^/]+/,`/ip4/${t}`);}return i?(i+=i.includes("/p2p/")?"":`/p2p/${n.mesh.peerId}`,i):null}catch{return null}}a(F,"resolveBootstrapFromUrl");function V(e){let s=e.trim(),a=/\/ip4\/172\.(1[6-9]|2[0-9]|3[0-1])\.[0-9]{1,3}\.[0-9]{1,3}/,n=/\/ip4\/127\.0\.0\.1/,c=/\/ip4\/192\.168\.[0-9]{1,3}\.[0-9]{1,3}/;if(a.test(s)||n.test(s)||c.test(s)){let i="127.0.0.1",t=s.replace(a,`/ip4/${i}`).replace(n,`/ip4/${i}`).replace(c,`/ip4/${i}`);return t!==s&&b$1.info(`[LIOP-Agent] \u{1F504} Local Routing Hack \u2192 Forced 127.0.0.1: ${t}`),t}return s}a(V,"normalizeBootstrap");function k(e){return e.includes("/ip4/172.23.0.10")?e.replace(/\/ip4\/172\.23\.0\.10\/tcp\/[0-9]+/,"/ip4/127.0.0.1/tcp/15001"):e.includes("/ip4/172.23.0.20")?e.replace(/\/ip4\/172\.23\.0\.20\/tcp\/[0-9]+/,"/ip4/127.0.0.1/tcp/15011"):e.includes("/ip4/172.21.0.13")?e.replace(/\/ip4\/172\.21\.0\.13\/tcp\/[0-9]+/,"/ip4/127.0.0.1/tcp/15031"):e.includes("/ip4/172.21.0.14")?e.replace(/\/ip4\/172\.21\.0\.14\/tcp\/[0-9]+/,"/ip4/127.0.0.1/tcp/15041"):e.includes("/ip4/172.20.0.10")?e.replace(/\/ip4\/172\.20\.0\.10\/tcp\/[0-9]+/,"/ip4/127.0.0.1/tcp/13001"):e.includes("/ip4/172.20.0.11")?e.replace(/\/ip4\/172\.20\.0\.11\/tcp\/[0-9]+/,"/ip4/127.0.0.1/tcp/13003"):e.includes("/ip4/172.20.0.12")?e.replace(/\/ip4\/172\.20\.0\.12\/tcp\/[0-9]+/,"/ip4/127.0.0.1/tcp/13004"):e.includes("/ip4/172.20.0.13")?e.replace(/\/ip4\/172\.20\.0\.13\/tcp\/[0-9]+/,"/ip4/127.0.0.1/tcp/13005"):e.includes("/ip4/127.0.0.1/tcp/4000")||e.includes("/ip4/127.0.0.1/tcp/3000")?null:e}a(k,"industrialAddressMapper");function q(e){try{let s=new URL(e);return (s.hostname==="127.0.0.1"||s.hostname==="localhost")&&(s.port==="13000"||s.port==="13001"||s.port==="15000"||s.port==="15018")}catch{return false}}a(q,"isDockerDemoHost");function C(){return process.env.NODE_ENV==="development"||process.env.NODE_ENV==="test"||process.env.LIOP_DOCKER_MAP==="true"||process.env.LIOP_DEV_MODE==="true"||!!process.env.LIOP_NEXUS_URL&&q(process.env.LIOP_NEXUS_URL)}a(C,"shouldEnableDockerMap");async function X(e){let s=[],a=process.argv.slice(2);if(a.length>0&&(s=a.filter(n=>n.startsWith("/"))),process.env.LIOP_NEXUS_URL||process.env.LIOP_BLG_URL){let n=process.env.LIOP_NEXUS_URL||process.env.LIOP_BLG_URL;if(n){let c=await F(n);if(c){let i=V(c);s.includes(i)||(s.push(i),b$1.info(`[LIOP-Agent] \u2705 Added bootstrap from URL discovery: ${i}`));}}}if(s.length===0){let n=[process.cwd(),R.join(process.cwd(),"tests/infra/nexus-data"),e,R.join(R.dirname(new URL(import.meta.url).pathname).replace(/^\/([A-Z]:)/,"$1"),"../../tests/infra/nexus-data")];for(let c of n)try{if(L.existsSync(c)){let t=L.readdirSync(c).filter(l=>l.endsWith(".multiaddr"));for(let l of t){let d=R.join(c,l),r=L.readFileSync(d,"utf8").trim();if(r){let m=V(r);s.includes(m)||(s.push(m),b$1.info(`[LIOP-Agent] \u2705 Loaded beacon: ${l} from ${c}`));}}if(s.length>0)break}}catch{}}return s.length===0&&process.env.LIOP_BOOTSTRAP&&s.push(process.env.LIOP_BOOTSTRAP.trim()),s.filter(n=>{try{return multiaddr(n),!0}catch{return false}})}a(X,"resolveBootstrapNodes");async function _(e,s,a$1){let n=a(async t=>{let l={"Content-Type":"application/json"};t&&(l.Authorization=`Bearer ${t}`),s.method&&(l["Mcp-Method"]=s.method);let d=s.params;return d?.name&&(l["Mcp-Name"]=d.name),await fetch(e,{method:"POST",headers:l,body:JSON.stringify(s),signal:AbortSignal.timeout(3e4)})},"send"),c;try{c=await a$1.getToken();}catch(t){b$1.warn(`[LIOP-Agent] Token acquisition warning: ${t instanceof Error?t.message:String(t)}`);}let i=await n(c);if(i.status===401&&c){b$1.info("[LIOP-Agent] \u{1F504} 401 received from Gateway. Refreshing token and retrying..."),a$1.invalidate();try{c=await a$1.getToken(),i=await n(c);}catch{}}if(!i.ok){let t=await i.text(),l=null;try{l=JSON.parse(t);}catch{}let d=l?.error;return {jsonrpc:"2.0",id:s.id,error:{code:d?.code??-32603,message:d?.message??`Gateway returned HTTP ${i.status}: ${t}`}}}return await i.json()}a(_,"forwardToGateway");async function z(e,s,a){b$1.info(`[LIOP-Agent] \u{1F6E1}\uFE0F Running in ADAPTIVE GATEWAY MODE -> ${e.mcpEndpoint}`),a.registerLocalTool(b),a.registerGatewayTools(e.tools.map(t=>({name:t})),e.mcpEndpoint);let n=e.tools.length,c=setInterval(async()=>{try{let t=await fetch(e.healthEndpoint,{headers:{Accept:"application/json"},signal:AbortSignal.timeout(4e3)});if(t.ok){let l=await t.json();l.tools&&l.tools.length!==n&&(b$1.info(`[LIOP-Agent] Gateway tools topology updated (${n} -> ${l.tools.length})`),n=l.tools.length,a.registerGatewayTools(l.tools.map(d=>({name:d})),e.mcpEndpoint),process.stdout.write(`{"jsonrpc":"2.0","method":"notifications/tools/list_changed"}
|
|
3
|
+
`),process.stdout.write(`{"jsonrpc":"2.0","method":"notifications/resources/list_changed"}
|
|
4
|
+
`));}}catch{}},15e3),i=N.createInterface({input:process.stdin,terminal:false});process.stdout.on("error",t=>{t.code==="EPIPE"&&(clearInterval(c),process.exit(0));}),i.on("line",async t=>{let l=t.trim();if(!l)return;let d$1;try{d$1=JSON.parse(l);}catch{return}let{id:r,method:m}=d$1;if(m==="server/discover"){let o={jsonrpc:"2.0",id:r,result:{resultType:"complete",supportedVersions:["2026-07-28","2025-11-25"],capabilities:{tools:{listChanged:true},resources:{listChanged:true,subscribe:true},prompts:{listChanged:true}},serverInfo:{name:"liop-adaptive-agent",version:"2.5.0"}}};process.stdout.write(`${JSON.stringify(o)}
|
|
5
|
+
`);return}if(m==="initialize"){let u=(d$1.params?.protocolVersion??d$1.params?._meta?.["io.modelcontextprotocol/protocolVersion"])==="2026-07-28"?"2026-07-28":"2025-11-25",f={jsonrpc:"2.0",id:r,result:{protocolVersion:u,capabilities:{tools:{listChanged:true},resources:{listChanged:true,subscribe:true},prompts:{listChanged:true}},serverInfo:{name:"liop-adaptive-agent",version:"2.5.0"}}};process.stdout.write(`${JSON.stringify(f)}
|
|
6
|
+
`);return}if(!(m==="notifications/initialized"||m==="notifications/cancelled")){if(m==="ping"){process.stdout.write(`${JSON.stringify({jsonrpc:"2.0",id:r,result:{}})}
|
|
7
|
+
`);return}if(m==="resources/templates/list"){let o={jsonrpc:"2.0",id:r,result:{resultType:"complete",ttlMs:3e5,cacheScope:"public",resourceTemplates:[]}};process.stdout.write(`${JSON.stringify(o)}
|
|
8
|
+
`);return}if(m==="subscriptions/listen"){let o={jsonrpc:"2.0",id:r,result:{resultType:"complete"}};process.stdout.write(`${JSON.stringify(o)}
|
|
9
|
+
`);return}if(m==="tools/call"){let o=d$1.params;if(o?.arguments&&(o.arguments=g(o.arguments)),o?.name){let u=f[o.name]||o.name;o.name=u;}if(o?.name==="LiopMeshStatus"){let u={jsonrpc:"2.0",id:r,result:{content:[{type:"text",text:JSON.stringify({mode:"adaptive-gateway",gatewayUrl:e.baseUrl,tier:e.tier,toolsAvailable:a.getAllToolDefinitions().length,authenticated:true,status:"ONLINE"})}]}};process.stdout.write(`${JSON.stringify(u)}
|
|
10
|
+
`);return}}try{let o=await _(e.mcpEndpoint,d$1,s);if(m==="tools/list"&&o.result&&typeof o.result=="object"){let u=o.result,f$1=u.tools;if(Array.isArray(f$1)){f$1.some(y=>y.name==="LiopMeshStatus")||f$1.unshift(b);for(let[y,h]of Object.entries(f)){let S=f$1.find(P=>P.name===h);S&&!f$1.some(P=>P.name===y)&&f$1.push({...S,name:y,description:`[Alias -> ${h}] ${S.description||""}`.trim()});}a.registerGatewayTools(f$1,e.mcpEndpoint);}d(d$1)||(u.resultType||(u.resultType="complete"),u.ttlMs||(u.ttlMs=3e5),u.cacheScope||(u.cacheScope="public"));}process.stdout.write(`${JSON.stringify(o)}
|
|
11
|
+
`);}catch(o){if(m==="tools/list"){let f=d(d$1)?{tools:a.getAllToolDefinitions()}:{resultType:"complete",ttlMs:3e5,cacheScope:"public",tools:a.getAllToolDefinitions()},p={jsonrpc:"2.0",id:r,result:f};process.stdout.write(`${JSON.stringify(p)}
|
|
12
|
+
`);}else {let u={jsonrpc:"2.0",id:r,error:{code:-32603,message:`Forwarding failed: ${o instanceof Error?o.message:String(o)}`}};process.stdout.write(`${JSON.stringify(u)}
|
|
13
|
+
`);}}}}),i.on("close",()=>{clearInterval(c),process.exit(0);});}a(z,"runGatewayMode");async function B(e){b$1.info(`[LIOP-Agent] \u{1F310} Running in P2P MESH MODE (${e.bootstrapNodes.length} bootstraps)`);let s=new m({name:"@nekzus/liop",version:"2.5.0"});s.enableZeroShotAutonomy();let a$3=new a$1({identityPath:e.identityPath,bootstrapNodes:e.bootstrapNodes,addressMapper:C()?k:void 0});await a$3.start();let n=new a$2(s,a$3);n.onToolsChanged=()=>{process.stdout.write(`{"jsonrpc":"2.0","method":"notifications/tools/list_changed"}
|
|
14
|
+
`),process.stdout.write(`{"jsonrpc":"2.0","method":"notifications/resources/list_changed"}
|
|
15
|
+
`);},setTimeout(()=>{n.refreshManifestCache(true).catch(()=>{});},2e3);let c=1e4,i=12e4,t=c,l=a(()=>{setTimeout(async()=>{let r=n.getCacheSize();await n.refreshManifestCache(true).catch(()=>{}),n.getCacheSize()!==r?t=c:t=Math.min(Math.round(t*1.5),i),l();},t);},"scheduleAdaptivePoll");l();let d=N.createInterface({input:process.stdin,terminal:false});process.stdout.on("error",r=>{r.code==="EPIPE"&&process.exit(0);}),d.on("line",async r=>{let m=r.trim();if(m)try{let o=JSON.parse(m);if(o.method){let u=await n.dispatch(o);u&&process.stdout.write(`${JSON.stringify(u)}
|
|
16
|
+
`);}}catch{}}),d.on("close",()=>process.exit(0)),process.on("SIGINT",async()=>{await a$3.stop(),process.exit(0);});}a(B,"runMeshMode");async function Z(e,s,a){let n=e.gateway,c=e.mesh;if(!n||!c)return n?z(n,s,a):c?B(c):void 0;b$1.info(`[LIOP-Agent] \u26A1 Running in HYBRID MODE (Gateway: ${n.baseUrl} + Mesh P2P)`),a.registerLocalTool(b),a.registerGatewayTools(n.tools.map(r=>({name:r})),n.mcpEndpoint);let i=null,t=null,l=(async()=>{try{let r=new m({name:"@nekzus/liop-hybrid",version:"2.5.0"});r.enableZeroShotAutonomy(),i=new a$1({identityPath:c.identityPath,bootstrapNodes:c.bootstrapNodes,addressMapper:C()?k:void 0}),await i.start(),t=new a$2(r,i),t.onToolsChanged=()=>{process.stdout.write(`{"jsonrpc":"2.0","method":"notifications/tools/list_changed"}
|
|
17
|
+
`),process.stdout.write(`{"jsonrpc":"2.0","method":"notifications/resources/list_changed"}
|
|
18
|
+
`);},await t.refreshManifestCache(!0).catch(()=>{}),b$1.info("[LIOP-Agent] \u2705 Background P2P Mesh initialization completed.");}catch(r){b$1.warn(`[LIOP-Agent] Background Mesh init warning: ${r instanceof Error?r.message:String(r)}`);}})(),d$1=N.createInterface({input:process.stdin,terminal:false});process.stdout.on("error",r=>{r.code==="EPIPE"&&process.exit(0);}),d$1.on("line",async r=>{let m=r.trim();if(!m)return;let o;try{o=JSON.parse(m);}catch{return}let{id:u,method:f$1}=o;if(f$1==="server/discover"){let p={jsonrpc:"2.0",id:u,result:{resultType:"complete",supportedVersions:["2026-07-28","2025-11-25"],capabilities:{tools:{listChanged:true},resources:{listChanged:true,subscribe:true},prompts:{listChanged:true}},serverInfo:{name:"liop-hybrid-agent",version:"2.5.0"}}};process.stdout.write(`${JSON.stringify(p)}
|
|
19
|
+
`);return}if(f$1==="initialize"){let y=(o.params?.protocolVersion??o.params?._meta?.["io.modelcontextprotocol/protocolVersion"])==="2026-07-28"?"2026-07-28":"2025-11-25",h={jsonrpc:"2.0",id:u,result:{protocolVersion:y,capabilities:{tools:{listChanged:true},resources:{listChanged:true,subscribe:true},prompts:{listChanged:true}},serverInfo:{name:"liop-hybrid-agent",version:"2.5.0"}}};process.stdout.write(`${JSON.stringify(h)}
|
|
20
|
+
`);return}if(!(f$1==="notifications/initialized"||f$1==="notifications/cancelled")){if(f$1==="ping"){process.stdout.write(`${JSON.stringify({jsonrpc:"2.0",id:u,result:{}})}
|
|
21
|
+
`);return}if(f$1==="resources/templates/list"){let p={jsonrpc:"2.0",id:u,result:{resultType:"complete",ttlMs:3e5,cacheScope:"public",resourceTemplates:[]}};process.stdout.write(`${JSON.stringify(p)}
|
|
22
|
+
`);return}if(f$1==="subscriptions/listen"){let p={jsonrpc:"2.0",id:u,result:{resultType:"complete"}};process.stdout.write(`${JSON.stringify(p)}
|
|
23
|
+
`);return}if(f$1==="tools/call"){let p=o.params;p?.arguments&&(p.arguments=g(p.arguments));let y=p?.name||"",h=f[y]||y;p?.name&&(p.name=h);let S=h;if(a.resolve(S)?.provider==="http-gateway"){let I=Date.now();try{let g=await _(n.mcpEndpoint,o,s);a.recordSuccess(S,Date.now()-I),process.stdout.write(`${JSON.stringify(g)}
|
|
24
|
+
`);return}catch{a.recordFailure(S),b$1.warn(`[LIOP-Agent] Gateway call failed for '${S}'. Checking P2P fallback...`);}}if(await l,t){let I=await t.dispatch(o);I&&process.stdout.write(`${JSON.stringify(I)}
|
|
25
|
+
`);return}}if(f$1==="tools/list"){let p=[];try{let T=(await _(n.mcpEndpoint,o,s)).result;Array.isArray(T?.tools)&&(p=T.tools,a.registerGatewayTools(p,n.mcpEndpoint));}catch{p=a.getAllToolDefinitions();}let y=[];if(t){let T=(await t.dispatch(o))?.result;Array.isArray(T?.tools)&&(y=T.tools);}let h=new Map;h.set("LiopMeshStatus",b);for(let g of p)h.set(g.name,g);for(let g of y)h.has(g.name)||h.set(g.name,g);for(let[g,T]of Object.entries(f)){let E=h.get(T);E&&!h.has(g)&&h.set(g,{...E,name:g,description:`[Alias -> ${T}] ${E.description||""}`.trim()});}let S=Array.from(h.values()).sort((g,T)=>g.name.localeCompare(T.name)),I=d(o)?{tools:S}:{resultType:"complete",ttlMs:3e5,cacheScope:"public",tools:S};process.stdout.write(`${JSON.stringify({jsonrpc:"2.0",id:u,result:I})}
|
|
26
|
+
`);return}try{let p=await _(n.mcpEndpoint,o,s);if(!d(o)&&p.result&&typeof p.result=="object"){let y=p.result;y.resultType||(y.resultType="complete");}process.stdout.write(`${JSON.stringify(p)}
|
|
27
|
+
`);}catch{if(await l,t){let p=await t.dispatch(o);p&&process.stdout.write(`${JSON.stringify(p)}
|
|
28
|
+
`);}}}}),d$1.on("close",async()=>{i&&await i.stop(),process.exit(0);});}a(Z,"runHybridMode");async function W(){if((process.platform==="win32"||process.platform==="darwin")&&!process.execArgv.includes("--use-system-ca")&&!(process.env.NODE_OPTIONS??"").includes("--use-system-ca")){let{spawn:u}=await import('child_process'),f=u(process.execPath,["--use-system-ca",...process.argv.slice(1)],{stdio:"inherit",env:process.env});f.on("exit",p=>process.exit(p??1)),f.on("error",()=>process.exit(1)),await new Promise(()=>{});return}let e=new Date().toISOString();b$1.info(`[LIOP-Agent] \u{1F680} Version 2.5.0 (Adaptive Zero-Config) | Build: ${e}`);let s=R.join(G.homedir(),".liop"),a=R.join(s,"identity.json");L.existsSync(s)||L.mkdirSync(s,{recursive:true});let n=await X(s),c=process.env.LIOP_BLG_URL,i=process.env.LIOP_NEXUS_URL,t=process.env.LIOP_CLIENT_ID||process.env.LIOP_OAUTH_CLIENT_ID||"liop-agent",l=process.env.LIOP_CLIENT_SECRET||process.env.LIOP_OAUTH_CLIENT_SECRET||"dev-secret-change-me",d=process.env.LIOP_TOKEN||process.env.LIOP_OAUTH_TOKEN,r=await b$2({blgUrl:c,nexusUrl:i,clientId:t,clientSecret:l,staticToken:d,bootstrapNodes:n,identityPath:a}),m=new a$3,o=new a$4({tokenEndpoint:r.gateway?.tokenEndpoint||`${i||"http://127.0.0.1:15000"}/oidc/token`,clientId:t,clientSecret:l,audience:r.gateway?.audience,scopes:r.gateway?.scopes,staticToken:d});switch(r.mode){case "gateway":if(!r.gateway)throw new Error("Topology probe indicated gateway mode without gateway info.");await z(r.gateway,o,m);break;case "mesh":if(!r.mesh)throw new Error("Topology probe indicated mesh mode without mesh info.");await B(r.mesh);break;case "hybrid":await Z(r,o,m);break}}a(W,"main");W().catch(e=>{b$1.error(`[LIOP-Agent] Fatal Error: ${e.message}`),process.exit(1);});//# sourceMappingURL=agent.js.map
|
|
896
29
|
//# sourceMappingURL=agent.js.map
|