@receptron/graphai_express 0.0.23 → 0.0.25

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.
@@ -1,21 +1,10 @@
1
- import express from "./express";
1
+ import express from "express";
2
2
  import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
3
- export type ExpressAgentInfo = {
4
- agentId: string;
5
- name: string;
6
- url: string;
7
- description: string;
8
- category: string[];
9
- author: string;
10
- license: string;
11
- repository: string;
12
- samples: any;
13
- inputs: any;
14
- output: any;
15
- stream: boolean;
16
- };
3
+ import { ExpressAgentInfo } from "./type";
4
+ export { ExpressAgentInfo };
17
5
  export declare const agentsList: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
18
6
  export declare const agentDoc: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
19
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>;
20
- export declare const nonStreamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
21
- export declare const streamAgentDispatcher: (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,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
@@ -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
- const nonStreamAgentDispatcher = (agentDictionary, agentFilters = []) => {
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
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@receptron/graphai_express",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "GraphAI express web server middleware.",
5
- "main": "lib/express.js",
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.9",
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.5",
41
+ "@graphai/agent_filters": "^0.0.6",
42
42
  "dotenv": "^16.4.5",
43
43
  "express": "^4.19.2",
44
- "graphai": "^0.5.1"
44
+ "graphai": "^0.5.3"
45
45
  },
46
- "types": "./lib/express.d.ts",
46
+ "types": "./lib/index.d.ts",
47
47
  "directories": {
48
48
  "lib": "lib"
49
49
  }