@receptron/graphai_express 0.0.32 → 0.0.33

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/graph.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import express from "express";
2
- import type { AgentFunctionInfoDictionary, AgentFilterInfo } from "graphai";
3
- import { StreamChunkCallback } from "./type";
4
- export declare const graphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
5
- export declare const streamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
6
- export declare const nonStreamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[]) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
2
+ import type { AgentFunctionInfoDictionary, AgentFilterInfo, TransactionLog } from "graphai";
3
+ import type { StreamChunkCallback } from "./type";
4
+ export declare const graphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
5
+ export declare const streamGraphRunner: (agentDictionary: AgentFunctionInfoDictionary, agentFilters?: AgentFilterInfo[], streamChunkCallback?: StreamChunkCallback, onLogCallback?: (__log: TransactionLog, __isUpdate: boolean) => void) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<express.Response<any, Record<string, any>> | undefined>;
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<express.Response<any, Record<string, any>> | undefined>;
package/lib/graph.js CHANGED
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nonStreamGraphRunner = exports.streamGraphRunner = exports.graphRunner = void 0;
4
4
  const graphai_1 = require("graphai");
5
5
  const agent_filters_1 = require("@graphai/agent_filters");
6
- const graphRunner = (agentDictionary, agentFilters = [], streamChunkCallback) => {
7
- const stream = (0, exports.streamGraphRunner)(agentDictionary, agentFilters, streamChunkCallback);
8
- const nonStream = (0, exports.nonStreamGraphRunner)(agentDictionary, agentFilters);
6
+ const graphRunner = (agentDictionary, agentFilters = [], streamChunkCallback, onLogCallback = (__log, __isUpdate) => { }) => {
7
+ const stream = (0, exports.streamGraphRunner)(agentDictionary, agentFilters, streamChunkCallback, onLogCallback);
8
+ const nonStream = (0, exports.nonStreamGraphRunner)(agentDictionary, agentFilters, onLogCallback);
9
9
  return async (req, res, next) => {
10
10
  const isStreaming = (req.headers["content-type"] || "").startsWith("text/event-stream");
11
11
  if (isStreaming) {
@@ -15,7 +15,7 @@ const graphRunner = (agentDictionary, agentFilters = [], streamChunkCallback) =>
15
15
  };
16
16
  };
17
17
  exports.graphRunner = graphRunner;
18
- const streamGraphRunner = (agentDictionary, agentFilters = [], streamChunkCallback) => {
18
+ const streamGraphRunner = (agentDictionary, agentFilters = [], streamChunkCallback, onLogCallback = (__log, __isUpdate) => { }) => {
19
19
  return async (req, res, next) => {
20
20
  try {
21
21
  res.setHeader("Content-Type", "text/event-stream;charset=utf-8");
@@ -36,7 +36,7 @@ const streamGraphRunner = (agentDictionary, agentFilters = [], streamChunkCallba
36
36
  agent: (0, agent_filters_1.streamAgentFilterGenerator)(streamCallback),
37
37
  };
38
38
  const filterList = [...agentFilters, streamAgentFilter];
39
- const dispatcher = streamGraphRunnerInternal(agentDictionary, filterList);
39
+ const dispatcher = streamGraphRunnerInternal(agentDictionary, filterList, onLogCallback);
40
40
  const result = await dispatcher(req);
41
41
  const json_data = JSON.stringify(result);
42
42
  res.write("___END___");
@@ -49,10 +49,10 @@ const streamGraphRunner = (agentDictionary, agentFilters = [], streamChunkCallba
49
49
  };
50
50
  };
51
51
  exports.streamGraphRunner = streamGraphRunner;
52
- const nonStreamGraphRunner = (agentDictionary, agentFilters = []) => {
52
+ const nonStreamGraphRunner = (agentDictionary, agentFilters = [], onLogCallback = (__log, __isUpdate) => { }) => {
53
53
  return async (req, res, next) => {
54
54
  try {
55
- const dispatcher = streamGraphRunnerInternal(agentDictionary, agentFilters);
55
+ const dispatcher = streamGraphRunnerInternal(agentDictionary, agentFilters, onLogCallback);
56
56
  const result = await dispatcher(req);
57
57
  return res.json(result);
58
58
  }
@@ -63,11 +63,12 @@ const nonStreamGraphRunner = (agentDictionary, agentFilters = []) => {
63
63
  };
64
64
  exports.nonStreamGraphRunner = nonStreamGraphRunner;
65
65
  // internal function
66
- const streamGraphRunnerInternal = (agentDictionary, agentFilters = []) => {
66
+ const streamGraphRunnerInternal = (agentDictionary, agentFilters = [], onLogCallback = (__log, __isUpdate) => { }) => {
67
67
  return async (req) => {
68
68
  const { graphData } = req.body;
69
69
  const { config } = req;
70
70
  const graphai = new graphai_1.GraphAI(graphData, agentDictionary, { agentFilters, config: config ?? {} });
71
+ graphai.onLogCallback = onLogCallback;
71
72
  const result = await graphai.run();
72
73
  return result;
73
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@receptron/graphai_express",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "description": "GraphAI express web server middleware.",
5
5
  "main": "lib/index.js",
6
6
  "files": [