@askexenow/exe-os 0.9.265 → 0.9.266
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/deploy/compose/.env.example +4 -2
- package/deploy/compose/docker-compose.yml +6 -4
- package/deploy/compose/generate-env.ts +5 -2
- package/dist/active-agent-2XJJZFEW.js +25 -0
- package/dist/active-agent-JZ4PHIAK.js +26 -0
- package/dist/agentic-ontology-J4B525DT.js +25 -0
- package/dist/backfill-metadata-TWEC6BJD.js +597 -0
- package/dist/backfill-metadata-VGZLCJWZ.js +597 -0
- package/dist/behaviors-BPIVFAGY.js +25 -0
- package/dist/bin/agentic-ontology-backfill.js +5 -5
- package/dist/bin/agentic-reflection-backfill.js +6 -6
- package/dist/bin/agentic-semantic-label.js +5 -5
- package/dist/bin/backfill-conversations.js +4 -4
- package/dist/bin/backfill-responses.js +4 -4
- package/dist/bin/backfill-vectors.js +5 -5
- package/dist/bin/bulk-sync-postgres.js +6 -6
- package/dist/bin/cc-doctor.js +6 -1
- package/dist/bin/cleanup-stale-review-tasks.js +9 -9
- package/dist/bin/cli.js +15 -15
- package/dist/bin/exe-agent-config.js +2 -2
- package/dist/bin/exe-agent.js +4 -4
- package/dist/bin/exe-assign.js +5 -5
- package/dist/bin/exe-boot.js +16 -16
- package/dist/bin/exe-call.js +4 -4
- package/dist/bin/exe-cloud.js +4 -4
- package/dist/bin/exe-dispatch.js +9 -9
- package/dist/bin/exe-doctor.js +1 -1
- package/dist/bin/exe-export-behaviors.js +7 -7
- package/dist/bin/exe-forget.js +6 -6
- package/dist/bin/exe-gateway.js +7 -7
- package/dist/bin/exe-healthcheck.js +6 -1
- package/dist/bin/exe-heartbeat.js +9 -9
- package/dist/bin/exe-kill.js +12 -12
- package/dist/bin/exe-launch-agent.js +16 -16
- package/dist/bin/exe-new-employee.js +6 -6
- package/dist/bin/exe-pending-messages.js +10 -10
- package/dist/bin/exe-pending-notifications.js +9 -9
- package/dist/bin/exe-pending-reviews.js +9 -9
- package/dist/bin/exe-rename.js +4 -4
- package/dist/bin/exe-review.js +11 -11
- package/dist/bin/exe-search.js +5 -5
- package/dist/bin/exe-session-cleanup.js +14 -14
- package/dist/bin/exe-settings.js +4 -4
- package/dist/bin/exe-start-codex.js +11 -11
- package/dist/bin/exe-start-opencode.js +8 -8
- package/dist/bin/exe-status.js +10 -10
- package/dist/bin/exe-team.js +3 -3
- package/dist/bin/git-sweep.js +10 -10
- package/dist/bin/graph-backfill.js +4 -4
- package/dist/bin/graph-export.js +5 -5
- package/dist/bin/import-history.js +7 -7
- package/dist/bin/install.js +6 -6
- package/dist/bin/intercom-check.js +4 -4
- package/dist/bin/mcp-sessions.js +2 -2
- package/dist/bin/orchestration-metrics.js +4 -4
- package/dist/bin/postgres-agentic-reflection-backfill.js +2 -2
- package/dist/bin/postgres-agentic-semantic-backfill.js +1 -1
- package/dist/bin/scan-tasks.js +9 -9
- package/dist/bin/setup.js +1 -1
- package/dist/bin/shard-migrate.js +4 -4
- package/dist/capacity-monitor-3QORC56J.js +49 -0
- package/dist/capacity-monitor-FWRBCZCZ.js +49 -0
- package/dist/catchup-brief-242H63OP.js +151 -0
- package/dist/catchup-brief-T7W2ARRB.js +151 -0
- package/dist/catchup-brief-VJDLXJHJ.js +151 -0
- package/dist/chunk-2FDYA3GS.js +75 -0
- package/dist/chunk-2V33IVZF.js +1148 -0
- package/dist/chunk-2W5NQOQJ.js +333 -0
- package/dist/chunk-32QR5EHE.js +244 -0
- package/dist/chunk-3DBROKA6.js +382 -0
- package/dist/chunk-3DS2YHAT.js +204 -0
- package/dist/chunk-3O2ZD7YV.js +227 -0
- package/dist/chunk-43O2PZH7.js +214 -0
- package/dist/chunk-4AHL6I7X.js +284 -0
- package/dist/chunk-5GBPXJIH.js +50 -0
- package/dist/chunk-5IXN2532.js +58 -0
- package/dist/chunk-5SH5TR45.js +731 -0
- package/dist/chunk-5XGMTWKW.js +128 -0
- package/dist/chunk-6AQAILCS.js +13696 -0
- package/dist/chunk-72KQJZBH.js +382 -0
- package/dist/chunk-7B2AENJ3.js +1345 -0
- package/dist/chunk-7GKMYFVR.js +551 -0
- package/dist/chunk-7HUGVJHW.js +1021 -0
- package/dist/chunk-7HWBGXDV.js +333 -0
- package/dist/chunk-7ROGPDW6.js +197 -0
- package/dist/chunk-7ZMLNURG.js +513 -0
- package/dist/chunk-A3G4UXNA.js +280 -0
- package/dist/chunk-A4T6U3XZ.js +371 -0
- package/dist/chunk-ADJNRFEK.js +13696 -0
- package/dist/chunk-AVJTW67M.js +513 -0
- package/dist/chunk-B6RC7DAC.js +1090 -0
- package/dist/chunk-BAOJLZVC.js +244 -0
- package/dist/chunk-BCUMPA7J.js +159 -0
- package/dist/chunk-BH2ST7KK.js +183 -0
- package/dist/chunk-C4BIYP5C.js +129 -0
- package/dist/chunk-CBUZG6OC.js +89 -0
- package/dist/chunk-CGQRWCCP.js +81 -0
- package/dist/chunk-CLX4WQHT.js +214 -0
- package/dist/chunk-D4CQZL46.js +76 -0
- package/dist/chunk-DEBLYXA2.js +56 -0
- package/dist/chunk-EDNUE5L3.js +38 -0
- package/dist/chunk-ESNHLTLC.js +1073 -0
- package/dist/chunk-FICUAZEA.js +128 -0
- package/dist/chunk-FP6U5PSY.js +818 -0
- package/dist/chunk-G55UTKFR.js +89 -0
- package/dist/chunk-GIJUXLK5.js +330 -0
- package/dist/chunk-GVSSEGIV.js +348 -0
- package/dist/chunk-GYOOZ725.js +330 -0
- package/dist/chunk-HCULUL4D.js +447 -0
- package/dist/chunk-HDRQKH7R.js +1051 -0
- package/dist/chunk-HHBN7Y7R.js +197 -0
- package/dist/chunk-IQBXQ7GF.js +1073 -0
- package/dist/chunk-ITF6GEJI.js +2091 -0
- package/dist/chunk-IXHVSWLM.js +58 -0
- package/dist/chunk-J3ZFONT4.js +1921 -0
- package/dist/chunk-JEOFG274.js +394 -0
- package/dist/chunk-JH7ISOIJ.js +33 -0
- package/dist/chunk-JVRMAVPN.js +731 -0
- package/dist/chunk-KBYRYSXT.js +3951 -0
- package/dist/chunk-KECNXWD6.js +1051 -0
- package/dist/chunk-KIYCHS35.js +128 -0
- package/dist/chunk-KUP3D6G2.js +1345 -0
- package/dist/chunk-KXS5HHDH.js +54 -0
- package/dist/chunk-LVZW4WQY.js +221 -0
- package/dist/chunk-LWOCCDSB.js +240 -0
- package/dist/chunk-M4HRKRSE.js +30 -0
- package/dist/chunk-MPG5DR3K.js +244 -0
- package/dist/chunk-NOG2LVBA.js +159 -0
- package/dist/chunk-NP3CYOEY.js +290 -0
- package/dist/chunk-OVQOKLYA.js +210 -0
- package/dist/chunk-OW26ML36.js +1148 -0
- package/dist/chunk-P2DOIWQG.js +260 -0
- package/dist/chunk-P2QTTEYP.js +3951 -0
- package/dist/chunk-P5IKFL7B.js +85 -0
- package/dist/chunk-PD2LUPHD.js +377 -0
- package/dist/chunk-PF5EFIAH.js +818 -0
- package/dist/chunk-PK3NFO76.js +551 -0
- package/dist/chunk-QKMFMJTU.js +171 -0
- package/dist/chunk-R77M74QM.js +13696 -0
- package/dist/chunk-RHZ2CRJU.js +3556 -0
- package/dist/chunk-RLR4LVO5.js +1090 -0
- package/dist/chunk-RMDDSWFH.js +495 -0
- package/dist/chunk-RPLEZ74B.js +95 -0
- package/dist/chunk-RXMVPGH2.js +346 -0
- package/dist/chunk-S2ARWNS6.js +135 -0
- package/dist/chunk-SHPIATX7.js +90 -0
- package/dist/chunk-SQUZ3TI2.js +668 -0
- package/dist/chunk-SUGBKORD.js +1148 -0
- package/dist/chunk-T2XD7XL2.js +346 -0
- package/dist/chunk-TAIYLROT.js +127 -0
- package/dist/chunk-TCD4XCBS.js +495 -0
- package/dist/chunk-TSBMSHMM.js +163 -0
- package/dist/chunk-U776PBU6.js +488 -0
- package/dist/chunk-UTVNIAOF.js +284 -0
- package/dist/chunk-VF6VT4MR.js +70 -0
- package/dist/chunk-VZXLYUKS.js +171 -0
- package/dist/chunk-WIAHPJDS.js +58 -0
- package/dist/chunk-WM5ELLT4.js +54 -0
- package/dist/chunk-WUUSPOCC.js +1921 -0
- package/dist/chunk-WXHAMPK4.js +81 -0
- package/dist/chunk-WYNZ23XH.js +262 -0
- package/dist/chunk-WZOQLU2Y.js +127 -0
- package/dist/chunk-X24GBZKR.js +157 -0
- package/dist/chunk-X5FRF5MG.js +13696 -0
- package/dist/chunk-XBPLYFBA.js +204 -0
- package/dist/chunk-XDGKFXFW.js +363 -0
- package/dist/chunk-XIT6ONPY.js +630 -0
- package/dist/chunk-XNRJ5JHU.js +377 -0
- package/dist/chunk-XREWTPZM.js +123 -0
- package/dist/chunk-XURCA5VD.js +297 -0
- package/dist/chunk-Y55VFZJB.js +50 -0
- package/dist/chunk-YIH2YMWP.js +76 -0
- package/dist/chunk-YZMCCT73.js +97 -0
- package/dist/chunk-ZTP3VV23.js +447 -0
- package/dist/co-activation-JOYR73H2.js +72 -0
- package/dist/co-occurrence-G7RRJ3DB.js +74 -0
- package/dist/core-memory-6KK55Z65.js +110 -0
- package/dist/core-memory-QRS6GBXL.js +110 -0
- package/dist/crdt-sync-QWK65Z5A.js +33 -0
- package/dist/crm-webhook-BNUS3USD.js +10 -0
- package/dist/crm-webhook-ZTIRFVAH.js +10 -0
- package/dist/cto-delegation-gate-DNZJGBS7.js +206 -0
- package/dist/cto-delegation-gate-YI3LK7VY.js +206 -0
- package/dist/daemon-orchestration-7LVOHYKA.js +135 -0
- package/dist/daemon-orchestration-SDQNWI3K.js +135 -0
- package/dist/db-backup-5ENHDNZI.js +33 -0
- package/dist/dreaming-PGJOCGAM.js +32 -0
- package/dist/dreaming-UNHHGOU3.js +32 -0
- package/dist/exe-drift-QQJMUQXA.js +68 -0
- package/dist/exe-export-BEZZSQB4.js +73 -0
- package/dist/exe-export-TQGI2VBT.js +73 -0
- package/dist/exe-import-2SR2UP3D.js +76 -0
- package/dist/exe-import-73Q4VLFK.js +76 -0
- package/dist/exe-key-6JHEINOM.js +579 -0
- package/dist/exe-key-RIRPIFK6.js +579 -0
- package/dist/exe-snapshot-NDMDQJOH.js +164 -0
- package/dist/exe-snapshot-PVCBPMPJ.js +164 -0
- package/dist/fast-db-init-22OBOPTN.js +7 -0
- package/dist/fast-db-init-M6ZYYGAL.js +7 -0
- package/dist/gateway/index.js +8 -8
- package/dist/git-staleness-4DGYC3RY.js +110 -0
- package/dist/git-task-sweep-CUR7R2ZM.js +40 -0
- package/dist/git-task-sweep-YG3IVGK3.js +40 -0
- package/dist/global-procedures-TYDNKM7V.js +20 -0
- package/dist/graph-auto-extract-I6B5HWTP.js +162 -0
- package/dist/hooks/bug-report-worker.js +11 -11
- package/dist/hooks/codex-stop-task-finalizer.js +11 -11
- package/dist/hooks/commit-complete.js +11 -11
- package/dist/hooks/error-recall.js +6 -6
- package/dist/hooks/exe-heartbeat-hook.js +3 -3
- package/dist/hooks/ingest.js +6 -6
- package/dist/hooks/instructions-loaded.js +4 -4
- package/dist/hooks/manifest.json +19 -19
- package/dist/hooks/notification.js +4 -4
- package/dist/hooks/post-compact.js +10 -10
- package/dist/hooks/post-tool-combined.js +5 -5
- package/dist/hooks/pre-compact.js +11 -11
- package/dist/hooks/pre-tool-use.js +14 -14
- package/dist/hooks/prompt-submit.js +20 -20
- package/dist/hooks/session-end.js +15 -15
- package/dist/hooks/session-start.js +10 -10
- package/dist/hooks/stop.js +14 -14
- package/dist/hooks/subagent-stop.js +10 -10
- package/dist/hooks/summary-worker.js +14 -14
- package/dist/index.js +17 -17
- package/dist/installer-4LP73C3M.js +38 -0
- package/dist/installer-AUVLNS4D.js +296 -0
- package/dist/installer-KCRLQSQH.js +38 -0
- package/dist/installer-KGXYUOIV.js +296 -0
- package/dist/installer-UI6TNJGO.js +342 -0
- package/dist/installer-Z7NPD4PD.js +342 -0
- package/dist/lib/cloud-sync.js +4 -4
- package/dist/lib/consolidation.js +5 -5
- package/dist/lib/database.js +2 -2
- package/dist/lib/db-daemon-client.js +6 -0
- package/dist/lib/db.js +2 -2
- package/dist/lib/employee-templates.js +4 -4
- package/dist/lib/employees.js +2 -2
- package/dist/lib/exe-daemon.js +39 -38
- package/dist/lib/hybrid-search.js +5 -5
- package/dist/lib/identity.js +2 -2
- package/dist/lib/messaging.js +9 -9
- package/dist/lib/reminders.js +3 -3
- package/dist/lib/schedules.js +5 -5
- package/dist/lib/session-registry.js +4 -4
- package/dist/lib/skill-learning.js +4 -4
- package/dist/lib/store.js +4 -4
- package/dist/lib/task-router.js +3 -3
- package/dist/lib/tasks.js +10 -10
- package/dist/lib/tmux-routing.js +8 -8
- package/dist/lib/token-spend.js +3 -3
- package/dist/mcp/register-tools.js +53 -52
- package/dist/mcp/server.js +54 -53
- package/dist/mcp/tools/complete-reminder.js +4 -4
- package/dist/mcp/tools/create-reminder.js +4 -4
- package/dist/mcp/tools/create-task.js +12 -12
- package/dist/mcp/tools/deactivate-behavior.js +5 -5
- package/dist/mcp/tools/list-reminders.js +4 -4
- package/dist/mcp/tools/list-tasks.js +12 -12
- package/dist/mcp/tools/send-message.js +11 -11
- package/dist/mcp/tools/update-task.js +11 -11
- package/dist/mcp-http-config-LN5ITKGS.js +27 -0
- package/dist/mcp-http-config-V43VHNEH.js +27 -0
- package/dist/memory-cards-S36DCEY4.js +174 -0
- package/dist/memory-graph-extractor-66YL4V4B.js +17 -0
- package/dist/memory-poisoning-defense-MXWE6CTY.js +225 -0
- package/dist/memory-reflection-W676LUX5.js +238 -0
- package/dist/notifications-OFLXZTDZ.js +45 -0
- package/dist/notifications-XAV4V7T5.js +45 -0
- package/dist/orchestration-events-MJLWJ2H2.js +25 -0
- package/dist/orchestrator-AIAKV5ST.js +33 -0
- package/dist/orchestrator-VK7D6I36.js +33 -0
- package/dist/pipeline-router-DXH5QVUH.js +13 -0
- package/dist/pipeline-router-EV6C5S33.js +13 -0
- package/dist/plan-limits-TQMLKZBG.js +26 -0
- package/dist/project-boot-4XTXHDG4.js +299 -0
- package/dist/projection-worker-NAYVNSI4.js +964 -0
- package/dist/reranker-KHZI7HQK.js +19 -0
- package/dist/reranker-UPMS3OX7.js +19 -0
- package/dist/reranker-ZN73HWSB.js +19 -0
- package/dist/review-polling-3UEZSPNT.js +124 -0
- package/dist/review-polling-KBDX3ILL.js +124 -0
- package/dist/runtime/index.js +11 -11
- package/dist/session-events-2CHOLA6D.js +36 -0
- package/dist/session-events-HM22KEHN.js +36 -0
- package/dist/session-kill-telemetry-LUPVYGZX.js +29 -0
- package/dist/session-scope-EPZZZHHJ.js +86 -0
- package/dist/session-scope-ZGE6GHMS.js +86 -0
- package/dist/setup-wizard-KNWH54HW.js +12 -0
- package/dist/skill-refinement-C4GNWV4F.js +157 -0
- package/dist/skill-refinement-CAUIE4YM.js +157 -0
- package/dist/steward-gate-MZ2DV36N.js +13 -0
- package/dist/task-enforcement-6OMXG6EA.js +333 -0
- package/dist/task-enforcement-JFSF6QDD.js +333 -0
- package/dist/task-scope-4HJSCJ7L.js +35 -0
- package/dist/task-scope-7HYE4AS6.js +35 -0
- package/dist/tasks-crud-JJL6MMJF.js +77 -0
- package/dist/tasks-crud-KMIPDHBZ.js +77 -0
- package/dist/tasks-notify-5D6LF52K.js +38 -0
- package/dist/tasks-notify-JNGGXFUY.js +38 -0
- package/dist/tasks-review-N6I5UC7G.js +47 -0
- package/dist/tasks-review-USHAMO5N.js +47 -0
- package/dist/telemetry-upload-BV2M2NND.js +739 -0
- package/dist/telemetry-upload-Y7QPDJW4.js +739 -0
- package/dist/token-budget-2LUZOFO7.js +84 -0
- package/dist/tool-telemetry-5JT6DPVK.js +17 -0
- package/dist/tui/App.js +16 -16
- package/dist/tui-data-DMAKZMGD.js +258 -0
- package/dist/tui-data-X7NI6ZQ3.js +258 -0
- package/dist/wiki-acl-QHGGWX63.js +111 -0
- package/dist/worker-gate-4XKUOFWO.js +21 -0
- package/dist/worker-gate-TPZBOXOA.js +21 -0
- package/dist/workflow-engine-F3URLOPA.js +28 -0
- package/dist/workflow-engine-OFOL446Z.js +28 -0
- package/dist/worktree-V3NVP7MV.js +26 -0
- package/dist/worktree-sweep-2CADL43Y.js +19 -0
- package/package.json +1 -1
- package/release-notes.json +16 -15
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getClient
|
|
3
|
+
} from "./chunk-RHZ2CRJU.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/pipeline-router.ts
|
|
6
|
+
import crypto from "crypto";
|
|
7
|
+
async function sinkConversationStore(msg, agentResponse, agentName) {
|
|
8
|
+
try {
|
|
9
|
+
const client = getClient();
|
|
10
|
+
const id = crypto.randomUUID();
|
|
11
|
+
const mediaJson = msg.media ? JSON.stringify(msg.media) : null;
|
|
12
|
+
await client.execute({
|
|
13
|
+
sql: `INSERT INTO conversations
|
|
14
|
+
(id, platform, external_id, sender_id, sender_name, sender_phone, sender_email,
|
|
15
|
+
recipient_id, channel_id, thread_id, reply_to_id,
|
|
16
|
+
content_text, content_media, agent_response, agent_name,
|
|
17
|
+
timestamp, ingested_at)
|
|
18
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
19
|
+
args: [
|
|
20
|
+
id,
|
|
21
|
+
msg.platform,
|
|
22
|
+
msg.messageId,
|
|
23
|
+
msg.senderId,
|
|
24
|
+
msg.senderName ?? null,
|
|
25
|
+
msg.senderPhone ?? null,
|
|
26
|
+
msg.senderEmail ?? null,
|
|
27
|
+
msg.accountId ?? null,
|
|
28
|
+
msg.channelId,
|
|
29
|
+
msg.threadId ?? `${msg.platform}:${msg.channelId}`,
|
|
30
|
+
msg.replyTo?.messageId ?? null,
|
|
31
|
+
msg.text ?? null,
|
|
32
|
+
mediaJson,
|
|
33
|
+
agentResponse ?? null,
|
|
34
|
+
agentName ?? null,
|
|
35
|
+
msg.timestamp,
|
|
36
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
return true;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
process.stderr.write(
|
|
42
|
+
`[pipeline] conversation-store error: ${err instanceof Error ? err.message : String(err)}
|
|
43
|
+
`
|
|
44
|
+
);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function sinkMemory(msg, agentResponse, agentName) {
|
|
49
|
+
try {
|
|
50
|
+
const { embed } = await import("./lib/embedder.js");
|
|
51
|
+
const { writeMemory, flushBatch } = await import("./lib/store.js");
|
|
52
|
+
const direction = agentResponse ? "conversation" : "inbound";
|
|
53
|
+
const rawText = [
|
|
54
|
+
`[${msg.platform}] ${direction} from ${msg.senderName ?? msg.senderId}`,
|
|
55
|
+
msg.text ? `Message: ${msg.text}` : null,
|
|
56
|
+
agentResponse ? `Agent (${agentName ?? "unknown"}): ${agentResponse}` : null
|
|
57
|
+
].filter(Boolean).join("\n");
|
|
58
|
+
const vector = await embed(rawText);
|
|
59
|
+
await writeMemory({
|
|
60
|
+
id: crypto.randomUUID(),
|
|
61
|
+
agent_id: agentName ?? "gateway",
|
|
62
|
+
agent_role: "gateway",
|
|
63
|
+
session_id: `gateway-${msg.platform}`,
|
|
64
|
+
timestamp: msg.timestamp,
|
|
65
|
+
tool_name: `gateway-${msg.platform}`,
|
|
66
|
+
project_name: "exe-os",
|
|
67
|
+
has_error: false,
|
|
68
|
+
raw_text: rawText,
|
|
69
|
+
vector,
|
|
70
|
+
importance: 4,
|
|
71
|
+
confidence: 0.8
|
|
72
|
+
});
|
|
73
|
+
await flushBatch();
|
|
74
|
+
return true;
|
|
75
|
+
} catch (err) {
|
|
76
|
+
process.stderr.write(
|
|
77
|
+
`[pipeline] memory-sink error: ${err instanceof Error ? err.message : String(err)}
|
|
78
|
+
`
|
|
79
|
+
);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function sinkCRM(msg, agentResponse, agentName) {
|
|
84
|
+
try {
|
|
85
|
+
const { isCRMBridgeEnabled, pushConversationToCRM, pushInboundMessageToCRM } = await import("./crm-bridge-BVTB6LZK.js");
|
|
86
|
+
if (!isCRMBridgeEnabled()) return false;
|
|
87
|
+
if (agentResponse) {
|
|
88
|
+
await pushConversationToCRM({
|
|
89
|
+
platform: msg.platform,
|
|
90
|
+
senderId: msg.senderId,
|
|
91
|
+
senderName: msg.senderName,
|
|
92
|
+
messageText: msg.text,
|
|
93
|
+
agentResponse,
|
|
94
|
+
agentName: agentName ?? "unknown",
|
|
95
|
+
timestamp: msg.timestamp,
|
|
96
|
+
accountId: msg.accountId
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
await pushInboundMessageToCRM({
|
|
100
|
+
platform: msg.platform,
|
|
101
|
+
senderId: msg.senderId,
|
|
102
|
+
senderName: msg.senderName,
|
|
103
|
+
messageText: msg.text,
|
|
104
|
+
timestamp: msg.timestamp,
|
|
105
|
+
accountId: msg.accountId
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
} catch (err) {
|
|
110
|
+
process.stderr.write(
|
|
111
|
+
`[pipeline] crm-sink error: ${err instanceof Error ? err.message : String(err)}
|
|
112
|
+
`
|
|
113
|
+
);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function sinkWiki(msg, agentResponse) {
|
|
118
|
+
try {
|
|
119
|
+
const { createWikiClient } = await import("./wiki-client-GBPR45BQ.js");
|
|
120
|
+
const client = await createWikiClient();
|
|
121
|
+
if (!client) return false;
|
|
122
|
+
const content = msg.text ?? "";
|
|
123
|
+
if (content.length < 50) return false;
|
|
124
|
+
const { chatInWorkspace } = await import("./wiki-client-GBPR45BQ.js");
|
|
125
|
+
const ingestText = [
|
|
126
|
+
`[${msg.platform}] Message from ${msg.senderName ?? msg.senderId} (${msg.timestamp}):`,
|
|
127
|
+
content,
|
|
128
|
+
agentResponse ? `
|
|
129
|
+
Agent response: ${agentResponse}` : ""
|
|
130
|
+
].join("\n");
|
|
131
|
+
await chatInWorkspace(client, "conversations", ingestText, "chat");
|
|
132
|
+
return true;
|
|
133
|
+
} catch (err) {
|
|
134
|
+
process.stderr.write(
|
|
135
|
+
`[pipeline] wiki-sink error: ${err instanceof Error ? err.message : String(err)}
|
|
136
|
+
`
|
|
137
|
+
);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function sinkEntityExtraction(msg, agentResponse, agentName) {
|
|
142
|
+
try {
|
|
143
|
+
const { extractFromConversation } = await import("./conversation-entity-extractor-EYSI4DKM.js");
|
|
144
|
+
const { storeExtraction } = await import("./graph-rag-G3EG5Q6L.js");
|
|
145
|
+
if ((msg.text?.length ?? 0) < 20) return false;
|
|
146
|
+
if (msg.isHistorical) return false;
|
|
147
|
+
const extraction = await extractFromConversation(msg, agentResponse, agentName);
|
|
148
|
+
if (extraction.entities.length === 0) return false;
|
|
149
|
+
const client = getClient();
|
|
150
|
+
const memoryId = `conv:${msg.messageId}`;
|
|
151
|
+
await storeExtraction(client, extraction, memoryId, msg.timestamp);
|
|
152
|
+
import("./conversation-wiki-populator-L7O6F3BB.js").then(
|
|
153
|
+
({ populateWikiFromExtraction }) => populateWikiFromExtraction(extraction, msg, agentResponse, agentName)
|
|
154
|
+
).catch((err) => {
|
|
155
|
+
process.stderr.write(
|
|
156
|
+
`[pipeline] wiki-population error: ${err instanceof Error ? err.message : String(err)}
|
|
157
|
+
`
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
return true;
|
|
161
|
+
} catch (err) {
|
|
162
|
+
process.stderr.write(
|
|
163
|
+
`[pipeline] entity-extraction-sink error: ${err instanceof Error ? err.message : String(err)}
|
|
164
|
+
`
|
|
165
|
+
);
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function ingest(msg, agentResponse, agentName) {
|
|
170
|
+
const errors = [];
|
|
171
|
+
const [conversationStored, memorySunk, crmSunk, wikiSunk, entityExtracted] = await Promise.all([
|
|
172
|
+
sinkConversationStore(msg, agentResponse, agentName).catch((e) => {
|
|
173
|
+
errors.push(`conversation: ${e}`);
|
|
174
|
+
return false;
|
|
175
|
+
}),
|
|
176
|
+
sinkMemory(msg, agentResponse, agentName).catch((e) => {
|
|
177
|
+
errors.push(`memory: ${e}`);
|
|
178
|
+
return false;
|
|
179
|
+
}),
|
|
180
|
+
sinkCRM(msg, agentResponse, agentName).catch((e) => {
|
|
181
|
+
errors.push(`crm: ${e}`);
|
|
182
|
+
return false;
|
|
183
|
+
}),
|
|
184
|
+
sinkWiki(msg, agentResponse).catch((e) => {
|
|
185
|
+
errors.push(`wiki: ${e}`);
|
|
186
|
+
return false;
|
|
187
|
+
}),
|
|
188
|
+
sinkEntityExtraction(msg, agentResponse, agentName).catch((e) => {
|
|
189
|
+
errors.push(`entity-extraction: ${e}`);
|
|
190
|
+
return false;
|
|
191
|
+
})
|
|
192
|
+
]);
|
|
193
|
+
if (errors.length > 0) {
|
|
194
|
+
process.stderr.write(
|
|
195
|
+
`[pipeline] ${errors.length} sink error(s): ${errors.join("; ")}
|
|
196
|
+
`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return { conversationStored, memorySunk, crmSunk, wikiSunk, entityExtracted, errors };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export {
|
|
203
|
+
ingest
|
|
204
|
+
};
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PLATFORM_PROCEDURE_TITLES
|
|
3
|
+
} from "./chunk-K77WC6HA.js";
|
|
4
|
+
import {
|
|
5
|
+
getClient,
|
|
6
|
+
getIdentity,
|
|
7
|
+
listIdentities,
|
|
8
|
+
updateIdentity
|
|
9
|
+
} from "./chunk-RHZ2CRJU.js";
|
|
10
|
+
import {
|
|
11
|
+
atomicWriteJsonSync
|
|
12
|
+
} from "./chunk-LYH5HE24.js";
|
|
13
|
+
|
|
14
|
+
// src/lib/orchestration-package.ts
|
|
15
|
+
import { randomUUID } from "crypto";
|
|
16
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
|
17
|
+
import os from "os";
|
|
18
|
+
import path from "path";
|
|
19
|
+
var PACKAGE_VERSION = "1.0";
|
|
20
|
+
var ROSTER_FILENAME = "exe-employees.json";
|
|
21
|
+
var ROSTER_BACKUP_FILENAME = "exe-employees.json.bak";
|
|
22
|
+
var EXE_OS_DIRNAME = ".exe-os";
|
|
23
|
+
var DEFAULT_BEHAVIOR_PRIORITY = "p1";
|
|
24
|
+
var DEFAULT_PROCEDURE_PRIORITY = "p0";
|
|
25
|
+
var DEFAULT_IDENTITY_UPDATED_BY = "orchestration-import";
|
|
26
|
+
function ensureObject(value, label) {
|
|
27
|
+
if (value == null || Array.isArray(value) || typeof value !== "object") {
|
|
28
|
+
throw new Error(`${label} must be an object`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function ensureString(value, label) {
|
|
33
|
+
if (typeof value !== "string") {
|
|
34
|
+
throw new Error(`${label} must be a string`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function ensureOptionalString(value, label) {
|
|
39
|
+
if (value == null) return void 0;
|
|
40
|
+
return ensureString(value, label);
|
|
41
|
+
}
|
|
42
|
+
function ensureNullableString(value, label) {
|
|
43
|
+
if (value == null) return null;
|
|
44
|
+
return ensureString(value, label);
|
|
45
|
+
}
|
|
46
|
+
function ensurePriority(value, label, fallback) {
|
|
47
|
+
if (value == null) return fallback;
|
|
48
|
+
if (value === "p0" || value === "p1" || value === "p2") {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`${label} must be one of: p0, p1, p2`);
|
|
52
|
+
}
|
|
53
|
+
function validateRosterEntry(value, index) {
|
|
54
|
+
const record = ensureObject(value, `roster[${index}]`);
|
|
55
|
+
return {
|
|
56
|
+
name: ensureString(record.name, `roster[${index}].name`),
|
|
57
|
+
role: ensureString(record.role, `roster[${index}].role`),
|
|
58
|
+
systemPrompt: ensureString(record.systemPrompt, `roster[${index}].systemPrompt`),
|
|
59
|
+
createdAt: typeof record.createdAt === "string" ? record.createdAt : "",
|
|
60
|
+
templateName: ensureOptionalString(record.templateName, `roster[${index}].templateName`),
|
|
61
|
+
templateVersion: typeof record.templateVersion === "number" ? record.templateVersion : void 0
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function validateBehaviorEntry(value, index) {
|
|
65
|
+
const record = ensureObject(value, `behaviors[${index}]`);
|
|
66
|
+
return {
|
|
67
|
+
agent_id: ensureString(record.agent_id, `behaviors[${index}].agent_id`),
|
|
68
|
+
project_name: ensureNullableString(record.project_name, `behaviors[${index}].project_name`),
|
|
69
|
+
domain: ensureNullableString(record.domain, `behaviors[${index}].domain`),
|
|
70
|
+
content: ensureString(record.content, `behaviors[${index}].content`),
|
|
71
|
+
priority: ensurePriority(record.priority, `behaviors[${index}].priority`, DEFAULT_BEHAVIOR_PRIORITY)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function validateProcedureEntry(value, index) {
|
|
75
|
+
const record = ensureObject(value, `procedures[${index}]`);
|
|
76
|
+
return {
|
|
77
|
+
title: ensureString(record.title, `procedures[${index}].title`),
|
|
78
|
+
content: ensureString(record.content, `procedures[${index}].content`),
|
|
79
|
+
priority: ensurePriority(record.priority, `procedures[${index}].priority`, DEFAULT_PROCEDURE_PRIORITY),
|
|
80
|
+
domain: ensureNullableString(record.domain, `procedures[${index}].domain`)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function getRosterPath() {
|
|
84
|
+
return path.join(os.homedir(), EXE_OS_DIRNAME, ROSTER_FILENAME);
|
|
85
|
+
}
|
|
86
|
+
function getBackupPath() {
|
|
87
|
+
return path.join(os.homedir(), EXE_OS_DIRNAME, ROSTER_BACKUP_FILENAME);
|
|
88
|
+
}
|
|
89
|
+
function readRosterFile() {
|
|
90
|
+
const rosterPath = getRosterPath();
|
|
91
|
+
if (!existsSync(rosterPath)) return [];
|
|
92
|
+
const raw = readFileSync(rosterPath, "utf-8");
|
|
93
|
+
const parsed = JSON.parse(raw);
|
|
94
|
+
if (!Array.isArray(parsed)) {
|
|
95
|
+
throw new Error("Roster file must contain a JSON array");
|
|
96
|
+
}
|
|
97
|
+
return parsed.map((entry, index) => validateRosterEntry(entry, index));
|
|
98
|
+
}
|
|
99
|
+
function writeRosterFile(roster) {
|
|
100
|
+
if (roster.length === 0) {
|
|
101
|
+
throw new Error("Refusing to write empty roster \u2014 this would delete all employees");
|
|
102
|
+
}
|
|
103
|
+
const rosterPath = getRosterPath();
|
|
104
|
+
mkdirSync(path.dirname(rosterPath), { recursive: true });
|
|
105
|
+
if (existsSync(rosterPath)) {
|
|
106
|
+
const currentRoster = readRosterFile();
|
|
107
|
+
if (roster.length < currentRoster.length) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Refusing to write roster with ${roster.length} entries \u2014 current roster has ${currentRoster.length}. Import would delete ${currentRoster.length - roster.length} employee(s). Use merge strategy instead, or add the missing entries to the package.`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
copyFileSync(rosterPath, getBackupPath());
|
|
113
|
+
}
|
|
114
|
+
atomicWriteJsonSync(rosterPath, roster);
|
|
115
|
+
}
|
|
116
|
+
function buildImportedRosterEntries(roster, timestamp) {
|
|
117
|
+
return roster.map((entry) => ({
|
|
118
|
+
name: entry.name,
|
|
119
|
+
role: entry.role,
|
|
120
|
+
systemPrompt: entry.systemPrompt,
|
|
121
|
+
createdAt: timestamp,
|
|
122
|
+
...entry.templateName != null ? { templateName: entry.templateName } : {},
|
|
123
|
+
...entry.templateVersion != null ? { templateVersion: entry.templateVersion } : {}
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
async function insertBehaviors(behaviors, timestamp) {
|
|
127
|
+
const client = getClient();
|
|
128
|
+
for (const behavior of behaviors) {
|
|
129
|
+
await client.execute({
|
|
130
|
+
sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at)
|
|
131
|
+
VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?)`,
|
|
132
|
+
args: [
|
|
133
|
+
randomUUID(),
|
|
134
|
+
behavior.agent_id,
|
|
135
|
+
behavior.project_name,
|
|
136
|
+
behavior.domain,
|
|
137
|
+
behavior.priority,
|
|
138
|
+
behavior.content,
|
|
139
|
+
timestamp,
|
|
140
|
+
timestamp
|
|
141
|
+
]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return behaviors.length;
|
|
145
|
+
}
|
|
146
|
+
async function insertProcedures(procedures, timestamp, options) {
|
|
147
|
+
const client = getClient();
|
|
148
|
+
const skipTitles = options?.skipTitles ?? /* @__PURE__ */ new Set();
|
|
149
|
+
let inserted = 0;
|
|
150
|
+
for (const procedure of procedures) {
|
|
151
|
+
if (skipTitles.has(procedure.title) || PLATFORM_PROCEDURE_TITLES.has(procedure.title)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
await client.execute({
|
|
155
|
+
sql: `INSERT INTO company_procedures (id, title, content, priority, domain, active, created_at, updated_at)
|
|
156
|
+
VALUES (?, ?, ?, ?, ?, 1, ?, ?)`,
|
|
157
|
+
args: [
|
|
158
|
+
randomUUID(),
|
|
159
|
+
procedure.title,
|
|
160
|
+
procedure.content,
|
|
161
|
+
procedure.priority,
|
|
162
|
+
procedure.domain,
|
|
163
|
+
timestamp,
|
|
164
|
+
timestamp
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
skipTitles.add(procedure.title);
|
|
168
|
+
inserted += 1;
|
|
169
|
+
}
|
|
170
|
+
return inserted;
|
|
171
|
+
}
|
|
172
|
+
async function replaceBehaviorsAndProcedures(behaviors, procedures, timestamp) {
|
|
173
|
+
const client = getClient();
|
|
174
|
+
const existingBehaviors = await client.execute({
|
|
175
|
+
sql: "SELECT agent_id, content FROM behaviors WHERE active = 1",
|
|
176
|
+
args: []
|
|
177
|
+
});
|
|
178
|
+
const existingBehaviorKeys = new Set(
|
|
179
|
+
existingBehaviors.rows.map((row) => `${String(row.agent_id)}::${String(row.content)}`)
|
|
180
|
+
);
|
|
181
|
+
const newBehaviors = behaviors.filter(
|
|
182
|
+
(b) => !existingBehaviorKeys.has(`${b.agent_id}::${b.content}`)
|
|
183
|
+
);
|
|
184
|
+
const existingProcedureTitles = await getActiveProcedureTitles();
|
|
185
|
+
return {
|
|
186
|
+
behaviors: await insertBehaviors(newBehaviors, timestamp),
|
|
187
|
+
procedures: await insertProcedures(procedures, timestamp, { skipTitles: existingProcedureTitles })
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
async function mergeRosterEntries(importedRoster, timestamp) {
|
|
191
|
+
const currentRoster = readRosterFile();
|
|
192
|
+
const existingNames = new Set(currentRoster.map((entry) => entry.name.toLowerCase()));
|
|
193
|
+
const additions = buildImportedRosterEntries(
|
|
194
|
+
importedRoster.filter((entry) => !existingNames.has(entry.name.toLowerCase())),
|
|
195
|
+
timestamp
|
|
196
|
+
);
|
|
197
|
+
if (additions.length > 0) {
|
|
198
|
+
writeRosterFile([...currentRoster, ...additions]);
|
|
199
|
+
}
|
|
200
|
+
return additions.length;
|
|
201
|
+
}
|
|
202
|
+
async function replaceRosterEntries(importedRoster, timestamp) {
|
|
203
|
+
const currentRoster = readRosterFile();
|
|
204
|
+
const importedByName = new Map(
|
|
205
|
+
buildImportedRosterEntries(importedRoster, timestamp).map((entry) => [entry.name.toLowerCase(), entry])
|
|
206
|
+
);
|
|
207
|
+
const merged = currentRoster.map((existing) => {
|
|
208
|
+
const imported = importedByName.get(existing.name.toLowerCase());
|
|
209
|
+
if (imported) {
|
|
210
|
+
importedByName.delete(existing.name.toLowerCase());
|
|
211
|
+
return imported;
|
|
212
|
+
}
|
|
213
|
+
return existing;
|
|
214
|
+
});
|
|
215
|
+
for (const newEntry of importedByName.values()) {
|
|
216
|
+
merged.push(newEntry);
|
|
217
|
+
}
|
|
218
|
+
writeRosterFile(merged);
|
|
219
|
+
return importedRoster.length;
|
|
220
|
+
}
|
|
221
|
+
async function importIdentities(identities, updatedBy) {
|
|
222
|
+
const entries = Object.entries(identities);
|
|
223
|
+
let imported = 0;
|
|
224
|
+
for (const [agentId, content] of entries) {
|
|
225
|
+
const existing = getIdentity(agentId);
|
|
226
|
+
if (existing?.raw) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
await updateIdentity(agentId, content, updatedBy);
|
|
230
|
+
imported += 1;
|
|
231
|
+
}
|
|
232
|
+
return imported;
|
|
233
|
+
}
|
|
234
|
+
async function getActiveProcedureTitles() {
|
|
235
|
+
const client = getClient();
|
|
236
|
+
const result = await client.execute({
|
|
237
|
+
sql: "SELECT title FROM company_procedures WHERE active = 1",
|
|
238
|
+
args: []
|
|
239
|
+
});
|
|
240
|
+
return new Set(result.rows.map((row) => String(row.title)));
|
|
241
|
+
}
|
|
242
|
+
async function exportOrchestration(createdBy) {
|
|
243
|
+
const client = getClient();
|
|
244
|
+
const roster = readRosterFile().map((entry) => ({
|
|
245
|
+
...entry,
|
|
246
|
+
createdAt: ""
|
|
247
|
+
}));
|
|
248
|
+
const identities = {};
|
|
249
|
+
for (const identitySummary of listIdentities()) {
|
|
250
|
+
const identity = getIdentity(identitySummary.agentId);
|
|
251
|
+
if (identity?.raw) {
|
|
252
|
+
identities[identitySummary.agentId] = identity.raw;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const behaviorResult = await client.execute({
|
|
256
|
+
sql: "SELECT agent_id, project_name, domain, content, priority FROM behaviors WHERE active = 1",
|
|
257
|
+
args: []
|
|
258
|
+
});
|
|
259
|
+
const procedureResult = await client.execute({
|
|
260
|
+
sql: "SELECT title, content, priority, domain FROM company_procedures WHERE active = 1",
|
|
261
|
+
args: []
|
|
262
|
+
});
|
|
263
|
+
const behaviors = behaviorResult.rows.map((row) => ({
|
|
264
|
+
agent_id: String(row.agent_id),
|
|
265
|
+
project_name: row.project_name == null ? null : String(row.project_name),
|
|
266
|
+
domain: row.domain == null ? null : String(row.domain),
|
|
267
|
+
content: String(row.content),
|
|
268
|
+
priority: ensurePriority(row.priority, "behaviors.priority", DEFAULT_BEHAVIOR_PRIORITY)
|
|
269
|
+
}));
|
|
270
|
+
const procedures = procedureResult.rows.map((row) => ({
|
|
271
|
+
title: String(row.title),
|
|
272
|
+
content: String(row.content),
|
|
273
|
+
priority: ensurePriority(row.priority, "procedures.priority", DEFAULT_PROCEDURE_PRIORITY),
|
|
274
|
+
domain: row.domain == null ? null : String(row.domain)
|
|
275
|
+
})).filter((procedure) => !PLATFORM_PROCEDURE_TITLES.has(procedure.title));
|
|
276
|
+
return {
|
|
277
|
+
version: PACKAGE_VERSION,
|
|
278
|
+
created_by: createdBy,
|
|
279
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
280
|
+
roster,
|
|
281
|
+
identities,
|
|
282
|
+
behaviors,
|
|
283
|
+
procedures
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
async function importOrchestration(pkg, strategy) {
|
|
287
|
+
const validated = validatePackage(pkg);
|
|
288
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
289
|
+
const updatedBy = validated.created_by || DEFAULT_IDENTITY_UPDATED_BY;
|
|
290
|
+
const rosterCount = strategy === "replace" ? await replaceRosterEntries(validated.roster, timestamp) : await mergeRosterEntries(validated.roster, timestamp);
|
|
291
|
+
const identityCount = await importIdentities(validated.identities, updatedBy);
|
|
292
|
+
if (strategy === "replace") {
|
|
293
|
+
const replaced = await replaceBehaviorsAndProcedures(
|
|
294
|
+
validated.behaviors,
|
|
295
|
+
validated.procedures,
|
|
296
|
+
timestamp
|
|
297
|
+
);
|
|
298
|
+
return {
|
|
299
|
+
imported: {
|
|
300
|
+
roster: rosterCount,
|
|
301
|
+
identities: identityCount,
|
|
302
|
+
behaviors: replaced.behaviors,
|
|
303
|
+
procedures: replaced.procedures
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
const existingProcedureTitles = await getActiveProcedureTitles();
|
|
308
|
+
const behaviorCount = await insertBehaviors(validated.behaviors, timestamp);
|
|
309
|
+
const procedureCount = await insertProcedures(
|
|
310
|
+
validated.procedures,
|
|
311
|
+
timestamp,
|
|
312
|
+
{ skipTitles: existingProcedureTitles }
|
|
313
|
+
);
|
|
314
|
+
return {
|
|
315
|
+
imported: {
|
|
316
|
+
roster: rosterCount,
|
|
317
|
+
identities: identityCount,
|
|
318
|
+
behaviors: behaviorCount,
|
|
319
|
+
procedures: procedureCount
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function validatePackage(data) {
|
|
324
|
+
const record = ensureObject(data, "package");
|
|
325
|
+
const version = ensureString(record.version, "version");
|
|
326
|
+
if (version !== PACKAGE_VERSION) {
|
|
327
|
+
throw new Error(`Unsupported orchestration package version: ${version}`);
|
|
328
|
+
}
|
|
329
|
+
if (!Array.isArray(record.roster)) {
|
|
330
|
+
throw new Error("roster is required and must be an array");
|
|
331
|
+
}
|
|
332
|
+
if (record.identities == null || Array.isArray(record.identities) || typeof record.identities !== "object") {
|
|
333
|
+
throw new Error("identities is required and must be an object");
|
|
334
|
+
}
|
|
335
|
+
if (!Array.isArray(record.behaviors)) {
|
|
336
|
+
throw new Error("behaviors is required and must be an array");
|
|
337
|
+
}
|
|
338
|
+
if (!Array.isArray(record.procedures)) {
|
|
339
|
+
throw new Error("procedures is required and must be an array");
|
|
340
|
+
}
|
|
341
|
+
const identities = Object.entries(record.identities).reduce(
|
|
342
|
+
(acc, [agentId, content]) => {
|
|
343
|
+
acc[agentId] = ensureString(content, `identities.${agentId}`);
|
|
344
|
+
return acc;
|
|
345
|
+
},
|
|
346
|
+
{}
|
|
347
|
+
);
|
|
348
|
+
return {
|
|
349
|
+
version: PACKAGE_VERSION,
|
|
350
|
+
created_by: ensureString(record.created_by, "created_by"),
|
|
351
|
+
created_at: ensureString(record.created_at, "created_at"),
|
|
352
|
+
roster: record.roster.map((entry, index) => validateRosterEntry(entry, index)),
|
|
353
|
+
identities,
|
|
354
|
+
behaviors: record.behaviors.map((entry, index) => validateBehaviorEntry(entry, index)),
|
|
355
|
+
procedures: record.procedures.map((entry, index) => validateProcedureEntry(entry, index))
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export {
|
|
360
|
+
exportOrchestration,
|
|
361
|
+
importOrchestration,
|
|
362
|
+
validatePackage
|
|
363
|
+
};
|