graphai 0.4.0 → 0.4.1

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.
@@ -3,7 +3,8 @@ export declare const propertyFilterAgent: AgentFunction<{
3
3
  include?: Array<string>;
4
4
  exclude?: Array<string>;
5
5
  alter?: Record<string, Record<string, string>>;
6
- inject?: Record<string, Record<string, any>>;
6
+ inject?: Array<Record<string, any>>;
7
+ swap?: Record<string, string>;
7
8
  }>;
8
9
  declare const propertyFilterAgentInfo: {
9
10
  name: string;
@@ -11,13 +12,15 @@ declare const propertyFilterAgentInfo: {
11
12
  include?: string[] | undefined;
12
13
  exclude?: string[] | undefined;
13
14
  alter?: Record<string, Record<string, string>> | undefined;
14
- inject?: Record<string, Record<string, any>> | undefined;
15
+ inject?: Record<string, any>[] | undefined;
16
+ swap?: Record<string, string> | undefined;
15
17
  }>;
16
18
  mock: AgentFunction<{
17
19
  include?: string[] | undefined;
18
20
  exclude?: string[] | undefined;
19
21
  alter?: Record<string, Record<string, string>> | undefined;
20
- inject?: Record<string, Record<string, any>> | undefined;
22
+ inject?: Record<string, any>[] | undefined;
23
+ swap?: Record<string, string> | undefined;
21
24
  }>;
22
25
  samples: ({
23
26
  inputs: (string | {
@@ -32,6 +35,7 @@ declare const propertyFilterAgentInfo: {
32
35
  exclude?: undefined;
33
36
  alter?: undefined;
34
37
  inject?: undefined;
38
+ swap?: undefined;
35
39
  };
36
40
  result: {
37
41
  color: string;
@@ -50,6 +54,7 @@ declare const propertyFilterAgentInfo: {
50
54
  exclude?: undefined;
51
55
  alter?: undefined;
52
56
  inject?: undefined;
57
+ swap?: undefined;
53
58
  };
54
59
  result: {
55
60
  color: string;
@@ -68,6 +73,7 @@ declare const propertyFilterAgentInfo: {
68
73
  include?: undefined;
69
74
  alter?: undefined;
70
75
  inject?: undefined;
76
+ swap?: undefined;
71
77
  };
72
78
  result: {
73
79
  type: string;
@@ -92,6 +98,7 @@ declare const propertyFilterAgentInfo: {
92
98
  include?: undefined;
93
99
  exclude?: undefined;
94
100
  inject?: undefined;
101
+ swap?: undefined;
95
102
  };
96
103
  result: {
97
104
  color: string;
@@ -110,14 +117,13 @@ declare const propertyFilterAgentInfo: {
110
117
  }[])[];
111
118
  params: {
112
119
  inject: {
113
- maker: {
114
- from: number;
115
- index?: undefined;
116
- };
117
- };
120
+ propId: string;
121
+ from: number;
122
+ }[];
118
123
  include?: undefined;
119
124
  exclude?: undefined;
120
125
  alter?: undefined;
126
+ swap?: undefined;
121
127
  };
122
128
  result: {
123
129
  color: string;
@@ -136,14 +142,38 @@ declare const propertyFilterAgentInfo: {
136
142
  }[])[];
137
143
  params: {
138
144
  inject: {
139
- maker: {
140
- index: number;
141
- from: number;
142
- };
145
+ propId: string;
146
+ from: number;
147
+ index: number;
148
+ }[];
149
+ include?: undefined;
150
+ exclude?: undefined;
151
+ alter?: undefined;
152
+ swap?: undefined;
153
+ };
154
+ result: {
155
+ color: string;
156
+ model: string;
157
+ type: string;
158
+ maker: string;
159
+ range: number;
160
+ }[];
161
+ } | {
162
+ inputs: (string | {
163
+ color: string;
164
+ model: string;
165
+ type: string;
166
+ maker: string;
167
+ range: number;
168
+ }[])[];
169
+ params: {
170
+ swap: {
171
+ maker: string;
143
172
  };
144
173
  include?: undefined;
145
174
  exclude?: undefined;
146
175
  alter?: undefined;
176
+ inject?: undefined;
147
177
  };
148
178
  result: {
149
179
  color: string;
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.propertyFilterAgent = void 0;
4
- const applyFilter = (input, index, inputs, include, exclude, alter, inject) => {
4
+ const applyFilter = (input, index, inputs, include, exclude, alter, inject, swap) => {
5
5
  const propIds = include ? include : Object.keys(input);
6
6
  const excludeSet = new Set(exclude ?? []);
7
- return propIds.reduce((tmp, propId) => {
7
+ const result = propIds.reduce((tmp, propId) => {
8
8
  if (!excludeSet.has(propId)) {
9
- const injection = inject && inject[propId];
10
9
  const mapping = alter && alter[propId];
11
- if (injection && (injection.index === undefined || injection.index === index)) {
12
- tmp[propId] = inputs[injection.from];
13
- }
14
- else if (mapping && mapping[input[propId]]) {
10
+ if (mapping && mapping[input[propId]]) {
15
11
  tmp[propId] = mapping[input[propId]];
16
12
  }
17
13
  else {
@@ -20,14 +16,29 @@ const applyFilter = (input, index, inputs, include, exclude, alter, inject) => {
20
16
  }
21
17
  return tmp;
22
18
  }, {});
19
+ if (inject) {
20
+ inject.forEach((item) => {
21
+ if (item.index === undefined || item.index === index) {
22
+ result[item.propId] = inputs[item.from];
23
+ }
24
+ });
25
+ }
26
+ if (swap) {
27
+ Object.keys(swap).forEach((key) => {
28
+ const tmp = result[key];
29
+ result[key] = result[swap[key]];
30
+ result[swap[key]] = tmp;
31
+ });
32
+ }
33
+ return result;
23
34
  };
24
35
  const propertyFilterAgent = async ({ inputs, params }) => {
25
36
  const [input] = inputs;
26
- const { include, exclude, alter, inject } = params;
37
+ const { include, exclude, alter, inject, swap } = params;
27
38
  if (Array.isArray(input)) {
28
- return input.map((item, index) => applyFilter(item, index, inputs, include, exclude, alter, inject));
39
+ return input.map((item, index) => applyFilter(item, index, inputs, include, exclude, alter, inject, swap));
29
40
  }
30
- return applyFilter(input, 0, inputs, include, exclude, alter);
41
+ return applyFilter(input, 0, inputs, include, exclude, alter, inject, swap);
31
42
  };
32
43
  exports.propertyFilterAgent = propertyFilterAgent;
33
44
  const testInputs = [
@@ -73,7 +84,7 @@ const propertyFilterAgentInfo = {
73
84
  },
74
85
  {
75
86
  inputs: testInputs,
76
- params: { inject: { maker: { from: 1 } } },
87
+ params: { inject: [{ propId: "maker", from: 1 }] },
77
88
  result: [
78
89
  { color: "red", model: "Model 3", type: "EV", maker: "Tesla Motors", range: 300 },
79
90
  { color: "blue", model: "Model Y", type: "EV", maker: "Tesla Motors", range: 400 },
@@ -81,12 +92,20 @@ const propertyFilterAgentInfo = {
81
92
  },
82
93
  {
83
94
  inputs: testInputs,
84
- params: { inject: { maker: { index: 0, from: 1 } } },
95
+ params: { inject: [{ propId: "maker", from: 1, index: 0 }] },
85
96
  result: [
86
97
  { color: "red", model: "Model 3", type: "EV", maker: "Tesla Motors", range: 300 },
87
98
  { color: "blue", model: "Model Y", type: "EV", maker: "Tesla", range: 400 },
88
99
  ],
89
100
  },
101
+ {
102
+ inputs: testInputs,
103
+ params: { swap: { maker: "model" } },
104
+ result: [
105
+ { color: "red", model: "Tesla", type: "EV", maker: "Model 3", range: 300 },
106
+ { color: "blue", model: "Tesla", type: "EV", maker: "Model Y", range: 400 },
107
+ ],
108
+ },
90
109
  ],
91
110
  description: "Filter properties based on property name either with 'include' or 'exclude'",
92
111
  category: ["data"],
@@ -1,16 +1,16 @@
1
1
  import { AgentFunction } from "../../graphai";
2
2
  export declare const mapAgent: AgentFunction<{
3
- injectionTo?: Array<string>;
3
+ namedInputs?: Array<string>;
4
4
  limit?: number;
5
5
  }, Record<string, Array<any>>, any>;
6
6
  declare const mapAgentInfo: {
7
7
  name: string;
8
8
  agent: AgentFunction<{
9
- injectionTo?: string[] | undefined;
9
+ namedInputs?: string[] | undefined;
10
10
  limit?: number | undefined;
11
11
  }, Record<string, any[]>, any>;
12
12
  mock: AgentFunction<{
13
- injectionTo?: string[] | undefined;
13
+ namedInputs?: string[] | undefined;
14
14
  limit?: number | undefined;
15
15
  }, Record<string, any[]>, any>;
16
16
  samples: never[];
@@ -14,11 +14,11 @@ const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData, a
14
14
  if (params.limit && params.limit < input.length) {
15
15
  input.length = params.limit; // trim
16
16
  }
17
- const injectionTo = params.injectionTo ??
17
+ const namedInputs = params.namedInputs ??
18
18
  inputs.map((__input, index) => {
19
19
  return `$${index}`;
20
20
  });
21
- injectionTo.forEach((nodeId) => {
21
+ namedInputs.forEach((nodeId) => {
22
22
  if (nestedGraphData.nodes[nodeId] === undefined) {
23
23
  // If the input node does not exist, automatically create a static node
24
24
  nestedGraphData.nodes[nodeId] = { value: {} };
@@ -27,7 +27,7 @@ const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData, a
27
27
  const graphs = input.map((data) => {
28
28
  const graphAI = new graphai_1.GraphAI(nestedGraphData, agents || {}, { taskManager, agentFilters: agentFilters || [] });
29
29
  // Only the first input will be mapped
30
- injectionTo.forEach((injectToNodeId, index) => {
30
+ namedInputs.forEach((injectToNodeId, index) => {
31
31
  graphAI.injectValue(injectToNodeId, index === 0 ? data : inputs[index], "__mapAgent_inputs__");
32
32
  });
33
33
  return graphAI;
@@ -2,15 +2,15 @@ import { AgentFunction } from "../../graphai";
2
2
  import { GraphData } from "../../type";
3
3
  export declare const getNestedGraphData: (graphData: GraphData | string | undefined, inputs: Array<any>) => GraphData;
4
4
  export declare const nestedAgent: AgentFunction<{
5
- injectionTo?: Array<string>;
5
+ namedInputs?: Array<string>;
6
6
  }>;
7
7
  declare const nestedAgentInfo: {
8
8
  name: string;
9
9
  agent: AgentFunction<{
10
- injectionTo?: string[] | undefined;
10
+ namedInputs?: string[] | undefined;
11
11
  }>;
12
12
  mock: AgentFunction<{
13
- injectionTo?: string[] | undefined;
13
+ namedInputs?: string[] | undefined;
14
14
  }>;
15
15
  samples: never[];
16
16
  description: string;
@@ -27,8 +27,8 @@ const nestedAgent = async ({ params, inputs, agents, log, taskManager, graphData
27
27
  (0, utils_1.assert)(status.concurrency > status.running, `nestedAgent: Concurrency is too low: ${status.concurrency}`);
28
28
  }
29
29
  const nestedGraphData = (0, exports.getNestedGraphData)(graphData, inputs);
30
- const injectionTo = params.injectionTo ?? inputs.map((__input, index) => `$${index}`);
31
- injectionTo.forEach((nodeId, index) => {
30
+ const namedInputs = params.namedInputs ?? inputs.map((__input, index) => `$${index}`);
31
+ namedInputs.forEach((nodeId, index) => {
32
32
  if (nestedGraphData.nodes[nodeId] === undefined) {
33
33
  // If the input node does not exist, automatically create a static node
34
34
  nestedGraphData.nodes[nodeId] = { value: inputs[index] };
@@ -4,5 +4,6 @@ export * from "./matrix_agents/vanilla";
4
4
  export * from "./test_agents/vanilla";
5
5
  export * from "./graph_agents/vanilla";
6
6
  export * from "./data_agents/vanilla";
7
- export * from "./function_agent";
8
- export * from "./embedding_agent";
7
+ import functionAgent from "./function_agent";
8
+ import stringEmbeddingsAgent from "./embedding_agent";
9
+ export { functionAgent, stringEmbeddingsAgent };
@@ -14,7 +14,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
14
14
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
17
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.stringEmbeddingsAgent = exports.functionAgent = void 0;
18
22
  // Please refrain from adding agents that require npm. Those should be added to the index.ts.
19
23
  __exportStar(require("./string_agents/vanilla"), exports);
20
24
  __exportStar(require("./array_agents/vanilla"), exports);
@@ -22,5 +26,7 @@ __exportStar(require("./matrix_agents/vanilla"), exports);
22
26
  __exportStar(require("./test_agents/vanilla"), exports);
23
27
  __exportStar(require("./graph_agents/vanilla"), exports);
24
28
  __exportStar(require("./data_agents/vanilla"), exports);
25
- __exportStar(require("./function_agent"), exports);
26
- __exportStar(require("./embedding_agent"), exports);
29
+ const function_agent_1 = __importDefault(require("./function_agent"));
30
+ exports.functionAgent = function_agent_1.default;
31
+ const embedding_agent_1 = __importDefault(require("./embedding_agent"));
32
+ exports.stringEmbeddingsAgent = embedding_agent_1.default;
@@ -1,28 +1,4 @@
1
1
  import { AgentFunctionInfo, AgentFunctionContext, AgentFunction, AgentFilterInfo, ResultData } from "../type";
2
- export declare const defaultTestContext: {
3
- debugInfo: {
4
- nodeId: string;
5
- retry: number;
6
- verbose: boolean;
7
- };
8
- params: {};
9
- filterParams: {};
10
- agents: {};
11
- log: never[];
12
- };
13
- export declare const defaultAgentInfo: {
14
- name: string;
15
- samples: {
16
- inputs: never[];
17
- params: {};
18
- result: {};
19
- }[];
20
- description: string;
21
- category: never[];
22
- author: string;
23
- repository: string;
24
- license: string;
25
- };
26
2
  export declare const getAgentInfo: (agent: AgentFunction<any, any, any>) => {
27
3
  name: string;
28
4
  samples: {
@@ -38,5 +14,16 @@ export declare const getAgentInfo: (agent: AgentFunction<any, any, any>) => {
38
14
  agent: AgentFunction<any, any, any>;
39
15
  mock: AgentFunction<any, any, any>;
40
16
  };
17
+ export declare const defaultTestContext: {
18
+ debugInfo: {
19
+ nodeId: string;
20
+ retry: number;
21
+ verbose: boolean;
22
+ };
23
+ params: {};
24
+ filterParams: {};
25
+ agents: {};
26
+ log: never[];
27
+ };
41
28
  export declare const agentTestRunner: (agentInfo: AgentFunctionInfo) => Promise<void>;
42
29
  export declare const agentFilterRunnerBuilder: (__agentFilters: AgentFilterInfo[]) => (context: AgentFunctionContext, agent: AgentFunction) => Promise<ResultData>;
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.agentFilterRunnerBuilder = exports.agentTestRunner = exports.getAgentInfo = exports.defaultAgentInfo = exports.defaultTestContext = void 0;
6
+ exports.agentFilterRunnerBuilder = exports.agentTestRunner = exports.defaultTestContext = exports.getAgentInfo = void 0;
7
+ const utils_1 = require("../utils/utils");
7
8
  const node_assert_1 = __importDefault(require("node:assert"));
8
9
  const node_test_1 = __importDefault(require("node:test"));
10
+ exports.getAgentInfo = utils_1.agentInfoWrapper;
9
11
  exports.defaultTestContext = {
10
12
  debugInfo: {
11
13
  nodeId: "test",
@@ -17,29 +19,6 @@ exports.defaultTestContext = {
17
19
  agents: {},
18
20
  log: [],
19
21
  };
20
- exports.defaultAgentInfo = {
21
- name: "defaultAgentInfo",
22
- samples: [
23
- {
24
- inputs: [],
25
- params: {},
26
- result: {},
27
- },
28
- ],
29
- description: "",
30
- category: [],
31
- author: "",
32
- repository: "",
33
- license: "",
34
- };
35
- const getAgentInfo = (agent) => {
36
- return {
37
- agent,
38
- mock: agent,
39
- ...exports.defaultAgentInfo,
40
- };
41
- };
42
- exports.getAgentInfo = getAgentInfo;
43
22
  // for agent
44
23
  const agentTestRunner = async (agentInfo) => {
45
24
  const { agent, samples, skipTest } = agentInfo;
@@ -1,7 +1,35 @@
1
- import { DataSource, ResultData } from "../type";
1
+ import { DataSource, ResultData, AgentFunction } from "../type";
2
2
  export declare const sleep: (milliseconds: number) => Promise<unknown>;
3
3
  export declare const parseNodeName: (inputNodeId: any, version: number) => DataSource;
4
4
  export declare function assert(condition: boolean, message: string, isWarn?: boolean): asserts condition;
5
5
  export declare const isObject: (x: unknown) => boolean;
6
6
  export declare const getDataFromSource: (result: ResultData | undefined, source: DataSource) => ResultData | undefined;
7
7
  export declare const strIntentionalError = "Intentional Error for Debugging";
8
+ export declare const defaultAgentInfo: {
9
+ name: string;
10
+ samples: {
11
+ inputs: never[];
12
+ params: {};
13
+ result: {};
14
+ }[];
15
+ description: string;
16
+ category: never[];
17
+ author: string;
18
+ repository: string;
19
+ license: string;
20
+ };
21
+ export declare const agentInfoWrapper: (agent: AgentFunction<any, any, any>) => {
22
+ name: string;
23
+ samples: {
24
+ inputs: never[];
25
+ params: {};
26
+ result: {};
27
+ }[];
28
+ description: string;
29
+ category: never[];
30
+ author: string;
31
+ repository: string;
32
+ license: string;
33
+ agent: AgentFunction<any, any, any>;
34
+ mock: AgentFunction<any, any, any>;
35
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strIntentionalError = exports.getDataFromSource = exports.isObject = exports.assert = exports.parseNodeName = exports.sleep = void 0;
3
+ exports.agentInfoWrapper = exports.defaultAgentInfo = exports.strIntentionalError = exports.getDataFromSource = exports.isObject = exports.assert = exports.parseNodeName = exports.sleep = void 0;
4
4
  const sleep = async (milliseconds) => {
5
5
  return await new Promise((resolve) => setTimeout(resolve, milliseconds));
6
6
  };
@@ -86,3 +86,26 @@ const getDataFromSource = (result, source) => {
86
86
  };
87
87
  exports.getDataFromSource = getDataFromSource;
88
88
  exports.strIntentionalError = "Intentional Error for Debugging";
89
+ exports.defaultAgentInfo = {
90
+ name: "defaultAgentInfo",
91
+ samples: [
92
+ {
93
+ inputs: [],
94
+ params: {},
95
+ result: {},
96
+ },
97
+ ],
98
+ description: "",
99
+ category: [],
100
+ author: "",
101
+ repository: "",
102
+ license: "",
103
+ };
104
+ const agentInfoWrapper = (agent) => {
105
+ return {
106
+ agent,
107
+ mock: agent,
108
+ ...exports.defaultAgentInfo,
109
+ };
110
+ };
111
+ exports.agentInfoWrapper = agentInfoWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphai",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Asynchronous data flow execution engine for agentic AI apps.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -40,7 +40,7 @@
40
40
  "express": "^4.19.2",
41
41
  "globals": "^15.2.0",
42
42
  "groq-sdk": "^0.3.3",
43
- "openai": "^4.12.4",
43
+ "openai": "^4.47.1",
44
44
  "prettier": "^3.2.5",
45
45
  "slashgpt": "^0.0.9",
46
46
  "tiktoken": "^1.0.14",