@aparte/core 1.10.1 → 1.12.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 (65) hide show
  1. package/dist/client/aparte-client.d.ts.map +1 -1
  2. package/dist/client/wire-history.d.ts +4 -0
  3. package/dist/client/wire-history.d.ts.map +1 -1
  4. package/dist/components/bubble/aparte-chat-bubble.d.ts +4 -1
  5. package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
  6. package/dist/components/chat/aparte-chat.d.ts +4 -0
  7. package/dist/components/chat/aparte-chat.d.ts.map +1 -1
  8. package/dist/components/composer/aparte-composer-cancel.d.ts.map +1 -1
  9. package/dist/components/composer/aparte-composer-input.d.ts.map +1 -1
  10. package/dist/components/composer/aparte-composer-send.d.ts.map +1 -1
  11. package/dist/components/composer/aparte-composer.d.ts +82 -0
  12. package/dist/components/composer/aparte-composer.d.ts.map +1 -1
  13. package/dist/components/composer/index.d.ts +1 -1
  14. package/dist/components/composer/index.d.ts.map +1 -1
  15. package/dist/components/conversation-list/aparte-conversation-list.d.ts +10 -0
  16. package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -1
  17. package/dist/components/index.d.ts +1 -1
  18. package/dist/components/index.d.ts.map +1 -1
  19. package/dist/config/action-provider.d.ts +25 -4
  20. package/dist/config/action-provider.d.ts.map +1 -1
  21. package/dist/config/aparte-config.d.ts +55 -1
  22. package/dist/config/aparte-config.d.ts.map +1 -1
  23. package/dist/config/index.d.ts +2 -0
  24. package/dist/config/index.d.ts.map +1 -1
  25. package/dist/config/locale.d.ts +10 -0
  26. package/dist/config/locale.d.ts.map +1 -1
  27. package/dist/config/model-catalogue.d.ts +35 -0
  28. package/dist/config/model-catalogue.d.ts.map +1 -0
  29. package/dist/context/checkpoint.d.ts +4 -0
  30. package/dist/context/checkpoint.d.ts.map +1 -1
  31. package/dist/conversations/conversation-manager.d.ts.map +1 -1
  32. package/dist/custom-elements.json +3552 -3038
  33. package/dist/{defer-hydration-OFqdbk3O.js → defer-hydration-DfYJjWtk.js} +239 -98
  34. package/dist/defer-hydration-DfYJjWtk.js.map +1 -0
  35. package/dist/elicitation/index.d.ts +1 -1
  36. package/dist/elicitation/index.d.ts.map +1 -1
  37. package/dist/elicitation/types.d.ts +18 -0
  38. package/dist/elicitation/types.d.ts.map +1 -1
  39. package/dist/generated/element-attributes.d.ts +2 -0
  40. package/dist/generated/element-attributes.d.ts.map +1 -1
  41. package/dist/index.css +1 -1
  42. package/dist/index.d.ts +5 -3
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +319 -83
  45. package/dist/index.js.map +1 -1
  46. package/dist/index.node.d.ts +5 -3
  47. package/dist/index.node.d.ts.map +1 -1
  48. package/dist/index.node.js +54 -53
  49. package/dist/index.node.js.map +1 -1
  50. package/dist/interop/element-props.d.ts +1 -1
  51. package/dist/interop/element-props.d.ts.map +1 -1
  52. package/dist/types/chat.d.ts +15 -4
  53. package/dist/types/chat.d.ts.map +1 -1
  54. package/dist/types/event-map.d.ts +1 -0
  55. package/dist/types/event-map.d.ts.map +1 -1
  56. package/dist/types/events.d.ts +7 -0
  57. package/dist/types/events.d.ts.map +1 -1
  58. package/dist/types/imperative-api.d.ts +6 -1
  59. package/dist/types/imperative-api.d.ts.map +1 -1
  60. package/dist/types/index.d.ts +1 -1
  61. package/dist/types/index.d.ts.map +1 -1
  62. package/dist/types/models.d.ts +24 -0
  63. package/dist/types/models.d.ts.map +1 -1
  64. package/package.json +2 -2
  65. package/dist/defer-hydration-OFqdbk3O.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-OFqdbk3O.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-OFqdbk3O.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));
@@ -3329,21 +3346,37 @@ class AparteChatBubble extends HTMLElement {
3329
3346
  this._footerEl.hidden = barEmpty && pickerHidden;
3330
3347
  this.querySelector(".aparte-message")?.toggleAttribute("data-branches", !pickerHidden);
3331
3348
  }
