@aparte/core 1.11.0 → 1.12.1

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 (57) hide show
  1. package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
  2. package/dist/components/chat/aparte-chat.d.ts +4 -0
  3. package/dist/components/chat/aparte-chat.d.ts.map +1 -1
  4. package/dist/components/composer/aparte-composer-cancel.d.ts.map +1 -1
  5. package/dist/components/composer/aparte-composer-input.d.ts.map +1 -1
  6. package/dist/components/composer/aparte-composer-send.d.ts.map +1 -1
  7. package/dist/components/composer/aparte-composer.d.ts +82 -0
  8. package/dist/components/composer/aparte-composer.d.ts.map +1 -1
  9. package/dist/components/composer/index.d.ts +1 -1
  10. package/dist/components/composer/index.d.ts.map +1 -1
  11. package/dist/components/conversation-list/aparte-conversation-list.d.ts +10 -0
  12. package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -1
  13. package/dist/components/index.d.ts +1 -1
  14. package/dist/components/index.d.ts.map +1 -1
  15. package/dist/config/aparte-config.d.ts +55 -1
  16. package/dist/config/aparte-config.d.ts.map +1 -1
  17. package/dist/config/index.d.ts +2 -0
  18. package/dist/config/index.d.ts.map +1 -1
  19. package/dist/config/locale.d.ts +10 -0
  20. package/dist/config/locale.d.ts.map +1 -1
  21. package/dist/config/model-catalogue.d.ts +35 -0
  22. package/dist/config/model-catalogue.d.ts.map +1 -0
  23. package/dist/context/checkpoint.d.ts +4 -0
  24. package/dist/context/checkpoint.d.ts.map +1 -1
  25. package/dist/conversations/conversation-manager.d.ts.map +1 -1
  26. package/dist/custom-elements.json +5849 -5387
  27. package/dist/{defer-hydration-2oPv7cU0.js → defer-hydration-DfYJjWtk.js} +214 -86
  28. package/dist/defer-hydration-DfYJjWtk.js.map +1 -0
  29. package/dist/elicitation/index.d.ts +1 -1
  30. package/dist/elicitation/index.d.ts.map +1 -1
  31. package/dist/elicitation/types.d.ts +18 -0
  32. package/dist/elicitation/types.d.ts.map +1 -1
  33. package/dist/generated/element-attributes.d.ts +2 -0
  34. package/dist/generated/element-attributes.d.ts.map +1 -1
  35. package/dist/index.css +1 -1
  36. package/dist/index.d.ts +5 -3
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +302 -82
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.node.d.ts +5 -3
  41. package/dist/index.node.d.ts.map +1 -1
  42. package/dist/index.node.js +54 -53
  43. package/dist/index.node.js.map +1 -1
  44. package/dist/interop/element-props.d.ts +1 -1
  45. package/dist/interop/element-props.d.ts.map +1 -1
  46. package/dist/types/event-map.d.ts +1 -0
  47. package/dist/types/event-map.d.ts.map +1 -1
  48. package/dist/types/events.d.ts +7 -0
  49. package/dist/types/events.d.ts.map +1 -1
  50. package/dist/types/imperative-api.d.ts +6 -1
  51. package/dist/types/imperative-api.d.ts.map +1 -1
  52. package/dist/types/index.d.ts +1 -1
  53. package/dist/types/index.d.ts.map +1 -1
  54. package/dist/types/models.d.ts +24 -0
  55. package/dist/types/models.d.ts.map +1 -1
  56. package/package.json +2 -2
  57. package/dist/defer-hydration-2oPv7cU0.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { L as deferHydrationOf, ai as resolveConfig, aq as subscribeConfigChange, al as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, y as chatIdOf, aw as gateGlide, Q as escapeAttr, an as segmentTiming, ax as chatBoundaryOf, ay as relabelCodeLanguages, az as relabelCitations, aA as toolCallRenderer, aB as activityRenderer, t as aparteGlobalConfig, aC as isMountedRenderer, aD as renderingVersionOf, a5 as onRenderersChange, aE as renderSourceList, aF as mergeSegmentUpdate, a3 as isSegmentSettled, a9 as pluralize, W as formatDuration, aG as toolNameOf, R as escapeHtml, aH as writeStreamedMarkdown, aI as replaceHighlighted, a2 as isSafeUrl, P as dispatchChatEvent, D as copyText, Y as getSegmentRenderer, _ as installDefaultRenderersOnce, aJ as toolRendererThatDrew, aK as activityRendererThatDrew, r as AparteMessageRepository, aL as CheckpointStateWatcher, aM as stampSegmentActivity, aN as stampSegmentOnInsert, aO as stampSegmentOnUpdate, aP as renumberSegments, aQ as openSegmentIds, aR as isTerminalStatus, aS as adoptMessageSegments, a0 as isAwaitingReply, aa as populateBubbleFromMessage, au as uuid, aj as revokeAttachmentUrls, a8 as parseMarkdownToSegments, aT as APARTE_DERIVED_SEGMENTS, aU as rememberConversationStatus, aV as tellConversationStatus, aW as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, aX as visibleReply, aY as usageTokens, q as AparteErrorCode, a4 as measureContext, aZ as inRenderedContent, g as APARTE_HOST_ATTR, $ as installDialogTriggersOnce } from "./defer-hydration-2oPv7cU0.js";
