@nekzus/liop 2.4.0-alpha.12 → 2.4.0-alpha.14

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.
Files changed (52) hide show
  1. package/dist/bin/agent.js +10 -10
  2. package/dist/bridge.d.ts +2 -2
  3. package/dist/bridge.js +3 -3
  4. package/dist/{chunk-EG46XMJT.js → chunk-2KSO3W4A.js} +2 -2
  5. package/dist/{chunk-EG46XMJT.js.map → chunk-2KSO3W4A.js.map} +1 -1
  6. package/dist/{chunk-UWC7OY7K.js → chunk-6CPRIMCD.js} +27 -5
  7. package/dist/chunk-6CPRIMCD.js.map +1 -0
  8. package/dist/{chunk-3BJ5QQHK.js → chunk-COISHJK5.js} +3 -3
  9. package/dist/{chunk-3BJ5QQHK.js.map → chunk-COISHJK5.js.map} +1 -1
  10. package/dist/{chunk-UCVP3XAL.js → chunk-HWUCX2II.js} +3 -3
  11. package/dist/{chunk-UCVP3XAL.js.map → chunk-HWUCX2II.js.map} +1 -1
  12. package/dist/{chunk-V2TP43CD.js → chunk-JPN5456V.js} +7 -7
  13. package/dist/{chunk-V2TP43CD.js.map → chunk-JPN5456V.js.map} +1 -1
  14. package/dist/{chunk-GYJQ63L2.js → chunk-KB7LNCVI.js} +9 -9
  15. package/dist/{chunk-GYJQ63L2.js.map → chunk-KB7LNCVI.js.map} +1 -1
  16. package/dist/chunk-LIBI3HMN.js +106 -0
  17. package/dist/chunk-LIBI3HMN.js.map +1 -0
  18. package/dist/{chunk-U2KYB6FN.js → chunk-OSJDFUBY.js} +5 -5
  19. package/dist/{chunk-U2KYB6FN.js.map → chunk-OSJDFUBY.js.map} +1 -1
  20. package/dist/{chunk-7RXOIDXP.js → chunk-QJIXNZTL.js} +3 -3
  21. package/dist/{chunk-7RXOIDXP.js.map → chunk-QJIXNZTL.js.map} +1 -1
  22. package/dist/{chunk-PEN3KFLF.js → chunk-RWBFGRF7.js} +3 -3
  23. package/dist/{chunk-PEN3KFLF.js.map → chunk-RWBFGRF7.js.map} +1 -1
  24. package/dist/{chunk-JPYPTJHX.js → chunk-TDTGUVLB.js} +101 -6
  25. package/dist/chunk-TDTGUVLB.js.map +1 -0
  26. package/dist/{chunk-DZ2FQGJD.js → chunk-UAUBVKMK.js} +3 -3
  27. package/dist/{chunk-DZ2FQGJD.js.map → chunk-UAUBVKMK.js.map} +1 -1
  28. package/dist/{chunk-ESRXG36Y.js → chunk-VRZ3UIYA.js} +3 -3
  29. package/dist/{chunk-ESRXG36Y.js.map → chunk-VRZ3UIYA.js.map} +1 -1
  30. package/dist/client.d.ts +2 -2
  31. package/dist/client.js +8 -8
  32. package/dist/gateway.d.ts +3 -3
  33. package/dist/gateway.js +7 -7
  34. package/dist/{hybrid-CrKB50nh.d.ts → hybrid-CTC9oYVp.d.ts} +4 -3
  35. package/dist/{index-CYr7H4aY.d.ts → index-DHdTB7B8.d.ts} +1 -1
  36. package/dist/{index-DoW2gzBZ.d.ts → index-Dqn4dtZP.d.ts} +2 -51
  37. package/dist/index.d.ts +6 -6
  38. package/dist/index.js +13 -13
  39. package/dist/mesh.js +2 -2
  40. package/dist/server.d.ts +2 -2
  41. package/dist/server.js +4 -4
  42. package/dist/{types-lJIxBlWF.d.ts → types-CMYlWlX2.d.ts} +164 -1
  43. package/dist/types.d.ts +1 -1
  44. package/dist/types.js +1 -1
  45. package/dist/verifier-A7HX6KAJ.js +6 -0
  46. package/dist/{verifier-HRFXBKT5.js.map → verifier-A7HX6KAJ.js.map} +1 -1
  47. package/package.json +21 -21
  48. package/dist/chunk-HA6YZ42O.js +0 -64
  49. package/dist/chunk-HA6YZ42O.js.map +0 -1
  50. package/dist/chunk-JPYPTJHX.js.map +0 -1
  51. package/dist/chunk-UWC7OY7K.js.map +0 -1
  52. package/dist/verifier-HRFXBKT5.js +0 -6
@@ -1,4 +1,4 @@
1
- import { log } from './chunk-HA6YZ42O.js';
1
+ import { log } from './chunk-LIBI3HMN.js';
2
2
 
3
3
  // src/runtime/token-manager.ts
