@7h3/protocol 0.5.3 → 0.5.4

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/index.js CHANGED
@@ -1,14 +1,7 @@
1
- //#region \0rolldown/runtime.js
2
- var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, i, o, s) => {
3
- if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
4
- get: ((e) => i[e]).bind(null, d),
5
- enumerable: !(s = n(i, d)) || s.enumerable
6
- });
7
- return e;
8
- }, c = (n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
9
- value: n,
10
- enumerable: !0
11
- }) : a, n)), l = new TextEncoder(), u = 256, d = /* @__PURE__ */ new Map(), f = 256, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
1
+ import e from "node:readline";
2
+ import { createCipheriv as t, createDecipheriv as n, createPrivateKey as r, createPublicKey as i, diffieHellman as a, generateKeyPairSync as o, hkdfSync as s, randomBytes as c } from "node:crypto";
3
+ //#region src/protocol.ts
4
+ var l = new TextEncoder(), u = 256, d = /* @__PURE__ */ new Map(), f = 256, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
12
5
  function ee() {
13
6
  return globalThis.Buffer ?? null;
14
7
  }
@@ -24,7 +17,7 @@ function re(e) {
24
17
  let t = `hs256:${e}`, n = d.get(t);
25
18
  if (n) return n;
26
19
  d.size >= u && d.clear();
27
- let r = _().importKey("raw", l.encode(e), {
20
+ let r = v().importKey("raw", l.encode(e), {
28
21
  name: "HMAC",
29
22
  hash: "SHA-256"
30
23
  }, !1, ["sign", "verify"]).catch((e) => {
@@ -36,7 +29,7 @@ function ie(e) {
36
29
  let t = `ed25519:pkcs8:${e}`, n = p.get(t);
37
30
  if (n) return n;
38
31
  p.size >= f && p.clear();
39
- let r = _().importKey("pkcs8", se(h(e)), { name: "Ed25519" }, !1, ["sign"]).catch((e) => {
32
+ let r = v().importKey("pkcs8", oe(g(e)), { name: "Ed25519" }, !1, ["sign"]).catch((e) => {
40
33
  throw p.delete(t), e;
41
34
  });
42
35
  return p.set(t, r), r;
@@ -45,33 +38,33 @@ function ae(e) {
45
38
  let t = `ed25519:spki:${e}`, n = m.get(t);
46
39
  if (n) return n;
47
40
  m.size >= f && m.clear();
48
- let r = _().importKey("spki", se(h(e)), { name: "Ed25519" }, !1, ["verify"]).catch((e) => {
41
+ let r = v().importKey("spki", oe(g(e)), { name: "Ed25519" }, !1, ["verify"]).catch((e) => {
49
42
  throw m.delete(t), e;
50
43
  });
51
44
  return m.set(t, r), r;
52
45
  }
53
- function oe(e) {
46
+ function h(e) {
54
47
  let t = ee();
55
48
  return (t ? t.from(e).toString("base64") : btoa(String.fromCharCode(...e))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
56
49
  }
57
- function h(e) {
50
+ function g(e) {
58
51
  let t = e.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(e.length / 4) * 4, "="), n = ee();
59
52
  if (n) return new Uint8Array(n.from(t, "base64"));
60
53
  let r = atob(t), i = new Uint8Array(r.length);
61
54
  for (let e = 0; e < r.length; e += 1) i[e] = r.charCodeAt(e);
62
55
  return i;
63
56
  }
64
- function se(e) {
57
+ function oe(e) {
65
58
  return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
66
59
  }
67
- function g(e) {
60
+ function _(e) {
68
61
  return `{"body":${ne(e.body)},"header":${te(e.header)}}`;
69
62
  }
70
- function _() {
63
+ function v() {
71
64
  if (typeof crypto > "u" || !crypto.subtle) throw Error("Web Crypto API is not available in this runtime");
72
65
  return crypto.subtle;
73
66
  }
74
- function v(e = 12) {
67
+ function y(e = 12) {
75
68
  if (typeof crypto > "u" || !crypto.getRandomValues) throw Error("Web Crypto API is not available in this runtime");
76
69
  let t = new Uint8Array(e);
77
70
  crypto.getRandomValues(t);
@@ -79,43 +72,43 @@ function v(e = 12) {
79
72
  for (let e of t) n += e.toString(16).padStart(2, "0");
80
73
  return n;
81
74
  }
82
- async function ce(e, t) {
83
- let n = _(), r = await re(t), i = await n.sign("HMAC", r, l.encode(e));
84
- return oe(new Uint8Array(i));
75
+ async function se(e, t) {
76
+ let n = v(), r = await re(t), i = await n.sign("HMAC", r, l.encode(e));
77
+ return h(new Uint8Array(i));
85
78
  }
86
- async function le(e, t, n) {
87
- let r = _(), i = await re(n), a = h(t);
79
+ async function ce(e, t, n) {
80
+ let r = v(), i = await re(n), a = g(t);
88
81
  return r.verify("HMAC", i, a.buffer, l.encode(e));
89
82
  }
90
- async function ue(e, t) {
91
- let n = _(), r = await ie(t), i = await n.sign("Ed25519", r, l.encode(e));
92
- return oe(new Uint8Array(i));
83
+ async function le(e, t) {
84
+ let n = v(), r = await ie(t), i = await n.sign("Ed25519", r, l.encode(e));
85
+ return h(new Uint8Array(i));
93
86
  }
94
- async function de(e, t, n) {
95
- let r = _(), i = await ae(n), a = h(t);
87
+ async function ue(e, t, n) {
88
+ let r = v(), i = await ae(n), a = g(t);
96
89
  return r.verify("Ed25519", i, a.buffer, l.encode(e));
97
90
  }
98
- async function fe(e, t) {
99
- return ce(e, t);
91
+ async function de(e, t) {
92
+ return se(e, t);
100
93
  }
101
- async function pe(e, t, n) {
102
- return le(e, t, n);
94
+ async function fe(e, t, n) {
95
+ return ce(e, t, n);
103
96
  }
104
- async function me() {
105
- let e = _(), t = await e.generateKey({ name: "Ed25519" }, !0, ["sign", "verify"]), n = await e.exportKey("pkcs8", t.privateKey), r = await e.exportKey("spki", t.publicKey);
97
+ async function pe() {
98
+ let e = v(), t = await e.generateKey({ name: "Ed25519" }, !0, ["sign", "verify"]), n = await e.exportKey("pkcs8", t.privateKey), r = await e.exportKey("spki", t.publicKey);
106
99
  return {
107
- privateKey: oe(new Uint8Array(n)),
108
- publicKey: oe(new Uint8Array(r))
100
+ privateKey: h(new Uint8Array(n)),
101
+ publicKey: h(new Uint8Array(r))
109
102
  };
110
103
  }
111
- async function y(e, t) {
112
- return ue(e, t);
104
+ async function b(e, t) {
105
+ return le(e, t);
113
106
  }
114
- async function b(e, t, n) {
115
- return de(e, t, n);
107
+ async function x(e, t, n) {
108
+ return ue(e, t, n);
116
109
  }
117
- async function x(e, t, n = "local-dev-key") {
118
- let r = await ce(g(e), t);
110
+ async function me(e, t, n = "local-dev-key") {
111
+ let r = await se(_(e), t);
119
112
  return {
120
113
  ...e,
121
114
  signature: {
@@ -125,14 +118,14 @@ async function x(e, t, n = "local-dev-key") {
125
118
  }
126
119
  };
127
120
  }
128
- async function he(e, t) {
129
- return !e.signature || e.signature.alg !== "HS256" ? !1 : le(g({
121
+ async function S(e, t) {
122
+ return !e.signature || e.signature.alg !== "HS256" ? !1 : ce(_({
130
123
  header: e.header,
131
124
  body: e.body
132
125
  }), e.signature.value, t);
133
126
  }
134
- async function S(e, t, n = "local-ed25519-key") {
135
- let r = await ue(g(e), t);
127
+ async function C(e, t, n = "local-ed25519-key") {
128
+ let r = await le(_(e), t);
136
129
  return {
137
130
  ...e,
138
131
  signature: {
@@ -142,19 +135,20 @@ async function S(e, t, n = "local-ed25519-key") {
142
135
  }
143
136
  };
144
137
  }
145
- async function C(e, t) {
146
- return !e.signature || e.signature.alg !== "ED25519" ? !1 : de(g({
138
+ async function w(e, t) {
139
+ return !e.signature || e.signature.alg !== "ED25519" ? !1 : ue(_({
147
140
  header: e.header,
148
141
  body: e.body
149
142
  }), e.signature.value, t);
150
143
  }
151
- async function ge(e, t) {
152
- return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ? he(e, t.secret) : C(e, t.publicKey);
144
+ async function he(e, t) {
145
+ return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ? S(e, t.secret) : w(e, t.publicKey);
153
146
  }
154
- async function _e(e, t, n) {
155
- return !t || t.alg !== n.alg ? !1 : n.alg === "HS256" ? pe(e, t.value, n.secret) : b(e, t.value, n.publicKey);
147
+ async function ge(e, t, n) {
148
+ return !t || t.alg !== n.alg ? !1 : n.alg === "HS256" ? fe(e, t.value, n.secret) : x(e, t.value, n.publicKey);
156
149
  }
157
- function w(e, t = Date.now()) {
150
+ var _e = 864e5;
151
+ function T(e, t = Date.now()) {
158
152
  let n = [], r = e.header ?? {}, i = e.body ?? {}, a = typeof r.version == "string" ? r.version : "", o = typeof r.messageId == "string" ? r.messageId : "", s = typeof r.sender == "string" ? r.sender : "", c = typeof r.nonce == "string" ? r.nonce : "", l = typeof r.timestampMs == "number" ? r.timestampMs : 0, u = typeof r.ttlMs == "number" ? r.ttlMs : 0, d = typeof i.content == "string" ? i.content : "";
159
153
  return a !== "7h3/0.1" && n.push({
160
154
  level: "error",
@@ -171,6 +165,9 @@ function w(e, t = Date.now()) {
171
165
  }), u <= 0 && n.push({
172
166
  level: "error",
173
167
  message: "ttlMs must be greater than zero"
168
+ }), u > 864e5 && n.push({
169
+ level: "error",
170
+ message: `ttlMs exceeds maximum allowed ${_e} ms`
174
171
  }), l + u < t && n.push({
175
172
  level: "error",
176
173
  message: "Message TTL expired"
@@ -179,17 +176,17 @@ function w(e, t = Date.now()) {
179
176
  message: "Empty content payload"
180
177
  }), n;
181
178
  }
182
- function T(e) {
179
+ function E(e) {
183
180
  let t = e.nowMs ?? Date.now();
184
181
  return {
185
182
  header: {
186
183
  version: "7h3/0.1",
187
- messageId: e.messageId ?? `msg-${t}-${v(6)}`,
184
+ messageId: e.messageId ?? `msg-${t}-${y(6)}`,
188
185
  timestampMs: t,
189
186
  ttlMs: e.ttlMs ?? 6e4,
190
187
  sender: e.sender,
191
188
  recipient: e.recipient,
192
- nonce: e.nonce ?? v(12)
189
+ nonce: e.nonce ?? y(12)
193
190
  },
194
191
  body: {
195
192
  intent: e.intent,
@@ -206,7 +203,7 @@ var ve = [
206
203
  73,
207
204
  80,
208
205
  66
209
- ], ye = Uint8Array.from(ve), be = 1, xe = 1024 * 1024, Se = 1, Ce = 2, we = 4, Te = 8, Ee = new TextEncoder(), De = new TextDecoder(), Oe = new Set([
206
+ ], ye = Uint8Array.from(ve), be = 1, xe = 1024 * 1024, Se = 1, Ce = 2, we = 4, Te = 8, Ee = new TextEncoder(), De = new TextDecoder(), Oe = /* @__PURE__ */ new Set([
210
207
  "PING",
211
208
  "PONG",
212
209
  "CAPS",
@@ -226,10 +223,10 @@ function je(e) {
226
223
  function Me(e) {
227
224
  return e === 1 ? "HS256" : e === 2 ? "ED25519" : null;
228
225
  }
229
- function E(e) {
226
+ function D(e) {
230
227
  return { bytes: ke(e) };
231
228
  }
232
- function D(e) {
229
+ function O(e) {
233
230
  return e ? 4 + e.bytes.byteLength : 0;
234
231
  }
235
232
  var Ne = class {
@@ -292,7 +289,7 @@ var Ne = class {
292
289
  }
293
290
  };
294
291
  function Fe(e) {
295
- let t = (e.header.recipient ? Se : 0) | (e.body.capability ? Ce : 0) | (e.body.correlationId ? we : 0) | (e.signature ? Te : 0), n = E(e.header.version), r = E(e.header.messageId), i = E(e.header.sender), a = E(e.header.nonce), o = E(e.body.intent), s = E(e.body.content), c = e.header.recipient ? E(e.header.recipient) : null, l = e.body.capability ? E(e.body.capability) : null, u = e.body.correlationId ? E(e.body.correlationId) : null, d = e.signature ? E(e.signature.keyId) : null, f = e.signature ? E(e.signature.value) : null, p = new Ne(ye.byteLength + 1 + 1 + 8 + 4 + D(n) + D(r) + D(i) + D(a) + D(o) + D(s) + D(c) + D(l) + D(u) + +!!e.signature + D(d) + D(f));
292
+ let t = (e.header.recipient ? Se : 0) | (e.body.capability ? Ce : 0) | (e.body.correlationId ? we : 0) | (e.signature ? Te : 0), n = D(e.header.version), r = D(e.header.messageId), i = D(e.header.sender), a = D(e.header.nonce), o = D(e.body.intent), s = D(e.body.content), c = e.header.recipient ? D(e.header.recipient) : null, l = e.body.capability ? D(e.body.capability) : null, u = e.body.correlationId ? D(e.body.correlationId) : null, d = e.signature ? D(e.signature.keyId) : null, f = e.signature ? D(e.signature.value) : null, p = new Ne(ye.byteLength + 1 + 1 + 8 + 4 + O(n) + O(r) + O(i) + O(a) + O(o) + O(s) + O(c) + O(l) + O(u) + +!!e.signature + O(d) + O(f));
296
293
  return p.writeBytes(ye), p.writeU8(be), p.writeU8(t), p.writeU64(e.header.timestampMs), p.writeU32(e.header.ttlMs), p.writeString(n), p.writeString(r), p.writeString(i), p.writeString(a), p.writeString(o), p.writeString(s), c && p.writeString(c), l && p.writeString(l), u && p.writeString(u), e.signature && d && f && (p.writeU8(je(e.signature.alg)), p.writeString(d), p.writeString(f)), p.finish();
297
294
  }
298
295
  function Ie(e, t = {}) {
@@ -433,7 +430,7 @@ var Le = class {
433
430
  this.items[t] = l, this.items[r] = c, t = r;
434
431
  }
435
432
  }
436
- }, O = class {
433
+ }, k = class {
437
434
  entries = /* @__PURE__ */ new Map();
438
435
  maxEntries;
439
436
  expiries = new Le();
@@ -673,7 +670,7 @@ function Je(e) {
673
670
  }];
674
671
  }
675
672
  }
676
- async function k(e, t = {}) {
673
+ async function A(e, t = {}) {
677
674
  let n = t.nowMs ?? Date.now(), r = t.requireSignature ?? !0, i = t.maxClockSkewMs ?? 3e4;
678
675
  async function a(e) {
679
676
  t.telemetry && await t.telemetry({
@@ -707,7 +704,7 @@ async function k(e, t = {}) {
707
704
  envelope: o.envelope
708
705
  };
709
706
  }
710
- let s = [...w(o.envelope, n)];
707
+ let s = [...T(o.envelope, n)];
711
708
  if (s.some((e) => e.level === "error")) return await a({
712
709
  phase: "rejected_validation",
713
710
  sender: o.envelope.header.sender,
@@ -764,7 +761,7 @@ async function k(e, t = {}) {
764
761
  diagnostics: s,
765
762
  envelope: o.envelope
766
763
  };
767
- if (!await _e(g({
764
+ if (!await ge(_({
768
765
  header: o.envelope.header,
769
766
  body: o.envelope.body
770
767
  }), o.envelope.signature, c)) return s.push({
@@ -815,7 +812,7 @@ async function Ye(e, t = {}) {
815
812
  let n = i;
816
813
  i += 1;
817
814
  let a = e[n];
818
- a && typeof a == "object" && "ok" in a && "diagnostics" in a && "envelope" in a ? r[n] = a : r[n] = await k(a, t);
815
+ a && typeof a == "object" && "ok" in a && "diagnostics" in a && "envelope" in a ? r[n] = a : r[n] = await A(a, t);
819
816
  }
820
817
  })), await t.telemetry?.({
821
818
  phase: "batch_summary",
@@ -829,12 +826,12 @@ var Xe = class {
829
826
  constructor(e = {}) {
830
827
  this.options = {
831
828
  ...e,
832
- replayCache: e.replayCache ?? new O(),
829
+ replayCache: e.replayCache ?? new k(),
833
830
  verificationMaterialCache: e.verificationMaterialCache ?? new ze()
834
831
  };
835
832
  }
836
833
  receive(e, t = Date.now()) {
837
- return k(e, {
834
+ return A(e, {
838
835
  ...this.options,
839
836
  nowMs: t
840
837
  });
@@ -847,7 +844,7 @@ var Xe = class {
847
844
  }
848
845
  };
849
846
  async function Ze(e) {
850
- return x(T(e), e.secret, e.keyId);
847
+ return me(E(e), e.secret, e.keyId);
851
848
  }
852
849
  //#endregion
853
850
  //#region src/protocolCapabilities.ts
@@ -930,13 +927,13 @@ var ot = class {
930
927
  resolveInboundSecret;
931
928
  onTask;
932
929
  constructor(e) {
933
- this.agentId = e.agentId, this.outboundSecret = e.outboundSecret, this.keyId = e.keyId ?? `${e.agentId}-k1`, this.capabilities = e.capabilities ?? [], this.supportedWireFormats = e.supportedWireFormats ?? ["compact", "json"], this.maxBatchSize = e.maxBatchSize ?? 1, this.ackModes = e.ackModes ?? ["receipt"], this.requireSignature = e.requireSignature ?? !0, this.replayCache = e.replayCache ?? new O(), this.sharedSecrets = e.sharedSecrets ?? {}, this.resolveInboundSecret = e.resolveInboundSecret, this.onTask = e.onTask;
930
+ this.agentId = e.agentId, this.outboundSecret = e.outboundSecret, this.keyId = e.keyId ?? `${e.agentId}-k1`, this.capabilities = e.capabilities ?? [], this.supportedWireFormats = e.supportedWireFormats ?? ["compact", "json"], this.maxBatchSize = e.maxBatchSize ?? 1, this.ackModes = e.ackModes ?? ["receipt"], this.requireSignature = e.requireSignature ?? !0, this.replayCache = e.replayCache ?? new k(), this.sharedSecrets = e.sharedSecrets ?? {}, this.resolveInboundSecret = e.resolveInboundSecret, this.onTask = e.onTask;
934
931
  }
935
932
  async inboundSecretResolver(e, t) {
936
933
  return this.resolveInboundSecret ? this.resolveInboundSecret(e, t) : this.sharedSecrets[t];
937
934
  }
938
935
  async createSignedIntent(e) {
939
- return x(T({
936
+ return me(E({
940
937
  sender: this.agentId,
941
938
  recipient: e.recipient,
942
939
  intent: e.intent,
@@ -950,7 +947,7 @@ var ot = class {
950
947
  }), this.outboundSecret, this.keyId);
951
948
  }
952
949
  async receiveAndRespond(e, t = Date.now()) {
953
- let n = await k(e, {
950
+ let n = await A(e, {
954
951
  nowMs: t,
955
952
  requireSignature: this.requireSignature,
956
953
  replayCache: this.replayCache,
@@ -1275,28 +1272,28 @@ function wt(e) {
1275
1272
  }
1276
1273
  };
1277
1274
  }
1278
- async function Tt(e = {}) {
1275
+ async function j(e = {}) {
1279
1276
  let t = await xt(e);
1280
1277
  return {
1281
1278
  policy: t,
1282
1279
  enforcer: wt(t)
1283
1280
  };
1284
1281
  }
1285
- function Et(e) {
1282
+ function Tt(e) {
1286
1283
  return Ct(e);
1287
1284
  }
1288
1285
  //#endregion
1289
1286
  //#region src/mcpGateway.ts
1290
- var Dt = [
1287
+ var Et = [
1291
1288
  "tools/call",
1292
1289
  "resources/read",
1293
1290
  "prompts/get"
1294
1291
  ];
1295
- function Ot(e) {
1292
+ function Dt(e) {
1296
1293
  return JSON.stringify(e);
1297
1294
  }
1298
- function A(e, t, n) {
1299
- return Ot({
1295
+ function M(e, t, n) {
1296
+ return Dt({
1300
1297
  jsonrpc: "2.0",
1301
1298
  id: e,
1302
1299
  error: {
@@ -1305,7 +1302,7 @@ function A(e, t, n) {
1305
1302
  }
1306
1303
  });
1307
1304
  }
1308
- function kt(e) {
1305
+ function Ot(e) {
1309
1306
  let t = JSON.parse(e);
1310
1307
  return t.jsonrpc !== "2.0" || typeof t.method != "string" || t.method.length === 0 || typeof t.id != "string" && typeof t.id != "number" ? null : {
1311
1308
  jsonrpc: "2.0",
@@ -1314,11 +1311,11 @@ function kt(e) {
1314
1311
  params: t.params
1315
1312
  };
1316
1313
  }
1317
- function At(e) {
1314
+ function kt(e) {
1318
1315
  return e.includes("not allowed") ? -32601 : e.includes("not authorized") ? -32001 : e.includes("rate-limited") ? -32002 : -32603;
1319
1316
  }
1320
- function jt(e) {
1321
- let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ?? Dt, i = e.workerCapabilityPrefix ?? "mcp.", a = e.gatewayWireFormat ?? "compact", o = e.workerWireFormat ?? "compact";
1317
+ function At(e) {
1318
+ let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ?? Et, i = e.workerCapabilityPrefix ?? "mcp.", a = e.gatewayWireFormat ?? "compact", o = e.workerWireFormat ?? "compact";
1322
1319
  async function s(t) {
1323
1320
  e.onAuditEvent && await e.onAuditEvent({
1324
1321
  ...t,
@@ -1337,7 +1334,7 @@ function jt(e) {
1337
1334
  wireFormat: o,
1338
1335
  onTask: async (e) => ({
1339
1336
  intent: "RESULT",
1340
- content: Ot({
1337
+ content: Dt({
1341
1338
  ok: !0,
1342
1339
  capability: e.body.capability,
1343
1340
  content: e.body.content
@@ -1350,18 +1347,18 @@ function jt(e) {
1350
1347
  if (!i) return null;
1351
1348
  let a = null;
1352
1349
  try {
1353
- let t = kt(i);
1350
+ let t = Ot(i);
1354
1351
  if (!t) return await s({
1355
1352
  phase: "request_error",
1356
1353
  code: -32600,
1357
1354
  message: "Invalid Request"
1358
- }), A(null, -32600, "Invalid Request");
1355
+ }), M(null, -32600, "Invalid Request");
1359
1356
  a = t.id, await s({
1360
1357
  phase: "request_received",
1361
1358
  id: t.id,
1362
1359
  method: t.method
1363
1360
  });
1364
- let o = await mt(c, t, {
1361
+ let o = {
1365
1362
  recipient: n,
1366
1363
  allowedMethods: r,
1367
1364
  methodToCapability: e.methodToCapability,
@@ -1376,42 +1373,42 @@ function jt(e) {
1376
1373
  policy: e
1377
1374
  });
1378
1375
  }
1379
- }), u = null;
1380
- if (await l.handleRaw(o, async (e) => {
1381
- u = e;
1382
- }), !u) return await s({
1376
+ }, u = await mt(c, t, o), d = null;
1377
+ if (await l.handleRaw(u, async (e) => {
1378
+ d = e;
1379
+ }), !d) return await s({
1383
1380
  phase: "verification_failed",
1384
1381
  id: t.id,
1385
1382
  method: t.method,
1386
1383
  code: -32603,
1387
1384
  message: "AIP worker did not produce a response"
1388
- }), A(a, -32603, "AIP worker did not produce a response");
1389
- let d = await c.receiveRaw(u);
1390
- return !d.ok || !d.received ? (await s({
1385
+ }), M(a, -32603, "AIP worker did not produce a response");
1386
+ let f = await c.receiveRaw(d);
1387
+ return !f.ok || !f.received ? (await s({
1391
1388
  phase: "verification_failed",
1392
1389
  id: t.id,
1393
1390
  method: t.method,
1394
1391
  code: -32603,
1395
1392
  message: "AIP verification failed"
1396
- }), A(a, -32603, "AIP verification failed")) : (await s({
1393
+ }), M(a, -32603, "AIP verification failed")) : (await s({
1397
1394
  phase: "request_success",
1398
1395
  id: t.id,
1399
1396
  method: t.method
1400
- }), Ot(ht(d.received, t.id)));
1397
+ }), Dt(ht(f.received, t.id)));
1401
1398
  } catch (e) {
1402
- let t = e instanceof Error ? e.message : "Internal error", n = At(t);
1399
+ let t = e instanceof Error ? e.message : "Internal error", n = kt(t);
1403
1400
  return await s({
1404
1401
  phase: "request_error",
1405
1402
  id: a,
1406
1403
  code: n,
1407
1404
  message: t
1408
- }), A(a, n, t);
1405
+ }), M(a, n, t);
1409
1406
  }
1410
1407
  } };
1411
1408
  }
1412
- async function Mt(e) {
1413
- if (!e.runtimePolicy?.enabled) return jt(e);
1414
- let { enforcer: t } = await Tt(e.runtimePolicy.options);
1409
+ async function jt(e) {
1410
+ if (!e.runtimePolicy?.enabled) return At(e);
1411
+ let { enforcer: t } = await j(e.runtimePolicy.options);
1415
1412
  t.assertInvariant({
1416
1413
  signatureVerification: !0,
1417
1414
  canonicalization: !0,
@@ -1423,7 +1420,7 @@ async function Mt(e) {
1423
1420
  latencySensitive: e.runtimePolicy.latencySensitive,
1424
1421
  compatibilityFirst: e.runtimePolicy.compatibilityFirst
1425
1422
  }), r = n.includes("binary") ? "binary" : "compact";
1426
- return jt({
1423
+ return At({
1427
1424
  ...e,
1428
1425
  gatewayWireFormat: r,
1429
1426
  workerWireFormat: r,
@@ -1439,14 +1436,14 @@ async function Mt(e) {
1439
1436
  }
1440
1437
  //#endregion
1441
1438
  //#region src/runtimePolicyManager.ts
1442
- var Nt = class {
1439
+ var Mt = class {
1443
1440
  snapshot = null;
1444
1441
  options;
1445
1442
  constructor(e = {}) {
1446
1443
  this.options = e;
1447
1444
  }
1448
1445
  async loadInitial() {
1449
- let e = await Tt(this.options);
1446
+ let e = await j(this.options);
1450
1447
  return this.snapshot = {
1451
1448
  ...e,
1452
1449
  loadedAtMs: Date.now()
@@ -1459,7 +1456,7 @@ var Nt = class {
1459
1456
  async refresh() {
1460
1457
  let e = this.snapshot;
1461
1458
  try {
1462
- let e = await Tt(this.options);
1459
+ let e = await j(this.options);
1463
1460
  return this.snapshot = {
1464
1461
  ...e,
1465
1462
  loadedAtMs: Date.now()
@@ -1469,7 +1466,7 @@ var Nt = class {
1469
1466
  throw t;
1470
1467
  }
1471
1468
  }
1472
- }, Pt = {
1469
+ }, Nt = {
1473
1470
  dev: {
1474
1471
  environment: "dev",
1475
1472
  mode: "ws-batch",
@@ -1495,12 +1492,12 @@ var Nt = class {
1495
1492
  retryMaxAttempts: 3
1496
1493
  }
1497
1494
  };
1498
- function Ft(e) {
1499
- return Pt[e];
1495
+ function Pt(e) {
1496
+ return Nt[e];
1500
1497
  }
1501
1498
  //#endregion
1502
1499
  //#region src/policyTelemetryFeedback.ts
1503
- function It(e) {
1500
+ function Ft(e) {
1504
1501
  let t = [], n = "normal";
1505
1502
  return e.dropPct > .1 && (t.push("reduce inflight cap"), t.push("reduce batch size"), t.push("increase retry backoff"), e.mode === "http" && e.concurrency >= 100 && t.push("switch to http-binary-batch"), n = e.dropPct > 2 ? "critical" : "warn"), e.p99Ms > 20 && (t.push("reduce batch size"), t.push("run adaptive benchmark and re-baseline"), n === "normal" && (n = "warn"), e.p99Ms > 100 && (n = "critical")), {
1506
1503
  severity: n,
@@ -1509,7 +1506,7 @@ function It(e) {
1509
1506
  }
1510
1507
  //#endregion
1511
1508
  //#region src/redisClient.ts
1512
- var Lt = class {
1509
+ var It = class {
1513
1510
  entries = /* @__PURE__ */ new Map();
1514
1511
  now;
1515
1512
  constructor(e = {}) {
@@ -1555,13 +1552,13 @@ var Lt = class {
1555
1552
  };
1556
1553
  return t;
1557
1554
  }
1558
- }, Rt = class {
1555
+ }, Lt = class {
1559
1556
  keyPrefix;
1560
1557
  client;
1561
1558
  constructor(e = {}) {
1562
1559
  if (this.keyPrefix = e.keyPrefix ?? "7h3:nonce:", e.client) this.client = e.client;
1563
1560
  else {
1564
- let e = new Lt();
1561
+ let e = new It();
1565
1562
  this.client = {
1566
1563
  set: (t, n, r) => e.set(t, n, {
1567
1564
  nx: r?.nx,
@@ -1580,7 +1577,7 @@ var Lt = class {
1580
1577
  px: Math.max(1, t)
1581
1578
  }) === null;
1582
1579
  }
1583
- }, zt = class {
1580
+ }, Rt = class {
1584
1581
  nodes;
1585
1582
  constructor(e) {
1586
1583
  this.nodes = e;
@@ -1589,17 +1586,17 @@ var Lt = class {
1589
1586
  return (await Promise.all(this.nodes.map((n) => n.check(e, t)))).some((e) => e);
1590
1587
  }
1591
1588
  };
1592
- function Bt(e, t = {}) {
1593
- return Vt(e) ? Ut(e, t) : new Rt(e);
1589
+ function zt(e, t = {}) {
1590
+ return Bt(e) ? Ht(e, t) : new Lt(e);
1594
1591
  }
1595
- function Vt(e) {
1592
+ function Bt(e) {
1596
1593
  return typeof e == "object" && !!e && typeof e.set == "function" && (typeof e.pipeline == "function" || !("quit" in e));
1597
1594
  }
1598
- function Ht(e) {
1599
- return new zt(e.map((e) => new Rt({ redisUrl: e })));
1595
+ function Vt(e) {
1596
+ return new Rt(e.map((e) => new Lt({ redisUrl: e })));
1600
1597
  }
1601
- function Ut(e, t = {}) {
1602
- let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ? Ut(new Lt(), {
1598
+ function Ht(e, t = {}) {
1599
+ let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ? Ht(new It(), {
1603
1600
  keyPrefix: n,
1604
1601
  errorBehavior: "reject"
1605
1602
  }) : void 0);
@@ -1639,7 +1636,7 @@ function Ut(e, t = {}) {
1639
1636
  }
1640
1637
  //#endregion
1641
1638
  //#region src/revocation.ts
1642
- var Wt = class {
1639
+ var Ut = class {
1643
1640
  revoked = /* @__PURE__ */ new Map();
1644
1641
  now;
1645
1642
  constructor(e = {}) {
@@ -1656,7 +1653,7 @@ var Wt = class {
1656
1653
  this.revoked.set(this.makeKey(e, t), n.untilMs ?? Infinity);
1657
1654
  }
1658
1655
  };
1659
- function Gt(e, t = {}) {
1656
+ function Wt(e, t = {}) {
1660
1657
  let n = t.keyPrefix ?? "aip:revoked:", r = t.errorBehavior ?? "reject", i = t.cacheTtlMs ?? 5e3, a = t.onDegraded, o = t.now ?? (() => Date.now()), s = /* @__PURE__ */ new Map();
1661
1658
  function c(e, t) {
1662
1659
  return `${n}${e}${t}`;
@@ -1688,7 +1685,7 @@ function Gt(e, t = {}) {
1688
1685
  }
1689
1686
  };
1690
1687
  }
1691
- function Kt(e, t, n = {}) {
1688
+ function Gt(e, t, n = {}) {
1692
1689
  let r = n.nowMsProvider ?? (() => Date.now());
1693
1690
  return async (n, i) => {
1694
1691
  if (!await t.isRevoked(i, n.keyId, r())) return e(n, i);
@@ -1696,7 +1693,7 @@ function Kt(e, t, n = {}) {
1696
1693
  }
1697
1694
  //#endregion
1698
1695
  //#region src/mcpWrapper.ts
1699
- function j(e, t, n) {
1696
+ function N(e, t, n) {
1700
1697
  return {
1701
1698
  jsonrpc: "2.0",
1702
1699
  id: e,
@@ -1706,20 +1703,20 @@ function j(e, t, n) {
1706
1703
  }
1707
1704
  };
1708
1705
  }
1709
- function qt(e, t) {
1706
+ function Kt(e, t) {
1710
1707
  return {
1711
1708
  requireSignature: !0,
1712
1709
  ...e.receive,
1713
1710
  replayCache: t
1714
1711
  };
1715
1712
  }
1716
- function Jt(e, t) {
1717
- let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = qt(t, t.receive?.replayCache ?? new O());
1713
+ function qt(e, t) {
1714
+ let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = Kt(t, t.receive?.replayCache ?? new k());
1718
1715
  async function a(e) {
1719
1716
  return Ke(await t.sign(e), n);
1720
1717
  }
1721
1718
  function o(e, n, i, o) {
1722
- return a(T({
1719
+ return a(E({
1723
1720
  sender: t.selfAgentId,
1724
1721
  recipient: e,
1725
1722
  intent: n,
@@ -1729,29 +1726,29 @@ function Jt(e, t) {
1729
1726
  }));
1730
1727
  }
1731
1728
  return async (n) => {
1732
- let r = await k(n, i), a = r.envelope?.header.sender, s = r.envelope?.header.messageId;
1733
- if (!r.ok || !r.envelope) return o(a, "ERROR", j(null, -32600, r.diagnostics.find((e) => e.level === "error")?.message ?? "AIP verification failed"), s);
1734
- if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR", j(null, -32600, "Recipient mismatch: envelope not addressed to this agent"), s);
1729
+ let r = await A(n, i), a = r.envelope?.header.sender, s = r.envelope?.header.messageId;
1730
+ if (!r.ok || !r.envelope) return o(a, "ERROR", N(null, -32600, r.diagnostics.find((e) => e.level === "error")?.message ?? "AIP verification failed"), s);
1731
+ if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR", N(null, -32600, "Recipient mismatch: envelope not addressed to this agent"), s);
1735
1732
  let c;
1736
1733
  try {
1737
1734
  c = JSON.parse(r.envelope.body.content);
1738
1735
  } catch {
1739
- return o(a, "ERROR", j(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
1736
+ return o(a, "ERROR", N(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
1740
1737
  }
1741
1738
  let l;
1742
1739
  try {
1743
1740
  l = await e(c);
1744
1741
  } catch (e) {
1745
- l = j(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
1742
+ l = N(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
1746
1743
  }
1747
1744
  return o(r.envelope.header.sender, "RESULT", l, s);
1748
1745
  };
1749
1746
  }
1750
- function Yt(e) {
1751
- let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = qt(e, e.receive?.replayCache ?? new O());
1747
+ function Jt(e) {
1748
+ let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = Kt(e, e.receive?.replayCache ?? new k());
1752
1749
  return {
1753
1750
  async encodeRequest(r) {
1754
- let i = T({
1751
+ let i = E({
1755
1752
  sender: e.selfAgentId,
1756
1753
  recipient: e.peerAgentId,
1757
1754
  intent: "TASK",
@@ -1764,7 +1761,7 @@ function Yt(e) {
1764
1761
  };
1765
1762
  },
1766
1763
  async decodeResponse(t, n = {}) {
1767
- let i = await k(t, r);
1764
+ let i = await A(t, r);
1768
1765
  if (!i.ok || !i.envelope) {
1769
1766
  let e = i.diagnostics.find((e) => e.level === "error")?.message ?? "unknown";
1770
1767
  throw Error(`AIP response verification failed: ${e}`);
@@ -1776,8 +1773,8 @@ function Yt(e) {
1776
1773
  }
1777
1774
  };
1778
1775
  }
1779
- function Xt(e, t) {
1780
- let n = Yt(t);
1776
+ function Yt(e, t) {
1777
+ let n = Jt(t);
1781
1778
  return async (t) => {
1782
1779
  let { raw: r, messageId: i } = await n.encodeRequest(t);
1783
1780
  return n.decodeResponse(await e(r), { expectCorrelationId: i });
@@ -1785,55 +1782,52 @@ function Xt(e, t) {
1785
1782
  }
1786
1783
  //#endregion
1787
1784
  //#region src/mcpTransports.ts
1788
- var M = /* @__PURE__ */ c((/* @__PURE__ */ o(((e, t) => {
1789
- t.exports = {};
1790
- })))(), 1);
1791
- function Zt(e) {
1785
+ function Xt(e) {
1792
1786
  if (typeof e != "string") throw Error("stdio adapter supports json/compact (string) wire formats; use the HTTP adapter for binary");
1793
1787
  return e;
1794
1788
  }
1795
- function Qt(e, t = {}) {
1796
- let n = t.input ?? process.stdin, r = t.output ?? process.stdout, i = M.default.createInterface({
1797
- input: n,
1789
+ function Zt(t, n = {}) {
1790
+ let r = n.input ?? process.stdin, i = n.output ?? process.stdout, a = e.createInterface({
1791
+ input: r,
1798
1792
  crlfDelay: Infinity
1799
- }), a = Promise.resolve(), o = (n) => {
1800
- let i = n.trim();
1801
- i && (a = a.then(async () => {
1793
+ }), o = Promise.resolve(), s = (e) => {
1794
+ let r = e.trim();
1795
+ r && (o = o.then(async () => {
1802
1796
  try {
1803
- let t = await e(i);
1804
- r.write(`${Zt(t)}\n`);
1797
+ let e = await t(r);
1798
+ i.write(`${Xt(e)}\n`);
1805
1799
  } catch (e) {
1806
- t.onError?.(e);
1800
+ n.onError?.(e);
1807
1801
  }
1808
1802
  }));
1809
1803
  };
1810
- return i.on("line", o), { close() {
1811
- i.off("line", o), i.close();
1804
+ return a.on("line", s), { close() {
1805
+ a.off("line", s), a.close();
1812
1806
  } };
1813
1807
  }
1814
- function $t(e) {
1815
- let t = M.default.createInterface({
1816
- input: e.input,
1808
+ function Qt(t) {
1809
+ let n = e.createInterface({
1810
+ input: t.input,
1817
1811
  crlfDelay: Infinity
1818
- }), n = [], r = (e) => {
1812
+ }), r = [], i = (e) => {
1819
1813
  let t = e.trim();
1820
1814
  if (!t) return;
1821
- let r = n.shift();
1822
- r && r(t);
1823
- };
1824
- return t.on("line", r), {
1825
- send(t) {
1826
- let r = Zt(t);
1827
- return new Promise((t) => {
1828
- n.push(t), e.output.write(`${r}\n`);
1815
+ let n = r.shift();
1816
+ n && n(t);
1817
+ };
1818
+ return n.on("line", i), {
1819
+ send(e) {
1820
+ let n = Xt(e);
1821
+ return new Promise((e) => {
1822
+ r.push(e), t.output.write(`${n}\n`);
1829
1823
  });
1830
1824
  },
1831
1825
  close() {
1832
- t.off("line", r), t.close();
1826
+ n.off("line", i), n.close();
1833
1827
  }
1834
1828
  };
1835
1829
  }
1836
- function en(e, t = {}) {
1830
+ function $t(e, t = {}) {
1837
1831
  return (n, r) => {
1838
1832
  let i = [];
1839
1833
  n.on("data", (e) => i.push(e)), n.on("error", () => {
@@ -1857,7 +1851,7 @@ function en(e, t = {}) {
1857
1851
  });
1858
1852
  };
1859
1853
  }
1860
- function tn(e) {
1854
+ function en(e) {
1861
1855
  let t = e.fetchImpl ?? fetch, n = e.binary ? "application/octet-stream" : "application/json";
1862
1856
  return { async send(r) {
1863
1857
  let i = await t(e.url, {
@@ -1873,12 +1867,12 @@ function tn(e) {
1873
1867
  }
1874
1868
  //#endregion
1875
1869
  //#region src/keyRegistry.ts
1876
- function nn(e) {
1870
+ function tn(e) {
1877
1871
  return { async getPublicKey(t) {
1878
1872
  return e[t] ?? null;
1879
1873
  } };
1880
1874
  }
1881
- function rn(...e) {
1875
+ function nn(...e) {
1882
1876
  return {
1883
1877
  async getPublicKey(t) {
1884
1878
  for (let n of e) {
@@ -1887,17 +1881,17 @@ function rn(...e) {
1887
1881
  }
1888
1882
  return null;
1889
1883
  },
1890
- async getSharedSecret(t) {
1891
- for (let n of e) {
1892
- if (!n.getSharedSecret) continue;
1893
- let e = await n.getSharedSecret(t);
1884
+ async getSharedSecret(t, n) {
1885
+ for (let r of e) {
1886
+ if (!r.getSharedSecret) continue;
1887
+ let e = await r.getSharedSecret(t, n);
1894
1888
  if (e !== null) return e;
1895
1889
  }
1896
1890
  return null;
1897
1891
  }
1898
1892
  };
1899
1893
  }
1900
- function an(e, t) {
1894
+ function rn(e, t) {
1901
1895
  let n = t?.ttlMs ?? 6e4, r = /* @__PURE__ */ new Map();
1902
1896
  async function i(e, t) {
1903
1897
  let i = Date.now(), a = r.get(e);
@@ -1912,25 +1906,25 @@ function an(e, t) {
1912
1906
  async getPublicKey(t) {
1913
1907
  return i(`pk:${t}`, () => e.getPublicKey(t));
1914
1908
  },
1915
- async getSharedSecret(t) {
1916
- return e.getSharedSecret ? i(`ss:${t}`, () => e.getSharedSecret(t)) : null;
1909
+ async getSharedSecret(t, n) {
1910
+ return e.getSharedSecret ? i(`ss:${n}:${t}`, () => e.getSharedSecret(t, n)) : null;
1917
1911
  }
1918
1912
  };
1919
1913
  }
1920
1914
  //#endregion
1921
1915
  //#region src/cborCodec.ts
1922
- var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3, ln = 4, un = 5, dn = 7, fn = 244, pn = 245, mn = 246, hn = 24, gn = 25, _n = 26, vn = 27, yn = 27, bn = class {
1916
+ var P = new TextEncoder(), an = new TextDecoder(), F = 0, on = 1, sn = 2, I = 3, cn = 4, ln = 5, un = 7, dn = 244, fn = 245, pn = 246, mn = 24, hn = 25, gn = 26, _n = 27, vn = 27, yn = class {
1923
1917
  chunks = [];
1924
1918
  encode(e) {
1925
1919
  return this.chunks = [], this._encode(e), this._concat();
1926
1920
  }
1927
1921
  _encode(e) {
1928
1922
  if (e == null) {
1929
- this.chunks.push(new Uint8Array([mn]));
1923
+ this.chunks.push(new Uint8Array([pn]));
1930
1924
  return;
1931
1925
  }
1932
1926
  if (typeof e == "boolean") {
1933
- this.chunks.push(new Uint8Array([e ? pn : fn]));
1927
+ this.chunks.push(new Uint8Array([e ? fn : dn]));
1934
1928
  return;
1935
1929
  }
1936
1930
  if (typeof e == "number") {
@@ -1968,28 +1962,28 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
1968
1962
  new DataView(t).setFloat64(0, e, !1), this.chunks.push(new Uint8Array(t));
1969
1963
  return;
1970
1964
  }
1971
- e >= 0 ? this._encodeHead(P, e) : this._encodeHead(sn, -1 - e);
1965
+ e >= 0 ? this._encodeHead(F, e) : this._encodeHead(on, -1 - e);
1972
1966
  }
1973
1967
  _float64Header() {
1974
1968
  return new Uint8Array([251]);
1975
1969
  }
1976
1970
  _encodeString(e) {
1977
- let t = N.encode(e);
1978
- this._encodeHead(F, t.length), this.chunks.push(t);
1971
+ let t = P.encode(e);
1972
+ this._encodeHead(I, t.length), this.chunks.push(t);
1979
1973
  }
1980
1974
  _encodeByteString(e) {
1981
- this._encodeHead(cn, e.length), this.chunks.push(e);
1975
+ this._encodeHead(sn, e.length), this.chunks.push(e);
1982
1976
  }
1983
1977
  _encodeArray(e) {
1984
- this._encodeHead(ln, e.length);
1978
+ this._encodeHead(cn, e.length);
1985
1979
  for (let t of e) this._encode(t);
1986
1980
  }
1987
1981
  _encodeMapFromAnyEntries(e) {
1988
1982
  let t = e.map(([e, t]) => {
1989
1983
  let n;
1990
- if (typeof e == "number" && Number.isInteger(e)) n = this._encodeHeadBytes(P, e);
1984
+ if (typeof e == "number" && Number.isInteger(e)) n = this._encodeHeadBytes(F, e);
1991
1985
  else {
1992
- let t = N.encode(String(e)), r = this._encodeHeadBytes(F, t.length);
1986
+ let t = P.encode(String(e)), r = this._encodeHeadBytes(I, t.length);
1993
1987
  n = this._concatPair(r, t);
1994
1988
  }
1995
1989
  return {
@@ -1998,27 +1992,27 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
1998
1992
  value: t
1999
1993
  };
2000
1994
  });
2001
- t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(un, t.length);
1995
+ t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(ln, t.length);
2002
1996
  for (let { key: e, value: n } of t) {
2003
- if (typeof e == "number" && Number.isInteger(e)) this._encodeHead(P, e);
1997
+ if (typeof e == "number" && Number.isInteger(e)) this._encodeHead(F, e);
2004
1998
  else {
2005
- let t = N.encode(String(e));
2006
- this._encodeHead(F, t.length), this.chunks.push(t);
1999
+ let t = P.encode(String(e));
2000
+ this._encodeHead(I, t.length), this.chunks.push(t);
2007
2001
  }
2008
2002
  this._encode(n);
2009
2003
  }
2010
2004
  }
2011
2005
  _encodeMapFromEntries(e) {
2012
2006
  let t = e.map(([e, t]) => {
2013
- let n = N.encode(e), r = this._encodeHeadBytes(F, n.length);
2007
+ let n = P.encode(e), r = this._encodeHeadBytes(I, n.length);
2014
2008
  return {
2015
2009
  keyBytes: n,
2016
2010
  keyEncoded: this._concatPair(r, n),
2017
2011
  value: t
2018
2012
  };
2019
2013
  });
2020
- t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(un, t.length);
2021
- for (let { keyBytes: e, value: n } of t) this._encodeHead(F, e.length), this.chunks.push(e), this._encode(n);
2014
+ t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(ln, t.length);
2015
+ for (let { keyBytes: e, value: n } of t) this._encodeHead(I, e.length), this.chunks.push(e), this._encode(n);
2022
2016
  }
2023
2017
  _compareBytes(e, t) {
2024
2018
  let n = Math.min(e.length, t.length);
@@ -2038,24 +2032,24 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
2038
2032
  _encodeHeadBytes(e, t) {
2039
2033
  let n = e << 5;
2040
2034
  if (t <= 23) return new Uint8Array([n | t]);
2041
- if (t <= 255) return new Uint8Array([n | hn, t]);
2035
+ if (t <= 255) return new Uint8Array([n | mn, t]);
2042
2036
  if (t <= 65535) {
2043
2037
  let e = /* @__PURE__ */ new ArrayBuffer(3), r = new DataView(e);
2044
- return r.setUint8(0, n | gn), r.setUint16(1, t, !1), new Uint8Array(e);
2038
+ return r.setUint8(0, n | hn), r.setUint16(1, t, !1), new Uint8Array(e);
2045
2039
  }
2046
2040
  if (t <= 4294967295) {
2047
2041
  let e = /* @__PURE__ */ new ArrayBuffer(5), r = new DataView(e);
2048
- return r.setUint8(0, n | _n), r.setUint32(1, t, !1), new Uint8Array(e);
2042
+ return r.setUint8(0, n | gn), r.setUint32(1, t, !1), new Uint8Array(e);
2049
2043
  }
2050
2044
  let r = /* @__PURE__ */ new ArrayBuffer(9), i = new DataView(r);
2051
- return i.setUint8(0, n | vn), i.setBigUint64(1, BigInt(t), !1), new Uint8Array(r);
2045
+ return i.setUint8(0, n | _n), i.setBigUint64(1, BigInt(t), !1), new Uint8Array(r);
2052
2046
  }
2053
2047
  _concat() {
2054
2048
  let e = this.chunks.reduce((e, t) => e + t.length, 0), t = new Uint8Array(e), n = 0;
2055
2049
  for (let e of this.chunks) t.set(e, n), n += e.length;
2056
2050
  return t;
2057
2051
  }
2058
- }, xn = class {
2052
+ }, bn = class {
2059
2053
  data;
2060
2054
  offset = 0;
2061
2055
  decode(e) {
@@ -2064,22 +2058,22 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
2064
2058
  _decode() {
2065
2059
  let e = this._readByte(), t = e >> 5 & 7, n = e & 31;
2066
2060
  switch (t) {
2067
- case P: return this._decodeUint(n);
2068
- case sn: return -1 - this._decodeUint(n);
2069
- case cn: {
2061
+ case F: return this._decodeUint(n);
2062
+ case on: return -1 - this._decodeUint(n);
2063
+ case sn: {
2070
2064
  let e = this._decodeUint(n);
2071
2065
  return this._readBytes(e);
2072
2066
  }
2073
- case F: {
2067
+ case I: {
2074
2068
  let e = this._decodeUint(n), t = this._readBytes(e);
2075
- return on.decode(t);
2069
+ return an.decode(t);
2076
2070
  }
2077
- case ln: {
2071
+ case cn: {
2078
2072
  let e = this._decodeUint(n), t = [];
2079
2073
  for (let n = 0; n < e; n++) t.push(this._decode());
2080
2074
  return t;
2081
2075
  }
2082
- case un: {
2076
+ case ln: {
2083
2077
  let e = this._decodeUint(n), t = {};
2084
2078
  for (let n = 0; n < e; n++) {
2085
2079
  let e = this._decode();
@@ -2087,11 +2081,11 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
2087
2081
  }
2088
2082
  return t;
2089
2083
  }
2090
- case dn:
2084
+ case un:
2091
2085
  if (n === 20) return !1;
2092
2086
  if (n === 21) return !0;
2093
2087
  if (n === 22) return null;
2094
- if (n === yn) {
2088
+ if (n === vn) {
2095
2089
  let e = this._readBytes(8);
2096
2090
  return new DataView(e.buffer, e.byteOffset, 8).getFloat64(0, !1);
2097
2091
  }
@@ -2101,16 +2095,16 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
2101
2095
  }
2102
2096
  _decodeUint(e) {
2103
2097
  if (e <= 23) return e;
2104
- if (e === hn) return this._readByte();
2105
- if (e === gn) {
2098
+ if (e === mn) return this._readByte();
2099
+ if (e === hn) {
2106
2100
  let e = this._readBytes(2);
2107
2101
  return new DataView(e.buffer, e.byteOffset, 2).getUint16(0, !1);
2108
2102
  }
2109
- if (e === _n) {
2103
+ if (e === gn) {
2110
2104
  let e = this._readBytes(4);
2111
2105
  return new DataView(e.buffer, e.byteOffset, 4).getUint32(0, !1);
2112
2106
  }
2113
- if (e === vn) {
2107
+ if (e === _n) {
2114
2108
  let e = this._readBytes(8);
2115
2109
  return Number(new DataView(e.buffer, e.byteOffset, 8).getBigUint64(0, !1));
2116
2110
  }
@@ -2126,16 +2120,16 @@ var N = new TextEncoder(), on = new TextDecoder(), P = 0, sn = 1, cn = 2, F = 3,
2126
2120
  return this.offset += e, t;
2127
2121
  }
2128
2122
  };
2129
- function Sn(e) {
2130
- return new bn().encode(e);
2123
+ function xn(e) {
2124
+ return new yn().encode(e);
2131
2125
  }
2132
- function Cn(e) {
2133
- return new xn().decode(e);
2126
+ function Sn(e) {
2127
+ return new bn().decode(e);
2134
2128
  }
2135
2129
  //#endregion
2136
2130
  //#region src/envelopeCbor.ts
2137
- var wn = "application/7h3-cbor";
2138
- function Tn(e) {
2131
+ var Cn = "application/7h3-cbor";
2132
+ function wn(e) {
2139
2133
  let t = /* @__PURE__ */ new Map();
2140
2134
  t.set(1, e.header.version), t.set(2, e.header.messageId), t.set(3, e.header.timestampMs), t.set(4, e.header.ttlMs), t.set(5, e.header.sender), e.header.recipient !== void 0 && t.set(6, e.header.recipient), t.set(7, e.header.nonce);
2141
2135
  let n = /* @__PURE__ */ new Map();
@@ -2147,10 +2141,10 @@ function Tn(e) {
2147
2141
  let e = /* @__PURE__ */ new Map();
2148
2142
  e.set(1, i.alg), e.set(2, i.keyId), e.set(3, i.value), r.set(3, e);
2149
2143
  }
2150
- return Sn(r);
2144
+ return xn(r);
2151
2145
  }
2152
- function En(e) {
2153
- let t = Cn(e);
2146
+ function Tn(e) {
2147
+ let t = Sn(e);
2154
2148
  if (!t || typeof t != "object" || Array.isArray(t)) throw Error("decodeEnvelopeCbor: expected a map at top level");
2155
2149
  let n = t, r = n[1];
2156
2150
  if (!r || typeof r != "object" || Array.isArray(r)) throw Error("decodeEnvelopeCbor: missing header map (key 1)");
@@ -2185,11 +2179,11 @@ function En(e) {
2185
2179
  }
2186
2180
  //#endregion
2187
2181
  //#region src/httpBinding.ts
2188
- var Dn = "x-7h3-envelope";
2189
- async function On(e, t, n) {
2182
+ var En = "x-7h3-envelope";
2183
+ async function Dn(e, t, n) {
2190
2184
  let r = t.headerName ?? "x-7h3-envelope", i = (Array.isArray(e["content-type"]) ? e["content-type"][0] : e["content-type"]) ?? "", a;
2191
2185
  if (i.includes("7h3-cbor") && n instanceof Uint8Array) try {
2192
- a = En(n);
2186
+ a = Tn(n);
2193
2187
  } catch (e) {
2194
2188
  return {
2195
2189
  ok: !1,
@@ -2219,7 +2213,7 @@ async function On(e, t, n) {
2219
2213
  detail: "missing required fields"
2220
2214
  };
2221
2215
  if (t.strictTtl ?? !0) {
2222
- let e = w(a).filter((e) => e.level === "error");
2216
+ let e = T(a).filter((e) => e.level === "error");
2223
2217
  if (e.length > 0) return {
2224
2218
  ok: !1,
2225
2219
  reason: "ttl-expired",
@@ -2234,18 +2228,18 @@ async function On(e, t, n) {
2234
2228
  reason: "unknown-sender",
2235
2229
  detail: o
2236
2230
  };
2237
- if (!await C(a, e)) return {
2231
+ if (!await w(a, e)) return {
2238
2232
  ok: !1,
2239
2233
  reason: "invalid-signature"
2240
2234
  };
2241
2235
  } else if (s === "HS256") {
2242
- let e = await t.keyRegistry.getSharedSecret?.(a.signature.keyId);
2236
+ let e = await t.keyRegistry.getSharedSecret?.(a.signature.keyId, o);
2243
2237
  if (!e) return {
2244
2238
  ok: !1,
2245
2239
  reason: "unknown-sender",
2246
2240
  detail: a.signature.keyId
2247
2241
  };
2248
- if (!await he(a, e)) return {
2242
+ if (!await S(a, e)) return {
2249
2243
  ok: !1,
2250
2244
  reason: "invalid-signature"
2251
2245
  };
@@ -2259,24 +2253,24 @@ async function On(e, t, n) {
2259
2253
  envelope: a
2260
2254
  };
2261
2255
  }
2262
- async function kn(e, t, n) {
2263
- let r = await S(e, t);
2256
+ async function On(e, t, n) {
2257
+ let r = await C(e, t);
2264
2258
  if (n?.format === "cbor") {
2265
- let e = Tn(r);
2259
+ let e = wn(r);
2266
2260
  return {
2267
- headers: { "content-type": wn },
2261
+ headers: { "content-type": Cn },
2268
2262
  body: e
2269
2263
  };
2270
2264
  }
2271
2265
  return { headers: { [n?.headerName ?? "x-7h3-envelope"]: JSON.stringify(r) } };
2272
2266
  }
2273
- async function An(e, t, n, r) {
2274
- let i = await x(e, t, n);
2267
+ async function kn(e, t, n, r) {
2268
+ let i = await me(e, t, n);
2275
2269
  return { headers: { [r?.headerName ?? "x-7h3-envelope"]: JSON.stringify(i) } };
2276
2270
  }
2277
- function jn(e) {
2271
+ function An(e) {
2278
2272
  return async function(t, n, r) {
2279
- let i = await On(t.headers, e);
2273
+ let i = await Dn(t.headers, e);
2280
2274
  if (!i.ok) {
2281
2275
  n.status(401).json({
2282
2276
  error: "7h3: request verification failed",
@@ -2288,13 +2282,13 @@ function jn(e) {
2288
2282
  t["7h3Envelope"] = i.envelope, r();
2289
2283
  };
2290
2284
  }
2291
- async function Mn(e, t, n, r) {
2292
- let { headers: i } = await kn(t, n, r), a = new Headers(e.headers);
2285
+ async function jn(e, t, n, r) {
2286
+ let { headers: i } = await On(t, n, r), a = new Headers(e.headers);
2293
2287
  for (let [e, t] of Object.entries(i)) a.set(e, t);
2294
2288
  return new Request(e, { headers: a });
2295
2289
  }
2296
- async function Nn(e, t) {
2297
- return Mn(e, T({
2290
+ async function Mn(e, t) {
2291
+ return jn(e, E({
2298
2292
  sender: t.sender,
2299
2293
  recipient: t.recipient,
2300
2294
  ttlMs: t.ttlMs ?? 6e4,
@@ -2304,39 +2298,39 @@ async function Nn(e, t) {
2304
2298
  }
2305
2299
  //#endregion
2306
2300
  //#region src/webhookBinding.ts
2307
- var I = "x-7h3-sig", L = "x-7h3-ts", Pn = 3e5;
2308
- function R(e, t) {
2301
+ var L = "x-7h3-sig", R = "x-7h3-ts", Nn = 3e5;
2302
+ function Pn(e, t) {
2309
2303
  return `${e}.${t}`;
2310
2304
  }
2311
2305
  async function Fn(e, t) {
2312
- let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await y(R(r, n), t.privateKey);
2306
+ let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await b(Pn(r, n), t.privateKey);
2313
2307
  return {
2314
- [I]: i,
2315
- [L]: String(r)
2308
+ [L]: i,
2309
+ [R]: String(r)
2316
2310
  };
2317
2311
  }
2318
2312
  async function In(e, t) {
2319
- let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await fe(R(r, n), t.secret);
2313
+ let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await de(Pn(r, n), t.secret);
2320
2314
  return {
2321
- [I]: i,
2322
- [L]: String(r)
2315
+ [L]: i,
2316
+ [R]: String(r)
2323
2317
  };
2324
2318
  }
2325
2319
  async function Ln(e, t, n) {
2326
- let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[I], a = t[L];
2320
+ let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[L], a = t[R];
2327
2321
  if (!i || !a) return !1;
2328
2322
  let o = Number(a);
2329
2323
  if (!Number.isFinite(o)) return !1;
2330
2324
  let s = n.maxAgeMs ?? 3e5;
2331
- return Date.now() - o > s ? !1 : b(R(o, r), i, n.publicKey);
2325
+ return Date.now() - o > s ? !1 : x(Pn(o, r), i, n.publicKey);
2332
2326
  }
2333
2327
  async function Rn(e, t, n) {
2334
- let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[I], a = t[L];
2328
+ let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[L], a = t[R];
2335
2329
  if (!i || !a) return !1;
2336
2330
  let o = Number(a);
2337
2331
  if (!Number.isFinite(o)) return !1;
2338
2332
  let s = n.maxAgeMs ?? 3e5;
2339
- return Date.now() - o > s ? !1 : pe(R(o, r), i, n.secret);
2333
+ return Date.now() - o > s ? !1 : fe(Pn(o, r), i, n.secret);
2340
2334
  }
2341
2335
  async function zn(e, t, n) {
2342
2336
  if (!await Ln(e, t, n)) throw Error("7h3: webhook signature verification failed");
@@ -2346,7 +2340,7 @@ async function zn(e, t, n) {
2346
2340
  //#region src/queueBinding.ts
2347
2341
  async function Bn(e, t) {
2348
2342
  let n = t.ttlMs ?? 36e5, r = typeof e == "string" ? e : JSON.stringify(e), i = {
2349
- envelope: await S(T({
2343
+ envelope: await C(E({
2350
2344
  sender: t.sender,
2351
2345
  recipient: t.recipient,
2352
2346
  intent: "TASK",
@@ -2365,7 +2359,16 @@ async function Vn(e, t) {
2365
2359
  throw Error("Queue message is not valid JSON");
2366
2360
  }
2367
2361
  if (!n.envelope || typeof n.envelope != "object") throw Error("Queue message missing envelope");
2368
- if (!await C(n.envelope, t.publicKey)) throw Error("Queue message signature verification failed");
2362
+ let r = t.nowMs ?? Date.now();
2363
+ if (t.strictTtl ?? !0) {
2364
+ let e = T(n.envelope, r).filter((e) => e.level === "error");
2365
+ if (e.length > 0) throw Error(`Queue message failed validation: ${e.map((e) => e.message).join("; ")}`);
2366
+ }
2367
+ if (!await w(n.envelope, t.publicKey)) throw Error("Queue message signature verification failed");
2368
+ if (t.replayCache) {
2369
+ let e = await t.replayCache.consume(n.envelope, r);
2370
+ if (!e.ok) throw Error(e.reason ?? "Queue message replay detected");
2371
+ }
2369
2372
  return {
2370
2373
  payload: n.payload,
2371
2374
  envelope: n.envelope
@@ -2414,7 +2417,7 @@ function U(e) {
2414
2417
  return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
2415
2418
  }
2416
2419
  function Gn() {
2417
- let e = new Uint8Array(16);
2420
+ let e = /* @__PURE__ */ new Uint8Array(16);
2418
2421
  return crypto.getRandomValues(e), V(e);
2419
2422
  }
2420
2423
  var W = /* @__PURE__ */ new Map(), Kn = 128;
@@ -2657,11 +2660,11 @@ function sr(e, t) {
2657
2660
  a(/* @__PURE__ */ Error(`unknown sender: ${o}`), n);
2658
2661
  return;
2659
2662
  }
2660
- if (!await C(i, s).catch(() => !1)) {
2663
+ if (!await w(i, s).catch(() => !1)) {
2661
2664
  a(/* @__PURE__ */ Error("invalid signature"), n);
2662
2665
  return;
2663
2666
  }
2664
- let c = w(i);
2667
+ let c = T(i);
2665
2668
  if (c.some((e) => e.level === "error")) {
2666
2669
  a(/* @__PURE__ */ Error(`envelope invalid: ${c.map((e) => e.message).join("; ")}`), n);
2667
2670
  return;
@@ -2679,7 +2682,7 @@ function sr(e, t) {
2679
2682
  return n;
2680
2683
  },
2681
2684
  async send(r) {
2682
- let i = typeof r == "string" ? r : JSON.stringify(r), a = await S(T({
2685
+ let i = typeof r == "string" ? r : JSON.stringify(r), a = await C(E({
2683
2686
  sender: t.sender,
2684
2687
  recipient: t.recipient,
2685
2688
  ttlMs: t.ttlMs ?? 3e4,
@@ -2735,7 +2738,7 @@ function lr(e, t) {
2735
2738
  //#region src/grpcBinding.ts
2736
2739
  var ur = "7h3-envelope-bin";
2737
2740
  async function dr(e) {
2738
- let t = await S(T({
2741
+ let t = await C(E({
2739
2742
  sender: e.sender,
2740
2743
  recipient: e.recipient,
2741
2744
  ttlMs: e.ttlMs ?? 6e4,
@@ -2761,7 +2764,7 @@ async function fr(e, t) {
2761
2764
  message: "7h3: malformed envelope metadata"
2762
2765
  };
2763
2766
  }
2764
- if (t.strictTtl !== !1 && w(i).some((e) => e.level === "error")) return {
2767
+ if (t.strictTtl !== !1 && T(i).some((e) => e.level === "error")) return {
2765
2768
  ok: !1,
2766
2769
  code: 4,
2767
2770
  message: "7h3: envelope expired or invalid"
@@ -2779,19 +2782,19 @@ async function fr(e, t) {
2779
2782
  code: 16,
2780
2783
  message: `7h3: unknown sender ${a}`
2781
2784
  };
2782
- if (!await C(i, e)) return {
2785
+ if (!await w(i, e)) return {
2783
2786
  ok: !1,
2784
2787
  code: 16,
2785
2788
  message: "7h3: invalid signature"
2786
2789
  };
2787
2790
  } else if (o === "HS256") {
2788
- let e = await t.keyRegistry.getSharedSecret?.(i.signature.keyId);
2791
+ let e = await t.keyRegistry.getSharedSecret?.(i.signature.keyId, a);
2789
2792
  if (!e) return {
2790
2793
  ok: !1,
2791
2794
  code: 16,
2792
2795
  message: "7h3: unknown key"
2793
2796
  };
2794
- if (!await he(i, e)) return {
2797
+ if (!await S(i, e)) return {
2795
2798
  ok: !1,
2796
2799
  code: 16,
2797
2800
  message: "7h3: invalid signature"
@@ -2873,8 +2876,8 @@ var vr = class {
2873
2876
  let e = Date.now(), t = this.getCurrentKey();
2874
2877
  if (t && e - t.createdAt < this.maxAgeMs - this.overlapMs) return null;
2875
2878
  t && !t.expiresAt && (t.expiresAt = e + this.overlapMs);
2876
- let { publicKey: n, privateKey: r } = await me(), i = {
2877
- id: `key-${e}-${v(4)}`,
2879
+ let { publicKey: n, privateKey: r } = await pe(), i = {
2880
+ id: `key-${e}-${y(4)}`,
2878
2881
  publicKey: n,
2879
2882
  privateKey: r,
2880
2883
  createdAt: e
@@ -2973,13 +2976,13 @@ function Sr(e, t) {
2973
2976
  return null;
2974
2977
  }
2975
2978
  function Cr(e, t) {
2976
- return !e.allowedSenders || e.allowedSenders.length === 0 ? !0 : e.allowedSenders.includes(t);
2979
+ return !e.allowedSenders || e.allowedSenders.length === 0 || e.allowedSenders.includes(t);
2977
2980
  }
2978
2981
  //#endregion
2979
2982
  //#region src/signedResponse.ts
2980
2983
  var wr = "x-7h3-response";
2981
2984
  async function Tr(e, t) {
2982
- let n = await S(T({
2985
+ let n = await C(E({
2983
2986
  sender: t.sender,
2984
2987
  recipient: t.recipient,
2985
2988
  intent: "RESULT",
@@ -3009,7 +3012,7 @@ async function Er(e, t, n) {
3009
3012
  ok: !1,
3010
3013
  reason: "ttl-expired",
3011
3014
  envelope: a
3012
- } : await C(a, n.publicKey) ? a.body.content === e ? {
3015
+ } : await w(a, n.publicKey) ? a.body.content === e ? {
3013
3016
  ok: !0,
3014
3017
  envelope: a
3015
3018
  } : {
@@ -3172,7 +3175,7 @@ function Q(e) {
3172
3175
  return t.push(`"scopes":${n}`), t.push(`"subject":${JSON.stringify(e.subject)}`), t.push(`"version":${JSON.stringify(e.version)}`), `{${t.join(",")}}`;
3173
3176
  }
3174
3177
  async function Pr(e) {
3175
- let t = Date.now(), n = `cap-${t}-${v(6)}`, r = e.keyId ?? `${e.issuerId}-key`, i = e.maxDelegations ?? 0, a = {
3178
+ let t = Date.now(), n = `cap-${t}-${y(6)}`, r = e.keyId ?? `${e.issuerId}-key`, i = e.maxDelegations ?? 0, a = {
3176
3179
  id: n,
3177
3180
  version: "7h3-cap/1",
3178
3181
  issuer: e.issuerId,
@@ -3183,7 +3186,7 @@ async function Pr(e) {
3183
3186
  delegationDepth: 0,
3184
3187
  maxDelegations: i,
3185
3188
  keyId: r
3186
- }, o = await y(Q(a), e.issuerPrivateKey);
3189
+ }, o = await b(Q(a), e.issuerPrivateKey);
3187
3190
  return {
3188
3191
  ...a,
3189
3192
  signature: o
@@ -3211,7 +3214,7 @@ async function Lr(e) {
3211
3214
  if (!Ir(a, t.scopes)) throw Error("Delegated scopes exceed parent token scopes");
3212
3215
  let o = t.expiresAt - i;
3213
3216
  if (e.ttlMs > o) throw Error(`Delegated ttlMs (${e.ttlMs}) exceeds parent token remaining TTL (${o})`);
3214
- let s = `cap-${i}-${v(6)}`, c = e.keyId ?? `${n}-key`, l = t.maxDelegations === void 0 ? void 0 : t.maxDelegations - 1, u = {
3217
+ let s = `cap-${i}-${y(6)}`, c = e.keyId ?? `${n}-key`, l = t.maxDelegations === void 0 ? void 0 : t.maxDelegations - 1, u = {
3215
3218
  id: s,
3216
3219
  version: "7h3-cap/1",
3217
3220
  issuer: n,
@@ -3223,7 +3226,7 @@ async function Lr(e) {
3223
3226
  parentTokenId: t.id,
3224
3227
  maxDelegations: l,
3225
3228
  keyId: c
3226
- }, d = await y(Q(u), e.delegatorPrivateKey);
3229
+ }, d = await b(Q(u), e.delegatorPrivateKey);
3227
3230
  return {
3228
3231
  ...u,
3229
3232
  signature: d
@@ -3232,7 +3235,7 @@ async function Lr(e) {
3232
3235
  async function Rr(e, t, n) {
3233
3236
  if ((n?.now ?? Date.now()) >= e.expiresAt) return !1;
3234
3237
  let { signature: r, ...i } = e;
3235
- return b(Q(i), r, t);
3238
+ return x(Q(i), r, t);
3236
3239
  }
3237
3240
  async function zr(e, t, n) {
3238
3241
  if (e.length === 0) return {
@@ -3271,7 +3274,7 @@ async function zr(e, t, n) {
3271
3274
  reason: `no-public-key-for-issuer:${i.issuer}`
3272
3275
  };
3273
3276
  let { signature: o, ...s } = i;
3274
- if (!await b(Q(s), o, a)) return {
3277
+ if (!await x(Q(s), o, a)) return {
3275
3278
  ok: !1,
3276
3279
  reason: `invalid-signature-at-index:${n}`
3277
3280
  };
@@ -3302,7 +3305,7 @@ var Ur = class {
3302
3305
  config;
3303
3306
  rateLimiter;
3304
3307
  constructor(e) {
3305
- this.config = e, this.rateLimiter = new br();
3308
+ this.config = e, this.rateLimiter = new br(), !e.replayStore && (e.policies ?? []).some((e) => e.require !== "none") && console.warn("[7h3-protocol] createGateway(): no replayStore configured with signature-requiring policies. Nonce/replay protection will not survive multiple gateway instances or restarts. See docs/GATEWAY.md#production-safety.");
3306
3309
  }
3307
3310
  async verify(e) {
3308
3311
  let t = performance.now(), n = Sr(this.config.policies ?? [], e.path);
@@ -3373,7 +3376,7 @@ var Ur = class {
3373
3376
  reason: "no-matching-policy"
3374
3377
  };
3375
3378
  }
3376
- let r = await On(e.headers, {
3379
+ let r = await Dn(e.headers, {
3377
3380
  keyRegistry: this.config.keyRegistry,
3378
3381
  headerName: this.config.headerName
3379
3382
  });
@@ -3425,7 +3428,7 @@ var Ur = class {
3425
3428
  reason: "sender-denied"
3426
3429
  };
3427
3430
  }
3428
- if (n?.rateLimit && !this.rateLimiter.consume(a, n.rateLimit).allowed) {
3431
+ if (n?.rateLimit && !(this.config.rateLimitStore ? await this.config.rateLimitStore.consume(a, n.rateLimit) : this.rateLimiter.consume(a, n.rateLimit)).allowed) {
3429
3432
  let n = performance.now() - t;
3430
3433
  return Z.verifications_total.increment({
3431
3434
  result: "fail",
@@ -3487,9 +3490,14 @@ var Ur = class {
3487
3490
  function Wr(e) {
3488
3491
  return new Ur(e);
3489
3492
  }
3493
+ function Gr(e) {
3494
+ if (e.defaultPolicy !== "deny") throw Error("createProductionGateway(): defaultPolicy must be explicitly 'deny'. Unmatched routes must never be forwarded unverified in production.");
3495
+ if (!e.replayStore) throw Error("createProductionGateway(): replayStore is required. Use a shared store (Redis/KV/Durable Object) so nonce replay protection survives multiple instances and restarts.");
3496
+ return new Ur(e);
3497
+ }
3490
3498
  //#endregion
3491
3499
  //#region src/auditLog.ts
3492
- function Gr(e) {
3500
+ function Kr(e) {
3493
3501
  let t = [
3494
3502
  `"id":${JSON.stringify(e.id)}`,
3495
3503
  `"timestampMs":${e.timestampMs}`,
@@ -3497,7 +3505,7 @@ function Gr(e) {
3497
3505
  ];
3498
3506
  return e.sender !== void 0 && t.push(`"sender":${JSON.stringify(e.sender)}`), e.path !== void 0 && t.push(`"path":${JSON.stringify(e.path)}`), e.method !== void 0 && t.push(`"method":${JSON.stringify(e.method)}`), e.envelopeId !== void 0 && t.push(`"envelopeId":${JSON.stringify(e.envelopeId)}`), e.failReason !== void 0 && t.push(`"failReason":${JSON.stringify(e.failReason)}`), e.upstream !== void 0 && t.push(`"upstream":${JSON.stringify(e.upstream)}`), e.responseStatus !== void 0 && t.push(`"responseStatus":${e.responseStatus}`), `{${t.join(",")}}`;
3499
3507
  }
3500
- var Kr = class {
3508
+ var qr = class {
3501
3509
  entries = [];
3502
3510
  privateKey;
3503
3511
  maxEntries;
@@ -3506,10 +3514,10 @@ var Kr = class {
3506
3514
  }
3507
3515
  async log(e) {
3508
3516
  let t = {
3509
- id: `audit-${Date.now()}-${v(5)}`,
3517
+ id: `audit-${Date.now()}-${y(5)}`,
3510
3518
  timestampMs: Date.now(),
3511
3519
  ...e
3512
- }, n = await y(Gr(t), this.privateKey), r = {
3520
+ }, n = await b(Kr(t), this.privateKey), r = {
3513
3521
  ...t,
3514
3522
  entrySignature: n
3515
3523
  };
@@ -3520,7 +3528,7 @@ var Kr = class {
3520
3528
  return e?.type !== void 0 && (t = t.filter((t) => t.type === e.type)), e?.sender !== void 0 && (t = t.filter((t) => t.sender === e.sender)), e?.since !== void 0 && (t = t.filter((t) => t.timestampMs >= e.since)), e?.limit !== void 0 && (t = t.slice(-e.limit)), t;
3521
3529
  }
3522
3530
  async verify(e, t) {
3523
- return b(Gr({
3531
+ return x(Kr({
3524
3532
  id: e.id,
3525
3533
  timestampMs: e.timestampMs,
3526
3534
  type: e.type,
@@ -3536,7 +3544,7 @@ var Kr = class {
3536
3544
  size() {
3537
3545
  return this.entries.length;
3538
3546
  }
3539
- }, qr = class {
3547
+ }, Jr = class {
3540
3548
  async log(e) {}
3541
3549
  async query(e) {
3542
3550
  return [];
@@ -3548,25 +3556,25 @@ var Kr = class {
3548
3556
  return 0;
3549
3557
  }
3550
3558
  };
3551
- function Jr(e, t) {
3552
- return new Kr(e, t?.maxEntries);
3559
+ function Yr(e, t) {
3560
+ return new qr(e, t?.maxEntries);
3553
3561
  }
3554
3562
  //#endregion
3555
3563
  //#region src/otel.ts
3556
- var Yr = null;
3557
- function Xr(e) {
3558
- Yr = e;
3564
+ var Xr = null;
3565
+ function Zr(e) {
3566
+ Xr = e;
3559
3567
  }
3560
- function Zr() {
3561
- if (Yr === null) return null;
3568
+ function Qr() {
3569
+ if (Xr === null) return null;
3562
3570
  try {
3563
- return Yr.getTracer("7h3/protocol");
3571
+ return Xr.getTracer("7h3/protocol");
3564
3572
  } catch {
3565
3573
  return null;
3566
3574
  }
3567
3575
  }
3568
- async function Qr(e, t) {
3569
- let n = Zr();
3576
+ async function $r(e, t) {
3577
+ let n = Qr();
3570
3578
  if (n === null) return e(null);
3571
3579
  let r = n.startSpan("7h3.verify", t);
3572
3580
  try {
@@ -3577,8 +3585,8 @@ async function Qr(e, t) {
3577
3585
  r.end();
3578
3586
  }
3579
3587
  }
3580
- async function $r(e) {
3581
- let t = Zr();
3588
+ async function ei(e) {
3589
+ let t = Qr();
3582
3590
  if (t === null) return e(null);
3583
3591
  let n = t.startSpan("7h3.audit.write");
3584
3592
  try {
@@ -3591,64 +3599,64 @@ async function $r(e) {
3591
3599
  }
3592
3600
  //#endregion
3593
3601
  //#region src/encryption.ts
3594
- function ei(e) {
3602
+ function ti(e) {
3595
3603
  return Buffer.from(e).toString("base64url");
3596
3604
  }
3597
3605
  function $(e) {
3598
3606
  return Buffer.from(e, "base64url");
3599
3607
  }
3600
- var ti = Buffer.from("302e020100300506032b656e04220420", "hex"), ni = Buffer.from("302a300506032b656e032100", "hex");
3601
- function ri(e) {
3608
+ var ni = Buffer.from("302e020100300506032b656e04220420", "hex"), ri = Buffer.from("302a300506032b656e032100", "hex");
3609
+ function ii(e) {
3602
3610
  let t = $(e);
3603
- return (0, M.createPrivateKey)({
3604
- key: Buffer.concat([ti, t]),
3611
+ return r({
3612
+ key: Buffer.concat([ni, t]),
3605
3613
  format: "der",
3606
3614
  type: "pkcs8"
3607
3615
  });
3608
3616
  }
3609
- function ii(e) {
3617
+ function ai(e) {
3610
3618
  let t = $(e);
3611
- return (0, M.createPublicKey)({
3612
- key: Buffer.concat([ni, t]),
3619
+ return i({
3620
+ key: Buffer.concat([ri, t]),
3613
3621
  format: "der",
3614
3622
  type: "spki"
3615
3623
  });
3616
3624
  }
3617
- function ai() {
3618
- let { privateKey: e, publicKey: t } = (0, M.generateKeyPairSync)("x25519"), n = e.export({ format: "jwk" });
3625
+ function oi() {
3626
+ let { privateKey: e, publicKey: t } = o("x25519"), n = e.export({ format: "jwk" });
3619
3627
  return {
3620
3628
  publicKey: t.export({ format: "jwk" }).x,
3621
3629
  privateKey: n.d
3622
3630
  };
3623
3631
  }
3624
- function oi(e, t, n) {
3625
- let r = (0, M.hkdfSync)("sha256", (0, M.diffieHellman)({
3626
- privateKey: ri(e),
3627
- publicKey: ii(t)
3632
+ function si(e, t, n) {
3633
+ let r = s("sha256", a({
3634
+ privateKey: ii(e),
3635
+ publicKey: ai(t)
3628
3636
  }), $(n), Buffer.from("7h3-enc/1", "utf8"), 32);
3629
3637
  return Buffer.from(r);
3630
3638
  }
3631
- function si(e, t) {
3632
- let n = ai(), r = (0, M.randomBytes)(12), i = ei(r), a = oi(n.privateKey, t, i), o = Buffer.from(JSON.stringify(e), "utf8"), s = (0, M.createCipheriv)("chacha20-poly1305", a, r, { authTagLength: 16 }), c = Buffer.concat([s.update(o), s.final()]), l = s.getAuthTag(), u = {
3633
- ephemeralPublic: n.publicKey,
3634
- nonce: i,
3635
- ciphertext: ei(c),
3636
- tag: ei(l)
3639
+ function ci(e, n) {
3640
+ let r = oi(), i = c(12), a = ti(i), o = si(r.privateKey, n, a), s = Buffer.from(JSON.stringify(e), "utf8"), l = t("chacha20-poly1305", o, i, { authTagLength: 16 }), u = Buffer.concat([l.update(s), l.final()]), d = l.getAuthTag(), f = {
3641
+ ephemeralPublic: r.publicKey,
3642
+ nonce: a,
3643
+ ciphertext: ti(u),
3644
+ tag: ti(d)
3637
3645
  };
3638
3646
  return {
3639
- encryptedContent: ei(Buffer.from(JSON.stringify(u), "utf8")),
3640
- ephemeralPublic: n.publicKey
3647
+ encryptedContent: ti(Buffer.from(JSON.stringify(f), "utf8")),
3648
+ ephemeralPublic: r.publicKey
3641
3649
  };
3642
3650
  }
3643
- function ci(e, t) {
3644
- let n = $(e).toString("utf8"), { ephemeralPublic: r, nonce: i, ciphertext: a, tag: o } = JSON.parse(n), s = oi(t, r, i), c = $(i), l = $(a), u = $(o), d = (0, M.createDecipheriv)("chacha20-poly1305", s, c, { authTagLength: 16 });
3645
- d.setAuthTag(u);
3646
- let f = Buffer.concat([d.update(l), d.final()]);
3647
- return JSON.parse(f.toString("utf8"));
3651
+ function li(e, t) {
3652
+ let r = $(e).toString("utf8"), { ephemeralPublic: i, nonce: a, ciphertext: o, tag: s } = JSON.parse(r), c = si(t, i, a), l = $(a), u = $(o), d = $(s), f = n("chacha20-poly1305", c, l, { authTagLength: 16 });
3653
+ f.setAuthTag(d);
3654
+ let p = Buffer.concat([f.update(u), f.final()]);
3655
+ return JSON.parse(p.toString("utf8"));
3648
3656
  }
3649
- async function li(e, t) {
3650
- let { encryptedContent: n } = si(e.body, t.recipientX25519PublicKey);
3651
- return S({
3657
+ async function ui(e, t) {
3658
+ let { encryptedContent: n } = ci(e.body, t.recipientX25519PublicKey);
3659
+ return C({
3652
3660
  header: e.header,
3653
3661
  body: {
3654
3662
  intent: "ENCRYPTED",
@@ -3658,12 +3666,12 @@ async function li(e, t) {
3658
3666
  }
3659
3667
  }, t.senderEd25519PrivateKey);
3660
3668
  }
3661
- async function ui(e, t) {
3662
- if (!await C(e, t.senderEd25519PublicKey)) throw Error("7h3/encryption: Ed25519 signature verification failed");
3669
+ async function di(e, t) {
3670
+ if (!await w(e, t.senderEd25519PublicKey)) throw Error("7h3/encryption: Ed25519 signature verification failed");
3663
3671
  return {
3664
3672
  envelope: e,
3665
- body: ci(e.body.content, t.recipientX25519PrivateKey)
3673
+ body: li(e.body.content, t.recipientX25519PrivateKey)
3666
3674
  };
3667
3675
  }
3668
3676
  //#endregion
3669
- export { ot as AgentSession, st as AipAgentAdapter, Mr as CAP_HEADER, wn as CBOR_CONTENT_TYPE, xn as CborDecoder, bn as CborEncoder, zt as ClusterRedisReplayStore, Dn as DEFAULT_HEADER, xe as DEFAULT_MAX_BINARY_ENVELOPE_BYTES, Re as DistributedReplayCache, ur as GRPC_METADATA_KEY, Kr as InMemoryAuditLog, Lt as InMemoryRedisLikeClient, O as InMemoryReplayCache, Wt as InMemoryRevocationStore, ze as InMemoryVerificationMaterialCache, vr as KeyRotationManager, qr as NoopAuditLog, Ur as Protocol7h3Gateway, kr as Protocol7h3Metrics, wr as RESPONSE_HEADER, Rt as RedisReplayStore, yr as RevocationRegistry, it as RollingKeyring, Nt as RuntimePolicyManager, Un as STREAM_HEADER, Xe as SessionTransport, er as SignedStreamReader, q as SignedStreamWriter, X as SimpleCounter, Or as SimpleHistogram, br as SlidingWindowRateLimiter, Pn as WEBHOOK_DEFAULT_TTL_MS, I as WEBHOOK_SIG_HEADER, L as WEBHOOK_TS_HEADER, Tt as bootstrapRuntimePolicyEnforcer, Q as canonicalizeCapabilityToken, g as canonicalizeEnvelope, zn as consumeWebhook, ct as createAipAgentAdapter, et as createAipCapabilities, jt as createAipMcpGatewayRuntime, Mt as createAipMcpGatewayRuntimeWithPolicy, Jr as createAuditLog, an as createCachingKeyRegistry, Ht as createClusterReplayStore, rn as createCompositeKeyRegistry, T as createEnvelope, Wr as createGateway, _r as createHttpKeyRegistry, tn as createHttpMcpClient, en as createHttpMcpHandler, jn as createHttpMiddleware, at as createKeyringSignatureResolver, Yt as createMcpClientCodec, jr as createMetricsMiddleware, wt as createPolicyEnforcer, mt as createRawTaskFromJsonRpc, lt as createRawTaskFromLangChain, dt as createRawTaskFromLlamaIndex, Bt as createRedisReplayStore, Gt as createRedisRevocationStore, Nn as createSignedFetchRequest, Ze as createSignedMessage, tr as createSignedStream, cr as createSignedWebSocketStream, nn as createStaticKeyRegistry, $t as createStdioMcpClient, nr as createStreamVerifier, Cn as decodeCbor, Ge as decodeEnvelope, Je as decodeEnvelopeBatch, Ie as decodeEnvelopeBinary, En as decodeEnvelopeCbor, or as decodeStreamChunk, ci as decryptBody, Lr as delegateCapabilityToken, oi as deriveEncryptionKey, tt as encodeAipCapabilities, Sn as encodeCbor, Ke as encodeEnvelope, qe as encodeEnvelopeBatch, Fe as encodeEnvelopeBinary, Tn as encodeEnvelopeCbor, ar as encodeStreamChunk, si as encryptBody, gr as fetchWellKnownKeys, me as generateEd25519KeypairBase64Url, ai as generateX25519KeyPair, Zr as getOtelTracer, Ft as getRuntimeTuningPreset, xr as globalRateLimiter, Cr as isAllowedSender, Et as isRuntimeMode, Pr as issueCapabilityToken, xt as loadRuntimePolicy, J as matchGlob, Sr as matchPolicy, Z as metrics, rt as negotiateAipCapabilities, ui as openEnvelope, nt as parseAipCapabilities, Hr as parseCapabilityChain, yt as parseRuntimePolicyJson, hr as parseWellKnownKeys, v as randomHex, k as receiveEnvelope, Ye as receiveEnvelopeBatch, lr as receiveSignedWebSocketStream, It as recommendPolicyAdjustments, Ar as renderPrometheusText, li as sealEnvelope, Vr as serializeCapabilityChain, Qt as serveMcpOverStdio, mr as serveWellKnownKeys, Xr as setOtelProvider, y as signCanonicalPayloadEd25519, fe as signCanonicalPayloadHmac, S as signEnvelopeEd25519, x as signEnvelopeHmac, Mn as signFetchRequest, dr as signGrpcCall, kn as signHttpRequest, An as signHttpRequestHmac, Bn as signQueueMessage, Tr as signResponse, rr as signStream, Fn as signWebhook, In as signWebhookHmac, ht as toJsonRpcResponse, ut as toLangChainMessage, ft as toLlamaIndexMessage, Br as tokenMatchesScope, w as validateEnvelope, vt as validateRuntimePolicy, b as verifyCanonicalPayloadEd25519, pe as verifyCanonicalPayloadHmac, _e as verifyCanonicalPayloadSignature, zr as verifyCapabilityChain, Rr as verifyCapabilityToken, C as verifyEnvelopeEd25519, he as verifyEnvelopeHmac, ge as verifyEnvelopeSignature, fr as verifyGrpcCall, On as verifyHttpEnvelope, Hn as verifyQueueBatch, Vn as verifyQueueMessage, Er as verifyResponse, ir as verifyStream, Ln as verifyWebhook, Rn as verifyWebhookHmac, $r as withAuditSpan, pr as withGrpcVerification, Kt as withRevocationCheck, Qr as withVerificationSpan, Xt as wrapMcpClient, Jt as wrapMcpServer, sr as wrapWebSocket };
3677
+ export { ot as AgentSession, st as AipAgentAdapter, Mr as CAP_HEADER, Cn as CBOR_CONTENT_TYPE, bn as CborDecoder, yn as CborEncoder, Rt as ClusterRedisReplayStore, En as DEFAULT_HEADER, xe as DEFAULT_MAX_BINARY_ENVELOPE_BYTES, Re as DistributedReplayCache, ur as GRPC_METADATA_KEY, qr as InMemoryAuditLog, It as InMemoryRedisLikeClient, k as InMemoryReplayCache, Ut as InMemoryRevocationStore, ze as InMemoryVerificationMaterialCache, vr as KeyRotationManager, _e as MAX_TTL_MS, Jr as NoopAuditLog, Ur as Protocol7h3Gateway, kr as Protocol7h3Metrics, wr as RESPONSE_HEADER, Lt as RedisReplayStore, yr as RevocationRegistry, it as RollingKeyring, Mt as RuntimePolicyManager, Un as STREAM_HEADER, Xe as SessionTransport, er as SignedStreamReader, q as SignedStreamWriter, X as SimpleCounter, Or as SimpleHistogram, br as SlidingWindowRateLimiter, Nn as WEBHOOK_DEFAULT_TTL_MS, L as WEBHOOK_SIG_HEADER, R as WEBHOOK_TS_HEADER, j as bootstrapRuntimePolicyEnforcer, Q as canonicalizeCapabilityToken, _ as canonicalizeEnvelope, zn as consumeWebhook, ct as createAipAgentAdapter, et as createAipCapabilities, At as createAipMcpGatewayRuntime, jt as createAipMcpGatewayRuntimeWithPolicy, Yr as createAuditLog, rn as createCachingKeyRegistry, Vt as createClusterReplayStore, nn as createCompositeKeyRegistry, E as createEnvelope, Wr as createGateway, _r as createHttpKeyRegistry, en as createHttpMcpClient, $t as createHttpMcpHandler, An as createHttpMiddleware, at as createKeyringSignatureResolver, Jt as createMcpClientCodec, jr as createMetricsMiddleware, wt as createPolicyEnforcer, Gr as createProductionGateway, mt as createRawTaskFromJsonRpc, lt as createRawTaskFromLangChain, dt as createRawTaskFromLlamaIndex, zt as createRedisReplayStore, Wt as createRedisRevocationStore, Mn as createSignedFetchRequest, Ze as createSignedMessage, tr as createSignedStream, cr as createSignedWebSocketStream, tn as createStaticKeyRegistry, Qt as createStdioMcpClient, nr as createStreamVerifier, Sn as decodeCbor, Ge as decodeEnvelope, Je as decodeEnvelopeBatch, Ie as decodeEnvelopeBinary, Tn as decodeEnvelopeCbor, or as decodeStreamChunk, li as decryptBody, Lr as delegateCapabilityToken, si as deriveEncryptionKey, tt as encodeAipCapabilities, xn as encodeCbor, Ke as encodeEnvelope, qe as encodeEnvelopeBatch, Fe as encodeEnvelopeBinary, wn as encodeEnvelopeCbor, ar as encodeStreamChunk, ci as encryptBody, gr as fetchWellKnownKeys, pe as generateEd25519KeypairBase64Url, oi as generateX25519KeyPair, Qr as getOtelTracer, Pt as getRuntimeTuningPreset, xr as globalRateLimiter, Cr as isAllowedSender, Tt as isRuntimeMode, Pr as issueCapabilityToken, xt as loadRuntimePolicy, J as matchGlob, Sr as matchPolicy, Z as metrics, rt as negotiateAipCapabilities, di as openEnvelope, nt as parseAipCapabilities, Hr as parseCapabilityChain, yt as parseRuntimePolicyJson, hr as parseWellKnownKeys, y as randomHex, A as receiveEnvelope, Ye as receiveEnvelopeBatch, lr as receiveSignedWebSocketStream, Ft as recommendPolicyAdjustments, Ar as renderPrometheusText, ui as sealEnvelope, Vr as serializeCapabilityChain, Zt as serveMcpOverStdio, mr as serveWellKnownKeys, Zr as setOtelProvider, b as signCanonicalPayloadEd25519, de as signCanonicalPayloadHmac, C as signEnvelopeEd25519, me as signEnvelopeHmac, jn as signFetchRequest, dr as signGrpcCall, On as signHttpRequest, kn as signHttpRequestHmac, Bn as signQueueMessage, Tr as signResponse, rr as signStream, Fn as signWebhook, In as signWebhookHmac, ht as toJsonRpcResponse, ut as toLangChainMessage, ft as toLlamaIndexMessage, Br as tokenMatchesScope, T as validateEnvelope, vt as validateRuntimePolicy, x as verifyCanonicalPayloadEd25519, fe as verifyCanonicalPayloadHmac, ge as verifyCanonicalPayloadSignature, zr as verifyCapabilityChain, Rr as verifyCapabilityToken, w as verifyEnvelopeEd25519, S as verifyEnvelopeHmac, he as verifyEnvelopeSignature, fr as verifyGrpcCall, Dn as verifyHttpEnvelope, Hn as verifyQueueBatch, Vn as verifyQueueMessage, Er as verifyResponse, ir as verifyStream, Ln as verifyWebhook, Rn as verifyWebhookHmac, ei as withAuditSpan, pr as withGrpcVerification, Gt as withRevocationCheck, $r as withVerificationSpan, Yt as wrapMcpClient, qt as wrapMcpServer, sr as wrapWebSocket };