@nekzus/liop 2.4.0-alpha.7 → 2.4.0-alpha.8
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/NOTICE +19 -0
- package/README.md +36 -17
- package/dist/bin/agent.js +674 -82
- package/dist/bin/agent.js.map +1 -1
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +3 -3
- package/dist/{chunk-T5IUZF47.js → chunk-3L2O2XKG.js} +12 -5
- package/dist/chunk-3L2O2XKG.js.map +1 -0
- package/dist/{chunk-SONUORBT.js → chunk-7BSCUYUE.js} +2 -2
- package/dist/chunk-7BSCUYUE.js.map +1 -0
- package/dist/{chunk-QLCOEP5J.js → chunk-7PITYWOV.js} +2 -2
- package/dist/chunk-7PITYWOV.js.map +1 -0
- package/dist/{chunk-74CISO2I.js → chunk-7RXOIDXP.js} +28 -4
- package/dist/chunk-7RXOIDXP.js.map +1 -0
- package/dist/{chunk-GA3Q2S7O.js → chunk-BOISQ45Z.js} +5 -5
- package/dist/chunk-BOISQ45Z.js.map +1 -0
- package/dist/{chunk-547TYL27.js → chunk-DZ2FQGJD.js} +26 -1423
- package/dist/chunk-DZ2FQGJD.js.map +1 -0
- package/dist/{chunk-PYKRQAER.js → chunk-EG46XMJT.js} +2 -2
- package/dist/chunk-EG46XMJT.js.map +1 -0
- package/dist/chunk-ESRXG36Y.js +115 -0
- package/dist/chunk-ESRXG36Y.js.map +1 -0
- package/dist/chunk-FTF6AMF6.js +3 -0
- package/dist/{chunk-RWRRBYG4.js.map → chunk-FTF6AMF6.js.map} +1 -1
- package/dist/{chunk-72MNYFR6.js → chunk-HA6YZ42O.js} +2 -2
- package/dist/chunk-HA6YZ42O.js.map +1 -0
- package/dist/{chunk-WCCGE4QR.js → chunk-HD2N3IJX.js} +144 -30
- package/dist/chunk-HD2N3IJX.js.map +1 -0
- package/dist/{chunk-OUUTDSOW.js → chunk-IK7CGWAZ.js} +3 -3
- package/dist/chunk-IK7CGWAZ.js.map +1 -0
- package/dist/chunk-L6J72C5X.js +1477 -0
- package/dist/chunk-L6J72C5X.js.map +1 -0
- package/dist/{chunk-U5BZ66VX.js → chunk-PAICJCKJ.js} +60 -175
- package/dist/chunk-PAICJCKJ.js.map +1 -0
- package/dist/{chunk-32ADSAJS.js → chunk-PEN3KFLF.js} +14 -4
- package/dist/chunk-PEN3KFLF.js.map +1 -0
- package/dist/{chunk-CRZBVFDV.js → chunk-T7R5HUFD.js} +225 -66
- package/dist/chunk-T7R5HUFD.js.map +1 -0
- package/dist/{chunk-WSW6YJNY.js → chunk-TKRX6CFI.js} +3 -3
- package/dist/chunk-TKRX6CFI.js.map +1 -0
- package/dist/chunk-UCVP3XAL.js +279 -0
- package/dist/chunk-UCVP3XAL.js.map +1 -0
- package/dist/chunk-VH4K4U45.js +180 -0
- package/dist/chunk-VH4K4U45.js.map +1 -0
- package/dist/{chunk-JIJPZFR2.js → chunk-Y62GORQF.js} +2 -2
- package/dist/chunk-Y62GORQF.js.map +1 -0
- package/dist/chunk-ZP3VVXOI.js +66 -0
- package/dist/chunk-ZP3VVXOI.js.map +1 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +11 -8
- package/dist/gateway.d.ts +3 -3
- package/dist/gateway.js +11 -9
- package/dist/{hybrid-CF__0YnC.d.ts → hybrid-CrKB50nh.d.ts} +2 -2
- package/dist/{index-cMV0_yD9.d.ts → index-CX43dvMs.d.ts} +2 -32
- package/dist/{index-BW95kAL4.d.ts → index-DoW2gzBZ.d.ts} +3 -21
- package/dist/index.d.ts +170 -46
- package/dist/index.js +20 -15
- package/dist/index.js.map +1 -1
- package/dist/kyber-CGOA7Q6A.js +3 -0
- package/dist/{kyber-3ULIJSE3.js.map → kyber-CGOA7Q6A.js.map} +1 -1
- package/dist/mesh.d.ts +27 -143
- package/dist/mesh.js +4 -3
- package/dist/node-B0b2vUFS.d.ts +164 -0
- package/dist/protocol/liop_core.proto +3 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.js +7 -6
- package/dist/types.js +1 -1
- package/dist/verifier-HRFXBKT5.js +6 -0
- package/dist/{verifier-3FAKCFNN.js.map → verifier-HRFXBKT5.js.map} +1 -1
- package/dist/workers/logic-execution.js +3 -3
- package/dist/workers/logic-execution.js.map +1 -1
- package/dist/workers/zk-verifier.js +1 -1
- package/dist/workers/zk-verifier.js.map +1 -1
- package/package.json +8 -2
- package/dist/chunk-32ADSAJS.js.map +0 -1
- package/dist/chunk-547TYL27.js.map +0 -1
- package/dist/chunk-72MNYFR6.js.map +0 -1
- package/dist/chunk-74CISO2I.js.map +0 -1
- package/dist/chunk-CRZBVFDV.js.map +0 -1
- package/dist/chunk-GA3Q2S7O.js.map +0 -1
- package/dist/chunk-JIJPZFR2.js.map +0 -1
- package/dist/chunk-OUUTDSOW.js.map +0 -1
- package/dist/chunk-PYKRQAER.js.map +0 -1
- package/dist/chunk-QLCOEP5J.js.map +0 -1
- package/dist/chunk-RWRRBYG4.js +0 -3
- package/dist/chunk-SONUORBT.js.map +0 -1
- package/dist/chunk-T5IUZF47.js.map +0 -1
- package/dist/chunk-U5BZ66VX.js.map +0 -1
- package/dist/chunk-WCCGE4QR.js.map +0 -1
- package/dist/chunk-WSW6YJNY.js.map +0 -1
- package/dist/kyber-3ULIJSE3.js +0 -3
- package/dist/verifier-3FAKCFNN.js +0 -5
|
@@ -73,5 +73,5 @@ var PromptSchema = z.object({
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
export { MCP_LEGACY_SUPPORT_ENABLED, MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION_LEGACY, PromptSchema, ResourceSchema, ToolSchema, adaptResponseForLegacyClient, buildLegacyInitializeResponse, isLegacyRequest };
|
|
76
|
-
//# sourceMappingURL=chunk-
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
76
|
+
//# sourceMappingURL=chunk-EG46XMJT.js.map
|
|
77
|
+
//# sourceMappingURL=chunk-EG46XMJT.js.map
|
|
@@ -0,0 +1 @@
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CAAU,KAAA;AACjB,EAAA,OAAO,SAAA,CAAU,UAAA;AAEjB,EAAA,OAAO;AAAA,IACN,GAAG,QAAA;AAAA,IACH,MAAA,EAAQ;AAAA,GACT;AACD;;;ACpFO,IAAM,oBAAA,GAAuB;AAyD7B,IAAM,UAAA,GAAa,EAAE,MAAA,CAAO;AAAA,EAClC,IAAA,EAAM,EAAE,MAAA,EAAO;AAAA,EACf,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,WAAA,EAAa,EAAE,MAAA,CAAO,CAAA,CAAE,QAAO,EAAG,CAAA,CAAE,SAAS;AAAA;AAC9C,CAAC;AAIM,IAAM,cAAA,GAAiB,EAAE,MAAA,CAAO;AAAA,EACtC,GAAA,EAAK,EAAE,MAAA,EAAO;AAAA,EACd,IAAA,EAAM,EAAE,MAAA,EAAO;AAAA,EACf,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,QAAA,EAAU,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACtB,CAAC;AAIM,IAAM,YAAA,GAAe,EAAE,MAAA,CAAO;AAAA,EACpC,IAAA,EAAM,EAAE,MAAA,EAAO;AAAA,EACf,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,WAAW,CAAA,CACT,KAAA;AAAA,IACA,EAAE,MAAA,CAAO;AAAA,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-EG46XMJT.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport 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","// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { 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"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { log } from './chunk-HA6YZ42O.js';
|
|
2
|
+
|
|
3
|
+
// src/runtime/token-manager.ts
|
|
4
|
+
var TokenManager = class _TokenManager {
|
|
5
|
+
cachedToken = null;
|
|
6
|
+
expiresAt = 0;
|
|
7
|
+
// Epoch ms
|
|
8
|
+
pendingPromise = null;
|
|
9
|
+
tokenEndpoint;
|
|
10
|
+
clientId;
|
|
11
|
+
clientSecret;
|
|
12
|
+
audience;
|
|
13
|
+
scope;
|
|
14
|
+
staticToken;
|
|
15
|
+
// Preemptive refresh threshold: 30 seconds before expiration
|
|
16
|
+
static REFRESH_BUFFER_MS = 3e4;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.tokenEndpoint = options.tokenEndpoint;
|
|
19
|
+
this.clientId = options.clientId;
|
|
20
|
+
this.clientSecret = options.clientSecret;
|
|
21
|
+
this.audience = options.audience ?? "urn:liop:mesh:api";
|
|
22
|
+
this.scope = Array.isArray(options.scopes) ? options.scopes.join(" ") : options.scopes ?? "liop:tools:call liop:tools:list liop:resources:read liop:schema:read liop:mesh:query";
|
|
23
|
+
this.staticToken = options.staticToken;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns a valid OAuth 2.1 access token.
|
|
27
|
+
* Automatically performs preemptive refresh if the token is close to expiry.
|
|
28
|
+
*/
|
|
29
|
+
async getToken() {
|
|
30
|
+
if (this.staticToken) {
|
|
31
|
+
return this.staticToken;
|
|
32
|
+
}
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
if (this.cachedToken && now < this.expiresAt - _TokenManager.REFRESH_BUFFER_MS) {
|
|
35
|
+
return this.cachedToken;
|
|
36
|
+
}
|
|
37
|
+
if (this.pendingPromise) {
|
|
38
|
+
return this.pendingPromise;
|
|
39
|
+
}
|
|
40
|
+
this.pendingPromise = (async () => {
|
|
41
|
+
try {
|
|
42
|
+
const token = await this.fetchNewToken();
|
|
43
|
+
this.cachedToken = token;
|
|
44
|
+
return token;
|
|
45
|
+
} finally {
|
|
46
|
+
this.pendingPromise = null;
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
return this.pendingPromise;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Force-invalidates cached token, e.g. after receiving a 401 Unauthorized response.
|
|
53
|
+
*/
|
|
54
|
+
invalidate() {
|
|
55
|
+
this.cachedToken = null;
|
|
56
|
+
this.expiresAt = 0;
|
|
57
|
+
if (this.clientId && this.clientSecret) {
|
|
58
|
+
this.staticToken = void 0;
|
|
59
|
+
}
|
|
60
|
+
log.info("[TokenManager] Cached OAuth access token invalidated.");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns true if the token is absent or has passed the refresh threshold.
|
|
64
|
+
*/
|
|
65
|
+
isExpired() {
|
|
66
|
+
if (this.staticToken) return false;
|
|
67
|
+
return !this.cachedToken || Date.now() >= this.expiresAt - _TokenManager.REFRESH_BUFFER_MS;
|
|
68
|
+
}
|
|
69
|
+
getExpiresAt() {
|
|
70
|
+
return this.expiresAt;
|
|
71
|
+
}
|
|
72
|
+
async fetchNewToken() {
|
|
73
|
+
log.info(
|
|
74
|
+
`[TokenManager] Requesting M2M token from ${this.tokenEndpoint} for client '${this.clientId}'...`
|
|
75
|
+
);
|
|
76
|
+
const params = new URLSearchParams({
|
|
77
|
+
grant_type: "client_credentials",
|
|
78
|
+
client_id: this.clientId,
|
|
79
|
+
client_secret: this.clientSecret,
|
|
80
|
+
resource: this.audience,
|
|
81
|
+
scope: this.scope
|
|
82
|
+
});
|
|
83
|
+
const response = await fetch(this.tokenEndpoint, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
87
|
+
Accept: "application/json"
|
|
88
|
+
},
|
|
89
|
+
body: params.toString(),
|
|
90
|
+
signal: AbortSignal.timeout(1e4)
|
|
91
|
+
});
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
const errorText = await response.text();
|
|
94
|
+
throw new Error(
|
|
95
|
+
`OAuth token request failed [HTTP ${response.status}]: ${errorText}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const data = await response.json();
|
|
99
|
+
if (!data.access_token) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"OAuth token response did not contain an 'access_token' field."
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const expiresInSec = typeof data.expires_in === "number" ? data.expires_in : 3600;
|
|
105
|
+
this.expiresAt = Date.now() + expiresInSec * 1e3;
|
|
106
|
+
log.info(
|
|
107
|
+
`[TokenManager] Acquired access token successfully. Expires in ${expiresInSec}s.`
|
|
108
|
+
);
|
|
109
|
+
return data.access_token;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export { TokenManager };
|
|
114
|
+
//# sourceMappingURL=chunk-ESRXG36Y.js.map
|
|
115
|
+
//# sourceMappingURL=chunk-ESRXG36Y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/token-manager.ts"],"names":[],"mappings":";;;AAwBO,IAAM,YAAA,GAAN,MAAM,aAAA,CAAa;AAAA,EACjB,WAAA,GAA6B,IAAA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AAM,KAAA,CAAM,IAAA,CAAK,aAAA,EAAe;AAAA,MAChD,MAAA,EAAQ,MAAA;AAAA,MACR,OAAA,EAAS;AAAA,QACR,cAAA,EAAgB,mCAAA;AAAA,QAChB,MAAA,EAAQ;AAAA,OACT;AAAA,MACA,IAAA,EAAM,OAAO,QAAA,EAAS;AAAA,MACtB,MAAA,EAAQ,WAAA,CAAY,OAAA,CAAQ,GAAM;AAAA,KAClC,CAAA;AAED,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AACjB,MAAA,MAAM,SAAA,GAAY,MAAM,QAAA,CAAS,IAAA,EAAK;AACtC,MAAA,MAAM,IAAI,KAAA;AAAA,QACT,CAAA,iCAAA,EAAoC,QAAA,CAAS,MAAM,CAAA,GAAA,EAAM,SAAS,CAAA;AAAA,OACnE;AAAA,IACD;AAEA,IAAA,MAAM,IAAA,GAAQ,MAAM,QAAA,CAAS,IAAA,EAAK;AAMlC,IAAA,IAAI,CAAC,KAAK,YAAA,EAAc;AACvB,MAAA,MAAM,IAAI,KAAA;AAAA,QACT;AAAA,OACD;AAAA,IACD;AAEA,IAAA,MAAM,eACL,OAAO,IAAA,CAAK,UAAA,KAAe,QAAA,GAAW,KAAK,UAAA,GAAa,IAAA;AACzD,IAAA,IAAA,CAAK,SAAA,GAAY,IAAA,CAAK,GAAA,EAAI,GAAI,YAAA,GAAe,GAAA;AAE7C,IAAA,GAAA,CAAI,IAAA;AAAA,MACH,iEAAiE,YAAY,CAAA,EAAA;AAAA,KAC9E;AAEA,IAAA,OAAO,IAAA,CAAK,YAAA;AAAA,EACb;AACD","file":"chunk-ESRXG36Y.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LIOP Token Manager — Adaptive OAuth 2.1 M2M Token Lifecycle\n *\n * Implements resilient token caching with preemptive refresh (30s safety buffer),\n * concurrency de-duplication (single in-flight HTTP request), and on-demand\n * invalidation for 401 Unauthorized handling.\n *\n * Standards: RFC 6749, RFC 8707 (Resource Indicators), RFC 9068 (JWT Profile)\n */\n\nimport { log } from \"../utils/logger.js\";\n\nexport interface TokenManagerOptions {\n\ttokenEndpoint: string;\n\tclientId: string;\n\tclientSecret: string;\n\taudience?: string;\n\tscopes?: string | string[];\n\tstaticToken?: string;\n}\n\nexport class TokenManager {\n\tprivate cachedToken: string | null = null;\n\tprivate expiresAt = 0; // Epoch ms\n\tprivate pendingPromise: Promise<string> | null = null;\n\n\tprivate readonly tokenEndpoint: string;\n\tprivate readonly clientId: string;\n\tprivate readonly clientSecret: string;\n\tprivate readonly audience: string;\n\tprivate readonly scope: string;\n\tprivate staticToken?: string;\n\n\t// Preemptive refresh threshold: 30 seconds before expiration\n\tprivate static readonly REFRESH_BUFFER_MS = 30_000;\n\n\tconstructor(options: TokenManagerOptions) {\n\t\tthis.tokenEndpoint = options.tokenEndpoint;\n\t\tthis.clientId = options.clientId;\n\t\tthis.clientSecret = options.clientSecret;\n\t\tthis.audience = options.audience ?? \"urn:liop:mesh:api\";\n\t\tthis.scope = Array.isArray(options.scopes)\n\t\t\t? options.scopes.join(\" \")\n\t\t\t: (options.scopes ??\n\t\t\t\t\"liop:tools:call liop:tools:list liop:resources:read liop:schema:read liop:mesh:query\");\n\t\tthis.staticToken = options.staticToken;\n\t}\n\n\t/**\n\t * Returns a valid OAuth 2.1 access token.\n\t * Automatically performs preemptive refresh if the token is close to expiry.\n\t */\n\tpublic async getToken(): Promise<string> {\n\t\tif (this.staticToken) {\n\t\t\treturn this.staticToken;\n\t\t}\n\n\t\tconst now = Date.now();\n\t\tif (\n\t\t\tthis.cachedToken &&\n\t\t\tnow < this.expiresAt - TokenManager.REFRESH_BUFFER_MS\n\t\t) {\n\t\t\treturn this.cachedToken;\n\t\t}\n\n\t\tif (this.pendingPromise) {\n\t\t\treturn this.pendingPromise;\n\t\t}\n\n\t\tthis.pendingPromise = (async () => {\n\t\t\ttry {\n\t\t\t\tconst token = await this.fetchNewToken();\n\t\t\t\tthis.cachedToken = token;\n\t\t\t\treturn token;\n\t\t\t} finally {\n\t\t\t\tthis.pendingPromise = null;\n\t\t\t}\n\t\t})();\n\n\t\treturn this.pendingPromise;\n\t}\n\n\t/**\n\t * Force-invalidates cached token, e.g. after receiving a 401 Unauthorized response.\n\t */\n\tpublic invalidate(): void {\n\t\tthis.cachedToken = null;\n\t\tthis.expiresAt = 0;\n\t\tif (this.clientId && this.clientSecret) {\n\t\t\tthis.staticToken = undefined;\n\t\t}\n\t\tlog.info(\"[TokenManager] Cached OAuth access token invalidated.\");\n\t}\n\n\t/**\n\t * Returns true if the token is absent or has passed the refresh threshold.\n\t */\n\tpublic isExpired(): boolean {\n\t\tif (this.staticToken) return false;\n\t\treturn (\n\t\t\t!this.cachedToken ||\n\t\t\tDate.now() >= this.expiresAt - TokenManager.REFRESH_BUFFER_MS\n\t\t);\n\t}\n\n\tpublic getExpiresAt(): number {\n\t\treturn this.expiresAt;\n\t}\n\n\tprivate async fetchNewToken(): Promise<string> {\n\t\tlog.info(\n\t\t\t`[TokenManager] Requesting M2M token from ${this.tokenEndpoint} for client '${this.clientId}'...`,\n\t\t);\n\n\t\tconst params = new URLSearchParams({\n\t\t\tgrant_type: \"client_credentials\",\n\t\t\tclient_id: this.clientId,\n\t\t\tclient_secret: this.clientSecret,\n\t\t\tresource: this.audience,\n\t\t\tscope: this.scope,\n\t\t});\n\n\t\tconst response = await fetch(this.tokenEndpoint, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\tAccept: \"application/json\",\n\t\t\t},\n\t\t\tbody: params.toString(),\n\t\t\tsignal: AbortSignal.timeout(10_000),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text();\n\t\t\tthrow new Error(\n\t\t\t\t`OAuth token request failed [HTTP ${response.status}]: ${errorText}`,\n\t\t\t);\n\t\t}\n\n\t\tconst data = (await response.json()) as {\n\t\t\taccess_token?: string;\n\t\t\texpires_in?: number;\n\t\t\ttoken_type?: string;\n\t\t};\n\n\t\tif (!data.access_token) {\n\t\t\tthrow new Error(\n\t\t\t\t\"OAuth token response did not contain an 'access_token' field.\",\n\t\t\t);\n\t\t}\n\n\t\tconst expiresInSec =\n\t\t\ttypeof data.expires_in === \"number\" ? data.expires_in : 3600;\n\t\tthis.expiresAt = Date.now() + expiresInSec * 1000;\n\n\t\tlog.info(\n\t\t\t`[TokenManager] Acquired access token successfully. Expires in ${expiresInSec}s.`,\n\t\t);\n\n\t\treturn data.access_token;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-FTF6AMF6.js"}
|
|
@@ -60,5 +60,5 @@ var LiopLogger = class _LiopLogger {
|
|
|
60
60
|
var log = LiopLogger.getInstance();
|
|
61
61
|
|
|
62
62
|
export { log };
|
|
63
|
-
//# sourceMappingURL=chunk-
|
|
64
|
-
//# sourceMappingURL=chunk-
|
|
63
|
+
//# sourceMappingURL=chunk-HA6YZ42O.js.map
|
|
64
|
+
//# sourceMappingURL=chunk-HA6YZ42O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/logger.ts"],"names":[],"mappings":";AAUO,IAAM,UAAA,GAAN,MAAM,WAAA,CAAW;AAAA,EACvB,OAAe,QAAA;AAAA,EACP,KAAA,GAAkB,MAAA;AAAA,EAElB,WAAA,GAAc;AACrB,IAAA,IAAA,CAAK,eAAA,EAAgB;AAAA,EACtB;AAAA,EAEA,OAAc,WAAA,GAA0B;AACvC,IAAA,IAAI,CAAC,YAAW,QAAA,EAAU;AACzB,MAAA,WAAA,CAAW,QAAA,GAAW,IAAI,WAAA,EAAW;AAAA,IACtC;AACA,IAAA,OAAO,WAAA,CAAW,QAAA;AAAA,EACnB;AAAA,EAEQ,eAAA,GAAkB;AACzB,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CAAK,SAAA,CAAU,MAAM,CAAA,EAAG;AAC3B,MAAA,OAAA,CAAQ,MAAM,IAAA,CAAK,aAAA,CAAc,QAAQ,OAAO,CAAA,EAAG,GAAG,IAAI,CAAA;AAAA,IAC3D;AAAA,EACD;AAAA,EAEO,IAAA,CAAK,YAAoB,IAAA,EAAiB;AAChD,IAAA,IAAI,IAAA,CAAK,SAAA,CAAU,MAAM,CAAA,EAAG;AAC3B,MAAA,OAAA,CAAQ,MAAM,IAAA,CAAK,aAAA,CAAc,QAAQ,OAAO,CAAA,EAAG,GAAG,IAAI,CAAA;AAAA,IAC3D;AAAA,EACD;AAAA,EAEO,KAAA,CAAM,YAAoB,IAAA,EAAiB;AACjD,IAAA,IAAI,IAAA,CAAK,SAAA,CAAU,OAAO,CAAA,EAAG;AAC5B,MAAA,OAAA,CAAQ,MAAM,IAAA,CAAK,aAAA,CAAc,SAAS,OAAO,CAAA,EAAG,GAAG,IAAI,CAAA;AAAA,IAC5D;AAAA,EACD;AACD,CAAA;AAEO,IAAM,GAAA,GAAM,WAAW,WAAA","file":"chunk-HA6YZ42O.js","sourcesContent":["// Copyright 2026 Nekzus Solutions and contributors\n// SPDX-License-Identifier: Apache-2.0\n\nexport type LogLevel = \"silent\" | \"error\" | \"warn\" | \"info\" | \"debug\";\n\n/**\n * LiopLogger - Structured Logging Abstraction\n * Configurable via `process.env.LIOP_LOG_LEVEL`.\n * Emits strictly to stderr to comply with MCP stdio protocols.\n */\nexport class LiopLogger {\n\tprivate static instance: LiopLogger;\n\tprivate level: LogLevel = \"info\";\n\n\tprivate constructor() {\n\t\tthis.setLevelFromEnv();\n\t}\n\n\tpublic static getInstance(): LiopLogger {\n\t\tif (!LiopLogger.instance) {\n\t\t\tLiopLogger.instance = new LiopLogger();\n\t\t}\n\t\treturn LiopLogger.instance;\n\t}\n\n\tprivate setLevelFromEnv() {\n\t\tconst envLevel = process.env.LIOP_LOG_LEVEL?.toLowerCase();\n\t\tif (\n\t\t\tenvLevel === \"silent\" ||\n\t\t\tenvLevel === \"error\" ||\n\t\t\tenvLevel === \"warn\" ||\n\t\t\tenvLevel === \"info\" ||\n\t\t\tenvLevel === \"debug\"\n\t\t) {\n\t\t\tthis.level = envLevel as LogLevel;\n\t\t} else {\n\t\t\t// Default level: info\n\t\t\tthis.level = \"info\";\n\t\t}\n\t}\n\n\tpublic setLevel(level: LogLevel) {\n\t\tthis.level = level;\n\t}\n\n\tprivate shouldLog(targetLevel: LogLevel): boolean {\n\t\tconst levels: Record<LogLevel, number> = {\n\t\t\tsilent: 0,\n\t\t\terror: 1,\n\t\t\twarn: 2,\n\t\t\tinfo: 3,\n\t\t\tdebug: 4,\n\t\t};\n\t\treturn levels[this.level] >= levels[targetLevel];\n\t}\n\n\tprivate formatMessage(level: string, message: string): string {\n\t\tconst ts = new Date().toISOString();\n\t\treturn `[${ts}] [${level}] ${message}`;\n\t}\n\n\tpublic error(message: string, ...args: unknown[]) {\n\t\tif (this.shouldLog(\"error\")) {\n\t\t\tconsole.error(this.formatMessage(\"ERROR\", message), ...args);\n\t\t}\n\t}\n\n\tpublic warn(message: string, ...args: unknown[]) {\n\t\tif (this.shouldLog(\"warn\")) {\n\t\t\tconsole.error(this.formatMessage(\"WARN\", message), ...args);\n\t\t}\n\t}\n\n\tpublic info(message: string, ...args: unknown[]) {\n\t\tif (this.shouldLog(\"info\")) {\n\t\t\tconsole.error(this.formatMessage(\"INFO\", message), ...args);\n\t\t}\n\t}\n\n\tpublic debug(message: string, ...args: unknown[]) {\n\t\tif (this.shouldLog(\"debug\")) {\n\t\t\tconsole.error(this.formatMessage(\"DEBUG\", message), ...args);\n\t\t}\n\t}\n}\n\nexport const log = LiopLogger.getInstance();\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { sanitizeOutput } from './chunk-
|
|
2
|
-
import { LIOP_SCOPES, Dilithium65Wrapper, authorizeRequest
|
|
3
|
-
import { GRPC_CHANNEL_OPTIONS, liopV1, createServerCredentials } from './chunk-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { sanitizeOutput } from './chunk-Y62GORQF.js';
|
|
2
|
+
import { LIOP_SCOPES, Dilithium65Wrapper, authorizeRequest } from './chunk-VH4K4U45.js';
|
|
3
|
+
import { GRPC_CHANNEL_OPTIONS, liopV1, createServerCredentials } from './chunk-TKRX6CFI.js';
|
|
4
|
+
import { egressBlocksTotal, toolCallsTotal, fuelConsumed, wireEgressBytesTotal, wireSavedBytesTotal, toolCallErrorsTotal } from './chunk-PAICJCKJ.js';
|
|
5
|
+
import { MeshNode } from './chunk-7RXOIDXP.js';
|
|
6
|
+
import { log } from './chunk-HA6YZ42O.js';
|
|
6
7
|
import { Buffer } from 'buffer';
|
|
7
8
|
import * as crypto3 from 'crypto';
|
|
8
9
|
import crypto3__default from 'crypto';
|
|
@@ -279,7 +280,9 @@ var JwtValidator = class {
|
|
|
279
280
|
"127.0.0.1:13000",
|
|
280
281
|
"localhost:13000",
|
|
281
282
|
"127.0.0.1:13001",
|
|
282
|
-
"localhost:13001"
|
|
283
|
+
"localhost:13001",
|
|
284
|
+
"127.0.0.1:15000",
|
|
285
|
+
"localhost:15000"
|
|
283
286
|
];
|
|
284
287
|
let issuerAuthority = "";
|
|
285
288
|
try {
|
|
@@ -481,6 +484,7 @@ var TaintAnalyzer = class _TaintAnalyzer {
|
|
|
481
484
|
]);
|
|
482
485
|
/** Reduce-family methods where the record param is the SECOND callback arg */
|
|
483
486
|
static REDUCE_METHODS = /* @__PURE__ */ new Set(["reduce", "reduceRight"]);
|
|
487
|
+
currentRecordCollections = /* @__PURE__ */ new Set();
|
|
484
488
|
constructor(piiFields, sensitiveKeys = []) {
|
|
485
489
|
this.piiFields = new Set(piiFields.map((f) => f.toLowerCase()));
|
|
486
490
|
this.sensitiveKeys = new Set(sensitiveKeys.map((f) => f.toLowerCase()));
|
|
@@ -652,6 +656,47 @@ ${sourceCode}
|
|
|
652
656
|
}
|
|
653
657
|
return false;
|
|
654
658
|
}
|
|
659
|
+
/** Checks if an expression resolves to env.records, records, an alias, or a derivation chain */
|
|
660
|
+
isRecordsSource(node) {
|
|
661
|
+
if (this.isEnvRecordsAccess(node)) return true;
|
|
662
|
+
if (node.type === "Identifier" && this.currentRecordCollections.has(node.name)) {
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
if (node.type === "CallExpression") {
|
|
666
|
+
const call = node;
|
|
667
|
+
if (call.callee.type === "MemberExpression") {
|
|
668
|
+
const member = call.callee;
|
|
669
|
+
const method = this.getPropertyName(member);
|
|
670
|
+
if (method && (method === "slice" || method === "filter" || method === "toSorted" || method === "map" || method === "concat")) {
|
|
671
|
+
return this.isRecordsSource(member.object);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
/** Gathers aliases and derivations of env.records (e.g. const accounts = env.records; const top5 = accounts.filter(...)) */
|
|
678
|
+
identifyRecordCollections(ast) {
|
|
679
|
+
this.currentRecordCollections.clear();
|
|
680
|
+
for (let pass = 0; pass < 3; pass++) {
|
|
681
|
+
const aliasVisitors = {
|
|
682
|
+
VariableDeclarator: (node) => {
|
|
683
|
+
if (!node.init || node.id.type !== "Identifier") return;
|
|
684
|
+
if (this.isRecordsSource(node.init)) {
|
|
685
|
+
this.currentRecordCollections.add(node.id.name);
|
|
686
|
+
}
|
|
687
|
+
},
|
|
688
|
+
AssignmentExpression: (node) => {
|
|
689
|
+
if (node.left.type !== "Identifier") return;
|
|
690
|
+
if (this.isRecordsSource(node.right)) {
|
|
691
|
+
this.currentRecordCollections.add(
|
|
692
|
+
node.left.name
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
simple(ast, aliasVisitors);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
655
700
|
/**
|
|
656
701
|
* Extracts field names accessed on a record parameter within a function body.
|
|
657
702
|
* e.g., in `(s, r) => s + r.balance`, extracts "balance".
|
|
@@ -733,17 +778,18 @@ ${sourceCode}
|
|
|
733
778
|
if (call.callee.type !== "MemberExpression") return false;
|
|
734
779
|
const callee = call.callee;
|
|
735
780
|
const method = this.getPropertyName(callee);
|
|
736
|
-
return method === "map" && this.
|
|
781
|
+
return method === "map" && this.isRecordsSource(callee.object);
|
|
737
782
|
}
|
|
738
783
|
// ── Pass 1: Record-Bound Variable Identification ──────────────────
|
|
739
784
|
identifyRecordBoundVars(ast, recordBoundVars) {
|
|
785
|
+
this.identifyRecordCollections(ast);
|
|
740
786
|
const visitors = {
|
|
741
787
|
CallExpression: (node) => {
|
|
742
788
|
if (node.callee.type !== "MemberExpression") return;
|
|
743
789
|
const member = node.callee;
|
|
744
790
|
const methodName = this.getPropertyName(member);
|
|
745
791
|
if (!methodName) return;
|
|
746
|
-
if (!this.
|
|
792
|
+
if (!this.isRecordsSource(member.object)) return;
|
|
747
793
|
const callback = node.arguments[0];
|
|
748
794
|
if (!callback) return;
|
|
749
795
|
if (callback.type === "ArrowFunctionExpression" || callback.type === "FunctionExpression") {
|
|
@@ -762,9 +808,9 @@ ${sourceCode}
|
|
|
762
808
|
}
|
|
763
809
|
}
|
|
764
810
|
},
|
|
765
|
-
// for (const r of env.records) → r is record-bound
|
|
811
|
+
// for (const r of env.records) or for (const r of accounts) → r is record-bound
|
|
766
812
|
ForOfStatement: (node) => {
|
|
767
|
-
if (!this.
|
|
813
|
+
if (!this.isRecordsSource(node.right)) return;
|
|
768
814
|
if (node.left.type === "VariableDeclaration") {
|
|
769
815
|
for (const declarator of node.left.declarations) {
|
|
770
816
|
if (declarator.id.type === "Identifier") {
|
|
@@ -780,7 +826,7 @@ ${sourceCode}
|
|
|
780
826
|
if (!node.init || node.id.type !== "Identifier") return;
|
|
781
827
|
if (node.init.type === "MemberExpression" && node.init.computed) {
|
|
782
828
|
const member = node.init;
|
|
783
|
-
if (this.
|
|
829
|
+
if (this.isRecordsSource(member.object)) {
|
|
784
830
|
recordBoundVars.add(node.id.name);
|
|
785
831
|
}
|
|
786
832
|
}
|
|
@@ -800,6 +846,18 @@ ${sourceCode}
|
|
|
800
846
|
}
|
|
801
847
|
},
|
|
802
848
|
AssignmentExpression: (node) => {
|
|
849
|
+
if (node.left.type === "MemberExpression") {
|
|
850
|
+
const member = node.left;
|
|
851
|
+
if (member.computed && this.isExpressionTainted(
|
|
852
|
+
member.property,
|
|
853
|
+
recordBoundVars,
|
|
854
|
+
taintedVars
|
|
855
|
+
)) {
|
|
856
|
+
if (member.object.type === "Identifier") {
|
|
857
|
+
taintedVars.add(member.object.name);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
803
861
|
if (node.left.type !== "Identifier") return;
|
|
804
862
|
if (this.isExpressionTainted(node.right, recordBoundVars, taintedVars)) {
|
|
805
863
|
taintedVars.add(node.left.name);
|
|
@@ -921,9 +979,26 @@ ${sourceCode}
|
|
|
921
979
|
}
|
|
922
980
|
case "ObjectExpression": {
|
|
923
981
|
const obj = node;
|
|
924
|
-
return obj.properties.some(
|
|
925
|
-
(prop
|
|
926
|
-
|
|
982
|
+
return obj.properties.some((prop) => {
|
|
983
|
+
if (prop.type === "Property") {
|
|
984
|
+
if (prop.computed && this.isExpressionTainted(prop.key, recordBoundVars, taintedVars)) {
|
|
985
|
+
return true;
|
|
986
|
+
}
|
|
987
|
+
return this.isExpressionTainted(
|
|
988
|
+
prop.value,
|
|
989
|
+
recordBoundVars,
|
|
990
|
+
taintedVars
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
if (prop.type === "SpreadElement") {
|
|
994
|
+
return this.isExpressionTainted(
|
|
995
|
+
prop.argument,
|
|
996
|
+
recordBoundVars,
|
|
997
|
+
taintedVars
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
return false;
|
|
1001
|
+
});
|
|
927
1002
|
}
|
|
928
1003
|
case "ArrayExpression": {
|
|
929
1004
|
const arr = node;
|
|
@@ -960,7 +1035,7 @@ ${sourceCode}
|
|
|
960
1035
|
}
|
|
961
1036
|
if (member.object.type === "MemberExpression" && propName && this.piiFields.has(propName.toLowerCase())) {
|
|
962
1037
|
const parentMember = member.object;
|
|
963
|
-
if (parentMember.computed && this.
|
|
1038
|
+
if (parentMember.computed && this.isRecordsSource(parentMember.object)) {
|
|
964
1039
|
return true;
|
|
965
1040
|
}
|
|
966
1041
|
}
|
|
@@ -988,7 +1063,7 @@ ${sourceCode}
|
|
|
988
1063
|
if (methodName && _TaintAnalyzer.TAINT_PROPAGATING_METHODS.has(methodName) && this.isExpressionTainted(callee.object, recordBoundVars, taintedVars)) {
|
|
989
1064
|
return true;
|
|
990
1065
|
}
|
|
991
|
-
if (this.
|
|
1066
|
+
if (this.isRecordsSource(callee.object) && call.arguments[0]) {
|
|
992
1067
|
const callback = call.arguments[0];
|
|
993
1068
|
if (callback.type === "ArrowFunctionExpression" || callback.type === "FunctionExpression") {
|
|
994
1069
|
return this.doesCallbackProduceTaint(
|
|
@@ -1061,6 +1136,11 @@ ${sourceCode}
|
|
|
1061
1136
|
scopedTaintedVars
|
|
1062
1137
|
);
|
|
1063
1138
|
}
|
|
1139
|
+
this.propagateTaint(
|
|
1140
|
+
callback.body,
|
|
1141
|
+
scopedRecordVars,
|
|
1142
|
+
scopedTaintedVars
|
|
1143
|
+
);
|
|
1064
1144
|
let hasTaintedReturnOrYield = false;
|
|
1065
1145
|
const returnVisitors = {
|
|
1066
1146
|
ReturnStatement: (node) => {
|
|
@@ -2243,14 +2323,18 @@ Data structure: ${schemaDigest}. Full schema: resource liop://schema/global`;
|
|
|
2243
2323
|
isError: true
|
|
2244
2324
|
};
|
|
2245
2325
|
}
|
|
2246
|
-
const
|
|
2247
|
-
const
|
|
2248
|
-
const
|
|
2326
|
+
const rawArgs = args && typeof args === "object" ? args : {};
|
|
2327
|
+
const payloadValue = rawArgs.payload ?? rawArgs.envelope ?? rawArgs.code;
|
|
2328
|
+
const bypassCache = rawArgs.__liop_bypass_ast_cache === true;
|
|
2329
|
+
const payloadHash = crypto3__default.createHash("sha256").update(payloadValue || "").digest("hex");
|
|
2249
2330
|
const logic = this.extractLogic(payloadValue);
|
|
2250
2331
|
const cached = this.logicCache.get(payloadHash);
|
|
2251
2332
|
if (!bypassCache && cached && now - cached.timestamp < this.CACHE_TTL_MS) {
|
|
2252
2333
|
if (logic) {
|
|
2253
|
-
|
|
2334
|
+
rawArgs.payload = logic;
|
|
2335
|
+
if (rawArgs.envelope !== void 0) {
|
|
2336
|
+
rawArgs.envelope = logic;
|
|
2337
|
+
}
|
|
2254
2338
|
const preflightReason = this.runPreflightPolicy(
|
|
2255
2339
|
name,
|
|
2256
2340
|
logic,
|
|
@@ -2281,10 +2365,11 @@ Data structure: ${schemaDigest}. Full schema: resource liop://schema/global`;
|
|
|
2281
2365
|
};
|
|
2282
2366
|
}
|
|
2283
2367
|
try {
|
|
2284
|
-
const logic2 = this.extractLogic(
|
|
2285
|
-
|
|
2286
|
-
)
|
|
2287
|
-
|
|
2368
|
+
const logic2 = this.extractLogic(payloadValue);
|
|
2369
|
+
rawArgs.payload = logic2;
|
|
2370
|
+
if (rawArgs.envelope !== void 0) {
|
|
2371
|
+
rawArgs.envelope = logic2;
|
|
2372
|
+
}
|
|
2288
2373
|
const preflightReason = this.runPreflightPolicy(
|
|
2289
2374
|
name,
|
|
2290
2375
|
logic2,
|
|
@@ -2771,7 +2856,7 @@ Data structure: ${schemaDigest}. Full schema: resource ${uri}. Guidelines: resou
|
|
|
2771
2856
|
log.info(
|
|
2772
2857
|
`[LIOP-RPC] Bypass authentication for matching localTestToken: ${localTestToken}`
|
|
2773
2858
|
);
|
|
2774
|
-
import('./kyber-
|
|
2859
|
+
import('./kyber-CGOA7Q6A.js').then(
|
|
2775
2860
|
async ({ Kyber768Wrapper }) => {
|
|
2776
2861
|
const { publicKey, secretKey } = await Kyber768Wrapper.generateKeyPair();
|
|
2777
2862
|
const sessionToken = crypto3__default.randomUUID();
|
|
@@ -2807,7 +2892,7 @@ Data structure: ${schemaDigest}. Full schema: resource ${uri}. Guidelines: resou
|
|
|
2807
2892
|
});
|
|
2808
2893
|
return;
|
|
2809
2894
|
}
|
|
2810
|
-
import('./kyber-
|
|
2895
|
+
import('./kyber-CGOA7Q6A.js').then(
|
|
2811
2896
|
async ({ Kyber768Wrapper }) => {
|
|
2812
2897
|
const { publicKey, secretKey } = await Kyber768Wrapper.generateKeyPair();
|
|
2813
2898
|
const sessionToken = crypto3__default.randomUUID();
|
|
@@ -2833,7 +2918,7 @@ Data structure: ${schemaDigest}. Full schema: resource ${uri}. Guidelines: resou
|
|
|
2833
2918
|
});
|
|
2834
2919
|
});
|
|
2835
2920
|
} else {
|
|
2836
|
-
import('./kyber-
|
|
2921
|
+
import('./kyber-CGOA7Q6A.js').then(async ({ Kyber768Wrapper }) => {
|
|
2837
2922
|
const { publicKey, secretKey } = await Kyber768Wrapper.generateKeyPair();
|
|
2838
2923
|
const sessionToken = crypto3__default.randomUUID();
|
|
2839
2924
|
this.sessions.set(sessionToken, {
|
|
@@ -3057,13 +3142,37 @@ Data structure: ${schemaDigest}. Full schema: resource ${uri}. Guidelines: resou
|
|
|
3057
3142
|
status: isBlocked ? "BLOCKED_EGRESS" : "SUCCESS"
|
|
3058
3143
|
});
|
|
3059
3144
|
toolCallsTotal.inc({
|
|
3145
|
+
capability: toolName || "unknown",
|
|
3060
3146
|
tool: toolName || "unknown",
|
|
3061
3147
|
status: isBlocked ? "blocked_egress" : "success"
|
|
3062
3148
|
});
|
|
3063
3149
|
fuelConsumed.observe(
|
|
3064
|
-
{
|
|
3150
|
+
{
|
|
3151
|
+
capability: toolName || "unknown",
|
|
3152
|
+
tool: toolName || "unknown"
|
|
3153
|
+
},
|
|
3065
3154
|
workerResponse.fuel_consumed || 0
|
|
3066
3155
|
);
|
|
3156
|
+
try {
|
|
3157
|
+
const egressBytes = Buffer.byteLength(response.semantic_evidence || "") + (response.cryptographic_proof ? response.cryptographic_proof.length : 0) + (response.zk_receipt ? response.zk_receipt.length : 0);
|
|
3158
|
+
wireEgressBytesTotal.inc(
|
|
3159
|
+
{ capability: toolName || "unknown" },
|
|
3160
|
+
egressBytes
|
|
3161
|
+
);
|
|
3162
|
+
if (this.sandboxRecords && this.sandboxRecords.length > 0) {
|
|
3163
|
+
const rawDatasetBytes = Buffer.byteLength(
|
|
3164
|
+
JSON.stringify(this.sandboxRecords)
|
|
3165
|
+
);
|
|
3166
|
+
const savedBytes = Math.max(0, rawDatasetBytes - egressBytes);
|
|
3167
|
+
if (savedBytes > 0) {
|
|
3168
|
+
wireSavedBytesTotal.inc(
|
|
3169
|
+
{ capability: toolName || "unknown" },
|
|
3170
|
+
savedBytes
|
|
3171
|
+
);
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
} catch {
|
|
3175
|
+
}
|
|
3067
3176
|
call.write(response, () => {
|
|
3068
3177
|
call.end();
|
|
3069
3178
|
});
|
|
@@ -3084,9 +3193,14 @@ Data structure: ${schemaDigest}. Full schema: resource ${uri}. Guidelines: resou
|
|
|
3084
3193
|
status: "ERROR"
|
|
3085
3194
|
});
|
|
3086
3195
|
toolCallsTotal.inc({
|
|
3196
|
+
capability: toolName || "unknown",
|
|
3087
3197
|
tool: toolName || "unknown",
|
|
3088
3198
|
status: "error"
|
|
3089
3199
|
});
|
|
3200
|
+
toolCallErrorsTotal.inc({
|
|
3201
|
+
capability: toolName || "unknown",
|
|
3202
|
+
error_type: "runtime_error"
|
|
3203
|
+
});
|
|
3090
3204
|
const errorResponse = {
|
|
3091
3205
|
semantic_evidence: errorMessage,
|
|
3092
3206
|
cryptographic_proof: Buffer.from(""),
|
|
@@ -3516,5 +3630,5 @@ Data structure: ${schemaDigest}. Full schema: resource ${uri}. Guidelines: resou
|
|
|
3516
3630
|
};
|
|
3517
3631
|
|
|
3518
3632
|
export { AUTH_DEFAULTS, AuditLogger, GENESIS_HASH, JwtValidator, LiopRpcServer, LiopServer, NerScanner, PII_PATTERNS, PII_PRESETS, PiiScanner, computeEntryHash, createOAuthServer, globalAuditLogger };
|
|
3519
|
-
//# sourceMappingURL=chunk-
|
|
3520
|
-
//# sourceMappingURL=chunk-
|
|
3633
|
+
//# sourceMappingURL=chunk-HD2N3IJX.js.map
|
|
3634
|
+
//# sourceMappingURL=chunk-HD2N3IJX.js.map
|