@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.
Files changed (100) hide show
  1. package/package.json +7 -1
  2. package/.github/workflows/generate-client.yml +0 -43
  3. package/.github/workflows/test.yml +0 -54
  4. package/.nestboxrc +0 -5
  5. package/src/commands/agent/apiUtils.ts +0 -113
  6. package/src/commands/agent/create.ts +0 -271
  7. package/src/commands/agent/deploy.ts +0 -523
  8. package/src/commands/agent/index.ts +0 -8
  9. package/src/commands/agent/list.ts +0 -104
  10. package/src/commands/agent/remove.ts +0 -103
  11. package/src/commands/agent/yaml-schema.ts +0 -57
  12. package/src/commands/agent.ts +0 -21
  13. package/src/commands/auth/index.ts +0 -3
  14. package/src/commands/auth/login.ts +0 -184
  15. package/src/commands/auth/logout.ts +0 -110
  16. package/src/commands/auth.ts +0 -12
  17. package/src/commands/compute/apiUtils.ts +0 -28
  18. package/src/commands/compute/create.ts +0 -195
  19. package/src/commands/compute/delete.ts +0 -147
  20. package/src/commands/compute/index.ts +0 -7
  21. package/src/commands/compute/list.ts +0 -117
  22. package/src/commands/compute.ts +0 -19
  23. package/src/commands/document/apiUtils.ts +0 -22
  24. package/src/commands/document/collectionCreate.ts +0 -46
  25. package/src/commands/document/collectionDelete.ts +0 -45
  26. package/src/commands/document/collectionGet.ts +0 -47
  27. package/src/commands/document/collectionList.ts +0 -52
  28. package/src/commands/document/collectionUpdate.ts +0 -53
  29. package/src/commands/document/docAdd.ts +0 -56
  30. package/src/commands/document/docDelete.ts +0 -47
  31. package/src/commands/document/docGet.ts +0 -49
  32. package/src/commands/document/docSearch.ts +0 -70
  33. package/src/commands/document/docUpdate.ts +0 -56
  34. package/src/commands/document/docUploadFile.ts +0 -55
  35. package/src/commands/document/index.ts +0 -17
  36. package/src/commands/document.ts +0 -48
  37. package/src/commands/generate/project.ts +0 -199
  38. package/src/commands/generate.ts +0 -15
  39. package/src/commands/image/apiUtils.ts +0 -22
  40. package/src/commands/image/display.ts +0 -34
  41. package/src/commands/image/index.ts +0 -4
  42. package/src/commands/image/list.ts +0 -61
  43. package/src/commands/image.ts +0 -15
  44. package/src/commands/project/add.ts +0 -47
  45. package/src/commands/project/apiUtils.ts +0 -20
  46. package/src/commands/project/index.ts +0 -5
  47. package/src/commands/project/list.ts +0 -78
  48. package/src/commands/project/use.ts +0 -45
  49. package/src/commands/project.ts +0 -19
  50. package/src/index.ts +0 -39
  51. package/src/types/agentType.ts +0 -7
  52. package/src/types/agentYaml.ts +0 -107
  53. package/src/types/auth.ts +0 -12
  54. package/src/types/statusMapping.ts +0 -8
  55. package/src/utils/agent.ts +0 -170
  56. package/src/utils/api.ts +0 -64
  57. package/src/utils/auth.ts +0 -140
  58. package/src/utils/config.ts +0 -37
  59. package/src/utils/error.ts +0 -168
  60. package/src/utils/plopGenerator.ts +0 -133
  61. package/src/utils/project.ts +0 -88
  62. package/src/utils/user.ts +0 -28
  63. package/src/utils/validation.ts +0 -22
  64. package/templates/base-js/index.js.hbs +0 -30
  65. package/templates/base-js/nestbox-agents.yaml.hbs +0 -12
  66. package/templates/base-js/package.json +0 -15
  67. package/templates/base-py/main.py.hbs +0 -42
  68. package/templates/base-py/nestbox-agents.yaml.hbs +0 -12
  69. package/templates/base-py/pyproject.toml +0 -19
  70. package/templates/base-ts/eslint.config.mjs +0 -27
  71. package/templates/base-ts/nestbox-agents.yaml.hbs +0 -12
  72. package/templates/base-ts/nestbox.config.json +0 -9
  73. package/templates/base-ts/package.json +0 -24
  74. package/templates/base-ts/src/index.ts.hbs +0 -29
  75. package/templates/base-ts/tsconfig.json +0 -14
  76. package/templates/chatbot-js/index.js.hbs +0 -18
  77. package/templates/chatbot-js/package-lock.json +0 -1571
  78. package/templates/chatbot-js/package.json +0 -15
  79. package/templates/chatbot-py/main.py.hbs +0 -42
  80. package/templates/chatbot-py/nestbox-agents.yaml.hbs +0 -12
  81. package/templates/chatbot-py/pyproject.toml +0 -19
  82. package/templates/chatbot-ts/eslint.config.mjs +0 -27
  83. package/templates/chatbot-ts/package.json +0 -24
  84. package/templates/chatbot-ts/src/index.ts.hbs +0 -18
  85. package/templates/chatbot-ts/tsconfig.json +0 -14
  86. package/test/README.md +0 -52
  87. package/test/agent.test.ts +0 -154
  88. package/test/auth.test.ts +0 -71
  89. package/test/compute.test.ts +0 -135
  90. package/test/document.test.ts +0 -217
  91. package/test/generate.test.ts +0 -67
  92. package/test/image.test.ts +0 -107
  93. package/test/mocks.ts +0 -122
  94. package/test/project.test.ts +0 -108
  95. package/test/setup.ts +0 -121
  96. package/tsconfig.json +0 -118
  97. package/vitest.config.d.ts +0 -2
  98. package/vitest.config.js +0 -23
  99. package/vitest.config.js.map +0 -1
  100. package/vitest.config.ts +0 -21
