agentica 0.12.7 → 0.12.9
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/bin/index.js +139 -41
- package/package.json +15 -12
- package/bin/bases/Connector.d.ts +0 -9
- package/bin/bases/Connector.js +0 -67
- package/bin/bases/Connector.js.map +0 -1
- package/bin/bases/Package.d.ts +0 -11
- package/bin/bases/Package.js +0 -74
- package/bin/bases/Package.js.map +0 -1
- package/bin/bases/Tsconfig.d.ts +0 -5
- package/bin/bases/Tsconfig.js +0 -135
- package/bin/bases/Tsconfig.js.map +0 -1
- package/bin/executable/AgenticaStart.d.ts +0 -7
- package/bin/executable/AgenticaStart.js +0 -324
- package/bin/executable/AgenticaStart.js.map +0 -1
- package/bin/index.d.ts +0 -2
- package/bin/index.js.map +0 -1
- package/bin/structures/IAgenticaStart.d.ts +0 -31
- package/bin/structures/IAgenticaStart.js +0 -3
- package/bin/structures/IAgenticaStart.js.map +0 -1
- package/bin/structures/IAgenticaStartOption.d.ts +0 -13
- package/bin/structures/IAgenticaStartOption.js +0 -3
- package/bin/structures/IAgenticaStartOption.js.map +0 -1
- package/bin/utils/capitalize.d.ts +0 -1
- package/bin/utils/capitalize.js +0 -12
- package/bin/utils/capitalize.js.map +0 -1
- package/bin/utils/createProjectDirectory.d.ts +0 -3
- package/bin/utils/createProjectDirectory.js +0 -16
- package/bin/utils/createProjectDirectory.js.map +0 -1
- package/bin/utils/getNpmPackages.d.ts +0 -14
- package/bin/utils/getNpmPackages.js +0 -147
- package/bin/utils/getNpmPackages.js.map +0 -1
- package/bin/utils/getQuestions.d.ts +0 -8
- package/bin/utils/getQuestions.js +0 -45
- package/bin/utils/getQuestions.js.map +0 -1
- package/bin/utils/types/PackageManager.d.ts +0 -1
- package/bin/utils/types/PackageManager.js +0 -3
- package/bin/utils/types/PackageManager.js.map +0 -1
- package/bin/utils/types/ProjectOption.d.ts +0 -4
- package/bin/utils/types/ProjectOption.js +0 -3
- package/bin/utils/types/ProjectOption.js.map +0 -1
- package/src/bases/Connector.ts +0 -80
- package/src/bases/Package.ts +0 -75
- package/src/bases/Tsconfig.ts +0 -122
- package/src/executable/AgenticaStart.ts +0 -302
- package/src/index.ts +0 -39
- package/src/structures/IAgenticaStart.ts +0 -35
- package/src/structures/IAgenticaStartOption.ts +0 -13
- package/src/utils/capitalize.ts +0 -7
- package/src/utils/createProjectDirectory.ts +0 -14
- package/src/utils/getNpmPackages.ts +0 -46
- package/src/utils/getQuestions.ts +0 -48
- package/src/utils/types/PackageManager.ts +0 -1
- package/src/utils/types/ProjectOption.ts +0 -4
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getQuestions = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const getQuestions = (input) => {
|
|
9
|
-
return [
|
|
10
|
-
{
|
|
11
|
-
type: "list",
|
|
12
|
-
name: "packageManager",
|
|
13
|
-
message: "Package Manager",
|
|
14
|
-
choices: [
|
|
15
|
-
"npm",
|
|
16
|
-
"pnpm",
|
|
17
|
-
`yarn (berry ${chalk_1.default.blueBright("is not supported")})`,
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
type: "list",
|
|
22
|
-
name: "projectType",
|
|
23
|
-
message: "Project Type",
|
|
24
|
-
choices: [
|
|
25
|
-
`NodeJS ${chalk_1.default.blueBright("Agent Server")}`,
|
|
26
|
-
`NestJS ${chalk_1.default.blueBright("Agent Server")}`,
|
|
27
|
-
`React ${chalk_1.default.blueBright("Client Application")}`,
|
|
28
|
-
`Standard ${chalk_1.default.blueBright("Application")}`,
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
type: "checkbox",
|
|
33
|
-
name: "services",
|
|
34
|
-
message: "Embedded Controllers",
|
|
35
|
-
choices: input.services,
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
type: "input",
|
|
39
|
-
name: "openAIKey",
|
|
40
|
-
message: "Please enter your OPEN_AI_API_KEY:",
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
};
|
|
44
|
-
exports.getQuestions = getQuestions;
|
|
45
|
-
//# sourceMappingURL=getQuestions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getQuestions.js","sourceRoot":"","sources":["../../src/utils/getQuestions.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAUnB,MAAM,YAAY,GAAG,CAC1B,KAAwB,EACF,EAAE;IACxB,OAAO;QACL;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,iBAAiB;YAC1B,OAAO,EAAE;gBACP,KAAK;gBACL,MAAM;gBACN,eAAe,eAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,GAAG;aACvD;SACF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,cAAc;YACvB,OAAO,EAAE;gBACP,UAAU,eAAK,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;gBAC5C,UAAU,eAAK,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;gBAC5C,SAAS,eAAK,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE;gBACjD,YAAY,eAAK,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;aAC9C;SACF;QACD;YACE,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,sBAAsB;YAC/B,OAAO,EAAE,KAAK,CAAC,QAAQ;SACxB;QACD;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,oCAAoC;SAC9C;KACF,CAAC;AACJ,CAAC,CAAC;AArCW,QAAA,YAAY,gBAqCvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type PackageManager = "npm" | "yarn" | "pnpm";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageManager.js","sourceRoot":"","sources":["../../../src/utils/types/PackageManager.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectOption.js","sourceRoot":"","sources":["../../../src/utils/types/ProjectOption.ts"],"names":[],"mappings":""}
|
package/src/bases/Connector.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { capitalize } from "../utils/capitalize";
|
|
2
|
-
|
|
3
|
-
export namespace Connector {
|
|
4
|
-
export type Code = "import" | "connector";
|
|
5
|
-
|
|
6
|
-
export const createAll = (input: { services: string[] }): string => {
|
|
7
|
-
// Generate import statements for selected services
|
|
8
|
-
const serviceImports = create("import")({ services: input.services });
|
|
9
|
-
|
|
10
|
-
// Create Connector
|
|
11
|
-
const serviceConnectors = create("connector")({ services: input.services });
|
|
12
|
-
|
|
13
|
-
// Generate agentica code
|
|
14
|
-
const codeTemplate = `
|
|
15
|
-
import { Agentica } from "@agentica/core";
|
|
16
|
-
import typia from "typia";
|
|
17
|
-
import dotenv from "dotenv";
|
|
18
|
-
import { OpenAI } from "openai";
|
|
19
|
-
${serviceImports}
|
|
20
|
-
|
|
21
|
-
dotenv.config();
|
|
22
|
-
|
|
23
|
-
export const agent = new Agentica({
|
|
24
|
-
model: "chatgpt",
|
|
25
|
-
vendor: {
|
|
26
|
-
api: new OpenAI({
|
|
27
|
-
apiKey: process.env.OPENAI_API_KEY!
|
|
28
|
-
}),
|
|
29
|
-
model: "gpt-4o-mini",
|
|
30
|
-
},
|
|
31
|
-
controllers: [
|
|
32
|
-
${serviceConnectors}
|
|
33
|
-
],
|
|
34
|
-
});
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
return codeTemplate;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const create =
|
|
41
|
-
(code: Code) =>
|
|
42
|
-
(input: { services: string[] }): string => {
|
|
43
|
-
switch (code) {
|
|
44
|
-
case "import":
|
|
45
|
-
return createImport(input);
|
|
46
|
-
case "connector":
|
|
47
|
-
return createConnector(input);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const createConnector = (input: { services: string[] }): string => {
|
|
52
|
-
const serviceConnectors = input.services
|
|
53
|
-
.map((service) => {
|
|
54
|
-
const serviceName = capitalize(service);
|
|
55
|
-
return `{
|
|
56
|
-
name: "${serviceName} Connector",
|
|
57
|
-
protocol: "class",
|
|
58
|
-
application: typia.llm.application<${serviceName}Service, "chatgpt">(),
|
|
59
|
-
execute: new ${serviceName}Service(),
|
|
60
|
-
}`;
|
|
61
|
-
})
|
|
62
|
-
.join(",\n");
|
|
63
|
-
|
|
64
|
-
return serviceConnectors;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const createImport = (input: { services: string[] }) => {
|
|
68
|
-
// Generate import statements for selected services
|
|
69
|
-
const serviceImports = input.services
|
|
70
|
-
.map(
|
|
71
|
-
(service) =>
|
|
72
|
-
`import { ${capitalize(
|
|
73
|
-
service,
|
|
74
|
-
)}Service } from "@wrtnlabs/connector-${service}";`,
|
|
75
|
-
)
|
|
76
|
-
.join("\n");
|
|
77
|
-
|
|
78
|
-
return serviceImports;
|
|
79
|
-
};
|
|
80
|
-
}
|
package/src/bases/Package.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
import { PackageManager } from "../utils/types/PackageManager";
|
|
6
|
-
|
|
7
|
-
export namespace Package {
|
|
8
|
-
export const create = async (input: {
|
|
9
|
-
projectName: string;
|
|
10
|
-
projectPath: string;
|
|
11
|
-
}): Promise<void> => {
|
|
12
|
-
const packageJson = {
|
|
13
|
-
name: input.projectName,
|
|
14
|
-
version: "0.0.1",
|
|
15
|
-
description: "",
|
|
16
|
-
scripts: {
|
|
17
|
-
build: "tsc",
|
|
18
|
-
dev: `ts-node ${input.projectName}/cli.ts`,
|
|
19
|
-
start: `node ${input.projectName}/cli.js`,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
await fs.writeFile(
|
|
24
|
-
path.join(input.projectPath, "package.json"),
|
|
25
|
-
JSON.stringify(packageJson, null, 2),
|
|
26
|
-
);
|
|
27
|
-
console.log("✅ package.json created");
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const installPackage =
|
|
31
|
-
(packageManager: PackageManager) =>
|
|
32
|
-
(input: { projectPath: string; services: string[] }) => {
|
|
33
|
-
const installCmd = (pkg: string) => {
|
|
34
|
-
switch (packageManager) {
|
|
35
|
-
case "npm":
|
|
36
|
-
return `npm install ${pkg}`;
|
|
37
|
-
case "yarn":
|
|
38
|
-
return `yarn add ${pkg}`;
|
|
39
|
-
case "pnpm":
|
|
40
|
-
return `pnpm add ${pkg}`;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const dependencies = [
|
|
45
|
-
"openai",
|
|
46
|
-
"typia",
|
|
47
|
-
"dotenv",
|
|
48
|
-
"@agentica/core",
|
|
49
|
-
"readline",
|
|
50
|
-
...input.services.map((s) => `@wrtnlabs/connector-${s}`),
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
const devDependencies = ["ts-node", "typescript"];
|
|
54
|
-
|
|
55
|
-
// install existing dependencies
|
|
56
|
-
console.log("🚀 Installing existing dependencies...");
|
|
57
|
-
execSync(`${packageManager} install`, {
|
|
58
|
-
cwd: input.projectPath,
|
|
59
|
-
stdio: "inherit",
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
dependencies.forEach((dep) => {
|
|
63
|
-
console.log(`🚀 Installing ${dep}...`);
|
|
64
|
-
execSync(installCmd(dep), { cwd: input.projectPath, stdio: "inherit" });
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
devDependencies.forEach((dep) => {
|
|
68
|
-
console.log(`🚀 Installing ${dep}...`);
|
|
69
|
-
execSync(`${installCmd(dep)} -D`, {
|
|
70
|
-
cwd: input.projectPath,
|
|
71
|
-
stdio: "inherit",
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
}
|
package/src/bases/Tsconfig.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import fs from "fs/promises";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
export namespace Tsconfig {
|
|
5
|
-
export const create = async (input: {
|
|
6
|
-
projectPath: string;
|
|
7
|
-
}): Promise<void> => {
|
|
8
|
-
await fs.writeFile(path.join(input.projectPath, "tsconfig.json"), tsconfig);
|
|
9
|
-
console.log("✅ tsconfig.json created");
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const tsconfig = `{
|
|
13
|
-
"compilerOptions": {
|
|
14
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
15
|
-
/* Projects */
|
|
16
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
17
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
18
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
19
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
20
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
21
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
22
|
-
/* Language and Environment */
|
|
23
|
-
"target": "es2015" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
24
|
-
"lib": [
|
|
25
|
-
"ES2021"
|
|
26
|
-
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
|
27
|
-
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
28
|
-
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
29
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
30
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
31
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
32
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
33
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
34
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
35
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
36
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
37
|
-
/* Modules */
|
|
38
|
-
"module": "commonjs" /* Specify what module code is generated. */,
|
|
39
|
-
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
40
|
-
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
41
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
42
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
43
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
44
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
45
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
46
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
47
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
48
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
49
|
-
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
|
50
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
51
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
52
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
53
|
-
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
54
|
-
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
55
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
56
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
57
|
-
/* JavaScript Support */
|
|
58
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
59
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
60
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
61
|
-
/* Emit */
|
|
62
|
-
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
63
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
64
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
65
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
66
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
67
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
68
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
69
|
-
"outDir": "./lib" /* Specify an output folder for all emitted files. */,
|
|
70
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
71
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
72
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
73
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
74
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
75
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
76
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
77
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
78
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
79
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
80
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
81
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
82
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
83
|
-
/* Interop Constraints */
|
|
84
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
85
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
86
|
-
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
87
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
88
|
-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
89
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
90
|
-
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
91
|
-
/* Type Checking */
|
|
92
|
-
"strict": true /* Enable all strict type-checking options. */,
|
|
93
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
94
|
-
"strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
|
|
95
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
96
|
-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
97
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
98
|
-
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
99
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
100
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
101
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
102
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
103
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
104
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
105
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
106
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
107
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
108
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
109
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
110
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
111
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
112
|
-
/* Completeness */
|
|
113
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
114
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
|
|
115
|
-
"plugins": [
|
|
116
|
-
{
|
|
117
|
-
"transform": "typia/lib/transform"
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
}
|
|
121
|
-
}`;
|
|
122
|
-
}
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import cp from "child_process";
|
|
3
|
-
import fs from "fs/promises";
|
|
4
|
-
import { downloadTemplate } from "giget";
|
|
5
|
-
import inquirer, { QuestionCollection } from "inquirer";
|
|
6
|
-
import path from "path";
|
|
7
|
-
import prettier from "prettier";
|
|
8
|
-
import typia from "typia";
|
|
9
|
-
|
|
10
|
-
import { Connector } from "../bases/Connector";
|
|
11
|
-
import { Package } from "../bases/Package";
|
|
12
|
-
import { Tsconfig } from "../bases/Tsconfig";
|
|
13
|
-
import { IAgenticaStart } from "../structures/IAgenticaStart";
|
|
14
|
-
import { IAgenticaStartOption } from "../structures/IAgenticaStartOption";
|
|
15
|
-
import { createProjectDirectory } from "../utils/createProjectDirectory";
|
|
16
|
-
import { getNpmPackages } from "../utils/getNpmPackages";
|
|
17
|
-
import { PackageManager } from "../utils/types/PackageManager";
|
|
18
|
-
import { ProjectOptionValue } from "../utils/types/ProjectOption";
|
|
19
|
-
|
|
20
|
-
export namespace AgenticaStart {
|
|
21
|
-
/**
|
|
22
|
-
* Execute `start` command.
|
|
23
|
-
*/
|
|
24
|
-
export async function execute({
|
|
25
|
-
projectName,
|
|
26
|
-
options,
|
|
27
|
-
}: IAgenticaStart.IExecuteInput) {
|
|
28
|
-
const projectPath = path.join(process.cwd(), projectName);
|
|
29
|
-
|
|
30
|
-
// Check if project already exists
|
|
31
|
-
if (
|
|
32
|
-
await fs
|
|
33
|
-
.access(path.join(process.cwd(), projectName))
|
|
34
|
-
.then(() => true)
|
|
35
|
-
.catch(() => false)
|
|
36
|
-
) {
|
|
37
|
-
console.error(
|
|
38
|
-
`❌ Project ${chalk.redBright(projectName)} already exists`,
|
|
39
|
-
);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Get connector package names from npm and sort alphabetically
|
|
44
|
-
const availableServices = (await getNpmPackages()).sort((a, b) =>
|
|
45
|
-
a.name.localeCompare(b.name),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const questions = getQuestions({ services: availableServices, options });
|
|
49
|
-
const config = {
|
|
50
|
-
...(await inquirer.prompt<{
|
|
51
|
-
projectType: ProjectOptionValue;
|
|
52
|
-
services: string[];
|
|
53
|
-
packageManager: PackageManager;
|
|
54
|
-
openAIKey: string;
|
|
55
|
-
}>(questions)),
|
|
56
|
-
...(options.project ? { projectType: options.project } : {}),
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const validAnswers = typia.assert(config);
|
|
60
|
-
const { packageManager, openAIKey, projectType, services } = validAnswers;
|
|
61
|
-
|
|
62
|
-
await AgenticaStarter.execute(projectType)({
|
|
63
|
-
projectName,
|
|
64
|
-
projectPath,
|
|
65
|
-
openAIKey,
|
|
66
|
-
services,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Run package installation
|
|
70
|
-
console.log("📦 Package installation in progress...");
|
|
71
|
-
|
|
72
|
-
Package.installPackage(packageManager)({
|
|
73
|
-
projectPath,
|
|
74
|
-
services,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
console.log(`\n🎉 Project ${projectName} created`);
|
|
78
|
-
|
|
79
|
-
console.log(
|
|
80
|
-
`\n⚠️ ${chalk.yellow("Note:")} Please implement constructor values for each controller generated in agent.ts or index.ts`,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get questions for `start` command.
|
|
86
|
-
*/
|
|
87
|
-
const getQuestions = (
|
|
88
|
-
input: IAgenticaStart.IGetQuestionsInput,
|
|
89
|
-
): QuestionCollection[] => {
|
|
90
|
-
const questions = [
|
|
91
|
-
{
|
|
92
|
-
type: "list",
|
|
93
|
-
name: "packageManager",
|
|
94
|
-
message: "Package Manager",
|
|
95
|
-
choices: [
|
|
96
|
-
"npm",
|
|
97
|
-
"pnpm",
|
|
98
|
-
{
|
|
99
|
-
name: `yarn (berry ${chalk.blueBright("is not supported")})`,
|
|
100
|
-
value: "yarn",
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
input.options.project
|
|
105
|
-
? null
|
|
106
|
-
: {
|
|
107
|
-
type: "list",
|
|
108
|
-
name: "projectType",
|
|
109
|
-
message: "Project Type",
|
|
110
|
-
choices: Object.values(AgenticaStarter.PROJECT).map((project) => ({
|
|
111
|
-
name: project.title,
|
|
112
|
-
value: project.key,
|
|
113
|
-
})),
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
type: "checkbox",
|
|
117
|
-
name: "services",
|
|
118
|
-
message: "Embedded Controllers",
|
|
119
|
-
choices: input.services,
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
type: "input",
|
|
123
|
-
name: "openAIKey",
|
|
124
|
-
message: "Please enter your OPENAI_API_KEY:",
|
|
125
|
-
},
|
|
126
|
-
] satisfies (QuestionCollection | null)[];
|
|
127
|
-
|
|
128
|
-
return questions.filter((question) => question !== null);
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Methods for Agentica start options.
|
|
134
|
-
*/
|
|
135
|
-
namespace AgenticaStarter {
|
|
136
|
-
export const execute = (option: ProjectOptionValue) => {
|
|
137
|
-
const runner = PROJECT[option].runner;
|
|
138
|
-
if (!runner) {
|
|
139
|
-
throw new Error(`Not supported project type: ${option}`);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return runner;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export const PROJECT = {
|
|
146
|
-
standalone: {
|
|
147
|
-
title: `Standalone ${chalk.blueBright("Application")}`,
|
|
148
|
-
key: "standalone",
|
|
149
|
-
runner: async (input: IAgenticaStartOption.IProject): Promise<void> => {
|
|
150
|
-
// Create project directory
|
|
151
|
-
createProjectDirectory({ projectPath: input.projectPath });
|
|
152
|
-
|
|
153
|
-
// Create package.json (without dependencies)
|
|
154
|
-
await Promise.all([
|
|
155
|
-
// create package.json
|
|
156
|
-
Package.create({
|
|
157
|
-
projectName: input.projectName,
|
|
158
|
-
projectPath: input.projectPath,
|
|
159
|
-
}),
|
|
160
|
-
// create tsconfig.json
|
|
161
|
-
Tsconfig.create({ projectPath: input.projectPath }),
|
|
162
|
-
]);
|
|
163
|
-
|
|
164
|
-
await fs.mkdir(path.join(input.projectPath, "src"), {
|
|
165
|
-
recursive: false,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// Create Agentica code
|
|
169
|
-
const agenticaCode = Connector.createAll({ services: input.services });
|
|
170
|
-
|
|
171
|
-
await writeTypescriptFile({
|
|
172
|
-
filePath: path.join(input.projectPath, "src/agent.ts"),
|
|
173
|
-
taskName: "Agentica code",
|
|
174
|
-
content: agenticaCode,
|
|
175
|
-
});
|
|
176
|
-
await setEnvFiles(input);
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
nodejs: {
|
|
181
|
-
title: `NodeJS ${chalk.blueBright("Agent Server")}`,
|
|
182
|
-
key: "nodejs",
|
|
183
|
-
runner: async (input: IAgenticaStartOption.IProject): Promise<void> =>
|
|
184
|
-
nonStandalone("nodejs")(input)(async () => {
|
|
185
|
-
// Modify index.ts: replace import and controller code
|
|
186
|
-
const indexFilePath = path.join(input.projectPath, "src/index.ts");
|
|
187
|
-
const indexFileContent = await fs
|
|
188
|
-
.readFile(indexFilePath, "utf-8")
|
|
189
|
-
.then((content) => {
|
|
190
|
-
if (input.services.length !== 0) {
|
|
191
|
-
return content
|
|
192
|
-
.replace(/import { BbsArticleService }.*;\n/g, "")
|
|
193
|
-
.replace(
|
|
194
|
-
/controllers:\s*\[[\s\S]*?\],\n/,
|
|
195
|
-
"controllers: [/// INSERT CONTROLLER HERE],\n",
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
return content;
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
return { indexFilePath, indexFileContent };
|
|
202
|
-
}),
|
|
203
|
-
},
|
|
204
|
-
nestjs: {
|
|
205
|
-
title: `NestJS ${chalk.blueBright("Agent Server")}`,
|
|
206
|
-
key: "nestjs",
|
|
207
|
-
runner: async (input: IAgenticaStartOption.IProject): Promise<void> =>
|
|
208
|
-
nonStandalone("nestjs")(input)(async () => {
|
|
209
|
-
const indexFilePath = path.join(
|
|
210
|
-
input.projectPath,
|
|
211
|
-
"src/controllers/chat/ChatController.ts",
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
const indexFileContent = await fs.readFile(indexFilePath, "utf-8");
|
|
215
|
-
return { indexFilePath, indexFileContent };
|
|
216
|
-
}),
|
|
217
|
-
},
|
|
218
|
-
react: {
|
|
219
|
-
title: `React ${chalk.blueBright("Client Application")} (Currently not supported)`,
|
|
220
|
-
key: "react",
|
|
221
|
-
runner: undefined,
|
|
222
|
-
},
|
|
223
|
-
} as const;
|
|
224
|
-
|
|
225
|
-
const nonStandalone =
|
|
226
|
-
(option: "nodejs" | "nestjs") =>
|
|
227
|
-
(input: IAgenticaStartOption.IProject) =>
|
|
228
|
-
async (
|
|
229
|
-
getIndexFileInfo: () => Promise<{
|
|
230
|
-
indexFilePath: string;
|
|
231
|
-
indexFileContent: string;
|
|
232
|
-
}>,
|
|
233
|
-
) => {
|
|
234
|
-
await writeTemplate(option, input.projectName);
|
|
235
|
-
|
|
236
|
-
// Create Agentica code
|
|
237
|
-
const importCode = Connector.create("import")({
|
|
238
|
-
services: input.services,
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
const connectorCode = Connector.create("connector")({
|
|
242
|
-
services: input.services,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
const { indexFilePath, indexFileContent } = await getIndexFileInfo();
|
|
246
|
-
|
|
247
|
-
// Insert importCode and connectorCode
|
|
248
|
-
const agenticaCode = indexFileContent
|
|
249
|
-
.replace("/// INSERT IMPORT HERE", importCode)
|
|
250
|
-
.replace("/// INSERT CONTROLLER HERE", connectorCode);
|
|
251
|
-
|
|
252
|
-
await writeTypescriptFile({
|
|
253
|
-
filePath: indexFilePath,
|
|
254
|
-
taskName: "Agentica code",
|
|
255
|
-
content: agenticaCode,
|
|
256
|
-
});
|
|
257
|
-
await setEnvFiles(input);
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
const writeTypescriptFile = async (props: {
|
|
261
|
-
filePath: string;
|
|
262
|
-
taskName: string;
|
|
263
|
-
content: string;
|
|
264
|
-
}): Promise<void> => {
|
|
265
|
-
const formattedFileContent = await prettier.format(props.content, {
|
|
266
|
-
parser: "typescript",
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
await fs.writeFile(props.filePath, formattedFileContent);
|
|
270
|
-
console.log(`✅ ${props.taskName} created`);
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* Set project .env files
|
|
274
|
-
*/
|
|
275
|
-
const setEnvFiles = async (
|
|
276
|
-
input: IAgenticaStartOption.IProject,
|
|
277
|
-
): Promise<void> => {
|
|
278
|
-
// Create .env file
|
|
279
|
-
const envContent = `OPENAI_API_KEY=${input.openAIKey}\n`;
|
|
280
|
-
await fs.writeFile(path.join(input.projectPath, ".env"), envContent);
|
|
281
|
-
console.log("✅ .env created");
|
|
282
|
-
};
|
|
283
|
-
/**
|
|
284
|
-
* Git Clone from template repository.
|
|
285
|
-
*/
|
|
286
|
-
export const writeTemplate = async (
|
|
287
|
-
type: ProjectOptionValue,
|
|
288
|
-
directory: string,
|
|
289
|
-
): Promise<void> => {
|
|
290
|
-
// COPY PROJECTS
|
|
291
|
-
await downloadTemplate(`github:wrtnlabs/agentica.template.${type}`, {
|
|
292
|
-
dir: directory,
|
|
293
|
-
});
|
|
294
|
-
process.chdir(directory);
|
|
295
|
-
|
|
296
|
-
console.log("✅ Template downloaded");
|
|
297
|
-
|
|
298
|
-
// REMOVE .GIT DIRECTORY
|
|
299
|
-
cp.execSync("npx rimraf .git");
|
|
300
|
-
cp.execSync("npx rimraf .github/dependabot.yml");
|
|
301
|
-
};
|
|
302
|
-
}
|