@aparte/core 1.10.1 → 1.11.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.
@@ -8564,10 +8564,10 @@ class AparteConversationController {
8564
8564
  const checkpointed = !!messageId && messages.some(
8565
8565
  (m) => m.id === messageId && typeof m.contextSummary?.createdAt === "number"
8566
8566
  );
8567
- const summaryMessage = !!summary && messages.some(
8567
+ const summaryMessage2 = !!summary && messages.some(
8568
8568
  (m) => m.compaction === true && typeof m.content === "string" && m.content.endsWith(summary)
8569
8569
  );
8570
- holds = checkpointed || summaryMessage;
8570
+ holds = checkpointed || summaryMessage2;
8571
8571
  }
8572
8572
  if (holds || !this._binding.afterRender || waits >= MAX_COMPACTION_SAVE_WAITS) {
8573
8573
  this._persistActive();
@@ -9653,6 +9653,19 @@ const COMPACTION_PREAMBLE = "The earlier part of this conversation was compacted
9653
9653
  const underPreamble = (text) => `${COMPACTION_PREAMBLE}
9654
9654
 
9655
9655
  ${text}`;
9656
+ const summaries = /* @__PURE__ */ new WeakMap();
9657
+ function summaryMessage(text) {
9658
+ const message = { role: "user", content: underPreamble(text) };
9659
+ summaries.set(message, message.content);
9660
+ return message;
9661
+ }
9662
+ function historySummaryOf(messages) {
9663
+ for (const message of messages) {
9664
+ const summary = summaries.get(message);
9665
+ if (summary !== void 0) return summary;
9666
+ }
9667
+ return void 0;
9668
+ }
9656
9669
  function mergeAdjacentUserMessages(messages) {
9657
9670
  const asParts = (c) => typeof c === "string" ? [{ type: "text", text: c }] : c;
9658
9671
  const out = [];
@@ -9660,15 +9673,13 @@ function mergeAdjacentUserMessages(messages) {
9660
9673
  const prev = out[out.length - 1];
9661
9674
  if (m.role !== "user" || prev?.role !== "user") {
9662
9675
  out.push(m);
9663
- } else if (typeof prev.content === "string" && typeof m.content === "string") {
9664
- out[out.length - 1] = { ...prev, content: `${prev.content}
9665
-
9666
- ${m.content}` };
9667
9676
  } else {
9668
- out[out.length - 1] = {
9669
- ...prev,
9670
- content: [...asParts(prev.content), { type: "text", text: "\n\n" }, ...asParts(m.content)]
9671
- };
9677
+ const merged = typeof prev.content === "string" && typeof m.content === "string" ? { ...prev, content: `${prev.content}
9678
+
9679
+ ${m.content}` } : { ...prev, content: [...asParts(prev.content), { type: "text", text: "\n\n" }, ...asParts(m.content)] };
9680
+ const summary = summaries.get(prev);
9681
+ if (summary !== void 0) summaries.set(merged, summary);
9682
+ out[out.length - 1] = merged;
9672
9683
  }
9673
9684
  }
9674
9685
  return out;
@@ -10811,13 +10822,15 @@ class AparteClient {
10811
10822
  };
10812
10823
  const registeredTools = this._toolsForCurrentModel();
10813
10824
  const buildRequest = async (requestMessages2) => {
10825
+ const historySummary = historySummaryOf(requestMessages2);
10826
+ const meta = historySummary === void 0 ? opts?.meta : { ...opts?.meta, historySummary };
10814
10827
  let built = {
10815
10828
  messages: requestMessages2,
10816
10829
  modelId,
10817
10830
  stream: true,
10818
10831
  tools: registeredTools.length ? registeredTools : void 0,
10819
10832
  ...opts?.temperature !== void 0 ? { temperature: opts.temperature } : {},
10820
- ...opts?.meta ? { _meta: opts.meta } : {}
10833
+ ...meta ? { _meta: meta } : {}
10821
10834
  };
10822
10835
  if (this.options.requestInterceptor) {
10823
10836
  built = await this.options.requestInterceptor(built, turn2);
@@ -11296,7 +11309,7 @@ class AparteClient {
11296
11309
  * `mergeAdjacentUserMessages` joins the two where the history is assembled.
11297
11310
  */
11298
11311
  _summaryMessage(summary) {
11299
- return summary === void 0 ? [] : [{ role: "user", content: underPreamble(summary) }];
11312
+ return summary === void 0 ? [] : [summaryMessage(summary)];
11300
11313
  }
11301
11314
  /** A message's tokens and metadata as a turn's `_meta`: a send and its retry say the same. */
11302
11315
  _turnMeta(asked2) {
@@ -12754,4 +12767,4 @@ export {
12754
12767
  chatIdOf as y,
12755
12768
  collectRendererStyles as z
12756
12769
  };
12757
- //# sourceMappingURL=defer-hydration-OFqdbk3O.js.map
12770
+ //# sourceMappingURL=defer-hydration-2oPv7cU0.js.map