@threadbase-sh/streamer 1.69.3 → 1.69.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4142,7 +4142,7 @@ async function readGitBranch(dir) {
4142
4142
  // src/server.ts
4143
4143
  var import_node_ws = require("@hono/node-ws");
4144
4144
  var import_client = require("@temporalio/client");
4145
- var import_crypto13 = require("crypto");
4145
+ var import_crypto14 = require("crypto");
4146
4146
  var import_events = require("events");
4147
4147
  var import_fs28 = require("fs");
4148
4148
  var import_promises7 = require("fs/promises");
@@ -9251,6 +9251,7 @@ var ConversationHandlers = class {
9251
9251
  };
9252
9252
 
9253
9253
  // src/api/handlers/sessions.handlers.ts
9254
+ var import_crypto9 = require("crypto");
9254
9255
  var import_fs15 = require("fs");
9255
9256
  var import_path16 = require("path");
9256
9257
 
@@ -10546,7 +10547,9 @@ var SessionHandlers = class {
10546
10547
  }
10547
10548
  const key = permissionContentKey(gate);
10548
10549
  if (this.pendingPermissionKey.get(sessionId) === key) return;
10549
- this.pendingPermission.set(sessionId, gate);
10550
+ const prior = this.pendingPermission.get(sessionId);
10551
+ const gateId = prior && permissionGateKey(prior) === permissionGateKey(gate) ? prior.gateId : (0, import_crypto9.randomUUID)();
10552
+ this.pendingPermission.set(sessionId, { ...gate, gateId });
10550
10553
  this.pendingPermissionKey.set(sessionId, key);
10551
10554
  const subscriberCount = this.sessionSubscribers.get(sessionId)?.size ?? 0;
10552
10555
  this.log.info(
@@ -10560,7 +10563,8 @@ var SessionHandlers = class {
10560
10563
  ...gate.detail ? { detail: gate.detail } : {},
10561
10564
  options: gate.options,
10562
10565
  ...gate.cursor !== void 0 ? { cursor: gate.cursor } : {},
10563
- contentKey: permissionGateKey(gate)
10566
+ contentKey: permissionGateKey(gate),
10567
+ gateId
10564
10568
  });
10565
10569
  }