@@ -1,133 +0,0 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import nodePlop from "node-plop";
4
-
5
- export interface TemplateConfig {
6
- name: string;
7
- description: string;
8
- prompts: any[];
9
- actions: any[];
10
- }
11
-
12
- const kebabize = (str: string) =>
13
- str.replace(
14
- /[A-Z]+(?![a-z])|[A-Z]/g,
15
- ($, ofs) => (ofs ? "-" : "") + $.toLowerCase()
16
- );
17
-
18
- /**
19
- * Generate project using plop.js templates
20
- */
21
- export async function generateWithPlop(
22
- templateType: string,
23
- language: string,
24
- targetFolder: string,
25
- projectName?: string,
26
- agentName?: string
27
- ): Promise<{ agentNameInYaml: string }> {
28
- // Create the target directory
29
- if (!fs.existsSync(targetFolder)) {
30
- fs.mkdirSync(targetFolder, { recursive: true });
31
- }
32
-
33
- // Set up plop programmatically
34
- const plop = await nodePlop("", {
35
- destBasePath: targetFolder,
36
- force: false,
37
- });
38
-
39
- // Template mapping
40
- const templateMapping: Record<string, string> = {
41
- agent: "base",
42
- chatbot: "chatbot",
43
- };
44
-
45
- const mappedTemplateType = templateMapping[templateType] || templateType;
46
- const templatePath = path.resolve(
47
- __dirname,
48
- `../../templates/${mappedTemplateType}-${language}`
49
- );
50
-
51
- if (!fs.existsSync(templatePath)) {
52
- throw new Error(`Template not found: ${templatePath}`);
53
- }
54
-
55
- // Configure the generator
56
- const generatorName = `${mappedTemplateType}-${language}`;
57
-
58
- // Get the main template file path and target name
59
- const mainTemplateFile =
60
- language === "ts" ? "src/index.ts.hbs" : "index.js.hbs";
61
- const targetFileName = language === "ts" ? "src/index.ts" : "index.js";
62
-
63
- plop.setGenerator(generatorName, {
64
- description: `Generate a new ${mappedTemplateType} project in ${language}`,
65
- prompts: [],
66
- actions: [
67
- // Copy all non-template files
68
- {
69
- type: "addMany",
70
- destination: ".",
71
- base: templatePath,
72
- templateFiles: `${templatePath}/**/*`,
73
- globOptions: {
74
- dot: true,
75
- ignore: ["**/node_modules/**", "**/*.hbs"],
76
- },
77
- },
78
- {
79
- type: "add",
80
- path: targetFileName,
81
- templateFile: path.join(templatePath, mainTemplateFile),
82
- },
83
- {
84
- type: "add",
85
- path: "nestbox-agents.yaml",
86
- templateFile: path.join(templatePath, "nestbox-agents.yaml.hbs"),
87
- },
88
- ],
89
- });
90
-
91
- // Run the generator
92
- const generator = plop.getGenerator(generatorName);
93
- const agentNameFinal =
94
- agentName || (templateType === "agent" ? "myAgent" : "myChatbot");
95
- const agentNameInYaml = kebabize(agentNameFinal);
96
- await generator.runActions({
97
- name: projectName || path.basename(targetFolder),
98
- agentName: agentNameFinal,
99
- agentNameInYaml,
100
- });
101
-
102
- // Update package.json with project name if provided
103
- if (projectName) {
104
- const packageJsonPath = path.join(targetFolder, "package.json");
105
- if (fs.existsSync(packageJsonPath)) {
106
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
107
- packageJson.name = projectName;
108
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
109
- }
110
- }
111
-
112
- return {
113
- agentNameInYaml,
114
- }
115
- }
116
-
117
- /**
118
- * List available templates
119
- */
120
- export function listAvailableTemplates(): string[] {
121
- const templatesDir = path.resolve(__dirname, "../../templates");
122
- if (!fs.existsSync(templatesDir)) {
123
- return [];
124
- }
125
-
126
- return fs
127
- .readdirSync(templatesDir)
128
- .filter((item) => {
129
- const itemPath = path.join(templatesDir, item);
130
- return fs.statSync(itemPath).isDirectory();
131
- })
132
- .map((item) => item.replace(/\.(ts|js)$/, ""));
133
- }
@@ -1,88 +0,0 @@
1
- import { ProjectsApi } from "@nestbox-ai/admin";
2
- import ora from "ora";
3
- import { readNestboxConfig } from "./config";
4
-
5
- interface ProjectInfo {
6
- id: string;
7
- name: string;
8
- }
9
-
10
- interface CommandOptions {
11
- instance: string;
12
- project?: string;
13
- collection?: string;
14
- name?: string;
15
- metadata?: string;
16
- [key: string]: any;
17
- }
18
-
19
- interface ResolveProjectOptions extends CommandOptions {
20
- showSpinner?: boolean; // New option to control spinner visibility
21
- }
22
-
23
- export async function resolveProject(
24
- projectsApi: ProjectsApi,
25
- options: ResolveProjectOptions
26
- ): Promise<ProjectInfo> {
27
- // Default to showing spinner if not specified
28
- const showSpinner = options.showSpinner !== false;
29
- const spinner = showSpinner ? ora('Resolving project...').start() : null;
30
-
31
- try {
32
- const projectsResponse = await projectsApi.projectControllerGetAllProjects();
33
- const allProjects = projectsResponse.data?.data?.projects;
34
-
35
- if (!allProjects || allProjects.length === 0) {
36
- if (spinner) spinner.fail('No projects found.');
37
- throw new Error('No projects found');
38
- }
39
-
40
- let projectId = options.project;
41
- let projectName = '';
42
-
43
- if (projectId) {
44
- const byId = allProjects.find((p) => p.id === projectId);
45
- const byName = allProjects.find((p) => p.name === projectId);
46
-
47
- if (byId) {
48
- projectName = byId.name;
49
- projectId = byId.id;
50
- } else if (byName) {
51
- projectName = byName.name;
52
- projectId = byName.id;
53
- } else {
54
- if (spinner) spinner.fail(`Project not found with ID or name: ${projectId}`);
55
- throw new Error(`Project not found with ID or name: ${projectId}`);
56
- }
57
-
58
- if (spinner) spinner.succeed(`Using project: ${projectName} (ID: ${projectId})`);
59
- } else {
60
- const config = readNestboxConfig();
61
- const defaultProjectName = config.projects?.default;
62
-
63
- if (!defaultProjectName) {
64
- if (spinner) spinner.fail('No project specified and no default project set. Please provide a project ID or set a default project.');
65
- throw new Error('No project specified and no default project set');
66
- }
67
-
68
- const defaultProject = allProjects.find((p) => p.name === defaultProjectName);
69
-
70
- if (!defaultProject) {
71
- if (spinner) spinner.fail(`Default project "${defaultProjectName}" not found.`);
72
- throw new Error(`Default project "${defaultProjectName}" not found.`);
73
- }
74
-
75
- projectId = defaultProject.id;
76
- projectName = defaultProject.name;
77
- if (spinner) spinner.succeed(`Using default project: ${projectName} (ID: ${projectId})`);
78
- }
79
-
80
- return { id: projectId, name: projectName };
81
- } catch (error) {
82
- if (spinner && spinner.isSpinning) {
83
- // If spinner was already stopped with fail, we don't need to fail it again
84
- spinner.fail('Failed to resolve project');
85
- }
86
- throw error;
87
- }
88
- }
package/src/utils/user.ts DELETED
@@ -1,28 +0,0 @@
1
- import axios from "axios";
2
- import { getAuthToken } from "./auth";
3
-
4
- export async function userData() {
5
- try {
6
- const authData = getAuthToken();
7
-
8
- if (!authData || !authData.serverUrl || !authData.token) {
9
- throw new Error("No authentication data found. Please login first.");
10
- }
11
-
12
- const response = await axios.get(
13
- `${authData.serverUrl}/user/me`,
14
- {
15
- headers: {
16
- Authorization: `${authData.token}`,
17
- },
18
- }
19
- );
20
-
21
- return response.data;
22
- } catch (error: any) {
23
- console.error("Error fetching user data:", error.message || "Unknown error");
24
- if (error.response) {
25
- }
26
- throw error; // Rethrow to allow caller to handle the error
27
- }
28
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Validates if a string is a valid JavaScript/TypeScript function name
3
- */
4
- export function isValidFunctionName(name: string): boolean {
5
- // Check if it's a valid JavaScript identifier
6
- const validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
7
-
8
- // Check if it's not a reserved keyword
9
- const reservedKeywords = [
10
- 'abstract', 'arguments', 'await', 'boolean', 'break', 'byte', 'case', 'catch',
11
- 'char', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',
12
- 'double', 'else', 'enum', 'eval', 'export', 'extends', 'false', 'final',
13
- 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import',
14
- 'in', 'instanceof', 'int', 'interface', 'let', 'long', 'native', 'new',
15
- 'null', 'package', 'private', 'protected', 'public', 'return', 'short',
16
- 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws',
17
- 'transient', 'true', 'try', 'typeof', 'var', 'void', 'volatile', 'while',
18
- 'with', 'yield'
19
- ];
20
-
21
- return validIdentifierRegex.test(name) && !reservedKeywords.includes(name.toLowerCase());
22
- }
@@ -1,30 +0,0 @@
1
- var { useAgent } = require('@nestbox-ai/functions');
2
- var { OpenAI } = require('openai');
3
-
4
- const MODEL_NAME = 'openai/gpt-oss-20b';
5
-
6
- const client = new OpenAI({
7
- baseURL: 'http://localhost:8000/v1',
8
- apiKey: 'sk-xxxxxx'
9
- });
10
-
11
- var {{agentName}} = useAgent(async (context, events) => {
12
-
13
- const response = await client.chat.completions.create({
14
- model: MODEL_NAME,
15
- messages: [
16
- {
17
- role: "user",
18
- content: "Why is the sky blue?"
19
- }
20
- ]
21
- });
22
- const result = response.choices[0].message.content;
23
- if (!result) {
24
- events.emitQueryFailed({ data: { error: 'No response from model' } });
25
- } else {
26
- events.emitQueryCompleted({ data: result });
27
- }
28
- });
29
-
30
- module.exports = { {{agentName}} };
@@ -1,12 +0,0 @@
1
- agents:
2
- - name: {{ agentNameInYaml }}
3
- description: Our new agent {{ agentNameInYaml }} that uses the nestbox API
4
- entry: {{agentName}}
5
- inputSchema:
6
- type: object
7
- properties:
8
- content:
9
- type: string
10
- description: The content of the input as string
11
- minLength: 10
12
- maxLength: 5000
@@ -1,15 +0,0 @@
1
- {
2
- "name": "app",
3
- "version": "1.0.0",
4
- "main": "index.js",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
7
- },
8
- "author": "",
9
- "license": "ISC",
10
- "description": "",
11
- "dependencies": {
12
- "@nestbox-ai/functions": "^2.0.0",
13
- "openai": "^6.5.0"
14
- }
15
- }
@@ -1,42 +0,0 @@
1
- from nestbox_ai_functions import use_agent
2
- from openai import OpenAI
3
-
4
- MODEL_NAME = "openai/gpt-oss-20b"
5
-
6
- client = OpenAI(
7
- base_url="http://localhost:8000/v1",
8
- api_key="sk-xxxxxx"
9
- )
10
-
11
- @use_agent
12
- async def {{agentName}}(context, events):
13
- try:
14
- response = client.chat.completions.create(
15
- model=MODEL_NAME,
16
- messages=[
17
- {
18
- "role": "user",
19
- "content": "Why is the sky blue?"
20
- }
21
- ],
22
- )
23
-
24
- result = response.choices[0].message.content if response.choices else None
25
-
26
- if not result:
27
- await events.emitQueryFailed({
28
- "data": {
29
- "error": "No response from model"
30
- }
31
- })
32
- else:
33
- await events.emitQueryCompleted({
34
- "data": result
35
- })
36
-
37
- except Exception as e:
38
- await events.emitQueryFailed({
39
- "data": {
40
- "error": str(e)
41
- }
42
- })
@@ -1,12 +0,0 @@
1
- agents:
2
- - name: {{ agentNameInYaml }}
3
- description: Our new agent {{ agentNameInYaml }} that uses the nestbox API
4
- entry: {{agentName}}
5
- inputSchema:
6
- type: object
7
- properties:
8
- content:
9
- type: string
10
- description: The content of the input as string
11
- minLength: 10
12
- maxLength: 5000
@@ -1,19 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=61.0"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "app"
7
- version = "1.0.0"
8
- description = "Nestbox AI Python Agent"
9
- requires-python = ">=3.9"
10
-
11
- dependencies = [
12
- "nestbox-ai-functions>=2.0.3",
13
- "openai>=1.40.0",
14
- "httpx>=0.27.0",
15
- "anyio>=4.0.0"
16
- ]
17
-
18
- [tool.setuptools]
19
- packages = ["."]
@@ -1,27 +0,0 @@
1
- import tsParser from "@typescript-eslint/parser";
2
- import eslintPluginTs from "@typescript-eslint/eslint-plugin";
3
-
4
- export default [
5
- {
6
- files: ["**/*.ts"],
7
- languageOptions: {
8
- parser: tsParser,
9
- parserOptions: {
10
- ecmaVersion: "latest",
11
- sourceType: "module",
12
- },
13
- },
14
- plugins: {
15
- "@typescript-eslint": eslintPluginTs,
16
- },
17
- rules: {
18
- ...eslintPluginTs.configs.recommended.rules,
19
- // Optional custom rules:
20
- // '@typescript-eslint/no-explicit-any': 'warn',
21
- // '@typescript-eslint/explicit-function-return-type': 'off',
22
- },
23
- },
24
- {
25
- ignores: ["dist/", "node_modules/"],
26
- },
27
- ];
@@ -1,12 +0,0 @@
1
- agents:
2
- - name: {{ agentNameInYaml }}
3
- description: Our new agent {{ agentNameInYaml }} that uses the nestbox API
4
- entry: {{agentName}}
5
- inputSchema:
6
- type: object
7
- properties:
8
- content:
9
- type: string
10
- description: The content of the input as string
11
- minLength: 10
12
- maxLength: 5000
@@ -1,9 +0,0 @@
1
- {
2
- "agents": {
3
- "predeploy": [
4
- "rm -rf dist",
5
- "npm run lint",
6
- "npm run build"
7
- ]
8
- }
9
- }
@@ -1,24 +0,0 @@
1
- {
2
- "name": "app-ts",
3
- "version": "1.0.0",
4
- "main": "dist/index.js",
5
- "scripts": {
6
- "build": "tsc",
7
- "start": "node dist/index.js",
8
- "dev": "ts-node src/index.ts",
9
- "lint": "eslint ."
10
- },
11
- "author": "",
12
- "license": "ISC",
13
- "description": "",
14
- "dependencies": {
15
- "@nestbox-ai/functions": "^2.0.0",
16
- "openai": "^6.5.0"
17
- },
18
- "devDependencies": {
19
- "@typescript-eslint/eslint-plugin": "^8.31.0",
20
- "@typescript-eslint/parser": "^8.31.0",
21
- "eslint": "^9.25.1",
22
- "typescript": "^5.8.3"
23
- }
24
- }
@@ -1,29 +0,0 @@
1
- import { AgentContext, AgentEvents, useAgent } from "@nestbox-ai/functions";
2
- import OpenAI from 'openai';
3
-
4
- const MODEL_NAME = 'openai/gpt-oss-20b';
5
-
6
- const client = new OpenAI({
7
- baseURL: 'http://localhost:8000/v1',
8
- apiKey: 'sk-xxxxxx'
9
- });
10
-
11
- export const {{agentName}} = useAgent(
12
- async (context: AgentContext, events: AgentEvents) => {
13
- const response = await client.chat.completions.create({
14
- model: MODEL_NAME,
15
- messages: [
16
- {
17
- role: "user",
18
- content: "Why is the sky blue?"
19
- }
20
- ]
21
- });
22
- const result = response.choices[0].message.content;
23
- if (!result) {
24
- events.emitQueryFailed({ data: { error: 'No response from model' } });
25
- } else {
26
- events.emitQueryCompleted({ data: result });
27
- }
28
- }
29
- );
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
4
- "module": "commonjs", /* Specify what module code is generated. */
5
- "rootDir": "./src",
6
- "outDir": "./dist",
7
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
8
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
9
- "strict": true, /* Enable all strict type-checking options. */
10
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
11
- },
12
- "include": ["src"],
13
- "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"],
14
- }
@@ -1,18 +0,0 @@
1
- var { useChatbot } = require('@nestbox-ai/functions');
2
- var { Ollama } = require('ollama');
3
-
4
- const ollama = new Ollama()
5
-
6
- var {{agentName}} = useChatbot(async (context, events) => {
7
-
8
- const response = await ollama.chat({
9
- messages: context.messages,
10
- model: 'gemma3:27b',
11
- stream: false,
12
- });
13
- const result = response.message.content;
14
-
15
- events.emitQueryCompleted({ data: result });
16
- });
17
-
18
- module.exports = { {{agentName}} };