@ouro.bot/cli 0.1.0-alpha.1067 → 0.1.0-alpha.1069

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.
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.readOrCreateTelegramIdentityKey = void 0;
36
37
  exports.createSabQueueProtectiveStateVerifier = createSabQueueProtectiveStateVerifier;
37
38
  exports.telegramAcceptanceAuditOwnerDigest = telegramAcceptanceAuditOwnerDigest;
38
39
  exports.sanctuaryTelegramTurnReceiptDigest = sanctuaryTelegramTurnReceiptDigest;
@@ -42,7 +43,6 @@ exports.sanctuaryTelegramUnauthorizedDropMac = sanctuaryTelegramUnauthorizedDrop
42
43
  exports.sanctuaryTelegramApprovalEvidenceMac = sanctuaryTelegramApprovalEvidenceMac;
43
44
  exports.telegramBotIdFromToken = telegramBotIdFromToken;
44
45
  exports.ownerDisplayName = ownerDisplayName;
45
- exports.readOrCreateTelegramIdentityKey = readOrCreateTelegramIdentityKey;
46
46
  exports.opaqueTelegramSubject = opaqueTelegramSubject;
47
47
  exports.migrateTelegramFriendIdentity = migrateTelegramFriendIdentity;
48
48
  exports.migrateTelegramSessionIdentity = migrateTelegramSessionIdentity;
@@ -74,6 +74,9 @@ const sanctuary_sab_1 = require("./sanctuary-sab");
74
74
  const sanctuary_download_credit_presentation_1 = require("./sanctuary-download-credit-presentation");
75
75
  const shared_turn_1 = require("./shared-turn");
76
76
  const config_1 = require("../heart/config");
77
+ const telegram_identity_key_1 = require("./telegram-identity-key");
78
+ var telegram_identity_key_2 = require("./telegram-identity-key");
79
+ Object.defineProperty(exports, "readOrCreateTelegramIdentityKey", { enumerable: true, get: function () { return telegram_identity_key_2.readOrCreateTelegramIdentityKey; } });
77
80
  const telegram_client_1 = require("./telegram-client");
78
81
  const sanctuary_authority_resident_1 = require("./sanctuary-authority-resident");
79
82
  const root_host_approval_runtime_1 = require("./root-host-approval-runtime");
@@ -128,7 +131,6 @@ function createSabQueueProtectiveStateVerifier(options = {}) {
128
131
  }
129
132
  const APPROVAL_EXPIRY_RECONCILE_INTERVAL_MS = 1_000;
130
133
  const TELEGRAM_SUBJECT_DOMAIN = "ouroboros.telegram.subject.v1";
131
- const TELEGRAM_IDENTITY_KEY = /^[A-Za-z0-9_-]{43}$/u;
132
134
  const TELEGRAM_SUBJECT = /^tg_[A-Za-z0-9_-]{43}$/u;
133
135
  const TELEGRAM_SUBJECT_INDEX = "identity-subjects.json";
