@flutchai/flutch-sdk 0.7.6 → 0.7.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/dist/index.d.cts CHANGED
@@ -366,8 +366,9 @@ declare class GraphController {
366
366
  timestamp: string;
367
367
  }>;
368
368
  getSupportedGraphTypes(): Promise<string[]>;
369
- generateAnswer(payload: IGraphRequestPayload): Promise<IGraphResponsePayload>;
369
+ generateAnswer(payload: IGraphRequestPayload, res: Response): Promise<IGraphResponsePayload>;
370
370
  streamAnswer(payload: IGraphRequestPayload, res: Response): Promise<void>;
371
+ private cancelOnDisconnect;
371
372
  cancelGeneration(requestId: string): Promise<{
372
373
  message: string;
373
374
  }>;
@@ -1428,7 +1429,7 @@ declare class McpRuntimeHttpClient implements McpRuntimeClient {
1428
1429
  private readonly baseUrl;
1429
1430
  constructor(mcpRuntimeUrl?: string);
1430
1431
  getTools(): Promise<McpTool[]>;
1431
- executeTool(name: string, args: any, context?: any, mcpServers?: Record<string, any>[]): Promise<ToolExecutionResult>;
1432
+ executeTool(name: string, args: any, context?: any, mcpServers?: Record<string, any>[], signal?: AbortSignal): Promise<ToolExecutionResult>;
1432
1433
  getToolStats(): Promise<any>;
1433
1434
  isHealthy(): Promise<boolean>;
1434
1435
  executeToolWithEvents(toolCallId: string, toolName: string, enrichedArgs: Record<string, any>, executionContext: Record<string, any>, config?: RunnableConfig, mcpServers?: Record<string, any>[]): Promise<{
@@ -1635,6 +1636,7 @@ declare class UniversalGraphService implements IGraphService {
1635
1636
  declare function bootstrap(AppModule: any, options?: {
1636
1637
  port?: number;
1637
1638
  globalPrefix?: string;
1639
+ bodyLimit?: string;
1638
1640
  }): Promise<_nestjs_common.INestApplication<any>>;
1639
1641
 
1640
1642
  interface ApiCallTracerOptions {
package/dist/index.d.ts CHANGED
@@ -366,8 +366,9 @@ declare class GraphController {
366
366
  timestamp: string;
367
367
  }>;
368
368
  getSupportedGraphTypes(): Promise<string[]>;
369
- generateAnswer(payload: IGraphRequestPayload): Promise<IGraphResponsePayload>;
369
+ generateAnswer(payload: IGraphRequestPayload, res: Response): Promise<IGraphResponsePayload>;
370
370
  streamAnswer(payload: IGraphRequestPayload, res: Response): Promise<void>;
371
+ private cancelOnDisconnect;
371
372
  cancelGeneration(requestId: string): Promise<{
372
373
  message: string;
373
374
  }>;
@@ -1428,7 +1429,7 @@ declare class McpRuntimeHttpClient implements McpRuntimeClient {
1428
1429
  private readonly baseUrl;
1429
1430
  constructor(mcpRuntimeUrl?: string);
1430
1431
  getTools(): Promise<McpTool[]>;
1431
- executeTool(name: string, args: any, context?: any, mcpServers?: Record<string, any>[]): Promise<ToolExecutionResult>;
1432
+ executeTool(name: string, args: any, context?: any, mcpServers?: Record<string, any>[], signal?: AbortSignal): Promise<ToolExecutionResult>;
1432
1433
  getToolStats(): Promise<any>;
1433
1434
  isHealthy(): Promise<boolean>;
1434
1435
  executeToolWithEvents(toolCallId: string, toolName: string, enrichedArgs: Record<string, any>, executionContext: Record<string, any>, config?: RunnableConfig, mcpServers?: Record<string, any>[]): Promise<{
@@ -1635,6 +1636,7 @@ declare class UniversalGraphService implements IGraphService {
1635
1636
  declare function bootstrap(AppModule: any, options?: {
1636
1637
  port?: number;
1637
1638
  globalPrefix?: string;
1639
+ bodyLimit?: string;
1638
1640
  }): Promise<_nestjs_common.INestApplication<any>>;
1639
1641
 
1640
1642
  interface ApiCallTracerOptions {
package/dist/index.js CHANGED
@@ -6,10 +6,10 @@ import * as fs from 'fs';
6
6
  import * as path2 from 'path';
7
7
  import * as os from 'os';
8
8
  import { ConfigService, ConfigModule } from '@nestjs/config';
9
+ import { Response, json, urlencoded } from 'express';
9
10
  import * as net from 'net';
10
11
  import mongoose from 'mongoose';
11
12
  import { MongoDBSaver } from '@langchain/langgraph-checkpoint-mongodb';
12
- import { Response } from 'express';
13
13
  import * as crypto from 'crypto';
14
14
  import { randomUUID, createHash, randomBytes } from 'crypto';
15
15
  import { Registry, collectDefaultMetrics, Counter, Histogram, Gauge } from 'prom-client';
@@ -1960,6 +1960,14 @@ async function bootstrap(AppModule, options = {}) {
1960
1960
  setupRedisMock();
1961
1961
  const app = await NestFactory.create(AppModule);
1962
1962
  const logger3 = new Logger("Bootstrap");
1963
+ const bodyLimit = options.bodyLimit || process.env.GRAPH_BODY_LIMIT || "10mb";
1964
+ app.use(json({
1965
+ limit: bodyLimit
1966
+ }));
1967
+ app.use(urlencoded({
1968
+ limit: bodyLimit,
1969
+ extended: true
1970
+ }));
1963
1971
  const requestedPort = options.port || parseInt(process.env.PORT || "3100", 10);
1964
1972
  const port = await findAvailablePort(requestedPort);
1965
1973
  const globalPrefix = options.globalPrefix;
@@ -2093,7 +2101,8 @@ var GraphController = class _GraphController {
2093
2101
  async getSupportedGraphTypes() {
2094
2102
  return this.graphService.getSupportedGraphTypes();
2095
2103
  }
2096
- async generateAnswer(payload) {
2104
+ async generateAnswer(payload, res) {
2105
+ this.cancelOnDisconnect(res, payload.requestId);
2097
2106
  try {
2098
2107
  return await this.graphService.generateAnswer(payload);
2099
2108
  } catch (error) {
@@ -2106,6 +2115,7 @@ var GraphController = class _GraphController {
2106
2115
  res.setHeader("Transfer-Encoding", "chunked");
2107
2116
  res.setHeader("Cache-Control", "no-cache");
2108
2117
  res.setHeader("Connection", "keep-alive");
2118
+ this.cancelOnDisconnect(res, payload.requestId);
2109
2119
  try {
2110
2120
  this.logger.debug(`[CONTROLLER] Starting streamAnswer for requestId: ${payload.requestId}`);
2111
2121
  const result = await this.graphService.streamAnswer(payload, (chunk) => {
@@ -2143,6 +2153,19 @@ var GraphController = class _GraphController {
2143
2153
  res.end();
2144
2154
  }
2145
2155
  }
2156
+ /**
2157
+ * A caller that hangs up before the answer is done — its own timeout, a
2158
+ * restart, a cancelled parent run — no longer waits for it, so the run is
2159
+ * cancelled: left going, it keeps calling models and tools nobody reads.
2160
+ */
2161
+ cancelOnDisconnect(res, requestId) {
2162
+ if (!requestId) return;
2163
+ res.on("close", () => {
2164
+ if (res.writableFinished) return;
2165
+ this.logger.warn(`[CONTROLLER] Caller disconnected before the answer: cancelling ${requestId}`);
2166
+ this.graphService.cancelGeneration(requestId).catch((error) => this.logger.warn(`[CONTROLLER] Cancel after disconnect failed for ${requestId}: ${error.message}`));
2167
+ });
2168
+ }
2146
2169
  async cancelGeneration(requestId) {
2147
2170
  try {
2148
2171
  await this.graphService.cancelGeneration(requestId);
@@ -2216,9 +2239,13 @@ _ts_decorate8([
2216
2239
  description: "Answer generated"
2217
2240
  }),
2218
2241
  _ts_param4(0, Body()),
2242
+ _ts_param4(1, Res({
2243
+ passthrough: true
2244
+ })),
2219
2245
  _ts_metadata6("design:type", Function),
2220
2246
  _ts_metadata6("design:paramtypes", [
2221
- typeof IGraphRequestPayload === "undefined" ? Object : IGraphRequestPayload
2247
+ typeof IGraphRequestPayload === "undefined" ? Object : IGraphRequestPayload,
2248
+ typeof Response === "undefined" ? Object : Response
2222
2249
  ]),
2223
2250
  _ts_metadata6("design:returntype", Promise)
2224
2251
  ], GraphController.prototype, "generateAnswer", null);
@@ -6999,7 +7026,7 @@ var McpRuntimeHttpClient = class _McpRuntimeHttpClient {
6999
7026
  /**
7000
7027
  * Execute a tool by name with given arguments
7001
7028
  */
7002
- async executeTool(name, args, context, mcpServers) {
7029
+ async executeTool(name, args, context, mcpServers, signal) {
7003
7030
  try {
7004
7031
  this.logger.debug(`Executing tool: ${name} with args:`, args);
7005
7032
  const payload = {
@@ -7012,7 +7039,9 @@ var McpRuntimeHttpClient = class _McpRuntimeHttpClient {
7012
7039
  if (mcpServers && mcpServers.length > 0) {
7013
7040
  payload.mcpServers = mcpServers;
7014
7041
  }
7015
- const response = await this.httpClient.post("/tools/execute", payload);
7042
+ const response = signal ? await this.httpClient.post("/tools/execute", payload, {
7043
+ signal
7044
+ }) : await this.httpClient.post("/tools/execute", payload);
7016
7045
  this.logger.log(`Tool ${name} executed successfully`);
7017
7046
  return response.data;
7018
7047
  } catch (error) {
@@ -7080,7 +7109,7 @@ var McpRuntimeHttpClient = class _McpRuntimeHttpClient {
7080
7109
  toolName
7081
7110
  ]
7082
7111
  }, JSON.stringify(enrichedArgs), parsedConfig.runId, void 0, parsedConfig.tags, parsedConfig.metadata, toolName);
7083
- const result = await this.executeTool(toolName, enrichedArgs, executionContext, mcpServers);
7112
+ const result = await this.executeTool(toolName, enrichedArgs, executionContext, mcpServers, config?.signal);
7084
7113
  const content = result.success ? JSON.stringify(result) : result.error || JSON.stringify(result);
7085
7114
  await runManager?.handleToolEnd(content);
7086
7115
  return {
@@ -7122,8 +7151,8 @@ function toolSearchTerms(text) {
7122
7151
  }
7123
7152
  __name(toolSearchTerms, "toolSearchTerms");
7124
7153
  function schemaParams(schema) {
7125
- const json = schema;
7126
- const properties = json?.properties ?? json?.shape ?? {};
7154
+ const json2 = schema;
7155
+ const properties = json2?.properties ?? json2?.shape ?? {};
7127
7156
  return Object.entries(properties).flatMap(([name, property]) => property?.description ? [
7128
7157
  name,
7129
7158
  property.description
@@ -8838,8 +8867,8 @@ var IV_LENGTH = 16;
8838
8867
  function encryptTokens(tokens, key) {
8839
8868
  const iv = crypto.randomBytes(IV_LENGTH);
8840
8869
  const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(key), iv);
8841
- const json = JSON.stringify(tokens);
8842
- let encrypted = cipher.update(json, "utf8", "hex");
8870
+ const json2 = JSON.stringify(tokens);
8871
+ let encrypted = cipher.update(json2, "utf8", "hex");
8843
8872
  encrypted += cipher.final("hex");
8844
8873
  return iv.toString("hex") + ":" + encrypted;
8845
8874
  }