graphai 1.0.11 → 1.0.13
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/bundle.cjs.js +1 -1
- package/lib/bundle.cjs.js.map +1 -1
- package/lib/bundle.esm.js +81 -25
- package/lib/bundle.esm.js.map +1 -1
- package/lib/bundle.umd.js +1 -1
- package/lib/bundle.umd.js.map +1 -1
- package/lib/graphai.d.ts +1 -0
- package/lib/graphai.js +14 -7
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/node.js +14 -13
- package/lib/type.d.ts +1 -0
- package/lib/utils/GraphAILogger.d.ts +19 -0
- package/lib/utils/GraphAILogger.js +51 -0
- package/lib/utils/data_source.js +2 -1
- package/lib/utils/nodeUtils.js +1 -0
- package/lib/utils/prop_function.js +3 -2
- package/lib/utils/utils.js +2 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export type { TransactionLog } from "./transaction_log";
|
|
|
5
5
|
export { defaultAgentInfo, agentInfoWrapper, defaultTestContext, strIntentionalError, assert, sleep, isObject, parseNodeName, debugResultKey, isComputedNodeData, isStaticNodeData, } from "./utils/utils";
|
|
6
6
|
export { inputs2dataSources } from "./utils/nodeUtils";
|
|
7
7
|
export { ValidationError } from "./validators/common";
|
|
8
|
+
export { GraphAILogger } from "./utils/GraphAILogger";
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = exports.inputs2dataSources = exports.isStaticNodeData = exports.isComputedNodeData = exports.debugResultKey = exports.parseNodeName = exports.isObject = exports.sleep = exports.assert = exports.strIntentionalError = exports.defaultTestContext = exports.agentInfoWrapper = exports.defaultAgentInfo = exports.NodeState = exports.graphDataLatestVersion = exports.defaultConcurrency = exports.GraphAI = void 0;
|
|
3
|
+
exports.GraphAILogger = exports.ValidationError = exports.inputs2dataSources = exports.isStaticNodeData = exports.isComputedNodeData = exports.debugResultKey = exports.parseNodeName = exports.isObject = exports.sleep = exports.assert = exports.strIntentionalError = exports.defaultTestContext = exports.agentInfoWrapper = exports.defaultAgentInfo = exports.NodeState = exports.graphDataLatestVersion = exports.defaultConcurrency = exports.GraphAI = void 0;
|
|
4
4
|
var graphai_1 = require("./graphai");
|
|
5
5
|
Object.defineProperty(exports, "GraphAI", { enumerable: true, get: function () { return graphai_1.GraphAI; } });
|
|
6
6
|
Object.defineProperty(exports, "defaultConcurrency", { enumerable: true, get: function () { return graphai_1.defaultConcurrency; } });
|
|
@@ -23,3 +23,5 @@ var nodeUtils_1 = require("./utils/nodeUtils");
|
|
|
23
23
|
Object.defineProperty(exports, "inputs2dataSources", { enumerable: true, get: function () { return nodeUtils_1.inputs2dataSources; } });
|
|
24
24
|
var common_1 = require("./validators/common");
|
|
25
25
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return common_1.ValidationError; } });
|
|
26
|
+
var GraphAILogger_1 = require("./utils/GraphAILogger");
|
|
27
|
+
Object.defineProperty(exports, "GraphAILogger", { enumerable: true, get: function () { return GraphAILogger_1.GraphAILogger; } });
|
package/lib/node.js
CHANGED
|
@@ -7,6 +7,7 @@ const type_1 = require("./type");
|
|
|
7
7
|
const utils_2 = require("./utils/utils");
|
|
8
8
|
const transaction_log_1 = require("./transaction_log");
|
|
9
9
|
const result_1 = require("./utils/result");
|
|
10
|
+
const GraphAILogger_1 = require("./utils/GraphAILogger");
|
|
10
11
|
class Node {
|
|
11
12
|
constructor(nodeId, graph) {
|
|
12
13
|
this.waitlist = new Set(); // List of nodes which need data from this node.
|
|
@@ -36,14 +37,14 @@ class Node {
|
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
39
|
else if (this.console === true || this.console.after === true) {
|
|
39
|
-
|
|
40
|
+
GraphAILogger_1.GraphAILogger.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
|
|
40
41
|
}
|
|
41
42
|
else if (this.console.after) {
|
|
42
43
|
if ((0, utils_2.isObject)(this.console.after)) {
|
|
43
|
-
|
|
44
|
+
GraphAILogger_1.GraphAILogger.log(JSON.stringify((0, result_1.resultsOf)(this.console.after, { self: { result } }, this.graph.propFunctions, true), null, 2));
|
|
44
45
|
}
|
|
45
46
|
else {
|
|
46
|
-
|
|
47
|
+
GraphAILogger_1.GraphAILogger.log(this.console.after);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
}
|
|
@@ -202,7 +203,7 @@ class ComputedNode extends Node {
|
|
|
202
203
|
// and attempt to retry (if specified).
|
|
203
204
|
executeTimeout(transactionId) {
|
|
204
205
|
if (this.state === type_1.NodeState.Executing && this.isCurrentTransaction(transactionId)) {
|
|
205
|
-
|
|
206
|
+
GraphAILogger_1.GraphAILogger.warn(`-- timeout ${this.timeout} with ${this.nodeId}`);
|
|
206
207
|
this.retry(type_1.NodeState.TimedOut, Error("Timeout"));
|
|
207
208
|
}
|
|
208
209
|
}
|
|
@@ -295,7 +296,7 @@ class ComputedNode extends Node {
|
|
|
295
296
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
296
297
|
// This condition happens when the agent function returns
|
|
297
298
|
// after the timeout (either retried or not).
|
|
298
|
-
|
|
299
|
+
GraphAILogger_1.GraphAILogger.log(`-- transactionId mismatch with ${this.nodeId} (probably timeout)`);
|
|
299
300
|
return;
|
|
300
301
|
}
|
|
301
302
|
// after process
|
|
@@ -333,20 +334,20 @@ class ComputedNode extends Node {
|
|
|
333
334
|
// the retry if specified.
|
|
334
335
|
errorProcess(error, transactionId, namedInputs) {
|
|
335
336
|
if (error instanceof Error && error.message !== utils_1.strIntentionalError) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
337
|
+
GraphAILogger_1.GraphAILogger.error(`<-- NodeId: ${this.nodeId}, Agent: ${this.agentId}`);
|
|
338
|
+
GraphAILogger_1.GraphAILogger.error({ namedInputs });
|
|
339
|
+
GraphAILogger_1.GraphAILogger.error(error);
|
|
340
|
+
GraphAILogger_1.GraphAILogger.error("-->");
|
|
340
341
|
}
|
|
341
342
|
if (!this.isCurrentTransaction(transactionId)) {
|
|
342
|
-
|
|
343
|
+
GraphAILogger_1.GraphAILogger.warn(`-- transactionId mismatch with ${this.nodeId} (not timeout)`);
|
|
343
344
|
return;
|
|
344
345
|
}
|
|
345
346
|
if (error instanceof Error) {
|
|
346
347
|
this.retry(type_1.NodeState.Failed, error);
|
|
347
348
|
}
|
|
348
349
|
else {
|
|
349
|
-
|
|
350
|
+
GraphAILogger_1.GraphAILogger.error(`-- NodeId: ${this.nodeId}: Unknown error was caught`);
|
|
350
351
|
this.retry(type_1.NodeState.Failed, Error("Unknown"));
|
|
351
352
|
}
|
|
352
353
|
}
|
|
@@ -394,10 +395,10 @@ class ComputedNode extends Node {
|
|
|
394
395
|
return;
|
|
395
396
|
}
|
|
396
397
|
else if (this.console === true || this.console.before === true) {
|
|
397
|
-
|
|
398
|
+
GraphAILogger_1.GraphAILogger.log(JSON.stringify(context.namedInputs, null, 2));
|
|
398
399
|
}
|
|
399
400
|
else if (this.console.before) {
|
|
400
|
-
|
|
401
|
+
GraphAILogger_1.GraphAILogger.log(this.console.before);
|
|
401
402
|
}
|
|
402
403
|
}
|
|
403
404
|
}
|
package/lib/type.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export type GraphOptions = {
|
|
|
85
85
|
bypassAgentIds?: string[] | undefined;
|
|
86
86
|
config?: ConfigDataDictionary;
|
|
87
87
|
graphLoader?: GraphDataLoader;
|
|
88
|
+
forceLoop?: boolean;
|
|
88
89
|
};
|
|
89
90
|
export type CacheTypes = "pureAgent" | "impureAgent";
|
|
90
91
|
export type AgentFunctionContextDebugInfo = {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type LogLevel = "debug" | "info" | "log" | "warn" | "error";
|
|
2
|
+
type LoggerFunction = (level: LogLevel, ...args: any[]) => void;
|
|
3
|
+
declare function setLevelEnabled(level: LogLevel, enabled: boolean): void;
|
|
4
|
+
declare function setLogger(logger: LoggerFunction): void;
|
|
5
|
+
declare function debug(...args: any[]): void;
|
|
6
|
+
declare function info(...args: any[]): void;
|
|
7
|
+
declare function log(...args: any[]): void;
|
|
8
|
+
declare function warn(...args: any[]): void;
|
|
9
|
+
declare function error(...args: any[]): void;
|
|
10
|
+
export declare const GraphAILogger: {
|
|
11
|
+
setLevelEnabled: typeof setLevelEnabled;
|
|
12
|
+
setLogger: typeof setLogger;
|
|
13
|
+
debug: typeof debug;
|
|
14
|
+
info: typeof info;
|
|
15
|
+
log: typeof log;
|
|
16
|
+
warn: typeof warn;
|
|
17
|
+
error: typeof error;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphAILogger = void 0;
|
|
4
|
+
const enabledLevels = {
|
|
5
|
+
debug: true,
|
|
6
|
+
info: true,
|
|
7
|
+
log: true,
|
|
8
|
+
warn: true,
|
|
9
|
+
error: true,
|
|
10
|
+
};
|
|
11
|
+
let customLogger = null;
|
|
12
|
+
function setLevelEnabled(level, enabled) {
|
|
13
|
+
enabledLevels[level] = enabled;
|
|
14
|
+
}
|
|
15
|
+
function setLogger(logger) {
|
|
16
|
+
customLogger = logger;
|
|
17
|
+
}
|
|
18
|
+
function output(level, ...args) {
|
|
19
|
+
if (!enabledLevels[level])
|
|
20
|
+
return;
|
|
21
|
+
if (customLogger) {
|
|
22
|
+
customLogger(level, ...args);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
(console[level] || console.log)(...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function debug(...args) {
|
|
29
|
+
output("debug", ...args);
|
|
30
|
+
}
|
|
31
|
+
function info(...args) {
|
|
32
|
+
output("info", ...args);
|
|
33
|
+
}
|
|
34
|
+
function log(...args) {
|
|
35
|
+
output("log", ...args);
|
|
36
|
+
}
|
|
37
|
+
function warn(...args) {
|
|
38
|
+
output("warn", ...args);
|
|
39
|
+
}
|
|
40
|
+
function error(...args) {
|
|
41
|
+
output("error", ...args);
|
|
42
|
+
}
|
|
43
|
+
exports.GraphAILogger = {
|
|
44
|
+
setLevelEnabled,
|
|
45
|
+
setLogger,
|
|
46
|
+
debug,
|
|
47
|
+
info,
|
|
48
|
+
log,
|
|
49
|
+
warn,
|
|
50
|
+
error,
|
|
51
|
+
};
|
package/lib/utils/data_source.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getDataFromSource = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
const prop_function_1 = require("./prop_function");
|
|
6
|
+
const GraphAILogger_1 = require("./GraphAILogger");
|
|
6
7
|
const getNestedData = (result, propId, propFunctions) => {
|
|
7
8
|
const match = propId.match(prop_function_1.propFunctionRegex);
|
|
8
9
|
if (match) {
|
|
@@ -38,7 +39,7 @@ const innerGetDataFromSource = (result, propIds, propFunctions) => {
|
|
|
38
39
|
const propId = propIds[0];
|
|
39
40
|
const ret = getNestedData(result, propId, propFunctions);
|
|
40
41
|
if (ret === undefined) {
|
|
41
|
-
|
|
42
|
+
GraphAILogger_1.GraphAILogger.error(`prop: ${propIds.join(".")} is not hit`);
|
|
42
43
|
}
|
|
43
44
|
if (propIds.length > 1) {
|
|
44
45
|
return innerGetDataFromSource(ret, propIds.slice(1), propFunctions);
|
package/lib/utils/nodeUtils.js
CHANGED
|
@@ -21,6 +21,7 @@ const inputs2dataSources = (inputs) => {
|
|
|
21
21
|
return (0, utils_1.parseNodeName)(inputs);
|
|
22
22
|
};
|
|
23
23
|
exports.inputs2dataSources = inputs2dataSources;
|
|
24
|
+
// TODO: Maybe it's a remnant of old array inputs. Check and delete.
|
|
24
25
|
const dataSourceNodeIds = (sources) => {
|
|
25
26
|
if (!Array.isArray(sources)) {
|
|
26
27
|
throw new Error("sources must be array!! maybe inputs is invalid");
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.utilsFunctions = exports.propFunctions = exports.propFunctionRegex = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
|
+
const GraphAILogger_1 = require("./GraphAILogger");
|
|
5
6
|
exports.propFunctionRegex = /^[a-zA-Z]+\([^)]*\)$/;
|
|
6
7
|
const propArrayFunction = (result, propId) => {
|
|
7
8
|
if (Array.isArray(result)) {
|
|
@@ -73,7 +74,7 @@ const propStringFunction = (result, propId) => {
|
|
|
73
74
|
if (sliceMatch[1] !== undefined) {
|
|
74
75
|
return result.slice(Number(sliceMatch[1]));
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
+
GraphAILogger_1.GraphAILogger.warn("slice is not valid format: " + sliceMatch);
|
|
77
78
|
}
|
|
78
79
|
const splitMatch = propId.match(/^split\(([-_:;.,\s\n]+)\)$/);
|
|
79
80
|
if (splitMatch) {
|
|
@@ -115,7 +116,7 @@ const utilsFunctions = (input, nodes) => {
|
|
|
115
116
|
return nodes[utils_1.loopCounterKey].result;
|
|
116
117
|
}
|
|
117
118
|
// If a placeholder does not match any key, replace it with an empty string.
|
|
118
|
-
|
|
119
|
+
GraphAILogger_1.GraphAILogger.warn("not match template utility function: ${" + input + "}");
|
|
119
120
|
return "";
|
|
120
121
|
};
|
|
121
122
|
exports.utilsFunctions = utilsFunctions;
|
package/lib/utils/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.loopCounterKey = exports.isStaticNodeData = exports.isComputedNodeData = exports.isNamedInputs = exports.defaultTestContext = exports.isLogicallyTrue = exports.debugResultKey = exports.agentInfoWrapper = exports.defaultAgentInfo = exports.strIntentionalError = exports.isNull = exports.isObject = exports.parseNodeName = exports.sleep = void 0;
|
|
4
4
|
exports.assert = assert;
|
|
5
5
|
const type_1 = require("../type");
|
|
6
|
+
const GraphAILogger_1 = require("./GraphAILogger");
|
|
6
7
|
const sleep = async (milliseconds) => {
|
|
7
8
|
return await new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
8
9
|
};
|
|
@@ -35,7 +36,7 @@ function assert(condition, message, isWarn = false) {
|
|
|
35
36
|
if (!isWarn) {
|
|
36
37
|
throw new Error(message);
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
GraphAILogger_1.GraphAILogger.warn("warn: " + message);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
const isObject = (x) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "Asynchronous data flow execution engine for agentic AI apps.",
|
|
5
5
|
"main": "lib/bundle.cjs.js",
|
|
6
6
|
"module": "lib/bundle.esm.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/receptron/graphai#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"typedoc": "^0.28.
|
|
32
|
+
"typedoc": "^0.28.4",
|
|
33
33
|
"typedoc-plugin-markdown": "^4.6.3"
|
|
34
34
|
},
|
|
35
35
|
"types": "./lib/index.d.ts",
|