4
4
  var TokenManager = class _TokenManager {
@@ -111,5 +111,5 @@ var TokenManager = class _TokenManager {
111
111
  };
112
112
 
113
113
  export { TokenManager };
114
- //# sourceMappingURL=chunk-ESRXG36Y.js.map
115
- //# sourceMappingURL=chunk-ESRXG36Y.js.map
114
+ //# sourceMappingURL=chunk-VRZ3UIYA.js.map
115
+ //# sourceMappingURL=chunk-VRZ3UIYA.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/runtime/token-manager.ts"],"names":[],"mappings":";;;AAwBO,IAAM,YAAA,GAAN,MAAM,aAAA,CAAa;AAAA,EACjB,WAAA,GAA6B,IAAA;AAAA,EAC7B,SAAA,GAAY,CAAA;AAAA;AAAA,EACZ,cAAA,GAAyC,IAAA;AAAA,EAEhC,aAAA;AAAA,EACA,QAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACT,WAAA;AAAA;AAAA,EAGR,OAAwB,iBAAA,GAAoB,GAAA;AAAA,EAE5C,YAAY,OAAA,EAA8B;AACzC,IAAA,IAAA,CAAK,gBAAgB,OAAA,CAAQ,aAAA;AAC7B,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AACxB,IAAA,IAAA,CAAK,eAAe,OAAA,CAAQ,YAAA;AAC5B,IAAA,IAAA,CAAK,QAAA,GAAW,QAAQ,QAAA,IAAY,mBAAA;AACpC,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA,CAAM,OAAA,CAAQ,OAAA,CAAQ,MAAM,CAAA,GACtC,OAAA,CAAQ,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA,GACtB,OAAA,CAAQ,MAAA,IACV,sFAAA;AACF,IAAA,IAAA,CAAK,cAAc,OAAA,CAAQ,WAAA;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,QAAA,GAA4B;AACxC,IAAA,IAAI,KAAK,WAAA,EAAa;AACrB,MAAA,OAAO,IAAA,CAAK,WAAA;A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A,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
+ {"version":3,"sources":["../src/runtime/token-manager.ts"],"names":[],"mappings":";;;AAwBO,IAAM,YAAA,GAAN,MAAM,aAAA,CAAa;AAAA,EACjB,WAAA,GAA6B,IAAA;AAAA,EAC7B,SAAA,GAAY,CAAA;AAAA;AAAA,EACZ,cAAA,GAAyC,IAAA;AAAA,EAEhC,aAAA;AAAA,EACA,QAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACT,WAAA;AAAA;AAAA,EAGR,OAAwB,iBAAA,GAAoB,GAAA;AAAA,EAE5C,YAAY,OAAA,EAA8B;AACzC,IAAA,IAAA,CAAK,gBAAgB,OAAA,CAAQ,aAAA;AAC7B,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ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Y,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-VRZ3UIYA.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"]}
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import './verifier-COnid_dg.js';
2
2
  import './node-B0b2vUFS.js';
3
- export { c as LiopClient } from './index-CYr7H4aY.js';
4
- import './types-lJIxBlWF.js';
3
+ export { c as LiopClient } from './index-DHdTB7B8.js';
4
+ import './types-CMYlWlX2.js';
5
5
  import '@grpc/grpc-js';
6
6
  import 'node:events';
7
7
  import 'zod';
package/dist/client.js CHANGED
@@ -1,13 +1,13 @@
1
- export { LiopClient } from './chunk-GYJQ63L2.js';
2
- import './chunk-ESRXG36Y.js';
3
- import './chunk-DZ2FQGJD.js';
4
- import './chunk-PEN3KFLF.js';
1
+ export { LiopClient } from './chunk-KB7LNCVI.js';
2
+ import './chunk-VRZ3UIYA.js';
3
+ import './chunk-UAUBVKMK.js';
4
+ import './chunk-RWBFGRF7.js';
5
5
  import './chunk-IK7CGWAZ.js';
6
6
  import './chunk-7PITYWOV.js';
7
- import './chunk-3BJ5QQHK.js';
7
+ import './chunk-COISHJK5.js';
8
8
  import './chunk-PAICJCKJ.js';
9
- import './chunk-EG46XMJT.js';
10
- import './chunk-7RXOIDXP.js';
11
- import './chunk-HA6YZ42O.js';
9
+ import './chunk-2KSO3W4A.js';
10
+ import './chunk-QJIXNZTL.js';
11
+ import './chunk-LIBI3HMN.js';
12
12
  //# sourceMappingURL=client.js.map
13
13
  //# sourceMappingURL=client.js.map
package/dist/gateway.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import './node-B0b2vUFS.js';
2
- import './index-DoW2gzBZ.js';
3
- export { L as LiopHybridGateway } from './hybrid-CrKB50nh.js';
2
+ import './index-Dqn4dtZP.js';
3
+ import './types-CMYlWlX2.js';
4
+ export { L as LiopHybridGateway } from './hybrid-CTC9oYVp.js';
4
5
  import 'zod';
5
- import './types-lJIxBlWF.js';
6
6
  import 'jose';
7
7
  import './verifier-COnid_dg.js';
package/dist/gateway.js CHANGED
@@ -1,13 +1,13 @@
1
- export { LiopHybridGateway } from './chunk-JPYPTJHX.js';
2
- import './chunk-V2TP43CD.js';
3
- import './chunk-DZ2FQGJD.js';
4
- import './chunk-PEN3KFLF.js';
1
+ export { LiopHybridGateway } from './chunk-TDTGUVLB.js';
2
+ import './chunk-JPN5456V.js';
3
+ import './chunk-UAUBVKMK.js';
4
+ import './chunk-RWBFGRF7.js';
5
5
  import './chunk-IK7CGWAZ.js';
6
6
  import './chunk-7PITYWOV.js';
7
7
  import './chunk-VH4K4U45.js';
8
- import './chunk-3BJ5QQHK.js';
8
+ import './chunk-COISHJK5.js';
9
9
  import './chunk-PAICJCKJ.js';
10
- import './chunk-EG46XMJT.js';
11
- import './chunk-HA6YZ42O.js';
10
+ import './chunk-2KSO3W4A.js';
11
+ import './chunk-LIBI3HMN.js';
12
12
  //# sourceMappingURL=gateway.js.map
13
13
  //# sourceMappingURL=gateway.js.map
@@ -1,7 +1,7 @@
1
1
  import { a as MeshNode } from './node-B0b2vUFS.js';
2
- import { L as LiopServer } from './index-DoW2gzBZ.js';
2
+ import { L as LiopServer } from './index-Dqn4dtZP.js';
3
+ import { b as McpRequest, M as McpEra, A as AuthInfo, c as McpResponse, G as GatewayInterceptorOptions } from './types-CMYlWlX2.js';
3
4
  import { L as LiopVerifier } from './verifier-COnid_dg.js';
4
- import { b as McpRequest, M as McpEra, A as AuthInfo, c as McpResponse } from './types-lJIxBlWF.js';
5
5
 
