@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/index.cjs CHANGED
@@ -8316,6 +8316,7 @@ function readBody2(req) {
8316
8316
  // src/api/handlers/conversations.handlers.ts
8317
8317
  var SEARCH_OVERFETCH = 4;
8318
8318
  var SEARCH_MAX_SCAN = 1e3;
8319
+ var MAX_BYTES_CEILING = 32 * 1024 * 1024;
8319
8320
  var ConversationHandlers = class {
8320
8321
  constructor(deps) {
8321
8322
  this.deps = deps;
@@ -8721,7 +8722,7 @@ var ConversationHandlers = class {
8721
8722
  const total = filtered.length;
8722
8723
  const hasAnchor = url.searchParams.has("anchor_index");
8723
8724
  const hasAfter = url.searchParams.has("after_index");
8724
- const usePaging = url.searchParams.has("msg_limit") || url.searchParams.has("before_index") || hasAnchor || hasAfter;
8725
+ const usePaging = url.searchParams.has("msg_limit") || url.searchParams.has("before_index") || url.searchParams.has("max_bytes") || hasAnchor || hasAfter;
8725
8726
  let slice = filtered;
8726
8727
  let fromIdx = 0;
8727
8728
  let messagePagination;
@@ -8843,6 +8844,28 @@ var ConversationHandlers = class {
8843
8844
  content
8844
8845
  };
8845
8846
  });
8847
+ const requestedMaxBytes = intParam(url, "max_bytes", 0);
8848
+ if (requestedMaxBytes > 0 && messagesPayload.length > 0) {
8849
+ const budget = Math.min(requestedMaxBytes, MAX_BYTES_CEILING);
8850
+ let used = 0;
8851
+ let firstKept = messagesPayload.length - 1;
8852
+ for (let i = messagesPayload.length - 1; i >= 0; i--) {
8853
+ const size = Buffer.byteLength(JSON.stringify(messagesPayload[i]));
8854
+ if (i < messagesPayload.length - 1 && used + size > budget) break;
8855
+ used += size;
8856
+ firstKept = i;
8857
+ }
8858
+ if (firstKept > 0) {
8859
+ messagesPayload.splice(0, firstKept);
8860
+ if (messagePagination) {
8861
+ const newFrom = fromIdx + firstKept;
8862
+ messagePagination.from_index = newFrom;
8863
+ messagePagination.has_more_older = newFrom > 0;
8864
+ messagePagination.next_before_index = newFrom > 0 ? newFrom : null;
8865
+ }
8866
+ }
8867
+ if (messagePagination) messagePagination.served_bytes = used;
8868
+ }
8846
8869
  const conv = conversation;
8847
8870
  const cachedConvMeta = this.cache?.getMetaById(id);
8848
8871
  const convProvider = coerceProviderForRunner(conv.provider ?? cachedConvMeta?.provider);