@flutchai/flutch-sdk 0.7.2 → 0.7.3
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 +33 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +33 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5212,6 +5212,10 @@ exports.EventProcessor = class _EventProcessor {
|
|
|
5212
5212
|
attachments: [],
|
|
5213
5213
|
metadata: {},
|
|
5214
5214
|
traceEvents: [],
|
|
5215
|
+
traceMessages: {
|
|
5216
|
+
messages: {},
|
|
5217
|
+
keys: /* @__PURE__ */ new WeakMap()
|
|
5218
|
+
},
|
|
5215
5219
|
traceStartedAt: null,
|
|
5216
5220
|
traceCompletedAt: null
|
|
5217
5221
|
};
|
|
@@ -5613,6 +5617,7 @@ exports.EventProcessor = class _EventProcessor {
|
|
|
5613
5617
|
const completedAt = acc.traceCompletedAt ?? startedAt;
|
|
5614
5618
|
const trace = acc.traceEvents.length > 0 ? {
|
|
5615
5619
|
events: acc.traceEvents,
|
|
5620
|
+
messages: acc.traceMessages.messages,
|
|
5616
5621
|
startedAt,
|
|
5617
5622
|
completedAt,
|
|
5618
5623
|
durationMs: Math.max(0, completedAt - startedAt),
|
|
@@ -5640,14 +5645,14 @@ exports.EventProcessor = class _EventProcessor {
|
|
|
5640
5645
|
};
|
|
5641
5646
|
}
|
|
5642
5647
|
captureTraceEvent(acc, event) {
|
|
5643
|
-
const normalized = this.normalizeTraceEvent(event);
|
|
5648
|
+
const normalized = this.normalizeTraceEvent(event, acc.traceMessages);
|
|
5644
5649
|
if (!normalized) {
|
|
5645
5650
|
return;
|
|
5646
5651
|
}
|
|
5647
5652
|
acc.traceEvents.push(normalized);
|
|
5648
5653
|
this.logger.debug(`[TRACE] Captured trace event ${normalized.type} for node ${normalized.nodeName} (${acc.traceEvents.length} total)`);
|
|
5649
5654
|
}
|
|
5650
|
-
normalizeTraceEvent(event) {
|
|
5655
|
+
normalizeTraceEvent(event, traceMessages) {
|
|
5651
5656
|
const type = event?.event ?? event?.type;
|
|
5652
5657
|
if (!type) {
|
|
5653
5658
|
return null;
|
|
@@ -5686,7 +5691,7 @@ exports.EventProcessor = class _EventProcessor {
|
|
|
5686
5691
|
const metadata = sanitizeTraceData(event?.metadata, 0, /* @__PURE__ */ new WeakSet(), {
|
|
5687
5692
|
maxStringLength: TRACE_MAX_STRING
|
|
5688
5693
|
});
|
|
5689
|
-
const data = sanitizeTraceData(
|
|
5694
|
+
const data = sanitizeTraceData(refTraceMessages(event?.data, traceMessages), 0, /* @__PURE__ */ new WeakSet(), {
|
|
5690
5695
|
maxStringLength: TRACE_MAX_STRING
|
|
5691
5696
|
});
|
|
5692
5697
|
const timestampSource = event?.timestamp ?? event?.time ?? event?.data?.timestamp ?? event?.data?.ts ?? Date.now();
|
|
@@ -5708,39 +5713,39 @@ exports.EventProcessor = class _EventProcessor {
|
|
|
5708
5713
|
exports.EventProcessor = _ts_decorate21([
|
|
5709
5714
|
common.Injectable()
|
|
5710
5715
|
], exports.EventProcessor);
|
|
5711
|
-
var TRACE_MAX_STRING =
|
|
5712
|
-
|
|
5713
|
-
function compactTraceMessages(value, depth = 0) {
|
|
5716
|
+
var TRACE_MAX_STRING = 1e5;
|
|
5717
|
+
function refTraceMessages(value, store, depth = 0) {
|
|
5714
5718
|
if (depth > 6 || value === null || typeof value !== "object") return value;
|
|
5715
5719
|
if (Array.isArray(value)) {
|
|
5716
|
-
|
|
5717
|
-
|
|
5720
|
+
if (isHistory(value)) {
|
|
5721
|
+
return value.map((message) => ({
|
|
5722
|
+
_traceMsg: messageKey(message, store)
|
|
5723
|
+
}));
|
|
5724
|
+
}
|
|
5725
|
+
return value.map((item) => refTraceMessages(item, store, depth + 1));
|
|
5718
5726
|
}
|
|
5719
5727
|
const out = {};
|
|
5720
5728
|
for (const [key, item] of Object.entries(value)) {
|
|
5721
|
-
out[key] =
|
|
5729
|
+
out[key] = refTraceMessages(item, store, depth + 1);
|
|
5722
5730
|
}
|
|
5723
5731
|
return out;
|
|
5724
5732
|
}
|
|
5725
|
-
__name(
|
|
5733
|
+
__name(refTraceMessages, "refTraceMessages");
|
|
5734
|
+
function messageKey(message, store) {
|
|
5735
|
+
const known = store.keys.get(message);
|
|
5736
|
+
if (known) return known;
|
|
5737
|
+
const key = `m${Object.keys(store.messages).length + 1}`;
|
|
5738
|
+
store.keys.set(message, key);
|
|
5739
|
+
store.messages[key] = sanitizeTraceData(message, 0, /* @__PURE__ */ new WeakSet(), {
|
|
5740
|
+
maxStringLength: TRACE_MAX_STRING
|
|
5741
|
+
});
|
|
5742
|
+
return key;
|
|
5743
|
+
}
|
|
5744
|
+
__name(messageKey, "messageKey");
|
|
5726
5745
|
function isHistory(items) {
|
|
5727
|
-
return items.length >
|
|
5746
|
+
return items.length > 0 && 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
5747
|
}
|
|
5729
5748
|
__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");
|
|
5744
5749
|
var als = new async_hooks.AsyncLocalStorage();
|
|
5745
5750
|
function withFlutchContext(ctx, fn) {
|
|
5746
5751
|
return als.run(ctx, fn);
|
|
@@ -6014,6 +6019,7 @@ exports.LangGraphEngine = class _LangGraphEngine {
|
|
|
6014
6019
|
agentId: context.agentId || "unknown",
|
|
6015
6020
|
companyId: context.companyId || "unknown",
|
|
6016
6021
|
events: trace.events,
|
|
6022
|
+
messages: trace.messages,
|
|
6017
6023
|
totalEvents: trace.totalEvents,
|
|
6018
6024
|
startedAt: trace.startedAt,
|
|
6019
6025
|
completedAt: trace.completedAt || Date.now(),
|
|
@@ -6100,6 +6106,7 @@ exports.LangGraphEngine = class _LangGraphEngine {
|
|
|
6100
6106
|
durationMs: payload.durationMs,
|
|
6101
6107
|
status: payload.status || "success",
|
|
6102
6108
|
error: payload.error,
|
|
6109
|
+
messages: payload.messages,
|
|
6103
6110
|
events: payload.events.map((event) => ({
|
|
6104
6111
|
timestamp: event.timestamp ? new Date(event.timestamp).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
6105
6112
|
meta: {
|
|
@@ -9133,7 +9140,6 @@ exports.buildEffortRequestFields = buildEffortRequestFields;
|
|
|
9133
9140
|
exports.buildOAuthAuthorizationUrl = buildOAuthAuthorizationUrl;
|
|
9134
9141
|
exports.buildOpenAIModelConfig = buildOpenAIModelConfig;
|
|
9135
9142
|
exports.clearAttachmentDataStore = clearAttachmentDataStore;
|
|
9136
|
-
exports.compactTraceMessages = compactTraceMessages;
|
|
9137
9143
|
exports.createEndpointDescriptors = createEndpointDescriptors;
|
|
9138
9144
|
exports.createGraphAttachment = createGraphAttachment;
|
|
9139
9145
|
exports.createMongoClientAdapter = createMongoClientAdapter;
|
|
@@ -9175,6 +9181,7 @@ exports.modelSupportsPromptCache = modelSupportsPromptCache;
|
|
|
9175
9181
|
exports.normalizeToolConfigs = normalizeToolConfigs;
|
|
9176
9182
|
exports.parseToolSearchResult = parseToolSearchResult;
|
|
9177
9183
|
exports.redactConnectionString = redactConnectionString;
|
|
9184
|
+
exports.refTraceMessages = refTraceMessages;
|
|
9178
9185
|
exports.registerFinanceExampleCallback = registerFinanceExampleCallback;
|
|
9179
9186
|
exports.registerUIEndpointsFromClass = registerUIEndpointsFromClass;
|
|
9180
9187
|
exports.resolveOAuthProviderConfig = resolveOAuthProviderConfig;
|