6
6
  /**
7
7
  * LIOP Sliding-Window Rate Limiter
@@ -153,9 +153,10 @@ declare class LiopHybridGateway {
153
153
  private jwtValidator?;
154
154
  private oauthProvider?;
155
155
  private rateLimiter;
156
+ private readonly interceptorOptions?;
156
157
  private isDraining;
157
158
  private activeRequests;
158
- constructor(liopServer: LiopServer, meshNode?: MeshNode | null, rpcPort?: number, rateLimiterOptions?: RateLimiterOptions);
159
+ constructor(liopServer: LiopServer, meshNode?: MeshNode | null, rpcPort?: number, rateLimiterOptions?: RateLimiterOptions, interceptorOptions?: GatewayInterceptorOptions);
159
160
  private setupH2Routes;
160
161
  private setupH1Routes;
161
162
  private handleGrpcStream;
@@ -2,7 +2,7 @@ import { L as LiopVerifier } from './verifier-COnid_dg.js';
2
2
  import { M as MeshNodeConfig } from './node-B0b2vUFS.js';
3
3
  import * as grpc from '@grpc/grpc-js';
4
4
  import { EventEmitter } from 'node:events';
5
- import { M as McpEra, C as CallToolRequest, a as CallToolResult } from './types-lJIxBlWF.js';
5
+ import { M as McpEra, C as CallToolRequest, a as CallToolResult } from './types-CMYlWlX2.js';
6
6
 
7
7
  interface CertManagerOptions {
8
8
  /** Path to the root CA certificate (PEM format) */
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { M as MeshNodeConfig, a as MeshNode } from './node-B0b2vUFS.js';
3
- import { J as JwtValidator, S as ServerInfo, a as CallToolResult, P as Prompt, G as GetPromptRequest, d as GetPromptResult, C as CallToolRequest, T as Tool, R as Resource } from './types-lJIxBlWF.js';
3
+ import { d as AuditLogger, J as JwtValidator, S as ServerInfo, a as CallToolResult, P as Prompt, e as GetPromptRequest, f as GetPromptResult, C as CallToolRequest, T as Tool, R as Resource } from './types-CMYlWlX2.js';
4
4
 
5
5
  /**
6
6
  * LIOP OAuth 2.1 Hybrid Auth — Configuration Types
@@ -100,55 +100,6 @@ declare const AUTH_DEFAULTS: {
100
100
  readonly signingAlgorithm: "EdDSA";
101
101
  };
102
102
 
103
- type AuditStatus = "SUCCESS" | "BLOCKED_EGRESS" | "ERROR" | "POLICY_VIOLATION";
104
- interface AuditEntry {
105
- id: string;
106
- timestamp: string;
107
- traceId: string;
108
- agentDid: string;
109
- peerId: string;
110
- toolName: string;
111
- datasetHash: string;
112
- fuelConsumed: number;
113
- outputHash: string;
114
- zkReceiptSig: string;
115
- status: AuditStatus;
116
- prevEntryHash: string;
117
- entryHash: string;
118
- }
119
- interface AuditRecordParams {
120
- timestamp?: string;
121
- traceId?: string;
122
- agentDid: string;
123
- peerId: string;
124
- toolName: string;
125
- datasetHash?: string;
126
- fuelConsumed: number;
127
- outputHash?: string;
128
- zkReceiptSig?: string;
129
- status: AuditStatus;
130
- }
131
- declare const GENESIS_HASH: string;
132
- declare function computeEntryHash(entryWithoutHash: Omit<AuditEntry, "entryHash">): string;
133
- declare class AuditLogger {
134
- private entries;
135
- private lastEntryHash;
136
- private filePath?;
137
- constructor(filePath?: string);
138
- recordExecution(params: AuditRecordParams): AuditEntry;
139
- getEntries(): readonly AuditEntry[];
140
- getEntryCount(): number;
141
- verifyIntegrity(): {
142
- valid: boolean;
143
- totalEntries: number;
144
- brokenIndex?: number;
145
- reason?: string;
146
- };
147
- exportJsonl(): string;
148
- private loadFromFile;
149
- }
150
- declare const globalAuditLogger: AuditLogger;
151
-
152
103
  /** Single named entity detected by the NER scanner. */
