@outsidedata/dolex 8.1.0 → 9.0.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.
Files changed (55) hide show
  1. package/README.md +30 -7
  2. package/dist/src/analysis/planner.d.ts +2 -1
  3. package/dist/src/analysis/planner.js +2 -2
  4. package/dist/src/analysis/quality.js +96 -5
  5. package/dist/src/analysis/rules.d.ts +22 -2
  6. package/dist/src/analysis/rules.js +64 -23
  7. package/dist/src/cleaning/index.d.ts +2 -6
  8. package/dist/src/cleaning/index.js +8 -3
  9. package/dist/src/cleaning/replay.d.ts +34 -0
  10. package/dist/src/cleaning/replay.js +58 -0
  11. package/dist/src/cli/commands/analyze.js +13 -1
  12. package/dist/src/cli/commands/clean.js +15 -3
  13. package/dist/src/cli/commands/deps.d.ts +1 -0
  14. package/dist/src/cli/commands/deps.js +41 -0
  15. package/dist/src/cli/commands/help.js +2 -1
  16. package/dist/src/cli/commands/sources.d.ts +2 -2
  17. package/dist/src/cli/commands/sources.js +138 -12
  18. package/dist/src/cli/commands/transform.js +19 -4
  19. package/dist/src/cli/index.js +3 -0
  20. package/dist/src/connectors/csv.js +29 -0
  21. package/dist/src/connectors/index.d.ts +2 -0
  22. package/dist/src/connectors/index.js +2 -0
  23. package/dist/src/connectors/manager.d.ts +39 -1
  24. package/dist/src/connectors/manager.js +142 -15
  25. package/dist/src/connectors/mongo/index.d.ts +13 -0
  26. package/dist/src/connectors/mongo/index.js +323 -0
  27. package/dist/src/connectors/pg/index.d.ts +2 -0
  28. package/dist/src/connectors/pg/index.js +248 -0
  29. package/dist/src/connectors/source-factory.d.ts +38 -0
  30. package/dist/src/connectors/source-factory.js +80 -0
  31. package/dist/src/connectors/sql-safety.js +3 -3
  32. package/dist/src/connectors/types.d.ts +51 -0
  33. package/dist/src/connectors/types.js +11 -1
  34. package/dist/src/mcp/index.d.ts +1 -1
  35. package/dist/src/mcp/index.js +20 -9
  36. package/dist/src/mcp/tools/analyze.js +11 -1
  37. package/dist/src/mcp/tools/capabilities.d.ts +1 -0
  38. package/dist/src/mcp/tools/capabilities.js +14 -0
  39. package/dist/src/mcp/tools/clean-column.js +2 -0
  40. package/dist/src/mcp/tools/drop-columns.js +2 -0
  41. package/dist/src/mcp/tools/list-transforms.js +22 -0
  42. package/dist/src/mcp/tools/promote-columns.js +2 -0
  43. package/dist/src/mcp/tools/refine-cli.d.ts +4 -4
  44. package/dist/src/mcp/tools/refine.d.ts +4 -4
  45. package/dist/src/mcp/tools/shared.d.ts +5 -0
  46. package/dist/src/mcp/tools/shared.js +11 -4
  47. package/dist/src/mcp/tools/sources.d.ts +46 -3
  48. package/dist/src/mcp/tools/sources.js +44 -4
  49. package/dist/src/mcp/tools/transform-data.js +22 -0
  50. package/dist/src/types.d.ts +29 -2
  51. package/dist/src/utils/capabilities.d.ts +28 -0
  52. package/dist/src/utils/capabilities.js +58 -0
  53. package/dist/src/utils/optional-deps.d.ts +8 -0
  54. package/dist/src/utils/optional-deps.js +8 -0
  55. package/package.json +5 -2
