@aparte/core 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { K as deferHydrationOf, ad as resolveConfig, ao as eventOrigin, ap as activeElementIn, aj as subscribeConfigChange, af as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, aq as gateGlide, O as escapeAttr, ar as chatBoundaryOf, as as relabelCodeLanguages, at as relabelCitations, au as toolCallRenderer, av as toolRendererThatDrew, t as aparteGlobalConfig, aw as isMountedRenderer, ax as renderingVersionOf, H as cssEscape, ay as onRenderersChange, az as renderSourceList, aA as mergeSegmentUpdate, P as escapeHtml, a0 as isSegmentSettled, aB as writeStreamedMarkdown, aC as replaceHighlighted, $ as isSafeUrl, C as copyText, V as getSegmentRenderer, X as installDefaultRenderersOnce, r as AparteMessageRepository, aD as CheckpointStateWatcher, aE as chatIdOf, aF as stampSegmentActivity, aG as stampSegmentOnInsert, aH as stampSegmentOnUpdate, aI as renumberSegments, aJ as openSegmentIds, aK as isTerminalStatus, aL as adoptMessageSegments, Z as isAwaitingReply, a5 as populateBubbleFromMessage, an as uuid, ae as revokeAttachmentUrls, a4 as parseMarkdownToSegments, aM as APARTE_DERIVED_SEGMENTS, aN as rememberConversationStatus, aO as tellConversationStatus, aP as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, aQ as visibleReply, aR as usageTokens, q as AparteErrorCode, a1 as measureContext, aS as rootOf, aT as inRenderedContent, g as APARTE_HOST_ATTR, Y as installDialogTriggersOnce } from "./defer-hydration-Dw5D80FC.js";
2
- import { A, a, b, c, d, f, h, i, j, k, l, m, n, p, s, S, u, v, y, z, B, D, E, F, G, I, J, L, M, N, Q, R, T, U, W, _, a2, a3, a6, a7, a8, a9, aa, ab, ac, ag, ah, ai, ak, al, am } from "./defer-hydration-Dw5D80FC.js";
1
+ import { K as deferHydrationOf, ad as resolveConfig, ao as eventOrigin, ap as activeElementIn, aj as subscribeConfigChange, af as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, aq as gateGlide, O as escapeAttr, ar as chatBoundaryOf, as as relabelCodeLanguages, at as relabelCitations, au as toolCallRenderer, av as toolRendererThatDrew, t as aparteGlobalConfig, aw as isMountedRenderer, ax as renderingVersionOf, H as cssEscape, ay as onRenderersChange, az as renderSourceList, aA as mergeSegmentUpdate, P as escapeHtml, a0 as isSegmentSettled, aB as writeStreamedMarkdown, aC as replaceHighlighted, $ as isSafeUrl, C as copyText, V as getSegmentRenderer, X as installDefaultRenderersOnce, r as AparteMessageRepository, aD as CheckpointStateWatcher, aE as chatIdOf, aF as stampSegmentActivity, aG as stampSegmentOnInsert, aH as stampSegmentOnUpdate, aI as renumberSegments, aJ as openSegmentIds, aK as isTerminalStatus, aL as adoptMessageSegments, Z as isAwaitingReply, a5 as populateBubbleFromMessage, an as uuid, ae as revokeAttachmentUrls, a4 as parseMarkdownToSegments, aM as APARTE_DERIVED_SEGMENTS, aN as rememberConversationStatus, aO as tellConversationStatus, aP as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, aQ as visibleReply, aR as usageTokens, q as AparteErrorCode, a1 as measureContext, aS as rootOf, aT as inRenderedContent, g as APARTE_HOST_ATTR, Y as installDialogTriggersOnce } from "./defer-hydration-_SZv5PeY.js";
2
+ import { A, a, b, c, d, f, h, i, j, k, l, m, n, p, s, S, u, v, y, z, B, D, E, F, G, I, J, L, M, N, Q, R, T, U, W, _, a2, a3, a6, a7, a8, a9, aa, ab, ac, ag, ah, ai, ak, al, am } from "./defer-hydration-_SZv5PeY.js";
3
3
  function presenceOn(value) {
4
4
  return value === "" ? true : Boolean(value);
5
5
  }
