@flutchai/flutch-sdk 0.1.20 → 0.1.23

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
@@ -3,7 +3,7 @@ import * as _nestjs_common from '@nestjs/common';
3
3
  import { OnModuleInit, Logger, Type, CanActivate, ExecutionContext, DynamicModule } from '@nestjs/common';
4
4
  import { ConfigService } from '@nestjs/config';
5
5
  import { HumanMessage, AIMessageChunk } from '@langchain/core/messages';
6
- import { CompiledStateGraph, LangGraphRunnableConfig, BaseChannel } from '@langchain/langgraph';
6
+ import { BaseChannel, CompiledStateGraph, LangGraphRunnableConfig } from '@langchain/langgraph';
7
7
  import Redis from 'ioredis';
8
8
  import { Registry } from 'prom-client';
9
9
  import { Response, Request } from 'express';
@@ -1124,6 +1124,7 @@ interface LLMCallRecord {
1124
1124
  interface ChannelState {
1125
1125
  contentChain: IContentBlock[];
1126
1126
  currentBlock: IContentBlock | null;
1127
+ pendingToolBlocks: IContentBlock[];
1127
1128
  }
1128
1129
  interface StreamAccumulator {
1129
1130
  channels: Map<StreamChannel, ChannelState>;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as _nestjs_common from '@nestjs/common';
3
3
  import { OnModuleInit, Logger, Type, CanActivate, ExecutionContext, DynamicModule } from '@nestjs/common';
4
4
  import { ConfigService } from '@nestjs/config';
5
5
  import { HumanMessage, AIMessageChunk } from '@langchain/core/messages';
6
- import { CompiledStateGraph, LangGraphRunnableConfig, BaseChannel } from '@langchain/langgraph';
6
+ import { BaseChannel, CompiledStateGraph, LangGraphRunnableConfig } from '@langchain/langgraph';
7
7
  import Redis from 'ioredis';
8
8
  import { Registry } from 'prom-client';
9
9
  import { Response, Request } from 'express';
@@ -1124,6 +1124,7 @@ interface LLMCallRecord {
1124
1124
  interface ChannelState {
1125
1125
  contentChain: IContentBlock[];
1126
1126
  currentBlock: IContentBlock | null;
1127
+ pendingToolBlocks: IContentBlock[];
1127
1128
  }
1128
1129
  interface StreamAccumulator {
1129
1130
  channels: Map<StreamChannel, ChannelState>;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { Injectable, Post, UseGuards, Req, Controller, Inject, Get, Body, Res, Param, Logger, Optional, Module, UnauthorizedException, ForbiddenException, ValidationPipe, HttpException, HttpStatus, NotFoundException, InternalServerErrorException, Headers } from '@nestjs/common';
2
+ import { Injectable, Post, UseGuards, Req, Controller, Inject, Get, Body, Res, Param, Logger, Optional, Module, UnauthorizedException, Headers, NotFoundException, InternalServerErrorException, ForbiddenException, ValidationPipe, HttpException, HttpStatus } from '@nestjs/common';
3
3
  import { ApiOperation, ApiResponse, ApiTags, ApiParam, DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
4
4
  import * as fs from 'fs';
5
5
  import * as path2 from 'path';
@@ -148,8 +148,8 @@ function findCallbackMethod(target, handler) {
148
148
  var CALLBACK_METADATA_KEY, CALLBACK_CLASS_METADATA_KEY;
149
149
  var init_callback_decorators = __esm({
150
150
  "src/callbacks/callback.decorators.ts"() {
151
- CALLBACK_METADATA_KEY = /* @__PURE__ */ Symbol("callbacks");
152
- CALLBACK_CLASS_METADATA_KEY = /* @__PURE__ */ Symbol("callback_class");
151
+ CALLBACK_METADATA_KEY = Symbol("callbacks");
152
+ CALLBACK_CLASS_METADATA_KEY = Symbol("callback_class");
153
153
  }
154
154
  });
155
155
  var EndpointRegistry;
@@ -421,8 +421,8 @@ var ENDPOINT_METADATA_KEY, UI_ENDPOINT_CLASS_METADATA_KEY, UI_ENDPOINT_METHOD_ME
421
421
  var init_endpoint_decorators = __esm({
422
422
  "src/agent-ui/endpoint.decorators.ts"() {
423
423
  ENDPOINT_METADATA_KEY = "graph:endpoints";
424
- UI_ENDPOINT_CLASS_METADATA_KEY = /* @__PURE__ */ Symbol("ui_endpoint_class");
425
- UI_ENDPOINT_METHOD_METADATA_KEY = /* @__PURE__ */ Symbol("ui_endpoint_methods");
424
+ UI_ENDPOINT_CLASS_METADATA_KEY = Symbol("ui_endpoint_class");
425
+ UI_ENDPOINT_METHOD_METADATA_KEY = Symbol("ui_endpoint_methods");
426
426
  }
427
427
  });
428
428
  var UIEndpointsDiscoveryService;
@@ -4419,8 +4419,14 @@ var EventProcessor = class {
4419
4419
  createAccumulator() {
4420
4420
  return {
4421
4421
  channels: /* @__PURE__ */ new Map([
4422
- ["text" /* TEXT */, { contentChain: [], currentBlock: null }],
4423
- ["processing" /* PROCESSING */, { contentChain: [], currentBlock: null }]
4422
+ [
4423
+ "text" /* TEXT */,
4424
+ { contentChain: [], currentBlock: null, pendingToolBlocks: [] }
4425
+ ],
4426
+ [
4427
+ "processing" /* PROCESSING */,
4428
+ { contentChain: [], currentBlock: null, pendingToolBlocks: [] }
4429
+ ]
4424
4430
  ]),
4425
4431
  attachments: [],
4426
4432
  metadata: {},
@@ -4484,6 +4490,7 @@ var EventProcessor = class {
4484
4490
  input: block.input || "",
4485
4491
  output: ""
4486
4492
  };
4493
+ state.pendingToolBlocks.push(state.currentBlock);
4487
4494
  this.sendDelta(
4488
4495
  channel,
4489
4496
  {
@@ -4602,24 +4609,36 @@ var EventProcessor = class {
4602
4609
  if (event.event === "on_tool_end") {
4603
4610
  const channel = event.metadata?.stream_channel ?? "text" /* TEXT */;
4604
4611
  const state = acc.channels.get(channel);
4605
- if (state?.currentBlock && state.currentBlock.type === "tool_use") {
4612
+ if (!state) return;
4613
+ const toolBlock = state.pendingToolBlocks.shift();
4614
+ if (toolBlock && toolBlock.type === "tool_use") {
4606
4615
  const output = event.data?.output;
4607
4616
  const outputString = typeof output === "string" ? output : JSON.stringify(output, null, 2);
4608
- state.currentBlock.output = outputString;
4617
+ toolBlock.output = outputString;
4609
4618
  this.sendDelta(
4610
4619
  channel,
4611
4620
  {
4612
4621
  type: "tool_output_chunk",
4613
- stepId: state.currentBlock.id,
4622
+ stepId: toolBlock.id,
4614
4623
  chunk: outputString
4615
4624
  },
4616
4625
  onPartial
4617
4626
  );
4618
4627
  this.logger.log("\u2705 Tool execution completed", {
4619
4628
  toolName: event.name,
4629
+ toolBlockId: toolBlock.id,
4620
4630
  outputPreview: outputString.substring(0, 200) + (outputString.length > 200 ? "..." : ""),
4621
4631
  runId: event.run_id
4622
4632
  });
4633
+ } else {
4634
+ this.logger.warn(
4635
+ "\u26A0\uFE0F on_tool_end received but no pending tool block found",
4636
+ {
4637
+ toolName: event.name,
4638
+ runId: event.run_id,
4639
+ pendingCount: state.pendingToolBlocks.length
4640
+ }
4641
+ );
4623
4642
  }
4624
4643
  return;
4625
4644
  }