@aparte/core 1.6.0 → 1.8.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 (61) hide show
  1. package/dist/client/aparte-client.d.ts +8 -0
  2. package/dist/client/aparte-client.d.ts.map +1 -1
  3. package/dist/client/stream-adapter.d.ts +20 -0
  4. package/dist/client/stream-adapter.d.ts.map +1 -1
  5. package/dist/client/wire-history.d.ts +2 -0
  6. package/dist/client/wire-history.d.ts.map +1 -1
  7. package/dist/components/bubble/aparte-chat-bubble.d.ts +14 -0
  8. package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
  9. package/dist/components/conversation-list/aparte-conversation-list.d.ts +46 -22
  10. package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -1
  11. package/dist/components/viewport/aparte-chat-viewport.d.ts +5 -0
  12. package/dist/components/viewport/aparte-chat-viewport.d.ts.map +1 -1
  13. package/dist/config/aparte-config.d.ts +44 -1
  14. package/dist/config/aparte-config.d.ts.map +1 -1
  15. package/dist/config/bubble-shell-renderer.d.ts +3 -0
  16. package/dist/config/bubble-shell-renderer.d.ts.map +1 -1
  17. package/dist/config/index.d.ts +1 -1
  18. package/dist/config/index.d.ts.map +1 -1
  19. package/dist/config/locale.d.ts +7 -0
  20. package/dist/config/locale.d.ts.map +1 -1
  21. package/dist/custom-elements.json +723 -71
  22. package/dist/{defer-hydration-W4yhnyfc.js → defer-hydration-BE2ToXC_.js} +452 -202
  23. package/dist/defer-hydration-BE2ToXC_.js.map +1 -0
  24. package/dist/elicitation/panel.d.ts.map +1 -1
  25. package/dist/host/aparte-chat-host.d.ts +8 -0
  26. package/dist/host/aparte-chat-host.d.ts.map +1 -1
  27. package/dist/index.css +1 -1
  28. package/dist/index.d.ts +6 -2
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +241 -181
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.node.d.ts +6 -2
  33. package/dist/index.node.d.ts.map +1 -1
  34. package/dist/index.node.js +52 -47
  35. package/dist/index.node.js.map +1 -1
  36. package/dist/kit-keyboard-BUSLQ5i4.js +434 -0
  37. package/dist/kit-keyboard-BUSLQ5i4.js.map +1 -0
  38. package/dist/renderers/segment-renderers.d.ts.map +1 -1
  39. package/dist/renderers/segments/activity.d.ts +5 -0
  40. package/dist/renderers/segments/activity.d.ts.map +1 -0
  41. package/dist/renderers/segments/tool-call.d.ts.map +1 -1
  42. package/dist/transport/agent-handler.d.ts +7 -0
  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 +62 -1
  51. package/dist/types/segments.d.ts.map +1 -1
  52. package/dist/types/tools.d.ts +46 -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/segments.d.ts +2 -0
  57. package/dist/utils/segments.d.ts.map +1 -1
  58. package/dist/utils/tabs.d.ts +49 -0
  59. package/dist/utils/tabs.d.ts.map +1 -0
  60. package/package.json +2 -2
  61. package/dist/defer-hydration-W4yhnyfc.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import { runSubAgent as runSubAgent$1, startSubAgent as startSubAgent$1, toolRefusal as toolRefusal$1, unansweredTail, runStreamAgent } from "@aparte/engine";
2
+ import { c as cssEscape, b as enhanceTabs, d as eventOrigin, r as rootOf } from "./kit-keyboard-BUSLQ5i4.js";
2
3
  import { A as APARTE_ICON_GLYPHS } from "./glyphs-LolG04CC.js";