10566
10570
  /**
@@ -10588,10 +10592,15 @@ var SessionHandlers = class {
10588
10592
  const body = await readBody2(req);
10589
10593
  const contentKey = body?.contentKey;
10590
10594
  const optionIndex = body?.optionIndex;
10595
+ const gateId = body?.gateId;
10591
10596
  if (typeof contentKey !== "string" || !Number.isInteger(optionIndex) || optionIndex < 0) {
10592
10597
  json(res, 400, { ok: false, reason: "Expected { contentKey: string, optionIndex: number }" });
10593
10598
  return;
10594
10599
  }
10600
+ if (gateId !== void 0 && typeof gateId !== "string") {
10601
+ json(res, 400, { ok: false, reason: "Expected gateId to be a string" });
10602
+ return;
10603
+ }
10595
10604
  const gateClosed = () => {
10596
10605
  this.pendingPermission.delete(sessionId);
10597
10606
  this.pendingPermissionKey.delete(sessionId);
@@ -10603,6 +10612,16 @@ var SessionHandlers = class {
10603
10612
  gateClosed();
10604
10613
  return;
10605
10614
  }
10615
+ if (gateId !== void 0 && gateId !== gate.gateId) {
10616
+ json(res, 409, { ok: false, reason: "gate_mismatch" });
10617
+ return;
10618
+ }
10619
+ if (gateId === void 0) {
10620
+ this.log.info(`[permission.answer_legacy_identity] ${sessionId.slice(0, 8)}`, {
10621
+ event: "permission.answer_legacy_identity",
10622
+ sessionId
10623
+ });
10624
+ }
10606
10625
  if (permissionGateKey(gate) !== contentKey) {
10607
10626
  json(res, 409, { ok: false, reason: "gate_mismatch" });
10608
10627
  return;
@@ -10612,7 +10631,8 @@ var SessionHandlers = class {
10612
10631
  json(res, 409, { ok: false, reason: "unknown_option" });
10613
10632
  return;
10614
10633
  }
10615
- if (!await this.permissionGateStillOpen(sessionId, contentKey)) {
10634
+ const provider = this.sessionStore.getManaged(sessionId)?.provider;
10635
+ if (provider !== CODEX_CLI_PROVIDER && !await this.permissionGateStillOpen(sessionId, contentKey)) {
10616
10636
  gateClosed();
10617
10637
  return;
10618
10638
  }
@@ -11320,7 +11340,7 @@ var ManagedSessionsRepository = class {
11320
11340
  };
11321
11341
 
11322
11342
  // src/db/repositories/projects.repository.ts
11323
- var import_crypto9 = require("crypto");
11343
+ var import_crypto10 = require("crypto");
11324
11344
  function rowToProject(row) {
11325
11345
  return {
11326
11346
  id: row.id,
@@ -11405,7 +11425,7 @@ var ProjectsRepository = class {
11405
11425
  });
11406
11426
  return rowToProject(this.getById.get(existing.id));
11407
11427
  }
11408
- const id = (0, import_crypto9.randomUUID)();
11428
+ const id = (0, import_crypto10.randomUUID)();
11409
11429
  this.insert.run({
11410
11430
  id,
11411
11431
  path,
@@ -11535,7 +11555,7 @@ var RuntimeStore = class _RuntimeStore {
11535
11555
  };
11536
11556
 
11537
11557
  // src/e2ee/noise.ts
11538
- var import_crypto10 = require("crypto");
11558
+ var import_crypto11 = require("crypto");
11539
11559
  var NOISE_PROTOCOL_NAME = "Noise_IKpsk1_25519_ChaChaPoly_SHA256";
11540
11560
  var PAIR_PROLOGUE = Buffer.from("threadbase-e2ee/1 pair", "utf-8");
11541
11561
  var DHLEN = 32;
@@ -11551,15 +11571,15 @@ var NoiseError = class extends Error {
11551
11571
  }
11552
11572
  };
11553
11573
  function generateKeyPair() {
11554
- const { publicKey, privateKey } = (0, import_crypto10.generateKeyPairSync)("x25519");
11574
+ const { publicKey, privateKey } = (0, import_crypto11.generateKeyPairSync)("x25519");
11555
11575
  return { publicKey, privateKey, publicKeyRaw: rawPublicKey(publicKey) };
11556
11576
  }
11557
11577
  function keyPairFrom(privateKey) {
11558
- const publicKey = (0, import_crypto10.createPublicKey)(privateKey);
11578
+ const publicKey = (0, import_crypto11.createPublicKey)(privateKey);
11559
11579
  return { publicKey, privateKey, publicKeyRaw: rawPublicKey(publicKey) };
11560
11580
  }
11561
11581
  function rawPublicKey(key) {
11562
- const pub = key.type === "public" ? key : (0, import_crypto10.createPublicKey)(key);
11582
+ const pub = key.type === "public" ? key : (0, import_crypto11.createPublicKey)(key);
11563
11583
  const jwk = pub.export({ format: "jwk" });
11564
11584
  if (jwk.crv !== "X25519" || typeof jwk.x !== "string") {
11565
11585
  throw new NoiseError("Not an X25519 public key");
@@ -11571,7 +11591,7 @@ function publicKeyFromRaw(raw) {
11571
11591
  throw new NoiseError(`X25519 public key must be ${DHLEN} bytes, got ${raw.length}`);
11572
11592
  }
11573
11593
  try {
11574
- return (0, import_crypto10.createPublicKey)({
11594
+ return (0, import_crypto11.createPublicKey)({
11575
11595
  key: { kty: "OKP", crv: "X25519", x: raw.toString("base64url") },
11576
11596
  format: "jwk"
11577
11597
  });
@@ -11580,7 +11600,7 @@ function publicKeyFromRaw(raw) {
11580
11600
  }
11581
11601
  }
11582
11602
  function pskFromPairToken(token) {
11583
- return (0, import_crypto10.createHash)("sha256").update("threadbase-e2ee/1 psk", "utf-8").update(token, "utf-8").digest();
11603
+ return (0, import_crypto11.createHash)("sha256").update("threadbase-e2ee/1 psk", "utf-8").update(token, "utf-8").digest();
11584
11604
  }
11585
11605
  function chachaNonce(n) {
11586
11606
  const nonce = Buffer.alloc(12);
@@ -11599,7 +11619,7 @@ var CipherState = class {
11599
11619
  }
11600
11620
  encryptWithAd(ad, plaintext) {
11601
11621
  if (!this.k) return plaintext;
11602
- const cipher = (0, import_crypto10.createCipheriv)("chacha20-poly1305", this.k, chachaNonce(this.n), {
11622
+ const cipher = (0, import_crypto11.createCipheriv)("chacha20-poly1305", this.k, chachaNonce(this.n), {
11603
11623
  authTagLength: TAGLEN
11604
11624
  });
11605
11625
  cipher.setAAD(ad, { plaintextLength: plaintext.length });
@@ -11612,7 +11632,7 @@ var CipherState = class {
11612
11632
  if (ciphertext.length < TAGLEN) throw new NoiseError("Ciphertext shorter than its tag");
11613
11633
  const body = ciphertext.subarray(0, ciphertext.length - TAGLEN);
11614
11634
  const tag = ciphertext.subarray(ciphertext.length - TAGLEN);
11615
- const decipher = (0, import_crypto10.createDecipheriv)("chacha20-poly1305", this.k, chachaNonce(this.n), {
11635
+ const decipher = (0, import_crypto11.createDecipheriv)("chacha20-poly1305", this.k, chachaNonce(this.n), {
11616
11636
  authTagLength: TAGLEN
11617
11637
  });
11618
11638
  decipher.setAAD(ad, { plaintextLength: body.length });
@@ -11633,7 +11653,7 @@ var SymmetricState = class {
11633
11653
  cipher = new CipherState();
11634
11654
  constructor(protocolName) {
11635
11655
  const name = Buffer.from(protocolName, "utf-8");
11636
- this.h = name.length <= HASHLEN ? Buffer.concat([name, Buffer.alloc(HASHLEN - name.length)]) : (0, import_crypto10.createHash)("sha256").update(name).digest();
11656
+ this.h = name.length <= HASHLEN ? Buffer.concat([name, Buffer.alloc(HASHLEN - name.length)]) : (0, import_crypto11.createHash)("sha256").update(name).digest();
11637
11657
  this.ck = Buffer.from(this.h);
11638
11658
  this.cipher.initializeKey(null);
11639
11659
  }
@@ -11645,7 +11665,7 @@ var SymmetricState = class {
11645
11665
  * subtly wrong.
11646
11666
  */