153
104
  interface NerEntity {
154
105
  type: "person" | "place" | "organization";
@@ -563,4 +514,4 @@ declare class LiopServer {
563
514
  private applyInMemoryBudget;
564
515
  }
565
516
 
566
- export { AUTH_DEFAULTS as A, GENESIS_HASH as G, LiopServer as L, NerScanner as N, type OAuthClientConfig as O, PII_PATTERNS as P, type ToolHandler as T, type LiopServerOptions as a, type AggregationPolicy as b, type AuditEntry as c, AuditLogger as d, type AuditRecordParams as e, type AuditStatus as f, type AuthRole as g, type LiopAuthConfig as h, type LogicExecutionPolicy as i, type OutputSanitizerConfig as j, PII_PRESETS as k, type PiiRule as l, PiiScanner as m, computeEntryHash as n, globalAuditLogger as o, sanitizeOutput as s };
517
+ export { AUTH_DEFAULTS as A, LiopServer as L, NerScanner as N, type OAuthClientConfig as O, PII_PATTERNS as P, type ToolHandler as T, type LiopServerOptions as a, type AggregationPolicy as b, type AuthRole as c, type LiopAuthConfig as d, type LogicExecutionPolicy as e, type OutputSanitizerConfig as f, PII_PRESETS as g, type PiiRule as h, PiiScanner as i, sanitizeOutput as s };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  export { LiopBridgeOptions, LiopMcpBridge, LiopStreamBridge, LiopStreamBridgeOptions } from './bridge.js';
2
- import { L as LiopTlsOptions } from './index-CYr7H4aY.js';
3
- export { C as CertInfo, a as CertManager, b as CertManagerOptions, c as LiopClient, d as createChannelCredentials, e as createServerCredentials } from './index-CYr7H4aY.js';
2
+ import { L as LiopTlsOptions } from './index-DHdTB7B8.js';
3
+ export { C as CertInfo, a as CertManager, b as CertManagerOptions, c as LiopClient, d as createChannelCredentials, e as createServerCredentials } from './index-DHdTB7B8.js';
4
4
  import * as http from 'node:http';
5
- export { I as InMemoryRateLimiter, L as LiopHybridGateway, a as LiopMcpRouter, R as RateLimitStatus, b as RateLimiterOptions } from './hybrid-CrKB50nh.js';
5
+ export { I as InMemoryRateLimiter, L as LiopHybridGateway, a as LiopMcpRouter, R as RateLimitStatus, b as RateLimiterOptions } from './hybrid-CTC9oYVp.js';
6
+ import { A as AuthInfo } from './types-CMYlWlX2.js';
7
+ export { g as AuditEntry, h as AuditInterceptor, d as AuditLogger, i as AuditRecordParams, j as AuditStatus, k as CacheableResult, C as CallToolRequest, a as CallToolResult, D as DiscoverResult, l as GENESIS_HASH, m as GatewayAdmissionResult, n as GatewayInterceptor, o as GatewayInterceptorContext, G as GatewayInterceptorOptions, e as GetPromptRequest, f as GetPromptResult, I as InputRequest, p as InputRequiredResult, q as InputResponse, J as JwtValidator, L as LogEvent, r as LogInterceptor, s as MCP_LEGACY_SUPPORT_ENABLED, t as MCP_PROTOCOL_VERSION, u as MCP_PROTOCOL_VERSION_LEGACY, M as McpEra, b as McpRequest, v as McpRequestMeta, c as McpResponse, P as Prompt, w as PromptSchema, R as Resource, x as ResourceSchema, S as ServerInfo, T as Tool, y as ToolSchema, z as computeEntryHash, B as executeGatewayInterceptor, E as globalAuditLogger } from './types-CMYlWlX2.js';
6
8
  export { L as LiopManifest, a as MeshNode, M as MeshNodeConfig } from './node-B0b2vUFS.js';
7
9
  export { SWARM_KEY_BYTE_LENGTH, createSwarmKey, deserializeSwarmKey, loadSwarmKey, parseSwarmKey, saveSwarmKey, serializeSwarmKey } from './mesh.js';
8
10
  import * as grpc from '@grpc/grpc-js';
9
- export { A as AUTH_DEFAULTS, b as AggregationPolicy, c as AuditEntry, d as AuditLogger, e as AuditRecordParams, f as AuditStatus, g as AuthRole, G as GENESIS_HASH, h as LiopAuthConfig, L as LiopServer, a as LiopServerOptions, i as LogicExecutionPolicy, N as NerScanner, O as OAuthClientConfig, j as OutputSanitizerConfig, P as PII_PATTERNS, k as PII_PRESETS, l as PiiRule, m as PiiScanner, T as ToolHandler, n as computeEntryHash, o as globalAuditLogger, s as sanitizeOutput } from './index-DoW2gzBZ.js';
10
- import { A as AuthInfo } from './types-lJIxBlWF.js';
11
- export { e as CacheableResult, C as CallToolRequest, a as CallToolResult, D as DiscoverResult, G as GetPromptRequest, d as GetPromptResult, I as InputRequest, f as InputRequiredResult, g as InputResponse, J as JwtValidator, h as MCP_LEGACY_SUPPORT_ENABLED, i as MCP_PROTOCOL_VERSION, j as MCP_PROTOCOL_VERSION_LEGACY, M as McpEra, b as McpRequest, k as McpRequestMeta, c as McpResponse, P as Prompt, l as PromptSchema, R as Resource, m as ResourceSchema, S as ServerInfo, T as Tool, n as ToolSchema } from './types-lJIxBlWF.js';
11
+ export { A as AUTH_DEFAULTS, b as AggregationPolicy, c as AuthRole, d as LiopAuthConfig, L as LiopServer, a as LiopServerOptions, e as LogicExecutionPolicy, N as NerScanner, O as OAuthClientConfig, f as OutputSanitizerConfig, P as PII_PATTERNS, g as PII_PRESETS, h as PiiRule, i as PiiScanner, T as ToolHandler, s as sanitizeOutput } from './index-Dqn4dtZP.js';
12
12
  import * as jose from 'jose';
13
13
  import Provider from 'oidc-provider';
14
14
  import '@modelcontextprotocol/sdk/server/mcp.js';
package/dist/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
  export { WasiSandbox, calculateAstInstructionFuel, getDefaultEnvironment } from './chunk-7BSCUYUE.js';
2
- export { AesGcmWrapper, LiopClient, LiopRpcClient } from './chunk-GYJQ63L2.js';
3
- export { LiopMcpBridge, LiopStreamBridge } from './chunk-U2KYB6FN.js';
4
- export { GRPC_WEB_CONSTANTS, InMemoryRateLimiter, LiopHybridGateway, buildProtectedResourceMetadata, decodeFrames, dispatchGrpcWebRequest, encodeDataFrame, encodeTrailerFrame, isGrpcWebRequest } from './chunk-JPYPTJHX.js';
5
- export { RoutingTable, probeTopology } from './chunk-UCVP3XAL.js';
6
- export { TokenManager } from './chunk-ESRXG36Y.js';
7
- export { AUTH_DEFAULTS, AuditLogger, GENESIS_HASH, JwtValidator, LiopRpcServer, LiopServer, NerScanner, PII_PATTERNS, PII_PRESETS, PiiScanner, computeEntryHash, createOAuthServer, globalAuditLogger } from './chunk-UWC7OY7K.js';
2
+ export { AesGcmWrapper, LiopClient, LiopRpcClient } from './chunk-KB7LNCVI.js';
3
+ export { LiopMcpBridge, LiopStreamBridge } from './chunk-OSJDFUBY.js';
4
+ export { GRPC_WEB_CONSTANTS, InMemoryRateLimiter, LiopHybridGateway, buildProtectedResourceMetadata, decodeFrames, dispatchGrpcWebRequest, encodeDataFrame, encodeTrailerFrame, executeGatewayInterceptor, isGrpcWebRequest } from './chunk-TDTGUVLB.js';
5
+ export { RoutingTable, probeTopology } from './chunk-HWUCX2II.js';
6
+ export { TokenManager } from './chunk-VRZ3UIYA.js';
7
+ export { AUTH_DEFAULTS, AuditLogger, GENESIS_HASH, JwtValidator, LiopRpcServer, LiopServer, NerScanner, PII_PATTERNS, PII_PRESETS, PiiScanner, computeEntryHash, createOAuthServer, globalAuditLogger } from './chunk-6CPRIMCD.js';
8
8
  export { sanitizeOutput } from './chunk-Y62GORQF.js';
9
- export { LiopMcpRouter } from './chunk-V2TP43CD.js';
10
- export { HeuristicTokenEstimator, LiopOTelBridge, RealTokenEstimator, TokenTelemetryEngine, createSyncTokenEstimator, createTokenEstimator } from './chunk-DZ2FQGJD.js';
11
- import './chunk-PEN3KFLF.js';
9
+ export { LiopMcpRouter } from './chunk-JPN5456V.js';
10
+ export { HeuristicTokenEstimator, LiopOTelBridge, RealTokenEstimator, TokenTelemetryEngine, createSyncTokenEstimator, createTokenEstimator } from './chunk-UAUBVKMK.js';
11
+ import './chunk-RWBFGRF7.js';
12
12
  import './chunk-IK7CGWAZ.js';
13
13
  export { Kyber768Wrapper } from './chunk-7PITYWOV.js';
14
14
  export { DILITHIUM65_CONSTANTS, Dilithium65Wrapper, LIOP_SCOPES, authorizeRequest } from './chunk-VH4K4U45.js';
15
- export { GRPC_CHANNEL_OPTIONS, createChannelCredentials, createServerCredentials } from './chunk-3BJ5QQHK.js';
15
+ export { GRPC_CHANNEL_OPTIONS, createChannelCredentials, createServerCredentials } from './chunk-COISHJK5.js';
16
16
  export { Counter, Gauge, Histogram, MetricsRegistry, egressBlocksTotal, fuelConsumed, manifestCacheSize, meshPeersConnected, operationDurationMs, pqcHandshakeDurationMs, pqcHandshakesTotal, protocolMetrics, tokensInputTotal, tokensOutputTotal, tokensSavedTotal, toolCallErrorsTotal, toolCallsTotal, wireEgressBytesTotal, wireSavedBytesTotal, zkVerificationDurationMs, zkVerificationsTotal } from './chunk-PAICJCKJ.js';
17
- export { MCP_LEGACY_SUPPORT_ENABLED, MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION_LEGACY, PromptSchema, ResourceSchema, ToolSchema } from './chunk-EG46XMJT.js';
17
+ export { MCP_LEGACY_SUPPORT_ENABLED, MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION_LEGACY, PromptSchema, ResourceSchema, ToolSchema } from './chunk-2KSO3W4A.js';
18
18
  export { SWARM_KEY_BYTE_LENGTH, createSwarmKey, deserializeSwarmKey, loadSwarmKey, parseSwarmKey, saveSwarmKey, serializeSwarmKey } from './chunk-ZP3VVXOI.js';
19
- export { MeshNode } from './chunk-7RXOIDXP.js';
20
- import { log } from './chunk-HA6YZ42O.js';
19
+ export { MeshNode } from './chunk-QJIXNZTL.js';
20
+ import { log } from './chunk-LIBI3HMN.js';
21
21
  import * as crypto from 'crypto';
22
22
  import { EventEmitter } from 'events';
23
23
  import * as fs from 'fs';
package/dist/mesh.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import './chunk-FTF6AMF6.js';
2
2
  export { SWARM_KEY_BYTE_LENGTH, createSwarmKey, deserializeSwarmKey, loadSwarmKey, parseSwarmKey, saveSwarmKey, serializeSwarmKey } from './chunk-ZP3VVXOI.js';
3
- export { MeshNode } from './chunk-7RXOIDXP.js';
4
- import './chunk-HA6YZ42O.js';
3
+ export { MeshNode } from './chunk-QJIXNZTL.js';
4
+ import './chunk-LIBI3HMN.js';
5
5
  //# sourceMappingURL=mesh.js.map
6
6
  //# sourceMappingURL=mesh.js.map
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { b as AggregationPolicy, L as LiopServer, a as LiopServerOptions, i as LogicExecutionPolicy, N as NerScanner, j as OutputSanitizerConfig, P as PII_PATTERNS, k as PII_PRESETS, l as PiiRule, m as PiiScanner, T as ToolHandler, s as sanitizeOutput } from './index-DoW2gzBZ.js';
1
+ export { b as AggregationPolicy, L as LiopServer, a as LiopServerOptions, e as LogicExecutionPolicy, N as NerScanner, f as OutputSanitizerConfig, P as PII_PATTERNS, g as PII_PRESETS, h as PiiRule, i as PiiScanner, T as ToolHandler, s as sanitizeOutput } from './index-Dqn4dtZP.js';
2
2
  import 'zod';
3
3
  import './node-B0b2vUFS.js';
4
- import './types-lJIxBlWF.js';
4
+ import './types-CMYlWlX2.js';
5
5
  import 'jose';
package/dist/server.js CHANGED
@@ -1,9 +1,9 @@
1
- export { LiopServer, NerScanner, PII_PATTERNS, PII_PRESETS, PiiScanner } from './chunk-UWC7OY7K.js';
1
+ export { LiopServer, NerScanner, PII_PATTERNS, PII_PRESETS, PiiScanner } from './chunk-6CPRIMCD.js';
2
2
  export { sanitizeOutput } from './chunk-Y62GORQF.js';
3
3
  import './chunk-VH4K4U45.js';
4
- import './chunk-3BJ5QQHK.js';
4
+ import './chunk-COISHJK5.js';
5
5
  import './chunk-PAICJCKJ.js';
6
- import './chunk-7RXOIDXP.js';
7
- import './chunk-HA6YZ42O.js';
6
+ import './chunk-QJIXNZTL.js';
7
+ import './chunk-LIBI3HMN.js';
8
8
  //# sourceMappingURL=server.js.map
9
9
  //# sourceMappingURL=server.js.map
@@ -1,6 +1,80 @@
1
1
  import { z } from 'zod';
2
2
  import * as jose from 'jose';
3
3
 
4
+ /**
5
+ * Technology-agnostic cryptographic audit interceptor.
6
+ *
7
+ * Fires asynchronously (fire-and-forget) AFTER each AuditEntry
8
+ * has been sealed (hash computed, chain linked, and optionally
9
+ * persisted to JSONL). The interceptor receives a frozen deep-clone
10
+ * of the completed AuditEntry — mutations cannot tamper with the
11
+ * hash chain.
12
+ *
13
+ * Use cases: forward audit entries to TypeSafe Jev for threat
14
+ * pattern detection, stream to SOC 2 SIEM aggregators, trigger
15
+ * PagerDuty alerts on BLOCKED_EGRESS/POLICY_VIOLATION statuses,
16
+ * or feed into compliance dashboards.
17
+ */
18
+ type AuditInterceptor = (entry: Readonly<AuditEntry>) => void | Promise<void>;
19
+
20
+ type AuditStatus = "SUCCESS" | "BLOCKED_EGRESS" | "ERROR" | "POLICY_VIOLATION";
21
+ interface AuditEntry {
22
+ id: string;
23
+ timestamp: string;
24
+ traceId: string;
25
+ agentDid: string;
26
+ peerId: string;
27
+ toolName: string;
28
+ datasetHash: string;
29
+ fuelConsumed: number;
30
+ outputHash: string;
31
+ zkReceiptSig: string;
32
+ status: AuditStatus;
33
+ prevEntryHash: string;
34
+ entryHash: string;
35
+ }
36
+ interface AuditRecordParams {
37
+ timestamp?: string;
38
+ traceId?: string;
39
+ agentDid: string;
40
+ peerId: string;
41
+ toolName: string;
42
+ datasetHash?: string;
43
+ fuelConsumed: number;
44
+ outputHash?: string;
45
+ zkReceiptSig?: string;
46
+ status: AuditStatus;
47
+ }
48
+ declare const GENESIS_HASH: string;
49
+ declare function computeEntryHash(entryWithoutHash: Omit<AuditEntry, "entryHash">): string;
50
+ declare class AuditLogger {
51
+ private entries;
52
+ private lastEntryHash;
53
+ private filePath?;
54
+ private interceptor?;
55
+ constructor(filePath?: string);
56
+ /**
57
+ * Registers a technology-agnostic audit interceptor.
58
+ * The interceptor fires AFTER the entry is sealed (hash computed)
59
+ * and appended to the chain. It receives a frozen deep-clone
60
+ * that cannot tamper with the hash chain.
61
+ * Pass `undefined` to disable interception (zero overhead).
62
+ */
63
+ setInterceptor(interceptor: AuditInterceptor | undefined): void;
64
+ recordExecution(params: AuditRecordParams): AuditEntry;
65
+ getEntries(): readonly AuditEntry[];
66
+ getEntryCount(): number;
67
+ verifyIntegrity(): {
68
+ valid: boolean;
69
+ totalEntries: number;
70
+ brokenIndex?: number;
71
+ reason?: string;
72
+ };
73
+ exportJsonl(): string;
74
+ private loadFromFile;
75
+ }
76
+ declare const globalAuditLogger: AuditLogger;
77
+
4
78
  /**
5
79
  * LIOP JWT Validator — Token Verification Engine
6
80
  *
@@ -97,6 +171,95 @@ declare const MCP_LEGACY_SUPPORT_ENABLED = true;
97
171
  */
98
172
  declare const MCP_PROTOCOL_VERSION_LEGACY: "2025-11-25";
99
173
 
174
+ /**
175
+ * Verdict returned by a GatewayInterceptor function.
176
+ * Determines whether the request is admitted into the routing pipeline.
177
+ */
178
+ interface GatewayAdmissionResult {
179
+ /** true = request passes to router.dispatch(). false = rejected at perimeter. */
180
+ allowed: boolean;
181
+ /** Human-readable denial reason (included in JSON-RPC error response). */
182
+ reason?: string;
183
+ /** Custom JSON-RPC error code. Defaults to -32099 when omitted. */
184
+ errorCode?: number;
185
+ /** Opaque metadata bag for telemetry or audit logging downstream. */
186
+ metadata?: Record<string, unknown>;
187
+ }
188
+ /**
189
+ * Contextual information passed to the interceptor alongside the request.
190
+ * Contains only non-sensitive, non-cryptographic perimeter metadata.
191
+ */
192
+ interface GatewayInterceptorContext {
193
+ /** Originating client IP address (post-JWT, post-rate-limit). */
194
+ clientIp: string;
195
+ /** Authenticated identity from JWT validation, or null for unauthenticated gateways. */
196
+ authInfo: AuthInfo | null;
197
+ /** Transport protocol that received this request. */
198
+ protocol: "http1" | "http2";
199
+ /** Abort signal that fires when the interceptor timeout expires. */
200
+ signal: AbortSignal;
201
+ }
202
+ /**
203
+ * Technology-agnostic admission function.
204
+ * The developer implements this in their application code, connecting
205
+ * any decision engine (TypeSafe Jev, ONNX, regex rules, custom logic).
206
+ *
207
+ * Receives a frozen deep-clone of the request to prevent prototype pollution.
208
+ * May return synchronously or asynchronously.
209
+ */
210
+ type GatewayInterceptor = (request: Readonly<McpRequest>, context: GatewayInterceptorContext) => Promise<GatewayAdmissionResult> | GatewayAdmissionResult;
211
+ /**
212
+ * Configuration for the perimeter admission hook.
213
+ */
214
+ interface GatewayInterceptorOptions {
215
+ /** The interceptor function. When undefined, the gateway skips interception entirely. */
216
+ interceptor?: GatewayInterceptor;
217
+ /** Maximum milliseconds to wait for the interceptor. Default: 2500. */
218
+ timeoutMs?: number;
219
+ /** Behavior when the interceptor throws or times out. Default: "closed". */
220
+ failMode?: "closed" | "open";
221
+ }
222
+ /**
223
+ * Executes the interceptor with timeout enforcement via AbortSignal.timeout(),
224
+ * prototype pollution isolation via structuredClone + Object.freeze,
225
+ * and fail-mode policy enforcement.
226
+ *
227
+ * AbortSignal.timeout() is stable since Node.js 17.3 (available in Node.js 20+ LTS).
228
+ * Promise.race guarantees the gateway never blocks beyond timeoutMs even if the
229
+ * interceptor ignores the signal.
230
+ */
231
+ declare function executeGatewayInterceptor(request: McpRequest, context: Omit<GatewayInterceptorContext, "signal">, options: Required<Pick<GatewayInterceptorOptions, "interceptor">> & GatewayInterceptorOptions): Promise<GatewayAdmissionResult>;
232
+
233
+ type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
234
+
235
+ /**
236
+ * Structured snapshot of an operational log event.
237
+ * Frozen copy — mutations have no effect on the logger.
238
+ */
239
+ interface LogEvent {
240
+ /** ISO 8601 timestamp of the log emission. */
241
+ timestamp: string;
242
+ /** Severity level that triggered this event. */
243
+ level: LogLevel;
244
+ /** Formatted log message (already interpolated by LiopLogger). */
245
+ message: string;
246
+ /** Additional variadic arguments passed to the log method. */
247
+ args: readonly unknown[];
248
+ }
249
+ /**
250
+ * Technology-agnostic operational log interceptor.
251
+ *
252
+ * Fires asynchronously (fire-and-forget) after each log emission
253
+ * that passes the current level filter. The interceptor receives
254
+ * a frozen snapshot of the log event. Errors thrown by the
255
+ * interceptor are caught silently and never propagate to the caller.
256
+ *
257
+ * Use cases: forward logs to TypeSafe Jev for anomaly detection,
258
+ * stream to a SIEM (Splunk, Datadog), aggregate in NotebookLM,
259
+ * or persist to a custom observability backend.
260
+ */
261
+ type LogInterceptor = (event: Readonly<LogEvent>) => void | Promise<void>;
262
+
100
263
  /**
101
264
  * Protocol Version Identifiers
102
265
  */
@@ -253,4 +416,4 @@ interface McpResponse {
253
416
  };
254
417
  }
