@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,52 +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 registerCollectionListCommand(collectionCommand: Command): void {
|
|
9
|
-
const listCmd = collectionCommand
|
|
10
|
-
.command('list')
|
|
11
|
-
.description('List document collections for a specific instance')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
14
|
-
|
|
15
|
-
listCmd.action(async (options) => {
|
|
16
|
-
await withTokenRefresh(async () => {
|
|
17
|
-
const apis = createDocumentApis();
|
|
18
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
19
|
-
|
|
20
|
-
const spinner = ora(`Listing document collections for instance ${options.instance} in project ${project.name}...`).start();
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const response: any = await apis.documentsApi.documentControllerGetAllCollections(project.id, options.instance);
|
|
24
|
-
const collections = Array.isArray(response.data?.collections) ? response.data.collections : [];
|
|
25
|
-
|
|
26
|
-
spinner.succeed('Successfully retrieved document collections');
|
|
27
|
-
|
|
28
|
-
if (collections.length === 0) {
|
|
29
|
-
console.log(chalk.yellow(`No document collections found for instance ${options.instance} in project ${project.name}`));
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
console.log(chalk.blue(`\nDocument collections for instance ${options.instance} in project ${project.name}:\n`));
|
|
34
|
-
|
|
35
|
-
collections.forEach((collection: any) => {
|
|
36
|
-
const name = typeof collection === 'string' ? collection : collection?.name || 'Unnamed Collection';
|
|
37
|
-
console.log(chalk.white.bold(name));
|
|
38
|
-
});
|
|
39
|
-
} catch (error: any) {
|
|
40
|
-
spinner.fail('Operation failed');
|
|
41
|
-
if (error.response && error.response.status === 401) {
|
|
42
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
43
|
-
} else if (error.response?.data?.message) {
|
|
44
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
45
|
-
} else {
|
|
46
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
47
|
-
}
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
@@ -1,53 +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 registerCollectionUpdateCommand(collectionCommand: Command): void {
|
|
9
|
-
const updateCmd = collectionCommand
|
|
10
|
-
.command('update')
|
|
11
|
-
.description('Update a document collection for a specific instance')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'ID of the document collection to update')
|
|
14
|
-
.option('--name <name>', 'New name of the document collection')
|
|
15
|
-
.option('--metadata <json>', 'New metadata for the document collection in JSON format')
|
|
16
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
17
|
-
|
|
18
|
-
updateCmd.action(async (options) => {
|
|
19
|
-
await withTokenRefresh(async () => {
|
|
20
|
-
const apis = createDocumentApis();
|
|
21
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
22
|
-
|
|
23
|
-
const spinner = ora(`Updating document collection "${options.collection}" for instance ${options.instance} in project ${project.name}...`).start();
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const metadataObj = options.metadata ? JSON.parse(options.metadata) : {};
|
|
27
|
-
|
|
28
|
-
await apis.documentsApi.documentControllerUpdateCollection(
|
|
29
|
-
project.id,
|
|
30
|
-
options.instance,
|
|
31
|
-
options.collection,
|
|
32
|
-
{
|
|
33
|
-
name: options.name,
|
|
34
|
-
metadata: metadataObj,
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
spinner.succeed('Successfully updated document collection');
|
|
39
|
-
console.log(chalk.green(`Document collection "${options.collection}" updated successfully.`));
|
|
40
|
-
} catch (error: any) {
|
|
41
|
-
spinner.fail('Operation failed');
|
|
42
|
-
if (error.response && error.response.status === 401) {
|
|
43
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
44
|
-
} else if (error.response?.data?.message) {
|
|
45
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
46
|
-
} else {
|
|
47
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
48
|
-
}
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
@@ -1,56 +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 registerDocAddCommand(docCommand: Command): void {
|
|
9
|
-
const addDocCmd = docCommand
|
|
10
|
-
.command('add')
|
|
11
|
-
.description('Add a new document to a collection')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'Collection ID')
|
|
14
|
-
.requiredOption('--id <id>', 'Document ID')
|
|
15
|
-
.requiredOption('--document <json>', 'Document content in JSON format')
|
|
16
|
-
.option('--metadata <json>', 'Document metadata in JSON format (optional)')
|
|
17
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
18
|
-
|
|
19
|
-
addDocCmd.action(async (options) => {
|
|
20
|
-
await withTokenRefresh(async () => {
|
|
21
|
-
const apis = createDocumentApis();
|
|
22
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
23
|
-
|
|
24
|
-
const spinner = ora(`Adding document to collection "${options.collection}" in instance ${options.instance}...`).start();
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const documentContent = JSON.parse(options.document);
|
|
28
|
-
const metadata = options.metadata ? JSON.parse(options.metadata) : {};
|
|
29
|
-
|
|
30
|
-
await apis.documentsApi.documentControllerAddDocToCollection(
|
|
31
|
-
project.id,
|
|
32
|
-
options.instance,
|
|
33
|
-
options.collection,
|
|
34
|
-
{
|
|
35
|
-
id: options.id,
|
|
36
|
-
document: JSON.stringify(documentContent),
|
|
37
|
-
metadata: metadata
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
spinner.succeed('Successfully added document to collection');
|
|
42
|
-
console.log(chalk.green(`Document with ID "${options.id}" added successfully to collection "${options.collection}".`));
|
|
43
|
-
} catch (error: any) {
|
|
44
|
-
spinner.fail('Operation failed');
|
|
45
|
-
if (error.response && error.response.status === 401) {
|
|
46
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
47
|
-
} else if (error.response?.data?.message) {
|
|
48
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
49
|
-
} else {
|
|
50
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
51
|
-
}
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
@@ -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 registerDocDeleteCommand(docCommand: Command): void {
|
|
9
|
-
const deleteDocCmd = docCommand
|
|
10
|
-
.command('delete')
|
|
11
|
-
.description('Delete a document from a collection')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'Collection ID')
|
|
14
|
-
.requiredOption('--doc <docId>', 'Document ID')
|
|
15
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
16
|
-
|
|
17
|
-
deleteDocCmd.action(async (options) => {
|
|
18
|
-
await withTokenRefresh(async () => {
|
|
19
|
-
const apis = createDocumentApis();
|
|
20
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
21
|
-
|
|
22
|
-
const spinner = ora(`Deleting document "${options.doc}" from collection "${options.collection}" in instance ${options.instance}...`).start();
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
await apis.documentsApi.documentControllerDeleteDocById(
|
|
26
|
-
project.id,
|
|
27
|
-
options.instance,
|
|
28
|
-
options.collection,
|
|
29
|
-
options.doc
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
spinner.succeed('Successfully deleted document');
|
|
33
|
-
console.log(chalk.green(`Document with ID "${options.doc}" deleted successfully from collection "${options.collection}".`));
|
|
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
|
-
}
|
|
@@ -1,49 +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 registerDocGetCommand(docCommand: Command): void {
|
|
9
|
-
const getDocCmd = docCommand
|
|
10
|
-
.command('get')
|
|
11
|
-
.description('Get a document from a collection')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'Collection ID')
|
|
14
|
-
.requiredOption('--doc <docId>', 'Document ID')
|
|
15
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
16
|
-
|
|
17
|
-
getDocCmd.action(async (options) => {
|
|
18
|
-
await withTokenRefresh(async () => {
|
|
19
|
-
const apis = createDocumentApis();
|
|
20
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
21
|
-
|
|
22
|
-
const spinner = ora(`Getting document "${options.doc}" from collection "${options.collection}" in instance ${options.instance}...`).start();
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const response = await apis.documentsApi.documentControllerGetDocById(
|
|
26
|
-
project.id,
|
|
27
|
-
options.instance,
|
|
28
|
-
options.collection,
|
|
29
|
-
options.doc
|
|
30
|
-
);
|
|
31
|
-
const document = response.data;
|
|
32
|
-
|
|
33
|
-
spinner.succeed('Successfully retrieved document');
|
|
34
|
-
console.log(chalk.blue(`\nDocument details for ID "${options.doc}" in collection "${options.collection}":\n`));
|
|
35
|
-
console.log(JSON.stringify(document, null, 2));
|
|
36
|
-
} catch (error: any) {
|
|
37
|
-
spinner.fail('Operation failed');
|
|
38
|
-
if (error.response && error.response.status === 401) {
|
|
39
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
40
|
-
} else if (error.response?.data?.message) {
|
|
41
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
42
|
-
} else {
|
|
43
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
44
|
-
}
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
@@ -1,70 +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 registerDocSearchCommand(docCommand: Command): void {
|
|
9
|
-
const searchCmd = docCommand
|
|
10
|
-
.command('search')
|
|
11
|
-
.description('Search for documents in a collection')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'Collection ID')
|
|
14
|
-
.requiredOption('--query <query>', 'Search query')
|
|
15
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)')
|
|
16
|
-
.option('--filter <json>', 'Filter criteria as JSON string');
|
|
17
|
-
|
|
18
|
-
searchCmd.action(async (options) => {
|
|
19
|
-
await withTokenRefresh(async () => {
|
|
20
|
-
const apis = createDocumentApis();
|
|
21
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
22
|
-
|
|
23
|
-
// Build the request body
|
|
24
|
-
const requestBody = {
|
|
25
|
-
query: options.query,
|
|
26
|
-
params: {},
|
|
27
|
-
filter: {},
|
|
28
|
-
include: ["embedding"]
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// Parse filter JSON if provided
|
|
32
|
-
if (options.filter) {
|
|
33
|
-
try {
|
|
34
|
-
requestBody.filter = JSON.parse(options.filter);
|
|
35
|
-
} catch (e: any) {
|
|
36
|
-
console.error(chalk.red('Error parsing filter JSON:'), e.message);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
console.log("REQUEST BODY", requestBody);
|
|
42
|
-
|
|
43
|
-
const spinner = ora(`Searching for documents in collection "${options.collection}" in instance ${options.instance}...`).start();
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
const response = await apis.documentsApi.documentControllerSimilaritySearch(
|
|
47
|
-
project.id,
|
|
48
|
-
options.instance,
|
|
49
|
-
options.collection,
|
|
50
|
-
requestBody
|
|
51
|
-
);
|
|
52
|
-
const results = response.data;
|
|
53
|
-
|
|
54
|
-
spinner.succeed('Successfully retrieved search results');
|
|
55
|
-
console.log(chalk.blue(`\nSearch results for query "${options.query}" in collection "${options.collection}":\n`));
|
|
56
|
-
console.log(JSON.stringify(results, null, 2));
|
|
57
|
-
} catch (error: any) {
|
|
58
|
-
spinner.fail('Operation failed');
|
|
59
|
-
if (error.response && error.response.status === 401) {
|
|
60
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
61
|
-
} else if (error.response?.data?.message) {
|
|
62
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
63
|
-
} else {
|
|
64
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
65
|
-
}
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
@@ -1,56 +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 registerDocUpdateCommand(docCommand: Command): void {
|
|
9
|
-
const updateDocCmd = docCommand
|
|
10
|
-
.command('update')
|
|
11
|
-
.description('Update a document in a collection')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'Collection ID')
|
|
14
|
-
.requiredOption('--doc <docId>', 'Document ID')
|
|
15
|
-
.requiredOption('--document <string>', 'Updated document content as a string')
|
|
16
|
-
.option('--metadata <json>', 'Updated document metadata in JSON format (optional)')
|
|
17
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
18
|
-
|
|
19
|
-
updateDocCmd.action(async (options) => {
|
|
20
|
-
await withTokenRefresh(async () => {
|
|
21
|
-
const apis = createDocumentApis();
|
|
22
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
23
|
-
|
|
24
|
-
const spinner = ora(`Updating document "${options.doc}" in collection "${options.collection}" in instance ${options.instance}...`).start();
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const documentContent = options.document;
|
|
28
|
-
const metadata = options.metadata ? JSON.parse(options.metadata) : {};
|
|
29
|
-
|
|
30
|
-
await apis.documentsApi.documentControllerUpdateDoc(
|
|
31
|
-
project.id,
|
|
32
|
-
options.instance,
|
|
33
|
-
options.collection,
|
|
34
|
-
options.doc,
|
|
35
|
-
{
|
|
36
|
-
document: documentContent,
|
|
37
|
-
metadata: metadata
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
spinner.succeed('Successfully updated document');
|
|
42
|
-
console.log(chalk.green(`Document with ID "${options.doc}" updated successfully in collection "${options.collection}".`));
|
|
43
|
-
} catch (error: any) {
|
|
44
|
-
spinner.fail('Operation failed');
|
|
45
|
-
if (error.response && error.response.status === 401) {
|
|
46
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
47
|
-
} else if (error.response?.data?.message) {
|
|
48
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
49
|
-
} else {
|
|
50
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
51
|
-
}
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
@@ -1,55 +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 registerDocUploadFileCommand(docCommand: Command): void {
|
|
9
|
-
const uploadFileCmd = docCommand
|
|
10
|
-
.command('upload-file')
|
|
11
|
-
.description('Add documents by file chunking')
|
|
12
|
-
.requiredOption('--instance <instanceId>', 'Instance ID')
|
|
13
|
-
.requiredOption('--collection <collectionId>', 'Collection ID')
|
|
14
|
-
.requiredOption('--file <path>', 'Path to the file to upload')
|
|
15
|
-
.option('--type <fileType>', 'Type of the file (e.g., pdf, txt, doc)')
|
|
16
|
-
.option('--options <json>', 'Additional options for file processing in JSON format')
|
|
17
|
-
.option('--project <projectId>', 'Project ID or name (defaults to the current project)');
|
|
18
|
-
|
|
19
|
-
uploadFileCmd.action(async (options) => {
|
|
20
|
-
await withTokenRefresh(async () => {
|
|
21
|
-
const apis = createDocumentApis();
|
|
22
|
-
const project = await resolveProject(apis.projectsApi, options);
|
|
23
|
-
|
|
24
|
-
const spinner = ora(`Processing file "${options.file}" for collection "${options.collection}" in instance ${options.instance}...`).start();
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const requestData = {
|
|
28
|
-
type: options.type,
|
|
29
|
-
url: options.file,
|
|
30
|
-
options: options.options ? JSON.parse(options.options) : {},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
await apis.documentsApi.documentControllerAddDocToCollectionFromFile(
|
|
34
|
-
project.id,
|
|
35
|
-
options.instance,
|
|
36
|
-
options.collection,
|
|
37
|
-
requestData
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
spinner.succeed('Successfully processed file for document chunking');
|
|
41
|
-
console.log(chalk.green(`File "${options.file}" processed successfully for collection "${options.collection}".`));
|
|
42
|
-
} catch (error: any) {
|
|
43
|
-
spinner.fail('Operation failed');
|
|
44
|
-
if (error.response && error.response.status === 401) {
|
|
45
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
46
|
-
} else if (error.response?.data?.message) {
|
|
47
|
-
console.error(chalk.red('API Error:'), error.response.data.message);
|
|
48
|
-
} else {
|
|
49
|
-
console.error(chalk.red('Error:'), error.message || 'Unknown error');
|
|
50
|
-
}
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Collection commands
|
|
2
|
-
export { registerCollectionListCommand } from './collectionList';
|
|
3
|
-
export { registerCollectionCreateCommand } from './collectionCreate';
|
|
4
|
-
export { registerCollectionGetCommand } from './collectionGet';
|
|
5
|
-
export { registerCollectionDeleteCommand } from './collectionDelete';
|
|
6
|
-
export { registerCollectionUpdateCommand } from './collectionUpdate';
|
|
7
|
-
|
|
8
|
-
// Document commands
|
|
9
|
-
export { registerDocAddCommand } from './docAdd';
|
|
10
|
-
export { registerDocGetCommand } from './docGet';
|
|
11
|
-
export { registerDocDeleteCommand } from './docDelete';
|
|
12
|
-
export { registerDocUpdateCommand } from './docUpdate';
|
|
13
|
-
export { registerDocUploadFileCommand } from './docUploadFile';
|
|
14
|
-
export { registerDocSearchCommand } from './docSearch';
|
|
15
|
-
|
|
16
|
-
// API utilities
|
|
17
|
-
export { createDocumentApis, type DocumentApiInstances } from './apiUtils';
|
package/src/commands/document.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import {
|
|
3
|
-
registerCollectionListCommand,
|
|
4
|
-
registerCollectionCreateCommand,
|
|
5
|
-
registerCollectionGetCommand,
|
|
6
|
-
registerCollectionDeleteCommand,
|
|
7
|
-
registerCollectionUpdateCommand,
|
|
8
|
-
registerDocAddCommand,
|
|
9
|
-
registerDocGetCommand,
|
|
10
|
-
registerDocDeleteCommand,
|
|
11
|
-
registerDocUpdateCommand,
|
|
12
|
-
registerDocUploadFileCommand,
|
|
13
|
-
registerDocSearchCommand
|
|
14
|
-
} from "./document/index";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Register all document-related commands
|
|
18
|
-
*/
|
|
19
|
-
export function registerDocumentCommands(program: Command): void {
|
|
20
|
-
// Create the main document command
|
|
21
|
-
const documentCommand = program
|
|
22
|
-
.command("document")
|
|
23
|
-
.description("Manage Nestbox documents");
|
|
24
|
-
|
|
25
|
-
// Create subcommands for collections and docs
|
|
26
|
-
const collectionCommand = documentCommand
|
|
27
|
-
.command("collection")
|
|
28
|
-
.description("Manage document collections");
|
|
29
|
-
|
|
30
|
-
const docCommand = documentCommand
|
|
31
|
-
.command("doc")
|
|
32
|
-
.description("Manage individual documents");
|
|
33
|
-
|
|
34
|
-
// Register all collection subcommands
|
|
35
|
-
registerCollectionListCommand(collectionCommand);
|
|
36
|
-
registerCollectionCreateCommand(collectionCommand);
|
|
37
|
-
registerCollectionGetCommand(collectionCommand);
|
|
38
|
-
registerCollectionDeleteCommand(collectionCommand);
|
|
39
|
-
registerCollectionUpdateCommand(collectionCommand);
|
|
40
|
-
|
|
41
|
-
// Register all document subcommands
|
|
42
|
-
registerDocAddCommand(docCommand);
|
|
43
|
-
registerDocGetCommand(docCommand);
|
|
44
|
-
registerDocDeleteCommand(docCommand);
|
|
45
|
-
registerDocUpdateCommand(docCommand);
|
|
46
|
-
registerDocUploadFileCommand(docCommand);
|
|
47
|
-
registerDocSearchCommand(docCommand);
|
|
48
|
-
}
|