@ai.ntellect/core 0.6.1 → 0.6.2

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.
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRouterAddress = exports.ROUTER_ADDRESSES = exports.getNetworkProvider = exports.networkConfigs = void 0;
4
+ exports.networkConfigs = {
5
+ ethereum: {
6
+ name: "Ethereum Mainnet",
7
+ id: 1,
8
+ rpc: "https://eth.llamarpc.com",
9
+ explorerUrl: "https://etherscan.io",
10
+ nativeToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
11
+ },
12
+ polygon: {
13
+ name: "Polygon Mainnet",
14
+ id: 137,
15
+ rpc: "https://polygon.llamarpc.com",
16
+ explorerUrl: "https://polygonscan.com",
17
+ nativeToken: "0x0000000000000000000000000000000000001010",
18
+ },
19
+ arbitrum: {
20
+ name: "Arbitrum Mainnet",
21
+ id: 42161,
22
+ rpc: "https://arbitrum.llamarpc.com",
23
+ explorerUrl: "https://arbiscan.io",
24
+ nativeToken: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
25
+ },
26
+ base: {
27
+ name: "Base Mainnet",
28
+ id: 8453,
29
+ rpc: "https://base.llamarpc.com",
30
+ explorerUrl: "https://basescan.org",
31
+ nativeToken: "0x4200000000000000000000000000000000000006",
32
+ },
33
+ solana: {
34
+ name: "Solana Mainnet",
35
+ rpc: "https://api.mainnet-beta.solana.com",
36
+ explorerUrl: "https://solscan.io",
37
+ nativeToken: "So11111111111111111111111111111111111111112",
38
+ },
39
+ sepolia: {
40
+ name: "Sepolia Testnet",
41
+ id: 11155111,
42
+ rpc: "https://rpc.sepolia.ethpandaops.io",
43
+ explorerUrl: "https://sepolia.etherscan.io",
44
+ nativeToken: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
45
+ },
46
+ baseSepolia: {
47
+ name: "Base Sepolia Testnet",
48
+ id: 84532,
49
+ rpc: "https://base-sepolia-rpc.publicnode.com",
50
+ explorerUrl: "https://sepolia.basescan.org",
51
+ nativeToken: "0x4200000000000000000000000000000000000006",
52
+ },
53
+ };
54
+ const getNetworkProvider = (networkName) => {
55
+ const config = exports.networkConfigs[networkName.toLowerCase()];
56
+ if (!config) {
57
+ throw new Error(`Network ${networkName} not supported`);
58
+ }
59
+ return { config };
60
+ };
61
+ exports.getNetworkProvider = getNetworkProvider;
62
+ exports.ROUTER_ADDRESSES = {
63
+ ethereum: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
64
+ sepolia: "0xeE567Fe1712Faf6149d80dA1E6934E354124CfE3",
65
+ arbitrum: "0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24",
66
+ polygon: "0xedf6066a2b290C185783862C7F4776A2C8077AD1",
67
+ base: "0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24",
68
+ optimism: "0x4A7b5Da61326A6379179b40d00F57E5bbDC962c2",
69
+ blast: "0xBB66Eb1c5e875933D44DAe661dbD80e5D9B03035",
70
+ zora: "0xa00F34A632630EFd15223B1968358bA4845bEEC7",
71
+ worldchain: "0x541aB7c31A119441eF3575F6973277DE0eF460bd",
72
+ };
73
+ const getRouterAddress = (networkName) => {
74
+ return exports.ROUTER_ADDRESSES[networkName.toLowerCase()];
75
+ };
76
+ exports.getRouterAddress = getRouterAddress;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupGraphsWithActions = setupGraphsWithActions;
4
+ const engine_1 = require("../graph/engine");
5
+ function setupGraphsWithActions(actions, baseStateMapping, graphMaps) {
6
+ const initialStates = actions.map((action) => {
7
+ const parametersObject = Object.fromEntries(action.parameters.map((param) => [
8
+ param.name,
9
+ param.value !== undefined ? param.value : null,
10
+ ]) // Handle optional values
11
+ );
12
+ const baseState = baseStateMapping[action.name] || {};
13
+ return Object.assign(Object.assign({}, baseState), parametersObject);
14
+ });
15
+ const selectedGraphs = actions
16
+ .map((action) => graphMaps.find((graph) => graph.name === action.name))
17
+ .filter((graph) => graph !== undefined);
18
+ if (selectedGraphs.length !== actions.length) {
19
+ throw new Error("Graph not found");
20
+ }
21
+ const startNodes = selectedGraphs.map((graph) => graph.entryNode);
22
+ const graphEngines = selectedGraphs.map((graph) => new engine_1.GraphEngine(graph));
23
+ return {
24
+ initialStates: initialStates,
25
+ graphs: graphEngines,
26
+ startNodes,
27
+ };
28
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringifyZodSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const stringifyZodSchema = (nodes) => {
6
+ return nodes
7
+ .map((node) => {
8
+ const schemaStr = node.schema
9
+ ? getSchemaString(node.schema)
10
+ : "No parameters";
11
+ return `Workflow: ${node.name}\nDescription: ${node.description}\nParameters: ${schemaStr}`;
12
+ })
13
+ .join("\n\n");
14
+ };
15
+ exports.stringifyZodSchema = stringifyZodSchema;
16
+ const getSchemaString = (schema) => {
17
+ if (schema instanceof zod_1.z.ZodObject) {
18
+ const entries = Object.entries(schema.shape);
19
+ const fields = entries.map(([key, value]) => {
20
+ const description = value._def.description;
21
+ const schemaStr = getSchemaString(value);
22
+ return description
23
+ ? `${key}: ${schemaStr} // ${description}`
24
+ : `${key}: ${schemaStr}`;
25
+ });
26
+ return `z.object({${fields.join(", ")}})`;
27
+ }
28
+ if (schema instanceof zod_1.z.ZodArray) {
29
+ return `z.array(${getSchemaString(schema.element)})`;
30
+ }
31
+ if (schema instanceof zod_1.z.ZodString) {
32
+ return "z.string()";
33
+ }
34
+ if (schema instanceof zod_1.z.ZodNumber) {
35
+ return "z.number()";
36
+ }
37
+ if (schema instanceof zod_1.z.ZodBoolean) {
38
+ return "z.boolean()";
39
+ }
40
+ return `z.unknown()`;
41
+ };
@@ -37,15 +37,13 @@ export class GraphController<T> {
37
37
  console.log("graph", graph);
38
38
 
39
39
  // Construct the initial state from action parameters.
40
- const initialState = {
41
- context: action.parameters.reduce(
42
- (acc: Record<string, any>, param: { name: string; value: any }) => {
43
- acc[param.name] = param.value;
44
- return acc;
45
- },
46
- {}
47
- ),
48
- };
40
+ const initialState = action.parameters.reduce(
41
+ (acc: Record<string, any>, param: { name: string; value: any }) => {
42
+ acc[param.name] = param.value;
43
+ return acc;
44
+ },
45
+ {}
46
+ );
49
47
 
50
48
  console.log("initialState", initialState);
51
49
 
package/graph/engine.ts CHANGED
@@ -1,11 +1,8 @@
1
1
  import { Persistence, RealTimeNotifier } from "@/interfaces";
2
2
  import { GraphDefinition, Node, SharedState } from "@/types";
3
- import { configDotenv } from "dotenv";
4
3
  import EventEmitter from "events";
5
4
  import { z } from "zod";
6
5
 
7
- configDotenv();
8
-
9
6
  interface GraphOptions<T> {
10
7
  initialState?: SharedState<T>;
11
8
  schema?: z.ZodSchema<T>;
package/index.ts CHANGED
@@ -5,4 +5,4 @@ export * from "./memory/adapters/meilisearch";
5
5
  export * from "./memory/adapters/redis";
6
6
 
7
7
  export * from "./interfaces";
8
- export * from "./types";
8
+ export * from "./types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai.ntellect/core",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,170 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const controller_1 = require("@/graph/controller");
13
- const chai_1 = require("chai");
14
- const zod_1 = require("zod");
15
- describe("Controller", () => {
16
- // Define test schema
17
- const TestSchema = zod_1.z.object({
18
- status: zod_1.z.string(),
19
- count: zod_1.z.number(),
20
- });
21
- // Sample workflow definitions
22
- const simpleWorkflow = {
23
- name: "simple-workflow",
24
- entryNode: "start",
25
- nodes: {
26
- start: {
27
- name: "start",
28
- execute: (_params, state) => __awaiter(void 0, void 0, void 0, function* () {
29
- return ({
30
- context: Object.assign(Object.assign({}, state.context), { status: "completed", count: state.context.count + 1 }),
31
- });
32
- }),
33
- relationships: [],
34
- },
35
- },
36
- schema: TestSchema,
37
- };
38
- const complexWorkflow = {
39
- name: "complex-workflow",
40
- entryNode: "first",
41
- nodes: {
42
- first: {
43
- name: "first",
44
- execute: (_params, state) => __awaiter(void 0, void 0, void 0, function* () {
45
- return ({
46
- context: Object.assign(Object.assign({}, state.context), { status: "step1", count: state.context.count + 2 }),
47
- });
48
- }),
49
- relationships: [],
50
- },
51
- },
52
- schema: TestSchema,
53
- };
54
- let controller;
55
- beforeEach(() => {
56
- controller = new controller_1.GraphController();
57
- });
58
- describe("Basic Execution", () => {
59
- it("should execute a single workflow successfully", () => __awaiter(void 0, void 0, void 0, function* () {
60
- const actions = [
61
- {
62
- name: "simple-workflow",
63
- parameters: [
64
- { name: "status", value: "initial" },
65
- { name: "count", value: 0 },
66
- ],
67
- },
68
- ];
69
- const result = yield controller.run(actions, [simpleWorkflow]);
70
- (0, chai_1.expect)(result.context).to.deep.equal({
71
- status: "completed",
72
- count: 1,
73
- });
74
- }));
75
- it("should handle multiple workflows", () => __awaiter(void 0, void 0, void 0, function* () {
76
- const actions = [
77
- {
78
- name: "complex-workflow",
79
- parameters: [
80
- { name: "status", value: "initial" },
81
- { name: "count", value: 0 },
82
- ],
83
- },
84
- ];
85
- const result = yield controller.run(actions, [
86
- simpleWorkflow,
87
- complexWorkflow,
88
- ]);
89
- (0, chai_1.expect)(result.context).to.deep.equal({
90
- status: "step1",
91
- count: 2,
92
- });
93
- }));
94
- });
95
- describe("Error Handling", () => {
96
- it("should throw error when no actions provided", () => __awaiter(void 0, void 0, void 0, function* () {
97
- try {
98
- yield controller.run([], [simpleWorkflow]);
99
- chai_1.expect.fail("Should have thrown an error");
100
- }
101
- catch (error) {
102
- (0, chai_1.expect)(error.message).to.equal("No actions provided");
103
- }
104
- }));
105
- it("should throw error when workflow not found", () => __awaiter(void 0, void 0, void 0, function* () {
106
- const actions = [
107
- {
108
- name: "non-existent-workflow",
109
- parameters: [
110
- { name: "status", value: "initial" },
111
- { name: "count", value: 0 },
112
- ],
113
- },
114
- ];
115
- try {
116
- yield controller.run(actions, [simpleWorkflow]);
117
- chai_1.expect.fail("Should have thrown an error");
118
- }
119
- catch (error) {
120
- (0, chai_1.expect)(error.message).to.equal("Graph not found: non-existent-workflow");
121
- }
122
- }));
123
- });
124
- describe("Parameter Handling", () => {
125
- it("should correctly process workflow parameters", () => __awaiter(void 0, void 0, void 0, function* () {
126
- const actions = [
127
- {
128
- name: "simple-workflow",
129
- parameters: [
130
- { name: "status", value: "custom-initial" },
131
- { name: "count", value: 10 },
132
- ],
133
- },
134
- ];
135
- const result = yield controller.run(actions, [simpleWorkflow]);
136
- (0, chai_1.expect)(result.context).to.deep.equal({
137
- status: "completed",
138
- count: 11,
139
- });
140
- }));
141
- });
142
- describe("Multiple Actions", () => {
143
- it("should process the first action only", () => __awaiter(void 0, void 0, void 0, function* () {
144
- const actions = [
145
- {
146
- name: "simple-workflow",
147
- parameters: [
148
- { name: "status", value: "initial" },
149
- { name: "count", value: 0 },
150
- ],
151
- },
152
- {
153
- name: "complex-workflow",
154
- parameters: [
155
- { name: "status", value: "initial" },
156
- { name: "count", value: 5 },
157
- ],
158
- },
159
- ];
160
- const result = yield controller.run(actions, [
161
- simpleWorkflow,
162
- complexWorkflow,
163
- ]);
164
- (0, chai_1.expect)(result.context).to.deep.equal({
165
- status: "completed",
166
- count: 1,
167
- });
168
- }));
169
- });
170
- });