luxlabs 1.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.
@@ -0,0 +1,226 @@
1
+ const axios = require('axios');
2
+ const chalk = require('chalk');
3
+ const {
4
+ getApiUrl,
5
+ getAuthHeaders,
6
+ isAuthenticated,
7
+ } = require('../lib/config');
8
+ const {
9
+ error,
10
+ success,
11
+ info,
12
+ formatJson,
13
+ formatTable,
14
+ requireArgs,
15
+ readFile,
16
+ } = require('../lib/helpers');
17
+
18
+ async function handleAgents(args) {
19
+ // Check authentication
20
+ if (!isAuthenticated()) {
21
+ console.log(
22
+ chalk.red('āŒ Not authenticated. Run'),
23
+ chalk.white('lux login'),
24
+ chalk.red('first.')
25
+ );
26
+ process.exit(1);
27
+ }
28
+
29
+ const command = args[0];
30
+
31
+ if (!command) {
32
+ console.log(`
33
+ ${chalk.bold('Usage:')} lux agent <command> [args]
34
+
35
+ ${chalk.bold('Commands:')}
36
+ list List all agents
37
+ get <agent-id> Get agent details and prompt
38
+ create <id> <name> [desc] Create new custom agent
39
+ delete <agent-id> Delete custom agent
40
+ prompt get <agent-id> Get agent prompt content
41
+ prompt set <agent-id> <file> Set agent prompt from file
42
+
43
+ ${chalk.bold('Examples:')}
44
+ lux agent list
45
+ lux agent get backend
46
+ lux agent create my-agent "My Custom Agent" "Description here"
47
+ lux agent delete my-agent
48
+ lux agent prompt get backend
49
+ lux agent prompt set my-agent ./prompt.md
50
+ `);
51
+ process.exit(0);
52
+ }
53
+
54
+ const apiUrl = getApiUrl();
55
+
56
+ try {
57
+ switch (command) {
58
+ case 'list': {
59
+ info('Loading agents...');
60
+ const { data } = await axios.get(`${apiUrl}/api/agents`, {
61
+ headers: getAuthHeaders(),
62
+ });
63
+
64
+ if (!data.agents || data.agents.length === 0) {
65
+ console.log('\n(No agents found)\n');
66
+ } else {
67
+ console.log(`\nFound ${data.agents.length} agent(s):\n`);
68
+ const formatted = data.agents.map((a) => ({
69
+ id: a.id,
70
+ name: a.name,
71
+ type: a.type,
72
+ category: a.category,
73
+ updated: new Date(a.updated_at).toLocaleDateString(),
74
+ }));
75
+ formatTable(formatted);
76
+ }
77
+ break;
78
+ }
79
+
80
+ case 'get': {
81
+ requireArgs(args.slice(1), 1, 'lux agent get <agent-id>');
82
+ const agentId = args[1];
83
+
84
+ info(`Loading agent: ${agentId}`);
85
+ const { data: agentData } = await axios.get(
86
+ `${apiUrl}/api/agents/${agentId}`,
87
+ { headers: getAuthHeaders() }
88
+ );
89
+
90
+ if (!agentData.agent) {
91
+ error(`Agent not found: ${agentId}`);
92
+ break;
93
+ }
94
+
95
+ const agent = agentData.agent;
96
+
97
+ console.log(`\nšŸ¤– ID: ${agent.id}`);
98
+ console.log(`šŸ“ Name: ${agent.name}`);
99
+ console.log(`šŸ“„ Description: ${agent.description || '(none)'}`);
100
+ console.log(`šŸ·ļø Type: ${agent.type}`);
101
+ console.log(`šŸ“‚ Category: ${agent.category}`);
102
+ console.log(`šŸŽÆ Purpose: ${agent.purpose || '(none)'}`);
103
+ console.log(`šŸ“… Created: ${agent.created_at}`);
104
+ console.log(`šŸ“… Updated: ${agent.updated_at}`);
105
+
106
+ // Fetch prompt content
107
+ info('Loading agent prompt...');
108
+ const { data: promptData } = await axios.get(
109
+ `${apiUrl}/api/agents/${agentId}/prompt`,
110
+ { headers: getAuthHeaders() }
111
+ );
112
+
113
+ if (promptData.content) {
114
+ console.log(`\nšŸ“‹ Prompt:\n`);
115
+ console.log(promptData.content);
116
+ } else {
117
+ console.log(`\nšŸ“‹ Prompt: (empty)`);
118
+ }
119
+
120
+ break;
121
+ }
122
+
123
+ case 'create': {
124
+ requireArgs(args.slice(1), 2, 'lux agent create <id> <name> [description]');
125
+ const id = args[1];
126
+ const name = args[2];
127
+ const description = args[3] || '';
128
+
129
+ info(`Creating agent: ${name}`);
130
+ const { data } = await axios.post(
131
+ `${apiUrl}/api/agents`,
132
+ {
133
+ id,
134
+ name,
135
+ description,
136
+ purpose: 'custom'
137
+ },
138
+ { headers: getAuthHeaders() }
139
+ );
140
+
141
+ success(`Agent created!`);
142
+ console.log(` ID: ${data.agent.id}`);
143
+ console.log(` Name: ${data.agent.name}`);
144
+ console.log(` Category: ${data.agent.category}`);
145
+ break;
146
+ }
147
+
148
+ case 'delete': {
149
+ requireArgs(args.slice(1), 1, 'lux agent delete <agent-id>');
150
+ const agentId = args[1];
151
+
152
+ info(`Deleting agent: ${agentId}`);
153
+ await axios.delete(
154
+ `${apiUrl}/api/agents/${agentId}`,
155
+ { headers: getAuthHeaders() }
156
+ );
157
+
158
+ success('Agent deleted!');
159
+ break;
160
+ }
161
+
162
+ case 'prompt': {
163
+ const subcommand = args[1];
164
+
165
+ if (!subcommand) {
166
+ error('Usage: lux agent prompt <get|set> <agent-id> [file]');
167
+ break;
168
+ }
169
+
170
+ switch (subcommand) {
171
+ case 'get': {
172
+ requireArgs(args.slice(2), 1, 'lux agent prompt get <agent-id>');
173
+ const agentId = args[2];
174
+
175
+ info(`Loading prompt for: ${agentId}`);
176
+ const { data } = await axios.get(
177
+ `${apiUrl}/api/agents/${agentId}/prompt`,
178
+ { headers: getAuthHeaders() }
179
+ );
180
+
181
+ if (data.content) {
182
+ console.log(data.content);
183
+ } else {
184
+ console.log('(empty prompt)');
185
+ }
186
+ break;
187
+ }
188
+
189
+ case 'set': {
190
+ requireArgs(args.slice(2), 2, 'lux agent prompt set <agent-id> <file>');
191
+ const agentId = args[2];
192
+ const filePath = args[3];
193
+
194
+ info(`Reading prompt from: ${filePath}`);
195
+ const content = readFile(filePath);
196
+
197
+ info(`Setting prompt for: ${agentId}`);
198
+ await axios.put(
199
+ `${apiUrl}/api/agents/${agentId}/prompt`,
200
+ { content },
201
+ { headers: getAuthHeaders() }
202
+ );
203
+
204
+ success('Prompt updated!');
205
+ break;
206
+ }
207
+
208
+ default:
209
+ error(`Unknown prompt subcommand: ${subcommand}\n\nUse: get | set`);
210
+ }
211
+ break;
212
+ }
213
+
214
+ default:
215
+ error(
216
+ `Unknown command: ${command}\n\nRun 'lux agent' to see available commands`
217
+ );
218
+ }
219
+ } catch (err) {
220
+ const errorMessage =
221
+ err.response?.data?.error || err.message || 'Unknown error';
222
+ error(`${errorMessage}`);
223
+ }
224
+ }
225
+
226
+ module.exports = { handleAgents };