11647
11667
  hkdf(ikm, outputs) {
11648
- const raw = Buffer.from((0, import_crypto10.hkdfSync)("sha256", ikm, this.ck, Buffer.alloc(0), HASHLEN * outputs));
11668
+ const raw = Buffer.from((0, import_crypto11.hkdfSync)("sha256", ikm, this.ck, Buffer.alloc(0), HASHLEN * outputs));
11649
11669
  const out = [];
11650
11670
  for (let i = 0; i < outputs; i++) out.push(raw.subarray(i * HASHLEN, (i + 1) * HASHLEN));
11651
11671
  return out;
@@ -11656,7 +11676,7 @@ var SymmetricState = class {
11656
11676
  this.cipher.initializeKey(tempK);
11657
11677
  }
11658
11678
  mixHash(data) {
11659
- this.h = (0, import_crypto10.createHash)("sha256").update(this.h).update(data).digest();
11679
+ this.h = (0, import_crypto11.createHash)("sha256").update(this.h).update(data).digest();
11660
11680
  }
11661
11681
  /** Spec §5.2. Used only by the `psk` token. */
11662
11682
  mixKeyAndHash(ikm) {
@@ -11686,7 +11706,7 @@ var SymmetricState = class {
11686
11706
  }
11687
11707
  };
11688
11708
  function dh(privateKey, publicKey) {
11689
- return (0, import_crypto10.diffieHellman)({ privateKey, publicKey });
11709
+ return (0, import_crypto11.diffieHellman)({ privateKey, publicKey });
11690
11710
  }
11691
11711
  function readMessage1(args) {
11692
11712
  assertMessageSize(args.message1, NOISE_MESSAGE_1_OVERHEAD);
@@ -11998,7 +12018,7 @@ var ExternalTailManager = class {
11998
12018
  };
11999
12019
 
12000
12020
  // src/pair-store.ts
12001
- var import_crypto11 = require("crypto");
12021
+ var import_crypto12 = require("crypto");
12002
12022
  var DEFAULT_TTL_SECONDS = 180;
12003
12023
  var SWEEP_INTERVAL_MS = 6e4;
12004
12024
  var PairTokenStore = class {
@@ -12013,7 +12033,7 @@ var PairTokenStore = class {
12013
12033
  }
12014
12034
  }
12015
12035
  mint() {
12016
- const token = `pt_${(0, import_crypto11.randomBytes)(16).toString("hex")}`;
12036
+ const token = `pt_${(0, import_crypto12.randomBytes)(16).toString("hex")}`;
12017
12037
  const expiresAt = Date.now() + this.ttlMs;
12018
12038
  this.current = { token, expiresAt, used: false };
12019
12039
  return {
@@ -13171,7 +13191,8 @@ function createApiDeps(deps) {
13171
13191
  ...pendingGate.detail ? { detail: pendingGate.detail } : {},
13172
13192
  options: pendingGate.options,
13173
13193
  ...pendingGate.cursor !== void 0 ? { cursor: pendingGate.cursor } : {},
13174
- contentKey: permissionGateKey(pendingGate)
13194
+ contentKey: permissionGateKey(pendingGate),
13195
+ gateId: pendingGate.gateId
13175
13196
  })
13176
13197
  );
13177
13198
  }
@@ -13238,7 +13259,7 @@ function createApiDeps(deps) {
13238
13259
  }
13239
13260
 
13240
13261
  // src/services/cache-integrity/cacheIntegrityMonitor.ts
13241
- var import_crypto12 = require("crypto");
13262
+ var import_crypto13 = require("crypto");
13242
13263
  var import_fs23 = require("fs");
13243
13264
 
13244
13265
  // src/services/cache-integrity/alertStore.ts
@@ -13303,7 +13324,7 @@ function envInt(name, fallback) {
13303
13324
  }
13304
13325
  function fingerprintOf(ids) {
13305
13326
  const sorted = [...ids].sort();
13306
- return `sha256:${(0, import_crypto12.createHash)("sha256").update(sorted.join("\n")).digest("hex")}`;
13327
+ return `sha256:${(0, import_crypto13.createHash)("sha256").update(sorted.join("\n")).digest("hex")}`;
13307
13328
  }
13308
13329
  var CacheIntegrityMonitor = class {
13309
13330
  constructor(cache, wsHub, log10, cacheDir, rescan, runDuringReset) {
@@ -16029,7 +16050,7 @@ var StreamerServer = class {
16029
16050
  runtimeStore = null;
16030
16051
  // Identifies this streamer run. A registry row carrying a different id is a
16031
16052
  // session that outlived the process that started it.
16032
- streamerInstanceId = (0, import_crypto13.randomUUID)();
16053
+ streamerInstanceId = (0, import_crypto14.randomUUID)();
16033
16054
  cacheMetadataRepo = null;
16034
16055
  // Push registration + delivery state (C7). Null when the cache DB failed to
16035
16056
  // open — registration then degrades to a no-op rather than 500ing.