@nestbox-ai/cli 1.0.32 → 1.0.34
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/dist/commands/agent/generate.js +46 -35
- package/dist/commands/agent/generate.js.map +1 -1
- package/dist/utils/agent.d.ts +0 -2
- package/dist/utils/agent.js +0 -37
- package/dist/utils/agent.js.map +1 -1
- package/dist/utils/plopGenerator.d.ts +14 -0
- package/dist/utils/plopGenerator.js +104 -0
- package/dist/utils/plopGenerator.js.map +1 -0
- package/dist/utils/validation.d.ts +4 -0
- package/dist/utils/validation.js +24 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +4 -2
- package/src/commands/agent/generate.ts +48 -41
- package/src/utils/agent.ts +0 -37
- package/src/utils/plopGenerator.ts +111 -0
- package/src/utils/validation.ts +22 -0
- package/templates/base-js/index.js.hbs +17 -0
- package/templates/base-js/package.json +15 -0
- package/templates/base-ts/eslint.config.mjs +27 -0
- package/templates/base-ts/package.json +24 -0
- package/templates/base-ts/src/index.ts.hbs +16 -0
- package/templates/base-ts/tsconfig.json +14 -0
- package/templates/chatbot-js/index.js.hbs +18 -0
- package/templates/chatbot-js/package-lock.json +1571 -0
- package/templates/chatbot-js/package.json +15 -0
- package/templates/chatbot-ts/eslint.config.mjs +27 -0
- package/templates/chatbot-ts/package.json +24 -0
- package/templates/chatbot-ts/src/index.ts.hbs +18 -0
- package/templates/chatbot-ts/tsconfig.json +14 -0
- package/templates/template-base-js.zip +0 -0
- package/templates/template-base-ts.zip +0 -0
- package/templates/template-chatbot-js.zip +0 -0
- package/templates/template-chatbot-ts.zip +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import nodePlop from 'node-plop';
|
|
5
|
+
|
|
6
|
+
export interface TemplateConfig {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
prompts: any[];
|
|
10
|
+
actions: any[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generate project using plop.js templates
|
|
15
|
+
*/
|
|
16
|
+
export async function generateWithPlop(
|
|
17
|
+
templateType: string,
|
|
18
|
+
language: string,
|
|
19
|
+
targetFolder: string,
|
|
20
|
+
projectName?: string,
|
|
21
|
+
agentName?: string
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
// Create the target directory
|
|
24
|
+
if (!fs.existsSync(targetFolder)) {
|
|
25
|
+
fs.mkdirSync(targetFolder, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Set up plop programmatically
|
|
29
|
+
const plop = await nodePlop('', {
|
|
30
|
+
destBasePath: targetFolder,
|
|
31
|
+
force: false
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Template mapping
|
|
35
|
+
const templateMapping: Record<string, string> = {
|
|
36
|
+
'agent': 'base',
|
|
37
|
+
'chatbot': 'chatbot'
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const mappedTemplateType = templateMapping[templateType] || templateType;
|
|
41
|
+
const templatePath = path.resolve(__dirname, `../../templates/${mappedTemplateType}-${language}`);
|
|
42
|
+
|
|
43
|
+
if (!fs.existsSync(templatePath)) {
|
|
44
|
+
throw new Error(`Template not found: ${templatePath}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Configure the generator
|
|
48
|
+
const generatorName = `${mappedTemplateType}-${language}`;
|
|
49
|
+
|
|
50
|
+
// Get the main template file path and target name
|
|
51
|
+
const mainTemplateFile = language === 'ts' ? 'src/index.ts.hbs' : 'index.js.hbs';
|
|
52
|
+
const targetFileName = language === 'ts' ? 'src/index.ts' : 'index.js';
|
|
53
|
+
|
|
54
|
+
plop.setGenerator(generatorName, {
|
|
55
|
+
description: `Generate a new ${mappedTemplateType} project in ${language}`,
|
|
56
|
+
prompts: [],
|
|
57
|
+
actions: [
|
|
58
|
+
// Copy all non-template files
|
|
59
|
+
{
|
|
60
|
+
type: 'addMany',
|
|
61
|
+
destination: '.',
|
|
62
|
+
base: templatePath,
|
|
63
|
+
templateFiles: `${templatePath}/**/*`,
|
|
64
|
+
globOptions: {
|
|
65
|
+
dot: true,
|
|
66
|
+
ignore: ['**/node_modules/**', '**/*.hbs']
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
// Add the main template file with proper naming
|
|
70
|
+
{
|
|
71
|
+
type: 'add',
|
|
72
|
+
path: targetFileName,
|
|
73
|
+
templateFile: path.join(templatePath, mainTemplateFile)
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Run the generator
|
|
79
|
+
const generator = plop.getGenerator(generatorName);
|
|
80
|
+
await generator.runActions({
|
|
81
|
+
name: projectName || path.basename(targetFolder),
|
|
82
|
+
agentName: agentName || (templateType === 'agent' ? 'myAgent' : 'myChatbot')
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Update package.json with project name if provided
|
|
86
|
+
if (projectName) {
|
|
87
|
+
const packageJsonPath = path.join(targetFolder, 'package.json');
|
|
88
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
89
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
90
|
+
packageJson.name = projectName;
|
|
91
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* List available templates
|
|
98
|
+
*/
|
|
99
|
+
export function listAvailableTemplates(): string[] {
|
|
100
|
+
const templatesDir = path.resolve(__dirname, '../../templates');
|
|
101
|
+
if (!fs.existsSync(templatesDir)) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return fs.readdirSync(templatesDir)
|
|
106
|
+
.filter(item => {
|
|
107
|
+
const itemPath = path.join(templatesDir, item);
|
|
108
|
+
return fs.statSync(itemPath).isDirectory();
|
|
109
|
+
})
|
|
110
|
+
.map(item => item.replace(/\.(ts|js)$/, ''));
|
|
111
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var { useAgent } = require('@nestbox-ai/functions');
|
|
2
|
+
var { Ollama } = require('ollama');
|
|
3
|
+
|
|
4
|
+
const ollama = new Ollama()
|
|
5
|
+
|
|
6
|
+
var {{agentName}} = useAgent(async (context, events) => {
|
|
7
|
+
|
|
8
|
+
const response = await ollama.generate({
|
|
9
|
+
prompt: 'Why is the sky blue?',
|
|
10
|
+
model: 'gemma3:27b',
|
|
11
|
+
});
|
|
12
|
+
const result = response.response;
|
|
13
|
+
|
|
14
|
+
events.emitQueryCompleted({ data: result });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
module.exports = { {{agentName}} };
|
|
@@ -0,0 +1,15 @@
|
|
|
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": "^1.0.0",
|
|
13
|
+
"ollama": "^0.5.14"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
];
|
|
@@ -0,0 +1,24 @@
|
|
|
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": "^1.0.16",
|
|
16
|
+
"ollama": "^0.5.15"
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AgentContext, AgentEvents, useAgent } from "@nestbox-ai/functions";
|
|
2
|
+
import { Ollama } from "ollama";
|
|
3
|
+
|
|
4
|
+
const ollama = new Ollama();
|
|
5
|
+
|
|
6
|
+
export const {{agentName}} = useAgent(
|
|
7
|
+
async (context: AgentContext, events: AgentEvents) => {
|
|
8
|
+
const response = await ollama.generate({
|
|
9
|
+
prompt: "Why is the sky blue?",
|
|
10
|
+
model: "gemma3:27b",
|
|
11
|
+
});
|
|
12
|
+
const result = response.response;
|
|
13
|
+
|
|
14
|
+
events.emitQueryCompleted({ data: result });
|
|
15
|
+
}
|
|
16
|
+
);
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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}} };
|