@flutchai/flutch-sdk 0.7.7 → 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.cjs CHANGED
@@ -2131,7 +2131,8 @@ exports.GraphController = class _GraphController {
2131
2131
  async getSupportedGraphTypes() {
2132
2132
  return this.graphService.getSupportedGraphTypes();
2133
2133
  }
2134
- async generateAnswer(payload) {
2134
+ async generateAnswer(payload, res) {
2135
+ this.cancelOnDisconnect(res, payload.requestId);
2135
2136
  try {
2136
2137
  return await this.graphService.generateAnswer(payload);
2137
2138
  } catch (error) {
@@ -2144,6 +2145,7 @@ exports.GraphController = class _GraphController {
2144
2145
  res.setHeader("Transfer-Encoding", "chunked");
2145
2146
  res.setHeader("Cache-Control", "no-cache");
2146
2147
  res.setHeader("Connection", "keep-alive");
2148
+ this.cancelOnDisconnect(res, payload.requestId);
2147
2149
  try {
2148
2150
  this.logger.debug(`[CONTROLLER] Starting streamAnswer for requestId: ${payload.requestId}`);
2149
2151
  const result = await this.graphService.streamAnswer(payload, (chunk) => {
@@ -2181,6 +2183,19 @@ exports.GraphController = class _GraphController {
2181
2183
  res.end();
2182
2184
  }
2183
2185
  }
2186
+ /**
2187
+ * A caller that hangs up before the answer is done — its own timeout, a
2188
+ * restart, a cancelled parent run — no longer waits for it, so the run is
2189
+ * cancelled: left going, it keeps calling models and tools nobody reads.
2190
+ */
2191
+ cancelOnDisconnect(res, requestId) {
2192
+ if (!requestId) return;
2193
+ res.on("close", () => {
2194
+ if (res.writableFinished) return;
2195
+ this.logger.warn(`[CONTROLLER] Caller disconnected before the answer: cancelling ${requestId}`);
2196
+ this.graphService.cancelGeneration(requestId).catch((error) => this.logger.warn(`[CONTROLLER] Cancel after disconnect failed for ${requestId}: ${error.message}`));
2197
+ });
2198
+ }
2184
2199
  async cancelGeneration(requestId) {
2185
2200
  try {
2186
2201
  await this.graphService.cancelGeneration(requestId);
@@ -2254,9 +2269,13 @@ _ts_decorate8([
2254
2269
  description: "Answer generated"
2255
2270
  }),
2256
2271
  _ts_param4(0, common.Body()),
2272
+ _ts_param4(1, common.Res({
2273
+ passthrough: true
2274
+ })),
2257
2275
  _ts_metadata6("design:type", Function),
2258
2276
  _ts_metadata6("design:paramtypes", [
2259
- typeof IGraphRequestPayload === "undefined" ? Object : IGraphRequestPayload
2277
+ typeof IGraphRequestPayload === "undefined" ? Object : IGraphRequestPayload,
2278
+ typeof express.Response === "undefined" ? Object : express.Response
2260
2279
  ]),
2261
2280
  _ts_metadata6("design:returntype", Promise)
2262
2281
  ], exports.GraphController.prototype, "generateAnswer", null);
@@ -7037,7 +7056,7 @@ exports.McpRuntimeHttpClient = class _McpRuntimeHttpClient {
7037
7056
  /**
7038
7057
  * Execute a tool by name with given arguments
7039
7058
  */
7040
- async executeTool(name, args, context, mcpServers) {
7059
+ async executeTool(name, args, context, mcpServers, signal) {
7041
7060
  try {
7042
7061
  this.logger.debug(`Executing tool: ${name} with args:`, args);
7043
7062
  const payload = {
@@ -7050,7 +7069,9 @@ exports.McpRuntimeHttpClient = class _McpRuntimeHttpClient {
7050
7069
  if (mcpServers && mcpServers.length > 0) {
7051
7070
  payload.mcpServers = mcpServers;
7052
7071
  }
7053
- const response = await this.httpClient.post("/tools/execute", payload);
7072
+ const response = signal ? await this.httpClient.post("/tools/execute", payload, {
7073
+ signal
7074
+ }) : await this.httpClient.post("/tools/execute", payload);
7054
7075
  this.logger.log(`Tool ${name} executed successfully`);
7055
7076
  return response.data;
7056
7077
  } catch (error) {
@@ -7118,7 +7139,7 @@ exports.McpRuntimeHttpClient = class _McpRuntimeHttpClient {
7118
7139
  toolName
7119
7140
  ]
7120
7141
  }, JSON.stringify(enrichedArgs), parsedConfig.runId, void 0, parsedConfig.tags, parsedConfig.metadata, toolName);
7121
- const result = await this.executeTool(toolName, enrichedArgs, executionContext, mcpServers);
7142
+ const result = await this.executeTool(toolName, enrichedArgs, executionContext, mcpServers, config?.signal);
7122
7143
  const content = result.success ? JSON.stringify(result) : result.error || JSON.stringify(result);
7123
7144
  await runManager?.handleToolEnd(content);
7124
7145
  return {