@nestbox-ai/cli 1.0.37 → 1.0.39
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/.github/workflows/test.yml +54 -0
- package/README.md +2 -1
- package/dist/commands/agent/apiUtils.d.ts +20 -0
- package/dist/commands/agent/apiUtils.js +75 -2
- package/dist/commands/agent/apiUtils.js.map +1 -1
- package/dist/commands/agent/create.d.ts +2 -29
- package/dist/commands/agent/create.js +123 -61
- package/dist/commands/agent/create.js.map +1 -1
- package/dist/commands/agent/deploy.js +183 -137
- package/dist/commands/agent/deploy.js.map +1 -1
- package/dist/commands/agent/index.d.ts +1 -2
- package/dist/commands/agent/index.js +3 -6
- package/dist/commands/agent/index.js.map +1 -1
- package/dist/commands/agent/yaml-schema.d.ts +72 -0
- package/dist/commands/agent/yaml-schema.js +61 -0
- package/dist/commands/agent/yaml-schema.js.map +1 -0
- package/dist/commands/agent.js +2 -2
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/generate/project.js +32 -28
- package/dist/commands/generate/project.js.map +1 -1
- package/dist/utils/agent.js +18 -20
- package/dist/utils/agent.js.map +1 -1
- package/package.json +3 -2
- package/src/commands/agent/apiUtils.ts +103 -14
- package/src/commands/agent/create.ts +266 -100
- package/src/commands/agent/deploy.ts +515 -264
- package/src/commands/agent/index.ts +1 -4
- package/src/commands/agent/yaml-schema.ts +57 -0
- package/src/commands/agent.ts +10 -10
- package/src/commands/generate/project.ts +179 -147
- package/src/utils/agent.ts +141 -125
- package/test/agent.test.ts +153 -124
- package/dist/commands/agent/createFromYaml.d.ts +0 -2
- package/dist/commands/agent/createFromYaml.js +0 -172
- package/dist/commands/agent/createFromYaml.js.map +0 -1
- package/src/commands/agent/createFromYaml.ts +0 -192
|
@@ -1,105 +1,271 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
3
|
import { resolveProject } from "../../utils/project";
|
|
4
|
+
import { loadNestboxConfig } from "../../utils/agent";
|
|
5
|
+
import {
|
|
6
|
+
createApis,
|
|
7
|
+
loadAgentFromYaml,
|
|
8
|
+
loadAllAgentNamesFromYaml,
|
|
9
|
+
} from "./apiUtils";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
type CreateAgentOptions = {
|
|
12
|
+
agent: string; // agent name
|
|
13
|
+
description: string;
|
|
14
|
+
inputSchema: any;
|
|
15
|
+
instance: string;
|
|
16
|
+
project?: string;
|
|
17
|
+
type?: string;
|
|
18
|
+
prefix?: string;
|
|
19
|
+
all?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type AgentCreateData = {
|
|
23
|
+
type: string;
|
|
24
|
+
agentName: string;
|
|
25
|
+
goal: string;
|
|
26
|
+
inputSchema: object;
|
|
27
|
+
machineManifestId: string;
|
|
28
|
+
projectId: string;
|
|
29
|
+
machineName: string;
|
|
30
|
+
machineInstanceId: number;
|
|
31
|
+
instanceIP: string;
|
|
32
|
+
userId: number;
|
|
33
|
+
entryFunctionName: string;
|
|
34
|
+
modelBaseId: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type MachineInstanceData = {
|
|
38
|
+
machineId?: string;
|
|
39
|
+
id?: number;
|
|
40
|
+
internalIP?: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
async function buildAgentData(
|
|
44
|
+
options: CreateAgentOptions,
|
|
45
|
+
machineInstanceData: MachineInstanceData = {}
|
|
46
|
+
): Promise<AgentCreateData> {
|
|
47
|
+
const createAgentData = {
|
|
48
|
+
agentName: "",
|
|
49
|
+
goal: "",
|
|
50
|
+
inputSchema: {},
|
|
51
|
+
|
|
52
|
+
machineManifestId: machineInstanceData.machineId,
|
|
53
|
+
machineName: options.instance,
|
|
54
|
+
machineInstanceId: machineInstanceData.id,
|
|
55
|
+
instanceIP: machineInstanceData.internalIP,
|
|
56
|
+
|
|
57
|
+
projectId: options.project,
|
|
58
|
+
type: options?.type || "REGULAR",
|
|
59
|
+
userId: 0,
|
|
60
|
+
modelBaseId: "",
|
|
61
|
+
entryFunctionName: "",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// check agent name and add prefix
|
|
65
|
+
if (!options.agent) {
|
|
66
|
+
throw new Error("Missing required argument <agent>.");
|
|
67
|
+
}
|
|
68
|
+
createAgentData.agentName = options.prefix
|
|
69
|
+
? options.prefix + "-" + options.agent
|
|
70
|
+
: options.agent;
|
|
71
|
+
|
|
72
|
+
// agent creation using arguments
|
|
73
|
+
if (options.description || options.inputSchema) {
|
|
74
|
+
if (!options.description) {
|
|
75
|
+
throw new Error("Missing required argument <description>.");
|
|
76
|
+
}
|
|
77
|
+
if (!options.inputSchema) {
|
|
78
|
+
throw new Error("Missing required argument <inputSchema>.");
|
|
79
|
+
}
|
|
80
|
+
createAgentData.goal = options.description;
|
|
81
|
+
createAgentData.inputSchema = JSON.parse(options.inputSchema);
|
|
82
|
+
} else {
|
|
83
|
+
const manifestAgent = await loadAgentFromYaml(options.agent);
|
|
84
|
+
|
|
85
|
+
if (!manifestAgent) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
"Could not find a yaml file definition of an agent or agent not defined in yaml file."
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
createAgentData.goal = manifestAgent.description;
|
|
92
|
+
createAgentData.inputSchema = manifestAgent.inputSchema || {};
|
|
93
|
+
createAgentData.type = options.type || manifestAgent?.type || "REGULAR";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return createAgentData as AgentCreateData;
|
|
19
97
|
}
|
|
20
98
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
export function registerCreateCommand(agentCommand: Command) {
|
|
100
|
+
agentCommand
|
|
101
|
+
.command("create")
|
|
102
|
+
.description("Create an agent with direct arguments or YAML.")
|
|
103
|
+
.option("--agent <agent>", "Agent name to deploy")
|
|
104
|
+
.option("--all", "Deploy all agents defined in nestbox-agents.yaml")
|
|
105
|
+
.option(
|
|
106
|
+
"--project <project>",
|
|
107
|
+
"Project ID (defaults to current project)"
|
|
108
|
+
)
|
|
109
|
+
.option("--type <type>", "Agent type (e.g. CHAT, AGENT, REGULAR)")
|
|
110
|
+
.option(
|
|
111
|
+
"--prefix <prefix>",
|
|
112
|
+
"A prefix added to beginning of the agent name."
|
|
113
|
+
)
|
|
114
|
+
.option("--description <description>", "Description of the agent")
|
|
115
|
+
.option("--instance <instance>", "Machine name")
|
|
116
|
+
.option("--inputSchema <inputSchema>", "Agent input schema")
|
|
117
|
+
.action(async (options): Promise<any> => {
|
|
118
|
+
try {
|
|
119
|
+
const apis = createApis();
|
|
120
|
+
|
|
121
|
+
// resolve project
|
|
122
|
+
const projectData = await resolveProject(apis.projectsApi, {
|
|
123
|
+
project: options?.project || "",
|
|
124
|
+
instance: options?.instance || "",
|
|
125
|
+
...options,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const projectRoot = process.cwd();
|
|
129
|
+
const nestboxConfig = loadNestboxConfig(projectRoot);
|
|
130
|
+
|
|
131
|
+
if (!options?.instance && !nestboxConfig?.instance) {
|
|
132
|
+
console.log(
|
|
133
|
+
chalk.red("Parameter <instance> not provided.")
|
|
134
|
+
);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const machineName =
|
|
139
|
+
options?.instance || nestboxConfig?.instance;
|
|
140
|
+
|
|
141
|
+
const instanceData: any =
|
|
142
|
+
await apis.instanceApi.machineInstancesControllerGetMachineInstanceByUserId(
|
|
143
|
+
projectData.id,
|
|
144
|
+
0,
|
|
145
|
+
10
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const targetInstance = instanceData.data.machineInstances.find(
|
|
149
|
+
(instance: any) => instance.instanceName === machineName
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (!targetInstance) {
|
|
153
|
+
console.error(
|
|
154
|
+
chalk.red(
|
|
155
|
+
`Instance with name "${machineName}" not found in project "${projectData.name}".`
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
console.log(chalk.yellow("Available instances:"));
|
|
159
|
+
instanceData.data.machineInstances.forEach(
|
|
160
|
+
(instance: any) => {
|
|
161
|
+
console.log(
|
|
162
|
+
chalk.yellow(
|
|
163
|
+
` - ${instance.instanceName} (ID: ${instance.id})`
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// handle --all (iterate all manifest agent names)
|
|
172
|
+
if (options.all) {
|
|
173
|
+
let created = 0;
|
|
174
|
+
let failed = 0;
|
|
175
|
+
const names = await loadAllAgentNamesFromYaml();
|
|
176
|
+
|
|
177
|
+
if (!names.length) {
|
|
178
|
+
console.log(
|
|
179
|
+
chalk.yellow("No agents found in YAML manifest.")
|
|
180
|
+
);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
console.log(
|
|
185
|
+
chalk.cyan(
|
|
186
|
+
`Deploying ${names.length} agent(s) from YAML${options.prefix ? ` with prefix "${options.prefix}"` : ""}...`
|
|
187
|
+
)
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const results: any[] = [];
|
|
191
|
+
for (const name of names) {
|
|
192
|
+
try {
|
|
193
|
+
const data = await buildAgentData(
|
|
194
|
+
{
|
|
195
|
+
...options,
|
|
196
|
+
project: projectData.id,
|
|
197
|
+
agent: name, // use name; buildAgentData will fetch full definition via loadAgentFromYaml
|
|
198
|
+
},
|
|
199
|
+
targetInstance
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const res =
|
|
203
|
+
await apis.agentsApi.machineAgentControllerCreateMachineAgent(
|
|
204
|
+
projectData.id,
|
|
205
|
+
{ ...data }
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
created++;
|
|
209
|
+
results.push(res.data);
|
|
210
|
+
console.log(
|
|
211
|
+
chalk.green(`✔ Created: ${data.agentName}`)
|
|
212
|
+
);
|
|
213
|
+
} catch (err: any) {
|
|
214
|
+
failed++;
|
|
215
|
+
const msg =
|
|
216
|
+
err?.response?.data?.message ||
|
|
217
|
+
err?.message ||
|
|
218
|
+
"Unknown error";
|
|
219
|
+
console.log(
|
|
220
|
+
chalk.red(`✖ Failed: ${name} — ${msg}`)
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
console.log(
|
|
226
|
+
chalk.cyan(
|
|
227
|
+
`Done. ${chalk.green(`${created} created`)}, ${chalk.red(
|
|
228
|
+
`${failed} failed`
|
|
229
|
+
)}.`
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
return results;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// original single-agent flow
|
|
236
|
+
const data = await buildAgentData(
|
|
237
|
+
{ ...options, project: projectData.id },
|
|
238
|
+
targetInstance
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const response =
|
|
242
|
+
await apis.agentsApi.machineAgentControllerCreateMachineAgent(
|
|
243
|
+
projectData.id,
|
|
244
|
+
{
|
|
245
|
+
...data,
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
console.log(chalk.green("Agent successfully created."));
|
|
250
|
+
return response.data;
|
|
251
|
+
} catch (error: any) {
|
|
252
|
+
if (error.response && error.response.status === 401) {
|
|
253
|
+
console.log(
|
|
254
|
+
chalk.red(
|
|
255
|
+
'Authentication token has expired. Please login again using "nestbox login <domain>".'
|
|
256
|
+
)
|
|
257
|
+
);
|
|
258
|
+
} else if (error.response) {
|
|
259
|
+
console.log(
|
|
260
|
+
chalk.red(
|
|
261
|
+
`API Error (${error.response.status}): ${
|
|
262
|
+
error.response.data?.message || "Unknown error"
|
|
263
|
+
}`
|
|
264
|
+
)
|
|
265
|
+
);
|
|
266
|
+
} else {
|
|
267
|
+
console.log(chalk.red(error.message || "Unknown error"));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
105
271
|
}
|