@pyxis-llm/react 0.0.0-stage → 0.5.3
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/AgentProfileEditor.d.ts +48 -0
- package/dist/AgentProfileEditor.d.ts.map +1 -0
- package/dist/AgentProfileEditor.js +122 -0
- package/dist/AgentProfileList.d.ts +17 -0
- package/dist/AgentProfileList.d.ts.map +1 -0
- package/dist/AgentProfileList.js +46 -0
- package/dist/AskCardAnswerChip.d.ts +8 -0
- package/dist/AskCardAnswerChip.d.ts.map +1 -0
- package/dist/AskCardAnswerChip.js +21 -0
- package/dist/AskCardView.d.ts +85 -0
- package/dist/AskCardView.d.ts.map +1 -0
- package/dist/AskCardView.js +158 -0
- package/dist/CatalogColumnBrowser.d.ts +33 -0
- package/dist/CatalogColumnBrowser.d.ts.map +1 -0
- package/dist/CatalogColumnBrowser.js +219 -0
- package/dist/CatalogModelPicker.d.ts +68 -0
- package/dist/CatalogModelPicker.d.ts.map +1 -0
- package/dist/CatalogModelPicker.js +119 -0
- package/dist/CatalogModelPickerMenuContent.d.ts +17 -0
- package/dist/CatalogModelPickerMenuContent.d.ts.map +1 -0
- package/dist/CatalogModelPickerMenuContent.js +103 -0
- package/dist/CatalogPickerMenuItem.d.ts +17 -0
- package/dist/CatalogPickerMenuItem.d.ts.map +1 -0
- package/dist/CatalogPickerMenuItem.js +15 -0
- package/dist/CatalogTreePickerOptions.d.ts +52 -0
- package/dist/CatalogTreePickerOptions.d.ts.map +1 -0
- package/dist/CatalogTreePickerOptions.js +248 -0
- package/dist/ChatMessage.d.ts +172 -0
- package/dist/ChatMessage.d.ts.map +1 -0
- package/dist/ChatMessage.js +295 -0
- package/dist/ChatPanel.d.ts +252 -0
- package/dist/ChatPanel.d.ts.map +1 -0
- package/dist/ChatPanel.js +247 -0
- package/dist/ChatTranscriptFind.d.ts +19 -0
- package/dist/ChatTranscriptFind.d.ts.map +1 -0
- package/dist/ChatTranscriptFind.js +224 -0
- package/dist/ChatTranscriptFindBar.d.ts +15 -0
- package/dist/ChatTranscriptFindBar.d.ts.map +1 -0
- package/dist/ChatTranscriptFindBar.js +22 -0
- package/dist/Composer.d.ts +43 -0
- package/dist/Composer.d.ts.map +1 -0
- package/dist/Composer.js +45 -0
- package/dist/ComposerAttachments.d.ts +101 -0
- package/dist/ComposerAttachments.d.ts.map +1 -0
- package/dist/ComposerAttachments.js +126 -0
- package/dist/DisplayCards.d.ts +18 -0
- package/dist/DisplayCards.d.ts.map +1 -0
- package/dist/DisplayCards.js +72 -0
- package/dist/ErrorBoundary.d.ts +27 -0
- package/dist/ErrorBoundary.d.ts.map +1 -0
- package/dist/ErrorBoundary.js +107 -0
- package/dist/ImageDisplayCard.d.ts +6 -0
- package/dist/ImageDisplayCard.d.ts.map +1 -0
- package/dist/ImageDisplayCard.js +57 -0
- package/dist/MarkdownCodeComponents.d.ts +23 -0
- package/dist/MarkdownCodeComponents.d.ts.map +1 -0
- package/dist/MarkdownCodeComponents.js +256 -0
- package/dist/MermaidDiagram.d.ts +18 -0
- package/dist/MermaidDiagram.d.ts.map +1 -0
- package/dist/MermaidDiagram.js +66 -0
- package/dist/MessageContentWithPastes.d.ts +14 -0
- package/dist/MessageContentWithPastes.d.ts.map +1 -0
- package/dist/MessageContentWithPastes.js +44 -0
- package/dist/PastePill.d.ts +16 -0
- package/dist/PastePill.d.ts.map +1 -0
- package/dist/PastePill.js +43 -0
- package/dist/ProviderAuthTerminal.d.ts +12 -0
- package/dist/ProviderAuthTerminal.d.ts.map +1 -0
- package/dist/ProviderAuthTerminal.js +50 -0
- package/dist/ProviderConnectForm.d.ts +62 -0
- package/dist/ProviderConnectForm.d.ts.map +1 -0
- package/dist/ProviderConnectForm.js +206 -0
- package/dist/ProviderList.d.ts +18 -0
- package/dist/ProviderList.d.ts.map +1 -0
- package/dist/ProviderList.js +67 -0
- package/dist/QueueStrip.d.ts +17 -0
- package/dist/QueueStrip.d.ts.map +1 -0
- package/dist/QueueStrip.js +60 -0
- package/dist/SettingsScreen.d.ts +10 -0
- package/dist/SettingsScreen.d.ts.map +1 -0
- package/dist/SettingsScreen.js +26 -0
- package/dist/StreamingMarkdown.d.ts +47 -0
- package/dist/StreamingMarkdown.d.ts.map +1 -0
- package/dist/StreamingMarkdown.js +103 -0
- package/dist/TurnTimer.d.ts +72 -0
- package/dist/TurnTimer.d.ts.map +1 -0
- package/dist/TurnTimer.js +114 -0
- package/dist/VegaChart.d.ts +36 -0
- package/dist/VegaChart.d.ts.map +1 -0
- package/dist/VegaChart.js +180 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +18 -0
- package/dist/catalogColumnBrowserTree.d.ts +9 -0
- package/dist/catalogColumnBrowserTree.d.ts.map +1 -0
- package/dist/catalogColumnBrowserTree.js +48 -0
- package/dist/catalogPickerMenuStyles.d.ts +81 -0
- package/dist/catalogPickerMenuStyles.d.ts.map +1 -0
- package/dist/catalogPickerMenuStyles.js +130 -0
- package/dist/charts.d.ts +12 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.js +45 -0
- package/dist/chatMessageScroll.d.ts +40 -0
- package/dist/chatMessageScroll.d.ts.map +1 -0
- package/dist/chatMessageScroll.js +62 -0
- package/dist/chatModelOptions.d.ts +28 -0
- package/dist/chatModelOptions.d.ts.map +1 -0
- package/dist/chatModelOptions.js +59 -0
- package/dist/chatTranscriptFindHighlights.d.ts +9 -0
- package/dist/chatTranscriptFindHighlights.d.ts.map +1 -0
- package/dist/chatTranscriptFindHighlights.js +88 -0
- package/dist/draftStore.d.ts +13 -0
- package/dist/draftStore.d.ts.map +1 -0
- package/dist/draftStore.js +38 -0
- package/dist/highlight.d.ts +4 -0
- package/dist/highlight.d.ts.map +1 -0
- package/dist/highlight.js +47 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/keyboardShortcuts.d.ts +5 -0
- package/dist/keyboardShortcuts.d.ts.map +1 -0
- package/dist/keyboardShortcuts.js +19 -0
- package/dist/markdownClipboard.d.ts +22 -0
- package/dist/markdownClipboard.d.ts.map +1 -0
- package/dist/markdownClipboard.js +98 -0
- package/dist/markdownPlugins.d.ts +31 -0
- package/dist/markdownPlugins.d.ts.map +1 -0
- package/dist/markdownPlugins.js +32 -0
- package/dist/mermaid.d.ts +17 -0
- package/dist/mermaid.d.ts.map +1 -0
- package/dist/mermaid.js +11 -0
- package/dist/mermaidRuntime.d.ts +21 -0
- package/dist/mermaidRuntime.d.ts.map +1 -0
- package/dist/mermaidRuntime.js +140 -0
- package/dist/modelCatalogHelpers.d.ts +14 -0
- package/dist/modelCatalogHelpers.d.ts.map +1 -0
- package/dist/modelCatalogHelpers.js +65 -0
- package/dist/modelCatalogSource.d.ts +22 -0
- package/dist/modelCatalogSource.d.ts.map +1 -0
- package/dist/modelCatalogSource.js +26 -0
- package/dist/modelCatalogTree.d.ts +24 -0
- package/dist/modelCatalogTree.d.ts.map +1 -0
- package/dist/modelCatalogTree.js +77 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +13 -0
- package/dist/pasteFences.d.ts +20 -0
- package/dist/pasteFences.d.ts.map +1 -0
- package/dist/pasteFences.js +157 -0
- package/dist/pasteFormat.d.ts +5 -0
- package/dist/pasteFormat.d.ts.map +1 -0
- package/dist/pasteFormat.js +18 -0
- package/dist/plugins.d.ts +110 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +98 -0
- package/dist/remarkAlerts.d.ts +12 -0
- package/dist/remarkAlerts.d.ts.map +1 -0
- package/dist/remarkAlerts.js +52 -0
- package/dist/sendMode.d.ts +69 -0
- package/dist/sendMode.d.ts.map +1 -0
- package/dist/sendMode.js +66 -0
- package/dist/useLlmdChatDriver.d.ts +367 -0
- package/dist/useLlmdChatDriver.d.ts.map +1 -0
- package/dist/useLlmdChatDriver.js +1739 -0
- package/dist/useLlmdModelCatalog.d.ts +23 -0
- package/dist/useLlmdModelCatalog.d.ts.map +1 -0
- package/dist/useLlmdModelCatalog.js +89 -0
- package/dist/useLlmdSessionModel.d.ts +34 -0
- package/dist/useLlmdSessionModel.d.ts.map +1 -0
- package/dist/useLlmdSessionModel.js +79 -0
- package/dist/useProviderAuthCommand.d.ts +26 -0
- package/dist/useProviderAuthCommand.d.ts.map +1 -0
- package/dist/useProviderAuthCommand.js +80 -0
- package/dist/vegaRuntime.d.ts +83 -0
- package/dist/vegaRuntime.d.ts.map +1 -0
- package/dist/vegaRuntime.js +314 -0
- package/dist/vendor/llmd-types/conversationEvents.d.ts +238 -0
- package/dist/vendor/llmd-types/conversationEvents.d.ts.map +1 -0
- package/dist/vendor/llmd-types/conversationEvents.js +98 -0
- package/dist/vendor/llmd-types/index.d.ts +4 -0
- package/dist/vendor/llmd-types/index.d.ts.map +1 -0
- package/dist/vendor/llmd-types/index.js +5 -0
- package/dist/vendor/llmd-types/messages.d.ts +67 -0
- package/dist/vendor/llmd-types/messages.d.ts.map +1 -0
- package/dist/vendor/llmd-types/messages.js +71 -0
- package/dist/vendor/llmd-types/sessionQueue.d.ts +54 -0
- package/dist/vendor/llmd-types/sessionQueue.d.ts.map +1 -0
- package/dist/vendor/llmd-types/sessionQueue.js +40 -0
- package/package.json +120 -4
- package/styles.css +389 -0
- package/README.md +0 -3
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 John Ewart <john@johnewart.net>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A complete, minimal chat surface: scrollable message list (via
|
|
8
|
+
* ChatMessage) + Composer, wired together by props/callbacks only.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately transport-agnostic: it does NOT import `@pyxis-llm/client` or
|
|
11
|
+
* drive `ChatStream` itself. `@pyxis-llm/client`'s gRPC transport
|
|
12
|
+
* (`@grpc/grpc-js`) is Node-only — most hosts (Electron renderers, browser
|
|
13
|
+
* apps) can't call it directly from the same process this component
|
|
14
|
+
* renders in, and even hosts that could will have very different session/
|
|
15
|
+
* attachment/model-catalog state management. So `ChatPanel` takes the
|
|
16
|
+
* current `messages` array and an `onSend` callback and lets the host own
|
|
17
|
+
* everything upstream of that (a hook wrapping `chatStreamEvents` over
|
|
18
|
+
* IPC, a REST proxy, a mock for tests — whatever fits).
|
|
19
|
+
*
|
|
20
|
+
* Extension points (the "slots and callbacks" needed to slim this down to a
|
|
21
|
+
* shared core while hosts add their own chrome):
|
|
22
|
+
* - `header` / `composerBefore` / `composerAfter`: arbitrary chrome
|
|
23
|
+
* (status bar, model switcher, attachments strip).
|
|
24
|
+
* - `renderCustomMessage` / `renderDecorations` / `transformVisibleContent`:
|
|
25
|
+
* forwarded to every ChatMessage — see its own docs for what each does.
|
|
26
|
+
* - Cards, code renderers and attachment placement come from llmd plugins
|
|
27
|
+
* (plugins.tsx: registerLlmdPlugin / LlmdPluginProvider), not props.
|
|
28
|
+
* - `usageByMessageId` / `decorationsByMessageId` / `trackedDocumentsByMessage`:
|
|
29
|
+
* per-message data a host looks up by id; ChatPanel does no bookkeeping
|
|
30
|
+
* of its own beyond the lookup.
|
|
31
|
+
*
|
|
32
|
+
* A host that supplies none of the optional props gets a fully working
|
|
33
|
+
* "vanilla" chat panel — text in, text out, attachments degrade to a
|
|
34
|
+
* placeholder — which is the Owlbert-style baseline. A host app
|
|
35
|
+
* adds graph badges, a model switcher, and its own attachment kinds purely
|
|
36
|
+
* by passing props; it never needs to fork this component.
|
|
37
|
+
*
|
|
38
|
+
* Addressing a single message: every `ChatMessage` root carries
|
|
39
|
+
* `data-message-id` (its `Message.id`) and `data-message-role`, so a host can
|
|
40
|
+
* map a DOM node or text selection back to a message and anchor its own
|
|
41
|
+
* overlays — selection menus, comment pins, highlight ranges — with no extra
|
|
42
|
+
* props. `scrollRequest` and the `ChatPanelHandle` ref bring a given message
|
|
43
|
+
* into view; see `ChatPanelScrollRequest` for why it carries a nonce and
|
|
44
|
+
* `autoScroll` for how the two interact.
|
|
45
|
+
*
|
|
46
|
+
* Note that message ids are the only *durable* address llmd has: turn ids and
|
|
47
|
+
* turn sequence numbers exist on the live conversation event stream but are
|
|
48
|
+
* not persisted, so anything a host wants to survive a reload should be keyed
|
|
49
|
+
* off `Message.id`.
|
|
50
|
+
*
|
|
51
|
+
* Ask cards (llmd's first-class AskCard/AskCardResponse primitive, including
|
|
52
|
+
* ones created server-side by the `ask_user` tool) need NO dedicated prop
|
|
53
|
+
* here: they're plain attachments (kind `ask_card`), rendered inline by
|
|
54
|
+
* `ChatMessage` via the existing `attachmentIndex`/`askCardResponses`/
|
|
55
|
+
* `onAskCardSubmit` props — see packages/react/e2e/askCard.e2e.test.tsx for
|
|
56
|
+
* the full round trip (load attachments, render, answer via
|
|
57
|
+
* UpsertSessionAttachment).
|
|
58
|
+
*/
|
|
59
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
60
|
+
import { ActionIcon, Group, ScrollArea, Text } from '@mantine/core';
|
|
61
|
+
import { IconArrowDown } from '@tabler/icons-react';
|
|
62
|
+
import { TurnTimerView, useTurnTimer } from './TurnTimer.js';
|
|
63
|
+
import { appendAnchorlessCardMessages, indexAskCardResponses, withLlmdAttachmentKindPlugins, } from '@pyxis-llm/core';
|
|
64
|
+
import { ChatMessage } from './ChatMessage.js';
|
|
65
|
+
import { Composer } from './Composer.js';
|
|
66
|
+
import { useLlmdPlugins } from './plugins.js';
|
|
67
|
+
import { useSendMode } from './sendMode.js';
|
|
68
|
+
import { QueueStrip } from './QueueStrip.js';
|
|
69
|
+
import { useDraft } from './draftStore.js';
|
|
70
|
+
import { centerMessageInViewport, findMessageElement, isPinnedToBottom, } from './chatMessageScroll.js';
|
|
71
|
+
/** How far above the bottom the reader must be before the jump-to-newest arrow appears. */
|
|
72
|
+
const SCROLL_BUTTON_THRESHOLD_PX = 120;
|
|
73
|
+
function distanceFromBottom(viewport) {
|
|
74
|
+
return viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;
|
|
75
|
+
}
|
|
76
|
+
export const ChatPanel = forwardRef(function ChatPanel({ messages: messagesProp, onSend, defaultSendBehavior, queue, queuePaused = false, onRemoveQueued, onReorderQueue, onSetQueuePaused, onInterruptWithQueued, streaming = false, onStop, onDeleteMessage, streamingMessageId, attachmentIndex, usageByMessageId, decorationsByMessageId, trackedDocumentsByMessageId, initialSeed, sessionTitle, sessionStatus, turnStartedAt, turnTiming, showTurnTimer = true, renderTurnTimer, renderCustomMessage, renderUserAttachment, renderDecorations, askCardResponses: askCardResponsesProp, onAskCardSubmit, onAskCardDismiss, transformVisibleContent, header, footer, composerBefore, composerAfter, composerPlaceholder, composerDisabled, composerValue, composerDraft, onComposerValueChange, autoScroll = true, scrollRequest, fullRenderTail = 10, hideTranscript = false, showScrollToBottom = true, className, }, ref) {
|
|
77
|
+
// Placement rules: llmd's own kinds plus every plugin's (plugins.tsx).
|
|
78
|
+
const { attachmentKindPlugins } = useLlmdPlugins();
|
|
79
|
+
const effectivePlugins = useMemo(() => withLlmdAttachmentKindPlugins(attachmentKindPlugins), [attachmentKindPlugins]);
|
|
80
|
+
// Idempotent (rows are keyed by card id), so a host that still appends
|
|
81
|
+
// anchorless rows itself gets no duplicates.
|
|
82
|
+
const messages = useMemo(() => appendAnchorlessCardMessages(messagesProp, attachmentIndex, effectivePlugins), [messagesProp, attachmentIndex, effectivePlugins]);
|
|
83
|
+
const derivedAskCardResponses = useMemo(() => (attachmentIndex ? indexAskCardResponses(attachmentIndex.values()) : undefined), [attachmentIndex]);
|
|
84
|
+
const askCardResponses = askCardResponsesProp ?? derivedAskCardResponses;
|
|
85
|
+
const viewportRef = useRef(null);
|
|
86
|
+
// Whether the viewport is parked at the bottom. Starts true so a freshly
|
|
87
|
+
// mounted panel lands on the newest message, then simply tracks where the
|
|
88
|
+
// viewport actually is.
|
|
89
|
+
//
|
|
90
|
+
// This single flag is what defines precedence between an explicit scroll
|
|
91
|
+
// request and autoScroll, without a separate "suspended" mode to get out of
|
|
92
|
+
// sync: a scroll-to-message leaves the viewport somewhere that is not the
|
|
93
|
+
// bottom, so autoScroll stops chasing for exactly as long as the user is
|
|
94
|
+
// reading up there — indistinguishable from having scrolled by hand. Coming
|
|
95
|
+
// back to the bottom (by scrolling, or via the handle) re-arms it.
|
|
96
|
+
const pinnedToBottomRef = useRef(true);
|
|
97
|
+
// Drives the jump-to-newest arrow. State (not the ref) so it re-renders; only set when
|
|
98
|
+
// it flips, so scrolling doesn't re-render the panel on every frame.
|
|
99
|
+
const [scrolledUp, setScrolledUp] = useState(false);
|
|
100
|
+
const syncScrolledUp = useCallback((viewport) => {
|
|
101
|
+
setScrolledUp(distanceFromBottom(viewport) > SCROLL_BUTTON_THRESHOLD_PX);
|
|
102
|
+
}, []);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const viewport = viewportRef.current;
|
|
105
|
+
if (!viewport)
|
|
106
|
+
return;
|
|
107
|
+
const onScroll = () => {
|
|
108
|
+
pinnedToBottomRef.current = isPinnedToBottom(viewport);
|
|
109
|
+
syncScrolledUp(viewport);
|
|
110
|
+
};
|
|
111
|
+
viewport.addEventListener('scroll', onScroll, { passive: true });
|
|
112
|
+
return () => viewport.removeEventListener('scroll', onScroll);
|
|
113
|
+
// hideTranscript: the viewport only exists while the transcript is shown.
|
|
114
|
+
}, [hideTranscript]);
|
|
115
|
+
const scrollToBottom = useCallback(() => {
|
|
116
|
+
const viewport = viewportRef.current;
|
|
117
|
+
if (!viewport)
|
|
118
|
+
return;
|
|
119
|
+
// Plain scrollTop assignment rather than viewport.scrollTo({...}): no
|
|
120
|
+
// smooth-scroll behavior is needed for "jump to newest message", and
|
|
121
|
+
// scrollTo is unimplemented in some test/embedded DOM environments
|
|
122
|
+
// (e.g. jsdom) even though scrollTop always works.
|
|
123
|
+
viewport.scrollTop = viewport.scrollHeight;
|
|
124
|
+
pinnedToBottomRef.current = true;
|
|
125
|
+
setScrolledUp(false);
|
|
126
|
+
}, []);
|
|
127
|
+
// Keep the newest message visible when the viewport or its content changes
|
|
128
|
+
// size without `messages` changing — e.g. footer chrome (a tool-activity
|
|
129
|
+
// strip, an error banner) appearing below the ScrollArea shrinks the
|
|
130
|
+
// viewport, which would otherwise hide the tail until the next message
|
|
131
|
+
// update. A resize fires no scroll event, so the pinned flag still reflects
|
|
132
|
+
// where the user was. Skipped where ResizeObserver is absent (jsdom).
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
const viewport = viewportRef.current;
|
|
135
|
+
if (!viewport || typeof ResizeObserver === 'undefined')
|
|
136
|
+
return;
|
|
137
|
+
const ro = new ResizeObserver(() => {
|
|
138
|
+
if (autoScroll && pinnedToBottomRef.current)
|
|
139
|
+
scrollToBottom();
|
|
140
|
+
// New content while reading higher up moves the bottom away without a scroll event.
|
|
141
|
+
else
|
|
142
|
+
syncScrolledUp(viewport);
|
|
143
|
+
});
|
|
144
|
+
ro.observe(viewport);
|
|
145
|
+
const content = viewport.firstElementChild;
|
|
146
|
+
if (content)
|
|
147
|
+
ro.observe(content);
|
|
148
|
+
// Shown again: land on the newest message, as on first mount.
|
|
149
|
+
if (autoScroll && pinnedToBottomRef.current)
|
|
150
|
+
scrollToBottom();
|
|
151
|
+
return () => ro.disconnect();
|
|
152
|
+
}, [autoScroll, scrollToBottom, syncScrolledUp, hideTranscript]);
|
|
153
|
+
const scrollToMessage = useCallback((messageId) => {
|
|
154
|
+
const viewport = viewportRef.current;
|
|
155
|
+
if (!viewport)
|
|
156
|
+
return false;
|
|
157
|
+
const el = findMessageElement(viewport, messageId);
|
|
158
|
+
if (!el)
|
|
159
|
+
return false;
|
|
160
|
+
centerMessageInViewport(viewport, el);
|
|
161
|
+
// Recomputed here rather than left to the scroll event: assigning the same
|
|
162
|
+
// scrollTop fires no event, and jsdom dispatches none at all, so the flag
|
|
163
|
+
// would keep a stale value in exactly the case that matters.
|
|
164
|
+
pinnedToBottomRef.current = isPinnedToBottom(viewport);
|
|
165
|
+
syncScrolledUp(viewport);
|
|
166
|
+
return true;
|
|
167
|
+
}, [syncScrolledUp]);
|
|
168
|
+
useImperativeHandle(ref, () => ({
|
|
169
|
+
scrollToMessage,
|
|
170
|
+
scrollToBottom,
|
|
171
|
+
getViewport: () => viewportRef.current,
|
|
172
|
+
}), [scrollToMessage, scrollToBottom]);
|
|
173
|
+
// The last scroll request we actually landed. Tracking it lets the effect
|
|
174
|
+
// below re-run harmlessly on every `messages` change (needed to retry a
|
|
175
|
+
// request whose target has not been fetched yet) without re-scrolling on
|
|
176
|
+
// every appended message once the request has been satisfied.
|
|
177
|
+
const landedScrollTokenRef = useRef(undefined);
|
|
178
|
+
// Set when a scroll request lands, cleared by the autoScroll effect below.
|
|
179
|
+
//
|
|
180
|
+
// Needed because both effects can fire in the same commit — a request that
|
|
181
|
+
// arrives together with new messages — and "am I at the bottom?" is not a
|
|
182
|
+
// sufficient tiebreaker on its own: centering one of the last messages leaves
|
|
183
|
+
// the viewport legitimately within the bottom threshold, so autoScroll would
|
|
184
|
+
// see "pinned" and yank the view to the newest message in the very commit
|
|
185
|
+
// that was supposed to honor the request. An explicit request wins its own
|
|
186
|
+
// commit outright; from the next one on, position decides as usual.
|
|
187
|
+
const scrollRequestLandedRef = useRef(false);
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (!scrollRequest?.messageId)
|
|
190
|
+
return;
|
|
191
|
+
if (landedScrollTokenRef.current === scrollRequest.token)
|
|
192
|
+
return;
|
|
193
|
+
if (scrollToMessage(scrollRequest.messageId)) {
|
|
194
|
+
landedScrollTokenRef.current = scrollRequest.token;
|
|
195
|
+
scrollRequestLandedRef.current = true;
|
|
196
|
+
}
|
|
197
|
+
}, [scrollRequest, messages, scrollToMessage]);
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
// Consumed unconditionally so it cannot leak into a later commit.
|
|
200
|
+
const yieldToScrollRequest = scrollRequestLandedRef.current;
|
|
201
|
+
scrollRequestLandedRef.current = false;
|
|
202
|
+
if (yieldToScrollRequest)
|
|
203
|
+
return;
|
|
204
|
+
if (!autoScroll)
|
|
205
|
+
return;
|
|
206
|
+
if (!pinnedToBottomRef.current)
|
|
207
|
+
return;
|
|
208
|
+
scrollToBottom();
|
|
209
|
+
}, [autoScroll, messages, scrollToBottom]);
|
|
210
|
+
const turnTimer = useTurnTimer(streaming, turnTiming ?? turnStartedAt);
|
|
211
|
+
const sendMode = useSendMode({
|
|
212
|
+
streaming,
|
|
213
|
+
queuePaused,
|
|
214
|
+
queueLength: queue?.length ?? 0,
|
|
215
|
+
defaultSendBehavior,
|
|
216
|
+
});
|
|
217
|
+
let firstUserMessageId;
|
|
218
|
+
for (const m of messages) {
|
|
219
|
+
if (m.role === 'user') {
|
|
220
|
+
firstUserMessageId = m.id;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return (_jsxs("div", { className: ['llmd-chat-panel', className].filter(Boolean).join(' '), style: { display: 'flex', flexDirection: 'column', height: hideTranscript ? 'auto' : '100%', minHeight: 0 }, children: [!hideTranscript && sessionTitle && (_jsx(Group, { className: "llmd-chat-panel__session-bar", justify: "space-between", wrap: "nowrap", gap: "sm", px: "sm", py: "xs", children: _jsx(Text, { className: "llmd-chat-panel__session-title", fw: 600, truncate: "end", children: sessionTitle }) })), !hideTranscript && header, !hideTranscript && (_jsxs("div", { className: "llmd-chat-panel__messages-frame", style: { position: 'relative', flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }, children: [showScrollToBottom && scrolledUp && (_jsx(ActionIcon, { className: "llmd-chat-panel__scroll-bottom", variant: "default", radius: "xl", size: "lg", "aria-label": "Scroll to newest message", onClick: scrollToBottom, style: { position: 'absolute', right: 16, bottom: 12, zIndex: 2, boxShadow: 'var(--mantine-shadow-md)' }, children: _jsx(IconArrowDown, { size: 18 }) })), _jsx(ScrollArea, { viewportRef: viewportRef, className: "llmd-chat-panel__messages", style: { flex: 1, minHeight: 0 }, children: messages.map((message, idx) => {
|
|
225
|
+
const id = message.id ?? String(idx);
|
|
226
|
+
return (_jsx(ChatMessage, { message: message, streamPlainContent: streaming && message.id === streamingMessageId, onDelete: onDeleteMessage ? () => onDeleteMessage(message) : undefined, deleteDisabled: streaming && message.id === streamingMessageId, attachmentIndex: attachmentIndex, usage: message.id ? usageByMessageId?.get(message.id) : undefined, decorations: message.id ? decorationsByMessageId?.get(message.id) : undefined, trackedDocuments: message.id ? trackedDocumentsByMessageId?.get(message.id) : undefined, initialSeed: message.id === firstUserMessageId ? initialSeed : undefined, renderCustomMessage: renderCustomMessage, renderUserAttachment: renderUserAttachment, renderDecorations: renderDecorations, askCardResponses: askCardResponses, onAskCardSubmit: onAskCardSubmit, onAskCardDismiss: onAskCardDismiss, transformVisibleContent: transformVisibleContent, containOffscreen: idx < messages.length - UNCONTAINED_TAIL_ROWS, deferMarkdown: idx < messages.length - fullRenderTail }, id));
|
|
227
|
+
}) })] })), !hideTranscript && footer, queue && (_jsx(QueueStrip, { queue: queue, paused: queuePaused, onRemove: onRemoveQueued, onReorder: onReorderQueue, onSetPaused: onSetQueuePaused, onInterruptWith: onInterruptWithQueued })), (sessionStatus || (showTurnTimer && turnTimer.elapsedMs !== undefined)) && (_jsxs(Group, { className: "llmd-chat-panel__turn-bar", justify: "space-between", wrap: "nowrap", gap: "sm", px: "sm", py: 4, children: [sessionStatus ? (_jsx(Text, { className: "llmd-chat-panel__session-status", size: "sm", c: "dimmed", truncate: "end", style: { minWidth: 0, flex: 1 }, children: sessionStatus })) : (
|
|
228
|
+
// Keeps the timer right-aligned when there is no headline.
|
|
229
|
+
_jsx("span", { style: { flex: 1 } })), showTurnTimer &&
|
|
230
|
+
turnTimer.elapsedMs !== undefined &&
|
|
231
|
+
(renderTurnTimer ? (renderTurnTimer(turnTimer)) : (_jsx(TurnTimerView, { state: turnTimer, className: "llmd-chat-panel__turn-timer" })))] })), _jsx(PanelComposer, { draft: composerValue === undefined ? composerDraft : undefined, onSend: (text, alternate) => onSend(text, sendMode.behaviorFor(alternate)), sendMode: sendMode, streaming: streaming, onStop: onStop, placeholder:
|
|
232
|
+
// While a turn runs, or the queue is in play, the empty input says
|
|
233
|
+
// what Enter and modifier+Enter will do.
|
|
234
|
+
streaming || queuePaused || (queue?.length ?? 0) > 0 ? sendMode.hint : composerPlaceholder, disabled: composerDisabled, value: composerValue, onValueChange: onComposerValueChange, beforeInput: composerBefore, afterInput: composerAfter })] }));
|
|
235
|
+
});
|
|
236
|
+
/**
|
|
237
|
+
* Newest rows never get `content-visibility: auto`, so scroll-to-bottom always
|
|
238
|
+
* measures their real height (see ChatMessageProps.containOffscreen).
|
|
239
|
+
*/
|
|
240
|
+
const UNCONTAINED_TAIL_ROWS = 4;
|
|
241
|
+
/** Composer that, given a draft store, subscribes to it itself. */
|
|
242
|
+
function PanelComposer({ draft, ...props }) {
|
|
243
|
+
return draft ? _jsx(DraftComposer, { draft: draft, ...props }) : _jsx(Composer, { ...props });
|
|
244
|
+
}
|
|
245
|
+
function DraftComposer({ draft, ...props }) {
|
|
246
|
+
return _jsx(Composer, { ...props, value: useDraft(draft) });
|
|
247
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
export type ChatTranscriptFindProps = {
|
|
3
|
+
rootRef: RefObject<HTMLElement | null>;
|
|
4
|
+
scrollViewportRef: RefObject<HTMLElement | null>;
|
|
5
|
+
/** Changing this (e.g. on new streamed content) re-runs the active search against the updated DOM. */
|
|
6
|
+
contentKey: string;
|
|
7
|
+
/** Closes and resets find state when this changes (e.g. switching sessions). */
|
|
8
|
+
sessionId: string | null;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
ariaLabel?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Cmd/Ctrl+F find-in-transcript: text search + highlight over a DOM subtree
|
|
14
|
+
* (via the CSS Custom Highlight API when available), with Cmd/Ctrl+G
|
|
15
|
+
* next/previous and Escape to close. Host mounts this once inside the chat
|
|
16
|
+
* surface and gives it refs to the searchable root and scroll viewport.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ChatTranscriptFind: import("react").NamedExoticComponent<ChatTranscriptFindProps>;
|
|
19
|
+
//# sourceMappingURL=ChatTranscriptFind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatTranscriptFind.d.ts","sourceRoot":"","sources":["../src/ChatTranscriptFind.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAkD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAcvF,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACvC,iBAAiB,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACjD,sGAAsG;IACtG,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,+DAiQ7B,CAAC"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 John Ewart <john@johnewart.net>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
7
|
+
import { ChatTranscriptFindBar } from './ChatTranscriptFindBar.js';
|
|
8
|
+
import { applyChatTranscriptFindHighlights, clearChatTranscriptFindHighlights, collectChatTranscriptMatchRanges, scrollChatTranscriptMatchIntoView, } from './chatTranscriptFindHighlights.js';
|
|
9
|
+
import { isModKey } from './keyboardShortcuts.js';
|
|
10
|
+
const FIND_DEBOUNCE_MS = 500;
|
|
11
|
+
/** Highlight API slows down with huge match lists; cap painted highlights only. */
|
|
12
|
+
const MAX_PAINTED_MATCHES = 300;
|
|
13
|
+
/**
|
|
14
|
+
* Cmd/Ctrl+F find-in-transcript: text search + highlight over a DOM subtree
|
|
15
|
+
* (via the CSS Custom Highlight API when available), with Cmd/Ctrl+G
|
|
16
|
+
* next/previous and Escape to close. Host mounts this once inside the chat
|
|
17
|
+
* surface and gives it refs to the searchable root and scroll viewport.
|
|
18
|
+
*/
|
|
19
|
+
export const ChatTranscriptFind = memo(function ChatTranscriptFind({ rootRef, scrollViewportRef, contentKey, sessionId, placeholder, ariaLabel, }) {
|
|
20
|
+
const [open, setOpen] = useState(false);
|
|
21
|
+
const [inputValue, setInputValue] = useState('');
|
|
22
|
+
const [matchLabel, setMatchLabel] = useState('');
|
|
23
|
+
const rangesRef = useRef([]);
|
|
24
|
+
const currentIndexRef = useRef(0);
|
|
25
|
+
const inputRef = useRef(null);
|
|
26
|
+
const debounceTimerRef = useRef(null);
|
|
27
|
+
const appliedQueryRef = useRef('');
|
|
28
|
+
const inputValueRef = useRef(inputValue);
|
|
29
|
+
const prevSessionIdRef = useRef(sessionId);
|
|
30
|
+
inputValueRef.current = inputValue;
|
|
31
|
+
const revealIndex = useCallback((index) => {
|
|
32
|
+
const ranges = rangesRef.current;
|
|
33
|
+
if (index < 0 || index >= ranges.length)
|
|
34
|
+
return;
|
|
35
|
+
applyChatTranscriptFindHighlights(ranges, index, MAX_PAINTED_MATCHES);
|
|
36
|
+
const viewport = scrollViewportRef.current;
|
|
37
|
+
const range = ranges[index];
|
|
38
|
+
if (viewport && range) {
|
|
39
|
+
scrollChatTranscriptMatchIntoView(range, viewport);
|
|
40
|
+
}
|
|
41
|
+
}, [scrollViewportRef]);
|
|
42
|
+
const updateMatchLabel = useCallback((index, count) => {
|
|
43
|
+
setMatchLabel(count === 0 ? 'No matches' : `${index + 1}/${count}`);
|
|
44
|
+
}, []);
|
|
45
|
+
const applySearch = useCallback((searchQuery, preserveIndex, scrollToMatch) => {
|
|
46
|
+
const root = rootRef.current;
|
|
47
|
+
const trimmed = searchQuery.trim();
|
|
48
|
+
appliedQueryRef.current = trimmed;
|
|
49
|
+
if (!root || !trimmed) {
|
|
50
|
+
rangesRef.current = [];
|
|
51
|
+
currentIndexRef.current = 0;
|
|
52
|
+
clearChatTranscriptFindHighlights();
|
|
53
|
+
setMatchLabel('');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const ranges = collectChatTranscriptMatchRanges(root, trimmed);
|
|
57
|
+
rangesRef.current = ranges;
|
|
58
|
+
const count = ranges.length;
|
|
59
|
+
if (count === 0) {
|
|
60
|
+
currentIndexRef.current = 0;
|
|
61
|
+
clearChatTranscriptFindHighlights();
|
|
62
|
+
setMatchLabel('No matches');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const index = preserveIndex
|
|
66
|
+
? Math.min(currentIndexRef.current, count - 1)
|
|
67
|
+
: 0;
|
|
68
|
+
currentIndexRef.current = index;
|
|
69
|
+
updateMatchLabel(index, count);
|
|
70
|
+
if (scrollToMatch) {
|
|
71
|
+
revealIndex(index);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
applyChatTranscriptFindHighlights(ranges, index, MAX_PAINTED_MATCHES);
|
|
75
|
+
}
|
|
76
|
+
}, [rootRef, revealIndex, updateMatchLabel]);
|
|
77
|
+
const cancelPendingSearch = useCallback(() => {
|
|
78
|
+
if (debounceTimerRef.current != null) {
|
|
79
|
+
clearTimeout(debounceTimerRef.current);
|
|
80
|
+
debounceTimerRef.current = null;
|
|
81
|
+
}
|
|
82
|
+
}, []);
|
|
83
|
+
const flushSearch = useCallback((preserveIndex, scrollToMatch) => {
|
|
84
|
+
cancelPendingSearch();
|
|
85
|
+
applySearch(inputValueRef.current, preserveIndex, scrollToMatch);
|
|
86
|
+
}, [applySearch, cancelPendingSearch]);
|
|
87
|
+
const scheduleSearch = useCallback((searchQuery, preserveIndex, scrollToMatch) => {
|
|
88
|
+
cancelPendingSearch();
|
|
89
|
+
const trimmed = searchQuery.trim();
|
|
90
|
+
if (!trimmed) {
|
|
91
|
+
applySearch('', preserveIndex, scrollToMatch);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
debounceTimerRef.current = setTimeout(() => {
|
|
95
|
+
debounceTimerRef.current = null;
|
|
96
|
+
applySearch(searchQuery, preserveIndex, scrollToMatch);
|
|
97
|
+
}, FIND_DEBOUNCE_MS);
|
|
98
|
+
}, [applySearch, cancelPendingSearch]);
|
|
99
|
+
const closeFind = useCallback(() => {
|
|
100
|
+
cancelPendingSearch();
|
|
101
|
+
setOpen(false);
|
|
102
|
+
setInputValue('');
|
|
103
|
+
setMatchLabel('');
|
|
104
|
+
appliedQueryRef.current = '';
|
|
105
|
+
currentIndexRef.current = 0;
|
|
106
|
+
rangesRef.current = [];
|
|
107
|
+
clearChatTranscriptFindHighlights();
|
|
108
|
+
}, [cancelPendingSearch]);
|
|
109
|
+
const openFind = useCallback((seedQuery) => {
|
|
110
|
+
setOpen(true);
|
|
111
|
+
if (seedQuery != null) {
|
|
112
|
+
setInputValue(seedQuery);
|
|
113
|
+
appliedQueryRef.current = '';
|
|
114
|
+
currentIndexRef.current = 0;
|
|
115
|
+
cancelPendingSearch();
|
|
116
|
+
applySearch(seedQuery, false, true);
|
|
117
|
+
}
|
|
118
|
+
requestAnimationFrame(() => {
|
|
119
|
+
inputRef.current?.focus();
|
|
120
|
+
inputRef.current?.select();
|
|
121
|
+
});
|
|
122
|
+
}, [applySearch, cancelPendingSearch]);
|
|
123
|
+
const findNext = useCallback(() => {
|
|
124
|
+
if (debounceTimerRef.current != null) {
|
|
125
|
+
flushSearch(false, true);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const count = rangesRef.current.length;
|
|
129
|
+
if (count === 0)
|
|
130
|
+
return;
|
|
131
|
+
const next = (currentIndexRef.current + 1) % count;
|
|
132
|
+
currentIndexRef.current = next;
|
|
133
|
+
updateMatchLabel(next, count);
|
|
134
|
+
revealIndex(next);
|
|
135
|
+
}, [flushSearch, revealIndex, updateMatchLabel]);
|
|
136
|
+
const findPrevious = useCallback(() => {
|
|
137
|
+
if (debounceTimerRef.current != null) {
|
|
138
|
+
flushSearch(false, true);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const count = rangesRef.current.length;
|
|
142
|
+
if (count === 0)
|
|
143
|
+
return;
|
|
144
|
+
const next = (currentIndexRef.current - 1 + count) % count;
|
|
145
|
+
currentIndexRef.current = next;
|
|
146
|
+
updateMatchLabel(next, count);
|
|
147
|
+
revealIndex(next);
|
|
148
|
+
}, [flushSearch, revealIndex, updateMatchLabel]);
|
|
149
|
+
const handleInputChange = useCallback((value) => {
|
|
150
|
+
setInputValue(value);
|
|
151
|
+
currentIndexRef.current = 0;
|
|
152
|
+
scheduleSearch(value, false, true);
|
|
153
|
+
}, [scheduleSearch]);
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (!open)
|
|
156
|
+
return;
|
|
157
|
+
if (debounceTimerRef.current != null)
|
|
158
|
+
return;
|
|
159
|
+
const q = inputValueRef.current.trim();
|
|
160
|
+
if (!q)
|
|
161
|
+
return;
|
|
162
|
+
applySearch(q, true, false);
|
|
163
|
+
}, [contentKey, open, applySearch]);
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (prevSessionIdRef.current === sessionId)
|
|
166
|
+
return;
|
|
167
|
+
prevSessionIdRef.current = sessionId;
|
|
168
|
+
closeFind();
|
|
169
|
+
}, [sessionId, closeFind]);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (!open)
|
|
172
|
+
clearChatTranscriptFindHighlights();
|
|
173
|
+
return () => {
|
|
174
|
+
cancelPendingSearch();
|
|
175
|
+
clearChatTranscriptFindHighlights();
|
|
176
|
+
};
|
|
177
|
+
}, [open, cancelPendingSearch]);
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
const onKeyDown = (e) => {
|
|
180
|
+
const mod = isModKey(e);
|
|
181
|
+
const key = e.key.toLowerCase();
|
|
182
|
+
if (mod && key === 'f') {
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
const selected = window.getSelection()?.toString().trim();
|
|
185
|
+
const seed = selected && !selected.includes('\n') && selected.length <= 500
|
|
186
|
+
? selected
|
|
187
|
+
: undefined;
|
|
188
|
+
if (open && seed == null) {
|
|
189
|
+
inputRef.current?.focus();
|
|
190
|
+
inputRef.current?.select();
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
openFind(seed ?? (open ? inputValueRef.current : undefined));
|
|
194
|
+
}
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (!open)
|
|
198
|
+
return;
|
|
199
|
+
if (mod && key === 'g') {
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
if (e.shiftKey)
|
|
202
|
+
findPrevious();
|
|
203
|
+
else
|
|
204
|
+
findNext();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (key === 'escape') {
|
|
208
|
+
e.preventDefault();
|
|
209
|
+
closeFind();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
window.addEventListener('keydown', onKeyDown);
|
|
213
|
+
return () => window.removeEventListener('keydown', onKeyDown);
|
|
214
|
+
}, [open, openFind, closeFind, findNext, findPrevious]);
|
|
215
|
+
if (!open)
|
|
216
|
+
return null;
|
|
217
|
+
const trimmedInput = inputValue.trim();
|
|
218
|
+
const displayMatchLabel = trimmedInput.length === 0
|
|
219
|
+
? ''
|
|
220
|
+
: trimmedInput !== appliedQueryRef.current
|
|
221
|
+
? '…'
|
|
222
|
+
: matchLabel;
|
|
223
|
+
return (_jsx(ChatTranscriptFindBar, { query: inputValue, onQueryChange: handleInputChange, inputRef: inputRef, matchLabel: displayMatchLabel, onFindNext: findNext, onFindPrevious: findPrevious, onClose: closeFind, placeholder: placeholder, ariaLabel: ariaLabel }));
|
|
224
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
export type ChatTranscriptFindBarProps = {
|
|
3
|
+
query: string;
|
|
4
|
+
onQueryChange: (value: string) => void;
|
|
5
|
+
inputRef: RefObject<HTMLInputElement | null>;
|
|
6
|
+
matchLabel: string;
|
|
7
|
+
onFindNext: () => void;
|
|
8
|
+
onFindPrevious: () => void;
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
ariaLabel?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function ChatTranscriptFindBar({ query, onQueryChange, inputRef, matchLabel, onFindNext, onFindPrevious, onClose, placeholder, ariaLabel, className, }: ChatTranscriptFindBarProps): import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=ChatTranscriptFindBar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatTranscriptFindBar.d.ts","sourceRoot":"","sources":["../src/ChatTranscriptFindBar.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EACpC,KAAK,EACL,aAAa,EACb,QAAQ,EACR,UAAU,EACV,UAAU,EACV,cAAc,EACd,OAAO,EACP,WAA6B,EAC7B,SAA0B,EAC1B,SAAsC,GACvC,EAAE,0BAA0B,+BA0D5B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 John Ewart <john@johnewart.net>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ActionIcon, Group, Text, TextInput } from '@mantine/core';
|
|
7
|
+
import { IconChevronDown, IconChevronUp, IconX } from '@tabler/icons-react';
|
|
8
|
+
export function ChatTranscriptFindBar({ query, onQueryChange, inputRef, matchLabel, onFindNext, onFindPrevious, onClose, placeholder = 'Find in chat…', ariaLabel = 'Find in chat', className = 'chat-transcript-find-bar', }) {
|
|
9
|
+
return (_jsx("div", { className: className, "data-chat-find-ignore": true, "data-code-find-ignore": true, children: _jsxs(Group, { gap: 6, wrap: "nowrap", children: [_jsx(TextInput, { ref: inputRef, size: "xs", placeholder: placeholder, value: query, onChange: (e) => onQueryChange(e.currentTarget.value), onKeyDown: (e) => {
|
|
10
|
+
if (e.key === 'Enter') {
|
|
11
|
+
e.preventDefault();
|
|
12
|
+
if (e.shiftKey)
|
|
13
|
+
onFindPrevious();
|
|
14
|
+
else
|
|
15
|
+
onFindNext();
|
|
16
|
+
}
|
|
17
|
+
if (e.key === 'Escape') {
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
onClose();
|
|
20
|
+
}
|
|
21
|
+
}, "aria-label": ariaLabel, styles: { input: { width: 200 } } }), _jsx(Text, { size: "xs", c: "dimmed", style: { minWidth: 52, textAlign: 'center' }, children: matchLabel }), _jsx(ActionIcon, { variant: "subtle", size: "sm", "aria-label": "Previous match", onClick: onFindPrevious, children: _jsx(IconChevronUp, { size: 16, stroke: 1.5 }) }), _jsx(ActionIcon, { variant: "subtle", size: "sm", "aria-label": "Next match", onClick: onFindNext, children: _jsx(IconChevronDown, { size: 16, stroke: 1.5 }) }), _jsx(ActionIcon, { variant: "subtle", size: "sm", "aria-label": "Close find", onClick: onClose, children: _jsx(IconX, { size: 16, stroke: 1.5 }) })] }) }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The message-entry surface: textarea (Enter to send, ⌥/Ctrl/⌘+Enter for the
|
|
3
|
+
* alternate send, Shift+Enter for a newline), a send button labelled with what
|
|
4
|
+
* it will do (see `sendMode`) plus a stop button while streaming, and two
|
|
5
|
+
* slots (`beforeInput`, `afterInput`) for host-specific rows — an
|
|
6
|
+
* attachments strip, a model switcher, paste pills, whatever. This
|
|
7
|
+
* component owns none of that; it only owns "type text, hit send".
|
|
8
|
+
*/
|
|
9
|
+
import { type ReactNode } from 'react';
|
|
10
|
+
import { type SendMode } from './sendMode.js';
|
|
11
|
+
export type ComposerProps = {
|
|
12
|
+
/**
|
|
13
|
+
* Called with the trimmed text on submit. Empty text never submits.
|
|
14
|
+
* `alternate` is true when ⌥, Ctrl or ⌘ is held (Enter or the button) — the
|
|
15
|
+
* "other" send (e.g. interrupt instead of queue).
|
|
16
|
+
*/
|
|
17
|
+
onSend: (text: string, alternate: boolean) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Live send mode (`useSendMode`): labels the send button with what it will do
|
|
20
|
+
* (Send / Queue / Interrupt) and flips it while a modifier is held in the
|
|
21
|
+
* input. Omitted = a plain "Send" button.
|
|
22
|
+
*/
|
|
23
|
+
sendMode?: SendMode;
|
|
24
|
+
/** True while an assistant reply is streaming — swaps the send button for a stop button. */
|
|
25
|
+
streaming?: boolean;
|
|
26
|
+
/** Called when the stop button is clicked while `streaming`. */
|
|
27
|
+
onStop?: () => void;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
autoFocus?: boolean;
|
|
31
|
+
/** Controlled value; omit to let the composer manage its own text state. */
|
|
32
|
+
value?: string;
|
|
33
|
+
onValueChange?: (text: string) => void;
|
|
34
|
+
/** Row rendered above the textarea (e.g. attachment pills, paste chips). */
|
|
35
|
+
beforeInput?: ReactNode;
|
|
36
|
+
/** Row rendered below the textarea, to the left of the send/stop button (e.g. model switcher). */
|
|
37
|
+
afterInput?: ReactNode;
|
|
38
|
+
minRows?: number;
|
|
39
|
+
maxRows?: number;
|
|
40
|
+
className?: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function Composer({ onSend, sendMode, streaming, onStop, placeholder, disabled, autoFocus, value, onValueChange, beforeInput, afterInput, minRows, maxRows, className, }: ComposerProps): import("react").JSX.Element;
|
|
43
|
+
//# sourceMappingURL=Composer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Composer.d.ts","sourceRoot":"","sources":["../src/Composer.tsx"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AAEH,OAAO,EAAqD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG1F,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IACnD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,4FAA4F;IAC5F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,4EAA4E;IAC5E,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,kGAAkG;IAClG,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,EACvB,MAAM,EACN,QAAQ,EACR,SAAiB,EACjB,MAAM,EACN,WAAwB,EACxB,QAAgB,EAChB,SAAiB,EACjB,KAAK,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAW,EACX,OAAY,EACZ,SAAS,GACV,EAAE,aAAa,+BA2Ff"}
|
package/dist/Composer.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 John Ewart <john@johnewart.net>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The message-entry surface: textarea (Enter to send, ⌥/Ctrl/⌘+Enter for the
|
|
8
|
+
* alternate send, Shift+Enter for a newline), a send button labelled with what
|
|
9
|
+
* it will do (see `sendMode`) plus a stop button while streaming, and two
|
|
10
|
+
* slots (`beforeInput`, `afterInput`) for host-specific rows — an
|
|
11
|
+
* attachments strip, a model switcher, paste pills, whatever. This
|
|
12
|
+
* component owns none of that; it only owns "type text, hit send".
|
|
13
|
+
*/
|
|
14
|
+
import { useCallback, useRef, useState } from 'react';
|
|
15
|
+
import { ActionIcon, Button, Textarea } from '@mantine/core';
|
|
16
|
+
import { IconPlayerStop, IconSend } from '@tabler/icons-react';
|
|
17
|
+
import { isAlternateSend } from './sendMode.js';
|
|
18
|
+
export function Composer({ onSend, sendMode, streaming = false, onStop, placeholder = 'Message…', disabled = false, autoFocus = false, value, onValueChange, beforeInput, afterInput, minRows = 1, maxRows = 10, className, }) {
|
|
19
|
+
const [internalValue, setInternalValue] = useState('');
|
|
20
|
+
const isControlled = value !== undefined;
|
|
21
|
+
const text = isControlled ? value : internalValue;
|
|
22
|
+
const textareaRef = useRef(null);
|
|
23
|
+
const setText = useCallback((next) => {
|
|
24
|
+
if (!isControlled)
|
|
25
|
+
setInternalValue(next);
|
|
26
|
+
onValueChange?.(next);
|
|
27
|
+
}, [isControlled, onValueChange]);
|
|
28
|
+
const submit = useCallback((alternate = false) => {
|
|
29
|
+
const trimmed = text.trim();
|
|
30
|
+
if (!trimmed || disabled)
|
|
31
|
+
return;
|
|
32
|
+
onSend(trimmed, alternate);
|
|
33
|
+
setText('');
|
|
34
|
+
}, [text, disabled, onSend, setText]);
|
|
35
|
+
const handleKeyDown = (e) => {
|
|
36
|
+
sendMode?.keyHandlers.onKeyDown(e);
|
|
37
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
submit(isAlternateSend(e));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const label = sendMode?.label ?? 'Send';
|
|
43
|
+
const hasText = !!text.trim();
|
|
44
|
+
return (_jsxs("div", { className: ['llmd-composer', className].filter(Boolean).join(' '), children: [beforeInput ? _jsx("div", { className: "llmd-composer__before", children: beforeInput }) : null, _jsxs("div", { className: "llmd-composer__row", style: { display: 'flex', alignItems: 'flex-end', gap: 8 }, children: [_jsx(Textarea, { ref: textareaRef, className: "llmd-composer__input", "data-llmd-composer-input": "", style: { flex: 1 }, value: text, onChange: (e) => setText(e.currentTarget.value), onKeyDown: handleKeyDown, onKeyUp: sendMode?.keyHandlers.onKeyUp, onBlur: sendMode?.keyHandlers.onBlur, placeholder: placeholder, disabled: disabled, autoFocus: autoFocus, autosize: true, minRows: minRows, maxRows: maxRows }), streaming ? (_jsx(ActionIcon, { type: "button", variant: "filled", color: "red", size: "lg", "aria-label": "Stop", onClick: onStop, children: _jsx(IconPlayerStop, { size: 16, stroke: 1.75 }) })) : null, !streaming || hasText ? (_jsx(Button, { type: "button", variant: "filled", size: "sm", className: "llmd-composer__send", "aria-label": label, "data-send-behavior": sendMode?.behavior, leftSection: _jsx(IconSend, { size: 14, stroke: 1.75 }), disabled: disabled || !hasText, onClick: (e) => submit(isAlternateSend(e)), children: label })) : null] }), afterInput ? _jsx("div", { className: "llmd-composer__after", children: afterInput }) : null] }));
|
|
45
|
+
}
|