@lightdash-tools/cli 0.2.6 → 0.3.1
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/README.md +72 -51
- package/dist/commands/agents.d.ts +11 -0
- package/dist/commands/agents.js +377 -0
- package/dist/commands/ai-agents.d.ts +2 -2
- package/dist/commands/ai-agents.js +68 -6
- package/dist/commands/content.js +2 -2
- package/dist/index.js +8 -2
- package/dist/utils/safety.d.ts +8 -1
- package/dist/utils/safety.js +87 -2
- package/package.json +3 -3
- package/src/commands/agents.ts +511 -0
- package/src/commands/ai-agents.ts +87 -9
- package/src/commands/content.ts +3 -3
- package/src/index.ts +11 -1
- package/src/utils/safety.ts +103 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* AI agents (v1) command implementation.
|
|
3
|
+
* AI agents (v1) command implementation — admin endpoints.
|
|
4
4
|
*/
|
|
5
5
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
6
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -17,13 +17,15 @@ const common_1 = require("@lightdash-tools/common");
|
|
|
17
17
|
const client_1 = require("../utils/client");
|
|
18
18
|
const safety_1 = require("../utils/safety");
|
|
19
19
|
/**
|
|
20
|
-
* Registers the top-level ai-agents command and its subcommands.
|
|
20
|
+
* Registers the top-level ai-agents command and its subcommands (admin scope).
|
|
21
21
|
*/
|
|
22
22
|
function registerAiAgentsCommand(program) {
|
|
23
|
-
const aiAgentsCmd = program
|
|
23
|
+
const aiAgentsCmd = program
|
|
24
|
+
.command('ai-agents')
|
|
25
|
+
.description('Manage AI agents — admin endpoints (cross-project)');
|
|
24
26
|
aiAgentsCmd
|
|
25
27
|
.command('list')
|
|
26
|
-
.description('List all AI agents (admin)')
|
|
28
|
+
.description('List all AI agents across the organization (admin)')
|
|
27
29
|
.action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, () => __awaiter(this, void 0, void 0, function* () {
|
|
28
30
|
try {
|
|
29
31
|
const client = (0, client_1.getClient)();
|
|
@@ -37,9 +39,22 @@ function registerAiAgentsCommand(program) {
|
|
|
37
39
|
})));
|
|
38
40
|
aiAgentsCmd
|
|
39
41
|
.command('threads')
|
|
40
|
-
.description('List AI agent threads (admin)')
|
|
42
|
+
.description('List AI agent threads across the organization (admin)')
|
|
41
43
|
.option('--page <number>', 'Page number', (v) => parseInt(v, 10))
|
|
42
44
|
.option('--page-size <number>', 'Page size', (v) => parseInt(v, 10))
|
|
45
|
+
.option('--agent <uuid>', 'Filter by agent UUID (repeatable)', (v, prev) => [
|
|
46
|
+
...(prev !== null && prev !== void 0 ? prev : []),
|
|
47
|
+
v,
|
|
48
|
+
])
|
|
49
|
+
.option('--project <uuid>', 'Filter by project UUID (repeatable)', (v, prev) => [
|
|
50
|
+
...(prev !== null && prev !== void 0 ? prev : []),
|
|
51
|
+
v,
|
|
52
|
+
])
|
|
53
|
+
.option('--human-score <number>', 'Filter by human score (-1, 0, or 1)', (v) => parseInt(v, 10))
|
|
54
|
+
.option('--date-from <date>', 'Start date filter (YYYY-MM-DD)')
|
|
55
|
+
.option('--date-to <date>', 'End date filter (YYYY-MM-DD)')
|
|
56
|
+
.option('--sort <field>', 'Sort field: createdAt | title')
|
|
57
|
+
.option('--sort-direction <dir>', 'Sort direction: asc | desc')
|
|
43
58
|
.action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, function () {
|
|
44
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
60
|
const options = this.opts();
|
|
@@ -50,6 +65,20 @@ function registerAiAgentsCommand(program) {
|
|
|
50
65
|
params.page = options.page;
|
|
51
66
|
if (options.pageSize != null)
|
|
52
67
|
params.pageSize = options.pageSize;
|
|
68
|
+
if (options.agent != null)
|
|
69
|
+
params.agentUuids = options.agent;
|
|
70
|
+
if (options.project != null)
|
|
71
|
+
params.projectUuids = options.project;
|
|
72
|
+
if (options.humanScore != null)
|
|
73
|
+
params.humanScore = options.humanScore;
|
|
74
|
+
if (options.dateFrom != null)
|
|
75
|
+
params.dateFrom = options.dateFrom;
|
|
76
|
+
if (options.dateTo != null)
|
|
77
|
+
params.dateTo = options.dateTo;
|
|
78
|
+
if (options.sort != null)
|
|
79
|
+
params.sortField = options.sort;
|
|
80
|
+
if (options.sortDirection != null)
|
|
81
|
+
params.sortDirection = options.sortDirection;
|
|
53
82
|
const result = yield client.v1.aiAgents.getAdminThreads(Object.keys(params).length > 0 ? params : undefined);
|
|
54
83
|
console.log(JSON.stringify(result, null, 2));
|
|
55
84
|
}
|
|
@@ -59,8 +88,11 @@ function registerAiAgentsCommand(program) {
|
|
|
59
88
|
}
|
|
60
89
|
});
|
|
61
90
|
}));
|
|
62
|
-
aiAgentsCmd
|
|
91
|
+
const settingsCmd = aiAgentsCmd
|
|
63
92
|
.command('settings')
|
|
93
|
+
.description('Manage AI organization settings');
|
|
94
|
+
settingsCmd
|
|
95
|
+
.command('get')
|
|
64
96
|
.description('Get AI organization settings')
|
|
65
97
|
.action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, () => __awaiter(this, void 0, void 0, function* () {
|
|
66
98
|
try {
|
|
@@ -73,4 +105,34 @@ function registerAiAgentsCommand(program) {
|
|
|
73
105
|
process.exit(1);
|
|
74
106
|
}
|
|
75
107
|
})));
|
|
108
|
+
settingsCmd
|
|
109
|
+
.command('update')
|
|
110
|
+
.description('Update AI organization settings')
|
|
111
|
+
.option('--ai-agents-visible <bool>', 'Show/hide AI agents feature (true|false)')
|
|
112
|
+
.action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, function () {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const options = this.opts();
|
|
115
|
+
const body = {};
|
|
116
|
+
if (options.aiAgentsVisible != null) {
|
|
117
|
+
if (options.aiAgentsVisible !== 'true' && options.aiAgentsVisible !== 'false') {
|
|
118
|
+
console.error(`Error: --ai-agents-visible must be 'true' or 'false', got: '${options.aiAgentsVisible}'`);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
body['aiAgentsVisible'] = options.aiAgentsVisible === 'true';
|
|
122
|
+
}
|
|
123
|
+
if (Object.keys(body).length === 0) {
|
|
124
|
+
console.error('Error: at least one option is required (e.g. --ai-agents-visible)');
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const client = (0, client_1.getClient)();
|
|
129
|
+
const result = yield client.v1.aiAgents.updateAiOrganizationSettings(body);
|
|
130
|
+
console.log(JSON.stringify(result, null, 2));
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('Error updating AI organization settings:', error instanceof Error ? error.message : String(error));
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}));
|
|
76
138
|
}
|
package/dist/commands/content.js
CHANGED
|
@@ -24,7 +24,7 @@ function registerContentCommand(program) {
|
|
|
24
24
|
contentCmd
|
|
25
25
|
.command('search <query>')
|
|
26
26
|
.description('Search project content (charts, dashboards, spaces)')
|
|
27
|
-
.option('--
|
|
27
|
+
.option('--projects <uuids...>', 'Filter by project UUIDs')
|
|
28
28
|
.option('--type <types...>', 'Filter by content types (chart, dashboard, space)')
|
|
29
29
|
.option('--page <number>', 'Page number', (v) => parseInt(v, 10))
|
|
30
30
|
.option('--page-size <number>', 'Page size', (v) => parseInt(v, 10))
|
|
@@ -33,7 +33,7 @@ function registerContentCommand(program) {
|
|
|
33
33
|
const client = (0, client_1.getClient)();
|
|
34
34
|
const result = yield client.v2.content.searchContent({
|
|
35
35
|
search: query,
|
|
36
|
-
projectUuids: options.
|
|
36
|
+
projectUuids: options.projects,
|
|
37
37
|
contentTypes: options.type,
|
|
38
38
|
page: options.page,
|
|
39
39
|
pageSize: options.pageSize,
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const commander_1 = require("commander");
|
|
8
|
+
const common_1 = require("@lightdash-tools/common");
|
|
8
9
|
const organization_1 = require("./commands/organization");
|
|
9
10
|
const organization_roles_1 = require("./commands/organization-roles");
|
|
10
11
|
const projects_1 = require("./commands/projects");
|
|
@@ -15,6 +16,7 @@ const space_access_1 = require("./commands/space-access");
|
|
|
15
16
|
const charts_1 = require("./commands/charts");
|
|
16
17
|
const dashboards_1 = require("./commands/dashboards");
|
|
17
18
|
const ai_agents_1 = require("./commands/ai-agents");
|
|
19
|
+
const agents_1 = require("./commands/agents");
|
|
18
20
|
const groups_1 = require("./commands/groups");
|
|
19
21
|
const users_1 = require("./commands/users");
|
|
20
22
|
const query_1 = require("./commands/query");
|
|
@@ -23,12 +25,15 @@ const metrics_1 = require("./commands/metrics");
|
|
|
23
25
|
const schedulers_1 = require("./commands/schedulers");
|
|
24
26
|
const tags_1 = require("./commands/tags");
|
|
25
27
|
const content_1 = require("./commands/content");
|
|
28
|
+
// Initialise audit log before any command runs (uses LIGHTDASH_AUDIT_LOG env var).
|
|
29
|
+
(0, common_1.initAuditLog)(process.env.LIGHTDASH_AUDIT_LOG);
|
|
26
30
|
const program = new commander_1.Command();
|
|
27
31
|
program
|
|
28
32
|
.name('lightdash-ai')
|
|
29
33
|
.description('CLI for Lightdash AI')
|
|
30
|
-
.version('0.
|
|
31
|
-
.option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'read-only')
|
|
34
|
+
.version('0.3.1')
|
|
35
|
+
.option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'read-only')
|
|
36
|
+
.option('--projects <uuids>', 'Comma-separated list of allowed project UUIDs (security guardrail)');
|
|
32
37
|
// Register all commands (organization and projects first so subcommands can attach)
|
|
33
38
|
(0, organization_1.registerOrganizationCommand)(program);
|
|
34
39
|
(0, organization_roles_1.registerOrganizationRolesCommand)(program);
|
|
@@ -40,6 +45,7 @@ program
|
|
|
40
45
|
(0, charts_1.registerChartsCommand)(program);
|
|
41
46
|
(0, dashboards_1.registerDashboardsCommand)(program);
|
|
42
47
|
(0, ai_agents_1.registerAiAgentsCommand)(program);
|
|
48
|
+
(0, agents_1.registerAgentsCommand)(program);
|
|
43
49
|
(0, groups_1.registerGroupsCommand)(program);
|
|
44
50
|
(0, users_1.registerUsersCommand)(program);
|
|
45
51
|
(0, query_1.registerQueryCommand)(program);
|
package/dist/utils/safety.d.ts
CHANGED
|
@@ -3,9 +3,16 @@ import type { ToolAnnotations } from '@lightdash-tools/common';
|
|
|
3
3
|
import type { Command } from 'commander';
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the safety mode from the command line options or environment variables.
|
|
6
|
+
* CLI --safety-mode takes priority over LIGHTDASH_TOOL_SAFETY_MODE.
|
|
6
7
|
*/
|
|
7
8
|
export declare function getSafetyMode(cmd: Command): SafetyMode;
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* Resolves the allowed project UUIDs from the command line options or environment variables.
|
|
11
|
+
* We specifically want the root --projects flag as the security guardrail.
|
|
12
|
+
* CLI root flags take priority over LIGHTDASH_TOOLS_ALLOWED_PROJECTS.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAllowedProjects(cmd: Command): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Wraps a CLI action with safety-mode enforcement and audit logging.
|
|
10
17
|
*/
|
|
11
18
|
export declare function wrapAction<T extends unknown[]>(annotations: ToolAnnotations, action: (...args: T) => Promise<void> | void): (this: Command, ...args: T) => Promise<void>;
|
package/dist/utils/safety.js
CHANGED
|
@@ -10,10 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getSafetyMode = getSafetyMode;
|
|
13
|
+
exports.getAllowedProjects = getAllowedProjects;
|
|
13
14
|
exports.wrapAction = wrapAction;
|
|
14
15
|
const common_1 = require("@lightdash-tools/common");
|
|
15
16
|
/**
|
|
16
17
|
* Resolves the safety mode from the command line options or environment variables.
|
|
18
|
+
* CLI --safety-mode takes priority over LIGHTDASH_TOOL_SAFETY_MODE.
|
|
17
19
|
*/
|
|
18
20
|
function getSafetyMode(cmd) {
|
|
19
21
|
const options = cmd.optsWithGlobals();
|
|
@@ -23,17 +25,100 @@ function getSafetyMode(cmd) {
|
|
|
23
25
|
return (0, common_1.getSafetyModeFromEnv)();
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
28
|
+
* Resolves the allowed project UUIDs from the command line options or environment variables.
|
|
29
|
+
* We specifically want the root --projects flag as the security guardrail.
|
|
30
|
+
* CLI root flags take priority over LIGHTDASH_TOOLS_ALLOWED_PROJECTS.
|
|
31
|
+
*/
|
|
32
|
+
function getAllowedProjects(cmd) {
|
|
33
|
+
let root = cmd;
|
|
34
|
+
while (root.parent) {
|
|
35
|
+
root = root.parent;
|
|
36
|
+
}
|
|
37
|
+
const options = root.opts();
|
|
38
|
+
const raw = options.projects;
|
|
39
|
+
if (raw) {
|
|
40
|
+
return raw
|
|
41
|
+
.split(',')
|
|
42
|
+
.map((s) => s.trim())
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
}
|
|
45
|
+
return (0, common_1.getAllowedProjectUuidsFromEnv)();
|
|
46
|
+
}
|
|
47
|
+
/** Builds a human-readable command path (e.g. "lightdash-ai charts list"). */
|
|
48
|
+
function getCommandPath(cmd) {
|
|
49
|
+
const parts = [];
|
|
50
|
+
let current = cmd;
|
|
51
|
+
while (current) {
|
|
52
|
+
const n = current.name();
|
|
53
|
+
if (n)
|
|
54
|
+
parts.unshift(n);
|
|
55
|
+
current = current.parent;
|
|
56
|
+
}
|
|
57
|
+
return parts.join(' ');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Wraps a CLI action with safety-mode enforcement and audit logging.
|
|
27
61
|
*/
|
|
28
62
|
function wrapAction(annotations, action) {
|
|
29
63
|
return function (...args) {
|
|
30
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const start = Date.now();
|
|
66
|
+
const commandPath = getCommandPath(this);
|
|
31
67
|
const mode = getSafetyMode(this);
|
|
68
|
+
const allowedProjects = getAllowedProjects(this);
|
|
69
|
+
const targetProjects = (0, common_1.extractProjectUuids)(args);
|
|
70
|
+
// ── Safety Mode Enforcement ──────────────────────────────────────────────
|
|
32
71
|
if (!(0, common_1.isAllowed)(mode, annotations)) {
|
|
72
|
+
(0, common_1.logAuditEntry)({
|
|
73
|
+
timestamp: new Date().toISOString(),
|
|
74
|
+
sessionId: (0, common_1.getSessionId)(),
|
|
75
|
+
tool: commandPath,
|
|
76
|
+
projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
|
|
77
|
+
status: 'blocked',
|
|
78
|
+
durationMs: Date.now() - start,
|
|
79
|
+
});
|
|
33
80
|
console.error(`Error: This command is disabled in ${mode} mode. To enable it, use --safety-mode or set LIGHTDASH_TOOL_SAFETY_MODE.`);
|
|
34
81
|
process.exit(1);
|
|
35
82
|
}
|
|
36
|
-
|
|
83
|
+
// ── Project Guardrail Enforcement ────────────────────────────────────────
|
|
84
|
+
if (allowedProjects.length > 0) {
|
|
85
|
+
const deniedProjects = targetProjects.filter((p) => !(0, common_1.areAllProjectsAllowed)(allowedProjects, [p]));
|
|
86
|
+
if (deniedProjects.length > 0) {
|
|
87
|
+
(0, common_1.logAuditEntry)({
|
|
88
|
+
timestamp: new Date().toISOString(),
|
|
89
|
+
sessionId: (0, common_1.getSessionId)(),
|
|
90
|
+
tool: commandPath,
|
|
91
|
+
projectUuids: targetProjects,
|
|
92
|
+
status: 'blocked',
|
|
93
|
+
durationMs: Date.now() - start,
|
|
94
|
+
});
|
|
95
|
+
console.error(`Error: Project(s) [${deniedProjects.join(', ')}] are not in the list of allowed projects. Allowed: [${allowedProjects.join(', ')}].`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const result = yield action.apply(this, args);
|
|
101
|
+
(0, common_1.logAuditEntry)({
|
|
102
|
+
timestamp: new Date().toISOString(),
|
|
103
|
+
sessionId: (0, common_1.getSessionId)(),
|
|
104
|
+
tool: commandPath,
|
|
105
|
+
projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
|
|
106
|
+
status: 'success',
|
|
107
|
+
durationMs: Date.now() - start,
|
|
108
|
+
});
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
(0, common_1.logAuditEntry)({
|
|
113
|
+
timestamp: new Date().toISOString(),
|
|
114
|
+
sessionId: (0, common_1.getSessionId)(),
|
|
115
|
+
tool: commandPath,
|
|
116
|
+
projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
|
|
117
|
+
status: 'error',
|
|
118
|
+
durationMs: Date.now() - start,
|
|
119
|
+
});
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
37
122
|
});
|
|
38
123
|
};
|
|
39
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "CLI for Lightdash AI.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"commander": "^14.0.3",
|
|
15
|
-
"@lightdash-tools/client": "0.
|
|
16
|
-
"@lightdash-tools/common": "0.
|
|
15
|
+
"@lightdash-tools/client": "0.3.1",
|
|
16
|
+
"@lightdash-tools/common": "0.3.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^25.2.3"
|