3
4
  function contentToText(content) {
4
5
  if (typeof content === "string") return content;
@@ -131,6 +132,7 @@ const APARTE_DEFAULT_LOCALE = {
131
132
  checkpointPending: "Summarising the context…",
132
133
  checkpointFailed: "Couldn't summarise the context",
133
134
  toolRunning: "Running",
135
+ toolQueued: "Queued",
134
136
  toolCompleted: "Done",
135
137
  toolRejected: "Rejected",
136
138
  toolStopped: "Stopped",
@@ -1102,8 +1104,9 @@ function stampSegmentOnInsert(segments, segment, messageId, defaults) {
1102
1104
  };
1103
1105
  }
1104
1106
  function adoptSegment(segments, segment, messageId, live2 = false) {
1107
+ const { queued: _live, ...rest } = segment;
1105
1108
  return {
1106
- ...segment,
1109
+ ...rest,
1107
1110
  messageId,
1108
1111
  index: segments.length,
1109
1112
  isStreaming: false,
@@ -3224,6 +3227,7 @@ function stateBadge(segment) {
3224
3227
  const status = segment.status ?? "pending";
3225
3228
  const word = (text) => escapeHtml(text);
3226
3229
  if (status === "awaiting-approval") return `${cfg.getIcon("pause")}${word(cfg.t("approvalWaiting"))}`;
3230
+ if (isQueued(segment)) return word(cfg.t("toolQueued"));
3227
3231
  if (status === "pending") return word(cfg.t("toolRunning"));
3228
3232
  if (status === "resolved") return `${cfg.getIcon("check")}${word(cfg.t("toolCompleted"))}`;
3229
3233
  if (status === "rejected") return `${cfg.getIcon("close")}${word(cfg.t("toolRejected"))}`;
@@ -3265,28 +3269,43 @@ function outcomeOf(segment) {
3265
3269
  if (segment.status === "rejected" && segment.refusal) return null;
3266
3270
  return { key: "toolOutput", text };
3267
3271
  }
3268
- function behindOf(segment, line) {
3272
+ function behindOf(segment, line, row) {
3269
3273
  const display = contextConfig().getToolDisplay(segment.toolCall?.name ?? "");
3270
3274
  const details = display && "details" in display ? display.details : line?.details;
3271
3275
  if (details === false) return { kind: "none" };
3272
3276
  if (typeof details !== "function") return { kind: "parts" };
3273
3277
  try {
3274
- const out = details(segment);
3278
+ const out = details(segment, row ? heldBy(row) : void 0);
3275
3279
  if (!out) return { kind: "none" };
3276
3280
  return { kind: "body", body: typeof out === "string" ? contextConfig().sanitizeHtml(out) : out };
3277
3281
  } catch {
3278
3282
  return { kind: "none" };
3279
3283
  }
3280
3284
  }
3281
- const appDetailOf = (element) => element.querySelector(':scope > .aparte-tool-detail[data-details="app"]');
3285
+ function disclosureOf(row) {
3286
+ if (row.tagName === "DETAILS") return row;
3287
+ return row.querySelector(":scope > details.aparte-tool-disclosure");
3288
+ }
3289
+ const appDetailOf = (element) => element.querySelector(':scope > .aparte-tool-detail[data-details="app"], :scope > .aparte-tool-disclosure > .aparte-tool-detail[data-details="app"]');
3282
3290
  function setBody(element, body) {
3283
3291
  const detail = element.querySelector(".aparte-tool-detail");
3284
3292
  if (!detail) return;
3285
3293
  if (typeof body !== "string" && body.parentNode === detail) return;
3286
- if (typeof body === "string") detail.innerHTML = body;
3287
- else detail.replaceChildren(body);
3294
+ if (typeof body === "string") {
3295
+ detail.innerHTML = body;
3296
+ heldBodies.delete(detail);
3297
+ } else {
3298
+ detail.replaceChildren(body);
3299
+ heldBodies.set(detail, body);
3300
+ }
3288
3301
  drawnBodies.set(detail, serialized(body));
3289
3302
  }
3303
+ const heldBodies = /* @__PURE__ */ new WeakMap();
3304
+ function heldBy(row) {
3305
+ const detail = appDetailOf(row);
3306
+ const body = detail ? heldBodies.get(detail) : void 0;
3307
+ return body && body.parentNode === detail ? body : void 0;
3308
+ }
3290
3309
  const drawnBodies = /* @__PURE__ */ new WeakMap();
3291
3310
  const serialized = (body) => typeof body === "string" ? body : body.outerHTML;
3292
3311
  function relabelBody(detail, body) {
@@ -3303,7 +3322,11 @@ function relabelBody(detail, body) {
3303
3322
  const prev = document.createElement("div");
3304
3323
  if (before !== void 0) prev.innerHTML = before;
3305
3324
  if (before !== void 0 && sameShape(prev, next) && sameShape(prev, detail)) patchChanges(detail, prev, next);
3306
- else detail.replaceChildren(...Array.from(next.childNodes));
3325
+ else {
3326
+ detail.replaceChildren(...Array.from(next.childNodes));
3327
+ if (typeof body === "string") heldBodies.delete(detail);
3328
+ else heldBodies.set(detail, body);
3329
+ }
3307
3330
  drawnBodies.set(detail, now);
3308
3331
  }
3309
3332
  function sameShape(a, b) {
@@ -3448,18 +3471,21 @@ function iconOf(segment) {
3448
3471
  return (key ? cfg.getIcon(key) : void 0) || cfg.getIcon("tool");
3449
3472
  }
3450
3473
  const isQuiet = (segment) => contextConfig().getToolDisplay(segment.toolCall?.name ?? "")?.quiet ?? true;
3474
+ const isQueued = (segment) => (segment.status ?? "pending") === "pending" && (segment.queued === true || segment.deferred?.reason === "queued");
3451
3475
  function quietOf(segment) {
3452
3476
  const status = segment.status ?? "pending";
3453
3477
  const quiet = isQuiet(segment);
3478
+ const running = status === "pending" && !isQueued(segment);
3454
3479
  return {
3455
- shimmer: quiet && status === "pending",
3456
- spinner: !quiet && status === "pending",
3457
- stateHidden: quiet && (status === "pending" || status === "resolved")
3480
+ shimmer: quiet && running,
3481
+ spinner: !quiet && running,
3482
+ stateHidden: quiet && (running || status === "resolved")
3458
3483
  };
3459
3484
  }
3460
3485
  function setQuiet(element, segment) {
3461
3486
  const quiet = quietOf(segment);
3462
3487
  element.toggleAttribute("data-quiet", isQuiet(segment));
3488
+ element.toggleAttribute("data-queued", isQueued(segment));
3463
3489
  element.querySelector(".aparte-tool-spinner")?.toggleAttribute("hidden", !quiet.spinner);
3464
3490
  element.querySelector(".aparte-tool-name")?.classList.toggle("aparte-shimmer", quiet.shimmer);
3465
3491
  element.querySelector(".aparte-tool-state")?.classList.toggle("aparte-sr-only", quiet.stateHidden);
@@ -3471,7 +3497,70 @@ function setName(element, segment, line) {
3471
3497
  if (el2.textContent !== text) el2.textContent = text;
3472
3498
  el2.classList.toggle("aparte-tool-name--label", isLabel);
3473
3499
  }
3474
- function pillMarkup(segment, line) {
3500
+ const opens = /* @__PURE__ */ new WeakMap();
3501
+ function openOf(line) {
3502
+ const open = line?.open;
3503
+ return open && typeof open.onOpen === "function" ? open : void 0;
3504
+ }
3505
+ function openAttrs(line) {
3506
+ const open = openOf(line);
3507
+ return open ? ` data-opens${open.current ? " data-current" : ""}` : "";
3508
+ }
3509
+ function openMarkup(line) {
3510
+ const open = openOf(line);
3511
+ if (!open) return "";
3512
+ const label = escapeAttr(typeof open.label === "string" ? open.label.trim() : "");
3513
+ const icon = contextConfig().getIcon("maximize");
3514
+ return `<button type="button" class="aparte-btn aparte-btn--icon aparte-btn--sm aparte-tool-open" aria-label="${label}" title="${label}"${open.current ? ' aria-current="true"' : ""}>${icon}</button>`;
3515
+ }
3516
+ function setOpen(row, line, structural) {
3517
+ const open = openOf(line);
3518
+ const lineEl = row.querySelector(":scope > .aparte-tool-line");
3519
+ let button = row.querySelector(":scope > :is(.aparte-tool-line, .aparte-tool-open-slot) > .aparte-tool-open");
3520
+ if (open) opens.set(row, open);
3521
+ else opens.delete(row);
3522
+ if (structural && lineEl && !!open !== !!button) {
3523
+ if (button) {
3524
+ button.remove();
3525
+ button = null;
3526
+ } else {
3527
+ const tpl = document.createElement("template");
3528
+ tpl.innerHTML = openMarkup(line);
3529
+ button = tpl.content.firstElementChild;
3530
+ lineEl.insertBefore(button, lineEl.querySelector(":scope > .aparte-tool-activity"));
3531
+ }
3532
+ }
3533
+ row.toggleAttribute("data-opens", !!open && !!button);
3534
+ row.toggleAttribute("data-current", !!open?.current && !!button);
3535
+ if (!open || !button) return;
3536
+ const label = typeof open.label === "string" ? open.label.trim() : "";
3537
+ if (button.getAttribute("aria-label") !== label) {
3538
+ button.setAttribute("aria-label", label);
3539
+ button.title = label;
3540
+ }
3541
+ if (open.current) button.setAttribute("aria-current", "true");
3542
+ else button.removeAttribute("aria-current");
3543
+ }
3544
+ const wiredOpen = /* @__PURE__ */ new WeakSet();
3545
+ function wireOpen(row) {
3546
+ if (wiredOpen.has(row)) return;
3547
+ wiredOpen.add(row);
3548
+ row.addEventListener("click", (event) => {
3549
+ const open = opens.get(row);
3550
+ const target = event.target;
3551
+ if (!open || !target?.closest || target.closest(".aparte-segment-tool-call") !== row) return;
3552
+ if (!target.closest(".aparte-tool-open")) {
3553
+ if (disclosureOf(row) || target.closest(".aparte-tool-line")?.parentElement !== row) return;
3554
+ if (row.ownerDocument.getSelection?.()?.isCollapsed === false) return;
3555
+ }
3556
+ try {
3557
+ open.onOpen(row);
3558
+ } catch (err) {
3559
+ console.error("[aparte] a tool line's onOpen threw", err);
3560
+ }
3561
+ });
3562
+ }
3563
+ function pillMarkup(segment, line, withOpen = true) {
3475
3564
  const badge = stateBadge(segment);
3476
3565
  const icon = iconOf(segment);
3477
3566
  const target = toolTarget(segment, line);
@@ -3479,6 +3568,7 @@ function pillMarkup(segment, line) {
3479
3568
  const note = noteOf(segment, line);
3480
3569
  const name = nameOf(segment, line);
3481
3570
  const quiet = quietOf(segment);
3571
+ const open = withOpen ? openMarkup(line) : "";
3482
3572
  return `
3483
3573
  <span class="aparte-tool-label">
3484
3574
  <span class="aparte-tool-icon">${icon}</span>
@@ -3487,20 +3577,20 @@ function pillMarkup(segment, line) {
3487
3577
  </span>
3488
3578
  <span class="aparte-spinner aparte-tool-spinner" aria-hidden="true"${quiet.spinner ? "" : " hidden"}></span>
3489
3579
  <span class="aparte-tool-state${quiet.stateHidden ? " aparte-sr-only" : ""}">${badge}</span>
3490
- <span class="aparte-tool-note"${note ? ` title="${escapeAttr(note)}"` : " hidden"}>${escapeHtml(note)}</span>
3580
+ <span class="aparte-tool-note"${note ? ` title="${escapeAttr(note)}"` : " hidden"}>${escapeHtml(note)}</span>${open}
3491
3581
  <span class="aparte-tool-activity"${activity ? "" : " hidden"}>${escapeHtml(activity)}</span>`;
3492
3582
  }
3493
3583
  function placeholderMarkup(segment) {
3494
3584
  return `<div class="aparte-segment aparte-segment-tool-call" data-segment-id="${escapeHtml(segment.id)}" data-status="${escapeAttr(segment.status ?? "pending")}" data-tool-call-id="${escapeAttr(segment.toolCall?.id ?? "")}" data-tool-name="${escapeAttr(segment.toolCall?.name ?? "tool")}" hidden></div>`;
3495
3585
  }
3496
- const isPlaceholder = (element) => element.hidden && element.classList.contains("aparte-segment-tool-call") && element.childElementCount === 0;
3497
- const drawnBy = /* @__PURE__ */ new WeakMap();
3498
- const behind = /* @__PURE__ */ new WeakMap();
3586
+ const isPlaceholder$1 = (element) => element.hidden && element.classList.contains("aparte-segment-tool-call") && element.childElementCount === 0;
3587
+ const drawnBy$1 = /* @__PURE__ */ new WeakMap();
3588
+ const behind$1 = /* @__PURE__ */ new WeakMap();
3499
3589
  function toolRendererThatDrew(element) {
3500
- return behind.get(element) ?? null;
3590
+ return behind$1.get(element) ?? null;
3501
3591
  }
3502
3592
  function drawerOf(element, current) {
3503
- const recorded = drawnBy.get(element);
3593
+ const recorded = drawnBy$1.get(element);
3504
3594
  if (recorded) return recorded;
3505
3595
  return element.classList.contains("aparte-segment-tool-call") ? null : current;
3506
3596
  }
@@ -3509,33 +3599,39 @@ function drawDefault(segment, behind2, line) {
3509
3599
  const status = segment.status ?? "pending";
3510
3600
  const toolCallId = segment.toolCall?.id ?? "";
3511
3601
  const pill = pillMarkup(segment, line);
3512
- const quiet = isQuiet(segment) ? " data-quiet" : "";
3602
+ const quiet = (isQuiet(segment) ? " data-quiet" : "") + (isQueued(segment) ? " data-queued" : "");
3603
+ const opensAt = openAttrs(line);
3513
3604
  const toggle = contextConfig().getIcon("expand");
3514
3605
  const input = behind2.kind === "parts" ? describeInput(segment) : "";
3515
3606
  const outcome = behind2.kind === "parts" ? outcomeOf(segment) : null;
3516
3607
  if (behind2.kind === "none" || behind2.kind === "parts" && !input && !outcome) {
3517
3608
  return `
3518
- <div class="aparte-segment aparte-segment-tool-call" data-segment-id="${escapeHtml(segment.id)}" data-status="${escapeAttr(status)}" data-tool-call-id="${escapeAttr(toolCallId)}" data-tool-name="${escapeAttr(name)}"${quiet}><div class="aparte-tool-line">${pill}</div>
3609
+ <div class="aparte-segment aparte-segment-tool-call" data-segment-id="${escapeHtml(segment.id)}" data-status="${escapeAttr(status)}" data-tool-call-id="${escapeAttr(toolCallId)}" data-tool-name="${escapeAttr(name)}"${quiet}${opensAt}><div class="aparte-tool-line">${pill}</div>
3519
3610
  </div>
3520
3611
  `;
3521
3612
  }
3522
3613
  const cfg = contextConfig();
3523
3614
  const copy = copyButtonMarkup("aparte-tool-copy");
3524
3615
  const open = segment.collapsed !== void 0 ? !segment.collapsed : cfg.getToolDisplay(name)?.open === true;
3616
+ const openButton = openMarkup(line);
3617
+ const disclosure = openButton ? `<details class="aparte-tool-disclosure"${open ? " open" : ""}>` : "";
3618
+ const rowStart = openButton ? `<div class="aparte-segment aparte-segment-tool-call" data-segment-id="${escapeHtml(segment.id)}" data-status="${escapeAttr(status)}" data-tool-call-id="${escapeAttr(toolCallId)}" data-tool-name="${escapeAttr(name)}"${quiet}${opensAt}>${disclosure}` : `<details class="aparte-segment aparte-segment-tool-call" data-segment-id="${escapeHtml(segment.id)}" data-status="${escapeAttr(status)}" data-tool-call-id="${escapeAttr(toolCallId)}" data-tool-name="${escapeAttr(name)}"${quiet}${opensAt}${open ? " open" : ""}>`;
3619
+ const rowEnd = openButton ? `</details><span class="aparte-tool-open-slot">${openButton}</span></div>` : "</details>";
3620
+ const summaryPill = pillMarkup(segment, line, false);
3525
3621
  if (behind2.kind === "body") {
3526
3622
  const tpl = document.createElement("template");
3527
3623
  tpl.innerHTML = `
3528
- <details class="aparte-segment aparte-segment-tool-call" data-segment-id="${escapeHtml(segment.id)}" data-status="${escapeAttr(status)}" data-tool-call-id="${escapeAttr(toolCallId)}" data-tool-name="${escapeAttr(name)}"${quiet}${open ? " open" : ""}>
3529
- <summary class="aparte-tool-summary"><span class="aparte-tool-toggle">${toggle}</span>${pill}</summary>
3624
+ ${rowStart}
3625
+ <summary class="aparte-tool-summary"><span class="aparte-tool-toggle">${toggle}</span>${summaryPill}</summary>
3530
3626
  <div class="aparte-tool-detail" data-details="app"></div>
3531
- </details>`.trim();
3627
+ ${rowEnd}`.trim();
3532
3628
  const row = tpl.content.firstElementChild;
3533
3629
  setBody(row, behind2.body);
3534
3630
  return row;
3535
3631
  }
3536
3632
  return `
3537
- <details class="aparte-segment aparte-segment-tool-call" data-segment-id="${escapeHtml(segment.id)}" data-status="${escapeAttr(status)}" data-tool-call-id="${escapeAttr(toolCallId)}" data-tool-name="${escapeAttr(name)}"${quiet}${open ? " open" : ""}>
3538
- <summary class="aparte-tool-summary"><span class="aparte-tool-toggle">${toggle}</span>${pill}</summary>
3633
+ ${rowStart}
3634
+ <summary class="aparte-tool-summary"><span class="aparte-tool-toggle">${toggle}</span>${summaryPill}</summary>
3539
3635
  <div class="aparte-tool-detail">
3540
3636
  ${input ? `
3541
3637
  <div class="aparte-tool-part" data-part="input">
@@ -3548,7 +3644,7 @@ function drawDefault(segment, behind2, line) {
3548
3644
  <div class="aparte-tool-part-body" role="region" tabindex="0" aria-label="${escapeAttr(cfg.t(outcome.key))}"><pre><code>${escapeHtml(outcome.text)}</code></pre></div>
3549
3645
  </div>` : ""}
3550
3646
  </div>
3551
- </details>
3647
+ ${rowEnd}
3552
3648
  `;
3553
3649
  }
3554
3650
  const toolCallRenderer = {
@@ -3561,8 +3657,8 @@ const toolCallRenderer = {
3561
3657
  injectToolRendererStyles(name, customRenderer);
3562
3658
  const out = customRenderer.render(segment);
3563
3659
  if (out instanceof HTMLElement) {
3564
- drawnBy.set(out, customRenderer);
3565
- behind.set(out, customRenderer);
3660
+ drawnBy$1.set(out, customRenderer);
3661
+ behind$1.set(out, customRenderer);
3566
3662
  }
3567
3663
  return out || placeholderMarkup(segment);
3568
3664
  }
@@ -3580,7 +3676,7 @@ const toolCallRenderer = {
3580
3676
  * No child node is added or removed, per the relabel contract.
3581
3677
  */
3582
3678
  relabel: (element, segment) => {
3583
- if (isPlaceholder(element)) return;
3679
+ if (isPlaceholder$1(element)) return;
3584
3680
  const cfg = contextConfig();
3585
3681
  const custom = drawerOf(element, cfg.getToolRenderer(segment.toolCall?.name) ?? null);
3586
3682
  if (custom) {
@@ -3594,6 +3690,7 @@ const toolCallRenderer = {
3594
3690
  setTarget(element, segment, line);
3595
3691
  setActivity(element, segment, line);
3596
3692
  setNote(element, segment, line);
3693
+ setOpen(element, line, false);
3597
3694
  const inputLabel = element.querySelector('[data-part="input"] .aparte-tool-part-label');
3598
3695
  if (inputLabel) inputLabel.textContent = cfg.t("toolInput");
3599
3696
  element.querySelector('[data-part="input"] .aparte-tool-part-body')?.setAttribute("aria-label", cfg.t("toolInput"));
@@ -3604,7 +3701,7 @@ const toolCallRenderer = {
3604
3701
  for (const button of element.querySelectorAll(".aparte-tool-copy")) relabelCopyButton(button);
3605
3702
  const appDetail = appDetailOf(element);
3606
3703
  if (appDetail) {
3607
- const behind2 = behindOf(segment, line);
3704
+ const behind2 = behindOf(segment, line, element);
3608
3705
  if (behind2.kind === "body") relabelBody(appDetail, behind2.body);
3609
3706
  }
3610
3707
  const statusEl = element.querySelector(".aparte-tool-state");
@@ -3627,13 +3724,13 @@ const toolCallRenderer = {
3627
3724
  update: (element, segment) => {
3628
3725
  const status = segment.status ?? "pending";
3629
3726
  const hidden = contextConfig().isToolHidden(segment.toolCall?.name ?? "tool");
3630
- if (hidden && isPlaceholder(element)) {
3727
+ if (hidden && isPlaceholder$1(element)) {
3631
3728
  element.setAttribute("data-status", status);
3632
3729
  return;
3633
3730
  }
3634
3731
  const custom = hidden ? null : contextConfig().getToolRenderer(segment.toolCall?.name) ?? null;
3635
- const drawn2 = isPlaceholder(element) ? null : drawerOf(element, custom);
3636
- if (drawn2 && drawn2 === custom && drawn2.update && !isPlaceholder(element)) {
3732
+ const drawn2 = isPlaceholder$1(element) ? null : drawerOf(element, custom);
3733
+ if (drawn2 && drawn2 === custom && drawn2.update && !isPlaceholder$1(element)) {
3637
3734
  drawn2.update(element, segment);
3638
3735
  return;
3639
3736
  }
@@ -3647,19 +3744,25 @@ const toolCallRenderer = {
3647
3744
  element.replaceWith(rebuilt);
3648
3745
  toolCallRenderer.setup?.(rebuilt, segment);
3649
3746
  }
3747
+ return rebuilt;
3650
3748
  };
3651
- if (custom || drawn2 || hidden || isPlaceholder(element)) {
3749
+ if (custom || drawn2 || hidden || isPlaceholder$1(element)) {
3652
3750
  rebuild(toolCallRenderer.render(segment));
3653
3751
  return;
3654
3752
  }
3655
3753
  const line = toolLineOf(segment, contextConfig());
3656
- const behind2 = behindOf(segment, line);
3754
+ const behind2 = behindOf(segment, line, element);
3657
3755
  const input = behind2.kind === "parts" ? describeInput(segment) : "";
3658
3756
  const outcome = behind2.kind === "parts" ? outcomeOf(segment) : null;
3659
3757
  const wantsDetail = behind2.kind === "body" || !!input || !!outcome;
3660
3758
  const holdsAppDetail = !!appDetailOf(element);
3661
- if (wantsDetail !== (element.tagName === "DETAILS") || wantsDetail && behind2.kind === "body" !== holdsAppDetail) {
3662
- rebuild(drawDefault(segment, behind2, line));
3759
+ const disclosure = disclosureOf(element);
3760
+ const wrapped = !!disclosure && disclosure !== element;
3761
+ if (wantsDetail !== !!disclosure || wantsDetail && behind2.kind === "body" !== holdsAppDetail || wantsDetail && wrapped !== !!openOf(line)) {
3762
+ const wasOpen = disclosure?.open;
3763
+ const now = rebuild(drawDefault(segment, behind2, line));
3764
+ const next = now && wasOpen !== void 0 ? disclosureOf(now) : null;
3765
+ if (next && wasOpen !== void 0) next.open = wasOpen;
3663
3766
  return;
3664
3767
  }
3665
3768
  element.setAttribute("data-status", status);
@@ -3670,6 +3773,7 @@ const toolCallRenderer = {
3670
3773
  setTarget(element, segment, line);
3671
3774
  setActivity(element, segment, line);
3672
3775
  setNote(element, segment, line);
3776
+ setOpen(element, line, true);
3673
3777
  if (behind2.kind === "body") {
3674
3778
  setBody(element, behind2.body);
3675
3779
  return;
@@ -3681,11 +3785,15 @@ const toolCallRenderer = {
3681
3785
  setup: (element, segment) => {
3682
3786
  const hidden = contextConfig().isToolHidden(segment.toolCall?.name ?? "tool");
3683
3787
  const customRenderer = hidden ? void 0 : contextConfig().getToolRenderer(segment.toolCall?.name);
3684
- if (customRenderer) behind.set(element, customRenderer);
3685
- if (isPlaceholder(element)) return;
3788
+ if (customRenderer) behind$1.set(element, customRenderer);
3789
+ if (isPlaceholder$1(element)) return;
3790
+ if (!customRenderer) {
3791
+ setOpen(element, toolLineOf(segment, contextConfig()), false);
3792
+ wireOpen(element);
3793
+ }
3686
3794
  wireParts(element);
3687
3795
  highlightParts(element);
3688
- if (customRenderer) drawnBy.set(element, customRenderer);
3796
+ if (customRenderer) drawnBy$1.set(element, customRenderer);
3689
3797
  customRenderer?.setup?.(element, segment);
3690
3798
  },
3691
3799
  /**
@@ -3694,10 +3802,10 @@ const toolCallRenderer = {
3694
3802
  * all the same, and the stream that caused it is not interrupted.
3695
3803
  */
3696
3804
  cleanup: (element, segment) => {
3697
- behind.delete(element);
3698
- const custom = drawnBy.get(element);
3805
+ behind$1.delete(element);
3806
+ const custom = drawnBy$1.get(element);
3699
3807
  if (!custom) return;
3700
- drawnBy.delete(element);
3808
+ drawnBy$1.delete(element);
3701
3809
  try {
3702
3810
  custom.cleanup?.(element, segment);
3703
3811
  } catch (err) {
@@ -3709,6 +3817,88 @@ const toolCallRenderer = {
3709
3817
  // has no other way onto the page.
3710
3818
  getStyles: () => ""
3711
3819
  };
3820
+ function placeholder(segment) {
3821
+ const el2 = document.createElement("div");
3822
+ el2.className = "aparte-segment aparte-segment-activity";
3823
+ el2.setAttribute("data-segment-id", segment.id);
3824
+ el2.setAttribute("data-activity-type", segment.activityType);
3825
+ el2.hidden = true;
3826
+ return el2;
3827
+ }
3828
+ const isPlaceholder = (element) => element.hidden && element.classList.contains("aparte-segment-activity") && element.childElementCount === 0;
3829
+ const drawnBy = /* @__PURE__ */ new WeakMap();
3830
+ const behind = /* @__PURE__ */ new WeakMap();
3831
+ function activityRendererThatDrew(element) {
3832
+ return behind.get(element) ?? null;
3833
+ }
3834
+ const rendererOf = (segment) => contextConfig().getActivityRenderer(segment.activityType) ?? null;
3835
+ const activityRenderer = {
3836
+ type: "activity",
3837
+ render: (segment) => {
3838
+ const custom = rendererOf(segment);
3839
+ if (!custom) return placeholder(segment);
3840
+ const out = custom.render(segment);
3841
+ if (out instanceof HTMLElement) {
3842
+ drawnBy.set(out, custom);
3843
+ behind.set(out, custom);
3844
+ return out;
3845
+ }
3846
+ return out.trim() ? out : placeholder(segment);
3847
+ },
3848
+ setup: (element, segment) => {
3849
+ const custom = rendererOf(segment);
3850
+ if (!custom) return;
3851
+ behind.set(element, custom);
3852
+ if (isPlaceholder(element)) return;
3853
+ drawnBy.set(element, custom);
3854
+ custom.setup?.(element, segment);
3855
+ },
3856
+ /**
3857
+ * The agent sent it again. The renderer that drew it patches it, when it can and is still
3858
+ * the one registered; otherwise it is drawn again here, and the bubble follows the element.
3859
+ */
3860
+ update: (element, segment) => {
3861
+ const custom = rendererOf(segment);
3862
+ const drawn2 = drawnBy.get(element) ?? null;
3863
+ if (drawn2 && drawn2 === custom && drawn2.update) {
3864
+ drawn2.update(element, segment);
3865
+ return;
3866
+ }
3867
+ if (!custom && !drawn2 && isPlaceholder(element)) {
3868
+ element.setAttribute("data-activity-type", segment.activityType);
3869
+ return;
3870
+ }
3871
+ const out = activityRenderer.render(segment);
3872
+ let rebuilt;
3873
+ if (typeof out === "string") {
3874
+ const tpl = document.createElement("template");
3875
+ tpl.innerHTML = out.trim();
3876
+ rebuilt = tpl.content.firstElementChild;
3877
+ } else {
3878
+ rebuilt = out;
3879
+ }
3880
+ if (!rebuilt) return;
3881
+ if (!rebuilt.hasAttribute("data-segment-id")) rebuilt.setAttribute("data-segment-id", segment.id);
3882
+ activityRenderer.cleanup?.(element, segment);
3883
+ element.replaceWith(rebuilt);
3884
+ activityRenderer.setup?.(rebuilt, segment);
3885
+ },
3886
+ relabel: (element, segment) => {
3887
+ drawnBy.get(element)?.relabel?.(element, segment);
3888
+ },
3889
+ /** The element leaves for good: the renderer that drew it cleans up. A cleanup that throws is reported, nothing more. */
3890
+ cleanup: (element, segment) => {
3891
+ behind.delete(element);
3892
+ const custom = drawnBy.get(element);
3893
+ if (!custom) return;
3894
+ drawnBy.delete(element);
3895
+ try {
3896
+ custom.cleanup?.(element, segment);
3897
+ } catch (err) {
3898
+ console.error("[aparte] an activity renderer's cleanup threw", err);
3899
+ }
3900
+ }
3901
+ };
3712
3902
  const registries = /* @__PURE__ */ new WeakMap();
3713
3903
  function registryFor(config) {
3714
3904
  let reg = registries.get(config);
@@ -3847,7 +4037,8 @@ const DEFAULT_RENDERERS = [
3847
4037
  thinkingRenderer,
3848
4038
  codeRenderer,
3849
4039
  errorRenderer,
3850
- toolCallRenderer
4040
+ toolCallRenderer,
4041
+ activityRenderer
3851
4042
  ];
3852
4043
  const toolRefusal = toolRefusal$1;
3853
4044
  const runSubAgent = runSubAgent$1;
@@ -3858,9 +4049,11 @@ function createStreamAdapter(opts) {
3858
4049
  let streaming = /* @__PURE__ */ new Set();
3859
4050
  let thinkingId = null;
3860
4051
  const toolSegments = /* @__PURE__ */ new Map();
4052
+ const queued = /* @__PURE__ */ new Set();
4053
+ const unqueued = (id, update) => queued.delete(id) ? { ...update, queued: void 0 } : update;
3861
4054
  const settle = (toolCallId, update) => {
3862
4055
  const id = `tool-${toolCallId}`;
3863
- target.updateSegment?.(id, toolSegments.has(id) ? update : { ...update, deferred: void 0 });
4056
+ target.updateSegment?.(id, unqueued(id, toolSegments.has(id) ? update : { ...update, deferred: void 0 }));
3864
4057
  };
3865
4058
  let thinkingContent = "";
3866
4059
  let thinkingCollapsed = false;
@@ -3882,20 +4075,20 @@ function createStreamAdapter(opts) {
3882
4075
  return { id, text, start, length: content.length, citations: [] };
3883
4076
  }).filter((s) => s.text);
3884
4077
  if (spans.length === 0) return;
3885
- const placed = /* @__PURE__ */ new Set();
4078
+ const placed2 = /* @__PURE__ */ new Set();
3886
4079
  for (const citation of callCitations) {
3887
4080
  const span = spans.find((s) => s.start >= 0 && citation.end > s.start && citation.end <= s.start + s.length);
3888
4081
  if (!span) continue;
3889
4082
  const end = citation.end - span.start;
3890
4083
  const start = citation.start === void 0 ? void 0 : Math.max(0, Math.min(end, citation.start - span.start));
3891
4084
  span.citations.push({ ...citation, end, ...start === void 0 ? {} : { start } });
3892
- for (const id of citation.sources) placed.add(id);
4085
+ for (const id of citation.sources) placed2.add(id);
3893
4086
  }
3894
4087
  const last = spans[spans.length - 1];
3895
4088
  const now = /* @__PURE__ */ new Set();
3896
4089
  for (const span of spans) {
3897
4090
  const named = new Set(span.citations.flatMap((c) => c.sources));
3898
- const sources2 = callSources.filter((s) => named.has(s.id) || span === last && !placed.has(s.id));
4091
+ const sources2 = callSources.filter((s) => named.has(s.id) || span === last && !placed2.has(s.id));
3899
4092
  if (sources2.length === 0) {
3900
4093
  if (given.has(span.id)) target.updateSegment?.(span.id, { sources: void 0, citations: void 0 });
3901
4094
  continue;
@@ -3912,8 +4105,47 @@ function createStreamAdapter(opts) {
3912
4105
  target.updateSegment?.(thinkingId, keepOpen ? { isStreaming: false } : { collapsed: true, isStreaming: false });
3913
4106
  thinkingCollapsed = true;
3914
4107
  };
4108
+ const steps = [];
4109
+ let shownStep = null;
4110
+ const showStep = () => {
4111
+ const next = steps.at(-1) ?? null;
4112
+ if (next === shownStep) return;
4113
+ shownStep = next;
4114
+ target.setStep?.(messageId, next);
4115
+ };
4116
+ const endSteps = () => {
4117
+ steps.length = 0;
4118
+ showStep();
4119
+ };
4120
+ const flushText = () => {
4121
+ const finals = parser.finalize();
4122
+ for (const s of finals) {
4123
+ noteText(s);
4124
+ if (!streaming.has(s.id)) target.addSegment?.(s);
4125
+ else if ("content" in s) target.updateSegment?.(s.id, segmentContentUpdate(s));
4126
+ }
4127
+ placeSources();
4128
+ };
4129
+ const activities = /* @__PURE__ */ new Set();
4130
+ const placed = (id) => {
4131
+ if (activities.has(id)) return true;
4132
+ const existing = target.getMessage ? target.getMessage(messageId)?.segments : target.segments;
4133
+ if (!existing?.some((s) => s.id === id)) return false;
4134
+ activities.add(id);
4135
+ return true;
4136
+ };
3915
4137
  const handle = (e) => {
3916
4138
  switch (e.type) {
4139
+ case "step-start":
4140
+ steps.push(e.name);
4141
+ showStep();
4142
+ break;
4143
+ case "step-end": {
4144
+ const at = steps.lastIndexOf(e.name);
4145
+ if (at >= 0) steps.splice(at, 1);
4146
+ showStep();
4147
+ break;
4148
+ }
3917
4149
  case "run-start":
3918
4150
  target.updateMessage?.(messageId, { status: "streaming" });
3919
4151
  break;
@@ -3972,14 +4204,19 @@ function createStreamAdapter(opts) {
3972
4204
  } else if (result.segments.length === 0) ;
3973
4205
  break;
3974
4206
  }
3975
- case "text-flush": {
3976
- const finals = parser.finalize();
3977
- for (const s of finals) {
3978
- noteText(s);
3979
- if (!streaming.has(s.id)) target.addSegment?.(s);
3980
- else if ("content" in s) target.updateSegment?.(s.id, segmentContentUpdate(s));
4207
+ case "text-flush":
4208
+ flushText();
4209
+ break;
4210
+ case "activity": {
4211
+ const id = `activity-${e.id}`;
4212
+ if (placed(id)) {
4213
+ target.updateSegment?.(id, { activityType: e.activityType, content: e.content });
4214
+ break;
3981
4215
  }
3982
- placeSources();
4216
+ activities.add(id);
4217
+ flushText();
4218
+ const segment = { id, type: "activity", activityId: e.id, activityType: e.activityType, content: e.content };
4219
+ target.addSegment?.(segment);
3983
4220
  break;
3984
4221
  }
3985
4222
  case "sources": {
@@ -4003,16 +4240,24 @@ function createStreamAdapter(opts) {
4003
4240
  id: `tool-${e.toolCallId}`,
4004
4241
  type: "tool_call",
4005
4242
  toolCall: { id: e.toolCallId, name: e.name, input: e.input },
4006
- status: "pending"
4243
+ status: "pending",
4244
+ // Read while it cannot go on yet: its row now, where the model wrote it.
4245
+ ...e.queued ? { queued: true } : {}
4007
4246
  };
4008
4247
  toolSegments.set(toolSeg.id, toolSeg);
4248
+ if (e.queued) queued.add(toolSeg.id);
4009
4249
  const renderer = config.getToolRenderer(e.name);
4010
4250
  if (renderer) injectToolRendererStyles(e.name, renderer);
4011
4251
  target.addSegment?.(toolSeg);
4012
4252
  break;
4013
4253
  }
4254
+ case "tool-running": {
4255
+ const id = `tool-${e.toolCallId}`;
4256
+ if (queued.delete(id)) target.updateSegment?.(id, { queued: void 0 });
4257
+ break;
4258
+ }
4014
4259
  case "tool-awaiting-approval":
4015
- target.updateSegment?.(`tool-${e.toolCallId}`, { status: "awaiting-approval" });
4260
+ target.updateSegment?.(`tool-${e.toolCallId}`, unqueued(`tool-${e.toolCallId}`, { status: "awaiting-approval" }));
4016
4261
  dispatchLifecycleEvent(target, "aparte-tool-approval-request", { toolCallId: e.toolCallId, toolName: e.name, input: e.input }, targetId);
4017
4262
  break;
4018
4263
  case "tool-approved":
@@ -4054,15 +4299,17 @@ function createStreamAdapter(opts) {
4054
4299
  }
4055
4300
  break;
4056
4301
  case "run-aborted":
4302
+ endSteps();
4057
4303
  dispatchLifecycleEvent(target, "aparte-message-aborted", { messageId }, targetId);
4058
4304
  break;
4059
4305
  case "run-suspended": {
4306
+ endSteps();
4060
4307
  const ticket = e.ticket;
4061
4308
  for (const p of e.pending) {
4062
4309
  if (p.agentId != null) continue;
4063
4310
  const id = `tool-${p.toolCallId}`;
4064
4311
  const deferred2 = { reason: p.reason, ...typeof ticket === "string" ? { ticket } : {} };
4065
- target.updateSegment?.(id, { deferred: deferred2 });
4312
+ target.updateSegment?.(id, unqueued(id, { deferred: deferred2 }));
4066
4313
  }
4067
4314
  target.updateMessage?.(messageId, { status: "completed" });
4068
4315
  if (e.usage) {
@@ -4075,6 +4322,7 @@ function createStreamAdapter(opts) {
4075
4322
  break;
4076
4323
  }
4077
4324
  case "run-done":
4325
+ endSteps();
4078
4326
  target.updateMessage?.(messageId, {
4079
4327
  status: "completed",
4080
4328
  ...e.finishReason ? { finishReason: e.finishReason } : {}
@@ -4369,6 +4617,7 @@ function createAparteAgentHandler(options) {
4369
4617
  if (!t) return void 0;
4370
4618
  return {
4371
4619
  ...t.tool.maxTurns !== void 0 ? { maxTurns: t.tool.maxTurns } : {},
4620
+ ...t.tool.parallel !== void 0 ? { parallel: t.tool.parallel } : {},
4372
4621
  needsApproval: (call) => {
4373
4622
  const ruling = rule(call);
4374
4623
  if (ruling?.verdict === "allow") return false;
@@ -4388,6 +4637,7 @@ function createAparteAgentHandler(options) {
4388
4637
  signal: run.signal,
4389
4638
  ...options.maxTurns !== void 0 ? { maxTurns: options.maxTurns } : {},
4390
4639
  ...options.toolTimeoutMs !== void 0 ? { toolTimeoutMs: options.toolTimeoutMs } : {},
4640
+ ...options.parallelTools !== void 0 ? { parallelTools: options.parallelTools } : {},
4391
4641
  // Ids that cannot repeat from one request to the next, as the browser
4392
4642
  // client mints them. The engine's default is a counter per run, and every
4393
4643
  // request is a run: the resume of a paused reply named its first sub-agent
@@ -5049,6 +5299,8 @@ class AparteConfig {
5049
5299
  /** Bumped by `reset()`: a restore function from before it must not undo what came after. */
5050
5300
  _overrideGeneration = 0;
5051
5301
  _toolDisplays = new ToolTable();
5302
+ /** By activity type — see {@link registerActivityRenderer}. */
5303
+ _activityRenderers = /* @__PURE__ */ new Map();
5052
5304
  /** What a plugin says about a call, read after the app's display — see {@link setToolLineProvider}. */
5053
5305
  _toolLineProvider = null;
5054
5306
  /** Tagged blocks the stream parser recognises in the prose — see {@link registerStreamBlock}. */
@@ -6184,6 +6436,45 @@ class AparteConfig {
6184
6436
  this._toolRenderers.delete(match);
6185
6437
  notifyRenderersChanged(this);
6186
6438
  }
6439
+ /**
6440
+ * Draw one type of agent activity — the structured progress an agent reports while it
6441
+ * works ("3 of 5 sources read"), which reaches the reply as an `activity` segment and is
6442
+ * updated in place each time the agent sends it again. Returns the function that takes
6443
+ * this renderer off again (it changes nothing once another one has replaced it).
6444
+ *
6445
+ * An activity with no renderer for its type is kept on the message and draws nothing:
6446
+ * no row, no room, no orphan header on a turn that holds nothing else. It is never sent
6447
+ * to the model either way. Activities already on screen follow a registration.
6448
+ *
6449
+ * @example
6450
+ * const off = aparteGlobalConfig.registerActivityRenderer('search-progress', {
6451
+ * render: (segment) => {
6452
+ * const el = document.createElement('p');
6453
+ * const { read, of } = segment.content as { read: number; of: number };
6454
+ * el.textContent = `${read} of ${of} sources read`;
6455
+ * return el;
6456
+ * },
6457
+ * update: (el, segment) => {
6458
+ * const { read, of } = segment.content as { read: number; of: number };
6459
+ * el.textContent = `${read} of ${of} sources read`;
6460
+ * },
6461
+ * });
6462
+ */
6463
+ registerActivityRenderer(activityType, renderer) {
6464
+ if (this._activityRenderers.get(activityType) !== renderer) {
6465
+ this._activityRenderers.set(activityType, renderer);
6466
+ notifyRenderersChanged(this);
6467
+ }
6468
+ return () => {
6469
+ if (this._activityRenderers.get(activityType) !== renderer) return;
6470
+ this._activityRenderers.delete(activityType);
6471
+ notifyRenderersChanged(this);
6472
+ };
6473
+ }
6474
+ /** The renderer registered for an activity type, or undefined. */
6475
+ getActivityRenderer(activityType) {
6476
+ return this._activityRenderers.get(activityType);
6477
+ }
6187
6478
  /** The renderer that draws a tool named `toolName` — exact, pattern or `'*'` — or undefined. */
6188
6479
  getToolRenderer(toolName) {
6189
6480
  return this._toolRenderers.resolve(toolName)?.value;
@@ -6600,6 +6891,7 @@ class AparteConfig {
6600
6891
  this._tools.clear();
6601
6892
  this._toolRenderers.clear();
6602
6893
  this._toolRendererOverrides.clear();
6894
+ this._activityRenderers.clear();
6603
6895
  this._overrideGeneration++;
6604
6896
  notifyRenderersChanged(this);
6605
6897
  this._toolDisplays.clear();
@@ -7310,9 +7602,6 @@ class AparteConversationManager {
7310
7602
  return (msg.content ?? "").trim();
7311
7603
  }
7312
7604
  }
7313
- function cssEscape(value) {
7314
- return value.replace(/["\\]/g, "\\$&").replace(/[\n\r\f]/g, (c) => `\\${c.charCodeAt(0).toString(16)} `);
7315
- }
7316
7605
  function filesToAttachments(files) {
7317
7606
  return files.map((file) => ({
7318
7607
  id: uuid(),
@@ -8036,6 +8325,8 @@ class AparteChatHost {
8036
8325
  options;
8037
8326
  /** Id of the assistant message currently streaming (null when idle). */
8038
8327
  _streamingId = null;
8328
+ /** The step the streaming reply is on: kept until its bubble is painted, never in the list. */
8329
+ _step = null;
8039
8330
  /**
8040
8331
  * The message object each bubble was last drawn from, by id (skip-rerender cache).
8041
8332
  *
@@ -8307,6 +8598,7 @@ class AparteChatHost {
8307
8598
  if (updates.status) {
8308
8599
  this._bubbleById(messageId)?.updateMessage?.({ status: updates.status });
8309
8600
  }
8601
+ if (this._step?.messageId === messageId && isTerminalStatus(merged.status)) this._step = null;
8310
8602
  if (index !== msgs.length - 1 && RENDERED_FIELDS.some((key) => key in updates)) {
8311
8603
  this._renderedIds.delete(messageId);
8312
8604
  const bubble = this._bubbleById(messageId);
@@ -8320,6 +8612,15 @@ class AparteChatHost {
8320
8612
  }
8321
8613
  }
8322
8614
  }
8615
+ /**
8616
+ * Say the step the agent is on in the reply's waiting indicator, or `null` for none. Live
8617
+ * only: never written into the message list. Kept for a bubble the framework has not
8618
+ * painted yet, and given to it when it is.
8619
+ */
8620
+ setStep(messageId, name) {
8621
+ this._step = name === null ? null : { messageId, name };
8622
+ this._bubbleById(messageId)?.setStep?.(name);
8623
+ }
8323
8624
  /** Append/replace the last message content (streaming text). */
8324
8625
  updateLastMessage(content, options) {
8325
8626
  if (options?.append) this.binding.onTypingChange?.(false);
@@ -8624,6 +8925,7 @@ class AparteChatHost {
8624
8925
  if (!bubble) return;
8625
8926
  populateBubbleFromMessage(bubble, message);
8626
8927
  this._renderedIds.set(message.id, message);
8928
+ if (this._step?.messageId === message.id) bubble.setStep?.(this._step.name);
8627
8929
  });
8628
8930
  this._checkpointState.reapply();
8629
8931
  }
@@ -8742,6 +9044,7 @@ class AparteChatHost {
8742
9044
  host2["updateLastMessage"] = (c, o) => this.updateLastMessage(c, o);
8743
9045
  host2["addSegment"] = (s) => this.addSegment(s);
8744
9046
  host2["updateSegment"] = (id, u) => this.updateSegment(id, u);
9047
+ host2["setStep"] = (id, name) => this.setStep(id, name);
8745
9048
  host2["removeSegment"] = (id) => this.removeSegment(id);
8746
9049
  host2["appendToSegment"] = (id, c) => this.appendToSegment(id, c);
8747
9050
  host2["getMessages"] = () => this.getMessages();
@@ -8916,7 +9219,7 @@ function segmentsToWireText(segments) {
8916
9219
  parts.push(`${fence}${lang}
8917
9220
  ${content ?? ""}
8918
9221
  ${fence}`);
8919
- } else if (segment.type === "thinking" || segment.type === "tool_call" || segment.type === "error") {
9222
+ } else if (segment.type === "thinking" || segment.type === "tool_call" || segment.type === "error" || segment.type === "activity") {
8920
9223
  continue;
8921
9224
  } else if (typeof content === "string" && content) {
8922
9225
  const wire = segment.wire;
@@ -9039,15 +9342,6 @@ function measureContext(input) {
9039
9342
  if (reply && unchanged) return result(nextRequestTokens(reply, k), false);
9040
9343
  return result(Math.round(k * total), true);
9041
9344
  }
9042
- function eventOrigin(e) {
9043
- return e.composedPath?.()[0] ?? e.target;
9044
- }
9045
- function rootOf(node) {
9046
- return node.getRootNode();
9047
- }
9048
- function activeElementIn(node) {
9049
- return node.getRootNode().activeElement ?? document.activeElement;
9050
- }
9051
9345
  let steppedPanelSeq = 0;
9052
9346
  let _relabels = null;
9053
9347
  function onRelabel(fn) {
@@ -9373,13 +9667,6 @@ function buildPanel(message, schema, onChange) {
9373
9667
  const dismiss = el$1("div", "aparte-elic-dismiss");
9374
9668
  panel.appendChild(dismiss);
9375
9669
  if (schema.type === "object") {
9376
- let show = function(index) {
9377
- current = index;
9378
- fields.forEach((f, i) => {
9379
- f.field.el.hidden = i !== index;
9380
- });
9381
- syncNav();
9382
- };
9383
9670
  const entries = Object.entries(schema.properties);
9384
9671
  const requiredKeys = new Set(schema.required ?? entries.map(([k]) => k));
9385
9672
  const cfg = contextConfig();
@@ -9426,36 +9713,25 @@ function buildPanel(message, schema, onChange) {
9426
9713
  chip.setAttribute("role", "tab");
9427
9714
  chip.textContent = f.header?.trim() || String(i + 1);
9428
9715
  chip.dir = "auto";
9429
- chip.addEventListener("click", () => {
9430
- show(i);
9431
- f.field.focus();
9432
- });
9433
9716
  chip.id = `${scope}-tab-${i}`;
9434
9717
  f.field.el.id = `${scope}-panel-${i}`;
9435
9718
  f.field.el.setAttribute("role", "tabpanel");
9436
9719
  f.field.el.setAttribute("aria-labelledby", chip.id);
9437
9720
  chip.setAttribute("aria-controls", f.field.el.id);
9438
- chip.addEventListener("keydown", (e) => {
9439
- const forward = getComputedStyle(steps).direction === "rtl" ? "ArrowLeft" : "ArrowRight";
9440
- const back = forward === "ArrowRight" ? "ArrowLeft" : "ArrowRight";
9441
- const step = e.key === forward ? 1 : e.key === back ? -1 : 0;
9442
- let next = -1;
9443
- if (step) next = (i + step + fields.length) % fields.length;
9444
- else if (e.key === "Home") next = 0;
9445
- else if (e.key === "End") next = fields.length - 1;
9446
- if (next < 0) return;
9447
- e.preventDefault();
9448
- show(next);
9449
- chips[next]?.focus();
9450
- });
9451
9721
  steps.appendChild(chip);
9452
9722
  return chip;
9453
9723
  });
9454
9724
  panel.insertBefore(steps, body);
9725
+ steps.addEventListener("aparte-tab-change", (e) => {
9726
+ current = chips.indexOf(e.detail.tab);
9727
+ });
9728
+ enhanceTabs(steps);
9729
+ steps.addEventListener("click", (e) => {
9730
+ const at = chips.indexOf(e.target.closest(".aparte-elic-step"));
9731
+ if (at >= 0 && at === current) fields[at].field.focus();
9732
+ });
9455
9733
  syncNav = () => {
9456
9734
  chips.forEach((chip, i) => {
9457
- chip.setAttribute("aria-selected", String(i === current));
9458
- chip.tabIndex = i === current ? 0 : -1;
9459
9735
  const answered = fields[i].field.isComplete();
9460
9736
  chip.toggleAttribute("data-answered", answered);
9461
9737
  const mark = chip.querySelector(".aparte-elic-step__mark");
@@ -9469,7 +9745,7 @@ function buildPanel(message, schema, onChange) {
9469
9745
  }
9470
9746
  });
9471
9747
  };
9472
- show(0);
9748
+ syncNav();
9473
9749
  return {
9474
9750
  ...api,
9475
9751
  focus: () => fields[current]?.field.focus()
@@ -10715,6 +10991,7 @@ ${content}
10715
10991
  if (!tool) return void 0;
10716
10992
  return {
10717
10993
  maxTurns: tool.maxTurns,
10994
+ parallel: tool.parallel,
10718
10995
  needsApproval: hostOwnsDecision ? tool.needsApproval : (call) => {
10719
10996
  const verdict = this._config.ruleOnToolCall(call).verdict;
10720
10997
  return verdict === "allow" ? false : verdict;
@@ -10745,6 +11022,7 @@ ${content}
10745
11022
  // inline path, so setting it was silently ignored here. Exactly the
10746
11023
  // asymmetry the option was added to remove.
10747
11024
  toolTimeoutMs: this.options.toolTimeoutMs,
11025
+ ...this.options.parallelTools !== void 0 ? { parallelTools: this.options.parallelTools } : {},
10748
11026
  // The id conventions the loop always had: prefixed artifact ids, but a
10749
11027
  // BARE uuid for the synthetic tool (the adapter renders `tool-<id>`).
10750
11028
  idGen: (prefix) => prefix === "synthetic-tool" ? uuid() : `${prefix}-${uuid()}`
@@ -11470,31 +11748,6 @@ function isAwaitingReply(message) {
11470
11748
  if (message.status === "streaming" || message.status === "pending") return true;
11471
11749
  return message.status === void 0 && message.role === "assistant" && !message.content?.trim() && !message.segments?.length;
11472
11750
  }
11473
- function placeFloating(anchor, floating, options = {}) {
11474
- const { gap = 4, margin = 8, side = "below", align = "start", rtl = false } = options;
11475
- const box = floating.getBoundingClientRect();
11476
- const clamp = (value, room, size) => Math.max(margin, Math.min(value, room - size - margin));
11477
- let top;
11478
- let left;
11479
- if (side === "beside") {
11480
- const after = anchor.right + gap;
11481
- const before = anchor.left - box.width - gap;
11482
- const [first, second] = rtl ? [before, after] : [after, before];
11483
- const fits = (x) => x >= margin && x + box.width <= window.innerWidth - margin;
11484
- left = fits(first) || !fits(second) ? first : second;
11485
- top = anchor.top;
11486
- } else {
11487
- const below = anchor.bottom + gap;
11488
- const above = anchor.top - box.height - gap;
11489
- const fitsBelow = below + box.height <= window.innerHeight - margin;
11490
- const fitsAbove = above >= margin;
11491
- if (side === "below") top = fitsBelow || !fitsAbove ? below : above;
11492
- else top = fitsAbove || !fitsBelow ? above : below;
11493
- left = align === "start" !== rtl ? anchor.left : anchor.right - box.width;
11494
- }
11495
- floating.style.top = `${clamp(top, window.innerHeight, box.height)}px`;
11496
- floating.style.left = `${clamp(left, window.innerWidth, box.width)}px`;
11497
- }
11498
11751
  function createSegmentList(opts) {
11499
11752
  const { messageId, config } = opts;
11500
11753
  let segments = (opts.segments ?? []).reduce((acc, segment) => {
@@ -11694,7 +11947,7 @@ function deferHydrationOf(ctor) {
11694
11947
  };
11695
11948
  }
11696
11949
  export {
11697
- isAwaitingReply as $,
11950
+ isFormatAdapter as $,
11698
11951
  APARTE_CONFIG_CHANGE as A,
11699
11952
  contextConfig as B,
11700
11953
  copyText as C,
@@ -11703,89 +11956,86 @@ export {
11703
11956
  createAparteChatHandler as F,
11704
11957
  createSegmentList as G,
11705
11958
  createStreamAdapter as H,
11706
- cssEscape as I,
11707
- declineDefaultRenderers as J,
11708
- defaultSanitizer as K,
11709
- deferHydrationOf as L,
11710
- defineMountedSegmentRenderer as M,
11711
- defineMountedToolRenderer as N,
11712
- detachConfig as O,
11713
- escapeAttr as P,
11714
- escapeHtml as Q,
11715
- estimateTokens as R,
11959
+ declineDefaultRenderers as I,
11960
+ defaultSanitizer as J,
11961
+ deferHydrationOf as K,
11962
+ defineMountedSegmentRenderer as L,
11963
+ defineMountedToolRenderer as M,
11964
+ detachConfig as N,
11965
+ escapeAttr as O,
11966
+ escapeHtml as P,
11967
+ estimateTokens as Q,
11968
+ estimateWireTokens as R,
11716
11969
  SUGGESTIONS_BLOCK_LANGUAGE as S,
11717
- estimateWireTokens as T,
11718
- filesToAttachments as U,
11719
- formatDuration as V,
11720
- getAllRenderers as W,
11721
- getSegmentRenderer as X,
11722
- historyFromCheckpoint as Y,
11723
- installDefaultRenderersOnce as Z,
11724
- installDialogTriggersOnce as _,
11970
+ filesToAttachments as T,
11971
+ formatDuration as U,
11972
+ getAllRenderers as V,
11973
+ getSegmentRenderer as W,
11974
+ historyFromCheckpoint as X,
11975
+ installDefaultRenderersOnce as Y,
11976
+ installDialogTriggersOnce as Z,
11977
+ isAwaitingReply as _,
11725
11978
  APARTE_CONVERSATION_SCHEMA_VERSION as a,
11726
- isFormatAdapter as a0,
11727
- isSafeUrl as a1,
11728
- isSegmentSettled as a2,
11729
- measureContext as a3,
11979
+ isSafeUrl as a0,
11980
+ isSegmentSettled as a1,
11981
+ measureContext as a2,
11982
+ onRenderersChange as a3,
11730
11983
  overrideSegmentRenderer as a4,
11731
11984
  parseAparteEventStream as a5,
11732
11985
  parseMarkdownToSegments as a6,
11733
- placeFloating as a7,
11734
- pluralize as a8,
11735
- populateBubbleFromMessage as a9,
11736
- toolCallRenderer as aA,
11737
- toolRendererThatDrew as aB,
11738
- isMountedRenderer as aC,
11739
- renderingVersionOf as aD,
11740
- onRenderersChange as aE,
11741
- renderSourceList as aF,
11742
- mergeSegmentUpdate as aG,
11743
- toolNameOf as aH,
11744
- writeStreamedMarkdown as aI,
11745
- replaceHighlighted as aJ,
11746
- CheckpointStateWatcher as aK,
11747
- chatIdOf as aL,
11748
- stampSegmentActivity as aM,
11749
- stampSegmentOnInsert as aN,
11750
- stampSegmentOnUpdate as aO,
11751
- renumberSegments as aP,
11752
- openSegmentIds as aQ,
11753
- isTerminalStatus as aR,
11754
- adoptMessageSegments as aS,
11755
- APARTE_DERIVED_SEGMENTS as aT,
11756
- rememberConversationStatus as aU,
11757
- tellConversationStatus as aV,
11758
- conversationStatusOf as aW,
11759
- visibleReply as aX,
11760
- usageTokens as aY,
11761
- rootOf as aZ,
11762
- inRenderedContent as a_,
11763
- readableToAsyncIterable as aa,
11764
- registerDefaultRenderers as ab,
11765
- registerSegmentRenderer as ac,
11766
- releaseDeferredHydration as ad,
11767
- renderCitations as ae,
11768
- renderCodeLanguages as af,
11769
- requestUserInput as ag,
11770
- resolveConfig as ah,
11771
- revokeAttachmentUrls as ai,
11772
- runSubAgent as aj,
11773
- runWithConfig as ak,
11774
- segmentDuration as al,
11775
- segmentTiming as am,
11776
- setupSuggestionBlocks as an,
11777
- startSubAgent as ao,
11778
- subscribeConfigChange as ap,
11779
- toToolCallView as aq,
11780
- toolRefusal as ar,
11781
- unregisterSegmentRenderer as as,
11782
- uuid as at,
11783
- eventOrigin as au,
11784
- activeElementIn as av,
11785
- gateGlide as aw,
11786
- chatBoundaryOf as ax,
11787
- relabelCodeLanguages as ay,
11788
- relabelCitations as az,
11986
+ pluralize as a7,
11987
+ populateBubbleFromMessage as a8,
11988
+ readableToAsyncIterable as a9,
11989
+ renderingVersionOf as aA,
11990
+ renderSourceList as aB,
11991
+ mergeSegmentUpdate as aC,
11992
+ toolNameOf as aD,
11993
+ writeStreamedMarkdown as aE,
11994
+ replaceHighlighted as aF,
11995
+ toolRendererThatDrew as aG,
11996
+ activityRendererThatDrew as aH,
11997
+ CheckpointStateWatcher as aI,
11998
+ chatIdOf as aJ,
11999
+ stampSegmentActivity as aK,
12000
+ stampSegmentOnInsert as aL,
12001
+ stampSegmentOnUpdate as aM,
12002
+ renumberSegments as aN,
12003
+ openSegmentIds as aO,
12004
+ isTerminalStatus as aP,
12005
+ adoptMessageSegments as aQ,
12006
+ APARTE_DERIVED_SEGMENTS as aR,
12007
+ rememberConversationStatus as aS,
12008
+ tellConversationStatus as aT,
12009
+ conversationStatusOf as aU,
12010
+ visibleReply as aV,
12011
+ usageTokens as aW,
12012
+ inRenderedContent as aX,
12013
+ registerDefaultRenderers as aa,
12014
+ registerSegmentRenderer as ab,
12015
+ releaseDeferredHydration as ac,
12016
+ renderCitations as ad,
12017
+ renderCodeLanguages as ae,
12018
+ requestUserInput as af,
12019
+ resolveConfig as ag,
12020
+ revokeAttachmentUrls as ah,
12021
+ runSubAgent as ai,
12022
+ runWithConfig as aj,
12023
+ segmentDuration as ak,
12024
+ segmentTiming as al,
12025
+ setupSuggestionBlocks as am,
12026
+ startSubAgent as an,
12027
+ subscribeConfigChange as ao,
12028
+ toToolCallView as ap,
12029
+ toolRefusal as aq,
12030
+ unregisterSegmentRenderer as ar,
12031
+ uuid as as,
12032
+ gateGlide as at,
12033
+ chatBoundaryOf as au,
12034
+ relabelCodeLanguages as av,
12035
+ relabelCitations as aw,
12036
+ toolCallRenderer as ax,
12037
+ activityRenderer as ay,
12038
+ isMountedRenderer as az,
11789
12039
  APARTE_DEFAULT_BUBBLE_ACTIONS as b,
11790
12040
  APARTE_DEFAULT_HOST_HANDLERS as c,
11791
12041
  APARTE_DEFAULT_ICON_FALLBACKS as d,
@@ -11812,4 +12062,4 @@ export {
11812
12062
  collectRendererStyles as y,
11813
12063
  contentToText as z
11814
12064
  };
11815
- //# sourceMappingURL=defer-hydration-W4yhnyfc.js.map
12065
+ //# sourceMappingURL=defer-hydration-BE2ToXC_.js.map