@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,195 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import { resolveProject } from "../../utils/project";
|
|
5
|
-
import { createComputeApis } from "./apiUtils";
|
|
6
|
-
import inquirer from "inquirer";
|
|
7
|
-
import axios from "axios";
|
|
8
|
-
import { userData } from "../../utils/user";
|
|
9
|
-
|
|
10
|
-
export function registerCreateCommand(computeCommand: Command): void {
|
|
11
|
-
computeCommand
|
|
12
|
-
.command('create')
|
|
13
|
-
.description('Create a new compute instance')
|
|
14
|
-
.requiredOption('--image <imageId>', 'Image ID to use for the compute instance')
|
|
15
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)')
|
|
16
|
-
.action(async (options) => {
|
|
17
|
-
try {
|
|
18
|
-
const apis = createComputeApis();
|
|
19
|
-
if (!apis) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const { miscellaneousApi, projectsApi, authToken } = apis;
|
|
24
|
-
|
|
25
|
-
// Resolve project using the shared utility
|
|
26
|
-
const project = await resolveProject(projectsApi, options);
|
|
27
|
-
|
|
28
|
-
const spinner = ora(`Fetching available images...`).start();
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
// Get available images data
|
|
32
|
-
const response = await miscellaneousApi.miscellaneousControllerGetData();
|
|
33
|
-
const availableImages: any = response.data || [];
|
|
34
|
-
|
|
35
|
-
// Find the selected image
|
|
36
|
-
const selectedImage = availableImages.find((image: any) => image.id === options.image);
|
|
37
|
-
|
|
38
|
-
if (!selectedImage) {
|
|
39
|
-
spinner.fail(`Image ID '${options.image}' does not exist.`);
|
|
40
|
-
console.log(chalk.yellow('Available image IDs:'));
|
|
41
|
-
availableImages.forEach((img: any) => {
|
|
42
|
-
console.log(` ${chalk.cyan(img.id)} - ${img.name} (${img.type})`);
|
|
43
|
-
});
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
spinner.succeed(`Found image: ${selectedImage.name}`);
|
|
48
|
-
|
|
49
|
-
// Ask for instance name first
|
|
50
|
-
const instanceNameAnswer = await inquirer.prompt([
|
|
51
|
-
{
|
|
52
|
-
type: 'input',
|
|
53
|
-
name: 'instanceName',
|
|
54
|
-
message: 'Enter a name for this compute instance:',
|
|
55
|
-
validate: (input: string) => {
|
|
56
|
-
if (!input || input.trim() === '') {
|
|
57
|
-
return 'Instance name cannot be empty';
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
]);
|
|
63
|
-
|
|
64
|
-
const instanceName = instanceNameAnswer.instanceName;
|
|
65
|
-
|
|
66
|
-
// Directly create the provisioningParams object with the structure needed for API
|
|
67
|
-
let provisioningParams: Record<string, any> = {};
|
|
68
|
-
|
|
69
|
-
if (selectedImage.provisioningParameters &&
|
|
70
|
-
selectedImage.provisioningParameters.properties) {
|
|
71
|
-
|
|
72
|
-
const requiredParams = selectedImage.provisioningParameters.required || [];
|
|
73
|
-
const paramProperties = selectedImage.provisioningParameters.properties;
|
|
74
|
-
|
|
75
|
-
// Build questions for inquirer
|
|
76
|
-
const questions = [];
|
|
77
|
-
|
|
78
|
-
for (const [paramName, paramConfig] of Object.entries(paramProperties) as any) {
|
|
79
|
-
const isRequired = requiredParams.includes(paramName);
|
|
80
|
-
const paramUI = selectedImage.provisioningParametersUI?.[paramName] || {};
|
|
81
|
-
|
|
82
|
-
let question: any = {
|
|
83
|
-
name: paramName,
|
|
84
|
-
message: paramUI['ui:title'] || `Enter ${paramName}:`,
|
|
85
|
-
when: isRequired // Only ask required params by default
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// Handle different parameter types
|
|
89
|
-
if (paramConfig.type === 'string') {
|
|
90
|
-
if (paramConfig.enum) {
|
|
91
|
-
question.type = 'list';
|
|
92
|
-
question.choices = paramConfig.enum;
|
|
93
|
-
} else if (paramUI['ui:widget'] === 'password') {
|
|
94
|
-
question.type = 'password';
|
|
95
|
-
} else {
|
|
96
|
-
question.type = 'input';
|
|
97
|
-
}
|
|
98
|
-
} else if (paramConfig.type === 'array') {
|
|
99
|
-
if (paramConfig.items && paramConfig.items.enum) {
|
|
100
|
-
question.type = 'checkbox';
|
|
101
|
-
question.choices = paramConfig.items.enum;
|
|
102
|
-
// Ensure at least one option is selected for required array parameters
|
|
103
|
-
question.validate = (input: any[]) => {
|
|
104
|
-
if (isRequired && (!input || input.length === 0)) {
|
|
105
|
-
return 'Please select at least one option';
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (paramUI['ui:help']) {
|
|
113
|
-
question.message += ` (${paramUI['ui:help']})`;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
questions.push(question);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (questions.length > 0) {
|
|
120
|
-
console.log(chalk.blue(`\nPlease provide the required parameters for ${selectedImage.name}:`));
|
|
121
|
-
const answers = await inquirer.prompt(questions);
|
|
122
|
-
|
|
123
|
-
// Assign the answers directly to provisioningParams
|
|
124
|
-
for (const [key, value] of Object.entries(answers)) {
|
|
125
|
-
provisioningParams[key] = value;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Now we have all the required params in provisioningParams
|
|
131
|
-
console.log(chalk.green(`\nCreating compute instance '${instanceName}' with image '${selectedImage.name}'`));
|
|
132
|
-
console.log(chalk.dim('Using the following parameters:'));
|
|
133
|
-
|
|
134
|
-
for (const [key, value] of Object.entries(provisioningParams)) {
|
|
135
|
-
console.log(chalk.dim(` ${key}: ${Array.isArray(value) ? value.join(', ') : value}`));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Start a spinner for the creation process
|
|
139
|
-
const creationSpinner = ora('Creating compute instance...').start();
|
|
140
|
-
|
|
141
|
-
const getUserData = await userData();
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
const createParams = {
|
|
145
|
-
userId: getUserData.id,
|
|
146
|
-
machineId: selectedImage.id,
|
|
147
|
-
machineTitle: selectedImage.name,
|
|
148
|
-
instanceName: instanceName,
|
|
149
|
-
...provisioningParams
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const createResponse = await axios.post(
|
|
153
|
-
`${authToken.serverUrl}/projects/${project.id}/instances`,
|
|
154
|
-
createParams,
|
|
155
|
-
{
|
|
156
|
-
headers: {
|
|
157
|
-
Authorization: authToken.token,
|
|
158
|
-
},
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
creationSpinner.succeed('Compute instance created successfully!');
|
|
162
|
-
|
|
163
|
-
console.log(chalk.green(`\nInstance '${instanceName}' is now being provisioned`));
|
|
164
|
-
console.log(chalk.gray('You can check the status with: nestbox compute list'));
|
|
165
|
-
console.log(chalk.green("Instance created successfully!"));
|
|
166
|
-
} catch (createError: any) {
|
|
167
|
-
creationSpinner.fail('Failed to create compute instance');
|
|
168
|
-
if (createError.response && createError.response.status === 401) {
|
|
169
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
170
|
-
} else if (createError.response) {
|
|
171
|
-
console.error(chalk.red('API Error:'), createError.response.data?.message || 'Unknown error');
|
|
172
|
-
} else {
|
|
173
|
-
console.error(chalk.red('Error:'), createError.message || 'Unknown error');
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
} catch (error: any) {
|
|
178
|
-
spinner.fail('Failed to fetch available images');
|
|
179
|
-
if (error.response && error.response.status === 401) {
|
|
180
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
181
|
-
} else if (error.response) {
|
|
182
|
-
console.error(chalk.red('API Error:'), error.response.data?.message || 'Unknown error');
|
|
183
|
-
} else {
|
|
184
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} catch (error: any) {
|
|
188
|
-
if (error.response && error.response.status === 401) {
|
|
189
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
190
|
-
} else {
|
|
191
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import { resolveProject } from "../../utils/project";
|
|
5
|
-
import { createComputeApis } from "./apiUtils";
|
|
6
|
-
import inquirer from "inquirer";
|
|
7
|
-
import axios from "axios";
|
|
8
|
-
|
|
9
|
-
export function registerDeleteCommand(computeCommand: Command): void {
|
|
10
|
-
computeCommand
|
|
11
|
-
.command('delete')
|
|
12
|
-
.description('Delete one or more compute instances')
|
|
13
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)')
|
|
14
|
-
.option('--force', 'Skip confirmation prompt')
|
|
15
|
-
.action(async (options) => {
|
|
16
|
-
try {
|
|
17
|
-
const apis = createComputeApis();
|
|
18
|
-
if (!apis) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const { machineInstanceApi, projectsApi, authToken } = apis;
|
|
23
|
-
|
|
24
|
-
// Resolve project using the shared utility
|
|
25
|
-
const project = await resolveProject(projectsApi, options);
|
|
26
|
-
|
|
27
|
-
const spinner = ora(`Fetching compute instances for project: ${project.name}`).start();
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
// Fetch machine instances for the project
|
|
31
|
-
const instancesResponse: any = await machineInstanceApi.machineInstancesControllerGetMachineInstanceByUserId(
|
|
32
|
-
project.id,
|
|
33
|
-
0, // page
|
|
34
|
-
50 // limit - increased to show more instances
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
spinner.succeed('Successfully retrieved compute instances');
|
|
38
|
-
|
|
39
|
-
const instances = instancesResponse.data?.machineInstances || [];
|
|
40
|
-
|
|
41
|
-
if (instances.length === 0) {
|
|
42
|
-
console.log(chalk.yellow('No compute instances found for this project.'));
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Create choices for the selection prompt
|
|
47
|
-
const instanceChoices = instances.map((instance: any) => ({
|
|
48
|
-
name: `${instance.instanceName || 'Unnamed'} (${instance.id})`,
|
|
49
|
-
value: instance.id,
|
|
50
|
-
short: instance.instanceName || instance.id
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
// Prompt user to select instances to delete
|
|
54
|
-
const { selectedInstances } = await inquirer.prompt([
|
|
55
|
-
{
|
|
56
|
-
type: 'checkbox',
|
|
57
|
-
name: 'selectedInstances',
|
|
58
|
-
message: 'Select compute instances to delete:',
|
|
59
|
-
choices: instanceChoices,
|
|
60
|
-
validate: (input) => {
|
|
61
|
-
if (input.length === 0) {
|
|
62
|
-
return 'Please select at least one instance to delete';
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
]);
|
|
68
|
-
|
|
69
|
-
if (selectedInstances.length === 0) {
|
|
70
|
-
console.log(chalk.yellow('No instances selected for deletion.'));
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Show selected instances
|
|
75
|
-
console.log(chalk.yellow('\nSelected instances for deletion:'));
|
|
76
|
-
const selectedInstanceDetails = instances
|
|
77
|
-
.filter((instance: any) => selectedInstances.includes(instance.id))
|
|
78
|
-
.map((instance: any) => ` - ${chalk.cyan(instance.instanceName || 'Unnamed')} (${instance.id})`);
|
|
79
|
-
|
|
80
|
-
console.log(selectedInstanceDetails.join('\n'));
|
|
81
|
-
|
|
82
|
-
// Confirm deletion if not using --force
|
|
83
|
-
if (!options.force) {
|
|
84
|
-
const { confirmDeletion } = await inquirer.prompt([
|
|
85
|
-
{
|
|
86
|
-
type: 'confirm',
|
|
87
|
-
name: 'confirmDeletion',
|
|
88
|
-
message: chalk.red('Are you sure you want to delete these instances? This cannot be undone.'),
|
|
89
|
-
default: false
|
|
90
|
-
}
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
if (!confirmDeletion) {
|
|
94
|
-
console.log(chalk.yellow('Deletion cancelled.'));
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Process deletion - using single request with all selected IDs
|
|
100
|
-
const deleteSpinner = ora(`Deleting ${selectedInstances.length} instance(s)...`).start();
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
await axios.delete(
|
|
104
|
-
`${authToken.serverUrl}/projects/${project.id}/instances`,
|
|
105
|
-
{
|
|
106
|
-
data: { ids: selectedInstances },
|
|
107
|
-
headers: {
|
|
108
|
-
Authorization: authToken.token,
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
deleteSpinner.succeed(`Successfully deleted ${selectedInstances.length} instance(s)`);
|
|
114
|
-
|
|
115
|
-
console.log(chalk.green('\nAll selected instances have been deleted'));
|
|
116
|
-
console.log(chalk.gray('You can verify with: nestbox compute list'));
|
|
117
|
-
|
|
118
|
-
} catch (error: any) {
|
|
119
|
-
deleteSpinner.fail(`Failed to delete instances`);
|
|
120
|
-
if (error.response && error.response.status === 401) {
|
|
121
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
122
|
-
} else if (error.response) {
|
|
123
|
-
console.error(chalk.red('API Error:'), error.response.data?.message || 'Unknown error');
|
|
124
|
-
} else {
|
|
125
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
} catch (error: any) {
|
|
130
|
-
spinner.fail('Failed to retrieve compute instances');
|
|
131
|
-
if (error.response && error.response.status === 401) {
|
|
132
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
133
|
-
} else if (error.response) {
|
|
134
|
-
console.error(chalk.red('API Error:'), error.response.data?.message || 'Unknown error');
|
|
135
|
-
} else {
|
|
136
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
} catch (error: any) {
|
|
140
|
-
if (error.response && error.response.status === 401) {
|
|
141
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
142
|
-
} else {
|
|
143
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Compute command exports
|
|
2
|
-
export { registerListCommand } from "./list";
|
|
3
|
-
export { registerCreateCommand } from "./create";
|
|
4
|
-
export { registerDeleteCommand } from "./delete";
|
|
5
|
-
|
|
6
|
-
// API utilities
|
|
7
|
-
export { createComputeApis, type ComputeApiInstances } from "./apiUtils";
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import Table from "cli-table3";
|
|
5
|
-
import { resolveProject } from "../../utils/project";
|
|
6
|
-
import { createComputeApis } from "./apiUtils";
|
|
7
|
-
import { statusMappings } from "../../types/statusMapping";
|
|
8
|
-
|
|
9
|
-
export function registerListCommand(computeCommand: Command): void {
|
|
10
|
-
computeCommand
|
|
11
|
-
.command('list')
|
|
12
|
-
.description('List all compute instances')
|
|
13
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)')
|
|
14
|
-
.action(async (options) => {
|
|
15
|
-
try {
|
|
16
|
-
const apis = createComputeApis();
|
|
17
|
-
if (!apis) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const { machineInstanceApi, projectsApi } = apis;
|
|
22
|
-
|
|
23
|
-
// Resolve project using the shared utility
|
|
24
|
-
const project = await resolveProject(projectsApi, options);
|
|
25
|
-
|
|
26
|
-
const spinner = ora(`Fetching compute instances for project: ${project.name}`).start();
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
// Fetch machine instances for the project
|
|
30
|
-
const instancesResponse: any = await machineInstanceApi.machineInstancesControllerGetMachineInstanceByUserId(
|
|
31
|
-
project.id,
|
|
32
|
-
0, // page
|
|
33
|
-
10 // limit
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
spinner.succeed('Successfully retrieved compute instances');
|
|
37
|
-
|
|
38
|
-
const instances = instancesResponse.data?.machineInstances || [];
|
|
39
|
-
|
|
40
|
-
if (instances.length === 0) {
|
|
41
|
-
console.log(chalk.yellow('No compute instances found for this project.'));
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Create table for display
|
|
46
|
-
const table = new Table({
|
|
47
|
-
head: [
|
|
48
|
-
chalk.white.bold('ID'),
|
|
49
|
-
chalk.white.bold('Name'),
|
|
50
|
-
chalk.white.bold('Status'),
|
|
51
|
-
chalk.white.bold('API Key')
|
|
52
|
-
],
|
|
53
|
-
style: {
|
|
54
|
-
head: [], // Disable the default styling
|
|
55
|
-
border: []
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Add rows to the table
|
|
60
|
-
instances.forEach((instance: any) => {
|
|
61
|
-
// Map the status if a mapping exists
|
|
62
|
-
const originalStatus = instance.runningStatus || 'unknown';
|
|
63
|
-
const displayStatus = statusMappings[originalStatus] || originalStatus;
|
|
64
|
-
|
|
65
|
-
// Color the status based on its mapped value
|
|
66
|
-
let statusColor;
|
|
67
|
-
|
|
68
|
-
switch(displayStatus.toLowerCase()) {
|
|
69
|
-
case 'ready':
|
|
70
|
-
statusColor = chalk.green(displayStatus);
|
|
71
|
-
break;
|
|
72
|
-
case 'failed':
|
|
73
|
-
statusColor = chalk.red(displayStatus);
|
|
74
|
-
break;
|
|
75
|
-
case 'initializing':
|
|
76
|
-
statusColor = chalk.yellow(displayStatus);
|
|
77
|
-
break;
|
|
78
|
-
case 'scheduled':
|
|
79
|
-
statusColor = chalk.blue(displayStatus);
|
|
80
|
-
break;
|
|
81
|
-
case 'deleting':
|
|
82
|
-
statusColor = chalk.red(displayStatus);
|
|
83
|
-
break;
|
|
84
|
-
default:
|
|
85
|
-
statusColor = chalk.gray(displayStatus);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
table.push([
|
|
89
|
-
instance.id || 'N/A',
|
|
90
|
-
instance.instanceName || 'N/A',
|
|
91
|
-
statusColor,
|
|
92
|
-
instance.instanceApiKey || 'N/A'
|
|
93
|
-
]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Display the table
|
|
97
|
-
console.log(table.toString());
|
|
98
|
-
|
|
99
|
-
} catch (error: any) {
|
|
100
|
-
spinner.fail('Failed to retrieve compute instances');
|
|
101
|
-
if (error.response && error.response.status === 401) {
|
|
102
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
103
|
-
} else if (error.response) {
|
|
104
|
-
console.error(chalk.red('API Error:'), error.response.data?.message || 'Unknown error');
|
|
105
|
-
} else {
|
|
106
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
} catch (error: any) {
|
|
110
|
-
if (error.response && error.response.status === 401) {
|
|
111
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
112
|
-
} else {
|
|
113
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
package/src/commands/compute.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { registerListCommand } from "./compute/list";
|
|
3
|
-
import { registerCreateCommand } from "./compute/create";
|
|
4
|
-
import { registerDeleteCommand } from "./compute/delete";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Register all compute-related commands
|
|
8
|
-
*/
|
|
9
|
-
export function registerComputeProgram(program: Command): void {
|
|
10
|
-
// Create the main compute command
|
|
11
|
-
const computeCommand = program
|
|
12
|
-
.command('compute')
|
|
13
|
-
.description('Manage Nestbox computes');
|
|
14
|
-
|
|
15
|
-
// Register all subcommands
|
|
16
|
-
registerListCommand(computeCommand);
|
|
17
|
-
registerCreateCommand(computeCommand);
|
|
18
|
-
registerDeleteCommand(computeCommand);
|
|
19
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DocumentsApi, ProjectsApi } from "@nestbox-ai/admin";
|
|
2
|
-
import { setupAuthAndConfig } from "../../utils/api";
|
|
3
|
-
|
|
4
|
-
export interface DocumentApiInstances {
|
|
5
|
-
documentsApi: DocumentsApi;
|
|
6
|
-
projectsApi: ProjectsApi;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Create API instances with current authentication using setupAuthAndConfig
|
|
11
|
-
*/
|
|
12
|
-
export function createDocumentApis(): DocumentApiInstances {
|
|
13
|
-
const authResult = setupAuthAndConfig();
|
|
14
|
-
if (!authResult) {
|
|
15
|
-
throw new Error('No authentication token found. Please log in first.');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
documentsApi: new DocumentsApi(authResult.configuration),
|
|
20
|
-
projectsApi: new ProjectsApi(authResult.configuration)
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,46 +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 { createDocumentApis } from "./apiUtils";
|
|
7
|
-
|
|
8
|
-
export function registerCollectionCreateCommand(collectionCommand: Command): void {
|
|
9
|
-
const createCmd = collectionCommand
|
|
10
|
-
.command('create')
|
|
11
|
-
.description('Create a new document collection for a specific instance')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--name <name>', 'Name of the document collection')
|
|
14
|
-
.option('--metadata <json>', 'Metadata for the document collection in JSON format')
|
|
15
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
16
|
-
|
|
17
|
-
createCmd.action(async (options) => {
|
|
18
|
-
await withTokenRefresh(async () => {
|
|
19
|
-
const apis = createDocumentApis();
|
|
20
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
21
|
-
|
|
22
|
-
const spinner = ora(`Creating document collection "${options.name}" for instance ${options.instance} in project ${project.name}...`).start();
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const metadataObj = options.metadata ? JSON.parse(options.metadata) : {};
|
|
26
|
-
await apis.documentsApi.documentControllerCreateCollection(project.id, options.instance, {
|
|
27
|
-
name: options.name,
|
|
28
|
-
metadata: metadataObj,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
spinner.succeed('Successfully created document collection');
|
|
32
|
-
console.log(chalk.green(`Document collection "${options.name}" created successfully.`));
|
|
33
|
-
} catch (error: any) {
|
|
34
|
-
spinner.fail('Operation failed');
|
|
35
|
-
if (error.response && error.response.status === 401) {
|
|
36
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
37
|
-
} else if (error.response?.data?.message) {
|
|
38
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
39
|
-
} else {
|
|
40
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
41
|
-
}
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
@@ -1,45 +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 { createDocumentApis } from "./apiUtils";
|
|
7
|
-
|
|
8
|
-
export function registerCollectionDeleteCommand(collectionCommand: Command): void {
|
|
9
|
-
const deleteCmd = collectionCommand
|
|
10
|
-
.command('delete')
|
|
11
|
-
.description('Delete a document collection for a specific instance')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'ID of the document collection to delete')
|
|
14
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
15
|
-
|
|
16
|
-
deleteCmd.action(async (options) => {
|
|
17
|
-
await withTokenRefresh(async () => {
|
|
18
|
-
const apis = createDocumentApis();
|
|
19
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
20
|
-
|
|
21
|
-
const spinner = ora(`Deleting document collection "${options.collection}" for instance ${options.instance} in project ${project.name}...`).start();
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
await apis.documentsApi.documentControllerDeleteCollection(
|
|
25
|
-
project.id,
|
|
26
|
-
options.instance,
|
|
27
|
-
options.collection
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
spinner.succeed('Successfully deleted document collection');
|
|
31
|
-
console.log(chalk.green(`Document collection "${options.collection}" deleted successfully.`));
|
|
32
|
-
} catch (error: any) {
|
|
33
|
-
spinner.fail('Operation failed');
|
|
34
|
-
if (error.response && error.response.status === 401) {
|
|
35
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
36
|
-
} else if (error.response?.data?.message) {
|
|
37
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
38
|
-
} else {
|
|
39
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
@@ -1,47 +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 { createDocumentApis } from "./apiUtils";
|
|
7
|
-
|
|
8
|
-
export function registerCollectionGetCommand(collectionCommand: Command): void {
|
|
9
|
-
const getCmd = collectionCommand
|
|
10
|
-
.command('get')
|
|
11
|
-
.description('Get details of a specific document collection for a specific instance')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'ID of the document collection to get')
|
|
14
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
15
|
-
|
|
16
|
-
getCmd.action(async (options) => {
|
|
17
|
-
await withTokenRefresh(async () => {
|
|
18
|
-
const apis = createDocumentApis();
|
|
19
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
20
|
-
|
|
21
|
-
const spinner = ora(`Getting document collection "${options.collection}" for instance ${options.instance} in project ${project.name}...`).start();
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
const response = await apis.documentsApi.documentControllerGetCollectionInfo(
|
|
25
|
-
project.id,
|
|
26
|
-
options.instance,
|
|
27
|
-
options.collection
|
|
28
|
-
);
|
|
29
|
-
const collectionDetails = response.data;
|
|
30
|
-
|
|
31
|
-
spinner.succeed('Successfully retrieved document collection');
|
|
32
|
-
console.log(chalk.blue(`\nDocument collection details for instance ${options.instance} in project ${project.name}:\n`));
|
|
33
|
-
console.log(JSON.stringify(collectionDetails, null, 2));
|
|
34
|
-
} catch (error: any) {
|
|
35
|
-
spinner.fail('Operation failed');
|
|
36
|
-
if (error.response && error.response.status === 401) {
|
|
37
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
38
|
-
} else if (error.response?.data?.message) {
|
|
39
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
40
|
-
} else {
|
|
41
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
42
|
-
}
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|