2
- import { A, a, b, c, d, f, h, i, j, k, l, m, n, p, s, S, u, v, z, B, C, E, F, G, H, I, J, K, M, N, O, T, U, V, X, Z, a1, a6, a7, ab, ac, ad, ae, af, ag, ah, ak, am, ao, ap, ar, as, at, av } from "./defer-hydration-2oPv7cU0.js";
1
+ import { M as deferHydrationOf, aj as resolveConfig, ar as subscribeConfigChange, am as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, y as chatIdOf, ax as gateGlide, R as escapeAttr, ao as segmentTiming, ay as chatBoundaryOf, az as relabelCodeLanguages, aA as relabelCitations, aB as toolCallRenderer, aC as activityRenderer, t as aparteGlobalConfig, aD as isMountedRenderer, aE as renderingVersionOf, a6 as onRenderersChange, aF as renderSourceList, aG as mergeSegmentUpdate, a4 as isSegmentSettled, aa as pluralize, X as formatDuration, aH as toolNameOf, T as escapeHtml, aI as writeStreamedMarkdown, aJ as replaceHighlighted, a3 as isSafeUrl, Q as dispatchChatEvent, D as copyText, Z as getSegmentRenderer, $ as installDefaultRenderersOnce, aK as toolRendererThatDrew, aL as activityRendererThatDrew, r as AparteMessageRepository, aM as CheckpointStateWatcher, aN as stampSegmentActivity, aO as stampSegmentOnInsert, aP as stampSegmentOnUpdate, aQ as renumberSegments, aR as openSegmentIds, aS as isTerminalStatus, aT as adoptMessageSegments, a1 as isAwaitingReply, ab as populateBubbleFromMessage, av as uuid, ak as revokeAttachmentUrls, a9 as parseMarkdownToSegments, aU as APARTE_DERIVED_SEGMENTS, aV as rememberConversationStatus, aW as tellConversationStatus, aX as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, aY as visibleReply, aZ as usageTokens, q as AparteErrorCode, a5 as measureContext, a_ as inRenderedContent, g as APARTE_HOST_ATTR, a0 as installDialogTriggersOnce } from "./defer-hydration-DfYJjWtk.js";
2
+ import { A, a, b, c, d, f, h, i, j, k, l, m, n, p, s, S, u, v, z, B, C, E, F, G, H, I, J, K, L, N, O, P, U, V, W, Y, _, a2, a7, a8, ac, ad, ae, af, ag, ah, ai, al, an, ap, aq, as, at, au, aw } from "./defer-hydration-DfYJjWtk.js";
3
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
4
  import { b as b2 } from "./kit-keyboard-BUSLQ5i4.js";
