@rubytech/create-realagent 1.0.828 → 1.0.830
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/config/brand.json +1 -1
- package/payload/platform/lib/oauth-llm/dist/index.d.ts +1 -1
- package/payload/platform/lib/oauth-llm/dist/index.d.ts.map +1 -1
- package/payload/platform/lib/oauth-llm/dist/index.js +21 -0
- package/payload/platform/lib/oauth-llm/dist/index.js.map +1 -1
- package/payload/platform/lib/oauth-llm/src/index.ts +24 -0
- package/payload/platform/neo4j/migrations/007-conversation-archive-source.ts +116 -0
- package/payload/platform/neo4j/schema.cypher +12 -2
- package/payload/platform/package.json +2 -2
- package/payload/platform/plugins/admin/hooks/__tests__/archive-ingest-surface-gate.test.sh +6 -6
- package/payload/platform/plugins/admin/hooks/archive-ingest-surface-gate.sh +14 -8
- package/payload/platform/plugins/admin/skills/onboarding/SKILL.md +2 -2
- package/payload/platform/plugins/contacts/mcp/dist/index.js +5 -5
- package/payload/platform/plugins/contacts/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/contact-create.d.ts +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/contact-create.d.ts.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/contact-create.js +29 -23
- package/payload/platform/plugins/contacts/mcp/dist/tools/contact-create.js.map +1 -1
- package/payload/platform/plugins/docs/references/plugins-guide.md +1 -1
- package/payload/platform/plugins/memory/PLUGIN.md +6 -5
- package/payload/platform/plugins/{whatsapp-import/bin/ingest.mjs → memory/bin/conversation-archive-ingest.mjs} +136 -212
- package/payload/platform/plugins/{whatsapp-import/bin/whatsapp-ingest.sh → memory/bin/conversation-archive-ingest.sh} +27 -19
- package/payload/platform/plugins/memory/mcp/dist/index.js +26 -212
- package/payload/platform/plugins/memory/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/__tests__/llm-classifier.test.js +4 -3
- package/payload/platform/plugins/memory/mcp/dist/lib/__tests__/llm-classifier.test.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/__tests__/schema-loader.test.js +11 -6
- package/payload/platform/plugins/memory/mcp/dist/lib/__tests__/schema-loader.test.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/__tests__/schema-validator.test.js +103 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/__tests__/schema-validator.test.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/index.d.ts +5 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/index.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/index.js +30 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/index.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/types.d.ts +48 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/types.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/types.js +23 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/types.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/whatsapp-text.d.ts +3 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/whatsapp-text.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/whatsapp-text.js +237 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-normalisers/whatsapp-text.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/delta-cursor.d.ts +11 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/delta-cursor.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/delta-cursor.js +21 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/delta-cursor.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/derive-keys.d.ts +16 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/derive-keys.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/derive-keys.js +39 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/derive-keys.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/sender-bind.d.ts +17 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/sender-bind.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/sender-bind.js +90 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/sender-bind.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/sessionize.d.ts +9 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/sessionize.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/sessionize.js +32 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/sessionize.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/to-turn-text.d.ts +3 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/to-turn-text.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/to-turn-text.js +27 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/conversation-pipeline/to-turn-text.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/document-chunker.d.ts +45 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/document-chunker.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/document-chunker.js +125 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/document-chunker.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-classifier.d.ts +24 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-classifier.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-classifier.js +293 -33
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-classifier.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-ranker.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-ranker.js +9 -2
- package/payload/platform/plugins/memory/mcp/dist/lib/llm-ranker.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/schema-validator.d.ts +16 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/schema-validator.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/schema-validator.js +12 -3
- package/payload/platform/plugins/memory/mcp/dist/lib/schema-validator.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-normalisers-source-agnosticism.test.d.ts +2 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-normalisers-source-agnosticism.test.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-normalisers-source-agnosticism.test.js +75 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-normalisers-source-agnosticism.test.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-normalisers-whatsapp-text.test.d.ts +2 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-normalisers-whatsapp-text.test.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-normalisers-whatsapp-text.test.js +67 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-normalisers-whatsapp-text.test.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-archive-write.test.js +2 -138
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-archive-write.test.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-ingest.test.js +39 -3
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/memory-ingest.test.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/profile-update-personfields-open.test.d.ts +2 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/profile-update-personfields-open.test.d.ts.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/profile-update-personfields-open.test.js +148 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/profile-update-personfields-open.test.js.map +1 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-archive-write.d.ts +1 -47
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-archive-write.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-archive-write.js +9 -318
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-archive-write.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.d.ts +7 -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 +14 -8
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-ingest.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/profile-update.d.ts +21 -17
- package/payload/platform/plugins/memory/mcp/dist/tools/profile-update.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/profile-update.js +77 -37
- package/payload/platform/plugins/memory/mcp/dist/tools/profile-update.js.map +1 -1
- package/payload/platform/plugins/memory/references/schema-base.md +3 -1
- package/payload/platform/plugins/{whatsapp-import/skills/whatsapp-import → memory/skills/conversation-archive}/SKILL.md +45 -36
- package/payload/platform/plugins/memory/skills/document-ingest/SKILL.md +59 -6
- package/payload/platform/plugins/whatsapp/PLUGIN.md +1 -1
- package/payload/platform/scripts/seed-neo4j.sh +9 -8
- package/payload/platform/templates/specialists/agents/database-operator.md +7 -14
- package/payload/server/chunk-7BO5HDJC.js +10093 -0
- package/payload/server/chunk-CUSH3UXP.js +2305 -0
- package/payload/server/chunk-EL4DZ56X.js +1116 -0
- package/payload/server/chunk-IWNDVGKT.js +10077 -0
- package/payload/server/chunk-KC7NUABI.js +654 -0
- package/payload/server/chunk-QOJ2D26Z.js +654 -0
- package/payload/server/chunk-RC46ZYGT.js +2305 -0
- package/payload/server/chunk-WUVXPZIV.js +1116 -0
- package/payload/server/client-pool-3TM3SRIA.js +32 -0
- package/payload/server/client-pool-7NTEFNVQ.js +32 -0
- package/payload/server/cloudflare-task-tracker-4NIODMGL.js +19 -0
- package/payload/server/cloudflare-task-tracker-WE77WXSI.js +19 -0
- package/payload/server/maxy-edge.js +3 -3
- package/payload/server/neo4j-migrations-4XPNJNM6.js +490 -0
- package/payload/server/neo4j-migrations-XTQ4WEV6.js +428 -0
- package/payload/server/server.js +6 -6
- package/payload/platform/plugins/whatsapp-import/PLUGIN.md +0 -48
- package/payload/platform/plugins/whatsapp-import/lib/src/__tests__/delta-append.test.ts +0 -163
- package/payload/platform/plugins/whatsapp-import/lib/src/__tests__/parse-export-lrm.test.ts +0 -83
- package/payload/platform/plugins/whatsapp-import/lib/src/__tests__/parse-export.test.ts +0 -678
- package/payload/platform/plugins/whatsapp-import/lib/src/__tests__/sessionize.test.ts +0 -91
- package/payload/platform/plugins/whatsapp-import/lib/src/__tests__/to-classifier-input.test.ts +0 -59
- package/payload/platform/plugins/whatsapp-import/lib/src/delta-cursor.ts +0 -54
- package/payload/platform/plugins/whatsapp-import/lib/src/derive-keys.ts +0 -82
- package/payload/platform/plugins/whatsapp-import/lib/src/index.ts +0 -22
- package/payload/platform/plugins/whatsapp-import/lib/src/parse-export.ts +0 -471
- package/payload/platform/plugins/whatsapp-import/lib/src/sessionize.ts +0 -81
- package/payload/platform/plugins/whatsapp-import/lib/src/to-classifier-input.ts +0 -48
- package/payload/platform/plugins/whatsapp-import/lib/tsconfig.json +0 -9
- package/payload/platform/plugins/whatsapp-import/lib/vitest.config.ts +0 -9
- package/payload/platform/plugins/whatsapp-import/skills/whatsapp-import/references/conversation-archive-shape.md +0 -143
- package/payload/platform/plugins/whatsapp-import/skills/whatsapp-import/references/export-parse.md +0 -109
|
@@ -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-WUVXPZIV.js";
|
|
16
|
+
import "./chunk-5OG7TUQL.js";
|
|
17
|
+
import "./chunk-CUSH3UXP.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,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-EL4DZ56X.js";
|
|
16
|
+
import "./chunk-5OG7TUQL.js";
|
|
17
|
+
import "./chunk-RC46ZYGT.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-KC7NUABI.js";
|
|
10
|
+
import "./chunk-CUSH3UXP.js";
|
|
11
|
+
export {
|
|
12
|
+
CLOUDFLARE_TASK_DIAGNOSTICS,
|
|
13
|
+
appendCloudflareSteps,
|
|
14
|
+
completeCloudflareTask,
|
|
15
|
+
openCloudflareTask,
|
|
16
|
+
readTunnelState,
|
|
17
|
+
recoverRunningCloudflareTasks,
|
|
18
|
+
resolveUnitGoneVerdict
|
|
19
|
+
};
|
|
@@ -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-QOJ2D26Z.js";
|
|
10
|
+
import "./chunk-RC46ZYGT.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-
|
|
19
|
+
} from "./chunk-7BO5HDJC.js";
|
|
20
|
+
import "./chunk-EL4DZ56X.js";
|
|
21
21
|
import "./chunk-5OG7TUQL.js";
|
|
22
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-RC46ZYGT.js";
|
|
23
23
|
|
|
24
24
|
// server/edge.ts
|
|
25
25
|
import { createServer, request as httpRequest } from "http";
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACCOUNTS_DIR
|
|
3
|
+
} from "./chunk-5OG7TUQL.js";
|
|
4
|
+
import {
|
|
5
|
+
getSession,
|
|
6
|
+
projectAgent
|
|
7
|
+
} from "./chunk-RC46ZYGT.js";
|
|
8
|
+
|
|
9
|
+
// app/lib/neo4j-migrations.ts
|
|
10
|
+
import { readFileSync as readFileSync2 } 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, readdirSync as readdirSync2 } from "fs";
|
|
84
|
+
import { resolve as resolve2 } from "path";
|
|
85
|
+
async function projectAccountAdmin(accountId, accountDir) {
|
|
86
|
+
const adminDir = resolve2(accountDir, "agents", "admin");
|
|
87
|
+
const configPath = resolve2(adminDir, "config.json");
|
|
88
|
+
if (!existsSync(adminDir) || !existsSync(configPath)) {
|
|
89
|
+
return { projected: 0, failed: 0 };
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
await projectAgent(accountId, accountDir, "admin");
|
|
93
|
+
return { projected: 1, failed: 0 };
|
|
94
|
+
} catch (err) {
|
|
95
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
96
|
+
console.error(
|
|
97
|
+
`[admin-agent-graph-backfill] account=${accountId.slice(0, 8)} project FAILED error="${msg}"`
|
|
98
|
+
);
|
|
99
|
+
return { projected: 0, failed: 1 };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function backfillAdminHandledBy(driver, accountId) {
|
|
103
|
+
const session = driver.session();
|
|
104
|
+
try {
|
|
105
|
+
const result = await session.run(
|
|
106
|
+
`MATCH (c:AdminConversation {accountId: $accountId})
|
|
107
|
+
WHERE NOT EXISTS((c)-[:HANDLED_BY]->(:Agent))
|
|
108
|
+
OPTIONAL MATCH (a:Agent {accountId: $accountId, slug: 'admin'})
|
|
109
|
+
FOREACH (_ IN CASE WHEN a IS NULL THEN [] ELSE [1] END | MERGE (c)-[:HANDLED_BY]->(a))
|
|
110
|
+
RETURN
|
|
111
|
+
count(c) AS candidates,
|
|
112
|
+
sum(CASE WHEN a IS NULL THEN 0 ELSE 1 END) AS edges`,
|
|
113
|
+
{ accountId }
|
|
114
|
+
);
|
|
115
|
+
const toNum = (v) => {
|
|
116
|
+
if (typeof v === "number") return v;
|
|
117
|
+
if (v && typeof v.toNumber === "function") {
|
|
118
|
+
return v.toNumber();
|
|
119
|
+
}
|
|
120
|
+
return 0;
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
candidates: toNum(result.records[0]?.get("candidates")),
|
|
124
|
+
edges: toNum(result.records[0]?.get("edges"))
|
|
125
|
+
};
|
|
126
|
+
} finally {
|
|
127
|
+
await session.close();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function backfillChannel(driver, accountId) {
|
|
131
|
+
const session = driver.session();
|
|
132
|
+
try {
|
|
133
|
+
const result = await session.run(
|
|
134
|
+
`MATCH (c:Conversation {accountId: $accountId})
|
|
135
|
+
WHERE c.channel IS NULL
|
|
136
|
+
SET c.channel = 'webchat'
|
|
137
|
+
RETURN count(c) AS backfilled`,
|
|
138
|
+
{ accountId }
|
|
139
|
+
);
|
|
140
|
+
const raw = result.records[0]?.get("backfilled");
|
|
141
|
+
if (typeof raw === "number") return raw;
|
|
142
|
+
if (raw && typeof raw.toNumber === "function") {
|
|
143
|
+
return raw.toNumber();
|
|
144
|
+
}
|
|
145
|
+
return 0;
|
|
146
|
+
} finally {
|
|
147
|
+
await session.close();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function applyAdminAgentBackfill(driver, platformRoot) {
|
|
151
|
+
const accountsDir = resolve2(platformRoot, "..", "data", "accounts");
|
|
152
|
+
const start = Date.now();
|
|
153
|
+
if (!existsSync(accountsDir)) {
|
|
154
|
+
console.error(
|
|
155
|
+
`[admin-agent-graph-backfill] accounts-dir missing at ${accountsDir} \u2014 nothing to do`
|
|
156
|
+
);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const accountEntries = readdirSync2(accountsDir, { withFileTypes: true }).filter((e) => e.isDirectory());
|
|
160
|
+
console.error(
|
|
161
|
+
`[admin-agent-graph-backfill] start accounts=${accountEntries.length}`
|
|
162
|
+
);
|
|
163
|
+
let totalProjected = 0;
|
|
164
|
+
let totalFailed = 0;
|
|
165
|
+
let totalHandledByCandidates = 0;
|
|
166
|
+
let totalHandledByEdges = 0;
|
|
167
|
+
let totalChannelBackfilled = 0;
|
|
168
|
+
const perAccount = [];
|
|
169
|
+
for (const entry of accountEntries) {
|
|
170
|
+
const accountDir = resolve2(accountsDir, entry.name);
|
|
171
|
+
const accountId = entry.name;
|
|
172
|
+
const accountStart = Date.now();
|
|
173
|
+
const { projected, failed } = await projectAccountAdmin(
|
|
174
|
+
accountId,
|
|
175
|
+
accountDir
|
|
176
|
+
);
|
|
177
|
+
totalProjected += projected;
|
|
178
|
+
totalFailed += failed;
|
|
179
|
+
let handledByStats = { candidates: 0, edges: 0 };
|
|
180
|
+
let channelBackfilled = 0;
|
|
181
|
+
try {
|
|
182
|
+
handledByStats = await backfillAdminHandledBy(driver, accountId);
|
|
183
|
+
totalHandledByCandidates += handledByStats.candidates;
|
|
184
|
+
totalHandledByEdges += handledByStats.edges;
|
|
185
|
+
} catch (err) {
|
|
186
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
187
|
+
console.error(
|
|
188
|
+
`[admin-agent-graph-backfill] account=${accountId.slice(0, 8)} handled-by-backfill FAILED error="${msg}"`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
channelBackfilled = await backfillChannel(driver, accountId);
|
|
193
|
+
totalChannelBackfilled += channelBackfilled;
|
|
194
|
+
} catch (err) {
|
|
195
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
196
|
+
console.error(
|
|
197
|
+
`[admin-agent-graph-backfill] account=${accountId.slice(0, 8)} channel-backfill FAILED error="${msg}"`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
perAccount.push({
|
|
201
|
+
accountId,
|
|
202
|
+
projected,
|
|
203
|
+
failed,
|
|
204
|
+
handledByCandidates: handledByStats.candidates,
|
|
205
|
+
handledByEdges: handledByStats.edges,
|
|
206
|
+
channelBackfilled
|
|
207
|
+
});
|
|
208
|
+
const ms2 = Date.now() - accountStart;
|
|
209
|
+
console.error(
|
|
210
|
+
`[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}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
const ms = Date.now() - start;
|
|
214
|
+
console.error(
|
|
215
|
+
`[admin-agent-graph-backfill] done totals: projected=${totalProjected} failed=${totalFailed} handled-by-candidates=${totalHandledByCandidates} handled-by-edges=${totalHandledByEdges} channel-backfilled=${totalChannelBackfilled} ms=${ms}`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
async function main() {
|
|
219
|
+
if (!existsSync(ACCOUNTS_DIR)) {
|
|
220
|
+
console.error(
|
|
221
|
+
`[admin-agent-graph-backfill] ACCOUNTS_DIR missing at ${ACCOUNTS_DIR} \u2014 nothing to do`
|
|
222
|
+
);
|
|
223
|
+
process.exit(0);
|
|
224
|
+
}
|
|
225
|
+
const driverShim = { session: () => getSession() };
|
|
226
|
+
const platformRoot = resolve2(ACCOUNTS_DIR, "..", "..", "platform");
|
|
227
|
+
try {
|
|
228
|
+
await applyAdminAgentBackfill(driverShim, platformRoot);
|
|
229
|
+
process.exit(0);
|
|
230
|
+
} catch (err) {
|
|
231
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
232
|
+
console.error(`[admin-agent-graph-backfill] fatal error="${msg}"`);
|
|
233
|
+
process.exit(2);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (process.argv[1]?.endsWith("004-project-admin-agent.ts")) {
|
|
237
|
+
main().catch((err) => {
|
|
238
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
239
|
+
console.error(`[admin-agent-graph-backfill] fatal error="${msg}"`);
|
|
240
|
+
process.exit(2);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ../neo4j/migrations/005-removed-review-feature.ts
|
|
245
|
+
import { resolve as resolve3 } from "path";
|
|
246
|
+
import { unlinkSync } from "fs";
|
|
247
|
+
import { homedir } from "os";
|
|
248
|
+
import { basename, dirname } from "path";
|
|
249
|
+
async function removeReviewFeature(driver, platformRoot) {
|
|
250
|
+
const session = driver.session();
|
|
251
|
+
let eventsDeleted = 0;
|
|
252
|
+
let alertsDeleted = 0;
|
|
253
|
+
try {
|
|
254
|
+
const eventResult = await session.run(
|
|
255
|
+
`MATCH (e:Event)
|
|
256
|
+
WHERE e.actionTool = "review-digest-compose"
|
|
257
|
+
OR e.eventId STARTS WITH "review-digest-"
|
|
258
|
+
DETACH DELETE e
|
|
259
|
+
RETURN count(e) AS deleted`
|
|
260
|
+
);
|
|
261
|
+
eventsDeleted = toNumber(eventResult.records[0]?.get("deleted"));
|
|
262
|
+
const alertResult = await session.run(
|
|
263
|
+
`MATCH (a:ReviewAlert)
|
|
264
|
+
DETACH DELETE a
|
|
265
|
+
RETURN count(a) AS deleted`
|
|
266
|
+
);
|
|
267
|
+
alertsDeleted = toNumber(alertResult.records[0]?.get("deleted"));
|
|
268
|
+
} finally {
|
|
269
|
+
await session.close();
|
|
270
|
+
}
|
|
271
|
+
const installDirName = basename(dirname(platformRoot));
|
|
272
|
+
const configDir = resolve3(homedir(), `.${installDirName}`);
|
|
273
|
+
const artefacts = [
|
|
274
|
+
resolve3(configDir, "logs", "review.log"),
|
|
275
|
+
resolve3(configDir, "review-rules.json"),
|
|
276
|
+
resolve3(configDir, "review-state.json"),
|
|
277
|
+
resolve3(configDir, "review-pending-alerts.jsonl")
|
|
278
|
+
];
|
|
279
|
+
for (const path of artefacts) {
|
|
280
|
+
try {
|
|
281
|
+
unlinkSync(path);
|
|
282
|
+
} catch (err) {
|
|
283
|
+
const code = err.code;
|
|
284
|
+
if (code === "ENOENT") continue;
|
|
285
|
+
console.error(
|
|
286
|
+
`[migration] removed-review-feature unlink-skip path=${path} reason=${code ?? "unknown"}`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
console.error(
|
|
291
|
+
`[migration] removed-review-feature events=${eventsDeleted} alerts=${alertsDeleted}`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
function toNumber(v) {
|
|
295
|
+
if (typeof v === "number") return v;
|
|
296
|
+
if (v && typeof v.toNumber === "function") {
|
|
297
|
+
return v.toNumber();
|
|
298
|
+
}
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ../neo4j/migrations/006-prune-bogus-whatsapp-persons.ts
|
|
303
|
+
var POLLUTED_NAME_REGEX = "(?s).*[\\n\\[].*";
|
|
304
|
+
async function pruneBogusWhatsappPersons(driver) {
|
|
305
|
+
const session = driver.session();
|
|
306
|
+
try {
|
|
307
|
+
const nonAutoRes = await session.run(
|
|
308
|
+
`MATCH (p:Person {source: 'whatsapp'})
|
|
309
|
+
WHERE coalesce(p.participantStatus, '') <> 'auto-created'
|
|
310
|
+
AND p.name =~ $regex
|
|
311
|
+
RETURN elementId(p) AS elementId, p.name AS name`,
|
|
312
|
+
{ regex: POLLUTED_NAME_REGEX }
|
|
313
|
+
);
|
|
314
|
+
const skippedNonAuto = nonAutoRes.records.length;
|
|
315
|
+
for (const record of nonAutoRes.records) {
|
|
316
|
+
const elementId = record.get("elementId");
|
|
317
|
+
const name = record.get("name");
|
|
318
|
+
console.error(
|
|
319
|
+
`[migration:whatsapp-bogus-person-prune] non-auto-match elementId=${elementId} name=${JSON.stringify(name)}`
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
const matchedRes = await session.run(
|
|
323
|
+
`MATCH (p:Person {source: 'whatsapp', participantStatus: 'auto-created'})
|
|
324
|
+
WHERE p.name =~ $regex
|
|
325
|
+
RETURN count(p) AS matched`,
|
|
326
|
+
{ regex: POLLUTED_NAME_REGEX }
|
|
327
|
+
);
|
|
328
|
+
const matched = toNumber2(matchedRes.records[0]?.get("matched"));
|
|
329
|
+
if (matched === 0) {
|
|
330
|
+
console.error(
|
|
331
|
+
`[migration:whatsapp-bogus-person-prune] matched=0 deleted=0 skipped-non-auto=${skippedNonAuto}`
|
|
332
|
+
);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const deleteRes = await session.run(
|
|
336
|
+
`MATCH (p:Person {source: 'whatsapp', participantStatus: 'auto-created'})
|
|
337
|
+
WHERE p.name =~ $regex
|
|
338
|
+
DETACH DELETE p
|
|
339
|
+
RETURN count(p) AS deleted`,
|
|
340
|
+
{ regex: POLLUTED_NAME_REGEX }
|
|
341
|
+
);
|
|
342
|
+
const deleted = toNumber2(deleteRes.records[0]?.get("deleted"));
|
|
343
|
+
console.error(
|
|
344
|
+
`[migration:whatsapp-bogus-person-prune] matched=${matched} deleted=${deleted} skipped-non-auto=${skippedNonAuto}`
|
|
345
|
+
);
|
|
346
|
+
} finally {
|
|
347
|
+
await session.close();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function toNumber2(v) {
|
|
351
|
+
if (typeof v === "number") return v;
|
|
352
|
+
if (v && typeof v.toNumber === "function") {
|
|
353
|
+
return v.toNumber();
|
|
354
|
+
}
|
|
355
|
+
return 0;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// ../neo4j/migrations/007-conversation-archive-source.ts
|
|
359
|
+
async function backfillConversationArchiveSource(driver) {
|
|
360
|
+
const session = driver.session();
|
|
361
|
+
try {
|
|
362
|
+
const archivesSourceSet = await runCount(
|
|
363
|
+
session,
|
|
364
|
+
`MATCH (a:ConversationArchive)
|
|
365
|
+
WHERE a.source IS NULL
|
|
366
|
+
SET a.source = 'whatsapp'
|
|
367
|
+
RETURN count(a) AS n`
|
|
368
|
+
);
|
|
369
|
+
const archivesAgentRenamed = await runCount(
|
|
370
|
+
session,
|
|
371
|
+
`MATCH (a:ConversationArchive)
|
|
372
|
+
WHERE a.createdByAgent = 'whatsapp-import'
|
|
373
|
+
SET a.createdByAgent = 'conversation-archive'
|
|
374
|
+
RETURN count(a) AS n`
|
|
375
|
+
);
|
|
376
|
+
const chunksSourceSet = await runCount(
|
|
377
|
+
session,
|
|
378
|
+
`MATCH (c:Section:Conversation)
|
|
379
|
+
WHERE c.source IS NULL
|
|
380
|
+
SET c.source = 'whatsapp'
|
|
381
|
+
RETURN count(c) AS n`
|
|
382
|
+
);
|
|
383
|
+
const chunksAgentRenamed = await runCount(
|
|
384
|
+
session,
|
|
385
|
+
`MATCH (c:Section:Conversation)
|
|
386
|
+
WHERE c.createdByAgent = 'whatsapp-import'
|
|
387
|
+
SET c.createdByAgent = 'conversation-archive'
|
|
388
|
+
RETURN count(c) AS n`
|
|
389
|
+
);
|
|
390
|
+
const edgesAgentRenamed = await runCount(
|
|
391
|
+
session,
|
|
392
|
+
`MATCH (a:ConversationArchive)-[r]-()
|
|
393
|
+
WHERE r.createdByAgent = 'whatsapp-import'
|
|
394
|
+
SET r.createdByAgent = 'conversation-archive'
|
|
395
|
+
RETURN count(r) AS n`
|
|
396
|
+
);
|
|
397
|
+
console.error(
|
|
398
|
+
`[migration:conversation-archive-source] archives-source-set=${archivesSourceSet} archives-agent-renamed=${archivesAgentRenamed} chunks-source-set=${chunksSourceSet} chunks-agent-renamed=${chunksAgentRenamed} edges-agent-renamed=${edgesAgentRenamed}`
|
|
399
|
+
);
|
|
400
|
+
} finally {
|
|
401
|
+
await session.close();
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async function runCount(session, cypher) {
|
|
405
|
+
const res = await session.run(cypher);
|
|
406
|
+
const v = res.records[0]?.get("n");
|
|
407
|
+
if (typeof v === "number") return v;
|
|
408
|
+
if (v && typeof v.toNumber === "function") {
|
|
409
|
+
return v.toNumber();
|
|
410
|
+
}
|
|
411
|
+
return 0;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// app/lib/neo4j-migrations.ts
|
|
415
|
+
var BOOT_MIGRATIONS = [
|
|
416
|
+
{ fileName: "003-person-name-eradicate.cypher", slug: "person-name-eradicate" }
|
|
417
|
+
];
|
|
418
|
+
async function applyBootMigrations(driver, platformRoot) {
|
|
419
|
+
for (const migration of BOOT_MIGRATIONS) {
|
|
420
|
+
await applyOne(driver, platformRoot, migration);
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
await pruneAlienAccounts(driver, platformRoot);
|
|
424
|
+
} catch (err) {
|
|
425
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
426
|
+
console.error(`[migration] failed prune-alien-accounts error="${msg}"`);
|
|
427
|
+
}
|
|
428
|
+
try {
|
|
429
|
+
await applyAdminAgentBackfill(driver, platformRoot);
|
|
430
|
+
} catch (err) {
|
|
431
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
432
|
+
console.error(`[migration] failed admin-agent-graph-backfill error="${msg}"`);
|
|
433
|
+
}
|
|
434
|
+
try {
|
|
435
|
+
await removeReviewFeature(driver, platformRoot);
|
|
436
|
+
} catch (err) {
|
|
437
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
438
|
+
console.error(`[migration] failed removed-review-feature error="${msg}"`);
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
await pruneBogusWhatsappPersons(driver);
|
|
442
|
+
} catch (err) {
|
|
443
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
444
|
+
console.error(`[migration] failed prune-bogus-whatsapp-persons error="${msg}"`);
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
await backfillConversationArchiveSource(driver);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
450
|
+
console.error(`[migration] failed conversation-archive-source error="${msg}"`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
async function applyOne(driver, platformRoot, migration) {
|
|
454
|
+
const path = resolve4(platformRoot, "neo4j/migrations", migration.fileName);
|
|
455
|
+
let cypher;
|
|
456
|
+
try {
|
|
457
|
+
cypher = readFileSync2(path, "utf-8");
|
|
458
|
+
} catch (err) {
|
|
459
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
460
|
+
console.error(
|
|
461
|
+
`[migration] failed ${migration.slug} error=cannot-read-file path=${path} msg=${msg}`
|
|
462
|
+
);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const session = driver.session();
|
|
466
|
+
try {
|
|
467
|
+
const result = await session.run(cypher);
|
|
468
|
+
const record = result.records[0];
|
|
469
|
+
const removedRaw = record?.get("removed");
|
|
470
|
+
const removed = toNumber3(removedRaw);
|
|
471
|
+
console.error(
|
|
472
|
+
`[migration] applied ${migration.slug} removed=${removed}`
|
|
473
|
+
);
|
|
474
|
+
} catch (err) {
|
|
475
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
476
|
+
console.error(`[migration] failed ${migration.slug} error="${msg}"`);
|
|
477
|
+
} finally {
|
|
478
|
+
await session.close();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function toNumber3(v) {
|
|
482
|
+
if (typeof v === "number") return v;
|
|
483
|
+
if (v && typeof v.toNumber === "function") {
|
|
484
|
+
return v.toNumber();
|
|
485
|
+
}
|
|
486
|
+
return 0;
|
|
487
|
+
}
|
|
488
|
+
export {
|
|
489
|
+
applyBootMigrations
|
|
490
|
+
};
|