@@ -6,6 +6,28 @@ export function handleListTransforms(deps) {
6
6
  const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
7
7
  if (isTransformError(ctx))
8
8
  return ctx;
9
+ // Live sources (Postgres/Mongo) have no SQLite handle. Their derived columns are
10
+ // session-local (created via transform_data) and surface in the introspected schema
11
+ // tagged layer:'derived'. List those from the schema instead of dereferencing a null
12
+ // db handle (which previously threw "Cannot read properties of undefined").
13
+ if (!ctx.db) {
14
+ const schema = await ctx.source.getSchema();
15
+ const tbl = schema.tables.find((t) => t.name === args.table);
16
+ const cols = tbl?.columns ?? [];
17
+ const derived = cols.filter((c) => c.layer === 'derived');
18
+ const sourceCols = cols.filter((c) => c.layer !== 'derived');
19
+ return jsonResponse({
20
+ source_columns: sourceCols.map((c) => c.name),
21
+ derived_columns: derived.map((c) => ({
22
+ column: c.name,
23
+ layer: 'derived',
24
+ note: 'session-local (created via transform_data); expression not tracked on a live source',
25
+ })),
26
+ working_columns: [],
27
+ total_columns: cols.length,
28
+ note: `Live ${ctx.source.type} source — derived columns are session-local to this connection and are not persisted (no working layer or manifest). Recreate them with transform_data.`,
29
+ });
30
+ }
9
31
  const metadata = new TransformMetadata(ctx.db);
10
32
  metadata.init();
11
33
  const mgr = new ColumnManager(ctx.db);
@@ -6,6 +6,8 @@ export function handlePromoteColumns(deps) {
6
6
  const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
7
7
  if (isTransformError(ctx))
8
8
  return ctx;
9
+ if (!ctx.db)
10
+ return errorResponse(`promote_columns persists derived columns to a CSV-side manifest. On a live ${ctx.source.type} source, derived columns are session-local (created with transform_data) and are not persisted — nothing to promote.`);
9
11
  const metadata = new TransformMetadata(ctx.db);
10
12
  metadata.init();
11
13
  let columnsToPromote;
@@ -90,7 +90,7 @@ export declare const refineCliInputSchema: z.ZodObject<{
90
90
  direction: "asc" | "desc";
91
91
  field?: string | undefined;
92
92
  } | null | undefined;
93
- format?: "compact" | "integer" | "percent" | "dollar" | "decimal" | undefined;
93
+ format?: "compact" | "integer" | "decimal" | "percent" | "dollar" | undefined;
94
94
  colorField?: string | undefined;
95
95
  palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
96
96
  filter?: {
@@ -98,9 +98,9 @@ export declare const refineCliInputSchema: z.ZodObject<{
98
98
  values: (string | number)[];
99
99
  op: "in" | "not_in" | "gt" | "gte" | "lt" | "lte";
100
100
  }[] | undefined;
101
+ limit?: number | undefined;
101
102
  layout?: "rows" | "columns" | undefined;
102
103
  subtitle?: string | undefined;
103
- limit?: number | undefined;
104
104
  flip?: boolean | undefined;
105
105
  xLabel?: string | undefined;
106
106
  yLabel?: string | undefined;
@@ -122,7 +122,7 @@ export declare const refineCliInputSchema: z.ZodObject<{
122
122
  direction: "asc" | "desc";
123
123
  field?: string | undefined;
124
124
  } | null | undefined;
125
- format?: "compact" | "integer" | "percent" | "dollar" | "decimal" | undefined;
125
+ format?: "compact" | "integer" | "decimal" | "percent" | "dollar" | undefined;
126
126
  colorField?: string | undefined;
127
127
  palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
128
128
  filter?: {
@@ -130,9 +130,9 @@ export declare const refineCliInputSchema: z.ZodObject<{
130
130
  values: (string | number)[];
131
131
  op?: "=" | "!=" | "in" | "not_in" | "gt" | "gte" | "lt" | "lte" | undefined;
132
132
  }[] | undefined;
133
+ limit?: number | undefined;
133
134
  layout?: "rows" | "columns" | undefined;
134
135
  subtitle?: string | undefined;
135
- limit?: number | undefined;
136
136
  flip?: boolean | undefined;
137
137
  xLabel?: string | undefined;
138
138
  yLabel?: string | undefined;
@@ -77,7 +77,7 @@ export declare const refineInputSchema: z.ZodObject<{
77
77
  direction: "asc" | "desc";
78
78
  field?: string | undefined;
79
79
  } | null | undefined;
80
- format?: "compact" | "integer" | "percent" | "dollar" | "decimal" | undefined;
80
+ format?: "compact" | "integer" | "decimal" | "percent" | "dollar" | undefined;
81
81
  colorField?: string | undefined;
82
82
  palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
83
83
  filter?: {
@@ -85,9 +85,9 @@ export declare const refineInputSchema: z.ZodObject<{
85
85
  values: (string | number)[];
86
86
  op: "in" | "not_in" | "gt" | "gte" | "lt" | "lte";
87
87
  }[] | undefined;
88
+ limit?: number | undefined;
88
89
  layout?: "rows" | "columns" | undefined;
89
90
  subtitle?: string | undefined;
90
- limit?: number | undefined;
91
91
  flip?: boolean | undefined;
92
92
  xLabel?: string | undefined;
93
93
  yLabel?: string | undefined;
@@ -108,7 +108,7 @@ export declare const refineInputSchema: z.ZodObject<{
108
108
  direction: "asc" | "desc";
109
109
  field?: string | undefined;
110
110
  } | null | undefined;
111
- format?: "compact" | "integer" | "percent" | "dollar" | "decimal" | undefined;
111
+ format?: "compact" | "integer" | "decimal" | "percent" | "dollar" | undefined;
112
112
  colorField?: string | undefined;
113
113
  palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
114
114
  filter?: {
@@ -116,9 +116,9 @@ export declare const refineInputSchema: z.ZodObject<{
116
116
  values: (string | number)[];
117
117
  op?: "=" | "!=" | "in" | "not_in" | "gt" | "gte" | "lt" | "lte" | undefined;
118
118
  }[] | undefined;
119
+ limit?: number | undefined;
119
120
  layout?: "rows" | "columns" | undefined;
120
121
  subtitle?: string | undefined;
121
- limit?: number | undefined;
122
122
  flip?: boolean | undefined;
123
123
  xLabel?: string | undefined;
124
124
  yLabel?: string | undefined;
@@ -7,6 +7,7 @@
7
7
  * - Color preference application to visualization specs
8
8
  */
9
9
  import type { DataColumn, VisualizationSpec, CompoundVisualizationSpec } from '../../types.js';
10
+ import type { DerivationCapabilities } from '../../connectors/types.js';
10
11
  type McpTextContent = {
11
12
  type: 'text';
12
13
  text: string;
@@ -80,8 +81,12 @@ export declare function resolveData(args: {
80
81
  export declare function isErrorResponse(result: ResolvedData | McpResponse): result is McpResponse;
81
82
  export interface TransformContext {
82
83
  source: any;
84
+ /** The raw SQLite handle — present only for the CSV/sqlite-alter materialization; undefined for
85
+ * a live source (PG/Mongo), which materializes via `source.applyDerivation`. */
83
86
  db: any;
84
87
  table: any;
88
+ /** The source's declared derivation contract (materialization / rowKey / server-side-queryable). */
89
+ caps: DerivationCapabilities;
85
90
  }
86
91
  /**
87
92
  * Shared setup for all transform tools: connect to source, get database handle,
@@ -240,10 +240,17 @@ export async function connectAndValidateTable(deps, sourceId, tableName) {
240
240
  return errorResponse(`Source not found: ${sourceId}`);
241
241
  }
242
242
  const source = connResult.source;
243
- const db = source.getDatabase?.();
244
- if (!db) {
245
- return errorResponse('Source does not support transforms (no database handle)');
243
+ // Source-agnostic derivation gate: the connector DECLARES whether/how it can derive a column
244
+ // (no longer a getDatabase-truthiness probe). A source that doesn't implement the seam is treated
245
+ // as non-deriving.
246
+ const caps = source.derivationCapabilities?.() ?? { canDerive: false, materialization: 'none', rowKey: null, serverSideQueryable: false };
247
+ if (!caps.canDerive) {
248
+ return errorResponse('Source does not support transforms');
246
249
  }
250
+ // CSV/sqlite-alter exposes a raw SQLite handle for the ALTER+rowid work; a live source (PG/Mongo)
251
+ // has no handle and materializes via source.applyDerivation. db may be undefined — each tool guards
252
+ // on what it needs (transform_data handles both; promote/drop/clean require the SQLite handle).
253
+ const db = source.getDatabase?.();
247
254
  let schema;
248
255
  try {
249
256
  schema = await source.getSchema();
@@ -256,7 +263,7 @@ export async function connectAndValidateTable(deps, sourceId, tableName) {
256
263
  const available = schema.tables.map((t) => t.name);
257
264
  return errorResponse(`Table '${tableName}' not found. Available: [${available.join(', ')}]`);
258
265
  }
259
- return { source, db, table };
266
+ return { source, db, table, caps };
260
267
  }
261
268
  /** Type guard: checks if a connectAndValidateTable result is an error response. */
262
269
  export function isTransformError(result) {
@@ -6,13 +6,43 @@ import { z } from 'zod';
6
6
  export declare function isSandboxPath(filePath: string): boolean;
7
7
  export declare const addSourceInputSchema: z.ZodObject<{
8
8
  name: z.ZodString;
9
- path: z.ZodString;
9
+ type: z.ZodOptional<z.ZodEnum<["csv", "postgres", "mongodb"]>>;
10
+ path: z.ZodOptional<z.ZodString>;
11
+ uri: z.ZodOptional<z.ZodString>;
12
+ host: z.ZodOptional<z.ZodString>;
13
+ port: z.ZodOptional<z.ZodNumber>;
14
+ database: z.ZodOptional<z.ZodString>;
15
+ user: z.ZodOptional<z.ZodString>;
16
+ password: z.ZodOptional<z.ZodString>;
17
+ passwordEnv: z.ZodOptional<z.ZodString>;
18
+ schema: z.ZodOptional<z.ZodString>;
19
+ collections: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
10
20
  }, "strip", z.ZodTypeAny, {
11
21
  name: string;
12
- path: string;
22
+ type?: "csv" | "postgres" | "mongodb" | undefined;
23
+ path?: string | undefined;
24
+ host?: string | undefined;
25
+ port?: number | undefined;
26
+ database?: string | undefined;
27
+ user?: string | undefined;
28
+ password?: string | undefined;
29
+ passwordEnv?: string | undefined;
30
+ schema?: string | undefined;
31
+ uri?: string | undefined;
32
+ collections?: string[] | undefined;
13
33
  }, {
14
34
  name: string;
15
- path: string;
35
+ type?: "csv" | "postgres" | "mongodb" | undefined;
36
+ path?: string | undefined;
37
+ host?: string | undefined;
38
+ port?: number | undefined;
39
+ database?: string | undefined;
40
+ user?: string | undefined;
41
+ password?: string | undefined;
42
+ passwordEnv?: string | undefined;
43
+ schema?: string | undefined;
44
+ uri?: string | undefined;
45
+ collections?: string[] | undefined;
16
46
  }>;
17
47
  export declare const removeSourceInputSchema: z.ZodObject<{
18
48
  sourceId: z.ZodString;
@@ -37,6 +67,19 @@ export declare const describeSourceInputSchema: z.ZodObject<{
37
67
  export declare function handleListSources(deps: {
38
68
  sourceManager: any;
39
69
  }): () => Promise<import("./shared.js").McpResponse>;
70
+ export declare const testSourceInputSchema: z.ZodObject<{
71
+ sourceId: z.ZodString;
72
+ }, "strip", z.ZodTypeAny, {
73
+ sourceId: string;
74
+ }, {
75
+ sourceId: string;
76
+ }>;
77
+ /** Connectivity health-check for a registered source — is the saved DB reachable with its credentials?
78
+ * Returns a classified kind (unreachable / auth-failed / db-not-found / driver-missing / …) so the
79
+ * assistant can give the user a specific fix, and repair via load_source (re-register) if needed. */
80
+ export declare function handleTestSource(deps: {
81
+ sourceManager: any;
82
+ }): (args: z.infer<typeof testSourceInputSchema>) => Promise<import("./shared.js").McpResponse>;
40
83
  export declare function handleAddSource(deps: {
41
84
  sourceManager: any;
42
85
  }): (args: z.infer<typeof addSourceInputSchema>) => Promise<import("./shared.js").McpResponse>;
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { z } from 'zod';
6
6
  import { errorResponse, jsonResponse } from './shared.js';
7
+ import { resolveSourceConfig } from '../../connectors/source-factory.js';
7
8
  const SANDBOX_PATH_PATTERNS = [
8
9
  /^\/mnt\/user-data\//,
9
10
  /^\/home\/claude\//,
@@ -15,7 +16,17 @@ export function isSandboxPath(filePath) {
15
16
  }
16
17
  export const addSourceInputSchema = z.object({
17
18
  name: z.string().describe('Name for this dataset'),
18
- path: z.string().describe('Path to a CSV file or directory of CSV files'),
19
+ type: z.enum(['csv', 'postgres', 'mongodb']).optional().describe('Source type (default: csv)'),
20
+ path: z.string().optional().describe('CSV: path to a .csv file or directory of CSV files'),
21
+ uri: z.string().optional().describe('Postgres libpq connection string, or MongoDB connection URI'),
22
+ host: z.string().optional().describe('DB host (postgres/mongodb) if not using uri'),
23
+ port: z.number().optional().describe('DB port'),
24
+ database: z.string().optional().describe('Database name (postgres discrete / mongodb — required for mongo)'),
25
+ user: z.string().optional().describe('Postgres user'),
26
+ password: z.string().optional().describe('Postgres password (stored in plaintext — prefer passwordEnv)'),
27
+ passwordEnv: z.string().optional().describe('Name of an env var holding the Postgres password (e.g. "PGPASSWORD"); keeps the secret out of the saved config'),
28
+ schema: z.string().optional().describe('Postgres schema to introspect (default: public)'),
29
+ collections: z.array(z.string()).optional().describe('MongoDB: restrict to these collections'),
19
30
  });
20
31
  export const removeSourceInputSchema = z.object({
21
32
  sourceId: z.string().describe('Dataset ID returned by load_csv'),
@@ -109,14 +120,33 @@ function buildSmartSummary(t) {
109
120
  export function handleListSources(deps) {
110
121
  return async () => jsonResponse(deps.sourceManager.list());
111
122
  }
123
+ export const testSourceInputSchema = z.object({
124
+ sourceId: z.string().describe('Source id or name to health-check'),
125
+ });
126
+ /** Connectivity health-check for a registered source — is the saved DB reachable with its credentials?
127
+ * Returns a classified kind (unreachable / auth-failed / db-not-found / driver-missing / …) so the
128
+ * assistant can give the user a specific fix, and repair via load_source (re-register) if needed. */
129
+ export function handleTestSource(deps) {
130
+ return async (args) => jsonResponse(await deps.sourceManager.testSource(args.sourceId));
131
+ }
112
132
  export function handleAddSource(deps) {
113
133
  return async (args) => {
114
- if (isSandboxPath(args.path)) {
134
+ if (args.path && isSandboxPath(args.path)) {
115
135
  return errorResponse('This path looks like a cloud sandbox path, not a local filesystem path. '
116
136
  + 'Dolex runs on the user\'s machine and can access any local file — but not cloud sandbox uploads. '
117
137
  + 'Ask the user for the real local path (e.g. /Users/name/Downloads/data.csv).');
118
138
  }
119
- const config = { type: 'csv', path: args.path };
139
+ let config;
140
+ try {
141
+ config = resolveSourceConfig({
142
+ type: args.type, path: args.path, uri: args.uri, host: args.host, port: args.port,
143
+ database: args.database, user: args.user, password: args.password, passwordEnv: args.passwordEnv,
144
+ schema: args.schema, collections: args.collections,
145
+ });
146
+ }
147
+ catch (err) {
148
+ return errorResponse(err.message);
149
+ }
120
150
  let entry;
121
151
  let reconnected = false;
122
152
  const existing = deps.sourceManager.get(args.name);
@@ -137,9 +167,19 @@ export function handleAddSource(deps) {
137
167
  return errorResponse(err.message);
138
168
  }
139
169
  if (!addResult.ok || !addResult.entry) {
140
- return errorResponse(addResult.error ?? 'Failed to load CSV');
170
+ return errorResponse(addResult.error ?? 'Failed to load source');
141
171
  }
142
172
  entry = addResult.entry;
173
+ // Config-first: the source is registered even if the DB wasn't reachable just now. Don't try to
174
+ // profile it (that would fail); tell the assistant it's saved and how to get it live.
175
+ if (addResult.verified === false) {
176
+ return jsonResponse({
177
+ sourceId: entry.id, name: entry.name, type: entry.type, registered: true, reachable: false,
178
+ message: `Registered "${entry.name}", but couldn't connect yet: ${addResult.warning}. `
179
+ + `Once the database is reachable (start it / fix credentials — for a missing driver run the install command), it will work. `
180
+ + `Relay the reason to the user; no re-registration is needed.`,
181
+ });
182
+ }
143
183
  }
144
184
  const schemaResult = await deps.sourceManager.getSchema(entry.id);
145
185
  const schema = schemaResult.ok ? schemaResult.schema : null;
@@ -6,6 +6,28 @@ export function handleTransformData(deps) {
6
6
  const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
7
7
  if (isTransformError(ctx))
8
8
  return ctx;
9
+ // Live source (PG/Mongo): materialize each derived column via the connector (native expression
10
+ // → shadow view / $set), visible to later queries, base data untouched. No SQLite handle.
11
+ if (!ctx.db) {
12
+ if (typeof ctx.source.applyDerivation !== 'function') {
13
+ return errorResponse(`This source cannot materialize a derived column (materialization: ${ctx.caps.materialization}).`);
14
+ }
15
+ const items = args.transforms ?? (args.create && args.expr ? [{ create: args.create, expr: args.expr }] : []);
16
+ if (!items.length)
17
+ return errorResponse('Provide `create` + `expr`, or a `transforms` array.');
18
+ try {
19
+ for (const t of items)
20
+ await ctx.source.applyDerivation(args.table, t.create, t.expr);
21
+ ctx.source.invalidateSchema?.();
22
+ return jsonResponse({
23
+ created: items.map((t) => ({ column: t.create, expr: t.expr, layer: 'derived', materialization: ctx.caps.materialization })),
24
+ note: `Derived on the live ${ctx.source.type} source (${ctx.caps.materialization}); session-local, base data untouched.`,
25
+ });
26
+ }
27
+ catch (err) {
28
+ return errorResponse(err.message);
29
+ }
30
+ }
9
31
  const metadata = new TransformMetadata(ctx.db);
10
32
  metadata.init();
11
33
  const transformedNames = new Set(metadata.list(args.table).map(r => r.column));
@@ -57,19 +57,46 @@ export interface DataSchema {
57
57
  foreignKeys: ForeignKey[];
58
58
  source: DataSourceInfo;
59
59
  }
60
- export type DataSourceType = 'csv';
60
+ export type DataSourceType = 'csv' | 'postgres' | 'mongodb';
61
61
  export interface DataSourceInfo {
62
62
  id: string;
63
63
  type: DataSourceType;
64
64
  name: string;
65
65
  config: DataSourceConfig;
66
66
  }
67
- export type DataSourceConfig = CsvSourceConfig;
67
+ export type DataSourceConfig = CsvSourceConfig | PostgresSourceConfig | MongoSourceConfig;
68
68
  export interface CsvSourceConfig {
69
69
  type: 'csv';
70
70
  /** Directory containing CSV files, or path to a single CSV */
71
71
  path: string;
72
72
  }
73
+ export interface PostgresSourceConfig {
74
+ type: 'postgres';
75
+ /** libpq connection string, OR provide discrete fields below. */
76
+ connectionString?: string;
77
+ host?: string;
78
+ port?: number;
79
+ database?: string;
80
+ user?: string;
81
+ /** Literal password. Stored in the registry — prefer `passwordEnv` to keep the secret out of the file. */
82
+ password?: string;
83
+ /** Name of an environment variable holding the password (e.g. "PGPASSWORD"). The registry stores
84
+ * only this reference, not the secret; the password is read from the environment at connect time. */
85
+ passwordEnv?: string;
86
+ /** Postgres schema to introspect (default: public). */
87
+ schema?: string;
88
+ }
89
+ export interface MongoSourceConfig {
90
+ type: 'mongodb';
91
+ /** Mongo connection URI, OR provide discrete host/port below. */
92
+ uri?: string;
93
+ host?: string;
94
+ port?: number;
95
+ /** Database to introspect (required — a Mongo connection has no single default db). */
96
+ database: string;
97
+ /** Restrict to these collections; omitted ⇒ all collections in the database. */
98
+ collections?: string[];
99
+ }
73
100
  /** Filter operator (used by transform pipeline for client-side row filtering) */
74
101
  export type RowFilterOp = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not_in' | 'between' | 'is_null' | 'is_not_null';
75
102
  /** A filter condition (used by transform pipeline for client-side row filtering) */
@@ -0,0 +1,28 @@
1
+ export interface CapabilityDep {
2
+ package: string;
3
+ installed: boolean;
4
+ version?: string;
5
+ enables: string;
6
+ install?: string;
7
+ }
8
+ export interface CapabilitiesReport {
9
+ dolexVersion?: string;
10
+ node: string;
11
+ platform: string;
12
+ coreOk: boolean;
13
+ /** Per source type: 'ready' or an actionable 'needs: npm install …'. The agent's key question. */
14
+ sources: {
15
+ csv: string;
16
+ postgres: string;
17
+ mongodb: string;
18
+ };
19
+ deps: CapabilityDep[];
20
+ python: {
21
+ available: boolean;
22
+ version?: string;
23
+ enables: string;
24
+ install?: string;
25
+ };
26
+ }
27
+ /** Probe the current environment for optional capabilities. Pure of side effects; never throws. */
28
+ export declare function probeCapabilities(): CapabilitiesReport;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Environment capability probe — the single source of truth for "what can Dolex do in THIS
3
+ * install?". Shared by the `dolex deps` CLI command (human + --json) and the MCP `capabilities`
4
+ * tool (an AI agent asks once, then drives within what's available instead of trying-and-crashing).
5
+ *
6
+ * Presence is resolved WITHOUT loading the package (no side effects); a missing optional package is
7
+ * a fact to report, never a crash — the connectors themselves fail gracefully (importOptional).
8
+ */
9
+ import { createRequire } from 'module';
10
+ import { execFileSync } from 'child_process';
11
+ import { readFileSync } from 'fs';
12
+ import { OPTIONAL_FEATURES } from './optional-deps.js';
13
+ import { packagePath } from './package-root.js';
14
+ const require = createRequire(import.meta.url);
15
+ /** A package's version, resolved without loading it. `null` ⇒ not installed. */
16
+ function pkgVersion(spec) {
17
+ try {
18
+ return JSON.parse(readFileSync(require.resolve(`${spec}/package.json`), 'utf8')).version ?? null;
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ }
24
+ const PROBES = [
25
+ { key: 'postgres', spec: 'pg', enables: 'Postgres data sources' },
26
+ { key: 'mongodb', spec: 'mongodb', enables: 'MongoDB data sources' },
27
+ { key: 'png', spec: 'playwright', enables: 'PNG / screenshot export' },
28
+ { key: 'mcp', spec: '@modelcontextprotocol/sdk', enables: 'the MCP server (`dolex mcp`)' },
29
+ ];
30
+ /** Probe the current environment for optional capabilities. Pure of side effects; never throws. */
31
+ export function probeCapabilities() {
32
+ const coreOk = !!pkgVersion('better-sqlite3');
33
+ const deps = PROBES.map((p) => {
34
+ const version = pkgVersion(p.spec);
35
+ return { package: p.spec, installed: !!version, version: version ?? undefined, enables: p.enables, install: version ? undefined : OPTIONAL_FEATURES[p.key].install };
36
+ });
37
+ const has = (spec) => deps.find((d) => d.package === spec).installed;
38
+ let pyVersion;
39
+ try {
40
+ pyVersion = execFileSync('python3', ['--version'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
41
+ }
42
+ catch { /* absent */ }
43
+ const python = { available: !!pyVersion, version: pyVersion, enables: 'data cleaning (clean_column / dolex clean)', install: pyVersion ? undefined : 'install python3 and put it on PATH' };
44
+ let dolexVersion;
45
+ try {
46
+ dolexVersion = JSON.parse(readFileSync(packagePath('package.json'), 'utf8')).version;
47
+ }
48
+ catch { /* best-effort */ }
49
+ return {
50
+ dolexVersion, node: process.version, platform: process.platform, coreOk,
51
+ sources: {
52
+ csv: coreOk ? 'ready' : 'core missing — reinstall dolex',
53
+ postgres: has('pg') ? 'ready' : 'needs: npm install pg',
54
+ mongodb: has('mongodb') ? 'ready' : 'needs: npm install mongodb',
55
+ },
56
+ deps, python,
57
+ };
58
+ }
@@ -25,6 +25,14 @@ export declare const OPTIONAL_FEATURES: {
25
25
  readonly feature: "the MCP server (`dolex mcp`)";
26
26
  readonly install: "npm install @modelcontextprotocol/sdk @modelcontextprotocol/ext-apps";
27
27
  };
28
+ readonly postgres: {
29
+ readonly feature: "Postgres data sources";
30
+ readonly install: "npm install pg";
31
+ };
32
+ readonly mongodb: {
33
+ readonly feature: "MongoDB data sources";
34
+ readonly install: "npm install mongodb";
35
+ };
28
36
  };
29
37
  export type OptionalFeatureKey = keyof typeof OPTIONAL_FEATURES;
30
38
  /** Build the standard, agent-and-human friendly "install this" message. */
@@ -19,6 +19,14 @@ export const OPTIONAL_FEATURES = {
19
19
  feature: 'the MCP server (`dolex mcp`)',
20
20
  install: 'npm install @modelcontextprotocol/sdk @modelcontextprotocol/ext-apps',
21
21
  },
22
+ postgres: {
23
+ feature: 'Postgres data sources',
24
+ install: 'npm install pg',
25
+ },
26
+ mongodb: {
27
+ feature: 'MongoDB data sources',
28
+ install: 'npm install mongodb',
29
+ },
22
30
  };
23
31
  /** Build the standard, agent-and-human friendly "install this" message. */
24
32
  export function missingDependencyMessage(key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outsidedata/dolex",
3
- "version": "8.1.0",
3
+ "version": "9.0.0",
4
4
  "description": "Turn your AI assistant into a data analyst you can trust on your own CSV files — column profiling, data-quality auditing, a prioritized analysis plan, and findings rendered across 43 chart types.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -88,7 +88,9 @@
88
88
  "optionalDependencies": {
89
89
  "@modelcontextprotocol/ext-apps": "^1.0.1",
90
90
  "@modelcontextprotocol/sdk": "^1.26.0",
91
- "topojson-client": "^3.1.0"
91
+ "topojson-client": "^3.1.0",
92
+ "pg": "^8.22.0",
93
+ "mongodb": "^7.4.0"
92
94
  },
93
95
  "peerDependencies": {
94
96
  "react": ">=18",
@@ -110,6 +112,7 @@
110
112
  "@types/better-sqlite3": "^7.6.13",
111
113
  "@types/node": "^20",
112
114
  "@types/papaparse": "^5.3.16",
115
+ "@types/pg": "^8.20.0",
113
116
  "@types/react": "^19.2.13",
114
117
  "@types/react-dom": "^19.2.3",
115
118
  "@types/topojson-client": "^3.1.5",