5
5
  function presenceOn(value) {
@@ -1423,7 +1423,7 @@ function draw(root, content, token) {
1423
1423
  }
1424
1424
  function drawMessageTokens(root, content, tokens) {
1425
1425
  if (root.querySelector(".aparte-inline-token")) return;
1426
- for (const token of [...tokens].sort((a2, b3) => b3.start - a2.start)) {
1426
+ for (const token of [...tokens].sort((a3, b3) => b3.start - a3.start)) {
1427
1427
  if (token.text) draw(root, content, token);
1428
1428
  }
1429
1429
  }
@@ -2157,6 +2157,8 @@ class AparteChatBubble extends HTMLElement {
2157
2157
  if ("status" in updates || "isStreaming" in updates || "queued" in updates || "deferred" in updates) {
2158
2158
  this._syncTurns();
2159
2159
  this._updateWaiting();
2160
+ } else if (this._cfg.getTurnSummary()?.label && this._turnHolding(this._drawn.get(segmentId)?.el)) {
2161
+ this._syncTurns();
2160
2162
  }
2161
2163
  }
2162
2164
  }
@@ -2410,6 +2412,7 @@ class AparteChatBubble extends HTMLElement {
2410
2412
  }
2411
2413
  const reason = this.getAttribute("data-checkpoint-reason") ?? "";
2412
2414
  const summary = this._checkpointSummaryText();
2415
+ const below = kind === "done" && this._contextSummary?.includesSelf === true;
2413
2416
  const signature = JSON.stringify([
2414
2417
  kind,
2415
2418
  this._contextSummary?.count,
@@ -2417,7 +2420,8 @@ class AparteChatBubble extends HTMLElement {
2417
2420
  reason,
2418
2421
  this._checkpointOpen,
2419
2422
  this._confirmingRestore,
2420
- this._checkpointOpen ? summary : ""
2423
+ this._checkpointOpen ? summary : "",
2424
+ below
2421
2425
  ]);
2422
2426
  if (current && !focus && signature === this._checkpointDrawn) return;
2423
2427
  const active = document.activeElement;
@@ -2435,8 +2439,13 @@ class AparteChatBubble extends HTMLElement {
2435
2439
  const panel = next.querySelector(".aparte-checkpoint__summary");
2436
2440
  if (panel) panel.innerHTML = this._cfg.renderMarkdown(summary);
2437
2441
  }
2438
- if (current) current.replaceWith(next);
2439
- else this.prepend(next);
2442
+ if (current && current.hasAttribute("data-below") === below) current.replaceWith(next);
2443
+ else {
2444
+ current?.remove();
2445
+ if (below) this.append(next);
2446
+ else this.prepend(next);
2447
+ }
2448
+ next.toggleAttribute("data-below", below);
2440
2449
  this._checkpointDrawn = signature;
2441
2450
  const wanted = focus ?? hadFocus;
2442
2451
  if (wanted) next.querySelector(`[data-checkpoint-action="${cssEscape(wanted)}"]`)?.focus();
@@ -2591,7 +2600,7 @@ class AparteChatBubble extends HTMLElement {
2591
2600
  const row = rowFor(member);
2592
2601
  if (row) lastInBody = place(body, row, lastInBody);
2593
2602
  }
2594
- this._labelTurn(turn, members, run.to === this._segments.length - 1, options?.openWhileRunning === true);
2603
+ this._labelTurn(turn, members, run.to === this._segments.length - 1, options ?? {});
2595
2604
  index = run.to;
2596
2605
  }
2597
2606
  for (const stale of container.querySelectorAll(":scope > .aparte-turn")) {
@@ -2599,7 +2608,7 @@ class AparteChatBubble extends HTMLElement {
2599
2608
  }
2600
2609
  }
2601
2610
  /** The fold's one line: what it is doing while it works, what it did once it has. */
2602
- _labelTurn(turn, members, trailing, openWhileRunning) {
2611
+ _labelTurn(turn, members, trailing, options) {
2603
2612
  const cfg = this._cfg;
2604
2613
  const steps = members.filter((member) => this._turnRole(member) === "fold");
2605
2614
  const calls = steps.filter((step) => step.type === "tool_call");
@@ -2607,10 +2616,18 @@ class AparteChatBubble extends HTMLElement {
2607
2616
  const label = turn.querySelector(":scope > summary > .aparte-turn__label");
2608
2617
  const current = turn.querySelector(":scope > summary > .aparte-turn__current");
2609
2618
  label.classList.toggle("aparte-shimmer", running);
2610
- label.textContent = running ? cfg.t("turnWorking") : this._turnOutcome(steps, calls.length);
2619
+ let own;
2620
+ try {
2621
+ own = options.label?.(steps, { running, config: cfg });
2622
+ } catch (error) {
2623
+ console.error("[aparte] the turn summary label threw; core's line is shown instead.", error);
2624
+ }
2625
+ label.textContent = own ?? (running ? cfg.t("turnWorking") : this._turnOutcome(steps, calls.length));
2626
+ label.toggleAttribute("aria-live", false);
2627
+ if (options.label) label.setAttribute("aria-live", "polite");
2611
2628
  const now = calls.filter((call) => !call.queued && call.deferred?.reason !== "queued").at(-1) ?? calls.at(-1);
2612
- current.textContent = running && now ? this._stepName(now) : "";
2613
- if (openWhileRunning && !("touched" in turn.dataset)) turn.open = running;
2629
+ current.textContent = own == null && running && now ? this._stepName(now) : "";
2630
+ if (options.openWhileRunning === true && !("touched" in turn.dataset)) turn.open = running;
2614
2631
  }
2615
2632
  _turnOutcome(steps, callCount) {
2616
2633
  const cfg = this._cfg;
@@ -3038,19 +3055,19 @@ class AparteChatBubble extends HTMLElement {
3038
3055
  const customAttachment = this._cfg.getAttachmentRenderer?.();
3039
3056
  if (customAttachment) {
3040
3057
  this._attachmentsEl.replaceChildren();
3041
- for (const a2 of this._attachments) {
3042
- const el2 = segmentRenderResultToElement(runWithConfig(this._cfg, () => customAttachment(a2)));
3058
+ for (const a3 of this._attachments) {
3059
+ const el2 = segmentRenderResultToElement(runWithConfig(this._cfg, () => customAttachment(a3)));
3043
3060
  if (el2) this._attachmentsEl.appendChild(el2);
3044
3061
  }
3045
3062
  return;
3046
3063
  }
3047
- this._attachmentsEl.innerHTML = this._attachments.map((a2) => {
3048
- const name = escapeHtml(a2.name);
3049
- if (a2.type.startsWith("image/") && this._isShowableUrl(a2.url)) {
3050
- 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>`;
3064
+ this._attachmentsEl.innerHTML = this._attachments.map((a3) => {
3065
+ const name = escapeHtml(a3.name);
3066
+ if (a3.type.startsWith("image/") && this._isShowableUrl(a3.url)) {
3067
+ return `<div class="aparte-thumbnail aparte-thumb aparte-thumb--image" title="${name}" data-type="${escapeHtml(a3.type)}"><img class="aparte-thumbnail__image" src="${escapeHtml(a3.url)}" alt="${name}" loading="lazy" /><span class="aparte-thumb__name">${name}</span></div>`;
3051
3068
  }
3052
- const openable = this._isOpenableUrl(a2.url) ? ` data-url="${escapeHtml(a2.url)}"` : "";
3053
- 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>`;
3069
+ const openable = this._isOpenableUrl(a3.url) ? ` data-url="${escapeHtml(a3.url)}"` : "";
3070
+ return `<div class="aparte-thumbnail aparte-thumb aparte-thumb--file" title="${name}" data-type="${escapeHtml(a3.type)}"${openable}><span class="aparte-thumbnail__label">${escapeHtml(this._fileExt(a3.name))}</span><span class="aparte-thumb__name">${name}</span></div>`;
3054
3071
  }).join("");
3055
3072
  const { attachmentPreview, filePreview } = this._cfg.getHostHandlers();
3056
3073
  const kinds = [attachmentPreview ? ".aparte-thumb--image" : "", filePreview ? ".aparte-thumb--file[data-url]" : ""].filter(Boolean);
@@ -3229,14 +3246,14 @@ class AparteChatBubble extends HTMLElement {
3229
3246
  const buttons = [];
3230
3247
  if (this._role === "user") {
3231
3248
  if (config.user) {
3232
- for (const a2 of config.user) buttons.push(this._actionButtonHtml(a2, icons, locale));
3249
+ for (const a3 of config.user) buttons.push(this._actionButtonHtml(a3, icons, locale));
3233
3250
  } else {
3234
3251
  if (config.copy) buttons.push(this._actionButtonHtml("copy", icons, locale));
3235
3252
  if (config.edit) buttons.push(this._actionButtonHtml("edit", icons, locale));
3236
3253
  }
3237
3254
  } else if (this._role === "assistant") {
3238
3255
  if (config.assistant) {
3239
- for (const a2 of config.assistant) buttons.push(this._actionButtonHtml(a2, icons, locale));
3256
+ for (const a3 of config.assistant) buttons.push(this._actionButtonHtml(a3, icons, locale));
3240
3257
  } else {
3241
3258
  if (config.copy) buttons.push(this._actionButtonHtml("copy", icons, locale));
3242
3259
  if (config.retry) buttons.push(this._actionButtonHtml("retry", icons, locale));
@@ -3337,18 +3354,18 @@ class AparteChatBubble extends HTMLElement {
3337
3354
  if (!this._actionBarEl) return;
3338
3355
  const locale = this._cfg.getLocale();
3339
3356
  const start = [];
3340
- for (const a2 of this._cfg.getActions("bubble")) {
3341
- const roles = a2.bubble?.roles ?? ["user", "assistant"];
3357
+ for (const a3 of this._cfg.getActions("bubble")) {
3358
+ const roles = a3.bubble?.roles ?? ["user", "assistant"];
3342
3359
  if (!roles.includes(this._role)) continue;
3343
- const word = Object.hasOwn(locale, a2.label) ? locale[a2.label] : void 0;
3344
- const label = typeof word === "string" ? word : a2.label;
3345
- const icon = a2.display === "label" || !a2.icon ? "" : a2.icon.startsWith("<") ? a2.icon : this._cfg.getIcon(a2.icon) ?? a2.iconFallback ?? "";
3346
- const written = a2.display === "label" || a2.display === "both" || icon === "";
3360
+ const word = Object.hasOwn(locale, a3.label) ? locale[a3.label] : void 0;
3361
+ const label = typeof word === "string" ? word : a3.label;
3362
+ const icon = a3.display === "label" || !a3.icon ? "" : a3.icon.startsWith("<") ? a3.icon : this._cfg.getIcon(a3.icon) ?? a3.iconFallback ?? "";
3363
+ const written = a3.display === "label" || a3.display === "both" || icon === "";
3347
3364
  const btn = document.createElement("button");
3348
3365
  btn.type = "button";
3349
3366
  btn.className = "aparte-btn aparte-btn--sm aparte-action-btn aparte-action-custom";
3350
3367
  if (!written) btn.classList.add("aparte-btn--icon");
3351
- btn.dataset["action"] = `custom:${a2.id}`;
3368
+ btn.dataset["action"] = `custom:${a3.id}`;
3352
3369
  btn.innerHTML = icon;
3353
3370
  if (written) {
3354
3371
  btn.append(label);
@@ -3356,7 +3373,7 @@ class AparteChatBubble extends HTMLElement {
3356
3373
  btn.setAttribute("aria-label", label);
3357
3374
  btn.setAttribute("title", label);
3358
3375
  }
3359
- if (a2.position === "start") start.push(btn);
3376
+ if (a3.position === "start") start.push(btn);
3360
3377
  else this._actionBarEl.appendChild(btn);
3361
3378
  }
3362
3379
  this._actionBarEl.prepend(...start);
@@ -4239,10 +4256,10 @@ class AparteChatViewport extends HTMLElement {
4239
4256
  this._notifyBubble(messageId, "addSegment", stamped);
4240
4257
  this._autoScroll();
4241
4258
  }
4242
- updateSegment(a2, b3, c2) {
4259
+ updateSegment(a3, b3, c2) {
4243
4260
  const clientForm = c2 === void 0 && typeof b3 === "object";
4244
- const messageId = clientForm ? this._activeMessageId() : a2;
4245
- const segmentId = clientForm ? a2 : b3;
4261
+ const messageId = clientForm ? this._activeMessageId() : a3;
4262
+ const segmentId = clientForm ? a3 : b3;
4246
4263
  const updates = clientForm ? b3 : c2;
4247
4264
  if (!messageId) return;
4248
4265
  const message = this._repo.getMessageById(messageId);
@@ -4255,10 +4272,10 @@ class AparteChatViewport extends HTMLElement {
4255
4272
  this._notifyBubble(messageId, "updateSegment", { segmentId, updates: stamped });
4256
4273
  }
4257
4274
  }
4258
- removeSegment(a2, b3) {
4275
+ removeSegment(a3, b3) {
4259
4276
  const clientForm = b3 === void 0;
4260
- const messageId = clientForm ? this._activeMessageId() : a2;
4261
- const segmentId = clientForm ? a2 : b3;
4277
+ const messageId = clientForm ? this._activeMessageId() : a3;
4278
+ const segmentId = clientForm ? a3 : b3;
4262
4279
  if (!messageId || !segmentId) return;
4263
4280
  const message = this._repo.getMessageById(messageId);
4264
4281
  if (message?.segments) {
@@ -5550,6 +5567,7 @@ function isOneLineField(target) {
5550
5567
  if (target instanceof HTMLTextAreaElement) return target.rows === 1;
5551
5568
  return target instanceof HTMLInputElement && ONE_LINE_INPUTS.has(target.type);
5552
5569
  }
5570
+ let queueIds = 0;
5553
5571
  class AparteComposer extends HTMLElement {
5554
5572
  _value = "";
5555
5573
  _streaming = false;
@@ -5579,8 +5597,13 @@ class AparteComposer extends HTMLElement {
5579
5597
  "streaming-change",
5580
5598
  "disabled-change",
5581
5599
  "attachments-change",
5582
- "panel-change"
5600
+ "panel-change",
5601
+ "queue-change"
5583
5602
  ]);
5603
+ /** The messages written during a reply, waiting for it to end — see {@link queue}. */
5604
+ _queue = [];
5605
+ /** Unique per composer, for the ids that name each queued message to its buttons. */
5606
+ _queueIdBase = `aparte-queued-${++queueIds}`;
5584
5607
  // Window event bindings
5585
5608
  _onMessageStart = this._handleMessageStart.bind(this);
5586
5609
  _onMessageDone = this._handleMessageDone.bind(this);
@@ -5628,7 +5651,7 @@ class AparteComposer extends HTMLElement {
5628
5651
  else this.removeAttribute("dir");
5629
5652
  }
5630
5653
  static get observedAttributes() {
5631
- return ["placeholder", "disabled", "target"];
5654
+ return ["placeholder", "disabled", "target", "stop-label"];
5632
5655
  }
5633
5656
  /** Stops the document listeners of `type-to-focus`; null while disconnected. */
5634
5657
  _offTypeToFocus = null;
@@ -5659,6 +5682,9 @@ class AparteComposer extends HTMLElement {
5659
5682
  if (name === "disabled") {
5660
5683
  this._emit("disabled-change", { disabled: value !== null });
5661
5684
  }
5685
+ if (name === "stop-label") {
5686
+ this._emit("stop-label-change", { stopLabel: this.stopLabel });
5687
+ }
5662
5688
  if (name === "placeholder") {
5663
5689
  for (const input of this.querySelectorAll("aparte-composer-input")) {
5664
5690
  input.syncPlaceholder?.();
@@ -5730,9 +5756,63 @@ class AparteComposer extends HTMLElement {
5730
5756
  disabled: this.disabled,
5731
5757
  attachments: [...this._attachments],
5732
5758
  panelActive: this._panelActive,
5733
- submitEnabled: this._panelSubmitEnabled
5759
+ submitEnabled: this._panelSubmitEnabled,
5760
+ queued: this.queued
5734
5761
  };
5735
5762
  }
5763
+ /**
5764
+ * What the Stop button says it stops: its accessible name and its tooltip, in place of the
5765
+ * locale's `stopButton`. For an app that knows what a stop would interrupt — "Stop the
5766
+ * sub-agents", "Stop the download". `null` (the default) is the locale's word. The
5767
+ * `stop-label` attribute is the state and this property writes it, so a framework binding
5768
+ * and a script reach the same thing; set it back to `null` when the run it named is over.
5769
+ * This chat's composer only, where `extendLocale({ stopButton })` would rename every chat
5770
+ * sharing the config.
5771
+ */
5772
+ get stopLabel() {
5773
+ const label = this.getAttribute("stop-label");
5774
+ return label?.trim() ? label : null;
5775
+ }
5776
+ set stopLabel(label) {
5777
+ if (label?.trim()) this.setAttribute("stop-label", label);
5778
+ else this.removeAttribute("stop-label");
5779
+ }
5780
+ /** The messages waiting for the reply to end, first to go first. A copy. */
5781
+ get queued() {
5782
+ return this._queue.map((q) => ({ ...q }));
5783
+ }
5784
+ /**
5785
+ * Whether Enter in the field queues the draft while a reply streams: the config's
5786
+ * `setQueueWhileStreaming`.
5787
+ */
5788
+ get queueWhileStreaming() {
5789
+ return this._cfg.getQueueWhileStreaming();
5790
+ }
5791
+ /**
5792
+ * Put the draft in the queue while a reply streams; it is sent when the reply ends well
5793
+ * (`aparte-message-done`), after the ones queued before it. With no reply in flight this
5794
+ * is a send. What Enter does with `setQueueWhileStreaming(true)`; call it from a button of
5795
+ * your own to queue whatever the setting.
5796
+ */
5797
+ queue() {
5798
+ if (this._panelActive) return;
5799
+ if (!this._streaming) {
5800
+ this.submit();
5801
+ return;
5802
+ }
5803
+ const content = this._value.trim();
5804
+ if (!content && this._attachments.length === 0) return;
5805
+ if (this.disabled) return;
5806
+ const tokens = this.querySelector("aparte-composer-input")?.getTokens?.();
5807
+ this._queue.push({
5808
+ content,
5809
+ ...this._attachments.length > 0 ? { files: [...this._attachments] } : {},
5810
+ ...tokens?.length ? { tokens } : {}
5811
+ });
5812
+ this.setValue("");
5813
+ this.clearAttachments();
5814
+ this._queueChanged();
5815
+ }
5736
5816
  /**
5737
5817
  * Set the composer's value — both what a send will submit and what the editor
5738
5818
  * shows. `<aparte-composer-input>` writes through any value it does not already
@@ -5967,10 +6047,24 @@ class AparteComposer extends HTMLElement {
5967
6047
  if (this.disabled) return;
5968
6048
  if (this._modelGated) return;
5969
6049
  if (this._uploading) return;
5970
- this._emit("submit", { value, attachments: this._attachments });
5971
6050
  const tokens = this.querySelector("aparte-composer-input")?.getTokens?.();
5972
- const detail = {
6051
+ const sent = this._send({
5973
6052
  content: value,
6053
+ ...this._attachments.length > 0 ? { files: [...this._attachments] } : {},
6054
+ ...tokens?.length ? { tokens } : {}
6055
+ });
6056
+ if (!sent) return;
6057
+ this.setValue("");
6058
+ this.clearAttachments();
6059
+ }
6060
+ /**
6061
+ * Send one message: `aparte-before-send`, then — unless a listener held it — `aparte-send`.
6062
+ * Returns whether it went. The one path for a message typed and for one that waited in the
6063
+ * queue, so a hold applies to both.
6064
+ */
6065
+ _send(message) {
6066
+ const detail = {
6067
+ content: message.content,
5974
6068
  timestamp: Date.now(),
5975
6069
  /*
5976
6070
  * `_ownTargetId()`, not the bare attribute — the same resolution `cancel()`
@@ -5980,16 +6074,103 @@ class AparteComposer extends HTMLElement {
5980
6074
  * reply to whichever one the host resolved first.
5981
6075
  */
5982
6076
  targetId: this._ownTargetId(),
5983
- files: this._attachments.length > 0 ? [...this._attachments] : void 0,
5984
- ...tokens?.length ? { tokens } : {}
6077
+ files: message.files?.length ? [...message.files] : void 0,
6078
+ ...message.tokens?.length ? { tokens: message.tokens } : {}
5985
6079
  };
6080
+ if (!dispatchChatEvent(this, "aparte-before-send", detail, { cancelable: true })) return false;
6081
+ this._emit("submit", { value: message.content, attachments: message.files ?? [] });
5986
6082
  this.dispatchEvent(new CustomEvent("aparte-send", {
5987
6083
  bubbles: true,
5988
6084
  composed: true,
5989
6085
  detail
5990
6086
  }));
5991
- this.setValue("");
5992
- this.clearAttachments();
6087
+ return true;
6088
+ }
6089
+ /**
6090
+ * The reply ended well: send the first queued message. After the event that said so has
6091
+ * reached every listener (the client is still closing that turn while it runs), and only
6092
+ * if no other reply started meanwhile — it then waits for that one.
6093
+ */
6094
+ _sendNextQueued() {
6095
+ if (this._streaming || this._queue.length === 0 || !this.isConnected) return;
6096
+ const next = this._queue.shift();
6097
+ this._queueChanged();
6098
+ if (this.disabled || this._modelGated || !this._send(next)) this._backToField([next]);
6099
+ }
6100
+ /**
6101
+ * Put queued messages back into the field, before what is being written there: after a
6102
+ * Stop or an error, or when one is held. Nothing is sent behind the person's back, and
6103
+ * nothing is lost.
6104
+ */
6105
+ _backToField(messages) {
6106
+ if (messages.length === 0) return;
6107
+ const text = [...messages.map((m2) => m2.content), this._value.trim()].filter(Boolean).join("\n\n");
6108
+ this.setValue(text);
6109
+ const files = messages.flatMap((m2) => m2.files ?? []);
6110
+ if (files.length > 0) this.addAttachments(files);
6111
+ }
6112
+ /** The queue changed: say so, and redraw the list over the field. */
6113
+ _queueChanged() {
6114
+ this._emit("queue-change", { queued: this.queued });
6115
+ this._drawQueue();
6116
+ }
6117
+ /**
6118
+ * The queued messages, drawn above the field's row (or first in the composer when it has
6119
+ * none): one line each, with a button that takes it back into the field and one that
6120
+ * removes it. Hidden while the queue is empty. Drawn by the composer, like a panel, so a
6121
+ * framework's own composition needs no part for it.
6122
+ */
6123
+ _drawQueue() {
6124
+ let strip = this.querySelector(":scope .aparte-composer-queue");
6125
+ if (!strip) {
6126
+ if (this._queue.length === 0) return;
6127
+ strip = document.createElement("div");
6128
+ strip.className = "aparte-composer-queue";
6129
+ strip.setAttribute("role", "group");
6130
+ const row = this.querySelector(".aparte-composer-row");
6131
+ if (row?.parentElement) row.parentElement.insertBefore(strip, row);
6132
+ else this.prepend(strip);
6133
+ }
6134
+ const cfg = this._cfg;
6135
+ const label = cfg.t("queueLabel") || "Sent when the reply ends";
6136
+ strip.setAttribute("aria-label", label);
6137
+ strip.hidden = this._queue.length === 0;
6138
+ const head = document.createElement("div");
6139
+ head.className = "aparte-composer-queue__label";
6140
+ head.textContent = label;
6141
+ const list = document.createElement("ul");
6142
+ list.className = "aparte-composer-queue__list";
6143
+ const base = this._queueIdBase;
6144
+ this._queue.forEach((message, index) => {
6145
+ const item = document.createElement("li");
6146
+ item.className = "aparte-composer-queue__item";
6147
+ const text = document.createElement("span");
6148
+ text.className = "aparte-composer-queue__text";
6149
+ text.id = `${base}-${index}`;
6150
+ text.textContent = message.content || (message.files ?? []).map((f2) => f2.name).join(", ");
6151
+ item.append(text, this._queueButton("edit", cfg.t("queueEdit") || "Edit", text.id, index), this._queueButton("trash", cfg.t("queueRemove") || "Remove", text.id, index));
6152
+ list.append(item);
6153
+ });
6154
+ strip.replaceChildren(head, list);
6155
+ }
6156
+ _queueButton(icon, label, describedBy, index) {
6157
+ const button2 = document.createElement("button");
6158
+ button2.type = "button";
6159
+ const part = icon === "trash" ? "aparte-composer-queue__remove" : "aparte-composer-queue__edit";
6160
+ button2.classList.add("aparte-btn", "aparte-btn--icon", "aparte-btn--sm", "aparte-btn--ghost", part);
6161
+ button2.innerHTML = this._cfg.getIcon(icon);
6162
+ button2.setAttribute("aria-label", label);
6163
+ button2.setAttribute("title", label);
6164
+ button2.setAttribute("aria-describedby", describedBy);
6165
+ button2.addEventListener("click", () => {
6166
+ const [message] = this._queue.splice(index, 1);
6167
+ this._queueChanged();
6168
+ if (icon === "edit" && message) {
6169
+ this._backToField([message]);
6170
+ this.focus();
6171
+ }
6172
+ });
6173
+ return button2;
5993
6174
  }
5994
6175
  /** Cancel the current streaming response. */
5995
6176
  cancel() {
@@ -6096,6 +6277,14 @@ class AparteComposer extends HTMLElement {
6096
6277
  this._streaming = false;
6097
6278
  this._emit("streaming-change", { streaming: false });
6098
6279
  if (this._panelActive) this._evictPanel();
6280
+ if (this._queue.length === 0) return;
6281
+ if (e.type === "aparte-message-done") {
6282
+ setTimeout(() => this._sendNextQueued(), 0);
6283
+ } else {
6284
+ const waiting = this._queue.splice(0);
6285
+ this._queueChanged();
6286
+ this._backToField(waiting);
6287
+ }
6099
6288
  }
6100
6289
  }
6101
6290
  deferHydrationOf(AparteComposer);
@@ -6431,7 +6620,10 @@ class AparteComposerInput extends HTMLElement {
6431
6620
  e.preventDefault();
6432
6621
  const root = this._getRoot();
6433
6622
  if (root) {
6434
- if (root.streaming) return;
6623
+ if (root.streaming) {
6624
+ if (root.queueWhileStreaming) root.queue();
6625
+ return;
6626
+ }
6435
6627
  root.submit();
6436
6628
  } else {
6437
6629
  this.dispatchEvent(new CustomEvent("aparte-composer-submit", { bubbles: true }));
@@ -6578,6 +6770,9 @@ class AparteComposerSend extends HTMLElement {
6578
6770
  this._refreshChrome();
6579
6771
  })
6580
6772
  );
6773
+ this._unsubscribes.push(
6774
+ root._on("stop-label-change", () => this._refreshChrome())
6775
+ );
6581
6776
  this._unsubscribes.push(subscribeConfigChange(this, () => this._refreshChrome()));
6582
6777
  }
6583
6778
  /**
@@ -6659,7 +6854,7 @@ class AparteComposerSend extends HTMLElement {
6659
6854
  this._button.disabled = false;
6660
6855
  this._button.innerHTML = this._getStopIcon();
6661
6856
  this._setAct("stop");
6662
- const label = resolveConfig(this).t("stopButton") || "Stop";
6857
+ const label = this._getRoot()?.stopLabel || resolveConfig(this).t("stopButton") || "Stop";
6663
6858
  this._button.setAttribute("aria-label", label);
6664
6859
  this._button.setAttribute("title", label);
6665
6860
  this._button.classList.add("aparte-is-streaming");
@@ -6726,6 +6921,9 @@ class AparteComposerCancel extends HTMLElement {
6726
6921
  if (this._button) this._button.hidden = !streaming;
6727
6922
  })
6728
6923
  );
6924
+ this._unsubscribes.push(
6925
+ root._on("stop-label-change", () => this._refreshChrome())
6926
+ );
6729
6927
  if (root.streaming && this._button) this._button.hidden = false;
6730
6928
  }
6731
6929
  _handleClick(e) {
@@ -6741,7 +6939,7 @@ class AparteComposerCancel extends HTMLElement {
6741
6939
  */
6742
6940
  _refreshChrome() {
6743
6941
  if (!this._button) return;
6744
- const label = resolveConfig(this).t("stopButton") || "Stop";
6942
+ const label = this._getRoot()?.stopLabel || resolveConfig(this).t("stopButton") || "Stop";
6745
6943
  this._button.setAttribute("aria-label", label);
6746
6944
  this._button.setAttribute("title", label);
6747
6945
  this._button.innerHTML = this._getStopIcon();
@@ -7143,6 +7341,7 @@ function rowSelector(attr, id) {
7143
7341
  return `[${attr}="${cssEscape(id)}"]`;
7144
7342
  }
7145
7343
  const DAY = 864e5;
7344
+ const LIST_GLYPHS = ["more", "edit", "pin", "archive", "unarchive", "trash"];
7146
7345
  const MENU_GAP = 4;
7147
7346
  const VIEWPORT_MARGIN = 8;
7148
7347
  class AparteConversationList extends HTMLElement {
@@ -7231,12 +7430,31 @@ class AparteConversationList extends HTMLElement {
7231
7430
  * and the group headings come from the locale, so without this the list stayed in
7232
7431
  * the previous language until something else happened to re-render it. Only OUR
7233
7432
  * config.
7433
+ *
7434
+ * Only for what the list draws from it, and held like any render asked from outside.
7435
+ * The event goes out for every change of the config (a provider registered, a model
7436
+ * selected, a tool display), and redrawing on each of them detached a row menu open
7437
+ * under the pointer and lost a title being renamed, when an app registered its models
7438
+ * a second after launch.
7234
7439
  */
7235
7440
  _onConfigChange = (e) => {
7236
7441
  const detail = e.detail;
7237
7442
  if (detail?.config && detail.config !== resolveConfig(this)) return;
7238
- this._render();
7443
+ const now = this._configDrawn();
7444
+ const drawn = this._drawnWith;
7445
+ if (drawn && drawn.locale === now.locale && drawn.glyphs === now.glyphs) return;
7446
+ this._renderUnlessHeld();
7239
7447
  };
7448
+ /** What the last render read from the config: its words and its glyphs. */
7449
+ _drawnWith = null;
7450
+ /** The locale the list's words come from, and the glyphs it draws. */
7451
+ _configDrawn() {
7452
+ const cfg = resolveConfig(this);
7453
+ return {
7454
+ locale: cfg.getLocale(),
7455
+ glyphs: LIST_GLYPHS.map((name) => cfg.getIcon(name)).join("\n")
7456
+ };
7457
+ }
7240
7458
  /**
7241
7459
  * `aparte-conversation-status`, on `window`: the controller's, a list's, or an app's own.
7242
7460
  * Kept page-wide too (an app may dispatch the event itself), then drawn on this row.
@@ -7398,6 +7616,7 @@ class AparteConversationList extends HTMLElement {
7398
7616
  return;
7399
7617
  }
7400
7618
  this._renderAfterMenu = false;
7619
+ this._drawnWith = this._configDrawn();
7401
7620
  this._releaseMenus();
7402
7621
  this._renaming = null;
7403
7622
  const focused2 = activeElementIn(this);
@@ -7544,7 +7763,7 @@ class AparteConversationList extends HTMLElement {
7544
7763
  }
7545
7764
  }
7546
7765
  const fixed = ["pinned", "today", "yesterday", "week", "month"].map((k2) => buckets.get(k2)).filter((g) => !!g);
7547
- const months = [...buckets.keys()].filter((k2) => k2.startsWith("m-")).sort((a2, b3) => b3.localeCompare(a2)).map((k2) => buckets.get(k2));
7766
+ const months = [...buckets.keys()].filter((k2) => k2.startsWith("m-")).sort((a3, b3) => b3.localeCompare(a3)).map((k2) => buckets.get(k2));
7548
7767
  const undated = buckets.get("undated");
7549
7768
  return [...named.values(), ...fixed, ...months, ...undated ? [undated] : []];
7550
7769
  }
@@ -9550,9 +9769,9 @@ function isBubble(node) {
9550
9769
  function holdsBubbles(nodes) {
9551
9770
  return Array.from(nodes).some((n2) => n2 instanceof Element && (isBubble(n2) || n2.localName === "aparte-chat-viewport" || n2.querySelector("aparte-chat-bubble") !== null));
9552
9771
  }
9553
- function sameElements(a2, b3) {
9554
- if (a2.length !== b3.length) return false;
9555
- for (let i2 = 0; i2 < a2.length; i2++) if (a2[i2] !== b3[i2]) return false;
9772
+ function sameElements(a3, b3) {
9773
+ if (a3.length !== b3.length) return false;
9774
+ for (let i2 = 0; i2 < a3.length; i2++) if (a3[i2] !== b3[i2]) return false;
9556
9775
  return true;
9557
9776
  }
9558
9777
  deferHydrationOf(AparteScrollRail);
@@ -11533,63 +11752,64 @@ export {
11533
11752
  E as createAgentStreamRunner,
11534
11753
  F as createAparteAgentHandler,
11535
11754
  G as createAparteChatHandler,
11536
- H as createSegmentList,
11537
- I as createStreamAdapter,
11755
+ H as createModelCatalogue,
11756
+ I as createSegmentList,
11757
+ J as createStreamAdapter,
11538
11758
  cssEscape,
11539
- J as declineDefaultRenderers,
11540
- K as defaultSanitizer,
11759
+ K as declineDefaultRenderers,
11760
+ L as defaultSanitizer,
11541
11761
  deferHydrationOf,
11542
- M as defineMountedSegmentRenderer,
11543
- N as defineMountedToolRenderer,
11544
- O as detachConfig,
11762
+ N as defineMountedSegmentRenderer,
11763
+ O as defineMountedToolRenderer,
11764
+ P as detachConfig,
11545
11765
  dispatchChatEvent,
11546
11766
  enhanceContextMenu,
11547
11767
  enhanceMenu,
11548
11768
  b2 as enhanceTabs,
11549
11769
  escapeAttr,
11550
11770
  escapeHtml,
11551
- T as estimateTokens,
11552
- U as estimateWireTokens,
11553
- V as filesToAttachments,
11771
+ U as estimateTokens,
11772
+ V as estimateWireTokens,
11773
+ W as filesToAttachments,
11554
11774
  formatDuration,
11555
- X as getAllRenderers,
11775
+ Y as getAllRenderers,
11556
11776
  getSegmentRenderer,
11557
- Z as historyFromCheckpoint,
11777
+ _ as historyFromCheckpoint,
11558
11778
  installDefaultRenderersOnce,
11559
11779
  installDialogTriggersOnce,
11560
11780
  isAwaitingReply,
11561
- a1 as isFormatAdapter,
11781
+ a2 as isFormatAdapter,
11562
11782
  isSafeUrl,
11563
11783
  isSegmentSettled,
11564
11784
  measureContext,
11565
11785
  onRenderersChange,
11566
- a6 as overrideSegmentRenderer,
11567
- a7 as parseAparteEventStream,
11786
+ a7 as overrideSegmentRenderer,
11787
+ a8 as parseAparteEventStream,
11568
11788
  parseMarkdownToSegments,
11569
11789
  placeFloating,
11570
11790
  pluralize,
11571
11791
  populateBubbleFromMessage,
11572
- ab as readableToAsyncIterable,
11792
+ ac as readableToAsyncIterable,
11573
11793
  registerAllComponents,
11574
- ac as registerDefaultRenderers,
11575
- ad as registerSegmentRenderer,
11576
- ae as releaseDeferredHydration,
11577
- af as renderCitations,
11578
- ag as renderCodeLanguages,
11579
- ah as requestUserInput,
11794
+ ad as registerDefaultRenderers,
11795
+ ae as registerSegmentRenderer,
11796
+ af as releaseDeferredHydration,
11797
+ ag as renderCitations,
11798
+ ah as renderCodeLanguages,
11799
+ ai as requestUserInput,
11580
11800
  resolveConfig,
11581
11801
  revokeAttachmentUrls,
11582
- ak as runSubAgent,
11802
+ al as runSubAgent,
11583
11803
  runWithConfig,
11584
- am as segmentDuration,
11804
+ an as segmentDuration,
11585
11805
  segmentTiming,
11586
- ao as setupSuggestionBlocks,
11587
- ap as startSubAgent,
11806
+ ap as setupSuggestionBlocks,
11807
+ aq as startSubAgent,
11588
11808
  subscribeConfigChange,
11589
- ar as toToolCallView,
11590
- as as toolRefusal,
11591
- at as unregisterSegmentRenderer,
11809
+ as as toToolCallView,
11810
+ at as toolRefusal,
11811
+ au as unregisterSegmentRenderer,
11592
11812
  uuid,
11593
- av as withoutAbandonedTurns
11813
+ aw as withoutAbandonedTurns
11594
11814
  };
11595
11815
  //# sourceMappingURL=index.js.map