134
136
  const TELEGRAM_ACCEPTANCE_AUDIT_EVENTS = new Set([
@@ -411,108 +413,14 @@ function telegramBotIdFromToken(token) {
411
413
  throw new Error("Telegram bot token does not expose a canonical numeric bot id");
412
414
  return match[1];
413
415
  }
414
- function canonicalTelegramIdentityKey(value) {
415
- const key = value.trim();
416
- if (!TELEGRAM_IDENTITY_KEY.test(key) || Buffer.from(key, "base64url").length !== 32) {
417
- throw new Error("Telegram opaque identity key is invalid");
418
- }
419
- return key;
420
- }
421
416
  function errorCode(error) {
422
417
  return error && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : undefined;
423
418
  }
424
- function openSecureTelegramDirectory(directory, afterOpen) {
425
- try {
426
- const existing = (0, node_fs_1.lstatSync)(directory);
427
- if (existing.isSymbolicLink())
428
- throw new Error("Telegram state directory must not be a symbolic link");
429
- if (!existing.isDirectory())
430
- throw new Error("Telegram state directory is not a directory");
431
- }
432
- catch (error) {
433
- if (errorCode(error) !== "ENOENT")
434
- throw error;
435
- (0, node_fs_1.mkdirSync)(directory, { recursive: true, mode: 0o700 });
436
- }
437
- const handle = (0, node_fs_1.openSync)(directory, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_DIRECTORY | node_fs_1.constants.O_NOFOLLOW);
438
- try {
439
- (0, node_fs_1.fchmodSync)(handle, 0o700);
440
- afterOpen?.(handle);
441
- const metadata = (0, node_fs_1.fstatSync)(handle);
442
- if (!metadata.isDirectory() || (metadata.mode & 0o777) !== 0o700) {
443
- throw new Error("Telegram state directory permissions are invalid");
444
- }
445
- return handle;
446
- }
447
- catch (error) {
448
- (0, node_fs_1.closeSync)(handle);
449
- throw error;
450
- }
451
- }
452
419
  /** The admitted owner's display name comes from the household's own house config. */
453
420
  function ownerDisplayName(agentName) {
454
421
  const { ownerName } = (0, sanctuary_house_1.readSanctuaryHouse)((0, identity_1.getAgentRoot)(agentName));
455
422
  return ownerName === sanctuary_house_1.DEFAULT_SANCTUARY_HOUSE.ownerName ? "Owner" : ownerName;
456
423
  }
457
- function readOrCreateTelegramIdentityKey(agentRoot, hooks = {}) {
458
- const directory = path.join(agentRoot, "state", "senses", "telegram");
459
- const keyPath = path.join(directory, "identity.key");
460
- const directoryHandle = openSecureTelegramDirectory(directory, hooks.afterOpenDirectory);
461
- const readKey = () => {
462
- const handle = (0, node_fs_1.openSync)(keyPath, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_NOFOLLOW);
463
- try {
464
- const metadata = (0, node_fs_1.fstatSync)(handle);
465
- if (!metadata.isFile() || (metadata.mode & 0o777) !== 0o600)
466
- throw new Error("Telegram opaque identity key permissions are invalid");
467
- return canonicalTelegramIdentityKey((0, node_fs_1.readFileSync)(handle, "utf8"));
468
- }
469
- finally {
470
- (0, node_fs_1.closeSync)(handle);
471
- }
472
- };
473
- try {
474
- try {
475
- return readKey();
476
- }
477
- catch (error) {
478
- if (errorCode(error) !== "ENOENT")
479
- throw error;
480
- }
481
- const key = (0, node_crypto_1.randomBytes)(32).toString("base64url");
482
- hooks.beforeCreate?.(keyPath);
483
- const temporaryPath = path.join(directory, `.identity.key.${(0, node_crypto_1.randomBytes)(12).toString("base64url")}.tmp`);
484
- let temporaryHandle;
485
- try {
486
- temporaryHandle = (0, node_fs_1.openSync)(temporaryPath, node_fs_1.constants.O_CREAT | node_fs_1.constants.O_EXCL | node_fs_1.constants.O_WRONLY | node_fs_1.constants.O_NOFOLLOW, 0o600);
487
- hooks.afterCreateTemporary?.(temporaryPath, keyPath);
488
- (0, node_fs_1.writeFileSync)(temporaryHandle, `${key}\n`);
489
- (0, node_fs_1.fsyncSync)(temporaryHandle);
490
- (0, node_fs_1.closeSync)(temporaryHandle);
491
- temporaryHandle = undefined;
492
- hooks.beforePublish?.(temporaryPath, keyPath);
493
- try {
494
- (0, node_fs_1.linkSync)(temporaryPath, keyPath);
495
- }
496
- catch (error) {
497
- if (errorCode(error) !== "EEXIST")
498
- throw error;
499
- return readKey();
500
- }
501
- (0, node_fs_1.fsyncSync)(directoryHandle);
502
- return key;
503
- }
504
- finally {
505
- if (temporaryHandle !== undefined)
506
- (0, node_fs_1.closeSync)(temporaryHandle);
507
- if ((0, node_fs_1.existsSync)(temporaryPath))
508
- (0, node_fs_1.unlinkSync)(temporaryPath);
509
- (0, node_fs_1.fsyncSync)(directoryHandle);
510
- }
511
- }
512
- finally {
513
- (0, node_fs_1.closeSync)(directoryHandle);
514
- }
515
- }
516
424
  function opaqueTelegramSubject(identityKey, botToken, authorizedUserId, authorizedChatId) {
517
425
  const payload = [
518
426
  TELEGRAM_SUBJECT_DOMAIN,
@@ -610,7 +518,7 @@ function discoverTelegramFilesystemSubjects(agentRoot) {
610
518
  function writeTelegramSubjectIndex(agentRoot, subject, legacySubjects, hooks = {}) {
611
519
  const directory = path.join(agentRoot, "state", "senses", "telegram");
612
520
  const indexPath = path.join(directory, TELEGRAM_SUBJECT_INDEX);
613
- const directoryHandle = openSecureTelegramDirectory(directory);
521
+ const directoryHandle = (0, telegram_identity_key_1.openSecureTelegramDirectory)(directory);
614
522
  const temporaryPath = path.join(directory, `.identity-subjects.${(0, node_crypto_1.randomBytes)(12).toString("base64url")}.tmp`);
615
523
  let temporaryHandle;
616
524
  try {
@@ -723,8 +631,8 @@ function createTelegramSenseApp(options) {
723
631
  const authorizedChatId = canonicalTelegramId(options.credentials.authorizedChatId, "authorized chat id");
724
632
  const agentRoot = options._agentRoot ?? (0, identity_1.getAgentRoot)(options.agentName);
725
633
  const identityKey = options.identityKey === undefined
726
- ? readOrCreateTelegramIdentityKey(agentRoot)
727
- : canonicalTelegramIdentityKey(options.identityKey);
634
+ ? (0, telegram_identity_key_1.readOrCreateTelegramIdentityKey)(agentRoot)
635
+ : (0, telegram_identity_key_1.canonicalTelegramIdentityKey)(options.identityKey);
728
636
  const subject = opaqueTelegramSubject(identityKey, botId ?? botToken, authorizedUserId, authorizedChatId);
729
637
  const transportPrivateValues = [botToken ?? "", authorizedUserId, authorizedChatId];
730
638
  const transportError = (error) => redactTelegramPrivateValues(error, transportPrivateValues);
@@ -2090,7 +1998,7 @@ async function createProductionTelegramRelationshipComposition(agentName, creden
2090
1998
  const ownerChatId = canonicalTelegramId(credentials.authorizedChatId, "authorized chat id");
2091
1999
  if (ownerUserId !== ownerChatId)
2092
2000
  throw new Error("Telegram owner relationship requires a private user-bound chat");
2093
- const ownerSessionKey = `telegram:${opaqueTelegramSubject(readOrCreateTelegramIdentityKey(agentRoot), botId, ownerUserId, ownerChatId)}`;
2001
+ const ownerSessionKey = `telegram:${opaqueTelegramSubject((0, telegram_identity_key_1.readOrCreateTelegramIdentityKey)(agentRoot), botId, ownerUserId, ownerChatId)}`;
2094
2002
  const store = new friends_1.FileFriendStore(path.join(agentRoot, "friends"));
2095
2003
  const sameBotTelegramBindings = (friend) => friend.externalIds.filter((external) => external.provider === "telegram-user" && external.tenantId === botId);
2096
2004
  const exactTelegramIdentity = (friend, userId) => {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1067",
3
+ "version": "0.1.0-alpha.1069",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@ouro.bot/cli",
9
- "version": "0.1.0-alpha.1067",
9
+ "version": "0.1.0-alpha.1069",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.78.0",
12
12
  "@ouro.bot/friends": "0.1.0-alpha.18",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1067",
3
+ "version": "0.1.0-alpha.1069",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },