@bytebase/dbhub 0.0.8 → 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.
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
import { ConnectorManager } from '../connectors/manager.js';
|
|
2
2
|
import { ConnectorRegistry } from '../connectors/interface.js';
|
|
3
3
|
import { createToolSuccessResponse } from '../utils/response-formatter.js';
|
|
4
|
+
import { isDemoMode } from '../config/env.js';
|
|
4
5
|
/**
|
|
5
6
|
* list_connectors tool handler
|
|
6
7
|
* Lists all available database connectors and their sample DSNs
|
|
8
|
+
* Indicates which connector is active based on current DSN
|
|
7
9
|
*/
|
|
8
10
|
export async function listConnectorsToolHandler(_args, _extra) {
|
|
9
11
|
const connectors = ConnectorManager.getAvailableConnectors();
|
|
10
12
|
const samples = ConnectorRegistry.getAllSampleDSNs();
|
|
13
|
+
// Get active connector if possible
|
|
14
|
+
let activeConnectorId = null;
|
|
15
|
+
try {
|
|
16
|
+
// Check if we have an active connection using static method
|
|
17
|
+
const activeConnector = ConnectorManager.getCurrentConnector();
|
|
18
|
+
activeConnectorId = activeConnector.id;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
// No active connector yet or not connected
|
|
22
|
+
}
|
|
23
|
+
// If we're in demo mode, SQLite should be active
|
|
24
|
+
const isDemo = isDemoMode();
|
|
25
|
+
if (isDemo && !activeConnectorId) {
|
|
26
|
+
activeConnectorId = 'sqlite';
|
|
27
|
+
}
|
|
11
28
|
// Convert to a more structured format
|
|
12
29
|
const sampleObjects = Object.entries(samples).map(([id, dsn]) => ({
|
|
13
30
|
id,
|
|
14
|
-
dsn
|
|
31
|
+
dsn,
|
|
32
|
+
active: id === activeConnectorId
|
|
15
33
|
}));
|
|
16
34
|
// Prepare response data
|
|
17
35
|
const responseData = {
|
|
18
36
|
connectors: sampleObjects,
|
|
19
|
-
count: sampleObjects.length
|
|
37
|
+
count: sampleObjects.length,
|
|
38
|
+
activeConnector: activeConnectorId,
|
|
39
|
+
demoMode: isDemo
|
|
20
40
|
};
|
|
21
41
|
// Use the utility to create a standardized response
|
|
22
42
|
return createToolSuccessResponse(responseData);
|