@receptron/graphai_express 0.0.7 → 0.0.8

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/README.md CHANGED
@@ -13,7 +13,8 @@ yarn add @receptron/graphai_express
13
13
 
14
14
  import express from "express";
15
15
  import * as agents from "graphai/lib/experimental_agents";
16
- import { agentDispatcher, streamAgentDispatcher, agentsList, agentDoc } from "@receptron/graphai_express";
16
+ import { agentDispatcher, nonStreamAgentDispatcher, streamAgentDispatcher, agentsList, agentDoc } from "@receptron/graphai_express";
17
+ import { AgentFunctionInfoDictionary } from "graphai";
17
18
 
18
19
  const agentDictionary: AgentFunctionInfoDictionary = agents;
19
20
  const hostName = "https://example.net";
@@ -22,8 +23,11 @@ const apiPrefix = "/api/agents";
22
23
  app.get(apiPrefix + "/:agentId", agentDoc(agentDictionary, hostName, apiPrefix)); // each API(agent) document
23
24
  app.get(apiPrefix + "/", agentsList(agentDictionary, hostName, apiPrefix)); // API(agent) list
24
25
 
26
+ // non stream and strwam
27
+ app.post(apiPrefix + "/:agentId", agentDispatcher(agentDictionary));
28
+
25
29
  // non stream
26
- app.post(apiPrefix + "/:agentId", agentDispatcher(agentDictionary)); // dispatch agents
30
+ app.post(apiPrefix + "/nonstream/:agentId", nonStreamAgentDispatcher(agentDictionary));
27
31
 
28
32
  // stream
29
33
  app.post(apiPrefix + "/stream/:agentId", streamAgentDispatcher(agentDictionary));
package/lib/express.d.ts CHANGED
@@ -3,4 +3,5 @@ import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
3
3
  export declare const agentsList: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
4
4
  export declare const agentDoc: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
5
5
  export declare const agentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
6
+ export declare const nonStreamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
6
7
  export declare const streamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
package/lib/express.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.streamAgentDispatcher = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
3
+ exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
4
4
  const graphai_1 = require("graphai");
5
5
  const stream_1 = require("graphai/lib/experimental_agent_filters/stream");
6
6
  // express middleware
@@ -53,13 +53,28 @@ exports.agentDoc = agentDoc;
53
53
  // express middleware
54
54
  // run agent
55
55
  const agentDispatcher = (agentDictionary, agentFilters = []) => {
56
+ const nonStram = (0, exports.nonStreamAgentDispatcher)(agentDictionary, agentFilters);
57
+ const stream = (0, exports.streamAgentDispatcher)(agentDictionary, agentFilters);
58
+ return async (req, res) => {
59
+ const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
60
+ console.log(isStreaming);
61
+ if (isStreaming) {
62
+ return await stream(req, res);
63
+ }
64
+ return await nonStram(req, res);
65
+ };
66
+ };
67
+ exports.agentDispatcher = agentDispatcher;
68
+ // express middleware
69
+ // run agent
70
+ const nonStreamAgentDispatcher = (agentDictionary, agentFilters = []) => {
56
71
  return async (req, res) => {
57
72
  const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters);
58
73
  const result = await dispatcher(req, res);
59
74
  return res.json(result);
60
75
  };
61
76
  };
62
- exports.agentDispatcher = agentDispatcher;
77
+ exports.nonStreamAgentDispatcher = nonStreamAgentDispatcher;
63
78
  // express middleware
64
79
  // run agent with streaming
65
80
  const streamAgentDispatcher = (agentDictionary, agentFilters = []) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@receptron/graphai_express",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "GraphAI express web server middleware.",
5
5
  "main": "lib/express.js",
6
6
  "files": [