@flutchai/flutch-sdk 0.1.6 → 0.1.7
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 +135 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +135 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -211,9 +211,13 @@ type CitationValue = {
|
|
|
211
211
|
|
|
212
212
|
interface IReasoningStep {
|
|
213
213
|
index: number;
|
|
214
|
-
type: "text" | "
|
|
214
|
+
type: "text" | "tool_use";
|
|
215
215
|
text?: string;
|
|
216
216
|
metadata?: Record<string, any>;
|
|
217
|
+
name?: string;
|
|
218
|
+
id?: string;
|
|
219
|
+
input?: string;
|
|
220
|
+
output?: string;
|
|
217
221
|
}
|
|
218
222
|
interface IReasoningChain {
|
|
219
223
|
steps: IReasoningStep[];
|
|
@@ -1120,11 +1124,14 @@ interface StreamAccumulator {
|
|
|
1120
1124
|
traceEvents: IGraphTraceEvent[];
|
|
1121
1125
|
traceStartedAt: number | null;
|
|
1122
1126
|
traceCompletedAt: number | null;
|
|
1127
|
+
currentReasoningSteps: IReasoningStep[];
|
|
1128
|
+
currentToolUse: IReasoningStep | null;
|
|
1123
1129
|
}
|
|
1124
1130
|
declare class EventProcessor {
|
|
1125
1131
|
private readonly logger;
|
|
1126
1132
|
createAccumulator(): StreamAccumulator;
|
|
1127
1133
|
private normalizeContentBlocks;
|
|
1134
|
+
private mapReasoningSteps;
|
|
1128
1135
|
processEvent(acc: StreamAccumulator, event: any, onPartial?: (chunk: string) => void): void;
|
|
1129
1136
|
getResult(acc: StreamAccumulator): {
|
|
1130
1137
|
content: IStoredMessageContent;
|
package/dist/index.d.ts
CHANGED
|
@@ -211,9 +211,13 @@ type CitationValue = {
|
|
|
211
211
|
|
|
212
212
|
interface IReasoningStep {
|
|
213
213
|
index: number;
|
|
214
|
-
type: "text" | "
|
|
214
|
+
type: "text" | "tool_use";
|
|
215
215
|
text?: string;
|
|
216
216
|
metadata?: Record<string, any>;
|
|
217
|
+
name?: string;
|
|
218
|
+
id?: string;
|
|
219
|
+
input?: string;
|
|
220
|
+
output?: string;
|
|
217
221
|
}
|
|
218
222
|
interface IReasoningChain {
|
|
219
223
|
steps: IReasoningStep[];
|
|
@@ -1120,11 +1124,14 @@ interface StreamAccumulator {
|
|
|
1120
1124
|
traceEvents: IGraphTraceEvent[];
|
|
1121
1125
|
traceStartedAt: number | null;
|
|
1122
1126
|
traceCompletedAt: number | null;
|
|
1127
|
+
currentReasoningSteps: IReasoningStep[];
|
|
1128
|
+
currentToolUse: IReasoningStep | null;
|
|
1123
1129
|
}
|
|
1124
1130
|
declare class EventProcessor {
|
|
1125
1131
|
private readonly logger;
|
|
1126
1132
|
createAccumulator(): StreamAccumulator;
|
|
1127
1133
|
private normalizeContentBlocks;
|
|
1134
|
+
private mapReasoningSteps;
|
|
1128
1135
|
processEvent(acc: StreamAccumulator, event: any, onPartial?: (chunk: string) => void): void;
|
|
1129
1136
|
getResult(acc: StreamAccumulator): {
|
|
1130
1137
|
content: IStoredMessageContent;
|
package/dist/index.js
CHANGED
|
@@ -4419,7 +4419,9 @@ var EventProcessor = class {
|
|
|
4419
4419
|
llmCalls: [],
|
|
4420
4420
|
traceEvents: [],
|
|
4421
4421
|
traceStartedAt: null,
|
|
4422
|
-
traceCompletedAt: null
|
|
4422
|
+
traceCompletedAt: null,
|
|
4423
|
+
currentReasoningSteps: [],
|
|
4424
|
+
currentToolUse: null
|
|
4423
4425
|
};
|
|
4424
4426
|
}
|
|
4425
4427
|
/**
|
|
@@ -4447,6 +4449,51 @@ var EventProcessor = class {
|
|
|
4447
4449
|
}
|
|
4448
4450
|
return [];
|
|
4449
4451
|
}
|
|
4452
|
+
/**
|
|
4453
|
+
* Groups tool_use and input_json_delta into proper structure
|
|
4454
|
+
* tool_use.input → output (tool execution result)
|
|
4455
|
+
* input_json_delta.input → output (tool execution result, accumulated)
|
|
4456
|
+
*/
|
|
4457
|
+
mapReasoningSteps(rawSteps) {
|
|
4458
|
+
const steps = [];
|
|
4459
|
+
let currentToolUse = null;
|
|
4460
|
+
for (const raw of rawSteps) {
|
|
4461
|
+
if (raw.type === "tool_use" || raw.type === "tool_call") {
|
|
4462
|
+
if (currentToolUse) {
|
|
4463
|
+
steps.push(currentToolUse);
|
|
4464
|
+
}
|
|
4465
|
+
currentToolUse = {
|
|
4466
|
+
index: raw.index || 0,
|
|
4467
|
+
type: "tool_use",
|
|
4468
|
+
name: raw.name,
|
|
4469
|
+
id: raw.id,
|
|
4470
|
+
input: "",
|
|
4471
|
+
// Parameters (IN) - filled separately or empty
|
|
4472
|
+
output: raw.input || ""
|
|
4473
|
+
// Result (OUT) - comes in tool_use.input
|
|
4474
|
+
};
|
|
4475
|
+
} else if (raw.type === "input_json_delta") {
|
|
4476
|
+
if (currentToolUse) {
|
|
4477
|
+
currentToolUse.output = (currentToolUse.output || "") + (raw.input || "");
|
|
4478
|
+
}
|
|
4479
|
+
} else {
|
|
4480
|
+
if (currentToolUse) {
|
|
4481
|
+
steps.push(currentToolUse);
|
|
4482
|
+
currentToolUse = null;
|
|
4483
|
+
}
|
|
4484
|
+
steps.push({
|
|
4485
|
+
index: raw.index || 0,
|
|
4486
|
+
type: raw.type,
|
|
4487
|
+
text: raw.text || "",
|
|
4488
|
+
metadata: raw.metadata
|
|
4489
|
+
});
|
|
4490
|
+
}
|
|
4491
|
+
}
|
|
4492
|
+
if (currentToolUse) {
|
|
4493
|
+
steps.push(currentToolUse);
|
|
4494
|
+
}
|
|
4495
|
+
return steps;
|
|
4496
|
+
}
|
|
4450
4497
|
/**
|
|
4451
4498
|
* Process a LangGraph stream event
|
|
4452
4499
|
* Mutates accumulator to collect data from different channels
|
|
@@ -4469,8 +4516,44 @@ var EventProcessor = class {
|
|
|
4469
4516
|
if (event.event === "on_chat_model_stream" && event.metadata?.stream_channel === "processing" /* PROCESSING */ && event.data?.chunk?.content) {
|
|
4470
4517
|
const chunk = event.data.chunk.content;
|
|
4471
4518
|
const blocks = this.normalizeContentBlocks(chunk);
|
|
4472
|
-
|
|
4473
|
-
|
|
4519
|
+
for (const block of blocks) {
|
|
4520
|
+
if (block.type === "tool_use" || block.type === "tool_call") {
|
|
4521
|
+
if (acc.currentToolUse) {
|
|
4522
|
+
acc.currentReasoningSteps.push(acc.currentToolUse);
|
|
4523
|
+
}
|
|
4524
|
+
acc.currentToolUse = {
|
|
4525
|
+
index: acc.currentReasoningSteps.length,
|
|
4526
|
+
type: "tool_use",
|
|
4527
|
+
name: block.name,
|
|
4528
|
+
id: block.id,
|
|
4529
|
+
input: block.input || "",
|
|
4530
|
+
output: ""
|
|
4531
|
+
};
|
|
4532
|
+
if (onPartial) {
|
|
4533
|
+
onPartial(
|
|
4534
|
+
JSON.stringify({
|
|
4535
|
+
processing_delta: {
|
|
4536
|
+
type: "step_started",
|
|
4537
|
+
step: acc.currentToolUse
|
|
4538
|
+
}
|
|
4539
|
+
})
|
|
4540
|
+
);
|
|
4541
|
+
}
|
|
4542
|
+
} else if (block.type === "input_json_delta") {
|
|
4543
|
+
if (acc.currentToolUse && onPartial) {
|
|
4544
|
+
const chunk2 = block.input || "";
|
|
4545
|
+
acc.currentToolUse.output += chunk2;
|
|
4546
|
+
onPartial(
|
|
4547
|
+
JSON.stringify({
|
|
4548
|
+
processing_delta: {
|
|
4549
|
+
type: "output_chunk",
|
|
4550
|
+
stepId: acc.currentToolUse.id,
|
|
4551
|
+
chunk: chunk2
|
|
4552
|
+
}
|
|
4553
|
+
})
|
|
4554
|
+
);
|
|
4555
|
+
}
|
|
4556
|
+
}
|
|
4474
4557
|
}
|
|
4475
4558
|
return;
|
|
4476
4559
|
}
|
|
@@ -4507,29 +4590,59 @@ var EventProcessor = class {
|
|
|
4507
4590
|
);
|
|
4508
4591
|
}
|
|
4509
4592
|
if (event.metadata?.stream_channel === "processing" /* PROCESSING */) {
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
[];
|
|
4514
|
-
let steps;
|
|
4515
|
-
if (Array.isArray(stepsRaw)) {
|
|
4516
|
-
steps = stepsRaw;
|
|
4517
|
-
} else if (typeof stepsRaw === "string" && stepsRaw.trim().length > 0) {
|
|
4518
|
-
steps = [
|
|
4519
|
-
{
|
|
4520
|
-
index: 0,
|
|
4521
|
-
type: "text",
|
|
4522
|
-
text: stepsRaw.trim()
|
|
4523
|
-
}
|
|
4524
|
-
];
|
|
4525
|
-
} else {
|
|
4526
|
-
steps = [];
|
|
4593
|
+
if (acc.currentToolUse) {
|
|
4594
|
+
acc.currentReasoningSteps.push(acc.currentToolUse);
|
|
4595
|
+
acc.currentToolUse = null;
|
|
4527
4596
|
}
|
|
4528
|
-
if (
|
|
4597
|
+
if (acc.currentReasoningSteps.length > 0) {
|
|
4529
4598
|
acc.reasoningChains.push({
|
|
4530
|
-
steps,
|
|
4599
|
+
steps: acc.currentReasoningSteps,
|
|
4531
4600
|
isComplete: true
|
|
4532
4601
|
});
|
|
4602
|
+
if (onPartial) {
|
|
4603
|
+
onPartial(
|
|
4604
|
+
JSON.stringify({
|
|
4605
|
+
processing_delta: {
|
|
4606
|
+
type: "chain_completed"
|
|
4607
|
+
}
|
|
4608
|
+
})
|
|
4609
|
+
);
|
|
4610
|
+
}
|
|
4611
|
+
acc.currentReasoningSteps = [];
|
|
4612
|
+
} else {
|
|
4613
|
+
const stepsRaw = output?.content || // AIMessageChunk object (direct)
|
|
4614
|
+
output?.kwargs?.content || // Serialized LangChain format
|
|
4615
|
+
event.data?.chunk?.content || // Older version
|
|
4616
|
+
[];
|
|
4617
|
+
let steps;
|
|
4618
|
+
if (Array.isArray(stepsRaw)) {
|
|
4619
|
+
steps = this.mapReasoningSteps(stepsRaw);
|
|
4620
|
+
} else if (typeof stepsRaw === "string" && stepsRaw.trim().length > 0) {
|
|
4621
|
+
steps = [
|
|
4622
|
+
{
|
|
4623
|
+
index: 0,
|
|
4624
|
+
type: "text",
|
|
4625
|
+
text: stepsRaw.trim()
|
|
4626
|
+
}
|
|
4627
|
+
];
|
|
4628
|
+
} else {
|
|
4629
|
+
steps = [];
|
|
4630
|
+
}
|
|
4631
|
+
if (steps.length > 0) {
|
|
4632
|
+
acc.reasoningChains.push({
|
|
4633
|
+
steps,
|
|
4634
|
+
isComplete: true
|
|
4635
|
+
});
|
|
4636
|
+
if (onPartial) {
|
|
4637
|
+
onPartial(
|
|
4638
|
+
JSON.stringify({
|
|
4639
|
+
processing_delta: {
|
|
4640
|
+
type: "chain_completed"
|
|
4641
|
+
}
|
|
4642
|
+
})
|
|
4643
|
+
);
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4533
4646
|
}
|
|
4534
4647
|
}
|
|
4535
4648
|
return;
|