morpheus-cli 0.4.15 → 0.5.1

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.
Files changed (51) hide show
  1. package/README.md +293 -1115
  2. package/dist/channels/telegram.js +379 -74
  3. package/dist/cli/commands/doctor.js +34 -0
  4. package/dist/cli/commands/init.js +128 -0
  5. package/dist/cli/commands/restart.js +32 -14
  6. package/dist/cli/commands/start.js +28 -12
  7. package/dist/config/manager.js +82 -0
  8. package/dist/config/mcp-manager.js +19 -1
  9. package/dist/config/schemas.js +9 -0
  10. package/dist/devkit/tools/network.js +1 -1
  11. package/dist/http/api.js +399 -10
  12. package/dist/runtime/apoc.js +25 -17
  13. package/dist/runtime/memory/sati/repository.js +30 -2
  14. package/dist/runtime/memory/sati/service.js +46 -15
  15. package/dist/runtime/memory/sati/system-prompts.js +71 -29
  16. package/dist/runtime/memory/session-embedding-worker.js +3 -3
  17. package/dist/runtime/memory/sqlite.js +24 -0
  18. package/dist/runtime/memory/trinity-db.js +203 -0
  19. package/dist/runtime/neo.js +124 -0
  20. package/dist/runtime/oracle.js +252 -205
  21. package/dist/runtime/providers/factory.js +1 -12
  22. package/dist/runtime/session-embedding-scheduler.js +1 -1
  23. package/dist/runtime/tasks/context.js +53 -0
  24. package/dist/runtime/tasks/dispatcher.js +91 -0
  25. package/dist/runtime/tasks/notifier.js +68 -0
  26. package/dist/runtime/tasks/repository.js +370 -0
  27. package/dist/runtime/tasks/types.js +1 -0
  28. package/dist/runtime/tasks/worker.js +99 -0
  29. package/dist/runtime/tools/__tests__/tools.test.js +1 -3
  30. package/dist/runtime/tools/apoc-tool.js +61 -8
  31. package/dist/runtime/tools/delegation-guard.js +29 -0
  32. package/dist/runtime/tools/factory.js +1 -1
  33. package/dist/runtime/tools/index.js +2 -3
  34. package/dist/runtime/tools/morpheus-tools.js +742 -0
  35. package/dist/runtime/tools/neo-tool.js +109 -0
  36. package/dist/runtime/tools/trinity-tool.js +98 -0
  37. package/dist/runtime/trinity-connector.js +611 -0
  38. package/dist/runtime/trinity-crypto.js +52 -0
  39. package/dist/runtime/trinity.js +246 -0
  40. package/dist/runtime/webhooks/dispatcher.js +10 -19
  41. package/dist/types/config.js +10 -0
  42. package/dist/ui/assets/index-DP2V4kRd.js +112 -0
  43. package/dist/ui/assets/index-mglRG5Zw.css +1 -0
  44. package/dist/ui/index.html +2 -2
  45. package/dist/ui/sw.js +1 -1
  46. package/package.json +6 -1
  47. package/dist/runtime/tools/analytics-tools.js +0 -139
  48. package/dist/runtime/tools/config-tools.js +0 -64
  49. package/dist/runtime/tools/diagnostic-tools.js +0 -153
  50. package/dist/ui/assets/index-LemKVRjC.js +0 -112
  51. package/dist/ui/assets/index-TCQ7VNYO.css +0 -1
