@kaelio/ktx 0.12.0 → 0.13.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/assets/python/{kaelio_ktx-0.12.0-py3-none-any.whl → kaelio_ktx-0.13.0-py3-none-any.whl} +0 -0
- package/assets/python/manifest.json +4 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/commands/setup-commands.js +13 -0
- package/dist/connection.js +14 -2
- package/dist/connectors/bigquery/connector.js +1 -14
- package/dist/connectors/clickhouse/connector.js +1 -15
- package/dist/connectors/duckdb/federated-attach.d.ts +7 -0
- package/dist/connectors/duckdb/federated-attach.js +86 -0
- package/dist/connectors/duckdb/federated-executor.d.ts +5 -0
- package/dist/connectors/duckdb/federated-executor.js +59 -0
- package/dist/connectors/mysql/connector.js +1 -15
- package/dist/connectors/postgres/connector.js +1 -14
- package/dist/connectors/shared/string-reference.d.ts +6 -0
- package/dist/connectors/shared/string-reference.js +19 -0
- package/dist/connectors/snowflake/connector.js +1 -14
- package/dist/connectors/sqlserver/connector.js +1 -14
- package/dist/context/connections/federation.d.ts +33 -0
- package/dist/context/connections/federation.js +51 -0
- package/dist/context/connections/local-warehouse-descriptor.d.ts +2 -0
- package/dist/context/connections/project-sql-executor.d.ts +18 -0
- package/dist/context/connections/project-sql-executor.js +39 -0
- package/dist/context/connections/query-executor.d.ts +2 -2
- package/dist/context/connections/read-only-sql.js +4 -3
- package/dist/context/connections/resolve-connection.d.ts +12 -0
- package/dist/context/connections/resolve-connection.js +37 -0
- package/dist/context/core/git-env.d.ts +4 -0
- package/dist/context/core/git-env.js +5 -1
- package/dist/context/ingest/adapters/live-database/manifest.d.ts +3 -0
- package/dist/context/ingest/adapters/live-database/manifest.js +19 -11
- package/dist/context/llm/claude-code-runtime.js +18 -2
- package/dist/context/mcp/context-tools.js +27 -2
- package/dist/context/mcp/local-project-ports.js +55 -50
- package/dist/context/mcp/types.d.ts +2 -0
- package/dist/context/scan/local-enrichment-artifacts.js +31 -3
- package/dist/context/sl/local-query.js +29 -12
- package/dist/context/sl/local-sl.js +27 -1
- package/dist/context/sl/source-files.d.ts +2 -0
- package/dist/context/sl/source-files.js +7 -0
- package/dist/ingest-query-executor.d.ts +2 -0
- package/dist/ingest-query-executor.js +8 -22
- package/dist/setup-agents.d.ts +21 -15
- package/dist/setup-agents.js +128 -42
- package/dist/setup-databases.d.ts +3 -0
- package/dist/setup-databases.js +16 -0
- package/dist/setup-sources.js +1 -5
- package/dist/setup.d.ts +1 -0
- package/dist/setup.js +1 -0
- package/dist/sql.d.ts +2 -0
- package/dist/sql.js +35 -53
- package/dist/telemetry/events.d.ts +2 -1
- package/dist/telemetry/events.js +11 -1
- package/package.json +2 -1
package/dist/sql.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { FEDERATED_CONNECTION_ID } from './context/connections/federation.js';
|
|
2
|
+
import { executeProjectReadOnlySql } from './context/connections/project-sql-executor.js';
|
|
3
|
+
import { resolveConfiguredConnection } from './context/connections/resolve-connection.js';
|
|
1
4
|
import { loadKtxProject } from './context/project/project.js';
|
|
5
|
+
import { sqlAnalysisDialectForDriver } from './context/sql-analysis/dialect.js';
|
|
2
6
|
import { resolveOutputMode } from './io/mode.js';
|
|
3
7
|
import { createKtxCliScanConnector } from './local-scan-connectors.js';
|
|
4
8
|
import { createManagedDaemonSqlAnalysisPort } from './managed-python-http.js';
|
|
@@ -8,19 +12,6 @@ import { emitTelemetryEvent, reportException } from './telemetry/index.js';
|
|
|
8
12
|
import { collectTelemetryRedactionSecrets } from './telemetry/redaction-secrets.js';
|
|
9
13
|
import { scrubErrorClass } from './telemetry/scrubber.js';
|
|
10
14
|
profileMark('module:sql');
|
|
11
|
-
function sqlAnalysisDialectForDriver(driver) {
|
|
12
|
-
const normalized = String(driver ?? '').trim().toLowerCase();
|
|
13
|
-
const map = {
|
|
14
|
-
postgres: 'postgres',
|
|
15
|
-
bigquery: 'bigquery',
|
|
16
|
-
snowflake: 'snowflake',
|
|
17
|
-
mysql: 'mysql',
|
|
18
|
-
sqlserver: 'tsql',
|
|
19
|
-
sqlite: 'sqlite',
|
|
20
|
-
clickhouse: 'clickhouse',
|
|
21
|
-
};
|
|
22
|
-
return map[normalized] ?? 'postgres';
|
|
23
|
-
}
|
|
24
15
|
function queryVerb(sql) {
|
|
25
16
|
const first = sql.trim().split(/\s+/, 1)[0]?.toLowerCase();
|
|
26
17
|
if (first === 'select' || first === 'explain' || first === 'show' || first === 'with') {
|
|
@@ -79,11 +70,6 @@ function printSqlResult(output, mode, io) {
|
|
|
79
70
|
}
|
|
80
71
|
printPretty(output, io);
|
|
81
72
|
}
|
|
82
|
-
async function cleanupConnector(connector) {
|
|
83
|
-
if (connector?.cleanup) {
|
|
84
|
-
await connector.cleanup();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
73
|
function resultOutput(connectionId, result) {
|
|
88
74
|
return {
|
|
89
75
|
connectionId,
|
|
@@ -100,12 +86,10 @@ export async function runKtxSql(args, io = process, deps = {}) {
|
|
|
100
86
|
let project;
|
|
101
87
|
try {
|
|
102
88
|
project = await (deps.loadProject ?? loadKtxProject)({ projectDir: args.projectDir });
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
driver = String(connection.driver ?? 'unknown').toLowerCase();
|
|
108
|
-
demoConnection = isDemoConnection(args.connectionId, connection);
|
|
89
|
+
const isFederated = args.connectionId === FEDERATED_CONNECTION_ID;
|
|
90
|
+
const connection = isFederated ? undefined : resolveConfiguredConnection(project.config, args.connectionId);
|
|
91
|
+
driver = isFederated ? 'duckdb' : String(connection?.driver ?? 'unknown').toLowerCase();
|
|
92
|
+
demoConnection = isFederated ? false : isDemoConnection(args.connectionId, connection);
|
|
109
93
|
const createSqlAnalysis = deps.createSqlAnalysis ??
|
|
110
94
|
(() => createManagedDaemonSqlAnalysisPort({
|
|
111
95
|
cliVersion: args.cliVersion,
|
|
@@ -114,44 +98,42 @@ export async function runKtxSql(args, io = process, deps = {}) {
|
|
|
114
98
|
io,
|
|
115
99
|
}));
|
|
116
100
|
const analysisPort = createSqlAnalysis();
|
|
117
|
-
const dialect = sqlAnalysisDialectForDriver(connection
|
|
101
|
+
const dialect = isFederated ? 'duckdb' : sqlAnalysisDialectForDriver(connection?.driver);
|
|
118
102
|
const validation = await analysisPort.validateReadOnly(args.sql, dialect);
|
|
119
103
|
if (!validation.ok) {
|
|
120
104
|
throw new Error(validation.error ?? 'SQL is not read-only.');
|
|
121
105
|
}
|
|
122
106
|
const referencedTableCount = await safeReferencedTableCount(analysisPort, args.sql, dialect);
|
|
123
107
|
const createScanConnector = deps.createScanConnector ?? createKtxCliScanConnector;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!connector.capabilities.readOnlySql || !connector.executeReadOnly) {
|
|
128
|
-
throw new Error(`Connection "${args.connectionId}" does not support read-only SQL execution.`);
|
|
129
|
-
}
|
|
130
|
-
const result = await connector.executeReadOnly({
|
|
108
|
+
const result = await executeProjectReadOnlySql({
|
|
109
|
+
project,
|
|
110
|
+
input: {
|
|
131
111
|
connectionId: args.connectionId,
|
|
112
|
+
projectDir: args.projectDir,
|
|
113
|
+
connection,
|
|
132
114
|
sql: args.sql,
|
|
133
115
|
maxRows: args.maxRows,
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
116
|
+
},
|
|
117
|
+
createConnector: (connectionId) => createScanConnector(project, connectionId),
|
|
118
|
+
executeFederated: deps.executeFederated,
|
|
119
|
+
runId: 'cli-sql',
|
|
120
|
+
});
|
|
121
|
+
const mode = resolveOutputMode({ explicit: args.output, json: args.json, io });
|
|
122
|
+
printSqlResult(resultOutput(args.connectionId, result), mode, io);
|
|
123
|
+
await emitTelemetryEvent({
|
|
124
|
+
name: 'sql_completed',
|
|
125
|
+
projectDir: args.projectDir,
|
|
126
|
+
io,
|
|
127
|
+
fields: {
|
|
128
|
+
driver,
|
|
129
|
+
isDemoConnection: demoConnection,
|
|
130
|
+
queryVerb: queryVerb(args.sql),
|
|
131
|
+
referencedTableCount,
|
|
132
|
+
durationMs: Math.max(0, performance.now() - startedAt),
|
|
133
|
+
outcome: 'ok',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
return 0;
|
|
155
137
|
}
|
|
156
138
|
catch (error) {
|
|
157
139
|
const errorClass = scrubErrorClass(error);
|
|
@@ -303,6 +303,7 @@ export declare const telemetryEventSchemas: {
|
|
|
303
303
|
}>;
|
|
304
304
|
durationMs: z.ZodNumber;
|
|
305
305
|
errorClass: z.ZodOptional<z.ZodString>;
|
|
306
|
+
errorDetail: z.ZodOptional<z.ZodString>;
|
|
306
307
|
sampleRate: z.ZodLiteral<1>;
|
|
307
308
|
mcpClientName: z.ZodOptional<z.ZodString>;
|
|
308
309
|
mcpClientVersion: z.ZodOptional<z.ZodString>;
|
|
@@ -459,7 +460,7 @@ export declare const telemetryEventCatalog: readonly [{
|
|
|
459
460
|
}, {
|
|
460
461
|
readonly name: "mcp_request_completed";
|
|
461
462
|
readonly description: "Emitted for sampled MCP tool requests.";
|
|
462
|
-
readonly fields: readonly ["toolName", "outcome", "durationMs", "errorClass", "sampleRate", "mcpClientName", "mcpClientVersion"];
|
|
463
|
+
readonly fields: readonly ["toolName", "outcome", "durationMs", "errorClass", "errorDetail", "sampleRate", "mcpClientName", "mcpClientVersion"];
|
|
463
464
|
}, {
|
|
464
465
|
readonly name: "daemon_started";
|
|
465
466
|
readonly description: "Emitted when the long-lived ktx-daemon HTTP server starts.";
|
package/dist/telemetry/events.js
CHANGED
|
@@ -145,6 +145,7 @@ const mcpRequestCompletedSchema = telemetryCommonEnvelopeSchema
|
|
|
145
145
|
outcome: outcomeSchema,
|
|
146
146
|
durationMs: z.number().nonnegative(),
|
|
147
147
|
errorClass: z.string().optional(),
|
|
148
|
+
errorDetail: z.string().max(1000).optional(),
|
|
148
149
|
sampleRate: z.literal(1),
|
|
149
150
|
// Raw, client-tool-controlled identity from the MCP initialize handshake
|
|
150
151
|
// (clientInfo.name/version). Optional: clients may omit clientInfo. Stored
|
|
@@ -326,7 +327,16 @@ export const telemetryEventCatalog = [
|
|
|
326
327
|
{
|
|
327
328
|
name: 'mcp_request_completed',
|
|
328
329
|
description: 'Emitted for sampled MCP tool requests.',
|
|
329
|
-
fields: [
|
|
330
|
+
fields: [
|
|
331
|
+
'toolName',
|
|
332
|
+
'outcome',
|
|
333
|
+
'durationMs',
|
|
334
|
+
'errorClass',
|
|
335
|
+
'errorDetail',
|
|
336
|
+
'sampleRate',
|
|
337
|
+
'mcpClientName',
|
|
338
|
+
'mcpClientVersion',
|
|
339
|
+
],
|
|
330
340
|
},
|
|
331
341
|
{
|
|
332
342
|
name: 'daemon_started',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaelio/ktx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Standalone ktx context layer for data agents",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Kaelio",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@clack/prompts": "1.4.0",
|
|
41
41
|
"@clickhouse/client": "^1.18.5",
|
|
42
42
|
"@commander-js/extra-typings": "14.0.0",
|
|
43
|
+
"@duckdb/node-api": "1.5.3-r.3",
|
|
43
44
|
"@google-cloud/bigquery": "^8.3.1",
|
|
44
45
|
"@looker/sdk": "^26.8.0",
|
|
45
46
|
"@looker/sdk-node": "^26.8.0",
|