@aparte/core 1.0.0 → 1.0.2
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/components/bubble/aparte-chat-bubble.d.ts +21 -0
- package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
- package/dist/components/bubble/bubble-sync.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer.d.ts +17 -1
- package/dist/components/composer/aparte-composer.d.ts.map +1 -1
- package/dist/custom-elements.json +1339 -1303
- package/dist/{defer-hydration-Dw5D80FC.js → defer-hydration-_SZv5PeY.js} +18 -5
- package/dist/defer-hydration-_SZv5PeY.js.map +1 -0
- package/dist/index.js +70 -8
- package/dist/index.js.map +1 -1
- package/dist/index.node.js +1 -1
- package/dist/renderers/segments/text.d.ts.map +1 -1
- package/dist/renderers/segments/thinking.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/defer-hydration-Dw5D80FC.js.map +0 -1
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-
|
|
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-
|
|
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,
|
|
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);
|
|
@@ -5038,6 +5071,11 @@ deferHydrationOf(AparteChatViewport);
|
|
|
5038
5071
|
if (!customElements.get("aparte-chat-viewport")) {
|
|
5039
5072
|
customElements.define("aparte-chat-viewport", AparteChatViewport);
|
|
5040
5073
|
}
|
|
5074
|
+
const ONE_LINE_INPUTS = /* @__PURE__ */ new Set(["text", "search", "email", "url", "tel", "number", "password"]);
|
|
5075
|
+
function isOneLineField(target) {
|
|
5076
|
+
if (target instanceof HTMLTextAreaElement) return target.rows === 1;
|
|
5077
|
+
return target instanceof HTMLInputElement && ONE_LINE_INPUTS.has(target.type);
|
|
5078
|
+
}
|
|
5041
5079
|
class AparteComposer extends HTMLElement {
|
|
5042
5080
|
_value = "";
|
|
5043
5081
|
_streaming = false;
|
|
@@ -5168,7 +5206,8 @@ class AparteComposer extends HTMLElement {
|
|
|
5168
5206
|
}
|
|
5169
5207
|
/**
|
|
5170
5208
|
* When false, Shift+Enter submits and a bare Enter inserts a newline —
|
|
5171
|
-
* the inverse of the default. Driven by the `submit-on-enter` attribute
|
|
5209
|
+
* the inverse of the default. Driven by the `submit-on-enter` attribute, and it
|
|
5210
|
+
* holds in a panel's one-line fields as it does in the editor.
|
|
5172
5211
|
*/
|
|
5173
5212
|
get submitOnEnter() {
|
|
5174
5213
|
return this.getAttribute("submit-on-enter") !== "false";
|
|
@@ -5276,6 +5315,7 @@ class AparteComposer extends HTMLElement {
|
|
|
5276
5315
|
const inputEl = this.querySelector("aparte-composer-input");
|
|
5277
5316
|
this.setAttribute("data-panel-active", "");
|
|
5278
5317
|
panel.dataset["apartePanel"] = "true";
|
|
5318
|
+
panel.addEventListener("keydown", this._onPanelKeydown);
|
|
5279
5319
|
if (host) {
|
|
5280
5320
|
host.appendChild(panel);
|
|
5281
5321
|
} else if (inputEl) {
|
|
@@ -5321,6 +5361,28 @@ class AparteComposer extends HTMLElement {
|
|
|
5321
5361
|
}
|
|
5322
5362
|
this._evictPanel();
|
|
5323
5363
|
}
|
|
5364
|
+
/**
|
|
5365
|
+
* Enter in a panel's one-line field presses the send button, as it does in the editor.
|
|
5366
|
+
*
|
|
5367
|
+
* The panel takes the editor's place and the editor was the only thing listening, so
|
|
5368
|
+
* what a person wrote in a panel went out by mouse alone: Enter added a line to an
|
|
5369
|
+
* approval's instruction and did nothing in a question's text box. It lives here, once,
|
|
5370
|
+
* because the button is the composer's and so is `submit-on-enter`; `submit()` then
|
|
5371
|
+
* applies the panel's own gates (no act for the button, nothing written, put aside).
|
|
5372
|
+
* The key is cancelled even when nothing can be sent, as the editor does, so an empty
|
|
5373
|
+
* field does not fill with blank lines.
|
|
5374
|
+
*
|
|
5375
|
+
* Same IME guard as the editor: that Enter confirms a candidate. `defaultPrevented`
|
|
5376
|
+
* leaves the key to a field that used it, a combobox picking its highlighted row.
|
|
5377
|
+
*/
|
|
5378
|
+
_onPanelKeydown = (e) => {
|
|
5379
|
+
if (e.key !== "Enter" || e.isComposing || e.keyCode === 229 || e.defaultPrevented) return;
|
|
5380
|
+
if (!isOneLineField(e.target)) return;
|
|
5381
|
+
const submits = this.submitOnEnter ? !e.shiftKey : e.shiftKey;
|
|
5382
|
+
if (!submits) return;
|
|
5383
|
+
e.preventDefault();
|
|
5384
|
+
this.submit();
|
|
5385
|
+
};
|
|
5324
5386
|
/** Close the panel AND tell its owner, so a pending request never orphans. */
|
|
5325
5387
|
_evictPanel() {
|
|
5326
5388
|
const onEvict = this._panelOnEvict;
|