@@ -0,0 +1,109 @@
1
+ import { tool } from "@langchain/core/tools";
2
+ import { z } from "zod";
3
+ import { TaskRepository } from "../tasks/repository.js";
4
+ import { TaskRequestContext } from "../tasks/context.js";
5
+ import { compositeDelegationError, isLikelyCompositeDelegationTask } from "./delegation-guard.js";
6
+ import { DisplayManager } from "../display.js";
7
+ const NEO_BUILTIN_CAPABILITIES = `
8
+ Neo built-in capabilities (always available — no MCP required):
9
+ • Config: morpheus_config_query, morpheus_config_update — read/write Morpheus configuration (LLM, channels, UI, etc.)
10
+ • Diagnostics: diagnostic_check — full system health report (config, databases, LLM provider, logs)
11
+ • Analytics: message_count, token_usage, provider_model_usage — message counts and token/cost usage stats
12
+ • Tasks: task_query — look up task status by id or session
13
+ • MCP Management: mcp_list, mcp_manage — list/add/update/delete/enable/disable MCP servers; use action "reload" to reload tools across all agents after config changes
14
+ • Webhooks: webhook_list, webhook_manage — create/update/delete webhooks; create returns api_key
15
+ • Trinity DB: trinity_db_list, trinity_db_manage — register/update/delete/test connection/refresh schema for databases`.trim();
16
+ const NEO_BASE_DESCRIPTION = `Delegate execution to Neo asynchronously.
17
+
18
+ This tool creates a background task and returns an acknowledgement with task id.
19
+ Use it for any request that requires Neo's built-in capabilities or a runtime MCP tool listed below.
20
+ Each delegated task must contain one atomic objective.
21
+
22
+ ${NEO_BUILTIN_CAPABILITIES}`;
23
+ function normalizeDescription(text) {
24
+ if (!text)
25
+ return "No description";
26
+ return text.replace(/\s+/g, " ").trim();
27
+ }
28
+ function buildCatalogSection(mcpTools) {
29
+ if (mcpTools.length === 0) {
30
+ return "\n\nRuntime MCP tools: none currently loaded.";
31
+ }
32
+ const maxItems = 32;
33
+ const lines = mcpTools.slice(0, maxItems).map((t) => {
34
+ const desc = normalizeDescription(t.description).slice(0, 120);
35
+ return `- ${t.name}: ${desc}`;
36
+ });
37
+ const hidden = mcpTools.length - lines.length;
38
+ if (hidden > 0) {
39
+ lines.push(`- ... and ${hidden} more tools`);
40
+ }
41
+ return `\n\nRuntime MCP tools:\n${lines.join("\n")}`;
42
+ }
43
+ export function updateNeoDelegateToolDescription(tools) {
44
+ const full = `${NEO_BASE_DESCRIPTION}${buildCatalogSection(tools)}`;
45
+ NeoDelegateTool.description = full;
46
+ }
47
+ export const NeoDelegateTool = tool(async ({ task, context }) => {
48
+ try {
49
+ const display = DisplayManager.getInstance();
50
+ if (isLikelyCompositeDelegationTask(task)) {
51
+ display.log(`Neo delegation rejected (non-atomic task): ${task.slice(0, 140)}`, {
52
+ source: "NeoDelegateTool",
53
+ level: "warning",
54
+ });
55
+ return compositeDelegationError();
56
+ }
57
+ const existingAck = TaskRequestContext.findDuplicateDelegation("neo", task);
58
+ if (existingAck) {
59
+ display.log(`Neo delegation deduplicated. Reusing task ${existingAck.task_id}.`, {
60
+ source: "NeoDelegateTool",
61
+ level: "info",
62
+ });
63
+ return `Task ${existingAck.task_id} already queued for ${existingAck.agent} execution.`;
64
+ }
65
+ if (!TaskRequestContext.canEnqueueDelegation()) {
66
+ display.log(`Neo delegation blocked by per-turn limit.`, {
67
+ source: "NeoDelegateTool",
68
+ level: "warning",
69
+ });
70
+ return "Delegation limit reached for this user turn. Split the request or wait for current tasks.";
71
+ }
72
+ const ctx = TaskRequestContext.get();
73
+ const repository = TaskRepository.getInstance();
74
+ const created = repository.createTask({
75
+ agent: "neo",
76
+ input: task,
77
+ context: context ?? null,
78
+ origin_channel: ctx?.origin_channel ?? "api",
79
+ session_id: ctx?.session_id ?? "default",
80
+ origin_message_id: ctx?.origin_message_id ?? null,
81
+ origin_user_id: ctx?.origin_user_id ?? null,
82
+ max_attempts: 3,
83
+ });
84
+ TaskRequestContext.setDelegationAck({ task_id: created.id, agent: "neo", task });
85
+ display.log(`Neo task created: ${created.id}`, {
86
+ source: "NeoDelegateTool",
87
+ level: "info",
88
+ meta: {
89
+ agent: created.agent,
90
+ origin_channel: created.origin_channel,
91
+ session_id: created.session_id,
92
+ input: created.input,
93
+ }
94
+ });
95
+ return `Task ${created.id} queued for Neo execution.`;
96
+ }
97
+ catch (err) {
98
+ const display = DisplayManager.getInstance();
99
+ display.log(`NeoDelegateTool error: ${err.message}`, { source: "NeoDelegateTool", level: "error" });
100
+ return `Neo task enqueue failed: ${err.message}`;
101
+ }
102
+ }, {
103
+ name: "neo_delegate",
104
+ description: NEO_BASE_DESCRIPTION,
105
+ schema: z.object({
106
+ task: z.string().describe("Clear task objective for Neo to execute **in the user's language**"),
107
+ context: z.string().optional().describe("Optional context from conversation **in the user's language**"),
108
+ }),
109
+ });
@@ -0,0 +1,98 @@
1
+ import { tool } from "@langchain/core/tools";
2
+ import { z } from "zod";
3
+ import { TaskRepository } from "../tasks/repository.js";
4
+ import { TaskRequestContext } from "../tasks/context.js";
5
+ import { compositeDelegationError, isLikelyCompositeDelegationTask } from "./delegation-guard.js";
6
+ import { DisplayManager } from "../display.js";
7
+ const TRINITY_BASE_DESCRIPTION = `Delegate a database task to Trinity, the specialized database subagent, asynchronously.
8
+
9
+ This tool enqueues a background task and returns an acknowledgement with task id.
10
+ Trinity interprets natural language database requests, generates the appropriate query, and returns results.
11
+
12
+ Use this tool when the user asks for ANY of the following:
13
+ - Querying data from a registered database (SELECT, find, aggregate)
14
+ - Checking database status or schema
15
+ - Running reports or analytics against a database
16
+ - Listing tables, collections, or fields
17
+ - Counting records or summarizing data`;
18
+ function buildDatabaseCatalog(databases) {
19
+ if (databases.length === 0) {
20
+ return '\n\nNo databases currently registered. Register databases via /api/trinity/databases.';
21
+ }
22
+ const lines = databases.map((db) => {
23
+ const schema = db.schema_json ? JSON.parse(db.schema_json) : null;
24
+ const tables = schema?.tables?.map((t) => t.name).join(', ') || 'schema not loaded';
25
+ return `- [${db.id}] ${db.name} (${db.type}): ${tables}`;
26
+ });
27
+ return `\n\nRegistered databases:\n${lines.join('\n')}`;
28
+ }
29
+ export function updateTrinityDelegateToolDescription(databases) {
30
+ const full = `${TRINITY_BASE_DESCRIPTION}${buildDatabaseCatalog(databases)}`;
31
+ TrinityDelegateTool.description = full;
32
+ }
33
+ export const TrinityDelegateTool = tool(async ({ task, context }) => {
34
+ try {
35
+ const display = DisplayManager.getInstance();
36
+ if (isLikelyCompositeDelegationTask(task)) {
37
+ display.log(`Trinity delegation rejected (non-atomic task): ${task.slice(0, 140)}`, {
38
+ source: 'TrinityDelegateTool',
39
+ level: 'warning',
40
+ });
41
+ return compositeDelegationError();
42
+ }
43
+ const existingAck = TaskRequestContext.findDuplicateDelegation('trinit', task);
44
+ if (existingAck) {
45
+ display.log(`Trinity delegation deduplicated. Reusing task ${existingAck.task_id}.`, {
46
+ source: 'TrinityDelegateTool',
47
+ level: 'info',
48
+ });
49
+ return `Task ${existingAck.task_id} already queued for ${existingAck.agent} execution.`;
50
+ }
51
+ if (!TaskRequestContext.canEnqueueDelegation()) {
52
+ display.log(`Trinity delegation blocked by per-turn limit.`, {
53
+ source: 'TrinityDelegateTool',
54
+ level: 'warning',
55
+ });
56
+ return 'Delegation limit reached for this user turn. Split the request or wait for current tasks.';
57
+ }
58
+ const ctx = TaskRequestContext.get();
59
+ const repository = TaskRepository.getInstance();
60
+ const created = repository.createTask({
61
+ agent: 'trinit',
62
+ input: task,
63
+ context: context ?? null,
64
+ origin_channel: ctx?.origin_channel ?? 'api',
65
+ session_id: ctx?.session_id ?? 'default',
66
+ origin_message_id: ctx?.origin_message_id ?? null,
67
+ origin_user_id: ctx?.origin_user_id ?? null,
68
+ max_attempts: 3,
69
+ });
70
+ TaskRequestContext.setDelegationAck({ task_id: created.id, agent: 'trinit', task });
71
+ display.log(`Trinity task created: ${created.id}`, {
72
+ source: 'TrinityDelegateTool',
73
+ level: 'info',
74
+ meta: {
75
+ agent: created.agent,
76
+ origin_channel: created.origin_channel,
77
+ session_id: created.session_id,
78
+ input: created.input,
79
+ },
80
+ });
81
+ return `Task ${created.id} queued for Trinity execution.`;
82
+ }
83
+ catch (err) {
84
+ const display = DisplayManager.getInstance();
85
+ display.log(`TrinityDelegateTool error: ${err.message}`, {
86
+ source: 'TrinityDelegateTool',
87
+ level: 'error',
88
+ });
89
+ return `Trinity task enqueue failed: ${err.message}`;
90
+ }
91
+ }, {
92
+ name: 'trinity_delegate',
93
+ description: TRINITY_BASE_DESCRIPTION,
94
+ schema: z.object({
95
+ task: z.string().describe('Clear description of the database task **in the user\'s language**'),
96
+ context: z.string().optional().describe('Optional context from the conversation to help Trinity understand the goal **in the user\'s language**'),
97
+ }),
98
+ });