@nestbox-ai/cli 1.0.48 → 1.0.49
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/package.json +7 -1
- package/.github/workflows/generate-client.yml +0 -43
- package/.github/workflows/test.yml +0 -54
- package/.nestboxrc +0 -5
- package/src/commands/agent/apiUtils.ts +0 -113
- package/src/commands/agent/create.ts +0 -271
- package/src/commands/agent/deploy.ts +0 -523
- package/src/commands/agent/index.ts +0 -8
- package/src/commands/agent/list.ts +0 -104
- package/src/commands/agent/remove.ts +0 -103
- package/src/commands/agent/yaml-schema.ts +0 -57
- package/src/commands/agent.ts +0 -21
- package/src/commands/auth/index.ts +0 -3
- package/src/commands/auth/login.ts +0 -184
- package/src/commands/auth/logout.ts +0 -110
- package/src/commands/auth.ts +0 -12
- package/src/commands/compute/apiUtils.ts +0 -28
- package/src/commands/compute/create.ts +0 -195
- package/src/commands/compute/delete.ts +0 -147
- package/src/commands/compute/index.ts +0 -7
- package/src/commands/compute/list.ts +0 -117
- package/src/commands/compute.ts +0 -19
- package/src/commands/document/apiUtils.ts +0 -22
- package/src/commands/document/collectionCreate.ts +0 -46
- package/src/commands/document/collectionDelete.ts +0 -45
- package/src/commands/document/collectionGet.ts +0 -47
- package/src/commands/document/collectionList.ts +0 -52
- package/src/commands/document/collectionUpdate.ts +0 -53
- package/src/commands/document/docAdd.ts +0 -56
- package/src/commands/document/docDelete.ts +0 -47
- package/src/commands/document/docGet.ts +0 -49
- package/src/commands/document/docSearch.ts +0 -70
- package/src/commands/document/docUpdate.ts +0 -56
- package/src/commands/document/docUploadFile.ts +0 -55
- package/src/commands/document/index.ts +0 -17
- package/src/commands/document.ts +0 -48
- package/src/commands/generate/project.ts +0 -199
- package/src/commands/generate.ts +0 -15
- package/src/commands/image/apiUtils.ts +0 -22
- package/src/commands/image/display.ts +0 -34
- package/src/commands/image/index.ts +0 -4
- package/src/commands/image/list.ts +0 -61
- package/src/commands/image.ts +0 -15
- package/src/commands/project/add.ts +0 -47
- package/src/commands/project/apiUtils.ts +0 -20
- package/src/commands/project/index.ts +0 -5
- package/src/commands/project/list.ts +0 -78
- package/src/commands/project/use.ts +0 -45
- package/src/commands/project.ts +0 -19
- package/src/index.ts +0 -39
- package/src/types/agentType.ts +0 -7
- package/src/types/agentYaml.ts +0 -107
- package/src/types/auth.ts +0 -12
- package/src/types/statusMapping.ts +0 -8
- package/src/utils/agent.ts +0 -170
- package/src/utils/api.ts +0 -64
- package/src/utils/auth.ts +0 -140
- package/src/utils/config.ts +0 -37
- package/src/utils/error.ts +0 -168
- package/src/utils/plopGenerator.ts +0 -133
- package/src/utils/project.ts +0 -88
- package/src/utils/user.ts +0 -28
- package/src/utils/validation.ts +0 -22
- package/templates/base-js/index.js.hbs +0 -30
- package/templates/base-js/nestbox-agents.yaml.hbs +0 -12
- package/templates/base-js/package.json +0 -15
- package/templates/base-py/main.py.hbs +0 -42
- package/templates/base-py/nestbox-agents.yaml.hbs +0 -12
- package/templates/base-py/pyproject.toml +0 -19
- package/templates/base-ts/eslint.config.mjs +0 -27
- package/templates/base-ts/nestbox-agents.yaml.hbs +0 -12
- package/templates/base-ts/nestbox.config.json +0 -9
- package/templates/base-ts/package.json +0 -24
- package/templates/base-ts/src/index.ts.hbs +0 -29
- package/templates/base-ts/tsconfig.json +0 -14
- package/templates/chatbot-js/index.js.hbs +0 -18
- package/templates/chatbot-js/package-lock.json +0 -1571
- package/templates/chatbot-js/package.json +0 -15
- package/templates/chatbot-py/main.py.hbs +0 -42
- package/templates/chatbot-py/nestbox-agents.yaml.hbs +0 -12
- package/templates/chatbot-py/pyproject.toml +0 -19
- package/templates/chatbot-ts/eslint.config.mjs +0 -27
- package/templates/chatbot-ts/package.json +0 -24
- package/templates/chatbot-ts/src/index.ts.hbs +0 -18
- package/templates/chatbot-ts/tsconfig.json +0 -14
- package/test/README.md +0 -52
- package/test/agent.test.ts +0 -154
- package/test/auth.test.ts +0 -71
- package/test/compute.test.ts +0 -135
- package/test/document.test.ts +0 -217
- package/test/generate.test.ts +0 -67
- package/test/image.test.ts +0 -107
- package/test/mocks.ts +0 -122
- package/test/project.test.ts +0 -108
- package/test/setup.ts +0 -121
- package/tsconfig.json +0 -118
- package/vitest.config.d.ts +0 -2
- package/vitest.config.js +0 -23
- package/vitest.config.js.map +0 -1
- package/vitest.config.ts +0 -21
|
@@ -1,523 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { getAuthToken } from "../../utils/auth";
|
|
6
|
-
import { withTokenRefresh } from "../../utils/error";
|
|
7
|
-
import ora from "ora";
|
|
8
|
-
import { resolveProject } from "../../utils/project";
|
|
9
|
-
import {
|
|
10
|
-
createZipFromDirectory,
|
|
11
|
-
isTypeScriptProject,
|
|
12
|
-
loadNestboxConfig,
|
|
13
|
-
runPredeployScripts,
|
|
14
|
-
} from "../../utils/agent";
|
|
15
|
-
import axios from "axios";
|
|
16
|
-
import {
|
|
17
|
-
createApis,
|
|
18
|
-
loadAgentFromYaml,
|
|
19
|
-
loadAllAgentNamesFromYaml,
|
|
20
|
-
} from "./apiUtils";
|
|
21
|
-
import inquirer from "inquirer";
|
|
22
|
-
|
|
23
|
-
type ManifestAgent = {
|
|
24
|
-
name: string;
|
|
25
|
-
goal: string;
|
|
26
|
-
entry: string;
|
|
27
|
-
inputSchema: any;
|
|
28
|
-
type: string;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type CreateAgentOptions = {
|
|
32
|
-
type?: string;
|
|
33
|
-
goal?: string;
|
|
34
|
-
inputSchema?: any;
|
|
35
|
-
machineManifestId?: string;
|
|
36
|
-
project?: string;
|
|
37
|
-
instance?: string;
|
|
38
|
-
machineInstanceId?: number;
|
|
39
|
-
instanceIP?: string;
|
|
40
|
-
entryFunctionName?: string;
|
|
41
|
-
modelBaseId?: string;
|
|
42
|
-
prefix?: string;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
type DeployAgentOptions = {
|
|
46
|
-
agent: string; // agent name
|
|
47
|
-
description?: string;
|
|
48
|
-
inputSchema?: any;
|
|
49
|
-
instance: string;
|
|
50
|
-
project?: string;
|
|
51
|
-
type?: string;
|
|
52
|
-
prefix?: string;
|
|
53
|
-
all?: boolean;
|
|
54
|
-
entryFunction: string;
|
|
55
|
-
log?: boolean;
|
|
56
|
-
silent?: boolean;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
type AgentCreateData = {
|
|
60
|
-
type: string;
|
|
61
|
-
agentName: string;
|
|
62
|
-
goal: string;
|
|
63
|
-
inputSchema: any;
|
|
64
|
-
machineManifestId: string;
|
|
65
|
-
projectId: string;
|
|
66
|
-
machineName: string;
|
|
67
|
-
machineInstanceId: number;
|
|
68
|
-
instanceIP: string;
|
|
69
|
-
userId: number;
|
|
70
|
-
entryFunctionName: string;
|
|
71
|
-
modelBaseId: string;
|
|
72
|
-
parameters: [{}];
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
type ConfigData = {
|
|
76
|
-
instance?: string;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
type MachineInstanceData = {
|
|
80
|
-
machineId?: string;
|
|
81
|
-
id?: number;
|
|
82
|
-
internalIP?: string;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
async function buildAgentData(
|
|
86
|
-
options: DeployAgentOptions,
|
|
87
|
-
machineInstanceData: MachineInstanceData = {}
|
|
88
|
-
): Promise<AgentCreateData> {
|
|
89
|
-
const deployAgentData = {
|
|
90
|
-
agentName: "",
|
|
91
|
-
goal: "",
|
|
92
|
-
inputSchema: {},
|
|
93
|
-
|
|
94
|
-
machineManifestId: machineInstanceData.machineId,
|
|
95
|
-
machineName: options.instance,
|
|
96
|
-
machineInstanceId: machineInstanceData.id,
|
|
97
|
-
instanceIP: machineInstanceData.internalIP,
|
|
98
|
-
|
|
99
|
-
projectId: options.project,
|
|
100
|
-
type: options?.type || "REGULAR",
|
|
101
|
-
userId: 0,
|
|
102
|
-
modelBaseId: "",
|
|
103
|
-
entryFunctionName: "",
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
if (!options.agent) {
|
|
107
|
-
throw new Error("Missing required argument <agent>.");
|
|
108
|
-
}
|
|
109
|
-
deployAgentData.agentName = options.prefix
|
|
110
|
-
? options.prefix + "-" + options.agent
|
|
111
|
-
: options.agent;
|
|
112
|
-
|
|
113
|
-
if (options.description || options.inputSchema || options.entryFunction) {
|
|
114
|
-
if (!options.description) {
|
|
115
|
-
throw new Error("Missing required argument <description>.");
|
|
116
|
-
}
|
|
117
|
-
if (!options.inputSchema) {
|
|
118
|
-
throw new Error("Missing required argument <inputSchema>.");
|
|
119
|
-
}
|
|
120
|
-
if (!options.entryFunction) {
|
|
121
|
-
throw new Error("Missing required argument <entryFunction>.");
|
|
122
|
-
}
|
|
123
|
-
deployAgentData.goal = options.description;
|
|
124
|
-
deployAgentData.inputSchema = JSON.parse(options.inputSchema);
|
|
125
|
-
deployAgentData.entryFunctionName = options.entryFunction;
|
|
126
|
-
} else {
|
|
127
|
-
const manifestAgent = await loadAgentFromYaml(options.agent);
|
|
128
|
-
|
|
129
|
-
if (!manifestAgent) {
|
|
130
|
-
throw new Error(
|
|
131
|
-
"Could not find a yaml file definition of an agent or agent not defined in yaml file."
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
deployAgentData.entryFunctionName = manifestAgent.entry;
|
|
136
|
-
deployAgentData.goal = manifestAgent.description;
|
|
137
|
-
deployAgentData.inputSchema = manifestAgent.inputSchema || {};
|
|
138
|
-
deployAgentData.type = options.type || manifestAgent?.type || "REGULAR";
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return deployAgentData as AgentCreateData;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function registerDeployCommand(agentCommand: Command) {
|
|
145
|
-
agentCommand
|
|
146
|
-
.command("deploy")
|
|
147
|
-
.description("Deploy an AI agent to the Nestbox platform")
|
|
148
|
-
.option(
|
|
149
|
-
"--prefix <prefix>",
|
|
150
|
-
"A prefix added to beginning of the agent name."
|
|
151
|
-
)
|
|
152
|
-
.option("--agent <agent>", "Agent name to deploy")
|
|
153
|
-
.option("--description <description>", "Goal/description of the agent")
|
|
154
|
-
.option("--inputSchema <inputSchema>", "Agent input schema")
|
|
155
|
-
.option(
|
|
156
|
-
"--project <project>",
|
|
157
|
-
"Project ID (defaults to current project)"
|
|
158
|
-
)
|
|
159
|
-
.option("--type <type>", "Agent type (e.g. CHAT, AGENT, REGULAR)")
|
|
160
|
-
.option("--entryFunction <entryFunction>", "Entry function name")
|
|
161
|
-
.option("--instance <instance>", "Machine name")
|
|
162
|
-
.option("--log", "Show detailed logs during deployment")
|
|
163
|
-
.option("--silent", "Disable automatic agent creation.")
|
|
164
|
-
.option("--all", "Deploy all agents defined in nestbox-agents.yaml")
|
|
165
|
-
.action(async (options): Promise<any> => {
|
|
166
|
-
try {
|
|
167
|
-
let apis = createApis();
|
|
168
|
-
|
|
169
|
-
await withTokenRefresh(
|
|
170
|
-
async () => {
|
|
171
|
-
let names: string[] = [];
|
|
172
|
-
if (options.all) {
|
|
173
|
-
names = await loadAllAgentNamesFromYaml();
|
|
174
|
-
if (!names.length) {
|
|
175
|
-
console.log(
|
|
176
|
-
chalk.yellow(
|
|
177
|
-
"No agents found in YAML manifest."
|
|
178
|
-
)
|
|
179
|
-
);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
} else {
|
|
183
|
-
if (!options?.agent) {
|
|
184
|
-
console.log(
|
|
185
|
-
chalk.red("Parameter <agent> not provided.")
|
|
186
|
-
);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
names = [options.agent];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const projectData = await resolveProject(
|
|
193
|
-
apis.projectsApi,
|
|
194
|
-
{
|
|
195
|
-
project: options.project,
|
|
196
|
-
instance: "",
|
|
197
|
-
...options,
|
|
198
|
-
}
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
const projectRoot = process.cwd();
|
|
202
|
-
const config = loadNestboxConfig(projectRoot);
|
|
203
|
-
|
|
204
|
-
if (!options?.instance && !config?.instance) {
|
|
205
|
-
console.log(
|
|
206
|
-
chalk.red("Parameter <instance> not provided.")
|
|
207
|
-
);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const machineName = options.instance || config.instance;
|
|
212
|
-
|
|
213
|
-
const instanceData: any =
|
|
214
|
-
await apis.instanceApi.machineInstancesControllerGetMachineInstanceByUserId(
|
|
215
|
-
projectData.id,
|
|
216
|
-
0,
|
|
217
|
-
10
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
const targetInstance =
|
|
221
|
-
instanceData.data.machineInstances.find(
|
|
222
|
-
(instance: any) =>
|
|
223
|
-
instance.instanceName === machineName
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
if (!targetInstance) {
|
|
227
|
-
console.error(
|
|
228
|
-
chalk.red(
|
|
229
|
-
`Instance with name "${machineName}" not found in project "${projectData.name}".`
|
|
230
|
-
)
|
|
231
|
-
);
|
|
232
|
-
console.log(chalk.yellow("Available instances:"));
|
|
233
|
-
instanceData.data.machineInstances.forEach(
|
|
234
|
-
(instance: any) => {
|
|
235
|
-
console.log(
|
|
236
|
-
chalk.yellow(
|
|
237
|
-
` - ${instance.instanceName} (ID: ${instance.id})`
|
|
238
|
-
)
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
for (const name of names) {
|
|
246
|
-
const data = await buildAgentData(
|
|
247
|
-
{
|
|
248
|
-
...options,
|
|
249
|
-
project: projectData.id,
|
|
250
|
-
instance: machineName,
|
|
251
|
-
agent: name,
|
|
252
|
-
},
|
|
253
|
-
targetInstance
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
const agentsData: any =
|
|
257
|
-
await apis.agentsApi.machineAgentControllerGetMachineAgentByProjectId(
|
|
258
|
-
projectData.id,
|
|
259
|
-
0,
|
|
260
|
-
100,
|
|
261
|
-
data.type
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
let targetAgent =
|
|
265
|
-
agentsData.data.machineAgents.find(
|
|
266
|
-
(agent: any) =>
|
|
267
|
-
agent.agentName === data.agentName
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
if (!targetAgent && !options.silent) {
|
|
271
|
-
const { confirmCreation } =
|
|
272
|
-
await inquirer.prompt([
|
|
273
|
-
{
|
|
274
|
-
type: "confirm",
|
|
275
|
-
name: "confirmCreation",
|
|
276
|
-
message: chalk.red(
|
|
277
|
-
`No agent with specified name "${data.agentName}" found. Would you like to create one first before deployment?`
|
|
278
|
-
),
|
|
279
|
-
default: false,
|
|
280
|
-
},
|
|
281
|
-
]);
|
|
282
|
-
|
|
283
|
-
if (!confirmCreation) {
|
|
284
|
-
continue;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (!targetAgent) {
|
|
289
|
-
const response =
|
|
290
|
-
await apis.agentsApi.machineAgentControllerCreateMachineAgent(
|
|
291
|
-
projectData.id,
|
|
292
|
-
{ ...data }
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
targetAgent = response.data;
|
|
296
|
-
|
|
297
|
-
console.log(
|
|
298
|
-
chalk.green(
|
|
299
|
-
`Created agent ${data.agentName} before deploying.`
|
|
300
|
-
)
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const agentId = targetAgent.id;
|
|
305
|
-
const resolvedEntry =
|
|
306
|
-
data.entryFunctionName ||
|
|
307
|
-
targetAgent.entryFunctionName ||
|
|
308
|
-
"main";
|
|
309
|
-
const instanceId = targetInstance.id;
|
|
310
|
-
|
|
311
|
-
const spinner = ora(
|
|
312
|
-
`Preparing to deploy ${data.agentName.toLowerCase()} ${agentId} to instance ${instanceId}...`
|
|
313
|
-
).start();
|
|
314
|
-
|
|
315
|
-
try {
|
|
316
|
-
let zipFilePath;
|
|
317
|
-
|
|
318
|
-
spinner.text = `Using project root: ${projectRoot}`;
|
|
319
|
-
|
|
320
|
-
const isTypeScript =
|
|
321
|
-
isTypeScriptProject(projectRoot);
|
|
322
|
-
|
|
323
|
-
if (
|
|
324
|
-
isTypeScript &&
|
|
325
|
-
(config?.agent?.predeploy ||
|
|
326
|
-
config?.agents?.predeploy)
|
|
327
|
-
) {
|
|
328
|
-
const predeployScripts =
|
|
329
|
-
config?.agent?.predeploy ||
|
|
330
|
-
config?.agents?.predeploy;
|
|
331
|
-
spinner.text = `Running predeploy scripts on project root...`;
|
|
332
|
-
await runPredeployScripts(
|
|
333
|
-
predeployScripts,
|
|
334
|
-
projectRoot
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
spinner.text = `Creating zip archive from project root ${projectRoot}...`;
|
|
339
|
-
zipFilePath =
|
|
340
|
-
createZipFromDirectory(projectRoot);
|
|
341
|
-
spinner.text = `Directory zipped successfully to ${zipFilePath}`;
|
|
342
|
-
|
|
343
|
-
spinner.text = `Deploying ${data.agentName.toLowerCase()} ${agentId} to instance ${instanceId}...`;
|
|
344
|
-
|
|
345
|
-
const authToken = getAuthToken();
|
|
346
|
-
const baseUrl = authToken?.serverUrl?.endsWith(
|
|
347
|
-
"/"
|
|
348
|
-
)
|
|
349
|
-
? authToken.serverUrl.slice(0, -1)
|
|
350
|
-
: authToken?.serverUrl;
|
|
351
|
-
|
|
352
|
-
const { default: FormData } = await import(
|
|
353
|
-
"form-data"
|
|
354
|
-
);
|
|
355
|
-
const form = new FormData();
|
|
356
|
-
|
|
357
|
-
form.append(
|
|
358
|
-
"file",
|
|
359
|
-
fs.createReadStream(zipFilePath)
|
|
360
|
-
);
|
|
361
|
-
form.append(
|
|
362
|
-
"machineAgentId",
|
|
363
|
-
agentId.toString()
|
|
364
|
-
);
|
|
365
|
-
form.append(
|
|
366
|
-
"instanceId",
|
|
367
|
-
instanceId.toString()
|
|
368
|
-
);
|
|
369
|
-
form.append("entryFunctionName", resolvedEntry);
|
|
370
|
-
form.append("isSourceCodeUpdate", "true");
|
|
371
|
-
form.append("projectId", projectData.id);
|
|
372
|
-
|
|
373
|
-
if (options.log) {
|
|
374
|
-
console.log(chalk.blue("Form Details "));
|
|
375
|
-
console.log(
|
|
376
|
-
chalk.blue(
|
|
377
|
-
` - File: ${path.basename(zipFilePath)}`
|
|
378
|
-
)
|
|
379
|
-
);
|
|
380
|
-
console.log(
|
|
381
|
-
chalk.blue(` - Agent ID: ${agentId}`)
|
|
382
|
-
);
|
|
383
|
-
console.log(
|
|
384
|
-
chalk.blue(
|
|
385
|
-
` - Instance ID: ${instanceId}`
|
|
386
|
-
)
|
|
387
|
-
);
|
|
388
|
-
console.log(
|
|
389
|
-
chalk.blue(
|
|
390
|
-
` - Entry Function: ${resolvedEntry}`
|
|
391
|
-
)
|
|
392
|
-
);
|
|
393
|
-
console.log(
|
|
394
|
-
chalk.blue(
|
|
395
|
-
` - Project ID: ${projectData.id}`
|
|
396
|
-
)
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
const axiosInstance = axios.create({
|
|
401
|
-
baseURL: baseUrl,
|
|
402
|
-
headers: {
|
|
403
|
-
...form.getHeaders(),
|
|
404
|
-
Authorization: authToken?.token,
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
const endpoint = `/projects/${projectData.id}/agents/${agentId}`;
|
|
409
|
-
|
|
410
|
-
spinner.text = `Deploy ${name}...`;
|
|
411
|
-
const res = await axiosInstance.patch(
|
|
412
|
-
endpoint,
|
|
413
|
-
form
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
await axios.patch(
|
|
417
|
-
baseUrl + endpoint,
|
|
418
|
-
{
|
|
419
|
-
projectId: data.projectId,
|
|
420
|
-
id: agentId,
|
|
421
|
-
agentName: data.agentName,
|
|
422
|
-
goal: data.goal,
|
|
423
|
-
inputSchema: data.inputSchema,
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
headers: {
|
|
427
|
-
Authorization: authToken?.token,
|
|
428
|
-
},
|
|
429
|
-
}
|
|
430
|
-
);
|
|
431
|
-
|
|
432
|
-
if (options.log) {
|
|
433
|
-
console.log(
|
|
434
|
-
chalk.blue("\nDeployment request:")
|
|
435
|
-
);
|
|
436
|
-
console.log(
|
|
437
|
-
chalk.blue(
|
|
438
|
-
` URL: ${baseUrl}${endpoint}`
|
|
439
|
-
)
|
|
440
|
-
);
|
|
441
|
-
console.log(chalk.blue(` Method: PATCH`));
|
|
442
|
-
console.log(
|
|
443
|
-
chalk.blue(
|
|
444
|
-
` File: ${path.basename(zipFilePath)}`
|
|
445
|
-
)
|
|
446
|
-
);
|
|
447
|
-
console.log(
|
|
448
|
-
chalk.blue(
|
|
449
|
-
` Response status: ${res.status} ${res.statusText}`
|
|
450
|
-
)
|
|
451
|
-
);
|
|
452
|
-
const lines = res.data.logEntries || [];
|
|
453
|
-
console.log(
|
|
454
|
-
chalk.blue(
|
|
455
|
-
` Deployment log entries (${lines.length} lines):`
|
|
456
|
-
)
|
|
457
|
-
);
|
|
458
|
-
lines.forEach((line: any) => {
|
|
459
|
-
console.log(
|
|
460
|
-
chalk.blue(
|
|
461
|
-
` - [${line.type} ${line.timestamp}] ${line.message} `
|
|
462
|
-
)
|
|
463
|
-
);
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
spinner.succeed("Successfully deployed");
|
|
467
|
-
console.log(
|
|
468
|
-
chalk.green(
|
|
469
|
-
`${data.agentName} deployed successfully!`
|
|
470
|
-
)
|
|
471
|
-
);
|
|
472
|
-
console.log(
|
|
473
|
-
chalk.cyan(
|
|
474
|
-
`📍 Instance: ${data.machineName}`
|
|
475
|
-
)
|
|
476
|
-
);
|
|
477
|
-
console.log(
|
|
478
|
-
chalk.cyan(`🤖 Agent: ${name} (${agentId})`)
|
|
479
|
-
);
|
|
480
|
-
console.log(
|
|
481
|
-
chalk.cyan(`⚙️ Entry: ${resolvedEntry}`)
|
|
482
|
-
);
|
|
483
|
-
console.log(
|
|
484
|
-
chalk.cyan(
|
|
485
|
-
`🔄 Process: ${res.data.processName}`
|
|
486
|
-
)
|
|
487
|
-
);
|
|
488
|
-
} catch (error: any) {
|
|
489
|
-
spinner.fail(
|
|
490
|
-
`Failed to deploy ${data.agentName.toLowerCase()}`
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
},
|
|
495
|
-
() => {
|
|
496
|
-
apis = createApis();
|
|
497
|
-
}
|
|
498
|
-
);
|
|
499
|
-
} catch (error: any) {
|
|
500
|
-
if (error.message && error.message.includes("Authentication")) {
|
|
501
|
-
console.error(chalk.red(error.message));
|
|
502
|
-
} else if (error.response) {
|
|
503
|
-
console.error(
|
|
504
|
-
chalk.red(
|
|
505
|
-
`API Error (${error.response.status}): ${error.response.data?.message || "Unknown error"}`
|
|
506
|
-
)
|
|
507
|
-
);
|
|
508
|
-
if (error.response.data) {
|
|
509
|
-
console.error(
|
|
510
|
-
chalk.red(
|
|
511
|
-
`Error Data: ${JSON.stringify(error.response.data, null, 2)}`
|
|
512
|
-
)
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
} else {
|
|
516
|
-
console.error(
|
|
517
|
-
chalk.red("Error:"),
|
|
518
|
-
error.message || "Unknown error"
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Individual command exports for direct usage if needed
|
|
2
|
-
export { registerListCommand } from "./list";
|
|
3
|
-
export { registerRemoveCommand } from "./remove";
|
|
4
|
-
export { registerDeployCommand } from "./deploy";
|
|
5
|
-
export { registerCreateCommand } from "./create";
|
|
6
|
-
|
|
7
|
-
// API utilities
|
|
8
|
-
export { createApis, type ApiInstances } from "./apiUtils";
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { withTokenRefresh } from "../../utils/error";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import ora from "ora";
|
|
5
|
-
import Table from "cli-table3";
|
|
6
|
-
import { resolveProject } from "../../utils/project";
|
|
7
|
-
import { AgentType } from "../../types/agentType";
|
|
8
|
-
import { createApis } from "./apiUtils";
|
|
9
|
-
|
|
10
|
-
export function registerListCommand(agentCommand: Command): void {
|
|
11
|
-
agentCommand
|
|
12
|
-
.command("list")
|
|
13
|
-
.description("List all AI agents associated with the authenticated user")
|
|
14
|
-
.option(
|
|
15
|
-
"--project <projectName>",
|
|
16
|
-
"Project name (defaults to the current project)"
|
|
17
|
-
)
|
|
18
|
-
.action(async (options) => {
|
|
19
|
-
try {
|
|
20
|
-
let apis = createApis();
|
|
21
|
-
|
|
22
|
-
// Execute with token refresh support
|
|
23
|
-
await withTokenRefresh(
|
|
24
|
-
async () => {
|
|
25
|
-
// Resolve project
|
|
26
|
-
const projectData = await resolveProject(apis.projectsApi, options);
|
|
27
|
-
|
|
28
|
-
const spinner = ora(
|
|
29
|
-
`Listing agents in project ${projectData.name}...`
|
|
30
|
-
).start();
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
// Get the agents for the specific project
|
|
34
|
-
const agentsResponse: any =
|
|
35
|
-
await apis.agentsApi.machineAgentControllerGetMachineAgentByProjectId(
|
|
36
|
-
projectData.id,
|
|
37
|
-
0,
|
|
38
|
-
10,
|
|
39
|
-
AgentType.REGULAR
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
spinner.succeed("Successfully retrieved agents");
|
|
43
|
-
|
|
44
|
-
// Display the results
|
|
45
|
-
const agents = agentsResponse.data?.machineAgents || [];
|
|
46
|
-
|
|
47
|
-
if (!agents || agents.length === 0) {
|
|
48
|
-
console.log(
|
|
49
|
-
chalk.yellow(`No agents found in project ${projectData.name}`)
|
|
50
|
-
);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
console.log(
|
|
55
|
-
chalk.blue(`\nAgents in project ${projectData.name}:\n`)
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
// Create a formatted table
|
|
59
|
-
const table = new Table({
|
|
60
|
-
head: [
|
|
61
|
-
chalk.white.bold("ID"),
|
|
62
|
-
chalk.white.bold("Name"),
|
|
63
|
-
chalk.white.bold("URL"),
|
|
64
|
-
],
|
|
65
|
-
style: {
|
|
66
|
-
head: [],
|
|
67
|
-
border: [],
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// Add agents to the table
|
|
72
|
-
agents.forEach((agent: any) => {
|
|
73
|
-
let url = "N/A";
|
|
74
|
-
if (agent.instanceIP) {
|
|
75
|
-
url = `${agent.instanceIP}/v1/agents/${agent.modelBaseId}/query`;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
table.push([agent.id || "N/A", agent.agentName || "N/A", url]);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
console.log(table.toString());
|
|
82
|
-
console.log(`\nTotal agents: ${agents.length}`);
|
|
83
|
-
|
|
84
|
-
} catch (error: any) {
|
|
85
|
-
spinner.fail("Failed to retrieve agents");
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
() => {
|
|
90
|
-
// Recreate APIs after token refresh
|
|
91
|
-
apis = createApis();
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
} catch (error: any) {
|
|
95
|
-
if (error.message && error.message.includes('Authentication')) {
|
|
96
|
-
console.error(chalk.red(error.message));
|
|
97
|
-
} else if (error.response?.data?.message) {
|
|
98
|
-
console.error(chalk.red("API Error:"), error.response.data.message);
|
|
99
|
-
} else {
|
|
100
|
-
console.error(chalk.red("Error:"), error.message || "Unknown error");
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|