@flutchai/flutch-sdk 0.1.20 → 0.1.22

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
@@ -177,8 +177,8 @@ function findCallbackMethod(target, handler) {
177
177
  var CALLBACK_METADATA_KEY, CALLBACK_CLASS_METADATA_KEY;
178
178
  var init_callback_decorators = __esm({
179
179
  "src/callbacks/callback.decorators.ts"() {
180
- CALLBACK_METADATA_KEY = /* @__PURE__ */ Symbol("callbacks");
181
- CALLBACK_CLASS_METADATA_KEY = /* @__PURE__ */ Symbol("callback_class");
180
+ CALLBACK_METADATA_KEY = Symbol("callbacks");
181
+ CALLBACK_CLASS_METADATA_KEY = Symbol("callback_class");
182
182
  }
183
183
  });
184
184
  exports.EndpointRegistry = void 0;
@@ -450,8 +450,8 @@ exports.ENDPOINT_METADATA_KEY = void 0; var UI_ENDPOINT_CLASS_METADATA_KEY, UI_E
450
450
  var init_endpoint_decorators = __esm({
451
451
  "src/agent-ui/endpoint.decorators.ts"() {
452
452
  exports.ENDPOINT_METADATA_KEY = "graph:endpoints";
453
- UI_ENDPOINT_CLASS_METADATA_KEY = /* @__PURE__ */ Symbol("ui_endpoint_class");
454
- UI_ENDPOINT_METHOD_METADATA_KEY = /* @__PURE__ */ Symbol("ui_endpoint_methods");
453
+ UI_ENDPOINT_CLASS_METADATA_KEY = Symbol("ui_endpoint_class");
454
+ UI_ENDPOINT_METHOD_METADATA_KEY = Symbol("ui_endpoint_methods");
455
455
  }
456
456
  });
457
457
  exports.UIEndpointsDiscoveryService = void 0;
@@ -4448,8 +4448,14 @@ exports.EventProcessor = class EventProcessor {
4448
4448
  createAccumulator() {
4449
4449
  return {
4450
4450
  channels: /* @__PURE__ */ new Map([
4451
- ["text" /* TEXT */, { contentChain: [], currentBlock: null }],
4452
- ["processing" /* PROCESSING */, { contentChain: [], currentBlock: null }]
4451
+ [
4452
+ "text" /* TEXT */,
4453
+ { contentChain: [], currentBlock: null, pendingToolBlocks: [] }
4454
+ ],
4455
+ [
4456
+ "processing" /* PROCESSING */,
4457
+ { contentChain: [], currentBlock: null, pendingToolBlocks: [] }
4458
+ ]
4453
4459
  ]),
4454
4460
  attachments: [],
4455
4461
  metadata: {},
@@ -4488,6 +4494,11 @@ exports.EventProcessor = class EventProcessor {
4488
4494
  */
4489
4495
  sendDelta(channel, delta, onPartial) {
4490
4496
  if (!onPartial) return;
4497
+ if (delta.type === "step_started" || delta.type === "tool_output_chunk" || delta.type === "tool_input_chunk") {
4498
+ this.logger.debug(
4499
+ `[DELTA] type=${delta.type} channel=${channel} stepId=${delta.stepId || delta.step?.id} name=${delta.step?.name || "N/A"}`
4500
+ );
4501
+ }
4491
4502
  onPartial(
4492
4503
  JSON.stringify({
4493
4504
  channel,
@@ -4513,6 +4524,7 @@ exports.EventProcessor = class EventProcessor {
4513
4524
  input: block.input || "",
4514
4525
  output: ""
4515
4526
  };
4527
+ state.pendingToolBlocks.push(state.currentBlock);
4516
4528
  this.sendDelta(
4517
4529
  channel,
4518
4530
  {
@@ -4631,24 +4643,39 @@ exports.EventProcessor = class EventProcessor {
4631
4643
  if (event.event === "on_tool_end") {
4632
4644
  const channel = event.metadata?.stream_channel ?? "text" /* TEXT */;
4633
4645
  const state = acc.channels.get(channel);
4634
- if (state?.currentBlock && state.currentBlock.type === "tool_use") {
4646
+ if (!state) return;
4647
+ this.logger.debug(
4648
+ `[on_tool_end] channel=${channel} pendingCount=${state.pendingToolBlocks.length} pendingIds=${state.pendingToolBlocks.map((b) => b.id).join(",")} currentBlock=${state.currentBlock?.id}`
4649
+ );
4650
+ const toolBlock = state.pendingToolBlocks.shift();
4651
+ if (toolBlock && toolBlock.type === "tool_use") {
4635
4652
  const output = event.data?.output;
4636
4653
  const outputString = typeof output === "string" ? output : JSON.stringify(output, null, 2);
4637
- state.currentBlock.output = outputString;
4654
+ toolBlock.output = outputString;
4638
4655
  this.sendDelta(
4639
4656
  channel,
4640
4657
  {
4641
4658
  type: "tool_output_chunk",
4642
- stepId: state.currentBlock.id,
4659
+ stepId: toolBlock.id,
4643
4660
  chunk: outputString
4644
4661
  },
4645
4662
  onPartial
4646
4663
  );
4647
4664
  this.logger.log("\u2705 Tool execution completed", {
4648
4665
  toolName: event.name,
4666
+ toolBlockId: toolBlock.id,
4649
4667
  outputPreview: outputString.substring(0, 200) + (outputString.length > 200 ? "..." : ""),
4650
4668
  runId: event.run_id
4651
4669
  });
4670
+ } else {
4671
+ this.logger.warn(
4672
+ "\u26A0\uFE0F on_tool_end received but no pending tool block found",
4673
+ {
4674
+ toolName: event.name,
4675
+ runId: event.run_id,
4676
+ pendingCount: state.pendingToolBlocks.length
4677
+ }
4678
+ );
4652
4679
  }
4653
4680
  return;
4654
4681
  }