@rubytech/create-maxy 1.0.831 → 1.0.832
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/package.json +1 -1
- package/payload/platform/neo4j/migrations/004-project-admin-agent.ts +36 -3
- package/payload/platform/plugins/memory/bin/conversation-archive-ingest.mjs +253 -110
- package/payload/platform/plugins/memory/bin/conversation-archive-ingest.sh +41 -14
- package/payload/platform/plugins/memory/mcp/dist/lib/uuid.d.ts +3 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/uuid.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/uuid.js +12 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/uuid.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.d.ts +11 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.js +17 -9
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.js.map +1 -1
- package/payload/platform/plugins/memory/skills/conversation-archive/SKILL.md +41 -9
- package/payload/platform/scripts/lib/resolve-account-dir.sh +19 -1
- package/payload/server/chunk-25QDCOE5.js +1116 -0
- package/payload/server/chunk-35YZS3KL.js +328 -0
- package/payload/server/chunk-7CBRZKZS.js +654 -0
- package/payload/server/chunk-IXOPV36P.js +2305 -0
- package/payload/server/chunk-ZKGAYLAK.js +10097 -0
- package/payload/server/client-pool-NBVGONQL.js +32 -0
- package/payload/server/cloudflare-task-tracker-R4FIORFL.js +19 -0
- package/payload/server/maxy-edge.js +4 -4
- package/payload/server/neo4j-migrations-3A6K2EB5.js +552 -0
- package/payload/server/server.js +19 -7
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
_evictAllForTest,
|
|
3
|
+
_poolSnapshotForTest,
|
|
4
|
+
acquireClient,
|
|
5
|
+
acquireOneShotClient,
|
|
6
|
+
evictClient,
|
|
7
|
+
getActiveClient,
|
|
8
|
+
interruptClient,
|
|
9
|
+
pushUserMessage,
|
|
10
|
+
recordCachedTokens,
|
|
11
|
+
recordCrash,
|
|
12
|
+
setInflight,
|
|
13
|
+
startIdleEvictTick,
|
|
14
|
+
stopIdleEvictTick
|
|
15
|
+
} from "./chunk-25QDCOE5.js";
|
|
16
|
+
import "./chunk-35YZS3KL.js";
|
|
17
|
+
import "./chunk-IXOPV36P.js";
|
|
18
|
+
export {
|
|
19
|
+
_evictAllForTest,
|
|
20
|
+
_poolSnapshotForTest,
|
|
21
|
+
acquireClient,
|
|
22
|
+
acquireOneShotClient,
|
|
23
|
+
evictClient,
|
|
24
|
+
getActiveClient,
|
|
25
|
+
interruptClient,
|
|
26
|
+
pushUserMessage,
|
|
27
|
+
recordCachedTokens,
|
|
28
|
+
recordCrash,
|
|
29
|
+
setInflight,
|
|
30
|
+
startIdleEvictTick,
|
|
31
|
+
stopIdleEvictTick
|
|
32
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLOUDFLARE_TASK_DIAGNOSTICS,
|
|
3
|
+
appendCloudflareSteps,
|
|
4
|
+
completeCloudflareTask,
|
|
5
|
+
openCloudflareTask,
|
|
6
|
+
readTunnelState,
|
|
7
|
+
recoverRunningCloudflareTasks,
|
|
8
|
+
resolveUnitGoneVerdict
|
|
9
|
+
} from "./chunk-7CBRZKZS.js";
|
|
10
|
+
import "./chunk-IXOPV36P.js";
|
|
11
|
+
export {
|
|
12
|
+
CLOUDFLARE_TASK_DIAGNOSTICS,
|
|
13
|
+
appendCloudflareSteps,
|
|
14
|
+
completeCloudflareTask,
|
|
15
|
+
openCloudflareTask,
|
|
16
|
+
readTunnelState,
|
|
17
|
+
recoverRunningCloudflareTasks,
|
|
18
|
+
resolveUnitGoneVerdict
|
|
19
|
+
};
|
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
sanitizeClientCorrId,
|
|
17
17
|
streamActionEvents,
|
|
18
18
|
vncLog
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import "./chunk-
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
19
|
+
} from "./chunk-ZKGAYLAK.js";
|
|
20
|
+
import "./chunk-25QDCOE5.js";
|
|
21
|
+
import "./chunk-35YZS3KL.js";
|
|
22
|
+
import "./chunk-IXOPV36P.js";
|
|
23
23
|
|
|
24
24
|
// server/edge.ts
|
|
25
25
|
import { createServer, request as httpRequest } from "http";
|
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACCOUNTS_DIR
|
|
3
|
+
} from "./chunk-35YZS3KL.js";
|
|
4
|
+
import {
|
|
5
|
+
getSession,
|
|
6
|
+
projectAgent
|
|
7
|
+
} from "./chunk-IXOPV36P.js";
|
|
8
|
+
|
|
9
|
+
// app/lib/neo4j-migrations.ts
|
|
10
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
11
|
+
import { resolve as resolve4 } from "path";
|
|
12
|
+
|
|
13
|
+
// ../neo4j/migrations/004-prune-alien-accounts.ts
|
|
14
|
+
import { readFileSync, readdirSync } from "fs";
|
|
15
|
+
import { resolve } from "path";
|
|
16
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
17
|
+
async function pruneAlienAccounts(driver, platformRoot) {
|
|
18
|
+
const accountsDir = resolve(platformRoot, "..", "data", "accounts");
|
|
19
|
+
const validIds = enumerateValidAccountIds(accountsDir);
|
|
20
|
+
if (validIds.size === 0) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`refusing to prune: no valid accounts found under ${accountsDir} \u2014 corrupt install? not deleting anything to avoid wiping the entire graph.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
const valid = Array.from(validIds);
|
|
26
|
+
const session = driver.session();
|
|
27
|
+
try {
|
|
28
|
+
const peek = await session.run(
|
|
29
|
+
`MATCH (n)
|
|
30
|
+
WHERE n.accountId IS NOT NULL AND NOT n.accountId IN $valid
|
|
31
|
+
RETURN DISTINCT n.accountId AS aid`,
|
|
32
|
+
{ valid }
|
|
33
|
+
);
|
|
34
|
+
const alienIds = [];
|
|
35
|
+
for (const record of peek.records) {
|
|
36
|
+
const aid = record.get("aid");
|
|
37
|
+
if (typeof aid === "string") alienIds.push(aid);
|
|
38
|
+
}
|
|
39
|
+
if (alienIds.length === 0) return;
|
|
40
|
+
const result = await session.run(
|
|
41
|
+
`MATCH (n)
|
|
42
|
+
WHERE n.accountId IS NOT NULL AND NOT n.accountId IN $valid
|
|
43
|
+
DETACH DELETE n
|
|
44
|
+
RETURN count(n) AS pruned`,
|
|
45
|
+
{ valid }
|
|
46
|
+
);
|
|
47
|
+
const prunedRaw = result.records[0]?.get("pruned");
|
|
48
|
+
const pruned = typeof prunedRaw === "number" ? prunedRaw : prunedRaw?.toNumber?.() ?? 0;
|
|
49
|
+
console.error(
|
|
50
|
+
`[graph-invariant] alien-accounts pruned=${pruned} accountIds=${alienIds.join(",")}`
|
|
51
|
+
);
|
|
52
|
+
} finally {
|
|
53
|
+
await session.close();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function enumerateValidAccountIds(accountsDir) {
|
|
57
|
+
const valid = /* @__PURE__ */ new Set();
|
|
58
|
+
let names;
|
|
59
|
+
try {
|
|
60
|
+
names = readdirSync(accountsDir);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
if (err.code === "ENOENT") return valid;
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
for (const name of names) {
|
|
66
|
+
if (!UUID_RE.test(name)) continue;
|
|
67
|
+
const configPath = resolve(accountsDir, name, "account.json");
|
|
68
|
+
try {
|
|
69
|
+
JSON.parse(readFileSync(configPath, "utf-8"));
|
|
70
|
+
valid.add(name);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
const code = err.code ?? "parse-error";
|
|
73
|
+
if (code === "ENOENT") continue;
|
|
74
|
+
console.error(
|
|
75
|
+
`[graph-invariant] account-json-skip uuid=${name} reason=${code}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return valid;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ../neo4j/migrations/004-project-admin-agent.ts
|
|
83
|
+
import { existsSync, readFileSync as readFileSync2, readdirSync as readdirSync2 } from "fs";
|
|
84
|
+
import { resolve as resolve2 } from "path";
|
|
85
|
+
function readValidAccountDirs(accountsDir) {
|
|
86
|
+
const valid = [];
|
|
87
|
+
const entries = readdirSync2(accountsDir, { withFileTypes: true }).filter((e) => e.isDirectory()).filter((e) => !e.name.startsWith("."));
|
|
88
|
+
for (const e of entries) {
|
|
89
|
+
const configPath = resolve2(accountsDir, e.name, "account.json");
|
|
90
|
+
if (!existsSync(configPath)) {
|
|
91
|
+
console.error(
|
|
92
|
+
`[platform] accounts-state STUB-DIR id=${e.name} \u2014 onboarding leak; remove or repair`
|
|
93
|
+
);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
JSON.parse(readFileSync2(configPath, "utf-8"));
|
|
98
|
+
valid.push(e.name);
|
|
99
|
+
} catch {
|
|
100
|
+
console.error(
|
|
101
|
+
`[platform] accounts-state CORRUPT-JSON id=${e.name} \u2014 account.json failed to parse`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return valid;
|
|
106
|
+
}
|
|
107
|
+
async function projectAccountAdmin(accountId, accountDir) {
|
|
108
|
+
const adminDir = resolve2(accountDir, "agents", "admin");
|
|
109
|
+
const configPath = resolve2(adminDir, "config.json");
|
|
110
|
+
if (!existsSync(adminDir) || !existsSync(configPath)) {
|
|
111
|
+
return { projected: 0, failed: 0 };
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
await projectAgent(accountId, accountDir, "admin");
|
|
115
|
+
return { projected: 1, failed: 0 };
|
|
116
|
+
} catch (err) {
|
|
117
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
118
|
+
console.error(
|
|
119
|
+
`[admin-agent-graph-backfill] account=${accountId.slice(0, 8)} project FAILED error="${msg}"`
|
|
120
|
+
);
|
|
121
|
+
return { projected: 0, failed: 1 };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function backfillAdminHandledBy(driver, accountId) {
|
|
125
|
+
const session = driver.session();
|
|
126
|
+
try {
|
|
127
|
+
const result = await session.run(
|
|
128
|
+
`MATCH (c:AdminConversation {accountId: $accountId})
|
|
129
|
+
WHERE NOT EXISTS((c)-[:HANDLED_BY]->(:Agent))
|
|
130
|
+
OPTIONAL MATCH (a:Agent {accountId: $accountId, slug: 'admin'})
|
|
131
|
+
FOREACH (_ IN CASE WHEN a IS NULL THEN [] ELSE [1] END | MERGE (c)-[:HANDLED_BY]->(a))
|
|
132
|
+
RETURN
|
|
133
|
+
count(c) AS candidates,
|
|
134
|
+
sum(CASE WHEN a IS NULL THEN 0 ELSE 1 END) AS edges`,
|
|
135
|
+
{ accountId }
|
|
136
|
+
);
|
|
137
|
+
const toNum = (v) => {
|
|
138
|
+
if (typeof v === "number") return v;
|
|
139
|
+
if (v && typeof v.toNumber === "function") {
|
|
140
|
+
return v.toNumber();
|
|
141
|
+
}
|
|
142
|
+
return 0;
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
candidates: toNum(result.records[0]?.get("candidates")),
|
|
146
|
+
edges: toNum(result.records[0]?.get("edges"))
|
|
147
|
+
};
|
|
148
|
+
} finally {
|
|
149
|
+
await session.close();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function backfillChannel(driver, accountId) {
|
|
153
|
+
const session = driver.session();
|
|
154
|
+
try {
|
|
155
|
+
const result = await session.run(
|
|
156
|
+
`MATCH (c:Conversation {accountId: $accountId})
|
|
157
|
+
WHERE c.channel IS NULL
|
|
158
|
+
SET c.channel = 'webchat'
|
|
159
|
+
RETURN count(c) AS backfilled`,
|
|
160
|
+
{ accountId }
|
|
161
|
+
);
|
|
162
|
+
const raw = result.records[0]?.get("backfilled");
|
|
163
|
+
if (typeof raw === "number") return raw;
|
|
164
|
+
if (raw && typeof raw.toNumber === "function") {
|
|
165
|
+
return raw.toNumber();
|
|
166
|
+
}
|
|
167
|
+
return 0;
|
|
168
|
+
} finally {
|
|
169
|
+
await session.close();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async function applyAdminAgentBackfill(driver, platformRoot) {
|
|
173
|
+
const accountsDir = resolve2(platformRoot, "..", "data", "accounts");
|
|
174
|
+
const start = Date.now();
|
|
175
|
+
if (!existsSync(accountsDir)) {
|
|
176
|
+
console.error(
|
|
177
|
+
`[admin-agent-graph-backfill] accounts-dir missing at ${accountsDir} \u2014 nothing to do`
|
|
178
|
+
);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const accountEntries = readValidAccountDirs(accountsDir).map((name) => ({ name }));
|
|
182
|
+
console.error(
|
|
183
|
+
`[admin-agent-graph-backfill] start accounts=${accountEntries.length}`
|
|
184
|
+
);
|
|
185
|
+
let totalProjected = 0;
|
|
186
|
+
let totalFailed = 0;
|
|
187
|
+
let totalHandledByCandidates = 0;
|
|
188
|
+
let totalHandledByEdges = 0;
|
|
189
|
+
let totalChannelBackfilled = 0;
|
|
190
|
+
const perAccount = [];
|
|
191
|
+
for (const entry of accountEntries) {
|
|
192
|
+
const accountDir = resolve2(accountsDir, entry.name);
|
|
193
|
+
const accountId = entry.name;
|
|
194
|
+
const accountStart = Date.now();
|
|
195
|
+
const { projected, failed } = await projectAccountAdmin(
|
|
196
|
+
accountId,
|
|
197
|
+
accountDir
|
|
198
|
+
);
|
|
199
|
+
totalProjected += projected;
|
|
200
|
+
totalFailed += failed;
|
|
201
|
+
let handledByStats = { candidates: 0, edges: 0 };
|
|
202
|
+
let channelBackfilled = 0;
|
|
203
|
+
try {
|
|
204
|
+
handledByStats = await backfillAdminHandledBy(driver, accountId);
|
|
205
|
+
totalHandledByCandidates += handledByStats.candidates;
|
|
206
|
+
totalHandledByEdges += handledByStats.edges;
|
|
207
|
+
} catch (err) {
|
|
208
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
209
|
+
console.error(
|
|
210
|
+
`[admin-agent-graph-backfill] account=${accountId.slice(0, 8)} handled-by-backfill FAILED error="${msg}"`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
channelBackfilled = await backfillChannel(driver, accountId);
|
|
215
|
+
totalChannelBackfilled += channelBackfilled;
|
|
216
|
+
} catch (err) {
|
|
217
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
218
|
+
console.error(
|
|
219
|
+
`[admin-agent-graph-backfill] account=${accountId.slice(0, 8)} channel-backfill FAILED error="${msg}"`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
perAccount.push({
|
|
223
|
+
accountId,
|
|
224
|
+
projected,
|
|
225
|
+
failed,
|
|
226
|
+
handledByCandidates: handledByStats.candidates,
|
|
227
|
+
handledByEdges: handledByStats.edges,
|
|
228
|
+
channelBackfilled
|
|
229
|
+
});
|
|
230
|
+
const ms2 = Date.now() - accountStart;
|
|
231
|
+
console.error(
|
|
232
|
+
`[admin-agent-graph-backfill] account=${accountId.slice(0, 8)} projected=${projected} failed=${failed} handled-by-candidates=${handledByStats.candidates} handled-by-edges=${handledByStats.edges} channel-backfilled=${channelBackfilled} ms=${ms2}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const ms = Date.now() - start;
|
|
236
|
+
console.error(
|
|
237
|
+
`[admin-agent-graph-backfill] done totals: projected=${totalProjected} failed=${totalFailed} handled-by-candidates=${totalHandledByCandidates} handled-by-edges=${totalHandledByEdges} channel-backfilled=${totalChannelBackfilled} ms=${ms}`
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
async function main() {
|
|
241
|
+
if (!existsSync(ACCOUNTS_DIR)) {
|
|
242
|
+
console.error(
|
|
243
|
+
`[admin-agent-graph-backfill] ACCOUNTS_DIR missing at ${ACCOUNTS_DIR} \u2014 nothing to do`
|
|
244
|
+
);
|
|
245
|
+
process.exit(0);
|
|
246
|
+
}
|
|
247
|
+
const driverShim = { session: () => getSession() };
|
|
248
|
+
const platformRoot = resolve2(ACCOUNTS_DIR, "..", "..", "platform");
|
|
249
|
+
try {
|
|
250
|
+
await applyAdminAgentBackfill(driverShim, platformRoot);
|
|
251
|
+
process.exit(0);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
254
|
+
console.error(`[admin-agent-graph-backfill] fatal error="${msg}"`);
|
|
255
|
+
process.exit(2);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (process.argv[1]?.endsWith("004-project-admin-agent.ts")) {
|
|
259
|
+
main().catch((err) => {
|
|
260
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
261
|
+
console.error(`[admin-agent-graph-backfill] fatal error="${msg}"`);
|
|
262
|
+
process.exit(2);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ../neo4j/migrations/005-removed-review-feature.ts
|
|
267
|
+
import { resolve as resolve3 } from "path";
|
|
268
|
+
import { unlinkSync } from "fs";
|
|
269
|
+
import { homedir } from "os";
|
|
270
|
+
import { basename, dirname } from "path";
|
|
271
|
+
async function removeReviewFeature(driver, platformRoot) {
|
|
272
|
+
const session = driver.session();
|
|
273
|
+
let eventsDeleted = 0;
|
|
274
|
+
let alertsDeleted = 0;
|
|
275
|
+
try {
|
|
276
|
+
const eventResult = await session.run(
|
|
277
|
+
`MATCH (e:Event)
|
|
278
|
+
WHERE e.actionTool = "review-digest-compose"
|
|
279
|
+
OR e.eventId STARTS WITH "review-digest-"
|
|
280
|
+
DETACH DELETE e
|
|
281
|
+
RETURN count(e) AS deleted`
|
|
282
|
+
);
|
|
283
|
+
eventsDeleted = toNumber(eventResult.records[0]?.get("deleted"));
|
|
284
|
+
const alertResult = await session.run(
|
|
285
|
+
`MATCH (a:ReviewAlert)
|
|
286
|
+
DETACH DELETE a
|
|
287
|
+
RETURN count(a) AS deleted`
|
|
288
|
+
);
|
|
289
|
+
alertsDeleted = toNumber(alertResult.records[0]?.get("deleted"));
|
|
290
|
+
} finally {
|
|
291
|
+
await session.close();
|
|
292
|
+
}
|
|
293
|
+
const installDirName = basename(dirname(platformRoot));
|
|
294
|
+
const configDir = resolve3(homedir(), `.${installDirName}`);
|
|
295
|
+
const artefacts = [
|
|
296
|
+
resolve3(configDir, "logs", "review.log"),
|
|
297
|
+
resolve3(configDir, "review-rules.json"),
|
|
298
|
+
resolve3(configDir, "review-state.json"),
|
|
299
|
+
resolve3(configDir, "review-pending-alerts.jsonl")
|
|
300
|
+
];
|
|
301
|
+
for (const path of artefacts) {
|
|
302
|
+
try {
|
|
303
|
+
unlinkSync(path);
|
|
304
|
+
} catch (err) {
|
|
305
|
+
const code = err.code;
|
|
306
|
+
if (code === "ENOENT") continue;
|
|
307
|
+
console.error(
|
|
308
|
+
`[migration] removed-review-feature unlink-skip path=${path} reason=${code ?? "unknown"}`
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
console.error(
|
|
313
|
+
`[migration] removed-review-feature events=${eventsDeleted} alerts=${alertsDeleted}`
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
function toNumber(v) {
|
|
317
|
+
if (typeof v === "number") return v;
|
|
318
|
+
if (v && typeof v.toNumber === "function") {
|
|
319
|
+
return v.toNumber();
|
|
320
|
+
}
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ../neo4j/migrations/006-prune-bogus-whatsapp-persons.ts
|
|
325
|
+
var POLLUTED_NAME_REGEX = "(?s).*[\\n\\[].*";
|
|
326
|
+
async function pruneBogusWhatsappPersons(driver) {
|
|
327
|
+
const session = driver.session();
|
|
328
|
+
try {
|
|
329
|
+
const nonAutoRes = await session.run(
|
|
330
|
+
`MATCH (p:Person {source: 'whatsapp'})
|
|
331
|
+
WHERE coalesce(p.participantStatus, '') <> 'auto-created'
|
|
332
|
+
AND p.name =~ $regex
|
|
333
|
+
RETURN elementId(p) AS elementId, p.name AS name`,
|
|
334
|
+
{ regex: POLLUTED_NAME_REGEX }
|
|
335
|
+
);
|
|
336
|
+
const skippedNonAuto = nonAutoRes.records.length;
|
|
337
|
+
for (const record of nonAutoRes.records) {
|
|
338
|
+
const elementId = record.get("elementId");
|
|
339
|
+
const name = record.get("name");
|
|
340
|
+
console.error(
|
|
341
|
+
`[migration:whatsapp-bogus-person-prune] non-auto-match elementId=${elementId} name=${JSON.stringify(name)}`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
const matchedRes = await session.run(
|
|
345
|
+
`MATCH (p:Person {source: 'whatsapp', participantStatus: 'auto-created'})
|
|
346
|
+
WHERE p.name =~ $regex
|
|
347
|
+
RETURN count(p) AS matched`,
|
|
348
|
+
{ regex: POLLUTED_NAME_REGEX }
|
|
349
|
+
);
|
|
350
|
+
const matched = toNumber2(matchedRes.records[0]?.get("matched"));
|
|
351
|
+
if (matched === 0) {
|
|
352
|
+
console.error(
|
|
353
|
+
`[migration:whatsapp-bogus-person-prune] matched=0 deleted=0 skipped-non-auto=${skippedNonAuto}`
|
|
354
|
+
);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const deleteRes = await session.run(
|
|
358
|
+
`MATCH (p:Person {source: 'whatsapp', participantStatus: 'auto-created'})
|
|
359
|
+
WHERE p.name =~ $regex
|
|
360
|
+
DETACH DELETE p
|
|
361
|
+
RETURN count(p) AS deleted`,
|
|
362
|
+
{ regex: POLLUTED_NAME_REGEX }
|
|
363
|
+
);
|
|
364
|
+
const deleted = toNumber2(deleteRes.records[0]?.get("deleted"));
|
|
365
|
+
console.error(
|
|
366
|
+
`[migration:whatsapp-bogus-person-prune] matched=${matched} deleted=${deleted} skipped-non-auto=${skippedNonAuto}`
|
|
367
|
+
);
|
|
368
|
+
} finally {
|
|
369
|
+
await session.close();
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function toNumber2(v) {
|
|
373
|
+
if (typeof v === "number") return v;
|
|
374
|
+
if (v && typeof v.toNumber === "function") {
|
|
375
|
+
return v.toNumber();
|
|
376
|
+
}
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ../neo4j/migrations/007-conversation-archive-source.ts
|
|
381
|
+
async function backfillConversationArchiveSource(driver) {
|
|
382
|
+
const session = driver.session();
|
|
383
|
+
try {
|
|
384
|
+
const archivesSourceSet = await runCount(
|
|
385
|
+
session,
|
|
386
|
+
`MATCH (a:ConversationArchive)
|
|
387
|
+
WHERE a.source IS NULL
|
|
388
|
+
SET a.source = 'whatsapp'
|
|
389
|
+
RETURN count(a) AS n`
|
|
390
|
+
);
|
|
391
|
+
const archivesAgentRenamed = await runCount(
|
|
392
|
+
session,
|
|
393
|
+
`MATCH (a:ConversationArchive)
|
|
394
|
+
WHERE a.createdByAgent = 'whatsapp-import'
|
|
395
|
+
SET a.createdByAgent = 'conversation-archive'
|
|
396
|
+
RETURN count(a) AS n`
|
|
397
|
+
);
|
|
398
|
+
const chunksSourceSet = await runCount(
|
|
399
|
+
session,
|
|
400
|
+
`MATCH (c:Section:Conversation)
|
|
401
|
+
WHERE c.source IS NULL
|
|
402
|
+
SET c.source = 'whatsapp'
|
|
403
|
+
RETURN count(c) AS n`
|
|
404
|
+
);
|
|
405
|
+
const chunksAgentRenamed = await runCount(
|
|
406
|
+
session,
|
|
407
|
+
`MATCH (c:Section:Conversation)
|
|
408
|
+
WHERE c.createdByAgent = 'whatsapp-import'
|
|
409
|
+
SET c.createdByAgent = 'conversation-archive'
|
|
410
|
+
RETURN count(c) AS n`
|
|
411
|
+
);
|
|
412
|
+
const edgesAgentRenamed = await runCount(
|
|
413
|
+
session,
|
|
414
|
+
`MATCH (a:ConversationArchive)-[r]-()
|
|
415
|
+
WHERE r.createdByAgent = 'whatsapp-import'
|
|
416
|
+
SET r.createdByAgent = 'conversation-archive'
|
|
417
|
+
RETURN count(r) AS n`
|
|
418
|
+
);
|
|
419
|
+
console.error(
|
|
420
|
+
`[migration:conversation-archive-source] archives-source-set=${archivesSourceSet} archives-agent-renamed=${archivesAgentRenamed} chunks-source-set=${chunksSourceSet} chunks-agent-renamed=${chunksAgentRenamed} edges-agent-renamed=${edgesAgentRenamed}`
|
|
421
|
+
);
|
|
422
|
+
} finally {
|
|
423
|
+
await session.close();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
async function runCount(session, cypher) {
|
|
427
|
+
const res = await session.run(cypher);
|
|
428
|
+
const v = res.records[0]?.get("n");
|
|
429
|
+
if (typeof v === "number") return v;
|
|
430
|
+
if (v && typeof v.toNumber === "function") {
|
|
431
|
+
return v.toNumber();
|
|
432
|
+
}
|
|
433
|
+
return 0;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// ../neo4j/migrations/008-adminuser-accountid-backfill.ts
|
|
437
|
+
async function backfillAdminUserAccountId(driver) {
|
|
438
|
+
const session = driver.session();
|
|
439
|
+
try {
|
|
440
|
+
const backfilled = await runCount2(
|
|
441
|
+
session,
|
|
442
|
+
`MATCH (au:AdminUser) WHERE au.accountId IS NULL
|
|
443
|
+
OPTIONAL MATCH (au)-[:ADMIN_OF]->(b:LocalBusiness)
|
|
444
|
+
WITH au, b WHERE b IS NOT NULL AND b.accountId IS NOT NULL
|
|
445
|
+
SET au.accountId = b.accountId
|
|
446
|
+
RETURN count(au) AS n`
|
|
447
|
+
);
|
|
448
|
+
const residualNull = await runCount2(
|
|
449
|
+
session,
|
|
450
|
+
`MATCH (au:AdminUser) WHERE au.accountId IS NULL
|
|
451
|
+
RETURN count(au) AS n`
|
|
452
|
+
);
|
|
453
|
+
console.error(
|
|
454
|
+
`[migration:adminuser-accountid] backfilled=${backfilled} residual-null=${residualNull}`
|
|
455
|
+
);
|
|
456
|
+
if (residualNull > 0) {
|
|
457
|
+
throw new Error(
|
|
458
|
+
`migration:adminuser-accountid: ${residualNull} :AdminUser node(s) still carry a null accountId after backfill \u2014 no ADMIN_OF edge to derive from. Manual reconciliation required (cypher-shell into the graph; either DELETE the orphan or attach a valid ADMIN_OF edge and re-run boot).`
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
} finally {
|
|
462
|
+
await session.close();
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async function runCount2(session, cypher) {
|
|
466
|
+
const res = await session.run(cypher);
|
|
467
|
+
const v = res.records[0]?.get("n");
|
|
468
|
+
if (typeof v === "number") return v;
|
|
469
|
+
if (v && typeof v.toNumber === "function") {
|
|
470
|
+
return v.toNumber();
|
|
471
|
+
}
|
|
472
|
+
return 0;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// app/lib/neo4j-migrations.ts
|
|
476
|
+
var BOOT_MIGRATIONS = [
|
|
477
|
+
{ fileName: "003-person-name-eradicate.cypher", slug: "person-name-eradicate" }
|
|
478
|
+
];
|
|
479
|
+
async function applyBootMigrations(driver, platformRoot) {
|
|
480
|
+
for (const migration of BOOT_MIGRATIONS) {
|
|
481
|
+
await applyOne(driver, platformRoot, migration);
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
await pruneAlienAccounts(driver, platformRoot);
|
|
485
|
+
} catch (err) {
|
|
486
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
487
|
+
console.error(`[migration] failed prune-alien-accounts error="${msg}"`);
|
|
488
|
+
}
|
|
489
|
+
try {
|
|
490
|
+
await applyAdminAgentBackfill(driver, platformRoot);
|
|
491
|
+
} catch (err) {
|
|
492
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
493
|
+
console.error(`[migration] failed admin-agent-graph-backfill error="${msg}"`);
|
|
494
|
+
}
|
|
495
|
+
try {
|
|
496
|
+
await removeReviewFeature(driver, platformRoot);
|
|
497
|
+
} catch (err) {
|
|
498
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
499
|
+
console.error(`[migration] failed removed-review-feature error="${msg}"`);
|
|
500
|
+
}
|
|
501
|
+
try {
|
|
502
|
+
await pruneBogusWhatsappPersons(driver);
|
|
503
|
+
} catch (err) {
|
|
504
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
505
|
+
console.error(`[migration] failed prune-bogus-whatsapp-persons error="${msg}"`);
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
await backfillConversationArchiveSource(driver);
|
|
509
|
+
} catch (err) {
|
|
510
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
511
|
+
console.error(`[migration] failed conversation-archive-source error="${msg}"`);
|
|
512
|
+
}
|
|
513
|
+
await backfillAdminUserAccountId(driver);
|
|
514
|
+
}
|
|
515
|
+
async function applyOne(driver, platformRoot, migration) {
|
|
516
|
+
const path = resolve4(platformRoot, "neo4j/migrations", migration.fileName);
|
|
517
|
+
let cypher;
|
|
518
|
+
try {
|
|
519
|
+
cypher = readFileSync3(path, "utf-8");
|
|
520
|
+
} catch (err) {
|
|
521
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
522
|
+
console.error(
|
|
523
|
+
`[migration] failed ${migration.slug} error=cannot-read-file path=${path} msg=${msg}`
|
|
524
|
+
);
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const session = driver.session();
|
|
528
|
+
try {
|
|
529
|
+
const result = await session.run(cypher);
|
|
530
|
+
const record = result.records[0];
|
|
531
|
+
const removedRaw = record?.get("removed");
|
|
532
|
+
const removed = toNumber3(removedRaw);
|
|
533
|
+
console.error(
|
|
534
|
+
`[migration] applied ${migration.slug} removed=${removed}`
|
|
535
|
+
);
|
|
536
|
+
} catch (err) {
|
|
537
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
538
|
+
console.error(`[migration] failed ${migration.slug} error="${msg}"`);
|
|
539
|
+
} finally {
|
|
540
|
+
await session.close();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
function toNumber3(v) {
|
|
544
|
+
if (typeof v === "number") return v;
|
|
545
|
+
if (v && typeof v.toNumber === "function") {
|
|
546
|
+
return v.toNumber();
|
|
547
|
+
}
|
|
548
|
+
return 0;
|
|
549
|
+
}
|
|
550
|
+
export {
|
|
551
|
+
applyBootMigrations
|
|
552
|
+
};
|
package/payload/server/server.js
CHANGED
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
vncLog,
|
|
52
52
|
waitForExit,
|
|
53
53
|
writeChromiumWrapper
|
|
54
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-ZKGAYLAK.js";
|
|
55
55
|
import {
|
|
56
56
|
agentLogStream,
|
|
57
57
|
clearSessionHistory,
|
|
@@ -79,17 +79,18 @@ import {
|
|
|
79
79
|
sigtermFlushStreamLogs,
|
|
80
80
|
unregisterSession,
|
|
81
81
|
validateSession
|
|
82
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-25QDCOE5.js";
|
|
83
83
|
import {
|
|
84
84
|
ACCOUNTS_DIR,
|
|
85
85
|
PLATFORM_ROOT,
|
|
86
86
|
getDefaultAccountId,
|
|
87
|
+
hasStubAccountDir,
|
|
87
88
|
resolveAccount,
|
|
88
89
|
resolveAgentConfig,
|
|
89
90
|
resolveDefaultAgentSlug,
|
|
90
91
|
resolveUserAccounts,
|
|
91
92
|
validateAgentSlug
|
|
92
|
-
} from "./chunk-
|
|
93
|
+
} from "./chunk-35YZS3KL.js";
|
|
93
94
|
import {
|
|
94
95
|
CLOUDFLARE_TASK_DIAGNOSTICS,
|
|
95
96
|
appendCloudflareSteps,
|
|
@@ -97,7 +98,7 @@ import {
|
|
|
97
98
|
openCloudflareTask,
|
|
98
99
|
readTunnelState,
|
|
99
100
|
resolveUnitGoneVerdict
|
|
100
|
-
} from "./chunk-
|
|
101
|
+
} from "./chunk-7CBRZKZS.js";
|
|
101
102
|
import {
|
|
102
103
|
GREETING_DIRECTIVE,
|
|
103
104
|
HAIKU_MODEL,
|
|
@@ -129,7 +130,7 @@ import {
|
|
|
129
130
|
verifyAndGetConversationUpdatedAt,
|
|
130
131
|
verifyConversationOwnership,
|
|
131
132
|
writeAdminUserAndPerson
|
|
132
|
-
} from "./chunk-
|
|
133
|
+
} from "./chunk-IXOPV36P.js";
|
|
133
134
|
|
|
134
135
|
// ../lib/graph-trash/dist/index.js
|
|
135
136
|
var require_dist = __commonJS({
|
|
@@ -6494,6 +6495,17 @@ app8.post("/set-pin", async (c) => {
|
|
|
6494
6495
|
if (existingUsers !== null && existingUsers.length > 0) {
|
|
6495
6496
|
return c.json({ error: "PIN is already configured." }, 409);
|
|
6496
6497
|
}
|
|
6498
|
+
const stubCheck = hasStubAccountDir();
|
|
6499
|
+
if (stubCheck.stub) {
|
|
6500
|
+
console.error(
|
|
6501
|
+
`[onboarding] set-pin REFUSED reason=stub-account-dirs dirs=${stubCheck.dirs.join(",")}`
|
|
6502
|
+
);
|
|
6503
|
+
return c.json({
|
|
6504
|
+
error: `Onboarding refused: data/accounts/ contains ${stubCheck.dirs.length} directory/ies without account.json (${stubCheck.dirs.join(", ")}). Resolve the stub before setting up.`,
|
|
6505
|
+
code: "STUB_ACCOUNT_DIR",
|
|
6506
|
+
dirs: stubCheck.dirs
|
|
6507
|
+
}, 409);
|
|
6508
|
+
}
|
|
6497
6509
|
let body;
|
|
6498
6510
|
try {
|
|
6499
6511
|
body = await c.req.json();
|
|
@@ -7285,7 +7297,7 @@ var app11 = new Hono();
|
|
|
7285
7297
|
app11.post("/cancel", requireAdminSession, async (c) => {
|
|
7286
7298
|
const session_key = c.var.sessionKey;
|
|
7287
7299
|
try {
|
|
7288
|
-
const { interruptClient: interruptClient2 } = await import("./client-pool-
|
|
7300
|
+
const { interruptClient: interruptClient2 } = await import("./client-pool-NBVGONQL.js");
|
|
7289
7301
|
await interruptClient2(session_key);
|
|
7290
7302
|
return c.json({ ok: true });
|
|
7291
7303
|
} catch (err) {
|
|
@@ -12843,7 +12855,7 @@ autoDeliverPremiumPlugins(bootEntitlement?.purchasedPlugins ?? void 0);
|
|
|
12843
12855
|
(async () => {
|
|
12844
12856
|
if (!bootAccount) return;
|
|
12845
12857
|
try {
|
|
12846
|
-
const { recoverRunningCloudflareTasks } = await import("./cloudflare-task-tracker-
|
|
12858
|
+
const { recoverRunningCloudflareTasks } = await import("./cloudflare-task-tracker-R4FIORFL.js");
|
|
12847
12859
|
const result = await recoverRunningCloudflareTasks(
|
|
12848
12860
|
bootAccount.accountId,
|
|
12849
12861
|
configDirForWhatsApp,
|