@lightdash-tools/cli 0.6.0 → 0.7.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/README.md +6 -2
- package/dist/commands/agentops/apply.d.ts +5 -0
- package/dist/commands/agentops/apply.js +53 -0
- package/dist/commands/agentops/bundle-schema.d.ts +5 -0
- package/dist/commands/agentops/bundle-schema.js +16 -0
- package/dist/commands/agentops/drift.d.ts +5 -0
- package/dist/commands/agentops/drift.js +46 -0
- package/dist/commands/agentops/evaluate-gate.d.ts +5 -0
- package/dist/commands/agentops/evaluate-gate.js +89 -0
- package/dist/commands/agentops/gate-schema.d.ts +5 -0
- package/dist/commands/agentops/gate-schema.js +16 -0
- package/dist/commands/agentops/plan.d.ts +5 -0
- package/dist/commands/agentops/plan.js +42 -0
- package/dist/commands/agentops/state.d.ts +4 -0
- package/dist/commands/agentops/state.js +8 -0
- package/dist/commands/agentops.d.ts +8 -0
- package/dist/commands/agentops.js +26 -0
- package/dist/commands/agentops.test.d.ts +1 -0
- package/dist/commands/agentops.test.js +400 -0
- package/dist/commands/agents-crud.d.ts +8 -0
- package/dist/commands/agents-crud.js +144 -0
- package/dist/commands/agents-discovery.d.ts +8 -0
- package/dist/commands/agents-discovery.js +139 -0
- package/dist/commands/agents-discovery.test.d.ts +1 -0
- package/dist/commands/agents-discovery.test.js +13 -0
- package/dist/commands/agents-evals.d.ts +8 -0
- package/dist/commands/agents-evals.js +246 -0
- package/dist/commands/agents-threads.d.ts +8 -0
- package/dist/commands/agents-threads.js +83 -0
- package/dist/commands/agents.js +8 -360
- package/dist/commands/ai-agents.js +52 -70
- package/dist/commands/charts.js +35 -46
- package/dist/commands/content.js +3 -12
- package/dist/commands/dashboards.js +3 -12
- package/dist/commands/explores.js +12 -21
- package/dist/commands/groups.js +44 -63
- package/dist/commands/metrics.js +6 -15
- package/dist/commands/organization-roles.js +28 -39
- package/dist/commands/organization.js +3 -12
- package/dist/commands/project-access.js +9 -18
- package/dist/commands/project-role-assignments.js +15 -24
- package/dist/commands/projects.js +33 -26
- package/dist/commands/query.js +30 -41
- package/dist/commands/schedulers.js +6 -15
- package/dist/commands/schema.js +33 -10
- package/dist/commands/schema.test.js +58 -1
- package/dist/commands/space-access.js +12 -21
- package/dist/commands/spaces.js +6 -15
- package/dist/commands/tags.js +6 -15
- package/dist/commands/users.js +23 -41
- package/dist/index.js +18 -16
- package/dist/index.test.js +9 -9
- package/dist/utils/cli-params.d.ts +4 -0
- package/dist/utils/cli-params.js +15 -0
- package/dist/utils/cli-params.test.d.ts +1 -0
- package/dist/utils/cli-params.test.js +12 -0
- package/dist/utils/file-input.d.ts +30 -0
- package/dist/utils/file-input.js +77 -0
- package/dist/utils/file-input.test.d.ts +1 -0
- package/dist/utils/file-input.test.js +68 -0
- package/dist/utils/safety.d.ts +5 -0
- package/dist/utils/safety.js +97 -109
- package/dist/utils/safety.test.js +135 -33
- package/package.json +14 -5
- package/src/commands/agentops/apply.ts +77 -0
- package/src/commands/agentops/bundle-schema.ts +20 -0
- package/src/commands/agentops/drift.ts +63 -0
- package/src/commands/agentops/evaluate-gate.ts +128 -0
- package/src/commands/agentops/gate-schema.ts +20 -0
- package/src/commands/agentops/plan.ts +55 -0
- package/src/commands/agentops/state.ts +5 -0
- package/src/commands/agentops.test.ts +454 -0
- package/src/commands/agentops.ts +28 -0
- package/src/commands/agents-crud.ts +193 -0
- package/src/commands/agents-discovery.test.ts +16 -0
- package/src/commands/agents-discovery.ts +180 -0
- package/src/commands/agents-evals.ts +353 -0
- package/src/commands/agents-threads.ts +116 -0
- package/src/commands/agents.ts +9 -493
- package/src/commands/ai-agents.ts +37 -28
- package/src/commands/charts.ts +6 -3
- package/src/commands/content.ts +3 -1
- package/src/commands/dashboards.ts +3 -1
- package/src/commands/explores.ts +3 -1
- package/src/commands/groups.ts +33 -33
- package/src/commands/metrics.ts +3 -1
- package/src/commands/organization-roles.ts +3 -1
- package/src/commands/organization.ts +3 -1
- package/src/commands/project-access.ts +3 -1
- package/src/commands/project-role-assignments.ts +3 -1
- package/src/commands/projects.ts +44 -18
- package/src/commands/query.ts +4 -1
- package/src/commands/schedulers.ts +3 -1
- package/src/commands/schema.test.ts +72 -1
- package/src/commands/schema.ts +60 -14
- package/src/commands/space-access.ts +3 -1
- package/src/commands/spaces.ts +3 -1
- package/src/commands/tags.ts +3 -1
- package/src/commands/users.ts +29 -25
- package/src/index.test.ts +10 -9
- package/src/index.ts +19 -16
- package/src/utils/cli-params.test.ts +13 -0
- package/src/utils/cli-params.ts +12 -0
- package/src/utils/client.test.ts +1 -0
- package/src/utils/file-input.test.ts +91 -0
- package/src/utils/file-input.ts +83 -0
- package/src/utils/safety.test.ts +158 -2
- package/src/utils/safety.ts +27 -20
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent discovery commands — preferences, suggestions, models, readiness.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
READ_ONLY_DEFAULT,
|
|
7
|
+
WRITE_DESTRUCTIVE,
|
|
8
|
+
WRITE_IDEMPOTENT,
|
|
9
|
+
type AiAgentUserPreferences,
|
|
10
|
+
} from '@lightdash-tools/common';
|
|
11
|
+
|
|
12
|
+
import { getClient } from '../utils/client';
|
|
13
|
+
import { hasExplicitFileInput, readParsedInput } from '../utils/file-input';
|
|
14
|
+
import { wrapAction } from '../utils/safety';
|
|
15
|
+
|
|
16
|
+
import type { Command } from 'commander';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Registers discovery subcommands on the `agents` command group.
|
|
20
|
+
*/
|
|
21
|
+
export function registerAgentsDiscoveryCommands(agentsCmd: Command): void {
|
|
22
|
+
const preferencesCmd = agentsCmd
|
|
23
|
+
.command('preferences')
|
|
24
|
+
.description('Manage per-user AI agent preferences in a project');
|
|
25
|
+
|
|
26
|
+
preferencesCmd
|
|
27
|
+
.command('get')
|
|
28
|
+
.description('Get current user agent preferences for a project')
|
|
29
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
30
|
+
.action(
|
|
31
|
+
wrapAction(READ_ONLY_DEFAULT, async function (this: Command) {
|
|
32
|
+
const { project } = this.opts() as { project: string };
|
|
33
|
+
try {
|
|
34
|
+
const client = getClient();
|
|
35
|
+
const result = await client.v1.aiAgents.getUserAgentPreferences(project);
|
|
36
|
+
console.log(JSON.stringify(result, null, 2));
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(
|
|
39
|
+
'Error fetching agent preferences:',
|
|
40
|
+
error instanceof Error ? error.message : String(error),
|
|
41
|
+
);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
preferencesCmd
|
|
48
|
+
.command('set')
|
|
49
|
+
.description('Set user agent preferences (flags or JSON/YAML via --file/--stdin)')
|
|
50
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
51
|
+
.option('--default-agent <uuid>', 'Default agent UUID for the project')
|
|
52
|
+
.option('--file <path>', 'Read preferences JSON/YAML from file')
|
|
53
|
+
.option('--stdin', 'Read preferences JSON/YAML from stdin')
|
|
54
|
+
.action(
|
|
55
|
+
wrapAction(WRITE_IDEMPOTENT, async function (this: Command) {
|
|
56
|
+
const options = this.opts() as {
|
|
57
|
+
project: string;
|
|
58
|
+
defaultAgent?: string;
|
|
59
|
+
file?: string;
|
|
60
|
+
stdin?: boolean;
|
|
61
|
+
};
|
|
62
|
+
let body: AiAgentUserPreferences;
|
|
63
|
+
if (hasExplicitFileInput(options)) {
|
|
64
|
+
const parsed = await readParsedInput({ file: options.file, stdin: options.stdin });
|
|
65
|
+
if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
66
|
+
console.error('Error: preferences input must be a JSON/YAML object');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const record = parsed as Record<string, unknown>;
|
|
70
|
+
if (typeof record.defaultAgentUuid !== 'string') {
|
|
71
|
+
console.error('Error: preferences must include defaultAgentUuid (string)');
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
body = { defaultAgentUuid: record.defaultAgentUuid };
|
|
75
|
+
} else if (options.defaultAgent != null) {
|
|
76
|
+
body = { defaultAgentUuid: options.defaultAgent };
|
|
77
|
+
} else {
|
|
78
|
+
console.error('Error: provide --default-agent or preferences via --file/--stdin');
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const client = getClient();
|
|
83
|
+
await client.v1.aiAgents.setUserAgentPreferences(options.project, body);
|
|
84
|
+
console.log(JSON.stringify({ status: 'ok' }, null, 2));
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error(
|
|
87
|
+
'Error setting agent preferences:',
|
|
88
|
+
error instanceof Error ? error.message : String(error),
|
|
89
|
+
);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
preferencesCmd
|
|
96
|
+
.command('delete')
|
|
97
|
+
.description('Clear user agent preferences for a project')
|
|
98
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
99
|
+
.action(
|
|
100
|
+
wrapAction(WRITE_DESTRUCTIVE, async function (this: Command) {
|
|
101
|
+
const { project } = this.opts() as { project: string };
|
|
102
|
+
try {
|
|
103
|
+
const client = getClient();
|
|
104
|
+
await client.v1.aiAgents.deleteUserAgentPreferences(project);
|
|
105
|
+
console.log(JSON.stringify({ status: 'ok' }, null, 2));
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(
|
|
108
|
+
'Error deleting agent preferences:',
|
|
109
|
+
error instanceof Error ? error.message : String(error),
|
|
110
|
+
);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
agentsCmd
|
|
117
|
+
.command('suggestions <agentUuid>')
|
|
118
|
+
.description('List verified question suggestions for an agent')
|
|
119
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
120
|
+
.action(
|
|
121
|
+
wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, cmd: Command) => {
|
|
122
|
+
const { project } = cmd.opts() as { project: string };
|
|
123
|
+
try {
|
|
124
|
+
const client = getClient();
|
|
125
|
+
const result = await client.v1.aiAgents.getAgentSuggestions(project, agentUuid);
|
|
126
|
+
console.log(JSON.stringify(result, null, 2));
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error(
|
|
129
|
+
'Error listing agent suggestions:',
|
|
130
|
+
error instanceof Error ? error.message : String(error),
|
|
131
|
+
);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
agentsCmd
|
|
138
|
+
.command('models <agentUuid>')
|
|
139
|
+
.description('List available AI model options for an agent')
|
|
140
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
141
|
+
.action(
|
|
142
|
+
wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, cmd: Command) => {
|
|
143
|
+
const { project } = cmd.opts() as { project: string };
|
|
144
|
+
try {
|
|
145
|
+
const client = getClient();
|
|
146
|
+
const result = await client.v1.aiAgents.getAgentModelOptions(project, agentUuid);
|
|
147
|
+
console.log(JSON.stringify(result, null, 2));
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error(
|
|
150
|
+
'Error listing agent models:',
|
|
151
|
+
error instanceof Error ? error.message : String(error),
|
|
152
|
+
);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const readinessCmd = agentsCmd.command('readiness').description('Agent release readiness checks');
|
|
159
|
+
|
|
160
|
+
readinessCmd
|
|
161
|
+
.command('evaluate <agentUuid>')
|
|
162
|
+
.description('Evaluate release readiness score for an agent')
|
|
163
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
164
|
+
.action(
|
|
165
|
+
wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, cmd: Command) => {
|
|
166
|
+
const { project } = cmd.opts() as { project: string };
|
|
167
|
+
try {
|
|
168
|
+
const client = getClient();
|
|
169
|
+
const result = await client.v1.aiAgents.evaluateAgentReadiness(project, agentUuid);
|
|
170
|
+
console.log(JSON.stringify(result, null, 2));
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error(
|
|
173
|
+
'Error evaluating agent readiness:',
|
|
174
|
+
error instanceof Error ? error.message : String(error),
|
|
175
|
+
);
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent evaluation commands.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
READ_ONLY_DEFAULT,
|
|
7
|
+
WRITE_DESTRUCTIVE,
|
|
8
|
+
WRITE_IDEMPOTENT,
|
|
9
|
+
WRITE_NONDESTRUCTIVE,
|
|
10
|
+
} from '@lightdash-tools/common';
|
|
11
|
+
|
|
12
|
+
import { getClient } from '../utils/client';
|
|
13
|
+
import { hasExplicitFileInput, readParsedInput } from '../utils/file-input';
|
|
14
|
+
import { wrapAction } from '../utils/safety';
|
|
15
|
+
|
|
16
|
+
import type { Command } from 'commander';
|
|
17
|
+
|
|
18
|
+
function extractPrompts(parsed: unknown): unknown[] {
|
|
19
|
+
if (Array.isArray(parsed)) {
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
if (parsed != null && typeof parsed === 'object' && 'prompts' in parsed) {
|
|
23
|
+
const prompts = (parsed as { prompts: unknown }).prompts;
|
|
24
|
+
if (!Array.isArray(prompts)) {
|
|
25
|
+
throw new Error('prompts field must be an array');
|
|
26
|
+
}
|
|
27
|
+
return prompts;
|
|
28
|
+
}
|
|
29
|
+
throw new Error('input must be a prompts array or an object with a prompts array');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Registers the `agents evals` subcommand group.
|
|
34
|
+
*/
|
|
35
|
+
export function registerAgentsEvalCommands(agentsCmd: Command): void {
|
|
36
|
+
const evalsCmd = agentsCmd
|
|
37
|
+
.command('evals')
|
|
38
|
+
.description('Manage agent evaluations and run test suites');
|
|
39
|
+
|
|
40
|
+
evalsCmd
|
|
41
|
+
.command('list <agentUuid>')
|
|
42
|
+
.description('List all evaluations for an agent')
|
|
43
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
44
|
+
.action(
|
|
45
|
+
wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, cmd: Command) => {
|
|
46
|
+
const { project } = cmd.opts() as { project: string };
|
|
47
|
+
try {
|
|
48
|
+
const client = getClient();
|
|
49
|
+
const result = await client.v1.aiAgents.listEvaluations(project, agentUuid);
|
|
50
|
+
console.log(JSON.stringify(result, null, 2));
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(
|
|
53
|
+
'Error listing evaluations:',
|
|
54
|
+
error instanceof Error ? error.message : String(error),
|
|
55
|
+
);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
evalsCmd
|
|
62
|
+
.command('get <agentUuid> <evalUuid>')
|
|
63
|
+
.description('Get a full evaluation including its prompts')
|
|
64
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
65
|
+
.action(
|
|
66
|
+
wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, evalUuid: string, cmd: Command) => {
|
|
67
|
+
const { project } = cmd.opts() as { project: string };
|
|
68
|
+
try {
|
|
69
|
+
const client = getClient();
|
|
70
|
+
const result = await client.v1.aiAgents.getEvaluation(project, agentUuid, evalUuid);
|
|
71
|
+
console.log(JSON.stringify(result, null, 2));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(
|
|
74
|
+
'Error fetching evaluation:',
|
|
75
|
+
error instanceof Error ? error.message : String(error),
|
|
76
|
+
);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
evalsCmd
|
|
83
|
+
.command('create <agentUuid>')
|
|
84
|
+
.description('Create a new evaluation with a title and optional prompts')
|
|
85
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
86
|
+
.option('--title <title>', 'Evaluation title')
|
|
87
|
+
.option('--description <text>', 'Evaluation description')
|
|
88
|
+
.option(
|
|
89
|
+
'--prompts <json>',
|
|
90
|
+
'JSON array of prompt objects: [{"prompt":"...","expectedResponse":"..."}]',
|
|
91
|
+
)
|
|
92
|
+
.option('--file <path>', 'Read evaluation JSON/YAML from file')
|
|
93
|
+
.option('--stdin', 'Read evaluation JSON/YAML from stdin')
|
|
94
|
+
.action(
|
|
95
|
+
wrapAction(WRITE_NONDESTRUCTIVE, async (agentUuid: string, cmd: Command) => {
|
|
96
|
+
const options = cmd.opts() as {
|
|
97
|
+
project: string;
|
|
98
|
+
title?: string;
|
|
99
|
+
description?: string;
|
|
100
|
+
prompts?: string;
|
|
101
|
+
file?: string;
|
|
102
|
+
stdin?: boolean;
|
|
103
|
+
};
|
|
104
|
+
try {
|
|
105
|
+
const client = getClient();
|
|
106
|
+
let body: Parameters<typeof client.v1.aiAgents.createEvaluation>[2];
|
|
107
|
+
|
|
108
|
+
if (hasExplicitFileInput(options)) {
|
|
109
|
+
const parsed = await readParsedInput({ file: options.file, stdin: options.stdin });
|
|
110
|
+
if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
111
|
+
console.error('Error: evaluation input must be a JSON/YAML object');
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
body = parsed as Parameters<typeof client.v1.aiAgents.createEvaluation>[2];
|
|
115
|
+
} else {
|
|
116
|
+
if (options.title == null) {
|
|
117
|
+
console.error('Error: --title is required unless using --file or --stdin');
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
body = {
|
|
121
|
+
title: options.title,
|
|
122
|
+
prompts: options.prompts ? (JSON.parse(options.prompts) as never) : [],
|
|
123
|
+
};
|
|
124
|
+
if (options.description != null) body.description = options.description;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const result = await client.v1.aiAgents.createEvaluation(
|
|
128
|
+
options.project,
|
|
129
|
+
agentUuid,
|
|
130
|
+
body,
|
|
131
|
+
);
|
|
132
|
+
console.log(JSON.stringify(result, null, 2));
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error(
|
|
135
|
+
'Error creating evaluation:',
|
|
136
|
+
error instanceof Error ? error.message : String(error),
|
|
137
|
+
);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
evalsCmd
|
|
144
|
+
.command('update <agentUuid> <evalUuid>')
|
|
145
|
+
.description('Update an evaluation title, description, or prompts')
|
|
146
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
147
|
+
.option('--title <title>', 'New title')
|
|
148
|
+
.option('--description <text>', 'New description')
|
|
149
|
+
.option('--prompts <json>', 'Replacement JSON array of prompt objects')
|
|
150
|
+
.option('--file <path>', 'Read evaluation patch JSON/YAML from file')
|
|
151
|
+
.option('--stdin', 'Read evaluation patch JSON/YAML from stdin')
|
|
152
|
+
.action(
|
|
153
|
+
wrapAction(WRITE_IDEMPOTENT, async (agentUuid: string, evalUuid: string, cmd: Command) => {
|
|
154
|
+
const options = cmd.opts() as {
|
|
155
|
+
project: string;
|
|
156
|
+
title?: string;
|
|
157
|
+
description?: string;
|
|
158
|
+
prompts?: string;
|
|
159
|
+
file?: string;
|
|
160
|
+
stdin?: boolean;
|
|
161
|
+
};
|
|
162
|
+
try {
|
|
163
|
+
const client = getClient();
|
|
164
|
+
let body: Parameters<typeof client.v1.aiAgents.updateEvaluation>[3];
|
|
165
|
+
|
|
166
|
+
if (hasExplicitFileInput(options)) {
|
|
167
|
+
const parsed = await readParsedInput({ file: options.file, stdin: options.stdin });
|
|
168
|
+
if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
169
|
+
console.error('Error: evaluation patch input must be a JSON/YAML object');
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
body = parsed as Parameters<typeof client.v1.aiAgents.updateEvaluation>[3];
|
|
173
|
+
} else {
|
|
174
|
+
const patch: Record<string, unknown> = {};
|
|
175
|
+
if (options.title != null) patch['title'] = options.title;
|
|
176
|
+
if (options.description != null) patch['description'] = options.description;
|
|
177
|
+
if (options.prompts != null) patch['prompts'] = JSON.parse(options.prompts);
|
|
178
|
+
if (Object.keys(patch).length === 0) {
|
|
179
|
+
console.error(
|
|
180
|
+
'Error: at least one of --title, --description, --prompts, --file, --stdin is required',
|
|
181
|
+
);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
body = patch as Parameters<typeof client.v1.aiAgents.updateEvaluation>[3];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const result = await client.v1.aiAgents.updateEvaluation(
|
|
188
|
+
options.project,
|
|
189
|
+
agentUuid,
|
|
190
|
+
evalUuid,
|
|
191
|
+
body,
|
|
192
|
+
);
|
|
193
|
+
console.log(JSON.stringify(result, null, 2));
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.error(
|
|
196
|
+
'Error updating evaluation:',
|
|
197
|
+
error instanceof Error ? error.message : String(error),
|
|
198
|
+
);
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
201
|
+
}),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
evalsCmd
|
|
205
|
+
.command('append <agentUuid> <evalUuid>')
|
|
206
|
+
.description('Append additional prompts to an existing evaluation')
|
|
207
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
208
|
+
.option('--prompts <json>', 'JSON array of prompt objects to append')
|
|
209
|
+
.option('--file <path>', 'Read prompts JSON/YAML from file')
|
|
210
|
+
.option('--stdin', 'Read prompts JSON/YAML from stdin')
|
|
211
|
+
.action(
|
|
212
|
+
wrapAction(
|
|
213
|
+
WRITE_NONDESTRUCTIVE,
|
|
214
|
+
async (agentUuid: string, evalUuid: string, cmd: Command) => {
|
|
215
|
+
const options = cmd.opts() as {
|
|
216
|
+
project: string;
|
|
217
|
+
prompts?: string;
|
|
218
|
+
file?: string;
|
|
219
|
+
stdin?: boolean;
|
|
220
|
+
};
|
|
221
|
+
try {
|
|
222
|
+
const client = getClient();
|
|
223
|
+
let prompts: unknown[];
|
|
224
|
+
|
|
225
|
+
if (hasExplicitFileInput(options)) {
|
|
226
|
+
const parsed = await readParsedInput({ file: options.file, stdin: options.stdin });
|
|
227
|
+
prompts = extractPrompts(parsed);
|
|
228
|
+
} else if (options.prompts != null) {
|
|
229
|
+
prompts = JSON.parse(options.prompts) as unknown[];
|
|
230
|
+
} else {
|
|
231
|
+
console.error('Error: --prompts, --file, or --stdin is required');
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const result = await client.v1.aiAgents.appendToEvaluation(
|
|
236
|
+
options.project,
|
|
237
|
+
agentUuid,
|
|
238
|
+
evalUuid,
|
|
239
|
+
{
|
|
240
|
+
prompts: prompts as never,
|
|
241
|
+
},
|
|
242
|
+
);
|
|
243
|
+
console.log(JSON.stringify(result, null, 2));
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.error(
|
|
246
|
+
'Error appending to evaluation:',
|
|
247
|
+
error instanceof Error ? error.message : String(error),
|
|
248
|
+
);
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
),
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
evalsCmd
|
|
256
|
+
.command('delete <agentUuid> <evalUuid>')
|
|
257
|
+
.description('Delete an evaluation')
|
|
258
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
259
|
+
.action(
|
|
260
|
+
wrapAction(WRITE_DESTRUCTIVE, async (agentUuid: string, evalUuid: string, cmd: Command) => {
|
|
261
|
+
const { project } = cmd.opts() as { project: string };
|
|
262
|
+
try {
|
|
263
|
+
const client = getClient();
|
|
264
|
+
await client.v1.aiAgents.deleteEvaluation(project, agentUuid, evalUuid);
|
|
265
|
+
console.error(`Evaluation ${evalUuid} deleted successfully`);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
console.error(
|
|
268
|
+
'Error deleting evaluation:',
|
|
269
|
+
error instanceof Error ? error.message : String(error),
|
|
270
|
+
);
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
273
|
+
}),
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
evalsCmd
|
|
277
|
+
.command('run <agentUuid> <evalUuid>')
|
|
278
|
+
.description('Trigger a new evaluation run')
|
|
279
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
280
|
+
.action(
|
|
281
|
+
wrapAction(
|
|
282
|
+
WRITE_NONDESTRUCTIVE,
|
|
283
|
+
async (agentUuid: string, evalUuid: string, cmd: Command) => {
|
|
284
|
+
const { project } = cmd.opts() as { project: string };
|
|
285
|
+
try {
|
|
286
|
+
const client = getClient();
|
|
287
|
+
const result = await client.v1.aiAgents.runEvaluation(project, agentUuid, evalUuid);
|
|
288
|
+
console.log(JSON.stringify(result, null, 2));
|
|
289
|
+
} catch (error) {
|
|
290
|
+
console.error(
|
|
291
|
+
'Error running evaluation:',
|
|
292
|
+
error instanceof Error ? error.message : String(error),
|
|
293
|
+
);
|
|
294
|
+
process.exit(1);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
),
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
evalsCmd
|
|
301
|
+
.command('runs <agentUuid> <evalUuid>')
|
|
302
|
+
.description('List all runs for an evaluation')
|
|
303
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
304
|
+
.action(
|
|
305
|
+
wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, evalUuid: string, cmd: Command) => {
|
|
306
|
+
const { project } = cmd.opts() as { project: string };
|
|
307
|
+
try {
|
|
308
|
+
const client = getClient();
|
|
309
|
+
const result = await client.v1.aiAgents.listAllEvaluationRuns(
|
|
310
|
+
project,
|
|
311
|
+
agentUuid,
|
|
312
|
+
evalUuid,
|
|
313
|
+
);
|
|
314
|
+
console.log(JSON.stringify(result, null, 2));
|
|
315
|
+
} catch (error) {
|
|
316
|
+
console.error(
|
|
317
|
+
'Error listing evaluation runs:',
|
|
318
|
+
error instanceof Error ? error.message : String(error),
|
|
319
|
+
);
|
|
320
|
+
process.exit(1);
|
|
321
|
+
}
|
|
322
|
+
}),
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
evalsCmd
|
|
326
|
+
.command('run-results <agentUuid> <evalUuid> <runUuid>')
|
|
327
|
+
.description('Get detailed results for a specific evaluation run')
|
|
328
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
329
|
+
.action(
|
|
330
|
+
wrapAction(
|
|
331
|
+
READ_ONLY_DEFAULT,
|
|
332
|
+
async (agentUuid: string, evalUuid: string, runUuid: string, cmd: Command) => {
|
|
333
|
+
const { project } = cmd.opts() as { project: string };
|
|
334
|
+
try {
|
|
335
|
+
const client = getClient();
|
|
336
|
+
const result = await client.v1.aiAgents.getEvaluationRunResults(
|
|
337
|
+
project,
|
|
338
|
+
agentUuid,
|
|
339
|
+
evalUuid,
|
|
340
|
+
runUuid,
|
|
341
|
+
);
|
|
342
|
+
console.log(JSON.stringify(result, null, 2));
|
|
343
|
+
} catch (error) {
|
|
344
|
+
console.error(
|
|
345
|
+
'Error fetching evaluation run results:',
|
|
346
|
+
error instanceof Error ? error.message : String(error),
|
|
347
|
+
);
|
|
348
|
+
process.exit(1);
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
),
|
|
352
|
+
);
|
|
353
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent thread management commands.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { READ_ONLY_DEFAULT, WRITE_OPEN_WORLD } from '@lightdash-tools/common';
|
|
6
|
+
|
|
7
|
+
import { getClient } from '../utils/client';
|
|
8
|
+
import { wrapAction } from '../utils/safety';
|
|
9
|
+
|
|
10
|
+
import type { Command } from 'commander';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Registers the `agents threads` subcommand group.
|
|
14
|
+
*/
|
|
15
|
+
export function registerAgentsThreadCommands(agentsCmd: Command): void {
|
|
16
|
+
const threadsCmd = agentsCmd.command('threads').description('Manage agent conversation threads');
|
|
17
|
+
|
|
18
|
+
threadsCmd
|
|
19
|
+
.command('list <agentUuid>')
|
|
20
|
+
.description('List all threads for an agent')
|
|
21
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
22
|
+
.action(
|
|
23
|
+
wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, cmd: Command) => {
|
|
24
|
+
const { project } = cmd.opts() as { project: string };
|
|
25
|
+
try {
|
|
26
|
+
const client = getClient();
|
|
27
|
+
const result = await client.v1.aiAgents.listAgentThreads(project, agentUuid);
|
|
28
|
+
console.log(JSON.stringify(result, null, 2));
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(
|
|
31
|
+
'Error listing threads:',
|
|
32
|
+
error instanceof Error ? error.message : String(error),
|
|
33
|
+
);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
threadsCmd
|
|
40
|
+
.command('get <agentUuid> <threadUuid>')
|
|
41
|
+
.description('Get a thread with all its messages')
|
|
42
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
43
|
+
.action(
|
|
44
|
+
wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, threadUuid: string, cmd: Command) => {
|
|
45
|
+
const { project } = cmd.opts() as { project: string };
|
|
46
|
+
try {
|
|
47
|
+
const client = getClient();
|
|
48
|
+
const result = await client.v1.aiAgents.getAgentThread(project, agentUuid, threadUuid);
|
|
49
|
+
console.log(JSON.stringify(result, null, 2));
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(
|
|
52
|
+
'Error fetching thread:',
|
|
53
|
+
error instanceof Error ? error.message : String(error),
|
|
54
|
+
);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const startThreadHandler = wrapAction(
|
|
61
|
+
WRITE_OPEN_WORLD,
|
|
62
|
+
async (agentUuid: string, cmd: Command) => {
|
|
63
|
+
const options = cmd.opts() as { project: string; prompt: string };
|
|
64
|
+
try {
|
|
65
|
+
const client = getClient();
|
|
66
|
+
const { thread, result } = await client.v1.aiAgents.startConversation(
|
|
67
|
+
options.project,
|
|
68
|
+
agentUuid,
|
|
69
|
+
{ prompt: options.prompt },
|
|
70
|
+
);
|
|
71
|
+
console.log(JSON.stringify({ threadUuid: thread.uuid, ...result }, null, 2));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(
|
|
74
|
+
'Error starting agent conversation:',
|
|
75
|
+
error instanceof Error ? error.message : String(error),
|
|
76
|
+
);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
threadsCmd
|
|
83
|
+
.command('generate <agentUuid>')
|
|
84
|
+
.alias('start')
|
|
85
|
+
.description('Start a new thread and generate the first agent response')
|
|
86
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
87
|
+
.requiredOption('--prompt <text>', 'User prompt')
|
|
88
|
+
.action(startThreadHandler);
|
|
89
|
+
|
|
90
|
+
threadsCmd
|
|
91
|
+
.command('continue <agentUuid> <threadUuid>')
|
|
92
|
+
.description('Continue an existing thread with a new prompt')
|
|
93
|
+
.requiredOption('--project <uuid>', 'Project UUID')
|
|
94
|
+
.requiredOption('--prompt <text>', 'User prompt')
|
|
95
|
+
.action(
|
|
96
|
+
wrapAction(WRITE_OPEN_WORLD, async (agentUuid: string, threadUuid: string, cmd: Command) => {
|
|
97
|
+
const options = cmd.opts() as { project: string; prompt: string };
|
|
98
|
+
try {
|
|
99
|
+
const client = getClient();
|
|
100
|
+
const result = await client.v1.aiAgents.continueConversation(
|
|
101
|
+
options.project,
|
|
102
|
+
agentUuid,
|
|
103
|
+
threadUuid,
|
|
104
|
+
{ prompt: options.prompt },
|
|
105
|
+
);
|
|
106
|
+
console.log(JSON.stringify(result, null, 2));
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(
|
|
109
|
+
'Error continuing thread:',
|
|
110
|
+
error instanceof Error ? error.message : String(error),
|
|
111
|
+
);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
}
|