@aparte/core 1.6.0 → 1.7.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.
Files changed (53) hide show
  1. package/dist/client/stream-adapter.d.ts +20 -0
  2. package/dist/client/stream-adapter.d.ts.map +1 -1
  3. package/dist/client/wire-history.d.ts +2 -0
  4. package/dist/client/wire-history.d.ts.map +1 -1
  5. package/dist/components/bubble/aparte-chat-bubble.d.ts +14 -0
  6. package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
  7. package/dist/components/conversation-list/aparte-conversation-list.d.ts +46 -22
  8. package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -1
  9. package/dist/components/viewport/aparte-chat-viewport.d.ts +5 -0
  10. package/dist/components/viewport/aparte-chat-viewport.d.ts.map +1 -1
  11. package/dist/config/aparte-config.d.ts +44 -1
  12. package/dist/config/aparte-config.d.ts.map +1 -1
  13. package/dist/config/bubble-shell-renderer.d.ts +3 -0
  14. package/dist/config/bubble-shell-renderer.d.ts.map +1 -1
  15. package/dist/config/index.d.ts +1 -1
  16. package/dist/config/index.d.ts.map +1 -1
  17. package/dist/custom-elements.json +721 -69
  18. package/dist/{defer-hydration-W4yhnyfc.js → defer-hydration-o5MFsc_Z.js} +423 -193
  19. package/dist/defer-hydration-o5MFsc_Z.js.map +1 -0
  20. package/dist/elicitation/panel.d.ts.map +1 -1
  21. package/dist/host/aparte-chat-host.d.ts +8 -0
  22. package/dist/host/aparte-chat-host.d.ts.map +1 -1
  23. package/dist/index.css +1 -1
  24. package/dist/index.d.ts +6 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +238 -179
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.node.d.ts +6 -2
  29. package/dist/index.node.d.ts.map +1 -1
  30. package/dist/index.node.js +52 -47
  31. package/dist/index.node.js.map +1 -1
  32. package/dist/kit-keyboard-BUSLQ5i4.js +434 -0
  33. package/dist/kit-keyboard-BUSLQ5i4.js.map +1 -0
  34. package/dist/renderers/segment-renderers.d.ts.map +1 -1
  35. package/dist/renderers/segments/activity.d.ts +5 -0
  36. package/dist/renderers/segments/activity.d.ts.map +1 -0
  37. package/dist/renderers/segments/tool-call.d.ts.map +1 -1
  38. package/dist/types/chat.d.ts +22 -0
  39. package/dist/types/chat.d.ts.map +1 -1
  40. package/dist/types/event-map.d.ts +4 -0
  41. package/dist/types/event-map.d.ts.map +1 -1
  42. package/dist/types/index.d.ts +2 -2
  43. package/dist/types/index.d.ts.map +1 -1
  44. package/dist/types/segments.d.ts +53 -1
  45. package/dist/types/segments.d.ts.map +1 -1
  46. package/dist/types/tools.d.ts +27 -1
  47. package/dist/types/tools.d.ts.map +1 -1
  48. package/dist/utils/menu.d.ts +90 -0
  49. package/dist/utils/menu.d.ts.map +1 -0
  50. package/dist/utils/tabs.d.ts +49 -0
  51. package/dist/utils/tabs.d.ts.map +1 -0
  52. package/package.json +2 -2
  53. package/dist/defer-hydration-W4yhnyfc.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
- import { L as deferHydrationOf, ah as resolveConfig, au as eventOrigin, av as activeElementIn, ap as subscribeConfigChange, ak as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, aw as gateGlide, P as escapeAttr, I as cssEscape, am as segmentTiming, ax as chatBoundaryOf, ay as relabelCodeLanguages, az as relabelCitations, aA as toolCallRenderer, aB as toolRendererThatDrew, t as aparteGlobalConfig, aC as isMountedRenderer, aD as renderingVersionOf, aE as onRenderersChange, aF as renderSourceList, aG as mergeSegmentUpdate, a2 as isSegmentSettled, a8 as pluralize, V as formatDuration, aH as toolNameOf, Q as escapeHtml, aI as writeStreamedMarkdown, aJ as replaceHighlighted, a1 as isSafeUrl, C as copyText, X as getSegmentRenderer, Z as installDefaultRenderersOnce, r as AparteMessageRepository, aK as CheckpointStateWatcher, aL as chatIdOf, aM as stampSegmentActivity, aN as stampSegmentOnInsert, aO as stampSegmentOnUpdate, aP as renumberSegments, aQ as openSegmentIds, aR as isTerminalStatus, aS as adoptMessageSegments, $ as isAwaitingReply, a9 as populateBubbleFromMessage, at as uuid, ai as revokeAttachmentUrls, a6 as parseMarkdownToSegments, aT as APARTE_DERIVED_SEGMENTS, aU as rememberConversationStatus, aV as tellConversationStatus, aW as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, a7 as placeFloating, aX as visibleReply, aY as usageTokens, q as AparteErrorCode, a3 as measureContext, aZ as rootOf, a_ as inRenderedContent, g as APARTE_HOST_ATTR, _ as installDialogTriggersOnce } from "./defer-hydration-W4yhnyfc.js";
2
- import { A, a, b, c, d, f, h, i, j, k, l, m, n, p, s, S, u, v, y, z, B, D, E, F, G, H, J, K, M, N, O, R, T, U, W, Y, a0, a4, a5, aa, ab, ac, ad, ae, af, ag, aj, al, an, ao, aq, ar, as } from "./defer-hydration-W4yhnyfc.js";
1
+ import { K as deferHydrationOf, ag as resolveConfig, ao as subscribeConfigChange, aj as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, at as gateGlide, O as escapeAttr, al as segmentTiming, au as chatBoundaryOf, av as relabelCodeLanguages, aw as relabelCitations, ax as toolCallRenderer, ay as activityRenderer, t as aparteGlobalConfig, az as isMountedRenderer, aA as renderingVersionOf, a3 as onRenderersChange, aB as renderSourceList, aC as mergeSegmentUpdate, a1 as isSegmentSettled, a7 as pluralize, U as formatDuration, aD as toolNameOf, P as escapeHtml, aE as writeStreamedMarkdown, aF as replaceHighlighted, a0 as isSafeUrl, C as copyText, W as getSegmentRenderer, Y as installDefaultRenderersOnce, aG as toolRendererThatDrew, aH as activityRendererThatDrew, r as AparteMessageRepository, aI as CheckpointStateWatcher, aJ as chatIdOf, aK as stampSegmentActivity, aL as stampSegmentOnInsert, aM as stampSegmentOnUpdate, aN as renumberSegments, aO as openSegmentIds, aP as isTerminalStatus, aQ as adoptMessageSegments, _ as isAwaitingReply, a8 as populateBubbleFromMessage, as as uuid, ah as revokeAttachmentUrls, a6 as parseMarkdownToSegments, aR as APARTE_DERIVED_SEGMENTS, aS as rememberConversationStatus, aT as tellConversationStatus, aU as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, aV as visibleReply, aW as usageTokens, q as AparteErrorCode, a2 as measureContext, aX as inRenderedContent, g as APARTE_HOST_ATTR, Z as installDialogTriggersOnce } from "./defer-hydration-o5MFsc_Z.js";
2
+ import { A, a, b, c, d, f, h, i, j, k, l, m, n, p, s, S, u, v, y, z, B, D, E, F, G, H, I, J, L, M, N, Q, R, T, V, X, $, a4, a5, a9, aa, ab, ac, ad, ae, af, ai, ak, am, an, ap, aq, ar } from "./defer-hydration-o5MFsc_Z.js";
3
+ import { d as eventOrigin, f as activeElementIn, c as cssEscape, a as enhanceMenu, e as enhanceContextMenu, p as placeFloating, r as rootOf } from "./kit-keyboard-BUSLQ5i4.js";
4
+ import { b as b2 } from "./kit-keyboard-BUSLQ5i4.js";
3
5
  function presenceOn(value) {
4
6
  return value === "" ? true : Boolean(value);
5
7
  }
