@aparte/core 1.5.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 (63) hide show
  1. package/dist/client/agent-runner.d.ts.map +1 -1
  2. package/dist/client/aparte-client.d.ts +6 -0
  3. package/dist/client/aparte-client.d.ts.map +1 -1
  4. package/dist/client/stream-adapter.d.ts +72 -2
  5. package/dist/client/stream-adapter.d.ts.map +1 -1
  6. package/dist/client/wire-history.d.ts +5 -2
  7. package/dist/client/wire-history.d.ts.map +1 -1
  8. package/dist/components/bubble/aparte-chat-bubble.d.ts +15 -1
  9. package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
  10. package/dist/components/conversation-list/aparte-conversation-list.d.ts +46 -22
  11. package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -1
  12. package/dist/components/viewport/aparte-chat-viewport.d.ts +10 -0
  13. package/dist/components/viewport/aparte-chat-viewport.d.ts.map +1 -1
  14. package/dist/config/aparte-config.d.ts +112 -4
  15. package/dist/config/aparte-config.d.ts.map +1 -1
  16. package/dist/config/bubble-shell-renderer.d.ts +3 -0
  17. package/dist/config/bubble-shell-renderer.d.ts.map +1 -1
  18. package/dist/config/index.d.ts +1 -1
  19. package/dist/config/index.d.ts.map +1 -1
  20. package/dist/config/locale.d.ts +9 -0
  21. package/dist/config/locale.d.ts.map +1 -1
  22. package/dist/custom-elements.json +1233 -77
  23. package/dist/{defer-hydration-lK-7XQXf.js → defer-hydration-o5MFsc_Z.js} +730 -237
  24. package/dist/defer-hydration-o5MFsc_Z.js.map +1 -0
  25. package/dist/elicitation/panel.d.ts.map +1 -1
  26. package/dist/host/aparte-chat-host.d.ts +8 -0
  27. package/dist/host/aparte-chat-host.d.ts.map +1 -1
  28. package/dist/index.css +1 -1
  29. package/dist/index.d.ts +11 -3
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +278 -211
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.node.d.ts +11 -3
  34. package/dist/index.node.d.ts.map +1 -1
  35. package/dist/index.node.js +46 -36
  36. package/dist/index.node.js.map +1 -1
  37. package/dist/kit-keyboard-BUSLQ5i4.js +434 -0
  38. package/dist/kit-keyboard-BUSLQ5i4.js.map +1 -0
  39. package/dist/renderers/segment-renderers.d.ts.map +1 -1
  40. package/dist/renderers/segments/activity.d.ts +5 -0
  41. package/dist/renderers/segments/activity.d.ts.map +1 -0
  42. package/dist/renderers/segments/tool-call.d.ts.map +1 -1
  43. package/dist/transport/agent-handler.d.ts.map +1 -1
  44. package/dist/types/chat.d.ts +22 -0
  45. package/dist/types/chat.d.ts.map +1 -1
  46. package/dist/types/event-map.d.ts +4 -0
  47. package/dist/types/event-map.d.ts.map +1 -1
  48. package/dist/types/index.d.ts +2 -2
  49. package/dist/types/index.d.ts.map +1 -1
  50. package/dist/types/segments.d.ts +53 -1
  51. package/dist/types/segments.d.ts.map +1 -1
  52. package/dist/types/tools.d.ts +67 -1
  53. package/dist/types/tools.d.ts.map +1 -1
  54. package/dist/utils/menu.d.ts +90 -0
  55. package/dist/utils/menu.d.ts.map +1 -0
  56. package/dist/utils/segment-list.d.ts +49 -0
  57. package/dist/utils/segment-list.d.ts.map +1 -0
  58. package/dist/utils/tabs.d.ts +49 -0
  59. package/dist/utils/tabs.d.ts.map +1 -0
  60. package/dist/utils/tool-line.d.ts +36 -9
  61. package/dist/utils/tool-line.d.ts.map +1 -1
  62. package/package.json +2 -2
  63. package/dist/defer-hydration-lK-7XQXf.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
- import { K as deferHydrationOf, ae as resolveConfig, ap as eventOrigin, aq as activeElementIn, ak as subscribeConfigChange, ag as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, ar as gateGlide, O as escapeAttr, H as cssEscape, ai as segmentTiming, as as chatBoundaryOf, at as relabelCodeLanguages, au as relabelCitations, av as toolCallRenderer, aw as toolRendererThatDrew, t as aparteGlobalConfig, ax as isMountedRenderer, ay as renderingVersionOf, az as onRenderersChange, aA as renderSourceList, aB as mergeSegmentUpdate, a0 as isSegmentSettled, aC as formatDuration, P as escapeHtml, aD as writeStreamedMarkdown, aE as replaceHighlighted, $ as isSafeUrl, C as copyText, V as getSegmentRenderer, X as installDefaultRenderersOnce, r as AparteMessageRepository, aF as CheckpointStateWatcher, aG as chatIdOf, aH as stampSegmentActivity, aI as stampSegmentOnInsert, aJ as stampSegmentOnUpdate, aK as renumberSegments, aL as openSegmentIds, aM as isTerminalStatus, aN as adoptMessageSegments, Z as isAwaitingReply, a6 as populateBubbleFromMessage, ao as uuid, af as revokeAttachmentUrls, a4 as parseMarkdownToSegments, aO as APARTE_DERIVED_SEGMENTS, aP as rememberConversationStatus, aQ as tellConversationStatus, aR as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, a5 as placeFloating, aS as visibleReply, aT as usageTokens, q as AparteErrorCode, a1 as measureContext, aU as rootOf, aV as inRenderedContent, g as APARTE_HOST_ATTR, Y as installDialogTriggersOnce } from "./defer-hydration-lK-7XQXf.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, I, J, L, M, N, Q, R, T, U, W, _, a2, a3, a7, a8, a9, aa, ab, ac, ad, ah, aj, al, am, an } from "./defer-hydration-lK-7XQXf.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
  }
