@receptron/graphai_express 0.0.5 → 0.0.7
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 +6 -4
- package/lib/express.d.ts +5 -5
- package/lib/express.js +8 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,19 +12,21 @@ yarn add @receptron/graphai_express
|
|
|
12
12
|
```TypeScript
|
|
13
13
|
|
|
14
14
|
import express from "express";
|
|
15
|
+
import * as agents from "graphai/lib/experimental_agents";
|
|
15
16
|
import { agentDispatcher, streamAgentDispatcher, agentsList, agentDoc } from "@receptron/graphai_express";
|
|
16
17
|
|
|
18
|
+
const agentDictionary: AgentFunctionInfoDictionary = agents;
|
|
17
19
|
const hostName = "https://example.net";
|
|
18
20
|
const apiPrefix = "/api/agents";
|
|
19
21
|
|
|
20
|
-
app.get(apiPrefix + "/:agentId", agentDoc(hostName, apiPrefix)); // each API(agent) document
|
|
21
|
-
app.get(apiPrefix + "/", agentsList(hostName, apiPrefix)); // API(agent) list
|
|
22
|
+
app.get(apiPrefix + "/:agentId", agentDoc(agentDictionary, hostName, apiPrefix)); // each API(agent) document
|
|
23
|
+
app.get(apiPrefix + "/", agentsList(agentDictionary, hostName, apiPrefix)); // API(agent) list
|
|
22
24
|
|
|
23
25
|
// non stream
|
|
24
|
-
app.post(apiPrefix + "/:agentId", agentDispatcher()); // dispatch agents
|
|
26
|
+
app.post(apiPrefix + "/:agentId", agentDispatcher(agentDictionary)); // dispatch agents
|
|
25
27
|
|
|
26
28
|
// stream
|
|
27
|
-
app.post(apiPrefix + "/stream/:agentId", streamAgentDispatcher());
|
|
29
|
+
app.post(apiPrefix + "/stream/:agentId", streamAgentDispatcher(agentDictionary));
|
|
28
30
|
|
|
29
31
|
```
|
|
30
32
|
|
package/lib/express.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from "./express";
|
|
2
|
-
import type { AgentFilterInfo } from "graphai";
|
|
3
|
-
export declare const agentsList: (hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
4
|
-
export declare const agentDoc: (hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
5
|
-
export declare const agentDispatcher: (agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
|
|
6
|
-
export declare const streamAgentDispatcher: (agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
|
|
2
|
+
import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
|
|
3
|
+
export declare const agentsList: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
4
|
+
export declare const agentDoc: (agentDictionary: AgentFunctionInfoDictionary, hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
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 streamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
|
package/lib/express.js
CHANGED
|
@@ -1,36 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.streamAgentDispatcher = exports.agentDispatcher = exports.agentDoc = exports.agentsList = void 0;
|
|
27
4
|
const graphai_1 = require("graphai");
|
|
28
5
|
const stream_1 = require("graphai/lib/experimental_agent_filters/stream");
|
|
29
|
-
const agents = __importStar(require("graphai/lib/experimental_agents"));
|
|
30
|
-
const agentDictionary = agents;
|
|
31
6
|
// express middleware
|
|
32
7
|
// return agent list
|
|
33
|
-
const agentsList = (hostName = "https://example.com", urlPath = "/agent") => {
|
|
8
|
+
const agentsList = (agentDictionary, hostName = "https://example.com", urlPath = "/agent") => {
|
|
34
9
|
return async (req, res) => {
|
|
35
10
|
const list = Object.keys(agentDictionary).map((agentName) => {
|
|
36
11
|
const agent = agentDictionary[agentName];
|
|
@@ -51,7 +26,7 @@ const agentsList = (hostName = "https://example.com", urlPath = "/agent") => {
|
|
|
51
26
|
exports.agentsList = agentsList;
|
|
52
27
|
// express middleware
|
|
53
28
|
// return agent detail info
|
|
54
|
-
const agentDoc = (hostName = "https://example.com", urlPath = "/agent") => {
|
|
29
|
+
const agentDoc = (agentDictionary, hostName = "https://example.com", urlPath = "/agent") => {
|
|
55
30
|
return async (req, res) => {
|
|
56
31
|
const { params } = req;
|
|
57
32
|
const { agentId } = params;
|
|
@@ -77,9 +52,9 @@ const agentDoc = (hostName = "https://example.com", urlPath = "/agent") => {
|
|
|
77
52
|
exports.agentDoc = agentDoc;
|
|
78
53
|
// express middleware
|
|
79
54
|
// run agent
|
|
80
|
-
const agentDispatcher = (agentFilters = []) => {
|
|
55
|
+
const agentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
81
56
|
return async (req, res) => {
|
|
82
|
-
const dispatcher = agentDispatcherInternal(agentFilters);
|
|
57
|
+
const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters);
|
|
83
58
|
const result = await dispatcher(req, res);
|
|
84
59
|
return res.json(result);
|
|
85
60
|
};
|
|
@@ -87,7 +62,7 @@ const agentDispatcher = (agentFilters = []) => {
|
|
|
87
62
|
exports.agentDispatcher = agentDispatcher;
|
|
88
63
|
// express middleware
|
|
89
64
|
// run agent with streaming
|
|
90
|
-
const streamAgentDispatcher = (agentFilters = []) => {
|
|
65
|
+
const streamAgentDispatcher = (agentDictionary, agentFilters = []) => {
|
|
91
66
|
return async (req, res) => {
|
|
92
67
|
res.setHeader("Content-Type", "text/event-stream;charset=utf-8");
|
|
93
68
|
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
@@ -102,7 +77,7 @@ const streamAgentDispatcher = (agentFilters = []) => {
|
|
|
102
77
|
agent: (0, stream_1.streamAgentFilterGenerator)(callback),
|
|
103
78
|
};
|
|
104
79
|
const filterList = [...agentFilters, streamAgentFilter];
|
|
105
|
-
const dispatcher = agentDispatcherInternal(filterList);
|
|
80
|
+
const dispatcher = agentDispatcherInternal(agentDictionary, filterList);
|
|
106
81
|
const result = await dispatcher(req, res);
|
|
107
82
|
const json_data = JSON.stringify(result);
|
|
108
83
|
res.write("___END___");
|
|
@@ -112,7 +87,7 @@ const streamAgentDispatcher = (agentFilters = []) => {
|
|
|
112
87
|
};
|
|
113
88
|
exports.streamAgentDispatcher = streamAgentDispatcher;
|
|
114
89
|
// dispatcher internal function
|
|
115
|
-
const agentDispatcherInternal = (agentFilters = []) => {
|
|
90
|
+
const agentDispatcherInternal = (agentDictionary, agentFilters = []) => {
|
|
116
91
|
return async (req, res) => {
|
|
117
92
|
const { params } = req;
|
|
118
93
|
const { agentId } = params;
|
|
@@ -130,7 +105,7 @@ const agentDispatcherInternal = (agentFilters = []) => {
|
|
|
130
105
|
retry,
|
|
131
106
|
verbose: false,
|
|
132
107
|
},
|
|
133
|
-
agents,
|
|
108
|
+
agents: agentDictionary,
|
|
134
109
|
filterParams: {},
|
|
135
110
|
};
|
|
136
111
|
const agentFilterRunner = (0, graphai_1.agentFilterRunnerBuilder)(agentFilters);
|