morpheus-cli 0.5.0 → 0.5.2
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/README.md +26 -7
- package/dist/channels/telegram.js +173 -0
- package/dist/cli/commands/restart.js +15 -14
- package/dist/cli/commands/start.js +17 -12
- package/dist/config/manager.js +31 -0
- package/dist/config/mcp-manager.js +19 -1
- package/dist/config/schemas.js +2 -0
- package/dist/http/api.js +222 -0
- package/dist/runtime/memory/session-embedding-worker.js +3 -3
- package/dist/runtime/memory/trinity-db.js +203 -0
- package/dist/runtime/neo.js +16 -26
- package/dist/runtime/oracle.js +16 -8
- package/dist/runtime/session-embedding-scheduler.js +1 -1
- package/dist/runtime/tasks/dispatcher.js +21 -0
- package/dist/runtime/tasks/repository.js +4 -0
- package/dist/runtime/tasks/worker.js +4 -1
- package/dist/runtime/tools/__tests__/tools.test.js +1 -3
- package/dist/runtime/tools/factory.js +1 -1
- package/dist/runtime/tools/index.js +1 -3
- package/dist/runtime/tools/morpheus-tools.js +742 -0
- package/dist/runtime/tools/neo-tool.js +19 -9
- package/dist/runtime/tools/trinity-tool.js +98 -0
- package/dist/runtime/trinity-connector.js +611 -0
- package/dist/runtime/trinity-crypto.js +52 -0
- package/dist/runtime/trinity.js +246 -0
- package/dist/runtime/webhooks/dispatcher.js +73 -2
- package/dist/runtime/webhooks/repository.js +7 -0
- package/dist/ui/assets/index-DP2V4kRd.js +112 -0
- package/dist/ui/assets/index-mglRG5Zw.css +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/ui/sw.js +1 -1
- package/package.json +6 -1
- package/dist/runtime/tools/analytics-tools.js +0 -139
- package/dist/runtime/tools/config-tools.js +0 -64
- package/dist/runtime/tools/diagnostic-tools.js +0 -153
- package/dist/runtime/tools/task-query-tool.js +0 -76
- package/dist/ui/assets/index-20lLB1sM.js +0 -112
- package/dist/ui/assets/index-BJ56bRfs.css +0 -1
|
@@ -4,31 +4,41 @@ import { TaskRepository } from "../tasks/repository.js";
|
|
|
4
4
|
import { TaskRequestContext } from "../tasks/context.js";
|
|
5
5
|
import { compositeDelegationError, isLikelyCompositeDelegationTask } from "./delegation-guard.js";
|
|
6
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();
|
|
7
16
|
const NEO_BASE_DESCRIPTION = `Delegate execution to Neo asynchronously.
|
|
8
17
|
|
|
9
18
|
This tool creates a background task and returns an acknowledgement with task id.
|
|
10
|
-
Use it for
|
|
11
|
-
|
|
12
|
-
|
|
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}`;
|
|
13
23
|
function normalizeDescription(text) {
|
|
14
24
|
if (!text)
|
|
15
25
|
return "No description";
|
|
16
26
|
return text.replace(/\s+/g, " ").trim();
|
|
17
27
|
}
|
|
18
|
-
function buildCatalogSection(
|
|
19
|
-
if (
|
|
20
|
-
return "\n\
|
|
28
|
+
function buildCatalogSection(mcpTools) {
|
|
29
|
+
if (mcpTools.length === 0) {
|
|
30
|
+
return "\n\nRuntime MCP tools: none currently loaded.";
|
|
21
31
|
}
|
|
22
32
|
const maxItems = 32;
|
|
23
|
-
const lines =
|
|
33
|
+
const lines = mcpTools.slice(0, maxItems).map((t) => {
|
|
24
34
|
const desc = normalizeDescription(t.description).slice(0, 120);
|
|
25
35
|
return `- ${t.name}: ${desc}`;
|
|
26
36
|
});
|
|
27
|
-
const hidden =
|
|
37
|
+
const hidden = mcpTools.length - lines.length;
|
|
28
38
|
if (hidden > 0) {
|
|
29
39
|
lines.push(`- ... and ${hidden} more tools`);
|
|
30
40
|
}
|
|
31
|
-
return `\n\
|
|
41
|
+
return `\n\nRuntime MCP tools:\n${lines.join("\n")}`;
|
|
32
42
|
}
|
|
33
43
|
export function updateNeoDelegateToolDescription(tools) {
|
|
34
44
|
const full = `${NEO_BASE_DESCRIPTION}${buildCatalogSection(tools)}`;
|
|
@@ -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
|
+
});
|