@receptron/graphai_cli 2.0.4 → 2.0.6

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/lib/args.js CHANGED
@@ -4,9 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.args = exports.hasOption = void 0;
7
- const yargs_1 = __importDefault(require("yargs"));
7
+ const yargs_1 = __importDefault(require("yargs/yargs"));
8
+ const helpers_1 = require("yargs/helpers");
8
9
  exports.hasOption = ["-l", "--list", "-d", "--detail", "-s", "--sample"].some((o) => process.argv.includes(o));
9
- exports.args = yargs_1.default
10
+ exports.args = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
10
11
  .scriptName("graphai")
11
12
  .option("list", {
12
13
  alias: "l",
package/lib/docs.js CHANGED
@@ -5,7 +5,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateDoc = exports.readTemplate = void 0;
7
7
  const utils_1 = require("graphai/lib/utils/utils");
8
- const json_schema_generator_1 = __importDefault(require("json-schema-generator"));
8
+ // json-schema-generator was unmaintained, replace with a simple schema generator
9
+ const generateSchema = (value) => {
10
+ if (Array.isArray(value)) {
11
+ if (value.length === 0) {
12
+ return { type: "array" };
13
+ }
14
+ return { type: "array", items: generateSchema(value[0]) };
15
+ }
16
+ if (value === null) {
17
+ return { type: "null" };
18
+ }
19
+ if (typeof value === "object") {
20
+ const properties = {};
21
+ const required = [];
22
+ for (const key of Object.keys(value)) {
23
+ properties[key] = generateSchema(value[key]);
24
+ required.push(key);
25
+ }
26
+ return { type: "object", properties, required };
27
+ }
28
+ if (typeof value === "string") {
29
+ return { type: "string" };
30
+ }
31
+ if (typeof value === "number") {
32
+ return { type: "number" };
33
+ }
34
+ if (typeof value === "boolean") {
35
+ return { type: "boolean" };
36
+ }
37
+ return { type: "any" };
38
+ };
9
39
  const fs_1 = __importDefault(require("fs"));
10
40
  const path_1 = __importDefault(require("path"));
11
41
  const agentAttribute = (agentInfo, key) => {
@@ -47,7 +77,7 @@ const agentAttribute = (agentInfo, key) => {
47
77
  }
48
78
  if (agentInfo.samples && agentInfo.samples[0]) {
49
79
  const sample = agentInfo.samples[0];
50
- return ["#### inputs", "```json", JSON.stringify((0, json_schema_generator_1.default)(sample.inputs), null, 2), "````"].join("\n\n");
80
+ return ["#### inputs", "```json", JSON.stringify(generateSchema(sample.inputs), null, 2), "````"].join("\n\n");
51
81
  }
52
82
  return "";
53
83
  }
@@ -106,7 +106,7 @@ const main = async () => {
106
106
  try {
107
107
  fd.write(data);
108
108
  }
109
- catch (e) {
109
+ catch (__e) {
110
110
  // nothinfg
111
111
  }
112
112
  process.stdout.write(data);
package/lib/mermaid.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { GraphData } from "graphai";
1
+ import { type GraphData } from "graphai";
2
2
  export declare const mermaid: (graphData: GraphData) => void;
package/lib/mermaid.js CHANGED
@@ -2,31 +2,88 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mermaid = void 0;
4
4
  const graphai_1 = require("graphai");
5
- const mapData = (nodeId, inputs) => {
6
- (0, graphai_1.inputs2dataSources)(inputs).map((source) => {
5
+ const BASE_INDENT = " ";
6
+ const sanitizeNodeId = (nodeId) => {
7
+ return `n_${nodeId.replace(/\./g, "_")}`;
8
+ };
9
+ const getFullNodeId = (nodeId, parentPath) => {
10
+ return parentPath ? `${parentPath}.${nodeId}` : nodeId;
11
+ };
12
+ const getIndentLevel = (parentPath) => {
13
+ return parentPath.split(".").filter(Boolean).length;
14
+ };
15
+ const formatLine = (content, depth = 0) => {
16
+ return BASE_INDENT + BASE_INDENT.repeat(depth) + content;
17
+ };
18
+ const processConnections = (inputs, targetNodeId, parentPath, state) => {
19
+ const depth = getIndentLevel(parentPath);
20
+ let sources = (0, graphai_1.inputs2dataSources)(inputs);
21
+ if (!Array.isArray(sources)) {
22
+ sources = [sources];
23
+ }
24
+ sources.forEach((source) => {
7
25
  if (source.nodeId) {
8
- if (source.propIds) {
9
- console.log(` ${source.nodeId}(${source.nodeId}) -- ${source.propIds.join(".")} --> ${nodeId}`);
10
- }
11
- else {
12
- console.log(` ${source.nodeId}(${source.nodeId}) --> ${nodeId}`);
13
- }
26
+ const sourceFullId = getFullNodeId(source.nodeId, parentPath);
27
+ const sourceMermaidId = sanitizeNodeId(sourceFullId);
28
+ const targetMermaidId = sanitizeNodeId(targetNodeId);
29
+ const connection = source.propIds
30
+ ? `${sourceMermaidId} -- ${source.propIds.join(".")} --> ${targetMermaidId}`
31
+ : `${sourceMermaidId} --> ${targetMermaidId}`;
32
+ state.lines.push(formatLine(connection, depth));
14
33
  }
15
34
  });
16
35
  };
17
- const mermaid = (graphData) => {
18
- console.log("flowchart TD");
19
- Object.keys(graphData.nodes).forEach((nodeId) => {
20
- const node = graphData.nodes[nodeId];
21
- // label / name
22
- if ("agent" in node) {
23
- if (node.inputs) {
24
- mapData(nodeId, node.inputs);
25
- }
26
- }
27
- if ("update" in node) {
28
- mapData(nodeId, { update: node.update });
36
+ const processNode = (nodeId, node, parentPath, state) => {
37
+ const fullNodeId = getFullNodeId(nodeId, parentPath);
38
+ const mermaidNodeId = sanitizeNodeId(fullNodeId);
39
+ const depth = getIndentLevel(parentPath);
40
+ if ("graph" in node) {
41
+ state.lines.push(formatLine(`subgraph ${mermaidNodeId}[${nodeId}: ${node.agent || ""}]`, depth));
42
+ if (node.graph && typeof node.graph === "object" && node.graph.nodes) {
43
+ Object.entries(node.graph.nodes).forEach(([subNodeId, subNode]) => {
44
+ processNode(subNodeId, subNode, fullNodeId, state);
45
+ });
29
46
  }
47
+ state.lines.push(formatLine("end", depth));
48
+ state.nestedGraphNodes.push(mermaidNodeId);
49
+ }
50
+ else if ("agent" in node) {
51
+ state.lines.push(formatLine(`${mermaidNodeId}(${nodeId}<br/>${node.agent})`, depth));
52
+ state.computedNodes.push(mermaidNodeId);
53
+ }
54
+ else {
55
+ state.lines.push(formatLine(`${mermaidNodeId}(${nodeId})`, depth));
56
+ state.staticNodes.push(mermaidNodeId);
57
+ }
58
+ if (node.inputs) {
59
+ processConnections(node.inputs, fullNodeId, parentPath, state);
60
+ }
61
+ if ("update" in node) {
62
+ processConnections({ update: node.update }, fullNodeId, parentPath, state);
63
+ }
64
+ };
65
+ const addNodeClasses = (state) => {
66
+ if (state.staticNodes.length > 0) {
67
+ state.lines.push(formatLine(`class ${state.staticNodes.join(",")} staticNode`));
68
+ }
69
+ if (state.computedNodes.length > 0) {
70
+ state.lines.push(formatLine(`class ${state.computedNodes.join(",")} computedNode`));
71
+ }
72
+ if (state.nestedGraphNodes.length > 0) {
73
+ state.lines.push(formatLine(`class ${state.nestedGraphNodes.join(",")} nestedGraph`));
74
+ }
75
+ };
76
+ const mermaid = (graphData) => {
77
+ const state = {
78
+ lines: ["flowchart TD"],
79
+ staticNodes: [],
80
+ computedNodes: [],
81
+ nestedGraphNodes: [],
82
+ };
83
+ Object.entries(graphData.nodes).forEach(([nodeId, node]) => {
84
+ processNode(nodeId, node, "", state);
30
85
  });
86
+ addNodeClasses(state);
87
+ console.log(state.lines.join("\n"));
31
88
  };
32
89
  exports.mermaid = mermaid;
package/lib/options.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Arguments } from "yargs";
1
+ import type { Arguments } from "yargs";
2
2
  import { AgentFunctionInfo } from "graphai";
3
3
  export declare const option: (args: Arguments, packages: Record<string, AgentFunctionInfo>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@receptron/graphai_cli",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "GraphAI command line tools.",
5
5
  "main": "lib/graphai_cli.js",
6
6
  "bin": {
@@ -10,14 +10,14 @@
10
10
  "./lib"
11
11
  ],
12
12
  "scripts": {
13
- "build": "tsc && tsc-alias",
13
+ "build": "tsc",
14
14
  "eslint": "eslint --fix",
15
15
  "doc": "echo nothing",
16
16
  "format": "prettier --write '{src,test_yaml,samples}/**/*.{yaml,ts,json}'",
17
17
  "test": "yarn run test_sh",
18
18
  "test_sh": "./scripts/test.sh",
19
- "test_node": "node --test -r tsconfig-paths/register --require ts-node/register ./test_yaml/test_*.ts",
20
- "cli": "node --require ts-node/register -r tsconfig-paths/register ./src/graphai_cli.ts",
19
+ "test_node": "node --test --require ts-node/register ./test_yaml/test_*.ts",
20
+ "cli": "node --require ts-node/register ./src/graphai_cli.ts",
21
21
  "b": "yarn run format && yarn run eslint && yarn run build"
22
22
  },
23
23
  "repository": {
@@ -34,15 +34,14 @@
34
34
  "@types/yargs": "^17.0.33"
35
35
  },
36
36
  "dependencies": {
37
- "@graphai/agents": "^2.0.4",
37
+ "@graphai/agents": "^2.0.8",
38
38
  "@graphai/stream_agent_filter": "^2.0.1",
39
39
  "@graphai/token_bound_string_agent": "^1.0.1",
40
- "@graphai/vanilla_node_agents": "^2.0.0",
41
- "@receptron/graphai_cli": "./receptron-graphai_cli-2.0.3-alpha.tgz",
40
+ "@graphai/vanilla_node_agents": "^2.0.1",
42
41
  "@receptron/test_utils": "^2.0.0",
43
- "dotenv": "^16.5.0",
44
- "graphai": "^2.0.5",
45
- "yargs": "^17.7.2"
42
+ "dotenv": "^17.2.1",
43
+ "graphai": "^2.0.13",
44
+ "yargs": "^18.0.0"
46
45
  },
47
46
  "types": "./lib/graphai_cli.d.ts",
48
47
  "directories": {