@receptron/graphai_cli 0.2.0
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/README.md +59 -0
- package/lib/args.d.ts +12 -0
- package/lib/args.js +42 -0
- package/lib/file_utils.d.ts +3 -0
- package/lib/file_utils.js +39 -0
- package/lib/graphai_cli.d.ts +2 -0
- package/lib/graphai_cli.js +77 -0
- package/lib/options.d.ts +3 -0
- package/lib/options.js +48 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +20 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# graphai cli
|
|
2
|
+
|
|
3
|
+
graphai command line tool
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
graphai_cli.ts <yaml_or_json_file>
|
|
9
|
+
|
|
10
|
+
run GraphAI with GraphAI file.
|
|
11
|
+
|
|
12
|
+
Positionals:
|
|
13
|
+
yaml_or_json_file yaml or json file [string]
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
--help Show help [boolean]
|
|
17
|
+
--version Show version number [boolean]
|
|
18
|
+
-l, --list agents list
|
|
19
|
+
-s, --sample agents list [string]
|
|
20
|
+
-d, --detail agent detail [string]
|
|
21
|
+
-v, --verbose verbose log [boolean] [required] [default: false]
|
|
22
|
+
--log output log [string]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Run graphai
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
graphai test_yaml/test_base.yml
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Get Agents List
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
graphai -l
|
|
35
|
+
|
|
36
|
+
Available Agents
|
|
37
|
+
- bypassAgent
|
|
38
|
+
- copyMessageAgent
|
|
39
|
+
- countingAgent
|
|
40
|
+
- dataObjectMergeTemplateAgent
|
|
41
|
+
- dataSumTemplateAgent
|
|
42
|
+
- dotProductAgent
|
|
43
|
+
- echoAgent
|
|
44
|
+
- mapAgent
|
|
45
|
+
- mergeNodeIdAgent
|
|
46
|
+
- nestedAgent
|
|
47
|
+
- popAgent
|
|
48
|
+
- pushAgent
|
|
49
|
+
- shiftAgent
|
|
50
|
+
- slashGPTAgent
|
|
51
|
+
- sleeperAgent
|
|
52
|
+
- sleeperAgentDebug
|
|
53
|
+
- sortByValuesAgent
|
|
54
|
+
- stringEmbeddingsAgent
|
|
55
|
+
- stringSplitterAgent
|
|
56
|
+
- stringTemplateAgent
|
|
57
|
+
- tokenBoundStringsAgent
|
|
58
|
+
- totalAgent
|
|
59
|
+
```
|
package/lib/args.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const hasOption: boolean;
|
|
2
|
+
export declare const args: {
|
|
3
|
+
[x: string]: unknown;
|
|
4
|
+
list: unknown;
|
|
5
|
+
sample: string | undefined;
|
|
6
|
+
d: string | undefined;
|
|
7
|
+
v: boolean;
|
|
8
|
+
log: string | undefined;
|
|
9
|
+
yaml_or_json_file: string | undefined;
|
|
10
|
+
_: (string | number)[];
|
|
11
|
+
$0: string;
|
|
12
|
+
};
|
package/lib/args.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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.args = exports.hasOption = void 0;
|
|
7
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
+
exports.hasOption = ["-l", "--list", "-d", "--detail", "-s", "--sample"].some((o) => process.argv.includes(o));
|
|
9
|
+
exports.args = yargs_1.default
|
|
10
|
+
.option("list", {
|
|
11
|
+
alias: "l",
|
|
12
|
+
description: "agents list",
|
|
13
|
+
})
|
|
14
|
+
.option("sample", {
|
|
15
|
+
alias: "s",
|
|
16
|
+
description: "agent sample data",
|
|
17
|
+
type: "string",
|
|
18
|
+
})
|
|
19
|
+
.option("d", {
|
|
20
|
+
alias: "detail",
|
|
21
|
+
describe: "agent detail",
|
|
22
|
+
type: "string",
|
|
23
|
+
})
|
|
24
|
+
.option("v", {
|
|
25
|
+
alias: "verbose",
|
|
26
|
+
describe: "verbose log",
|
|
27
|
+
demandOption: true,
|
|
28
|
+
default: false,
|
|
29
|
+
type: "boolean",
|
|
30
|
+
})
|
|
31
|
+
.option("log", {
|
|
32
|
+
description: "output log",
|
|
33
|
+
demandOption: false,
|
|
34
|
+
type: "string",
|
|
35
|
+
})
|
|
36
|
+
.command(exports.hasOption ? "* [yaml_or_json_file]" : "* <yaml_or_json_file>", "run GraphAI with GraphAI file.")
|
|
37
|
+
.positional("yaml_or_json_file", {
|
|
38
|
+
describe: "yaml or json file",
|
|
39
|
+
type: "string",
|
|
40
|
+
demandOption: exports.hasOption,
|
|
41
|
+
})
|
|
42
|
+
.parseSync();
|
|
@@ -0,0 +1,39 @@
|
|
|
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.fileBaseName = exports.readGraphaiData = exports.mkdirLogDir = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
10
|
+
const mkdirLogDir = (logsDir) => {
|
|
11
|
+
if (!fs_1.default.existsSync(logsDir)) {
|
|
12
|
+
fs_1.default.mkdirSync(logsDir, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.mkdirLogDir = mkdirLogDir;
|
|
16
|
+
const readGraphaiData = (file) => {
|
|
17
|
+
if (file.endsWith(".yaml") || file.endsWith(".yml")) {
|
|
18
|
+
return readYamlFile(file);
|
|
19
|
+
}
|
|
20
|
+
if (file.endsWith(".json")) {
|
|
21
|
+
return readJsonFile(file);
|
|
22
|
+
}
|
|
23
|
+
throw new Error("No file exists " + file);
|
|
24
|
+
};
|
|
25
|
+
exports.readGraphaiData = readGraphaiData;
|
|
26
|
+
const readJsonFile = (fileName) => {
|
|
27
|
+
const file_file = fs_1.default.readFileSync(fileName, "utf8");
|
|
28
|
+
const file = JSON.parse(file_file);
|
|
29
|
+
return file;
|
|
30
|
+
};
|
|
31
|
+
const readYamlFile = (fileName) => {
|
|
32
|
+
const file_file = fs_1.default.readFileSync(fileName, "utf8");
|
|
33
|
+
const file = yaml_1.default.parse(file_file);
|
|
34
|
+
return file;
|
|
35
|
+
};
|
|
36
|
+
const fileBaseName = (file) => {
|
|
37
|
+
return path_1.default.basename(file).replace(/\.[a-zA-Z_-]+$/, "");
|
|
38
|
+
};
|
|
39
|
+
exports.fileBaseName = fileBaseName;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
const graphai_1 = require("graphai");
|
|
31
|
+
const packages = __importStar(require("graphai/lib/experimental_agents/packages"));
|
|
32
|
+
const fs_1 = __importDefault(require("fs"));
|
|
33
|
+
const path_1 = __importDefault(require("path"));
|
|
34
|
+
const args_1 = require("./args");
|
|
35
|
+
const utils_1 = require("./utils");
|
|
36
|
+
const file_utils_1 = require("./file_utils");
|
|
37
|
+
const options_1 = require("./options");
|
|
38
|
+
const fileFullPath = (file) => {
|
|
39
|
+
return path_1.default.resolve(process.cwd() + "/" + file) || "";
|
|
40
|
+
};
|
|
41
|
+
const main = async () => {
|
|
42
|
+
if (args_1.hasOption) {
|
|
43
|
+
(0, options_1.option)(args_1.args, packages);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const file_path = fileFullPath(args_1.args.yaml_or_json_file);
|
|
47
|
+
if (!fs_1.default.existsSync(file_path)) {
|
|
48
|
+
console.log("no file exist: " + file_path);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (args_1.args.log) {
|
|
52
|
+
const logfile = fileFullPath(args_1.args.log);
|
|
53
|
+
(0, file_utils_1.mkdirLogDir)(path_1.default.dirname(logfile));
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const graph_data = (0, file_utils_1.readGraphaiData)(file_path);
|
|
57
|
+
const agents = Object.entries(packages).reduce((tmp, current) => {
|
|
58
|
+
const [k, v] = current;
|
|
59
|
+
tmp[v.name] = v.agent;
|
|
60
|
+
return tmp;
|
|
61
|
+
}, {});
|
|
62
|
+
const graph = new graphai_1.GraphAI(graph_data, agents);
|
|
63
|
+
if (args_1.args.verbose) {
|
|
64
|
+
graph.onLogCallback = utils_1.callbackLog;
|
|
65
|
+
}
|
|
66
|
+
const results = await graph.run();
|
|
67
|
+
console.log(results);
|
|
68
|
+
if (args_1.args.log) {
|
|
69
|
+
const logfile = fileFullPath(args_1.args.log);
|
|
70
|
+
fs_1.default.writeFileSync(logfile, JSON.stringify(graph.transactionLogs(), null, 2));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
console.log("error", e);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
main();
|
package/lib/options.d.ts
ADDED
package/lib/options.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.option = void 0;
|
|
4
|
+
const option = (args, packages) => {
|
|
5
|
+
const list = () => {
|
|
6
|
+
console.log("Available Agents");
|
|
7
|
+
console.log(Object.entries(packages)
|
|
8
|
+
.map(([k, v]) => "* " + k + " - " + v.description)
|
|
9
|
+
.sort()
|
|
10
|
+
.join("\n"));
|
|
11
|
+
};
|
|
12
|
+
const getAgent = (agentId) => {
|
|
13
|
+
return Object.entries(packages).find(([k, v]) => k === agentId);
|
|
14
|
+
};
|
|
15
|
+
const detail = () => {
|
|
16
|
+
const agent = getAgent(args.detail);
|
|
17
|
+
if (!agent) {
|
|
18
|
+
console.log("no agent: " + args.detail);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
console.log("* " + agent[0]);
|
|
22
|
+
const detail = agent[1];
|
|
23
|
+
console.log([detail.name, " - ", detail.description].join(""));
|
|
24
|
+
console.log("Author " + detail.author);
|
|
25
|
+
console.log("Repository " + detail.repository);
|
|
26
|
+
console.log("Licence " + detail.license);
|
|
27
|
+
};
|
|
28
|
+
const sample = () => {
|
|
29
|
+
const agent = getAgent(args.sample);
|
|
30
|
+
if (!agent) {
|
|
31
|
+
console.log("no agent: " + args.sample);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const detail = agent[1];
|
|
35
|
+
console.log("* " + agent[0]);
|
|
36
|
+
console.log(JSON.stringify(detail.samples, null, 2));
|
|
37
|
+
};
|
|
38
|
+
if (args.list) {
|
|
39
|
+
list();
|
|
40
|
+
}
|
|
41
|
+
if (args.detail) {
|
|
42
|
+
detail();
|
|
43
|
+
}
|
|
44
|
+
if (args.sample) {
|
|
45
|
+
sample();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.option = option;
|
package/lib/utils.d.ts
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callbackLog = void 0;
|
|
4
|
+
const type_1 = require("graphai/lib/type");
|
|
5
|
+
const callbackLog = ({ nodeId, state, inputs, result, errorMessage }) => {
|
|
6
|
+
if (state === type_1.NodeState.Executing) {
|
|
7
|
+
console.log(`${nodeId.padEnd(10)} =>( ${(JSON.stringify(inputs) ?? "").slice(0, 60)}`);
|
|
8
|
+
}
|
|
9
|
+
else if (state === type_1.NodeState.Injected || state == type_1.NodeState.Completed) {
|
|
10
|
+
const shortName = state === type_1.NodeState.Injected ? "= " : "{} ";
|
|
11
|
+
console.log(`${nodeId.padEnd(10)} ${shortName} ${(JSON.stringify(result) ?? "").slice(0, 60)}`);
|
|
12
|
+
}
|
|
13
|
+
else if (state == type_1.NodeState.Failed) {
|
|
14
|
+
console.log(`${nodeId.padEnd(10)} ERR ${(errorMessage ?? "").slice(0, 60)}`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
console.log(`${nodeId.padEnd(10)} ${state}`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.callbackLog = callbackLog;
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@receptron/graphai_cli",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "GraphAI command line tools.",
|
|
5
|
+
"main": "lib/graphai_cli.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"graphai": "lib/graphai_cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"./lib"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc && tsc-alias",
|
|
14
|
+
"eslint": "eslint --fix --ext .ts ./src",
|
|
15
|
+
"format": "prettier --write '{src,tests,samples}/**/*.ts' .eslintrc.js",
|
|
16
|
+
"test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/test_*.ts",
|
|
17
|
+
"cli": "npx ts-node -r tsconfig-paths/register ./src/graphai_cli.ts",
|
|
18
|
+
"b": "yarn run format && yarn run eslint && yarn run build"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/receptron/graphai_cli"
|
|
23
|
+
},
|
|
24
|
+
"author": "Receptron team",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/receptron/graphai_cli/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/receptron/graphai_cli#readme",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/express": "^4.17.21",
|
|
32
|
+
"@types/node": "^20.8.7",
|
|
33
|
+
"@types/yargs": "^17.0.32",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
35
|
+
"@typescript-eslint/parser": "^6.8.0",
|
|
36
|
+
"eslint": "^7.32.0 || ^8.2.0",
|
|
37
|
+
"eslint-plugin-import": "^2.25.2",
|
|
38
|
+
"prettier": "^3.0.3",
|
|
39
|
+
"ts-node": "^10.9.1",
|
|
40
|
+
"tsc-alias": "^1.8.8",
|
|
41
|
+
"tsconfig-paths": "^4.2.0",
|
|
42
|
+
"typescript": "^5.2.2"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@inquirer/prompts": "^5.0.0",
|
|
46
|
+
"arxiv-api-ts": "^1.0.3",
|
|
47
|
+
"deepmerge": "^4.3.1",
|
|
48
|
+
"dotenv": "^16.4.5",
|
|
49
|
+
"express": "^4.19.2",
|
|
50
|
+
"graphai": "0.2.0",
|
|
51
|
+
"openai": "^4.12.4",
|
|
52
|
+
"slashgpt": "^0.0.8",
|
|
53
|
+
"tiktoken": "^1.0.14",
|
|
54
|
+
"wikipedia": "^2.1.2",
|
|
55
|
+
"yaml": "^2.3.3",
|
|
56
|
+
"yargs": "^17.7.2"
|
|
57
|
+
},
|
|
58
|
+
"types": "./lib/graphai_cli.d.ts",
|
|
59
|
+
"directories": {
|
|
60
|
+
"lib": "lib"
|
|
61
|
+
}
|
|
62
|
+
}
|