@elyracode/db-tools 0.9.49 → 0.9.50

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.50] - 2026-10-10
4
+
5
+ ### Fixed
6
+ - `ELYRA_CLICKHOUSE_TIMEOUT_CONNECT` now works. It was passed to the ClickHouse client as `connect_timeout`, which the client does not support, so it was silently ignored and an unreachable server only failed after the query timeout. The extension now pings the server first and fails with a clear message once the connect timeout passes
7
+ - The MySQL and ClickHouse tool descriptions no longer claim that the user approves each query; there is no such step. They now state the actual rule: only SELECT queries unless `ELYRA_DB_ALLOW_WRITES=true`
8
+ - Type errors in the tool definitions (result details were inferred too narrowly, and the third `execute` argument, the abort signal, was named `ctx`). The extension is now type-checked with the rest of the repository
9
+
3
10
  ## [0.9.49] - 2026-10-10
4
11
 
5
12
  ### Changed
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import type { ExtensionAPI } from "@elyracode/coding-agent";
3
+ import type { AgentToolResult, ExtensionAPI } from "@elyracode/coding-agent";
4
4
  import type * as ClickHouse from "@clickhouse/client";
5
5
  import type * as MySql from "mysql2/promise";
6
6
  import { Type } from "typebox";
@@ -15,6 +15,55 @@ let clickhouseDriver: Promise<typeof ClickHouse> | undefined;
15
15
  const loadMysql = (): Promise<typeof MySql> => (mysqlDriver ??= import("mysql2/promise"));
16
16
  const loadClickHouse = (): Promise<typeof ClickHouse> => (clickhouseDriver ??= import("@clickhouse/client"));
17
17
 
