@flutchai/flutch-sdk 0.1.22 → 0.1.24
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 +49 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +49 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4450,11 +4450,21 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4450
4450
|
channels: /* @__PURE__ */ new Map([
|
|
4451
4451
|
[
|
|
4452
4452
|
"text" /* TEXT */,
|
|
4453
|
-
{
|
|
4453
|
+
{
|
|
4454
|
+
contentChain: [],
|
|
4455
|
+
currentBlock: null,
|
|
4456
|
+
pendingToolBlocks: [],
|
|
4457
|
+
toolBlocksByRunId: /* @__PURE__ */ new Map()
|
|
4458
|
+
}
|
|
4454
4459
|
],
|
|
4455
4460
|
[
|
|
4456
4461
|
"processing" /* PROCESSING */,
|
|
4457
|
-
{
|
|
4462
|
+
{
|
|
4463
|
+
contentChain: [],
|
|
4464
|
+
currentBlock: null,
|
|
4465
|
+
pendingToolBlocks: [],
|
|
4466
|
+
toolBlocksByRunId: /* @__PURE__ */ new Map()
|
|
4467
|
+
}
|
|
4458
4468
|
]
|
|
4459
4469
|
]),
|
|
4460
4470
|
attachments: [],
|
|
@@ -4494,11 +4504,6 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4494
4504
|
*/
|
|
4495
4505
|
sendDelta(channel, delta, onPartial) {
|
|
4496
4506
|
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
|
-
}
|
|
4502
4507
|
onPartial(
|
|
4503
4508
|
JSON.stringify({
|
|
4504
4509
|
channel,
|
|
@@ -4632,11 +4637,20 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4632
4637
|
return;
|
|
4633
4638
|
}
|
|
4634
4639
|
if (event.event === "on_tool_start") {
|
|
4640
|
+
const channel = event.metadata?.stream_channel ?? "text" /* TEXT */;
|
|
4641
|
+
const state = acc.channels.get(channel);
|
|
4642
|
+
if (state && event.run_id) {
|
|
4643
|
+
const idx = state.pendingToolBlocks.findIndex(
|
|
4644
|
+
(b) => b.name === event.name
|
|
4645
|
+
);
|
|
4646
|
+
if (idx !== -1) {
|
|
4647
|
+
const block = state.pendingToolBlocks.splice(idx, 1)[0];
|
|
4648
|
+
state.toolBlocksByRunId.set(event.run_id, block);
|
|
4649
|
+
}
|
|
4650
|
+
}
|
|
4635
4651
|
this.logger.log("\u{1F527} Tool execution started", {
|
|
4636
4652
|
toolName: event.name,
|
|
4637
|
-
|
|
4638
|
-
runId: event.run_id,
|
|
4639
|
-
metadata: event.metadata
|
|
4653
|
+
runId: event.run_id
|
|
4640
4654
|
});
|
|
4641
4655
|
return;
|
|
4642
4656
|
}
|
|
@@ -4644,10 +4658,13 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4644
4658
|
const channel = event.metadata?.stream_channel ?? "text" /* TEXT */;
|
|
4645
4659
|
const state = acc.channels.get(channel);
|
|
4646
4660
|
if (!state) return;
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4661
|
+
let toolBlock;
|
|
4662
|
+
if (event.run_id && state.toolBlocksByRunId.has(event.run_id)) {
|
|
4663
|
+
toolBlock = state.toolBlocksByRunId.get(event.run_id);
|
|
4664
|
+
state.toolBlocksByRunId.delete(event.run_id);
|
|
4665
|
+
} else {
|
|
4666
|
+
toolBlock = state.pendingToolBlocks.shift();
|
|
4667
|
+
}
|
|
4651
4668
|
if (toolBlock && toolBlock.type === "tool_use") {
|
|
4652
4669
|
const output = event.data?.output;
|
|
4653
4670
|
const outputString = typeof output === "string" ? output : JSON.stringify(output, null, 2);
|
|
@@ -4661,26 +4678,26 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4661
4678
|
},
|
|
4662
4679
|
onPartial
|
|
4663
4680
|
);
|
|
4664
|
-
this.logger.log("\u2705 Tool
|
|
4681
|
+
this.logger.log("\u2705 Tool completed", {
|
|
4665
4682
|
toolName: event.name,
|
|
4666
4683
|
toolBlockId: toolBlock.id,
|
|
4667
|
-
outputPreview: outputString.substring(0, 200) + (outputString.length > 200 ? "..." : ""),
|
|
4668
4684
|
runId: event.run_id
|
|
4669
4685
|
});
|
|
4670
4686
|
} else {
|
|
4671
|
-
this.logger.warn(
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
runId: event.run_id,
|
|
4676
|
-
pendingCount: state.pendingToolBlocks.length
|
|
4677
|
-
}
|
|
4678
|
-
);
|
|
4687
|
+
this.logger.warn("\u26A0\uFE0F on_tool_end: no matching tool block", {
|
|
4688
|
+
toolName: event.name,
|
|
4689
|
+
runId: event.run_id
|
|
4690
|
+
});
|
|
4679
4691
|
}
|
|
4680
4692
|
return;
|
|
4681
4693
|
}
|
|
4682
4694
|
if (event.event === "on_tool_error") {
|
|
4683
|
-
|
|
4695
|
+
const channel = event.metadata?.stream_channel ?? "text" /* TEXT */;
|
|
4696
|
+
const state = acc.channels.get(channel);
|
|
4697
|
+
if (state && event.run_id) {
|
|
4698
|
+
state.toolBlocksByRunId.delete(event.run_id);
|
|
4699
|
+
}
|
|
4700
|
+
this.logger.error("\u274C Tool failed", {
|
|
4684
4701
|
toolName: event.name,
|
|
4685
4702
|
error: event.data?.error,
|
|
4686
4703
|
runId: event.run_id
|
|
@@ -4728,6 +4745,13 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4728
4745
|
getResult(acc) {
|
|
4729
4746
|
const allChains = [];
|
|
4730
4747
|
for (const [channel, state] of acc.channels.entries()) {
|
|
4748
|
+
if (state.pendingToolBlocks.length > 0 || state.toolBlocksByRunId.size > 0) {
|
|
4749
|
+
this.logger.warn("\u26A0\uFE0F Orphaned tool blocks detected at finalization", {
|
|
4750
|
+
channel,
|
|
4751
|
+
pendingCount: state.pendingToolBlocks.length,
|
|
4752
|
+
mappedCount: state.toolBlocksByRunId.size
|
|
4753
|
+
});
|
|
4754
|
+
}
|
|
4731
4755
|
if (state.currentBlock) {
|
|
4732
4756
|
state.contentChain.push(state.currentBlock);
|
|
4733
4757
|
}
|