@receptron/graphai_express 1.0.3 → 2.0.0
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 +4 -4
- package/lib/agents.js +6 -5
- package/lib/completions.d.ts +1 -1
- package/lib/completions.js +8 -6
- package/lib/graph.d.ts +3 -3
- package/lib/graph.js +4 -4
- package/package.json +8 -6
package/lib/agents.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ 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<
|
|
8
|
-
export declare const agentRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<
|
|
9
|
-
export declare const nonStreamAgentDispatcher: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], isDispatch?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<
|
|
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<
|
|
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>;
|
package/lib/agents.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.streamAgentDispatcher = exports.nonStreamAgentDispatcher = exports.agentRunner = exports.agentDispatcher = exports.agentDoc = exports.agentsList = exports.updateAgentVerbose = void 0;
|
|
4
|
-
const
|
|
4
|
+
const stream_agent_filter_1 = require("@graphai/stream_agent_filter");
|
|
5
|
+
const agent_filter_utils_1 = require("@graphai/agent_filter_utils");
|
|
5
6
|
const type_1 = require("./type");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
let graphaiExpressVerbose = false;
|
|
@@ -98,7 +99,7 @@ const nonStreamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch
|
|
|
98
99
|
try {
|
|
99
100
|
const dispatcher = agentDispatcherInternal(agentDictionary, agentFilters, isDispatch);
|
|
100
101
|
const result = await dispatcher(req, res);
|
|
101
|
-
|
|
102
|
+
res.json(result);
|
|
102
103
|
}
|
|
103
104
|
catch (e) {
|
|
104
105
|
next(e);
|
|
@@ -129,7 +130,7 @@ const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch =
|
|
|
129
130
|
};
|
|
130
131
|
const streamAgentFilter = {
|
|
131
132
|
name: "streamAgentFilter",
|
|
132
|
-
agent: (0,
|
|
133
|
+
agent: (0, stream_agent_filter_1.streamAgentFilterGenerator)(callback),
|
|
133
134
|
};
|
|
134
135
|
const filterList = [...agentFilters, streamAgentFilter];
|
|
135
136
|
const dispatcher = agentDispatcherInternal(agentDictionary, filterList, isDispatch);
|
|
@@ -138,7 +139,7 @@ const streamAgentDispatcher = (agentDictionary, agentFilters = [], isDispatch =
|
|
|
138
139
|
res.write(endOfStreamDelimiter);
|
|
139
140
|
}
|
|
140
141
|
res.write(contentCallback(result));
|
|
141
|
-
|
|
142
|
+
res.end();
|
|
142
143
|
}
|
|
143
144
|
catch (e) {
|
|
144
145
|
next(e);
|
|
@@ -171,7 +172,7 @@ const agentDispatcherInternal = (agentDictionary, agentFilters = [], isDispatch
|
|
|
171
172
|
const { agents: __nonLog, ...logContext } = context;
|
|
172
173
|
console.log("agentDispatcherInternal(context): ", logContext);
|
|
173
174
|
}
|
|
174
|
-
const agentFilterRunner = (0,
|
|
175
|
+
const agentFilterRunner = (0, agent_filter_utils_1.agentFilterRunnerBuilder)(agentFilters);
|
|
175
176
|
const result = await agentFilterRunner(context, agent.agent);
|
|
176
177
|
return result;
|
|
177
178
|
};
|
package/lib/completions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import type { AgentFunctionInfoDictionary, AgentFilterInfo, TransactionLog } from "graphai";
|
|
3
3
|
import type { Model2GraphData } from "./type";
|
|
4
|
-
export declare const completionRunner: (agentDictionary: AgentFunctionInfoDictionary, model2GraphData: Model2GraphData, agentFilters?: AgentFilterInfo[], onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<
|
|
4
|
+
export declare const completionRunner: (agentDictionary: AgentFunctionInfoDictionary, model2GraphData: Model2GraphData, agentFilters?: AgentFilterInfo[], onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
|
package/lib/completions.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.completionRunner = void 0;
|
|
4
4
|
const graphai_1 = require("graphai");
|
|
5
|
-
const
|
|
5
|
+
const stream_agent_filter_1 = require("@graphai/stream_agent_filter");
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
7
|
// TODO choise graph(done)
|
|
8
8
|
// stream flag(done);
|
|
@@ -38,7 +38,7 @@ const completionRunner = (agentDictionary, model2GraphData, agentFilters = [], o
|
|
|
38
38
|
const { stream, model, messages } = req.body;
|
|
39
39
|
// validation
|
|
40
40
|
if (!model || typeof model !== "string") {
|
|
41
|
-
|
|
41
|
+
res.status(400).json({
|
|
42
42
|
error: {
|
|
43
43
|
message: "`model` is required and must be a string",
|
|
44
44
|
type: "invalid_request_error",
|
|
@@ -46,9 +46,10 @@ const completionRunner = (agentDictionary, model2GraphData, agentFilters = [], o
|
|
|
46
46
|
code: "invalid_model",
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
|
+
return;
|
|
49
50
|
}
|
|
50
51
|
if (!messages || !Array.isArray(messages) || messages.length === 0) {
|
|
51
|
-
|
|
52
|
+
res.status(400).json({
|
|
52
53
|
error: {
|
|
53
54
|
message: "`messages` must be an array of objects with `role` and `content` as strings",
|
|
54
55
|
type: "invalid_request_error",
|
|
@@ -56,6 +57,7 @@ const completionRunner = (agentDictionary, model2GraphData, agentFilters = [], o
|
|
|
56
57
|
code: "invalid_messages",
|
|
57
58
|
},
|
|
58
59
|
});
|
|
60
|
+
return;
|
|
59
61
|
}
|
|
60
62
|
// const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream")
|
|
61
63
|
if (stream) {
|
|
@@ -84,7 +86,7 @@ const streamGraphRunner = (agentDictionary, model2GraphData, agentFilters = [],
|
|
|
84
86
|
};
|
|
85
87
|
const streamAgentFilter = {
|
|
86
88
|
name: "streamAgentFilter",
|
|
87
|
-
agent: (0,
|
|
89
|
+
agent: (0, stream_agent_filter_1.streamAgentFilterGenerator)(streamCallback),
|
|
88
90
|
};
|
|
89
91
|
const filterList = [...agentFilters, streamAgentFilter];
|
|
90
92
|
res.write(streamCompletionChunkCallback(baseData, "start"));
|
|
@@ -97,7 +99,7 @@ const streamGraphRunner = (agentDictionary, model2GraphData, agentFilters = [],
|
|
|
97
99
|
catch (__err) {
|
|
98
100
|
res.write(`data: ${JSON.stringify({ error: "GraphAI Something went wrong" })}\n\n`);
|
|
99
101
|
}
|
|
100
|
-
|
|
102
|
+
res.end();
|
|
101
103
|
}
|
|
102
104
|
catch (e) {
|
|
103
105
|
next(e);
|
|
@@ -109,7 +111,7 @@ const nonStreamGraphRunner = (agentDictionary, model2GraphData, agentFilters = [
|
|
|
109
111
|
try {
|
|
110
112
|
const dispatcher = streamGraphRunnerInternal(agentDictionary, model2GraphData, agentFilters, onLogCallback);
|
|
111
113
|
const result = await dispatcher(req);
|
|
112
|
-
|
|
114
|
+
res.json(result);
|
|
113
115
|
}
|
|
114
116
|
catch (e) {
|
|
115
117
|
next(e);
|
package/lib/graph.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import type { AgentFunctionInfoDictionary, AgentFilterInfo, TransactionLog } from "graphai";
|
|
3
3
|
import type { StreamChunkCallback, ContentCallback } from "./type";
|
|
4
|
-
export declare const graphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback, endOfStreamDelimiter?: string, onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<
|
|
5
|
-
export declare const streamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback, endOfStreamDelimiter?: string, onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<
|
|
6
|
-
export declare const nonStreamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<
|
|
4
|
+
export declare const graphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback, endOfStreamDelimiter?: string, onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
|
|
5
|
+
export declare const streamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, contentCallback?: ContentCallback, endOfStreamDelimiter?: string, onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
|
|
6
|
+
export declare const nonStreamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
|
package/lib/graph.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.nonStreamGraphRunner = exports.streamGraphRunner = exports.graphRunner = void 0;
|
|
4
4
|
const graphai_1 = require("graphai");
|
|
5
|
-
const
|
|
5
|
+
const stream_agent_filter_1 = require("@graphai/stream_agent_filter");
|
|
6
6
|
const type_1 = require("./type");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const graphRunner = (agentDictionary, agentFilters = [], streamChunkCallback, contentCallback = utils_1.defaultContentCallback, endOfStreamDelimiter = type_1.DefaultEndOfStreamDelimiter, onLogCallback = (__log, __isUpdate) => { }) => {
|
|
@@ -35,7 +35,7 @@ const streamGraphRunner = (agentDictionary, agentFilters = [], streamChunkCallba
|
|
|
35
35
|
};
|
|
36
36
|
const streamAgentFilter = {
|
|
37
37
|
name: "streamAgentFilter",
|
|
38
|
-
agent: (0,
|
|
38
|
+
agent: (0, stream_agent_filter_1.streamAgentFilterGenerator)(streamCallback),
|
|
39
39
|
};
|
|
40
40
|
const filterList = [...agentFilters, streamAgentFilter];
|
|
41
41
|
const dispatcher = streamGraphRunnerInternal(agentDictionary, filterList, onLogCallback);
|
|
@@ -44,7 +44,7 @@ const streamGraphRunner = (agentDictionary, agentFilters = [], streamChunkCallba
|
|
|
44
44
|
res.write(endOfStreamDelimiter);
|
|
45
45
|
}
|
|
46
46
|
res.write(contentCallback(result));
|
|
47
|
-
|
|
47
|
+
res.end();
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
50
|
next(e);
|
|
@@ -57,7 +57,7 @@ const nonStreamGraphRunner = (agentDictionary, agentFilters = [], onLogCallback
|
|
|
57
57
|
try {
|
|
58
58
|
const dispatcher = streamGraphRunnerInternal(agentDictionary, agentFilters, onLogCallback);
|
|
59
59
|
const result = await dispatcher(req);
|
|
60
|
-
|
|
60
|
+
res.json(result);
|
|
61
61
|
}
|
|
62
62
|
catch (e) {
|
|
63
63
|
next(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@receptron/graphai_express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "GraphAI express web server middleware.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -27,15 +27,17 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/receptron/graphai_utils/tree/main/packages/express#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/cors": "^2.8.
|
|
31
|
-
"
|
|
30
|
+
"@types/cors": "^2.8.18",
|
|
31
|
+
"@types/express-serve-static-core": "^5.0.6",
|
|
32
|
+
"sinon": "^20.0.0",
|
|
32
33
|
"sinon-express-mock": "^2.2.1"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@graphai/
|
|
36
|
+
"@graphai/agent_filter_utils": "^2.0.0",
|
|
37
|
+
"@graphai/stream_agent_filter": "^2.0.1",
|
|
36
38
|
"cors": "^2.8.5",
|
|
37
|
-
"dotenv": "^16.
|
|
38
|
-
"express": "^
|
|
39
|
+
"dotenv": "^16.5.0",
|
|
40
|
+
"express": "^5.1.0"
|
|
39
41
|
},
|
|
40
42
|
"types": "./lib/index.d.ts",
|
|
41
43
|
"directories": {
|