@receptron/graphai_express 0.1.2 → 0.2.0
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 +1 -0
- package/lib/agents.js +25 -10
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/package.json +6 -8
package/lib/agents.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
|
|
3
3
|
import { StreamChunkCallback, ContentCallback } from "./type";
|
|
4
|
+
export declare const updateAgentVerbose: (val: boolean) => void;
|
|
4
5
|
export declare const agentsList: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
5
6
|
export declare const agentDoc: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
6
7
|
export declare const agentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
|
package/lib/agents.js
CHANGED
|
@@ -1,9 +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;
|
|
3
|
+
exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentRunner = exports.agentDispatcher = exports.agentDoc = exports.agentsList = exports.updateAgentVerbose = void 0;
|
|
4
4
|
const agent_filters_1 = require("@graphai/agent_filters");
|
|
5
5
|
const type_1 = require("./type");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
+
let graphaiExpressVerbose = false;
|
|
8
|
+
const updateAgentVerbose = (val) => {
|
|
9
|
+
graphaiExpressVerbose = val;
|
|
10
|
+
};
|
|
11
|
+
exports.updateAgentVerbose = updateAgentVerbose;
|
|
7
12
|
// express middleware
|
|
8
13
|
// return agent list
|
|
9
14
|
const agentsList = (agentDictionary, hostName = "https://example.com", urlPath = "/agent") => {
|
|
@@ -60,6 +65,9 @@ const __agentDispatcher = (agentDictionary, agentFilters = [], streamChunkCallba
|
|
|
60
65
|
const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters, isDispatch, streamChunkCallback, contentCallback);
|
|
61
66
|
return async (req, res, next) => {
|
|
62
67
|
const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
|
|
68
|
+
if (graphaiExpressVerbose) {
|
|
69
|
+
console.log("__agentDispatcher(isStreaming): ", isStreaming);
|
|
70
|
+
}
|
|
63
71
|
if (isStreaming) {
|
|
64
72
|
return await stream(req, res, next);
|
|
65
73
|
}
|
|
@@ -84,6 +92,9 @@ exports.agentRunner = agentRunner;
|
|
|
84
92
|
// run agent
|
|
85
93
|
const nonStreamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
86
94
|
return async (req, res, next) => {
|
|
95
|
+
if (graphaiExpressVerbose) {
|
|
96
|
+
console.log("nonStreamAgentDispatcher");
|
|
97
|
+
}
|
|
87
98
|
try {
|
|
88
99
|
const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters, isDispatch);
|
|
89
100
|
const result = await dispatcher(req, res);
|
|
@@ -99,6 +110,9 @@ exports.nonStreamAgentDispatcher = nonStreamAgentDispatcher;
|
|
|
99
110
|
// run agent with streaming
|
|
100
111
|
const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true, streamChunkCallback, contentCallback = utils_1.defaultContentCallback, endOfStreamDelimiter = type_1.DefaultEndOfStreamDelimiter) => {
|
|
101
112
|
return async (req, res, next) => {
|
|
113
|
+
if (graphaiExpressVerbose) {
|
|
114
|
+
console.log("streamAgentDispatcher");
|
|
115
|
+
}
|
|
102
116
|
try {
|
|
103
117
|
res.setHeader("Content-Type", "text/event-stream;charset=utf-8");
|
|
104
118
|
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
@@ -135,9 +149,12 @@ exports.streamAgentDispatcher = streamAgentDispatcher;
|
|
|
135
149
|
// dispatcher internal function
|
|
136
150
|
const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
137
151
|
return async (req, res) => {
|
|
152
|
+
if (graphaiExpressVerbose) {
|
|
153
|
+
console.log("agentDispatcherInternal");
|
|
154
|
+
}
|
|
138
155
|
const { params } = req;
|
|
139
|
-
const { agentId } = isDispatch ? params : req.body;
|
|
140
|
-
const {
|
|
156
|
+
const { agentId } = isDispatch ? params : req.body.debugInfo;
|
|
157
|
+
const { params: agentParams, debugInfo, filterParams, namedInputs /* graphData */ } = req.body;
|
|
141
158
|
const agent = agentDictionary[agentId];
|
|
142
159
|
if (agent === undefined) {
|
|
143
160
|
res.status(404).send("Not found");
|
|
@@ -145,16 +162,14 @@ const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch
|
|
|
145
162
|
}
|
|
146
163
|
const context = {
|
|
147
164
|
params: agentParams || {},
|
|
148
|
-
inputs,
|
|
149
165
|
namedInputs,
|
|
150
|
-
debugInfo
|
|
151
|
-
nodeId,
|
|
152
|
-
retry,
|
|
153
|
-
verbose: false,
|
|
154
|
-
},
|
|
166
|
+
debugInfo,
|
|
155
167
|
agents: agentDictionary,
|
|
156
|
-
filterParams
|
|
168
|
+
filterParams,
|
|
157
169
|
};
|
|
170
|
+
if (graphaiExpressVerbose) {
|
|
171
|
+
console.log("agentDispatcherInternal(context): ", context);
|
|
172
|
+
}
|
|
158
173
|
const agentFilterRunner = (0, agent_filters_1.agentFilterRunnerBuilder)(agentFilters);
|
|
159
174
|
const result = await agentFilterRunner(context, agent.agent);
|
|
160
175
|
return result;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { agentsList, agentDoc, agentDispatcher, agentRunner, nonStreamAgentDispatcher, streamAgentDispatcher } from "./agents";
|
|
1
|
+
export { agentsList, agentDoc, agentDispatcher, agentRunner, nonStreamAgentDispatcher, streamAgentDispatcher, updateAgentVerbose } from "./agents";
|
|
2
2
|
export { graphRunner, streamGraphRunner, nonStreamGraphRunner } from "./graph";
|
|
3
3
|
export { ExpressAgentInfo, StreamChunkCallback, ContentCallback } from "./type";
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nonStreamGraphRunner = exports.streamGraphRunner = exports.graphRunner = exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentRunner = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
|
|
3
|
+
exports.nonStreamGraphRunner = exports.streamGraphRunner = exports.graphRunner = exports.updateAgentVerbose = exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentRunner = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
|
|
4
4
|
var agents_1 = require("./agents");
|
|
5
5
|
Object.defineProperty(exports, "agentsList", { enumerable: true, get: function () { return agents_1.agentsList; } });
|
|
6
6
|
Object.defineProperty(exports, "agentDoc", { enumerable: true, get: function () { return agents_1.agentDoc; } });
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "agentDispatcher", { enumerable: true, get: funct
|
|
|
8
8
|
Object.defineProperty(exports, "agentRunner", { enumerable: true, get: function () { return agents_1.agentRunner; } });
|
|
9
9
|
Object.defineProperty(exports, "nonStreamAgentDispatcher", { enumerable: true, get: function () { return agents_1.nonStreamAgentDispatcher; } });
|
|
10
10
|
Object.defineProperty(exports, "streamAgentDispatcher", { enumerable: true, get: function () { return agents_1.streamAgentDispatcher; } });
|
|
11
|
+
Object.defineProperty(exports, "updateAgentVerbose", { enumerable: true, get: function () { return agents_1.updateAgentVerbose; } });
|
|
11
12
|
var graph_1 = require("./graph");
|
|
12
13
|
Object.defineProperty(exports, "graphRunner", { enumerable: true, get: function () { return graph_1.graphRunner; } });
|
|
13
14
|
Object.defineProperty(exports, "streamGraphRunner", { enumerable: true, get: function () { return graph_1.streamGraphRunner; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@receptron/graphai_express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "GraphAI express web server middleware.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -27,17 +27,15 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/receptron/graphai_utils/tree/main/packages/express#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"
|
|
31
|
-
"graphai": "^0.6.7",
|
|
30
|
+
"@types/cors": "^2.8.17",
|
|
32
31
|
"sinon": "^19.0.2",
|
|
33
|
-
"sinon-express-mock": "^2.2.1"
|
|
34
|
-
"typescript-eslint": "^8.18.1"
|
|
32
|
+
"sinon-express-mock": "^2.2.1"
|
|
35
33
|
},
|
|
36
34
|
"dependencies": {
|
|
37
|
-
"@graphai/agent_filters": "^0.
|
|
35
|
+
"@graphai/agent_filters": "^0.2.2",
|
|
36
|
+
"cors": "^2.8.5",
|
|
38
37
|
"dotenv": "^16.4.7",
|
|
39
|
-
"express": "^4.21.2"
|
|
40
|
-
"graphai": "^0.6.7"
|
|
38
|
+
"express": "^4.21.2"
|
|
41
39
|
},
|
|
42
40
|
"types": "./lib/index.d.ts",
|
|
43
41
|
"directories": {
|