255
418
 
256
- export { type AuthInfo as A, type CallToolRequest as C, type DiscoverResult as D, type GetPromptRequest as G, type InputRequest as I, JwtValidator as J, type McpEra as M, type Prompt as P, type Resource as R, type ServerInfo as S, type Tool as T, type CallToolResult as a, type McpRequest as b, type McpResponse as c, type GetPromptResult as d, type CacheableResult as e, type InputRequiredResult as f, type InputResponse as g, MCP_LEGACY_SUPPORT_ENABLED as h, MCP_PROTOCOL_VERSION as i, MCP_PROTOCOL_VERSION_LEGACY as j, type McpRequestMeta as k, PromptSchema as l, ResourceSchema as m, ToolSchema as n };
419
+ export { type AuthInfo as A, executeGatewayInterceptor as B, type CallToolRequest as C, type DiscoverResult as D, globalAuditLogger as E, type GatewayInterceptorOptions as G, type InputRequest as I, JwtValidator as J, type LogEvent as L, type McpEra as M, type Prompt as P, type Resource as R, type ServerInfo as S, type Tool as T, type CallToolResult as a, type McpRequest as b, type McpResponse as c, AuditLogger as d, type GetPromptRequest as e, type GetPromptResult as f, type AuditEntry as g, type AuditInterceptor as h, type AuditRecordParams as i, type AuditStatus as j, type CacheableResult as k, GENESIS_HASH as l, type GatewayAdmissionResult as m, type GatewayInterceptor as n, type GatewayInterceptorContext as o, type InputRequiredResult as p, type InputResponse as q, type LogInterceptor as r, MCP_LEGACY_SUPPORT_ENABLED as s, MCP_PROTOCOL_VERSION as t, MCP_PROTOCOL_VERSION_LEGACY as u, type McpRequestMeta as v, PromptSchema as w, ResourceSchema as x, ToolSchema as y, computeEntryHash as z };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import 'zod';
2
- export { A as AuthInfo, e as CacheableResult, C as CallToolRequest, a as CallToolResult, D as DiscoverResult, G as GetPromptRequest, d as GetPromptResult, I as InputRequest, f as InputRequiredResult, g as InputResponse, h as MCP_LEGACY_SUPPORT_ENABLED, i as MCP_PROTOCOL_VERSION, j as MCP_PROTOCOL_VERSION_LEGACY, M as McpEra, b as McpRequest, k as McpRequestMeta, c as McpResponse, P as Prompt, l as PromptSchema, R as Resource, m as ResourceSchema, S as ServerInfo, T as Tool, n as ToolSchema } from './types-lJIxBlWF.js';
2
+ export { h as AuditInterceptor, A as AuthInfo, k as CacheableResult, C as CallToolRequest, a as CallToolResult, D as DiscoverResult, m as GatewayAdmissionResult, n as GatewayInterceptor, o as GatewayInterceptorContext, G as GatewayInterceptorOptions, e as GetPromptRequest, f as GetPromptResult, I as InputRequest, p as InputRequiredResult, q as InputResponse, L as LogEvent, r as LogInterceptor, s as MCP_LEGACY_SUPPORT_ENABLED, t as MCP_PROTOCOL_VERSION, u as MCP_PROTOCOL_VERSION_LEGACY, M as McpEra, b as McpRequest, v as McpRequestMeta, c as McpResponse, P as Prompt, w as PromptSchema, R as Resource, x as ResourceSchema, S as ServerInfo, T as Tool, y as ToolSchema } from './types-CMYlWlX2.js';
3
3
  import 'jose';
