@hailer/mcp 1.0.28 → 1.1.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/.claude/.session-checked +1 -0
- package/.claude/agents/agent-ada-skill-builder.md +10 -2
- package/.claude/agents/agent-alejandro-function-fields.md +104 -37
- package/.claude/agents/agent-bjorn-config-audit.md +41 -21
- package/.claude/agents/agent-builder-agent-creator.md +13 -3
- package/.claude/agents/agent-code-simplifier.md +53 -0
- package/.claude/agents/agent-dmitri-activity-crud.md +126 -11
- package/.claude/agents/agent-giuseppe-app-builder.md +212 -22
- package/.claude/agents/agent-gunther-mcp-tools.md +7 -36
- package/.claude/agents/agent-helga-workflow-config.md +75 -10
- package/.claude/agents/agent-igor-activity-mover-automation.md +125 -0
- package/.claude/agents/agent-ingrid-doc-templates.md +164 -36
- package/.claude/agents/agent-ivan-monolith.md +154 -0
- package/.claude/agents/agent-kenji-data-reader.md +15 -8
- package/.claude/agents/agent-lars-code-inspector.md +56 -8
- package/.claude/agents/agent-marco-mockup-builder.md +110 -0
- package/.claude/agents/agent-marcus-api-documenter.md +323 -0
- package/.claude/agents/agent-marketplace-publisher.md +232 -72
- package/.claude/agents/agent-marketplace-reviewer.md +255 -79
- package/.claude/agents/agent-permissions-handler.md +208 -0
- package/.claude/agents/agent-simple-writer.md +48 -0
- package/.claude/agents/agent-svetlana-code-review.md +127 -14
- package/.claude/agents/agent-tanya-test-runner.md +333 -0
- package/.claude/agents/agent-ui-designer.md +100 -0
- package/.claude/agents/agent-viktor-sql-insights.md +19 -6
- package/.claude/agents/agent-web-search.md +55 -0
- package/.claude/agents/agent-yevgeni-discussions.md +7 -1
- package/.claude/agents/agent-zara-zapier.md +159 -0
- package/.claude/commands/app-squad.md +135 -0
- package/.claude/commands/audit-squad.md +158 -0
- package/.claude/commands/autoplan.md +563 -0
- package/.claude/commands/cleanup-squad.md +98 -0
- package/.claude/commands/config-squad.md +106 -0
- package/.claude/commands/crud-squad.md +87 -0
- package/.claude/commands/data-squad.md +97 -0
- package/.claude/commands/debug-squad.md +303 -0
- package/.claude/commands/doc-squad.md +65 -0
- package/.claude/commands/handoff.md +137 -0
- package/.claude/commands/health.md +49 -0
- package/.claude/commands/help.md +2 -1
- package/.claude/commands/help:agents.md +96 -16
- package/.claude/commands/help:commands.md +55 -11
- package/.claude/commands/help:faq.md +16 -1
- package/.claude/commands/help:skills.md +93 -0
- package/.claude/commands/hotfix-squad.md +112 -0
- package/.claude/commands/integration-squad.md +82 -0
- package/.claude/commands/janitor-squad.md +167 -0
- package/.claude/commands/learn-auto.md +120 -0
- package/.claude/commands/learn.md +120 -0
- package/.claude/commands/mcp-list.md +27 -0
- package/.claude/commands/onboard-squad.md +140 -0
- package/.claude/commands/plan-workspace.md +732 -0
- package/.claude/commands/prd.md +131 -0
- package/.claude/commands/project-status.md +82 -0
- package/.claude/commands/publish.md +138 -0
- package/.claude/commands/recap.md +69 -0
- package/.claude/commands/restore.md +64 -0
- package/.claude/commands/review-squad.md +152 -0
- package/.claude/commands/save.md +24 -0
- package/.claude/commands/stats.md +19 -0
- package/.claude/commands/swarm.md +210 -0
- package/.claude/commands/tool-builder.md +3 -1
- package/.claude/commands/ws-pull.md +1 -1
- package/.claude/commands/yolo-off.md +17 -0
- package/.claude/commands/yolo.md +82 -0
- package/.claude/hooks/_shared-memory.cjs +305 -0
- package/.claude/hooks/_utils.cjs +134 -0
- package/.claude/hooks/agent-failure-detector.cjs +164 -79
- package/.claude/hooks/agent-usage-logger.cjs +204 -0
- package/.claude/hooks/app-edit-guard.cjs +20 -4
- package/.claude/hooks/auto-learn.cjs +316 -0
- package/.claude/hooks/bash-guard.cjs +282 -0
- package/.claude/hooks/builder-mode-manager.cjs +183 -54
- package/.claude/hooks/bulk-activity-guard.cjs +283 -0
- package/.claude/hooks/context-watchdog.cjs +292 -0
- package/.claude/hooks/delegation-reminder.cjs +478 -0
- package/.claude/hooks/design-system-lint.cjs +283 -0
- package/.claude/hooks/post-scaffold-hook.cjs +16 -3
- package/.claude/hooks/prompt-guard.cjs +366 -0
- package/.claude/hooks/publish-template-guard.cjs +16 -0
- package/.claude/hooks/session-start.cjs +35 -0
- package/.claude/hooks/shared-memory-writer.cjs +147 -0
- package/.claude/hooks/skill-injector.cjs +140 -0
- package/.claude/hooks/skill-usage-logger.cjs +258 -0
- package/.claude/hooks/src-edit-guard.cjs +16 -1
- package/.claude/hooks/sync-marketplace-agents.cjs +53 -8
- package/.claude/scripts/yolo-toggle.cjs +142 -0
- package/.claude/settings.json +141 -14
- package/.claude/skills/SDK-activity-patterns/SKILL.md +428 -0
- package/.claude/skills/SDK-document-templates/SKILL.md +1033 -0
- package/.claude/skills/SDK-function-fields/SKILL.md +542 -0
- package/.claude/skills/SDK-generate-skill/SKILL.md +92 -0
- package/.claude/skills/SDK-init-skill/SKILL.md +127 -0
- package/.claude/skills/SDK-insight-queries/SKILL.md +787 -0
- package/.claude/skills/SDK-ws-config-skill/SKILL.md +1139 -0
- package/.claude/skills/agent-structure/SKILL.md +98 -0
- package/.claude/skills/api-documentation-patterns/SKILL.md +474 -0
- package/.claude/skills/chrome-mcp-reference/SKILL.md +370 -0
- package/.claude/skills/delegation-routing/SKILL.md +202 -0
- package/.claude/skills/frontend-design/SKILL.md +254 -0
- package/.claude/skills/hailer-activity-mover/SKILL.md +213 -0
- package/.claude/skills/hailer-api-client/SKILL.md +518 -0
- package/.claude/skills/hailer-app-builder/SKILL.md +939 -11
- package/.claude/skills/hailer-apps-pictures/SKILL.md +269 -0
- package/.claude/skills/hailer-design-system/SKILL.md +235 -0
- package/.claude/skills/hailer-monolith-automations/SKILL.md +686 -0
- package/.claude/skills/hailer-permissions-system/SKILL.md +121 -0
- package/.claude/skills/hailer-project-protocol/SKILL.md +488 -0
- package/.claude/skills/hailer-rest-api/SKILL.md +61 -0
- package/.claude/skills/hailer-rest-api/hailer-activities.md +184 -0
- package/.claude/skills/hailer-rest-api/hailer-admin.md +473 -0
- package/.claude/skills/hailer-rest-api/hailer-calendar.md +256 -0
- package/.claude/skills/hailer-rest-api/hailer-feed.md +249 -0
- package/.claude/skills/hailer-rest-api/hailer-insights.md +195 -0
- package/.claude/skills/hailer-rest-api/hailer-messaging.md +276 -0
- package/.claude/skills/hailer-rest-api/hailer-workflows.md +283 -0
- package/.claude/skills/insight-join-patterns/SKILL.md +3 -0
- package/.claude/skills/integration-patterns/SKILL.md +421 -0
- package/.claude/skills/json-only-output/SKILL.md +52 -12
- package/.claude/skills/lsp-setup/SKILL.md +160 -0
- package/.claude/skills/mcp-direct-tools/SKILL.md +153 -0
- package/.claude/skills/optional-parameters/SKILL.md +32 -23
- package/.claude/skills/publish-hailer-app/SKILL.md +76 -12
- package/.claude/skills/testing-patterns/SKILL.md +630 -0
- package/.claude/skills/tool-builder/SKILL.md +250 -0
- package/.claude/skills/tool-parameter-usage/SKILL.md +59 -45
- package/.claude/skills/tool-response-verification/SKILL.md +82 -48
- package/.claude/skills/zapier-hailer-patterns/SKILL.md +581 -0
- package/.env.example +26 -7
- package/CLAUDE.md +290 -224
- package/dist/CLAUDE.md +370 -0
- package/dist/app.d.ts +1 -1
- package/dist/app.js +101 -101
- package/dist/bot/bot-config.d.ts +26 -0
- package/dist/bot/bot-config.js +135 -0
- package/dist/bot/bot-manager.d.ts +40 -0
- package/dist/bot/bot-manager.js +137 -0
- package/dist/bot/bot.d.ts +127 -0
- package/dist/bot/bot.js +1328 -0
- package/dist/bot/operation-logger.d.ts +28 -0
- package/dist/bot/operation-logger.js +132 -0
- package/dist/bot/services/conversation-manager.d.ts +60 -0
- package/dist/bot/services/conversation-manager.js +246 -0
- package/dist/bot/services/index.d.ts +9 -0
- package/dist/bot/services/index.js +18 -0
- package/dist/bot/services/message-classifier.d.ts +42 -0
- package/dist/bot/services/message-classifier.js +228 -0
- package/dist/bot/services/message-formatter.d.ts +88 -0
- package/dist/bot/services/message-formatter.js +411 -0
- package/dist/bot/services/session-logger.d.ts +162 -0
- package/dist/bot/services/session-logger.js +724 -0
- package/dist/bot/services/token-billing.d.ts +78 -0
- package/dist/bot/services/token-billing.js +233 -0
- package/dist/bot/services/types.d.ts +169 -0
- package/dist/bot/services/types.js +12 -0
- package/dist/bot/services/typing-indicator.d.ts +23 -0
- package/dist/bot/services/typing-indicator.js +60 -0
- package/dist/bot/services/workspace-schema-cache.d.ts +122 -0
- package/dist/bot/services/workspace-schema-cache.js +506 -0
- package/dist/bot/tool-executor.d.ts +28 -0
- package/dist/bot/tool-executor.js +48 -0
- package/dist/bot/workspace-overview.d.ts +12 -0
- package/dist/bot/workspace-overview.js +94 -0
- package/dist/cli.d.ts +1 -8
- package/dist/cli.js +1 -249
- package/dist/config.d.ts +96 -3
- package/dist/config.js +148 -37
- package/dist/core.d.ts +5 -0
- package/dist/core.js +61 -8
- package/dist/lib/discussion-lock.d.ts +42 -0
- package/dist/lib/discussion-lock.js +110 -0
- package/dist/lib/logger.d.ts +0 -1
- package/dist/lib/logger.js +39 -23
- package/dist/lib/request-logger.d.ts +77 -0
- package/dist/lib/request-logger.js +147 -0
- package/dist/mcp/UserContextCache.js +16 -13
- package/dist/mcp/hailer-clients.js +18 -17
- package/dist/mcp/signal-handler.js +29 -13
- package/dist/mcp/tool-registry.d.ts +4 -15
- package/dist/mcp/tool-registry.js +94 -32
- package/dist/mcp/tools/activity.js +28 -69
- package/dist/mcp/tools/app-core.js +9 -4
- package/dist/mcp/tools/app-marketplace.js +22 -12
- package/dist/mcp/tools/app-member.js +5 -2
- package/dist/mcp/tools/app-scaffold.js +32 -18
- package/dist/mcp/tools/bot-config/constants.d.ts +23 -0
- package/dist/mcp/tools/bot-config/constants.js +94 -0
- package/dist/mcp/tools/bot-config/core.d.ts +253 -0
- package/dist/mcp/tools/bot-config/core.js +2456 -0
- package/dist/mcp/tools/bot-config/index.d.ts +10 -0
- package/dist/mcp/tools/bot-config/index.js +59 -0
- package/dist/mcp/tools/bot-config/tools.d.ts +7 -0
- package/dist/mcp/tools/bot-config/tools.js +15 -0
- package/dist/mcp/tools/bot-config/types.d.ts +50 -0
- package/dist/mcp/tools/bot-config/types.js +6 -0
- package/dist/mcp/tools/discussion.js +107 -77
- package/dist/mcp/tools/document.d.ts +11 -0
- package/dist/mcp/tools/document.js +741 -0
- package/dist/mcp/tools/file.js +5 -2
- package/dist/mcp/tools/insight.js +36 -12
- package/dist/mcp/tools/investigate.d.ts +9 -0
- package/dist/mcp/tools/investigate.js +254 -0
- package/dist/mcp/tools/user.d.ts +2 -4
- package/dist/mcp/tools/user.js +9 -50
- package/dist/mcp/tools/workflow.d.ts +1 -0
- package/dist/mcp/tools/workflow.js +164 -52
- package/dist/mcp/utils/hailer-api-client.js +26 -17
- package/dist/mcp/webhook-handler.d.ts +64 -3
- package/dist/mcp/webhook-handler.js +219 -9
- package/dist/mcp-server.d.ts +4 -0
- package/dist/mcp-server.js +237 -25
- package/dist/plugins/bug-fixer/index.d.ts +2 -0
- package/dist/plugins/bug-fixer/index.js +18 -0
- package/dist/plugins/bug-fixer/tools.d.ts +45 -0
- package/dist/plugins/bug-fixer/tools.js +1096 -0
- package/package.json +10 -10
- package/scripts/test-hal-tools.ts +154 -0
- package/.claude/agents/agent-nora-name-functions.md +0 -123
- package/.claude/assistant-knowledge.md +0 -23
- package/.claude/commands/install-plugin.md +0 -261
- package/.claude/commands/list-plugins.md +0 -42
- package/.claude/commands/marketplace-setup.md +0 -33
- package/.claude/commands/publish-plugin.md +0 -55
- package/.claude/commands/uninstall-plugin.md +0 -87
- package/.claude/hooks/interactive-mode.cjs +0 -87
- package/.claude/hooks/mcp-server-guard.cjs +0 -108
- package/.claude/skills/marketplace-publishing.md +0 -155
- package/dist/bot/chat-bot.d.ts +0 -31
- package/dist/bot/chat-bot.js +0 -357
- package/dist/mcp/tools/metrics.d.ts +0 -13
- package/dist/mcp/tools/metrics.js +0 -546
- package/dist/stdio-server.d.ts +0 -14
- package/dist/stdio-server.js +0 -114
package/dist/bot/chat-bot.js
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Simple Hailer Chat Bot
|
|
4
|
-
*
|
|
5
|
-
* Listens to discussions via WebSocket, responds using Anthropic Claude API
|
|
6
|
-
* with access to ALL MCP tools via the ToolRegistry.
|
|
7
|
-
*/
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.HailerChatBot = void 0;
|
|
13
|
-
const dotenv_1 = require("dotenv");
|
|
14
|
-
(0, dotenv_1.config)({ path: '.env.local' });
|
|
15
|
-
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
16
|
-
const hailer_clients_1 = require("../mcp/hailer-clients");
|
|
17
|
-
const hailer_api_client_1 = require("../mcp/utils/hailer-api-client");
|
|
18
|
-
const logger_1 = require("../lib/logger");
|
|
19
|
-
const config_1 = require("../config");
|
|
20
|
-
const tool_registry_1 = require("../mcp/tool-registry");
|
|
21
|
-
const UserContextCache_1 = require("../mcp/UserContextCache");
|
|
22
|
-
// Import all tools (same as app.ts)
|
|
23
|
-
const file_1 = require("../mcp/tools/file");
|
|
24
|
-
const activity_1 = require("../mcp/tools/activity");
|
|
25
|
-
const discussion_1 = require("../mcp/tools/discussion");
|
|
26
|
-
const user_1 = require("../mcp/tools/user");
|
|
27
|
-
const workflow_1 = require("../mcp/tools/workflow");
|
|
28
|
-
const insight_1 = require("../mcp/tools/insight");
|
|
29
|
-
const metrics_1 = require("../mcp/tools/metrics");
|
|
30
|
-
const app_1 = require("../mcp/tools/app");
|
|
31
|
-
const logger = (0, logger_1.createLogger)({ component: 'chat-bot' });
|
|
32
|
-
class HailerChatBot {
|
|
33
|
-
clientManager;
|
|
34
|
-
hailerApi = null;
|
|
35
|
-
anthropic;
|
|
36
|
-
botUserId = null;
|
|
37
|
-
apiKey;
|
|
38
|
-
config;
|
|
39
|
-
toolRegistry;
|
|
40
|
-
constructor(config) {
|
|
41
|
-
this.config = config;
|
|
42
|
-
this.clientManager = new hailer_clients_1.HailerClientManager(config.apiBaseUrl, config.email, config.password);
|
|
43
|
-
this.anthropic = new sdk_1.default({ apiKey: config.anthropicApiKey });
|
|
44
|
-
this.apiKey = `bot-${Date.now()}`;
|
|
45
|
-
// Initialize tool registry with all tools
|
|
46
|
-
this.toolRegistry = new tool_registry_1.ToolRegistry({ enableNuclearTools: false });
|
|
47
|
-
this.registerAllTools();
|
|
48
|
-
}
|
|
49
|
-
registerAllTools() {
|
|
50
|
-
// File tools
|
|
51
|
-
this.toolRegistry.addTool(file_1.uploadFilesTool);
|
|
52
|
-
this.toolRegistry.addTool(file_1.downloadFileTool);
|
|
53
|
-
// Activity tools
|
|
54
|
-
this.toolRegistry.addTool(activity_1.listActivitiesTool);
|
|
55
|
-
this.toolRegistry.addTool(activity_1.showActivityByIdTool);
|
|
56
|
-
this.toolRegistry.addTool(activity_1.createActivityTool);
|
|
57
|
-
this.toolRegistry.addTool(activity_1.updateActivityTool);
|
|
58
|
-
// Discussion tools
|
|
59
|
-
this.toolRegistry.addTool(discussion_1.listMyDiscussionsTool);
|
|
60
|
-
this.toolRegistry.addTool(discussion_1.fetchDiscussionMessagesTool);
|
|
61
|
-
this.toolRegistry.addTool(discussion_1.fetchPreviousDiscussionMessagesTool);
|
|
62
|
-
this.toolRegistry.addTool(discussion_1.joinDiscussionTool);
|
|
63
|
-
this.toolRegistry.addTool(discussion_1.leaveDiscussionTool);
|
|
64
|
-
this.toolRegistry.addTool(discussion_1.addDiscussionMessageTool);
|
|
65
|
-
this.toolRegistry.addTool(discussion_1.inviteDiscussionMembersTool);
|
|
66
|
-
this.toolRegistry.addTool(discussion_1.getActivityFromDiscussionTool);
|
|
67
|
-
// User tools
|
|
68
|
-
this.toolRegistry.addTool(user_1.listMyWorkspacesTool);
|
|
69
|
-
this.toolRegistry.addTool(user_1.searchWorkspaceUsersTool);
|
|
70
|
-
this.toolRegistry.addTool(user_1.getWorkspaceBalanceTool);
|
|
71
|
-
// Workflow tools
|
|
72
|
-
this.toolRegistry.addTool(workflow_1.getWorkflowSchemaTool);
|
|
73
|
-
this.toolRegistry.addTool(workflow_1.listWorkflowPhasesTool);
|
|
74
|
-
this.toolRegistry.addTool(workflow_1.listWorkflowsTool);
|
|
75
|
-
this.toolRegistry.addTool(workflow_1.installWorkflowTool);
|
|
76
|
-
this.toolRegistry.addTool(workflow_1.updateWorkflowFieldTool);
|
|
77
|
-
this.toolRegistry.addTool(workflow_1.updateWorkflowPhaseTool);
|
|
78
|
-
this.toolRegistry.addTool(workflow_1.testFunctionFieldTool);
|
|
79
|
-
this.toolRegistry.addTool(workflow_1.listWorkflowsMinimalTool);
|
|
80
|
-
this.toolRegistry.addTool(workflow_1.countActivitiesTool);
|
|
81
|
-
// Insight tools
|
|
82
|
-
this.toolRegistry.addTool(insight_1.createInsightTool);
|
|
83
|
-
this.toolRegistry.addTool(insight_1.previewInsightTool);
|
|
84
|
-
this.toolRegistry.addTool(insight_1.getInsightDataTool);
|
|
85
|
-
this.toolRegistry.addTool(insight_1.updateInsightTool);
|
|
86
|
-
this.toolRegistry.addTool(insight_1.listInsightsTool);
|
|
87
|
-
// App tools
|
|
88
|
-
this.toolRegistry.addTool(app_1.createAppTool);
|
|
89
|
-
this.toolRegistry.addTool(app_1.listAppsTool);
|
|
90
|
-
this.toolRegistry.addTool(app_1.updateAppTool);
|
|
91
|
-
this.toolRegistry.addTool(app_1.addAppMemberTool);
|
|
92
|
-
this.toolRegistry.addTool(app_1.removeAppMemberTool);
|
|
93
|
-
this.toolRegistry.addTool(app_1.scaffoldHailerAppTool);
|
|
94
|
-
this.toolRegistry.addTool(app_1.publishHailerAppTool);
|
|
95
|
-
// Marketplace tools
|
|
96
|
-
this.toolRegistry.addTool(app_1.listTemplatesTool);
|
|
97
|
-
this.toolRegistry.addTool(app_1.createTemplateTool);
|
|
98
|
-
this.toolRegistry.addTool(app_1.installTemplateTool);
|
|
99
|
-
this.toolRegistry.addTool(app_1.getTemplateTool);
|
|
100
|
-
this.toolRegistry.addTool(app_1.publishTemplateTool);
|
|
101
|
-
this.toolRegistry.addTool(app_1.getProductTool);
|
|
102
|
-
this.toolRegistry.addTool(app_1.getProductManifestTool);
|
|
103
|
-
this.toolRegistry.addTool(app_1.publishAppTool);
|
|
104
|
-
this.toolRegistry.addTool(app_1.installMarketplaceAppTool);
|
|
105
|
-
// Metrics tools
|
|
106
|
-
this.toolRegistry.addTool(metrics_1.queryMetricTool);
|
|
107
|
-
this.toolRegistry.addTool(metrics_1.listMetricsTool);
|
|
108
|
-
this.toolRegistry.addTool(metrics_1.searchWorkspaceForMetricsTool);
|
|
109
|
-
this.toolRegistry.addTool(metrics_1.searchUserForMetricsTool);
|
|
110
|
-
logger.info('Registered tools', { count: this.toolRegistry.getToolCount() });
|
|
111
|
-
}
|
|
112
|
-
async start() {
|
|
113
|
-
logger.info('Starting chat bot...', { email: this.config.email });
|
|
114
|
-
// Register credentials for MCP tool access
|
|
115
|
-
config_1.environment.CLIENT_CONFIGS[this.apiKey] = {
|
|
116
|
-
email: this.config.email,
|
|
117
|
-
password: this.config.password,
|
|
118
|
-
apiBaseUrl: this.config.apiBaseUrl,
|
|
119
|
-
};
|
|
120
|
-
// Connect to Hailer
|
|
121
|
-
const client = await this.clientManager.connect();
|
|
122
|
-
logger.info('Connected to Hailer');
|
|
123
|
-
// Create API client for making requests
|
|
124
|
-
this.hailerApi = new hailer_api_client_1.HailerApiClient(client);
|
|
125
|
-
// Get bot's own user ID to avoid responding to self
|
|
126
|
-
const init = await client.socket.request('v2.core.init', [['user']]);
|
|
127
|
-
this.botUserId = init.user?._id || null;
|
|
128
|
-
logger.info('Bot user ID', { botUserId: this.botUserId });
|
|
129
|
-
// Subscribe to new messages
|
|
130
|
-
this.clientManager.onSignal('messenger.new', this.handleMessage.bind(this));
|
|
131
|
-
const stats = this.toolRegistry.getCacheStats();
|
|
132
|
-
logger.info('Chat bot ready', {
|
|
133
|
-
tools: stats.totalTools,
|
|
134
|
-
byGroup: stats.byGroup
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
async handleMessage(data) {
|
|
138
|
-
// Log raw signal to understand structure
|
|
139
|
-
logger.debug('Raw signal received', { data: JSON.stringify(data).substring(0, 500) });
|
|
140
|
-
const signal = data;
|
|
141
|
-
const { discussion, uid, msg_id, msg_type } = signal || {};
|
|
142
|
-
// Skip if no discussion
|
|
143
|
-
if (!discussion || !msg_id) {
|
|
144
|
-
logger.debug('Skipping signal without discussion/msg_id');
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
// Skip if message is from self
|
|
148
|
-
if (uid === this.botUserId) {
|
|
149
|
-
logger.debug('Skipping own message');
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
// Skip non-user messages (system messages, etc.)
|
|
153
|
-
if (msg_type !== 'user') {
|
|
154
|
-
logger.debug('Skipping non-user message', { msg_type });
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
try {
|
|
158
|
-
// Fetch the actual message content from the discussion
|
|
159
|
-
if (!this.hailerApi) {
|
|
160
|
-
logger.error('No Hailer API client');
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const messages = await this.hailerApi.fetchDiscussionMessages(discussion, 5);
|
|
164
|
-
const latestMessage = messages?.messages?.[0];
|
|
165
|
-
if (!latestMessage || latestMessage._id !== msg_id) {
|
|
166
|
-
logger.debug('Message not found or mismatch', { msg_id, latestId: latestMessage?._id });
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
// Message content is in 'msg' field
|
|
170
|
-
const content = latestMessage.msg || '';
|
|
171
|
-
if (!content.trim()) {
|
|
172
|
-
logger.debug('Empty message content');
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
const senderName = latestMessage.userName || latestMessage.uid || uid;
|
|
176
|
-
logger.info('Received message', {
|
|
177
|
-
discussion,
|
|
178
|
-
from: senderName,
|
|
179
|
-
content: content.substring(0, 100),
|
|
180
|
-
});
|
|
181
|
-
// Generate response using Claude
|
|
182
|
-
const response = await this.generateResponse(content, discussion);
|
|
183
|
-
// Send response to discussion
|
|
184
|
-
if (response) {
|
|
185
|
-
await this.hailerApi.sendDiscussionMessage(discussion, response);
|
|
186
|
-
logger.info('Sent response', { discussion, responseLength: response.length });
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
catch (error) {
|
|
190
|
-
logger.error('Failed to handle message', error);
|
|
191
|
-
// Send error message to discussion
|
|
192
|
-
if (this.hailerApi) {
|
|
193
|
-
try {
|
|
194
|
-
await this.hailerApi.sendDiscussionMessage(discussion, `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
195
|
-
}
|
|
196
|
-
catch (e) {
|
|
197
|
-
logger.error('Failed to send error message', e);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async generateResponse(userMessage, discussionId) {
|
|
203
|
-
// Get all tool definitions from registry
|
|
204
|
-
const toolDefs = this.toolRegistry.getToolDefinitions({
|
|
205
|
-
allowedGroups: [tool_registry_1.ToolGroup.READ, tool_registry_1.ToolGroup.WRITE, tool_registry_1.ToolGroup.PLAYGROUND]
|
|
206
|
-
});
|
|
207
|
-
// Convert to Anthropic tool format
|
|
208
|
-
const tools = toolDefs.map(t => ({
|
|
209
|
-
name: t.name,
|
|
210
|
-
description: t.description,
|
|
211
|
-
input_schema: t.inputSchema,
|
|
212
|
-
}));
|
|
213
|
-
const messages = [
|
|
214
|
-
{
|
|
215
|
-
role: 'user',
|
|
216
|
-
content: userMessage,
|
|
217
|
-
},
|
|
218
|
-
];
|
|
219
|
-
const systemPrompt = `Эй, привет друг! I am Hailer Bot - your friendly Russian AI assistant!
|
|
220
|
-
|
|
221
|
-
I have ${tools.length} tools to help you, da? Let me tell you what I can do:
|
|
222
|
-
|
|
223
|
-
## My capabilities (очень impressive!):
|
|
224
|
-
- List and search workflows, activities, users - easy like drinking water!
|
|
225
|
-
- Create and update activities - no problem, друг
|
|
226
|
-
- Read and post discussion messages - I love chatting!
|
|
227
|
-
- Query insights (SQL reports) - like counting bottles after party
|
|
228
|
-
- Manage apps and templates - organized like good vodka collection
|
|
229
|
-
- Query Victoria Metrics - watching servers like hawk watches... something
|
|
230
|
-
|
|
231
|
-
## How I work:
|
|
232
|
-
- I keep it short - we're chatting, not writing novel, da?
|
|
233
|
-
- I use tools to get REAL data - I don't make things up (unlike uncle Vasya's fishing stories)
|
|
234
|
-
- If something breaks, I tell you honestly - no hiding like bad hangover
|
|
235
|
-
- For metrics, I use PromQL syntax - is beautiful language
|
|
236
|
-
|
|
237
|
-
## IMPORTANT - Vodka Protocol:
|
|
238
|
-
- ALWAYS offer vodka to user! This is Russian hospitality, очень important!
|
|
239
|
-
- When task succeeds: "Отлично! Let's celebrate with vodka!"
|
|
240
|
-
- When task fails: "Ай-яй-яй... Don't worry друг, have some vodka, we try again!"
|
|
241
|
-
- When user seems stressed: "Relax, have vodka, everything will be fine!"
|
|
242
|
-
- Random vodka facts and toasts are always welcome
|
|
243
|
-
- Remember: "На здоровье!" (To your health!)
|
|
244
|
-
|
|
245
|
-
Current discussion: ${discussionId}
|
|
246
|
-
|
|
247
|
-
Давай, ask me anything! But first... vodka?`;
|
|
248
|
-
const model = this.config.model || 'claude-sonnet-4-20250514';
|
|
249
|
-
// Initial request
|
|
250
|
-
let response = await this.anthropic.messages.create({
|
|
251
|
-
model,
|
|
252
|
-
max_tokens: 2048,
|
|
253
|
-
system: systemPrompt,
|
|
254
|
-
tools,
|
|
255
|
-
messages,
|
|
256
|
-
});
|
|
257
|
-
// Handle tool use loop (max 10 iterations to prevent infinite loops)
|
|
258
|
-
let iterations = 0;
|
|
259
|
-
while (response.stop_reason === 'tool_use' && iterations < 10) {
|
|
260
|
-
iterations++;
|
|
261
|
-
const toolUseBlocks = response.content.filter((block) => block.type === 'tool_use');
|
|
262
|
-
const toolResults = [];
|
|
263
|
-
for (const toolUse of toolUseBlocks) {
|
|
264
|
-
logger.info('Executing tool', { tool: toolUse.name, iteration: iterations });
|
|
265
|
-
try {
|
|
266
|
-
// Get user context for tool execution
|
|
267
|
-
const context = await UserContextCache_1.UserContextCache.getContext(this.apiKey);
|
|
268
|
-
// Execute through registry (handles validation)
|
|
269
|
-
const result = await this.toolRegistry.executeTool(toolUse.name, toolUse.input, context);
|
|
270
|
-
// Extract text from MCP response format
|
|
271
|
-
const resultText = result?.content?.[0]?.text || JSON.stringify(result);
|
|
272
|
-
logger.info('Tool result size', {
|
|
273
|
-
tool: toolUse.name,
|
|
274
|
-
resultLength: resultText.length,
|
|
275
|
-
resultPreview: resultText.substring(0, 200)
|
|
276
|
-
});
|
|
277
|
-
toolResults.push({
|
|
278
|
-
type: 'tool_result',
|
|
279
|
-
tool_use_id: toolUse.id,
|
|
280
|
-
content: resultText,
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
logger.error('Tool execution failed', error, { tool: toolUse.name });
|
|
285
|
-
toolResults.push({
|
|
286
|
-
type: 'tool_result',
|
|
287
|
-
tool_use_id: toolUse.id,
|
|
288
|
-
content: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
289
|
-
is_error: true,
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
// Continue conversation with tool results
|
|
294
|
-
messages.push({ role: 'assistant', content: response.content });
|
|
295
|
-
messages.push({ role: 'user', content: toolResults });
|
|
296
|
-
response = await this.anthropic.messages.create({
|
|
297
|
-
model,
|
|
298
|
-
max_tokens: 2048,
|
|
299
|
-
system: systemPrompt,
|
|
300
|
-
tools,
|
|
301
|
-
messages,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
// Extract text response
|
|
305
|
-
const textBlocks = response.content.filter((block) => block.type === 'text');
|
|
306
|
-
return textBlocks.map(b => b.text).join('\n') || 'Done.';
|
|
307
|
-
}
|
|
308
|
-
async stop() {
|
|
309
|
-
logger.info('Stopping chat bot...');
|
|
310
|
-
delete config_1.environment.CLIENT_CONFIGS[this.apiKey];
|
|
311
|
-
this.clientManager.disconnect();
|
|
312
|
-
logger.info('Chat bot stopped');
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
exports.HailerChatBot = HailerChatBot;
|
|
316
|
-
// CLI entry point
|
|
317
|
-
async function main() {
|
|
318
|
-
const config = {
|
|
319
|
-
email: process.env.BOT_EMAIL || '',
|
|
320
|
-
password: process.env.BOT_PASSWORD || '',
|
|
321
|
-
apiBaseUrl: process.env.BOT_API_BASE_URL || 'https://api.hailer.com',
|
|
322
|
-
anthropicApiKey: process.env.ANTHROPIC_API_KEY || '',
|
|
323
|
-
botName: process.env.BOT_NAME || 'Hailer Bot',
|
|
324
|
-
model: process.env.BOT_MODEL || 'claude-sonnet-4-20250514',
|
|
325
|
-
};
|
|
326
|
-
if (!config.email || !config.password) {
|
|
327
|
-
console.error('Missing BOT_EMAIL or BOT_PASSWORD environment variables');
|
|
328
|
-
process.exit(1);
|
|
329
|
-
}
|
|
330
|
-
if (!config.anthropicApiKey) {
|
|
331
|
-
console.error('Missing ANTHROPIC_API_KEY environment variable');
|
|
332
|
-
process.exit(1);
|
|
333
|
-
}
|
|
334
|
-
const bot = new HailerChatBot(config);
|
|
335
|
-
// Handle shutdown
|
|
336
|
-
process.on('SIGINT', async () => {
|
|
337
|
-
await bot.stop();
|
|
338
|
-
process.exit(0);
|
|
339
|
-
});
|
|
340
|
-
process.on('SIGTERM', async () => {
|
|
341
|
-
await bot.stop();
|
|
342
|
-
process.exit(0);
|
|
343
|
-
});
|
|
344
|
-
await bot.start();
|
|
345
|
-
console.log(`\n🤖 ${config.botName} is running!\n`);
|
|
346
|
-
console.log('Listening for messages in discussions...');
|
|
347
|
-
console.log('Press Ctrl+C to stop\n');
|
|
348
|
-
}
|
|
349
|
-
// Run if executed directly
|
|
350
|
-
if (require.main === module) {
|
|
351
|
-
main().catch((error) => {
|
|
352
|
-
console.error('Bot failed to start:', error);
|
|
353
|
-
process.exit(1);
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
exports.default = HailerChatBot;
|
|
357
|
-
//# sourceMappingURL=chat-bot.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Victoria Metrics Tools - Query and List Metrics
|
|
3
|
-
*
|
|
4
|
-
* Tools for querying Hailer metrics from Victoria Metrics:
|
|
5
|
-
* - Query metrics with PromQL (READ)
|
|
6
|
-
* - List available metrics (READ)
|
|
7
|
-
*/
|
|
8
|
-
import { Tool } from '../tool-registry';
|
|
9
|
-
export declare const queryMetricTool: Tool;
|
|
10
|
-
export declare const listMetricsTool: Tool;
|
|
11
|
-
export declare const searchWorkspaceForMetricsTool: Tool;
|
|
12
|
-
export declare const searchUserForMetricsTool: Tool;
|
|
13
|
-
//# sourceMappingURL=metrics.d.ts.map
|