@rubytech/create-realagent 1.0.865 → 1.0.866

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.
@@ -1,9 +1,19 @@
1
1
  import {
2
+ ACCOUNTS_DIR,
2
3
  ATTACHMENTS_ROOT,
4
+ CDP_PORT,
5
+ COMMERCIAL_MODE,
3
6
  Hono,
7
+ LOG_DIR,
8
+ MAXY_DIR,
4
9
  MAX_FILES_PER_MESSAGE,
5
10
  MAX_FILE_SIZE_BYTES,
11
+ PLATFORM_ROOT,
6
12
  SUPPORTED_MIME_TYPES,
13
+ TELEGRAM_ADMIN_WEBHOOK_SECRET_FILE,
14
+ TELEGRAM_WEBHOOK_SECRET_FILE,
15
+ USERS_FILE,
16
+ WEBSOCKIFY_PORT,
7
17
  assertSupportedMime,
8
18
  autoDeliverPremiumPlugins,
9
19
  browserViewerLog,
@@ -25,6 +35,8 @@ import {
25
35
  ensureLogDir,
26
36
  ensureVnc,
27
37
  findMissingPlugins,
38
+ getDefaultAccountId,
39
+ hasStubAccountDir,
28
40
  hashPassword,
29
41
  httpLog,
30
42
  invokeAgent,
@@ -37,13 +49,19 @@ import {
37
49
  load,
38
50
  logPath,
39
51
  pickComponentBytes,
52
+ preflushSliceOf,
40
53
  recordFailedAttempt,
41
54
  render,
42
55
  renderLoginPage,
43
56
  requireAdminSession,
57
+ resolveAccount,
58
+ resolveAgentConfig,
44
59
  resolveBrowserTransport,
45
60
  resolveClientIp,
61
+ resolveConversationLogPaths,
62
+ resolveDefaultAgentSlug,
46
63
  resolveEntitlement,
64
+ resolveUserAccounts,
47
65
  safeJson,
48
66
  sanitizeClientCorrId,
49
67
  serve,
@@ -56,6 +74,7 @@ import {
56
74
  streamLogPathFor,
57
75
  stripAttachmentMetaSuffix,
58
76
  tryCookieBridgeForConversation,
77
+ validateAgentSlug,
59
78
  validateFilePathInAccount,
60
79
  validateKey,
61
80
  validatePasswordStrength,
@@ -64,25 +83,14 @@ import {
64
83
  vncLog,
65
84
  waitForExit,
66
85
  writeChromiumWrapper
67
- } from "./chunk-2Q2S52GB.js";
86
+ } from "./chunk-ND23BDBM.js";
68
87
  import {
69
- ACCOUNTS_DIR,
70
- CDP_PORT,
71
- COMMERCIAL_MODE,
72
- LOG_DIR,
73
- MAXY_DIR,
74
- PLATFORM_ROOT,
75
- TELEGRAM_ADMIN_WEBHOOK_SECRET_FILE,
76
- TELEGRAM_WEBHOOK_SECRET_FILE,
77
- USERS_FILE,
78
- WEBSOCKIFY_PORT,
79
88
  agentLogStream,
80
89
  clearSessionHistory,
81
90
  completeGrantSetup,
82
91
  getAccountIdForSession,
83
92
  getAgentNameForSession,
84
93
  getConversationIdForSession,
85
- getDefaultAccountId,
86
94
  getGrantForSession,
87
95
  getGroupSlugForSession,
88
96
  getRoleForSession,
@@ -90,26 +98,19 @@ import {
90
98
  getUserIdForSession,
91
99
  getUserNameForSession,
92
100
  getVisitorIdForSession,
93
- hasStubAccountDir,
94
101
  interruptClient,
95
102
  listAdminSessionsInProgress,
96
103
  preConversationLogStream,
97
- preflushStreamLogKey,
98
104
  registerGrantSession,
99
105
  registerResumedSession,
100
106
  registerSession,
101
- resolveAccount,
102
- resolveAgentConfig,
103
- resolveDefaultAgentSlug,
104
- resolveUserAccounts,
105
107
  setAgentSessionId,
106
108
  setConversationIdForSession,
107
109
  setGroupContextForSession,
108
110
  sigtermFlushStreamLogs,
109
111
  unregisterSession,
110
- validateAgentSlug,
111
112
  validateSession
112
- } from "./chunk-22LK7D5R.js";
113
+ } from "./chunk-TOLLHW7W.js";
113
114
  import {
114
115
  CLOUDFLARE_TASK_DIAGNOSTICS,
115
116
  appendCloudflareSteps,
@@ -117,13 +118,14 @@ import {
117
118
  openCloudflareTask,
118
119
  readTunnelState,
119
120
  resolveUnitGoneVerdict
120
- } from "./chunk-BY4LZDL4.js";
121
+ } from "./chunk-UXLZ5Z3Y.js";
121
122
  import {
122
123
  GREETING_DIRECTIVE,
123
124
  HAIKU_MODEL,
124
125
  backfillNullUserIdConversations,
125
126
  bindVisitorToGroup,
126
127
  checkGroupMembership,
128
+ createNewAdminConversation,
127
129
  deleteAgentProjection,
128
130
  deleteConversation,
129
131
  embed,
@@ -148,7 +150,7 @@ import {
148
150
  verifyAndGetConversationUpdatedAt,
149
151
  verifyConversationOwnership,
150
152
  writeAdminUserAndPerson
151
- } from "./chunk-7ADUQXTU.js";
153
+ } from "./chunk-FHNFKJZN.js";
152
154
  import {
153
155
  __commonJS,
154
156
  __toESM
@@ -651,8 +653,8 @@ var serveStatic = (options = { root: "" }) => {
651
653
  };
652
654
 
653
655
  // server/index.ts
654
- import { readFileSync as readFileSync18, existsSync as existsSync24, watchFile } from "fs";
655
- import { resolve as resolve21, join as join12, basename as basename4 } from "path";
656
+ import { readFileSync as readFileSync18, existsSync as existsSync23, watchFile } from "fs";
657
+ import { resolve as resolve21, join as join11, basename as basename4 } from "path";
656
658
  import { homedir as homedir3 } from "os";
657
659
 
658
660
  // app/lib/agent-slug-pattern.ts
@@ -7147,6 +7149,7 @@ var session_default2 = app10;
7147
7149
  // server/routes/admin/chat.ts
7148
7150
  import { resolve as resolve8 } from "path";
7149
7151
  import { appendFileSync as appendFileSync3 } from "fs";
7152
+ import { randomUUID as randomUUID6 } from "crypto";
7150
7153
 
7151
7154
  // app/lib/script-stream-tailer.ts
7152
7155
  import * as childProcess from "child_process";
@@ -7436,7 +7439,7 @@ var app11 = new Hono();
7436
7439
  app11.post("/cancel", requireAdminSession, async (c) => {
7437
7440
  const session_key = c.var.sessionKey;
7438
7441
  try {
7439
- const { interruptClient: interruptClient2 } = await import("./client-pool-3BCJTPPA.js");
7442
+ const { interruptClient: interruptClient2 } = await import("./client-pool-2IUOSYDF.js");
7440
7443
  await interruptClient2(session_key);
7441
7444
  return c.json({ ok: true });
7442
7445
  } catch (err) {
@@ -7593,17 +7596,29 @@ app11.post("/", requireAdminSession, async (c) => {
7593
7596
  if (!isSystemMessage) {
7594
7597
  gatewayResult = await processInbound(message, "web-admin");
7595
7598
  }
7596
- const encoder = new TextEncoder();
7597
- const sseConvId = getConversationIdForSession(session_key);
7598
- const sseLogStream = sseConvId ? agentLogStream("sse-events", account.accountDir, sseConvId) : preConversationLogStream("sse-events", account.accountDir);
7599
- const sk = sseConvId?.slice(0, 8) ?? session_key.slice(0, 8);
7600
- function resolveTeeStreamLogPath() {
7601
- const liveConvId = getConversationIdForSession(session_key);
7602
- const key = liveConvId ?? preflushStreamLogKey(session_key);
7603
- return resolve8(account.accountDir, "logs", `claude-agent-stream-${key}.log`);
7599
+ let conversationId = getConversationIdForSession(session_key);
7600
+ if (!conversationId) {
7601
+ const userId = getUserIdForSession(session_key);
7602
+ const userName = getUserNameForSession(session_key);
7603
+ const accountId = getAccountIdForSession(session_key);
7604
+ if (!userId || !accountId) {
7605
+ return chatReject(401, "Invalid or expired admin session", session_key);
7606
+ }
7607
+ const minted = randomUUID6();
7608
+ const created = await createNewAdminConversation(userId, accountId, session_key, userName, minted);
7609
+ if (!created) {
7610
+ return chatReject(500, "Failed to create conversation", session_key);
7611
+ }
7612
+ conversationId = created;
7613
+ setConversationIdForSession(session_key, conversationId);
7614
+ console.log(`[chat-route] new conversation conversationId=${conversationId} sessionKey=${session_key.slice(0, 12)}\u2026`);
7604
7615
  }
7616
+ const encoder = new TextEncoder();
7617
+ const sseLogStream = agentLogStream("sse-events", account.accountDir, conversationId);
7618
+ const sk = conversationId.slice(0, 8);
7619
+ const teeStreamLogPath = resolve8(account.accountDir, "logs", `claude-agent-stream-${conversationId}.log`);
7605
7620
  try {
7606
- appendFileSync3(resolveTeeStreamLogPath(), `[${(/* @__PURE__ */ new Date()).toISOString()}] [chat-route-version=task606-tee-path-resolve] sessionKey=${session_key.slice(0, 12)}\u2026
7621
+ appendFileSync3(teeStreamLogPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] [chat-route-version=task965-mint-at-entry] sessionKey=${session_key.slice(0, 12)}\u2026 conversationId=${conversationId}
7607
7622
  `);
7608
7623
  } catch {
7609
7624
  }
@@ -7612,7 +7627,7 @@ app11.post("/", requireAdminSession, async (c) => {
7612
7627
  incoming.on("close", () => {
7613
7628
  const tsClose = (/* @__PURE__ */ new Date()).toISOString();
7614
7629
  try {
7615
- appendFileSync3(resolveTeeStreamLogPath(), `[${tsClose}] [incoming-close] sessionKey=${session_key.slice(0, 12)}\u2026 complete=${incoming.complete}
7630
+ appendFileSync3(teeStreamLogPath, `[${tsClose}] [incoming-close] sessionKey=${session_key.slice(0, 12)}\u2026 complete=${incoming.complete}
7616
7631
  `);
7617
7632
  } catch {
7618
7633
  }
@@ -7620,7 +7635,7 @@ app11.post("/", requireAdminSession, async (c) => {
7620
7635
  console.error(`[${tsClose}] [incoming-close] DISCONNECT sessionKey=${session_key.slice(0, 12)}\u2026`);
7621
7636
  interruptClient(session_key).catch((err) => {
7622
7637
  try {
7623
- appendFileSync3(resolveTeeStreamLogPath(), `[${(/* @__PURE__ */ new Date()).toISOString()}] [incoming-close] interrupt-failed: ${err instanceof Error ? err.message : String(err)}
7638
+ appendFileSync3(teeStreamLogPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] [incoming-close] interrupt-failed: ${err instanceof Error ? err.message : String(err)}
7624
7639
  `);
7625
7640
  } catch {
7626
7641
  }
@@ -7629,7 +7644,7 @@ app11.post("/", requireAdminSession, async (c) => {
7629
7644
  });
7630
7645
  } else {
7631
7646
  try {
7632
- appendFileSync3(resolveTeeStreamLogPath(), `[${(/* @__PURE__ */ new Date()).toISOString()}] [incoming-close] UNAVAILABLE \u2014 c.env.incoming is not an EventEmitter
7647
+ appendFileSync3(teeStreamLogPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] [incoming-close] UNAVAILABLE \u2014 c.env.incoming is not an EventEmitter
7633
7648
  `);
7634
7649
  } catch {
7635
7650
  }
@@ -7641,7 +7656,7 @@ app11.post("/", requireAdminSession, async (c) => {
7641
7656
  } catch {
7642
7657
  }
7643
7658
  try {
7644
- appendFileSync3(resolveTeeStreamLogPath(), line);
7659
+ appendFileSync3(teeStreamLogPath, line);
7645
7660
  } catch {
7646
7661
  }
7647
7662
  return true;
@@ -7681,13 +7696,12 @@ app11.post("/", requireAdminSession, async (c) => {
7681
7696
  },
7682
7697
  async start(controller) {
7683
7698
  let controllerOpen = true;
7684
- const sseEntry = { controller, conversationId: sseConvId ?? null, sessionKey: session_key };
7699
+ const sseEntry = { controller, conversationId, sessionKey: session_key };
7685
7700
  try {
7686
7701
  const reqSignal = c.req.raw?.signal;
7687
7702
  if (reqSignal) {
7688
7703
  reqSignal.addEventListener("abort", () => {
7689
- const abortLogKey = sseConvId ?? preflushStreamLogKey(session_key);
7690
- const abortStreamLog = agentLogStream("claude-agent-stream", account.accountDir, abortLogKey);
7704
+ const abortStreamLog = agentLogStream("claude-agent-stream", account.accountDir, conversationId);
7691
7705
  const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
7692
7706
  sseLog.write(`[${ts}] [${sk}] admin: ABORT [operator-cancel] interrupting pool client
7693
7707
  `);
@@ -7701,28 +7715,25 @@ app11.post("/", requireAdminSession, async (c) => {
7701
7715
  }
7702
7716
  try {
7703
7717
  registerAdminSSE(sseEntry);
7704
- if (sseConvId) {
7705
- const streamLogPath = resolve8(account.accountDir, "logs", `claude-agent-stream-${sseConvId}.log`);
7706
- tailer = startScriptStreamTailer({
7707
- path: streamLogPath,
7708
- onEvent: (event) => {
7709
- if (!controllerOpen) return;
7710
- const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
7711
- sseLog.write(`[${ts}] [${sk}] admin: ${JSON.stringify(event)}
7718
+ tailer = startScriptStreamTailer({
7719
+ path: teeStreamLogPath,
7720
+ onEvent: (event) => {
7721
+ if (!controllerOpen) return;
7722
+ const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
7723
+ sseLog.write(`[${ts}] [${sk}] admin: ${JSON.stringify(event)}
7712
7724
  `);
7713
- try {
7714
- controller.enqueue(encoder.encode(`data: ${JSON.stringify(event)}
7725
+ try {
7726
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(event)}
7715
7727
 
7716
7728
  `));
7717
- } catch {
7718
- controllerOpen = false;
7719
- }
7720
- },
7721
- onError: (err) => {
7722
- console.error(`[script-stream-tailer] ${streamLogPath}: ${err.message}`);
7729
+ } catch {
7730
+ controllerOpen = false;
7723
7731
  }
7724
- });
7725
- }
7732
+ },
7733
+ onError: (err) => {
7734
+ console.error(`[script-stream-tailer] ${teeStreamLogPath}: ${err.message}`);
7735
+ }
7736
+ });
7726
7737
  for await (const event of invokeAgent(
7727
7738
  { type: "admin", skipTopicCheck },
7728
7739
  message,
@@ -7831,42 +7842,8 @@ app12.post("/", requireAdminSession, async (c) => {
7831
7842
  var compact_default = app12;
7832
7843
 
7833
7844
  // server/routes/admin/logs.ts
7834
- import { existsSync as existsSync13, readdirSync as readdirSync5, readFileSync as readFileSync11, statSync as statSync6 } from "fs";
7845
+ import { existsSync as existsSync12, readdirSync as readdirSync5, readFileSync as readFileSync11, statSync as statSync6 } from "fs";
7835
7846
  import { resolve as resolve9, basename as basename2 } from "path";
7836
-
7837
- // app/lib/logs-read-resolve.ts
7838
- import { existsSync as existsSync12 } from "fs";
7839
- import { join as join9 } from "path";
7840
- function resolveConversationLogPaths(fullFilename, preflushFilename, logDirs) {
7841
- const tried = [fullFilename, preflushFilename];
7842
- const hits = [];
7843
- const stalePreflushPaths = [];
7844
- for (const dir of logDirs) {
7845
- const fullPath = join9(dir, fullFilename);
7846
- if (existsSync12(fullPath)) {
7847
- hits.push({ path: fullPath, shape: "full", dir });
7848
- const preflushSibling = join9(dir, preflushFilename);
7849
- if (existsSync12(preflushSibling)) {
7850
- stalePreflushPaths.push(preflushSibling);
7851
- }
7852
- }
7853
- }
7854
- if (hits.length > 0) {
7855
- return { hits, stalePreflushPaths, tried };
7856
- }
7857
- for (const dir of logDirs) {
7858
- const preflushPath = join9(dir, preflushFilename);
7859
- if (existsSync12(preflushPath)) {
7860
- hits.push({ path: preflushPath, shape: "preflush", dir });
7861
- }
7862
- }
7863
- return { hits, stalePreflushPaths, tried };
7864
- }
7865
- function preflushSliceOf(id) {
7866
- return `preflush-${id.slice(0, 12)}`;
7867
- }
7868
-
7869
- // server/routes/admin/logs.ts
7870
7847
  var TAIL_BYTES = 8192;
7871
7848
  var app13 = new Hono();
7872
7849
  app13.get("/", async (c) => {
@@ -7958,7 +7935,7 @@ app13.get("/", async (c) => {
7958
7935
  }
7959
7936
  const MISSING_SENTINEL = ".task702-identifier-not-supplied.log";
7960
7937
  const fullFilename = conversationId ? `${prefix}-${conversationId}.log` : MISSING_SENTINEL;
7961
- const preflushFilename = sessionKey ? `${prefix}-${preflushSliceOf(sessionKey)}.log` : MISSING_SENTINEL;
7938
+ const preflushFilename = sessionKey && typeParam === "public" ? `${prefix}-${preflushSliceOf(sessionKey)}.log` : MISSING_SENTINEL;
7962
7939
  const { hits, stalePreflushPaths, tried } = resolveConversationLogPaths(
7963
7940
  fullFilename,
7964
7941
  preflushFilename,
@@ -8015,7 +7992,7 @@ app13.get("/", async (c) => {
8015
7992
  const seen = /* @__PURE__ */ new Set();
8016
7993
  const logs = {};
8017
7994
  for (const dir of logDirs) {
8018
- if (!existsSync13(dir)) continue;
7995
+ if (!existsSync12(dir)) continue;
8019
7996
  let files;
8020
7997
  try {
8021
7998
  files = readdirSync5(dir).filter((f) => f.endsWith(".log"));
@@ -8066,7 +8043,7 @@ var claude_info_default = app14;
8066
8043
 
8067
8044
  // server/routes/admin/attachment.ts
8068
8045
  import { readFile as readFile2, readdir } from "fs/promises";
8069
- import { existsSync as existsSync14 } from "fs";
8046
+ import { existsSync as existsSync13 } from "fs";
8070
8047
  import { resolve as resolve10 } from "path";
8071
8048
  var app15 = new Hono();
8072
8049
  app15.get("/:attachmentId", requireAdminSession, async (c) => {
@@ -8080,11 +8057,11 @@ app15.get("/:attachmentId", requireAdminSession, async (c) => {
8080
8057
  return new Response("Not found", { status: 404 });
8081
8058
  }
8082
8059
  const dir = resolve10(ATTACHMENTS_ROOT, accountId, attachmentId);
8083
- if (!existsSync14(dir)) {
8060
+ if (!existsSync13(dir)) {
8084
8061
  return new Response("Not found", { status: 404 });
8085
8062
  }
8086
8063
  const metaPath = resolve10(dir, `${attachmentId}.meta.json`);
8087
- if (!existsSync14(metaPath)) {
8064
+ if (!existsSync13(metaPath)) {
8088
8065
  return new Response("Not found", { status: 404 });
8089
8066
  }
8090
8067
  let meta;
@@ -8112,13 +8089,13 @@ var attachment_default = app15;
8112
8089
 
8113
8090
  // server/routes/admin/agents.ts
8114
8091
  import { resolve as resolve11 } from "path";
8115
- import { readdirSync as readdirSync6, readFileSync as readFileSync12, existsSync as existsSync15, rmSync } from "fs";
8092
+ import { readdirSync as readdirSync6, readFileSync as readFileSync12, existsSync as existsSync14, rmSync } from "fs";
8116
8093
  var app16 = new Hono();
8117
8094
  app16.get("/", (c) => {
8118
8095
  const account = resolveAccount();
8119
8096
  if (!account) return c.json({ agents: [] });
8120
8097
  const agentsDir = resolve11(account.accountDir, "agents");
8121
- if (!existsSync15(agentsDir)) return c.json({ agents: [] });
8098
+ if (!existsSync14(agentsDir)) return c.json({ agents: [] });
8122
8099
  const agents = [];
8123
8100
  try {
8124
8101
  const entries = readdirSync6(agentsDir, { withFileTypes: true });
@@ -8126,7 +8103,7 @@ app16.get("/", (c) => {
8126
8103
  if (!entry.isDirectory()) continue;
8127
8104
  if (entry.name === "admin") continue;
8128
8105
  const configPath2 = resolve11(agentsDir, entry.name, "config.json");
8129
- if (!existsSync15(configPath2)) continue;
8106
+ if (!existsSync14(configPath2)) continue;
8130
8107
  try {
8131
8108
  const config = JSON.parse(readFileSync12(configPath2, "utf-8"));
8132
8109
  agents.push({
@@ -8155,7 +8132,7 @@ app16.delete("/:slug", async (c) => {
8155
8132
  return c.json({ error: "Invalid agent slug" }, 400);
8156
8133
  }
8157
8134
  const agentDir = resolve11(account.accountDir, "agents", slug);
8158
- if (!existsSync15(agentDir)) {
8135
+ if (!existsSync14(agentDir)) {
8159
8136
  return c.json({ error: "Agent not found" }, 404);
8160
8137
  }
8161
8138
  try {
@@ -8185,7 +8162,7 @@ app16.post("/:slug/project", async (c) => {
8185
8162
  return c.json({ error: "Invalid agent slug" }, 400);
8186
8163
  }
8187
8164
  const agentDir = resolve11(account.accountDir, "agents", slug);
8188
- if (!existsSync15(agentDir)) {
8165
+ if (!existsSync14(agentDir)) {
8189
8166
  return c.json({ error: "Agent not found on disk" }, 404);
8190
8167
  }
8191
8168
  try {
@@ -8201,7 +8178,7 @@ var agents_default = app16;
8201
8178
  // server/routes/admin/sessions.ts
8202
8179
  import crypto2 from "crypto";
8203
8180
  import { resolve as resolvePath } from "path";
8204
- import { appendFileSync as appendFileSync4, existsSync as existsSync17 } from "fs";
8181
+ import { appendFileSync as appendFileSync4, existsSync as existsSync16 } from "fs";
8205
8182
 
8206
8183
  // app/lib/synthetic-marker.ts
8207
8184
  var CLOUDFLARE_MARKER_PREFIX = "Cloudflare setup completed (actionId: ";
@@ -8213,9 +8190,9 @@ function isSyntheticUserMarker(content) {
8213
8190
  }
8214
8191
 
8215
8192
  // app/lib/claude-agent/jsonl-replay.ts
8216
- import { existsSync as existsSync16, readFileSync as readFileSync13 } from "fs";
8193
+ import { existsSync as existsSync15, readFileSync as readFileSync13 } from "fs";
8217
8194
  function replayJsonl(jsonlPath) {
8218
- if (!existsSync16(jsonlPath)) {
8195
+ if (!existsSync15(jsonlPath)) {
8219
8196
  return { messages: [], jsonlMissing: true, malformedLines: 0 };
8220
8197
  }
8221
8198
  let raw;
@@ -8349,7 +8326,7 @@ function validateAndShapeAttachments(raws, conversationAccountId, conversationId
8349
8326
  let reason = null;
8350
8327
  if (!a.attachmentId || !a.filename || !a.mimeType || !a.storagePath) reason = "schema-fail";
8351
8328
  else if (a.accountId !== conversationAccountId) reason = "account-mismatch";
8352
- else if (!existsSync17(a.storagePath)) reason = "missing-file";
8329
+ else if (!existsSync16(a.storagePath)) reason = "missing-file";
8353
8330
  if (reason) {
8354
8331
  invalid++;
8355
8332
  try {
@@ -9125,12 +9102,12 @@ function isValidDomain(value) {
9125
9102
  }
9126
9103
 
9127
9104
  // app/lib/alias-domains.ts
9128
- import { existsSync as existsSync18, mkdirSync as mkdirSync6, readFileSync as readFileSync14, writeFileSync as writeFileSync7 } from "fs";
9105
+ import { existsSync as existsSync17, mkdirSync as mkdirSync6, readFileSync as readFileSync14, writeFileSync as writeFileSync7 } from "fs";
9129
9106
  import { dirname as dirname5 } from "path";
9130
9107
  import { resolve as resolve12 } from "path";
9131
9108
  var ALIAS_DOMAINS_PATH = resolve12(MAXY_DIR, "alias-domains.json");
9132
9109
  function readExisting() {
9133
- if (!existsSync18(ALIAS_DOMAINS_PATH)) return /* @__PURE__ */ new Set();
9110
+ if (!existsSync17(ALIAS_DOMAINS_PATH)) return /* @__PURE__ */ new Set();
9134
9111
  try {
9135
9112
  const parsed = JSON.parse(readFileSync14(ALIAS_DOMAINS_PATH, "utf-8"));
9136
9113
  if (!Array.isArray(parsed)) return /* @__PURE__ */ new Set();
@@ -9378,8 +9355,8 @@ app22.get("/tunnels", requireAdminSession, async (c) => {
9378
9355
  if (!correlationId) return err("session", "No active conversation for session \u2014 refresh chat.");
9379
9356
  streamLogPath = streamLogPathFor(accountId, correlationId).streamLogPath;
9380
9357
  const certPath = resolve13(homedir2(), brand.configDir, "cloudflared", "cert.pem");
9381
- const { existsSync: existsSync25 } = await import("fs");
9382
- if (!existsSync25(certPath)) {
9358
+ const { existsSync: existsSync24 } = await import("fs");
9359
+ if (!existsSync24(certPath)) {
9383
9360
  return err("cert", `Cloudflare origin certificate is not on disk yet (${certPath}). Complete the Cloudflare login first by submitting the form once \u2014 the OAuth flow writes cert.pem.`);
9384
9361
  }
9385
9362
  const result = await runFormSpawn({
@@ -9677,7 +9654,7 @@ var cloudflare_default = app22;
9677
9654
  import { createReadStream as createReadStream3 } from "fs";
9678
9655
  import { readdir as readdir2, readFile as readFile3, stat as stat3, mkdir as mkdir2, writeFile as writeFile3, unlink as unlink2 } from "fs/promises";
9679
9656
  import { realpathSync as realpathSync3 } from "fs";
9680
- import { basename as basename3, dirname as dirname6, join as join10, resolve as resolve15, sep as sep2 } from "path";
9657
+ import { basename as basename3, dirname as dirname6, join as join9, resolve as resolve15, sep as sep2 } from "path";
9681
9658
  import { Readable as Readable2 } from "stream";
9682
9659
 
9683
9660
  // app/lib/data-path.ts
@@ -10035,7 +10012,7 @@ async function cascadeDeleteDocument(params) {
10035
10012
  var UUID_RE4 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10036
10013
  async function readMeta(absDir, baseName) {
10037
10014
  try {
10038
- const raw = await readFile3(join10(absDir, `${baseName}.meta.json`), "utf8");
10015
+ const raw = await readFile3(join9(absDir, `${baseName}.meta.json`), "utf8");
10039
10016
  const parsed = JSON.parse(raw);
10040
10017
  if (typeof parsed?.filename === "string") {
10041
10018
  return { filename: parsed.filename, mimeType: typeof parsed.mimeType === "string" ? parsed.mimeType : void 0 };
@@ -10073,7 +10050,7 @@ async function readAccountNames() {
10073
10050
  }
10074
10051
  async function enrich(absolute, entry, accountNames) {
10075
10052
  if (entry.kind === "directory" && UUID_RE4.test(entry.name)) {
10076
- const meta = await readMeta(join10(absolute, entry.name), entry.name);
10053
+ const meta = await readMeta(join9(absolute, entry.name), entry.name);
10077
10054
  if (meta?.filename) {
10078
10055
  entry.displayName = meta.filename;
10079
10056
  entry.mimeType = meta.mimeType;
@@ -10132,7 +10109,7 @@ app23.get("/", requireAdminSession, async (c) => {
10132
10109
  continue;
10133
10110
  }
10134
10111
  try {
10135
- const entryPath = join10(absolute, name);
10112
+ const entryPath = join9(absolute, name);
10136
10113
  const s = await stat3(entryPath);
10137
10114
  entries.push({
10138
10115
  name,
@@ -10305,7 +10282,7 @@ app23.delete("/", requireAdminSession, async (c) => {
10305
10282
  }
10306
10283
  const dot = base.lastIndexOf(".");
10307
10284
  const stem = dot === -1 ? base : base.slice(0, dot);
10308
- const sidecarPath = UUID_RE4.test(stem) && base !== `${stem}.meta.json` ? join10(dirname6(absolute), `${stem}.meta.json`) : null;
10285
+ const sidecarPath = UUID_RE4.test(stem) && base !== `${stem}.meta.json` ? join9(dirname6(absolute), `${stem}.meta.json`) : null;
10309
10286
  await unlink2(absolute);
10310
10287
  if (sidecarPath) {
10311
10288
  try {
@@ -11927,7 +11904,7 @@ var adherence_default = app31;
11927
11904
  import neo4j3 from "neo4j-driver";
11928
11905
  import { readFile as readFile4, readdir as readdir3, stat as stat4 } from "fs/promises";
11929
11906
  import { resolve as resolve16, relative as relative2, isAbsolute } from "path";
11930
- import { existsSync as existsSync19 } from "fs";
11907
+ import { existsSync as existsSync18 } from "fs";
11931
11908
  var LIMIT = 50;
11932
11909
  var TEXT_MIME_PREFIXES = ["text/", "application/json", "application/markdown"];
11933
11910
  var ADMIN_AGENT_FILES = ["IDENTITY.md", "SOUL.md", "KNOWLEDGE.md"];
@@ -12075,7 +12052,7 @@ async function fetchAgentTemplateRows(accountDir) {
12075
12052
  async function unionSpecialistFilenames(overrideDir, bundledDir) {
12076
12053
  const names = /* @__PURE__ */ new Set();
12077
12054
  for (const dir of [overrideDir, bundledDir]) {
12078
- if (!existsSync19(dir)) continue;
12055
+ if (!existsSync18(dir)) continue;
12079
12056
  try {
12080
12057
  const entries = await readdir3(dir);
12081
12058
  for (const entry of entries) {
@@ -12090,7 +12067,7 @@ async function unionSpecialistFilenames(overrideDir, bundledDir) {
12090
12067
  }
12091
12068
  async function readAgentTemplateRow(inp) {
12092
12069
  let chosenPath = null;
12093
- if (existsSync19(inp.overridePath)) {
12070
+ if (existsSync18(inp.overridePath)) {
12094
12071
  try {
12095
12072
  validateFilePathInAccount(inp.overridePath, inp.overrideRoot);
12096
12073
  chosenPath = inp.overridePath;
@@ -12101,7 +12078,7 @@ async function readAgentTemplateRow(inp) {
12101
12078
  );
12102
12079
  return null;
12103
12080
  }
12104
- } else if (existsSync19(inp.bundledPath)) {
12081
+ } else if (existsSync18(inp.bundledPath)) {
12105
12082
  if (!isWithin(inp.bundledPath, inp.bundledRoot)) {
12106
12083
  console.error(
12107
12084
  `[admin/sidebar-artefacts] agent-template-read-failed agent=${inp.displayName} kind=${inp.logName} error="bundled path outside PLATFORM_ROOT"`
@@ -12143,7 +12120,7 @@ var sidebar_artefacts_default = app32;
12143
12120
  // server/routes/admin/sidebar-artefact-save.ts
12144
12121
  import { mkdir as mkdir3, readdir as readdir4, stat as stat5, writeFile as writeFile4 } from "fs/promises";
12145
12122
  import { resolve as resolve17 } from "path";
12146
- import { existsSync as existsSync20 } from "fs";
12123
+ import { existsSync as existsSync19 } from "fs";
12147
12124
  var ADMIN_AGENT_FILES2 = /* @__PURE__ */ new Set(["IDENTITY.md", "SOUL.md", "KNOWLEDGE.md"]);
12148
12125
  var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
12149
12126
  var app33 = new Hono();
@@ -12207,7 +12184,7 @@ async function resolveSavePath(id, accountId, accountDir) {
12207
12184
  }
12208
12185
  if (UUID_RE5.test(id)) {
12209
12186
  const dir = resolve17(ATTACHMENTS_ROOT, accountId, id);
12210
- if (!existsSync20(dir)) {
12187
+ if (!existsSync19(dir)) {
12211
12188
  return { kind: "reject", status: 400, reason: "not-found" };
12212
12189
  }
12213
12190
  try {
@@ -12231,7 +12208,7 @@ var sidebar_artefact_save_default = app33;
12231
12208
 
12232
12209
  // server/routes/admin/sidebar-artefact-content.ts
12233
12210
  import { readFile as readFile5, readdir as readdir5 } from "fs/promises";
12234
- import { existsSync as existsSync21 } from "fs";
12211
+ import { existsSync as existsSync20 } from "fs";
12235
12212
  import { resolve as resolve18 } from "path";
12236
12213
  var UUID_RE6 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
12237
12214
  var app34 = new Hono();
@@ -12245,7 +12222,7 @@ app34.get("/", requireAdminSession, async (c) => {
12245
12222
  return new Response("Not found", { status: 404 });
12246
12223
  }
12247
12224
  const dir = resolve18(ATTACHMENTS_ROOT, accountId, id);
12248
- if (!existsSync21(dir)) {
12225
+ if (!existsSync20(dir)) {
12249
12226
  console.error(`[admin/sidebar-artefact-content] not-found id=${id.slice(0, 8)}`);
12250
12227
  return new Response("Not found", { status: 404 });
12251
12228
  }
@@ -12279,12 +12256,12 @@ app34.get("/", requireAdminSession, async (c) => {
12279
12256
  var sidebar_artefact_content_default = app34;
12280
12257
 
12281
12258
  // server/routes/admin/health.ts
12282
- import { existsSync as existsSync22, readFileSync as readFileSync16 } from "fs";
12283
- import { resolve as resolve19, join as join11 } from "path";
12259
+ import { existsSync as existsSync21, readFileSync as readFileSync16 } from "fs";
12260
+ import { resolve as resolve19, join as join10 } from "path";
12284
12261
  var PLATFORM_ROOT6 = process.env.MAXY_PLATFORM_ROOT ?? resolve19(process.cwd(), "..");
12285
12262
  var brandHostname = "maxy";
12286
- var brandJsonPath = join11(PLATFORM_ROOT6, "config", "brand.json");
12287
- if (existsSync22(brandJsonPath)) {
12263
+ var brandJsonPath = join10(PLATFORM_ROOT6, "config", "brand.json");
12264
+ if (existsSync21(brandJsonPath)) {
12288
12265
  try {
12289
12266
  const brand = JSON.parse(readFileSync16(brandJsonPath, "utf-8"));
12290
12267
  if (brand.hostname) brandHostname = brand.hostname;
@@ -12295,7 +12272,7 @@ var VERSION_FILE = resolve19(PLATFORM_ROOT6, `config/.${brandHostname}-version`)
12295
12272
  var PROCESS_STARTED_AT = (/* @__PURE__ */ new Date()).toISOString();
12296
12273
  var PROBE_TIMEOUT_MS = 1e3;
12297
12274
  function readVersion() {
12298
- if (!existsSync22(VERSION_FILE)) return "unknown";
12275
+ if (!existsSync21(VERSION_FILE)) return "unknown";
12299
12276
  return readFileSync16(VERSION_FILE, "utf-8").trim() || "unknown";
12300
12277
  }
12301
12278
  async function probeConversationDb() {
@@ -12377,7 +12354,7 @@ app36.route("/health-brand", health_default2);
12377
12354
  var admin_default = app36;
12378
12355
 
12379
12356
  // server/routes/sites.ts
12380
- import { existsSync as existsSync23, readFileSync as readFileSync17, realpathSync as realpathSync4, statSync as statSync7 } from "fs";
12357
+ import { existsSync as existsSync22, readFileSync as readFileSync17, realpathSync as realpathSync4, statSync as statSync7 } from "fs";
12381
12358
  import { resolve as resolve20 } from "path";
12382
12359
  var SAFE_SEG_RE = /^[a-z0-9_][a-z0-9_.-]{0,99}$/i;
12383
12360
  var MIME = {
@@ -12443,7 +12420,7 @@ app37.get("/:rel{.*}", (c) => {
12443
12420
  }
12444
12421
  let stat6;
12445
12422
  try {
12446
- stat6 = existsSync23(filePath) ? statSync7(filePath) : null;
12423
+ stat6 = existsSync22(filePath) ? statSync7(filePath) : null;
12447
12424
  } catch {
12448
12425
  stat6 = null;
12449
12426
  }
@@ -12462,7 +12439,7 @@ app37.get("/:rel{.*}", (c) => {
12462
12439
  console.error(`[sites] path-traversal-rejected path=${reqPath} reason=escape status=403`);
12463
12440
  return c.text("Forbidden", 403);
12464
12441
  }
12465
- if (!existsSync23(filePath)) {
12442
+ if (!existsSync22(filePath)) {
12466
12443
  console.error(`[sites] not-found path=${reqPath} status=404`);
12467
12444
  return c.text("Not found", 404);
12468
12445
  }
@@ -12613,12 +12590,12 @@ function clientFrom(c) {
12613
12590
  );
12614
12591
  }
12615
12592
  var PLATFORM_ROOT7 = process.env.MAXY_PLATFORM_ROOT || "";
12616
- var BRAND_JSON_PATH = PLATFORM_ROOT7 ? join12(PLATFORM_ROOT7, "config", "brand.json") : "";
12593
+ var BRAND_JSON_PATH = PLATFORM_ROOT7 ? join11(PLATFORM_ROOT7, "config", "brand.json") : "";
12617
12594
  var BRAND = { productName: "Maxy", hostname: "maxy", configDir: ".maxy", domain: "getmaxy.com" };
12618
- if (BRAND_JSON_PATH && !existsSync24(BRAND_JSON_PATH)) {
12595
+ if (BRAND_JSON_PATH && !existsSync23(BRAND_JSON_PATH)) {
12619
12596
  console.error(`[brand] WARNING: brand.json not found at ${BRAND_JSON_PATH} \u2014 using Maxy defaults`);
12620
12597
  }
12621
- if (BRAND_JSON_PATH && existsSync24(BRAND_JSON_PATH)) {
12598
+ if (BRAND_JSON_PATH && existsSync23(BRAND_JSON_PATH)) {
12622
12599
  try {
12623
12600
  const parsed = JSON.parse(readFileSync18(BRAND_JSON_PATH, "utf-8"));
12624
12601
  BRAND = { ...BRAND, ...parsed };
@@ -12639,10 +12616,10 @@ var brandLoginOpts = {
12639
12616
  bodyFont: BRAND.defaultFonts?.body,
12640
12617
  logoContainsName: !!BRAND.logoContainsName
12641
12618
  };
12642
- var ALIAS_DOMAINS_PATH2 = join12(homedir3(), BRAND.configDir, "alias-domains.json");
12619
+ var ALIAS_DOMAINS_PATH2 = join11(homedir3(), BRAND.configDir, "alias-domains.json");
12643
12620
  function loadAliasDomains() {
12644
12621
  try {
12645
- if (!existsSync24(ALIAS_DOMAINS_PATH2)) return null;
12622
+ if (!existsSync23(ALIAS_DOMAINS_PATH2)) return null;
12646
12623
  const parsed = JSON.parse(readFileSync18(ALIAS_DOMAINS_PATH2, "utf-8"));
12647
12624
  if (!Array.isArray(parsed)) {
12648
12625
  console.error("[alias-domains] malformed alias-domains.json \u2014 expected array");
@@ -13015,7 +12992,7 @@ app38.get("/agent-assets/:slug/:filename", (c) => {
13015
12992
  console.error(`[agent-assets] path-traversal-rejected slug=${slug} file=${filename}`);
13016
12993
  return c.text("Forbidden", 403);
13017
12994
  }
13018
- if (!existsSync24(filePath)) {
12995
+ if (!existsSync23(filePath)) {
13019
12996
  console.error(`[agent-assets] serve slug=${slug} file=${filename} status=404`);
13020
12997
  return c.text("Not found", 404);
13021
12998
  }
@@ -13045,7 +13022,7 @@ app38.get("/generated/:filename", (c) => {
13045
13022
  console.error(`[generated] serve file=${filename} status=403`);
13046
13023
  return c.text("Forbidden", 403);
13047
13024
  }
13048
- if (!existsSync24(filePath)) {
13025
+ if (!existsSync23(filePath)) {
13049
13026
  console.error(`[generated] serve file=${filename} status=404`);
13050
13027
  return c.text("Not found", 404);
13051
13028
  }
@@ -13062,7 +13039,7 @@ app38.route("/sites", sites_default);
13062
13039
  var htmlCache = /* @__PURE__ */ new Map();
13063
13040
  var brandLogoPath = "/brand/maxy-monochrome.png";
13064
13041
  var brandIconPath = "/brand/maxy-monochrome.png";
13065
- if (BRAND_JSON_PATH && existsSync24(BRAND_JSON_PATH)) {
13042
+ if (BRAND_JSON_PATH && existsSync23(BRAND_JSON_PATH)) {
13066
13043
  try {
13067
13044
  const fullBrand = JSON.parse(readFileSync18(BRAND_JSON_PATH, "utf-8"));
13068
13045
  if (fullBrand.assets?.logo) brandLogoPath = `/brand/${fullBrand.assets.logo}`;
@@ -13081,8 +13058,8 @@ var brandScript = `<script>window.__BRAND__=${JSON.stringify({
13081
13058
  function readInstalledVersion() {
13082
13059
  try {
13083
13060
  if (!PLATFORM_ROOT7) return "unknown";
13084
- const versionFile = join12(PLATFORM_ROOT7, "config", `.${BRAND.hostname}-version`);
13085
- if (!existsSync24(versionFile)) return "unknown";
13061
+ const versionFile = join11(PLATFORM_ROOT7, "config", `.${BRAND.hostname}-version`);
13062
+ if (!existsSync23(versionFile)) return "unknown";
13086
13063
  const content = readFileSync18(versionFile, "utf-8").trim();
13087
13064
  return content || "unknown";
13088
13065
  } catch {
@@ -13140,15 +13117,15 @@ ${clientErrorReporterScript}
13140
13117
  }
13141
13118
  var brandedHtmlCache = /* @__PURE__ */ new Map();
13142
13119
  function loadBrandingCache(agentSlug) {
13143
- const configDir2 = join12(homedir3(), BRAND.configDir);
13120
+ const configDir2 = join11(homedir3(), BRAND.configDir);
13144
13121
  try {
13145
- const accountJsonPath = join12(configDir2, "account.json");
13146
- if (!existsSync24(accountJsonPath)) return null;
13122
+ const accountJsonPath = join11(configDir2, "account.json");
13123
+ if (!existsSync23(accountJsonPath)) return null;
13147
13124
  const account = JSON.parse(readFileSync18(accountJsonPath, "utf-8"));
13148
13125
  const accountId = account.accountId;
13149
13126
  if (!accountId) return null;
13150
- const cachePath = join12(configDir2, "branding-cache", accountId, `${agentSlug}.json`);
13151
- if (!existsSync24(cachePath)) return null;
13127
+ const cachePath = join11(configDir2, "branding-cache", accountId, `${agentSlug}.json`);
13128
+ if (!existsSync23(cachePath)) return null;
13152
13129
  return JSON.parse(readFileSync18(cachePath, "utf-8"));
13153
13130
  } catch {
13154
13131
  return null;
@@ -13156,9 +13133,9 @@ function loadBrandingCache(agentSlug) {
13156
13133
  }
13157
13134
  function resolveDefaultSlug() {
13158
13135
  try {
13159
- const configDir2 = join12(homedir3(), BRAND.configDir);
13160
- const accountJsonPath = join12(configDir2, "account.json");
13161
- if (!existsSync24(accountJsonPath)) return null;
13136
+ const configDir2 = join11(homedir3(), BRAND.configDir);
13137
+ const accountJsonPath = join11(configDir2, "account.json");
13138
+ if (!existsSync23(accountJsonPath)) return null;
13162
13139
  const account = JSON.parse(readFileSync18(accountJsonPath, "utf-8"));
13163
13140
  return account.defaultAgent || null;
13164
13141
  } catch {
@@ -13338,7 +13315,7 @@ try {
13338
13315
  (async () => {
13339
13316
  try {
13340
13317
  let userId = "";
13341
- if (existsSync24(USERS_FILE)) {
13318
+ if (existsSync23(USERS_FILE)) {
13342
13319
  const users = JSON.parse(readFileSync18(USERS_FILE, "utf-8").trim() || "[]");
13343
13320
  userId = users[0]?.userId ?? "";
13344
13321
  }
@@ -13349,7 +13326,7 @@ try {
13349
13326
  })();
13350
13327
  (async () => {
13351
13328
  try {
13352
- if (!existsSync24(USERS_FILE)) return;
13329
+ if (!existsSync23(USERS_FILE)) return;
13353
13330
  const usersRaw = readFileSync18(USERS_FILE, "utf-8").trim();
13354
13331
  if (!usersRaw) return;
13355
13332
  const users = JSON.parse(usersRaw);
@@ -13401,7 +13378,7 @@ autoDeliverPremiumPlugins(bootEntitlement?.purchasedPlugins ?? void 0);
13401
13378
  (async () => {
13402
13379
  if (!bootAccount) return;
13403
13380
  try {
13404
- const { recoverRunningCloudflareTasks } = await import("./cloudflare-task-tracker-OOQCL5ZB.js");
13381
+ const { recoverRunningCloudflareTasks } = await import("./cloudflare-task-tracker-OCFIVXEJ.js");
13405
13382
  const result = await recoverRunningCloudflareTasks(
13406
13383
  bootAccount.accountId,
13407
13384
  configDirForWhatsApp,
@@ -13451,7 +13428,7 @@ if (bootAccountConfig?.whatsapp) {
13451
13428
  }
13452
13429
  init({
13453
13430
  configDir: configDirForWhatsApp,
13454
- platformRoot: resolve21(process.env.MAXY_PLATFORM_ROOT ?? join12(__dirname, "..")),
13431
+ platformRoot: resolve21(process.env.MAXY_PLATFORM_ROOT ?? join11(__dirname, "..")),
13455
13432
  accountConfig: bootAccountConfig,
13456
13433
  onMessage: async (msg) => {
13457
13434
  try {