@@ -1383,7 +1385,7 @@ function draw(root, content, token) {
1383
1385
  }
1384
1386
  function drawMessageTokens(root, content, tokens) {
1385
1387
  if (root.querySelector(".aparte-inline-token")) return;
1386
- for (const token of [...tokens].sort((a2, b2) => b2.start - a2.start)) {
1388
+ for (const token of [...tokens].sort((a2, b3) => b3.start - a2.start)) {
1387
1389
  if (token.text) draw(root, content, token);
1388
1390
  }
1389
1391
  }
@@ -1499,6 +1501,11 @@ function buildCheckpointSeparator(options) {
1499
1501
  }
1500
1502
  return root;
1501
1503
  }
1504
+ function innerRendererThatDrew(segment, el2) {
1505
+ if (segment.type === "tool_call") return toolRendererThatDrew(el2);
1506
+ if (segment.type === "activity") return activityRendererThatDrew(el2);
1507
+ return null;
1508
+ }
1502
1509
  let _warnedNoRenderer = false;
1503
1510
  function warnMissingRenderer(type) {
1504
1511
  if (_warnedNoRenderer) return;
@@ -1556,6 +1563,8 @@ class AparteChatBubble extends HTMLElement {
1556
1563
  _role = "assistant";
1557
1564
  _attachments = [];
1558
1565
  _usage = null;
1566
+ /** The step the agent is on while this reply waits: live only, never part of the message. */
1567
+ _step = null;
1559
1568
  _finishReason = null;
1560
1569
  /** The checkpoint this message carries: the separator above it is drawn from it. */
1561
1570
  _contextSummary = null;
@@ -1658,6 +1667,12 @@ class AparteChatBubble extends HTMLElement {
1658
1667
  if (!name || cfg.isToolHidden(name)) return null;
1659
1668
  return cfg.getToolRenderer(name) ?? null;
1660
1669
  }
1670
+ /** The tool or activity renderer in effect for a segment, when core's own renderer for its type is what draws it. */
1671
+ _innerRendererFor(segment) {
1672
+ if (segment.type !== "activity") return this._toolRendererFor(segment);
1673
+ if (resolveSegmentRenderer("activity", this._cfg) !== activityRenderer) return null;
1674
+ return this._cfg.getActivityRenderer(segment.activityType) ?? null;
1675
+ }
1661
1676
  /**
1662
1677
  * Record a segment as drawn, set it up, then read back which tool renderer is behind the
1663
1678
  * row (tool-call.ts records it as the row is set up — one record, not a second lookup).
@@ -1671,7 +1686,7 @@ class AparteChatBubble extends HTMLElement {
1671
1686
  this._drawn.set(segment.id, drawn);
1672
1687
  if (!this.isConnected) this._scheduleReleaseCheck();
1673
1688
  if (renderer?.setup) runWithConfig(this._cfg, () => renderer.setup(el2, drawnAs));
1674
- if (segment.type === "tool_call") drawn.tool = toolRendererThatDrew(el2);
1689
+ drawn.tool = innerRendererThatDrew(segment, el2);
1675
1690
  }
1676
1691
  /**
1677
1692
  * The segment as its renderer's `setup` sees it: one ADDED while the message streams is
@@ -1757,7 +1772,7 @@ class AparteChatBubble extends HTMLElement {
1757
1772
  }
1758
1773
  /** The renderer that drew this segment is still the one in effect (for a tool call, the tool renderer too). */
1759
1774
  _stillDrawnByCurrent(segment, drawn) {
1760
- return resolveSegmentRenderer(segment.type, this._cfg) === drawn.renderer && this._toolRendererFor(segment) === drawn.tool;
1775
+ return resolveSegmentRenderer(segment.type, this._cfg) === drawn.renderer && this._innerRendererFor(segment) === drawn.tool;
1761
1776
  }
1762
1777
  /**
1763
1778
  * A renderer registered, unregistered or overridden since these segments were drawn: draw
@@ -1788,7 +1803,7 @@ class AparteChatBubble extends HTMLElement {
1788
1803
  * as that renderer is still the one in effect.
1789
1804
  */
1790
1805
  _keepsItsDrawing(segment, drawn) {
1791
- const mounted = isMountedRenderer(drawn.renderer) || segment.type === "tool_call" && isMountedRenderer(drawn.tool);
1806
+ const mounted = isMountedRenderer(drawn.renderer) || isMountedRenderer(drawn.tool);
1792
1807
  return mounted && this._stillDrawnByCurrent(segment, drawn);
1793
1808
  }
1794
1809
  /**
@@ -2189,6 +2204,21 @@ class AparteChatBubble extends HTMLElement {
2189
2204
  this._usage = usage ?? null;
2190
2205
  this._updateActionBar();
2191
2206
  }
2207
+ /**
2208
+ * Say the step the agent is on ("Reading the parser") while this reply waits, or `null`
2209
+ * when it is on none. The client calls it as the run announces steps.
2210
+ *
2211
+ * Live only: the words show beside the waiting dots while the reply has nothing to show
2212
+ * (or between two calls), and are what a screen reader hears in place of "Typing". They
2213
+ * are never one of the message's segments, never saved and never sent to the model, and
2214
+ * they go with the reply's end even when nobody closed the step.
2215
+ */
2216
+ setStep(name) {
2217
+ const next = typeof name === "string" && name.trim() ? name.trim() : null;
2218
+ if (next === this._step) return;
2219
+ this._step = next;
2220
+ this._updateWaiting();
2221
+ }
2192
2222
  /**
2193
2223
  * Say why the model stopped writing this reply (assistant only).
2194
2224
  *
@@ -2582,7 +2612,7 @@ class AparteChatBubble extends HTMLElement {
2582
2612
  const now = this._segmentsEl ? rowOf(this._segmentsEl, segmentId) : null;
2583
2613
  if (now && now !== drawn.el) {
2584
2614
  drawn.el = now;
2585
- drawn.tool = segment.type === "tool_call" ? toolRendererThatDrew(now) : null;
2615
+ drawn.tool = innerRendererThatDrew(segment, now);
2586
2616
  }
2587
2617
  }
2588
2618
  } else {
@@ -2647,7 +2677,8 @@ class AparteChatBubble extends HTMLElement {
2647
2677
  <div class="aparte-content" dir="auto"></div>
2648
2678
  <div class="aparte-waiting" hidden>
2649
2679
  <span class="aparte-dots" aria-hidden="true"><span class="aparte-dot"></span><span class="aparte-dot"></span><span class="aparte-dot"></span></span>
2650
- <span class="aparte-sr-only"></span>
2680
+ <span class="aparte-waiting-step aparte-shimmer" aria-hidden="true" dir="auto" hidden></span>
2681
+ <span class="aparte-sr-only" aria-live="polite">${escapeHtml(this._cfg.getLocale().typing ?? "")}</span>
2651
2682
  </div>
2652
2683
  </div>
2653
2684
  <div class="aparte-footer">
@@ -2743,8 +2774,23 @@ class AparteChatBubble extends HTMLElement {
2743
2774
  const el2 = this.querySelector(".aparte-waiting");
2744
2775
  if (!el2) return;
2745
2776
  el2.hidden = !waiting;
2777
+ const step = waiting ? this._step : null;
2778
+ let words = el2.querySelector(".aparte-waiting-step");
2779
+ if (!words && step) {
2780
+ words = document.createElement("span");
2781
+ words.className = "aparte-waiting-step aparte-shimmer";
2782
+ words.setAttribute("aria-hidden", "true");
2783
+ words.dir = "auto";
2784
+ const dots = el2.querySelector(".aparte-dots");
2785
+ if (dots) dots.after(words);
2786
+ else el2.prepend(words);
2787
+ }
2788
+ if (words) {
2789
+ words.hidden = !step;
2790
+ if (step && words.textContent !== step) words.textContent = step;
2791
+ }
2746
2792
  if (!waiting) return;
2747
- const label = this._cfg.getLocale().typing;
2793
+ const label = step ?? this._cfg.getLocale().typing;
2748
2794
  const sr = el2.querySelector(".aparte-sr-only");
2749
2795
  if (sr && sr.textContent !== label) sr.textContent = label;
2750
2796
  }
@@ -3135,7 +3181,7 @@ class AparteChatBubble extends HTMLElement {
3135
3181
  * whether to offer the button at all.
3136
3182
  */
3137
3183
  _copyableText() {
3138
- return (this._content || this._segments.filter((s2) => s2.type !== "thinking").map((s2) => s2.content ?? "").join("\n")).trim();
3184
+ return (this._content || this._segments.filter((s2) => s2.type !== "thinking" && s2.type !== "activity").map((s2) => s2.content ?? "").join("\n")).trim();
3139
3185
  }
3140
3186
  /**
3141
3187
  * The copy button is for text. `hidden` rather than removed: the bar is rebuilt
@@ -3209,8 +3255,8 @@ class AparteChatBubble extends HTMLElement {
3209
3255
  _setRovingIndex() {
3210
3256
  const buttons = this._rovingButtons();
3211
3257
  if (!buttons.length) return;
3212
- const usable = buttons.filter((b2) => !b2.disabled);
3213
- const current = buttons.find((b2) => b2.tabIndex === 0 && !b2.disabled);
3258
+ const usable = buttons.filter((b3) => !b3.disabled);
3259
+ const current = buttons.find((b3) => b3.tabIndex === 0 && !b3.disabled);
3214
3260
  const stop = current ?? usable[0] ?? buttons[0];
3215
3261
  for (const button2 of buttons) button2.tabIndex = button2 === stop ? 0 : -1;
3216
3262
  }
@@ -3226,10 +3272,10 @@ class AparteChatBubble extends HTMLElement {
3226
3272
  const event = e;
3227
3273
  const keys = ["ArrowLeft", "ArrowRight", "Home", "End"];
3228
3274
  if (!keys.includes(event.key)) return;
3229
- const buttons = this._rovingButtons().filter((b2) => !b2.disabled);
3275
+ const buttons = this._rovingButtons().filter((b3) => !b3.disabled);
3230
3276
  if (buttons.length === 0) return;
3231
3277
  const active = document.activeElement;
3232
- const from = buttons.findIndex((b2) => b2 === active);
3278
+ const from = buttons.findIndex((b3) => b3 === active);
3233
3279
  if (from === -1 && event.key !== "Home" && event.key !== "End") return;
3234
3280
  const rtl = (this.closest("[dir]")?.getAttribute("dir") ?? document.documentElement.dir) === "rtl";
3235
3281
  const forward = rtl ? "ArrowLeft" : "ArrowRight";
@@ -3506,6 +3552,7 @@ class AparteChatBubble extends HTMLElement {
3506
3552
  _updateStreaming(streaming) {
3507
3553
  const wasStreaming = this._streaming;
3508
3554
  this._streaming = streaming;
3555
+ if (!streaming) this._step = null;
3509
3556
  const message = this.querySelector(".aparte-message");
3510
3557
  if (message) {
3511
3558
  message.setAttribute("data-streaming", String(streaming));
@@ -4148,11 +4195,11 @@ class AparteChatViewport extends HTMLElement {
4148
4195
  this._notifyBubble(messageId, "addSegment", stamped);
4149
4196
  this._autoScroll();
4150
4197
  }
4151
- updateSegment(a2, b2, c2) {
4152
- const clientForm = c2 === void 0 && typeof b2 === "object";
4198
+ updateSegment(a2, b3, c2) {
4199
+ const clientForm = c2 === void 0 && typeof b3 === "object";
4153
4200
  const messageId = clientForm ? this._activeMessageId() : a2;
4154
- const segmentId = clientForm ? a2 : b2;
4155
- const updates = clientForm ? b2 : c2;
4201
+ const segmentId = clientForm ? a2 : b3;
4202
+ const updates = clientForm ? b3 : c2;
4156
4203
  if (!messageId) return;
4157
4204
  const message = this._repo.getMessageById(messageId);
4158
4205
  if (!message?.segments) return;
@@ -4164,10 +4211,10 @@ class AparteChatViewport extends HTMLElement {
4164
4211
  this._notifyBubble(messageId, "updateSegment", { segmentId, updates: stamped });
4165
4212
  }
4166
4213
  }
4167
- removeSegment(a2, b2) {
4168
- const clientForm = b2 === void 0;
4214
+ removeSegment(a2, b3) {
4215
+ const clientForm = b3 === void 0;
4169
4216
  const messageId = clientForm ? this._activeMessageId() : a2;
4170
- const segmentId = clientForm ? a2 : b2;
4217
+ const segmentId = clientForm ? a2 : b3;
4171
4218
  if (!messageId || !segmentId) return;
4172
4219
  const message = this._repo.getMessageById(messageId);
4173
4220
  if (message?.segments) {
@@ -4204,6 +4251,13 @@ class AparteChatViewport extends HTMLElement {
4204
4251
  if (message) message.usage = usage;
4205
4252
  this._notifyBubble(messageId, "setUsage", usage);
4206
4253
  }
4254
+ /**
4255
+ * Say the step the agent is on ("Reading the parser") in the reply's waiting indicator,
4256
+ * or `null` for none. Live only: handed to the bubble, never written on the message.
4257
+ */
4258
+ setStep(messageId, name) {
4259
+ this._notifyBubble(messageId, "setStep", name);
4260
+ }
4207
4261
  // ─────────────────────────────────────────────────────────────────────────
4208
4262
  // Message Management
4209
4263
  // ─────────────────────────────────────────────────────────────────────────
@@ -4513,7 +4567,7 @@ class AparteChatViewport extends HTMLElement {
4513
4567
  if (!this._frameworkManagedDOM) {
4514
4568
  const wrapper = this.querySelector(".aparte-messages-wrapper");
4515
4569
  if (wrapper) {
4516
- Array.from(wrapper.querySelectorAll("aparte-chat-bubble")).forEach((b2) => b2.remove());
4570
+ Array.from(wrapper.querySelectorAll("aparte-chat-bubble")).forEach((b3) => b3.remove());
4517
4571
  }
4518
4572
  }
4519
4573
  this._setSpacerHeight(0);
@@ -4624,6 +4678,9 @@ class AparteChatViewport extends HTMLElement {
4624
4678
  case "setUsage":
4625
4679
  bubble.setUsage?.(payload);
4626
4680
  break;
4681
+ case "setStep":
4682
+ bubble.setStep?.(payload);
4683
+ break;
4627
4684
  case "update": {
4628
4685
  const updates = payload;
4629
4686
  const renderable = ["status", "segments", "content", "attachments", "usage", "finishReason", "contextSummary", "compaction"];
@@ -5263,7 +5320,7 @@ class AparteChatViewport extends HTMLElement {
5263
5320
  this._setSpacerHeight(0);
5264
5321
  return;
5265
5322
  }
5266
- const lastUserBubble = [...allBubbles].reverse().find((b2) => b2.getAttribute("data-role") === "user");
5323
+ const lastUserBubble = [...allBubbles].reverse().find((b3) => b3.getAttribute("data-role") === "user");
5267
5324
  if (!lastUserBubble) {
5268
5325
  this._setSpacerHeight(0);
5269
5326
  return;
@@ -7058,7 +7115,14 @@ const VIEWPORT_MARGIN = 8;
7058
7115
  class AparteConversationList extends HTMLElement {
7059
7116
  _conversations = [];
7060
7117
  _activeId = null;
7061
- _open = null;
7118
+ /**
7119
+ * What stops the menus of the rows on screen: one `enhanceMenu` per `⋯`, and the
7120
+ * context menu over the whole list. A render replaces the rows, so it releases them
7121
+ * all and wires the new ones.
7122
+ */
7123
+ _menus = [];
7124
+ /** The context menu's element: one for the list, filled for the row it was asked about. */
7125
+ _contextMenu = null;
7062
7126
  _renaming = null;
7063
7127
  _warnedNoManager = false;
7064
7128
  static get observedAttributes() {
@@ -7101,17 +7165,17 @@ class AparteConversationList extends HTMLElement {
7101
7165
  }
7102
7166
  this.addEventListener("click", this._onClick);
7103
7167
  this.addEventListener("keydown", this._onKeydown);
7104
- this.addEventListener("focusout", this._onFocusOut);
7168
+ this.addEventListener("aparte-menu-select", this._onMenuSelect);
7105
7169
  this.addEventListener("pointerdown", this._onPress);
7106
7170
  this._render();
7107
7171
  window.addEventListener("aparte-config-change", this._onConfigChange);
7108
7172
  window.addEventListener("aparte-conversation-status", this._onStatus);
7109
7173
  }
7110
7174
  disconnectedCallback() {
7111
- this._closeMenu();
7175
+ this._releaseMenus();
7112
7176
  this.removeEventListener("click", this._onClick);
7113
7177
  this.removeEventListener("keydown", this._onKeydown);
7114
- this.removeEventListener("focusout", this._onFocusOut);
7178
+ this.removeEventListener("aparte-menu-select", this._onMenuSelect);
7115
7179
  this.removeEventListener("pointerdown", this._onPress);
7116
7180
  window.removeEventListener("pointerup", this._onRelease, true);
7117
7181
  window.removeEventListener("pointercancel", this._onRelease, true);
@@ -7237,7 +7301,7 @@ class AparteConversationList extends HTMLElement {
7237
7301
  this._renderAfterPress = true;
7238
7302
  return;
7239
7303
  }
7240
- this._closeMenu();
7304
+ this._releaseMenus();
7241
7305
  this._renaming = null;
7242
7306
  const focused2 = activeElementIn(this);
7243
7307
  const held = focused2 && this.contains(focused2) ? focused2.closest("[data-select-id], [data-more-id]") : null;
@@ -7268,6 +7332,7 @@ class AparteConversationList extends HTMLElement {
7268
7332
  this.innerHTML = groups;
7269
7333
  }
7270
7334
  this._applyFilter();
7335
+ this._wireMenus();
7271
7336
  if (!restore) return;
7272
7337
  const back = this.querySelector(restore);
7273
7338
  if (back && visible(back)) {
@@ -7371,7 +7436,7 @@ class AparteConversationList extends HTMLElement {
7371
7436
  }
7372
7437
  }
7373
7438
  const fixed = ["pinned", "today", "yesterday", "week", "month"].map((k2) => buckets.get(k2)).filter((g) => !!g);
7374
- const months = [...buckets.keys()].filter((k2) => k2.startsWith("m-")).sort((a2, b2) => b2.localeCompare(a2)).map((k2) => buckets.get(k2));
7439
+ const months = [...buckets.keys()].filter((k2) => k2.startsWith("m-")).sort((a2, b3) => b3.localeCompare(a2)).map((k2) => buckets.get(k2));
7375
7440
  const undated = buckets.get("undated");
7376
7441
  return [...fixed, ...months, ...undated ? [undated] : []];
7377
7442
  }
@@ -7457,85 +7522,91 @@ class AparteConversationList extends HTMLElement {
7457
7522
  </div>
7458
7523
  </div>`;
7459
7524
  }
7460
- _openMenu(row, button2) {
7461
- this._closeMenu();
7462
- const id = row.dataset["convId"];
7463
- const conv = this._conversations.find((c2) => c2.id === id);
7464
- if (!conv) return;
7525
+ /** A row menu's element, empty: `_fillMenu` gives it its items as it opens. */
7526
+ _newMenu() {
7465
7527
  const menu = document.createElement("div");
7466
7528
  menu.className = "aparte-menu aparte-conv-menu";
7467
7529
  menu.setAttribute("role", "menu");
7530
+ return menu;
7531
+ }
7532
+ /**
7533
+ * Fills `menu` for the row's conversation and puts it in the row, as it opens; it leaves
7534
+ * the row when it closes, so a list with no menu open holds none. `enhanceMenu` places it
7535
+ * fixed to the window, because a sidebar scrolls and an absolute menu on the last rows
7536
+ * would be clipped by the list's own overflow. False — stay closed — when the
7537
+ * conversation is gone.
7538
+ */
7539
+ _fillMenu(row, menu) {
7540
+ const id = row.dataset["convId"];
7541
+ const conv = id ? this._conversations.find((c2) => c2.id === id) : void 0;
7542
+ if (!conv) return false;
7543
+ menu.dataset["menuFor"] = conv.id;
7544
+ menu.setAttribute("role", "menu");
7468
7545
  menu.setAttribute("aria-label", conv.title || this._t("newChat"));
7469
7546
  menu.innerHTML = this._menuMarkup(conv);
7470
7547
  row.appendChild(menu);
7471
- button2.setAttribute("aria-expanded", "true");
7472
- this._open = { id, row, button: button2, menu };
7473
- this._placeMenu(button2, menu);
7474
- menu.querySelector('[role="menuitem"]')?.focus();
7475
- document.addEventListener("pointerdown", this._onDocumentPointerDown, true);
7476
- document.addEventListener("pointerup", this._onDocumentPointerUp, true);
7477
- document.addEventListener("pointercancel", this._onDocumentPointerUp, true);
7478
- window.addEventListener("scroll", this._onWindowScroll, true);
7479
- window.addEventListener("resize", this._onWindowScroll);
7480
- }
7481
- /**
7482
- * Fixed, below the button's end edge, flipped above it when the viewport ends
7483
- * first. Fixed rather than absolute because a sidebar scrolls: an absolute menu on
7484
- * the last rows would be clipped by the list's own overflow. No anchoring library —
7485
- * the menu closes on any scroll or resize, which is what makes the arithmetic
7486
- * safe to do once.
7487
- */
7488
- _placeMenu(button2, menu) {
7489
- placeFloating(button2.getBoundingClientRect(), menu, {
7548
+ return true;
7549
+ }
7550
+ /**
7551
+ * The keyboard, the closing and the placing are `enhanceMenu`'s, the same code the kit
7552
+ * gives a host for its own menus: each row's `⋯` drives its own menu, and a right
7553
+ * click, Shift+F10 or the Menu key on a row opens one shared menu there
7554
+ * (`enhanceContextMenu`). Both fill as they open.
7555
+ */
7556
+ _wireMenus() {
7557
+ for (const button2 of this.querySelectorAll("[data-more-id]")) {
7558
+ const row = button2.closest("[data-conv-id]");
7559
+ if (!row) continue;
7560
+ const menu = this._newMenu();
7561
+ this._menus.push(enhanceMenu(button2, menu, {
7562
+ gap: MENU_GAP,
7563
+ margin: VIEWPORT_MARGIN,
7564
+ align: "end",
7565
+ onOpen: () => this._fillMenu(row, menu),
7566
+ onClose: () => menu.remove()
7567
+ }));
7568
+ }
7569
+ const context = this._contextMenu ??= this._newMenu();
7570
+ this._menus.push(enhanceContextMenu(this, context, {
7490
7571
  gap: MENU_GAP,
7491
7572
  margin: VIEWPORT_MARGIN,
7492
- align: "end",
7493
- rtl: getComputedStyle(this).direction === "rtl"
7573
+ onOpen: (target) => {
7574
+ const row = target.closest("[data-conv-id]");
7575
+ if (!row || !this.contains(row) || target.closest("[data-rename-id], [data-menu-for]")) return false;
7576
+ return this._fillMenu(row, context);
7577
+ },
7578
+ onClose: () => context.remove()
7579
+ }));
7580
+ }
7581
+ /** Closes whichever menu is open, without moving the focus, and stops them all. */
7582
+ _releaseMenus() {
7583
+ for (const release of this._menus.splice(0)) release();
7584
+ }
7585
+ /**
7586
+ * Placed again once the question has taken the items' place, since it is not their
7587
+ * size: the `⋯` menu against its button, the context menu on the corner it opened at.
7588
+ */
7589
+ _placeQuestion(menu, id) {
7590
+ const rtl = getComputedStyle(this).direction === "rtl";
7591
+ const button2 = menu === this._contextMenu ? null : this.querySelector(rowSelector("data-more-id", id));
7592
+ const box = menu.getBoundingClientRect();
7593
+ const corner = rtl ? box.right : box.left;
7594
+ placeFloating(button2?.getBoundingClientRect() ?? { top: box.top, bottom: box.top, left: corner, right: corner }, menu, {
7595
+ gap: button2 ? MENU_GAP : 0,
7596
+ margin: VIEWPORT_MARGIN,
7597
+ align: button2 ? "end" : "start",
7598
+ rtl
7494
7599
  });
7495
7600
  }
7496
- _closeMenu(returnFocus = false) {
7497
- const open = this._open;
7498
- if (!open) return;
7499
- this._open = null;
7500
- open.menu.remove();
7501
- open.button.setAttribute("aria-expanded", "false");
7502
- document.removeEventListener("pointerdown", this._onDocumentPointerDown, true);
7503
- document.removeEventListener("pointerup", this._onDocumentPointerUp, true);
7504
- document.removeEventListener("pointercancel", this._onDocumentPointerUp, true);
7505
- this._pressInMenu = false;
7506
- window.removeEventListener("scroll", this._onWindowScroll, true);
7507
- window.removeEventListener("resize", this._onWindowScroll);
7508
- if (returnFocus && open.button.isConnected) open.button.focus();
7509
- }
7510
- /**
7511
- * A pointer is down inside the open menu. WebKit does not move the focus to a
7512
- * button on mousedown: the element that held it is blurred instead — `focusout`
7513
- * with no `relatedTarget` — before the click reaches the item. `_onFocusOut` used
7514
- * to read that as the focus leaving the menu and close it on the press, so with a
7515
- * mouse no item could be chosen at all. Held from the press to its release.
7516
- */
7517
- _pressInMenu = false;
7518
- _onDocumentPointerUp = () => {
7519
- this._pressInMenu = false;
7520
- };
7521
- _onDocumentPointerDown = (e) => {
7522
- const open = this._open;
7523
- if (!open) return;
7524
- const target = eventOrigin(e);
7525
- this._pressInMenu = !!target && open.menu.contains(target);
7526
- if (open.menu.contains(target) || open.button.contains(target)) return;
7527
- this._closeMenu();
7528
- };
7529
- _onWindowScroll = () => {
7530
- this._closeMenu();
7531
- };
7532
- _onFocusOut = (e) => {
7533
- const open = this._open;
7534
- if (!open) return;
7535
- const next = e.relatedTarget;
7536
- if (!next && this._pressInMenu) return;
7537
- if (next && (open.menu.contains(next) || open.button.contains(next))) return;
7538
- if (open.menu.contains(e.target)) this._closeMenu();
7601
+ /**
7602
+ * An item chosen in a row's menu: `enhanceMenu` asks before it closes. Delete keeps it
7603
+ * open, since the question takes the items' place. The event stops here: the menu is
7604
+ * this element's own, and what the list tells the page is `aparte-conversation-*`.
7605
+ */
7606
+ _onMenuSelect = (e) => {
7607
+ if (e.target.dataset["menuFor"] === void 0) return;
7608
+ e.stopPropagation();
7609
+ if (e.detail.item.dataset["menuAction"] === "delete") e.preventDefault();
7539
7610
  };
7540
7611
  /**
7541
7612
  * The gesture, finished. The event has already gone out — cancelable, so a host
@@ -7567,26 +7638,25 @@ class AparteConversationList extends HTMLElement {
7567
7638
  console.warn("[aparte-conversation-list] the conversation manager refused the change:", err);
7568
7639
  });
7569
7640
  }
7570
- _onMenuAction(action2) {
7571
- const open = this._open;
7572
- if (!open) return;
7573
- const conv = this._conversations.find((c2) => c2.id === open.id);
7574
- if (!conv) {
7575
- this._closeMenu();
7576
- return;
7577
- }
7641
+ /**
7642
+ * What the item does, once the menu has done its part: by now it has closed and put the
7643
+ * focus back on the `⋯` (or the row) — except for delete, kept open to ask.
7644
+ */
7645
+ _onMenuAction(action2, menu) {
7646
+ const conv = this._conversations.find((c2) => c2.id === menu.dataset["menuFor"]);
7647
+ if (!conv) return;
7578
7648
  const id = conv.id;
7579
7649
  switch (action2) {
7580
- case "rename":
7581
- this._closeMenu();
7582
- this._startRename(open.row, conv);
7650
+ case "rename": {
7651
+ const row = this.querySelector(rowSelector("data-conv-id", id));
7652
+ if (row) this._startRename(row, conv);
7583
7653
  return;
7654
+ }
7584
7655
  // The two toggles dispatch each name as a LITERAL, in its own branch: the
7585
7656
  // manifest analyzer records a dispatch whose name is a ternary as an event
7586
7657
  // with no name (the Angular generator then crashes on it), and one whose
7587
7658
  // name is a local as an event called after the local.
7588
7659
  case "pin":
7589
- this._closeMenu(true);
7590
7660
  if (conv.pinnedAt) {
7591
7661
  const unpin = new CustomEvent(
7592
7662
  "aparte-conversation-unpin",
@@ -7604,7 +7674,6 @@ class AparteConversationList extends HTMLElement {
7604
7674
  }
7605
7675
  return;
7606
7676
  case "archive":
7607
- this._closeMenu(true);
7608
7677
  if (conv.archivedAt) {
7609
7678
  const unarchive = new CustomEvent(
7610
7679
  "aparte-conversation-unarchive",
@@ -7622,22 +7691,20 @@ class AparteConversationList extends HTMLElement {
7622
7691
  }
7623
7692
  return;
7624
7693
  case "delete": {
7625
- const previous = [...open.menu.childNodes];
7694
+ const previous = [...menu.childNodes];
7626
7695
  const holder = document.createElement("div");
7627
7696
  holder.innerHTML = this._confirmMarkup(conv);
7628
- open.menu.append(...holder.childNodes);
7629
- open.menu.setAttribute("role", "dialog");
7630
- open.menu.setAttribute("aria-label", this._confirmQuestion(conv));
7631
- open.menu.querySelector('[data-menu-action="cancel"]')?.focus();
7697
+ menu.append(...holder.childNodes);
7698
+ menu.setAttribute("role", "dialog");
7699
+ menu.setAttribute("aria-label", this._confirmQuestion(conv));
7700
+ menu.querySelector('[data-menu-action="cancel"]')?.focus();
7632
7701
  for (const node of previous) node.remove();
7633
- this._placeMenu(open.button, open.menu);
7702
+ this._placeQuestion(menu, id);
7634
7703
  return;
7635
7704
  }
7636
7705
  case "cancel":
7637
- this._closeMenu(true);
7638
7706
  return;
7639
7707
  case "confirm-delete": {
7640
- this._closeMenu(true);
7641
7708
  const remove = new CustomEvent(
7642
7709
  "aparte-conversation-delete",
7643
7710
  { detail: { id }, bubbles: true, composed: true, cancelable: true }
@@ -7648,27 +7715,20 @@ class AparteConversationList extends HTMLElement {
7648
7715
  }
7649
7716
  }
7650
7717
  }
7651
- _menuFocusables() {
7652
- const open = this._open;
7653
- if (!open) return [];
7654
- return Array.from(open.menu.querySelectorAll('[role="menuitem"], [data-menu-action]'));
7655
- }
7656
- _onMenuKeydown(e) {
7657
- const items = this._menuFocusables();
7658
- const index = items.indexOf(activeElementIn(this));
7718
+ /**
7719
+ * The delete question's own keys: the arrows, Home and End between its two answers.
7720
+ * A menu holds no item while it asks, so the menu's own arrows have nothing to move
7721
+ * to; Escape and Tab are still the menu's, and close it.
7722
+ */
7723
+ _onQuestionKeydown(e, menu) {
7724
+ if (e.defaultPrevented) return;
7725
+ const answers = Array.from(menu.querySelectorAll("[data-menu-action]"));
7726
+ const index = answers.indexOf(activeElementIn(this));
7659
7727
  const focusAt = (i2) => {
7660
7728
  e.preventDefault();
7661
- items[(i2 + items.length) % items.length]?.focus();
7729
+ answers[(i2 + answers.length) % answers.length]?.focus();
7662
7730
  };
7663
7731
  switch (e.key) {
7664
- case "Escape":
7665
- e.preventDefault();
7666
- this._closeMenu(true);
7667
- return;
7668
- case "Tab":
7669
- e.preventDefault();
7670
- this._closeMenu(true);
7671
- return;
7672
7732
  case "ArrowDown":
7673
7733
  focusAt(index + 1);
7674
7734
  return;
@@ -7679,7 +7739,7 @@ class AparteConversationList extends HTMLElement {
7679
7739
  focusAt(0);
7680
7740
  return;
7681
7741
  case "End":
7682
- focusAt(items.length - 1);
7742
+ focusAt(answers.length - 1);
7683
7743
  return;
7684
7744
  }
7685
7745
  }
@@ -7736,25 +7796,19 @@ class AparteConversationList extends HTMLElement {
7736
7796
  _onClick = (e) => {
7737
7797
  const target = e.target;
7738
7798
  const menuAction = target.closest("[data-menu-action]");
7739
- if (menuAction && this._open?.menu.contains(menuAction)) {
7799
+ const menu = menuAction?.closest("[data-menu-for]");
7800
+ if (menuAction && menu) {
7740
7801
  e.stopPropagation();
7741
- this._onMenuAction(menuAction.dataset["menuAction"]);
7802
+ this._onMenuAction(menuAction.dataset["menuAction"], menu);
7742
7803
  return;
7743
7804
  }
7744
- const more = target.closest("[data-more-id]");
7745
- if (more) {
7805
+ if (target.closest("[data-more-id]")) {
7746
7806
  e.stopPropagation();
7747
- if (this._open?.button === more) {
7748
- this._closeMenu(true);
7749
- } else {
7750
- this._openMenu(more.closest("[data-conv-id]"), more);
7751
- }
7752
7807
  return;
7753
7808
  }
7754
7809
  if (target.closest("[data-rename-id]")) return;
7755
7810
  const select = target.closest("[data-select-id]");
7756
7811
  if (select) {
7757
- this._closeMenu();
7758
7812
  const targetId = this.getAttribute("target");
7759
7813
  this.dispatchEvent(new CustomEvent(
7760
7814
  "aparte-conversation-select",
@@ -7764,8 +7818,9 @@ class AparteConversationList extends HTMLElement {
7764
7818
  };
7765
7819
  _onKeydown = (e) => {
7766
7820
  const target = e.target;
7767
- if (this._open?.menu.contains(target)) {
7768
- this._onMenuKeydown(e);
7821
+ const menu = target.closest("[data-menu-for]");
7822
+ if (menu) {
7823
+ if (menu.getAttribute("role") === "dialog") this._onQuestionKeydown(e, menu);
7769
7824
  return;
7770
7825
  }
7771
7826
  if (target.matches("[data-rename-id]")) {
@@ -8917,7 +8972,7 @@ class AparteScrollRail extends HTMLElement {
8917
8972
  /** The bubbles that get a tick, from all of them. */
8918
8973
  _bubbles(all = this._messages()) {
8919
8974
  const every = this.getAttribute("every") === "message" ? "message" : "user";
8920
- return every === "message" ? all : all.filter((b2) => b2.getAttribute("data-role") === "user");
8975
+ return every === "message" ? all : all.filter((b3) => b3.getAttribute("data-role") === "user");
8921
8976
  }
8922
8977
  // ─── Rendering ────────────────────────────────────────────────────────
8923
8978
  /** The first words of a message, for the tick's name. An excerpt, never a summary. */
@@ -8975,7 +9030,7 @@ class AparteScrollRail extends HTMLElement {
8975
9030
  const id = item.firstElementChild instanceof HTMLElement ? item.firstElementChild.dataset["messageId"] : void 0;
8976
9031
  if (id) existing.set(id, item);
8977
9032
  }
8978
- const known = new Set(bubbles.map((b2) => b2.getAttribute("message-id")));
9033
+ const known = new Set(bubbles.map((b3) => b3.getAttribute("message-id")));
8979
9034
  for (const [id, item] of existing) {
8980
9035
  if (known.has(id)) continue;
8981
9036
  item.remove();
@@ -9388,9 +9443,9 @@ function isBubble(node) {
9388
9443
  function holdsBubbles(nodes) {
9389
9444
  return Array.from(nodes).some((n2) => n2 instanceof Element && (isBubble(n2) || n2.localName === "aparte-chat-viewport" || n2.querySelector("aparte-chat-bubble") !== null));
9390
9445
  }
9391
- function sameElements(a2, b2) {
9392
- if (a2.length !== b2.length) return false;
9393
- for (let i2 = 0; i2 < a2.length; i2++) if (a2[i2] !== b2[i2]) return false;
9446
+ function sameElements(a2, b3) {
9447
+ if (a2.length !== b3.length) return false;
9448
+ for (let i2 = 0; i2 < a2.length; i2++) if (a2[i2] !== b3[i2]) return false;
9394
9449
  return true;
9395
9450
  }
9396
9451
  deferHydrationOf(AparteScrollRail);
@@ -11353,54 +11408,58 @@ export {
11353
11408
  G as createSegmentList,
11354
11409
  H as createStreamAdapter,
11355
11410
  cssEscape,
11356
- J as declineDefaultRenderers,
11357
- K as defaultSanitizer,
11411
+ I as declineDefaultRenderers,
11412
+ J as defaultSanitizer,
11358
11413
  deferHydrationOf,
11359
- M as defineMountedSegmentRenderer,
11360
- N as defineMountedToolRenderer,
11361
- O as detachConfig,
11414
+ L as defineMountedSegmentRenderer,
11415
+ M as defineMountedToolRenderer,
11416
+ N as detachConfig,
11417
+ enhanceContextMenu,
11418
+ enhanceMenu,
11419
+ b2 as enhanceTabs,
11362
11420
  escapeAttr,
11363
11421
  escapeHtml,
11364
- R as estimateTokens,
11365
- T as estimateWireTokens,
11366
- U as filesToAttachments,
11422
+ Q as estimateTokens,
11423
+ R as estimateWireTokens,
11424
+ T as filesToAttachments,
11367
11425
  formatDuration,
11368
- W as getAllRenderers,
11426
+ V as getAllRenderers,
11369
11427
  getSegmentRenderer,
11370
- Y as historyFromCheckpoint,
11428
+ X as historyFromCheckpoint,
11371
11429
  installDefaultRenderersOnce,
11372
11430
  installDialogTriggersOnce,
11373
11431
  isAwaitingReply,
11374
- a0 as isFormatAdapter,
11432
+ $ as isFormatAdapter,
11375
11433
  isSafeUrl,
11376
11434
  isSegmentSettled,
11377
11435
  measureContext,
11436
+ onRenderersChange,
11378
11437
  a4 as overrideSegmentRenderer,
11379
11438
  a5 as parseAparteEventStream,
11380
11439
  parseMarkdownToSegments,
11381
11440
  placeFloating,
11382
11441
  pluralize,
11383
11442
  populateBubbleFromMessage,
11384
- aa as readableToAsyncIterable,
11443
+ a9 as readableToAsyncIterable,
11385
11444
  registerAllComponents,
11386
- ab as registerDefaultRenderers,
11387
- ac as registerSegmentRenderer,
11388
- ad as releaseDeferredHydration,
11389
- ae as renderCitations,
11390
- af as renderCodeLanguages,
11391
- ag as requestUserInput,
11445
+ aa as registerDefaultRenderers,
11446
+ ab as registerSegmentRenderer,
11447
+ ac as releaseDeferredHydration,
11448
+ ad as renderCitations,
11449
+ ae as renderCodeLanguages,
11450
+ af as requestUserInput,
11392
11451
  resolveConfig,
11393
11452
  revokeAttachmentUrls,
11394
- aj as runSubAgent,
11453
+ ai as runSubAgent,
11395
11454
  runWithConfig,
11396
- al as segmentDuration,
11455
+ ak as segmentDuration,
11397
11456
  segmentTiming,
11398
- an as setupSuggestionBlocks,
11399
- ao as startSubAgent,
11457
+ am as setupSuggestionBlocks,
11458
+ an as startSubAgent,
11400
11459
  subscribeConfigChange,
11401
- aq as toToolCallView,
11402
- ar as toolRefusal,
11403
- as as unregisterSegmentRenderer,
11460
+ ap as toToolCallView,
11461
+ aq as toolRefusal,
11462
+ ar as unregisterSegmentRenderer,
11404
11463
  uuid
11405
11464
  };
11406
11465
  //# sourceMappingURL=index.js.map