@flutchai/flutch-sdk 0.1.15 → 0.1.17
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 -22
- 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 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4832,6 +4832,8 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4832
4832
|
return this.processGraphResult(result);
|
|
4833
4833
|
}
|
|
4834
4834
|
async streamGraph(graph, config, onPartial, signal) {
|
|
4835
|
+
const acc = this.eventProcessor.createAccumulator();
|
|
4836
|
+
let streamError = null;
|
|
4835
4837
|
try {
|
|
4836
4838
|
if (signal) {
|
|
4837
4839
|
config.signal = signal;
|
|
@@ -4841,7 +4843,6 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4841
4843
|
version: "v2"
|
|
4842
4844
|
// Important for correct operation
|
|
4843
4845
|
});
|
|
4844
|
-
const acc = this.eventProcessor.createAccumulator();
|
|
4845
4846
|
for await (const event of eventStream) {
|
|
4846
4847
|
try {
|
|
4847
4848
|
this.eventProcessor.processEvent(acc, event, onPartial);
|
|
@@ -4851,20 +4852,44 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4851
4852
|
);
|
|
4852
4853
|
}
|
|
4853
4854
|
}
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4855
|
+
} catch (error) {
|
|
4856
|
+
streamError = error instanceof Error ? error : new Error(String(error));
|
|
4857
|
+
this.logger.error(
|
|
4858
|
+
`[STREAM-ERROR] Error in streamGraph: ${streamError.message}`
|
|
4859
|
+
);
|
|
4860
|
+
this.logger.error(`[STREAM-ERROR] Stack trace: ${streamError.stack}`);
|
|
4861
|
+
} finally {
|
|
4862
|
+
await this.sendTraceFromAccumulator(acc, config, streamError);
|
|
4863
|
+
}
|
|
4864
|
+
const { content, trace } = this.eventProcessor.getResult(acc);
|
|
4865
|
+
this.logger.debug("[STREAM-RESULT] Got result from EventProcessor", {
|
|
4866
|
+
hasContent: !!content,
|
|
4867
|
+
hasContext: !!config.configurable?.context,
|
|
4868
|
+
hasTrace: !!trace,
|
|
4869
|
+
traceEvents: trace?.events?.length || 0,
|
|
4870
|
+
hadError: !!streamError
|
|
4871
|
+
});
|
|
4872
|
+
if (streamError) {
|
|
4873
|
+
throw streamError;
|
|
4874
|
+
}
|
|
4875
|
+
return content;
|
|
4876
|
+
}
|
|
4877
|
+
/**
|
|
4878
|
+
* Extract trace from accumulator and send to backend webhook
|
|
4879
|
+
* Called in finally block to ensure trace is sent even on errors
|
|
4880
|
+
*/
|
|
4881
|
+
async sendTraceFromAccumulator(acc, config, error) {
|
|
4882
|
+
try {
|
|
4883
|
+
const { trace } = this.eventProcessor.getResult(acc);
|
|
4861
4884
|
if (trace && trace.events.length > 0 && config.configurable?.context) {
|
|
4862
4885
|
const context = config.configurable.context;
|
|
4863
4886
|
this.logger.debug("[TRACE-WEBHOOK] Sending trace events batch", {
|
|
4864
4887
|
messageId: context.messageId,
|
|
4865
4888
|
totalEvents: trace.totalEvents,
|
|
4866
4889
|
eventsArrayLength: trace.events.length,
|
|
4867
|
-
firstEventType: trace.events[0]?.type
|
|
4890
|
+
firstEventType: trace.events[0]?.type,
|
|
4891
|
+
hadError: !!error,
|
|
4892
|
+
errorMessage: error?.message
|
|
4868
4893
|
});
|
|
4869
4894
|
await this.sendTraceEventsBatch({
|
|
4870
4895
|
messageId: context.messageId || "unknown",
|
|
@@ -4875,24 +4900,28 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4875
4900
|
events: trace.events,
|
|
4876
4901
|
totalEvents: trace.totalEvents,
|
|
4877
4902
|
startedAt: trace.startedAt,
|
|
4878
|
-
completedAt: trace.completedAt,
|
|
4879
|
-
durationMs: trace.durationMs
|
|
4903
|
+
completedAt: trace.completedAt || Date.now(),
|
|
4904
|
+
durationMs: trace.durationMs || Date.now() - trace.startedAt,
|
|
4905
|
+
status: error ? "error" : "success",
|
|
4906
|
+
error: error ? { message: error.message, name: error.name } : void 0
|
|
4880
4907
|
});
|
|
4881
4908
|
} else {
|
|
4882
4909
|
this.logger.debug("[TRACE-WEBHOOK] Skipping webhook", {
|
|
4883
4910
|
hasTrace: !!trace,
|
|
4884
4911
|
traceEvents: trace?.events?.length || 0,
|
|
4885
4912
|
hasContext: !!config.configurable?.context,
|
|
4886
|
-
contextKeys: config.configurable?.context ? Object.keys(config.configurable.context) : []
|
|
4913
|
+
contextKeys: config.configurable?.context ? Object.keys(config.configurable.context) : [],
|
|
4914
|
+
hadError: !!error
|
|
4887
4915
|
});
|
|
4888
4916
|
}
|
|
4889
|
-
|
|
4890
|
-
} catch (error) {
|
|
4917
|
+
} catch (webhookError) {
|
|
4891
4918
|
this.logger.error(
|
|
4892
|
-
|
|
4919
|
+
"[TRACE-WEBHOOK] Failed to send trace in finally block",
|
|
4920
|
+
{
|
|
4921
|
+
error: webhookError instanceof Error ? webhookError.message : String(webhookError),
|
|
4922
|
+
originalError: error?.message
|
|
4923
|
+
}
|
|
4893
4924
|
);
|
|
4894
|
-
this.logger.error(`[STREAM-ERROR] Stack trace: ${error.stack}`);
|
|
4895
|
-
throw error;
|
|
4896
4925
|
}
|
|
4897
4926
|
}
|
|
4898
4927
|
/**
|
|
@@ -4959,6 +4988,8 @@ exports.LangGraphEngine = class LangGraphEngine {
|
|
|
4959
4988
|
startedAt: payload.startedAt,
|
|
4960
4989
|
completedAt: payload.completedAt,
|
|
4961
4990
|
durationMs: payload.durationMs,
|
|
4991
|
+
status: payload.status || "success",
|
|
4992
|
+
error: payload.error,
|
|
4962
4993
|
events: payload.events.map((event) => ({
|
|
4963
4994
|
timestamp: event.timestamp ? new Date(event.timestamp).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
4964
4995
|
meta: {
|
|
@@ -5355,11 +5386,7 @@ var McpConverter = class _McpConverter {
|
|
|
5355
5386
|
let zodProp;
|
|
5356
5387
|
switch (prop.type) {
|
|
5357
5388
|
case "string":
|
|
5358
|
-
|
|
5359
|
-
zodProp = zod.z.enum(prop.enum);
|
|
5360
|
-
} else {
|
|
5361
|
-
zodProp = zod.z.string();
|
|
5362
|
-
}
|
|
5389
|
+
zodProp = zod.z.string();
|
|
5363
5390
|
break;
|
|
5364
5391
|
case "number":
|
|
5365
5392
|
zodProp = zod.z.number();
|