billion-context 0.1.53-pr.241.82 → 0.1.53-pr.244.85

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.js CHANGED
@@ -50535,6 +50535,24 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
50535
50535
  }
50536
50536
 
50537
50537
  // src/loop/adapter-responses.ts
50538
+ function shortItemHash(input) {
50539
+ let h = 2166136261;
50540
+ for (let i = 0; i < input.length; i++) {
50541
+ h ^= input.charCodeAt(i);
50542
+ h = Math.imul(h, 16777619);
50543
+ }
50544
+ return (h >>> 0).toString(36);
50545
+ }
50546
+ var RESPONSES_ITEM_ID_MAX = 64;
50547
+ function sanitizeResponsesInputIds(input) {
50548
+ if (!Array.isArray(input)) return;
50549
+ for (const item of input) {
50550
+ const rec = item;
50551
+ if (typeof rec?.id === "string" && rec.id.length > RESPONSES_ITEM_ID_MAX) {
50552
+ rec.id = `msg-fix-${shortItemHash(rec.id)}`;
50553
+ }
50554
+ }
50555
+ }
50538
50556
  function rewriteItemEvent(type, obj, mapped) {
50539
50557
  const item = { ...obj.item ?? {}, id: mapped.id };
50540
50558
  return Buffer.from(`event: ${type}
@@ -50766,7 +50784,7 @@ function createResponsesAdapter(textProtocol, projection) {
50766
50784
  yield { kind: "meta", chunk: rawBuf, firstRoundOnly: false };
50767
50785
  } else if (item?.type === "message" && round > 1 && !suppressTextLifecycle) {
50768
50786
  const origId = typeof item.id === "string" ? item.id : "";
50769
- const mapped = { id: `msg-proxy-${round}-${origId || outputIndex}`, index: outputIndex++ };
50787
+ const mapped = { id: `msg-proxy-${round}-${shortItemHash(origId || String(outputIndex))}`, index: outputIndex++ };
50770
50788
  if (origId) remapped.set(origId, mapped);
50771
50789
  yield { kind: "meta", chunk: rewriteItemEvent(type, obj, mapped), firstRoundOnly: false };
50772
50790
  } else if (item?.type !== "message" || !suppressTextLifecycle) {
@@ -54698,6 +54716,7 @@ function prepareResponses(parsed, req, opts, core, config, prompts, log2, sessio
54698
54716
  let responsesProjection;
54699
54717
  let rebuiltInput = parsed.input;
54700
54718
  let toolsOut = parsed.tools;
54719
+ sanitizeResponsesInputIds(parsed.input);
54701
54720
  const shouldInject = opts.compress.injectTool;
54702
54721
  const injectTools = shouldInject && !pluginMode;
54703
54722
  const responsesTextProtocol = FORCE_TEXT_PROTOCOL || resolveCompressProtocol(opts.routes, session.meta.upstreamOrigin) === "marker";