@sybilion/uilib 1.3.37 → 1.3.38
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/esm/components/ui/Chat/Chat.types.js +6 -1
- package/dist/esm/components/ui/Chat/ChatChrome/ChatChrome.js +7 -10
- package/dist/esm/components/ui/Chat/ChatPrompt/ChatPrompt.js +2 -1
- package/dist/esm/components/ui/Chat/ChatPrompt/useChatPromptEditor.js +5 -2
- package/dist/esm/components/ui/Chat/ChatSheet/useChatPanelChromeModel.js +31 -14
- package/dist/esm/index.js +1 -1
- package/dist/esm/tiptap/slash-mention/createSlashMentionExtension.js +24 -5
- package/dist/esm/types/src/components/ui/Chat/Chat.types.d.ts +6 -1
- package/dist/esm/types/src/components/ui/Chat/Chat.types.test.d.ts +1 -0
- package/dist/esm/types/src/components/ui/Chat/ChatChrome/ChatChrome.d.ts +1 -1
- package/dist/esm/types/src/components/ui/Chat/ChatChrome/ChatChrome.types.d.ts +3 -6
- package/dist/esm/types/src/components/ui/Chat/ChatPrompt/ChatPrompt.d.ts +1 -1
- package/dist/esm/types/src/components/ui/Chat/ChatPrompt/useChatPromptEditor.d.ts +3 -2
- package/dist/esm/types/src/components/ui/Chat/ChatSheet/useChatPanelChromeModel.d.ts +1 -1
- package/dist/esm/types/src/components/ui/Chat/index.d.ts +1 -1
- package/dist/esm/types/src/tiptap/slash-mention/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/ui/Chat/Chat.types.test.ts +32 -0
- package/src/components/ui/Chat/Chat.types.ts +13 -1
- package/src/components/ui/Chat/ChatChrome/ChatChrome.tsx +24 -46
- package/src/components/ui/Chat/ChatChrome/ChatChrome.types.ts +6 -8
- package/src/components/ui/Chat/ChatPrompt/ChatPrompt.tsx +2 -0
- package/src/components/ui/Chat/ChatPrompt/useChatPromptEditor.ts +10 -2
- package/src/components/ui/Chat/ChatSheet/useChatPanelChromeModel.tsx +49 -20
- package/src/components/ui/Chat/index.ts +5 -1
- package/src/docs/pages/ChatAttachmentsDropzonePage.tsx +0 -5
- package/src/docs/pages/ChatPage.tsx +0 -5
- package/src/docs/pages/ChatSlashCommandsPage.tsx +40 -13
- package/src/docs/pages/ChatUserCsvAttachmentPage.tsx +0 -5
- package/src/tiptap/slash-mention/createSlashMentionExtension.ts +24 -5
- package/src/tiptap/slash-mention/types.ts +2 -1
|
@@ -6,5 +6,10 @@ var MessageRole;
|
|
|
6
6
|
})(MessageRole || (MessageRole = {}));
|
|
7
7
|
/** System placeholder while dashboard generation runs (must match ChatSheet `addMessage` text). */
|
|
8
8
|
const GENERATING_DASHBOARD_SYSTEM_TEXT = 'Generating dashboard…';
|
|
9
|
+
/** Slash command id that triggers dashboard generation when `onGenerateDashboard` is set. */
|
|
10
|
+
const GENERATE_DASHBOARD_SLASH_COMMAND_ID = 'generate-dashboard';
|
|
11
|
+
function isGenerateDashboardSlashMessage(message) {
|
|
12
|
+
return message.trim() === `/${GENERATE_DASHBOARD_SLASH_COMMAND_ID}`;
|
|
13
|
+
}
|
|
9
14
|
|
|
10
|
-
export { GENERATING_DASHBOARD_SYSTEM_TEXT, MessageRole };
|
|
15
|
+
export { GENERATE_DASHBOARD_SLASH_COMMAND_ID, GENERATING_DASHBOARD_SYSTEM_TEXT, MessageRole, isGenerateDashboardSlashMessage };
|
|
@@ -4,7 +4,7 @@ import { useMemo, useState, useCallback, useEffect } from 'react';
|
|
|
4
4
|
import { displayLabelForBranchKeyFromMessages, humanizeBranchKey } from '../ChatMessage/presetScript.js';
|
|
5
5
|
import { TextShimmer } from '../../TextShimmer/TextShimmer.js';
|
|
6
6
|
import { Scroll } from '@homecode/ui';
|
|
7
|
-
import { X, PaperPlaneRightIcon
|
|
7
|
+
import { X, PaperPlaneRightIcon } from '@phosphor-icons/react';
|
|
8
8
|
import { Button } from '../../Button/Button.js';
|
|
9
9
|
import { DropZone } from '../../DropZone/DropZone.js';
|
|
10
10
|
import { PanelResizeHandle } from '../../Sidebar/Sidebar.js';
|
|
@@ -14,7 +14,7 @@ import { filterToTextAttachments, isAttachmentsDropzoneEnabled, buildAcceptAttr
|
|
|
14
14
|
import { extractChatAttachmentItems } from '../chatAttachmentExtract.js';
|
|
15
15
|
import S from './ChatChrome.styl.js';
|
|
16
16
|
|
|
17
|
-
function ChatChrome({ showResizeHandle, resizeHandle, onClose, isEmpty, renderPresets, messages, onQuickReply, suppressedQuickReplyKeys, isLoading, scriptContinueLabel, onScriptContinue, renderMessageChart,
|
|
17
|
+
function ChatChrome({ showResizeHandle, resizeHandle, onClose, isEmpty, renderPresets, messages, onQuickReply, suppressedQuickReplyKeys, isLoading, scriptContinueLabel, onScriptContinue, renderMessageChart, showSyntheticBranchButtons, unusedBranchKeys, showInlinePresets, isLastMessageFromUser, scrollRef, effectiveScopeId, onPromptSubmit, onChatDeleted, promptPrefill, footerClassName, emptyState, allowedAttachments, allowPdfAttachments = false, onAttachmentsDropped, slashCommandItems, onSlashItemCommand, promptPlaceholder, }) {
|
|
18
18
|
const filteredAllowedAttachments = useMemo(() => filterToTextAttachments(allowedAttachments), [allowedAttachments]);
|
|
19
19
|
const attachmentsDropzoneEnabled = isAttachmentsDropzoneEnabled(allowedAttachments, allowPdfAttachments);
|
|
20
20
|
const attachmentAccept = useMemo(() => buildAcceptAttr(filteredAllowedAttachments, allowPdfAttachments), [filteredAllowedAttachments, allowPdfAttachments]);
|
|
@@ -73,14 +73,11 @@ function ChatChrome({ showResizeHandle, resizeHandle, onClose, isEmpty, renderPr
|
|
|
73
73
|
: undefined, onScriptContinue: isLast && scriptContinueLabel
|
|
74
74
|
? onScriptContinue
|
|
75
75
|
: undefined, renderMessageChart: renderMessageChart }, msg.id));
|
|
76
|
-
}),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
: null, isScriptComplete &&
|
|
82
|
-
onGenerateDashboard &&
|
|
83
|
-
!generatingDashboard ? (jsxs(Button, { type: "button", variant: "default", size: "lg", disabled: isLoading, onClick: onGenerateDashboardClick, children: [jsx(ChartLineIcon, {}), "Generate Dashboard"] })) : null] })), showInlinePresets && renderPresets('inline'), isLoading && isLastMessageFromUser && (jsx(TextShimmer, { duration: 1, spread: 5, className: S.loader, children: "Thinking..." }))] }) })), jsxs("div", { className: cn(S.footer, footerClassName), children: [isEmpty ? (jsx("div", { className: S.notice, children: "Forecast Assistant can make mistakes." })) : null, jsx(Chat.Prompt, { onSubmit: handlePromptSubmitWithAttachments, disabled: promptBusy, attachments: pendingAttachments, onRemoveAttachment: handleRemoveAttachment, prefillMessage: promptPrefill ?? undefined, placeholder: promptPlaceholder, slashCommandItems: slashCommandItems, attachmentAccept: attachmentsDropzoneEnabled ? attachmentAccept : undefined, onAttachmentFiles: attachmentsDropzoneEnabled ? handleAttachmentFiles : undefined })] })] })] })] }));
|
|
76
|
+
}), showSyntheticBranchButtons ? (jsx("div", { className: S.branchRow, children: unusedBranchKeys.map(key => {
|
|
77
|
+
const label = displayLabelForBranchKeyFromMessages(key, messages) ??
|
|
78
|
+
humanizeBranchKey(key);
|
|
79
|
+
return (jsx("span", { className: S.branchBtnWrap, children: jsxs(Button, { type: "button", variant: "outline", size: "sm", disabled: isLoading, onClick: () => onQuickReply(key, label), children: [jsx(PaperPlaneRightIcon, {}), label] }) }, key));
|
|
80
|
+
}) })) : null, showInlinePresets && renderPresets('inline'), isLoading && isLastMessageFromUser && (jsx(TextShimmer, { duration: 1, spread: 5, className: S.loader, children: "Thinking..." }))] }) })), jsxs("div", { className: cn(S.footer, footerClassName), children: [isEmpty ? (jsx("div", { className: S.notice, children: "Forecast Assistant can make mistakes." })) : null, jsx(Chat.Prompt, { onSubmit: handlePromptSubmitWithAttachments, disabled: promptBusy, attachments: pendingAttachments, onRemoveAttachment: handleRemoveAttachment, prefillMessage: promptPrefill ?? undefined, placeholder: promptPlaceholder, slashCommandItems: slashCommandItems, onSlashItemCommand: onSlashItemCommand, attachmentAccept: attachmentsDropzoneEnabled ? attachmentAccept : undefined, onAttachmentFiles: attachmentsDropzoneEnabled ? handleAttachmentFiles : undefined })] })] })] })] }));
|
|
84
81
|
}
|
|
85
82
|
|
|
86
83
|
export { ChatChrome };
|
|
@@ -6,13 +6,14 @@ import { ChatPromptAttachments } from './ChatPromptAttachments.js';
|
|
|
6
6
|
import { ChatPromptComposer } from './ChatPromptComposer.js';
|
|
7
7
|
import { useChatPromptEditor } from './useChatPromptEditor.js';
|
|
8
8
|
|
|
9
|
-
function ChatPrompt({ onSubmit, placeholder, className, footer, prefillMessage, slashCommandItems, attachments = [], onRemoveAttachment, disabled = false, attachmentAccept, onAttachmentFiles, }) {
|
|
9
|
+
function ChatPrompt({ onSubmit, placeholder, className, footer, prefillMessage, slashCommandItems, onSlashItemCommand, attachments = [], onRemoveAttachment, disabled = false, attachmentAccept, onAttachmentFiles, }) {
|
|
10
10
|
const attachmentsCount = attachments.length;
|
|
11
11
|
const emitSubmitRef = useRef(() => { });
|
|
12
12
|
const { editor, trimmedMessage, resetAfterSend, handleComposerKeyDown } = useChatPromptEditor({
|
|
13
13
|
disabled,
|
|
14
14
|
placeholder,
|
|
15
15
|
slashCommandItems,
|
|
16
|
+
onSlashItemCommand,
|
|
16
17
|
prefillMessage,
|
|
17
18
|
attachmentsCount,
|
|
18
19
|
onEnterSubmit: () => emitSubmitRef.current(),
|
|
@@ -7,8 +7,10 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
7
7
|
import { chatPromptSafeEditorDom, syncChatPromptComposerHeight } from './ChatPrompt.helpers.js';
|
|
8
8
|
import { CHAT_PROMPT_EMPTY_DOC, chatPromptParagraphDoc } from './chatPromptDoc.js';
|
|
9
9
|
|
|
10
|
-
function useChatPromptEditor({ disabled, placeholder, slashCommandItems, prefillMessage, attachmentsCount = 0, onEnterSubmit, }) {
|
|
10
|
+
function useChatPromptEditor({ disabled, placeholder, slashCommandItems, onSlashItemCommand, prefillMessage, attachmentsCount = 0, onEnterSubmit, }) {
|
|
11
11
|
const slashOpenRef = useRef(false);
|
|
12
|
+
const onSlashItemCommandRef = useRef(onSlashItemCommand);
|
|
13
|
+
onSlashItemCommandRef.current = onSlashItemCommand;
|
|
12
14
|
const suggestionActiveUpdater = useCallback((active) => {
|
|
13
15
|
slashOpenRef.current = active;
|
|
14
16
|
}, []);
|
|
@@ -50,6 +52,7 @@ function useChatPromptEditor({ disabled, placeholder, slashCommandItems, prefill
|
|
|
50
52
|
items: slashItemsStable,
|
|
51
53
|
suggestionPlacement: 'above',
|
|
52
54
|
onSuggestionUiActiveChange: suggestionActiveUpdater,
|
|
55
|
+
onItemCommand: ctx => onSlashItemCommandRef.current?.(ctx) === true,
|
|
53
56
|
}));
|
|
54
57
|
}
|
|
55
58
|
return exts;
|
|
@@ -86,7 +89,7 @@ function useChatPromptEditor({ disabled, placeholder, slashCommandItems, prefill
|
|
|
86
89
|
setPlainDraft(ed.getText());
|
|
87
90
|
},
|
|
88
91
|
onCreate: bindEditorDom,
|
|
89
|
-
}, [extensions,
|
|
92
|
+
}, [extensions, bindEditorDom, ariaLabelComposer]);
|
|
90
93
|
useEffect(() => {
|
|
91
94
|
if (!editor)
|
|
92
95
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
|
3
|
-
import { MessageRole, GENERATING_DASHBOARD_SYSTEM_TEXT } from '../Chat.types.js';
|
|
3
|
+
import { MessageRole, GENERATING_DASHBOARD_SYSTEM_TEXT, GENERATE_DASHBOARD_SLASH_COMMAND_ID, isGenerateDashboardSlashMessage } from '../Chat.types.js';
|
|
4
4
|
import { isGraphIntakeAssistantStepComplete, matchUserTextToQuickReply, isPresetScriptGraph, branchesFromPresetScriptGraph, parseScriptLine, textHasQuickReplyMarkers, branchKeysUsedFromChatHistory, branchKeysUsedByUserMessages, extractQuickReplyLabelKeyPairsFromText, entryBranchKeyBeforeLastAssistant } from '../ChatMessage/presetScript.js';
|
|
5
5
|
import { buildChatSendMessagePayload, displayTextFromSendPayload } from '../buildChatSendMessagePayload.js';
|
|
6
6
|
import { usedPresetIdsFromMessages, formatChatTranscript } from '../chat-preset-utils.js';
|
|
@@ -58,7 +58,7 @@ function useChatPanelChromeModel({ embedAsPage, presets, scopeId, onMessage, onS
|
|
|
58
58
|
const [quickReplyBranchesByChat, setQuickReplyBranchesByChat] = useState({});
|
|
59
59
|
const [usedScriptBranchKeysByChat, setUsedScriptBranchKeysByChat] = useState({});
|
|
60
60
|
const [intakeByChatId, setIntakeByChatId] = useState({});
|
|
61
|
-
/** Preset intake finished for this session
|
|
61
|
+
/** Preset intake finished for this session (e.g. `onScriptComplete` callback). */
|
|
62
62
|
const [scriptCompleteByChatId, setScriptCompleteByChatId] = useState({});
|
|
63
63
|
const [generatingDashboard, setGeneratingDashboard] = useState(false);
|
|
64
64
|
const scriptAdvanceLockRef = useRef(false);
|
|
@@ -712,10 +712,6 @@ function useChatPanelChromeModel({ embedAsPage, presets, scopeId, onMessage, onS
|
|
|
712
712
|
lastMsg?.role === MessageRole.ASSISTANT &&
|
|
713
713
|
!linearScriptActive &&
|
|
714
714
|
(!graphActive || (!lastHasQuickMarkers && unusedBranchKeys.length === 0));
|
|
715
|
-
const isScriptComplete = Boolean(currentChatId && scriptCompleteByChatId[currentChatId]);
|
|
716
|
-
/** Branch row also when intake is done but all branches used (Generate Dashboard only). */
|
|
717
|
-
const showBranchActionsRow = showSyntheticBranchButtons ||
|
|
718
|
-
(isScriptComplete && Boolean(onGenerateDashboard) && !generatingDashboard);
|
|
719
715
|
const handleGenerateDashboard = useCallback(async () => {
|
|
720
716
|
if (!currentChatId || !onGenerateDashboard)
|
|
721
717
|
return;
|
|
@@ -743,6 +739,33 @@ function useChatPanelChromeModel({ embedAsPage, presets, scopeId, onMessage, onS
|
|
|
743
739
|
addMessage,
|
|
744
740
|
removeMessageById,
|
|
745
741
|
]);
|
|
742
|
+
const onSlashItemCommand = useCallback(({ item }) => {
|
|
743
|
+
if (item.id !== GENERATE_DASHBOARD_SLASH_COMMAND_ID ||
|
|
744
|
+
!onGenerateDashboard) {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
if (generatingDashboard) {
|
|
748
|
+
return true;
|
|
749
|
+
}
|
|
750
|
+
queueMicrotask(() => {
|
|
751
|
+
void handleGenerateDashboard();
|
|
752
|
+
});
|
|
753
|
+
return true;
|
|
754
|
+
}, [onGenerateDashboard, generatingDashboard, handleGenerateDashboard]);
|
|
755
|
+
const onPromptSubmitWithSlashCommands = useCallback(async (message, attachments) => {
|
|
756
|
+
if (isGenerateDashboardSlashMessage(message) &&
|
|
757
|
+
onGenerateDashboard &&
|
|
758
|
+
!generatingDashboard) {
|
|
759
|
+
void handleGenerateDashboard();
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
return handlePromptSubmit(message, attachments);
|
|
763
|
+
}, [
|
|
764
|
+
handlePromptSubmit,
|
|
765
|
+
onGenerateDashboard,
|
|
766
|
+
generatingDashboard,
|
|
767
|
+
handleGenerateDashboard,
|
|
768
|
+
]);
|
|
746
769
|
const onDragChatWidth = useCallback((rawPx) => setChatWidthPx(rawPx, { persist: false }), [setChatWidthPx]);
|
|
747
770
|
const onDragChatComplete = useCallback((finalRawPx) => setChatWidthPx(finalRawPx, { persist: true }), [setChatWidthPx]);
|
|
748
771
|
const chromeProps = {
|
|
@@ -766,20 +789,13 @@ function useChatPanelChromeModel({ embedAsPage, presets, scopeId, onMessage, onS
|
|
|
766
789
|
scriptContinueLabel,
|
|
767
790
|
onScriptContinue,
|
|
768
791
|
renderMessageChart,
|
|
769
|
-
showBranchActionsRow,
|
|
770
792
|
showSyntheticBranchButtons,
|
|
771
793
|
unusedBranchKeys,
|
|
772
|
-
isScriptComplete,
|
|
773
|
-
onGenerateDashboard,
|
|
774
|
-
generatingDashboard,
|
|
775
|
-
onGenerateDashboardClick: () => {
|
|
776
|
-
void handleGenerateDashboard();
|
|
777
|
-
},
|
|
778
794
|
showInlinePresets,
|
|
779
795
|
isLastMessageFromUser,
|
|
780
796
|
scrollRef,
|
|
781
797
|
effectiveScopeId,
|
|
782
|
-
onPromptSubmit:
|
|
798
|
+
onPromptSubmit: onPromptSubmitWithSlashCommands,
|
|
783
799
|
onChatDeleted: endLocalDemoFlow,
|
|
784
800
|
promptPrefill: promptLinkPrefill,
|
|
785
801
|
emptyState: resolvedEmptyState,
|
|
@@ -787,6 +803,7 @@ function useChatPanelChromeModel({ embedAsPage, presets, scopeId, onMessage, onS
|
|
|
787
803
|
allowPdfAttachments,
|
|
788
804
|
onAttachmentsDropped,
|
|
789
805
|
slashCommandItems,
|
|
806
|
+
onSlashItemCommand,
|
|
790
807
|
};
|
|
791
808
|
const toggleOpen = () => onOpenChange(!isOpen);
|
|
792
809
|
return {
|
package/dist/esm/index.js
CHANGED
|
@@ -32,7 +32,7 @@ export { useChatPanelChromeModel } from './components/ui/Chat/ChatSheet/useChatP
|
|
|
32
32
|
export { ChatMessage } from './components/ui/Chat/ChatMessage/ChatMessage.js';
|
|
33
33
|
export { ChatPrompt } from './components/ui/Chat/ChatPrompt/ChatPrompt.js';
|
|
34
34
|
export { ChatPresets } from './components/ui/Chat/ChatPresets/ChatPresets.js';
|
|
35
|
-
export { MessageRole } from './components/ui/Chat/Chat.types.js';
|
|
35
|
+
export { GENERATE_DASHBOARD_SLASH_COMMAND_ID, MessageRole, isGenerateDashboardSlashMessage } from './components/ui/Chat/Chat.types.js';
|
|
36
36
|
export { CsvIcon } from './components/icons/CsvIcon/CsvIcon.js';
|
|
37
37
|
export { Checkbox } from './components/ui/Checkbox/Checkbox.js';
|
|
38
38
|
export { Confirm } from './components/ui/Confirm/Confirm.js';
|
|
@@ -68,6 +68,28 @@ function slashMentionSuggestionRender(uiRef, placement = 'below') {
|
|
|
68
68
|
onKeyDown: ({ event }) => uiRef.current?.onKeyboardEvent(event) ?? false,
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
function clearSlashTriggerEditor(editor, range) {
|
|
72
|
+
if (editor.isDestroyed)
|
|
73
|
+
return;
|
|
74
|
+
try {
|
|
75
|
+
editor.chain().focus().deleteRange(range).clearContent().run();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Editor view may be tearing down during suggestion exit.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function collapseEditorSelectionEnd(editor) {
|
|
82
|
+
if (editor.isDestroyed)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
editor.view?.dom?.ownerDocument?.defaultView
|
|
86
|
+
?.getSelection?.()
|
|
87
|
+
?.collapseToEnd();
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// view.dom throws when editor is not mounted
|
|
91
|
+
}
|
|
92
|
+
}
|
|
71
93
|
function insertDefaultMention(editor, range, props, slashChar) {
|
|
72
94
|
const nodeAfter = editor.view.state.selection.$to.nodeAfter;
|
|
73
95
|
const extend = nodeAfter?.text?.startsWith(' ') ? 1 : 0;
|
|
@@ -135,11 +157,8 @@ function createSlashMentionExtension({ items: resolvedItems, slashChar = '/', pl
|
|
|
135
157
|
command: ({ editor, range, props }) => {
|
|
136
158
|
const item = props;
|
|
137
159
|
if (onItemCommand?.({ editor, range, item }) === true) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
?.getSelection?.()
|
|
141
|
-
?.collapseToEnd();
|
|
142
|
-
});
|
|
160
|
+
clearSlashTriggerEditor(editor, range);
|
|
161
|
+
queueMicrotask(() => collapseEditorSelectionEnd(editor));
|
|
143
162
|
return null;
|
|
144
163
|
}
|
|
145
164
|
insertDefaultMention(editor, range, item, slashChar);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
-
import type { SlashCommandItem } from '#uilib/tiptap/slash-mention/types';
|
|
2
|
+
import type { SlashCommandItem, SlashOnItemCommand } from '#uilib/tiptap/slash-mention/types';
|
|
3
3
|
import type { PresetScriptGraph } from './ChatMessage/presetScript';
|
|
4
4
|
export declare enum MessageRole {
|
|
5
5
|
USER = "user",
|
|
@@ -8,6 +8,9 @@ export declare enum MessageRole {
|
|
|
8
8
|
}
|
|
9
9
|
/** System placeholder while dashboard generation runs (must match ChatSheet `addMessage` text). */
|
|
10
10
|
export declare const GENERATING_DASHBOARD_SYSTEM_TEXT = "Generating dashboard\u2026";
|
|
11
|
+
/** Slash command id that triggers dashboard generation when `onGenerateDashboard` is set. */
|
|
12
|
+
export declare const GENERATE_DASHBOARD_SLASH_COMMAND_ID = "generate-dashboard";
|
|
13
|
+
export declare function isGenerateDashboardSlashMessage(message: string): boolean;
|
|
11
14
|
/** USER-only: text file attached to a message; shown as downloadable file row(s). */
|
|
12
15
|
export type UserTextFileAttachment = {
|
|
13
16
|
displayName: string;
|
|
@@ -84,6 +87,8 @@ export interface ChatPromptProps {
|
|
|
84
87
|
onAttachmentFiles?: (files: File[]) => void;
|
|
85
88
|
/** Slash menu (`/`); omit or pass empty to disable Mention trigger (no default items). */
|
|
86
89
|
slashCommandItems?: SlashCommandItem[];
|
|
90
|
+
/** Custom slash pick handler; return true to skip default mention insert. */
|
|
91
|
+
onSlashItemCommand?: SlashOnItemCommand;
|
|
87
92
|
}
|
|
88
93
|
export interface ChatMessageProps {
|
|
89
94
|
role: MessageRole;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ChatChromeProps } from './ChatChrome.types';
|
|
2
|
-
export declare function ChatChrome({ showResizeHandle, resizeHandle, onClose, isEmpty, renderPresets, messages, onQuickReply, suppressedQuickReplyKeys, isLoading, scriptContinueLabel, onScriptContinue, renderMessageChart,
|
|
2
|
+
export declare function ChatChrome({ showResizeHandle, resizeHandle, onClose, isEmpty, renderPresets, messages, onQuickReply, suppressedQuickReplyKeys, isLoading, scriptContinueLabel, onScriptContinue, renderMessageChart, showSyntheticBranchButtons, unusedBranchKeys, showInlinePresets, isLastMessageFromUser, scrollRef, effectiveScopeId, onPromptSubmit, onChatDeleted, promptPrefill, footerClassName, emptyState, allowedAttachments, allowPdfAttachments, onAttachmentsDropped, slashCommandItems, onSlashItemCommand, promptPlaceholder, }: ChatChromeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,7 +2,7 @@ import type { RefObject } from 'react';
|
|
|
2
2
|
import type { ChatAttachmentDropItem, Message } from '#uilib/components/ui/Chat/Chat.types';
|
|
3
3
|
import type { ChatEmptyStateProps } from '#uilib/components/ui/Chat/ChatEmptyState/ChatEmptyState.types';
|
|
4
4
|
import type { ChatPresetsLayout } from '#uilib/components/ui/Chat/ChatPresets';
|
|
5
|
-
import type { SlashCommandItem } from '#uilib/tiptap/slash-mention/types';
|
|
5
|
+
import type { SlashCommandItem, SlashOnItemCommand } from '#uilib/tiptap/slash-mention/types';
|
|
6
6
|
import type { ScrollRef } from '@homecode/ui';
|
|
7
7
|
export type ChatChromeResizeHandleConfig = {
|
|
8
8
|
isActive: boolean;
|
|
@@ -26,13 +26,8 @@ export interface ChatChromeProps {
|
|
|
26
26
|
scriptContinueLabel: string | undefined;
|
|
27
27
|
onScriptContinue: (() => void) | undefined;
|
|
28
28
|
renderMessageChart?: () => React.ReactNode;
|
|
29
|
-
showBranchActionsRow: boolean;
|
|
30
29
|
showSyntheticBranchButtons: boolean;
|
|
31
30
|
unusedBranchKeys: string[];
|
|
32
|
-
isScriptComplete: boolean;
|
|
33
|
-
onGenerateDashboard: ((transcript: string) => void | Promise<void>) | undefined;
|
|
34
|
-
generatingDashboard: boolean;
|
|
35
|
-
onGenerateDashboardClick: () => void;
|
|
36
31
|
showInlinePresets: boolean;
|
|
37
32
|
isLastMessageFromUser: boolean;
|
|
38
33
|
scrollRef: RefObject<ScrollRef | null>;
|
|
@@ -51,6 +46,8 @@ export interface ChatChromeProps {
|
|
|
51
46
|
onAttachmentsDropped?: (items: ChatAttachmentDropItem[]) => void | Promise<void>;
|
|
52
47
|
/** Slash menu (`/`), forwarded to `Chat.Prompt`; omit or pass empty list to disable slash palette. */
|
|
53
48
|
slashCommandItems?: SlashCommandItem[];
|
|
49
|
+
/** Custom slash pick handler; forwarded to `Chat.Prompt`. */
|
|
50
|
+
onSlashItemCommand?: SlashOnItemCommand;
|
|
54
51
|
/** Composer placeholder forwarded to `Chat.Prompt`. */
|
|
55
52
|
promptPlaceholder?: string;
|
|
56
53
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ChatPromptProps } from '../Chat.types';
|
|
2
|
-
export declare function ChatPrompt({ onSubmit, placeholder, className, footer, prefillMessage, slashCommandItems, attachments, onRemoveAttachment, disabled, attachmentAccept, onAttachmentFiles, }: ChatPromptProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare function ChatPrompt({ onSubmit, placeholder, className, footer, prefillMessage, slashCommandItems, onSlashItemCommand, attachments, onRemoveAttachment, disabled, attachmentAccept, onAttachmentFiles, }: ChatPromptProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
2
|
-
import type { SlashCommandItem } from '#uilib/tiptap/slash-mention/types';
|
|
2
|
+
import type { SlashCommandItem, SlashOnItemCommand } from '#uilib/tiptap/slash-mention/types';
|
|
3
3
|
import type { Editor } from '@tiptap/core';
|
|
4
4
|
export type UseChatPromptEditorOptions = {
|
|
5
5
|
disabled: boolean;
|
|
6
6
|
placeholder?: string;
|
|
7
7
|
slashCommandItems?: SlashCommandItem[];
|
|
8
|
+
onSlashItemCommand?: SlashOnItemCommand;
|
|
8
9
|
prefillMessage?: string | null;
|
|
9
10
|
/** Staged attachment count — Enter-to-send when text empty but files present. */
|
|
10
11
|
attachmentsCount?: number;
|
|
@@ -17,4 +18,4 @@ export type UseChatPromptEditorResult = {
|
|
|
17
18
|
resetAfterSend: () => void;
|
|
18
19
|
handleComposerKeyDown: (event: ReactKeyboardEvent) => void;
|
|
19
20
|
};
|
|
20
|
-
export declare function useChatPromptEditor({ disabled, placeholder, slashCommandItems, prefillMessage, attachmentsCount, onEnterSubmit, }: UseChatPromptEditorOptions): UseChatPromptEditorResult;
|
|
21
|
+
export declare function useChatPromptEditor({ disabled, placeholder, slashCommandItems, onSlashItemCommand, prefillMessage, attachmentsCount, onEnterSubmit, }: UseChatPromptEditorOptions): UseChatPromptEditorResult;
|
|
@@ -12,7 +12,7 @@ export type UseChatPanelChromeModelInput = {
|
|
|
12
12
|
onMessage?: (message: string) => void;
|
|
13
13
|
/** Fires when a preset script has no further `[Label|branchKey]` steps (graph leaf or linear script end). */
|
|
14
14
|
onScriptComplete?: (payload: ScriptCompletePayload) => void;
|
|
15
|
-
/**
|
|
15
|
+
/** Generate dashboard from chat transcript (e.g. via `/generate-dashboard` slash command). */
|
|
16
16
|
onGenerateDashboard?: (transcript: string) => void | Promise<void>;
|
|
17
17
|
/** Renders `[CHART]` tokens in assistant messages. */
|
|
18
18
|
renderMessageChart?: () => React.ReactNode;
|
|
@@ -14,6 +14,6 @@ export { ChatPrompt } from './ChatPrompt';
|
|
|
14
14
|
export { ChatPresets } from './ChatPresets';
|
|
15
15
|
export type { ChatEmptyStateConfig, ChatEmptyStateContext, ChatEmptyStateProps, } from './ChatEmptyState/ChatEmptyState.types';
|
|
16
16
|
export type { Chat as ChatType, ChatAttachmentDropItem, ChatSendMessagePayload, ChatProps, ChatPreset as ChatPresetType, Message, UserTextFileAttachment, } from './Chat.types';
|
|
17
|
-
export { MessageRole } from './Chat.types';
|
|
17
|
+
export { GENERATE_DASHBOARD_SLASH_COMMAND_ID, isGenerateDashboardSlashMessage, MessageRole, } from './Chat.types';
|
|
18
18
|
export type { SlashCommandItem } from '#uilib/tiptap/slash-mention/types';
|
|
19
19
|
export { CsvIcon } from '../../icons/CsvIcon/CsvIcon';
|
|
@@ -10,7 +10,8 @@ export type SlashItemCommandContext = {
|
|
|
10
10
|
item: SlashCommandItem;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
* If provided, run
|
|
13
|
+
* If provided, run when a slash item is picked. Return true to skip mention insert
|
|
14
|
+
* (extension clears the trigger text from the composer).
|
|
14
15
|
*/
|
|
15
16
|
export type SlashOnItemCommand = (ctx: SlashItemCommandContext) => boolean;
|
|
16
17
|
/** Where the slash palette opens relative to the caret. */
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GENERATE_DASHBOARD_SLASH_COMMAND_ID,
|
|
3
|
+
isGenerateDashboardSlashMessage,
|
|
4
|
+
} from './Chat.types';
|
|
5
|
+
|
|
6
|
+
describe('isGenerateDashboardSlashMessage', () => {
|
|
7
|
+
it('matches exact slash command', () => {
|
|
8
|
+
expect(
|
|
9
|
+
isGenerateDashboardSlashMessage(
|
|
10
|
+
`/${GENERATE_DASHBOARD_SLASH_COMMAND_ID}`,
|
|
11
|
+
),
|
|
12
|
+
).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('trims surrounding whitespace', () => {
|
|
16
|
+
expect(
|
|
17
|
+
isGenerateDashboardSlashMessage(
|
|
18
|
+
` /${GENERATE_DASHBOARD_SLASH_COMMAND_ID} `,
|
|
19
|
+
),
|
|
20
|
+
).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('rejects plain text and partial commands', () => {
|
|
24
|
+
expect(isGenerateDashboardSlashMessage('generate-dashboard')).toBe(false);
|
|
25
|
+
expect(isGenerateDashboardSlashMessage('/generate')).toBe(false);
|
|
26
|
+
expect(
|
|
27
|
+
isGenerateDashboardSlashMessage(
|
|
28
|
+
`/ ${GENERATE_DASHBOARD_SLASH_COMMAND_ID}`,
|
|
29
|
+
),
|
|
30
|
+
).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
SlashCommandItem,
|
|
5
|
+
SlashOnItemCommand,
|
|
6
|
+
} from '#uilib/tiptap/slash-mention/types';
|
|
4
7
|
|
|
5
8
|
import type { PresetScriptGraph } from './ChatMessage/presetScript';
|
|
6
9
|
|
|
@@ -13,6 +16,13 @@ export enum MessageRole {
|
|
|
13
16
|
/** System placeholder while dashboard generation runs (must match ChatSheet `addMessage` text). */
|
|
14
17
|
export const GENERATING_DASHBOARD_SYSTEM_TEXT = 'Generating dashboard…';
|
|
15
18
|
|
|
19
|
+
/** Slash command id that triggers dashboard generation when `onGenerateDashboard` is set. */
|
|
20
|
+
export const GENERATE_DASHBOARD_SLASH_COMMAND_ID = 'generate-dashboard';
|
|
21
|
+
|
|
22
|
+
export function isGenerateDashboardSlashMessage(message: string): boolean {
|
|
23
|
+
return message.trim() === `/${GENERATE_DASHBOARD_SLASH_COMMAND_ID}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
16
26
|
/** USER-only: text file attached to a message; shown as downloadable file row(s). */
|
|
17
27
|
export type UserTextFileAttachment = {
|
|
18
28
|
displayName: string;
|
|
@@ -96,6 +106,8 @@ export interface ChatPromptProps {
|
|
|
96
106
|
onAttachmentFiles?: (files: File[]) => void;
|
|
97
107
|
/** Slash menu (`/`); omit or pass empty to disable Mention trigger (no default items). */
|
|
98
108
|
slashCommandItems?: SlashCommandItem[];
|
|
109
|
+
/** Custom slash pick handler; return true to skip default mention insert. */
|
|
110
|
+
onSlashItemCommand?: SlashOnItemCommand;
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
export interface ChatMessageProps {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '#uilib/components/ui/Chat/ChatMessage/presetScript';
|
|
8
8
|
import { TextShimmer } from '#uilib/components/ui/TextShimmer';
|
|
9
9
|
import { Scroll } from '@homecode/ui';
|
|
10
|
-
import {
|
|
10
|
+
import { PaperPlaneRightIcon, X } from '@phosphor-icons/react';
|
|
11
11
|
|
|
12
12
|
import { Button } from '../../Button';
|
|
13
13
|
import { DropZone } from '../../DropZone/DropZone';
|
|
@@ -37,13 +37,8 @@ export function ChatChrome({
|
|
|
37
37
|
scriptContinueLabel,
|
|
38
38
|
onScriptContinue,
|
|
39
39
|
renderMessageChart,
|
|
40
|
-
showBranchActionsRow,
|
|
41
40
|
showSyntheticBranchButtons,
|
|
42
41
|
unusedBranchKeys,
|
|
43
|
-
isScriptComplete,
|
|
44
|
-
onGenerateDashboard,
|
|
45
|
-
generatingDashboard,
|
|
46
|
-
onGenerateDashboardClick,
|
|
47
42
|
showInlinePresets,
|
|
48
43
|
isLastMessageFromUser,
|
|
49
44
|
scrollRef,
|
|
@@ -57,6 +52,7 @@ export function ChatChrome({
|
|
|
57
52
|
allowPdfAttachments = false,
|
|
58
53
|
onAttachmentsDropped,
|
|
59
54
|
slashCommandItems,
|
|
55
|
+
onSlashItemCommand,
|
|
60
56
|
promptPlaceholder,
|
|
61
57
|
}: ChatChromeProps) {
|
|
62
58
|
const filteredAllowedAttachments = useMemo(
|
|
@@ -223,48 +219,29 @@ export function ChatChrome({
|
|
|
223
219
|
);
|
|
224
220
|
})}
|
|
225
221
|
|
|
226
|
-
{
|
|
222
|
+
{showSyntheticBranchButtons ? (
|
|
227
223
|
<div className={S.branchRow}>
|
|
228
|
-
{
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
</span>
|
|
248
|
-
);
|
|
249
|
-
})
|
|
250
|
-
: null}
|
|
251
|
-
|
|
252
|
-
{isScriptComplete &&
|
|
253
|
-
onGenerateDashboard &&
|
|
254
|
-
!generatingDashboard ? (
|
|
255
|
-
<Button
|
|
256
|
-
type="button"
|
|
257
|
-
variant="default"
|
|
258
|
-
size="lg"
|
|
259
|
-
disabled={isLoading}
|
|
260
|
-
onClick={onGenerateDashboardClick}
|
|
261
|
-
>
|
|
262
|
-
<ChartLineIcon />
|
|
263
|
-
Generate Dashboard
|
|
264
|
-
</Button>
|
|
265
|
-
) : null}
|
|
224
|
+
{unusedBranchKeys.map(key => {
|
|
225
|
+
const label =
|
|
226
|
+
displayLabelForBranchKeyFromMessages(key, messages) ??
|
|
227
|
+
humanizeBranchKey(key);
|
|
228
|
+
return (
|
|
229
|
+
<span key={key} className={S.branchBtnWrap}>
|
|
230
|
+
<Button
|
|
231
|
+
type="button"
|
|
232
|
+
variant="outline"
|
|
233
|
+
size="sm"
|
|
234
|
+
disabled={isLoading}
|
|
235
|
+
onClick={() => onQuickReply(key, label)}
|
|
236
|
+
>
|
|
237
|
+
<PaperPlaneRightIcon />
|
|
238
|
+
{label}
|
|
239
|
+
</Button>
|
|
240
|
+
</span>
|
|
241
|
+
);
|
|
242
|
+
})}
|
|
266
243
|
</div>
|
|
267
|
-
)}
|
|
244
|
+
) : null}
|
|
268
245
|
|
|
269
246
|
{showInlinePresets && renderPresets('inline')}
|
|
270
247
|
|
|
@@ -291,6 +268,7 @@ export function ChatChrome({
|
|
|
291
268
|
prefillMessage={promptPrefill ?? undefined}
|
|
292
269
|
placeholder={promptPlaceholder}
|
|
293
270
|
slashCommandItems={slashCommandItems}
|
|
271
|
+
onSlashItemCommand={onSlashItemCommand}
|
|
294
272
|
attachmentAccept={
|
|
295
273
|
attachmentsDropzoneEnabled ? attachmentAccept : undefined
|
|
296
274
|
}
|
|
@@ -6,7 +6,10 @@ import type {
|
|
|
6
6
|
} from '#uilib/components/ui/Chat/Chat.types';
|
|
7
7
|
import type { ChatEmptyStateProps } from '#uilib/components/ui/Chat/ChatEmptyState/ChatEmptyState.types';
|
|
8
8
|
import type { ChatPresetsLayout } from '#uilib/components/ui/Chat/ChatPresets';
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
SlashCommandItem,
|
|
11
|
+
SlashOnItemCommand,
|
|
12
|
+
} from '#uilib/tiptap/slash-mention/types';
|
|
10
13
|
import type { ScrollRef } from '@homecode/ui';
|
|
11
14
|
|
|
12
15
|
export type ChatChromeResizeHandleConfig = {
|
|
@@ -33,15 +36,8 @@ export interface ChatChromeProps {
|
|
|
33
36
|
scriptContinueLabel: string | undefined;
|
|
34
37
|
onScriptContinue: (() => void) | undefined;
|
|
35
38
|
renderMessageChart?: () => React.ReactNode;
|
|
36
|
-
showBranchActionsRow: boolean;
|
|
37
39
|
showSyntheticBranchButtons: boolean;
|
|
38
40
|
unusedBranchKeys: string[];
|
|
39
|
-
isScriptComplete: boolean;
|
|
40
|
-
onGenerateDashboard:
|
|
41
|
-
| ((transcript: string) => void | Promise<void>)
|
|
42
|
-
| undefined;
|
|
43
|
-
generatingDashboard: boolean;
|
|
44
|
-
onGenerateDashboardClick: () => void;
|
|
45
41
|
showInlinePresets: boolean;
|
|
46
42
|
isLastMessageFromUser: boolean;
|
|
47
43
|
scrollRef: RefObject<ScrollRef | null>;
|
|
@@ -65,6 +61,8 @@ export interface ChatChromeProps {
|
|
|
65
61
|
) => void | Promise<void>;
|
|
66
62
|
/** Slash menu (`/`), forwarded to `Chat.Prompt`; omit or pass empty list to disable slash palette. */
|
|
67
63
|
slashCommandItems?: SlashCommandItem[];
|
|
64
|
+
/** Custom slash pick handler; forwarded to `Chat.Prompt`. */
|
|
65
|
+
onSlashItemCommand?: SlashOnItemCommand;
|
|
68
66
|
/** Composer placeholder forwarded to `Chat.Prompt`. */
|
|
69
67
|
promptPlaceholder?: string;
|
|
70
68
|
}
|
|
@@ -14,6 +14,7 @@ export function ChatPrompt({
|
|
|
14
14
|
footer,
|
|
15
15
|
prefillMessage,
|
|
16
16
|
slashCommandItems,
|
|
17
|
+
onSlashItemCommand,
|
|
17
18
|
attachments = [],
|
|
18
19
|
onRemoveAttachment,
|
|
19
20
|
disabled = false,
|
|
@@ -28,6 +29,7 @@ export function ChatPrompt({
|
|
|
28
29
|
disabled,
|
|
29
30
|
placeholder,
|
|
30
31
|
slashCommandItems,
|
|
32
|
+
onSlashItemCommand,
|
|
31
33
|
prefillMessage,
|
|
32
34
|
attachmentsCount,
|
|
33
35
|
onEnterSubmit: () => emitSubmitRef.current(),
|
|
@@ -12,7 +12,10 @@ import {
|
|
|
12
12
|
DEFAULT_CHAT_SLASH_ITEMS,
|
|
13
13
|
createSlashMentionExtension,
|
|
14
14
|
} from '#uilib/tiptap/slash-mention';
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
SlashCommandItem,
|
|
17
|
+
SlashOnItemCommand,
|
|
18
|
+
} from '#uilib/tiptap/slash-mention/types';
|
|
16
19
|
import type { AnyExtension, Editor } from '@tiptap/core';
|
|
17
20
|
import { Placeholder } from '@tiptap/extensions';
|
|
18
21
|
import { useEditor } from '@tiptap/react';
|
|
@@ -28,6 +31,7 @@ export type UseChatPromptEditorOptions = {
|
|
|
28
31
|
disabled: boolean;
|
|
29
32
|
placeholder?: string;
|
|
30
33
|
slashCommandItems?: SlashCommandItem[];
|
|
34
|
+
onSlashItemCommand?: SlashOnItemCommand;
|
|
31
35
|
prefillMessage?: string | null;
|
|
32
36
|
/** Staged attachment count — Enter-to-send when text empty but files present. */
|
|
33
37
|
attachmentsCount?: number;
|
|
@@ -46,11 +50,14 @@ export function useChatPromptEditor({
|
|
|
46
50
|
disabled,
|
|
47
51
|
placeholder,
|
|
48
52
|
slashCommandItems,
|
|
53
|
+
onSlashItemCommand,
|
|
49
54
|
prefillMessage,
|
|
50
55
|
attachmentsCount = 0,
|
|
51
56
|
onEnterSubmit,
|
|
52
57
|
}: UseChatPromptEditorOptions): UseChatPromptEditorResult {
|
|
53
58
|
const slashOpenRef = useRef(false);
|
|
59
|
+
const onSlashItemCommandRef = useRef(onSlashItemCommand);
|
|
60
|
+
onSlashItemCommandRef.current = onSlashItemCommand;
|
|
54
61
|
const suggestionActiveUpdater = useCallback((active: boolean) => {
|
|
55
62
|
slashOpenRef.current = active;
|
|
56
63
|
}, []);
|
|
@@ -96,6 +103,7 @@ export function useChatPromptEditor({
|
|
|
96
103
|
items: slashItemsStable,
|
|
97
104
|
suggestionPlacement: 'above',
|
|
98
105
|
onSuggestionUiActiveChange: suggestionActiveUpdater,
|
|
106
|
+
onItemCommand: ctx => onSlashItemCommandRef.current?.(ctx) === true,
|
|
99
107
|
}),
|
|
100
108
|
);
|
|
101
109
|
}
|
|
@@ -139,7 +147,7 @@ export function useChatPromptEditor({
|
|
|
139
147
|
},
|
|
140
148
|
onCreate: bindEditorDom,
|
|
141
149
|
},
|
|
142
|
-
[extensions,
|
|
150
|
+
[extensions, bindEditorDom, ariaLabelComposer],
|
|
143
151
|
);
|
|
144
152
|
|
|
145
153
|
useEffect(() => {
|
|
@@ -2,9 +2,11 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
ChatPreset,
|
|
5
|
+
GENERATE_DASHBOARD_SLASH_COMMAND_ID,
|
|
5
6
|
GENERATING_DASHBOARD_SYSTEM_TEXT,
|
|
6
7
|
MessageRole,
|
|
7
8
|
type ScriptCompletePayload,
|
|
9
|
+
isGenerateDashboardSlashMessage,
|
|
8
10
|
} from '#uilib/components/ui/Chat/Chat.types';
|
|
9
11
|
import {
|
|
10
12
|
branchKeysUsedByUserMessages,
|
|
@@ -38,7 +40,10 @@ import useEvent from '#uilib/hooks/useEvent';
|
|
|
38
40
|
import { useIsMobile } from '#uilib/hooks/useIsMobile';
|
|
39
41
|
import { useQueryParams } from '#uilib/hooks/useQueryParams';
|
|
40
42
|
import logger from '#uilib/lib/logger';
|
|
41
|
-
import type {
|
|
43
|
+
import type {
|
|
44
|
+
SlashCommandItem,
|
|
45
|
+
SlashItemCommandContext,
|
|
46
|
+
} from '#uilib/tiptap/slash-mention/types';
|
|
42
47
|
import { mergePresetFreeformDefaults } from '#uilib/utils/chatPresetMerge';
|
|
43
48
|
import { ScrollRef } from '@homecode/ui';
|
|
44
49
|
|
|
@@ -58,7 +63,7 @@ export type UseChatPanelChromeModelInput = {
|
|
|
58
63
|
onMessage?: (message: string) => void;
|
|
59
64
|
/** Fires when a preset script has no further `[Label|branchKey]` steps (graph leaf or linear script end). */
|
|
60
65
|
onScriptComplete?: (payload: ScriptCompletePayload) => void;
|
|
61
|
-
/**
|
|
66
|
+
/** Generate dashboard from chat transcript (e.g. via `/generate-dashboard` slash command). */
|
|
62
67
|
onGenerateDashboard?: (transcript: string) => void | Promise<void>;
|
|
63
68
|
/** Renders `[CHART]` tokens in assistant messages. */
|
|
64
69
|
renderMessageChart?: () => React.ReactNode;
|
|
@@ -193,7 +198,7 @@ export function useChatPanelChromeModel({
|
|
|
193
198
|
const [intakeByChatId, setIntakeByChatId] = useState<
|
|
194
199
|
Record<string, IntakeScriptState | undefined>
|
|
195
200
|
>({});
|
|
196
|
-
/** Preset intake finished for this session
|
|
201
|
+
/** Preset intake finished for this session (e.g. `onScriptComplete` callback). */
|
|
197
202
|
const [scriptCompleteByChatId, setScriptCompleteByChatId] = useState<
|
|
198
203
|
Record<string, boolean>
|
|
199
204
|
>({});
|
|
@@ -956,15 +961,6 @@ export function useChatPanelChromeModel({
|
|
|
956
961
|
!linearScriptActive &&
|
|
957
962
|
(!graphActive || (!lastHasQuickMarkers && unusedBranchKeys.length === 0));
|
|
958
963
|
|
|
959
|
-
const isScriptComplete = Boolean(
|
|
960
|
-
currentChatId && scriptCompleteByChatId[currentChatId],
|
|
961
|
-
);
|
|
962
|
-
|
|
963
|
-
/** Branch row also when intake is done but all branches used (Generate Dashboard only). */
|
|
964
|
-
const showBranchActionsRow =
|
|
965
|
-
showSyntheticBranchButtons ||
|
|
966
|
-
(isScriptComplete && Boolean(onGenerateDashboard) && !generatingDashboard);
|
|
967
|
-
|
|
968
964
|
const handleGenerateDashboard = useCallback(async () => {
|
|
969
965
|
if (!currentChatId || !onGenerateDashboard) return;
|
|
970
966
|
const transcript = formatChatTranscript(
|
|
@@ -997,6 +993,45 @@ export function useChatPanelChromeModel({
|
|
|
997
993
|
removeMessageById,
|
|
998
994
|
]);
|
|
999
995
|
|
|
996
|
+
const onSlashItemCommand = useCallback(
|
|
997
|
+
({ item }: SlashItemCommandContext) => {
|
|
998
|
+
if (
|
|
999
|
+
item.id !== GENERATE_DASHBOARD_SLASH_COMMAND_ID ||
|
|
1000
|
+
!onGenerateDashboard
|
|
1001
|
+
) {
|
|
1002
|
+
return false;
|
|
1003
|
+
}
|
|
1004
|
+
if (generatingDashboard) {
|
|
1005
|
+
return true;
|
|
1006
|
+
}
|
|
1007
|
+
queueMicrotask(() => {
|
|
1008
|
+
void handleGenerateDashboard();
|
|
1009
|
+
});
|
|
1010
|
+
return true;
|
|
1011
|
+
},
|
|
1012
|
+
[onGenerateDashboard, generatingDashboard, handleGenerateDashboard],
|
|
1013
|
+
);
|
|
1014
|
+
|
|
1015
|
+
const onPromptSubmitWithSlashCommands = useCallback(
|
|
1016
|
+
async (message: string, attachments?: ChatAttachmentDropItem[]) => {
|
|
1017
|
+
if (
|
|
1018
|
+
isGenerateDashboardSlashMessage(message) &&
|
|
1019
|
+
onGenerateDashboard &&
|
|
1020
|
+
!generatingDashboard
|
|
1021
|
+
) {
|
|
1022
|
+
void handleGenerateDashboard();
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
return handlePromptSubmit(message, attachments);
|
|
1026
|
+
},
|
|
1027
|
+
[
|
|
1028
|
+
handlePromptSubmit,
|
|
1029
|
+
onGenerateDashboard,
|
|
1030
|
+
generatingDashboard,
|
|
1031
|
+
handleGenerateDashboard,
|
|
1032
|
+
],
|
|
1033
|
+
);
|
|
1034
|
+
|
|
1000
1035
|
const onDragChatWidth = useCallback(
|
|
1001
1036
|
(rawPx: number) => setChatWidthPx(rawPx, { persist: false }),
|
|
1002
1037
|
[setChatWidthPx],
|
|
@@ -1028,20 +1063,13 @@ export function useChatPanelChromeModel({
|
|
|
1028
1063
|
scriptContinueLabel,
|
|
1029
1064
|
onScriptContinue,
|
|
1030
1065
|
renderMessageChart,
|
|
1031
|
-
showBranchActionsRow,
|
|
1032
1066
|
showSyntheticBranchButtons,
|
|
1033
1067
|
unusedBranchKeys,
|
|
1034
|
-
isScriptComplete,
|
|
1035
|
-
onGenerateDashboard,
|
|
1036
|
-
generatingDashboard,
|
|
1037
|
-
onGenerateDashboardClick: () => {
|
|
1038
|
-
void handleGenerateDashboard();
|
|
1039
|
-
},
|
|
1040
1068
|
showInlinePresets,
|
|
1041
1069
|
isLastMessageFromUser,
|
|
1042
1070
|
scrollRef,
|
|
1043
1071
|
effectiveScopeId,
|
|
1044
|
-
onPromptSubmit:
|
|
1072
|
+
onPromptSubmit: onPromptSubmitWithSlashCommands,
|
|
1045
1073
|
onChatDeleted: endLocalDemoFlow,
|
|
1046
1074
|
promptPrefill: promptLinkPrefill,
|
|
1047
1075
|
emptyState: resolvedEmptyState,
|
|
@@ -1049,6 +1077,7 @@ export function useChatPanelChromeModel({
|
|
|
1049
1077
|
allowPdfAttachments,
|
|
1050
1078
|
onAttachmentsDropped,
|
|
1051
1079
|
slashCommandItems,
|
|
1080
|
+
onSlashItemCommand,
|
|
1052
1081
|
};
|
|
1053
1082
|
|
|
1054
1083
|
const toggleOpen = () => onOpenChange(!isOpen);
|
|
@@ -39,6 +39,10 @@ export type {
|
|
|
39
39
|
Message,
|
|
40
40
|
UserTextFileAttachment,
|
|
41
41
|
} from './Chat.types';
|
|
42
|
-
export {
|
|
42
|
+
export {
|
|
43
|
+
GENERATE_DASHBOARD_SLASH_COMMAND_ID,
|
|
44
|
+
isGenerateDashboardSlashMessage,
|
|
45
|
+
MessageRole,
|
|
46
|
+
} from './Chat.types';
|
|
43
47
|
export type { SlashCommandItem } from '#uilib/tiptap/slash-mention/types';
|
|
44
48
|
export { CsvIcon } from '../../icons/CsvIcon/CsvIcon';
|
|
@@ -120,13 +120,8 @@ export default function ChatAttachmentsDropzonePage() {
|
|
|
120
120
|
isLoading={isLoading}
|
|
121
121
|
scriptContinueLabel={undefined}
|
|
122
122
|
onScriptContinue={undefined}
|
|
123
|
-
showBranchActionsRow={false}
|
|
124
123
|
showSyntheticBranchButtons={false}
|
|
125
124
|
unusedBranchKeys={[]}
|
|
126
|
-
isScriptComplete={false}
|
|
127
|
-
onGenerateDashboard={undefined}
|
|
128
|
-
generatingDashboard={false}
|
|
129
|
-
onGenerateDashboardClick={() => {}}
|
|
130
125
|
showInlinePresets={false}
|
|
131
126
|
isLastMessageFromUser={isLastMessageFromUser}
|
|
132
127
|
scrollRef={scrollRef}
|
|
@@ -84,13 +84,8 @@ export default function ChatPage() {
|
|
|
84
84
|
isLoading={isLoading}
|
|
85
85
|
scriptContinueLabel={undefined}
|
|
86
86
|
onScriptContinue={undefined}
|
|
87
|
-
showBranchActionsRow={false}
|
|
88
87
|
showSyntheticBranchButtons={false}
|
|
89
88
|
unusedBranchKeys={[]}
|
|
90
|
-
isScriptComplete={false}
|
|
91
|
-
onGenerateDashboard={undefined}
|
|
92
|
-
generatingDashboard={false}
|
|
93
|
-
onGenerateDashboardClick={() => {}}
|
|
94
89
|
showInlinePresets={false}
|
|
95
90
|
isLastMessageFromUser={isLastMessageFromUser}
|
|
96
91
|
scrollRef={scrollRef}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type SlashCommandItem,
|
|
9
9
|
} from '#uilib/components/ui/Chat';
|
|
10
10
|
import { PageContentSection } from '#uilib/components/ui/Page';
|
|
11
|
+
import type { SlashItemCommandContext } from '#uilib/tiptap/slash-mention/types';
|
|
11
12
|
import { ScrollRef } from '@homecode/ui';
|
|
12
13
|
|
|
13
14
|
import { AppPageHeader } from '../components/AppPageHeader/AppPageHeader';
|
|
@@ -15,18 +16,23 @@ import { DocsHeaderActions } from '../docsHeaderActions';
|
|
|
15
16
|
|
|
16
17
|
const NO_QUICK_REPLY_KEYS: ReadonlySet<string> = new Set();
|
|
17
18
|
|
|
19
|
+
const DOCS_SAMPLE_COMMAND_ID = 'sample-command';
|
|
20
|
+
|
|
18
21
|
/** Sample items so the docs demo still shows a `/` palette (`DEFAULT_CHAT_SLASH_ITEMS` is empty). */
|
|
19
22
|
const DOCS_SAMPLE_SLASH_ITEMS: SlashCommandItem[] = [
|
|
20
23
|
{
|
|
21
|
-
id:
|
|
22
|
-
label:
|
|
24
|
+
id: DOCS_SAMPLE_COMMAND_ID,
|
|
25
|
+
label: DOCS_SAMPLE_COMMAND_ID,
|
|
23
26
|
description:
|
|
24
|
-
'Demo
|
|
27
|
+
'Demo handler — clears composer and runs `onSlashItemCommand` (no mention insert).',
|
|
25
28
|
},
|
|
26
29
|
];
|
|
27
30
|
|
|
31
|
+
const SAMPLE_COMMAND_REPLY_TEXT =
|
|
32
|
+
'Sample command ran via `onSlashItemCommand` — composer cleared, no mention inserted.';
|
|
33
|
+
|
|
28
34
|
const ASSISTANT_REPLY_TEXT =
|
|
29
|
-
'Demo reply
|
|
35
|
+
'Demo reply for a normal message. Slash picks with a custom handler skip mention insert.';
|
|
30
36
|
|
|
31
37
|
function makeMessage(role: MessageRole, text: string): Message {
|
|
32
38
|
return {
|
|
@@ -56,11 +62,34 @@ export default function ChatSlashCommandsPage() {
|
|
|
56
62
|
messages.length > 0 &&
|
|
57
63
|
messages[messages.length - 1]?.role === MessageRole.USER;
|
|
58
64
|
|
|
65
|
+
const runSampleCommand = useCallback(() => {
|
|
66
|
+
setMessages(prev => [
|
|
67
|
+
...prev,
|
|
68
|
+
makeMessage(MessageRole.ASSISTANT, SAMPLE_COMMAND_REPLY_TEXT),
|
|
69
|
+
]);
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
const onSlashItemCommand = useCallback(
|
|
73
|
+
({ item }: SlashItemCommandContext) => {
|
|
74
|
+
if (item.id !== DOCS_SAMPLE_COMMAND_ID) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
queueMicrotask(() => runSampleCommand());
|
|
78
|
+
return true;
|
|
79
|
+
},
|
|
80
|
+
[runSampleCommand],
|
|
81
|
+
);
|
|
82
|
+
|
|
59
83
|
const onSubmit = useCallback(
|
|
60
84
|
(raw: string) => {
|
|
61
85
|
const text = raw.trim();
|
|
62
86
|
if (!text || isLoading) return;
|
|
63
87
|
|
|
88
|
+
if (text === `/${DOCS_SAMPLE_COMMAND_ID}`) {
|
|
89
|
+
runSampleCommand();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
64
93
|
setMessages(prev => [...prev, makeMessage(MessageRole.USER, text)]);
|
|
65
94
|
setIsLoading(true);
|
|
66
95
|
|
|
@@ -76,7 +105,7 @@ export default function ChatSlashCommandsPage() {
|
|
|
76
105
|
setIsLoading(false);
|
|
77
106
|
}, 900);
|
|
78
107
|
},
|
|
79
|
-
[isLoading],
|
|
108
|
+
[isLoading, runSampleCommand],
|
|
80
109
|
);
|
|
81
110
|
|
|
82
111
|
return (
|
|
@@ -84,7 +113,7 @@ export default function ChatSlashCommandsPage() {
|
|
|
84
113
|
<AppPageHeader
|
|
85
114
|
breadcrumbs={[{ label: 'Chat' }, { label: 'Chat slash commands' }]}
|
|
86
115
|
title="Chat slash commands"
|
|
87
|
-
subheader={`Slash palette uses TipTap Mention with "/" as the trigger.
|
|
116
|
+
subheader={`Slash palette uses TipTap Mention with "/" as the trigger. Pass slashCommandItems from the app; optional onSlashItemCommand can clear the composer and run an action instead of inserting a mention.`}
|
|
88
117
|
actions={
|
|
89
118
|
<DocsHeaderActions slashCommandItems={DOCS_SAMPLE_SLASH_ITEMS} />
|
|
90
119
|
}
|
|
@@ -97,7 +126,9 @@ export default function ChatSlashCommandsPage() {
|
|
|
97
126
|
</Link>{' '}
|
|
98
127
|
shell below: scrolling history, empty state, disclaimer, composer.
|
|
99
128
|
Type <kbd className="font-mono">/</kbd> at line start or after a
|
|
100
|
-
space; pick
|
|
129
|
+
space; pick <kbd className="font-mono">sample-command</kbd> to run the
|
|
130
|
+
custom handler, or send{' '}
|
|
131
|
+
<kbd className="font-mono">/sample-command</kbd> with Enter.
|
|
101
132
|
</p>
|
|
102
133
|
<ChatChrome
|
|
103
134
|
showResizeHandle={false}
|
|
@@ -111,13 +142,8 @@ export default function ChatSlashCommandsPage() {
|
|
|
111
142
|
isLoading={isLoading}
|
|
112
143
|
scriptContinueLabel={undefined}
|
|
113
144
|
onScriptContinue={undefined}
|
|
114
|
-
showBranchActionsRow={false}
|
|
115
145
|
showSyntheticBranchButtons={false}
|
|
116
146
|
unusedBranchKeys={[]}
|
|
117
|
-
isScriptComplete={false}
|
|
118
|
-
onGenerateDashboard={undefined}
|
|
119
|
-
generatingDashboard={false}
|
|
120
|
-
onGenerateDashboardClick={() => {}}
|
|
121
147
|
showInlinePresets={false}
|
|
122
148
|
isLastMessageFromUser={isLastMessageFromUser}
|
|
123
149
|
scrollRef={scrollRef}
|
|
@@ -125,11 +151,12 @@ export default function ChatSlashCommandsPage() {
|
|
|
125
151
|
onPromptSubmit={onSubmit}
|
|
126
152
|
onChatDeleted={() => {}}
|
|
127
153
|
slashCommandItems={DOCS_SAMPLE_SLASH_ITEMS}
|
|
154
|
+
onSlashItemCommand={onSlashItemCommand}
|
|
128
155
|
promptPlaceholder='Ask something or type "/" for demo commands…'
|
|
129
156
|
emptyState={{
|
|
130
157
|
title: 'Try a slash command',
|
|
131
158
|
description:
|
|
132
|
-
'
|
|
159
|
+
'Pick sample-command from the palette or send /sample-command — onSlashItemCommand clears the composer and runs the demo action.',
|
|
133
160
|
additionalContent: (
|
|
134
161
|
<p>Optional empty-state slot via additionalContent.</p>
|
|
135
162
|
),
|
|
@@ -148,13 +148,8 @@ export default function ChatUserCsvAttachmentPage() {
|
|
|
148
148
|
isLoading={isLoading}
|
|
149
149
|
scriptContinueLabel={undefined}
|
|
150
150
|
onScriptContinue={undefined}
|
|
151
|
-
showBranchActionsRow={false}
|
|
152
151
|
showSyntheticBranchButtons={false}
|
|
153
152
|
unusedBranchKeys={[]}
|
|
154
|
-
isScriptComplete={false}
|
|
155
|
-
onGenerateDashboard={undefined}
|
|
156
|
-
generatingDashboard={false}
|
|
157
|
-
onGenerateDashboardClick={() => {}}
|
|
158
153
|
showInlinePresets={false}
|
|
159
154
|
isLastMessageFromUser={isLastMessageFromUser}
|
|
160
155
|
scrollRef={scrollRef}
|
|
@@ -124,6 +124,28 @@ export function slashMentionSuggestionRender(
|
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
function clearSlashTriggerEditor(
|
|
128
|
+
editor: Editor,
|
|
129
|
+
range: { from: number; to: number },
|
|
130
|
+
): void {
|
|
131
|
+
if (editor.isDestroyed) return;
|
|
132
|
+
try {
|
|
133
|
+
editor.chain().focus().deleteRange(range).clearContent().run();
|
|
134
|
+
} catch {
|
|
135
|
+
// Editor view may be tearing down during suggestion exit.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function collapseEditorSelectionEnd(editor: Editor): void {
|
|
140
|
+
if (editor.isDestroyed) return;
|
|
141
|
+
try {
|
|
142
|
+
editor.view?.dom?.ownerDocument?.defaultView
|
|
143
|
+
?.getSelection?.()
|
|
144
|
+
?.collapseToEnd();
|
|
145
|
+
} catch {
|
|
146
|
+
// view.dom throws when editor is not mounted
|
|
147
|
+
}
|
|
148
|
+
}
|
|
127
149
|
function insertDefaultMention(
|
|
128
150
|
editor: Editor,
|
|
129
151
|
range: { from: number; to: number },
|
|
@@ -223,11 +245,8 @@ export function createSlashMentionExtension({
|
|
|
223
245
|
command: ({ editor, range, props }) => {
|
|
224
246
|
const item = props as SlashCommandItem;
|
|
225
247
|
if (onItemCommand?.({ editor, range, item }) === true) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
?.getSelection?.()
|
|
229
|
-
?.collapseToEnd();
|
|
230
|
-
});
|
|
248
|
+
clearSlashTriggerEditor(editor, range);
|
|
249
|
+
queueMicrotask(() => collapseEditorSelectionEnd(editor));
|
|
231
250
|
return null;
|
|
232
251
|
}
|
|
233
252
|
insertDefaultMention(editor, range, item, slashChar);
|
|
@@ -13,7 +13,8 @@ export type SlashItemCommandContext = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* If provided, run
|
|
16
|
+
* If provided, run when a slash item is picked. Return true to skip mention insert
|
|
17
|
+
* (extension clears the trigger text from the composer).
|
|
17
18
|
*/
|
|
18
19
|
export type SlashOnItemCommand = (ctx: SlashItemCommandContext) => boolean;
|
|
19
20
|
|