3332
- /** Append the registered custom action buttons for this bubble's role. */
3349
+ /**
3350
+ * The actions the app registered for this bubble's role, on their side of the built-ins:
3351
+ * `position: 'start'` before them, the rest after, each side in `order`.
3352
+ */
3333
3353
  _appendCustomActions() {
3334
3354
  if (!this._actionBarEl) return;
3335
- for (const a2 of this._cfg.getActions("bubble")) {
3336
- const roles = a2.bubble?.roles ?? ["user", "assistant"];
3355
+ const locale = this._cfg.getLocale();
3356
+ const start = [];
3357
+ for (const a3 of this._cfg.getActions("bubble")) {
3358
+ const roles = a3.bubble?.roles ?? ["user", "assistant"];
3337
3359
  if (!roles.includes(this._role)) continue;
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 === "";
3338
3364
  const btn = document.createElement("button");
3339
3365
  btn.type = "button";
3340
- btn.className = "aparte-btn aparte-btn--icon aparte-btn--sm aparte-action-btn aparte-action-custom";
3341
- btn.dataset["action"] = `custom:${a2.id}`;
3342
- btn.setAttribute("aria-label", a2.label);
3343
- btn.setAttribute("title", a2.label);
3344
- btn.innerHTML = a2.icon.startsWith("<") ? a2.icon : this._cfg.getIcon(a2.icon) ?? a2.iconFallback ?? "";
3345
- this._actionBarEl.appendChild(btn);
3366
+ btn.className = "aparte-btn aparte-btn--sm aparte-action-btn aparte-action-custom";
3367
+ if (!written) btn.classList.add("aparte-btn--icon");
3368
+ btn.dataset["action"] = `custom:${a3.id}`;
3369
+ btn.innerHTML = icon;
3370
+ if (written) {
3371
+ btn.append(label);
3372
+ } else {
3373
+ btn.setAttribute("aria-label", label);
3374
+ btn.setAttribute("title", label);
3375
+ }
3376
+ if (a3.position === "start") start.push(btn);
3377
+ else this._actionBarEl.appendChild(btn);
3346
3378
  }
3379
+ this._actionBarEl.prepend(...start);
3347
3380
  }
3348
3381
  /** Build the `<button>` HTML for a single named action (shared by flag + per-role rendering). */
3349
3382
  _actionButtonHtml(action2, icons, locale) {
@@ -4223,10 +4256,10 @@ class AparteChatViewport extends HTMLElement {
4223
4256
  this._notifyBubble(messageId, "addSegment", stamped);
4224
4257
  this._autoScroll();
4225
4258
  }
4226
- updateSegment(a2, b3, c2) {
4259
+ updateSegment(a3, b3, c2) {
4227
4260
  const clientForm = c2 === void 0 && typeof b3 === "object";
4228
- const messageId = clientForm ? this._activeMessageId() : a2;
4229
- const segmentId = clientForm ? a2 : b3;
4261
+ const messageId = clientForm ? this._activeMessageId() : a3;
4262
+ const segmentId = clientForm ? a3 : b3;
4230
4263
  const updates = clientForm ? b3 : c2;
4231
4264
  if (!messageId) return;
4232
4265
  const message = this._repo.getMessageById(messageId);
@@ -4239,10 +4272,10 @@ class AparteChatViewport extends HTMLElement {
4239
4272
  this._notifyBubble(messageId, "updateSegment", { segmentId, updates: stamped });
4240
4273
  }
4241
4274
  }
4242
- removeSegment(a2, b3) {
4275
+ removeSegment(a3, b3) {
4243
4276
  const clientForm = b3 === void 0;
4244
- const messageId = clientForm ? this._activeMessageId() : a2;
4245
- const segmentId = clientForm ? a2 : b3;
4277
+ const messageId = clientForm ? this._activeMessageId() : a3;
4278
+ const segmentId = clientForm ? a3 : b3;
4246
4279
  if (!messageId || !segmentId) return;
4247
4280
  const message = this._repo.getMessageById(messageId);
4248
4281
  if (message?.segments) {
@@ -5534,6 +5567,7 @@ function isOneLineField(target) {
5534
5567
  if (target instanceof HTMLTextAreaElement) return target.rows === 1;
5535
5568
  return target instanceof HTMLInputElement && ONE_LINE_INPUTS.has(target.type);
5536
5569
  }
5570
+ let queueIds = 0;
5537
5571
  class AparteComposer extends HTMLElement {
5538
5572
  _value = "";
5539
5573
  _streaming = false;
@@ -5563,8 +5597,13 @@ class AparteComposer extends HTMLElement {
5563
5597
  "streaming-change",
5564
5598
  "disabled-change",
5565
5599
  "attachments-change",
5566
- "panel-change"
5600
+ "panel-change",
5601
+ "queue-change"
5567
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}`;
5568
5607
  // Window event bindings
5569
5608
  _onMessageStart = this._handleMessageStart.bind(this);
5570
5609
  _onMessageDone = this._handleMessageDone.bind(this);
@@ -5612,7 +5651,7 @@ class AparteComposer extends HTMLElement {
5612
5651
  else this.removeAttribute("dir");
5613
5652
  }
5614
5653
  static get observedAttributes() {
5615
- return ["placeholder", "disabled", "target"];
5654
+ return ["placeholder", "disabled", "target", "stop-label"];
5616
5655
  }
5617
5656
  /** Stops the document listeners of `type-to-focus`; null while disconnected. */
5618
5657
  _offTypeToFocus = null;
@@ -5643,6 +5682,9 @@ class AparteComposer extends HTMLElement {
5643
5682
  if (name === "disabled") {
5644
5683
  this._emit("disabled-change", { disabled: value !== null });
5645
5684
  }
5685
+ if (name === "stop-label") {
5686
+ this._emit("stop-label-change", { stopLabel: this.stopLabel });
5687
+ }
5646
5688
  if (name === "placeholder") {
5647
5689
  for (const input of this.querySelectorAll("aparte-composer-input")) {
5648
5690
  input.syncPlaceholder?.();
@@ -5714,9 +5756,63 @@ class AparteComposer extends HTMLElement {
5714
5756
  disabled: this.disabled,
5715
5757
  attachments: [...this._attachments],
5716
5758
  panelActive: this._panelActive,
5717
- submitEnabled: this._panelSubmitEnabled
5759
+ submitEnabled: this._panelSubmitEnabled,
5760
+ queued: this.queued
5718
5761
  };
5719
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
+ }
5720
5816
  /**
5721
5817
  * Set the composer's value — both what a send will submit and what the editor
5722
5818
  * shows. `<aparte-composer-input>` writes through any value it does not already
@@ -5951,10 +6047,24 @@ class AparteComposer extends HTMLElement {
5951
6047
  if (this.disabled) return;
5952
6048
  if (this._modelGated) return;
5953
6049
  if (this._uploading) return;
5954
- this._emit("submit", { value, attachments: this._attachments });
5955
6050
  const tokens = this.querySelector("aparte-composer-input")?.getTokens?.();
5956
- const detail = {
6051
+ const sent = this._send({
5957
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,
5958
6068
  timestamp: Date.now(),
5959
6069
  /*
5960
6070
  * `_ownTargetId()`, not the bare attribute — the same resolution `cancel()`
@@ -5964,16 +6074,103 @@ class AparteComposer extends HTMLElement {
5964
6074
  * reply to whichever one the host resolved first.
5965
6075
  */
5966
6076
  targetId: this._ownTargetId(),
5967
- files: this._attachments.length > 0 ? [...this._attachments] : void 0,
5968
- ...tokens?.length ? { tokens } : {}
6077
+ files: message.files?.length ? [...message.files] : void 0,
6078
+ ...message.tokens?.length ? { tokens: message.tokens } : {}
5969
6079
  };
6080
+ if (!dispatchChatEvent(this, "aparte-before-send", detail, { cancelable: true })) return false;
6081
+ this._emit("submit", { value: message.content, attachments: message.files ?? [] });
5970
6082
  this.dispatchEvent(new CustomEvent("aparte-send", {
5971
6083
  bubbles: true,
5972
6084
  composed: true,
5973
6085
  detail
5974
6086
  }));
5975
- this.setValue("");
5976
- 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;
5977
6174
  }
5978
6175
  /** Cancel the current streaming response. */
5979
6176
  cancel() {
@@ -6080,6 +6277,14 @@ class AparteComposer extends HTMLElement {
6080
6277
  this._streaming = false;
6081
6278
  this._emit("streaming-change", { streaming: false });
6082
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
+ }
6083
6288
  }
6084
6289
  }
6085
6290
  deferHydrationOf(AparteComposer);
@@ -6415,7 +6620,10 @@ class AparteComposerInput extends HTMLElement {
6415
6620
  e.preventDefault();
6416
6621
  const root = this._getRoot();
6417
6622
  if (root) {
6418
- if (root.streaming) return;
6623
+ if (root.streaming) {
6624
+ if (root.queueWhileStreaming) root.queue();
6625
+ return;
6626
+ }
6419
6627
  root.submit();
6420
6628
  } else {
6421
6629
  this.dispatchEvent(new CustomEvent("aparte-composer-submit", { bubbles: true }));
@@ -6562,6 +6770,9 @@ class AparteComposerSend extends HTMLElement {
6562
6770
  this._refreshChrome();
6563
6771
  })
6564
6772
  );
6773
+ this._unsubscribes.push(
6774
+ root._on("stop-label-change", () => this._refreshChrome())
6775
+ );
6565
6776
  this._unsubscribes.push(subscribeConfigChange(this, () => this._refreshChrome()));
6566
6777
  }
6567
6778
  /**
@@ -6643,7 +6854,7 @@ class AparteComposerSend extends HTMLElement {
6643
6854
  this._button.disabled = false;
6644
6855
  this._button.innerHTML = this._getStopIcon();
6645
6856
  this._setAct("stop");
6646
- const label = resolveConfig(this).t("stopButton") || "Stop";
6857
+ const label = this._getRoot()?.stopLabel || resolveConfig(this).t("stopButton") || "Stop";
6647
6858
  this._button.setAttribute("aria-label", label);
6648
6859
  this._button.setAttribute("title", label);
6649
6860
  this._button.classList.add("aparte-is-streaming");
@@ -6710,6 +6921,9 @@ class AparteComposerCancel extends HTMLElement {
6710
6921
  if (this._button) this._button.hidden = !streaming;
6711
6922
  })
6712
6923
  );
6924
+ this._unsubscribes.push(
6925
+ root._on("stop-label-change", () => this._refreshChrome())
6926
+ );
6713
6927
  if (root.streaming && this._button) this._button.hidden = false;
6714
6928
  }
6715
6929
  _handleClick(e) {
@@ -6725,7 +6939,7 @@ class AparteComposerCancel extends HTMLElement {
6725
6939
  */
6726
6940
  _refreshChrome() {
6727
6941
  if (!this._button) return;
6728
- const label = resolveConfig(this).t("stopButton") || "Stop";
6942
+ const label = this._getRoot()?.stopLabel || resolveConfig(this).t("stopButton") || "Stop";
6729
6943
  this._button.setAttribute("aria-label", label);
6730
6944
  this._button.setAttribute("title", label);
6731
6945
  this._button.innerHTML = this._getStopIcon();
@@ -7127,6 +7341,7 @@ function rowSelector(attr, id) {
7127
7341
  return `[${attr}="${cssEscape(id)}"]`;
7128
7342
  }
7129
7343
  const DAY = 864e5;
7344
+ const LIST_GLYPHS = ["more", "edit", "pin", "archive", "unarchive", "trash"];
7130
7345
  const MENU_GAP = 4;
7131
7346
  const VIEWPORT_MARGIN = 8;
7132
7347
  class AparteConversationList extends HTMLElement {
@@ -7215,12 +7430,31 @@ class AparteConversationList extends HTMLElement {
7215
7430
  * and the group headings come from the locale, so without this the list stayed in
7216
7431
  * the previous language until something else happened to re-render it. Only OUR
7217
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.
7218
7439
  */
7219
7440
  _onConfigChange = (e) => {
7220
7441
  const detail = e.detail;
7221
7442
  if (detail?.config && detail.config !== resolveConfig(this)) return;
7222
- 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();
7223
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
+ }
7224
7458
  /**
7225
7459
  * `aparte-conversation-status`, on `window`: the controller's, a list's, or an app's own.
7226
7460
  * Kept page-wide too (an app may dispatch the event itself), then drawn on this row.
@@ -7382,6 +7616,7 @@ class AparteConversationList extends HTMLElement {
7382
7616
  return;
7383
7617
  }
7384
7618
  this._renderAfterMenu = false;
7619
+ this._drawnWith = this._configDrawn();
7385
7620
  this._releaseMenus();
7386
7621
  this._renaming = null;
7387
7622
  const focused2 = activeElementIn(this);
@@ -7528,7 +7763,7 @@ class AparteConversationList extends HTMLElement {
7528
7763
  }
7529
7764
  }
7530
7765
  const fixed = ["pinned", "today", "yesterday", "week", "month"].map((k2) => buckets.get(k2)).filter((g) => !!g);
7531
- 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));
7532
7767
  const undated = buckets.get("undated");
7533
7768
  return [...named.values(), ...fixed, ...months, ...undated ? [undated] : []];
7534
7769
  }
@@ -9534,9 +9769,9 @@ function isBubble(node) {
9534
9769
  function holdsBubbles(nodes) {
9535
9770
  return Array.from(nodes).some((n2) => n2 instanceof Element && (isBubble(n2) || n2.localName === "aparte-chat-viewport" || n2.querySelector("aparte-chat-bubble") !== null));
9536
9771
  }
9537
- function sameElements(a2, b3) {
9538
- if (a2.length !== b3.length) return false;
9539
- 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;
9540
9775
  return true;
9541
9776
  }
9542
9777
  deferHydrationOf(AparteScrollRail);
@@ -11517,63 +11752,64 @@ export {
11517
11752
  E as createAgentStreamRunner,
11518
11753
  F as createAparteAgentHandler,
11519
11754
  G as createAparteChatHandler,
11520
- H as createSegmentList,
11521
- I as createStreamAdapter,
11755
+ H as createModelCatalogue,
11756
+ I as createSegmentList,
11757
+ J as createStreamAdapter,
11522
11758
  cssEscape,
11523
- J as declineDefaultRenderers,
11524
- K as defaultSanitizer,
11759
+ K as declineDefaultRenderers,
11760
+ L as defaultSanitizer,
11525
11761
  deferHydrationOf,
11526
- M as defineMountedSegmentRenderer,
11527
- N as defineMountedToolRenderer,
11528
- O as detachConfig,
11762
+ N as defineMountedSegmentRenderer,
11763
+ O as defineMountedToolRenderer,
11764
+ P as detachConfig,
11529
11765
  dispatchChatEvent,
11530
11766
  enhanceContextMenu,
11531
11767
  enhanceMenu,
11532
11768
  b2 as enhanceTabs,
11533
11769
  escapeAttr,
11534
11770
  escapeHtml,
11535
- T as estimateTokens,
11536
- U as estimateWireTokens,
11537
- V as filesToAttachments,
11771
+ U as estimateTokens,
11772
+ V as estimateWireTokens,
11773
+ W as filesToAttachments,
11538
11774
  formatDuration,
11539
- X as getAllRenderers,
11775
+ Y as getAllRenderers,
11540
11776
  getSegmentRenderer,
11541
- Z as historyFromCheckpoint,
11777
+ _ as historyFromCheckpoint,
11542
11778
  installDefaultRenderersOnce,
11543
11779
  installDialogTriggersOnce,
11544
11780
  isAwaitingReply,
11545
- a1 as isFormatAdapter,
11781
+ a2 as isFormatAdapter,
11546
11782
  isSafeUrl,
11547
11783
  isSegmentSettled,
11548
11784
  measureContext,
11549
11785
  onRenderersChange,
11550
- a6 as overrideSegmentRenderer,
11551
- a7 as parseAparteEventStream,
11786
+ a7 as overrideSegmentRenderer,
11787
+ a8 as parseAparteEventStream,
11552
11788
  parseMarkdownToSegments,
11553
11789
  placeFloating,
11554
11790
  pluralize,
11555
11791
  populateBubbleFromMessage,
11556
- ab as readableToAsyncIterable,
11792
+ ac as readableToAsyncIterable,
11557
11793
  registerAllComponents,
11558
- ac as registerDefaultRenderers,
11559
- ad as registerSegmentRenderer,
11560
- ae as releaseDeferredHydration,
11561
- af as renderCitations,
11562
- ag as renderCodeLanguages,
11563
- 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,
11564
11800
  resolveConfig,
11565
11801
  revokeAttachmentUrls,
11566
- ak as runSubAgent,
11802
+ al as runSubAgent,
11567
11803
  runWithConfig,
11568
- am as segmentDuration,
11804
+ an as segmentDuration,
11569
11805
  segmentTiming,
11570
- ao as setupSuggestionBlocks,
11571
- ap as startSubAgent,
11806
+ ap as setupSuggestionBlocks,
11807
+ aq as startSubAgent,
11572
11808
  subscribeConfigChange,
11573
- ar as toToolCallView,
11574
- as as toolRefusal,
11575
- at as unregisterSegmentRenderer,
11809
+ as as toToolCallView,
11810
+ at as toolRefusal,
11811
+ au as unregisterSegmentRenderer,
11576
11812
  uuid,
11577
- av as withoutAbandonedTurns
11813
+ aw as withoutAbandonedTurns
11578
11814
  };
11579
11815
  //# sourceMappingURL=index.js.map