@receptron/graphai_express 2.0.0 → 3.0.1

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 CHANGED
@@ -1,10 +1,10 @@
1
1
  import express from "express";
2
- import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
2
+ import type { AgentFunctionInfoDictionary, AgentFilterInfo, ConfigDataDictionary } from "graphai";
3
3
  import { StreamChunkCallback, ContentCallback } from "./type";
4
4
  export declare const updateAgentVerbose: (val: boolean) => void;
5
5
  export declare const agentsList: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
6
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[], streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
8
- export declare const agentRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
9
- export declare const nonStreamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
10
- export declare const streamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean, streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback, endOfStreamDelimiter?: string) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
7
+ export declare const agentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, config?: ConfigDataDictionary, contentCallback?: ContentCallback) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
8
+ export declare const agentRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, config?: ConfigDataDictionary, contentCallback?: ContentCallback) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
9
+ export declare const nonStreamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean, config?: ConfigDataDictionary) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
10
+ export declare const streamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean, streamChunkCallback?: StreamChunkCallback, config?: ConfigDataDictionary, contentCallback?: ContentCallback, endOfStreamDelimiter?: string) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
package/lib/agents.js CHANGED
@@ -61,9 +61,9 @@ const agentDoc = (agentDictionary, hostName = "https://example.com", urlPath = "
61
61
  };
62
62
  };
63
63
  exports.agentDoc = agentDoc;
64
- const __agentDispatcher = (agentDictionary, agentFilters = [], streamChunkCallback, contentCallback = utils_1.defaultContentCallback, isDispatch = true) => {
65
- const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters, isDispatch);
66
- const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters, isDispatch, streamChunkCallback, contentCallback);
64
+ const __agentDispatcher = (agentDictionary, agentFilters = [], streamChunkCallback, contentCallback = utils_1.defaultContentCallback, isDispatch = true, config = {}) => {
65
+ const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters, isDispatch, config);
66
+ const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters, isDispatch, streamChunkCallback, config, contentCallback, type_1.DefaultEndOfStreamDelimiter);
67
67
  return async (req, res, next) => {
68
68
  const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
69
69
  if (graphaiExpressVerbose) {
@@ -78,26 +78,26 @@ const __agentDispatcher = (agentDictionary, agentFilters = [], streamChunkCallba
78
78
  // express middleware
79
79
  // dispatch and run agent
80
80
  // app.post(apiPrefix + "/:agentId", agentDispatcher(agentDictionary));
81
- const agentDispatcher = (agentDictionary, agentFilters = [], streamChunkCallback, contentCallback = utils_1.defaultContentCallback) => {
82
- return __agentDispatcher(agentDictionary, agentFilters, streamChunkCallback, contentCallback, true);
81
+ const agentDispatcher = (agentDictionary, agentFilters = [], streamChunkCallback, config = {}, contentCallback = utils_1.defaultContentCallback) => {
82
+ return __agentDispatcher(agentDictionary, agentFilters, streamChunkCallback, contentCallback, true, config);
83
83
  };
84
84
  exports.agentDispatcher = agentDispatcher;
85
85
  // express middleware
86
86
  // run agent
87
87
  // app.post(agentPrefix, agentRunner(agentDictionary));
88
- const agentRunner = (agentDictionary, agentFilters = [], streamChunkCallback, contentCallback = utils_1.defaultContentCallback) => {
89
- return __agentDispatcher(agentDictionary, agentFilters, streamChunkCallback, contentCallback, false);
88
+ const agentRunner = (agentDictionary, agentFilters = [], streamChunkCallback, config = {}, contentCallback = utils_1.defaultContentCallback) => {
89
+ return __agentDispatcher(agentDictionary, agentFilters, streamChunkCallback, contentCallback, false, config);
90
90
  };
91
91
  exports.agentRunner = agentRunner;
92
92
  // express middleware
93
93
  // run agent
94
- const nonStreamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true) => {
94
+ const nonStreamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true, config = {}) => {
95
95
  return async (req, res, next) => {
96
96
  if (graphaiExpressVerbose) {
97
97
  console.log("nonStreamAgentDispatcher");
98
98
  }
99
99
  try {
100
- const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters, isDispatch);
100
+ const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters, isDispatch, config);
101
101
  const result = await dispatcher(req, res);
102
102
  res.json(result);
103
103
  }
@@ -109,7 +109,7 @@ const nonStreamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch
109
109
  exports.nonStreamAgentDispatcher = nonStreamAgentDispatcher;
110
110
  // express middleware
111
111
  // run agent with streaming
112
- const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true, streamChunkCallback, contentCallback = utils_1.defaultContentCallback, endOfStreamDelimiter = type_1.DefaultEndOfStreamDelimiter) => {
112
+ const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch = true, streamChunkCallback, config = {}, contentCallback = utils_1.defaultContentCallback, endOfStreamDelimiter = type_1.DefaultEndOfStreamDelimiter) => {
113
113
  return async (req, res, next) => {
114
114
  if (graphaiExpressVerbose) {
115
115
  console.log("streamAgentDispatcher");
@@ -133,7 +133,7 @@ const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch =
133
133
  agent: (0, stream_agent_filter_1.streamAgentFilterGenerator)(callback),
134
134
  };
135
135
  const filterList = [...agentFilters, streamAgentFilter];
136
- const dispatcher = agentDispatcherInternal(agentDictionary, filterList, isDispatch);
136
+ const dispatcher = agentDispatcherInternal(agentDictionary, filterList, isDispatch, config);
137
137
  const result = await dispatcher(req, res);
138
138
  if (endOfStreamDelimiter !== "") {
139
139
  res.write(endOfStreamDelimiter);
@@ -147,8 +147,17 @@ const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch =
147
147
  };
148
148
  };
149
149
  exports.streamAgentDispatcher = streamAgentDispatcher;
150
+ const getConfig = (config, agentId) => {
151
+ if (agentId) {
152
+ return {
153
+ ...(config["global"] ?? {}),
154
+ ...(config[agentId] ?? {}),
155
+ };
156
+ }
157
+ return {};
158
+ };
150
159
  // dispatcher internal function
151
- const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch = true) => {
160
+ const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch = true, config = {}) => {
152
161
  return async (req, res) => {
153
162
  if (graphaiExpressVerbose) {
154
163
  console.log("agentDispatcherInternal");
@@ -167,6 +176,7 @@ const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch
167
176
  debugInfo,
168
177
  agents: agentDictionary,
169
178
  filterParams,
179
+ config: getConfig(config, agentId),
170
180
  };
171
181
  if (graphaiExpressVerbose) {
172
182
  const { agents: __nonLog, ...logContext } = context;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@receptron/graphai_express",
3
- "version": "2.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "GraphAI express web server middleware.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@graphai/agent_filter_utils": "^2.0.0",
37
- "@graphai/stream_agent_filter": "^2.0.1",
37
+ "@graphai/stream_agent_filter": "^2.0.2",
38
38
  "cors": "^2.8.5",
39
39
  "dotenv": "^16.5.0",
40
40
  "express": "^5.1.0"