clawsql 0.1.0
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.example +97 -0
- package/README.md +372 -0
- package/dist/__tests__/config/settings.test.d.ts +5 -0
- package/dist/__tests__/config/settings.test.d.ts.map +1 -0
- package/dist/__tests__/config/settings.test.js +154 -0
- package/dist/__tests__/config/settings.test.js.map +1 -0
- package/dist/__tests__/core/discovery/topology.test.d.ts +5 -0
- package/dist/__tests__/core/discovery/topology.test.d.ts.map +1 -0
- package/dist/__tests__/core/discovery/topology.test.js +191 -0
- package/dist/__tests__/core/discovery/topology.test.js.map +1 -0
- package/dist/__tests__/core/failover/executor.test.d.ts +5 -0
- package/dist/__tests__/core/failover/executor.test.d.ts.map +1 -0
- package/dist/__tests__/core/failover/executor.test.js +256 -0
- package/dist/__tests__/core/failover/executor.test.js.map +1 -0
- package/dist/__tests__/core/monitoring/collector.test.d.ts +5 -0
- package/dist/__tests__/core/monitoring/collector.test.d.ts.map +1 -0
- package/dist/__tests__/core/monitoring/collector.test.js +131 -0
- package/dist/__tests__/core/monitoring/collector.test.js.map +1 -0
- package/dist/__tests__/core/monitoring/exporters.test.d.ts +5 -0
- package/dist/__tests__/core/monitoring/exporters.test.d.ts.map +1 -0
- package/dist/__tests__/core/monitoring/exporters.test.js +90 -0
- package/dist/__tests__/core/monitoring/exporters.test.js.map +1 -0
- package/dist/__tests__/core/routing/proxysql-manager.test.d.ts +5 -0
- package/dist/__tests__/core/routing/proxysql-manager.test.d.ts.map +1 -0
- package/dist/__tests__/core/routing/proxysql-manager.test.js +155 -0
- package/dist/__tests__/core/routing/proxysql-manager.test.js.map +1 -0
- package/dist/__tests__/types/index.test.d.ts +5 -0
- package/dist/__tests__/types/index.test.d.ts.map +1 -0
- package/dist/__tests__/types/index.test.js +290 -0
- package/dist/__tests__/types/index.test.js.map +1 -0
- package/dist/__tests__/utils/exceptions.test.d.ts +5 -0
- package/dist/__tests__/utils/exceptions.test.d.ts.map +1 -0
- package/dist/__tests__/utils/exceptions.test.js +142 -0
- package/dist/__tests__/utils/exceptions.test.js.map +1 -0
- package/dist/api/routes/clusters.d.ts +7 -0
- package/dist/api/routes/clusters.d.ts.map +1 -0
- package/dist/api/routes/clusters.js +123 -0
- package/dist/api/routes/clusters.js.map +1 -0
- package/dist/api/routes/config.d.ts +7 -0
- package/dist/api/routes/config.d.ts.map +1 -0
- package/dist/api/routes/config.js +65 -0
- package/dist/api/routes/config.js.map +1 -0
- package/dist/api/routes/failover.d.ts +7 -0
- package/dist/api/routes/failover.d.ts.map +1 -0
- package/dist/api/routes/failover.js +100 -0
- package/dist/api/routes/failover.js.map +1 -0
- package/dist/api/routes/instances.d.ts +11 -0
- package/dist/api/routes/instances.d.ts.map +1 -0
- package/dist/api/routes/instances.js +315 -0
- package/dist/api/routes/instances.js.map +1 -0
- package/dist/api/routes/monitoring.d.ts +7 -0
- package/dist/api/routes/monitoring.d.ts.map +1 -0
- package/dist/api/routes/monitoring.js +72 -0
- package/dist/api/routes/monitoring.js.map +1 -0
- package/dist/api/routes/webhooks.d.ts +12 -0
- package/dist/api/routes/webhooks.d.ts.map +1 -0
- package/dist/api/routes/webhooks.js +232 -0
- package/dist/api/routes/webhooks.js.map +1 -0
- package/dist/api/schemas/index.d.ts +965 -0
- package/dist/api/schemas/index.d.ts.map +1 -0
- package/dist/api/schemas/index.js +171 -0
- package/dist/api/schemas/index.js.map +1 -0
- package/dist/app.d.ts +13 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +197 -0
- package/dist/app.js.map +1 -0
- package/dist/bin/clawsql.d.ts +12 -0
- package/dist/bin/clawsql.d.ts.map +1 -0
- package/dist/bin/clawsql.js +43 -0
- package/dist/bin/clawsql.js.map +1 -0
- package/dist/cli/agent/handler.d.ts +73 -0
- package/dist/cli/agent/handler.d.ts.map +1 -0
- package/dist/cli/agent/handler.js +258 -0
- package/dist/cli/agent/handler.js.map +1 -0
- package/dist/cli/agent/index.d.ts +14 -0
- package/dist/cli/agent/index.d.ts.map +1 -0
- package/dist/cli/agent/index.js +30 -0
- package/dist/cli/agent/index.js.map +1 -0
- package/dist/cli/agent/openclaw-integration.d.ts +81 -0
- package/dist/cli/agent/openclaw-integration.d.ts.map +1 -0
- package/dist/cli/agent/openclaw-integration.js +341 -0
- package/dist/cli/agent/openclaw-integration.js.map +1 -0
- package/dist/cli/agent/providers/anthropic.d.ts +27 -0
- package/dist/cli/agent/providers/anthropic.d.ts.map +1 -0
- package/dist/cli/agent/providers/anthropic.js +106 -0
- package/dist/cli/agent/providers/anthropic.js.map +1 -0
- package/dist/cli/agent/providers/base.d.ts +91 -0
- package/dist/cli/agent/providers/base.d.ts.map +1 -0
- package/dist/cli/agent/providers/base.js +24 -0
- package/dist/cli/agent/providers/base.js.map +1 -0
- package/dist/cli/agent/providers/openai.d.ts +27 -0
- package/dist/cli/agent/providers/openai.d.ts.map +1 -0
- package/dist/cli/agent/providers/openai.js +98 -0
- package/dist/cli/agent/providers/openai.js.map +1 -0
- package/dist/cli/agent/tools/index.d.ts +32 -0
- package/dist/cli/agent/tools/index.d.ts.map +1 -0
- package/dist/cli/agent/tools/index.js +263 -0
- package/dist/cli/agent/tools/index.js.map +1 -0
- package/dist/cli/commands/cleanup.d.ts +12 -0
- package/dist/cli/commands/cleanup.d.ts.map +1 -0
- package/dist/cli/commands/cleanup.js +205 -0
- package/dist/cli/commands/cleanup.js.map +1 -0
- package/dist/cli/commands/clusters.d.ts +12 -0
- package/dist/cli/commands/clusters.d.ts.map +1 -0
- package/dist/cli/commands/clusters.js +468 -0
- package/dist/cli/commands/clusters.js.map +1 -0
- package/dist/cli/commands/config.d.ts +12 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +406 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/cron.d.ts +12 -0
- package/dist/cli/commands/cron.d.ts.map +1 -0
- package/dist/cli/commands/cron.js +215 -0
- package/dist/cli/commands/cron.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +13 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +687 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/failover.d.ts +16 -0
- package/dist/cli/commands/failover.d.ts.map +1 -0
- package/dist/cli/commands/failover.js +333 -0
- package/dist/cli/commands/failover.js.map +1 -0
- package/dist/cli/commands/health.d.ts +12 -0
- package/dist/cli/commands/health.d.ts.map +1 -0
- package/dist/cli/commands/health.js +125 -0
- package/dist/cli/commands/health.js.map +1 -0
- package/dist/cli/commands/help.d.ts +12 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +52 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/instances.d.ts +12 -0
- package/dist/cli/commands/instances.d.ts.map +1 -0
- package/dist/cli/commands/instances.js +801 -0
- package/dist/cli/commands/instances.js.map +1 -0
- package/dist/cli/commands/notify.d.ts +12 -0
- package/dist/cli/commands/notify.d.ts.map +1 -0
- package/dist/cli/commands/notify.js +43 -0
- package/dist/cli/commands/notify.js.map +1 -0
- package/dist/cli/commands/sql.d.ts +12 -0
- package/dist/cli/commands/sql.d.ts.map +1 -0
- package/dist/cli/commands/sql.js +90 -0
- package/dist/cli/commands/sql.js.map +1 -0
- package/dist/cli/commands/start.d.ts +12 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +174 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +12 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +218 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +12 -0
- package/dist/cli/commands/stop.d.ts.map +1 -0
- package/dist/cli/commands/stop.js +128 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/commands/topology.d.ts +12 -0
- package/dist/cli/commands/topology.d.ts.map +1 -0
- package/dist/cli/commands/topology.js +106 -0
- package/dist/cli/commands/topology.js.map +1 -0
- package/dist/cli/completer.d.ts +47 -0
- package/dist/cli/completer.d.ts.map +1 -0
- package/dist/cli/completer.js +332 -0
- package/dist/cli/completer.js.map +1 -0
- package/dist/cli/formatter.d.ts +165 -0
- package/dist/cli/formatter.d.ts.map +1 -0
- package/dist/cli/formatter.js +408 -0
- package/dist/cli/formatter.js.map +1 -0
- package/dist/cli/index.d.ts +21 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +79 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/raw-input.d.ts +97 -0
- package/dist/cli/raw-input.d.ts.map +1 -0
- package/dist/cli/raw-input.js +493 -0
- package/dist/cli/raw-input.js.map +1 -0
- package/dist/cli/registry.d.ts +103 -0
- package/dist/cli/registry.d.ts.map +1 -0
- package/dist/cli/registry.js +205 -0
- package/dist/cli/registry.js.map +1 -0
- package/dist/cli/repl.d.ts +83 -0
- package/dist/cli/repl.d.ts.map +1 -0
- package/dist/cli/repl.js +447 -0
- package/dist/cli/repl.js.map +1 -0
- package/dist/cli/ui/components.d.ts +144 -0
- package/dist/cli/ui/components.d.ts.map +1 -0
- package/dist/cli/ui/components.js +331 -0
- package/dist/cli/ui/components.js.map +1 -0
- package/dist/cli/ui/index.d.ts +7 -0
- package/dist/cli/ui/index.d.ts.map +1 -0
- package/dist/cli/ui/index.js +23 -0
- package/dist/cli/ui/index.js.map +1 -0
- package/dist/cli/utils/docker-files.d.ts +39 -0
- package/dist/cli/utils/docker-files.d.ts.map +1 -0
- package/dist/cli/utils/docker-files.js +223 -0
- package/dist/cli/utils/docker-files.js.map +1 -0
- package/dist/cli/utils/docker-prereq.d.ts +48 -0
- package/dist/cli/utils/docker-prereq.d.ts.map +1 -0
- package/dist/cli/utils/docker-prereq.js +203 -0
- package/dist/cli/utils/docker-prereq.js.map +1 -0
- package/dist/config/settings.d.ts +594 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +250 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/core/discovery/cluster-view.d.ts +50 -0
- package/dist/core/discovery/cluster-view.d.ts.map +1 -0
- package/dist/core/discovery/cluster-view.js +235 -0
- package/dist/core/discovery/cluster-view.js.map +1 -0
- package/dist/core/discovery/scanner.d.ts +70 -0
- package/dist/core/discovery/scanner.d.ts.map +1 -0
- package/dist/core/discovery/scanner.js +197 -0
- package/dist/core/discovery/scanner.js.map +1 -0
- package/dist/core/discovery/topology.d.ts +118 -0
- package/dist/core/discovery/topology.d.ts.map +1 -0
- package/dist/core/discovery/topology.js +550 -0
- package/dist/core/discovery/topology.js.map +1 -0
- package/dist/core/failover/candidate-selector.d.ts +46 -0
- package/dist/core/failover/candidate-selector.d.ts.map +1 -0
- package/dist/core/failover/candidate-selector.js +70 -0
- package/dist/core/failover/candidate-selector.js.map +1 -0
- package/dist/core/failover/executor.d.ts +104 -0
- package/dist/core/failover/executor.d.ts.map +1 -0
- package/dist/core/failover/executor.js +248 -0
- package/dist/core/failover/executor.js.map +1 -0
- package/dist/core/failover/operation-builder.d.ts +71 -0
- package/dist/core/failover/operation-builder.d.ts.map +1 -0
- package/dist/core/failover/operation-builder.js +157 -0
- package/dist/core/failover/operation-builder.js.map +1 -0
- package/dist/core/failover/operation-runner.d.ts +75 -0
- package/dist/core/failover/operation-runner.d.ts.map +1 -0
- package/dist/core/failover/operation-runner.js +191 -0
- package/dist/core/failover/operation-runner.js.map +1 -0
- package/dist/core/failover/promoter.d.ts +33 -0
- package/dist/core/failover/promoter.d.ts.map +1 -0
- package/dist/core/failover/promoter.js +97 -0
- package/dist/core/failover/promoter.js.map +1 -0
- package/dist/core/failover/recovery-manager.d.ts +47 -0
- package/dist/core/failover/recovery-manager.d.ts.map +1 -0
- package/dist/core/failover/recovery-manager.js +145 -0
- package/dist/core/failover/recovery-manager.js.map +1 -0
- package/dist/core/failover/types.d.ts +54 -0
- package/dist/core/failover/types.d.ts.map +1 -0
- package/dist/core/failover/types.js +8 -0
- package/dist/core/failover/types.js.map +1 -0
- package/dist/core/monitoring/collector.d.ts +25 -0
- package/dist/core/monitoring/collector.d.ts.map +1 -0
- package/dist/core/monitoring/collector.js +115 -0
- package/dist/core/monitoring/collector.js.map +1 -0
- package/dist/core/monitoring/exporters.d.ts +49 -0
- package/dist/core/monitoring/exporters.d.ts.map +1 -0
- package/dist/core/monitoring/exporters.js +126 -0
- package/dist/core/monitoring/exporters.js.map +1 -0
- package/dist/core/routing/proxysql-manager.d.ts +213 -0
- package/dist/core/routing/proxysql-manager.d.ts.map +1 -0
- package/dist/core/routing/proxysql-manager.js +632 -0
- package/dist/core/routing/proxysql-manager.js.map +1 -0
- package/dist/core/sync/replica-recovery.d.ts +40 -0
- package/dist/core/sync/replica-recovery.d.ts.map +1 -0
- package/dist/core/sync/replica-recovery.js +134 -0
- package/dist/core/sync/replica-recovery.js.map +1 -0
- package/dist/core/sync/sync-coordinator.d.ts +83 -0
- package/dist/core/sync/sync-coordinator.d.ts.map +1 -0
- package/dist/core/sync/sync-coordinator.js +254 -0
- package/dist/core/sync/sync-coordinator.js.map +1 -0
- package/dist/core/sync/topology-watcher.d.ts +76 -0
- package/dist/core/sync/topology-watcher.d.ts.map +1 -0
- package/dist/core/sync/topology-watcher.js +222 -0
- package/dist/core/sync/topology-watcher.js.map +1 -0
- package/dist/core/sync/types.d.ts +85 -0
- package/dist/core/sync/types.d.ts.map +1 -0
- package/dist/core/sync/types.js +8 -0
- package/dist/core/sync/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +212 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +153 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/database.d.ts +62 -0
- package/dist/utils/database.d.ts.map +1 -0
- package/dist/utils/database.js +257 -0
- package/dist/utils/database.js.map +1 -0
- package/dist/utils/exceptions.d.ts +69 -0
- package/dist/utils/exceptions.d.ts.map +1 -0
- package/dist/utils/exceptions.js +121 -0
- package/dist/utils/exceptions.js.map +1 -0
- package/dist/utils/logger.d.ts +20 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +90 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mysql-client.d.ts +43 -0
- package/dist/utils/mysql-client.d.ts.map +1 -0
- package/dist/utils/mysql-client.js +125 -0
- package/dist/utils/mysql-client.js.map +1 -0
- package/docker/Dockerfile +61 -0
- package/docker/Dockerfile.node +41 -0
- package/docker/grafana/dashboards/clawsql.json +212 -0
- package/docker/grafana/provisioning/dashboards/dashboards.yml +13 -0
- package/docker/grafana/provisioning/datasources/datasources.yml +12 -0
- package/docker/init/primary.sql +26 -0
- package/docker/init/replica.sql +16 -0
- package/docker/orchestrator/orchestrator.conf.json +98 -0
- package/docker/prometheus/prometheus.yml +45 -0
- package/docker/proxysql/entrypoint.sh +8 -0
- package/docker/proxysql/init.sql.demo +30 -0
- package/docker/proxysql/proxysql.cnf +38 -0
- package/docker-compose.demo.yml +115 -0
- package/docker-compose.yml +217 -0
- package/init/primary.sql +19 -0
- package/init/replica.sql +13 -0
- package/package.json +84 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ClawSQL CLI - AI Agent Handler
|
|
4
|
+
*
|
|
5
|
+
* Handles natural language input via OpenClaw or direct LLM calls.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.AIAgent = void 0;
|
|
9
|
+
exports.createAIAgent = createAIAgent;
|
|
10
|
+
const anthropic_js_1 = require("./providers/anthropic.js");
|
|
11
|
+
const openai_js_1 = require("./providers/openai.js");
|
|
12
|
+
const index_js_1 = require("./tools/index.js");
|
|
13
|
+
/**
|
|
14
|
+
* System prompt for the AI agent
|
|
15
|
+
*/
|
|
16
|
+
const SYSTEM_PROMPT = `You are an AI assistant for ClawSQL, a MySQL cluster management system.
|
|
17
|
+
|
|
18
|
+
You help users manage MySQL clusters through natural language commands. You have access to tools that let you:
|
|
19
|
+
- View cluster topology and instance status
|
|
20
|
+
- Check health of MySQL instances
|
|
21
|
+
- Execute SQL queries (SELECT and SHOW only)
|
|
22
|
+
- View failover configuration
|
|
23
|
+
|
|
24
|
+
When a user asks a question:
|
|
25
|
+
1. Use the appropriate tool to gather information
|
|
26
|
+
2. Provide a clear, concise response based on the results
|
|
27
|
+
3. If multiple steps are needed, explain what you're doing
|
|
28
|
+
|
|
29
|
+
Always be helpful and provide accurate information about the cluster state.
|
|
30
|
+
If you cannot perform an action (like unsafe SQL), explain why.
|
|
31
|
+
|
|
32
|
+
Available clusters and instances are managed by Orchestrator and ProxySQL.`;
|
|
33
|
+
/**
|
|
34
|
+
* AI Agent for ClawSQL CLI
|
|
35
|
+
*/
|
|
36
|
+
class AIAgent {
|
|
37
|
+
provider = null;
|
|
38
|
+
tools;
|
|
39
|
+
conversationHistory = [];
|
|
40
|
+
config;
|
|
41
|
+
openclawAvailable = null;
|
|
42
|
+
constructor(ctx, config) {
|
|
43
|
+
this.config = {
|
|
44
|
+
enabled: true,
|
|
45
|
+
provider: 'openclaw',
|
|
46
|
+
maxIterations: 5,
|
|
47
|
+
...config,
|
|
48
|
+
};
|
|
49
|
+
// Initialize provider (may be null for openclaw mode)
|
|
50
|
+
if (this.config.provider !== 'openclaw') {
|
|
51
|
+
this.provider = this.createProvider();
|
|
52
|
+
}
|
|
53
|
+
this.tools = (0, index_js_1.createAgentTools)(ctx);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create the LLM provider based on configuration
|
|
57
|
+
*/
|
|
58
|
+
createProvider() {
|
|
59
|
+
switch (this.config.provider) {
|
|
60
|
+
case 'openai':
|
|
61
|
+
return new openai_js_1.OpenAIProvider();
|
|
62
|
+
case 'anthropic':
|
|
63
|
+
default:
|
|
64
|
+
return new anthropic_js_1.AnthropicProvider();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if the agent is properly configured
|
|
69
|
+
*/
|
|
70
|
+
isConfigured() {
|
|
71
|
+
if (this.config.provider === 'openclaw') {
|
|
72
|
+
return true; // OpenClaw is always "configured" if installed
|
|
73
|
+
}
|
|
74
|
+
return this.config.enabled && (this.provider?.isConfigured() ?? false);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the provider name
|
|
78
|
+
*/
|
|
79
|
+
getProviderName() {
|
|
80
|
+
return this.config.provider;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Process a natural language input
|
|
84
|
+
* @param input The user's natural language input
|
|
85
|
+
* @param onChunk Optional callback for streaming output chunks
|
|
86
|
+
* @param signal Optional AbortSignal to cancel the operation
|
|
87
|
+
*/
|
|
88
|
+
async process(input, onChunk, signal) {
|
|
89
|
+
// Try OpenClaw first if configured
|
|
90
|
+
if (this.config.provider === 'openclaw') {
|
|
91
|
+
try {
|
|
92
|
+
const { isOpenClawAvailable, sendToOpenClaw, sendToOpenClawStream } = await import('./openclaw-integration.js');
|
|
93
|
+
if (this.openclawAvailable === null) {
|
|
94
|
+
this.openclawAvailable = await isOpenClawAvailable();
|
|
95
|
+
}
|
|
96
|
+
if (this.openclawAvailable) {
|
|
97
|
+
const contextPrompt = this.buildOpenClawContext();
|
|
98
|
+
// Use streaming if callback provided
|
|
99
|
+
if (onChunk) {
|
|
100
|
+
return await sendToOpenClawStream(`${contextPrompt}\n\nUser query: ${input}`, onChunk, { signal });
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return await sendToOpenClaw(`${contextPrompt}\n\nUser query: ${input}`, { signal });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
// Check if it was aborted
|
|
109
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
// Fall through to direct LLM
|
|
113
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
114
|
+
console.error('OpenClaw not available, falling back to direct LLM:', msg);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Fall back to direct LLM calls
|
|
118
|
+
if (!this.provider || !this.provider.isConfigured()) {
|
|
119
|
+
return 'AI features are not configured. Install OpenClaw (recommended) or set ANTHROPIC_API_KEY or OPENAI_API_KEY environment variable.';
|
|
120
|
+
}
|
|
121
|
+
return this.processWithLLM(input, signal);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Process using direct LLM call
|
|
125
|
+
*/
|
|
126
|
+
async processWithLLM(input, signal) {
|
|
127
|
+
// Add user message to history
|
|
128
|
+
this.conversationHistory.push({
|
|
129
|
+
role: 'user',
|
|
130
|
+
content: input,
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
let iteration = 0;
|
|
134
|
+
let response = await this.sendChat(signal);
|
|
135
|
+
// Handle tool use loop
|
|
136
|
+
while (response.toolUse && iteration < this.config.maxIterations) {
|
|
137
|
+
iteration++;
|
|
138
|
+
// Execute tool calls
|
|
139
|
+
const toolResults = await this.executeTools(response.toolUse);
|
|
140
|
+
// Add assistant message with tool use
|
|
141
|
+
this.conversationHistory.push({
|
|
142
|
+
role: 'assistant',
|
|
143
|
+
content: response.content || '',
|
|
144
|
+
});
|
|
145
|
+
// Add tool results
|
|
146
|
+
for (const result of toolResults) {
|
|
147
|
+
this.conversationHistory.push({
|
|
148
|
+
role: 'user',
|
|
149
|
+
content: JSON.stringify({
|
|
150
|
+
type: 'tool_result',
|
|
151
|
+
tool_use_id: result.tool_use_id,
|
|
152
|
+
content: result.content,
|
|
153
|
+
is_error: result.is_error,
|
|
154
|
+
}),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
// Get next response
|
|
158
|
+
response = await this.sendChat(signal);
|
|
159
|
+
}
|
|
160
|
+
// Add final assistant response to history
|
|
161
|
+
if (response.content) {
|
|
162
|
+
this.conversationHistory.push({
|
|
163
|
+
role: 'assistant',
|
|
164
|
+
content: response.content,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return response.content || 'No response generated.';
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
// Re-throw abort errors
|
|
171
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
175
|
+
return `Error: ${message}`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Build context for OpenClaw
|
|
180
|
+
*/
|
|
181
|
+
buildOpenClawContext() {
|
|
182
|
+
return `You are the ClawSQL assistant for MySQL cluster management.
|
|
183
|
+
|
|
184
|
+
CRITICAL: Use the 'clawsql' skill. Execute commands EXACTLY as shown:
|
|
185
|
+
- Topology: clawsql --command /topology
|
|
186
|
+
- Health: clawsql --command /health
|
|
187
|
+
- Clusters: clawsql --command /clusters
|
|
188
|
+
- SQL queries: clawsql --command "/sql YOUR_QUERY_HERE"
|
|
189
|
+
|
|
190
|
+
For user questions about databases/tables/users, execute SQL directly:
|
|
191
|
+
- SHOW DATABASES
|
|
192
|
+
- SHOW TABLES FROM database_name
|
|
193
|
+
- SELECT User, Host FROM mysql.user
|
|
194
|
+
|
|
195
|
+
NEVER say "I cannot" or make excuses. Execute the command. If it fails, show the actual error.`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Send a chat request to the LLM
|
|
199
|
+
*/
|
|
200
|
+
async sendChat(signal) {
|
|
201
|
+
if (!this.provider) {
|
|
202
|
+
throw new Error('No LLM provider configured');
|
|
203
|
+
}
|
|
204
|
+
const response = await this.provider.chat([{ role: 'system', content: SYSTEM_PROMPT }, ...this.conversationHistory], this.tools, { signal });
|
|
205
|
+
return {
|
|
206
|
+
content: response.content,
|
|
207
|
+
toolUse: response.toolUse,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Execute tool calls
|
|
212
|
+
*/
|
|
213
|
+
async executeTools(toolUse) {
|
|
214
|
+
const results = [];
|
|
215
|
+
for (const tool of toolUse) {
|
|
216
|
+
const toolDef = this.tools.find(t => t.name === tool.name);
|
|
217
|
+
if (!toolDef) {
|
|
218
|
+
results.push({
|
|
219
|
+
tool_use_id: tool.id,
|
|
220
|
+
content: JSON.stringify({ error: `Unknown tool: ${tool.name}` }),
|
|
221
|
+
is_error: true,
|
|
222
|
+
});
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const result = await toolDef.execute(tool.input, null);
|
|
227
|
+
results.push({
|
|
228
|
+
tool_use_id: tool.id,
|
|
229
|
+
content: JSON.stringify(result),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
results.push({
|
|
234
|
+
tool_use_id: tool.id,
|
|
235
|
+
content: JSON.stringify({
|
|
236
|
+
error: error instanceof Error ? error.message : String(error),
|
|
237
|
+
}),
|
|
238
|
+
is_error: true,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return results;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Clear conversation history
|
|
246
|
+
*/
|
|
247
|
+
reset() {
|
|
248
|
+
this.conversationHistory = [];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.AIAgent = AIAgent;
|
|
252
|
+
/**
|
|
253
|
+
* Create an AI agent instance
|
|
254
|
+
*/
|
|
255
|
+
function createAIAgent(ctx, config) {
|
|
256
|
+
return new AIAgent(ctx, config);
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/cli/agent/handler.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA4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,CAAC;qBAC9D,CAAC;oBACF,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;CACF;AApPD,0BAoPC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,GAAe,EAAE,MAA6B;IAC1E,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawSQL CLI - AI Agent Module
|
|
3
|
+
*
|
|
4
|
+
* Exports for the AI agent system.
|
|
5
|
+
*/
|
|
6
|
+
export { AIAgent, createAIAgent } from './handler.js';
|
|
7
|
+
export type { AgentConfig } from './handler.js';
|
|
8
|
+
export type { LLMProvider, ChatMessage, ChatResponse, AgentTool, ToolParameterSchema } from './providers/base.js';
|
|
9
|
+
export { loadAIConfig } from './providers/base.js';
|
|
10
|
+
export { AnthropicProvider, getAnthropicProvider } from './providers/anthropic.js';
|
|
11
|
+
export { OpenAIProvider, getOpenAIProvider } from './providers/openai.js';
|
|
12
|
+
export { createAgentTools } from './tools/index.js';
|
|
13
|
+
export { OpenClawAgent, createOpenClawAgent, isOpenClawAvailable, sendToOpenClaw, scheduleCron, sendNotification, writeToMemory, } from './openclaw-integration.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/agent/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAClH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,aAAa,GACd,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ClawSQL CLI - AI Agent Module
|
|
4
|
+
*
|
|
5
|
+
* Exports for the AI agent system.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.writeToMemory = exports.sendNotification = exports.scheduleCron = exports.sendToOpenClaw = exports.isOpenClawAvailable = exports.createOpenClawAgent = exports.OpenClawAgent = exports.createAgentTools = exports.getOpenAIProvider = exports.OpenAIProvider = exports.getAnthropicProvider = exports.AnthropicProvider = exports.loadAIConfig = exports.createAIAgent = exports.AIAgent = void 0;
|
|
9
|
+
var handler_js_1 = require("./handler.js");
|
|
10
|
+
Object.defineProperty(exports, "AIAgent", { enumerable: true, get: function () { return handler_js_1.AIAgent; } });
|
|
11
|
+
Object.defineProperty(exports, "createAIAgent", { enumerable: true, get: function () { return handler_js_1.createAIAgent; } });
|
|
12
|
+
var base_js_1 = require("./providers/base.js");
|
|
13
|
+
Object.defineProperty(exports, "loadAIConfig", { enumerable: true, get: function () { return base_js_1.loadAIConfig; } });
|
|
14
|
+
var anthropic_js_1 = require("./providers/anthropic.js");
|
|
15
|
+
Object.defineProperty(exports, "AnthropicProvider", { enumerable: true, get: function () { return anthropic_js_1.AnthropicProvider; } });
|
|
16
|
+
Object.defineProperty(exports, "getAnthropicProvider", { enumerable: true, get: function () { return anthropic_js_1.getAnthropicProvider; } });
|
|
17
|
+
var openai_js_1 = require("./providers/openai.js");
|
|
18
|
+
Object.defineProperty(exports, "OpenAIProvider", { enumerable: true, get: function () { return openai_js_1.OpenAIProvider; } });
|
|
19
|
+
Object.defineProperty(exports, "getOpenAIProvider", { enumerable: true, get: function () { return openai_js_1.getOpenAIProvider; } });
|
|
20
|
+
var index_js_1 = require("./tools/index.js");
|
|
21
|
+
Object.defineProperty(exports, "createAgentTools", { enumerable: true, get: function () { return index_js_1.createAgentTools; } });
|
|
22
|
+
var openclaw_integration_js_1 = require("./openclaw-integration.js");
|
|
23
|
+
Object.defineProperty(exports, "OpenClawAgent", { enumerable: true, get: function () { return openclaw_integration_js_1.OpenClawAgent; } });
|
|
24
|
+
Object.defineProperty(exports, "createOpenClawAgent", { enumerable: true, get: function () { return openclaw_integration_js_1.createOpenClawAgent; } });
|
|
25
|
+
Object.defineProperty(exports, "isOpenClawAvailable", { enumerable: true, get: function () { return openclaw_integration_js_1.isOpenClawAvailable; } });
|
|
26
|
+
Object.defineProperty(exports, "sendToOpenClaw", { enumerable: true, get: function () { return openclaw_integration_js_1.sendToOpenClaw; } });
|
|
27
|
+
Object.defineProperty(exports, "scheduleCron", { enumerable: true, get: function () { return openclaw_integration_js_1.scheduleCron; } });
|
|
28
|
+
Object.defineProperty(exports, "sendNotification", { enumerable: true, get: function () { return openclaw_integration_js_1.sendNotification; } });
|
|
29
|
+
Object.defineProperty(exports, "writeToMemory", { enumerable: true, get: function () { return openclaw_integration_js_1.writeToMemory; } });
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/agent/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,2CAAsD;AAA7C,qGAAA,OAAO,OAAA;AAAE,2GAAA,aAAa,OAAA;AAG/B,+CAAmD;AAA1C,uGAAA,YAAY,OAAA;AACrB,yDAAmF;AAA1E,iHAAA,iBAAiB,OAAA;AAAE,oHAAA,oBAAoB,OAAA;AAChD,mDAA0E;AAAjE,2GAAA,cAAc,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAC1C,6CAAoD;AAA3C,4GAAA,gBAAgB,OAAA;AACzB,qEAQmC;AAPjC,wHAAA,aAAa,OAAA;AACb,8HAAA,mBAAmB,OAAA;AACnB,8HAAA,mBAAmB,OAAA;AACnB,yHAAA,cAAc,OAAA;AACd,uHAAA,YAAY,OAAA;AACZ,2HAAA,gBAAgB,OAAA;AAChB,wHAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawSQL CLI - OpenClaw Integration
|
|
3
|
+
*
|
|
4
|
+
* Integrates with OpenClaw gateway for AI-powered operations.
|
|
5
|
+
*/
|
|
6
|
+
import { CLIContext } from '../registry.js';
|
|
7
|
+
/**
|
|
8
|
+
* OpenClaw integration options
|
|
9
|
+
*/
|
|
10
|
+
export interface OpenClawOptions {
|
|
11
|
+
gatewayUrl?: string;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check if OpenClaw gateway is running
|
|
16
|
+
* Note: The status command may show "unreachable" due to internal scope issues,
|
|
17
|
+
* but the agent can still work. We check if OpenClaw is installed and try to use it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isOpenClawAvailable(): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Send a message to OpenClaw agent
|
|
22
|
+
*/
|
|
23
|
+
export declare function sendToOpenClaw(message: string, options?: OpenClawOptions & {
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Send a message to OpenClaw agent with streaming output
|
|
28
|
+
* Calls onChunk callback for each chunk of output as it arrives
|
|
29
|
+
*
|
|
30
|
+
* NOTE: OpenClaw's agent command outputs all at once after processing completes,
|
|
31
|
+
* not incrementally. The streaming callback will typically receive one large chunk.
|
|
32
|
+
* This is a limitation of OpenClaw's internal output handling, not Node.js buffering.
|
|
33
|
+
*/
|
|
34
|
+
export declare function sendToOpenClawStream(message: string, onChunk: (chunk: string) => void, options?: OpenClawOptions & {
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Schedule a cron job via OpenClaw
|
|
39
|
+
*/
|
|
40
|
+
export declare function scheduleCron(name: string, schedule: string, prompt: string): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Send a notification via OpenClaw channels
|
|
43
|
+
*/
|
|
44
|
+
export declare function sendNotification(to: string, message: string): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Write to OpenClaw memory
|
|
47
|
+
*/
|
|
48
|
+
export declare function writeToMemory(content: string, filename?: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* OpenClaw-backed AI agent
|
|
51
|
+
*/
|
|
52
|
+
export declare class OpenClawAgent {
|
|
53
|
+
private context;
|
|
54
|
+
private available;
|
|
55
|
+
constructor(ctx: CLIContext);
|
|
56
|
+
/**
|
|
57
|
+
* Check if OpenClaw is available
|
|
58
|
+
*/
|
|
59
|
+
isAvailable(): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Process a natural language query
|
|
62
|
+
*/
|
|
63
|
+
process(input: string): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Build context prompt with current cluster state
|
|
66
|
+
*/
|
|
67
|
+
private buildContextPrompt;
|
|
68
|
+
/**
|
|
69
|
+
* Schedule periodic health checks
|
|
70
|
+
*/
|
|
71
|
+
scheduleHealthCheck(schedule?: string): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Send an alert through configured channels
|
|
74
|
+
*/
|
|
75
|
+
alert(channel: string, message: string): Promise<string>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create an OpenClaw agent instance
|
|
79
|
+
*/
|
|
80
|
+
export declare function createOpenClawAgent(ctx: CLIContext): OpenClawAgent;
|
|
81
|
+
//# sourceMappingURL=openclaw-integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openclaw-integration.d.ts","sourceRoot":"","sources":["../../../src/cli/agent/openclaw-integration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAgC5D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACnD,OAAO,CAAC,MAAM,CAAC,CAgEjB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,EAChC,OAAO,CAAC,EAAE,eAAe,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACnD,OAAO,CAAC,MAAM,CAAC,CA0EjB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAmCjB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,E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