@receptron/graphai_express 0.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/README.md +27 -0
- package/lib/express.d.ts +4 -0
- package/lib/express.js +94 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
## GraphAI express middleware.
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
import express from "express";
|
|
9
|
+
import { agentDispatcher, agentsList, agentDoc } from "@/express";
|
|
10
|
+
|
|
11
|
+
const hostName = "https://example.net";
|
|
12
|
+
const apiPrefix = "/api/agents";
|
|
13
|
+
|
|
14
|
+
app.post(apiPrefix + "/:agentId", agentDispatcher); // dispatch agents
|
|
15
|
+
app.get(apiPrefix + "/:agentId", agentDoc(hostName, apiPrefix)); // each API(agent) document
|
|
16
|
+
app.get(apiPrefix + "/", agentsList(hostName, apiPrefix)); // API(agent) list
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### from curl.
|
|
22
|
+
|
|
23
|
+
T.B.D.
|
|
24
|
+
|
|
25
|
+
### from GraphAI Client
|
|
26
|
+
|
|
27
|
+
T.B.D.
|
package/lib/express.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import express from "./express";
|
|
2
|
+
export declare const agentDoc: (hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
|
3
|
+
export declare const agentDispatcher: (req: express.Request, res: express.Response) => Promise<void>;
|
|
4
|
+
export declare const agentsList: (hostName?: string, urlPath?: string) => (req: express.Request, res: express.Response) => Promise<void>;
|
package/lib/express.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.agentsList = exports.agentDispatcher = exports.agentDoc = void 0;
|
|
27
|
+
const agents = __importStar(require("graphai/lib/experimental_agents"));
|
|
28
|
+
const agentDictionary = agents;
|
|
29
|
+
const agentDoc = (hostName = "https://example.com", urlPath = "/agent") => {
|
|
30
|
+
return async (req, res) => {
|
|
31
|
+
const { params } = req;
|
|
32
|
+
const { agentId } = params;
|
|
33
|
+
const agent = agentDictionary[agentId];
|
|
34
|
+
if (agent === undefined) {
|
|
35
|
+
res.status(404).send("Not found");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const result = {
|
|
39
|
+
agentId: agentId,
|
|
40
|
+
name: agent.name,
|
|
41
|
+
url: hostName + urlPath + "/" + agentId,
|
|
42
|
+
description: agent.description,
|
|
43
|
+
category: agent.category,
|
|
44
|
+
samples: agent.samples,
|
|
45
|
+
author: agent.author,
|
|
46
|
+
license: agent.license,
|
|
47
|
+
repository: agent.repository,
|
|
48
|
+
};
|
|
49
|
+
res.json(result);
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
exports.agentDoc = agentDoc;
|
|
53
|
+
const agentDispatcher = async (req, res) => {
|
|
54
|
+
const { params } = req;
|
|
55
|
+
const { agentId } = params;
|
|
56
|
+
const { nodeId, retry, params: agentParams, inputs } = req.body;
|
|
57
|
+
const agent = agentDictionary[agentId];
|
|
58
|
+
if (agent === undefined) {
|
|
59
|
+
res.status(404).send("Not found");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const result = await agent.agent({
|
|
63
|
+
params: agentParams,
|
|
64
|
+
inputs,
|
|
65
|
+
debugInfo: {
|
|
66
|
+
nodeId,
|
|
67
|
+
retry,
|
|
68
|
+
verbose: false,
|
|
69
|
+
},
|
|
70
|
+
agents,
|
|
71
|
+
filterParams: {},
|
|
72
|
+
});
|
|
73
|
+
res.json(result);
|
|
74
|
+
};
|
|
75
|
+
exports.agentDispatcher = agentDispatcher;
|
|
76
|
+
const agentsList = (hostName = "https://example.com", urlPath = "/agent") => {
|
|
77
|
+
return async (req, res) => {
|
|
78
|
+
const list = Object.keys(agentDictionary).map((agentName) => {
|
|
79
|
+
const agent = agentDictionary[agentName];
|
|
80
|
+
return {
|
|
81
|
+
agentId: agentName,
|
|
82
|
+
name: agent.name,
|
|
83
|
+
url: hostName + urlPath + "/" + agentName,
|
|
84
|
+
description: agent.description,
|
|
85
|
+
category: agent.category,
|
|
86
|
+
author: agent.author,
|
|
87
|
+
license: agent.license,
|
|
88
|
+
repository: agent.repository,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
res.json({ agents: list });
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
exports.agentsList = agentsList;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@receptron/graphai_express",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "GraphAI express web server middleware.",
|
|
5
|
+
"main": "lib/express.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"./lib"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc && tsc-alias",
|
|
11
|
+
"eslint": "eslint --fix",
|
|
12
|
+
"server": "ts-node -r tsconfig-paths/register test/express.ts",
|
|
13
|
+
"format": "prettier --write '{src,test}/**/*.{yaml,ts,json}'",
|
|
14
|
+
"test": "node --test -r tsconfig-paths/register --require ts-node/register ./test/test_*.ts",
|
|
15
|
+
"b": "yarn run format && yarn run eslint && yarn run build"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/receptron/graphai_utils"
|
|
20
|
+
},
|
|
21
|
+
"author": "Receptron team",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/receptron/graphai_utils/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/receptron/graphai_utils#readme",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/express": "^4.17.21",
|
|
29
|
+
"@types/json-schema-generator": "^2.0.3",
|
|
30
|
+
"@types/node": "^20.8.7",
|
|
31
|
+
"@types/yargs": "^17.0.32",
|
|
32
|
+
"eslint": "^9.2.0",
|
|
33
|
+
"prettier": "^3.0.3",
|
|
34
|
+
"ts-node": "^10.9.1",
|
|
35
|
+
"tsc-alias": "^1.8.8",
|
|
36
|
+
"tsconfig-paths": "^4.2.0",
|
|
37
|
+
"typescript": "^5.4.3",
|
|
38
|
+
"typescript-eslint": "^7.8.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@inquirer/prompts": "^5.0.0",
|
|
42
|
+
"arxiv-api-ts": "^1.0.3",
|
|
43
|
+
"deepmerge": "^4.3.1",
|
|
44
|
+
"dotenv": "^16.4.5",
|
|
45
|
+
"express": "^4.19.2",
|
|
46
|
+
"graphai": "0.4.2",
|
|
47
|
+
"groq-sdk": "^0.3.3",
|
|
48
|
+
"json-schema-generator": "^2.0.6",
|
|
49
|
+
"openai": "^4.12.4",
|
|
50
|
+
"slashgpt": "^0.0.8",
|
|
51
|
+
"tiktoken": "^1.0.14",
|
|
52
|
+
"wikipedia": "^2.1.2",
|
|
53
|
+
"xml2js": "^0.6.2",
|
|
54
|
+
"yaml": "^2.3.3",
|
|
55
|
+
"yargs": "^17.7.2"
|
|
56
|
+
},
|
|
57
|
+
"types": "./lib/express.d.ts",
|
|
58
|
+
"directories": {
|
|
59
|
+
"lib": "lib"
|
|
60
|
+
}
|
|
61
|
+
}
|