@7h3/protocol 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -24,7 +24,7 @@ function re(e) {
24
24
  let t = `hs256:${e}`, n = d.get(t);
25
25
  if (n) return n;
26
26
  d.size >= u && d.clear();
27
- let r = v().importKey("raw", l.encode(e), {
27
+ let r = _().importKey("raw", l.encode(e), {
28
28
  name: "HMAC",
29
29
  hash: "SHA-256"
30
30
  }, !1, ["sign", "verify"]).catch((e) => {
@@ -36,7 +36,7 @@ function ie(e) {
36
36
  let t = `ed25519:pkcs8:${e}`, n = p.get(t);
37
37
  if (n) return n;
38
38
  p.size >= f && p.clear();
39
- let r = v().importKey("pkcs8", oe(g(e)), { name: "Ed25519" }, !1, ["sign"]).catch((e) => {
39
+ let r = _().importKey("pkcs8", se(h(e)), { name: "Ed25519" }, !1, ["sign"]).catch((e) => {
40
40
  throw p.delete(t), e;
41
41
  });
42
42
  return p.set(t, r), r;
@@ -45,69 +45,77 @@ function ae(e) {
45
45
  let t = `ed25519:spki:${e}`, n = m.get(t);
46
46
  if (n) return n;
47
47
  m.size >= f && m.clear();
48
- let r = v().importKey("spki", oe(g(e)), { name: "Ed25519" }, !1, ["verify"]).catch((e) => {
48
+ let r = _().importKey("spki", se(h(e)), { name: "Ed25519" }, !1, ["verify"]).catch((e) => {
49
49
  throw m.delete(t), e;
50
50
  });
51
51
  return m.set(t, r), r;
52
52
  }
53
- function h(e) {
53
+ function oe(e) {
54
54
  let t = ee();
55
55
  return (t ? t.from(e).toString("base64") : btoa(String.fromCharCode(...e))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
56
56
  }
57
- function g(e) {
57
+ function h(e) {
58
58
  let t = e.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(e.length / 4) * 4, "="), n = ee();
59
59
  if (n) return new Uint8Array(n.from(t, "base64"));
60
60
  let r = atob(t), i = new Uint8Array(r.length);
61
61
  for (let e = 0; e < r.length; e += 1) i[e] = r.charCodeAt(e);
62
62
  return i;
63
63
  }
64
- function oe(e) {
64
+ function se(e) {
65
65
  return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
66
66
  }
67
- function _(e) {
67
+ function g(e) {
68
68
  return `{"body":${ne(e.body)},"header":${te(e.header)}}`;
69
69
  }
70
- function v() {
70
+ function _() {
71
71
  if (typeof crypto > "u" || !crypto.subtle) throw Error("Web Crypto API is not available in this runtime");
72
72
  return crypto.subtle;
73
73
  }
74
- async function se(e, t) {
75
- let n = v(), r = await re(t), i = await n.sign("HMAC", r, l.encode(e));
76
- return h(new Uint8Array(i));
74
+ function v(e = 12) {
75
+ if (typeof crypto > "u" || !crypto.getRandomValues) throw Error("Web Crypto API is not available in this runtime");
76
+ let t = new Uint8Array(e);
77
+ crypto.getRandomValues(t);
78
+ let n = "";
79
+ for (let e of t) n += e.toString(16).padStart(2, "0");
80
+ return n;
77
81
  }
78
- async function ce(e, t, n) {
79
- let r = v(), i = await re(n), a = g(t);
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));
85
+ }
86
+ async function le(e, t, n) {
87
+ let r = _(), i = await re(n), a = h(t);
80
88
  return r.verify("HMAC", i, a.buffer, l.encode(e));
81
89
  }
82
- async function le(e, t) {
83
- let n = v(), r = await ie(t), i = await n.sign("Ed25519", r, l.encode(e));
84
- return h(new Uint8Array(i));
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));
85
93
  }
86
- async function ue(e, t, n) {
87
- let r = v(), i = await ae(n), a = g(t);
94
+ async function de(e, t, n) {
95
+ let r = _(), i = await ae(n), a = h(t);
88
96
  return r.verify("Ed25519", i, a.buffer, l.encode(e));
89
97
  }
90
- async function de(e, t) {
91
- return se(e, t);
98
+ async function fe(e, t) {
99
+ return ce(e, t);
92
100
  }
93
- async function fe(e, t, n) {
94
- return ce(e, t, n);
101
+ async function pe(e, t, n) {
102
+ return le(e, t, n);
95
103
  }
96
- async function pe() {
97
- 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);
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);
98
106
  return {
99
- privateKey: h(new Uint8Array(n)),
100
- publicKey: h(new Uint8Array(r))
107
+ privateKey: oe(new Uint8Array(n)),
108
+ publicKey: oe(new Uint8Array(r))
101
109
  };
102
110
  }
103
111
  async function y(e, t) {
104
- return le(e, t);
112
+ return ue(e, t);
105
113
  }
106
114
  async function b(e, t, n) {
107
- return ue(e, t, n);
115
+ return de(e, t, n);
108
116
  }
109
117
  async function x(e, t, n = "local-dev-key") {
110
- let r = await se(_(e), t);
118
+ let r = await ce(g(e), t);
111
119
  return {
112
120
  ...e,
113
121
  signature: {
@@ -117,14 +125,14 @@ async function x(e, t, n = "local-dev-key") {
117
125
  }
118
126
  };
119
127
  }
120
- async function me(e, t) {
121
- return !e.signature || e.signature.alg !== "HS256" ? !1 : ce(_({
128
+ async function he(e, t) {
129
+ return !e.signature || e.signature.alg !== "HS256" ? !1 : le(g({
122
130
  header: e.header,
123
131
  body: e.body
124
132
  }), e.signature.value, t);
125
133
  }
126
134
  async function S(e, t, n = "local-ed25519-key") {
127
- let r = await le(_(e), t);
135
+ let r = await ue(g(e), t);
128
136
  return {
129
137
  ...e,
130
138
  signature: {
@@ -135,16 +143,16 @@ async function S(e, t, n = "local-ed25519-key") {
135
143
  };
136
144
  }
137
145
  async function C(e, t) {
138
- return !e.signature || e.signature.alg !== "ED25519" ? !1 : ue(_({
146
+ return !e.signature || e.signature.alg !== "ED25519" ? !1 : de(g({
139
147
  header: e.header,
140
148
  body: e.body
141
149
  }), e.signature.value, t);
142
150
  }
143
- async function he(e, t) {
144
- return !e.signature || e.signature.alg !== t.alg ? !1 : t.alg === "HS256" ? me(e, t.secret) : C(e, t.publicKey);
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);
145
153
  }
146
- async function ge(e, t, n) {
147
- return !t || t.alg !== n.alg ? !1 : n.alg === "HS256" ? fe(e, t.value, n.secret) : b(e, t.value, n.publicKey);
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);
148
156
  }
149
157
  function w(e, t = Date.now()) {
150
158
  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 : "";
@@ -176,12 +184,12 @@ function T(e) {
176
184
  return {
177
185
  header: {
178
186
  version: "7h3/0.1",
179
- messageId: e.messageId ?? `msg-${t}-${Math.random().toString(36).slice(2, 10)}`,
187
+ messageId: e.messageId ?? `msg-${t}-${v(6)}`,
180
188
  timestampMs: t,
181
189
  ttlMs: e.ttlMs ?? 6e4,
182
190
  sender: e.sender,
183
191
  recipient: e.recipient,
184
- nonce: e.nonce ?? Math.random().toString(36).slice(2, 12)
192
+ nonce: e.nonce ?? v(12)
185
193
  },
186
194
  body: {
187
195
  intent: e.intent,
@@ -193,12 +201,12 @@ function T(e) {
193
201
  }
194
202
  //#endregion
195
203
  //#region src/protocolBinary.ts
196
- var _e = [
204
+ var ve = [
197
205
  65,
198
206
  73,
199
207
  80,
200
208
  66
201
- ], ve = Uint8Array.from(_e), ye = 1, be = 1024 * 1024, xe = 1, Se = 2, Ce = 4, we = 8, Te = new TextEncoder(), Ee = new TextDecoder(), De = new Set([
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([
202
210
  "PING",
203
211
  "PONG",
204
212
  "CAPS",
@@ -206,25 +214,25 @@ var _e = [
206
214
  "RESULT",
207
215
  "ERROR"
208
216
  ]);
209
- function Oe(e) {
210
- return Te.encode(e);
211
- }
212
217
  function ke(e) {
213
- return Ee.decode(e);
218
+ return Ee.encode(e);
214
219
  }
215
220
  function Ae(e) {
216
- return e === "ED25519" ? 2 : 1;
221
+ return De.decode(e);
217
222
  }
218
223
  function je(e) {
224
+ return e === "ED25519" ? 2 : 1;
225
+ }
226
+ function Me(e) {
219
227
  return e === 1 ? "HS256" : e === 2 ? "ED25519" : null;
220
228
  }
221
229
  function E(e) {
222
- return { bytes: Oe(e) };
230
+ return { bytes: ke(e) };
223
231
  }
224
232
  function D(e) {
225
233
  return e ? 4 + e.bytes.byteLength : 0;
226
234
  }
227
- var Me = class {
235
+ var Ne = class {
228
236
  bytes;
229
237
  view;
230
238
  offset = 0;
@@ -249,7 +257,7 @@ var Me = class {
249
257
  finish() {
250
258
  return this.bytes;
251
259
  }
252
- }, Ne = class {
260
+ }, Pe = class {
253
261
  bytes;
254
262
  offset = 0;
255
263
  constructor(e) {
@@ -280,14 +288,14 @@ var Me = class {
280
288
  }
281
289
  readString() {
282
290
  let e = this.readU32();
283
- return ke(this.readBytes(e));
291
+ return Ae(this.readBytes(e));
284
292
  }
285
293
  };
286
- function Pe(e) {
287
- let t = (e.header.recipient ? xe : 0) | (e.body.capability ? Se : 0) | (e.body.correlationId ? Ce : 0) | (e.signature ? we : 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 Me(ve.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));
288
- return p.writeBytes(ve), p.writeU8(ye), 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(Ae(e.signature.alg)), p.writeString(d), p.writeString(f)), p.finish();
294
+ 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));
296
+ 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();
289
297
  }
290
- function Fe(e, t = {}) {
298
+ function Ie(e, t = {}) {
291
299
  try {
292
300
  let n = t.maxFrameBytes ?? 1048576;
293
301
  if (e.byteLength > n) return {
@@ -298,13 +306,13 @@ function Fe(e, t = {}) {
298
306
  }],
299
307
  envelope: null
300
308
  };
301
- let r = new Ne(e);
309
+ let r = new Pe(e);
302
310
  if ([
303
311
  r.readU8(),
304
312
  r.readU8(),
305
313
  r.readU8(),
306
314
  r.readU8()
307
- ].some((e, t) => e !== _e[t])) return {
315
+ ].some((e, t) => e !== ve[t])) return {
308
316
  ok: !1,
309
317
  diagnostics: [{
310
318
  level: "error",
@@ -313,7 +321,7 @@ function Fe(e, t = {}) {
313
321
  envelope: null
314
322
  };
315
323
  let i = r.readU8();
316
- if (i !== ye) return {
324
+ if (i !== be) return {
317
325
  ok: !1,
318
326
  diagnostics: [{
319
327
  level: "error",
@@ -343,7 +351,7 @@ function Fe(e, t = {}) {
343
351
  }],
344
352
  envelope: null
345
353
  };
346
- if (!De.has(c.body.intent)) return {
354
+ if (!Oe.has(c.body.intent)) return {
347
355
  ok: !1,
348
356
  diagnostics: [{
349
357
  level: "error",
@@ -351,8 +359,8 @@ function Fe(e, t = {}) {
351
359
  }],
352
360
  envelope: null
353
361
  };
354
- if (a & xe && (c.header.recipient = r.readString()), a & Se && (c.body.capability = r.readString()), a & Ce && (c.body.correlationId = r.readString()), a & we) {
355
- let e = r.readU8(), t = je(e);
362
+ if (a & Se && (c.header.recipient = r.readString()), a & Ce && (c.body.capability = r.readString()), a & we && (c.body.correlationId = r.readString()), a & Te) {
363
+ let e = r.readU8(), t = Me(e);
356
364
  if (!t) return {
357
365
  ok: !1,
358
366
  diagnostics: [{
@@ -392,7 +400,7 @@ function Fe(e, t = {}) {
392
400
  }
393
401
  //#endregion
394
402
  //#region src/protocolReplay.ts
395
- var Ie = class {
403
+ var Le = class {
396
404
  items = [];
397
405
  peek() {
398
406
  return this.items[0];
@@ -428,7 +436,7 @@ var Ie = class {
428
436
  }, O = class {
429
437
  entries = /* @__PURE__ */ new Map();
430
438
  maxEntries;
431
- expiries = new Ie();
439
+ expiries = new Le();
432
440
  constructor(e = 1e4) {
433
441
  this.maxEntries = e;
434
442
  }
@@ -476,7 +484,7 @@ var Ie = class {
476
484
  consumeMany(e, t = Date.now()) {
477
485
  return e.map((e) => this.consume(e, t));
478
486
  }
479
- }, Le = class {
487
+ }, Re = class {
480
488
  store;
481
489
  constructor(e) {
482
490
  this.store = e;
@@ -504,7 +512,7 @@ var Ie = class {
504
512
  }
505
513
  return Promise.all(e.map((e) => this.consume(e, t)));
506
514
  }
507
- }, Re = class {
515
+ }, ze = class {
508
516
  entries = /* @__PURE__ */ new Map();
509
517
  maxEntries;
510
518
  constructor(e = 512) {
@@ -534,20 +542,20 @@ var Ie = class {
534
542
  this.entries.delete(e);
535
543
  }
536
544
  };
537
- function ze(e, t) {
545
+ function Be(e, t) {
538
546
  return `${t}|${e.alg}|${e.keyId}`;
539
547
  }
540
- function Be(e) {
548
+ function Ve(e) {
541
549
  if (!e || typeof e != "object") return !1;
542
550
  let t = e;
543
551
  return !!(t.header && t.body);
544
552
  }
545
- function Ve(e) {
553
+ function He(e) {
546
554
  if (!e || typeof e != "object") return !1;
547
555
  let t = e;
548
556
  return t.v === "7h3/0.1" && typeof t.mid == "string" && typeof t.i == "string";
549
557
  }
550
- function He(e) {
558
+ function Ue(e) {
551
559
  return {
552
560
  header: {
553
561
  version: e.v,
@@ -571,7 +579,7 @@ function He(e) {
571
579
  } : void 0
572
580
  };
573
581
  }
574
- function Ue(e) {
582
+ function We(e) {
575
583
  return {
576
584
  v: e.header.version,
577
585
  mid: e.header.messageId,
@@ -591,15 +599,15 @@ function Ue(e) {
591
599
  } : void 0
592
600
  };
593
601
  }
594
- function We(e) {
595
- if (e instanceof Uint8Array) return Fe(e);
602
+ function Ge(e) {
603
+ if (e instanceof Uint8Array) return Ie(e);
596
604
  try {
597
605
  let t = JSON.parse(e);
598
- return Ve(t) ? {
606
+ return He(t) ? {
599
607
  ok: !0,
600
608
  diagnostics: [],
601
- envelope: He(t)
602
- } : Be(t) ? {
609
+ envelope: Ue(t)
610
+ } : Ve(t) ? {
603
611
  ok: !0,
604
612
  diagnostics: [],
605
613
  envelope: t
@@ -622,20 +630,20 @@ function We(e) {
622
630
  };
623
631
  }
624
632
  }
625
- function Ge(e, t = "json") {
626
- return t === "binary" ? Pe(e) : JSON.stringify(t === "compact" ? Ue(e) : e);
633
+ function Ke(e, t = "json") {
634
+ return t === "binary" ? Fe(e) : JSON.stringify(t === "compact" ? We(e) : e);
627
635
  }
628
- function Ke(e, t = "compact") {
629
- return JSON.stringify(t === "compact" ? e.map(Ue) : e);
636
+ function qe(e, t = "compact") {
637
+ return JSON.stringify(t === "compact" ? e.map(We) : e);
630
638
  }
631
- function qe(e) {
639
+ function Je(e) {
632
640
  try {
633
641
  let t = JSON.parse(e);
634
- return Array.isArray(t) ? t.map((e) => Ve(e) ? {
642
+ return Array.isArray(t) ? t.map((e) => He(e) ? {
635
643
  ok: !0,
636
644
  diagnostics: [],
637
- envelope: He(e)
638
- } : Be(e) ? {
645
+ envelope: Ue(e)
646
+ } : Ve(e) ? {
639
647
  ok: !0,
640
648
  diagnostics: [],
641
649
  envelope: e
@@ -673,7 +681,7 @@ async function k(e, t = {}) {
673
681
  ...e
674
682
  });
675
683
  }
676
- let o = typeof e == "string" || e instanceof Uint8Array ? We(e) : {
684
+ let o = typeof e == "string" || e instanceof Uint8Array ? Ge(e) : {
677
685
  ok: !0,
678
686
  diagnostics: [],
679
687
  envelope: e
@@ -731,7 +739,7 @@ async function k(e, t = {}) {
731
739
  diagnostics: s,
732
740
  envelope: o.envelope
733
741
  });
734
- let c, l = o.envelope.signature, u = ze(l, o.envelope.header.sender);
742
+ let c, l = o.envelope.signature, u = Be(l, o.envelope.header.sender);
735
743
  if (t.verificationMaterialCache && (c = t.verificationMaterialCache.get(u, n)), t.signatureResolver && (c ??= await t.signatureResolver(l, o.envelope.header.sender)), !c && l.alg === "HS256" && t.secretResolver) {
736
744
  let e = await t.secretResolver(l.keyId, o.envelope.header.sender);
737
745
  e && (c = {
@@ -756,7 +764,7 @@ async function k(e, t = {}) {
756
764
  diagnostics: s,
757
765
  envelope: o.envelope
758
766
  };
759
- if (!await ge(_({
767
+ if (!await _e(g({
760
768
  header: o.envelope.header,
761
769
  body: o.envelope.body
762
770
  }), o.envelope.signature, c)) return s.push({
@@ -798,7 +806,7 @@ async function k(e, t = {}) {
798
806
  envelope: o.envelope
799
807
  };
800
808
  }
801
- async function Je(e, t = {}) {
809
+ async function Ye(e, t = {}) {
802
810
  let n = Math.max(1, Math.floor(t.batchConcurrency ?? Infinity));
803
811
  return (async (e) => {
804
812
  let r = Array(e.length), i = 0, a = Number.isFinite(n) ? Math.min(n, e.length) : e.length;
@@ -814,15 +822,15 @@ async function Je(e, t = {}) {
814
822
  nowMs: t.nowMs ?? Date.now(),
815
823
  reason: `items=${e.length};accepted=${r.filter((e) => e?.ok).length}`
816
824
  }), r;
817
- })(typeof e == "string" ? qe(e).map((e) => e.ok && e.envelope ? e.envelope : e) : e);
825
+ })(typeof e == "string" ? Je(e).map((e) => e.ok && e.envelope ? e.envelope : e) : e);
818
826
  }
819
- var Ye = class {
827
+ var Xe = class {
820
828
  options;
821
829
  constructor(e = {}) {
822
830
  this.options = {
823
831
  ...e,
824
832
  replayCache: e.replayCache ?? new O(),
825
- verificationMaterialCache: e.verificationMaterialCache ?? new Re()
833
+ verificationMaterialCache: e.verificationMaterialCache ?? new ze()
826
834
  };
827
835
  }
828
836
  receive(e, t = Date.now()) {
@@ -832,23 +840,23 @@ var Ye = class {
832
840
  });
833
841
  }
834
842
  receiveBatch(e, t = Date.now()) {
835
- return Je(e, {
843
+ return Ye(e, {
836
844
  ...this.options,
837
845
  nowMs: t
838
846
  });
839
847
  }
840
848
  };
841
- async function Xe(e) {
849
+ async function Ze(e) {
842
850
  return x(T(e), e.secret, e.keyId);
843
851
  }
844
852
  //#endregion
845
853
  //#region src/protocolCapabilities.ts
846
- var Ze = [
854
+ var Qe = [
847
855
  "binary",
848
856
  "compact",
849
857
  "json"
850
- ], Qe = ["fast", "receipt"];
851
- function $e(e) {
858
+ ], $e = ["fast", "receipt"];
859
+ function et(e) {
852
860
  return {
853
861
  agent: e.agent,
854
862
  capabilities: e.capabilities ?? [],
@@ -857,10 +865,10 @@ function $e(e) {
857
865
  ackModes: e.ackModes ?? ["receipt"]
858
866
  };
859
867
  }
860
- function et(e) {
868
+ function tt(e) {
861
869
  return JSON.stringify(e);
862
870
  }
863
- function tt(e) {
871
+ function nt(e) {
864
872
  try {
865
873
  let t = JSON.parse(e);
866
874
  return typeof t.agent != "string" || !Array.isArray(t.capabilities) || !Array.isArray(t.wireFormats) || !Array.isArray(t.ackModes) || typeof t.batchMax != "number" || t.batchMax < 1 ? null : {
@@ -874,8 +882,8 @@ function tt(e) {
874
882
  return null;
875
883
  }
876
884
  }
877
- function nt(e, t) {
878
- let n = Ze.find((n) => e.wireFormats.includes(n) && t.wireFormats.includes(n)) ?? "compact", r = Qe.find((n) => e.ackModes.includes(n) && t.ackModes.includes(n)) ?? "receipt";
885
+ function rt(e, t) {
886
+ let n = Qe.find((n) => e.wireFormats.includes(n) && t.wireFormats.includes(n)) ?? "compact", r = $e.find((n) => e.ackModes.includes(n) && t.ackModes.includes(n)) ?? "receipt";
879
887
  return {
880
888
  wireFormat: n,
881
889
  batchMax: Math.max(1, Math.min(e.batchMax, t.batchMax)),
@@ -884,7 +892,7 @@ function nt(e, t) {
884
892
  }
885
893
  //#endregion
886
894
  //#region src/keyRotation.ts
887
- var rt = class {
895
+ var it = class {
888
896
  records;
889
897
  constructor(e = []) {
890
898
  this.records = [...e];
@@ -903,12 +911,12 @@ var rt = class {
903
911
  return this.records.filter((r) => r.sender === t && r.keyId === e.keyId && r.alg === e.alg && r.status !== "revoked" && r.notBeforeMs <= n && n < r.notAfterMs).sort((e, t) => t.notBeforeMs - e.notBeforeMs)[0]?.material;
904
912
  }
905
913
  };
906
- function it(e, t = () => Date.now()) {
914
+ function at(e, t = () => Date.now()) {
907
915
  return async (n, r) => e.resolveVerificationMaterial(n, r, t());
908
916
  }
909
917
  //#endregion
910
918
  //#region src/protocolAgent.ts
911
- var at = class {
919
+ var ot = class {
912
920
  agentId;
913
921
  outboundSecret;
914
922
  keyId;
@@ -973,7 +981,7 @@ var at = class {
973
981
  if (e.body.intent === "CAPS") return this.createSignedIntent({
974
982
  recipient: e.header.sender,
975
983
  intent: "RESULT",
976
- content: et($e({
984
+ content: tt(et({
977
985
  agent: this.agentId,
978
986
  capabilities: this.capabilities,
979
987
  wireFormats: this.supportedWireFormats,
@@ -1001,14 +1009,14 @@ var at = class {
1001
1009
  }
1002
1010
  return null;
1003
1011
  }
1004
- }, ot = class {
1012
+ }, st = class {
1005
1013
  session;
1006
1014
  wireFormat;
1007
1015
  constructor(e) {
1008
- this.session = new at(e), this.wireFormat = e.wireFormat ?? "compact";
1016
+ this.session = new ot(e), this.wireFormat = e.wireFormat ?? "compact";
1009
1017
  }
1010
1018
  toRaw(e) {
1011
- return Ge(e, this.wireFormat);
1019
+ return Ke(e, this.wireFormat);
1012
1020
  }
1013
1021
  async createRawIntent(e) {
1014
1022
  let t = await this.session.createSignedIntent(e);
@@ -1022,12 +1030,12 @@ var at = class {
1022
1030
  return r.response && await t(this.toRaw(r.response), r.response), r;
1023
1031
  }
1024
1032
  };
1025
- function st(e) {
1026
- return new ot(e);
1033
+ function ct(e) {
1034
+ return new st(e);
1027
1035
  }
1028
1036
  //#endregion
1029
1037
  //#region src/frameworkAdapters.ts
1030
- async function ct(e, t, n = {}) {
1038
+ async function lt(e, t, n = {}) {
1031
1039
  return e.createRawIntent({
1032
1040
  recipient: n.recipient,
1033
1041
  intent: "TASK",
@@ -1036,7 +1044,7 @@ async function ct(e, t, n = {}) {
1036
1044
  correlationId: n.correlationId
1037
1045
  });
1038
1046
  }
1039
- function lt(e) {
1047
+ function ut(e) {
1040
1048
  return {
1041
1049
  content: e.body.content,
1042
1050
  name: e.body.intent,
@@ -1050,7 +1058,7 @@ function lt(e) {
1050
1058
  }
1051
1059
  };
1052
1060
  }
1053
- async function ut(e, t, n = {}) {
1061
+ async function dt(e, t, n = {}) {
1054
1062
  return e.createRawIntent({
1055
1063
  recipient: n.recipient,
1056
1064
  intent: "TASK",
@@ -1059,7 +1067,7 @@ async function ut(e, t, n = {}) {
1059
1067
  correlationId: n.correlationId
1060
1068
  });
1061
1069
  }
1062
- function dt(e) {
1070
+ function ft(e) {
1063
1071
  return {
1064
1072
  role: e.body.intent === "TASK" ? "user" : "assistant",
1065
1073
  content: e.body.content,
@@ -1072,15 +1080,15 @@ function dt(e) {
1072
1080
  }
1073
1081
  };
1074
1082
  }
1075
- function ft(e) {
1083
+ function pt(e) {
1076
1084
  return `mcp.${e}`;
1077
1085
  }
1078
- async function pt(e, t, n = {}) {
1086
+ async function mt(e, t, n = {}) {
1079
1087
  async function r(e) {
1080
1088
  n.onPolicyEvent && await n.onPolicyEvent(e);
1081
1089
  }
1082
1090
  if (n.allowedMethods && !n.allowedMethods.includes(t.method)) {
1083
- let e = n.methodToCapability ? n.methodToCapability(t.method) : ft(t.method), i = {
1091
+ let e = n.methodToCapability ? n.methodToCapability(t.method) : pt(t.method), i = {
1084
1092
  intent: "TASK",
1085
1093
  recipient: n.recipient,
1086
1094
  capability: e,
@@ -1095,7 +1103,7 @@ async function pt(e, t, n = {}) {
1095
1103
  reason: "method_not_allowed"
1096
1104
  }), Error(`JSON-RPC method '${t.method}' is not allowed`);
1097
1105
  }
1098
- let i = n.methodToCapability ? n.methodToCapability(t.method) : ft(t.method), a = {
1106
+ let i = n.methodToCapability ? n.methodToCapability(t.method) : pt(t.method), a = {
1099
1107
  intent: "TASK",
1100
1108
  recipient: n.recipient,
1101
1109
  capability: i,
@@ -1149,7 +1157,7 @@ async function pt(e, t, n = {}) {
1149
1157
  })
1150
1158
  });
1151
1159
  }
1152
- function mt(e, t, n = {}) {
1160
+ function ht(e, t, n = {}) {
1153
1161
  if (e.body.intent === "ERROR") return {
1154
1162
  jsonrpc: "2.0",
1155
1163
  id: t,
@@ -1162,7 +1170,7 @@ function mt(e, t, n = {}) {
1162
1170
  }
1163
1171
  }
1164
1172
  };
1165
- let r = e.body.content;
1173
+ let r;
1166
1174
  try {
1167
1175
  r = JSON.parse(e.body.content);
1168
1176
  } catch {
@@ -1176,16 +1184,16 @@ function mt(e, t, n = {}) {
1176
1184
  }
1177
1185
  //#endregion
1178
1186
  //#region src/runtimePolicy.ts
1179
- function ht(e) {
1187
+ function gt(e) {
1180
1188
  return typeof e == "object" && !!e && !Array.isArray(e);
1181
1189
  }
1182
- function gt(e, t) {
1190
+ function _t(e, t) {
1183
1191
  if (typeof e != "string" || e.trim().length === 0) throw Error(`Invalid runtime policy: '${t}' must be a non-empty string`);
1184
1192
  return e;
1185
1193
  }
1186
- function _t(e) {
1187
- if (!ht(e)) throw Error("Invalid runtime policy: root must be an object");
1188
- let t = gt(e.version, "version"), n = gt(e.name, "name"), r = gt(e.status, "status");
1194
+ function vt(e) {
1195
+ if (!gt(e)) throw Error("Invalid runtime policy: root must be an object");
1196
+ let t = _t(e.version, "version"), n = _t(e.name, "name"), r = _t(e.status, "status");
1189
1197
  return {
1190
1198
  ...e,
1191
1199
  version: t,
@@ -1193,17 +1201,17 @@ function _t(e) {
1193
1201
  status: r
1194
1202
  };
1195
1203
  }
1196
- function vt(e) {
1204
+ function yt(e) {
1197
1205
  let t;
1198
1206
  try {
1199
1207
  t = JSON.parse(e);
1200
1208
  } catch (e) {
1201
1209
  let t = e instanceof Error ? e.message : String(e);
1202
- throw Error(`Invalid runtime policy JSON: ${t}`);
1210
+ throw Error(`Invalid runtime policy JSON: ${t}`, { cause: e });
1203
1211
  }
1204
- return _t(t);
1212
+ return vt(t);
1205
1213
  }
1206
- async function yt(e) {
1214
+ async function bt(e) {
1207
1215
  if (typeof fetch == "function") {
1208
1216
  let t = await fetch(e);
1209
1217
  if (!t.ok) throw Error(`Failed to fetch runtime policy at '${e}': ${t.status} ${t.statusText}`);
@@ -1211,26 +1219,26 @@ async function yt(e) {
1211
1219
  }
1212
1220
  throw Error("No default runtime file reader available in this environment. Provide 'readTextFile' in loadRuntimePolicy(options).");
1213
1221
  }
1214
- async function bt(e = {}) {
1222
+ async function xt(e = {}) {
1215
1223
  let t = e.path ?? "AI_RUNTIME_POLICY.json";
1216
- return vt(await (e.readTextFile ?? yt)(t));
1224
+ return yt(await (e.readTextFile ?? bt)(t));
1217
1225
  }
1218
1226
  //#endregion
1219
1227
  //#region src/policyEnforcer.ts
1220
- function xt(e, t) {
1228
+ function St(e, t) {
1221
1229
  if (!Array.isArray(e) || e.length !== 2) throw Error(`Invalid policy tuning range '${t}': expected [min,max]`);
1222
1230
  let n = Number(e[0]), r = Number(e[1]);
1223
1231
  if (!Number.isFinite(n) || !Number.isFinite(r) || n <= 0 || r < n) throw Error(`Invalid policy tuning range '${t}': expected positive ascending numbers`);
1224
1232
  return [Math.floor(n), Math.floor(r)];
1225
1233
  }
1226
- function St(e) {
1234
+ function Ct(e) {
1227
1235
  return e === "http" || e === "ws" || e === "http-binary" || e === "http-batch" || e === "http-binary-batch" || e === "ws-batch" || e === "ws-binary" || e === "ws-binary-batch";
1228
1236
  }
1229
- function Ct(e) {
1237
+ function wt(e) {
1230
1238
  let t = Number((e.slo_defaults ?? {}).drop_pct_max ?? .1), n = Number((e.slo_defaults ?? {}).p99_ms_max ?? 20), r = Number((e.tuning ?? {}).max_retry_attempts ?? 3), i = Array.isArray((e.tuning ?? {}).retriable_status_codes) ? (e.tuning ?? {}).retriable_status_codes.map((e) => Number(e)).filter((e) => Number.isFinite(e)) : [503], a = e.tuning ?? {}, o = a.batch_size, s = a.inflight_cap, c = a.retry_backoff_ms, l = (e) => ({
1231
- batchSizeRange: xt(o?.[`${e}_traffic`], `batch_size.${e}_traffic`),
1232
- inflightCapRange: xt(s?.[`${e}_traffic`], `inflight_cap.${e}_traffic`),
1233
- retryBackoffMsRange: xt(c?.[`${e}_traffic`], `retry_backoff_ms.${e}_traffic`)
1239
+ batchSizeRange: St(o?.[`${e}_traffic`], `batch_size.${e}_traffic`),
1240
+ inflightCapRange: St(s?.[`${e}_traffic`], `inflight_cap.${e}_traffic`),
1241
+ retryBackoffMsRange: St(c?.[`${e}_traffic`], `retry_backoff_ms.${e}_traffic`)
1234
1242
  });
1235
1243
  function u(e) {
1236
1244
  return e.concurrency >= 100 ? "http-binary-batch" : e.latencySensitive ? "ws-batch" : e.compatibilityFirst ? "http" : "ws-batch";
@@ -1267,28 +1275,28 @@ function Ct(e) {
1267
1275
  }
1268
1276
  };
1269
1277
  }
1270
- async function A(e = {}) {
1271
- let t = await bt(e);
1278
+ async function Tt(e = {}) {
1279
+ let t = await xt(e);
1272
1280
  return {
1273
1281
  policy: t,
1274
- enforcer: Ct(t)
1282
+ enforcer: wt(t)
1275
1283
  };
1276
1284
  }
1277
- function wt(e) {
1278
- return St(e);
1285
+ function Et(e) {
1286
+ return Ct(e);
1279
1287
  }
1280
1288
  //#endregion
1281
1289
  //#region src/mcpGateway.ts
1282
- var Tt = [
1290
+ var Dt = [
1283
1291
  "tools/call",
1284
1292
  "resources/read",
1285
1293
  "prompts/get"
1286
1294
  ];
1287
- function Et(e) {
1295
+ function Ot(e) {
1288
1296
  return JSON.stringify(e);
1289
1297
  }
1290
- function j(e, t, n) {
1291
- return Et({
1298
+ function A(e, t, n) {
1299
+ return Ot({
1292
1300
  jsonrpc: "2.0",
1293
1301
  id: e,
1294
1302
  error: {
@@ -1297,7 +1305,7 @@ function j(e, t, n) {
1297
1305
  }
1298
1306
  });
1299
1307
  }
1300
- function Dt(e) {
1308
+ function kt(e) {
1301
1309
  let t = JSON.parse(e);
1302
1310
  return t.jsonrpc !== "2.0" || typeof t.method != "string" || t.method.length === 0 || typeof t.id != "string" && typeof t.id != "number" ? null : {
1303
1311
  jsonrpc: "2.0",
@@ -1306,30 +1314,30 @@ function Dt(e) {
1306
1314
  params: t.params
1307
1315
  };
1308
1316
  }
1309
- function Ot(e) {
1317
+ function At(e) {
1310
1318
  return e.includes("not allowed") ? -32601 : e.includes("not authorized") ? -32001 : e.includes("rate-limited") ? -32002 : -32603;
1311
1319
  }
1312
- function kt(e) {
1313
- let t = e.gatewayAgentId ?? "agent.gateway", n = e.workerAgentId ?? "agent.worker", r = e.allowedMethods ?? Tt, i = e.workerCapabilityPrefix ?? "mcp.", a = e.gatewayWireFormat ?? "compact", o = e.workerWireFormat ?? "compact";
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";
1314
1322
  async function s(t) {
1315
1323
  e.onAuditEvent && await e.onAuditEvent({
1316
1324
  ...t,
1317
1325
  timestampMs: Date.now()
1318
1326
  });
1319
1327
  }
1320
- let c = st({
1328
+ let c = ct({
1321
1329
  agentId: t,
1322
1330
  outboundSecret: e.sharedSecret,
1323
1331
  sharedSecrets: { [n]: e.sharedSecret },
1324
1332
  wireFormat: a
1325
- }), l = st({
1333
+ }), l = ct({
1326
1334
  agentId: n,
1327
1335
  outboundSecret: e.sharedSecret,
1328
1336
  sharedSecrets: { [t]: e.sharedSecret },
1329
1337
  wireFormat: o,
1330
1338
  onTask: async (e) => ({
1331
1339
  intent: "RESULT",
1332
- content: Et({
1340
+ content: Ot({
1333
1341
  ok: !0,
1334
1342
  capability: e.body.capability,
1335
1343
  content: e.body.content
@@ -1342,18 +1350,18 @@ function kt(e) {
1342
1350
  if (!i) return null;
1343
1351
  let a = null;
1344
1352
  try {
1345
- let t = Dt(i);
1353
+ let t = kt(i);
1346
1354
  if (!t) return await s({
1347
1355
  phase: "request_error",
1348
1356
  code: -32600,
1349
1357
  message: "Invalid Request"
1350
- }), j(null, -32600, "Invalid Request");
1358
+ }), A(null, -32600, "Invalid Request");
1351
1359
  a = t.id, await s({
1352
1360
  phase: "request_received",
1353
1361
  id: t.id,
1354
1362
  method: t.method
1355
1363
  });
1356
- let o = await pt(c, t, {
1364
+ let o = await mt(c, t, {
1357
1365
  recipient: n,
1358
1366
  allowedMethods: r,
1359
1367
  methodToCapability: e.methodToCapability,
@@ -1377,7 +1385,7 @@ function kt(e) {
1377
1385
  method: t.method,
1378
1386
  code: -32603,
1379
1387
  message: "AIP worker did not produce a response"
1380
- }), j(a, -32603, "AIP worker did not produce a response");
1388
+ }), A(a, -32603, "AIP worker did not produce a response");
1381
1389
  let d = await c.receiveRaw(u);
1382
1390
  return !d.ok || !d.received ? (await s({
1383
1391
  phase: "verification_failed",
@@ -1385,25 +1393,25 @@ function kt(e) {
1385
1393
  method: t.method,
1386
1394
  code: -32603,
1387
1395
  message: "AIP verification failed"
1388
- }), j(a, -32603, "AIP verification failed")) : (await s({
1396
+ }), A(a, -32603, "AIP verification failed")) : (await s({
1389
1397
  phase: "request_success",
1390
1398
  id: t.id,
1391
1399
  method: t.method
1392
- }), Et(mt(d.received, t.id)));
1400
+ }), Ot(ht(d.received, t.id)));
1393
1401
  } catch (e) {
1394
- let t = e instanceof Error ? e.message : "Internal error", n = Ot(t);
1402
+ let t = e instanceof Error ? e.message : "Internal error", n = At(t);
1395
1403
  return await s({
1396
1404
  phase: "request_error",
1397
1405
  id: a,
1398
1406
  code: n,
1399
1407
  message: t
1400
- }), j(a, n, t);
1408
+ }), A(a, n, t);
1401
1409
  }
1402
1410
  } };
1403
1411
  }
1404
- async function At(e) {
1405
- if (!e.runtimePolicy?.enabled) return kt(e);
1406
- let { enforcer: t } = await A(e.runtimePolicy.options);
1412
+ async function Mt(e) {
1413
+ if (!e.runtimePolicy?.enabled) return jt(e);
1414
+ let { enforcer: t } = await Tt(e.runtimePolicy.options);
1407
1415
  t.assertInvariant({
1408
1416
  signatureVerification: !0,
1409
1417
  canonicalization: !0,
@@ -1415,7 +1423,7 @@ async function At(e) {
1415
1423
  latencySensitive: e.runtimePolicy.latencySensitive,
1416
1424
  compatibilityFirst: e.runtimePolicy.compatibilityFirst
1417
1425
  }), r = n.includes("binary") ? "binary" : "compact";
1418
- return kt({
1426
+ return jt({
1419
1427
  ...e,
1420
1428
  gatewayWireFormat: r,
1421
1429
  workerWireFormat: r,
@@ -1431,14 +1439,14 @@ async function At(e) {
1431
1439
  }
1432
1440
  //#endregion
1433
1441
  //#region src/runtimePolicyManager.ts
1434
- var jt = class {
1442
+ var Nt = class {
1435
1443
  snapshot = null;
1436
1444
  options;
1437
1445
  constructor(e = {}) {
1438
1446
  this.options = e;
1439
1447
  }
1440
1448
  async loadInitial() {
1441
- let e = await A(this.options);
1449
+ let e = await Tt(this.options);
1442
1450
  return this.snapshot = {
1443
1451
  ...e,
1444
1452
  loadedAtMs: Date.now()
@@ -1451,7 +1459,7 @@ var jt = class {
1451
1459
  async refresh() {
1452
1460
  let e = this.snapshot;
1453
1461
  try {
1454
- let e = await A(this.options);
1462
+ let e = await Tt(this.options);
1455
1463
  return this.snapshot = {
1456
1464
  ...e,
1457
1465
  loadedAtMs: Date.now()
@@ -1461,7 +1469,7 @@ var jt = class {
1461
1469
  throw t;
1462
1470
  }
1463
1471
  }
1464
- }, Mt = {
1472
+ }, Pt = {
1465
1473
  dev: {
1466
1474
  environment: "dev",
1467
1475
  mode: "ws-batch",
@@ -1487,12 +1495,12 @@ var jt = class {
1487
1495
  retryMaxAttempts: 3
1488
1496
  }
1489
1497
  };
1490
- function Nt(e) {
1491
- return Mt[e];
1498
+ function Ft(e) {
1499
+ return Pt[e];
1492
1500
  }
1493
1501
  //#endregion
1494
1502
  //#region src/policyTelemetryFeedback.ts
1495
- function Pt(e) {
1503
+ function It(e) {
1496
1504
  let t = [], n = "normal";
1497
1505
  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")), {
1498
1506
  severity: n,
@@ -1501,7 +1509,7 @@ function Pt(e) {
1501
1509
  }
1502
1510
  //#endregion
1503
1511
  //#region src/redisClient.ts
1504
- var Ft = class {
1512
+ var Lt = class {
1505
1513
  entries = /* @__PURE__ */ new Map();
1506
1514
  now;
1507
1515
  constructor(e = {}) {
@@ -1547,13 +1555,13 @@ var Ft = class {
1547
1555
  };
1548
1556
  return t;
1549
1557
  }
1550
- }, It = class {
1558
+ }, Rt = class {
1551
1559
  keyPrefix;
1552
1560
  client;
1553
1561
  constructor(e = {}) {
1554
1562
  if (this.keyPrefix = e.keyPrefix ?? "7h3:nonce:", e.client) this.client = e.client;
1555
1563
  else {
1556
- let e = new Ft();
1564
+ let e = new Lt();
1557
1565
  this.client = {
1558
1566
  set: (t, n, r) => e.set(t, n, {
1559
1567
  nx: r?.nx,
@@ -1572,7 +1580,7 @@ var Ft = class {
1572
1580
  px: Math.max(1, t)
1573
1581
  }) === null;
1574
1582
  }
1575
- }, Lt = class {
1583
+ }, zt = class {
1576
1584
  nodes;
1577
1585
  constructor(e) {
1578
1586
  this.nodes = e;
@@ -1581,17 +1589,17 @@ var Ft = class {
1581
1589
  return (await Promise.all(this.nodes.map((n) => n.check(e, t)))).some((e) => e);
1582
1590
  }
1583
1591
  };
1584
- function Rt(e, t = {}) {
1585
- return zt(e) ? Vt(e, t) : new It(e);
1592
+ function Bt(e, t = {}) {
1593
+ return Vt(e) ? Ut(e, t) : new Rt(e);
1586
1594
  }
1587
- function zt(e) {
1595
+ function Vt(e) {
1588
1596
  return typeof e == "object" && !!e && typeof e.set == "function" && (typeof e.pipeline == "function" || !("quit" in e));
1589
1597
  }
1590
- function Bt(e) {
1591
- return new Lt(e.map((e) => new It({ redisUrl: e })));
1598
+ function Ht(e) {
1599
+ return new zt(e.map((e) => new Rt({ redisUrl: e })));
1592
1600
  }
1593
- function Vt(e, t = {}) {
1594
- let n = t.keyPrefix ?? "aip:replay:", r = t.errorBehavior ?? "fallback", i = t.onDegraded, a = t.fallback ?? (r === "fallback" ? Vt(new Ft(), {
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(), {
1595
1603
  keyPrefix: n,
1596
1604
  errorBehavior: "reject"
1597
1605
  }) : void 0);
@@ -1631,7 +1639,7 @@ function Vt(e, t = {}) {
1631
1639
  }
1632
1640
  //#endregion
1633
1641
  //#region src/revocation.ts
1634
- var Ht = class {
1642
+ var Wt = class {
1635
1643
  revoked = /* @__PURE__ */ new Map();
1636
1644
  now;
1637
1645
  constructor(e = {}) {
@@ -1648,7 +1656,7 @@ var Ht = class {
1648
1656
  this.revoked.set(this.makeKey(e, t), n.untilMs ?? Infinity);
1649
1657
  }
1650
1658
  };
1651
- function Ut(e, t = {}) {
1659
+ function Gt(e, t = {}) {
1652
1660
  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();
1653
1661
  function c(e, t) {
1654
1662
  return `${n}${e}${t}`;
@@ -1680,7 +1688,7 @@ function Ut(e, t = {}) {
1680
1688
  }
1681
1689
  };
1682
1690
  }
1683
- function Wt(e, t, n = {}) {
1691
+ function Kt(e, t, n = {}) {
1684
1692
  let r = n.nowMsProvider ?? (() => Date.now());
1685
1693
  return async (n, i) => {
1686
1694
  if (!await t.isRevoked(i, n.keyId, r())) return e(n, i);
@@ -1688,7 +1696,7 @@ function Wt(e, t, n = {}) {
1688
1696
  }
1689
1697
  //#endregion
1690
1698
  //#region src/mcpWrapper.ts
1691
- function Gt(e, t, n) {
1699
+ function j(e, t, n) {
1692
1700
  return {
1693
1701
  jsonrpc: "2.0",
1694
1702
  id: e,
@@ -1698,17 +1706,17 @@ function Gt(e, t, n) {
1698
1706
  }
1699
1707
  };
1700
1708
  }
1701
- function Kt(e, t) {
1709
+ function qt(e, t) {
1702
1710
  return {
1703
1711
  requireSignature: !0,
1704
1712
  ...e.receive,
1705
1713
  replayCache: t
1706
1714
  };
1707
1715
  }
1708
- function qt(e, t) {
1709
- let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = Kt(t, t.receive?.replayCache ?? new O());
1716
+ function Jt(e, t) {
1717
+ let n = t.wireFormat ?? "compact", r = t.ttlMs ?? 6e4, i = qt(t, t.receive?.replayCache ?? new O());
1710
1718
  async function a(e) {
1711
- return Ge(await t.sign(e), n);
1719
+ return Ke(await t.sign(e), n);
1712
1720
  }
1713
1721
  function o(e, n, i, o) {
1714
1722
  return a(T({
@@ -1722,25 +1730,25 @@ function qt(e, t) {
1722
1730
  }
1723
1731
  return async (n) => {
1724
1732
  let r = await k(n, i), a = r.envelope?.header.sender, s = r.envelope?.header.messageId;
1725
- if (!r.ok || !r.envelope) return o(a, "ERROR", Gt(null, -32600, r.diagnostics.find((e) => e.level === "error")?.message ?? "AIP verification failed"), s);
1726
- if (r.envelope.header.recipient !== t.selfAgentId) return o(a, "ERROR", Gt(null, -32600, "Recipient mismatch: envelope not addressed to this agent"), s);
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);
1727
1735
  let c;
1728
1736
  try {
1729
1737
  c = JSON.parse(r.envelope.body.content);
1730
1738
  } catch {
1731
- return o(a, "ERROR", Gt(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
1739
+ return o(a, "ERROR", j(null, -32700, "Parse error: envelope body is not JSON-RPC"), s);
1732
1740
  }
1733
1741
  let l;
1734
1742
  try {
1735
1743
  l = await e(c);
1736
1744
  } catch (e) {
1737
- l = Gt(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
1745
+ l = j(c.id ?? null, -32603, e instanceof Error ? e.message : "Internal error");
1738
1746
  }
1739
1747
  return o(r.envelope.header.sender, "RESULT", l, s);
1740
1748
  };
1741
1749
  }
1742
- function Jt(e) {
1743
- let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = Kt(e, e.receive?.replayCache ?? new O());
1750
+ function Yt(e) {
1751
+ let t = e.wireFormat ?? "compact", n = e.ttlMs ?? 6e4, r = qt(e, e.receive?.replayCache ?? new O());
1744
1752
  return {
1745
1753
  async encodeRequest(r) {
1746
1754
  let i = T({
@@ -1751,7 +1759,7 @@ function Jt(e) {
1751
1759
  ttlMs: n
1752
1760
  });
1753
1761
  return {
1754
- raw: Ge(await e.sign(i), t),
1762
+ raw: Ke(await e.sign(i), t),
1755
1763
  messageId: i.header.messageId
1756
1764
  };
1757
1765
  },
@@ -1768,8 +1776,8 @@ function Jt(e) {
1768
1776
  }
1769
1777
  };
1770
1778
  }
1771
- function Yt(e, t) {
1772
- let n = Jt(t);
1779
+ function Xt(e, t) {
1780
+ let n = Yt(t);
1773
1781
  return async (t) => {
1774
1782
  let { raw: r, messageId: i } = await n.encodeRequest(t);
1775
1783
  return n.decodeResponse(await e(r), { expectCorrelationId: i });
@@ -1780,11 +1788,11 @@ function Yt(e, t) {
1780
1788
  var M = /* @__PURE__ */ c((/* @__PURE__ */ o(((e, t) => {
1781
1789
  t.exports = {};
1782
1790
  })))(), 1);
1783
- function Xt(e) {
1791
+ function Zt(e) {
1784
1792
  if (typeof e != "string") throw Error("stdio adapter supports json/compact (string) wire formats; use the HTTP adapter for binary");
1785
1793
  return e;
1786
1794
  }
1787
- function Zt(e, t = {}) {
1795
+ function Qt(e, t = {}) {
1788
1796
  let n = t.input ?? process.stdin, r = t.output ?? process.stdout, i = M.default.createInterface({
1789
1797
  input: n,
1790
1798
  crlfDelay: Infinity
@@ -1793,7 +1801,7 @@ function Zt(e, t = {}) {
1793
1801
  i && (a = a.then(async () => {
1794
1802
  try {
1795
1803
  let t = await e(i);
1796
- r.write(`${Xt(t)}\n`);
1804
+ r.write(`${Zt(t)}\n`);
1797
1805
  } catch (e) {
1798
1806
  t.onError?.(e);
1799
1807
  }
@@ -1803,7 +1811,7 @@ function Zt(e, t = {}) {
1803
1811
  i.off("line", o), i.close();
1804
1812
  } };
1805
1813
  }
1806
- function Qt(e) {
1814
+ function $t(e) {
1807
1815
  let t = M.default.createInterface({
1808
1816
  input: e.input,
1809
1817
  crlfDelay: Infinity
@@ -1815,7 +1823,7 @@ function Qt(e) {
1815
1823
  };
1816
1824
  return t.on("line", r), {
1817
1825
  send(t) {
1818
- let r = Xt(t);
1826
+ let r = Zt(t);
1819
1827
  return new Promise((t) => {
1820
1828
  n.push(t), e.output.write(`${r}\n`);
1821
1829
  });
@@ -1825,7 +1833,7 @@ function Qt(e) {
1825
1833
  }
1826
1834
  };
1827
1835
  }
1828
- function $t(e, t = {}) {
1836
+ function en(e, t = {}) {
1829
1837
  return (n, r) => {
1830
1838
  let i = [];
1831
1839
  n.on("data", (e) => i.push(e)), n.on("error", () => {
@@ -1849,7 +1857,7 @@ function $t(e, t = {}) {
1849
1857
  });
1850
1858
  };
1851
1859
  }
1852
- function en(e) {
1860
+ function tn(e) {
1853
1861
  let t = e.fetchImpl ?? fetch, n = e.binary ? "application/octet-stream" : "application/json";
1854
1862
  return { async send(r) {
1855
1863
  let i = await t(e.url, {
@@ -1865,12 +1873,12 @@ function en(e) {
1865
1873
  }
1866
1874
  //#endregion
1867
1875
  //#region src/keyRegistry.ts
1868
- function tn(e) {
1876
+ function nn(e) {
1869
1877
  return { async getPublicKey(t) {
1870
1878
  return e[t] ?? null;
1871
1879
  } };
1872
1880
  }
1873
- function nn(...e) {
1881
+ function rn(...e) {
1874
1882
  return {
1875
1883
  async getPublicKey(t) {
1876
1884
  for (let n of e) {
@@ -1889,7 +1897,7 @@ function nn(...e) {
1889
1897
  }
1890
1898
  };
1891
1899
  }
1892
- function rn(e, t) {
1900
+ function an(e, t) {
1893
1901
  let n = t?.ttlMs ?? 6e4, r = /* @__PURE__ */ new Map();
1894
1902
  async function i(e, t) {
1895
1903
  let i = Date.now(), a = r.get(e);
@@ -1911,18 +1919,18 @@ function rn(e, t) {
1911
1919
  }
1912
1920
  //#endregion
1913
1921
  //#region src/cborCodec.ts
1914
- var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 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 {
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 {
1915
1923
  chunks = [];
1916
1924
  encode(e) {
1917
1925
  return this.chunks = [], this._encode(e), this._concat();
1918
1926
  }
1919
1927
  _encode(e) {
1920
1928
  if (e == null) {
1921
- this.chunks.push(new Uint8Array([pn]));
1929
+ this.chunks.push(new Uint8Array([mn]));
1922
1930
  return;
1923
1931
  }
1924
1932
  if (typeof e == "boolean") {
1925
- this.chunks.push(new Uint8Array([e ? fn : dn]));
1933
+ this.chunks.push(new Uint8Array([e ? pn : fn]));
1926
1934
  return;
1927
1935
  }
1928
1936
  if (typeof e == "number") {
@@ -1960,7 +1968,7 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
1960
1968
  new DataView(t).setFloat64(0, e, !1), this.chunks.push(new Uint8Array(t));
1961
1969
  return;
1962
1970
  }
1963
- e >= 0 ? this._encodeHead(P, e) : this._encodeHead(on, -1 - e);
1971
+ e >= 0 ? this._encodeHead(P, e) : this._encodeHead(sn, -1 - e);
1964
1972
  }
1965
1973
  _float64Header() {
1966
1974
  return new Uint8Array([251]);
@@ -1970,10 +1978,10 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
1970
1978
  this._encodeHead(F, t.length), this.chunks.push(t);
1971
1979
  }
1972
1980
  _encodeByteString(e) {
1973
- this._encodeHead(sn, e.length), this.chunks.push(e);
1981
+ this._encodeHead(cn, e.length), this.chunks.push(e);
1974
1982
  }
1975
1983
  _encodeArray(e) {
1976
- this._encodeHead(cn, e.length);
1984
+ this._encodeHead(ln, e.length);
1977
1985
  for (let t of e) this._encode(t);
1978
1986
  }
1979
1987
  _encodeMapFromAnyEntries(e) {
@@ -1990,7 +1998,7 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
1990
1998
  value: t
1991
1999
  };
1992
2000
  });
1993
- t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(ln, t.length);
2001
+ t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(un, t.length);
1994
2002
  for (let { key: e, value: n } of t) {
1995
2003
  if (typeof e == "number" && Number.isInteger(e)) this._encodeHead(P, e);
1996
2004
  else {
@@ -2009,7 +2017,7 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2009
2017
  value: t
2010
2018
  };
2011
2019
  });
2012
- t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(ln, t.length);
2020
+ t.sort((e, t) => this._compareBytes(e.keyEncoded, t.keyEncoded)), this._encodeHead(un, t.length);
2013
2021
  for (let { keyBytes: e, value: n } of t) this._encodeHead(F, e.length), this.chunks.push(e), this._encode(n);
2014
2022
  }
2015
2023
  _compareBytes(e, t) {
@@ -2030,24 +2038,24 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2030
2038
  _encodeHeadBytes(e, t) {
2031
2039
  let n = e << 5;
2032
2040
  if (t <= 23) return new Uint8Array([n | t]);
2033
- if (t <= 255) return new Uint8Array([n | mn, t]);
2041
+ if (t <= 255) return new Uint8Array([n | hn, t]);
2034
2042
  if (t <= 65535) {
2035
2043
  let e = /* @__PURE__ */ new ArrayBuffer(3), r = new DataView(e);
2036
- return r.setUint8(0, n | hn), r.setUint16(1, t, !1), new Uint8Array(e);
2044
+ return r.setUint8(0, n | gn), r.setUint16(1, t, !1), new Uint8Array(e);
2037
2045
  }
2038
2046
  if (t <= 4294967295) {
2039
2047
  let e = /* @__PURE__ */ new ArrayBuffer(5), r = new DataView(e);
2040
- return r.setUint8(0, n | gn), r.setUint32(1, t, !1), new Uint8Array(e);
2048
+ return r.setUint8(0, n | _n), r.setUint32(1, t, !1), new Uint8Array(e);
2041
2049
  }
2042
2050
  let r = /* @__PURE__ */ new ArrayBuffer(9), i = new DataView(r);
2043
- return i.setUint8(0, n | _n), i.setBigUint64(1, BigInt(t), !1), new Uint8Array(r);
2051
+ return i.setUint8(0, n | vn), i.setBigUint64(1, BigInt(t), !1), new Uint8Array(r);
2044
2052
  }
2045
2053
  _concat() {
2046
2054
  let e = this.chunks.reduce((e, t) => e + t.length, 0), t = new Uint8Array(e), n = 0;
2047
2055
  for (let e of this.chunks) t.set(e, n), n += e.length;
2048
2056
  return t;
2049
2057
  }
2050
- }, bn = class {
2058
+ }, xn = class {
2051
2059
  data;
2052
2060
  offset = 0;
2053
2061
  decode(e) {
@@ -2057,21 +2065,21 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2057
2065
  let e = this._readByte(), t = e >> 5 & 7, n = e & 31;
2058
2066
  switch (t) {
2059
2067
  case P: return this._decodeUint(n);
2060
- case on: return -1 - this._decodeUint(n);
2061
- case sn: {
2068
+ case sn: return -1 - this._decodeUint(n);
2069
+ case cn: {
2062
2070
  let e = this._decodeUint(n);
2063
2071
  return this._readBytes(e);
2064
2072
  }
2065
2073
  case F: {
2066
2074
  let e = this._decodeUint(n), t = this._readBytes(e);
2067
- return an.decode(t);
2075
+ return on.decode(t);
2068
2076
  }
2069
- case cn: {
2077
+ case ln: {
2070
2078
  let e = this._decodeUint(n), t = [];
2071
2079
  for (let n = 0; n < e; n++) t.push(this._decode());
2072
2080
  return t;
2073
2081
  }
2074
- case ln: {
2082
+ case un: {
2075
2083
  let e = this._decodeUint(n), t = {};
2076
2084
  for (let n = 0; n < e; n++) {
2077
2085
  let e = this._decode();
@@ -2079,11 +2087,11 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2079
2087
  }
2080
2088
  return t;
2081
2089
  }
2082
- case un:
2090
+ case dn:
2083
2091
  if (n === 20) return !1;
2084
2092
  if (n === 21) return !0;
2085
2093
  if (n === 22) return null;
2086
- if (n === vn) {
2094
+ if (n === yn) {
2087
2095
  let e = this._readBytes(8);
2088
2096
  return new DataView(e.buffer, e.byteOffset, 8).getFloat64(0, !1);
2089
2097
  }
@@ -2093,16 +2101,16 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2093
2101
  }
2094
2102
  _decodeUint(e) {
2095
2103
  if (e <= 23) return e;
2096
- if (e === mn) return this._readByte();
2097
- if (e === hn) {
2104
+ if (e === hn) return this._readByte();
2105
+ if (e === gn) {
2098
2106
  let e = this._readBytes(2);
2099
2107
  return new DataView(e.buffer, e.byteOffset, 2).getUint16(0, !1);
2100
2108
  }
2101
- if (e === gn) {
2109
+ if (e === _n) {
2102
2110
  let e = this._readBytes(4);
2103
2111
  return new DataView(e.buffer, e.byteOffset, 4).getUint32(0, !1);
2104
2112
  }
2105
- if (e === _n) {
2113
+ if (e === vn) {
2106
2114
  let e = this._readBytes(8);
2107
2115
  return Number(new DataView(e.buffer, e.byteOffset, 8).getBigUint64(0, !1));
2108
2116
  }
@@ -2118,16 +2126,16 @@ var N = new TextEncoder(), an = new TextDecoder(), P = 0, on = 1, sn = 2, F = 3,
2118
2126
  return this.offset += e, t;
2119
2127
  }
2120
2128
  };
2121
- function xn(e) {
2122
- return new yn().encode(e);
2123
- }
2124
2129
  function Sn(e) {
2125
- return new bn().decode(e);
2130
+ return new bn().encode(e);
2131
+ }
2132
+ function Cn(e) {
2133
+ return new xn().decode(e);
2126
2134
  }
2127
2135
  //#endregion
2128
2136
  //#region src/envelopeCbor.ts
2129
- var Cn = "application/7h3-cbor";
2130
- function wn(e) {
2137
+ var wn = "application/7h3-cbor";
2138
+ function Tn(e) {
2131
2139
  let t = /* @__PURE__ */ new Map();
2132
2140
  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);
2133
2141
  let n = /* @__PURE__ */ new Map();
@@ -2139,10 +2147,10 @@ function wn(e) {
2139
2147
  let e = /* @__PURE__ */ new Map();
2140
2148
  e.set(1, i.alg), e.set(2, i.keyId), e.set(3, i.value), r.set(3, e);
2141
2149
  }
2142
- return xn(r);
2150
+ return Sn(r);
2143
2151
  }
2144
- function Tn(e) {
2145
- let t = Sn(e);
2152
+ function En(e) {
2153
+ let t = Cn(e);
2146
2154
  if (!t || typeof t != "object" || Array.isArray(t)) throw Error("decodeEnvelopeCbor: expected a map at top level");
2147
2155
  let n = t, r = n[1];
2148
2156
  if (!r || typeof r != "object" || Array.isArray(r)) throw Error("decodeEnvelopeCbor: missing header map (key 1)");
@@ -2177,11 +2185,11 @@ function Tn(e) {
2177
2185
  }
2178
2186
  //#endregion
2179
2187
  //#region src/httpBinding.ts
2180
- var En = "x-7h3-envelope";
2181
- async function Dn(e, t, n) {
2188
+ var Dn = "x-7h3-envelope";
2189
+ async function On(e, t, n) {
2182
2190
  let r = t.headerName ?? "x-7h3-envelope", i = (Array.isArray(e["content-type"]) ? e["content-type"][0] : e["content-type"]) ?? "", a;
2183
2191
  if (i.includes("7h3-cbor") && n instanceof Uint8Array) try {
2184
- a = Tn(n);
2192
+ a = En(n);
2185
2193
  } catch (e) {
2186
2194
  return {
2187
2195
  ok: !1,
@@ -2237,7 +2245,7 @@ async function Dn(e, t, n) {
2237
2245
  reason: "unknown-sender",
2238
2246
  detail: a.signature.keyId
2239
2247
  };
2240
- if (!await me(a, e)) return {
2248
+ if (!await he(a, e)) return {
2241
2249
  ok: !1,
2242
2250
  reason: "invalid-signature"
2243
2251
  };
@@ -2251,24 +2259,24 @@ async function Dn(e, t, n) {
2251
2259
  envelope: a
2252
2260
  };
2253
2261
  }
2254
- async function On(e, t, n) {
2262
+ async function kn(e, t, n) {
2255
2263
  let r = await S(e, t);
2256
2264
  if (n?.format === "cbor") {
2257
- let e = wn(r);
2265
+ let e = Tn(r);
2258
2266
  return {
2259
- headers: { "content-type": Cn },
2267
+ headers: { "content-type": wn },
2260
2268
  body: e
2261
2269
  };
2262
2270
  }
2263
2271
  return { headers: { [n?.headerName ?? "x-7h3-envelope"]: JSON.stringify(r) } };
2264
2272
  }
2265
- async function kn(e, t, n, r) {
2273
+ async function An(e, t, n, r) {
2266
2274
  let i = await x(e, t, n);
2267
2275
  return { headers: { [r?.headerName ?? "x-7h3-envelope"]: JSON.stringify(i) } };
2268
2276
  }
2269
- function An(e) {
2277
+ function jn(e) {
2270
2278
  return async function(t, n, r) {
2271
- let i = await Dn(t.headers, e);
2279
+ let i = await On(t.headers, e);
2272
2280
  if (!i.ok) {
2273
2281
  n.status(401).json({
2274
2282
  error: "7h3: request verification failed",
@@ -2280,13 +2288,13 @@ function An(e) {
2280
2288
  t["7h3Envelope"] = i.envelope, r();
2281
2289
  };
2282
2290
  }
2283
- async function jn(e, t, n, r) {
2284
- let { headers: i } = await On(t, n, r), a = new Headers(e.headers);
2291
+ async function Mn(e, t, n, r) {
2292
+ let { headers: i } = await kn(t, n, r), a = new Headers(e.headers);
2285
2293
  for (let [e, t] of Object.entries(i)) a.set(e, t);
2286
2294
  return new Request(e, { headers: a });
2287
2295
  }
2288
- async function Mn(e, t) {
2289
- return jn(e, T({
2296
+ async function Nn(e, t) {
2297
+ return Mn(e, T({
2290
2298
  sender: t.sender,
2291
2299
  recipient: t.recipient,
2292
2300
  ttlMs: t.ttlMs ?? 6e4,
@@ -2296,25 +2304,25 @@ async function Mn(e, t) {
2296
2304
  }
2297
2305
  //#endregion
2298
2306
  //#region src/webhookBinding.ts
2299
- var I = "x-7h3-sig", L = "x-7h3-ts", Nn = 3e5;
2307
+ var I = "x-7h3-sig", L = "x-7h3-ts", Pn = 3e5;
2300
2308
  function R(e, t) {
2301
2309
  return `${e}.${t}`;
2302
2310
  }
2303
- async function Pn(e, t) {
2311
+ async function Fn(e, t) {
2304
2312
  let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await y(R(r, n), t.privateKey);
2305
2313
  return {
2306
2314
  [I]: i,
2307
2315
  [L]: String(r)
2308
2316
  };
2309
2317
  }
2310
- async function Fn(e, t) {
2311
- let n = typeof e == "string" ? e : new TextDecoder().decode(e), r = Date.now(), i = await de(R(r, n), t.secret);
2318
+ 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);
2312
2320
  return {
2313
2321
  [I]: i,
2314
2322
  [L]: String(r)
2315
2323
  };
2316
2324
  }
2317
- async function In(e, t, n) {
2325
+ async function Ln(e, t, n) {
2318
2326
  let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[I], a = t[L];
2319
2327
  if (!i || !a) return !1;
2320
2328
  let o = Number(a);
@@ -2322,21 +2330,21 @@ async function In(e, t, n) {
2322
2330
  let s = n.maxAgeMs ?? 3e5;
2323
2331
  return Date.now() - o > s ? !1 : b(R(o, r), i, n.publicKey);
2324
2332
  }
2325
- async function Ln(e, t, n) {
2333
+ async function Rn(e, t, n) {
2326
2334
  let r = typeof e == "string" ? e : new TextDecoder().decode(e), i = t[I], a = t[L];
2327
2335
  if (!i || !a) return !1;
2328
2336
  let o = Number(a);
2329
2337
  if (!Number.isFinite(o)) return !1;
2330
2338
  let s = n.maxAgeMs ?? 3e5;
2331
- return Date.now() - o > s ? !1 : fe(R(o, r), i, n.secret);
2339
+ return Date.now() - o > s ? !1 : pe(R(o, r), i, n.secret);
2332
2340
  }
2333
- async function Rn(e, t, n) {
2334
- if (!await In(e, t, n)) throw Error("7h3: webhook signature verification failed");
2341
+ async function zn(e, t, n) {
2342
+ if (!await Ln(e, t, n)) throw Error("7h3: webhook signature verification failed");
2335
2343
  return JSON.parse(e);
2336
2344
  }
2337
2345
  //#endregion
2338
2346
  //#region src/queueBinding.ts
2339
- async function zn(e, t) {
2347
+ async function Bn(e, t) {
2340
2348
  let n = t.ttlMs ?? 36e5, r = typeof e == "string" ? e : JSON.stringify(e), i = {
2341
2349
  envelope: await S(T({
2342
2350
  sender: t.sender,
@@ -2349,7 +2357,7 @@ async function zn(e, t) {
2349
2357
  };
2350
2358
  return JSON.stringify(i);
2351
2359
  }
2352
- async function Bn(e, t) {
2360
+ async function Vn(e, t) {
2353
2361
  let n;
2354
2362
  try {
2355
2363
  n = JSON.parse(e);
@@ -2363,10 +2371,10 @@ async function Bn(e, t) {
2363
2371
  envelope: n.envelope
2364
2372
  };
2365
2373
  }
2366
- async function Vn(e, t) {
2374
+ async function Hn(e, t) {
2367
2375
  return Promise.all(e.map(async (e) => {
2368
2376
  try {
2369
- let { payload: n, envelope: r } = await Bn(e, t);
2377
+ let { payload: n, envelope: r } = await Vn(e, t);
2370
2378
  return {
2371
2379
  ok: !0,
2372
2380
  payload: n,
@@ -2383,17 +2391,20 @@ async function Vn(e, t) {
2383
2391
  }
2384
2392
  //#endregion
2385
2393
  //#region src/stream.ts
2386
- var Hn = "x-7h3-stream", z = new TextEncoder();
2394
+ var Un = "x-7h3-stream", z = new TextEncoder();
2387
2395
  function B() {
2388
2396
  if (typeof crypto > "u" || !crypto.subtle) throw Error("Web Crypto API is not available in this runtime");
2389
2397
  return crypto.subtle;
2390
2398
  }
2399
+ function Wn() {
2400
+ return globalThis.Buffer;
2401
+ }
2391
2402
  function V(e) {
2392
- let t = globalThis.Buffer;
2403
+ let t = Wn();
2393
2404
  return (t ? t.from(e).toString("base64") : btoa(String.fromCharCode(...e))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
2394
2405
  }
2395
2406
  function H(e) {
2396
- let t = e.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(e.length / 4) * 4, "="), n = globalThis.Buffer;
2407
+ let t = e.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(e.length / 4) * 4, "="), n = Wn();
2397
2408
  if (n) return new Uint8Array(n.from(t, "base64"));
2398
2409
  let r = atob(t), i = new Uint8Array(r.length);
2399
2410
  for (let e = 0; e < r.length; e++) i[e] = r.charCodeAt(e);
@@ -2402,15 +2413,15 @@ function H(e) {
2402
2413
  function U(e) {
2403
2414
  return e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
2404
2415
  }
2405
- function Un() {
2416
+ function Gn() {
2406
2417
  let e = new Uint8Array(16);
2407
2418
  return crypto.getRandomValues(e), V(e);
2408
2419
  }
2409
- var W = /* @__PURE__ */ new Map(), Wn = 128;
2410
- function Gn(e, t) {
2420
+ var W = /* @__PURE__ */ new Map(), Kn = 128;
2421
+ function qn(e, t) {
2411
2422
  let n = `${e}:${t}`, r = W.get(n);
2412
2423
  if (r) return r;
2413
- W.size >= Wn && W.clear();
2424
+ W.size >= Kn && W.clear();
2414
2425
  let i = B(), a = H(e), o = (async () => {
2415
2426
  let e = await i.importKey("raw", U(a), "HKDF", !1, ["deriveBits"]), n = await i.deriveBits({
2416
2427
  name: "HKDF",
@@ -2425,31 +2436,31 @@ function Gn(e, t) {
2425
2436
  })();
2426
2437
  return o.catch(() => W.delete(n)), W.set(n, o), o;
2427
2438
  }
2428
- var G = /* @__PURE__ */ new Map(), Kn = 64;
2429
- function qn(e) {
2439
+ var G = /* @__PURE__ */ new Map(), Jn = 64;
2440
+ function Yn(e) {
2430
2441
  let t = G.get(e);
2431
2442
  if (t) return t;
2432
- G.size >= Kn && G.clear();
2443
+ G.size >= Jn && G.clear();
2433
2444
  let n = B().importKey("pkcs8", U(H(e)), { name: "Ed25519" }, !1, ["sign"]).catch((t) => {
2434
2445
  throw G.delete(e), t;
2435
2446
  });
2436
2447
  return G.set(e, n), n;
2437
2448
  }
2438
- var K = /* @__PURE__ */ new Map(), Jn = 64;
2439
- function Yn(e) {
2449
+ var K = /* @__PURE__ */ new Map(), Xn = 64;
2450
+ function Zn(e) {
2440
2451
  let t = K.get(e);
2441
2452
  if (t) return t;
2442
- K.size >= Jn && K.clear();
2453
+ K.size >= Xn && K.clear();
2443
2454
  let n = B().importKey("spki", U(H(e)), { name: "Ed25519" }, !1, ["verify"]).catch((t) => {
2444
2455
  throw K.delete(e), t;
2445
2456
  });
2446
2457
  return K.set(e, n), n;
2447
2458
  }
2448
- function Xn(e) {
2459
+ function Qn(e) {
2449
2460
  let t = e.map((e) => `${e.i}:${e.d}`);
2450
2461
  return z.encode(t.join("\n"));
2451
2462
  }
2452
- async function Zn(e) {
2463
+ async function $n(e) {
2453
2464
  let t = await B().digest("SHA-256", U(e));
2454
2465
  return new Uint8Array(t);
2455
2466
  }
@@ -2460,7 +2471,7 @@ var q = class {
2460
2471
  hmacKeyPromise = null;
2461
2472
  constructor(e) {
2462
2473
  this.opts = {
2463
- nonce: e.nonce ?? Un(),
2474
+ nonce: e.nonce ?? Gn(),
2464
2475
  keyId: e.keyId ?? "stream-key",
2465
2476
  ...e
2466
2477
  };
@@ -2469,7 +2480,7 @@ var q = class {
2469
2480
  return this.opts.nonce;
2470
2481
  }
2471
2482
  getHmacKey() {
2472
- return this.hmacKeyPromise ||= Gn(this.opts.privateKey, this.opts.nonce), this.hmacKeyPromise;
2483
+ return this.hmacKeyPromise ||= qn(this.opts.privateKey, this.opts.nonce), this.hmacKeyPromise;
2473
2484
  }
2474
2485
  async computeChunkHmac(e, t) {
2475
2486
  let n = B(), r = await this.getHmacKey(), i = `${this.opts.nonce}:${e}:${t}`, a = await n.sign("HMAC", r, z.encode(i));
@@ -2488,7 +2499,7 @@ var q = class {
2488
2499
  };
2489
2500
  }
2490
2501
  async finalize() {
2491
- let e = B(), t = await qn(this.opts.privateKey), n = await Zn(Xn(this.accum)), r = await e.sign("Ed25519", t, U(n)), i = V(new Uint8Array(r)), a = this.seq;
2502
+ let e = B(), t = await Yn(this.opts.privateKey), n = await $n(Qn(this.accum)), r = await e.sign("Ed25519", t, U(n)), i = V(new Uint8Array(r)), a = this.seq;
2492
2503
  return {
2493
2504
  i: a,
2494
2505
  d: "",
@@ -2498,7 +2509,7 @@ var q = class {
2498
2509
  kid: this.opts.keyId
2499
2510
  };
2500
2511
  }
2501
- }, Qn = class {
2512
+ }, er = class {
2502
2513
  opts;
2503
2514
  expectedSeq = 0;
2504
2515
  accum = [];
@@ -2535,14 +2546,14 @@ var q = class {
2535
2546
  };
2536
2547
  let t = B(), n;
2537
2548
  try {
2538
- n = await Yn(this.opts.publicKey);
2549
+ n = await Zn(this.opts.publicKey);
2539
2550
  } catch {
2540
2551
  return {
2541
2552
  ok: !1,
2542
2553
  reason: "invalid public key"
2543
2554
  };
2544
2555
  }
2545
- let r = await Zn(Xn(this.accum)), i = H(e.sig);
2556
+ let r = await $n(Qn(this.accum)), i = H(e.sig);
2546
2557
  return await t.verify("Ed25519", n, U(i), U(r)) ? {
2547
2558
  ok: !0,
2548
2559
  totalBytes: this.totalBytes,
@@ -2553,20 +2564,20 @@ var q = class {
2553
2564
  };
2554
2565
  }
2555
2566
  };
2556
- function $n(e) {
2567
+ function tr(e) {
2557
2568
  return new q(e);
2558
2569
  }
2559
- function er(e) {
2560
- return new Qn(e);
2570
+ function nr(e) {
2571
+ return new er(e);
2561
2572
  }
2562
- async function tr(e, t) {
2573
+ async function rr(e, t) {
2563
2574
  let n = new q(t), r = [];
2564
2575
  if (Array.isArray(e)) for (let t of e) r.push(await n.writeChunk(t));
2565
2576
  else for await (let t of e) r.push(await n.writeChunk(t));
2566
2577
  return r.push(await n.finalize()), r;
2567
2578
  }
2568
- async function nr(e, t) {
2569
- let n = new Qn(t), r = e.slice(0, -1), i = e[e.length - 1];
2579
+ async function ir(e, t) {
2580
+ let n = new er(t), r = e.slice(0, -1), i = e[e.length - 1];
2570
2581
  if (e.length === 0) return {
2571
2582
  ok: !1,
2572
2583
  reason: "empty chunk array — missing final frame"
@@ -2592,10 +2603,10 @@ async function nr(e, t) {
2592
2603
  }
2593
2604
  return n.finalize(i);
2594
2605
  }
2595
- function rr(e) {
2606
+ function ar(e) {
2596
2607
  return JSON.stringify(e);
2597
2608
  }
2598
- function ir(e) {
2609
+ function or(e) {
2599
2610
  let t;
2600
2611
  try {
2601
2612
  t = JSON.parse(e);
@@ -2622,7 +2633,7 @@ function ir(e) {
2622
2633
  }
2623
2634
  //#endregion
2624
2635
  //#region src/wsBinding.ts
2625
- function ar(e, t) {
2636
+ function sr(e, t) {
2626
2637
  let n = 0, r = [], i = [];
2627
2638
  function a(e, n) {
2628
2639
  t.onVerifyFail?.(e, n);
@@ -2668,16 +2679,15 @@ function ar(e, t) {
2668
2679
  return n;
2669
2680
  },
2670
2681
  async send(r) {
2671
- let i = typeof r == "string" ? r : JSON.stringify(r), a = T({
2682
+ let i = typeof r == "string" ? r : JSON.stringify(r), a = await S(T({
2672
2683
  sender: t.sender,
2673
2684
  recipient: t.recipient,
2674
2685
  ttlMs: t.ttlMs ?? 3e4,
2675
2686
  intent: "TASK",
2676
- content: i
2677
- });
2678
- a.body.correlationId = String(++n);
2679
- let o = await S(a, t.privateKey);
2680
- e.send(JSON.stringify(o));
2687
+ content: i,
2688
+ correlationId: String(++n)
2689
+ }), t.privateKey);
2690
+ e.send(JSON.stringify(a));
2681
2691
  },
2682
2692
  onMessage(e) {
2683
2693
  r.push(e);
@@ -2687,28 +2697,28 @@ function ar(e, t) {
2687
2697
  }
2688
2698
  };
2689
2699
  }
2690
- function or(e, t) {
2700
+ function cr(e, t) {
2691
2701
  let n = new q(t), r = async (t) => {
2692
2702
  let r = typeof t.data == "string" ? t.data : t.data.toString("utf8"), i = await n.writeChunk(r);
2693
- e.send(rr(i));
2703
+ e.send(ar(i));
2694
2704
  }, i = async () => {
2695
2705
  e.removeEventListener("message", r), e.removeEventListener("close", i);
2696
2706
  let t = await n.finalize();
2697
- e.send(rr(t));
2707
+ e.send(ar(t));
2698
2708
  };
2699
2709
  return e.addEventListener("message", r), e.addEventListener("close", i), n;
2700
2710
  }
2701
- function sr(e, t) {
2711
+ function lr(e, t) {
2702
2712
  return new Promise((n, r) => {
2703
2713
  let i = [], a = async (e) => {
2704
2714
  let a = typeof e.data == "string" ? e.data : e.data.toString("utf8"), o;
2705
2715
  try {
2706
- o = ir(a);
2716
+ o = or(a);
2707
2717
  } catch (e) {
2708
2718
  s(), r(e);
2709
2719
  return;
2710
2720
  }
2711
- i.push(o), o.f && (s(), n(await nr(i, t)));
2721
+ i.push(o), o.f && (s(), n(await ir(i, t)));
2712
2722
  }, o = () => {
2713
2723
  s(), n({
2714
2724
  ok: !1,
@@ -2723,8 +2733,8 @@ function sr(e, t) {
2723
2733
  }
2724
2734
  //#endregion
2725
2735
  //#region src/grpcBinding.ts
2726
- var cr = "7h3-envelope-bin";
2727
- async function lr(e) {
2736
+ var ur = "7h3-envelope-bin";
2737
+ async function dr(e) {
2728
2738
  let t = await S(T({
2729
2739
  sender: e.sender,
2730
2740
  recipient: e.recipient,
@@ -2734,7 +2744,7 @@ async function lr(e) {
2734
2744
  }), e.privateKey);
2735
2745
  return { [e.metadataKey ?? "7h3-envelope-bin"]: JSON.stringify(t) };
2736
2746
  }
2737
- async function ur(e, t) {
2747
+ async function fr(e, t) {
2738
2748
  let n = e[t.metadataKey ?? "7h3-envelope-bin"], r = Array.isArray(n) ? n[0] : n instanceof Uint8Array ? new TextDecoder().decode(n) : n;
2739
2749
  if (!r) return {
2740
2750
  ok: !1,
@@ -2781,7 +2791,7 @@ async function ur(e, t) {
2781
2791
  code: 16,
2782
2792
  message: "7h3: unknown key"
2783
2793
  };
2784
- if (!await me(i, e)) return {
2794
+ if (!await he(i, e)) return {
2785
2795
  ok: !1,
2786
2796
  code: 16,
2787
2797
  message: "7h3: invalid signature"
@@ -2796,39 +2806,39 @@ async function ur(e, t) {
2796
2806
  envelope: i
2797
2807
  };
2798
2808
  }
2799
- function dr(e, t) {
2809
+ function pr(e, t) {
2800
2810
  return async (n) => {
2801
- let r = await ur(n.metadata, t);
2811
+ let r = await fr(n.metadata, t);
2802
2812
  if (!r.ok) throw Object.assign(Error(r.message), { code: r.code });
2803
2813
  return n["7h3Envelope"] = r.envelope, e(n);
2804
2814
  };
2805
2815
  }
2806
2816
  //#endregion
2807
2817
  //#region src/keyInfra.ts
2808
- function fr(e) {
2818
+ function mr(e) {
2809
2819
  return JSON.stringify(e);
2810
2820
  }
2811
- function pr(e) {
2821
+ function hr(e) {
2812
2822
  let t = JSON.parse(e);
2813
2823
  if (t.version !== "7h3/0.1") throw Error(`unsupported version: ${t.version}`);
2814
2824
  return t;
2815
2825
  }
2816
- async function mr(e, t) {
2826
+ async function gr(e, t) {
2817
2827
  let n = e.replace(/\/$/, "") + "/.well-known/7h3-keys", r = new AbortController(), i = t?.timeout ? setTimeout(() => r.abort(), t.timeout) : void 0;
2818
2828
  try {
2819
2829
  let e = await fetch(n, { signal: r.signal });
2820
2830
  if (!e.ok) throw Error(`HTTP ${e.status} from ${n}`);
2821
- return pr(await e.text());
2831
+ return hr(await e.text());
2822
2832
  } finally {
2823
2833
  i !== void 0 && clearTimeout(i);
2824
2834
  }
2825
2835
  }
2826
- function hr(e) {
2836
+ function _r(e) {
2827
2837
  let t = /* @__PURE__ */ new Map(), n = e?.cacheMs ?? 6e4, r = e?.timeout ?? 5e3;
2828
2838
  async function i(e) {
2829
2839
  let i = Date.now(), a = t.get(e);
2830
2840
  if (a && a.expiresAt > i) return a.doc;
2831
- let o = await mr(e, { timeout: r });
2841
+ let o = await gr(e, { timeout: r });
2832
2842
  return t.set(e, {
2833
2843
  doc: o,
2834
2844
  expiresAt: i + n
@@ -2845,7 +2855,7 @@ function hr(e) {
2845
2855
  }
2846
2856
  } };
2847
2857
  }
2848
- var gr = class {
2858
+ var vr = class {
2849
2859
  maxAgeMs;
2850
2860
  overlapMs;
2851
2861
  keys = [];
@@ -2863,8 +2873,8 @@ var gr = class {
2863
2873
  let e = Date.now(), t = this.getCurrentKey();
2864
2874
  if (t && e - t.createdAt < this.maxAgeMs - this.overlapMs) return null;
2865
2875
  t && !t.expiresAt && (t.expiresAt = e + this.overlapMs);
2866
- let { publicKey: n, privateKey: r } = await pe(), i = {
2867
- id: `key-${e}-${Math.random().toString(36).slice(2, 8)}`,
2876
+ let { publicKey: n, privateKey: r } = await me(), i = {
2877
+ id: `key-${e}-${v(4)}`,
2868
2878
  publicKey: n,
2869
2879
  privateKey: r,
2870
2880
  createdAt: e
@@ -2895,7 +2905,7 @@ var gr = class {
2895
2905
  return this.keys.find((n) => n.id === e && (!n.expiresAt || n.expiresAt > t))?.publicKey ?? this.getCurrentKey()?.publicKey ?? null;
2896
2906
  } };
2897
2907
  }
2898
- }, _r = class {
2908
+ }, yr = class {
2899
2909
  revoked = /* @__PURE__ */ new Map();
2900
2910
  revoke(e, t) {
2901
2911
  this.revoked.set(e, {
@@ -2918,15 +2928,12 @@ var gr = class {
2918
2928
  for (let t of e.revokedKeys) this.revoked.has(t.id) || this.revoked.set(t.id, t);
2919
2929
  }
2920
2930
  wrapRegistry(e) {
2921
- let t = this;
2922
2931
  return {
2923
- async getPublicKey(n) {
2924
- return t.isRevoked(n) ? null : e.getPublicKey(n);
2925
- },
2932
+ getPublicKey: async (t) => this.isRevoked(t) ? null : e.getPublicKey(t),
2926
2933
  getSharedSecret: e.getSharedSecret?.bind(e)
2927
2934
  };
2928
2935
  }
2929
- }, vr = class {
2936
+ }, br = class {
2930
2937
  windows = /* @__PURE__ */ new Map();
2931
2938
  check(e, t, n = Date.now()) {
2932
2939
  let r = n - t.windowMs, i = (this.windows.get(e) ?? []).filter((e) => e > r), a = i.length, o = a < t.requests;
@@ -2950,7 +2957,7 @@ var gr = class {
2950
2957
  clear() {
2951
2958
  this.windows.clear();
2952
2959
  }
2953
- }, yr = new vr();
2960
+ }, xr = new br();
2954
2961
  //#endregion
2955
2962
  //#region src/routePolicy.ts
2956
2963
  function J(e, t) {
@@ -2961,17 +2968,17 @@ function J(e, t) {
2961
2968
  }
2962
2969
  return n += "$", new RegExp(n).test(t);
2963
2970
  }
2964
- function br(e, t) {
2971
+ function Sr(e, t) {
2965
2972
  for (let n of e) if (J(n.path, t)) return n;
2966
2973
  return null;
2967
2974
  }
2968
- function xr(e, t) {
2975
+ function Cr(e, t) {
2969
2976
  return !e.allowedSenders || e.allowedSenders.length === 0 ? !0 : e.allowedSenders.includes(t);
2970
2977
  }
2971
2978
  //#endregion
2972
2979
  //#region src/signedResponse.ts
2973
- var Sr = "x-7h3-response";
2974
- async function Cr(e, t) {
2980
+ var wr = "x-7h3-response";
2981
+ async function Tr(e, t) {
2975
2982
  let n = await S(T({
2976
2983
  sender: t.sender,
2977
2984
  recipient: t.recipient,
@@ -2980,10 +2987,10 @@ async function Cr(e, t) {
2980
2987
  correlationId: t.correlationId,
2981
2988
  ttlMs: t.ttlMs ?? 6e4
2982
2989
  }), t.privateKey);
2983
- return { headers: { [Sr]: JSON.stringify(n) } };
2990
+ return { headers: { [wr]: JSON.stringify(n) } };
2984
2991
  }
2985
- async function wr(e, t, n) {
2986
- let r = t[Sr], i = Array.isArray(r) ? r[0] : r;
2992
+ async function Er(e, t, n) {
2993
+ let r = t[wr], i = Array.isArray(r) ? r[0] : r;
2987
2994
  if (!i) return {
2988
2995
  ok: !1,
2989
2996
  reason: "missing-header"
@@ -3020,7 +3027,7 @@ async function wr(e, t, n) {
3020
3027
  function Y(e) {
3021
3028
  return !e || Object.keys(e).length === 0 ? "__default__" : Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}=${t}`).join(",");
3022
3029
  }
3023
- function Tr(e) {
3030
+ function Dr(e) {
3024
3031
  return !e || Object.keys(e).length === 0 ? "" : `{${Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}="${t}"`).join(",")}}`;
3025
3032
  }
3026
3033
  var X = class {
@@ -3041,7 +3048,7 @@ var X = class {
3041
3048
  });
3042
3049
  return e;
3043
3050
  }
3044
- }, Er = class {
3051
+ }, Or = class {
3045
3052
  bucketBounds;
3046
3053
  states = /* @__PURE__ */ new Map();
3047
3054
  labelSets = /* @__PURE__ */ new Map();
@@ -3097,9 +3104,9 @@ var X = class {
3097
3104
  getBounds() {
3098
3105
  return [...this.bucketBounds];
3099
3106
  }
3100
- }, Dr = class {
3107
+ }, kr = class {
3101
3108
  verifications_total = new X();
3102
- verification_duration_ms = new Er([
3109
+ verification_duration_ms = new Or([
3103
3110
  .1,
3104
3111
  .5,
3105
3112
  1,
@@ -3113,15 +3120,15 @@ var X = class {
3113
3120
  replay_detections_total = new X();
3114
3121
  audit_entries_total = new X();
3115
3122
  active_connections = new X();
3116
- }, Z = new Dr();
3117
- function Or(e, t = "7h3") {
3123
+ }, Z = new kr();
3124
+ function Ar(e, t = "7h3") {
3118
3125
  let n = [];
3119
3126
  function r(e, r, i) {
3120
3127
  let a = `${t}_${e}`;
3121
3128
  n.push(`# HELP ${a} ${r}`), n.push(`# TYPE ${a} counter`);
3122
3129
  let o = i.entries();
3123
3130
  if (o.length === 0) n.push(`${a} 0`);
3124
- else for (let { labels: e, value: t } of o) e && Object.keys(e).length > 0 ? n.push(`${a}${Tr(e)} ${t}`) : n.push(`${a} ${t}`);
3131
+ else for (let { labels: e, value: t } of o) e && Object.keys(e).length > 0 ? n.push(`${a}${Dr(e)} ${t}`) : n.push(`${a} ${t}`);
3125
3132
  }
3126
3133
  function i(e, r, i) {
3127
3134
  let a = `${t}_${e}`;
@@ -3131,7 +3138,7 @@ function Or(e, t = "7h3") {
3131
3138
  for (let e of i.getBounds()) n.push(`${a}_bucket{le="${e}"} 0`);
3132
3139
  n.push(`${a}_bucket{le="+Inf"} 0`), n.push(`${a}_sum 0`), n.push(`${a}_count 0`);
3133
3140
  } else for (let { labels: e, snapshot: t } of o) {
3134
- let r = e && Object.keys(e).length > 0 ? Tr(e) : "";
3141
+ let r = e && Object.keys(e).length > 0 ? Dr(e) : "";
3135
3142
  for (let [e, i] of Object.entries(t.buckets)) {
3136
3143
  if (e === "+Inf") continue;
3137
3144
  let t = r ? r.slice(0, -1) + `,le="${e}"}` : `{le="${e}"}`;
@@ -3143,29 +3150,29 @@ function Or(e, t = "7h3") {
3143
3150
  }
3144
3151
  return r("verifications_total", "Total number of AIP envelope verifications, by result, algorithm, and transport", e.verifications_total), i("verification_duration_ms", "Verification latency in milliseconds", e.verification_duration_ms), r("rate_limit_hits_total", "Total number of rate-limit rejections, by sender and path", e.rate_limit_hits_total), r("sender_denials_total", "Total number of sender-denied (403) rejections, by sender and path", e.sender_denials_total), r("replay_detections_total", "Total number of replay-detected events, by transport", e.replay_detections_total), r("audit_entries_total", "Total number of audit log entries written, by type", e.audit_entries_total), r("active_connections", "Current active connections, by transport (WS/gRPC)", e.active_connections), n.join("\n") + "\n";
3145
3152
  }
3146
- function kr(e = "/metrics", t = Z, n = "7h3") {
3153
+ function jr(e = "/metrics", t = Z, n = "7h3") {
3147
3154
  return (r, i, a) => {
3148
3155
  if (r.url === e && (r.method === "GET" || r.method === void 0)) {
3149
- let e = Or(t, n);
3156
+ let e = Ar(t, n);
3150
3157
  i.writeHead(200, { "content-type": "text/plain; version=0.0.4; charset=utf-8" }), i.end(e);
3151
3158
  } else a();
3152
3159
  };
3153
3160
  }
3154
3161
  //#endregion
3155
3162
  //#region src/capability.ts
3156
- var Ar = "x-7h3-capability";
3157
- function jr(e) {
3163
+ var Mr = "x-7h3-capability";
3164
+ function Nr(e) {
3158
3165
  let t = [];
3159
3166
  return e.maxDelegations !== void 0 && t.push(`"maxDelegations":${e.maxDelegations}`), e.methods !== void 0 && t.push(`"methods":${JSON.stringify(e.methods)}`), t.push(`"pathGlob":${JSON.stringify(e.pathGlob)}`), `{${t.join(",")}}`;
3160
3167
  }
3161
3168
  function Q(e) {
3162
3169
  let t = [];
3163
3170
  t.push(`"delegationDepth":${e.delegationDepth}`), t.push(`"expiresAt":${e.expiresAt}`), t.push(`"id":${JSON.stringify(e.id)}`), t.push(`"issuedAt":${e.issuedAt}`), t.push(`"issuer":${JSON.stringify(e.issuer)}`), t.push(`"keyId":${JSON.stringify(e.keyId)}`), e.maxDelegations !== void 0 && t.push(`"maxDelegations":${e.maxDelegations}`), e.parentTokenId !== void 0 && t.push(`"parentTokenId":${JSON.stringify(e.parentTokenId)}`);
3164
- let n = `[${e.scopes.map(jr).join(",")}]`;
3171
+ let n = `[${e.scopes.map(Nr).join(",")}]`;
3165
3172
  return t.push(`"scopes":${n}`), t.push(`"subject":${JSON.stringify(e.subject)}`), t.push(`"version":${JSON.stringify(e.version)}`), `{${t.join(",")}}`;
3166
3173
  }
3167
- async function Mr(e) {
3168
- let t = Date.now(), n = `cap-${t}-${Math.random().toString(36).slice(2, 12)}`, r = e.keyId ?? `${e.issuerId}-key`, i = e.maxDelegations ?? 0, a = {
3174
+ 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 = {
3169
3176
  id: n,
3170
3177
  version: "7h3-cap/1",
3171
3178
  issuer: e.issuerId,
@@ -3182,7 +3189,7 @@ async function Mr(e) {
3182
3189
  signature: o
3183
3190
  };
3184
3191
  }
3185
- function Nr(e, t) {
3192
+ function Fr(e, t) {
3186
3193
  if (!J(t.pathGlob, e.pathGlob)) return !1;
3187
3194
  if (t.methods !== void 0) {
3188
3195
  if (e.methods === void 0) return !1;
@@ -3190,21 +3197,21 @@ function Nr(e, t) {
3190
3197
  }
3191
3198
  return !0;
3192
3199
  }
3193
- function Pr(e, t) {
3194
- for (let n of e) if (!t.some((e) => Nr(n, e))) return !1;
3200
+ function Ir(e, t) {
3201
+ for (let n of e) if (!t.some((e) => Fr(n, e))) return !1;
3195
3202
  return !0;
3196
3203
  }
3197
- async function Fr(e) {
3204
+ async function Lr(e) {
3198
3205
  let { parentToken: t, delegatorId: n, newSubject: r } = e;
3199
3206
  if (n !== t.subject) throw Error(`delegatorId '${n}' does not match parentToken.subject '${t.subject}'`);
3200
3207
  let i = Date.now();
3201
3208
  if (i >= t.expiresAt) throw Error("Parent token is expired");
3202
3209
  if (t.maxDelegations !== void 0 && t.maxDelegations <= 0) throw Error("Parent token does not allow further delegation (maxDelegations=0)");
3203
3210
  let a = e.scopes ?? t.scopes;
3204
- if (!Pr(a, t.scopes)) throw Error("Delegated scopes exceed parent token scopes");
3211
+ if (!Ir(a, t.scopes)) throw Error("Delegated scopes exceed parent token scopes");
3205
3212
  let o = t.expiresAt - i;
3206
3213
  if (e.ttlMs > o) throw Error(`Delegated ttlMs (${e.ttlMs}) exceeds parent token remaining TTL (${o})`);
3207
- let s = `cap-${i}-${Math.random().toString(36).slice(2, 12)}`, c = e.keyId ?? `${n}-key`, l = t.maxDelegations === void 0 ? void 0 : t.maxDelegations - 1, u = {
3214
+ let s = `cap-${i}-${v(6)}`, c = e.keyId ?? `${n}-key`, l = t.maxDelegations === void 0 ? void 0 : t.maxDelegations - 1, u = {
3208
3215
  id: s,
3209
3216
  version: "7h3-cap/1",
3210
3217
  issuer: n,
@@ -3222,12 +3229,12 @@ async function Fr(e) {
3222
3229
  signature: d
3223
3230
  };
3224
3231
  }
3225
- async function Ir(e, t, n) {
3232
+ async function Rr(e, t, n) {
3226
3233
  if ((n?.now ?? Date.now()) >= e.expiresAt) return !1;
3227
3234
  let { signature: r, ...i } = e;
3228
3235
  return b(Q(i), r, t);
3229
3236
  }
3230
- async function Lr(e, t, n) {
3237
+ async function zr(e, t, n) {
3231
3238
  if (e.length === 0) return {
3232
3239
  ok: !1,
3233
3240
  reason: "empty-chain"
@@ -3270,7 +3277,7 @@ async function Lr(e, t, n) {
3270
3277
  };
3271
3278
  }
3272
3279
  let i = e[e.length - 1];
3273
- return n?.requiredPathGlob !== void 0 && !Rr(i, n.requiredPathGlob, n.requiredMethod) ? {
3280
+ return n?.requiredPathGlob !== void 0 && !Br(i, n.requiredPathGlob, n.requiredMethod) ? {
3274
3281
  ok: !1,
3275
3282
  reason: "leaf-token-does-not-cover-required-scope"
3276
3283
  } : {
@@ -3279,26 +3286,26 @@ async function Lr(e, t, n) {
3279
3286
  chain: e
3280
3287
  };
3281
3288
  }
3282
- function Rr(e, t, n) {
3289
+ function Br(e, t, n) {
3283
3290
  for (let r of e.scopes) if (J(r.pathGlob, t) && (r.methods === void 0 || n === void 0 || r.methods.includes(n.toUpperCase()))) return !0;
3284
3291
  return !1;
3285
3292
  }
3286
- function zr(e) {
3293
+ function Vr(e) {
3287
3294
  return JSON.stringify(e);
3288
3295
  }
3289
- function Br(e) {
3296
+ function Hr(e) {
3290
3297
  return JSON.parse(e);
3291
3298
  }
3292
3299
  //#endregion
3293
3300
  //#region src/gateway.ts
3294
- var Vr = class {
3301
+ var Ur = class {
3295
3302
  config;
3296
3303
  rateLimiter;
3297
3304
  constructor(e) {
3298
- this.config = e, this.rateLimiter = new vr();
3305
+ this.config = e, this.rateLimiter = new br();
3299
3306
  }
3300
3307
  async verify(e) {
3301
- let t = performance.now(), n = br(this.config.policies ?? [], e.path);
3308
+ let t = performance.now(), n = Sr(this.config.policies ?? [], e.path);
3302
3309
  if (n?.require === "none" || !n && (this.config.defaultPolicy ?? "allow") === "allow") {
3303
3310
  let e = performance.now() - t;
3304
3311
  return Z.verifications_total.increment({
@@ -3311,13 +3318,13 @@ var Vr = class {
3311
3318
  };
3312
3319
  }
3313
3320
  if (this.config.capabilityRegistry) {
3314
- let n = e.headers[Ar], r = Array.isArray(n) ? n[0] : n;
3321
+ let n = e.headers[Mr], r = Array.isArray(n) ? n[0] : n;
3315
3322
  if (r) try {
3316
- let n = await Lr(Br(r), this.config.capabilityRegistry, {
3323
+ let n = await zr(Hr(r), this.config.capabilityRegistry, {
3317
3324
  requiredPathGlob: e.path,
3318
3325
  requiredMethod: e.method
3319
3326
  });
3320
- if (n.ok && Rr(n.token, e.path, e.method)) {
3327
+ if (n.ok && Br(n.token, e.path, e.method)) {
3321
3328
  let e = performance.now() - t;
3322
3329
  return Z.verifications_total.increment({
3323
3330
  result: "ok",
@@ -3366,7 +3373,7 @@ var Vr = class {
3366
3373
  reason: "no-matching-policy"
3367
3374
  };
3368
3375
  }
3369
- let r = await Dn(e.headers, {
3376
+ let r = await On(e.headers, {
3370
3377
  keyRegistry: this.config.keyRegistry,
3371
3378
  headerName: this.config.headerName
3372
3379
  });
@@ -3403,7 +3410,7 @@ var Vr = class {
3403
3410
  };
3404
3411
  }
3405
3412
  }
3406
- if (n && !xr(n, a)) {
3413
+ if (n && !Cr(n, a)) {
3407
3414
  let n = performance.now() - t;
3408
3415
  return Z.verifications_total.increment({
3409
3416
  result: "fail",
@@ -3460,7 +3467,7 @@ var Vr = class {
3460
3467
  body: e.body
3461
3468
  }), a = await i.text(), o = { "content-type": i.headers.get("content-type") ?? "application/json" };
3462
3469
  if (this.config.privateKey !== void 0 && (this.config.signResponses ?? !0) && this.config.sender !== void 0) {
3463
- let e = await Cr(a, {
3470
+ let e = await Tr(a, {
3464
3471
  privateKey: this.config.privateKey,
3465
3472
  sender: this.config.sender,
3466
3473
  recipient: t.sender || void 0
@@ -3477,12 +3484,12 @@ var Vr = class {
3477
3484
  return this.rateLimiter;
3478
3485
  }
3479
3486
  };
3480
- function Hr(e) {
3481
- return new Vr(e);
3487
+ function Wr(e) {
3488
+ return new Ur(e);
3482
3489
  }
3483
3490
  //#endregion
3484
3491
  //#region src/auditLog.ts
3485
- function Ur(e) {
3492
+ function Gr(e) {
3486
3493
  let t = [
3487
3494
  `"id":${JSON.stringify(e.id)}`,
3488
3495
  `"timestampMs":${e.timestampMs}`,
@@ -3490,7 +3497,7 @@ function Ur(e) {
3490
3497
  ];
3491
3498
  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(",")}}`;
3492
3499
  }
3493
- var Wr = class {
3500
+ var Kr = class {
3494
3501
  entries = [];
3495
3502
  privateKey;
3496
3503
  maxEntries;
@@ -3499,10 +3506,10 @@ var Wr = class {
3499
3506
  }
3500
3507
  async log(e) {
3501
3508
  let t = {
3502
- id: `audit-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
3509
+ id: `audit-${Date.now()}-${v(5)}`,
3503
3510
  timestampMs: Date.now(),
3504
3511
  ...e
3505
- }, n = await y(Ur(t), this.privateKey), r = {
3512
+ }, n = await y(Gr(t), this.privateKey), r = {
3506
3513
  ...t,
3507
3514
  entrySignature: n
3508
3515
  };
@@ -3513,7 +3520,7 @@ var Wr = class {
3513
3520
  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;
3514
3521
  }
3515
3522
  async verify(e, t) {
3516
- return b(Ur({
3523
+ return b(Gr({
3517
3524
  id: e.id,
3518
3525
  timestampMs: e.timestampMs,
3519
3526
  type: e.type,
@@ -3529,7 +3536,7 @@ var Wr = class {
3529
3536
  size() {
3530
3537
  return this.entries.length;
3531
3538
  }
3532
- }, Gr = class {
3539
+ }, qr = class {
3533
3540
  async log(e) {}
3534
3541
  async query(e) {
3535
3542
  return [];
@@ -3541,25 +3548,25 @@ var Wr = class {
3541
3548
  return 0;
3542
3549
  }
3543
3550
  };
3544
- function Kr(e, t) {
3545
- return new Wr(e, t?.maxEntries);
3551
+ function Jr(e, t) {
3552
+ return new Kr(e, t?.maxEntries);
3546
3553
  }
3547
3554
  //#endregion
3548
3555
  //#region src/otel.ts
3549
- var qr = null;
3550
- function Jr(e) {
3551
- qr = e;
3556
+ var Yr = null;
3557
+ function Xr(e) {
3558
+ Yr = e;
3552
3559
  }
3553
- function Yr() {
3554
- if (qr === null) return null;
3560
+ function Zr() {
3561
+ if (Yr === null) return null;
3555
3562
  try {
3556
- return qr.getTracer("7h3/protocol");
3563
+ return Yr.getTracer("7h3/protocol");
3557
3564
  } catch {
3558
3565
  return null;
3559
3566
  }
3560
3567
  }
3561
- async function Xr(e, t) {
3562
- let n = Yr();
3568
+ async function Qr(e, t) {
3569
+ let n = Zr();
3563
3570
  if (n === null) return e(null);
3564
3571
  let r = n.startSpan("7h3.verify", t);
3565
3572
  try {
@@ -3570,8 +3577,8 @@ async function Xr(e, t) {
3570
3577
  r.end();
3571
3578
  }
3572
3579
  }
3573
- async function Zr(e) {
3574
- let t = Yr();
3580
+ async function $r(e) {
3581
+ let t = Zr();
3575
3582
  if (t === null) return e(null);
3576
3583
  let n = t.startSpan("7h3.audit.write");
3577
3584
  try {
@@ -3584,63 +3591,63 @@ async function Zr(e) {
3584
3591
  }
3585
3592
  //#endregion
3586
3593
  //#region src/encryption.ts
3587
- function Qr(e) {
3594
+ function ei(e) {
3588
3595
  return Buffer.from(e).toString("base64url");
3589
3596
  }
3590
3597
  function $(e) {
3591
3598
  return Buffer.from(e, "base64url");
3592
3599
  }
3593
- var $r = Buffer.from("302e020100300506032b656e04220420", "hex"), ei = Buffer.from("302a300506032b656e032100", "hex");
3594
- function ti(e) {
3600
+ var ti = Buffer.from("302e020100300506032b656e04220420", "hex"), ni = Buffer.from("302a300506032b656e032100", "hex");
3601
+ function ri(e) {
3595
3602
  let t = $(e);
3596
3603
  return (0, M.createPrivateKey)({
3597
- key: Buffer.concat([$r, t]),
3604
+ key: Buffer.concat([ti, t]),
3598
3605
  format: "der",
3599
3606
  type: "pkcs8"
3600
3607
  });
3601
3608
  }
3602
- function ni(e) {
3609
+ function ii(e) {
3603
3610
  let t = $(e);
3604
3611
  return (0, M.createPublicKey)({
3605
- key: Buffer.concat([ei, t]),
3612
+ key: Buffer.concat([ni, t]),
3606
3613
  format: "der",
3607
3614
  type: "spki"
3608
3615
  });
3609
3616
  }
3610
- function ri() {
3617
+ function ai() {
3611
3618
  let { privateKey: e, publicKey: t } = (0, M.generateKeyPairSync)("x25519"), n = e.export({ format: "jwk" });
3612
3619
  return {
3613
3620
  publicKey: t.export({ format: "jwk" }).x,
3614
3621
  privateKey: n.d
3615
3622
  };
3616
3623
  }
3617
- function ii(e, t, n) {
3624
+ function oi(e, t, n) {
3618
3625
  let r = (0, M.hkdfSync)("sha256", (0, M.diffieHellman)({
3619
- privateKey: ti(e),
3620
- publicKey: ni(t)
3626
+ privateKey: ri(e),
3627
+ publicKey: ii(t)
3621
3628
  }), $(n), Buffer.from("7h3-enc/1", "utf8"), 32);
3622
3629
  return Buffer.from(r);
3623
3630
  }
3624
- function ai(e, t) {
3625
- let n = ri(), r = (0, M.randomBytes)(12), i = Qr(r), a = ii(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 = {
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 = {
3626
3633
  ephemeralPublic: n.publicKey,
3627
3634
  nonce: i,
3628
- ciphertext: Qr(c),
3629
- tag: Qr(l)
3635
+ ciphertext: ei(c),
3636
+ tag: ei(l)
3630
3637
  };
3631
3638
  return {
3632
- encryptedContent: Qr(Buffer.from(JSON.stringify(u), "utf8")),
3639
+ encryptedContent: ei(Buffer.from(JSON.stringify(u), "utf8")),
3633
3640
  ephemeralPublic: n.publicKey
3634
3641
  };
3635
3642
  }
3636
- function oi(e, t) {
3637
- let n = $(e).toString("utf8"), { ephemeralPublic: r, nonce: i, ciphertext: a, tag: o } = JSON.parse(n), s = ii(t, r, i), c = $(i), l = $(a), u = $(o), d = (0, M.createDecipheriv)("chacha20-poly1305", s, c, { authTagLength: 16 });
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 });
3638
3645
  d.setAuthTag(u);
3639
3646
  let f = Buffer.concat([d.update(l), d.final()]);
3640
3647
  return JSON.parse(f.toString("utf8"));
3641
3648
  }
3642
- async function si(e, t) {
3643
- let { encryptedContent: n } = ai(e.body, t.recipientX25519PublicKey);
3649
+ async function li(e, t) {
3650
+ let { encryptedContent: n } = si(e.body, t.recipientX25519PublicKey);
3644
3651
  return S({
3645
3652
  header: e.header,
3646
3653
  body: {
@@ -3651,12 +3658,12 @@ async function si(e, t) {
3651
3658
  }
3652
3659
  }, t.senderEd25519PrivateKey);
3653
3660
  }
3654
- async function ci(e, t) {
3661
+ async function ui(e, t) {
3655
3662
  if (!await C(e, t.senderEd25519PublicKey)) throw Error("7h3/encryption: Ed25519 signature verification failed");
3656
3663
  return {
3657
3664
  envelope: e,
3658
- body: oi(e.body.content, t.recipientX25519PrivateKey)
3665
+ body: ci(e.body.content, t.recipientX25519PrivateKey)
3659
3666
  };
3660
3667
  }
3661
3668
  //#endregion
3662
- export { at as AgentSession, ot as AipAgentAdapter, Ar as CAP_HEADER, Cn as CBOR_CONTENT_TYPE, bn as CborDecoder, yn as CborEncoder, Lt as ClusterRedisReplayStore, En as DEFAULT_HEADER, be as DEFAULT_MAX_BINARY_ENVELOPE_BYTES, Le as DistributedReplayCache, cr as GRPC_METADATA_KEY, Wr as InMemoryAuditLog, Ft as InMemoryRedisLikeClient, O as InMemoryReplayCache, Ht as InMemoryRevocationStore, Re as InMemoryVerificationMaterialCache, gr as KeyRotationManager, Gr as NoopAuditLog, Vr as Protocol7h3Gateway, Dr as Protocol7h3Metrics, Sr as RESPONSE_HEADER, It as RedisReplayStore, _r as RevocationRegistry, rt as RollingKeyring, jt as RuntimePolicyManager, Hn as STREAM_HEADER, Ye as SessionTransport, Qn as SignedStreamReader, q as SignedStreamWriter, X as SimpleCounter, Er as SimpleHistogram, vr as SlidingWindowRateLimiter, Nn as WEBHOOK_DEFAULT_TTL_MS, I as WEBHOOK_SIG_HEADER, L as WEBHOOK_TS_HEADER, A as bootstrapRuntimePolicyEnforcer, Q as canonicalizeCapabilityToken, _ as canonicalizeEnvelope, Rn as consumeWebhook, st as createAipAgentAdapter, $e as createAipCapabilities, kt as createAipMcpGatewayRuntime, At as createAipMcpGatewayRuntimeWithPolicy, Kr as createAuditLog, rn as createCachingKeyRegistry, Bt as createClusterReplayStore, nn as createCompositeKeyRegistry, T as createEnvelope, Hr as createGateway, hr as createHttpKeyRegistry, en as createHttpMcpClient, $t as createHttpMcpHandler, An as createHttpMiddleware, it as createKeyringSignatureResolver, Jt as createMcpClientCodec, kr as createMetricsMiddleware, Ct as createPolicyEnforcer, pt as createRawTaskFromJsonRpc, ct as createRawTaskFromLangChain, ut as createRawTaskFromLlamaIndex, Rt as createRedisReplayStore, Ut as createRedisRevocationStore, Mn as createSignedFetchRequest, Xe as createSignedMessage, $n as createSignedStream, or as createSignedWebSocketStream, tn as createStaticKeyRegistry, Qt as createStdioMcpClient, er as createStreamVerifier, Sn as decodeCbor, We as decodeEnvelope, qe as decodeEnvelopeBatch, Fe as decodeEnvelopeBinary, Tn as decodeEnvelopeCbor, ir as decodeStreamChunk, oi as decryptBody, Fr as delegateCapabilityToken, ii as deriveEncryptionKey, et as encodeAipCapabilities, xn as encodeCbor, Ge as encodeEnvelope, Ke as encodeEnvelopeBatch, Pe as encodeEnvelopeBinary, wn as encodeEnvelopeCbor, rr as encodeStreamChunk, ai as encryptBody, mr as fetchWellKnownKeys, pe as generateEd25519KeypairBase64Url, ri as generateX25519KeyPair, Yr as getOtelTracer, Nt as getRuntimeTuningPreset, yr as globalRateLimiter, xr as isAllowedSender, wt as isRuntimeMode, Mr as issueCapabilityToken, bt as loadRuntimePolicy, J as matchGlob, br as matchPolicy, Z as metrics, nt as negotiateAipCapabilities, ci as openEnvelope, tt as parseAipCapabilities, Br as parseCapabilityChain, vt as parseRuntimePolicyJson, pr as parseWellKnownKeys, k as receiveEnvelope, Je as receiveEnvelopeBatch, sr as receiveSignedWebSocketStream, Pt as recommendPolicyAdjustments, Or as renderPrometheusText, si as sealEnvelope, zr as serializeCapabilityChain, Zt as serveMcpOverStdio, fr as serveWellKnownKeys, Jr as setOtelProvider, y as signCanonicalPayloadEd25519, de as signCanonicalPayloadHmac, S as signEnvelopeEd25519, x as signEnvelopeHmac, jn as signFetchRequest, lr as signGrpcCall, On as signHttpRequest, kn as signHttpRequestHmac, zn as signQueueMessage, Cr as signResponse, tr as signStream, Pn as signWebhook, Fn as signWebhookHmac, mt as toJsonRpcResponse, lt as toLangChainMessage, dt as toLlamaIndexMessage, Rr as tokenMatchesScope, w as validateEnvelope, _t as validateRuntimePolicy, b as verifyCanonicalPayloadEd25519, fe as verifyCanonicalPayloadHmac, ge as verifyCanonicalPayloadSignature, Lr as verifyCapabilityChain, Ir as verifyCapabilityToken, C as verifyEnvelopeEd25519, me as verifyEnvelopeHmac, he as verifyEnvelopeSignature, ur as verifyGrpcCall, Dn as verifyHttpEnvelope, Vn as verifyQueueBatch, Bn as verifyQueueMessage, wr as verifyResponse, nr as verifyStream, In as verifyWebhook, Ln as verifyWebhookHmac, Zr as withAuditSpan, dr as withGrpcVerification, Wt as withRevocationCheck, Xr as withVerificationSpan, Yt as wrapMcpClient, qt as wrapMcpServer, ar as wrapWebSocket };
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 };