@@ -1314,17 +1316,6 @@ deferHydrationOf(AparteChat);
1314
1316
  if (!customElements.get("aparte-chat")) {
1315
1317
  customElements.define("aparte-chat", AparteChat);
1316
1318
  }
1317
- function pluralize(forms, n2, tag) {
1318
- let category = "other";
1319
- try {
1320
- category = new Intl.PluralRules(tag).select(n2);
1321
- } catch {
1322
- }
1323
- const options = forms.split("|");
1324
- const named = (name) => options.find((form2) => form2.startsWith(`${name}:`));
1325
- const form = named(category) ?? named("other") ?? forms;
1326
- return form.slice(form.indexOf(":") + 1).replace("{n}", String(n2));
1327
- }
1328
1319
  function planTurns(items, roleOf) {
1329
1320
  const runs = [];
1330
1321
  let from = -1;
@@ -1394,7 +1385,7 @@ function draw(root, content, token) {
1394
1385
  }
1395
1386
  function drawMessageTokens(root, content, tokens) {
1396
1387
  if (root.querySelector(".aparte-inline-token")) return;
1397
- for (const token of [...tokens].sort((a4, b2) => b2.start - a4.start)) {
1388
+ for (const token of [...tokens].sort((a2, b3) => b3.start - a2.start)) {
1398
1389
  if (token.text) draw(root, content, token);
1399
1390
  }
1400
1391
  }
@@ -1510,6 +1501,11 @@ function buildCheckpointSeparator(options) {
1510
1501
  }
1511
1502
  return root;
1512
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
+ }
1513
1509
  let _warnedNoRenderer = false;
1514
1510
  function warnMissingRenderer(type) {
1515
1511
  if (_warnedNoRenderer) return;
@@ -1567,6 +1563,8 @@ class AparteChatBubble extends HTMLElement {
1567
1563
  _role = "assistant";
1568
1564
  _attachments = [];
1569
1565
  _usage = null;
1566
+ /** The step the agent is on while this reply waits: live only, never part of the message. */
1567
+ _step = null;
1570
1568
  _finishReason = null;
1571
1569
  /** The checkpoint this message carries: the separator above it is drawn from it. */
1572
1570
  _contextSummary = null;
@@ -1669,6 +1667,12 @@ class AparteChatBubble extends HTMLElement {
1669
1667
  if (!name || cfg.isToolHidden(name)) return null;
1670
1668
  return cfg.getToolRenderer(name) ?? null;
1671
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
+ }
1672
1676
  /**
1673
1677
  * Record a segment as drawn, set it up, then read back which tool renderer is behind the
1674
1678
  * row (tool-call.ts records it as the row is set up — one record, not a second lookup).
@@ -1682,7 +1686,7 @@ class AparteChatBubble extends HTMLElement {
1682
1686
  this._drawn.set(segment.id, drawn);
1683
1687
  if (!this.isConnected) this._scheduleReleaseCheck();
1684
1688
  if (renderer?.setup) runWithConfig(this._cfg, () => renderer.setup(el2, drawnAs));
1685
- if (segment.type === "tool_call") drawn.tool = toolRendererThatDrew(el2);
1689
+ drawn.tool = innerRendererThatDrew(segment, el2);
1686
1690
  }
1687
1691
  /**
1688
1692
  * The segment as its renderer's `setup` sees it: one ADDED while the message streams is
@@ -1768,7 +1772,7 @@ class AparteChatBubble extends HTMLElement {
1768
1772
  }
1769
1773
  /** The renderer that drew this segment is still the one in effect (for a tool call, the tool renderer too). */
1770
1774
  _stillDrawnByCurrent(segment, drawn) {
1771
- 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;
1772
1776
  }
1773
1777
  /**
1774
1778
  * A renderer registered, unregistered or overridden since these segments were drawn: draw
@@ -1799,7 +1803,7 @@ class AparteChatBubble extends HTMLElement {
1799
1803
  * as that renderer is still the one in effect.
1800
1804
  */
1801
1805
  _keepsItsDrawing(segment, drawn) {
1802
- const mounted = isMountedRenderer(drawn.renderer) || segment.type === "tool_call" && isMountedRenderer(drawn.tool);
1806
+ const mounted = isMountedRenderer(drawn.renderer) || isMountedRenderer(drawn.tool);
1803
1807
  return mounted && this._stillDrawnByCurrent(segment, drawn);
1804
1808
  }
1805
1809
  /**
@@ -2200,6 +2204,21 @@ class AparteChatBubble extends HTMLElement {
2200
2204
  this._usage = usage ?? null;
2201
2205
  this._updateActionBar();
2202
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
+ }
2203
2222
  /**
2204
2223
  * Say why the model stopped writing this reply (assistant only).
2205
2224
  *
@@ -2566,16 +2585,9 @@ class AparteChatBubble extends HTMLElement {
2566
2585
  }
2567
2586
  return tools ? cfg.t("turnUsed").replace("{tools}", () => tools) : cfg.t("thought");
2568
2587
  }
2569
- /** What a call goes by on screen: the label the app gave it, else its identifier. */
2588
+ /** What a call goes by on screen — the name its row shows, through the same function. */
2570
2589
  _stepName(call) {
2571
- const name = call.toolCall?.name ?? "";
2572
- const label = this._cfg.getToolDisplay(name)?.label;
2573
- if (typeof label !== "function") return label ?? name;
2574
- try {
2575
- return label(call);
2576
- } catch {
2577
- return name;
2578
- }
2590
+ return toolNameOf(call, this._cfg).text;
2579
2591
  }
2580
2592
  _applySegmentUpdate(segmentId, segment, updates) {
2581
2593
  const el2 = this._segmentsEl ? rowOf(this._segmentsEl, segmentId) : null;
@@ -2600,7 +2612,7 @@ class AparteChatBubble extends HTMLElement {
2600
2612
  const now = this._segmentsEl ? rowOf(this._segmentsEl, segmentId) : null;
2601
2613
  if (now && now !== drawn.el) {
2602
2614
  drawn.el = now;
2603
- drawn.tool = segment.type === "tool_call" ? toolRendererThatDrew(now) : null;
2615
+ drawn.tool = innerRendererThatDrew(segment, now);
2604
2616
  }
2605
2617
  }
2606
2618
  } else {
@@ -2665,7 +2677,8 @@ class AparteChatBubble extends HTMLElement {
2665
2677
  <div class="aparte-content" dir="auto"></div>
2666
2678
  <div class="aparte-waiting" hidden>
2667
2679
  <span class="aparte-dots" aria-hidden="true"><span class="aparte-dot"></span><span class="aparte-dot"></span><span class="aparte-dot"></span></span>
2668
- <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>
2669
2682
  </div>
2670
2683
  </div>
2671
2684
  <div class="aparte-footer">
@@ -2761,8 +2774,23 @@ class AparteChatBubble extends HTMLElement {
2761
2774
  const el2 = this.querySelector(".aparte-waiting");
2762
2775
  if (!el2) return;
2763
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
+ }
2764
2792
  if (!waiting) return;
2765
- const label = this._cfg.getLocale().typing;
2793
+ const label = step ?? this._cfg.getLocale().typing;
2766
2794
  const sr = el2.querySelector(".aparte-sr-only");
2767
2795
  if (sr && sr.textContent !== label) sr.textContent = label;
2768
2796
  }
@@ -2972,19 +3000,19 @@ class AparteChatBubble extends HTMLElement {
2972
3000
  const customAttachment = this._cfg.getAttachmentRenderer?.();
2973
3001
  if (customAttachment) {
2974
3002
  this._attachmentsEl.replaceChildren();
2975
- for (const a4 of this._attachments) {
2976
- const el2 = segmentRenderResultToElement(runWithConfig(this._cfg, () => customAttachment(a4)));
3003
+ for (const a2 of this._attachments) {
3004
+ const el2 = segmentRenderResultToElement(runWithConfig(this._cfg, () => customAttachment(a2)));
2977
3005
  if (el2) this._attachmentsEl.appendChild(el2);
2978
3006
  }
2979
3007
  return;
2980
3008
  }
2981
- this._attachmentsEl.innerHTML = this._attachments.map((a4) => {
2982
- const name = escapeHtml(a4.name);
2983
- if (a4.type.startsWith("image/") && this._isShowableUrl(a4.url)) {
2984
- return `<div class="aparte-thumbnail aparte-thumb aparte-thumb--image" title="${name}" data-type="${escapeHtml(a4.type)}"><img class="aparte-thumbnail__image" src="${escapeHtml(a4.url)}" alt="${name}" loading="lazy" /><span class="aparte-thumb__name">${name}</span></div>`;
3009
+ this._attachmentsEl.innerHTML = this._attachments.map((a2) => {
3010
+ const name = escapeHtml(a2.name);
3011
+ if (a2.type.startsWith("image/") && this._isShowableUrl(a2.url)) {
3012
+ return `<div class="aparte-thumbnail aparte-thumb aparte-thumb--image" title="${name}" data-type="${escapeHtml(a2.type)}"><img class="aparte-thumbnail__image" src="${escapeHtml(a2.url)}" alt="${name}" loading="lazy" /><span class="aparte-thumb__name">${name}</span></div>`;
2985
3013
  }
2986
- const openable = this._isOpenableUrl(a4.url) ? ` data-url="${escapeHtml(a4.url)}"` : "";
2987
- return `<div class="aparte-thumbnail aparte-thumb aparte-thumb--file" title="${name}" data-type="${escapeHtml(a4.type)}"${openable}><span class="aparte-thumbnail__label">${escapeHtml(this._fileExt(a4.name))}</span><span class="aparte-thumb__name">${name}</span></div>`;
3014
+ const openable = this._isOpenableUrl(a2.url) ? ` data-url="${escapeHtml(a2.url)}"` : "";
3015
+ return `<div class="aparte-thumbnail aparte-thumb aparte-thumb--file" title="${name}" data-type="${escapeHtml(a2.type)}"${openable}><span class="aparte-thumbnail__label">${escapeHtml(this._fileExt(a2.name))}</span><span class="aparte-thumb__name">${name}</span></div>`;
2988
3016
  }).join("");
2989
3017
  const { attachmentPreview, filePreview } = this._cfg.getHostHandlers();
2990
3018
  const kinds = [attachmentPreview ? ".aparte-thumb--image" : "", filePreview ? ".aparte-thumb--file[data-url]" : ""].filter(Boolean);
@@ -3153,7 +3181,7 @@ class AparteChatBubble extends HTMLElement {
3153
3181
  * whether to offer the button at all.
3154
3182
  */
3155
3183
  _copyableText() {
3156
- 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();
3157
3185
  }
3158
3186
  /**
3159
3187
  * The copy button is for text. `hidden` rather than removed: the bar is rebuilt
@@ -3176,14 +3204,14 @@ class AparteChatBubble extends HTMLElement {
3176
3204
  const buttons = [];
3177
3205
  if (this._role === "user") {
3178
3206
  if (config.user) {
3179
- for (const a4 of config.user) buttons.push(this._actionButtonHtml(a4, icons, locale));
3207
+ for (const a2 of config.user) buttons.push(this._actionButtonHtml(a2, icons, locale));
3180
3208
  } else {
3181
3209
  if (config.copy) buttons.push(this._actionButtonHtml("copy", icons, locale));
3182
3210
  if (config.edit) buttons.push(this._actionButtonHtml("edit", icons, locale));
3183
3211
  }
3184
3212
  } else if (this._role === "assistant") {
3185
3213
  if (config.assistant) {
3186
- for (const a4 of config.assistant) buttons.push(this._actionButtonHtml(a4, icons, locale));
3214
+ for (const a2 of config.assistant) buttons.push(this._actionButtonHtml(a2, icons, locale));
3187
3215
  } else {
3188
3216
  if (config.copy) buttons.push(this._actionButtonHtml("copy", icons, locale));
3189
3217
  if (config.retry) buttons.push(this._actionButtonHtml("retry", icons, locale));
@@ -3227,8 +3255,8 @@ class AparteChatBubble extends HTMLElement {
3227
3255
  _setRovingIndex() {
3228
3256
  const buttons = this._rovingButtons();
3229
3257
  if (!buttons.length) return;
3230
- const usable = buttons.filter((b2) => !b2.disabled);
3231
- 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);
3232
3260
  const stop = current ?? usable[0] ?? buttons[0];
3233
3261
  for (const button2 of buttons) button2.tabIndex = button2 === stop ? 0 : -1;
3234
3262
  }
@@ -3244,10 +3272,10 @@ class AparteChatBubble extends HTMLElement {
3244
3272
  const event = e;
3245
3273
  const keys = ["ArrowLeft", "ArrowRight", "Home", "End"];
3246
3274
  if (!keys.includes(event.key)) return;
3247
- const buttons = this._rovingButtons().filter((b2) => !b2.disabled);
3275
+ const buttons = this._rovingButtons().filter((b3) => !b3.disabled);
3248
3276
  if (buttons.length === 0) return;
3249
3277
  const active = document.activeElement;
3250
- const from = buttons.findIndex((b2) => b2 === active);
3278
+ const from = buttons.findIndex((b3) => b3 === active);
3251
3279
  if (from === -1 && event.key !== "Home" && event.key !== "End") return;
3252
3280
  const rtl = (this.closest("[dir]")?.getAttribute("dir") ?? document.documentElement.dir) === "rtl";
3253
3281
  const forward = rtl ? "ArrowLeft" : "ArrowRight";
@@ -3279,16 +3307,16 @@ class AparteChatBubble extends HTMLElement {
3279
3307
  /** Append the registered custom action buttons for this bubble's role. */
3280
3308
  _appendCustomActions() {
3281
3309
  if (!this._actionBarEl) return;
3282
- for (const a4 of this._cfg.getActions("bubble")) {
3283
- const roles = a4.bubble?.roles ?? ["user", "assistant"];
3310
+ for (const a2 of this._cfg.getActions("bubble")) {
3311
+ const roles = a2.bubble?.roles ?? ["user", "assistant"];
3284
3312
  if (!roles.includes(this._role)) continue;
3285
3313
  const btn = document.createElement("button");
3286
3314
  btn.type = "button";
3287
3315
  btn.className = "aparte-btn aparte-btn--icon aparte-btn--sm aparte-action-btn aparte-action-custom";
3288
- btn.dataset["action"] = `custom:${a4.id}`;
3289
- btn.setAttribute("aria-label", a4.label);
3290
- btn.setAttribute("title", a4.label);
3291
- btn.innerHTML = a4.icon.startsWith("<") ? a4.icon : this._cfg.getIcon(a4.icon) ?? a4.iconFallback ?? "";
3316
+ btn.dataset["action"] = `custom:${a2.id}`;
3317
+ btn.setAttribute("aria-label", a2.label);
3318
+ btn.setAttribute("title", a2.label);
3319
+ btn.innerHTML = a2.icon.startsWith("<") ? a2.icon : this._cfg.getIcon(a2.icon) ?? a2.iconFallback ?? "";
3292
3320
  this._actionBarEl.appendChild(btn);
3293
3321
  }
3294
3322
  }
@@ -3524,6 +3552,7 @@ class AparteChatBubble extends HTMLElement {
3524
3552
  _updateStreaming(streaming) {
3525
3553
  const wasStreaming = this._streaming;
3526
3554
  this._streaming = streaming;
3555
+ if (!streaming) this._step = null;
3527
3556
  const message = this.querySelector(".aparte-message");
3528
3557
  if (message) {
3529
3558
  message.setAttribute("data-streaming", String(streaming));
@@ -4166,11 +4195,11 @@ class AparteChatViewport extends HTMLElement {
4166
4195
  this._notifyBubble(messageId, "addSegment", stamped);
4167
4196
  this._autoScroll();
4168
4197
  }
4169
- updateSegment(a4, b2, c2) {
4170
- const clientForm = c2 === void 0 && typeof b2 === "object";
4171
- const messageId = clientForm ? this._activeMessageId() : a4;
4172
- const segmentId = clientForm ? a4 : b2;
4173
- const updates = clientForm ? b2 : c2;
4198
+ updateSegment(a2, b3, c2) {
4199
+ const clientForm = c2 === void 0 && typeof b3 === "object";
4200
+ const messageId = clientForm ? this._activeMessageId() : a2;
4201
+ const segmentId = clientForm ? a2 : b3;
4202
+ const updates = clientForm ? b3 : c2;
4174
4203
  if (!messageId) return;
4175
4204
  const message = this._repo.getMessageById(messageId);
4176
4205
  if (!message?.segments) return;
@@ -4182,10 +4211,10 @@ class AparteChatViewport extends HTMLElement {
4182
4211
  this._notifyBubble(messageId, "updateSegment", { segmentId, updates: stamped });
4183
4212
  }
4184
4213
  }
4185
- removeSegment(a4, b2) {
4186
- const clientForm = b2 === void 0;
4187
- const messageId = clientForm ? this._activeMessageId() : a4;
4188
- const segmentId = clientForm ? a4 : b2;
4214
+ removeSegment(a2, b3) {
4215
+ const clientForm = b3 === void 0;
4216
+ const messageId = clientForm ? this._activeMessageId() : a2;
4217
+ const segmentId = clientForm ? a2 : b3;
4189
4218
  if (!messageId || !segmentId) return;
4190
4219
  const message = this._repo.getMessageById(messageId);
4191
4220
  if (message?.segments) {
@@ -4222,6 +4251,13 @@ class AparteChatViewport extends HTMLElement {
4222
4251
  if (message) message.usage = usage;
4223
4252
  this._notifyBubble(messageId, "setUsage", usage);
4224
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
+ }
4225
4261
  // ─────────────────────────────────────────────────────────────────────────
4226
4262
  // Message Management
4227
4263
  // ─────────────────────────────────────────────────────────────────────────
@@ -4531,7 +4567,7 @@ class AparteChatViewport extends HTMLElement {
4531
4567
  if (!this._frameworkManagedDOM) {
4532
4568
  const wrapper = this.querySelector(".aparte-messages-wrapper");
4533
4569
  if (wrapper) {
4534
- Array.from(wrapper.querySelectorAll("aparte-chat-bubble")).forEach((b2) => b2.remove());
4570
+ Array.from(wrapper.querySelectorAll("aparte-chat-bubble")).forEach((b3) => b3.remove());
4535
4571
  }
4536
4572
  }
4537
4573
  this._setSpacerHeight(0);
@@ -4642,6 +4678,9 @@ class AparteChatViewport extends HTMLElement {
4642
4678
  case "setUsage":
4643
4679
  bubble.setUsage?.(payload);
4644
4680
  break;
4681
+ case "setStep":
4682
+ bubble.setStep?.(payload);
4683
+ break;
4645
4684
  case "update": {
4646
4685
  const updates = payload;
4647
4686
  const renderable = ["status", "segments", "content", "attachments", "usage", "finishReason", "contextSummary", "compaction"];
@@ -5102,6 +5141,15 @@ class AparteChatViewport extends HTMLElement {
5102
5141
  }
5103
5142
  _scrollToBottom() {
5104
5143
  if (!this._container) return;
5144
+ if (this._fitsOnceCentred()) {
5145
+ this._smoothScrollOnce = false;
5146
+ if (this._gliding()) {
5147
+ this._glideUntil = 0;
5148
+ this._ownScrollAt = performance.now();
5149
+ this._container.scrollTop = 0;
5150
+ }
5151
+ return;
5152
+ }
5105
5153
  if (this._smoothScrollOnce) {
5106
5154
  this._smoothScrollOnce = false;
5107
5155
  this._smoothScrollToBottom();
@@ -5115,6 +5163,18 @@ class AparteChatViewport extends HTMLElement {
5115
5163
  this._container.scrollTop = this._container.scrollHeight;
5116
5164
  this._settleAtBottom();
5117
5165
  }
5166
+ /** The transcript will fit once the room the centring spacer under the composer still
5167
+ * holds (`center-empty`, or a wrapper's auto-centre) is back. That room is 0 once the
5168
+ * slide is over, and outside those layouts. */
5169
+ _fitsOnceCentred() {
5170
+ if (!this._container) return false;
5171
+ const room = this._centringRoom();
5172
+ return room > 0 && this._container.scrollHeight - this._getSpacerHeight() <= this._container.clientHeight + room;
5173
+ }
5174
+ _centringRoom() {
5175
+ const host = this.closest("aparte-chat[center-empty], .aparte-chat-container--auto-center");
5176
+ return host ? parseFloat(getComputedStyle(host, "::after").height) || 0 : 0;
5177
+ }
5118
5178
  _gliding() {
5119
5179
  return performance.now() < this._glideUntil;
5120
5180
  }
@@ -5260,7 +5320,7 @@ class AparteChatViewport extends HTMLElement {
5260
5320
  this._setSpacerHeight(0);
5261
5321
  return;
5262
5322
  }
5263
- const lastUserBubble = [...allBubbles].reverse().find((b2) => b2.getAttribute("data-role") === "user");
5323
+ const lastUserBubble = [...allBubbles].reverse().find((b3) => b3.getAttribute("data-role") === "user");
5264
5324
  if (!lastUserBubble) {
5265
5325
  this._setSpacerHeight(0);
5266
5326
  return;
@@ -5270,7 +5330,7 @@ class AparteChatViewport extends HTMLElement {
5270
5330
  const userRect = lastUserBubble.getBoundingClientRect();
5271
5331
  const userTopInContent = userRect.top - containerRect.top + this._container.scrollTop;
5272
5332
  const scrollHeightWithoutSpacer = this._container.scrollHeight - currentSpacerH;
5273
- if (scrollHeightWithoutSpacer <= this._container.clientHeight) {
5333
+ if (scrollHeightWithoutSpacer <= this._container.clientHeight + this._centringRoom()) {
5274
5334
  this._setSpacerHeight(0);
5275
5335
  return;
5276
5336
  }
@@ -7055,7 +7115,14 @@ const VIEWPORT_MARGIN = 8;
7055
7115
  class AparteConversationList extends HTMLElement {
7056
7116
  _conversations = [];
7057
7117
  _activeId = null;
7058
- _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;
7059
7126
  _renaming = null;
7060
7127
  _warnedNoManager = false;
7061
7128
  static get observedAttributes() {
@@ -7098,17 +7165,17 @@ class AparteConversationList extends HTMLElement {
7098
7165
  }
7099
7166
  this.addEventListener("click", this._onClick);
7100
7167
  this.addEventListener("keydown", this._onKeydown);
7101
- this.addEventListener("focusout", this._onFocusOut);
7168
+ this.addEventListener("aparte-menu-select", this._onMenuSelect);
7102
7169
  this.addEventListener("pointerdown", this._onPress);
7103
7170
  this._render();
7104
7171
  window.addEventListener("aparte-config-change", this._onConfigChange);
7105
7172
  window.addEventListener("aparte-conversation-status", this._onStatus);
7106
7173
  }
7107
7174
  disconnectedCallback() {
7108
- this._closeMenu();
7175
+ this._releaseMenus();
7109
7176
  this.removeEventListener("click", this._onClick);
7110
7177
  this.removeEventListener("keydown", this._onKeydown);
7111
- this.removeEventListener("focusout", this._onFocusOut);
7178
+ this.removeEventListener("aparte-menu-select", this._onMenuSelect);
7112
7179
  this.removeEventListener("pointerdown", this._onPress);
7113
7180
  window.removeEventListener("pointerup", this._onRelease, true);
7114
7181
  window.removeEventListener("pointercancel", this._onRelease, true);
@@ -7234,7 +7301,7 @@ class AparteConversationList extends HTMLElement {
7234
7301
  this._renderAfterPress = true;
7235
7302
  return;
7236
7303
  }
7237
- this._closeMenu();
7304
+ this._releaseMenus();
7238
7305
  this._renaming = null;
7239
7306
  const focused2 = activeElementIn(this);
7240
7307
  const held = focused2 && this.contains(focused2) ? focused2.closest("[data-select-id], [data-more-id]") : null;
@@ -7265,6 +7332,7 @@ class AparteConversationList extends HTMLElement {
7265
7332
  this.innerHTML = groups;
7266
7333
  }
7267
7334
  this._applyFilter();
7335
+ this._wireMenus();
7268
7336
  if (!restore) return;
7269
7337
  const back = this.querySelector(restore);
7270
7338
  if (back && visible(back)) {
@@ -7368,7 +7436,7 @@ class AparteConversationList extends HTMLElement {
7368
7436
  }
7369
7437
  }
7370
7438
  const fixed = ["pinned", "today", "yesterday", "week", "month"].map((k2) => buckets.get(k2)).filter((g) => !!g);
7371
- const months = [...buckets.keys()].filter((k2) => k2.startsWith("m-")).sort((a4, b2) => b2.localeCompare(a4)).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));
7372
7440
  const undated = buckets.get("undated");
7373
7441
  return [...fixed, ...months, ...undated ? [undated] : []];
7374
7442
  }
@@ -7454,85 +7522,91 @@ class AparteConversationList extends HTMLElement {
7454
7522
  </div>
7455
7523
  </div>`;
7456
7524
  }
7457
- _openMenu(row, button2) {
7458
- this._closeMenu();
7459
- const id = row.dataset["convId"];
7460
- const conv = this._conversations.find((c2) => c2.id === id);
7461
- if (!conv) return;
7525
+ /** A row menu's element, empty: `_fillMenu` gives it its items as it opens. */
7526
+ _newMenu() {
7462
7527
  const menu = document.createElement("div");
7463
7528
  menu.className = "aparte-menu aparte-conv-menu";
7464
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");
7465
7545
  menu.setAttribute("aria-label", conv.title || this._t("newChat"));
7466
7546
  menu.innerHTML = this._menuMarkup(conv);
7467
7547
  row.appendChild(menu);
7468
- button2.setAttribute("aria-expanded", "true");
7469
- this._open = { id, row, button: button2, menu };
7470
- this._placeMenu(button2, menu);
7471
- menu.querySelector('[role="menuitem"]')?.focus();
7472
- document.addEventListener("pointerdown", this._onDocumentPointerDown, true);
7473
- document.addEventListener("pointerup", this._onDocumentPointerUp, true);
7474
- document.addEventListener("pointercancel", this._onDocumentPointerUp, true);
7475
- window.addEventListener("scroll", this._onWindowScroll, true);
7476
- window.addEventListener("resize", this._onWindowScroll);
7477
- }
7478
- /**
7479
- * Fixed, below the button's end edge, flipped above it when the viewport ends
7480
- * first. Fixed rather than absolute because a sidebar scrolls: an absolute menu on
7481
- * the last rows would be clipped by the list's own overflow. No anchoring library —
7482
- * the menu closes on any scroll or resize, which is what makes the arithmetic
7483
- * safe to do once.
7484
- */
7485
- _placeMenu(button2, menu) {
7486
- 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, {
7487
7571
  gap: MENU_GAP,
7488
7572
  margin: VIEWPORT_MARGIN,
7489
- align: "end",
7490
- 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
7491
7599
  });
7492
7600
  }
7493
- _closeMenu(returnFocus = false) {
7494
- const open = this._open;
7495
- if (!open) return;
7496
- this._open = null;
7497
- open.menu.remove();
7498
- open.button.setAttribute("aria-expanded", "false");
7499
- document.removeEventListener("pointerdown", this._onDocumentPointerDown, true);
7500
- document.removeEventListener("pointerup", this._onDocumentPointerUp, true);
7501
- document.removeEventListener("pointercancel", this._onDocumentPointerUp, true);
7502
- this._pressInMenu = false;
7503
- window.removeEventListener("scroll", this._onWindowScroll, true);
7504
- window.removeEventListener("resize", this._onWindowScroll);
7505
- if (returnFocus && open.button.isConnected) open.button.focus();
7506
- }
7507
- /**
7508
- * A pointer is down inside the open menu. WebKit does not move the focus to a
7509
- * button on mousedown: the element that held it is blurred instead — `focusout`
7510
- * with no `relatedTarget` — before the click reaches the item. `_onFocusOut` used
7511
- * to read that as the focus leaving the menu and close it on the press, so with a
7512
- * mouse no item could be chosen at all. Held from the press to its release.
7513
- */
7514
- _pressInMenu = false;
7515
- _onDocumentPointerUp = () => {
7516
- this._pressInMenu = false;
7517
- };
7518
- _onDocumentPointerDown = (e) => {
7519
- const open = this._open;
7520
- if (!open) return;
7521
- const target = eventOrigin(e);
7522
- this._pressInMenu = !!target && open.menu.contains(target);
7523
- if (open.menu.contains(target) || open.button.contains(target)) return;
7524
- this._closeMenu();
7525
- };
7526
- _onWindowScroll = () => {
7527
- this._closeMenu();
7528
- };
7529
- _onFocusOut = (e) => {
7530
- const open = this._open;
7531
- if (!open) return;
7532
- const next = e.relatedTarget;
7533
- if (!next && this._pressInMenu) return;
7534
- if (next && (open.menu.contains(next) || open.button.contains(next))) return;
7535
- 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();
7536
7610
  };
7537
7611
  /**
7538
7612
  * The gesture, finished. The event has already gone out — cancelable, so a host
@@ -7564,26 +7638,25 @@ class AparteConversationList extends HTMLElement {
7564
7638
  console.warn("[aparte-conversation-list] the conversation manager refused the change:", err);
7565
7639
  });
7566
7640
  }
7567
- _onMenuAction(action2) {
7568
- const open = this._open;
7569
- if (!open) return;
7570
- const conv = this._conversations.find((c2) => c2.id === open.id);
7571
- if (!conv) {
7572
- this._closeMenu();
7573
- return;
7574
- }
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;
7575
7648
  const id = conv.id;
7576
7649
  switch (action2) {
7577
- case "rename":
7578
- this._closeMenu();
7579
- 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);
7580
7653
  return;
7654
+ }
7581
7655
  // The two toggles dispatch each name as a LITERAL, in its own branch: the
7582
7656
  // manifest analyzer records a dispatch whose name is a ternary as an event
7583
7657
  // with no name (the Angular generator then crashes on it), and one whose
7584
7658
  // name is a local as an event called after the local.
7585
7659
  case "pin":
7586
- this._closeMenu(true);
7587
7660
  if (conv.pinnedAt) {
7588
7661
  const unpin = new CustomEvent(
7589
7662
  "aparte-conversation-unpin",
@@ -7601,7 +7674,6 @@ class AparteConversationList extends HTMLElement {
7601
7674
  }
7602
7675
  return;
7603
7676
  case "archive":
7604
- this._closeMenu(true);
7605
7677
  if (conv.archivedAt) {
7606
7678
  const unarchive = new CustomEvent(
7607
7679
  "aparte-conversation-unarchive",
@@ -7619,22 +7691,20 @@ class AparteConversationList extends HTMLElement {
7619
7691
  }
7620
7692
  return;
7621
7693
  case "delete": {
7622
- const previous = [...open.menu.childNodes];
7694
+ const previous = [...menu.childNodes];
7623
7695
  const holder = document.createElement("div");
7624
7696
  holder.innerHTML = this._confirmMarkup(conv);
7625
- open.menu.append(...holder.childNodes);
7626
- open.menu.setAttribute("role", "dialog");
7627
- open.menu.setAttribute("aria-label", this._confirmQuestion(conv));
7628
- 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();
7629
7701
  for (const node of previous) node.remove();
7630
- this._placeMenu(open.button, open.menu);
7702
+ this._placeQuestion(menu, id);
7631
7703
  return;
7632
7704
  }
7633
7705
  case "cancel":
7634
- this._closeMenu(true);
7635
7706
  return;
7636
7707
  case "confirm-delete": {
7637
- this._closeMenu(true);
7638
7708
  const remove = new CustomEvent(
7639
7709
  "aparte-conversation-delete",
7640
7710
  { detail: { id }, bubbles: true, composed: true, cancelable: true }
@@ -7645,27 +7715,20 @@ class AparteConversationList extends HTMLElement {
7645
7715
  }
7646
7716
  }
7647
7717
  }
7648
- _menuFocusables() {
7649
- const open = this._open;
7650
- if (!open) return [];
7651
- return Array.from(open.menu.querySelectorAll('[role="menuitem"], [data-menu-action]'));
7652
- }
7653
- _onMenuKeydown(e) {
7654
- const items = this._menuFocusables();
7655
- 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));
7656
7727
  const focusAt = (i2) => {
7657
7728
  e.preventDefault();
7658
- items[(i2 + items.length) % items.length]?.focus();
7729
+ answers[(i2 + answers.length) % answers.length]?.focus();
7659
7730
  };
7660
7731
  switch (e.key) {
7661
- case "Escape":
7662
- e.preventDefault();
7663
- this._closeMenu(true);
7664
- return;
7665
- case "Tab":
7666
- e.preventDefault();
7667
- this._closeMenu(true);
7668
- return;
7669
7732
  case "ArrowDown":
7670
7733
  focusAt(index + 1);
7671
7734
  return;
@@ -7676,7 +7739,7 @@ class AparteConversationList extends HTMLElement {
7676
7739
  focusAt(0);
7677
7740
  return;
7678
7741
  case "End":
7679
- focusAt(items.length - 1);
7742
+ focusAt(answers.length - 1);
7680
7743
  return;
7681
7744
  }
7682
7745
  }
@@ -7733,25 +7796,19 @@ class AparteConversationList extends HTMLElement {
7733
7796
  _onClick = (e) => {
7734
7797
  const target = e.target;
7735
7798
  const menuAction = target.closest("[data-menu-action]");
7736
- if (menuAction && this._open?.menu.contains(menuAction)) {
7799
+ const menu = menuAction?.closest("[data-menu-for]");
7800
+ if (menuAction && menu) {
7737
7801
  e.stopPropagation();
7738
- this._onMenuAction(menuAction.dataset["menuAction"]);
7802
+ this._onMenuAction(menuAction.dataset["menuAction"], menu);
7739
7803
  return;
7740
7804
  }
7741
- const more = target.closest("[data-more-id]");
7742
- if (more) {
7805
+ if (target.closest("[data-more-id]")) {
7743
7806
  e.stopPropagation();
7744
- if (this._open?.button === more) {
7745
- this._closeMenu(true);
7746
- } else {
7747
- this._openMenu(more.closest("[data-conv-id]"), more);
7748
- }
7749
7807
  return;
7750
7808
  }
7751
7809
  if (target.closest("[data-rename-id]")) return;
7752
7810
  const select = target.closest("[data-select-id]");
7753
7811
  if (select) {
7754
- this._closeMenu();
7755
7812
  const targetId = this.getAttribute("target");
7756
7813
  this.dispatchEvent(new CustomEvent(
7757
7814
  "aparte-conversation-select",
@@ -7761,8 +7818,9 @@ class AparteConversationList extends HTMLElement {
7761
7818
  };
7762
7819
  _onKeydown = (e) => {
7763
7820
  const target = e.target;
7764
- if (this._open?.menu.contains(target)) {
7765
- this._onMenuKeydown(e);
7821
+ const menu = target.closest("[data-menu-for]");
7822
+ if (menu) {
7823
+ if (menu.getAttribute("role") === "dialog") this._onQuestionKeydown(e, menu);
7766
7824
  return;
7767
7825
  }
7768
7826
  if (target.matches("[data-rename-id]")) {
@@ -8914,7 +8972,7 @@ class AparteScrollRail extends HTMLElement {
8914
8972
  /** The bubbles that get a tick, from all of them. */
8915
8973
  _bubbles(all = this._messages()) {
8916
8974
  const every = this.getAttribute("every") === "message" ? "message" : "user";
8917
- 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");
8918
8976
  }
8919
8977
  // ─── Rendering ────────────────────────────────────────────────────────
8920
8978
  /** The first words of a message, for the tick's name. An excerpt, never a summary. */
@@ -8972,7 +9030,7 @@ class AparteScrollRail extends HTMLElement {
8972
9030
  const id = item.firstElementChild instanceof HTMLElement ? item.firstElementChild.dataset["messageId"] : void 0;
8973
9031
  if (id) existing.set(id, item);
8974
9032
  }
8975
- const known = new Set(bubbles.map((b2) => b2.getAttribute("message-id")));
9033
+ const known = new Set(bubbles.map((b3) => b3.getAttribute("message-id")));
8976
9034
  for (const [id, item] of existing) {
8977
9035
  if (known.has(id)) continue;
8978
9036
  item.remove();
@@ -9385,9 +9443,9 @@ function isBubble(node) {
9385
9443
  function holdsBubbles(nodes) {
9386
9444
  return Array.from(nodes).some((n2) => n2 instanceof Element && (isBubble(n2) || n2.localName === "aparte-chat-viewport" || n2.querySelector("aparte-chat-bubble") !== null));
9387
9445
  }
9388
- function sameElements(a4, b2) {
9389
- if (a4.length !== b2.length) return false;
9390
- for (let i2 = 0; i2 < a4.length; i2++) if (a4[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;
9391
9449
  return true;
9392
9450
  }
9393
9451
  deferHydrationOf(AparteScrollRail);
@@ -11347,7 +11405,8 @@ export {
11347
11405
  D as createAgentStreamRunner,
11348
11406
  E as createAparteAgentHandler,
11349
11407
  F as createAparteChatHandler,
11350
- G as createStreamAdapter,
11408
+ G as createSegmentList,
11409
+ H as createStreamAdapter,
11351
11410
  cssEscape,
11352
11411
  I as declineDefaultRenderers,
11353
11412
  J as defaultSanitizer,
@@ -11355,44 +11414,52 @@ export {
11355
11414
  L as defineMountedSegmentRenderer,
11356
11415
  M as defineMountedToolRenderer,
11357
11416
  N as detachConfig,
11417
+ enhanceContextMenu,
11418
+ enhanceMenu,
11419
+ b2 as enhanceTabs,
11358
11420
  escapeAttr,
11359
11421
  escapeHtml,
11360
11422
  Q as estimateTokens,
11361
11423
  R as estimateWireTokens,
11362
11424
  T as filesToAttachments,
11363
- U as getAllRenderers,
11425
+ formatDuration,
11426
+ V as getAllRenderers,
11364
11427
  getSegmentRenderer,
11365
- W as historyFromCheckpoint,
11428
+ X as historyFromCheckpoint,
11366
11429
  installDefaultRenderersOnce,
11367
11430
  installDialogTriggersOnce,
11368
11431
  isAwaitingReply,
11369
- _ as isFormatAdapter,
11432
+ $ as isFormatAdapter,
11370
11433
  isSafeUrl,
11371
11434
  isSegmentSettled,
11372
11435
  measureContext,
11373
- a2 as overrideSegmentRenderer,
11374
- a3 as parseAparteEventStream,
11436
+ onRenderersChange,
11437
+ a4 as overrideSegmentRenderer,
11438
+ a5 as parseAparteEventStream,
11375
11439
  parseMarkdownToSegments,
11376
11440
  placeFloating,
11441
+ pluralize,
11377
11442
  populateBubbleFromMessage,
11378
- a7 as readableToAsyncIterable,
11443
+ a9 as readableToAsyncIterable,
11379
11444
  registerAllComponents,
11380
- a8 as registerDefaultRenderers,
11381
- a9 as registerSegmentRenderer,
11382
- aa as releaseDeferredHydration,
11383
- ab as renderCitations,
11384
- ac as renderCodeLanguages,
11385
- ad 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,
11386
11451
  resolveConfig,
11387
11452
  revokeAttachmentUrls,
11453
+ ai as runSubAgent,
11388
11454
  runWithConfig,
11389
- ah as segmentDuration,
11455
+ ak as segmentDuration,
11390
11456
  segmentTiming,
11391
- aj as setupSuggestionBlocks,
11457
+ am as setupSuggestionBlocks,
11458
+ an as startSubAgent,
11392
11459
  subscribeConfigChange,
11393
- al as toToolCallView,
11394
- am as toolRefusal,
11395
- an as unregisterSegmentRenderer,
11460
+ ap as toToolCallView,
11461
+ aq as toolRefusal,
11462
+ ar as unregisterSegmentRenderer,
11396
11463
  uuid
11397
11464
  };
11398
11465
  //# sourceMappingURL=index.js.map