@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,199 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import { createNestboxConfig } from "../../utils/agent";
|
|
6
|
-
import {
|
|
7
|
-
generateWithPlop,
|
|
8
|
-
listAvailableTemplates,
|
|
9
|
-
} from "../../utils/plopGenerator";
|
|
10
|
-
import { isValidFunctionName } from "../../utils/validation";
|
|
11
|
-
import inquirer from "inquirer";
|
|
12
|
-
import path from "path";
|
|
13
|
-
|
|
14
|
-
export function registerProjectCommand(generateCommand: Command): void {
|
|
15
|
-
generateCommand
|
|
16
|
-
.command("project <folder>")
|
|
17
|
-
.description("Generate a new project from templates")
|
|
18
|
-
.option("--lang <language>", "Project language (ts|js)")
|
|
19
|
-
.option("--template <type>", "Template type (agent|chatbot)")
|
|
20
|
-
.option(
|
|
21
|
-
"--name <agentName>",
|
|
22
|
-
"Agent/Chatbot name (must be a valid function name)"
|
|
23
|
-
)
|
|
24
|
-
.option("--project <projectId>", "Project ID")
|
|
25
|
-
.action(async (folder, options) => {
|
|
26
|
-
try {
|
|
27
|
-
const spinner = ora(
|
|
28
|
-
"Initializing project generation..."
|
|
29
|
-
).start();
|
|
30
|
-
|
|
31
|
-
// Ensure target folder doesn't exist
|
|
32
|
-
if (fs.existsSync(folder)) {
|
|
33
|
-
spinner.fail(`Folder ${folder} already exists`);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let selectedLang = options.lang;
|
|
38
|
-
let selectedTemplate = options.template;
|
|
39
|
-
let agentName = options.name;
|
|
40
|
-
|
|
41
|
-
// Interactive selection if not provided
|
|
42
|
-
if (!selectedLang || !selectedTemplate) {
|
|
43
|
-
spinner.stop();
|
|
44
|
-
|
|
45
|
-
const answers = await inquirer.prompt([
|
|
46
|
-
{
|
|
47
|
-
type: "list",
|
|
48
|
-
name: "lang",
|
|
49
|
-
message: "Select project language:",
|
|
50
|
-
choices: [
|
|
51
|
-
{ name: "TypeScript", value: "ts" },
|
|
52
|
-
{ name: "JavaScript", value: "js" },
|
|
53
|
-
{ name: "Python", value: "py" },
|
|
54
|
-
],
|
|
55
|
-
when: () => !selectedLang,
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
type: "list",
|
|
59
|
-
name: "template",
|
|
60
|
-
message: "Select template type:",
|
|
61
|
-
choices: [
|
|
62
|
-
{ name: "Agent", value: "agent" },
|
|
63
|
-
{ name: "Chatbot", value: "chatbot" },
|
|
64
|
-
],
|
|
65
|
-
when: () => !selectedTemplate,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
type: "input",
|
|
69
|
-
name: "agentName",
|
|
70
|
-
message:
|
|
71
|
-
"Enter agent/chatbot name (must be a valid function name):",
|
|
72
|
-
when: () => !agentName,
|
|
73
|
-
default: (answers: any) => {
|
|
74
|
-
const type =
|
|
75
|
-
selectedTemplate || answers.template;
|
|
76
|
-
return type === "agent"
|
|
77
|
-
? "myAgent"
|
|
78
|
-
: "myChatbot";
|
|
79
|
-
},
|
|
80
|
-
validate: (input: string) => {
|
|
81
|
-
if (!input.trim()) {
|
|
82
|
-
return "Agent name cannot be empty";
|
|
83
|
-
}
|
|
84
|
-
if (!isValidFunctionName(input.trim())) {
|
|
85
|
-
return "Must be a valid function name (e.g., myAgent, chatBot123, my_agent)";
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
selectedLang = selectedLang || answers.lang;
|
|
93
|
-
selectedTemplate = selectedTemplate || answers.template;
|
|
94
|
-
agentName = agentName || answers.agentName;
|
|
95
|
-
|
|
96
|
-
spinner.start("Generating project...");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Validate agent name if provided via CLI option
|
|
100
|
-
if (agentName && !isValidFunctionName(agentName)) {
|
|
101
|
-
spinner.fail(
|
|
102
|
-
`Invalid agent name: "${agentName}". Must be a valid function name (e.g., myAgent, chatBot123, my_agent)`
|
|
103
|
-
);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Set default agent name if not provided
|
|
108
|
-
if (!agentName) {
|
|
109
|
-
agentName =
|
|
110
|
-
selectedTemplate === "agent" ? "myAgent" : "myChatbot";
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Find matching template in local templates folder
|
|
114
|
-
const templateMapping: Record<string, string> = {
|
|
115
|
-
agent: "base",
|
|
116
|
-
chatbot: "chatbot",
|
|
117
|
-
};
|
|
118
|
-
const mappedTemplateType =
|
|
119
|
-
templateMapping[selectedTemplate] || selectedTemplate;
|
|
120
|
-
|
|
121
|
-
// Check if template directory exists
|
|
122
|
-
console.log(__dirname);
|
|
123
|
-
const templatePath = path.resolve(
|
|
124
|
-
__dirname,
|
|
125
|
-
`../../../templates/${mappedTemplateType}-${selectedLang}`
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
if (!fs.existsSync(templatePath)) {
|
|
129
|
-
spinner.fail(`Template not found: ${templatePath}`);
|
|
130
|
-
// Show available templates
|
|
131
|
-
const availableTemplates = listAvailableTemplates();
|
|
132
|
-
if (availableTemplates.length > 0) {
|
|
133
|
-
console.log(chalk.yellow("Available templates:"));
|
|
134
|
-
availableTemplates.forEach(template => {
|
|
135
|
-
console.log(chalk.yellow(` - ${template}`));
|
|
136
|
-
});
|
|
137
|
-
} else {
|
|
138
|
-
console.log(
|
|
139
|
-
chalk.red(
|
|
140
|
-
"No templates found. Please add your templates to the templates directory."
|
|
141
|
-
)
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
spinner.text = `Generating ${mappedTemplateType} project in ${folder}...`;
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
// Generate project using plop
|
|
151
|
-
const { agentNameInYaml } = await generateWithPlop(
|
|
152
|
-
selectedTemplate,
|
|
153
|
-
selectedLang,
|
|
154
|
-
folder,
|
|
155
|
-
path.basename(folder),
|
|
156
|
-
agentName
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
// Create nestbox.config.json for TypeScript projects
|
|
160
|
-
createNestboxConfig(folder, selectedLang === "ts");
|
|
161
|
-
|
|
162
|
-
spinner.succeed(
|
|
163
|
-
`Successfully generated ${mappedTemplateType} project in ${folder}`
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
console.log(chalk.green("\nNext steps:"));
|
|
167
|
-
console.log(chalk.yellow(` cd ${folder}`));
|
|
168
|
-
if (selectedLang === "py") {
|
|
169
|
-
console.log(
|
|
170
|
-
chalk.yellow(
|
|
171
|
-
" pip install -r requirements.txt"
|
|
172
|
-
)
|
|
173
|
-
);
|
|
174
|
-
} else {
|
|
175
|
-
console.log(chalk.yellow(" npm install"));
|
|
176
|
-
if (selectedLang === "ts") {
|
|
177
|
-
console.log(chalk.yellow(" npm run build"));
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
console.log(
|
|
181
|
-
chalk.yellow(
|
|
182
|
-
` nestbox agent deploy --agent ${agentNameInYaml} --instance <instance-name>`
|
|
183
|
-
)
|
|
184
|
-
);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
// Clean up on error
|
|
187
|
-
if (fs.existsSync(folder)) {
|
|
188
|
-
fs.rmSync(folder, { recursive: true, force: true });
|
|
189
|
-
}
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
} catch (error: any) {
|
|
193
|
-
console.error(
|
|
194
|
-
chalk.red("Error:"),
|
|
195
|
-
error.message || "Failed to generate project"
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
package/src/commands/generate.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { registerProjectCommand } from "./generate/project";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Register all generate-related commands
|
|
6
|
-
*/
|
|
7
|
-
export function registerGenerateCommands(program: Command): void {
|
|
8
|
-
// Create the main generate command
|
|
9
|
-
const generateCommand = program
|
|
10
|
-
.command("generate")
|
|
11
|
-
.description("Generate new projects and components");
|
|
12
|
-
|
|
13
|
-
// Register all subcommands
|
|
14
|
-
registerProjectCommand(generateCommand);
|
|
15
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { MiscellaneousApi, ProjectsApi } from "@nestbox-ai/admin";
|
|
2
|
-
import { setupAuthAndConfig } from "../../utils/api";
|
|
3
|
-
|
|
4
|
-
export interface ApiInstances {
|
|
5
|
-
miscellaneousApi: MiscellaneousApi;
|
|
6
|
-
projectsApi: ProjectsApi;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Create API instances with current authentication using setupAuthAndConfig
|
|
11
|
-
*/
|
|
12
|
-
export function createApis(): ApiInstances {
|
|
13
|
-
const authResult = setupAuthAndConfig();
|
|
14
|
-
if (!authResult) {
|
|
15
|
-
throw new Error('No authentication token found. Please log in first.');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
miscellaneousApi: new MiscellaneousApi(authResult.configuration),
|
|
20
|
-
projectsApi: new ProjectsApi(authResult.configuration),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import Table from "cli-table3";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
|
|
4
|
-
// Helper function to display images in a table
|
|
5
|
-
export function displayImagesTable(images: any[]): void {
|
|
6
|
-
const table = new Table({
|
|
7
|
-
head: [
|
|
8
|
-
chalk.white.bold('Name'),
|
|
9
|
-
chalk.white.bold('Type'),
|
|
10
|
-
chalk.white.bold('License'),
|
|
11
|
-
chalk.white.bold('Category'),
|
|
12
|
-
chalk.white.bold('Pricing'),
|
|
13
|
-
chalk.white.bold('Source')
|
|
14
|
-
],
|
|
15
|
-
style: {
|
|
16
|
-
head: [],
|
|
17
|
-
border: []
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// Add rows to the table
|
|
22
|
-
images.forEach((image: any) => {
|
|
23
|
-
table.push([
|
|
24
|
-
image.name || 'N/A',
|
|
25
|
-
image.type || 'N/A',
|
|
26
|
-
image.metadata?.License || 'N/A',
|
|
27
|
-
image.metadata?.Type || 'N/A',
|
|
28
|
-
image.metadata?.Pricing || 'N/A',
|
|
29
|
-
image.source || 'N/A'
|
|
30
|
-
]);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
console.log(table.toString());
|
|
34
|
-
}
|
|
@@ -1,61 +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 { resolveProject } from "../../utils/project";
|
|
6
|
-
import { createApis } from "./apiUtils";
|
|
7
|
-
import { displayImagesTable } from "./display";
|
|
8
|
-
|
|
9
|
-
export function registerListCommand(imageCommand: Command): void {
|
|
10
|
-
imageCommand
|
|
11
|
-
.command('list')
|
|
12
|
-
.description('List images for a project')
|
|
13
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)')
|
|
14
|
-
.action(async (options) => {
|
|
15
|
-
try {
|
|
16
|
-
const apis = createApis();
|
|
17
|
-
|
|
18
|
-
// Execute with token refresh support
|
|
19
|
-
await withTokenRefresh(
|
|
20
|
-
async () => {
|
|
21
|
-
// Resolve project using the shared utility
|
|
22
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
23
|
-
|
|
24
|
-
const spinner = ora(`Listing images for project ${project.name}...`).start();
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const response = await apis.miscellaneousApi.miscellaneousControllerGetData();
|
|
28
|
-
|
|
29
|
-
spinner.succeed('Successfully retrieved images');
|
|
30
|
-
|
|
31
|
-
const images: any = response.data;
|
|
32
|
-
|
|
33
|
-
if (!images || images.length === 0) {
|
|
34
|
-
console.log(chalk.yellow(`No images found for project ${project.name}.`));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Create and display the table
|
|
39
|
-
displayImagesTable(images);
|
|
40
|
-
|
|
41
|
-
} catch (error: any) {
|
|
42
|
-
spinner.fail('Failed to retrieve images');
|
|
43
|
-
if (error.response && error.response.status === 401) {
|
|
44
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
45
|
-
} else if (error.response) {
|
|
46
|
-
console.error(chalk.red('API Error:'), error.response.data?.message || 'Unknown error');
|
|
47
|
-
} else {
|
|
48
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
} catch (error: any) {
|
|
54
|
-
if (error.response && error.response.status === 401) {
|
|
55
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
56
|
-
} else {
|
|
57
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
package/src/commands/image.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { registerListCommand } from "./image/list";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Register all image-related commands
|
|
6
|
-
*/
|
|
7
|
-
export function registerImageCommands(program: Command): void {
|
|
8
|
-
// Create the main image command
|
|
9
|
-
const imageCommand = program
|
|
10
|
-
.command("image")
|
|
11
|
-
.description("Manage Nestbox images");
|
|
12
|
-
|
|
13
|
-
// Register all subcommands
|
|
14
|
-
registerListCommand(imageCommand);
|
|
15
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { readNestboxConfig, writeNestboxConfig } from "../../utils/config";
|
|
4
|
-
import { createApis } from "./apiUtils";
|
|
5
|
-
|
|
6
|
-
export function registerAddCommand(projectCommand: Command): void {
|
|
7
|
-
projectCommand
|
|
8
|
-
.command('add <project-name> [alias]')
|
|
9
|
-
.description('Add a project with optional alias')
|
|
10
|
-
.action((projectName: string, alias?: string) => {
|
|
11
|
-
try {
|
|
12
|
-
const apis = createApis();
|
|
13
|
-
|
|
14
|
-
const config = readNestboxConfig();
|
|
15
|
-
config.projects = config.projects || {};
|
|
16
|
-
|
|
17
|
-
// Check if the project already exists
|
|
18
|
-
if (config.projects[projectName]) {
|
|
19
|
-
console.error(chalk.red(`Project '${projectName}' already exists.`));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
// Check if the alias already exists
|
|
23
|
-
if (alias && config.projects[alias]) {
|
|
24
|
-
console.error(chalk.red(`Alias '${alias}' already exists.`));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (alias) {
|
|
29
|
-
config.projects[alias] = projectName;
|
|
30
|
-
console.log(chalk.green(`Added project '${projectName}' with alias '${alias}'`));
|
|
31
|
-
} else {
|
|
32
|
-
config.projects[projectName] = projectName;
|
|
33
|
-
console.log(chalk.green(`Added project '${projectName}'`));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// If this is the first project, set it as default
|
|
37
|
-
if (!config.projects.default) {
|
|
38
|
-
config.projects.default = projectName;
|
|
39
|
-
console.log(chalk.green(`Set '${projectName}' as the default project`));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
writeNestboxConfig(config);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error(chalk.red('Error adding project:'), error instanceof Error ? error.message : 'Unknown error');
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Configuration, ProjectsApi } from "@nestbox-ai/admin";
|
|
2
|
-
import { setupAuthAndConfig, type AuthResult } from "../../utils/api";
|
|
3
|
-
|
|
4
|
-
export interface ApiInstances {
|
|
5
|
-
projectsApi: ProjectsApi;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Create API instances with current authentication using setupAuthAndConfig
|
|
10
|
-
*/
|
|
11
|
-
export function createApis(): ApiInstances {
|
|
12
|
-
const authResult = setupAuthAndConfig();
|
|
13
|
-
if (!authResult) {
|
|
14
|
-
throw new Error('No authentication token found. Please log in first.');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
projectsApi: new ProjectsApi(authResult.configuration),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// Export utility functions that might be used by other modules
|
|
2
|
-
export { readNestboxConfig, writeNestboxConfig, getNestboxConfigPath } from "../../utils/config";
|
|
3
|
-
export type { ProjectsConfig, NestboxConfig } from "../../utils/config";
|
|
4
|
-
export { createApis } from "./apiUtils";
|
|
5
|
-
export type { ApiInstances } from "./apiUtils";
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { withTokenRefresh } from "../../utils/error";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import { readNestboxConfig } from "../../utils/config";
|
|
5
|
-
import { createApis } from "./apiUtils";
|
|
6
|
-
|
|
7
|
-
export function registerListCommand(projectCommand: Command): void {
|
|
8
|
-
projectCommand
|
|
9
|
-
.command('list')
|
|
10
|
-
.description('List all projects')
|
|
11
|
-
.action(async () => {
|
|
12
|
-
try {
|
|
13
|
-
const apis = createApis();
|
|
14
|
-
|
|
15
|
-
// Execute with token refresh support
|
|
16
|
-
await withTokenRefresh(
|
|
17
|
-
async () => {
|
|
18
|
-
// Get projects from API
|
|
19
|
-
const response = await apis.projectsApi.projectControllerGetAllProjects();
|
|
20
|
-
const apiProjects = response.data.data.projects;
|
|
21
|
-
|
|
22
|
-
if (!apiProjects || apiProjects.length === 0) {
|
|
23
|
-
console.log(chalk.yellow('No projects found.'));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Read local config to get default project and aliases
|
|
28
|
-
const config = readNestboxConfig();
|
|
29
|
-
const localProjects = config.projects || {};
|
|
30
|
-
const defaultProject = localProjects.default;
|
|
31
|
-
|
|
32
|
-
console.log(chalk.blue('Available Projects:'));
|
|
33
|
-
console.log(''); // Empty line for better formatting
|
|
34
|
-
|
|
35
|
-
// Display each project from the API
|
|
36
|
-
apiProjects.forEach((project: any) => {
|
|
37
|
-
const projectName = project.name;
|
|
38
|
-
const isDefault = defaultProject === projectName;
|
|
39
|
-
|
|
40
|
-
// Find aliases for this project
|
|
41
|
-
const aliases = Object.entries(localProjects)
|
|
42
|
-
.filter(([key, value]) => value === projectName && key !== 'default' && key !== projectName)
|
|
43
|
-
.map(([alias]) => alias);
|
|
44
|
-
|
|
45
|
-
// Build the display line
|
|
46
|
-
let displayLine = ` ${projectName}`;
|
|
47
|
-
|
|
48
|
-
if (aliases.length > 0) {
|
|
49
|
-
displayLine += chalk.gray(` (aliases: ${aliases.join(', ')})`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (isDefault) {
|
|
53
|
-
displayLine += chalk.green(' [DEFAULT]');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log(displayLine);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Show summary
|
|
60
|
-
console.log(''); // Empty line
|
|
61
|
-
if (defaultProject) {
|
|
62
|
-
console.log(chalk.gray(`Default project: ${defaultProject}`));
|
|
63
|
-
} else {
|
|
64
|
-
console.log(chalk.gray('No default project set. Use "nestbox project use <project-name>" to set one.'));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
} catch (error: any) {
|
|
69
|
-
if (error.message && error.message.includes('Authentication')) {
|
|
70
|
-
console.error(chalk.red(error.message));
|
|
71
|
-
} else if (error.message) {
|
|
72
|
-
console.error(chalk.red('Error listing projects:'), error.message);
|
|
73
|
-
} else {
|
|
74
|
-
console.error(chalk.red('Error listing projects:'), 'Unknown error');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { withTokenRefresh } from "../../utils/error";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import { readNestboxConfig, writeNestboxConfig } from "../../utils/config";
|
|
5
|
-
import { createApis } from "./apiUtils";
|
|
6
|
-
|
|
7
|
-
export function registerUseCommand(projectCommand: Command): void {
|
|
8
|
-
projectCommand
|
|
9
|
-
.command('use <project-name>')
|
|
10
|
-
.description('Set default project for all commands')
|
|
11
|
-
.action(async (projectName: string) => {
|
|
12
|
-
try {
|
|
13
|
-
const apis = createApis();
|
|
14
|
-
|
|
15
|
-
// Execute with token refresh support
|
|
16
|
-
await withTokenRefresh(
|
|
17
|
-
async () => {
|
|
18
|
-
const config = readNestboxConfig();
|
|
19
|
-
config.projects = config.projects || {};
|
|
20
|
-
config.projects.default = projectName;
|
|
21
|
-
|
|
22
|
-
// Check if the project exists
|
|
23
|
-
const response = await apis.projectsApi.projectControllerGetAllProjects();
|
|
24
|
-
const projectExists = response.data.data.projects.some((project: any) => project.name === projectName);
|
|
25
|
-
if (!projectExists) {
|
|
26
|
-
console.error(chalk.red(`Project '${projectName}' does not exist.`));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Write the configuration
|
|
31
|
-
writeNestboxConfig(config);
|
|
32
|
-
console.log(chalk.green(`Default project set to '${projectName}'`));
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
} catch (error: any) {
|
|
36
|
-
if (error.message && error.message.includes('Authentication')) {
|
|
37
|
-
console.error(chalk.red(error.message));
|
|
38
|
-
} else if (error.message) {
|
|
39
|
-
console.error(chalk.red('Error setting default project:'), error.message);
|
|
40
|
-
} else {
|
|
41
|
-
console.error(chalk.red('Error setting default project:'), 'Unknown error');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
package/src/commands/project.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { registerUseCommand } from "./project/use";
|
|
3
|
-
import { registerAddCommand } from "./project/add";
|
|
4
|
-
import { registerListCommand } from "./project/list";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Register all project-related commands
|
|
8
|
-
*/
|
|
9
|
-
export function registerProjectCommands(program: Command): void {
|
|
10
|
-
// Create the main project command
|
|
11
|
-
const projectCommand = program
|
|
12
|
-
.command("project")
|
|
13
|
-
.description("Manage Nestbox projects");
|
|
14
|
-
|
|
15
|
-
// Register all subcommands
|
|
16
|
-
registerUseCommand(projectCommand);
|
|
17
|
-
registerAddCommand(projectCommand);
|
|
18
|
-
registerListCommand(projectCommand);
|
|
19
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
5
|
-
import { join } from 'path';
|
|
6
|
-
import { registerAuthCommands } from './commands/auth';
|
|
7
|
-
import { registerProjectCommands } from './commands/project';
|
|
8
|
-
import { registerComputeProgram } from './commands/compute';
|
|
9
|
-
import { registerDocumentCommands } from './commands/document';
|
|
10
|
-
import { registerImageCommands } from './commands/image';
|
|
11
|
-
import { registerAgentCommands } from './commands/agent';
|
|
12
|
-
import { registerGenerateCommands } from './commands/generate';
|
|
13
|
-
|
|
14
|
-
// Read version from package.json
|
|
15
|
-
const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
|
|
16
|
-
|
|
17
|
-
// Setup the CLI program
|
|
18
|
-
const program = new Command();
|
|
19
|
-
program
|
|
20
|
-
.name('nestbox')
|
|
21
|
-
.description('CLI tool for the Nestbox AI platform')
|
|
22
|
-
.version(packageJson.version);
|
|
23
|
-
|
|
24
|
-
// Register command groups
|
|
25
|
-
registerAuthCommands(program);
|
|
26
|
-
registerProjectCommands(program);
|
|
27
|
-
registerComputeProgram(program);
|
|
28
|
-
registerAgentCommands(program);
|
|
29
|
-
registerGenerateCommands(program);
|
|
30
|
-
registerDocumentCommands(program);
|
|
31
|
-
registerImageCommands(program);
|
|
32
|
-
|
|
33
|
-
// Parse command line arguments
|
|
34
|
-
program.parse(process.argv);
|
|
35
|
-
|
|
36
|
-
// Only show help if no arguments were provided
|
|
37
|
-
if (process.argv.length === 2) {
|
|
38
|
-
program.help();
|
|
39
|
-
}
|