@threadbase-sh/streamer 1.56.0 → 1.57.0
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/cli.cjs +24 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +24 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8271,6 +8271,7 @@ function readBody2(req) {
|
|
|
8271
8271
|
// src/api/handlers/conversations.handlers.ts
|
|
8272
8272
|
var SEARCH_OVERFETCH = 4;
|
|
8273
8273
|
var SEARCH_MAX_SCAN = 1e3;
|
|
8274
|
+
var MAX_BYTES_CEILING = 32 * 1024 * 1024;
|
|
8274
8275
|
var ConversationHandlers = class {
|
|
8275
8276
|
constructor(deps) {
|
|
8276
8277
|
this.deps = deps;
|
|
@@ -8676,7 +8677,7 @@ var ConversationHandlers = class {
|
|
|
8676
8677
|
const total = filtered.length;
|
|
8677
8678
|
const hasAnchor = url.searchParams.has("anchor_index");
|
|
8678
8679
|
const hasAfter = url.searchParams.has("after_index");
|
|
8679
|
-
const usePaging = url.searchParams.has("msg_limit") || url.searchParams.has("before_index") || hasAnchor || hasAfter;
|
|
8680
|
+
const usePaging = url.searchParams.has("msg_limit") || url.searchParams.has("before_index") || url.searchParams.has("max_bytes") || hasAnchor || hasAfter;
|
|
8680
8681
|
let slice = filtered;
|
|
8681
8682
|
let fromIdx = 0;
|
|
8682
8683
|
let messagePagination;
|
|
@@ -8798,6 +8799,28 @@ var ConversationHandlers = class {
|
|
|
8798
8799
|
content
|
|
8799
8800
|
};
|
|
8800
8801
|
});
|
|
8802
|
+
const requestedMaxBytes = intParam(url, "max_bytes", 0);
|
|
8803
|
+
if (requestedMaxBytes > 0 && messagesPayload.length > 0) {
|
|
8804
|
+
const budget = Math.min(requestedMaxBytes, MAX_BYTES_CEILING);
|
|
8805
|
+
let used = 0;
|
|
8806
|
+
let firstKept = messagesPayload.length - 1;
|
|
8807
|
+
for (let i = messagesPayload.length - 1; i >= 0; i--) {
|
|
8808
|
+
const size = Buffer.byteLength(JSON.stringify(messagesPayload[i]));
|
|
8809
|
+
if (i < messagesPayload.length - 1 && used + size > budget) break;
|
|
8810
|
+
used += size;
|
|
8811
|
+
firstKept = i;
|
|
8812
|
+
}
|
|
8813
|
+
if (firstKept > 0) {
|
|
8814
|
+
messagesPayload.splice(0, firstKept);
|
|
8815
|
+
if (messagePagination) {
|
|
8816
|
+
const newFrom = fromIdx + firstKept;
|
|
8817
|
+
messagePagination.from_index = newFrom;
|
|
8818
|
+
messagePagination.has_more_older = newFrom > 0;
|
|
8819
|
+
messagePagination.next_before_index = newFrom > 0 ? newFrom : null;
|
|
8820
|
+
}
|
|
8821
|
+
}
|
|
8822
|
+
if (messagePagination) messagePagination.served_bytes = used;
|
|
8823
|
+
}
|
|
8801
8824
|
const conv = conversation;
|
|
8802
8825
|
const cachedConvMeta = this.cache?.getMetaById(id);
|
|
8803
8826
|
const convProvider = coerceProviderForRunner(conv.provider ?? cachedConvMeta?.provider);
|