package/dist/types.js CHANGED
@@ -1,3 +1,3 @@
1
- export { MCP_LEGACY_SUPPORT_ENABLED, MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION_LEGACY, PromptSchema, ResourceSchema, ToolSchema } from './chunk-EG46XMJT.js';
1
+ export { MCP_LEGACY_SUPPORT_ENABLED, MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION_LEGACY, PromptSchema, ResourceSchema, ToolSchema } from './chunk-2KSO3W4A.js';
2
2
  //# sourceMappingURL=types.js.map
3
3
  //# sourceMappingURL=types.js.map
@@ -0,0 +1,6 @@
1
+ export { LiopVerifier } from './chunk-RWBFGRF7.js';
2
+ import './chunk-IK7CGWAZ.js';
3
+ import './chunk-PAICJCKJ.js';
4
+ import './chunk-LIBI3HMN.js';
5
+ //# sourceMappingURL=verifier-A7HX6KAJ.js.map
6
+ //# sourceMappingURL=verifier-A7HX6KAJ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"verifier-HRFXBKT5.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"verifier-A7HX6KAJ.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nekzus/liop",
3
- "version": "2.4.0-alpha.12",
3
+ "version": "2.4.0-alpha.14",
4
4
  "description": "Official SDK for Logic-Injection-on-Origin Protocol (LIOP). Deploy Logic-on-Origin with WebAssembly at gRPC speed and bidirectional MCP compatibility.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -86,15 +86,15 @@
