@aparte/core 1.0.1 → 1.1.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.
- package/dist/client/aparte-client.d.ts +2 -0
- package/dist/client/aparte-client.d.ts.map +1 -1
- package/dist/components/bubble/aparte-chat-bubble.d.ts +25 -0
- package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
- package/dist/components/bubble/bubble-sync.d.ts +2 -1
- package/dist/components/bubble/bubble-sync.d.ts.map +1 -1
- package/dist/components/bubble/feedback-reasons.d.ts +13 -0
- package/dist/components/bubble/feedback-reasons.d.ts.map +1 -0
- package/dist/components/bubble/message-tokens.d.ts +10 -0
- package/dist/components/bubble/message-tokens.d.ts.map +1 -0
- package/dist/components/bubble/turn-groups.d.ts +24 -0
- package/dist/components/bubble/turn-groups.d.ts.map +1 -0
- package/dist/components/composer/aparte-composer-attachments.d.ts +3 -0
- package/dist/components/composer/aparte-composer-attachments.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-input.d.ts +29 -0
- package/dist/components/composer/aparte-composer-input.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-toolbar.d.ts +4 -0
- package/dist/components/composer/aparte-composer-toolbar.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer.d.ts +32 -4
- package/dist/components/composer/aparte-composer.d.ts.map +1 -1
- package/dist/components/composer/composer-tokens.d.ts +21 -0
- package/dist/components/composer/composer-tokens.d.ts.map +1 -0
- package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -1
- package/dist/components/viewport/aparte-chat-viewport.d.ts +2 -0
- package/dist/components/viewport/aparte-chat-viewport.d.ts.map +1 -1
- package/dist/config/aparte-config.d.ts +24 -1
- package/dist/config/aparte-config.d.ts.map +1 -1
- package/dist/config/locale.d.ts +44 -0
- package/dist/config/locale.d.ts.map +1 -1
- package/dist/conversations/conversation-controller.d.ts +19 -0
- package/dist/conversations/conversation-controller.d.ts.map +1 -1
- package/dist/conversations/conversation-manager.d.ts +2 -0
- package/dist/conversations/conversation-manager.d.ts.map +1 -1
- package/dist/conversations/types.d.ts +4 -0
- package/dist/conversations/types.d.ts.map +1 -1
- package/dist/custom-elements.json +1552 -7
- package/dist/{defer-hydration-_SZv5PeY.js → defer-hydration-BBdqAZej.js} +252 -61
- package/dist/defer-hydration-BBdqAZej.js.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +635 -95
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +3 -1
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +21 -20
- package/dist/index.node.js.map +1 -1
- package/dist/interop/element-props.d.ts +1 -1
- package/dist/interop/element-props.d.ts.map +1 -1
- package/dist/types/chat.d.ts +3 -0
- package/dist/types/chat.d.ts.map +1 -1
- package/dist/types/event-map.d.ts +4 -1
- package/dist/types/event-map.d.ts.map +1 -1
- package/dist/types/events.d.ts +93 -1
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/model-provider.d.ts +6 -0
- package/dist/types/model-provider.d.ts.map +1 -1
- package/dist/types/models.d.ts +44 -0
- package/dist/types/models.d.ts.map +1 -1
- package/dist/utils/place-floating.d.ts +20 -0
- package/dist/utils/place-floating.d.ts.map +1 -0
- package/dist/utils/plural.d.ts +7 -0
- package/dist/utils/plural.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/defer-hydration-_SZv5PeY.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { K as deferHydrationOf,
|
|
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,
|
|
1
|
+
import { K as deferHydrationOf, ae as resolveConfig, ap as eventOrigin, aq as activeElementIn, ak as subscribeConfigChange, ag as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, ar as gateGlide, O as escapeAttr, H as cssEscape, ai as segmentTiming, as as chatBoundaryOf, at as relabelCodeLanguages, au as relabelCitations, av as toolCallRenderer, aw as toolRendererThatDrew, t as aparteGlobalConfig, ax as isMountedRenderer, ay as renderingVersionOf, az as onRenderersChange, aA as renderSourceList, aB as mergeSegmentUpdate, a0 as isSegmentSettled, aC as formatDuration, P as escapeHtml, aD as writeStreamedMarkdown, aE as replaceHighlighted, $ as isSafeUrl, C as copyText, V as getSegmentRenderer, X as installDefaultRenderersOnce, r as AparteMessageRepository, aF as CheckpointStateWatcher, aG as chatIdOf, aH as stampSegmentActivity, aI as stampSegmentOnInsert, aJ as stampSegmentOnUpdate, aK as renumberSegments, aL as openSegmentIds, aM as isTerminalStatus, aN as adoptMessageSegments, Z as isAwaitingReply, a6 as populateBubbleFromMessage, ao as uuid, af as revokeAttachmentUrls, a4 as parseMarkdownToSegments, aO as APARTE_DERIVED_SEGMENTS, aP as rememberConversationStatus, aQ as tellConversationStatus, aR as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, a5 as placeFloating, aS as visibleReply, aT as usageTokens, q as AparteErrorCode, a1 as measureContext, aU as rootOf, aV as inRenderedContent, g as APARTE_HOST_ATTR, Y as installDialogTriggersOnce } from "./defer-hydration-BBdqAZej.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, a7, a8, a9, aa, ab, ac, ad, ah, aj, al, am, an } from "./defer-hydration-BBdqAZej.js";
|
|
3
3
|
function presenceOn(value) {
|
|
4
4
|
return value === "" ? true : Boolean(value);
|
|
5
5
|
}
|
|
@@ -1307,6 +1307,112 @@ deferHydrationOf(AparteChat);
|
|
|
1307
1307
|
if (!customElements.get("aparte-chat")) {
|
|
1308
1308
|
customElements.define("aparte-chat", AparteChat);
|
|
1309
1309
|
}
|
|
1310
|
+
function pluralize(forms, n2, tag) {
|
|
1311
|
+
let category = "other";
|
|
1312
|
+
try {
|
|
1313
|
+
category = new Intl.PluralRules(tag).select(n2);
|
|
1314
|
+
} catch {
|
|
1315
|
+
}
|
|
1316
|
+
const options = forms.split("|");
|
|
1317
|
+
const named = (name) => options.find((form2) => form2.startsWith(`${name}:`));
|
|
1318
|
+
const form = named(category) ?? named("other") ?? forms;
|
|
1319
|
+
return form.slice(form.indexOf(":") + 1).replace("{n}", String(n2));
|
|
1320
|
+
}
|
|
1321
|
+
function planTurns(items, roleOf) {
|
|
1322
|
+
const runs = [];
|
|
1323
|
+
let from = -1;
|
|
1324
|
+
let last = -1;
|
|
1325
|
+
let members = 0;
|
|
1326
|
+
const close = () => {
|
|
1327
|
+
if (members >= 2) runs.push({ from, to: last });
|
|
1328
|
+
from = -1;
|
|
1329
|
+
last = -1;
|
|
1330
|
+
members = 0;
|
|
1331
|
+
};
|
|
1332
|
+
items.forEach((item, index) => {
|
|
1333
|
+
const role = roleOf(item);
|
|
1334
|
+
if (role === "stop") {
|
|
1335
|
+
close();
|
|
1336
|
+
} else if (role === "fold") {
|
|
1337
|
+
if (from < 0) from = index;
|
|
1338
|
+
last = index;
|
|
1339
|
+
members += 1;
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
close();
|
|
1343
|
+
return runs;
|
|
1344
|
+
}
|
|
1345
|
+
function rowOf(container, segmentId) {
|
|
1346
|
+
const id = `[data-segment-id="${cssEscape(segmentId)}"]`;
|
|
1347
|
+
return container.querySelector(`:scope > ${id}, :scope > .aparte-turn > .aparte-turn__body > ${id}`);
|
|
1348
|
+
}
|
|
1349
|
+
function turnDuration(members) {
|
|
1350
|
+
let start = Infinity;
|
|
1351
|
+
let end = -Infinity;
|
|
1352
|
+
for (const member of members) {
|
|
1353
|
+
const { startedAt, endedAt } = segmentTiming(member) ?? {};
|
|
1354
|
+
if (startedAt == null || endedAt == null) return void 0;
|
|
1355
|
+
start = Math.min(start, startedAt);
|
|
1356
|
+
end = Math.max(end, endedAt);
|
|
1357
|
+
}
|
|
1358
|
+
return members.length > 0 ? end - start : void 0;
|
|
1359
|
+
}
|
|
1360
|
+
const count = (haystack, needle) => needle ? haystack.split(needle).length - 1 : 0;
|
|
1361
|
+
function pill(doc, token) {
|
|
1362
|
+
const el2 = doc.createElement("span");
|
|
1363
|
+
el2.className = "aparte-tag aparte-inline-token";
|
|
1364
|
+
if (token.kind) el2.dataset["kind"] = token.kind;
|
|
1365
|
+
const label = doc.createElement("span");
|
|
1366
|
+
label.className = "aparte-tag__label";
|
|
1367
|
+
label.textContent = token.label;
|
|
1368
|
+
el2.appendChild(label);
|
|
1369
|
+
return el2;
|
|
1370
|
+
}
|
|
1371
|
+
function draw(root, content, token) {
|
|
1372
|
+
let skip = count(content.slice(0, token.start), token.text);
|
|
1373
|
+
const doc = root.ownerDocument;
|
|
1374
|
+
const walker = doc.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
1375
|
+
while (walker.nextNode()) {
|
|
1376
|
+
const node = walker.currentNode;
|
|
1377
|
+
for (let at = node.data.indexOf(token.text); at >= 0; at = node.data.indexOf(token.text, at + token.text.length)) {
|
|
1378
|
+
if (skip-- > 0) continue;
|
|
1379
|
+
const range = doc.createRange();
|
|
1380
|
+
range.setStart(node, at);
|
|
1381
|
+
range.setEnd(node, at + token.text.length);
|
|
1382
|
+
range.deleteContents();
|
|
1383
|
+
range.insertNode(pill(doc, token));
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
function drawMessageTokens(root, content, tokens) {
|
|
1389
|
+
if (root.querySelector(".aparte-inline-token")) return;
|
|
1390
|
+
for (const token of [...tokens].sort((a4, b2) => b2.start - a4.start)) {
|
|
1391
|
+
if (token.text) draw(root, content, token);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
function button(label, className, onClick2) {
|
|
1395
|
+
const el2 = document.createElement("button");
|
|
1396
|
+
el2.type = "button";
|
|
1397
|
+
el2.className = `aparte-btn aparte-btn--sm ${className}`;
|
|
1398
|
+
el2.textContent = label;
|
|
1399
|
+
el2.addEventListener("click", onClick2);
|
|
1400
|
+
return el2;
|
|
1401
|
+
}
|
|
1402
|
+
function buildFeedbackReasons(options) {
|
|
1403
|
+
const root = document.createElement("div");
|
|
1404
|
+
root.className = "aparte-feedback-reasons";
|
|
1405
|
+
root.setAttribute("role", "group");
|
|
1406
|
+
root.setAttribute("aria-label", options.title);
|
|
1407
|
+
const title = document.createElement("span");
|
|
1408
|
+
title.textContent = options.title;
|
|
1409
|
+
root.appendChild(title);
|
|
1410
|
+
for (const reason of options.reasons) {
|
|
1411
|
+
root.appendChild(button(reason, "aparte-btn--surface", () => options.onPick(reason)));
|
|
1412
|
+
}
|
|
1413
|
+
root.appendChild(button(options.dismiss, "aparte-btn--ghost", options.onClose));
|
|
1414
|
+
return root;
|
|
1415
|
+
}
|
|
1310
1416
|
const isStore = (candidate) => !!candidate && typeof candidate.getMessages === "function" && typeof candidate.updateMessage === "function";
|
|
1311
1417
|
function storeOf(from) {
|
|
1312
1418
|
const boundary = chatBoundaryOf(from);
|
|
@@ -1332,10 +1438,10 @@ function el$1(tag, className, text) {
|
|
|
1332
1438
|
return node;
|
|
1333
1439
|
}
|
|
1334
1440
|
function action(name, label) {
|
|
1335
|
-
const
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
return
|
|
1441
|
+
const button2 = el$1("button", "aparte-btn aparte-btn--ghost aparte-btn--sm aparte-checkpoint__action", label);
|
|
1442
|
+
button2.type = "button";
|
|
1443
|
+
button2.setAttribute("data-checkpoint-action", name);
|
|
1444
|
+
return button2;
|
|
1339
1445
|
}
|
|
1340
1446
|
function buildCheckpointSeparator(options) {
|
|
1341
1447
|
const { kind, locale } = options;
|
|
@@ -1448,6 +1554,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
1448
1554
|
_branchPickerEl = null;
|
|
1449
1555
|
_footerEl = null;
|
|
1450
1556
|
_content = "";
|
|
1557
|
+
_tokens;
|
|
1451
1558
|
_streaming = false;
|
|
1452
1559
|
_segments = [];
|
|
1453
1560
|
_role = "assistant";
|
|
@@ -1669,6 +1776,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
1669
1776
|
if (!drawn || this._stillDrawnByCurrent(segment, drawn)) continue;
|
|
1670
1777
|
this._redrawSegment(segment);
|
|
1671
1778
|
}
|
|
1779
|
+
this._syncTurns();
|
|
1672
1780
|
}
|
|
1673
1781
|
/**
|
|
1674
1782
|
* The registries' channel: a renderer changed on our config — or on the global one, whose
|
|
@@ -1712,6 +1820,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
1712
1820
|
if (this._keepsItsDrawing(segment, drawn)) continue;
|
|
1713
1821
|
this._redrawSegment(segment);
|
|
1714
1822
|
}
|
|
1823
|
+
this._syncTurns();
|
|
1715
1824
|
this._reflectError();
|
|
1716
1825
|
this._syncCopyAction();
|
|
1717
1826
|
}
|
|
@@ -1736,12 +1845,11 @@ class AparteChatBubble extends HTMLElement {
|
|
|
1736
1845
|
for (const segment of this._segments) {
|
|
1737
1846
|
const renderer = resolveSegmentRenderer(segment.type, this._cfg);
|
|
1738
1847
|
if (!renderer?.relabel) continue;
|
|
1739
|
-
const el2 = this._segmentsEl.
|
|
1740
|
-
`:scope > [data-segment-id="${cssEscape(segment.id)}"]`
|
|
1741
|
-
);
|
|
1848
|
+
const el2 = rowOf(this._segmentsEl, segment.id);
|
|
1742
1849
|
if (!el2) continue;
|
|
1743
1850
|
runWithConfig(this._cfg, () => renderer.relabel(el2, segment));
|
|
1744
1851
|
}
|
|
1852
|
+
this._syncTurns();
|
|
1745
1853
|
}
|
|
1746
1854
|
/**
|
|
1747
1855
|
* Re-apply the locale strings written straight into the markup by `_render()` —
|
|
@@ -1879,6 +1987,36 @@ class AparteChatBubble extends HTMLElement {
|
|
|
1879
1987
|
this._updateContent();
|
|
1880
1988
|
this._syncCopyAction();
|
|
1881
1989
|
}
|
|
1990
|
+
/** The row under the action bar that asks why, when the app listed reasons. */
|
|
1991
|
+
_askFeedbackReason(messageId) {
|
|
1992
|
+
const reasons = this._cfg.getBubbleActions().feedbackReasons;
|
|
1993
|
+
if (!reasons?.length || this.querySelector(".aparte-feedback-reasons")) return;
|
|
1994
|
+
const panel = buildFeedbackReasons({
|
|
1995
|
+
reasons,
|
|
1996
|
+
title: this._cfg.t("feedbackReasonTitle"),
|
|
1997
|
+
dismiss: this._cfg.t("feedbackReasonDismiss"),
|
|
1998
|
+
onPick: (reason) => {
|
|
1999
|
+
panel.remove();
|
|
2000
|
+
this.dispatchEvent(new CustomEvent("aparte-feedback-reason", {
|
|
2001
|
+
bubbles: true,
|
|
2002
|
+
composed: true,
|
|
2003
|
+
detail: { messageId, reason }
|
|
2004
|
+
}));
|
|
2005
|
+
},
|
|
2006
|
+
onClose: () => panel.remove()
|
|
2007
|
+
});
|
|
2008
|
+
this.querySelector(".aparte-footer")?.after(panel);
|
|
2009
|
+
}
|
|
2010
|
+
/** The tokens a user message was written with, drawn as they looked in the composer. */
|
|
2011
|
+
setTokens(tokens) {
|
|
2012
|
+
this._tokens = tokens;
|
|
2013
|
+
this._drawTokens();
|
|
2014
|
+
}
|
|
2015
|
+
_drawTokens() {
|
|
2016
|
+
if (this._contentEl && this._role === "user" && this._tokens?.length) {
|
|
2017
|
+
drawMessageTokens(this._contentEl, this._content, this._tokens);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
1882
2020
|
/** Set content directly */
|
|
1883
2021
|
setContent(content) {
|
|
1884
2022
|
this._content = content;
|
|
@@ -1944,6 +2082,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
1944
2082
|
if (kept.has(segment.id)) this._applySegmentUpdate(segment.id, segment, segment);
|
|
1945
2083
|
else this._redrawSegment(segment);
|
|
1946
2084
|
}
|
|
2085
|
+
this._syncTurns();
|
|
1947
2086
|
this._reflectError();
|
|
1948
2087
|
this._syncCopyAction();
|
|
1949
2088
|
return true;
|
|
@@ -1952,6 +2091,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
1952
2091
|
addSegment(segment) {
|
|
1953
2092
|
this._segments.push(segment);
|
|
1954
2093
|
this._appendSegmentEl(segment);
|
|
2094
|
+
this._syncTurns();
|
|
1955
2095
|
if (segment.type === "text" && segment.sources) this._syncSources();
|
|
1956
2096
|
this._updateWaiting();
|
|
1957
2097
|
}
|
|
@@ -1966,7 +2106,10 @@ class AparteChatBubble extends HTMLElement {
|
|
|
1966
2106
|
this._applySegmentUpdate(segmentId, updated, updates);
|
|
1967
2107
|
if ("sources" in updates) this._syncSources();
|
|
1968
2108
|
this._syncCopyAction();
|
|
1969
|
-
if ("status" in updates || "isStreaming" in updates)
|
|
2109
|
+
if ("status" in updates || "isStreaming" in updates) {
|
|
2110
|
+
this._syncTurns();
|
|
2111
|
+
this._updateWaiting();
|
|
2112
|
+
}
|
|
1970
2113
|
}
|
|
1971
2114
|
}
|
|
1972
2115
|
/** Append content to a segment */
|
|
@@ -2024,8 +2167,9 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2024
2167
|
this._segments.splice(index, 1);
|
|
2025
2168
|
}
|
|
2026
2169
|
this._release(segmentId);
|
|
2027
|
-
const el2 = this._segmentsEl
|
|
2170
|
+
const el2 = this._segmentsEl ? rowOf(this._segmentsEl, segmentId) : null;
|
|
2028
2171
|
el2?.remove();
|
|
2172
|
+
this._syncTurns();
|
|
2029
2173
|
this._syncSources();
|
|
2030
2174
|
this._updateWaiting();
|
|
2031
2175
|
this._syncCopyAction();
|
|
@@ -2087,8 +2231,8 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2087
2231
|
* Prev/Next clicks dispatch `aparte-branch-navigate` (bubbles: true) so
|
|
2088
2232
|
* the viewport can handle the actual tree switch.
|
|
2089
2233
|
*/
|
|
2090
|
-
setSiblings(
|
|
2091
|
-
this._siblingCount =
|
|
2234
|
+
setSiblings(count2, index) {
|
|
2235
|
+
this._siblingCount = count2;
|
|
2092
2236
|
this._siblingIndex = index;
|
|
2093
2237
|
this._updateBranchPicker();
|
|
2094
2238
|
}
|
|
@@ -2100,6 +2244,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2100
2244
|
this._role = updates.role;
|
|
2101
2245
|
this._updateRole();
|
|
2102
2246
|
}
|
|
2247
|
+
if ("tokens" in updates) this._tokens = updates.tokens;
|
|
2103
2248
|
if ("content" in updates) {
|
|
2104
2249
|
this._content = updates.content;
|
|
2105
2250
|
this._updateContent();
|
|
@@ -2239,11 +2384,11 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2239
2384
|
* be lost with it.
|
|
2240
2385
|
*/
|
|
2241
2386
|
_onCheckpointClick = (event) => {
|
|
2242
|
-
const
|
|
2243
|
-
const separator =
|
|
2244
|
-
if (!
|
|
2245
|
-
if (
|
|
2246
|
-
switch (
|
|
2387
|
+
const button2 = event.target?.closest?.("[data-checkpoint-action]");
|
|
2388
|
+
const separator = button2?.closest(".aparte-checkpoint");
|
|
2389
|
+
if (!button2 || !separator || separator.parentElement !== this) return;
|
|
2390
|
+
if (button2.closest(".aparte-checkpoint__summary")) return;
|
|
2391
|
+
switch (button2.getAttribute("data-checkpoint-action")) {
|
|
2247
2392
|
case "toggle":
|
|
2248
2393
|
this._checkpointOpen = !this._checkpointOpen;
|
|
2249
2394
|
this._updateCheckpoint("toggle");
|
|
@@ -2309,8 +2454,124 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2309
2454
|
if (this._contentEl) this._contentEl.style.display = "none";
|
|
2310
2455
|
this._reflectError();
|
|
2311
2456
|
}
|
|
2457
|
+
/** Whether a segment joins a turn's fold, is passed over by it, or ends it. */
|
|
2458
|
+
_turnRole(segment) {
|
|
2459
|
+
if (segment.type === "thinking") return "fold";
|
|
2460
|
+
if (segment.type !== "tool_call") return "stop";
|
|
2461
|
+
const call = segment;
|
|
2462
|
+
if (this._cfg.isToolHidden(call.toolCall?.name ?? "")) return "skip";
|
|
2463
|
+
if (call.status === "awaiting-approval" || call.status === "failed") return "stop";
|
|
2464
|
+
return this._toolRendererFor(segment) ? "stop" : "fold";
|
|
2465
|
+
}
|
|
2466
|
+
/** The fold a drawn row sits in, or null when it is a direct child. */
|
|
2467
|
+
_turnHolding(row) {
|
|
2468
|
+
const turn = row?.parentElement?.parentElement;
|
|
2469
|
+
return turn?.classList.contains("aparte-turn") && turn.parentElement === this._segmentsEl ? turn : null;
|
|
2470
|
+
}
|
|
2471
|
+
_createTurn() {
|
|
2472
|
+
const turn = document.createElement("details");
|
|
2473
|
+
turn.className = "aparte-turn aparte-accordion__item";
|
|
2474
|
+
const summary = document.createElement("summary");
|
|
2475
|
+
summary.className = "aparte-accordion__header aparte-turn__summary";
|
|
2476
|
+
const label = document.createElement("span");
|
|
2477
|
+
label.className = "aparte-turn__label";
|
|
2478
|
+
const current = document.createElement("span");
|
|
2479
|
+
current.className = "aparte-turn__current";
|
|
2480
|
+
const icon = document.createElement("span");
|
|
2481
|
+
icon.className = "aparte-accordion__icon";
|
|
2482
|
+
icon.innerHTML = this._cfg.getIcon("expand");
|
|
2483
|
+
summary.append(label, current, icon);
|
|
2484
|
+
summary.addEventListener("click", () => {
|
|
2485
|
+
turn.dataset["touched"] = "";
|
|
2486
|
+
});
|
|
2487
|
+
const body = document.createElement("div");
|
|
2488
|
+
body.className = "aparte-accordion__panel aparte-turn__body";
|
|
2489
|
+
turn.append(summary, body);
|
|
2490
|
+
return turn;
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* Fold each run of steps behind its line, by moving the rows already drawn: a moved
|
|
2494
|
+
* `<details>` keeps its open state, a redraw would lose it. Called whenever the plan can
|
|
2495
|
+
* change, never per token. A fold is found again by its members, not by its place, so one
|
|
2496
|
+
* that grows or splits keeps its own open state.
|
|
2497
|
+
*/
|
|
2498
|
+
_syncTurns() {
|
|
2499
|
+
const container = this._segmentsEl;
|
|
2500
|
+
if (!container || this._releasedWhileDetached) return;
|
|
2501
|
+
const options = this._cfg.getTurnSummary();
|
|
2502
|
+
const runs = options ? planTurns(this._segments, (segment) => this._turnRole(segment)) : [];
|
|
2503
|
+
if (runs.length === 0 && !container.querySelector(":scope > .aparte-turn")) return;
|
|
2504
|
+
const place = (parent, node, after) => {
|
|
2505
|
+
const expected = after ? after.nextSibling : parent.firstChild;
|
|
2506
|
+
if (node !== expected) parent.insertBefore(node, expected);
|
|
2507
|
+
return node;
|
|
2508
|
+
};
|
|
2509
|
+
const rowFor = (segment) => this._drawn.get(segment.id)?.el;
|
|
2510
|
+
const used = /* @__PURE__ */ new Set();
|
|
2511
|
+
const startsAt = new Map(runs.map((run) => [run.from, run]));
|
|
2512
|
+
let lastPlaced = null;
|
|
2513
|
+
for (let index = 0; index < this._segments.length; index += 1) {
|
|
2514
|
+
const run = startsAt.get(index);
|
|
2515
|
+
if (!run) {
|
|
2516
|
+
const row = rowFor(this._segments[index]);
|
|
2517
|
+
if (row) lastPlaced = place(container, row, lastPlaced);
|
|
2518
|
+
continue;
|
|
2519
|
+
}
|
|
2520
|
+
const members = this._segments.slice(run.from, run.to + 1);
|
|
2521
|
+
const existing = members.map((member) => this._turnHolding(rowFor(member))).find((held) => held && !used.has(held));
|
|
2522
|
+
const turn = existing ?? this._createTurn();
|
|
2523
|
+
used.add(turn);
|
|
2524
|
+
lastPlaced = place(container, turn, lastPlaced);
|
|
2525
|
+
const body = turn.querySelector(":scope > .aparte-turn__body");
|
|
2526
|
+
let lastInBody = null;
|
|
2527
|
+
for (const member of members) {
|
|
2528
|
+
const row = rowFor(member);
|
|
2529
|
+
if (row) lastInBody = place(body, row, lastInBody);
|
|
2530
|
+
}
|
|
2531
|
+
this._labelTurn(turn, members, run.to === this._segments.length - 1, options?.openWhileRunning === true);
|
|
2532
|
+
index = run.to;
|
|
2533
|
+
}
|
|
2534
|
+
for (const stale of container.querySelectorAll(":scope > .aparte-turn")) {
|
|
2535
|
+
if (!used.has(stale)) stale.remove();
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
/** The fold's one line: what it is doing while it works, what it did once it has. */
|
|
2539
|
+
_labelTurn(turn, members, trailing, openWhileRunning) {
|
|
2540
|
+
const cfg = this._cfg;
|
|
2541
|
+
const steps = members.filter((member) => this._turnRole(member) === "fold");
|
|
2542
|
+
const calls = steps.filter((step) => step.type === "tool_call");
|
|
2543
|
+
const running = this._streaming && trailing || calls.some((call) => !isSegmentSettled(call));
|
|
2544
|
+
const label = turn.querySelector(":scope > summary > .aparte-turn__label");
|
|
2545
|
+
const current = turn.querySelector(":scope > summary > .aparte-turn__current");
|
|
2546
|
+
label.classList.toggle("aparte-shimmer", running);
|
|
2547
|
+
label.textContent = running ? cfg.t("turnWorking") : this._turnOutcome(steps, calls.length);
|
|
2548
|
+
current.textContent = running && calls.length > 0 ? this._stepName(calls.at(-1)) : "";
|
|
2549
|
+
if (openWhileRunning && !("touched" in turn.dataset)) turn.open = running;
|
|
2550
|
+
}
|
|
2551
|
+
_turnOutcome(steps, callCount) {
|
|
2552
|
+
const cfg = this._cfg;
|
|
2553
|
+
const tag = cfg.getLocale().tag || void 0;
|
|
2554
|
+
const tools = callCount > 0 ? pluralize(cfg.t("turnTools"), callCount, tag) : "";
|
|
2555
|
+
const ms = turnDuration(steps);
|
|
2556
|
+
if (ms !== void 0) {
|
|
2557
|
+
const worked = cfg.t("turnWorked").replace("{duration}", () => formatDuration(ms, tag));
|
|
2558
|
+
return tools ? `${worked} · ${tools}` : worked;
|
|
2559
|
+
}
|
|
2560
|
+
return tools ? cfg.t("turnUsed").replace("{tools}", () => tools) : cfg.t("thought");
|
|
2561
|
+
}
|
|
2562
|
+
/** What a call goes by on screen: the label the app gave it, else its identifier. */
|
|
2563
|
+
_stepName(call) {
|
|
2564
|
+
const name = call.toolCall?.name ?? "";
|
|
2565
|
+
const label = this._cfg.getToolDisplay(name)?.label;
|
|
2566
|
+
if (typeof label !== "function") return label ?? name;
|
|
2567
|
+
try {
|
|
2568
|
+
return label(call);
|
|
2569
|
+
} catch {
|
|
2570
|
+
return name;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2312
2573
|
_applySegmentUpdate(segmentId, segment, updates) {
|
|
2313
|
-
const el2 = this._segmentsEl
|
|
2574
|
+
const el2 = this._segmentsEl ? rowOf(this._segmentsEl, segmentId) : null;
|
|
2314
2575
|
if (!el2) {
|
|
2315
2576
|
this._renderSegments();
|
|
2316
2577
|
return;
|
|
@@ -2329,7 +2590,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2329
2590
|
const drawn = this._drawn.get(segmentId);
|
|
2330
2591
|
if (drawn) {
|
|
2331
2592
|
drawn.segment = segment;
|
|
2332
|
-
const now = this._segmentsEl
|
|
2593
|
+
const now = this._segmentsEl ? rowOf(this._segmentsEl, segmentId) : null;
|
|
2333
2594
|
if (now && now !== drawn.el) {
|
|
2334
2595
|
drawn.el = now;
|
|
2335
2596
|
drawn.tool = segment.type === "tool_call" ? toolRendererThatDrew(now) : null;
|
|
@@ -2482,7 +2743,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2482
2743
|
const last = this._segments.at(-1);
|
|
2483
2744
|
const lastEl = this._segmentsEl?.lastElementChild;
|
|
2484
2745
|
const asking = last?.type === "tool_call" && last.status === "awaiting-approval";
|
|
2485
|
-
const betweenSteps = last?.type === "tool_call" && (isSegmentSettled(last) || lastEl?.hidden === true);
|
|
2746
|
+
const betweenSteps = last?.type === "tool_call" && (isSegmentSettled(last) || lastEl?.hidden === true) && lastEl?.classList.contains("aparte-turn") !== true;
|
|
2486
2747
|
const waiting = this._streaming && this._role !== "user" && !asking && (empty || betweenSteps);
|
|
2487
2748
|
const box = this.querySelector(".aparte-message-content");
|
|
2488
2749
|
if (box) box.hidden = empty && !waiting;
|
|
@@ -2589,6 +2850,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2589
2850
|
this._cfg,
|
|
2590
2851
|
() => writeStreamedMarkdown(this, this._contentEl, this._content, this._streaming)
|
|
2591
2852
|
);
|
|
2853
|
+
this._drawTokens();
|
|
2592
2854
|
this._updateWaiting();
|
|
2593
2855
|
if (!this._streaming) this._highlightContentCode();
|
|
2594
2856
|
}
|
|
@@ -2642,6 +2904,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2642
2904
|
this._install(segment, el2, void 0);
|
|
2643
2905
|
}
|
|
2644
2906
|
}
|
|
2907
|
+
this._syncTurns();
|
|
2645
2908
|
if (this._contentEl) {
|
|
2646
2909
|
this._contentEl.style.display = this._segments.length > 0 ? "none" : "";
|
|
2647
2910
|
}
|
|
@@ -2782,9 +3045,9 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2782
3045
|
*/
|
|
2783
3046
|
_onBranchPickerClick = (event) => {
|
|
2784
3047
|
const target = event.target;
|
|
2785
|
-
const
|
|
2786
|
-
if (!
|
|
2787
|
-
const direction =
|
|
3048
|
+
const button2 = target?.closest?.(".aparte-branch-prev, .aparte-branch-next");
|
|
3049
|
+
if (!button2 || !this.contains(button2)) return;
|
|
3050
|
+
const direction = button2.classList.contains("aparte-branch-prev") ? "prev" : "next";
|
|
2788
3051
|
const messageId = this.getAttribute("message-id");
|
|
2789
3052
|
if (!messageId) return;
|
|
2790
3053
|
const detail = { messageId, direction };
|
|
@@ -2960,7 +3223,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2960
3223
|
const usable = buttons.filter((b2) => !b2.disabled);
|
|
2961
3224
|
const current = buttons.find((b2) => b2.tabIndex === 0 && !b2.disabled);
|
|
2962
3225
|
const stop = current ?? usable[0] ?? buttons[0];
|
|
2963
|
-
for (const
|
|
3226
|
+
for (const button2 of buttons) button2.tabIndex = button2 === stop ? 0 : -1;
|
|
2964
3227
|
}
|
|
2965
3228
|
/**
|
|
2966
3229
|
* Left/Right walk the bar, Home/End jump to its ends, and both wrap.
|
|
@@ -2987,7 +3250,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
2987
3250
|
else if (event.key === forward) next = (from + 1) % buttons.length;
|
|
2988
3251
|
else next = (from - 1 + buttons.length) % buttons.length;
|
|
2989
3252
|
event.preventDefault();
|
|
2990
|
-
for (const
|
|
3253
|
+
for (const button2 of this._rovingButtons()) button2.tabIndex = button2 === buttons[next] ? 0 : -1;
|
|
2991
3254
|
buttons[next]?.focus();
|
|
2992
3255
|
};
|
|
2993
3256
|
/**
|
|
@@ -3144,6 +3407,8 @@ class AparteChatBubble extends HTMLElement {
|
|
|
3144
3407
|
composed: true,
|
|
3145
3408
|
detail
|
|
3146
3409
|
}));
|
|
3410
|
+
if (value === "negative") this._askFeedbackReason(messageId);
|
|
3411
|
+
else this.querySelector(".aparte-feedback-reasons")?.remove();
|
|
3147
3412
|
break;
|
|
3148
3413
|
}
|
|
3149
3414
|
case "info": {
|
|
@@ -3216,7 +3481,7 @@ class AparteChatBubble extends HTMLElement {
|
|
|
3216
3481
|
const back = Array.from(this._actionBarEl.querySelectorAll("[data-action]")).find((btn) => btn.getAttribute("data-action") === returnTo);
|
|
3217
3482
|
const target = back && !back.disabled ? back : this._actionBarEl.querySelector("button:not([disabled])");
|
|
3218
3483
|
if (target) {
|
|
3219
|
-
for (const
|
|
3484
|
+
for (const button2 of this._rovingButtons()) button2.tabIndex = button2 === target ? 0 : -1;
|
|
3220
3485
|
target.focus();
|
|
3221
3486
|
}
|
|
3222
3487
|
}
|
|
@@ -3262,12 +3527,14 @@ class AparteChatBubble extends HTMLElement {
|
|
|
3262
3527
|
message.removeAttribute("aria-busy");
|
|
3263
3528
|
message.classList.remove("aparte-message-streaming");
|
|
3264
3529
|
}
|
|
3530
|
+
message.toggleAttribute("data-caret", streaming && this._cfg.getStreamingCaret());
|
|
3265
3531
|
}
|
|
3266
3532
|
this._updateWaiting();
|
|
3267
3533
|
this._updateFinishNote();
|
|
3268
3534
|
if (wasStreaming && !streaming) this._updateContent();
|
|
3269
3535
|
if (wasStreaming && !streaming) this._settleWrittenSegments();
|
|
3270
3536
|
if (wasStreaming && !streaming && this._segments.length > 0) this._redrawIfStale();
|
|
3537
|
+
this._syncTurns();
|
|
3271
3538
|
}
|
|
3272
3539
|
}
|
|
3273
3540
|
deferHydrationOf(AparteChatBubble);
|
|
@@ -3462,6 +3729,13 @@ function markDerivedSegments(message) {
|
|
|
3462
3729
|
function hasDerivedSegments(message) {
|
|
3463
3730
|
return message[APARTE_DERIVED_SEGMENTS] === true;
|
|
3464
3731
|
}
|
|
3732
|
+
function longDate(at, tag) {
|
|
3733
|
+
try {
|
|
3734
|
+
return new Intl.DateTimeFormat(tag || void 0, { dateStyle: "long" }).format(at);
|
|
3735
|
+
} catch {
|
|
3736
|
+
return at.toDateString();
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3465
3739
|
class AparteChatViewport extends HTMLElement {
|
|
3466
3740
|
// The scroll surface: an internal `.aparte-viewport-container` div (core mode)
|
|
3467
3741
|
// or the host element itself (framework-managed mode). HTMLElement covers both.
|
|
@@ -3663,6 +3937,7 @@ class AparteChatViewport extends HTMLElement {
|
|
|
3663
3937
|
this._scrollBtn?.setAttribute("aria-label", resolveConfig(this).t("scrollToBottom"));
|
|
3664
3938
|
const surface = this._frameworkManagedDOM ? this : this.querySelector(".aparte-viewport-container");
|
|
3665
3939
|
surface?.setAttribute("aria-label", resolveConfig(this).t("transcript"));
|
|
3940
|
+
this._syncDateSeparators();
|
|
3666
3941
|
};
|
|
3667
3942
|
/**
|
|
3668
3943
|
* The transcript is a TAB STOP, with a name.
|
|
@@ -4373,6 +4648,30 @@ class AparteChatViewport extends HTMLElement {
|
|
|
4373
4648
|
break;
|
|
4374
4649
|
}
|
|
4375
4650
|
}
|
|
4651
|
+
/** The day on the first bubble of each one, by what is on screen: a branch has its own days. */
|
|
4652
|
+
_syncDateSeparators() {
|
|
4653
|
+
const cfg = resolveConfig(this);
|
|
4654
|
+
const on = cfg.getDateSeparators();
|
|
4655
|
+
if (!on && !this.querySelector("aparte-chat-bubble[data-date]")) return;
|
|
4656
|
+
const now = /* @__PURE__ */ new Date();
|
|
4657
|
+
const dayOf = (at) => new Date(at.getFullYear(), at.getMonth(), at.getDate()).getTime();
|
|
4658
|
+
const today = dayOf(now);
|
|
4659
|
+
let previous = null;
|
|
4660
|
+
this.querySelectorAll("aparte-chat-bubble").forEach((bubble) => {
|
|
4661
|
+
const raw = Number(bubble.getAttribute("timestamp"));
|
|
4662
|
+
const at = raw ? new Date(raw) : null;
|
|
4663
|
+
const day = at ? dayOf(at) : null;
|
|
4664
|
+
const starts = on && at && day !== previous;
|
|
4665
|
+
if (day !== null) previous = day;
|
|
4666
|
+
if (!starts || !at) {
|
|
4667
|
+
if (bubble.hasAttribute("data-date")) bubble.removeAttribute("data-date");
|
|
4668
|
+
return;
|
|
4669
|
+
}
|
|
4670
|
+
const elapsed = Math.round((today - day) / 864e5);
|
|
4671
|
+
const label = elapsed === 0 ? cfg.t("conversationGroupToday") : elapsed === 1 ? cfg.t("conversationGroupYesterday") : longDate(at, cfg.getLocale().tag);
|
|
4672
|
+
if (bubble.getAttribute("data-date") !== label) bubble.setAttribute("data-date", label);
|
|
4673
|
+
});
|
|
4674
|
+
}
|
|
4376
4675
|
/**
|
|
4377
4676
|
* Re-render the active path: clears the messages wrapper and rebuilds bubbles
|
|
4378
4677
|
* for every message on the current active branch path (root → head).
|
|
@@ -4411,6 +4710,7 @@ class AparteChatViewport extends HTMLElement {
|
|
|
4411
4710
|
wrapper.appendChild(bubble);
|
|
4412
4711
|
populateBubbleFromMessage(bubble, message, sibInfo);
|
|
4413
4712
|
}
|
|
4713
|
+
this._syncDateSeparators();
|
|
4414
4714
|
this._dispatchPathChanged(activeMessages, siblingsInfo);
|
|
4415
4715
|
this._syncBusy();
|
|
4416
4716
|
this._checkpointState?.reapply();
|
|
@@ -4638,6 +4938,9 @@ class AparteChatViewport extends HTMLElement {
|
|
|
4638
4938
|
}
|
|
4639
4939
|
this._mutationObserver = new MutationObserver((mutations) => {
|
|
4640
4940
|
this._lastMutationAt = performance.now();
|
|
4941
|
+
if (mutations.some((m2) => m2.type === "childList" && (m2.target === this || m2.target.classList?.contains("aparte-messages-wrapper")))) {
|
|
4942
|
+
this._syncDateSeparators();
|
|
4943
|
+
}
|
|
4641
4944
|
if (this._frameworkManagedDOM) this._keepScrollButtonLast();
|
|
4642
4945
|
if (this._isAutoScrollEnabled && !this._gliding()) {
|
|
4643
4946
|
const added = mutations.flatMap((m2) => Array.from(m2.addedNodes)).filter((n2) => n2 instanceof Element && n2.tagName === "APARTE-CHAT-BUBBLE");
|
|
@@ -5071,6 +5374,11 @@ deferHydrationOf(AparteChatViewport);
|
|
|
5071
5374
|
if (!customElements.get("aparte-chat-viewport")) {
|
|
5072
5375
|
customElements.define("aparte-chat-viewport", AparteChatViewport);
|
|
5073
5376
|
}
|
|
5377
|
+
const ONE_LINE_INPUTS = /* @__PURE__ */ new Set(["text", "search", "email", "url", "tel", "number", "password"]);
|
|
5378
|
+
function isOneLineField(target) {
|
|
5379
|
+
if (target instanceof HTMLTextAreaElement) return target.rows === 1;
|
|
5380
|
+
return target instanceof HTMLInputElement && ONE_LINE_INPUTS.has(target.type);
|
|
5381
|
+
}
|
|
5074
5382
|
class AparteComposer extends HTMLElement {
|
|
5075
5383
|
_value = "";
|
|
5076
5384
|
_streaming = false;
|
|
@@ -5201,7 +5509,8 @@ class AparteComposer extends HTMLElement {
|
|
|
5201
5509
|
}
|
|
5202
5510
|
/**
|
|
5203
5511
|
* When false, Shift+Enter submits and a bare Enter inserts a newline —
|
|
5204
|
-
* the inverse of the default. Driven by the `submit-on-enter` attribute
|
|
5512
|
+
* the inverse of the default. Driven by the `submit-on-enter` attribute, and it
|
|
5513
|
+
* holds in a panel's one-line fields as it does in the editor.
|
|
5205
5514
|
*/
|
|
5206
5515
|
get submitOnEnter() {
|
|
5207
5516
|
return this.getAttribute("submit-on-enter") !== "false";
|
|
@@ -5261,6 +5570,28 @@ class AparteComposer extends HTMLElement {
|
|
|
5261
5570
|
this._attachments = [...this._attachments, ...Array.from(files)];
|
|
5262
5571
|
this._emit("attachments-change", { attachments: this._attachments });
|
|
5263
5572
|
}
|
|
5573
|
+
/**
|
|
5574
|
+
* Show how an attachment's upload is going, for an app that uploads as soon as a file
|
|
5575
|
+
* is picked. While one is `uploading`, nothing is sent. `null` clears it.
|
|
5576
|
+
*/
|
|
5577
|
+
setAttachmentState(file, state) {
|
|
5578
|
+
if (state) this._attachmentStates.set(file, state);
|
|
5579
|
+
else this._attachmentStates.delete(file);
|
|
5580
|
+
this._syncUploading();
|
|
5581
|
+
this.querySelector("aparte-composer-attachments")?.showState(file, state);
|
|
5582
|
+
}
|
|
5583
|
+
/** The state {@link setAttachmentState} last gave this file. */
|
|
5584
|
+
getAttachmentState(file) {
|
|
5585
|
+
return this._attachmentStates.get(file);
|
|
5586
|
+
}
|
|
5587
|
+
_attachmentStates = /* @__PURE__ */ new WeakMap();
|
|
5588
|
+
get _uploading() {
|
|
5589
|
+
return this._attachments.some((file) => this._attachmentStates.get(file)?.status === "uploading");
|
|
5590
|
+
}
|
|
5591
|
+
/** Reflected for the shipped CSS, the way the model gate is. */
|
|
5592
|
+
_syncUploading() {
|
|
5593
|
+
this.toggleAttribute("data-uploading", this._uploading);
|
|
5594
|
+
}
|
|
5264
5595
|
/**
|
|
5265
5596
|
* Drop one pending attachment and notify. Matched by IDENTITY — pass the same
|
|
5266
5597
|
* `File` object the composer handed you, not an equal one; two picks of the same
|
|
@@ -5268,11 +5599,13 @@ class AparteComposer extends HTMLElement {
|
|
|
5268
5599
|
*/
|
|
5269
5600
|
removeAttachment(file) {
|
|
5270
5601
|
this._attachments = this._attachments.filter((f2) => f2 !== file);
|
|
5602
|
+
this._syncUploading();
|
|
5271
5603
|
this._emit("attachments-change", { attachments: this._attachments });
|
|
5272
5604
|
}
|
|
5273
5605
|
/** Drop every pending attachment and notify. */
|
|
5274
5606
|
clearAttachments() {
|
|
5275
5607
|
this._attachments = [];
|
|
5608
|
+
this._syncUploading();
|
|
5276
5609
|
this._emit("attachments-change", { attachments: [] });
|
|
5277
5610
|
}
|
|
5278
5611
|
/**
|
|
@@ -5309,6 +5642,7 @@ class AparteComposer extends HTMLElement {
|
|
|
5309
5642
|
const inputEl = this.querySelector("aparte-composer-input");
|
|
5310
5643
|
this.setAttribute("data-panel-active", "");
|
|
5311
5644
|
panel.dataset["apartePanel"] = "true";
|
|
5645
|
+
panel.addEventListener("keydown", this._onPanelKeydown);
|
|
5312
5646
|
if (host) {
|
|
5313
5647
|
host.appendChild(panel);
|
|
5314
5648
|
} else if (inputEl) {
|
|
@@ -5354,6 +5688,28 @@ class AparteComposer extends HTMLElement {
|
|
|
5354
5688
|
}
|
|
5355
5689
|
this._evictPanel();
|
|
5356
5690
|
}
|
|
5691
|
+
/**
|
|
5692
|
+
* Enter in a panel's one-line field presses the send button, as it does in the editor.
|
|
5693
|
+
*
|
|
5694
|
+
* The panel takes the editor's place and the editor was the only thing listening, so
|
|
5695
|
+
* what a person wrote in a panel went out by mouse alone: Enter added a line to an
|
|
5696
|
+
* approval's instruction and did nothing in a question's text box. It lives here, once,
|
|
5697
|
+
* because the button is the composer's and so is `submit-on-enter`; `submit()` then
|
|
5698
|
+
* applies the panel's own gates (no act for the button, nothing written, put aside).
|
|
5699
|
+
* The key is cancelled even when nothing can be sent, as the editor does, so an empty
|
|
5700
|
+
* field does not fill with blank lines.
|
|
5701
|
+
*
|
|
5702
|
+
* Same IME guard as the editor: that Enter confirms a candidate. `defaultPrevented`
|
|
5703
|
+
* leaves the key to a field that used it, a combobox picking its highlighted row.
|
|
5704
|
+
*/
|
|
5705
|
+
_onPanelKeydown = (e) => {
|
|
5706
|
+
if (e.key !== "Enter" || e.isComposing || e.keyCode === 229 || e.defaultPrevented) return;
|
|
5707
|
+
if (!isOneLineField(e.target)) return;
|
|
5708
|
+
const submits = this.submitOnEnter ? !e.shiftKey : e.shiftKey;
|
|
5709
|
+
if (!submits) return;
|
|
5710
|
+
e.preventDefault();
|
|
5711
|
+
this.submit();
|
|
5712
|
+
};
|
|
5357
5713
|
/** Close the panel AND tell its owner, so a pending request never orphans. */
|
|
5358
5714
|
_evictPanel() {
|
|
5359
5715
|
const onEvict = this._panelOnEvict;
|
|
@@ -5432,7 +5788,9 @@ class AparteComposer extends HTMLElement {
|
|
|
5432
5788
|
if (!value && this._attachments.length === 0) return;
|
|
5433
5789
|
if (this.disabled) return;
|
|
5434
5790
|
if (this._modelGated) return;
|
|
5791
|
+
if (this._uploading) return;
|
|
5435
5792
|
this._emit("submit", { value, attachments: this._attachments });
|
|
5793
|
+
const tokens = this.querySelector("aparte-composer-input")?.getTokens?.();
|
|
5436
5794
|
const detail = {
|
|
5437
5795
|
content: value,
|
|
5438
5796
|
timestamp: Date.now(),
|
|
@@ -5444,7 +5802,8 @@ class AparteComposer extends HTMLElement {
|
|
|
5444
5802
|
* reply to whichever one the host resolved first.
|
|
5445
5803
|
*/
|
|
5446
5804
|
targetId: this._ownTargetId(),
|
|
5447
|
-
files: this._attachments.length > 0 ? [...this._attachments] : void 0
|
|
5805
|
+
files: this._attachments.length > 0 ? [...this._attachments] : void 0,
|
|
5806
|
+
...tokens?.length ? { tokens } : {}
|
|
5448
5807
|
};
|
|
5449
5808
|
this.dispatchEvent(new CustomEvent("aparte-send", {
|
|
5450
5809
|
bubbles: true,
|
|
@@ -5585,6 +5944,88 @@ function acceptsFile(accept, file) {
|
|
|
5585
5944
|
const type = file.type.toLowerCase();
|
|
5586
5945
|
return tokens.some((token) => token.startsWith(".") ? name.endsWith(token) : token.endsWith("/*") ? type.startsWith(token.slice(0, -1)) : type === token);
|
|
5587
5946
|
}
|
|
5947
|
+
const TOKEN_ATTR = "data-aparte-token";
|
|
5948
|
+
const TEXT_ATTR = "data-aparte-text";
|
|
5949
|
+
const TOKEN_CHAR = "";
|
|
5950
|
+
const isText = (node) => node.nodeType === Node.TEXT_NODE;
|
|
5951
|
+
const isToken = (node) => node.nodeType === Node.ELEMENT_NODE && node.hasAttribute(TOKEN_ATTR);
|
|
5952
|
+
const indexIn = (node) => Array.prototype.indexOf.call(node.parentNode.childNodes, node);
|
|
5953
|
+
function leaves(root, out = []) {
|
|
5954
|
+
root.childNodes.forEach((child) => {
|
|
5955
|
+
if (isText(child) || child.nodeName === "BR" || isToken(child)) out.push(child);
|
|
5956
|
+
else leaves(child, out);
|
|
5957
|
+
});
|
|
5958
|
+
return out;
|
|
5959
|
+
}
|
|
5960
|
+
const sizeOf = (leaf) => isText(leaf) ? leaf.data.length : 1;
|
|
5961
|
+
function flatText(editor) {
|
|
5962
|
+
return leaves(editor).map((leaf) => isText(leaf) ? leaf.data : leaf.nodeName === "BR" ? "\n" : TOKEN_CHAR).join("");
|
|
5963
|
+
}
|
|
5964
|
+
function flatOffset(editor, container, offset) {
|
|
5965
|
+
const point = editor.ownerDocument.createRange();
|
|
5966
|
+
point.setStart(container, offset);
|
|
5967
|
+
point.collapse(true);
|
|
5968
|
+
let flat = 0;
|
|
5969
|
+
for (const leaf of leaves(editor)) {
|
|
5970
|
+
if (leaf === container) return flat + offset;
|
|
5971
|
+
if (point.comparePoint(leaf.parentNode, indexIn(leaf)) >= 0) return flat;
|
|
5972
|
+
flat += sizeOf(leaf);
|
|
5973
|
+
}
|
|
5974
|
+
return flat;
|
|
5975
|
+
}
|
|
5976
|
+
function domPoint(editor, flat) {
|
|
5977
|
+
let left = flat;
|
|
5978
|
+
for (const leaf of leaves(editor)) {
|
|
5979
|
+
if (isText(leaf) && left <= leaf.data.length) return [leaf, left];
|
|
5980
|
+
if (left === 0) return [leaf.parentNode, indexIn(leaf)];
|
|
5981
|
+
left -= sizeOf(leaf);
|
|
5982
|
+
}
|
|
5983
|
+
return [editor, editor.childNodes.length];
|
|
5984
|
+
}
|
|
5985
|
+
function flatRange(editor, from, to) {
|
|
5986
|
+
const range = editor.ownerDocument.createRange();
|
|
5987
|
+
range.setStart(...domPoint(editor, from));
|
|
5988
|
+
range.setEnd(...domPoint(editor, to));
|
|
5989
|
+
return range;
|
|
5990
|
+
}
|
|
5991
|
+
function tokenElement(doc, id, token) {
|
|
5992
|
+
const el2 = doc.createElement("span");
|
|
5993
|
+
el2.className = "aparte-tag aparte-inline-token";
|
|
5994
|
+
el2.setAttribute("contenteditable", "false");
|
|
5995
|
+
el2.setAttribute(TOKEN_ATTR, id);
|
|
5996
|
+
el2.setAttribute(TEXT_ATTR, token.text ?? token.label);
|
|
5997
|
+
if (token.kind) el2.dataset["kind"] = token.kind;
|
|
5998
|
+
const label = doc.createElement("span");
|
|
5999
|
+
label.className = "aparte-tag__label";
|
|
6000
|
+
label.textContent = token.label;
|
|
6001
|
+
el2.appendChild(label);
|
|
6002
|
+
return el2;
|
|
6003
|
+
}
|
|
6004
|
+
function serializeDraft(editor, known) {
|
|
6005
|
+
let out = "";
|
|
6006
|
+
const tokens = [];
|
|
6007
|
+
for (const leaf of leaves(editor)) {
|
|
6008
|
+
if (isText(leaf)) out += leaf.data;
|
|
6009
|
+
else if (leaf.nodeName === "BR") out += "\n";
|
|
6010
|
+
else {
|
|
6011
|
+
const el2 = leaf;
|
|
6012
|
+
const source = known.get(el2.getAttribute(TOKEN_ATTR) ?? "");
|
|
6013
|
+
const text = el2.getAttribute(TEXT_ATTR) ?? el2.textContent ?? "";
|
|
6014
|
+
const start = out.length;
|
|
6015
|
+
out += text;
|
|
6016
|
+
tokens.push({
|
|
6017
|
+
label: el2.textContent ?? "",
|
|
6018
|
+
text,
|
|
6019
|
+
start,
|
|
6020
|
+
end: out.length,
|
|
6021
|
+
...el2.dataset["kind"] ? { kind: el2.dataset["kind"] } : {},
|
|
6022
|
+
...source?.data !== void 0 ? { data: source.data } : {}
|
|
6023
|
+
});
|
|
6024
|
+
}
|
|
6025
|
+
}
|
|
6026
|
+
const lead = out.length - out.trimStart().length;
|
|
6027
|
+
return { value: out.trim(), tokens: tokens.map((token) => ({ ...token, start: token.start - lead, end: token.end - lead })) };
|
|
6028
|
+
}
|
|
5588
6029
|
class AparteComposerInput extends HTMLElement {
|
|
5589
6030
|
_editor = null;
|
|
5590
6031
|
_maxHeight = 200;
|
|
@@ -5642,22 +6083,48 @@ class AparteComposerInput extends HTMLElement {
|
|
|
5642
6083
|
* alone would collapse a multi-line draft onto a single line.
|
|
5643
6084
|
*/
|
|
5644
6085
|
getValue() {
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
6086
|
+
return this._editor ? serializeDraft(this._editor, this._tokens).value : "";
|
|
6087
|
+
}
|
|
6088
|
+
/** The tokens in the draft, with their place in {@link getValue}. */
|
|
6089
|
+
getTokens() {
|
|
6090
|
+
return this._editor ? serializeDraft(this._editor, this._tokens).tokens : [];
|
|
6091
|
+
}
|
|
6092
|
+
/** The caret, or `null` when the editor does not hold a collapsed selection. */
|
|
6093
|
+
getCaret() {
|
|
6094
|
+
const sel = this.ownerDocument?.getSelection();
|
|
6095
|
+
if (!this._editor || !sel?.rangeCount || !sel.isCollapsed || !this._editor.contains(sel.anchorNode)) return null;
|
|
6096
|
+
return { text: flatText(this._editor), offset: flatOffset(this._editor, sel.anchorNode, sel.anchorOffset) };
|
|
6097
|
+
}
|
|
6098
|
+
/** The box of a range of the draft on screen, to anchor something to the text. */
|
|
6099
|
+
getRangeRect(from, to = from) {
|
|
6100
|
+
if (!this._editor) return null;
|
|
6101
|
+
const range = flatRange(this._editor, from, to);
|
|
6102
|
+
return range.getClientRects?.()[0] ?? null;
|
|
6103
|
+
}
|
|
6104
|
+
/** Replace a range of the draft with text, and leave the caret after it. */
|
|
6105
|
+
replaceRange(from, to, text) {
|
|
6106
|
+
this._write(from, to, () => text ? this._insertPlain(text) : this._exec("delete"), () => this.ownerDocument.createTextNode(text));
|
|
6107
|
+
}
|
|
6108
|
+
/**
|
|
6109
|
+
* Replace a range of the draft with a token, followed by a space for the caret to land
|
|
6110
|
+
* on: a caret cannot rest after something that is not editable at the end of a line.
|
|
6111
|
+
*/
|
|
6112
|
+
insertToken(from, to, token) {
|
|
6113
|
+
const id = String(++this._lastTokenId);
|
|
6114
|
+
this._tokens.set(id, token);
|
|
6115
|
+
const doc = this.ownerDocument;
|
|
6116
|
+
const fragment = () => {
|
|
6117
|
+
const out = doc.createDocumentFragment();
|
|
6118
|
+
out.append(tokenElement(doc, id, token), doc.createTextNode(" "));
|
|
6119
|
+
return out;
|
|
5653
6120
|
};
|
|
5654
|
-
|
|
5655
|
-
return out.trim();
|
|
6121
|
+
this._write(from, to, () => this._exec("insertHTML", `${tokenElement(doc, id, token).outerHTML} `), fragment);
|
|
5656
6122
|
}
|
|
5657
6123
|
/** Replace the editor's content and mirror the value onto the parent composer. */
|
|
5658
6124
|
setValue(value) {
|
|
5659
6125
|
if (!this._editor) return;
|
|
5660
6126
|
this._editor.textContent = value;
|
|
6127
|
+
this._tokens.clear();
|
|
5661
6128
|
this._updatePlaceholderVisibility();
|
|
5662
6129
|
this._adjustHeight();
|
|
5663
6130
|
this._getRoot()?.setValue(value);
|
|
@@ -5666,6 +6133,7 @@ class AparteComposerInput extends HTMLElement {
|
|
|
5666
6133
|
clear() {
|
|
5667
6134
|
if (!this._editor) return;
|
|
5668
6135
|
this._editor.innerHTML = "";
|
|
6136
|
+
this._tokens.clear();
|
|
5669
6137
|
this._updatePlaceholderVisibility();
|
|
5670
6138
|
this._adjustHeight();
|
|
5671
6139
|
this._getRoot()?.setValue("");
|
|
@@ -5702,6 +6170,48 @@ class AparteComposerInput extends HTMLElement {
|
|
|
5702
6170
|
_getRoot() {
|
|
5703
6171
|
return this.closest("aparte-composer");
|
|
5704
6172
|
}
|
|
6173
|
+
/** What each pill in the editor stands for; a pill brought back by Undo finds its data here. */
|
|
6174
|
+
_tokens = /* @__PURE__ */ new Map();
|
|
6175
|
+
_lastTokenId = 0;
|
|
6176
|
+
/**
|
|
6177
|
+
* Through the browser's own edit commands, or Undo would not know about the change;
|
|
6178
|
+
* straight on the DOM where it has none.
|
|
6179
|
+
*/
|
|
6180
|
+
_write(from, to, edit, fallback) {
|
|
6181
|
+
const editor = this._editor;
|
|
6182
|
+
const sel = this.ownerDocument?.getSelection();
|
|
6183
|
+
if (!editor || !sel) return;
|
|
6184
|
+
editor.focus();
|
|
6185
|
+
const range = flatRange(editor, from, to);
|
|
6186
|
+
sel.removeAllRanges();
|
|
6187
|
+
sel.addRange(range);
|
|
6188
|
+
if (edit()) return;
|
|
6189
|
+
range.deleteContents();
|
|
6190
|
+
const node = fallback();
|
|
6191
|
+
const last = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? node.lastChild : node;
|
|
6192
|
+
range.insertNode(node);
|
|
6193
|
+
range.setStartAfter(last);
|
|
6194
|
+
range.collapse(true);
|
|
6195
|
+
sel.removeAllRanges();
|
|
6196
|
+
sel.addRange(range);
|
|
6197
|
+
this._handleInput();
|
|
6198
|
+
}
|
|
6199
|
+
/** A browser edit command, or `false` where there is none: a caller then edits the DOM. */
|
|
6200
|
+
_exec(command, value) {
|
|
6201
|
+
try {
|
|
6202
|
+
return this.ownerDocument.execCommand(command, false, value);
|
|
6203
|
+
} catch {
|
|
6204
|
+
return false;
|
|
6205
|
+
}
|
|
6206
|
+
}
|
|
6207
|
+
/**
|
|
6208
|
+
* Plain text, as one edit. Several lines go as `<br>`s, because `insertText` makes each
|
|
6209
|
+
* line a block, and the draft is read flat: the lines would be sent run together.
|
|
6210
|
+
*/
|
|
6211
|
+
_insertPlain(text) {
|
|
6212
|
+
if (!/[\r\n]/.test(text)) return this._exec("insertText", text);
|
|
6213
|
+
return this._exec("insertHTML", escapeHtml(text).replace(/\r\n?|\n/g, "<br>"));
|
|
6214
|
+
}
|
|
5705
6215
|
_getPlaceholder() {
|
|
5706
6216
|
return this.getAttribute("placeholder") || this._getRoot()?.placeholder || resolveConfig(this).t("inputPlaceholder") || "Type a message...";
|
|
5707
6217
|
}
|
|
@@ -5747,6 +6257,7 @@ class AparteComposerInput extends HTMLElement {
|
|
|
5747
6257
|
}
|
|
5748
6258
|
_handleKeydown(e) {
|
|
5749
6259
|
if (e.isComposing || e.keyCode === 229) return;
|
|
6260
|
+
if (e.defaultPrevented) return;
|
|
5750
6261
|
if (e.key !== "Enter") return;
|
|
5751
6262
|
const submitOnEnter = this._getRoot()?.submitOnEnter ?? true;
|
|
5752
6263
|
const submits = submitOnEnter ? !e.shiftKey : e.shiftKey;
|
|
@@ -5783,9 +6294,7 @@ class AparteComposerInput extends HTMLElement {
|
|
|
5783
6294
|
return;
|
|
5784
6295
|
}
|
|
5785
6296
|
const text = cd.getData("text/plain");
|
|
5786
|
-
if (text)
|
|
5787
|
-
document.execCommand("insertText", false, text);
|
|
5788
|
-
}
|
|
6297
|
+
if (text) this._insertPlain(text);
|
|
5789
6298
|
}
|
|
5790
6299
|
_adjustHeight() {
|
|
5791
6300
|
if (!this._editor) return;
|
|
@@ -6094,6 +6603,36 @@ class AparteComposerAttachments extends HTMLElement {
|
|
|
6094
6603
|
);
|
|
6095
6604
|
this._render(root.attachments);
|
|
6096
6605
|
}
|
|
6606
|
+
/** Draw how a file's upload is going on its tile. */
|
|
6607
|
+
showState(file, state) {
|
|
6608
|
+
const index = this._getRoot()?.attachments.indexOf(file) ?? -1;
|
|
6609
|
+
const tile = this.querySelectorAll(".aparte-thumb")[index];
|
|
6610
|
+
if (!tile) return;
|
|
6611
|
+
tile.toggleAttribute("data-failed", state?.status === "error");
|
|
6612
|
+
let bar = tile.querySelector(".aparte-progress");
|
|
6613
|
+
if (state?.status !== "uploading") {
|
|
6614
|
+
bar?.remove();
|
|
6615
|
+
return;
|
|
6616
|
+
}
|
|
6617
|
+
if (!bar) {
|
|
6618
|
+
bar = document.createElement("div");
|
|
6619
|
+
bar.className = "aparte-progress aparte-thumb__progress";
|
|
6620
|
+
bar.setAttribute("role", "progressbar");
|
|
6621
|
+
bar.setAttribute("aria-label", file.name);
|
|
6622
|
+
bar.innerHTML = '<div class="aparte-progress__bar"></div>';
|
|
6623
|
+
tile.appendChild(bar);
|
|
6624
|
+
}
|
|
6625
|
+
const known = state.progress !== void 0;
|
|
6626
|
+
bar.classList.toggle("aparte-progress--indeterminate", !known);
|
|
6627
|
+
if (known) {
|
|
6628
|
+
bar.setAttribute("aria-valuenow", String(state.progress));
|
|
6629
|
+
bar.setAttribute("aria-valuemin", "0");
|
|
6630
|
+
bar.setAttribute("aria-valuemax", "100");
|
|
6631
|
+
bar.style.setProperty("--aparte-progress-value", String(state.progress));
|
|
6632
|
+
} else {
|
|
6633
|
+
bar.removeAttribute("aria-valuenow");
|
|
6634
|
+
}
|
|
6635
|
+
}
|
|
6097
6636
|
/** Release the previous render's blob URLs so they don't leak. */
|
|
6098
6637
|
_revokeUrls() {
|
|
6099
6638
|
this._objectUrls.forEach((url) => URL.revokeObjectURL(url));
|
|
@@ -6114,6 +6653,11 @@ class AparteComposerAttachments extends HTMLElement {
|
|
|
6114
6653
|
}
|
|
6115
6654
|
return `<div class="aparte-thumbnail aparte-thumb aparte-thumb--file" title="${name}"><span class="aparte-thumbnail__label">${escapeHtml(this._ext(file.name))}</span><span class="aparte-thumb__name">${name}</span>${remove}</div>`;
|
|
6116
6655
|
}).join("");
|
|
6656
|
+
const composer = this._getRoot();
|
|
6657
|
+
if (composer) for (const file of files) {
|
|
6658
|
+
const state = composer.getAttachmentState(file);
|
|
6659
|
+
if (state) this.showState(file, state);
|
|
6660
|
+
}
|
|
6117
6661
|
this.querySelectorAll(".aparte-thumb__remove").forEach((btn, i2) => {
|
|
6118
6662
|
btn.addEventListener("click", (e) => {
|
|
6119
6663
|
e.stopPropagation();
|
|
@@ -6833,7 +7377,7 @@ class AparteConversationList extends HTMLElement {
|
|
|
6833
7377
|
</div>
|
|
6834
7378
|
</div>`;
|
|
6835
7379
|
}
|
|
6836
|
-
_openMenu(row,
|
|
7380
|
+
_openMenu(row, button2) {
|
|
6837
7381
|
this._closeMenu();
|
|
6838
7382
|
const id = row.dataset["convId"];
|
|
6839
7383
|
const conv = this._conversations.find((c2) => c2.id === id);
|
|
@@ -6844,9 +7388,9 @@ class AparteConversationList extends HTMLElement {
|
|
|
6844
7388
|
menu.setAttribute("aria-label", conv.title || this._t("newChat"));
|
|
6845
7389
|
menu.innerHTML = this._menuMarkup(conv);
|
|
6846
7390
|
row.appendChild(menu);
|
|
6847
|
-
|
|
6848
|
-
this._open = { id, row, button, menu };
|
|
6849
|
-
this._placeMenu(
|
|
7391
|
+
button2.setAttribute("aria-expanded", "true");
|
|
7392
|
+
this._open = { id, row, button: button2, menu };
|
|
7393
|
+
this._placeMenu(button2, menu);
|
|
6850
7394
|
menu.querySelector('[role="menuitem"]')?.focus();
|
|
6851
7395
|
document.addEventListener("pointerdown", this._onDocumentPointerDown, true);
|
|
6852
7396
|
document.addEventListener("pointerup", this._onDocumentPointerUp, true);
|
|
@@ -6861,18 +7405,13 @@ class AparteConversationList extends HTMLElement {
|
|
|
6861
7405
|
* the menu closes on any scroll or resize, which is what makes the arithmetic
|
|
6862
7406
|
* safe to do once.
|
|
6863
7407
|
*/
|
|
6864
|
-
_placeMenu(
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
}
|
|
6871
|
-
const rtl = getComputedStyle(this).direction === "rtl";
|
|
6872
|
-
let left = rtl ? r.left : r.right - m2.width;
|
|
6873
|
-
left = Math.max(VIEWPORT_MARGIN, Math.min(left, window.innerWidth - m2.width - VIEWPORT_MARGIN));
|
|
6874
|
-
menu.style.top = `${top}px`;
|
|
6875
|
-
menu.style.left = `${left}px`;
|
|
7408
|
+
_placeMenu(button2, menu) {
|
|
7409
|
+
placeFloating(button2.getBoundingClientRect(), menu, {
|
|
7410
|
+
gap: MENU_GAP,
|
|
7411
|
+
margin: VIEWPORT_MARGIN,
|
|
7412
|
+
align: "end",
|
|
7413
|
+
rtl: getComputedStyle(this).direction === "rtl"
|
|
7414
|
+
});
|
|
6876
7415
|
}
|
|
6877
7416
|
_closeMenu(returnFocus = false) {
|
|
6878
7417
|
const open = this._open;
|
|
@@ -7388,14 +7927,14 @@ class AparteSuggestions extends HTMLElement {
|
|
|
7388
7927
|
row.setAttribute("role", "group");
|
|
7389
7928
|
row.setAttribute("aria-label", this._groupLabel());
|
|
7390
7929
|
for (const suggestion of this._suggestions) {
|
|
7391
|
-
const
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7930
|
+
const button2 = document.createElement("button");
|
|
7931
|
+
button2.type = "button";
|
|
7932
|
+
button2.className = "aparte-btn aparte-btn--surface aparte-btn--pill aparte-suggestion";
|
|
7933
|
+
button2.textContent = labelOf(suggestion);
|
|
7395
7934
|
const prompt = promptOf(suggestion);
|
|
7396
|
-
if (prompt !==
|
|
7397
|
-
|
|
7398
|
-
row.appendChild(
|
|
7935
|
+
if (prompt !== button2.textContent) button2.title = prompt;
|
|
7936
|
+
button2.addEventListener("click", () => this._activate(suggestion));
|
|
7937
|
+
row.appendChild(button2);
|
|
7399
7938
|
}
|
|
7400
7939
|
this.appendChild(row);
|
|
7401
7940
|
}
|
|
@@ -7966,10 +8505,10 @@ class AparteContext extends HTMLElement {
|
|
|
7966
8505
|
}
|
|
7967
8506
|
}
|
|
7968
8507
|
_action(name, label) {
|
|
7969
|
-
const
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
return
|
|
8508
|
+
const button2 = el("button", "aparte-btn aparte-btn--sm aparte-btn--surface aparte-context__action", label);
|
|
8509
|
+
button2.type = "button";
|
|
8510
|
+
button2.setAttribute("data-context-action", name);
|
|
8511
|
+
return button2;
|
|
7973
8512
|
}
|
|
7974
8513
|
/**
|
|
7975
8514
|
* Ask the registered compactor to compact this chat now, as a person asked. With none
|
|
@@ -8654,13 +9193,13 @@ class AparteScrollRail extends HTMLElement {
|
|
|
8654
9193
|
this._write("--aparte-scroll-rail-gap", "");
|
|
8655
9194
|
}
|
|
8656
9195
|
const height = this.clientHeight;
|
|
8657
|
-
const
|
|
8658
|
-
if (!
|
|
9196
|
+
const count2 = this._list()?.children.length ?? 0;
|
|
9197
|
+
if (!count2 || !height || count2 * hit <= height) {
|
|
8659
9198
|
this._write("--aparte-scroll-rail-hit-size", "");
|
|
8660
9199
|
this._write("--aparte-scroll-rail-gap", "");
|
|
8661
9200
|
return;
|
|
8662
9201
|
}
|
|
8663
|
-
const pitch = Math.max(MIN_PITCH, Math.floor(height /
|
|
9202
|
+
const pitch = Math.max(MIN_PITCH, Math.floor(height / count2));
|
|
8664
9203
|
this._write("--aparte-scroll-rail-hit-size", `${pitch}px`);
|
|
8665
9204
|
this._write("--aparte-scroll-rail-gap", `${Math.max(0, pitch - thickness)}px`);
|
|
8666
9205
|
}
|
|
@@ -10064,18 +10603,18 @@ class AparteLauncher extends HTMLElement {
|
|
|
10064
10603
|
* writing an id on the host's card is the launcher itself, the button's own ancestor.
|
|
10065
10604
|
*/
|
|
10066
10605
|
_renderButton() {
|
|
10067
|
-
const
|
|
10068
|
-
if (!
|
|
10606
|
+
const button2 = this._button;
|
|
10607
|
+
if (!button2) return;
|
|
10069
10608
|
this._keepButton();
|
|
10070
10609
|
const config = this._config();
|
|
10071
10610
|
const locale = config.getLocale();
|
|
10072
10611
|
const open = this.open;
|
|
10073
10612
|
const label = open ? "" : (this.getAttribute("label") ?? "").trim();
|
|
10074
10613
|
const shape = label ? "aparte-btn--pill" : "aparte-btn--circle";
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
if (label)
|
|
10078
|
-
else
|
|
10614
|
+
button2.className = ["aparte-btn", "aparte-btn--primary", "aparte-btn--solid", "aparte-btn--lg", shape, "aparte-launcher__button"].join(" ");
|
|
10615
|
+
button2.setAttribute("aria-expanded", String(open));
|
|
10616
|
+
if (label) button2.removeAttribute("aria-label");
|
|
10617
|
+
else button2.setAttribute("aria-label", open ? locale.launcherClose ?? "Close the chat" : locale.launcherOpen ?? "Open the chat");
|
|
10079
10618
|
const icon = document.createElement("span");
|
|
10080
10619
|
icon.className = "aparte-launcher__icon";
|
|
10081
10620
|
icon.setAttribute("aria-hidden", "true");
|
|
@@ -10087,7 +10626,7 @@ class AparteLauncher extends HTMLElement {
|
|
|
10087
10626
|
text.textContent = label;
|
|
10088
10627
|
parts.push(text);
|
|
10089
10628
|
}
|
|
10090
|
-
|
|
10629
|
+
button2.replaceChildren(...parts);
|
|
10091
10630
|
}
|
|
10092
10631
|
// ─── Sheet ────────────────────────────────────────────────────────────
|
|
10093
10632
|
_onMediaChange = (e) => this._applySheet(e.matches);
|
|
@@ -10204,11 +10743,11 @@ function onClick(event) {
|
|
|
10204
10743
|
}
|
|
10205
10744
|
function onKeyDown(event) {
|
|
10206
10745
|
if (event.key !== "Enter" && event.key !== " ") return;
|
|
10207
|
-
const
|
|
10208
|
-
if (!
|
|
10746
|
+
const button2 = event.target;
|
|
10747
|
+
if (!button2?.matches?.(`span${HELD}`)) return;
|
|
10209
10748
|
event.preventDefault();
|
|
10210
10749
|
event.stopPropagation();
|
|
10211
|
-
showHeldImage(
|
|
10750
|
+
showHeldImage(button2);
|
|
10212
10751
|
}
|
|
10213
10752
|
function installImageHoldsOnce() {
|
|
10214
10753
|
const doc = document;
|
|
@@ -10345,25 +10884,26 @@ export {
|
|
|
10345
10884
|
a2 as overrideSegmentRenderer,
|
|
10346
10885
|
a3 as parseAparteEventStream,
|
|
10347
10886
|
parseMarkdownToSegments,
|
|
10887
|
+
placeFloating,
|
|
10348
10888
|
populateBubbleFromMessage,
|
|
10349
|
-
|
|
10889
|
+
a7 as readableToAsyncIterable,
|
|
10350
10890
|
registerAllComponents,
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10891
|
+
a8 as registerDefaultRenderers,
|
|
10892
|
+
a9 as registerSegmentRenderer,
|
|
10893
|
+
aa as releaseDeferredHydration,
|
|
10894
|
+
ab as renderCitations,
|
|
10895
|
+
ac as renderCodeLanguages,
|
|
10896
|
+
ad as requestUserInput,
|
|
10357
10897
|
resolveConfig,
|
|
10358
10898
|
revokeAttachmentUrls,
|
|
10359
10899
|
runWithConfig,
|
|
10360
|
-
|
|
10361
|
-
|
|
10362
|
-
|
|
10900
|
+
ah as segmentDuration,
|
|
10901
|
+
segmentTiming,
|
|
10902
|
+
aj as setupSuggestionBlocks,
|
|
10363
10903
|
subscribeConfigChange,
|
|
10364
|
-
|
|
10365
|
-
|
|
10366
|
-
|
|
10904
|
+
al as toToolCallView,
|
|
10905
|
+
am as toolRefusal,
|
|
10906
|
+
an as unregisterSegmentRenderer,
|
|
10367
10907
|
uuid
|
|
10368
10908
|
};
|
|
10369
10909
|
//# sourceMappingURL=index.js.map
|