@receptron/graphai_express 0.0.22 → 0.0.24
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/{express.d.ts → index.d.ts} +6 -3
- package/lib/{express.js → index.js} +28 -11
- package/lib/type.d.ts +15 -0
- package/lib/type.js +2 -0
- package/package.json +6 -6
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import express from "
|
|
1
|
+
import express from "express";
|
|
2
2
|
import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
|
|
3
|
+
import { ExpressAgentInfo } from "./type";
|
|
4
|
+
export { ExpressAgentInfo };
|
|
3
5
|
export declare const agentsList: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
4
6
|
export declare const agentDoc: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
5
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>;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
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,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
|
|
3
|
+
exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentRunner = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
|
|
4
4
|
const agent_filters_1 = require("@graphai/agent_filters");
|
|
5
5
|
// express middleware
|
|
6
6
|
// return agent list
|
|
@@ -20,7 +20,7 @@ const agentsList = (agentDictionary, hostName = "https://example.com", urlPath =
|
|
|
20
20
|
samples: agent.samples,
|
|
21
21
|
inputs: agent.inputs,
|
|
22
22
|
output: agent.output,
|
|
23
|
-
stream: agent.stream,
|
|
23
|
+
stream: agent.stream ?? false,
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
26
|
res.json({ agents: list });
|
|
@@ -54,10 +54,11 @@ const agentDoc = (agentDictionary, hostName = "https://example.com", urlPath = "
|
|
|
54
54
|
};
|
|
55
55
|
exports.agentDoc = agentDoc;
|
|
56
56
|
// express middleware
|
|
57
|
-
// run agent
|
|
57
|
+
// dispatch and run agent
|
|
58
|
+
// app.post(apiPrefix + "/:agentId", agentDispatcher(agentDictionary));
|
|
58
59
|
const agentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
59
|
-
const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters);
|
|
60
|
-
const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters);
|
|
60
|
+
const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters, true);
|
|
61
|
+
const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters, true);
|
|
61
62
|
return async (req, res, next) => {
|
|
62
63
|
const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
|
|
63
64
|
if (isStreaming) {
|
|
@@ -69,10 +70,25 @@ const agentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
|
69
70
|
exports.agentDispatcher = agentDispatcher;
|
|
70
71
|
// express middleware
|
|
71
72
|
// run agent
|
|
72
|
-
|
|
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) => {
|
|
73
89
|
return async (req, res, next) => {
|
|
74
90
|
try {
|
|
75
|
-
const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters);
|
|
91
|
+
const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters, isDispatch);
|
|
76
92
|
const result = await dispatcher(req, res);
|
|
77
93
|
return res.json(result);
|
|
78
94
|
}
|
|
@@ -84,7 +100,7 @@ const nonStreamAgentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
|
84
100
|
exports.nonStreamAgentDispatcher = nonStreamAgentDispatcher;
|
|
85
101
|
// express middleware
|
|
86
102
|
// run agent with streaming
|
|
87
|
-
const streamAgentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
103
|
+
const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
88
104
|
return async (req, res, next) => {
|
|
89
105
|
try {
|
|
90
106
|
res.setHeader("Content-Type", "text/event-stream;charset=utf-8");
|
|
@@ -100,7 +116,7 @@ const streamAgentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
|
100
116
|
agent: (0, agent_filters_1.streamAgentFilterGenerator)(callback),
|
|
101
117
|
};
|
|
102
118
|
const filterList = [...agentFilters, streamAgentFilter];
|
|
103
|
-
const dispatcher = agentDispatcherInternal(agentDictionary, filterList);
|
|
119
|
+
const dispatcher = agentDispatcherInternal(agentDictionary, filterList, isDispatch);
|
|
104
120
|
const result = await dispatcher(req, res);
|
|
105
121
|
const json_data = JSON.stringify(result);
|
|
106
122
|
res.write("___END___");
|
|
@@ -114,10 +130,11 @@ const streamAgentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
|
114
130
|
};
|
|
115
131
|
exports.streamAgentDispatcher = streamAgentDispatcher;
|
|
116
132
|
// dispatcher internal function
|
|
117
|
-
const agentDispatcherInternal = (agentDictionary, agentFilters = []) => {
|
|
133
|
+
const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch = true) => {
|
|
118
134
|
return async (req, res) => {
|
|
119
135
|
const { params } = req;
|
|
120
|
-
const { agentId } = params;
|
|
136
|
+
const { agentId } = isDispatch ? params : req.body;
|
|
137
|
+
console.log(agentId);
|
|
121
138
|
const { nodeId, retry, params: agentParams, inputs, namedInputs } = req.body;
|
|
122
139
|
const agent = agentDictionary[agentId];
|
|
123
140
|
if (agent === undefined) {
|
package/lib/type.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentFunctionInfoSample } from "graphai";
|
|
2
|
+
export type ExpressAgentInfo = {
|
|
3
|
+
agentId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
url: string;
|
|
6
|
+
description: string;
|
|
7
|
+
category: string[];
|
|
8
|
+
author: string;
|
|
9
|
+
license: string;
|
|
10
|
+
repository: string;
|
|
11
|
+
samples: AgentFunctionInfoSample[];
|
|
12
|
+
inputs: any;
|
|
13
|
+
output: any;
|
|
14
|
+
stream: boolean;
|
|
15
|
+
};
|
package/lib/type.js
ADDED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@receptron/graphai_express",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "GraphAI express web server middleware.",
|
|
5
|
-
"main": "lib/
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"./lib"
|
|
8
8
|
],
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/receptron/graphai_utils/tree/main/packages/express#readme",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@graphai/agents": "^0.0.
|
|
29
|
+
"@graphai/agents": "^0.0.14",
|
|
30
30
|
"@types/express": "^4.17.21",
|
|
31
31
|
"@types/node": "^20.8.7",
|
|
32
32
|
"eslint": "^9.3.0",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"typescript-eslint": "^7.9.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@graphai/agent_filters": "^0.0.
|
|
41
|
+
"@graphai/agent_filters": "^0.0.6",
|
|
42
42
|
"dotenv": "^16.4.5",
|
|
43
43
|
"express": "^4.19.2",
|
|
44
|
-
"graphai": "^0.5.
|
|
44
|
+
"graphai": "^0.5.2"
|
|
45
45
|
},
|
|
46
|
-
"types": "./lib/
|
|
46
|
+
"types": "./lib/index.d.ts",
|
|
47
47
|
"directories": {
|
|
48
48
|
"lib": "lib"
|
|
49
49
|
}
|