@receptron/graphai_express 0.0.26 → 0.0.27
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/agents.d.ts +8 -0
- package/lib/agents.js +159 -0
- package/lib/graph.d.ts +5 -0
- package/lib/graph.js +68 -0
- package/lib/index.d.ts +3 -10
- package/lib/index.js +12 -157
- package/package.json +2 -1
package/lib/agents.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
|
|
3
|
+
export declare const agentsList: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
4
|
+
export declare const agentDoc: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
5
|
+
export declare const agentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
6
|
+
export declare const agentRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
7
|
+
export declare const nonStreamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
8
|
+
export declare const streamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
package/lib/agents.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentRunner = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
|
|
4
|
+
const agent_filters_1 = require("@graphai/agent_filters");
|
|
5
|
+
// express middleware
|
|
6
|
+
// return agent list
|
|
7
|
+
const agentsList = (agentDictionary, hostName = "https://example.com", urlPath = "/agent") => {
|
|
8
|
+
return async (req, res) => {
|
|
9
|
+
const list = Object.keys(agentDictionary).map((agentName) => {
|
|
10
|
+
const agent = agentDictionary[agentName];
|
|
11
|
+
return {
|
|
12
|
+
agentId: agentName,
|
|
13
|
+
name: agent.name,
|
|
14
|
+
url: hostName + urlPath + "/" + agentName,
|
|
15
|
+
description: agent.description,
|
|
16
|
+
category: agent.category,
|
|
17
|
+
author: agent.author,
|
|
18
|
+
license: agent.license,
|
|
19
|
+
repository: agent.repository,
|
|
20
|
+
samples: agent.samples,
|
|
21
|
+
inputs: agent.inputs,
|
|
22
|
+
output: agent.output,
|
|
23
|
+
stream: agent.stream ?? false,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
res.json({ agents: list });
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.agentsList = agentsList;
|
|
30
|
+
// express middleware
|
|
31
|
+
// return agent detail info
|
|
32
|
+
const agentDoc = (agentDictionary, hostName = "https://example.com", urlPath = "/agent") => {
|
|
33
|
+
return async (req, res) => {
|
|
34
|
+
const { params } = req;
|
|
35
|
+
const { agentId } = params;
|
|
36
|
+
const agent = agentDictionary[agentId];
|
|
37
|
+
if (agent === undefined) {
|
|
38
|
+
res.status(404).send("Not found");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const result = {
|
|
42
|
+
agentId: agentId,
|
|
43
|
+
name: agent.name,
|
|
44
|
+
url: hostName + urlPath + "/" + agentId,
|
|
45
|
+
description: agent.description,
|
|
46
|
+
category: agent.category,
|
|
47
|
+
samples: agent.samples,
|
|
48
|
+
author: agent.author,
|
|
49
|
+
license: agent.license,
|
|
50
|
+
repository: agent.repository,
|
|
51
|
+
};
|
|
52
|
+
res.json(result);
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
exports.agentDoc = agentDoc;
|
|
56
|
+
// express middleware
|
|
57
|
+
// dispatch and run agent
|
|
58
|
+
// app.post(apiPrefix + "/:agentId", agentDispatcher(agentDictionary));
|
|
59
|
+
const agentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
60
|
+
const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters, true);
|
|
61
|
+
const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters, true);
|
|
62
|
+
return async (req, res, next) => {
|
|
63
|
+
const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
|
|
64
|
+
if (isStreaming) {
|
|
65
|
+
return await stream(req, res, next);
|
|
66
|
+
}
|
|
67
|
+
return await nonStram(req, res, next);
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
exports.agentDispatcher = agentDispatcher;
|
|
71
|
+
// express middleware
|
|
72
|
+
// run agent
|
|
73
|
+
// app.post(agentPrefix, agentRunner(agentDictionary));
|
|
74
|
+
const agentRunner = (agentDictionary, agentFilters = []) => {
|
|
75
|
+
const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters, false);
|
|
76
|
+
const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters, false);
|
|
77
|
+
return async (req, res, next) => {
|
|
78
|
+
const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
|
|
79
|
+
if (isStreaming) {
|
|
80
|
+
return await stream(req, res, next);
|
|
81
|
+
}
|
|
82
|
+
return await nonStram(req, res, next);
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
exports.agentRunner = agentRunner;
|
|
86
|
+
// express middleware
|
|
87
|
+
// run agent
|
|
88
|
+
const nonStreamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
89
|
+
return async (req, res, next) => {
|
|
90
|
+
try {
|
|
91
|
+
const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters, isDispatch);
|
|
92
|
+
const result = await dispatcher(req, res);
|
|
93
|
+
return res.json(result);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
next(e);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
exports.nonStreamAgentDispatcher = nonStreamAgentDispatcher;
|
|
101
|
+
// express middleware
|
|
102
|
+
// run agent with streaming
|
|
103
|
+
const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
104
|
+
return async (req, res, next) => {
|
|
105
|
+
try {
|
|
106
|
+
res.setHeader("Content-Type", "text/event-stream;charset=utf-8");
|
|
107
|
+
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
108
|
+
res.setHeader("X-Accel-Buffering", "no");
|
|
109
|
+
const callback = (context, token) => {
|
|
110
|
+
if (token) {
|
|
111
|
+
res.write(token);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const streamAgentFilter = {
|
|
115
|
+
name: "streamAgentFilter",
|
|
116
|
+
agent: (0, agent_filters_1.streamAgentFilterGenerator)(callback),
|
|
117
|
+
};
|
|
118
|
+
const filterList = [...agentFilters, streamAgentFilter];
|
|
119
|
+
const dispatcher = agentDispatcherInternal(agentDictionary, filterList, isDispatch);
|
|
120
|
+
const result = await dispatcher(req, res);
|
|
121
|
+
const json_data = JSON.stringify(result);
|
|
122
|
+
res.write("___END___");
|
|
123
|
+
res.write(json_data);
|
|
124
|
+
return res.end();
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
next(e);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
exports.streamAgentDispatcher = streamAgentDispatcher;
|
|
132
|
+
// dispatcher internal function
|
|
133
|
+
const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
134
|
+
return async (req, res) => {
|
|
135
|
+
const { params } = req;
|
|
136
|
+
const { agentId } = isDispatch ? params : req.body;
|
|
137
|
+
const { nodeId, retry, params: agentParams, inputs, namedInputs } = req.body;
|
|
138
|
+
const agent = agentDictionary[agentId];
|
|
139
|
+
if (agent === undefined) {
|
|
140
|
+
res.status(404).send("Not found");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const context = {
|
|
144
|
+
params: agentParams || {},
|
|
145
|
+
inputs,
|
|
146
|
+
namedInputs,
|
|
147
|
+
debugInfo: {
|
|
148
|
+
nodeId,
|
|
149
|
+
retry,
|
|
150
|
+
verbose: false,
|
|
151
|
+
},
|
|
152
|
+
agents: agentDictionary,
|
|
153
|
+
filterParams: {},
|
|
154
|
+
};
|
|
155
|
+
const agentFilterRunner = (0, agent_filters_1.agentFilterRunnerBuilder)(agentFilters);
|
|
156
|
+
const result = await agentFilterRunner(context, agent.agent);
|
|
157
|
+
return result;
|
|
158
|
+
};
|
|
159
|
+
};
|
package/lib/graph.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
|
|
3
|
+
export declare const graphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
4
|
+
export declare const streamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
5
|
+
export declare const nonStreamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
package/lib/graph.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nonStreamGraphRunner = exports.streamGraphRunner = exports.graphRunner = void 0;
|
|
4
|
+
const graphai_1 = require("graphai");
|
|
5
|
+
const agent_filters_1 = require("@graphai/agent_filters");
|
|
6
|
+
const graphRunner = (agentDictionary, agentFilters = []) => {
|
|
7
|
+
const stream = (0, exports.streamGraphRunner)(agentDictionary, agentFilters);
|
|
8
|
+
const nonStream = (0, exports.nonStreamGraphRunner)(agentDictionary, agentFilters);
|
|
9
|
+
return async (req, res, next) => {
|
|
10
|
+
const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
|
|
11
|
+
if (isStreaming) {
|
|
12
|
+
return await stream(req, res, next);
|
|
13
|
+
}
|
|
14
|
+
return await nonStream(req, res, next);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.graphRunner = graphRunner;
|
|
18
|
+
const streamGraphRunner = (agentDictionary, agentFilters = []) => {
|
|
19
|
+
return async (req, res, next) => {
|
|
20
|
+
try {
|
|
21
|
+
res.setHeader("Content-Type", "text/event-stream;charset=utf-8");
|
|
22
|
+
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
23
|
+
res.setHeader("X-Accel-Buffering", "no");
|
|
24
|
+
const callback = (context, token) => {
|
|
25
|
+
if (token) {
|
|
26
|
+
res.write(token);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const streamAgentFilter = {
|
|
30
|
+
name: "streamAgentFilter",
|
|
31
|
+
agent: (0, agent_filters_1.streamAgentFilterGenerator)(callback),
|
|
32
|
+
};
|
|
33
|
+
const filterList = [...agentFilters, streamAgentFilter];
|
|
34
|
+
const dispatcher = streamGraphRunnerInternal(agentDictionary, filterList);
|
|
35
|
+
const result = await dispatcher(req, res);
|
|
36
|
+
const json_data = JSON.stringify(result);
|
|
37
|
+
res.write("___END___");
|
|
38
|
+
res.write(json_data);
|
|
39
|
+
return res.end();
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
next(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.streamGraphRunner = streamGraphRunner;
|
|
47
|
+
const nonStreamGraphRunner = (agentDictionary, agentFilters = []) => {
|
|
48
|
+
return async (req, res, next) => {
|
|
49
|
+
try {
|
|
50
|
+
const dispatcher = streamGraphRunnerInternal(agentDictionary, agentFilters);
|
|
51
|
+
const result = await dispatcher(req, res);
|
|
52
|
+
return res.json(result);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
next(e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
exports.nonStreamGraphRunner = nonStreamGraphRunner;
|
|
60
|
+
// internal function
|
|
61
|
+
const streamGraphRunnerInternal = (agentDictionary, agentFilters = []) => {
|
|
62
|
+
return async (req, __res) => {
|
|
63
|
+
const { graphData } = req.body;
|
|
64
|
+
const graphai = new graphai_1.GraphAI(graphData, agentDictionary, { agentFilters });
|
|
65
|
+
const result = await graphai.run(true);
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { ExpressAgentInfo };
|
|
5
|
-
export declare const agentsList: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
6
|
-
export declare const agentDoc: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
7
|
-
export declare const agentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
8
|
-
export declare const agentRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
9
|
-
export declare const nonStreamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
10
|
-
export declare const streamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
1
|
+
export { agentsList, agentDoc, agentDispatcher, agentRunner, nonStreamAgentDispatcher, streamAgentDispatcher } from "./agents";
|
|
2
|
+
export { graphRunner, streamGraphRunner, nonStreamGraphRunner } from "./graph";
|
|
3
|
+
export { ExpressAgentInfo } from "./type";
|
package/lib/index.js
CHANGED
|
@@ -1,159 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentRunner = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
description: agent.description,
|
|
16
|
-
category: agent.category,
|
|
17
|
-
author: agent.author,
|
|
18
|
-
license: agent.license,
|
|
19
|
-
repository: agent.repository,
|
|
20
|
-
samples: agent.samples,
|
|
21
|
-
inputs: agent.inputs,
|
|
22
|
-
output: agent.output,
|
|
23
|
-
stream: agent.stream ?? false,
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
res.json({ agents: list });
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
exports.agentsList = agentsList;
|
|
30
|
-
// express middleware
|
|
31
|
-
// return agent detail info
|
|
32
|
-
const agentDoc = (agentDictionary, hostName = "https://example.com", urlPath = "/agent") => {
|
|
33
|
-
return async (req, res) => {
|
|
34
|
-
const { params } = req;
|
|
35
|
-
const { agentId } = params;
|
|
36
|
-
const agent = agentDictionary[agentId];
|
|
37
|
-
if (agent === undefined) {
|
|
38
|
-
res.status(404).send("Not found");
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const result = {
|
|
42
|
-
agentId: agentId,
|
|
43
|
-
name: agent.name,
|
|
44
|
-
url: hostName + urlPath + "/" + agentId,
|
|
45
|
-
description: agent.description,
|
|
46
|
-
category: agent.category,
|
|
47
|
-
samples: agent.samples,
|
|
48
|
-
author: agent.author,
|
|
49
|
-
license: agent.license,
|
|
50
|
-
repository: agent.repository,
|
|
51
|
-
};
|
|
52
|
-
res.json(result);
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
exports.agentDoc = agentDoc;
|
|
56
|
-
// express middleware
|
|
57
|
-
// dispatch and run agent
|
|
58
|
-
// app.post(apiPrefix + "/:agentId", agentDispatcher(agentDictionary));
|
|
59
|
-
const agentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
60
|
-
const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters, true);
|
|
61
|
-
const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters, true);
|
|
62
|
-
return async (req, res, next) => {
|
|
63
|
-
const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
|
|
64
|
-
if (isStreaming) {
|
|
65
|
-
return await stream(req, res, next);
|
|
66
|
-
}
|
|
67
|
-
return await nonStram(req, res, next);
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
exports.agentDispatcher = agentDispatcher;
|
|
71
|
-
// express middleware
|
|
72
|
-
// run agent
|
|
73
|
-
// app.post(agentPrefix, agentRunner(agentDictionary));
|
|
74
|
-
const agentRunner = (agentDictionary, agentFilters = []) => {
|
|
75
|
-
const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters, false);
|
|
76
|
-
const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters, false);
|
|
77
|
-
return async (req, res, next) => {
|
|
78
|
-
const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
|
|
79
|
-
if (isStreaming) {
|
|
80
|
-
return await stream(req, res, next);
|
|
81
|
-
}
|
|
82
|
-
return await nonStram(req, res, next);
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
exports.agentRunner = agentRunner;
|
|
86
|
-
// express middleware
|
|
87
|
-
// run agent
|
|
88
|
-
const nonStreamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
89
|
-
return async (req, res, next) => {
|
|
90
|
-
try {
|
|
91
|
-
const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters, isDispatch);
|
|
92
|
-
const result = await dispatcher(req, res);
|
|
93
|
-
return res.json(result);
|
|
94
|
-
}
|
|
95
|
-
catch (e) {
|
|
96
|
-
next(e);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
exports.nonStreamAgentDispatcher = nonStreamAgentDispatcher;
|
|
101
|
-
// express middleware
|
|
102
|
-
// run agent with streaming
|
|
103
|
-
const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
104
|
-
return async (req, res, next) => {
|
|
105
|
-
try {
|
|
106
|
-
res.setHeader("Content-Type", "text/event-stream;charset=utf-8");
|
|
107
|
-
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
108
|
-
res.setHeader("X-Accel-Buffering", "no");
|
|
109
|
-
const callback = (context, token) => {
|
|
110
|
-
if (token) {
|
|
111
|
-
res.write(token);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const streamAgentFilter = {
|
|
115
|
-
name: "streamAgentFilter",
|
|
116
|
-
agent: (0, agent_filters_1.streamAgentFilterGenerator)(callback),
|
|
117
|
-
};
|
|
118
|
-
const filterList = [...agentFilters, streamAgentFilter];
|
|
119
|
-
const dispatcher = agentDispatcherInternal(agentDictionary, filterList, isDispatch);
|
|
120
|
-
const result = await dispatcher(req, res);
|
|
121
|
-
const json_data = JSON.stringify(result);
|
|
122
|
-
res.write("___END___");
|
|
123
|
-
res.write(json_data);
|
|
124
|
-
return res.end();
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
next(e);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
exports.streamAgentDispatcher = streamAgentDispatcher;
|
|
132
|
-
// dispatcher internal function
|
|
133
|
-
const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
134
|
-
return async (req, res) => {
|
|
135
|
-
const { params } = req;
|
|
136
|
-
const { agentId } = isDispatch ? params : req.body;
|
|
137
|
-
const { nodeId, retry, params: agentParams, inputs, namedInputs } = req.body;
|
|
138
|
-
const agent = agentDictionary[agentId];
|
|
139
|
-
if (agent === undefined) {
|
|
140
|
-
res.status(404).send("Not found");
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const context = {
|
|
144
|
-
params: agentParams || {},
|
|
145
|
-
inputs,
|
|
146
|
-
namedInputs,
|
|
147
|
-
debugInfo: {
|
|
148
|
-
nodeId,
|
|
149
|
-
retry,
|
|
150
|
-
verbose: false,
|
|
151
|
-
},
|
|
152
|
-
agents: agentDictionary,
|
|
153
|
-
filterParams: {},
|
|
154
|
-
};
|
|
155
|
-
const agentFilterRunner = (0, agent_filters_1.agentFilterRunnerBuilder)(agentFilters);
|
|
156
|
-
const result = await agentFilterRunner(context, agent.agent);
|
|
157
|
-
return result;
|
|
158
|
-
};
|
|
159
|
-
};
|
|
3
|
+
exports.nonStreamGraphRunner = exports.streamGraphRunner = exports.graphRunner = exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentRunner = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
|
|
4
|
+
var agents_1 = require("./agents");
|
|
5
|
+
Object.defineProperty(exports, "agentsList", { enumerable: true, get: function () { return agents_1.agentsList; } });
|
|
6
|
+
Object.defineProperty(exports, "agentDoc", { enumerable: true, get: function () { return agents_1.agentDoc; } });
|
|
7
|
+
Object.defineProperty(exports, "agentDispatcher", { enumerable: true, get: function () { return agents_1.agentDispatcher; } });
|
|
8
|
+
Object.defineProperty(exports, "agentRunner", { enumerable: true, get: function () { return agents_1.agentRunner; } });
|
|
9
|
+
Object.defineProperty(exports, "nonStreamAgentDispatcher", { enumerable: true, get: function () { return agents_1.nonStreamAgentDispatcher; } });
|
|
10
|
+
Object.defineProperty(exports, "streamAgentDispatcher", { enumerable: true, get: function () { return agents_1.streamAgentDispatcher; } });
|
|
11
|
+
var graph_1 = require("./graph");
|
|
12
|
+
Object.defineProperty(exports, "graphRunner", { enumerable: true, get: function () { return graph_1.graphRunner; } });
|
|
13
|
+
Object.defineProperty(exports, "streamGraphRunner", { enumerable: true, get: function () { return graph_1.streamGraphRunner; } });
|
|
14
|
+
Object.defineProperty(exports, "nonStreamGraphRunner", { enumerable: true, get: function () { return graph_1.nonStreamGraphRunner; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@receptron/graphai_express",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "GraphAI express web server middleware.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"eslint": "eslint --fix",
|
|
12
12
|
"server": "ts-node -r tsconfig-paths/register test/express.ts",
|
|
13
13
|
"test_stream": "ts-node -r tsconfig-paths/register test/stream_client.ts",
|
|
14
|
+
"test_stream2": "ts-node -r tsconfig-paths/register test/stream_graph.ts",
|
|
14
15
|
"test": "ts-node -r tsconfig-paths/register test/client.ts",
|
|
15
16
|
"format": "prettier --write '{src,test}/**/*.{yaml,ts,json}'",
|
|
16
17
|
"ci": "yarn run format && yarn run eslint && yarn run build"
|