@nestbox-ai/cli 1.0.48 → 1.0.50
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 +6 -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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestbox-ai/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.50",
|
|
4
4
|
"description": "The cli tools that helps developers to build agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
"coverage": "vitest run --coverage",
|
|
18
18
|
"clean": "rimraf dist"
|
|
19
19
|
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"GETTING_STARTED.md"
|
|
24
|
+
],
|
|
20
25
|
"repository": {
|
|
21
26
|
"type": "git",
|
|
22
27
|
"url": "git+https://github.com/NestboxAI/nestbox-ai-cli-tools.git"
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
name: Test, Build and Publish Nestbox AI CLI Tools
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
|
|
8
|
-
permissions:
|
|
9
|
-
id-token: write
|
|
10
|
-
contents: write
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
test-and-publish:
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v4
|
|
18
|
-
|
|
19
|
-
- name: Setup Node.js
|
|
20
|
-
uses: actions/setup-node@v4
|
|
21
|
-
with:
|
|
22
|
-
node-version: '20'
|
|
23
|
-
cache: 'npm'
|
|
24
|
-
|
|
25
|
-
- name: Upgrade npm (required for OIDC)
|
|
26
|
-
run: npm install -g npm@latest
|
|
27
|
-
|
|
28
|
-
- name: Install dependencies
|
|
29
|
-
run: npm install --prefer-offline --no-audit
|
|
30
|
-
|
|
31
|
-
- name: Run tests
|
|
32
|
-
run: npm run test:ci
|
|
33
|
-
|
|
34
|
-
- name: Update package version
|
|
35
|
-
run: |
|
|
36
|
-
new_version="1.0.${{ github.run_number }}"
|
|
37
|
-
jq ".version = \"$new_version\"" package.json > temp.json && mv temp.json package.json
|
|
38
|
-
|
|
39
|
-
- name: Build project
|
|
40
|
-
run: npm run build
|
|
41
|
-
|
|
42
|
-
- name: Publish to npm
|
|
43
|
-
run: npm publish --access public --provenance
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
name: Test Nestbox AI CLI Tools
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches-ignore:
|
|
6
|
-
- main
|
|
7
|
-
pull_request:
|
|
8
|
-
branches:
|
|
9
|
-
- main
|
|
10
|
-
|
|
11
|
-
permissions:
|
|
12
|
-
contents: read
|
|
13
|
-
|
|
14
|
-
jobs:
|
|
15
|
-
test:
|
|
16
|
-
runs-on: ubuntu-latest
|
|
17
|
-
|
|
18
|
-
steps:
|
|
19
|
-
- uses: actions/checkout@v4
|
|
20
|
-
|
|
21
|
-
- name: Setup Node.js
|
|
22
|
-
uses: actions/setup-node@v4
|
|
23
|
-
with:
|
|
24
|
-
node-version: '20'
|
|
25
|
-
cache: 'npm'
|
|
26
|
-
|
|
27
|
-
- name: Install dependencies
|
|
28
|
-
run: |
|
|
29
|
-
npm install --prefer-offline --no-audit
|
|
30
|
-
|
|
31
|
-
- name: Install platform-specific dependencies
|
|
32
|
-
run: |
|
|
33
|
-
# Install Linux-specific Rollup binary for vitest
|
|
34
|
-
npm install @rollup/rollup-linux-x64-gnu --no-save || echo "Warning: Could not install platform-specific Rollup binary"
|
|
35
|
-
continue-on-error: true
|
|
36
|
-
|
|
37
|
-
- name: Verify installation
|
|
38
|
-
run: |
|
|
39
|
-
npm list vitest --depth=0
|
|
40
|
-
node --version
|
|
41
|
-
npm --version
|
|
42
|
-
|
|
43
|
-
- name: Run tests
|
|
44
|
-
run: |
|
|
45
|
-
echo "Running tests..."
|
|
46
|
-
echo "Node.js version: $(node --version)"
|
|
47
|
-
echo "NPM version: $(npm --version)"
|
|
48
|
-
echo "Checking if vitest is available..."
|
|
49
|
-
npx vitest --version || echo "Vitest not found via npx"
|
|
50
|
-
npm run test:ci
|
|
51
|
-
echo "All tests passed! ✅"
|
|
52
|
-
|
|
53
|
-
- name: Build project
|
|
54
|
-
run: npm run build
|
package/.nestboxrc
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MachineAgentApi,
|
|
3
|
-
MachineInstancesApi,
|
|
4
|
-
ProjectsApi,
|
|
5
|
-
} from "@nestbox-ai/admin";
|
|
6
|
-
import { setupAuthAndConfig } from "../../utils/api";
|
|
7
|
-
import fs from "fs/promises";
|
|
8
|
-
import path from "path";
|
|
9
|
-
import yaml from "js-yaml";
|
|
10
|
-
import Ajv from "ajv";
|
|
11
|
-
import { yamlSchema } from "./yaml-schema";
|
|
12
|
-
|
|
13
|
-
export interface ApiInstances {
|
|
14
|
-
agentsApi: MachineAgentApi;
|
|
15
|
-
projectsApi: ProjectsApi;
|
|
16
|
-
instanceApi: MachineInstancesApi;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Create API instances with current authentication using setupAuthAndConfig
|
|
21
|
-
*/
|
|
22
|
-
export function createApis(): ApiInstances {
|
|
23
|
-
const authResult = setupAuthAndConfig();
|
|
24
|
-
if (!authResult) {
|
|
25
|
-
throw new Error("No authentication token found. Please log in first.");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
agentsApi: new MachineAgentApi(authResult.configuration),
|
|
30
|
-
projectsApi: new ProjectsApi(authResult.configuration),
|
|
31
|
-
instanceApi: new MachineInstancesApi(authResult.configuration),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const ajv = new Ajv({ strict: false });
|
|
36
|
-
const validate = ajv.compile(yamlSchema);
|
|
37
|
-
|
|
38
|
-
export type ManifestAgent = {
|
|
39
|
-
name: string;
|
|
40
|
-
description: string;
|
|
41
|
-
entry: string;
|
|
42
|
-
type?: "REGULAR" | "CHATBOT" | "WORKFLOW";
|
|
43
|
-
inputSchema: {
|
|
44
|
-
type: "object";
|
|
45
|
-
properties: Record<
|
|
46
|
-
string,
|
|
47
|
-
{
|
|
48
|
-
type: string;
|
|
49
|
-
description?: string;
|
|
50
|
-
default?: string | number | boolean | null;
|
|
51
|
-
}
|
|
52
|
-
>;
|
|
53
|
-
required?: string[];
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export type ManifestFile = { agents: ManifestAgent[] };
|
|
58
|
-
|
|
59
|
-
export async function loadAgentFromYaml(
|
|
60
|
-
agentName: string
|
|
61
|
-
): Promise<ManifestAgent | undefined> {
|
|
62
|
-
const file = path.join(process.cwd(), "nestbox-agents.yaml");
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
await fs.access(file);
|
|
66
|
-
} catch (err: any) {
|
|
67
|
-
if (err?.code === "ENOENT") return undefined;
|
|
68
|
-
throw new Error(`cannot access nestbox-agents.yaml: ${err.message}`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const raw = await fs.readFile(file, "utf8");
|
|
72
|
-
const doc = yaml.load(raw) as unknown;
|
|
73
|
-
|
|
74
|
-
if (!validate(doc)) {
|
|
75
|
-
const msg = ajv.errorsText(validate.errors, { separator: "\n- " });
|
|
76
|
-
throw new Error(`invalid nestbox-agents.yaml:\n- ${msg}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const mf = doc as ManifestFile;
|
|
80
|
-
return mf.agents.find(a => a?.name === agentName);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export async function loadAllAgentNamesFromYaml(): Promise<string[]> {
|
|
84
|
-
const file = path.join(process.cwd(), "nestbox-agents.yaml");
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
await fs.access(file);
|
|
88
|
-
} catch (err: any) {
|
|
89
|
-
if (err?.code === "ENOENT") return [];
|
|
90
|
-
throw new Error(`cannot access nestbox-agents.yaml: ${err.message}`);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const raw = await fs.readFile(file, "utf8");
|
|
94
|
-
const doc = yaml.load(raw) as unknown;
|
|
95
|
-
|
|
96
|
-
if (!validate(doc)) {
|
|
97
|
-
const msg = ajv.errorsText(validate.errors, { separator: "\n- " });
|
|
98
|
-
throw new Error(`invalid nestbox-agents.yaml:\n- ${msg}`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const mf = doc as ManifestFile;
|
|
102
|
-
const names = Array.isArray(mf?.agents)
|
|
103
|
-
? (mf.agents.map(a => a?.name).filter(Boolean) as string[])
|
|
104
|
-
: [];
|
|
105
|
-
|
|
106
|
-
// de-duplicate by name, keep first occurrence
|
|
107
|
-
const seen = new Set<string>();
|
|
108
|
-
return names.filter(n => {
|
|
109
|
-
if (seen.has(n)) return false;
|
|
110
|
-
seen.add(n);
|
|
111
|
-
return true;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { resolveProject } from "../../utils/project";
|
|
4
|
-
import { loadNestboxConfig } from "../../utils/agent";
|
|
5
|
-
import {
|
|
6
|
-
createApis,
|
|
7
|
-
loadAgentFromYaml,
|
|
8
|
-
loadAllAgentNamesFromYaml,
|
|
9
|
-
} from "./apiUtils";
|
|
10
|
-
|
|
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;
|
|
97
|
-
}
|
|
98
|
-
|
|
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
|
-
});
|
|
271
|
-
}
|