@harnessio/ui3-ai-chat 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-constants.d.ts +14 -0
- package/dist/chat-constants.d.ts.map +1 -0
- package/dist/chat-constants.js +13 -0
- package/dist/chat-drawer-layout.d.ts +10 -0
- package/dist/chat-drawer-layout.d.ts.map +1 -0
- package/dist/chat-drawer-layout.js +66 -0
- package/dist/chat-header.d.ts +13 -0
- package/dist/chat-header.d.ts.map +1 -0
- package/dist/chat-header.js +45 -0
- package/dist/chat-history.d.ts +6 -0
- package/dist/chat-history.d.ts.map +1 -0
- package/dist/chat-history.js +119 -0
- package/dist/chat-homepage-body.d.ts +5 -0
- package/dist/chat-homepage-body.d.ts.map +1 -0
- package/dist/chat-homepage-body.js +17 -0
- package/dist/chat-input-plus-menu.d.ts +2 -0
- package/dist/chat-input-plus-menu.d.ts.map +1 -0
- package/dist/chat-input-plus-menu.js +15 -0
- package/dist/chat-input.d.ts +2 -0
- package/dist/chat-input.d.ts.map +1 -0
- package/dist/chat-input.js +65 -0
- package/dist/chat-layout.d.ts +14 -0
- package/dist/chat-layout.d.ts.map +1 -0
- package/dist/chat-layout.js +16 -0
- package/dist/chat-message-list.d.ts +13 -0
- package/dist/chat-message-list.d.ts.map +1 -0
- package/dist/chat-message-list.js +13 -0
- package/dist/chat-panel-body.d.ts +5 -0
- package/dist/chat-panel-body.d.ts.map +1 -0
- package/dist/chat-panel-body.js +17 -0
- package/dist/chat-scroll-fade.d.ts +9 -0
- package/dist/chat-scroll-fade.d.ts.map +1 -0
- package/dist/chat-scroll-fade.js +22 -0
- package/dist/chat-speech-button.d.ts +7 -0
- package/dist/chat-speech-button.d.ts.map +1 -0
- package/dist/chat-speech-button.js +12 -0
- package/dist/chat.d.ts +5 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +18 -0
- package/dist/context/chat-event-context.d.ts +10 -0
- package/dist/context/chat-event-context.d.ts.map +1 -0
- package/dist/context/chat-event-context.js +9 -0
- package/dist/context/chat-host-context.d.ts +22 -0
- package/dist/context/chat-host-context.d.ts.map +1 -0
- package/dist/context/chat-host-context.js +27 -0
- package/dist/context/chat-position-context.d.ts +14 -0
- package/dist/context/chat-position-context.d.ts.map +1 -0
- package/dist/context/chat-position-context.js +17 -0
- package/dist/default-chat-welcome.d.ts +7 -0
- package/dist/default-chat-welcome.d.ts.map +1 -0
- package/dist/default-chat-welcome.js +35 -0
- package/dist/error-boundaries/chat-error-boundary.d.ts +15 -0
- package/dist/error-boundaries/chat-error-boundary.d.ts.map +1 -0
- package/dist/error-boundaries/chat-error-boundary.js +18 -0
- package/dist/error-boundaries/index.d.ts +3 -0
- package/dist/error-boundaries/index.d.ts.map +1 -0
- package/dist/error-boundaries/index.js +2 -0
- package/dist/error-boundaries/message-error-boundary.d.ts +15 -0
- package/dist/error-boundaries/message-error-boundary.d.ts.map +1 -0
- package/dist/error-boundaries/message-error-boundary.js +18 -0
- package/dist/harness-loader/harness-loader-blades.d.ts +21 -0
- package/dist/harness-loader/harness-loader-blades.d.ts.map +1 -0
- package/dist/harness-loader/harness-loader-blades.js +25 -0
- package/dist/harness-loader/harness-loader.css +335 -0
- package/dist/harness-loader/harness-loader.d.ts +8 -0
- package/dist/harness-loader/harness-loader.d.ts.map +1 -0
- package/dist/harness-loader/harness-loader.js +9 -0
- package/dist/hooks/use-chat-content-state.d.ts +23 -0
- package/dist/hooks/use-chat-content-state.d.ts.map +1 -0
- package/dist/hooks/use-chat-content-state.js +97 -0
- package/dist/hooks/use-chat-mcp-connectors.d.ts +4 -0
- package/dist/hooks/use-chat-mcp-connectors.d.ts.map +1 -0
- package/dist/hooks/use-chat-mcp-connectors.js +5 -0
- package/dist/hooks/use-chat-tracking.d.ts +19 -0
- package/dist/hooks/use-chat-tracking.d.ts.map +1 -0
- package/dist/hooks/use-chat-tracking.js +84 -0
- package/dist/hooks/use-idle-session-prompt.d.ts +13 -0
- package/dist/hooks/use-idle-session-prompt.d.ts.map +1 -0
- package/dist/hooks/use-idle-session-prompt.js +147 -0
- package/dist/hooks/use-speech-to-text.d.ts +49 -0
- package/dist/hooks/use-speech-to-text.d.ts.map +1 -0
- package/dist/hooks/use-speech-to-text.js +117 -0
- package/dist/idle-session-banner.d.ts +6 -0
- package/dist/idle-session-banner.d.ts.map +1 -0
- package/dist/idle-session-banner.js +13 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/plugins/core-plugin.d.ts +3 -0
- package/dist/plugins/core-plugin.d.ts.map +1 -0
- package/dist/plugins/core-plugin.js +47 -0
- package/dist/providers/chat-runtime-provider.d.ts +10 -0
- package/dist/providers/chat-runtime-provider.d.ts.map +1 -0
- package/dist/providers/chat-runtime-provider.js +15 -0
- package/dist/renderers/elicitation/confirm-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/confirm-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/confirm-renderer.js +16 -0
- package/dist/renderers/elicitation/free-text-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/free-text-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/free-text-renderer.js +25 -0
- package/dist/renderers/elicitation/index.d.ts +5 -0
- package/dist/renderers/elicitation/index.d.ts.map +1 -0
- package/dist/renderers/elicitation/index.js +4 -0
- package/dist/renderers/elicitation/multi-select-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/multi-select-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/multi-select-renderer.js +47 -0
- package/dist/renderers/elicitation/select-renderer.d.ts +4 -0
- package/dist/renderers/elicitation/select-renderer.d.ts.map +1 -0
- package/dist/renderers/elicitation/select-renderer.js +32 -0
- package/dist/renderers/elicitation/shared.d.ts +146 -0
- package/dist/renderers/elicitation/shared.d.ts.map +1 -0
- package/dist/renderers/elicitation/shared.js +237 -0
- package/dist/renderers/error-renderer.d.ts +3 -0
- package/dist/renderers/error-renderer.d.ts.map +1 -0
- package/dist/renderers/error-renderer.js +11 -0
- package/dist/renderers/file-renderer.d.ts +12 -0
- package/dist/renderers/file-renderer.d.ts.map +1 -0
- package/dist/renderers/file-renderer.js +35 -0
- package/dist/renderers/follow-up-prompts-renderer.d.ts +3 -0
- package/dist/renderers/follow-up-prompts-renderer.d.ts.map +1 -0
- package/dist/renderers/follow-up-prompts-renderer.js +55 -0
- package/dist/renderers/prompts-renderer.d.ts +14 -0
- package/dist/renderers/prompts-renderer.d.ts.map +1 -0
- package/dist/renderers/prompts-renderer.js +5 -0
- package/dist/renderers/suggestions-renderer.d.ts +3 -0
- package/dist/renderers/suggestions-renderer.d.ts.map +1 -0
- package/dist/renderers/suggestions-renderer.js +24 -0
- package/dist/renderers/table-renderer.d.ts +22 -0
- package/dist/renderers/table-renderer.d.ts.map +1 -0
- package/dist/renderers/table-renderer.js +49 -0
- package/dist/renderers/text-renderer.d.ts +10 -0
- package/dist/renderers/text-renderer.d.ts.map +1 -0
- package/dist/renderers/text-renderer.js +10 -0
- package/dist/renderers/thought-process.d.ts +10 -0
- package/dist/renderers/thought-process.d.ts.map +1 -0
- package/dist/renderers/thought-process.js +8 -0
- package/dist/renderers/tool-call-renderer.d.ts +12 -0
- package/dist/renderers/tool-call-renderer.d.ts.map +1 -0
- package/dist/renderers/tool-call-renderer.js +37 -0
- package/dist/stores/chat-input-options-store.d.ts +9 -0
- package/dist/stores/chat-input-options-store.d.ts.map +1 -0
- package/dist/stores/chat-input-options-store.js +6 -0
- package/dist/stores/chat-settings-store.d.ts +11 -0
- package/dist/stores/chat-settings-store.d.ts.map +1 -0
- package/dist/stores/chat-settings-store.js +8 -0
- package/dist/stores/idle-session-prompt-store.d.ts +21 -0
- package/dist/stores/idle-session-prompt-store.d.ts.map +1 -0
- package/dist/stores/idle-session-prompt-store.js +34 -0
- package/dist/styles.css +129 -0
- package/dist/thread-actions-menu.d.ts +11 -0
- package/dist/thread-actions-menu.d.ts.map +1 -0
- package/dist/thread-actions-menu.js +55 -0
- package/dist/truncated-chip-label.d.ts +12 -0
- package/dist/truncated-chip-label.d.ts.map +1 -0
- package/dist/truncated-chip-label.js +11 -0
- package/dist/types/chat-events.d.ts +18 -0
- package/dist/types/chat-events.d.ts.map +1 -0
- package/dist/types/chat-events.js +1 -0
- package/dist/types/chat-layout.d.ts +9 -0
- package/dist/types/chat-layout.d.ts.map +1 -0
- package/dist/types/chat-layout.js +8 -0
- package/dist/utils/sentence-case.d.ts +2 -0
- package/dist/utils/sentence-case.d.ts.map +1 -0
- package/dist/utils/sentence-case.js +14 -0
- package/dist/utils/time-utils.d.ts +7 -0
- package/dist/utils/time-utils.d.ts.map +1 -0
- package/dist/utils/time-utils.js +27 -0
- package/package.json +49 -3
- package/README.md +0 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum number of characters allowed in a single chat message input.
|
|
3
|
+
* This limit (~32k tokens) aligns with industry standards and prevents
|
|
4
|
+
* extremely large inputs that could cause performance issues.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MAX_CHAT_INPUT_CHARACTERS = 128000;
|
|
7
|
+
/**
|
|
8
|
+
* After more than this much idle time on an active conversation, intercepting
|
|
9
|
+
* the next send shows a soft card suggesting a new chat (30 minutes).
|
|
10
|
+
* Starting a new session only happens when the user clicks the card CTA —
|
|
11
|
+
* which then sends the same message in the new session.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CHAT_IDLE_NEW_SESSION_MS: number;
|
|
14
|
+
//# sourceMappingURL=chat-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-constants.d.ts","sourceRoot":"","sources":["../src/chat-constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,SAAS,CAAA;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,QAAiB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum number of characters allowed in a single chat message input.
|
|
3
|
+
* This limit (~32k tokens) aligns with industry standards and prevents
|
|
4
|
+
* extremely large inputs that could cause performance issues.
|
|
5
|
+
*/
|
|
6
|
+
export const MAX_CHAT_INPUT_CHARACTERS = 128000;
|
|
7
|
+
/**
|
|
8
|
+
* After more than this much idle time on an active conversation, intercepting
|
|
9
|
+
* the next send shows a soft card suggesting a new chat (30 minutes).
|
|
10
|
+
* Starting a new session only happens when the user clicks the card CTA —
|
|
11
|
+
* which then sends the same message in the new session.
|
|
12
|
+
*/
|
|
13
|
+
export const CHAT_IDLE_NEW_SESSION_MS = 30 * 60 * 1000;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
export interface ChatDrawerLayoutProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
open?: boolean;
|
|
5
|
+
onOpenChange?: (open: boolean) => void;
|
|
6
|
+
onClose?: () => void;
|
|
7
|
+
onDetailPanelChange?: (visible: boolean) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const ChatDrawerLayout: FC<ChatDrawerLayoutProps>;
|
|
10
|
+
//# sourceMappingURL=chat-drawer-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-drawer-layout.d.ts","sourceRoot":"","sources":["../src/chat-drawer-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAA4C,MAAM,OAAO,CAAA;AAO/E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,SAAS,CAAA;IACnB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,mBAAmB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CACjD;AAMD,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CAsHtD,CAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { AuxiliaryRenderer, useContentFocus } from '@harnessio/ai-chat-core';
|
|
4
|
+
import { Drawer, Layout } from '@harnessio/ui/components';
|
|
5
|
+
import { useChatTracking } from './hooks/use-chat-tracking';
|
|
6
|
+
const DEFAULT_WIDTH = 500;
|
|
7
|
+
const MIN_WIDTH = 400;
|
|
8
|
+
const MAX_WIDTH = 1200;
|
|
9
|
+
export const ChatDrawerLayout = ({ children, open, onOpenChange, onClose, onDetailPanelChange }) => {
|
|
10
|
+
const contentFocus = useContentFocus();
|
|
11
|
+
const showDetailPanel = contentFocus.isActive && contentFocus.focusedContent && contentFocus.focusedMessage;
|
|
12
|
+
const [drawerWidth, setDrawerWidth] = useState(DEFAULT_WIDTH);
|
|
13
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
14
|
+
const drawerRef = useRef(null);
|
|
15
|
+
const { trackPanelOpened, trackPanelClosed } = useChatTracking();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
onDetailPanelChange?.(!!showDetailPanel);
|
|
18
|
+
}, [showDetailPanel, onDetailPanelChange]);
|
|
19
|
+
const handleOpenChange = (isOpen) => {
|
|
20
|
+
onOpenChange?.(isOpen);
|
|
21
|
+
if (!isOpen) {
|
|
22
|
+
onClose?.();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (open) {
|
|
27
|
+
trackPanelOpened({ variant: 'drawer' });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
trackPanelClosed({ variant: 'drawer' });
|
|
31
|
+
}
|
|
32
|
+
}, [open]);
|
|
33
|
+
const handleMouseDown = useCallback((e) => {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
setIsResizing(true);
|
|
36
|
+
}, []);
|
|
37
|
+
const handleMouseMove = useCallback((e) => {
|
|
38
|
+
if (!isResizing)
|
|
39
|
+
return;
|
|
40
|
+
const newWidth = window.innerWidth - e.clientX;
|
|
41
|
+
if (newWidth >= MIN_WIDTH && newWidth <= MAX_WIDTH) {
|
|
42
|
+
setDrawerWidth(newWidth);
|
|
43
|
+
}
|
|
44
|
+
}, [isResizing]);
|
|
45
|
+
const handleMouseUp = useCallback(() => {
|
|
46
|
+
setIsResizing(false);
|
|
47
|
+
}, []);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (isResizing) {
|
|
50
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
51
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
52
|
+
document.body.style.cursor = 'ew-resize';
|
|
53
|
+
document.body.style.userSelect = 'none';
|
|
54
|
+
return () => {
|
|
55
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
56
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
57
|
+
document.body.style.cursor = '';
|
|
58
|
+
document.body.style.userSelect = '';
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}, [isResizing, handleMouseMove, handleMouseUp]);
|
|
62
|
+
const totalWidth = showDetailPanel ? drawerWidth + 500 : drawerWidth;
|
|
63
|
+
return (_jsx(Drawer.Root, { open: open, onOpenChange: handleOpenChange, direction: "right", children: _jsx(Drawer.Content, { style: { width: totalWidth, maxWidth: '90vw' }, children: _jsx(Drawer.Body, { className: "flex h-full flex-col p-0", classNameContent: "p-0 h-full", scrollable: false, children: _jsxs("div", { className: "relative flex h-full", children: [!showDetailPanel && (_jsx("div", { role: "button", tabIndex: 0, "aria-label": "Resize chat drawer", className: "hover:bg-blue-500 group absolute left-0 top-0 z-50 h-full w-1 cursor-ew-resize", onMouseDown: handleMouseDown, style: {
|
|
64
|
+
backgroundColor: isResizing ? '#3b82f6' : 'transparent'
|
|
65
|
+
}, children: _jsx("div", { className: "bg-gray-400 group-hover:bg-blue-500 absolute left-0 top-1/2 h-12 w-1 -translate-y-1/2 rounded-r transition-colors" }) })), _jsxs(Layout.Horizontal, { className: "h-full flex-1 overflow-scroll", gap: "none", children: [_jsx(Layout.Vertical, { className: "min-w-0 flex-1", ref: drawerRef, children: children }), showDetailPanel && (_jsx(Layout.Vertical, { className: "h-full shrink-0 overflow-auto border-l border-cn-3 p-cn-sm", style: { width: 500, maxWidth: 700 }, children: _jsx(AuxiliaryRenderer, { message: contentFocus.focusedMessage, content: contentFocus.focusedContent, context: "detail", onClose: () => contentFocus.blur() }, `${contentFocus.focusedMessageId}-${contentFocus.focusedContentIndex}`) }))] })] }) }) }) }));
|
|
66
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChatLayoutPosition } from './types/chat-layout';
|
|
2
|
+
interface ChatHeaderProps {
|
|
3
|
+
showHistory: boolean;
|
|
4
|
+
hideTitle?: boolean;
|
|
5
|
+
onToggleHistory: () => void;
|
|
6
|
+
onOpenSettings?: () => void;
|
|
7
|
+
onStartNewThread: () => void;
|
|
8
|
+
position?: ChatLayoutPosition;
|
|
9
|
+
onPositionChange?: (position: ChatLayoutPosition) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const ChatHeader: ({ showHistory, hideTitle, onToggleHistory, onOpenSettings, onStartNewThread, position, onPositionChange }: ChatHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=chat-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-header.d.ts","sourceRoot":"","sources":["../src/chat-header.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAGxD,UAAU,eAAe;IACvB,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,eAAe,EAAE,MAAM,IAAI,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B,gBAAgB,EAAE,MAAM,IAAI,CAAA;IAC5B,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IAC7B,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAA;CAC1D;AAED,eAAO,MAAM,UAAU,8GAQpB,eAAe,4CAmKjB,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useCurrentThread, useMessages, useThreadListState } from '@harnessio/ai-chat-core';
|
|
4
|
+
import { Alert, Button, DropdownMenu, IconV2, Layout, Text } from '@harnessio/ui/components';
|
|
5
|
+
import { toSentenceCase } from './utils/sentence-case';
|
|
6
|
+
export const ChatHeader = ({ showHistory, hideTitle, onToggleHistory, onOpenSettings, onStartNewThread, position, onPositionChange }) => {
|
|
7
|
+
const thread = useCurrentThread();
|
|
8
|
+
useMessages();
|
|
9
|
+
const { mainThreadId, threadItems } = useThreadListState();
|
|
10
|
+
const [copyError, setCopyError] = useState(null);
|
|
11
|
+
const title = thread?.title ?? threadItems[mainThreadId]?.title;
|
|
12
|
+
const getPositionIcon = () => {
|
|
13
|
+
switch (position) {
|
|
14
|
+
case 'right':
|
|
15
|
+
return 'chat-position-right';
|
|
16
|
+
case 'fullscreen':
|
|
17
|
+
return 'chat-position-full';
|
|
18
|
+
default:
|
|
19
|
+
return 'chat-position-left';
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const handleCopyConversationId = async () => {
|
|
23
|
+
if (!thread?.conversationId) {
|
|
24
|
+
setCopyError('No conversation ID available');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
await navigator.clipboard.writeText(thread.conversationId);
|
|
29
|
+
setCopyError(null);
|
|
30
|
+
}
|
|
31
|
+
catch (_error) {
|
|
32
|
+
setCopyError('Failed to copy conversation ID');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const renderTitle = () => {
|
|
36
|
+
if (showHistory) {
|
|
37
|
+
return (_jsxs(Layout.Horizontal, { align: "center", gap: "xs", children: [_jsx(Button, { iconOnly: true, variant: "transparent", size: "sm", "aria-label": "Back", tooltipProps: { content: 'Back', side: 'bottom' }, onClick: onToggleHistory, children: _jsx(IconV2, { name: "arrow-left" }) }), _jsx(Text, { variant: "heading-small", children: "History" })] }));
|
|
38
|
+
}
|
|
39
|
+
if (title && !hideTitle) {
|
|
40
|
+
return (_jsx(Text, { variant: "heading-small", truncate: true, children: toSentenceCase(title) }));
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
return (_jsxs(Layout.Vertical, { gap: "xs", children: [copyError && (_jsx(Alert.Root, { theme: "danger", dismissible: true, onDismiss: () => setCopyError(null), children: _jsx(Alert.Description, { children: copyError }) })), _jsxs(Layout.Horizontal, { align: "center", justify: "between", gap: "md", children: [renderTitle(), _jsxs(Layout.Horizontal, { align: "center", gap: "4xs", className: "ml-auto", children: [_jsx(Button, { iconOnly: true, variant: "ghost", size: "sm", "aria-label": "New thread", tooltipProps: { content: 'New thread', side: 'bottom' }, onClick: onStartNewThread, children: _jsx(IconV2, { name: "new-thread" }) }), position && (_jsxs(DropdownMenu.Root, { children: [_jsx(DropdownMenu.Trigger, { asChild: true, children: _jsx(Button, { iconOnly: true, variant: "ghost", size: "sm", "aria-label": "Chat position", tooltipProps: { content: 'Chat position', side: 'bottom' }, children: _jsx(IconV2, { name: getPositionIcon() }) }) }), _jsxs(DropdownMenu.Content, { align: "end", children: [_jsx(DropdownMenu.IconItem, { className: "cursor-pointer", icon: "chat-position-left", title: "Position on left", checkmark: position === 'left', onClick: () => onPositionChange?.('left') }), _jsx(DropdownMenu.IconItem, { className: "cursor-pointer", icon: "chat-position-right", title: "Position on right", checkmark: position === 'right', onClick: () => onPositionChange?.('right') })] })] })), _jsxs(DropdownMenu.Root, { children: [_jsx(DropdownMenu.Trigger, { asChild: true, children: _jsx(Button, { iconOnly: true, variant: "ghost", size: "sm", "aria-label": "More", tooltipProps: { content: 'More', side: 'bottom' }, children: _jsx(IconV2, { name: "more-horizontal" }) }) }), _jsxs(DropdownMenu.Content, { align: "end", children: [_jsx(DropdownMenu.IconItem, { className: "cursor-pointer", icon: "clock", title: "History", onClick: onToggleHistory }), thread?.conversationId && (_jsx(DropdownMenu.IconItem, { className: "cursor-pointer", icon: "copy", title: "Copy Conversation ID", onClick: handleCopyConversationId })), onOpenSettings ? (_jsx(DropdownMenu.IconItem, { className: "cursor-pointer", icon: "settings", title: "Settings", onClick: onOpenSettings })) : null] })] })] })] })] }));
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-history.d.ts","sourceRoot":"","sources":["../src/chat-history.tsx"],"names":[],"mappings":"AAqBA,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,IAAI,CAAA;CAC3B;AAID,eAAO,MAAM,WAAW,uBAAwB,gBAAgB,4CA0N/D,CAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { useThreadList, useThreadListState } from '@harnessio/ai-chat-core';
|
|
4
|
+
import { Alert, IconV2, Layout, SearchInput, Skeleton, StackedList, Text, TextInput, TimeAgoCard } from '@harnessio/ui/components';
|
|
5
|
+
import { useInfiniteScroll } from '@harnessio/ui/hooks';
|
|
6
|
+
import { useChatTracking } from './hooks/use-chat-tracking';
|
|
7
|
+
import { useIdleSessionPromptStore } from './stores/idle-session-prompt-store';
|
|
8
|
+
import { ThreadActionsMenu } from './thread-actions-menu';
|
|
9
|
+
import { toSentenceCase } from './utils/sentence-case';
|
|
10
|
+
const PAGE_SIZE = 50;
|
|
11
|
+
export const ChatHistory = ({ onSelectThread }) => {
|
|
12
|
+
const threadList = useThreadList();
|
|
13
|
+
const threadListState = useThreadListState();
|
|
14
|
+
const { trackIdlePromptHeld } = useChatTracking();
|
|
15
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
16
|
+
const [offset, setOffset] = useState(0);
|
|
17
|
+
const [hasMore, setHasMore] = useState(true);
|
|
18
|
+
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
19
|
+
const [renamingThreadId, setRenamingThreadId] = useState(null);
|
|
20
|
+
const [renameValue, setRenameValue] = useState('');
|
|
21
|
+
const [isRenamingInProgress, setIsRenamingInProgress] = useState(false);
|
|
22
|
+
const [copyError, setCopyError] = useState(null);
|
|
23
|
+
const loadMore = useCallback(async () => {
|
|
24
|
+
if (isLoadingMore || !hasMore || threadListState.isLoading)
|
|
25
|
+
return;
|
|
26
|
+
setIsLoadingMore(true);
|
|
27
|
+
try {
|
|
28
|
+
const newThreads = await threadList.loadThreads({
|
|
29
|
+
query: searchTerm || undefined,
|
|
30
|
+
offset,
|
|
31
|
+
limit: PAGE_SIZE,
|
|
32
|
+
replace: false // Append to existing list
|
|
33
|
+
});
|
|
34
|
+
setHasMore(newThreads.length >= PAGE_SIZE);
|
|
35
|
+
setOffset(prev => prev + newThreads.length);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
setIsLoadingMore(false);
|
|
39
|
+
}
|
|
40
|
+
}, [offset, hasMore, isLoadingMore, searchTerm, threadList, threadListState.isLoading]);
|
|
41
|
+
// Initial load
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const loadInitial = async () => {
|
|
44
|
+
const threads = await threadList.loadThreads({ offset: 0, limit: PAGE_SIZE, replace: true });
|
|
45
|
+
setHasMore(threads.length >= PAGE_SIZE);
|
|
46
|
+
setOffset(threads.length);
|
|
47
|
+
};
|
|
48
|
+
loadInitial();
|
|
49
|
+
}, []);
|
|
50
|
+
// Search handler
|
|
51
|
+
const handleSearch = useCallback(async (value) => {
|
|
52
|
+
setSearchTerm(value);
|
|
53
|
+
setOffset(0);
|
|
54
|
+
setHasMore(true);
|
|
55
|
+
const threads = await threadList.loadThreads({ query: value, offset: 0, limit: PAGE_SIZE, replace: true });
|
|
56
|
+
setHasMore(threads.length >= PAGE_SIZE);
|
|
57
|
+
setOffset(threads.length);
|
|
58
|
+
}, [threadList]);
|
|
59
|
+
const handleThreadClick = (threadId, conversationId) => {
|
|
60
|
+
const store = useIdleSessionPromptStore.getState();
|
|
61
|
+
store.markConversationAccessed(conversationId);
|
|
62
|
+
const held = store.dismissAndRestore();
|
|
63
|
+
if (held) {
|
|
64
|
+
trackIdlePromptHeld({
|
|
65
|
+
conversationId,
|
|
66
|
+
nextConversationId: conversationId,
|
|
67
|
+
promptLength: held.length
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
threadList.switchToThread(threadId);
|
|
71
|
+
onSelectThread();
|
|
72
|
+
};
|
|
73
|
+
const handleRename = useCallback(async (threadId, newTitle) => {
|
|
74
|
+
if (!newTitle.trim() || isRenamingInProgress)
|
|
75
|
+
return;
|
|
76
|
+
setIsRenamingInProgress(true);
|
|
77
|
+
try {
|
|
78
|
+
await threadList.renameThread(threadId, newTitle.trim());
|
|
79
|
+
setRenamingThreadId(null);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.error('Failed to rename thread:', error);
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
setIsRenamingInProgress(false);
|
|
86
|
+
}
|
|
87
|
+
}, [threadList, isRenamingInProgress]);
|
|
88
|
+
const threadItems = Object.values(threadListState.threadItems);
|
|
89
|
+
const displayThreads = useMemo(() => {
|
|
90
|
+
return threadItems.filter(thread => thread.conversationId && !thread.conversationId.startsWith('temp-'));
|
|
91
|
+
}, [threadItems]);
|
|
92
|
+
const showEmpty = !threadListState.isLoading && displayThreads.length === 0;
|
|
93
|
+
const showSkeletons = threadListState.isLoading && displayThreads.length === 0;
|
|
94
|
+
const showThreads = displayThreads.length > 0;
|
|
95
|
+
const { sentinelRef } = useInfiniteScroll({
|
|
96
|
+
onLoadMore: loadMore,
|
|
97
|
+
hasMore,
|
|
98
|
+
isLoading: isLoadingMore || threadListState.isLoading,
|
|
99
|
+
rootMargin: '100px'
|
|
100
|
+
});
|
|
101
|
+
return (_jsxs(Layout.Vertical, { className: "h-full gap-cn-sm", children: [_jsx(SearchInput, { placeholder: "Search your chats...", onChange: handleSearch }), copyError && (_jsx(Alert.Root, { theme: "danger", dismissible: true, onDismiss: () => setCopyError(null), children: _jsx(Alert.Description, { children: copyError }) })), _jsxs(Layout.Vertical, { className: "flex-1 gap-cn-xs overflow-y-auto", children: [showSkeletons && (_jsx(Layout.Vertical, { gap: "xs", children: Array.from({ length: 5 }).map((_, index) => (_jsx("div", { className: "px-cn-sm py-cn-xs", children: _jsx(Skeleton.Typography, { variant: "body-normal", className: "w-3/4" }) }, index))) })), showEmpty && (_jsxs(Layout.Vertical, { align: "center", justify: "center", className: "h-full", children: [_jsx(IconV2, { name: "chat-bubble", size: "lg", className: "text-icons-disabled mb-cn-sm" }), _jsx(Text, { variant: "body-normal", className: "text-foreground-disabled", children: searchTerm ? 'No matching chats found' : 'No chat history yet' })] })), showThreads && (_jsxs(_Fragment, { children: [_jsx(StackedList.Root, { className: "bg-transparent", border: false, children: displayThreads.map(thread => (_jsx(StackedList.Item, { paddingX: "sm", paddingY: "xs", onClick: renamingThreadId === thread.id
|
|
102
|
+
? undefined
|
|
103
|
+
: () => handleThreadClick(thread.id, thread.conversationId), className: "rounded-cn-sm border-none", actions: _jsx(ThreadActionsMenu, { threadId: thread.id, threadTitle: toSentenceCase(thread.title || 'Untitled chat'), conversationId: thread.conversationId, onDelete: threadList.deleteThread, onRenameStart: () => {
|
|
104
|
+
setRenamingThreadId(thread.id);
|
|
105
|
+
setRenameValue(toSentenceCase(thread.title || ''));
|
|
106
|
+
}, onCopyError: setCopyError }), children: _jsx(StackedList.Field, { title: renamingThreadId === thread.id ? (_jsx(TextInput, { value: renameValue, onChange: e => setRenameValue(e.target.value), onBlur: () => {
|
|
107
|
+
if (!isRenamingInProgress) {
|
|
108
|
+
setRenamingThreadId(null);
|
|
109
|
+
}
|
|
110
|
+
}, onKeyDown: e => {
|
|
111
|
+
if (e.key === 'Enter') {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
handleRename(thread.id, renameValue);
|
|
114
|
+
}
|
|
115
|
+
else if (e.key === 'Escape') {
|
|
116
|
+
setRenamingThreadId(null);
|
|
117
|
+
}
|
|
118
|
+
}, autoFocus: true, className: "w-full", onClick: e => e.stopPropagation(), disabled: isRenamingInProgress })) : (toSentenceCase(thread.title || 'Untitled chat')), description: thread.updatedAt ? (_jsx(TimeAgoCard, { timestamp: thread.updatedAt, textProps: { variant: 'caption-normal', color: 'foreground-4' } })) : null }) }, thread.id))) }), _jsx("div", { ref: sentinelRef, className: "py-cn-sm", children: isLoadingMore && (_jsx(Layout.Vertical, { align: "center", justify: "center", children: _jsx(IconV2, { name: "loader", size: "lg", className: "text-icons-2 animate-spin" }) })) })] }))] })] }));
|
|
119
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ChatContentState } from './hooks/use-chat-content-state';
|
|
2
|
+
type ChatHomepageBodyProps = Pick<ChatContentState, 'showHistory' | 'handleSelectThread' | 'showChatWelcomeScreen' | 'messages' | 'scrollRef' | 'handleScroll' | 'showScrollButton' | 'scrollEdgeFadeStyle' | 'scrollToBottom'>;
|
|
3
|
+
export declare const ChatHomepageBody: ({ showHistory, handleSelectThread, showChatWelcomeScreen, messages, scrollRef, handleScroll, showScrollButton, scrollEdgeFadeStyle, scrollToBottom }: ChatHomepageBodyProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=chat-homepage-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-homepage-body.d.ts","sourceRoot":"","sources":["../src/chat-homepage-body.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEjE,KAAK,qBAAqB,GAAG,IAAI,CAC/B,gBAAgB,EACd,aAAa,GACb,oBAAoB,GACpB,uBAAuB,GACvB,UAAU,GACV,WAAW,GACX,cAAc,GACd,kBAAkB,GAClB,qBAAqB,GACrB,gBAAgB,CACnB,CAAA;AAED,eAAO,MAAM,gBAAgB,yJAU1B,qBAAqB,4CAgCvB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Layout } from '@harnessio/ui/components';
|
|
3
|
+
import { ChatHistory } from './chat-history';
|
|
4
|
+
import { ChatInput } from './chat-input';
|
|
5
|
+
import { ChatLayout } from './chat-layout';
|
|
6
|
+
import { ChatMessageList } from './chat-message-list';
|
|
7
|
+
import { useChatHost } from './context/chat-host-context';
|
|
8
|
+
export const ChatHomepageBody = ({ showHistory, handleSelectThread, showChatWelcomeScreen, messages, scrollRef, handleScroll, showScrollButton, scrollEdgeFadeStyle, scrollToBottom }) => {
|
|
9
|
+
const { WelcomeScreen } = useChatHost();
|
|
10
|
+
if (showHistory) {
|
|
11
|
+
return (_jsx(ChatLayout.Section, { className: "relative overflow-hidden", children: _jsx(ChatHistory, { onSelectThread: handleSelectThread }) }));
|
|
12
|
+
}
|
|
13
|
+
if (showChatWelcomeScreen) {
|
|
14
|
+
return (_jsx(ChatLayout.Section, { className: "relative overflow-hidden", children: _jsxs(Layout.Vertical, { align: "center", justify: "center", className: "h-full", children: [_jsx(WelcomeScreen, { variant: "homepage" }), _jsx(ChatInput, {})] }) }));
|
|
15
|
+
}
|
|
16
|
+
return (_jsx(ChatMessageList, { messages: messages, scrollRef: scrollRef, handleScroll: handleScroll, showScrollButton: showScrollButton, scrollEdgeFadeStyle: scrollEdgeFadeStyle, scrollToBottom: scrollToBottom }));
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-input-plus-menu.d.ts","sourceRoot":"","sources":["../src/chat-input-plus-menu.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,+CAmC7B,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, DropdownMenu, IconV2 } from '@harnessio/ui/components';
|
|
3
|
+
import { useChatMcpConnectors } from './hooks/use-chat-mcp-connectors';
|
|
4
|
+
import { useChatSettingsStore } from './stores/chat-settings-store';
|
|
5
|
+
export const ChatInputPlusMenu = () => {
|
|
6
|
+
const { isEnabled } = useChatMcpConnectors();
|
|
7
|
+
const openSettings = useChatSettingsStore(state => state.openSettings);
|
|
8
|
+
return (_jsxs(DropdownMenu.Root, { children: [_jsx(DropdownMenu.Trigger, { asChild: true, children: _jsx(Button, { type: "button", variant: "ghost", size: "xs", iconOnly: true, "aria-label": "Add", tooltipProps: { content: 'Add' }, children: _jsx(IconV2, { name: "plus", size: "sm" }) }) }), _jsxs(DropdownMenu.Content, { className: "min-w-[208px]", align: "start", sideOffset: 4, children: [isEnabled && (_jsx(DropdownMenu.IconItem, { icon: "connectors", title: "Add MCP server", className: "cursor-pointer", onClick: e => {
|
|
9
|
+
e.stopPropagation();
|
|
10
|
+
openSettings('mcp-connectors');
|
|
11
|
+
} })), _jsx(DropdownMenu.IconItem, { icon: "bookmark", title: "Add rules", className: "cursor-pointer", onClick: e => {
|
|
12
|
+
e.stopPropagation();
|
|
13
|
+
openSettings('rules');
|
|
14
|
+
} })] })] }));
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-input.d.ts","sourceRoot":"","sources":["../src/chat-input.tsx"],"names":[],"mappings":"AAaA,eAAO,MAAM,SAAS,+CAgGrB,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
3
|
+
import { useChatContext, useComposer, useCurrentThread } from '@harnessio/ai-chat-core';
|
|
4
|
+
import { Layout, PromptInput, Text } from '@harnessio/ui/components';
|
|
5
|
+
import { MAX_CHAT_INPUT_CHARACTERS } from './chat-constants';
|
|
6
|
+
import { ChatSpeechButton } from './chat-speech-button';
|
|
7
|
+
import { useChatHost } from './context/chat-host-context';
|
|
8
|
+
import { useChatTracking } from './hooks/use-chat-tracking';
|
|
9
|
+
import { useIdleSessionPrompt } from './hooks/use-idle-session-prompt';
|
|
10
|
+
import { useSpeechToText } from './hooks/use-speech-to-text';
|
|
11
|
+
import { useIdleSessionPromptStore } from './stores/idle-session-prompt-store';
|
|
12
|
+
export const ChatInput = () => {
|
|
13
|
+
const composer = useComposer();
|
|
14
|
+
const thread = useCurrentThread();
|
|
15
|
+
const { contexts, removeContext } = useChatContext();
|
|
16
|
+
const { trackMessageSent } = useChatTracking();
|
|
17
|
+
const { interceptSendIfIdle } = useIdleSessionPrompt();
|
|
18
|
+
const { PlusMenu } = useChatHost();
|
|
19
|
+
const restoredMessage = useIdleSessionPromptStore(state => state.restoredMessage);
|
|
20
|
+
const handleTranscript = useCallback((text) => composer.setText(text), [composer]);
|
|
21
|
+
const speech = useSpeechToText({
|
|
22
|
+
maxLength: MAX_CHAT_INPUT_CHARACTERS,
|
|
23
|
+
onTranscript: handleTranscript
|
|
24
|
+
});
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (restoredMessage == null)
|
|
27
|
+
return;
|
|
28
|
+
const message = useIdleSessionPromptStore.getState().consumeRestoredMessage();
|
|
29
|
+
if (message) {
|
|
30
|
+
composer.setText(message);
|
|
31
|
+
}
|
|
32
|
+
}, [composer, restoredMessage]);
|
|
33
|
+
const contextTags = useMemo(() => {
|
|
34
|
+
return Object.values(contexts)
|
|
35
|
+
.sort((a, b) => (a.priority ?? 999) - (b.priority ?? 999))
|
|
36
|
+
.map(ctx => ({
|
|
37
|
+
id: ctx.id,
|
|
38
|
+
displayName: ctx.displayName
|
|
39
|
+
}));
|
|
40
|
+
}, [contexts]);
|
|
41
|
+
const handleSubmit = (e) => {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
if (thread.isRunning) {
|
|
44
|
+
thread.cancelRun();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const prompt = composer.text;
|
|
48
|
+
if (!prompt.trim())
|
|
49
|
+
return;
|
|
50
|
+
speech.stop();
|
|
51
|
+
if (interceptSendIfIdle(prompt)) {
|
|
52
|
+
composer.clear();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
composer.send();
|
|
56
|
+
useIdleSessionPromptStore.getState().markConversationAccessed(thread.conversationId);
|
|
57
|
+
trackMessageSent({
|
|
58
|
+
prompt,
|
|
59
|
+
hasContext: Object.keys(contexts).length > 0
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return (_jsxs(Layout.Vertical, { gap: "none", className: "w-full", children: [_jsxs(PromptInput.Root, { onSubmit: handleSubmit, children: [contextTags.length > 0 && _jsx(PromptInput.Tags, { tags: contextTags, onRemove: id => removeContext(id) }), _jsx(PromptInput.Textarea, { value: composer.text, onChange: e => {
|
|
63
|
+
composer.setText(e.target.value);
|
|
64
|
+
}, maxLength: MAX_CHAT_INPUT_CHARACTERS, placeholder: speech.listening ? 'Listening' : undefined }), _jsxs(PromptInput.Toolbar, { children: [PlusMenu ? (_jsx(PromptInput.Tools, { children: _jsx(PlusMenu, {}) })) : null, _jsxs(Layout.Horizontal, { gap: "xs", className: "items-center", children: [speech.supported && (_jsx(ChatSpeechButton, { listening: speech.listening, error: speech.error, onToggle: () => speech.toggle(composer.text) })), _jsx(PromptInput.Submit, { status: thread.isRunning ? 'streaming' : undefined })] })] })] }), _jsx(Text, { variant: "body-single-line-normal", color: "foreground-4", className: "mt-cn-3xs block w-full text-center", style: { fontSize: '0.5rem' }, children: "Harness AI can make mistakes. Check answers." })] }));
|
|
65
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface ChatLayoutProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
declare function Header({ children, className, style, ...props }: ChatLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare function Section({ children, className, style, ...props }: ChatLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
declare function Footer({ children, className, style, ...props }: ChatLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const ChatLayout: {
|
|
9
|
+
Header: typeof Header;
|
|
10
|
+
Section: typeof Section;
|
|
11
|
+
Footer: typeof Footer;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=chat-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-layout.d.ts","sourceRoot":"","sources":["../src/chat-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AASzB,UAAU,eAAgB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IACpE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,iBAAS,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,eAAe,2CAMxE;AAED,iBAAS,OAAO,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,eAAe,2CAMzE;AAED,iBAAS,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,eAAe,2CAMxE;AAED,eAAO,MAAM,UAAU;;;;CAA8B,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from '@harnessio/ui/utils';
|
|
3
|
+
const CHAT_CONTAINER_PADDING = {
|
|
4
|
+
paddingLeft: 'var(--cn-ai-chat-container)',
|
|
5
|
+
paddingRight: 'var(--cn-ai-chat-container)'
|
|
6
|
+
};
|
|
7
|
+
function Header({ children, className, style, ...props }) {
|
|
8
|
+
return (_jsx("div", { className: cn('shrink-0', className), style: { ...CHAT_CONTAINER_PADDING, ...style }, ...props, children: children }));
|
|
9
|
+
}
|
|
10
|
+
function Section({ children, className, style, ...props }) {
|
|
11
|
+
return (_jsx("div", { className: cn('min-h-0 flex-1', className), style: { ...CHAT_CONTAINER_PADDING, ...style }, ...props, children: children }));
|
|
12
|
+
}
|
|
13
|
+
function Footer({ children, className, style, ...props }) {
|
|
14
|
+
return (_jsx("div", { className: cn('shrink-0 pb-cn-xs', className), style: { ...CHAT_CONTAINER_PADDING, ...style }, ...props, children: children }));
|
|
15
|
+
}
|
|
16
|
+
export const ChatLayout = { Header, Section, Footer };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Message } from '@harnessio/ai-chat-core';
|
|
3
|
+
interface ChatMessageListProps {
|
|
4
|
+
messages: readonly Message[];
|
|
5
|
+
scrollRef: React.RefObject<HTMLDivElement>;
|
|
6
|
+
handleScroll: (e: React.UIEvent<HTMLDivElement>) => void;
|
|
7
|
+
showScrollButton: boolean;
|
|
8
|
+
scrollEdgeFadeStyle: React.CSSProperties;
|
|
9
|
+
scrollToBottom: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const ChatMessageList: ({ messages, scrollRef, handleScroll, showScrollButton, scrollEdgeFadeStyle, scrollToBottom }: ChatMessageListProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=chat-message-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-message-list.d.ts","sourceRoot":"","sources":["../src/chat-message-list.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAmB,OAAO,EAAE,MAAM,yBAAyB,CAAA;AASlE,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAA;IAC5B,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC1C,YAAY,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,IAAI,CAAA;IACxD,gBAAgB,EAAE,OAAO,CAAA;IACzB,mBAAmB,EAAE,KAAK,CAAC,aAAa,CAAA;IACxC,cAAc,EAAE,MAAM,IAAI,CAAA;CAC3B;AAED,eAAO,MAAM,eAAe,iGAOzB,oBAAoB,4CAkDtB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ContentRenderer } from '@harnessio/ai-chat-core';
|
|
3
|
+
import { Button, IconV2, Layout } from '@harnessio/ui/components';
|
|
4
|
+
import { ChatInput } from './chat-input';
|
|
5
|
+
import { ChatLayout } from './chat-layout';
|
|
6
|
+
import { MessageErrorBoundary } from './error-boundaries';
|
|
7
|
+
import { HarnessLoader } from './harness-loader/harness-loader';
|
|
8
|
+
import { IdleSessionBanner } from './idle-session-banner';
|
|
9
|
+
export const ChatMessageList = ({ messages, scrollRef, handleScroll, showScrollButton, scrollEdgeFadeStyle, scrollToBottom }) => {
|
|
10
|
+
return (_jsxs(_Fragment, { children: [_jsxs(ChatLayout.Section, { className: "relative overflow-hidden", children: [_jsx(Layout.Vertical, { ref: scrollRef, onScroll: handleScroll, className: "chat-scroll-edge-fade h-full overflow-y-auto pb-cn-md", style: scrollEdgeFadeStyle, children: messages.map(message => (_jsx(MessageErrorBoundary, { children: _jsxs(Layout.Vertical, { justify: message.role === 'user' ? 'end' : 'start', children: [message.content.map((content, idx) => (_jsx(ContentRenderer, { message: message, content: content }, idx))), message.role === 'assistant' &&
|
|
11
|
+
message.status.type === 'running' &&
|
|
12
|
+
!message.content.some(content => content.status?.type === 'streaming') && (_jsx("div", { className: "mb-cn-sm", children: _jsx(HarnessLoader, { size: 20 }) }))] }) }, message.id))) }), showScrollButton && (_jsx(Button, { iconOnly: true, rounded: true, ignoreIconOnlyTooltip: true, variant: "outline", className: "absolute inset-x-0 bottom-cn-xs z-10 mx-auto", onClick: scrollToBottom, children: _jsx(IconV2, { name: "arrow-down" }) }))] }), _jsxs(ChatLayout.Footer, { children: [_jsx(IdleSessionBanner, {}), _jsx(ChatInput, {})] })] }));
|
|
13
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ChatContentState } from './hooks/use-chat-content-state';
|
|
2
|
+
type ChatPanelBodyProps = Pick<ChatContentState, 'showHistory' | 'handleSelectThread' | 'showChatWelcomeScreen' | 'messages' | 'scrollRef' | 'handleScroll' | 'showScrollButton' | 'scrollEdgeFadeStyle' | 'scrollToBottom'>;
|
|
3
|
+
export declare const ChatPanelBody: ({ showHistory, handleSelectThread, showChatWelcomeScreen, messages, scrollRef, handleScroll, showScrollButton, scrollEdgeFadeStyle, scrollToBottom }: ChatPanelBodyProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=chat-panel-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-panel-body.d.ts","sourceRoot":"","sources":["../src/chat-panel-body.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEjE,KAAK,kBAAkB,GAAG,IAAI,CAC5B,gBAAgB,EACd,aAAa,GACb,oBAAoB,GACpB,uBAAuB,GACvB,UAAU,GACV,WAAW,GACX,cAAc,GACd,kBAAkB,GAClB,qBAAqB,GACrB,gBAAgB,CACnB,CAAA;AAED,eAAO,MAAM,aAAa,yJAUvB,kBAAkB,4CA0CpB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Layout } from '@harnessio/ui/components';
|
|
3
|
+
import { ChatHistory } from './chat-history';
|
|
4
|
+
import { ChatInput } from './chat-input';
|
|
5
|
+
import { ChatLayout } from './chat-layout';
|
|
6
|
+
import { ChatMessageList } from './chat-message-list';
|
|
7
|
+
import { useChatHost } from './context/chat-host-context';
|
|
8
|
+
export const ChatPanelBody = ({ showHistory, handleSelectThread, showChatWelcomeScreen, messages, scrollRef, handleScroll, showScrollButton, scrollEdgeFadeStyle, scrollToBottom }) => {
|
|
9
|
+
const { WelcomeScreen } = useChatHost();
|
|
10
|
+
if (showHistory) {
|
|
11
|
+
return (_jsx(ChatLayout.Section, { className: "relative overflow-hidden", children: _jsx(ChatHistory, { onSelectThread: handleSelectThread }) }));
|
|
12
|
+
}
|
|
13
|
+
if (showChatWelcomeScreen) {
|
|
14
|
+
return (_jsxs(_Fragment, { children: [_jsx(ChatLayout.Section, { className: "relative overflow-hidden", children: _jsx(Layout.Vertical, { ref: scrollRef, onScroll: handleScroll, className: "chat-scroll-edge-fade h-full overflow-y-auto", style: scrollEdgeFadeStyle, children: _jsx(WelcomeScreen, { variant: "panel" }) }) }), _jsx(ChatLayout.Footer, { children: _jsx(ChatInput, {}) })] }));
|
|
15
|
+
}
|
|
16
|
+
return (_jsx(ChatMessageList, { messages: messages, scrollRef: scrollRef, handleScroll: handleScroll, showScrollButton: showScrollButton, scrollEdgeFadeStyle: scrollEdgeFadeStyle, scrollToBottom: scrollToBottom }));
|
|
17
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
export interface ChatScrollEdgeFades {
|
|
3
|
+
top: boolean;
|
|
4
|
+
bottom: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const CHAT_SCROLL_EDGE_FADE_NONE: ChatScrollEdgeFades;
|
|
7
|
+
export declare function getChatScrollEdgeFades(element: HTMLDivElement | null): ChatScrollEdgeFades;
|
|
8
|
+
export declare function getChatScrollEdgeFadeStyle(fades: ChatScrollEdgeFades): CSSProperties;
|
|
9
|
+
//# sourceMappingURL=chat-scroll-fade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-scroll-fade.d.ts","sourceRoot":"","sources":["../src/chat-scroll-fade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,OAAO,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,eAAO,MAAM,0BAA0B,EAAE,mBAAmD,CAAA;AAE5F,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,GAAG,mBAAmB,CAkB1F;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,mBAAmB,GAAG,aAAa,CAKpF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const CHAT_SCROLL_EDGE_FADE_NONE = { top: false, bottom: false };
|
|
2
|
+
export function getChatScrollEdgeFades(element) {
|
|
3
|
+
if (!element) {
|
|
4
|
+
return CHAT_SCROLL_EDGE_FADE_NONE;
|
|
5
|
+
}
|
|
6
|
+
const { scrollTop, scrollHeight, clientHeight } = element;
|
|
7
|
+
const canScroll = scrollHeight - clientHeight > 1;
|
|
8
|
+
if (!canScroll) {
|
|
9
|
+
return CHAT_SCROLL_EDGE_FADE_NONE;
|
|
10
|
+
}
|
|
11
|
+
const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
|
|
12
|
+
return {
|
|
13
|
+
top: scrollTop > 1,
|
|
14
|
+
bottom: distanceFromBottom > 1
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function getChatScrollEdgeFadeStyle(fades) {
|
|
18
|
+
return {
|
|
19
|
+
'--chat-scroll-fade-top-start': fades.top ? 'transparent' : 'black',
|
|
20
|
+
'--chat-scroll-fade-bottom-end': fades.bottom ? 'transparent' : 'black'
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ChatSpeechButtonProps {
|
|
2
|
+
listening: boolean;
|
|
3
|
+
error?: string | null;
|
|
4
|
+
onToggle: () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const ChatSpeechButton: ({ listening, error, onToggle }: ChatSpeechButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=chat-speech-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-speech-button.d.ts","sourceRoot":"","sources":["../src/chat-speech-button.tsx"],"names":[],"mappings":"AAEA,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB;AAED,eAAO,MAAM,gBAAgB,mCAAoC,qBAAqB,4CA0BrF,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Button, IconV2 } from '@harnessio/ui/components';
|
|
3
|
+
export const ChatSpeechButton = ({ listening, error, onToggle }) => {
|
|
4
|
+
const tooltip = error ? error : listening ? 'Stop listening' : 'Voice input';
|
|
5
|
+
const label = listening ? 'Stop voice input' : 'Start voice input';
|
|
6
|
+
const iconName = (listening ? 'stop-solid' : 'microphone');
|
|
7
|
+
return (_jsx(Button, { type: "button", variant: "ghost", size: "xs", rounded: true, iconOnly: true, theme: listening ? 'danger' : 'default', "aria-label": label, "aria-pressed": listening, "data-listening": listening ? 'true' : undefined, tooltipProps: { content: tooltip, side: 'top', align: 'center' }, onClick: event => {
|
|
8
|
+
event.preventDefault();
|
|
9
|
+
event.stopPropagation();
|
|
10
|
+
onToggle();
|
|
11
|
+
}, children: _jsx(IconV2, { name: iconName }) }));
|
|
12
|
+
};
|