18
+ /** Details reported by the query tools. */
19
+ interface QueryDetails {
20
+ rowCount?: number;
21
+ }
22
+
23
+ /**
24
+ * Create a ClickHouse client and make sure the server answers within `timeoutConnect`.
25
+ * The client has no connect-timeout option of its own (only `request_timeout` for the whole
26
+ * request), so ELYRA_CLICKHOUSE_TIMEOUT_CONNECT is enforced with a ping before the query.
27
+ */
28
+ async function openClickHouse(config: ClickHouseConfig): Promise<ClickHouse.ClickHouseClient> {
29
+ const protocol = config.https ? "https" : "http";
30
+ const client = (await loadClickHouse()).createClient({
31
+ url: `${protocol}://${config.host}:${config.port}`,
32
+ username: config.user,
33
+ password: config.password,
34
+ database: config.database,
35
+ request_timeout: config.timeoutQuery,
36
+ });
37
+ let timer: ReturnType<typeof setTimeout> | undefined;
38
+ const ping = client.ping();
39
+ ping.catch(() => {});
40
+ try {
41
+ const result = await Promise.race([
42
+ ping,
43
+ new Promise<never>((_, reject) => {
44
+ timer = setTimeout(
45
+ () =>
46
+ reject(
47
+ new Error(
48
+ `could not reach ClickHouse at ${config.host}:${config.port} within ${config.timeoutConnect} ms (ELYRA_CLICKHOUSE_TIMEOUT_CONNECT)`,
49
+ ),
50
+ ),
51
+ config.timeoutConnect,
52
+ );
53
+ }),
54
+ ]);
55
+ if (!result.success) {
56
+ throw result.error instanceof Error ? result.error : new Error("ClickHouse ping failed");
57
+ }
58
+ return client;
59
+ } catch (error) {
60
+ await client.close().catch(() => {});
61
+ throw error;
62
+ } finally {
63
+ clearTimeout(timer);
64
+ }
65
+ }
66
+
18
67
  export default function (elyra: ExtensionAPI) {
19
68
  // ── Load .env ──
20
69
  // Reads the project's .env file (if it exists) and maps common Laravel/Docker
@@ -35,14 +84,14 @@ export default function (elyra: ExtensionAPI) {
35
84
  description:
36
85
  "Execute a SQL query against the configured MySQL database. Returns results as JSON. " +
37
86
  "Use get_database_schema first to understand the database structure. " +
38
- "By default, only SELECT queries are allowed. The user must approve each query before execution.",
87
+ "By default, only SELECT queries are allowed (set ELYRA_DB_ALLOW_WRITES=true to allow writes).",
39
88
  parameters: Type.Object({
40
89
  sql: Type.String({ description: "The SQL query to execute" }),
41
90
  database: Type.Optional(
42
91
  Type.String({ description: "Override the default database (optional)" }),
43
92
  ),
44
93
  }),
45
- execute: async (toolCallId, params, ctx) => {
94
+ execute: async (_toolCallId, params): Promise<AgentToolResult<QueryDetails>> => {
46
95
  const config = getMysqlConfig(params.database);
47
96
  if (!config) {
48
97
  return {
@@ -111,14 +160,14 @@ export default function (elyra: ExtensionAPI) {
111
160
  description:
112
161
  "Execute a SQL query against the configured ClickHouse database. Returns results as JSON. " +
113
162
  "ClickHouse is optimized for analytical queries on large datasets. " +
114
- "Use get_database_schema first to understand the database structure. The user must approve each query before execution.",
163
+ "Use get_database_schema first to understand the database structure. By default, only SELECT queries are allowed.",
115
164
  parameters: Type.Object({
116
165
  sql: Type.String({ description: "The SQL query to execute" }),
117
166
  database: Type.Optional(
118
167
  Type.String({ description: "Override the default database (optional)" }),
119
168
  ),
120
169
  }),
121
- execute: async (toolCallId, params, ctx) => {
170
+ execute: async (_toolCallId, params): Promise<AgentToolResult<QueryDetails>> => {
122
171
  const config = getClickHouseConfig(params.database);
123
172
  if (!config) {
124
173
  return {
@@ -146,15 +195,7 @@ export default function (elyra: ExtensionAPI) {
146
195
  }
147
196
 
148
197
  try {
149
- const protocol = config.https ? "https" : "http";
150
- const client = (await loadClickHouse()).createClient({
151
- url: `${protocol}://${config.host}:${config.port}`,
152
- username: config.user,
153
- password: config.password,
154
- database: config.database,
155
- connect_timeout: config.timeoutConnect,
156
- request_timeout: config.timeoutQuery,
157
- });
198
+ const client = await openClickHouse(config);
158
199
 
159
200
  try {
160
201
  const result = await client.query({
@@ -200,7 +241,7 @@ export default function (elyra: ExtensionAPI) {
200
241
  Type.String({ description: "Path to the SQLite database file (default: auto-detect from .env or database/database.sqlite)" }),
201
242
  ),
202
243
  }),
203
- execute: async (_toolCallId, params) => {
244
+ execute: async (_toolCallId, params): Promise<AgentToolResult<QueryDetails>> => {
204
245
  const dbPath = resolveSqlitePath(params.db_path);
205
246
  if (!dbPath) {
206
247
  return {
@@ -507,15 +548,7 @@ async function getClickHouseSchema(
507
548
  }
508
549
 
509
550
  try {
510
- const protocol = config.https ? "https" : "http";
511
- const client = (await loadClickHouse()).createClient({
512
- url: `${protocol}://${config.host}:${config.port}`,
513
- username: config.user,
514
- password: config.password,
515
- database: config.database,
516
- connect_timeout: config.timeoutConnect,
517
- request_timeout: config.timeoutQuery,
518
- });
551
+ const client = await openClickHouse(config);
519
552
 
520
553
  try {
521
554
  if (table) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyracode/db-tools",
3
- "version": "0.9.49",
3
+ "version": "0.9.50",
4
4
  "description": "Database tools for Elyra - query MySQL and ClickHouse with schema awareness and safety guardrails",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -0,0 +1,48 @@
1
+ import type { AddressInfo } from "node:net";
2
+ import { createServer, type Server, type Socket } from "node:net";
3
+ import { afterEach, describe, expect, it } from "vitest";
4
+ import dbTools from "../extensions/index.js";
5
+
6
+ type Tool = { name: string; execute: (...args: unknown[]) => Promise<{ content: Array<{ text?: string }> }> };
7
+
8
+ function loadTools(): Map<string, Tool> {
9
+ const tools = new Map<string, Tool>();
10
+ const api = new Proxy(
11
+ { registerTool: (tool: Tool) => tools.set(tool.name, tool) },
12
+ { get: (target, prop) => (prop in target ? target[prop as keyof typeof target] : () => {}) },
13
+ );
14
+ dbTools(api as never);
15
+ return tools;
16
+ }
17
+
18
+ describe("ClickHouse connect timeout", () => {
19
+ let server: Server | undefined;
20
+ const sockets: Socket[] = [];
21
+ const saved = { ...process.env };
22
+
23
+ afterEach(() => {
24
+ for (const s of sockets.splice(0)) s.destroy();
25
+ server?.close();
26
+ process.env = { ...saved };
27
+ });
28
+
29
+ it("fails fast with a clear error when the server accepts but never answers", async () => {
30
+ // Accept connections and never respond, like a firewall or a hung server.
31
+ server = createServer((socket) => sockets.push(socket));
32
+ await new Promise<void>((resolve) => server!.listen(0, "127.0.0.1", resolve));
33
+ const port = (server.address() as AddressInfo).port;
34
+ process.env.ELYRA_CLICKHOUSE_HOST = "127.0.0.1";
35
+ process.env.ELYRA_CLICKHOUSE_PORT = String(port);
36
+ process.env.ELYRA_CLICKHOUSE_DATABASE = "default";
37
+ process.env.ELYRA_CLICKHOUSE_TIMEOUT_CONNECT = "300";
38
+ process.env.ELYRA_CLICKHOUSE_TIMEOUT_QUERY = "30000";
39
+
40
+ const tool = loadTools().get("query_clickhouse");
41
+ expect(tool).toBeDefined();
42
+ const started = Date.now();
43
+ const result = await tool!.execute("call-1", { sql: "SELECT 1" });
44
+ const elapsed = Date.now() - started;
45
+ expect(result.content[0].text).toContain("within 300 ms");
46
+ expect(elapsed).toBeLessThan(3000);
47
+ });
48
+ });