@rubytech/create-realagent 1.0.771 → 1.0.773

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.
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Real Agent</title>
7
7
  <link rel="icon" href="/favicon.ico">
8
- <script type="module" crossorigin src="/assets/admin-CaXX8wc3.js"></script>
8
+ <script type="module" crossorigin src="/assets/admin-C4CTVtBu.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/chunk-DD-I1_y5.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/jsx-runtime-DeNudFNA.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/preload-helper-qlgyTAkD.js">
@@ -47,7 +47,7 @@ import {
47
47
  vncLog,
48
48
  waitForExit,
49
49
  writeChromiumWrapper
50
- } from "./chunk-IO2WQEY4.js";
50
+ } from "./chunk-PIMJJCOQ.js";
51
51
  import {
52
52
  ACCOUNTS_DIR,
53
53
  GREETING_DIRECTIVE,
@@ -87,6 +87,7 @@ import {
87
87
  interruptClient,
88
88
  listAdminSessions,
89
89
  listAdminSessionsInProgress,
90
+ loadAdminUserName,
90
91
  loadOnboardingStep,
91
92
  preConversationLogStream,
92
93
  preflushStreamLogKey,
@@ -106,8 +107,9 @@ import {
106
107
  validateAgentSlug,
107
108
  validateSession,
108
109
  verifyAndGetConversationUpdatedAt,
109
- verifyConversationOwnership
110
- } from "./chunk-TKYZ7AEB.js";
110
+ verifyConversationOwnership,
111
+ writeAdminUserAndPerson
112
+ } from "./chunk-2HBD6IRL.js";
111
113
 
112
114
  // ../lib/graph-trash/dist/index.js
113
115
  var require_dist = __commonJS({
@@ -7443,12 +7445,22 @@ app8.post("/set-pin", async (c) => {
7443
7445
  if (!body.pin || body.pin.length < 4) {
7444
7446
  return c.json({ error: "PIN must be at least 4 characters." }, 400);
7445
7447
  }
7448
+ const fullName = (body.name ?? "").trim();
7449
+ if (!fullName) {
7450
+ return c.json({ error: "Your name is required." }, 400);
7451
+ }
7446
7452
  const hash = hashPin(body.pin);
7447
- const userId = randomUUID7();
7448
- mkdirSync6(dirname5(USERS_FILE), { recursive: true });
7449
- writeFileSync7(USERS_FILE, JSON.stringify([{ userId, name: "Owner", pin: hash }]), { mode: 384 });
7450
- console.log(`[set-pin] created users.json: userId=${userId.slice(0, 8)}\u2026 hash=${hash.slice(0, 8)}\u2026`);
7451
7453
  const account = resolveAccount();
7454
+ const existingOwnerUserId = account?.config.admins?.find((a) => a.role === "owner")?.userId;
7455
+ const userId = existingOwnerUserId ?? randomUUID7();
7456
+ if (existingOwnerUserId) {
7457
+ console.log(`[set-pin] reusing existing owner userId=${userId.slice(0, 8)}\u2026 (change-PIN preserves identity)`);
7458
+ } else {
7459
+ console.log(`[set-pin] minted new userId=${userId.slice(0, 8)}\u2026 (first-time install)`);
7460
+ }
7461
+ mkdirSync6(dirname5(USERS_FILE), { recursive: true });
7462
+ writeFileSync7(USERS_FILE, JSON.stringify([{ userId, pin: hash }]), { mode: 384 });
7463
+ console.log(`[set-pin] wrote users.json: userId=${userId.slice(0, 8)}\u2026 hash=${hash.slice(0, 8)}\u2026`);
7452
7464
  if (account) {
7453
7465
  try {
7454
7466
  const config = JSON.parse(readFileSync10(`${account.accountDir}/account.json`, "utf-8"));
@@ -7461,6 +7473,21 @@ app8.post("/set-pin", async (c) => {
7461
7473
  } catch (err) {
7462
7474
  console.error(`[set-pin] failed to update account.json admins: ${err instanceof Error ? err.message : String(err)}`);
7463
7475
  }
7476
+ try {
7477
+ const result = await writeAdminUserAndPerson({
7478
+ userId,
7479
+ fullName,
7480
+ accountId: account.accountId
7481
+ });
7482
+ console.log(
7483
+ `[admin-identity] adminuser-bound userId=${userId.slice(0, 8)} givenName=${result.givenName} familyName=${result.familyName ?? "null"} personReused=${result.personReused}`
7484
+ );
7485
+ } catch (err) {
7486
+ console.error(
7487
+ `[admin-identity] adminuser-bind-failed userId=${userId.slice(0, 8)} accountId=${account.accountId.slice(0, 8)} error=${err instanceof Error ? err.message : String(err)}`
7488
+ );
7489
+ return c.json({ error: "Failed to write admin identity to graph. Check Neo4j connectivity and retry." }, 500);
7490
+ }
7464
7491
  }
7465
7492
  return c.json({ ok: true });
7466
7493
  });
@@ -7706,8 +7733,9 @@ app9.post("/", async (c) => {
7706
7733
  var client_error_default = app9;
7707
7734
 
7708
7735
  // server/routes/admin/session.ts
7709
- import { readFileSync as readFileSync11, existsSync as existsSync13 } from "fs";
7736
+ import { readFileSync as readFileSync11, writeFileSync as writeFileSync8, existsSync as existsSync13 } from "fs";
7710
7737
  import { createHash as createHash2 } from "crypto";
7738
+ var deprecationLogged = /* @__PURE__ */ new Set();
7711
7739
  function hashPin2(pin) {
7712
7740
  return createHash2("sha256").update(pin).digest("hex");
7713
7741
  }
@@ -7717,6 +7745,33 @@ function readUsersFile2() {
7717
7745
  if (!raw) return [];
7718
7746
  return JSON.parse(raw);
7719
7747
  }
7748
+ function stripLegacyNameField(users) {
7749
+ const dirty = users.some((u) => "name" in u && u.name !== void 0);
7750
+ if (!dirty) return;
7751
+ for (const u of users) {
7752
+ if ("name" in u && u.name !== void 0) {
7753
+ if (!deprecationLogged.has(u.userId)) {
7754
+ console.log(`[admin-identity] users-json-name-field-deprecated userId=${u.userId.slice(0, 8)}`);
7755
+ deprecationLogged.add(u.userId);
7756
+ }
7757
+ delete u.name;
7758
+ }
7759
+ }
7760
+ try {
7761
+ writeFileSync8(USERS_FILE, JSON.stringify(users), { mode: 384 });
7762
+ } catch (err) {
7763
+ console.error(`[admin-identity] users-json strip failed: ${err instanceof Error ? err.message : String(err)}`);
7764
+ }
7765
+ }
7766
+ async function resolveUserName(accountId, userId) {
7767
+ const result = await loadAdminUserName(accountId, userId);
7768
+ if (result.source === "neo4j") {
7769
+ console.log(`[admin-identity] userName-source=neo4j userId=${userId.slice(0, 8)} givenName=${result.givenName} familyName=${result.familyName ?? "null"} joined=${result.joined}`);
7770
+ return result.joined;
7771
+ }
7772
+ console.log(`[admin-identity] userName-source=fallback reason=${result.reason} userId=${userId.slice(0, 8)} accountId=${accountId.slice(0, 8)}`);
7773
+ return result.reason === "neo4j-unreachable" ? "Owner" : void 0;
7774
+ }
7720
7775
  async function createAdminSession(accountId, thinkingView, userId, userName, role) {
7721
7776
  const account = resolveAccount();
7722
7777
  const effectiveThinkingView = thinkingView ?? account?.config.thinkingView ?? "default";
@@ -7776,11 +7831,20 @@ app10.get("/", async (c) => {
7776
7831
  }
7777
7832
  const role = getRoleForSession(sessionKey);
7778
7833
  console.log(`[admin-session] role=${role ?? "null"} sessionKey=${sessionKey.slice(0, 8)} phase=restore`);
7834
+ const restoredUserId = getUserIdForSession(sessionKey);
7835
+ let restoredUserName = getUserNameForSession(sessionKey);
7836
+ if (restoredUserId) {
7837
+ const resolved = await resolveUserName(accountId, restoredUserId);
7838
+ restoredUserName = resolved;
7839
+ if (resolved !== void 0) {
7840
+ registerSession(sessionKey, "admin", accountId, void 0, restoredUserId, resolved, role ?? void 0);
7841
+ }
7842
+ }
7779
7843
  return c.json({
7780
7844
  session_key: sessionKey,
7781
7845
  agent_id: "admin",
7782
- userId: getUserIdForSession(sessionKey),
7783
- userName: getUserNameForSession(sessionKey),
7846
+ userId: restoredUserId,
7847
+ userName: restoredUserName,
7784
7848
  role: role ?? null,
7785
7849
  thinkingView,
7786
7850
  onboardingComplete,
@@ -7812,7 +7876,8 @@ app10.post("/", async (c) => {
7812
7876
  console.log(`[session] PIN auth failed: no matching user`);
7813
7877
  return c.json({ error: "Invalid PIN" }, 401);
7814
7878
  }
7815
- const { userId, name: userName } = matchedUser;
7879
+ stripLegacyNameField(users);
7880
+ const { userId } = matchedUser;
7816
7881
  const accounts = resolveUserAccounts(userId);
7817
7882
  if (accounts.length === 0) {
7818
7883
  console.log(`[session] user has no accounts: userId=${userId}`);
@@ -7831,13 +7896,14 @@ app10.post("/", async (c) => {
7831
7896
  return { accountId: a.accountId, businessName, role: a.role };
7832
7897
  })
7833
7898
  );
7834
- return c.json({ accounts: accountList, userId, userName });
7899
+ return c.json({ accounts: accountList, userId });
7835
7900
  }
7836
7901
  const selected = body.accountId ? accounts.find((a) => a.accountId === body.accountId) : accounts[0];
7837
7902
  if (!selected) {
7838
7903
  console.log(`[session] account selection invalid: userId=${userId} requested=${body.accountId}`);
7839
7904
  return c.json({ error: "Invalid account selection." }, 403);
7840
7905
  }
7906
+ const userName = await resolveUserName(selected.accountId, userId);
7841
7907
  const payload = await createAdminSession(selected.accountId, selected.config.thinkingView, userId, userName, selected.role);
7842
7908
  return c.json(payload);
7843
7909
  });
@@ -8135,7 +8201,7 @@ var app11 = new Hono();
8135
8201
  app11.post("/cancel", requireAdminSession, async (c) => {
8136
8202
  const session_key = c.var.sessionKey;
8137
8203
  try {
8138
- const { interruptClient: interruptClient2 } = await import("./client-pool-CX2MFW75.js");
8204
+ const { interruptClient: interruptClient2 } = await import("./client-pool-U3A5YUO7.js");
8139
8205
  await interruptClient2(session_key);
8140
8206
  return c.json({ ok: true });
8141
8207
  } catch (err) {
@@ -9340,7 +9406,7 @@ function isValidDomain(value) {
9340
9406
  }
9341
9407
 
9342
9408
  // app/lib/alias-domains.ts
9343
- import { existsSync as existsSync18, mkdirSync as mkdirSync8, readFileSync as readFileSync14, writeFileSync as writeFileSync8 } from "fs";
9409
+ import { existsSync as existsSync18, mkdirSync as mkdirSync8, readFileSync as readFileSync14, writeFileSync as writeFileSync9 } from "fs";
9344
9410
  import { dirname as dirname7 } from "path";
9345
9411
  import { resolve as resolve16 } from "path";
9346
9412
  var ALIAS_DOMAINS_PATH = resolve16(MAXY_DIR, "alias-domains.json");
@@ -9359,7 +9425,7 @@ function addAliasDomain(hostname2) {
9359
9425
  if (existing.has(hostname2)) return;
9360
9426
  existing.add(hostname2);
9361
9427
  mkdirSync8(dirname7(ALIAS_DOMAINS_PATH), { recursive: true });
9362
- writeFileSync8(ALIAS_DOMAINS_PATH, JSON.stringify([...existing], null, 2) + "\n", "utf-8");
9428
+ writeFileSync9(ALIAS_DOMAINS_PATH, JSON.stringify([...existing], null, 2) + "\n", "utf-8");
9363
9429
  }
9364
9430
 
9365
9431
  // server/routes/admin/cloudflare.ts