86
86
  "node": ">=20.0"
87
87
  },
88
88
  "devDependencies": {
89
- "@biomejs/biome": "2.5.10",
89
+ "@biomejs/biome": "2.5.14",
90
90
  "@opentelemetry/api": "1.9.1",
91
- "@opentelemetry/sdk-metrics": "2.10.0",
91
+ "@opentelemetry/sdk-metrics": "2.11.0",
92
92
  "@types/node": "26.4.0",
93
- "@types/oidc-provider": "9.11.1",
93
+ "@types/oidc-provider": "9.12.1",
94
94
  "@vitest/coverage-v8": "4.1.11",
95
95
  "gpt-tokenizer": "4.0.0",
96
96
  "tsup": "8.5.1",
97
- "tsx": "4.23.12",
97
+ "tsx": "4.23.13",
98
98
  "typescript": "6.0.3",
99
99
  "vitest": "4.1.11"
100
100
  },
@@ -105,37 +105,37 @@
105
105
  "@grpc/proto-loader": "0.8.1",
106
106
  "@hono/node-server": "2.1.1",
107
107
  "@libp2p/autonat": "^3.0.27",
108
- "@libp2p/bootstrap": "12.0.30",
108
+ "@libp2p/bootstrap": "12.0.32",
109
109
  "@libp2p/circuit-relay-v2": "^4.2.12",
110
110
  "@libp2p/crypto": "5.1.23",
111
111
  "@libp2p/dcutr": "^3.0.27",
112
- "@libp2p/identify": "4.1.13",
113
- "@libp2p/kad-dht": "16.4.4",
112
+ "@libp2p/identify": "4.1.14",
113
+ "@libp2p/kad-dht": "16.4.5",
114
114
  "@libp2p/mdns": "^12.0.30",
115
115
  "@libp2p/peer-id": "6.0.15",
116
- "@libp2p/ping": "3.1.12",
116
+ "@libp2p/ping": "3.1.13",
117
117
  "@libp2p/pnet": "^3.0.29",
118
- "@libp2p/tcp": "11.0.27",
119
- "@libp2p/websockets": "10.1.20",
118
+ "@libp2p/tcp": "11.0.28",
119
+ "@libp2p/websockets": "10.1.21",
120
120
  "@multiformats/multiaddr": "13.0.3",
121
- "@noble/post-quantum": "0.7.0",
121
+ "@noble/post-quantum": "0.7.1",
122
122
  "acorn": "8.18.0",
123
123
  "acorn-walk": "8.3.5",
124
- "hono": "4.13.5",
124
+ "hono": "4.13.8",
125
125
  "it-pipe": "3.0.1",
126
- "jose": "6.2.10",
127
- "libp2p": "3.3.9",
126
+ "jose": "6.2.12",
127
+ "libp2p": "3.3.11",
128
128
  "mlkem": "2.7.0",
129
129
  "multiformats": "14.0.5",
130
- "oidc-provider": "9.11.5",
130
+ "oidc-provider": "9.12.2",
131
131
  "optional": "0.1.4",
132
- "piscina": "5.3.1",
132
+ "piscina": "5.3.2",
133
133
  "uint8arrays": "6.1.1",
134
- "zod": "4.4.3"
134
+ "zod": "4.6.5"
135
135
  },
136
136
  "optionalDependencies": {
137
137
  "@modelcontextprotocol/sdk": "1.30.0",
138
- "compromise": "14.16.0"
138
+ "compromise": "14.17.0"
139
139
  },
140
140
  "peerDependencies": {
141
141
  "@modelcontextprotocol/sdk": "1.30.0",
@@ -152,9 +152,9 @@
152
152
  "overrides": {
153
153
  "content-type": "1.0.5",
154
154
  "protobufjs": "^7.6.1",
155
- "piscina": "5.3.1",
155
+ "piscina": "5.3.2",
156
156
  "ws": "^8.21.0",
157
- "hono": "4.13.5",
157
+ "hono": "4.13.8",
158
158
  "fast-uri": "^3.1.5",
159
159
  "brace-expansion": "^1.1.18",
160
160
  "ip-address": "^10.3.1",