@lightdash-tools/cli 0.20.0 → 0.22.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/dist/commands/agentops.test.js +81 -0
- package/dist/commands/agents-crud.js +5 -4
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/commands/agentops.test.ts +85 -0
- package/src/commands/agents-crud.ts +18 -10
- package/src/index.ts +1 -1
|
@@ -258,6 +258,87 @@ spec:
|
|
|
258
258
|
(0, vitest_1.expect)(diff.summary.updates).toBe(0);
|
|
259
259
|
(0, vitest_1.expect)(diff.summary.noops).toBe(1);
|
|
260
260
|
});
|
|
261
|
+
(0, vitest_1.it)('detects drift when bundle sets enableContentTools', () => {
|
|
262
|
+
var _a, _b, _c;
|
|
263
|
+
const bundleWithContentTools = (0, common_1.parseLightdashAiAgentBundle)(`
|
|
264
|
+
apiVersion: lightdash.ai/v1alpha1
|
|
265
|
+
kind: LightdashAiAgentBundle
|
|
266
|
+
metadata:
|
|
267
|
+
name: sales-bundle
|
|
268
|
+
spec:
|
|
269
|
+
projectUuid: ${PROJECT_UUID}
|
|
270
|
+
agents:
|
|
271
|
+
- key: sales
|
|
272
|
+
uuid: ${AGENT_UUID}
|
|
273
|
+
name: Sales Agent
|
|
274
|
+
instruction: Help with sales
|
|
275
|
+
enableContentTools: true
|
|
276
|
+
evaluations: []
|
|
277
|
+
`);
|
|
278
|
+
const current = {
|
|
279
|
+
projectUuid: PROJECT_UUID,
|
|
280
|
+
agents: [
|
|
281
|
+
{
|
|
282
|
+
agent: {
|
|
283
|
+
uuid: AGENT_UUID,
|
|
284
|
+
name: 'Sales Agent',
|
|
285
|
+
description: null,
|
|
286
|
+
instruction: 'Help with sales',
|
|
287
|
+
tags: null,
|
|
288
|
+
enableContentTools: false,
|
|
289
|
+
},
|
|
290
|
+
evaluations: [],
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
};
|
|
294
|
+
const diff = (0, common_1.computeBundleDiff)(bundleWithContentTools, current);
|
|
295
|
+
(0, vitest_1.expect)(diff.summary.updates).toBe(1);
|
|
296
|
+
(0, vitest_1.expect)((_a = diff.changes[0]) === null || _a === void 0 ? void 0 : _a.operation).toBe('update');
|
|
297
|
+
(0, vitest_1.expect)((_c = (_b = diff.changes[0]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c.enableContentTools).toEqual({ from: false, to: true });
|
|
298
|
+
});
|
|
299
|
+
(0, vitest_1.it)('detects spaceAccess-only bundle drift as update', () => {
|
|
300
|
+
var _a, _b, _c;
|
|
301
|
+
const spaceUuid = '00000000-0000-4000-8000-000000000040';
|
|
302
|
+
const bundleWithSpaceAccess = (0, common_1.parseLightdashAiAgentBundle)(`
|
|
303
|
+
apiVersion: lightdash.ai/v1alpha1
|
|
304
|
+
kind: LightdashAiAgentBundle
|
|
305
|
+
metadata:
|
|
306
|
+
name: sales-bundle
|
|
307
|
+
spec:
|
|
308
|
+
projectUuid: ${PROJECT_UUID}
|
|
309
|
+
agents:
|
|
310
|
+
- key: sales
|
|
311
|
+
uuid: ${AGENT_UUID}
|
|
312
|
+
name: Sales Agent
|
|
313
|
+
instruction: Help with sales
|
|
314
|
+
spaceAccess:
|
|
315
|
+
- ${spaceUuid}
|
|
316
|
+
evaluations: []
|
|
317
|
+
`);
|
|
318
|
+
const current = {
|
|
319
|
+
projectUuid: PROJECT_UUID,
|
|
320
|
+
agents: [
|
|
321
|
+
{
|
|
322
|
+
agent: {
|
|
323
|
+
uuid: AGENT_UUID,
|
|
324
|
+
name: 'Sales Agent',
|
|
325
|
+
description: null,
|
|
326
|
+
instruction: 'Help with sales',
|
|
327
|
+
tags: null,
|
|
328
|
+
spaceAccess: [],
|
|
329
|
+
},
|
|
330
|
+
evaluations: [],
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
};
|
|
334
|
+
const diff = (0, common_1.computeBundleDiff)(bundleWithSpaceAccess, current);
|
|
335
|
+
(0, vitest_1.expect)(diff.summary.updates).toBe(1);
|
|
336
|
+
(0, vitest_1.expect)((_a = diff.changes[0]) === null || _a === void 0 ? void 0 : _a.operation).toBe('update');
|
|
337
|
+
(0, vitest_1.expect)((_c = (_b = diff.changes[0]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c.spaceAccess).toEqual({
|
|
338
|
+
from: [],
|
|
339
|
+
to: [spaceUuid],
|
|
340
|
+
});
|
|
341
|
+
});
|
|
261
342
|
(0, vitest_1.it)('includes agentUuid on name-matched agent update changes', () => {
|
|
262
343
|
const nameMatchedBundle = (0, common_1.parseLightdashAiAgentBundle)(`
|
|
263
344
|
apiVersion: lightdash.ai/v1alpha1
|
|
@@ -46,7 +46,7 @@ function registerAgentsCrudCommands(agentsCmd) {
|
|
|
46
46
|
}));
|
|
47
47
|
agentsCmd
|
|
48
48
|
.command('create')
|
|
49
|
-
.description('Create a new agent in a project')
|
|
49
|
+
.description('Create a new agent in a project (omitted permission flags default to secure: data/content/SQL/user context off, adminOnly on)')
|
|
50
50
|
.requiredOption('--project <uuid>', 'Project UUID')
|
|
51
51
|
.option('--name <name>', 'Agent name')
|
|
52
52
|
.option('--description <text>', 'Agent description')
|
|
@@ -57,22 +57,23 @@ function registerAgentsCrudCommands(agentsCmd) {
|
|
|
57
57
|
const options = this.opts();
|
|
58
58
|
try {
|
|
59
59
|
const client = (0, client_1.getClient)();
|
|
60
|
-
let
|
|
60
|
+
let createInput;
|
|
61
61
|
if ((0, file_input_1.hasExplicitFileInput)(options)) {
|
|
62
62
|
const parsed = await (0, file_input_1.readParsedInput)({ file: options.file, stdin: options.stdin });
|
|
63
63
|
if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
64
64
|
console.error('Error: agent input must be a JSON/YAML object');
|
|
65
65
|
process.exit(1);
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
createInput = parsed;
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
70
|
if (options.name == null) {
|
|
71
71
|
console.error('Error: --name is required unless using --file or --stdin');
|
|
72
72
|
process.exit(1);
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
createInput = Object.assign(Object.assign({ name: options.name }, (options.description != null ? { description: options.description } : {})), (options.instruction != null ? { instruction: options.instruction } : {}));
|
|
75
75
|
}
|
|
76
|
+
const body = (0, common_1.buildSecureCreateAiAgentBody)(Object.assign(Object.assign({}, createInput), { projectUuid: options.project }));
|
|
76
77
|
const result = await client.v1.aiAgents.createAgent(options.project, body);
|
|
77
78
|
console.log(JSON.stringify(result, null, 2));
|
|
78
79
|
}
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ const program = new commander_1.Command();
|
|
|
32
32
|
program
|
|
33
33
|
.name('lightdash-ai')
|
|
34
34
|
.description('CLI for Lightdash AI')
|
|
35
|
-
.version('0.
|
|
35
|
+
.version('0.22.0')
|
|
36
36
|
.option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'read-only')
|
|
37
37
|
.option('--projects <uuids>', 'Comma-separated list of allowed project UUIDs (security guardrail)')
|
|
38
38
|
.option('--dry-run', 'Simulate mutating operations without executing (env: LIGHTDASH_TOOLS_DRY_RUN=1)');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "CLI for Lightdash AI.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"commander": "^15.0.0",
|
|
20
20
|
"yaml": "^2.9.0",
|
|
21
|
-
"@lightdash-tools/
|
|
22
|
-
"@lightdash-tools/
|
|
21
|
+
"@lightdash-tools/client": "0.22.0",
|
|
22
|
+
"@lightdash-tools/common": "0.22.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^25.9.3"
|
|
@@ -286,6 +286,91 @@ spec:
|
|
|
286
286
|
expect(diff.summary.noops).toBe(1);
|
|
287
287
|
});
|
|
288
288
|
|
|
289
|
+
it('detects drift when bundle sets enableContentTools', () => {
|
|
290
|
+
const bundleWithContentTools = parseLightdashAiAgentBundle(`
|
|
291
|
+
apiVersion: lightdash.ai/v1alpha1
|
|
292
|
+
kind: LightdashAiAgentBundle
|
|
293
|
+
metadata:
|
|
294
|
+
name: sales-bundle
|
|
295
|
+
spec:
|
|
296
|
+
projectUuid: ${PROJECT_UUID}
|
|
297
|
+
agents:
|
|
298
|
+
- key: sales
|
|
299
|
+
uuid: ${AGENT_UUID}
|
|
300
|
+
name: Sales Agent
|
|
301
|
+
instruction: Help with sales
|
|
302
|
+
enableContentTools: true
|
|
303
|
+
evaluations: []
|
|
304
|
+
`);
|
|
305
|
+
|
|
306
|
+
const current = {
|
|
307
|
+
projectUuid: PROJECT_UUID,
|
|
308
|
+
agents: [
|
|
309
|
+
{
|
|
310
|
+
agent: {
|
|
311
|
+
uuid: AGENT_UUID,
|
|
312
|
+
name: 'Sales Agent',
|
|
313
|
+
description: null,
|
|
314
|
+
instruction: 'Help with sales',
|
|
315
|
+
tags: null,
|
|
316
|
+
enableContentTools: false,
|
|
317
|
+
},
|
|
318
|
+
evaluations: [],
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const diff = computeBundleDiff(bundleWithContentTools, current);
|
|
324
|
+
expect(diff.summary.updates).toBe(1);
|
|
325
|
+
expect(diff.changes[0]?.operation).toBe('update');
|
|
326
|
+
expect(diff.changes[0]?.fields?.enableContentTools).toEqual({ from: false, to: true });
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('detects spaceAccess-only bundle drift as update', () => {
|
|
330
|
+
const spaceUuid = '00000000-0000-4000-8000-000000000040';
|
|
331
|
+
const bundleWithSpaceAccess = parseLightdashAiAgentBundle(`
|
|
332
|
+
apiVersion: lightdash.ai/v1alpha1
|
|
333
|
+
kind: LightdashAiAgentBundle
|
|
334
|
+
metadata:
|
|
335
|
+
name: sales-bundle
|
|
336
|
+
spec:
|
|
337
|
+
projectUuid: ${PROJECT_UUID}
|
|
338
|
+
agents:
|
|
339
|
+
- key: sales
|
|
340
|
+
uuid: ${AGENT_UUID}
|
|
341
|
+
name: Sales Agent
|
|
342
|
+
instruction: Help with sales
|
|
343
|
+
spaceAccess:
|
|
344
|
+
- ${spaceUuid}
|
|
345
|
+
evaluations: []
|
|
346
|
+
`);
|
|
347
|
+
|
|
348
|
+
const current = {
|
|
349
|
+
projectUuid: PROJECT_UUID,
|
|
350
|
+
agents: [
|
|
351
|
+
{
|
|
352
|
+
agent: {
|
|
353
|
+
uuid: AGENT_UUID,
|
|
354
|
+
name: 'Sales Agent',
|
|
355
|
+
description: null,
|
|
356
|
+
instruction: 'Help with sales',
|
|
357
|
+
tags: null,
|
|
358
|
+
spaceAccess: [],
|
|
359
|
+
},
|
|
360
|
+
evaluations: [],
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const diff = computeBundleDiff(bundleWithSpaceAccess, current);
|
|
366
|
+
expect(diff.summary.updates).toBe(1);
|
|
367
|
+
expect(diff.changes[0]?.operation).toBe('update');
|
|
368
|
+
expect(diff.changes[0]?.fields?.spaceAccess).toEqual({
|
|
369
|
+
from: [],
|
|
370
|
+
to: [spaceUuid],
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
289
374
|
it('includes agentUuid on name-matched agent update changes', () => {
|
|
290
375
|
const nameMatchedBundle = parseLightdashAiAgentBundle(`
|
|
291
376
|
apiVersion: lightdash.ai/v1alpha1
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
* Agent CRUD commands (list, get, create, update, delete).
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
buildSecureCreateAiAgentBody,
|
|
7
|
+
READ_ONLY_DEFAULT,
|
|
8
|
+
WRITE_DESTRUCTIVE,
|
|
9
|
+
WRITE_IDEMPOTENT,
|
|
10
|
+
} from '@lightdash-tools/common';
|
|
6
11
|
|
|
7
12
|
import { getClient } from '../utils/client';
|
|
8
13
|
import { hasExplicitFileInput, readParsedInput } from '../utils/file-input';
|
|
@@ -58,7 +63,9 @@ export function registerAgentsCrudCommands(agentsCmd: Command): void {
|
|
|
58
63
|
|
|
59
64
|
agentsCmd
|
|
60
65
|
.command('create')
|
|
61
|
-
.description(
|
|
66
|
+
.description(
|
|
67
|
+
'Create a new agent in a project (omitted permission flags default to secure: data/content/SQL/user context off, adminOnly on)',
|
|
68
|
+
)
|
|
62
69
|
.requiredOption('--project <uuid>', 'Project UUID')
|
|
63
70
|
.option('--name <name>', 'Agent name')
|
|
64
71
|
.option('--description <text>', 'Agent description')
|
|
@@ -77,7 +84,7 @@ export function registerAgentsCrudCommands(agentsCmd: Command): void {
|
|
|
77
84
|
};
|
|
78
85
|
try {
|
|
79
86
|
const client = getClient();
|
|
80
|
-
let
|
|
87
|
+
let createInput: Record<string, unknown>;
|
|
81
88
|
|
|
82
89
|
if (hasExplicitFileInput(options)) {
|
|
83
90
|
const parsed = await readParsedInput({ file: options.file, stdin: options.stdin });
|
|
@@ -85,23 +92,24 @@ export function registerAgentsCrudCommands(agentsCmd: Command): void {
|
|
|
85
92
|
console.error('Error: agent input must be a JSON/YAML object');
|
|
86
93
|
process.exit(1);
|
|
87
94
|
}
|
|
88
|
-
|
|
89
|
-
...(parsed as Record<string, unknown>),
|
|
90
|
-
projectUuid: options.project,
|
|
91
|
-
} as Parameters<typeof client.v1.aiAgents.createAgent>[1];
|
|
95
|
+
createInput = parsed as Record<string, unknown>;
|
|
92
96
|
} else {
|
|
93
97
|
if (options.name == null) {
|
|
94
98
|
console.error('Error: --name is required unless using --file or --stdin');
|
|
95
99
|
process.exit(1);
|
|
96
100
|
}
|
|
97
|
-
|
|
101
|
+
createInput = {
|
|
98
102
|
name: options.name,
|
|
99
|
-
projectUuid: options.project,
|
|
100
103
|
...(options.description != null ? { description: options.description } : {}),
|
|
101
104
|
...(options.instruction != null ? { instruction: options.instruction } : {}),
|
|
102
|
-
}
|
|
105
|
+
};
|
|
103
106
|
}
|
|
104
107
|
|
|
108
|
+
const body = buildSecureCreateAiAgentBody({
|
|
109
|
+
...(createInput as Parameters<typeof buildSecureCreateAiAgentBody>[0]),
|
|
110
|
+
projectUuid: options.project,
|
|
111
|
+
});
|
|
112
|
+
|
|
105
113
|
const result = await client.v1.aiAgents.createAgent(options.project, body);
|
|
106
114
|
console.log(JSON.stringify(result, null, 2));
|
|
107
115
|
} catch (error) {
|
package/src/index.ts
CHANGED