@@ -1561,15 +1561,45 @@ class AparteChatBubble extends HTMLElement {
1561
1561
  * Recorded BEFORE `setup`: a setup that throws (a framework mount) leaves an element that
1562
1562
  * will still be cleaned up. The same id drawn twice releases the first element.
1563
1563
  */
1564
- _install(segment, el2, renderer) {
1564
+ _install(segment, el2, renderer, drawnAs = segment) {
1565
1565
  const previous = this._drawn.get(segment.id);
1566
1566
  if (previous && previous.el !== el2) this._release(segment.id);
1567
1567
  const drawn = { el: el2, renderer, tool: null, segment };
1568
1568
  this._drawn.set(segment.id, drawn);
1569
1569
  if (!this.isConnected) this._scheduleReleaseCheck();
1570
- if (renderer?.setup) runWithConfig(this._cfg, () => renderer.setup(el2, segment));
1570
+ if (renderer?.setup) runWithConfig(this._cfg, () => renderer.setup(el2, drawnAs));
1571
1571
  if (segment.type === "tool_call") drawn.tool = toolRendererThatDrew(el2);
1572
1572
  }
1573
+ /**
1574
+ * The segment as its renderer's `setup` sees it: one ADDED while the message streams is
1575
+ * arriving, flag or no flag.
1576
+ *
1577
+ * A text or reasoning segment flagged `isStreaming: true` is written by its renderer's
1578
+ * `setup` through the streaming renderer, from its first chunk. The stream parser's text
1579
+ * carries no flag at all, though: `update` reads a missing flag as "still arriving",
1580
+ * `setup` cannot, because a restored message's segments carry none either and are
1581
+ * finished. So its first chunk — drawn by `render` and `setup`, while `update` only runs
1582
+ * from the second — went through the one-shot provider, which reads `Done: **Book ` as
1583
+ * finished text: with marked, the `**` showed raw until the next chunk reached the
1584
+ * streaming renderer, which completes it. `addSegment` on a streaming message is a segment
1585
+ * arriving, and the bubble is what knows the message streams, so it tells `setup`
1586
+ * (`render` keeps the segment as stored: the reasoning label reads the flag, and would lose
1587
+ * its shimmer again at the next chunk). `setSegments` infers nothing — a hand-set text is
1588
+ * finished, and the streaming renderer would keep back what may still open a token (the
1589
+ * full stop after `**bold**`) until the turn ends; a framework host flags the segment
1590
+ * itself (`populateBubbleFromMessage`). Either way the segment joins `_written`, to be
1591
+ * settled — flushed, then drawn whole — when the message stops.
1592
+ */
1593
+ _drawnAs(segment, added = false) {
1594
+ if (segment.type !== "text" && segment.type !== "thinking") return segment;
1595
+ if (segment.isStreaming === true) {
1596
+ this._written.add(segment.id);
1597
+ return segment;
1598
+ }
1599
+ if (!added || segment.isStreaming === false || !this._streaming) return segment;
1600
+ this._written.add(segment.id);
1601
+ return { ...segment, isStreaming: true };
1602
+ }
1573
1603
  /**
1574
1604
  * The segment's element leaves for good: its renderer's `cleanup`, once. A cleanup that
1575
1605
  * throws is reported and costs nothing else — the element still goes, and the others
@@ -1612,13 +1642,14 @@ class AparteChatBubble extends HTMLElement {
1612
1642
  const renderer = resolveSegmentRenderer(segment.type, cfg);
1613
1643
  const old = drawn.el;
1614
1644
  this._release(segment.id);
1645
+ const drawnAs = renderer ? this._drawnAs(segment) : segment;
1615
1646
  const el2 = renderer ? segmentRenderResultToElement(runWithConfig(cfg, () => renderer.render(segment)), segment) : unrenderedSegment(segment);
1616
1647
  if (!el2) {
1617
1648
  old.remove();
1618
1649
  return true;
1619
1650
  }
1620
1651
  old.replaceWith(el2);
1621
- this._install(segment, el2, renderer);
1652
+ this._install(segment, el2, renderer, drawnAs);
1622
1653
  return true;
1623
1654
  }
1624
1655
  /** The renderer that drew this segment is still the one in effect (for a tool call, the tool renderer too). */
@@ -2264,10 +2295,11 @@ class AparteChatBubble extends HTMLElement {
2264
2295
  if (this._segments.length === 1) this._drawnWithVersion = renderingVersionOf(this._cfg);
2265
2296
  const renderer = resolveSegmentRenderer(segment.type, this._cfg);
2266
2297
  if (renderer) {
2298
+ const drawnAs = this._drawnAs(segment, true);
2267
2299
  const el2 = segmentRenderResultToElement(runWithConfig(this._cfg, () => renderer.render(segment)), segment);
2268
2300
  if (el2) {
2269
2301
  this._segmentsEl.appendChild(el2);
2270
- this._install(segment, el2, renderer);
2302
+ this._install(segment, el2, renderer, drawnAs);
2271
2303
  }
2272
2304
  } else {
2273
2305
  const el2 = unrenderedSegment(segment);
@@ -2598,10 +2630,11 @@ class AparteChatBubble extends HTMLElement {
2598
2630
  for (const segment of this._segments) {
2599
2631
  const renderer = resolveSegmentRenderer(segment.type, this._cfg);
2600
2632
  if (renderer) {
2633
+ const drawnAs = this._drawnAs(segment);
2601
2634
  const el2 = segmentRenderResultToElement(runWithConfig(this._cfg, () => renderer.render(segment)), segment);
2602
2635
  if (el2) {
2603
2636
  this._segmentsEl.appendChild(el2);
2604
- this._install(segment, el2, renderer);
2637
+ this._install(segment, el2, renderer, drawnAs);
2605
2638
  }
2606
2639
  } else {
2607
2640
  const el2 = unrenderedSegment(segment);