@fortressllm/sybil 0.0.3
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/.env copy +91 -0
- package/.env.example +139 -0
- package/BROWSER_CONTROL.md +354 -0
- package/CLI_CHAT_FEATURE.md +224 -0
- package/CLI_GUIDE.md +359 -0
- package/DYNAMIC_SKILLS.md +345 -0
- package/DockerFile.sandbox +14 -0
- package/PROGRESS.md +249 -0
- package/README.md +281 -0
- package/RENAME_LOG.md +62 -0
- package/SIMPLIFIED_TELEGRAM_UX.md +273 -0
- package/SYBIL_SUMMARY.md +360 -0
- package/TASK11_NETWORK.md +202 -0
- package/TASK14_CLI.md +432 -0
- package/TASK8_SAFETY.md +317 -0
- package/TASK9_COMPLETION.md +186 -0
- package/TASK9_SUMMARY.md +201 -0
- package/TELEGRAM_OTP_AUTH.md +359 -0
- package/VECTOR_MEMORY.md +163 -0
- package/assets/logo.png +0 -0
- package/cypfq_code_search.md +287 -0
- package/cypfq_driver_search.md +297 -0
- package/cypfq_github_search.md +297 -0
- package/cypfq_repo_search.md +370 -0
- package/dist/agents/autonomous-agent.d.ts +61 -0
- package/dist/agents/autonomous-agent.d.ts.map +1 -0
- package/dist/agents/autonomous-agent.js +536 -0
- package/dist/agents/autonomous-agent.js.map +1 -0
- package/dist/agents/network.d.ts +1006 -0
- package/dist/agents/network.d.ts.map +1 -0
- package/dist/agents/network.js +1266 -0
- package/dist/agents/network.js.map +1 -0
- package/dist/cli/commands/backup.d.ts +3 -0
- package/dist/cli/commands/backup.d.ts.map +1 -0
- package/dist/cli/commands/backup.js +63 -0
- package/dist/cli/commands/backup.js.map +1 -0
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +163 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +3 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +107 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/init.d.ts +3 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +138 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +3 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +81 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/otp.d.ts +3 -0
- package/dist/cli/commands/otp.d.ts.map +1 -0
- package/dist/cli/commands/otp.js +142 -0
- package/dist/cli/commands/otp.js.map +1 -0
- package/dist/cli/commands/restore.d.ts +3 -0
- package/dist/cli/commands/restore.d.ts.map +1 -0
- package/dist/cli/commands/restore.js +99 -0
- package/dist/cli/commands/restore.js.map +1 -0
- package/dist/cli/commands/start.d.ts +3 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +65 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +3 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +68 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +3 -0
- package/dist/cli/commands/stop.d.ts.map +1 -0
- package/dist/cli/commands/stop.js +62 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/commands/update.d.ts +3 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +49 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/commands/whatsapp.d.ts +3 -0
- package/dist/cli/commands/whatsapp.d.ts.map +1 -0
- package/dist/cli/commands/whatsapp.js +281 -0
- package/dist/cli/commands/whatsapp.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +58 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +750 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +109 -0
- package/dist/index.js.map +1 -0
- package/dist/mastra/index.d.ts +4 -0
- package/dist/mastra/index.d.ts.map +1 -0
- package/dist/mastra/index.js +37 -0
- package/dist/mastra/index.js.map +1 -0
- package/dist/mastra/memory.d.ts +9 -0
- package/dist/mastra/memory.d.ts.map +1 -0
- package/dist/mastra/memory.js +92 -0
- package/dist/mastra/memory.js.map +1 -0
- package/dist/processors/index.d.ts +74 -0
- package/dist/processors/index.d.ts.map +1 -0
- package/dist/processors/index.js +153 -0
- package/dist/processors/index.js.map +1 -0
- package/dist/processors/semantic-recall.d.ts +63 -0
- package/dist/processors/semantic-recall.d.ts.map +1 -0
- package/dist/processors/semantic-recall.js +216 -0
- package/dist/processors/semantic-recall.js.map +1 -0
- package/dist/processors/tool-search.d.ts +26 -0
- package/dist/processors/tool-search.d.ts.map +1 -0
- package/dist/processors/tool-search.js +41 -0
- package/dist/processors/tool-search.js.map +1 -0
- package/dist/skills/dynamic/skill-generator.d.ts +169 -0
- package/dist/skills/dynamic/skill-generator.d.ts.map +1 -0
- package/dist/skills/dynamic/skill-generator.js +488 -0
- package/dist/skills/dynamic/skill-generator.js.map +1 -0
- package/dist/tools/agent-delegation-tools.d.ts +142 -0
- package/dist/tools/agent-delegation-tools.d.ts.map +1 -0
- package/dist/tools/agent-delegation-tools.js +263 -0
- package/dist/tools/agent-delegation-tools.js.map +1 -0
- package/dist/tools/browser-tools.d.ts +374 -0
- package/dist/tools/browser-tools.d.ts.map +1 -0
- package/dist/tools/browser-tools.js +752 -0
- package/dist/tools/browser-tools.js.map +1 -0
- package/dist/tools/dynamic/registry.d.ts +61 -0
- package/dist/tools/dynamic/registry.d.ts.map +1 -0
- package/dist/tools/dynamic/registry.js +121 -0
- package/dist/tools/dynamic/registry.js.map +1 -0
- package/dist/tools/dynamic/tool-generator.d.ts +99 -0
- package/dist/tools/dynamic/tool-generator.d.ts.map +1 -0
- package/dist/tools/dynamic/tool-generator.js +367 -0
- package/dist/tools/dynamic/tool-generator.js.map +1 -0
- package/dist/tools/extended-tools.d.ts +176 -0
- package/dist/tools/extended-tools.d.ts.map +1 -0
- package/dist/tools/extended-tools.js +464 -0
- package/dist/tools/extended-tools.js.map +1 -0
- package/dist/tools/library/calendar/index.d.ts +134 -0
- package/dist/tools/library/calendar/index.d.ts.map +1 -0
- package/dist/tools/library/calendar/index.js +160 -0
- package/dist/tools/library/calendar/index.js.map +1 -0
- package/dist/tools/podman-workspace-mcp-cli.d.ts +3 -0
- package/dist/tools/podman-workspace-mcp-cli.d.ts.map +1 -0
- package/dist/tools/podman-workspace-mcp-cli.js +12 -0
- package/dist/tools/podman-workspace-mcp-cli.js.map +1 -0
- package/dist/tools/podman-workspace-mcp.d.ts +247 -0
- package/dist/tools/podman-workspace-mcp.d.ts.map +1 -0
- package/dist/tools/podman-workspace-mcp.js +1093 -0
- package/dist/tools/podman-workspace-mcp.js.map +1 -0
- package/dist/tools/podman-workspace.d.ts +148 -0
- package/dist/tools/podman-workspace.d.ts.map +1 -0
- package/dist/tools/podman-workspace.js +682 -0
- package/dist/tools/podman-workspace.js.map +1 -0
- package/dist/tools/telegram-file-tools.d.ts +78 -0
- package/dist/tools/telegram-file-tools.d.ts.map +1 -0
- package/dist/tools/telegram-file-tools.js +294 -0
- package/dist/tools/telegram-file-tools.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +467 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +156 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/tools/web-tools.d.ts +77 -0
- package/dist/tools/web-tools.d.ts.map +1 -0
- package/dist/tools/web-tools.js +416 -0
- package/dist/tools/web-tools.js.map +1 -0
- package/dist/tools/whatsapp-autoreply-tools.d.ts +118 -0
- package/dist/tools/whatsapp-autoreply-tools.d.ts.map +1 -0
- package/dist/tools/whatsapp-autoreply-tools.js +503 -0
- package/dist/tools/whatsapp-autoreply-tools.js.map +1 -0
- package/dist/tools/whatsapp-tools.d.ts +175 -0
- package/dist/tools/whatsapp-tools.d.ts.map +1 -0
- package/dist/tools/whatsapp-tools.js +566 -0
- package/dist/tools/whatsapp-tools.js.map +1 -0
- package/dist/utils/logger.d.ts +65 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +307 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/model-config.d.ts +73 -0
- package/dist/utils/model-config.d.ts.map +1 -0
- package/dist/utils/model-config.js +366 -0
- package/dist/utils/model-config.js.map +1 -0
- package/dist/utils/semantic-memory.d.ts +82 -0
- package/dist/utils/semantic-memory.d.ts.map +1 -0
- package/dist/utils/semantic-memory.js +189 -0
- package/dist/utils/semantic-memory.js.map +1 -0
- package/dist/utils/system.d.ts +2 -0
- package/dist/utils/system.d.ts.map +1 -0
- package/dist/utils/system.js +24 -0
- package/dist/utils/system.js.map +1 -0
- package/dist/utils/telegram-auth.d.ts +54 -0
- package/dist/utils/telegram-auth.d.ts.map +1 -0
- package/dist/utils/telegram-auth.js +146 -0
- package/dist/utils/telegram-auth.js.map +1 -0
- package/dist/utils/telegram.d.ts +7 -0
- package/dist/utils/telegram.d.ts.map +1 -0
- package/dist/utils/telegram.js +1494 -0
- package/dist/utils/telegram.js.map +1 -0
- package/dist/utils/whatsapp-client.d.ts +166 -0
- package/dist/utils/whatsapp-client.d.ts.map +1 -0
- package/dist/utils/whatsapp-client.js +722 -0
- package/dist/utils/whatsapp-client.js.map +1 -0
- package/dist/workflows/planner-workflow.d.ts +39 -0
- package/dist/workflows/planner-workflow.d.ts.map +1 -0
- package/dist/workflows/planner-workflow.js +165 -0
- package/dist/workflows/planner-workflow.js.map +1 -0
- package/dist/workflows/skill-builder-workflow.d.ts +16 -0
- package/dist/workflows/skill-builder-workflow.d.ts.map +1 -0
- package/dist/workflows/skill-builder-workflow.js +157 -0
- package/dist/workflows/skill-builder-workflow.js.map +1 -0
- package/dist/workspace/index.d.ts +23 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +64 -0
- package/dist/workspace/index.js.map +1 -0
- package/docs/README.md +140 -0
- package/docs/api/agents.md +481 -0
- package/docs/api/browser-tools.md +469 -0
- package/docs/api/memory.md +629 -0
- package/docs/architecture/agent-networks.md +586 -0
- package/docs/architecture/memory.md +579 -0
- package/docs/architecture/overview.md +436 -0
- package/docs/architecture/tools.md +637 -0
- package/docs/cli-tui.md +367 -0
- package/docs/guides/environment-variables.md +502 -0
- package/docs/guides/troubleshooting.md +882 -0
- package/docs/tutorials/agent-networks.md +432 -0
- package/docs/tutorials/dynamic-tools.md +469 -0
- package/docs/tutorials/getting-started.md +263 -0
- package/docs/tutorials/skills.md +561 -0
- package/docs/tutorials/web-browsing.md +329 -0
- package/mastra.db-shm +0 -0
- package/mastra.db-wal +0 -0
- package/package.json +71 -0
- package/plan.md +601 -0
- package/skills/code-review/SKILL.md +48 -0
- package/skills/task-planning/SKILL.md +55 -0
- package/skills/web-research/SKILL.md +79 -0
- package/skills/whatsapp-management/SKILL.md +78 -0
- package/src/agents/autonomous-agent.ts +626 -0
- package/src/agents/network.ts +1307 -0
- package/src/cli/commands/backup.ts +78 -0
- package/src/cli/commands/config.ts +176 -0
- package/src/cli/commands/doctor.ts +111 -0
- package/src/cli/commands/init.ts +150 -0
- package/src/cli/commands/logs.ts +94 -0
- package/src/cli/commands/otp.ts +162 -0
- package/src/cli/commands/restore.ts +118 -0
- package/src/cli/commands/start.ts +76 -0
- package/src/cli/commands/status.ts +81 -0
- package/src/cli/commands/stop.ts +68 -0
- package/src/cli/commands/update.ts +61 -0
- package/src/cli/commands/whatsapp.ts +322 -0
- package/src/cli/index.ts +69 -0
- package/src/cli.ts +830 -0
- package/src/index.ts +124 -0
- package/src/mastra/index.ts +49 -0
- package/src/mastra/memory.ts +99 -0
- package/src/mastra/public/workspace/plan.md +115 -0
- package/src/mastra/public/workspace/research/react-tailwind/skill.md +47 -0
- package/src/processors/index.ts +170 -0
- package/src/processors/semantic-recall.ts +277 -0
- package/src/processors/tool-search.ts +46 -0
- package/src/skills/dynamic/skill-generator.ts +568 -0
- package/src/tools/agent-delegation-tools.ts +301 -0
- package/src/tools/browser-tools.ts +792 -0
- package/src/tools/dynamic/registry.ts +144 -0
- package/src/tools/dynamic/tool-generator.ts +406 -0
- package/src/tools/extended-tools.ts +498 -0
- package/src/tools/library/calendar/index.ts +172 -0
- package/src/tools/podman-workspace-mcp-cli.ts +14 -0
- package/src/tools/podman-workspace-mcp.ts +1290 -0
- package/src/tools/podman-workspace.ts +858 -0
- package/src/tools/telegram-file-tools.ts +320 -0
- package/src/tools/tool-registry.ts +233 -0
- package/src/tools/web-tools.ts +461 -0
- package/src/tools/whatsapp-autoreply-tools.ts +616 -0
- package/src/tools/whatsapp-tools.ts +602 -0
- package/src/utils/logger.ts +368 -0
- package/src/utils/model-config.ts +437 -0
- package/src/utils/semantic-memory.ts +230 -0
- package/src/utils/system.ts +25 -0
- package/src/utils/telegram-auth.ts +201 -0
- package/src/utils/telegram.ts +1847 -0
- package/src/utils/whatsapp-client.ts +808 -0
- package/src/workflows/planner-workflow.ts +178 -0
- package/src/workflows/skill-builder-workflow.ts +175 -0
- package/src/workspace/index.ts +69 -0
- package/tsconfig.json +22 -0
- package/view-logs.sh +116 -0
- package/whatsapp-session.sh +197 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// telegram-file-tools.ts - Tools for agents to send files to Telegram
|
|
2
|
+
import { createTool } from "@mastra/core/tools";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { bot } from "../utils/telegram.js";
|
|
5
|
+
import * as fs from "fs/promises";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Tool: Send a file to Telegram
|
|
10
|
+
* This tool allows agents to send files back to the user via Telegram
|
|
11
|
+
*/
|
|
12
|
+
export const sendTelegramFileTool = createTool({
|
|
13
|
+
id: "send-telegram-file",
|
|
14
|
+
description: "Send a file to the user via Telegram. Use this to share documents, images, code files, or any other files with the user. Supports both absolute paths and relative paths from the workspace directory.",
|
|
15
|
+
inputSchema: z.object({
|
|
16
|
+
filePath: z.string().describe("Path to the file to send (absolute or relative to workspace). Examples: 'report.pdf', '/absolute/path/to/file.txt', 'subdir/data.json'"),
|
|
17
|
+
caption: z.string().optional().describe("Optional caption/description for the file"),
|
|
18
|
+
filename: z.string().optional().describe("Optional custom filename (defaults to original filename)"),
|
|
19
|
+
}),
|
|
20
|
+
outputSchema: z.object({
|
|
21
|
+
success: z.boolean(),
|
|
22
|
+
message: z.string(),
|
|
23
|
+
filePath: z.string(),
|
|
24
|
+
fileSize: z.number().optional().describe("Size of the file in bytes"),
|
|
25
|
+
}),
|
|
26
|
+
execute: async (inputData, context) => {
|
|
27
|
+
const { filePath: inputPath, caption, filename } = inputData;
|
|
28
|
+
|
|
29
|
+
// Get chatId from request context (set by Telegram handler)
|
|
30
|
+
const chatId = context?.requestContext?.get("telegramChatId") as number | undefined;
|
|
31
|
+
|
|
32
|
+
if (!chatId) {
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
message: "No Telegram chat context available. This tool can only be used when processing Telegram messages.",
|
|
36
|
+
filePath: inputPath,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
// Resolve file path - handle both absolute and relative paths
|
|
42
|
+
let resolvedPath: string;
|
|
43
|
+
if (path.isAbsolute(inputPath)) {
|
|
44
|
+
resolvedPath = inputPath;
|
|
45
|
+
} else {
|
|
46
|
+
// Relative path - resolve against workspace directory
|
|
47
|
+
const workspaceDir = process.env.WORKSPACE_DIR || "./workspace";
|
|
48
|
+
resolvedPath = path.join(workspaceDir, inputPath);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Verify file exists
|
|
52
|
+
let stats;
|
|
53
|
+
try {
|
|
54
|
+
stats = await fs.stat(resolvedPath);
|
|
55
|
+
} catch {
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
message: `File not found: "${inputPath}". Use the listFiles tool to see available files in the workspace.`,
|
|
59
|
+
filePath: inputPath,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!stats.isFile()) {
|
|
64
|
+
return {
|
|
65
|
+
success: false,
|
|
66
|
+
message: `Path is not a file: "${inputPath}"`,
|
|
67
|
+
filePath: inputPath,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Check file size (Telegram limit is 20MB for bots)
|
|
72
|
+
const maxSize = 20 * 1024 * 1024; // 20MB
|
|
73
|
+
if (stats.size > maxSize) {
|
|
74
|
+
return {
|
|
75
|
+
success: false,
|
|
76
|
+
message: `File "${path.basename(resolvedPath)}" is too large (${(stats.size / 1024 / 1024).toFixed(2)} MB). Maximum size is 20 MB.`,
|
|
77
|
+
filePath: inputPath,
|
|
78
|
+
fileSize: stats.size,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Read file content
|
|
83
|
+
const fileContent = await fs.readFile(resolvedPath);
|
|
84
|
+
const fileName = filename || path.basename(resolvedPath);
|
|
85
|
+
|
|
86
|
+
// Determine file type based on extension
|
|
87
|
+
const ext = path.extname(resolvedPath).toLowerCase();
|
|
88
|
+
const isImage = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp'].includes(ext);
|
|
89
|
+
const isVideo = ['.mp4', '.avi', '.mov', '.mkv', '.webm'].includes(ext);
|
|
90
|
+
const isAudio = ['.mp3', '.ogg', '.wav', '.m4a', '.flac'].includes(ext);
|
|
91
|
+
|
|
92
|
+
// File options for custom filename
|
|
93
|
+
const fileOptions = {
|
|
94
|
+
filename: fileName,
|
|
95
|
+
contentType: undefined as string | undefined,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Send file based on type
|
|
99
|
+
if (isImage) {
|
|
100
|
+
fileOptions.contentType = `image/${ext.replace('.', '')}`;
|
|
101
|
+
await bot.sendPhoto(chatId, fileContent, {
|
|
102
|
+
caption: caption || undefined,
|
|
103
|
+
}, fileOptions);
|
|
104
|
+
} else if (isVideo) {
|
|
105
|
+
fileOptions.contentType = `video/${ext.replace('.', '')}`;
|
|
106
|
+
await bot.sendVideo(chatId, fileContent, {
|
|
107
|
+
caption: caption || undefined,
|
|
108
|
+
}, fileOptions);
|
|
109
|
+
} else if (isAudio) {
|
|
110
|
+
fileOptions.contentType = `audio/${ext.replace('.', '')}`;
|
|
111
|
+
await bot.sendAudio(chatId, fileContent, {
|
|
112
|
+
caption: caption || undefined,
|
|
113
|
+
}, fileOptions);
|
|
114
|
+
} else {
|
|
115
|
+
// Send as document for other file types
|
|
116
|
+
await bot.sendDocument(chatId, fileContent, {
|
|
117
|
+
caption: caption || undefined,
|
|
118
|
+
}, fileOptions);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
success: true,
|
|
123
|
+
message: `File sent successfully to Telegram: ${fileName} (${(stats.size / 1024).toFixed(2)} KB)`,
|
|
124
|
+
filePath: inputPath,
|
|
125
|
+
fileSize: stats.size,
|
|
126
|
+
};
|
|
127
|
+
} catch (error: any) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
message: `Failed to send file: ${error.message}`,
|
|
131
|
+
filePath: inputPath,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Tool: Send a text message to Telegram
|
|
139
|
+
* This tool allows agents to send additional text messages
|
|
140
|
+
*/
|
|
141
|
+
export const sendTelegramMessageTool = createTool({
|
|
142
|
+
id: "send-telegram-message",
|
|
143
|
+
description: "Send a text message to the user via Telegram. Use this for status updates, summaries, or additional information.",
|
|
144
|
+
inputSchema: z.object({
|
|
145
|
+
message: z.string().describe("The message text to send (supports Markdown)"),
|
|
146
|
+
parseMode: z.enum(["Markdown", "HTML", "none"]).optional().describe("Parse mode for the message (default: Markdown)"),
|
|
147
|
+
}),
|
|
148
|
+
outputSchema: z.object({
|
|
149
|
+
success: z.boolean(),
|
|
150
|
+
message: z.string(),
|
|
151
|
+
}),
|
|
152
|
+
execute: async (inputData, context) => {
|
|
153
|
+
const { message, parseMode = "Markdown" } = inputData;
|
|
154
|
+
|
|
155
|
+
// Get chatId from request context (set by Telegram handler)
|
|
156
|
+
const chatId = context?.requestContext?.get("telegramChatId") as number | undefined;
|
|
157
|
+
|
|
158
|
+
if (!chatId) {
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
message: "No Telegram chat context available. This tool can only be used when processing Telegram messages.",
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
await bot.sendMessage(chatId, message, {
|
|
167
|
+
parse_mode: parseMode === "none" ? undefined : parseMode,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
success: true,
|
|
172
|
+
message: "Message sent successfully to Telegram",
|
|
173
|
+
};
|
|
174
|
+
} catch (error: any) {
|
|
175
|
+
return {
|
|
176
|
+
success: false,
|
|
177
|
+
message: `Failed to send message: ${error.message}`,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Tool: Send multiple files as a media group to Telegram
|
|
185
|
+
* Useful for sending related files together
|
|
186
|
+
*/
|
|
187
|
+
export const sendTelegramMediaGroupTool = createTool({
|
|
188
|
+
id: "send-telegram-media-group",
|
|
189
|
+
description: "Send multiple photos/videos as an album to Telegram. All files will be grouped together in a single message. Supports both absolute and relative paths from the workspace directory.",
|
|
190
|
+
inputSchema: z.object({
|
|
191
|
+
filePaths: z.array(z.string()).describe("Array of file paths to send (images or videos). Supports relative paths from workspace."),
|
|
192
|
+
caption: z.string().optional().describe("Optional caption for the media group"),
|
|
193
|
+
}),
|
|
194
|
+
outputSchema: z.object({
|
|
195
|
+
success: z.boolean(),
|
|
196
|
+
message: z.string(),
|
|
197
|
+
sentCount: z.number(),
|
|
198
|
+
skippedCount: z.number().optional().describe("Number of files skipped (non-media or not found)"),
|
|
199
|
+
}),
|
|
200
|
+
execute: async (inputData, context) => {
|
|
201
|
+
const { filePaths, caption } = inputData;
|
|
202
|
+
|
|
203
|
+
// Get chatId from request context (set by Telegram handler)
|
|
204
|
+
const chatId = context?.requestContext?.get("telegramChatId") as number | undefined;
|
|
205
|
+
|
|
206
|
+
if (!chatId) {
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
message: "No Telegram chat context available. This tool can only be used when processing Telegram messages.",
|
|
210
|
+
sentCount: 0,
|
|
211
|
+
skippedCount: 0,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (filePaths.length === 0) {
|
|
216
|
+
return {
|
|
217
|
+
success: false,
|
|
218
|
+
message: "No files provided",
|
|
219
|
+
sentCount: 0,
|
|
220
|
+
skippedCount: 0,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
const media: any[] = [];
|
|
226
|
+
let skippedCount = 0;
|
|
227
|
+
const maxSize = 20 * 1024 * 1024; // 20MB per file
|
|
228
|
+
|
|
229
|
+
for (let i = 0; i < filePaths.length; i++) {
|
|
230
|
+
const inputPath = filePaths[i];
|
|
231
|
+
|
|
232
|
+
// Resolve file path
|
|
233
|
+
let resolvedPath: string;
|
|
234
|
+
if (path.isAbsolute(inputPath)) {
|
|
235
|
+
resolvedPath = inputPath;
|
|
236
|
+
} else {
|
|
237
|
+
const workspaceDir = process.env.WORKSPACE_DIR || "./workspace";
|
|
238
|
+
resolvedPath = path.join(workspaceDir, inputPath);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Check if file exists
|
|
242
|
+
let stats;
|
|
243
|
+
try {
|
|
244
|
+
stats = await fs.stat(resolvedPath);
|
|
245
|
+
} catch {
|
|
246
|
+
skippedCount++;
|
|
247
|
+
continue; // Skip files that don't exist
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (!stats.isFile()) {
|
|
251
|
+
skippedCount++;
|
|
252
|
+
continue; // Skip directories
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Check size limit
|
|
256
|
+
if (stats.size > maxSize) {
|
|
257
|
+
skippedCount++;
|
|
258
|
+
continue; // Skip files that are too large
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const ext = path.extname(resolvedPath).toLowerCase();
|
|
262
|
+
const isImage = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp'].includes(ext);
|
|
263
|
+
const isVideo = ['.mp4', '.avi', '.mov', '.mkv', '.webm'].includes(ext);
|
|
264
|
+
|
|
265
|
+
if (!isImage && !isVideo) {
|
|
266
|
+
skippedCount++;
|
|
267
|
+
continue; // Skip non-media files
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const fileContent = await fs.readFile(resolvedPath);
|
|
271
|
+
const mediaItem: any = {
|
|
272
|
+
type: isImage ? 'photo' : 'video',
|
|
273
|
+
media: fileContent,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// Add caption only to the first item
|
|
277
|
+
if (i === 0 && caption) {
|
|
278
|
+
mediaItem.caption = caption;
|
|
279
|
+
mediaItem.parse_mode = 'Markdown';
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
media.push(mediaItem);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (media.length === 0) {
|
|
286
|
+
return {
|
|
287
|
+
success: false,
|
|
288
|
+
message: "No valid media files found (only images and videos are supported for media groups). Some files may not exist or be too large.",
|
|
289
|
+
sentCount: 0,
|
|
290
|
+
skippedCount,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
await bot.sendMediaGroup(chatId, media);
|
|
295
|
+
|
|
296
|
+
return {
|
|
297
|
+
success: true,
|
|
298
|
+
message: `Media group sent successfully with ${media.length} items${skippedCount > 0 ? ` (${skippedCount} files skipped)` : ''}`,
|
|
299
|
+
sentCount: media.length,
|
|
300
|
+
skippedCount,
|
|
301
|
+
};
|
|
302
|
+
} catch (error: any) {
|
|
303
|
+
return {
|
|
304
|
+
success: false,
|
|
305
|
+
message: `Failed to send media group: ${error.message}`,
|
|
306
|
+
sentCount: 0,
|
|
307
|
+
skippedCount: 0,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// Export all Telegram tools
|
|
314
|
+
export const telegramTools = {
|
|
315
|
+
sendTelegramFile: sendTelegramFileTool,
|
|
316
|
+
sendTelegramMessage: sendTelegramMessageTool,
|
|
317
|
+
sendTelegramMediaGroup: sendTelegramMediaGroupTool,
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export default telegramTools;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registry for Dynamic Tool Discovery
|
|
3
|
+
*
|
|
4
|
+
* This module exports all available tools for use with ToolSearchProcessor
|
|
5
|
+
* enabling dynamic tool loading based on user requests.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createTool } from "@mastra/core/tools";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import * as cheerio from "cheerio";
|
|
12
|
+
|
|
13
|
+
// Import existing tools from other files
|
|
14
|
+
import {
|
|
15
|
+
fetchWebContentTool,
|
|
16
|
+
searchWebTool,
|
|
17
|
+
extractStructuredDataTool,
|
|
18
|
+
deepResearchTool
|
|
19
|
+
} from "./web-tools.js";
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
getWhatsAppStatusTool,
|
|
23
|
+
initializeWhatsAppTool,
|
|
24
|
+
sendWhatsAppMessageTool,
|
|
25
|
+
getWhatsAppChatsTool,
|
|
26
|
+
getWhatsAppMessagesTool,
|
|
27
|
+
getWhatsAppContactTool,
|
|
28
|
+
getAllWhatsAppContactsTool,
|
|
29
|
+
getMyWhatsAppInfoTool,
|
|
30
|
+
broadcastWhatsAppMessageTool,
|
|
31
|
+
} from "./whatsapp-tools.js";
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
configureAutoReplyTool,
|
|
35
|
+
approvePendingReplyTool,
|
|
36
|
+
} from "./whatsapp-autoreply-tools.js";
|
|
37
|
+
|
|
38
|
+
// Import extended tools that are actually available
|
|
39
|
+
import {
|
|
40
|
+
readFileTool,
|
|
41
|
+
writeFileTool,
|
|
42
|
+
listDirectoryTool,
|
|
43
|
+
executeCodeTool,
|
|
44
|
+
createCalendarEventTool,
|
|
45
|
+
listCalendarEventsTool,
|
|
46
|
+
sendEmailTool,
|
|
47
|
+
queryDatabaseTool,
|
|
48
|
+
postToTwitterTool,
|
|
49
|
+
getAnalyticsReportTool,
|
|
50
|
+
} from "./extended-tools.js";
|
|
51
|
+
|
|
52
|
+
// Import dynamic tool generation tools
|
|
53
|
+
import {
|
|
54
|
+
generateToolTool,
|
|
55
|
+
listGeneratedToolsTool,
|
|
56
|
+
deleteGeneratedToolTool,
|
|
57
|
+
} from "./dynamic/tool-generator.js";
|
|
58
|
+
|
|
59
|
+
// Import dynamic skill generation tools
|
|
60
|
+
import {
|
|
61
|
+
generateSkillTool,
|
|
62
|
+
learnSkillFromFeedbackTool,
|
|
63
|
+
listSkillsTool,
|
|
64
|
+
activateSkillTool,
|
|
65
|
+
analyzeForSkillOpportunityTool,
|
|
66
|
+
} from "../skills/dynamic/skill-generator.js";
|
|
67
|
+
|
|
68
|
+
import { dynamicToolRegistry } from "./dynamic/registry.js";
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* All available tools for dynamic discovery
|
|
72
|
+
* Total: 33 tools across multiple domains (25 static + 3 dynamic tool generation + 5 dynamic skill generation)
|
|
73
|
+
*/
|
|
74
|
+
export const allTools = {
|
|
75
|
+
// Web tools (4)
|
|
76
|
+
fetchWebContent: fetchWebContentTool,
|
|
77
|
+
searchWeb: searchWebTool,
|
|
78
|
+
extractStructuredData: extractStructuredDataTool,
|
|
79
|
+
deepResearch: deepResearchTool,
|
|
80
|
+
|
|
81
|
+
// WhatsApp tools (11)
|
|
82
|
+
getWhatsAppStatus: getWhatsAppStatusTool,
|
|
83
|
+
initializeWhatsApp: initializeWhatsAppTool,
|
|
84
|
+
sendWhatsAppMessage: sendWhatsAppMessageTool,
|
|
85
|
+
getWhatsAppChats: getWhatsAppChatsTool,
|
|
86
|
+
getWhatsAppMessages: getWhatsAppMessagesTool,
|
|
87
|
+
getWhatsAppContact: getWhatsAppContactTool,
|
|
88
|
+
getAllWhatsAppContacts: getAllWhatsAppContactsTool,
|
|
89
|
+
getMyWhatsAppInfo: getMyWhatsAppInfoTool,
|
|
90
|
+
broadcastWhatsAppMessage: broadcastWhatsAppMessageTool,
|
|
91
|
+
configureAutoReply: configureAutoReplyTool,
|
|
92
|
+
approvePendingReply: approvePendingReplyTool,
|
|
93
|
+
|
|
94
|
+
// Filesystem tools (3)
|
|
95
|
+
readFile: readFileTool,
|
|
96
|
+
writeFile: writeFileTool,
|
|
97
|
+
listDirectory: listDirectoryTool,
|
|
98
|
+
|
|
99
|
+
// Code execution (1)
|
|
100
|
+
executeCode: executeCodeTool,
|
|
101
|
+
|
|
102
|
+
// Calendar tools (2)
|
|
103
|
+
createCalendarEvent: createCalendarEventTool,
|
|
104
|
+
listCalendarEvents: listCalendarEventsTool,
|
|
105
|
+
|
|
106
|
+
// Email (1)
|
|
107
|
+
sendEmail: sendEmailTool,
|
|
108
|
+
|
|
109
|
+
// Database (1)
|
|
110
|
+
queryDatabase: queryDatabaseTool,
|
|
111
|
+
|
|
112
|
+
// Social media (1)
|
|
113
|
+
postToTwitter: postToTwitterTool,
|
|
114
|
+
|
|
115
|
+
// Analytics (1)
|
|
116
|
+
getAnalyticsReport: getAnalyticsReportTool,
|
|
117
|
+
|
|
118
|
+
// Dynamic tool generation (3)
|
|
119
|
+
generateTool: generateToolTool,
|
|
120
|
+
listGeneratedTools: listGeneratedToolsTool,
|
|
121
|
+
deleteGeneratedTool: deleteGeneratedToolTool,
|
|
122
|
+
|
|
123
|
+
// Dynamic skill generation (5)
|
|
124
|
+
generateSkill: generateSkillTool,
|
|
125
|
+
learnSkillFromFeedback: learnSkillFromFeedbackTool,
|
|
126
|
+
listSkills: listSkillsTool,
|
|
127
|
+
activateSkill: activateSkillTool,
|
|
128
|
+
analyzeForSkillOpportunity: analyzeForSkillOpportunityTool,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Tool count for reference
|
|
133
|
+
*/
|
|
134
|
+
export const toolCount = Object.keys(allTools).length;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Tool categories for organization
|
|
138
|
+
*/
|
|
139
|
+
export const toolCategories = {
|
|
140
|
+
web: ["fetchWebContent", "searchWeb", "extractStructuredData", "deepResearch"],
|
|
141
|
+
whatsapp: ["getWhatsAppStatus", "initializeWhatsApp", "sendWhatsAppMessage", "getWhatsAppChats", "getWhatsAppMessages", "getWhatsAppContact", "getMyWhatsAppInfo", "broadcastWhatsAppMessage", "configureAutoReply", "approvePendingReply"],
|
|
142
|
+
filesystem: ["readFile", "writeFile", "listDirectory"],
|
|
143
|
+
code: ["executeCode"],
|
|
144
|
+
calendar: ["createCalendarEvent", "listCalendarEvents"],
|
|
145
|
+
email: ["sendEmail"],
|
|
146
|
+
database: ["queryDatabase"],
|
|
147
|
+
social: ["postToTwitter"],
|
|
148
|
+
analytics: ["getAnalyticsReport"],
|
|
149
|
+
dynamic: [
|
|
150
|
+
"generateTool",
|
|
151
|
+
"listGeneratedTools",
|
|
152
|
+
"deleteGeneratedTool",
|
|
153
|
+
"generateSkill",
|
|
154
|
+
"learnSkillFromFeedback",
|
|
155
|
+
"listSkills",
|
|
156
|
+
"activateSkill",
|
|
157
|
+
"analyzeForSkillOpportunity",
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get tools by category
|
|
163
|
+
*/
|
|
164
|
+
export function getToolsByCategory(category: keyof typeof toolCategories): string[] {
|
|
165
|
+
return toolCategories[category] || [];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Get tool descriptions for search indexing
|
|
170
|
+
* This is used by ToolSearchProcessor for semantic matching
|
|
171
|
+
*/
|
|
172
|
+
export const toolDescriptions: Record<string, string> = {
|
|
173
|
+
// Web tools
|
|
174
|
+
fetchWebContent: "Fetch and extract content from web pages. Read articles, documentation, or any web content.",
|
|
175
|
+
searchWeb: "Search the web for information. Use DuckDuckGo to find current information.",
|
|
176
|
+
extractStructuredData: "Extract structured data from web pages using CSS selectors. Scrape specific elements.",
|
|
177
|
+
deepResearch: "Perform comprehensive research on topics. Search, read, and synthesize information.",
|
|
178
|
+
|
|
179
|
+
// WhatsApp tools
|
|
180
|
+
getWhatsAppStatus: "Check WhatsApp connection status. Verify if WhatsApp is ready.",
|
|
181
|
+
initializeWhatsApp: "Initialize WhatsApp Web connection. Scan QR code to connect.",
|
|
182
|
+
sendWhatsAppMessage: "Send WhatsApp messages to contacts. Use international phone format.",
|
|
183
|
+
getWhatsAppChats: "List WhatsApp conversations. View recent chats.",
|
|
184
|
+
getWhatsAppMessages: "Retrieve WhatsApp message history. View conversation messages.",
|
|
185
|
+
getWhatsAppContact: "Get WhatsApp contact information. View contact details.",
|
|
186
|
+
getMyWhatsAppInfo: "Get my WhatsApp profile information. View my account details.",
|
|
187
|
+
broadcastWhatsAppMessage: "Broadcast WhatsApp message to multiple contacts. Send bulk messages.",
|
|
188
|
+
configureAutoReply: "Configure WhatsApp auto-reply settings. Enable/disable auto-replies.",
|
|
189
|
+
approvePendingReply: "Approve pending WhatsApp auto-replies. Review and send pending messages.",
|
|
190
|
+
|
|
191
|
+
// Filesystem tools
|
|
192
|
+
readFile: "Read file contents from the filesystem. Open and view files.",
|
|
193
|
+
writeFile: "Write content to files. Create or update files.",
|
|
194
|
+
listDirectory: "List files and directories. Explore folder contents.",
|
|
195
|
+
|
|
196
|
+
// Code execution
|
|
197
|
+
executeCode: "Execute code in sandboxed environment. Run JavaScript, Python, or shell scripts.",
|
|
198
|
+
|
|
199
|
+
// Calendar tools
|
|
200
|
+
createCalendarEvent: "Create calendar events and meetings. Schedule appointments.",
|
|
201
|
+
listCalendarEvents: "List upcoming calendar events. View schedule.",
|
|
202
|
+
|
|
203
|
+
// Email
|
|
204
|
+
sendEmail: "Send emails. Send notifications and communications.",
|
|
205
|
+
|
|
206
|
+
// Database
|
|
207
|
+
queryDatabase: "Query databases using SQL. Retrieve data.",
|
|
208
|
+
|
|
209
|
+
// Social media
|
|
210
|
+
postToTwitter: "Post tweets to Twitter. Share updates on social media.",
|
|
211
|
+
|
|
212
|
+
// Analytics
|
|
213
|
+
getAnalyticsReport: "Get analytics and reports. View website traffic and metrics.",
|
|
214
|
+
|
|
215
|
+
// Dynamic tool generation (3)
|
|
216
|
+
generateTool: "Generate new custom tools based on requirements. Create tools dynamically from natural language descriptions.",
|
|
217
|
+
listGeneratedTools: "List all dynamically generated tools. View custom tools created by the agent.",
|
|
218
|
+
deleteGeneratedTool: "Delete a dynamically generated tool. Remove custom tools when no longer needed.",
|
|
219
|
+
|
|
220
|
+
// Dynamic skill generation (5)
|
|
221
|
+
generateSkill: "Create a new skill that teaches the agent how to handle specific tasks. Skills guide behavior in particular domains.",
|
|
222
|
+
learnSkillFromFeedback: "Learn or update a skill based on user feedback. Extract patterns from what worked well.",
|
|
223
|
+
listSkills: "List all available skills that can be activated. Skills enhance agent capabilities.",
|
|
224
|
+
activateSkill: "Activate a skill for use in the current conversation. Skills provide specialized instructions.",
|
|
225
|
+
analyzeForSkillOpportunity: "Analyze interactions to identify opportunities for new skills. Find gaps in capabilities.",
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Export dynamic tool registry for runtime tool loading
|
|
230
|
+
*/
|
|
231
|
+
export { dynamicToolRegistry };
|
|
232
|
+
|
|
233
|
+
export default allTools;
|