@flutchai/flutch-sdk 0.1.6 → 0.1.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 +163 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +164 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3076,9 +3076,6 @@ var _AbstractGraphBuilder = class _AbstractGraphBuilder {
|
|
|
3076
3076
|
if (this.manifest?.companySlug && this.manifest?.name) {
|
|
3077
3077
|
return `${this.manifest.companySlug}.${this.manifest.name}::${this.version}`;
|
|
3078
3078
|
}
|
|
3079
|
-
console.log(
|
|
3080
|
-
`DEBUG graphType: manifest=${!!this.manifest}, companySlug=${this.manifest?.companySlug}, name=${this.manifest?.name}, version=${this.version}`
|
|
3081
|
-
);
|
|
3082
3079
|
return `unknown::${this.version}`;
|
|
3083
3080
|
}
|
|
3084
3081
|
/**
|
|
@@ -3410,6 +3407,9 @@ exports.UniversalGraphService = class UniversalGraphService {
|
|
|
3410
3407
|
this.engine = engine;
|
|
3411
3408
|
this.endpointRegistry = endpointRegistry;
|
|
3412
3409
|
this.logger.log("UniversalGraphService initialized");
|
|
3410
|
+
if (!this.engine) {
|
|
3411
|
+
this.logger.error("GRAPH_ENGINE is not properly injected!");
|
|
3412
|
+
}
|
|
3413
3413
|
}
|
|
3414
3414
|
logger = new common.Logger(exports.UniversalGraphService.name);
|
|
3415
3415
|
/**
|
|
@@ -4405,11 +4405,11 @@ function sanitizeTraceError(error, options) {
|
|
|
4405
4405
|
raw: sanitizeTraceData(error, 0, /* @__PURE__ */ new WeakSet(), options)
|
|
4406
4406
|
};
|
|
4407
4407
|
}
|
|
4408
|
-
var GraphEngineType = /* @__PURE__ */ ((
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
return
|
|
4408
|
+
var GraphEngineType = /* @__PURE__ */ ((GraphEngineType3) => {
|
|
4409
|
+
GraphEngineType3["LANGGRAPH"] = "langgraph";
|
|
4410
|
+
GraphEngineType3["LANGFLOW"] = "langflow";
|
|
4411
|
+
GraphEngineType3["FLOWISE"] = "flowise";
|
|
4412
|
+
return GraphEngineType3;
|
|
4413
4413
|
})(GraphEngineType || {});
|
|
4414
4414
|
exports.GraphEngineFactory = class GraphEngineFactory {
|
|
4415
4415
|
constructor(langgraph) {
|
|
@@ -4448,7 +4448,9 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4448
4448
|
llmCalls: [],
|
|
4449
4449
|
traceEvents: [],
|
|
4450
4450
|
traceStartedAt: null,
|
|
4451
|
-
traceCompletedAt: null
|
|
4451
|
+
traceCompletedAt: null,
|
|
4452
|
+
currentReasoningSteps: [],
|
|
4453
|
+
currentToolUse: null
|
|
4452
4454
|
};
|
|
4453
4455
|
}
|
|
4454
4456
|
/**
|
|
@@ -4476,6 +4478,51 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4476
4478
|
}
|
|
4477
4479
|
return [];
|
|
4478
4480
|
}
|
|
4481
|
+
/**
|
|
4482
|
+
* Groups tool_use and input_json_delta into proper structure
|
|
4483
|
+
* tool_use.input → output (tool execution result)
|
|
4484
|
+
* input_json_delta.input → output (tool execution result, accumulated)
|
|
4485
|
+
*/
|
|
4486
|
+
mapReasoningSteps(rawSteps) {
|
|
4487
|
+
const steps = [];
|
|
4488
|
+
let currentToolUse = null;
|
|
4489
|
+
for (const raw of rawSteps) {
|
|
4490
|
+
if (raw.type === "tool_use" || raw.type === "tool_call") {
|
|
4491
|
+
if (currentToolUse) {
|
|
4492
|
+
steps.push(currentToolUse);
|
|
4493
|
+
}
|
|
4494
|
+
currentToolUse = {
|
|
4495
|
+
index: raw.index || 0,
|
|
4496
|
+
type: "tool_use",
|
|
4497
|
+
name: raw.name,
|
|
4498
|
+
id: raw.id,
|
|
4499
|
+
input: "",
|
|
4500
|
+
// Parameters (IN) - filled separately or empty
|
|
4501
|
+
output: raw.input || ""
|
|
4502
|
+
// Result (OUT) - comes in tool_use.input
|
|
4503
|
+
};
|
|
4504
|
+
} else if (raw.type === "input_json_delta") {
|
|
4505
|
+
if (currentToolUse) {
|
|
4506
|
+
currentToolUse.output = (currentToolUse.output || "") + (raw.input || "");
|
|
4507
|
+
}
|
|
4508
|
+
} else {
|
|
4509
|
+
if (currentToolUse) {
|
|
4510
|
+
steps.push(currentToolUse);
|
|
4511
|
+
currentToolUse = null;
|
|
4512
|
+
}
|
|
4513
|
+
steps.push({
|
|
4514
|
+
index: raw.index || 0,
|
|
4515
|
+
type: raw.type,
|
|
4516
|
+
text: raw.text || "",
|
|
4517
|
+
metadata: raw.metadata
|
|
4518
|
+
});
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
if (currentToolUse) {
|
|
4522
|
+
steps.push(currentToolUse);
|
|
4523
|
+
}
|
|
4524
|
+
return steps;
|
|
4525
|
+
}
|
|
4479
4526
|
/**
|
|
4480
4527
|
* Process a LangGraph stream event
|
|
4481
4528
|
* Mutates accumulator to collect data from different channels
|
|
@@ -4498,8 +4545,44 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4498
4545
|
if (event.event === "on_chat_model_stream" && event.metadata?.stream_channel === "processing" /* PROCESSING */ && event.data?.chunk?.content) {
|
|
4499
4546
|
const chunk = event.data.chunk.content;
|
|
4500
4547
|
const blocks = this.normalizeContentBlocks(chunk);
|
|
4501
|
-
|
|
4502
|
-
|
|
4548
|
+
for (const block of blocks) {
|
|
4549
|
+
if (block.type === "tool_use" || block.type === "tool_call") {
|
|
4550
|
+
if (acc.currentToolUse) {
|
|
4551
|
+
acc.currentReasoningSteps.push(acc.currentToolUse);
|
|
4552
|
+
}
|
|
4553
|
+
acc.currentToolUse = {
|
|
4554
|
+
index: acc.currentReasoningSteps.length,
|
|
4555
|
+
type: "tool_use",
|
|
4556
|
+
name: block.name,
|
|
4557
|
+
id: block.id,
|
|
4558
|
+
input: block.input || "",
|
|
4559
|
+
output: ""
|
|
4560
|
+
};
|
|
4561
|
+
if (onPartial) {
|
|
4562
|
+
onPartial(
|
|
4563
|
+
JSON.stringify({
|
|
4564
|
+
processing_delta: {
|
|
4565
|
+
type: "step_started",
|
|
4566
|
+
step: acc.currentToolUse
|
|
4567
|
+
}
|
|
4568
|
+
})
|
|
4569
|
+
);
|
|
4570
|
+
}
|
|
4571
|
+
} else if (block.type === "input_json_delta") {
|
|
4572
|
+
if (acc.currentToolUse && onPartial) {
|
|
4573
|
+
const chunk2 = block.input || "";
|
|
4574
|
+
acc.currentToolUse.output += chunk2;
|
|
4575
|
+
onPartial(
|
|
4576
|
+
JSON.stringify({
|
|
4577
|
+
processing_delta: {
|
|
4578
|
+
type: "output_chunk",
|
|
4579
|
+
stepId: acc.currentToolUse.id,
|
|
4580
|
+
chunk: chunk2
|
|
4581
|
+
}
|
|
4582
|
+
})
|
|
4583
|
+
);
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4503
4586
|
}
|
|
4504
4587
|
return;
|
|
4505
4588
|
}
|
|
@@ -4536,29 +4619,59 @@ exports.EventProcessor = class EventProcessor {
|
|
|
4536
4619
|
);
|
|
4537
4620
|
}
|
|
4538
4621
|
if (event.metadata?.stream_channel === "processing" /* PROCESSING */) {
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
[];
|
|
4543
|
-
let steps;
|
|
4544
|
-
if (Array.isArray(stepsRaw)) {
|
|
4545
|
-
steps = stepsRaw;
|
|
4546
|
-
} else if (typeof stepsRaw === "string" && stepsRaw.trim().length > 0) {
|
|
4547
|
-
steps = [
|
|
4548
|
-
{
|
|
4549
|
-
index: 0,
|
|
4550
|
-
type: "text",
|
|
4551
|
-
text: stepsRaw.trim()
|
|
4552
|
-
}
|
|
4553
|
-
];
|
|
4554
|
-
} else {
|
|
4555
|
-
steps = [];
|
|
4622
|
+
if (acc.currentToolUse) {
|
|
4623
|
+
acc.currentReasoningSteps.push(acc.currentToolUse);
|
|
4624
|
+
acc.currentToolUse = null;
|
|
4556
4625
|
}
|
|
4557
|
-
if (
|
|
4626
|
+
if (acc.currentReasoningSteps.length > 0) {
|
|
4558
4627
|
acc.reasoningChains.push({
|
|
4559
|
-
steps,
|
|
4628
|
+
steps: acc.currentReasoningSteps,
|
|
4560
4629
|
isComplete: true
|
|
4561
4630
|
});
|
|
4631
|
+
if (onPartial) {
|
|
4632
|
+
onPartial(
|
|
4633
|
+
JSON.stringify({
|
|
4634
|
+
processing_delta: {
|
|
4635
|
+
type: "chain_completed"
|
|
4636
|
+
}
|
|
4637
|
+
})
|
|
4638
|
+
);
|
|
4639
|
+
}
|
|
4640
|
+
acc.currentReasoningSteps = [];
|
|
4641
|
+
} else {
|
|
4642
|
+
const stepsRaw = output?.content || // AIMessageChunk object (direct)
|
|
4643
|
+
output?.kwargs?.content || // Serialized LangChain format
|
|
4644
|
+
event.data?.chunk?.content || // Older version
|
|
4645
|
+
[];
|
|
4646
|
+
let steps;
|
|
4647
|
+
if (Array.isArray(stepsRaw)) {
|
|
4648
|
+
steps = this.mapReasoningSteps(stepsRaw);
|
|
4649
|
+
} else if (typeof stepsRaw === "string" && stepsRaw.trim().length > 0) {
|
|
4650
|
+
steps = [
|
|
4651
|
+
{
|
|
4652
|
+
index: 0,
|
|
4653
|
+
type: "text",
|
|
4654
|
+
text: stepsRaw.trim()
|
|
4655
|
+
}
|
|
4656
|
+
];
|
|
4657
|
+
} else {
|
|
4658
|
+
steps = [];
|
|
4659
|
+
}
|
|
4660
|
+
if (steps.length > 0) {
|
|
4661
|
+
acc.reasoningChains.push({
|
|
4662
|
+
steps,
|
|
4663
|
+
isComplete: true
|
|
4664
|
+
});
|
|
4665
|
+
if (onPartial) {
|
|
4666
|
+
onPartial(
|
|
4667
|
+
JSON.stringify({
|
|
4668
|
+
processing_delta: {
|
|
4669
|
+
type: "chain_completed"
|
|
4670
|
+
}
|
|
4671
|
+
})
|
|
4672
|
+
);
|
|
4673
|
+
}
|
|
4674
|
+
}
|
|
4562
4675
|
}
|
|
4563
4676
|
}
|
|
4564
4677
|
return;
|
|
@@ -4742,6 +4855,9 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4742
4855
|
constructor(eventProcessor, configService) {
|
|
4743
4856
|
this.eventProcessor = eventProcessor;
|
|
4744
4857
|
this.configService = configService;
|
|
4858
|
+
if (!eventProcessor) {
|
|
4859
|
+
this.logger.error("EventProcessor is undefined/null!");
|
|
4860
|
+
}
|
|
4745
4861
|
}
|
|
4746
4862
|
logger = new common.Logger(exports.LangGraphEngine.name);
|
|
4747
4863
|
/**
|
|
@@ -4844,8 +4960,8 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4844
4960
|
*/
|
|
4845
4961
|
async sendMetricsWebhook(payload) {
|
|
4846
4962
|
try {
|
|
4847
|
-
const backendUrl = this.configService
|
|
4848
|
-
const internalToken = this.configService
|
|
4963
|
+
const backendUrl = this.configService?.get("API_URL") || "http://amelie-service";
|
|
4964
|
+
const internalToken = this.configService?.get("INTERNAL_API_TOKEN");
|
|
4849
4965
|
if (!internalToken) {
|
|
4850
4966
|
this.logger.warn(
|
|
4851
4967
|
"[METRICS-WEBHOOK] INTERNAL_API_TOKEN not configured, skipping webhook"
|
|
@@ -4884,8 +5000,8 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4884
5000
|
}
|
|
4885
5001
|
async sendTraceEventsBatch(payload) {
|
|
4886
5002
|
try {
|
|
4887
|
-
const backendUrl = this.configService
|
|
4888
|
-
const internalToken = this.configService
|
|
5003
|
+
const backendUrl = this.configService?.get("API_URL") || "http://amelie-service";
|
|
5004
|
+
const internalToken = this.configService?.get("INTERNAL_API_TOKEN");
|
|
4889
5005
|
if (!internalToken) {
|
|
4890
5006
|
this.logger.warn(
|
|
4891
5007
|
"[TRACE-EVENTS-BATCH] INTERNAL_API_TOKEN not configured, skipping batch webhook"
|
|
@@ -4967,7 +5083,8 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4967
5083
|
}
|
|
4968
5084
|
};
|
|
4969
5085
|
exports.LangGraphEngine = __decorateClass([
|
|
4970
|
-
common.Injectable()
|
|
5086
|
+
common.Injectable(),
|
|
5087
|
+
__decorateParam(1, common.Optional())
|
|
4971
5088
|
], exports.LangGraphEngine);
|
|
4972
5089
|
|
|
4973
5090
|
// src/core/universal-graph.module.ts
|
|
@@ -5043,9 +5160,16 @@ exports.UniversalGraphModule = class UniversalGraphModule {
|
|
|
5043
5160
|
// Discovery services from @nestjs/core
|
|
5044
5161
|
core.MetadataScanner,
|
|
5045
5162
|
// Event processor for stream handling
|
|
5046
|
-
|
|
5163
|
+
{
|
|
5164
|
+
provide: exports.EventProcessor,
|
|
5165
|
+
useFactory: () => new exports.EventProcessor()
|
|
5166
|
+
},
|
|
5047
5167
|
// Graph engines
|
|
5048
|
-
|
|
5168
|
+
{
|
|
5169
|
+
provide: exports.LangGraphEngine,
|
|
5170
|
+
useFactory: (eventProcessor) => new exports.LangGraphEngine(eventProcessor, void 0),
|
|
5171
|
+
inject: [exports.EventProcessor]
|
|
5172
|
+
},
|
|
5049
5173
|
exports.BuilderRegistryService,
|
|
5050
5174
|
exports.GraphEngineFactory,
|
|
5051
5175
|
exports.VersionedGraphService,
|
|
@@ -5151,12 +5275,8 @@ exports.UniversalGraphModule = class UniversalGraphModule {
|
|
|
5151
5275
|
},
|
|
5152
5276
|
{
|
|
5153
5277
|
provide: "GRAPH_ENGINE",
|
|
5154
|
-
useFactory: (
|
|
5155
|
-
|
|
5156
|
-
options.engineType || "langgraph" /* LANGGRAPH */
|
|
5157
|
-
);
|
|
5158
|
-
},
|
|
5159
|
-
inject: [exports.GraphEngineFactory]
|
|
5278
|
+
useFactory: (langGraphEngine) => langGraphEngine,
|
|
5279
|
+
inject: [exports.LangGraphEngine]
|
|
5160
5280
|
},
|
|
5161
5281
|
{
|
|
5162
5282
|
provide: "GRAPH_BUILDERS",
|