@flutchai/flutch-sdk 0.7.1 → 0.7.2
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 +40 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +40 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5683,8 +5683,12 @@ exports.EventProcessor = class _EventProcessor {
|
|
|
5683
5683
|
if (!hasLangGraphNode && type.startsWith("on_chain")) {
|
|
5684
5684
|
return null;
|
|
5685
5685
|
}
|
|
5686
|
-
const metadata = sanitizeTraceData(event?.metadata)
|
|
5687
|
-
|
|
5686
|
+
const metadata = sanitizeTraceData(event?.metadata, 0, /* @__PURE__ */ new WeakSet(), {
|
|
5687
|
+
maxStringLength: TRACE_MAX_STRING
|
|
5688
|
+
});
|
|
5689
|
+
const data = sanitizeTraceData(compactTraceMessages(event?.data), 0, /* @__PURE__ */ new WeakSet(), {
|
|
5690
|
+
maxStringLength: TRACE_MAX_STRING
|
|
5691
|
+
});
|
|
5688
5692
|
const timestampSource = event?.timestamp ?? event?.time ?? event?.data?.timestamp ?? event?.data?.ts ?? Date.now();
|
|
5689
5693
|
const timestamp = Number(timestampSource) || Date.now();
|
|
5690
5694
|
const streamChannel = typeof event?.metadata?.stream_channel === "string" ? event.metadata.stream_channel : typeof metadata?.stream_channel === "string" ? metadata.stream_channel : void 0;
|
|
@@ -5704,6 +5708,39 @@ exports.EventProcessor = class _EventProcessor {
|
|
|
5704
5708
|
exports.EventProcessor = _ts_decorate21([
|
|
5705
5709
|
common.Injectable()
|
|
5706
5710
|
], exports.EventProcessor);
|
|
5711
|
+
var TRACE_MAX_STRING = 2e4;
|
|
5712
|
+
var TRACE_KEEP_LAST_MESSAGES = 6;
|
|
5713
|
+
function compactTraceMessages(value, depth = 0) {
|
|
5714
|
+
if (depth > 6 || value === null || typeof value !== "object") return value;
|
|
5715
|
+
if (Array.isArray(value)) {
|
|
5716
|
+
const items = isHistory(value) ? compactHistory(value) : value;
|
|
5717
|
+
return items.map((item) => compactTraceMessages(item, depth + 1));
|
|
5718
|
+
}
|
|
5719
|
+
const out = {};
|
|
5720
|
+
for (const [key, item] of Object.entries(value)) {
|
|
5721
|
+
out[key] = compactTraceMessages(item, depth + 1);
|
|
5722
|
+
}
|
|
5723
|
+
return out;
|
|
5724
|
+
}
|
|
5725
|
+
__name(compactTraceMessages, "compactTraceMessages");
|
|
5726
|
+
function isHistory(items) {
|
|
5727
|
+
return items.length > TRACE_KEEP_LAST_MESSAGES + 2 && items.every((item) => item !== null && typeof item === "object" && !Array.isArray(item) && ("lc_kwargs" in item || "content" in item && ("type" in item || "role" in item)));
|
|
5728
|
+
}
|
|
5729
|
+
__name(isHistory, "isHistory");
|
|
5730
|
+
function compactHistory(messages) {
|
|
5731
|
+
const keep = TRACE_KEEP_LAST_MESSAGES + 1;
|
|
5732
|
+
if (messages.length <= keep + 1) return messages;
|
|
5733
|
+
const omitted = messages.length - keep;
|
|
5734
|
+
return [
|
|
5735
|
+
messages[0],
|
|
5736
|
+
{
|
|
5737
|
+
type: "trace_omitted",
|
|
5738
|
+
omittedMessages: omitted
|
|
5739
|
+
},
|
|
5740
|
+
...messages.slice(-TRACE_KEEP_LAST_MESSAGES)
|
|
5741
|
+
];
|
|
5742
|
+
}
|
|
5743
|
+
__name(compactHistory, "compactHistory");
|
|
5707
5744
|
var als = new async_hooks.AsyncLocalStorage();
|
|
5708
5745
|
function withFlutchContext(ctx, fn) {
|
|
5709
5746
|
return als.run(ctx, fn);
|
|
@@ -9096,6 +9133,7 @@ exports.buildEffortRequestFields = buildEffortRequestFields;
|
|
|
9096
9133
|
exports.buildOAuthAuthorizationUrl = buildOAuthAuthorizationUrl;
|
|
9097
9134
|
exports.buildOpenAIModelConfig = buildOpenAIModelConfig;
|
|
9098
9135
|
exports.clearAttachmentDataStore = clearAttachmentDataStore;
|
|
9136
|
+
exports.compactTraceMessages = compactTraceMessages;
|
|
9099
9137
|
exports.createEndpointDescriptors = createEndpointDescriptors;
|
|
9100
9138
|
exports.createGraphAttachment = createGraphAttachment;
|
|
9101
9139
|
exports.createMongoClientAdapter = createMongoClientAdapter;
|