@sveda-ai/solid 0.3.1
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/LICENSE +557 -0
- package/README.md +18 -0
- package/dist/appearance.d.ts +9 -0
- package/dist/appearance.d.ts.map +1 -0
- package/dist/components/SvedaChat.d.ts +16 -0
- package/dist/components/SvedaChat.d.ts.map +1 -0
- package/dist/components/SvedaComposer.d.ts +17 -0
- package/dist/components/SvedaComposer.d.ts.map +1 -0
- package/dist/components/SvedaMessageList.d.ts +11 -0
- package/dist/components/SvedaMessageList.d.ts.map +1 -0
- package/dist/components/SvedaMinimizedTrigger.d.ts +10 -0
- package/dist/components/SvedaMinimizedTrigger.d.ts.map +1 -0
- package/dist/components/SvedaQuickPrompts.d.ts +14 -0
- package/dist/components/SvedaQuickPrompts.d.ts.map +1 -0
- package/dist/components/SvedaTabs.d.ts +14 -0
- package/dist/components/SvedaTabs.d.ts.map +1 -0
- package/dist/components/SvedaToolbar.d.ts +21 -0
- package/dist/components/SvedaToolbar.d.ts.map +1 -0
- package/dist/components/SvedaWelcome.d.ts +20 -0
- package/dist/components/SvedaWelcome.d.ts.map +1 -0
- package/dist/components/shell/ChatHistoryList.d.ts +11 -0
- package/dist/components/shell/ChatHistoryList.d.ts.map +1 -0
- package/dist/components/shell/SvedaFrameTicks.d.ts +2 -0
- package/dist/components/shell/SvedaFrameTicks.d.ts.map +1 -0
- package/dist/components/shell/SvedaResizeHandles.d.ts +8 -0
- package/dist/components/shell/SvedaResizeHandles.d.ts.map +1 -0
- package/dist/hooks/useSvedaChat.d.ts +33 -0
- package/dist/hooks/useSvedaChat.d.ts.map +1 -0
- package/dist/hooks/useSvedaChatPage.d.ts +99 -0
- package/dist/hooks/useSvedaChatPage.d.ts.map +1 -0
- package/dist/hooks/useSvedaStreaming.d.ts +44 -0
- package/dist/hooks/useSvedaStreaming.d.ts.map +1 -0
- package/dist/i18n/index.d.ts +16 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1557 -0
- package/dist/launcherIcons.d.ts +7 -0
- package/dist/launcherIcons.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/provider.d.ts +65 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/styles.css +38 -0
- package/package.json +71 -0
- package/src/appearance.ts +75 -0
- package/src/chat.css +35 -0
- package/src/components/SvedaChat.tsx +381 -0
- package/src/components/SvedaComposer.tsx +116 -0
- package/src/components/SvedaMessageList.tsx +89 -0
- package/src/components/SvedaMinimizedTrigger.tsx +40 -0
- package/src/components/SvedaQuickPrompts.tsx +36 -0
- package/src/components/SvedaTabs.tsx +109 -0
- package/src/components/SvedaToolbar.tsx +140 -0
- package/src/components/SvedaWelcome.tsx +50 -0
- package/src/components/shell/ChatHistoryList.tsx +158 -0
- package/src/components/shell/SvedaFrameTicks.tsx +22 -0
- package/src/components/shell/SvedaResizeHandles.tsx +49 -0
- package/src/hooks/useSvedaChat.ts +97 -0
- package/src/hooks/useSvedaChatPage.ts +644 -0
- package/src/hooks/useSvedaStreaming.ts +102 -0
- package/src/i18n/index.ts +61 -0
- package/src/index.ts +113 -0
- package/src/launcherIcons.ts +41 -0
- package/src/lib/utils.ts +6 -0
- package/src/markdown.css +96 -0
- package/src/provider.tsx +196 -0
- package/src/styles.css +6 -0
- package/src/theme.css +137 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { buildChatTabTitleMap, type SvedaTabChat } from '@sveda-ai/chat';
|
|
2
|
+
import { Loader2, Plus, X } from 'lucide-solid';
|
|
3
|
+
import { For, Show, type Component, createMemo } from 'solid-js';
|
|
4
|
+
import { useSvedaT } from '../i18n/index';
|
|
5
|
+
import { cn } from '../lib/utils';
|
|
6
|
+
|
|
7
|
+
export interface SvedaTabsProps {
|
|
8
|
+
tabs: SvedaTabChat[];
|
|
9
|
+
currentChatId?: string | null;
|
|
10
|
+
streamingChatIds?: Set<string>;
|
|
11
|
+
unreadChatIds?: Set<string>;
|
|
12
|
+
compact?: boolean;
|
|
13
|
+
onSelectChat: (chatId: string) => void;
|
|
14
|
+
onCloseTab: (chatId: string) => void;
|
|
15
|
+
onNewChat: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const SvedaTabs: Component<SvedaTabsProps> = props => {
|
|
19
|
+
const t = useSvedaT();
|
|
20
|
+
|
|
21
|
+
const visibleTabs = createMemo(() => (props.tabs ?? []).filter(tab => tab?.id));
|
|
22
|
+
const tabTitles = createMemo(() => buildChatTabTitleMap(visibleTabs(), t));
|
|
23
|
+
|
|
24
|
+
const isStreaming = (chatId: string) =>
|
|
25
|
+
props.streamingChatIds instanceof Set ? props.streamingChatIds.has(chatId) : false;
|
|
26
|
+
|
|
27
|
+
const hasUnread = (chatId: string) =>
|
|
28
|
+
!isStreaming(chatId) &&
|
|
29
|
+
(props.unreadChatIds instanceof Set ? props.unreadChatIds.has(chatId) : false);
|
|
30
|
+
|
|
31
|
+
const tabTriggerClass = (chatId: string) =>
|
|
32
|
+
cn(
|
|
33
|
+
'inline-flex h-10 max-w-56 shrink-0 items-center gap-1.5 whitespace-nowrap border-b border-transparent px-3 py-2 font-mono text-[11px] tracking-[0.12em] text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none',
|
|
34
|
+
props.currentChatId === chatId ? 'border-foreground bg-transparent text-foreground' : '',
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Show when={visibleTabs().length > 0}>
|
|
39
|
+
<div
|
|
40
|
+
class={cn(
|
|
41
|
+
'flex shrink-0 items-stretch border-b border-border bg-card',
|
|
42
|
+
props.compact ? 'px-3' : 'px-4 md:px-6',
|
|
43
|
+
)}
|
|
44
|
+
>
|
|
45
|
+
<div class="min-w-0 flex-1 overflow-x-auto">
|
|
46
|
+
<div class="flex h-12 min-w-max items-end gap-px px-1">
|
|
47
|
+
<For each={visibleTabs()}>
|
|
48
|
+
{tab => (
|
|
49
|
+
<div
|
|
50
|
+
role="button"
|
|
51
|
+
tabindex="0"
|
|
52
|
+
class={tabTriggerClass(tab.id)}
|
|
53
|
+
onClick={() => props.onSelectChat(tab.id)}
|
|
54
|
+
onKeyDown={event => {
|
|
55
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
props.onSelectChat(tab.id);
|
|
58
|
+
}
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
<Show
|
|
62
|
+
when={isStreaming(tab.id)}
|
|
63
|
+
fallback={
|
|
64
|
+
<Show when={hasUnread(tab.id)}>
|
|
65
|
+
<span
|
|
66
|
+
class="h-2 w-2 shrink-0 rounded-full bg-primary"
|
|
67
|
+
aria-label={t('chatTabUnread')}
|
|
68
|
+
/>
|
|
69
|
+
</Show>
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
<Loader2
|
|
73
|
+
class="h-3.5 w-3.5 shrink-0 animate-spin text-primary"
|
|
74
|
+
aria-label={t('chatTabRunning')}
|
|
75
|
+
/>
|
|
76
|
+
</Show>
|
|
77
|
+
<span class="min-w-0 truncate">{tabTitles().get(tab.id)}</span>
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
class="ml-0.5 rounded-sm p-0.5 text-muted-foreground opacity-70 hover:bg-background/80 hover:text-foreground hover:opacity-100"
|
|
81
|
+
aria-label={t('closeChatTab')}
|
|
82
|
+
onMouseDown={event => event.stopPropagation()}
|
|
83
|
+
onClick={event => {
|
|
84
|
+
event.stopPropagation();
|
|
85
|
+
props.onCloseTab(tab.id);
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
<X class="h-3 w-3" />
|
|
89
|
+
</button>
|
|
90
|
+
</div>
|
|
91
|
+
)}
|
|
92
|
+
</For>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<div class="flex shrink-0 items-center border-l border-border/40 pl-1">
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
class="inline-flex h-9 w-9 shrink-0 items-center justify-center text-muted-foreground hover:text-foreground"
|
|
100
|
+
aria-label={t('newChat')}
|
|
101
|
+
onClick={() => props.onNewChat()}
|
|
102
|
+
>
|
|
103
|
+
<Plus class="h-4 w-4" />
|
|
104
|
+
</button>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
</Show>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { History, Maximize2, MessageSquare, Minimize2, PanelRight, Sparkles, X } from 'lucide-solid';
|
|
2
|
+
import { type Component, Show, createMemo } from 'solid-js';
|
|
3
|
+
import { useSvedaT } from '../i18n/index';
|
|
4
|
+
import { cn } from '../lib/utils';
|
|
5
|
+
|
|
6
|
+
const iconButtonClass =
|
|
7
|
+
'inline-flex h-9 w-9 items-center justify-center bg-transparent text-muted-foreground hover:text-foreground';
|
|
8
|
+
|
|
9
|
+
export interface SvedaToolbarProps {
|
|
10
|
+
isMobile: boolean;
|
|
11
|
+
viewMode: string;
|
|
12
|
+
isImmersiveDesktop?: boolean;
|
|
13
|
+
showHistorySidebar?: boolean;
|
|
14
|
+
title: string;
|
|
15
|
+
viewModeFloatingLabel?: string;
|
|
16
|
+
viewModeFixedLabel?: string;
|
|
17
|
+
immersiveEnterLabel?: string;
|
|
18
|
+
immersiveExitLabel?: string;
|
|
19
|
+
immersiveBrandName?: string;
|
|
20
|
+
immersiveBrandLogo?: string;
|
|
21
|
+
onToggleHistorySidebar?: () => void;
|
|
22
|
+
onToggleViewMode?: () => void;
|
|
23
|
+
onEnterImmersive?: () => void;
|
|
24
|
+
onExitImmersive?: () => void;
|
|
25
|
+
onMinimize: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const SvedaToolbar: Component<SvedaToolbarProps> = props => {
|
|
29
|
+
const t = useSvedaT();
|
|
30
|
+
|
|
31
|
+
const headerClass = createMemo(() => {
|
|
32
|
+
const base =
|
|
33
|
+
'flex h-12 shrink-0 flex-row items-center justify-between border-b border-border bg-card px-3';
|
|
34
|
+
if (props.viewMode === 'floating' && !props.isMobile) {
|
|
35
|
+
return `${base} rounded-t-[var(--sveda-radius)]`;
|
|
36
|
+
}
|
|
37
|
+
return `${base} rounded-none`;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<header class={headerClass()}>
|
|
42
|
+
<Show
|
|
43
|
+
when={!props.isImmersiveDesktop}
|
|
44
|
+
fallback={
|
|
45
|
+
<div class="flex min-w-0 flex-1 items-center gap-4">
|
|
46
|
+
<div class="w-[min(20rem,33vw)] min-w-0">
|
|
47
|
+
<div class="flex items-center gap-2">
|
|
48
|
+
<Show
|
|
49
|
+
when={props.immersiveBrandLogo}
|
|
50
|
+
fallback={<Sparkles class="size-5 shrink-0 text-primary" />}
|
|
51
|
+
>
|
|
52
|
+
<img
|
|
53
|
+
src={props.immersiveBrandLogo}
|
|
54
|
+
alt={props.immersiveBrandName ?? ''}
|
|
55
|
+
class="size-7 shrink-0 rounded"
|
|
56
|
+
/>
|
|
57
|
+
</Show>
|
|
58
|
+
<span class="truncate text-lg font-bold leading-none text-foreground">
|
|
59
|
+
{props.immersiveBrandName}
|
|
60
|
+
</span>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<h2 class="min-w-0 flex-1 truncate text-left font-mono text-[11px] font-normal uppercase tracking-[0.14em] text-foreground">
|
|
64
|
+
{props.title}
|
|
65
|
+
</h2>
|
|
66
|
+
</div>
|
|
67
|
+
}
|
|
68
|
+
>
|
|
69
|
+
<div class="flex min-w-0 flex-1 items-center gap-2">
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
class={cn(iconButtonClass, props.showHistorySidebar ? 'bg-muted/60 text-foreground' : '')}
|
|
73
|
+
aria-label={t('chatHistory')}
|
|
74
|
+
title={t('chatHistory')}
|
|
75
|
+
onClick={() => props.onToggleHistorySidebar?.()}
|
|
76
|
+
>
|
|
77
|
+
<History class="h-4 w-4" />
|
|
78
|
+
</button>
|
|
79
|
+
<h2 class="min-w-0 flex-1 truncate text-left font-mono text-[11px] font-normal uppercase tracking-[0.14em] text-foreground">
|
|
80
|
+
{props.title}
|
|
81
|
+
</h2>
|
|
82
|
+
</div>
|
|
83
|
+
</Show>
|
|
84
|
+
<div class="flex shrink-0 items-center gap-0.5">
|
|
85
|
+
<Show when={!props.isMobile && props.viewMode === 'immersive'}>
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
class={iconButtonClass}
|
|
89
|
+
aria-label={props.immersiveExitLabel ?? t('immersiveModeExit')}
|
|
90
|
+
title={props.immersiveExitLabel ?? t('immersiveModeExit')}
|
|
91
|
+
onClick={() => props.onExitImmersive?.()}
|
|
92
|
+
>
|
|
93
|
+
<Minimize2 class="h-4 w-4" />
|
|
94
|
+
</button>
|
|
95
|
+
</Show>
|
|
96
|
+
<Show when={!props.isMobile && props.viewMode !== 'immersive'}>
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
class={iconButtonClass}
|
|
100
|
+
aria-label={props.immersiveEnterLabel ?? t('immersiveModeEnter')}
|
|
101
|
+
title={props.immersiveEnterLabel ?? t('immersiveModeEnter')}
|
|
102
|
+
onClick={() => props.onEnterImmersive?.()}
|
|
103
|
+
>
|
|
104
|
+
<Maximize2 class="h-4 w-4" />
|
|
105
|
+
</button>
|
|
106
|
+
</Show>
|
|
107
|
+
<Show when={!props.isMobile && props.viewMode !== 'immersive'}>
|
|
108
|
+
<button
|
|
109
|
+
type="button"
|
|
110
|
+
class={iconButtonClass}
|
|
111
|
+
aria-label={
|
|
112
|
+
props.viewMode === 'floating'
|
|
113
|
+
? (props.viewModeFixedLabel ?? t('viewModeFixed'))
|
|
114
|
+
: (props.viewModeFloatingLabel ?? t('viewModeFloating'))
|
|
115
|
+
}
|
|
116
|
+
title={
|
|
117
|
+
props.viewMode === 'floating'
|
|
118
|
+
? (props.viewModeFixedLabel ?? t('viewModeFixed'))
|
|
119
|
+
: (props.viewModeFloatingLabel ?? t('viewModeFloating'))
|
|
120
|
+
}
|
|
121
|
+
onClick={() => props.onToggleViewMode?.()}
|
|
122
|
+
>
|
|
123
|
+
<Show when={props.viewMode === 'floating'} fallback={<MessageSquare class="h-4 w-4" />}>
|
|
124
|
+
<PanelRight class="h-4 w-4" />
|
|
125
|
+
</Show>
|
|
126
|
+
</button>
|
|
127
|
+
</Show>
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
class={iconButtonClass}
|
|
131
|
+
aria-label={t('toolbarMinimize')}
|
|
132
|
+
title={t('toolbarMinimize')}
|
|
133
|
+
onClick={() => props.onMinimize()}
|
|
134
|
+
>
|
|
135
|
+
<X class="h-4 w-4" />
|
|
136
|
+
</button>
|
|
137
|
+
</div>
|
|
138
|
+
</header>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { JSX } from 'solid-js';
|
|
2
|
+
import { Show, type Component } from 'solid-js';
|
|
3
|
+
import { SvedaComposer } from './SvedaComposer';
|
|
4
|
+
import { SvedaQuickPrompts, type SvedaQuickPromptItem } from './SvedaQuickPrompts';
|
|
5
|
+
|
|
6
|
+
export interface SvedaWelcomeProps {
|
|
7
|
+
inputMessage: string;
|
|
8
|
+
onInputMessage: (value: string) => void;
|
|
9
|
+
isLoading?: boolean;
|
|
10
|
+
confirmationPending?: boolean;
|
|
11
|
+
hasCurrentChat?: boolean;
|
|
12
|
+
isStreaming?: boolean;
|
|
13
|
+
showQuickPromptButtons?: boolean;
|
|
14
|
+
quickPromptButtons?: SvedaQuickPromptItem[];
|
|
15
|
+
quickPromptsTitle: string;
|
|
16
|
+
onSend: () => void;
|
|
17
|
+
onStop: () => void;
|
|
18
|
+
onSendQuickPrompt: (prompt: string) => void;
|
|
19
|
+
top?: JSX.Element;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const SvedaWelcome: Component<SvedaWelcomeProps> = props => {
|
|
23
|
+
return (
|
|
24
|
+
<div class="flex min-h-0 flex-1 flex-col justify-center overflow-y-auto px-4 py-8">
|
|
25
|
+
<div class="flex w-full flex-col gap-3">
|
|
26
|
+
{props.top}
|
|
27
|
+
<SvedaComposer
|
|
28
|
+
value={props.inputMessage}
|
|
29
|
+
onInput={props.onInputMessage}
|
|
30
|
+
isLoading={props.isLoading}
|
|
31
|
+
confirmationPending={props.confirmationPending}
|
|
32
|
+
hasCurrentChat={props.hasCurrentChat}
|
|
33
|
+
isStreaming={props.isStreaming}
|
|
34
|
+
noBorder
|
|
35
|
+
onSend={props.onSend}
|
|
36
|
+
onStop={props.onStop}
|
|
37
|
+
/>
|
|
38
|
+
<Show when={props.showQuickPromptButtons}>
|
|
39
|
+
<SvedaQuickPrompts
|
|
40
|
+
class="px-4"
|
|
41
|
+
prompts={props.quickPromptButtons ?? []}
|
|
42
|
+
title={props.quickPromptsTitle}
|
|
43
|
+
disabled={props.isLoading || props.isStreaming || props.confirmationPending}
|
|
44
|
+
onSelect={props.onSendQuickPrompt}
|
|
45
|
+
/>
|
|
46
|
+
</Show>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { SvedaChatHistory } from '@sveda-ai/chat';
|
|
2
|
+
import { getUserMessageText } from '@sveda-ai/chat';
|
|
3
|
+
import { Search, SquarePen, Trash2 } from 'lucide-solid';
|
|
4
|
+
import { For, Show, createMemo, createSignal, type Component } from 'solid-js';
|
|
5
|
+
import { useSvedaT } from '../../i18n/index';
|
|
6
|
+
import { cn } from '../../lib/utils';
|
|
7
|
+
|
|
8
|
+
export interface ChatHistoryListProps {
|
|
9
|
+
histories: SvedaChatHistory[];
|
|
10
|
+
currentChatId?: string | null;
|
|
11
|
+
onSelectChat: (chatId: string) => void;
|
|
12
|
+
onDeleteChat: (chatId: string) => void;
|
|
13
|
+
onRenameChat: (chatId: string) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const dayDiff = (timestamp: number) => {
|
|
17
|
+
const targetDate = new Date(Number(timestamp) || Date.now());
|
|
18
|
+
const now = new Date();
|
|
19
|
+
const targetStart = new Date(targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate()).getTime();
|
|
20
|
+
const nowStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
|
|
21
|
+
return Math.max(0, Math.floor((nowStart - targetStart) / 86400000));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const ChatHistoryList: Component<ChatHistoryListProps> = props => {
|
|
25
|
+
const t = useSvedaT();
|
|
26
|
+
const [searchQuery, setSearchQuery] = createSignal('');
|
|
27
|
+
|
|
28
|
+
const previewFor = (chat: SvedaChatHistory) => {
|
|
29
|
+
if (typeof chat.preview === 'string' && chat.preview.trim()) {
|
|
30
|
+
return chat.preview.trim();
|
|
31
|
+
}
|
|
32
|
+
const message = chat.messages?.find(item => item.role === 'user');
|
|
33
|
+
return message ? getUserMessageText(message) : '';
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const filtered = createMemo(() => {
|
|
37
|
+
const query = searchQuery().trim().toLowerCase();
|
|
38
|
+
const histories = props.histories;
|
|
39
|
+
if (!query) {
|
|
40
|
+
return histories;
|
|
41
|
+
}
|
|
42
|
+
return histories.filter(chat => {
|
|
43
|
+
const preview = previewFor(chat);
|
|
44
|
+
return chat.title.toLowerCase().includes(query) || preview.toLowerCase().includes(query);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const groups = createMemo(() => {
|
|
49
|
+
const grouped: { label: string; chats: SvedaChatHistory[] }[] = [];
|
|
50
|
+
const indexByLabel = new Map<string, number>();
|
|
51
|
+
for (const chat of filtered()) {
|
|
52
|
+
const diff = dayDiff(chat.updatedAt);
|
|
53
|
+
const label =
|
|
54
|
+
diff === 0
|
|
55
|
+
? t('today')
|
|
56
|
+
: diff === 1
|
|
57
|
+
? t('yesterday')
|
|
58
|
+
: diff === 2
|
|
59
|
+
? t('dayBeforeYesterday')
|
|
60
|
+
: t('daysAgo', { count: diff });
|
|
61
|
+
const index = indexByLabel.get(label);
|
|
62
|
+
if (index === undefined) {
|
|
63
|
+
indexByLabel.set(label, grouped.length);
|
|
64
|
+
grouped.push({ label, chats: [chat] });
|
|
65
|
+
} else {
|
|
66
|
+
grouped[index].chats.push(chat);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return grouped;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div class="flex h-full min-h-0 w-full flex-col bg-background">
|
|
74
|
+
<div class="shrink-0 border-b border-border p-3">
|
|
75
|
+
<div class="mb-3 flex items-center justify-between">
|
|
76
|
+
<p class="text-sm font-semibold">{t('chatHistory')}</p>
|
|
77
|
+
</div>
|
|
78
|
+
<div class="flex h-10 items-center gap-2 rounded-[var(--sveda-radius)] border border-border bg-input px-3">
|
|
79
|
+
<Search class="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden="true" />
|
|
80
|
+
<input
|
|
81
|
+
value={searchQuery()}
|
|
82
|
+
type="text"
|
|
83
|
+
autocomplete="off"
|
|
84
|
+
placeholder={t('searchChats')}
|
|
85
|
+
class="h-full min-w-0 flex-1 border-0 bg-transparent p-0 text-sm text-card-foreground outline-none placeholder:text-muted-foreground"
|
|
86
|
+
onInput={event => setSearchQuery(event.currentTarget.value)}
|
|
87
|
+
/>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="min-h-0 flex-1 overflow-y-auto p-2">
|
|
91
|
+
<Show
|
|
92
|
+
when={groups().length > 0}
|
|
93
|
+
fallback={<div class="px-2 py-6 text-center text-sm text-muted-foreground">{t('noChatsFound')}</div>}
|
|
94
|
+
>
|
|
95
|
+
<For each={groups()}>
|
|
96
|
+
{group => (
|
|
97
|
+
<div class="mb-3 last:mb-1">
|
|
98
|
+
<p class="px-2 pb-1 text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
99
|
+
{group.label}
|
|
100
|
+
</p>
|
|
101
|
+
<For each={group.chats}>
|
|
102
|
+
{chat => (
|
|
103
|
+
<div
|
|
104
|
+
role="button"
|
|
105
|
+
tabIndex={0}
|
|
106
|
+
class={cn(
|
|
107
|
+
'group relative cursor-pointer px-2 py-2 transition-colors hover:bg-muted',
|
|
108
|
+
props.currentChatId === chat.id ? 'bg-primary/10' : '',
|
|
109
|
+
)}
|
|
110
|
+
onClick={() => props.onSelectChat(chat.id)}
|
|
111
|
+
onKeyDown={event => {
|
|
112
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
props.onSelectChat(chat.id);
|
|
115
|
+
}
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<div class="flex items-start justify-between gap-2">
|
|
119
|
+
<div class="min-w-0 flex-1">
|
|
120
|
+
<p class="truncate text-sm font-medium">{chat.title}</p>
|
|
121
|
+
<p class="truncate text-xs text-muted-foreground">{previewFor(chat)}</p>
|
|
122
|
+
</div>
|
|
123
|
+
<div class="flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100">
|
|
124
|
+
<button
|
|
125
|
+
type="button"
|
|
126
|
+
class="inline-flex h-6 w-6 items-center justify-center"
|
|
127
|
+
aria-label={t('renameChat')}
|
|
128
|
+
onClick={event => {
|
|
129
|
+
event.stopPropagation();
|
|
130
|
+
props.onRenameChat(chat.id);
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<SquarePen class="h-3 w-3" />
|
|
134
|
+
</button>
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
class="inline-flex h-6 w-6 items-center justify-center"
|
|
138
|
+
aria-label={t('delete')}
|
|
139
|
+
onClick={event => {
|
|
140
|
+
event.stopPropagation();
|
|
141
|
+
props.onDeleteChat(chat.id);
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<Trash2 class="h-3 w-3" />
|
|
145
|
+
</button>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
)}
|
|
150
|
+
</For>
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
</For>
|
|
154
|
+
</Show>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function SvedaFrameTicks() {
|
|
2
|
+
return (
|
|
3
|
+
<>
|
|
4
|
+
<span
|
|
5
|
+
class="pointer-events-none absolute -left-px -top-px z-10 h-2.5 w-2.5 border-l border-t border-foreground"
|
|
6
|
+
aria-hidden="true"
|
|
7
|
+
/>
|
|
8
|
+
<span
|
|
9
|
+
class="pointer-events-none absolute -right-px -top-px z-10 h-2.5 w-2.5 border-r border-t border-foreground"
|
|
10
|
+
aria-hidden="true"
|
|
11
|
+
/>
|
|
12
|
+
<span
|
|
13
|
+
class="pointer-events-none absolute -bottom-px -left-px z-10 h-2.5 w-2.5 border-b border-l border-foreground"
|
|
14
|
+
aria-hidden="true"
|
|
15
|
+
/>
|
|
16
|
+
<span
|
|
17
|
+
class="pointer-events-none absolute -bottom-px -right-px z-10 h-2.5 w-2.5 border-b border-r border-foreground"
|
|
18
|
+
aria-hidden="true"
|
|
19
|
+
/>
|
|
20
|
+
</>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Show, type Component } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
export interface SvedaResizeHandlesProps {
|
|
4
|
+
isMobile: boolean;
|
|
5
|
+
viewMode: string;
|
|
6
|
+
onStartResize: (direction: string, event: PointerEvent) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const SvedaResizeHandles: Component<SvedaResizeHandlesProps> = props => {
|
|
10
|
+
return (
|
|
11
|
+
<Show when={!props.isMobile && (props.viewMode === 'fixed' || props.viewMode === 'floating')}>
|
|
12
|
+
<Show
|
|
13
|
+
when={props.viewMode === 'fixed'}
|
|
14
|
+
fallback={
|
|
15
|
+
<>
|
|
16
|
+
<div
|
|
17
|
+
class="absolute left-0 top-0 z-10 h-3 w-3 touch-none cursor-nw-resize rounded-br hover:bg-primary/20"
|
|
18
|
+
role="separator"
|
|
19
|
+
aria-label="Resize chat"
|
|
20
|
+
onPointerDown={event => props.onStartResize('top-left', event)}
|
|
21
|
+
/>
|
|
22
|
+
<div
|
|
23
|
+
class="absolute left-3 right-3 top-0 z-10 h-1 touch-none cursor-n-resize hover:bg-primary/30"
|
|
24
|
+
role="separator"
|
|
25
|
+
aria-orientation="horizontal"
|
|
26
|
+
aria-label="Resize chat height"
|
|
27
|
+
onPointerDown={event => props.onStartResize('top', event)}
|
|
28
|
+
/>
|
|
29
|
+
<div
|
|
30
|
+
class="absolute bottom-3 left-0 top-3 z-10 w-1 touch-none cursor-w-resize hover:bg-primary/30"
|
|
31
|
+
role="separator"
|
|
32
|
+
aria-orientation="vertical"
|
|
33
|
+
aria-label="Resize chat width"
|
|
34
|
+
onPointerDown={event => props.onStartResize('left', event)}
|
|
35
|
+
/>
|
|
36
|
+
</>
|
|
37
|
+
}
|
|
38
|
+
>
|
|
39
|
+
<div
|
|
40
|
+
class="absolute bottom-3 left-0 top-3 z-10 w-1 touch-none cursor-ew-resize hover:bg-primary/30"
|
|
41
|
+
role="separator"
|
|
42
|
+
aria-orientation="vertical"
|
|
43
|
+
aria-label="Resize chat"
|
|
44
|
+
onPointerDown={event => props.onStartResize('fixed-left', event)}
|
|
45
|
+
/>
|
|
46
|
+
</Show>
|
|
47
|
+
</Show>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSvedaChatStore,
|
|
3
|
+
type SvedaChatHistory,
|
|
4
|
+
type SvedaChatState,
|
|
5
|
+
type SvedaChatStoreSnapshot,
|
|
6
|
+
} from '@sveda-ai/chat';
|
|
7
|
+
import { createEffect, createMemo, createSignal, onCleanup } from 'solid-js';
|
|
8
|
+
import { useSvedaT } from '../i18n/index';
|
|
9
|
+
import { SVEDA_EMBED_AUTH_EVENT, useSvedaContext } from '../provider';
|
|
10
|
+
|
|
11
|
+
export type { SvedaChatHistory, SvedaChatState };
|
|
12
|
+
|
|
13
|
+
let initialized = false;
|
|
14
|
+
let subscribed = false;
|
|
15
|
+
|
|
16
|
+
const store = getSvedaChatStore({ embedAuthEvent: SVEDA_EMBED_AUTH_EVENT });
|
|
17
|
+
|
|
18
|
+
export function useSvedaChat() {
|
|
19
|
+
const ctx = useSvedaContext();
|
|
20
|
+
const t = useSvedaT();
|
|
21
|
+
|
|
22
|
+
const [snapshot, setSnapshot] = createSignal<SvedaChatStoreSnapshot>(store.getState());
|
|
23
|
+
const [revision, setRevision] = createSignal(0);
|
|
24
|
+
|
|
25
|
+
if (!subscribed) {
|
|
26
|
+
subscribed = true;
|
|
27
|
+
store.subscribe(() => {
|
|
28
|
+
setSnapshot(store.getState());
|
|
29
|
+
setRevision(v => v + 1);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
createEffect(() => {
|
|
34
|
+
store.setClient(ctx.client);
|
|
35
|
+
store.setTranslate(t);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!initialized) {
|
|
39
|
+
initialized = true;
|
|
40
|
+
store.initAuthListener();
|
|
41
|
+
void store.loadHistories();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const chatState = createMemo(() => snapshot().chatState);
|
|
45
|
+
const currentChat = createMemo(() => snapshot().currentChat);
|
|
46
|
+
const chatHistories = createMemo(() => snapshot().chatHistories);
|
|
47
|
+
const isOpen = createMemo(() => chatState().isOpen);
|
|
48
|
+
const isMinimized = createMemo(() => chatState().isMinimized);
|
|
49
|
+
const isLoading = createMemo(() => chatState().isLoading);
|
|
50
|
+
const isLoadingChatHistory = createMemo(() => chatState().isLoadingChatHistory);
|
|
51
|
+
const hasCurrentChat = createMemo(() => !!currentChat());
|
|
52
|
+
|
|
53
|
+
const sortedHistories = createMemo(() => {
|
|
54
|
+
revision();
|
|
55
|
+
return store.sortedHistories();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const openChatTabs = createMemo(() => {
|
|
59
|
+
revision();
|
|
60
|
+
return store.openChatTabs();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
onCleanup(() => {
|
|
64
|
+
/* store is a process singleton; keep subscription alive across remounts */
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
chatState,
|
|
69
|
+
currentChat,
|
|
70
|
+
chatHistories,
|
|
71
|
+
sortedHistories,
|
|
72
|
+
openChatTabs,
|
|
73
|
+
isOpen,
|
|
74
|
+
isMinimized,
|
|
75
|
+
isLoading,
|
|
76
|
+
isLoadingChatHistory,
|
|
77
|
+
hasCurrentChat,
|
|
78
|
+
loadHistories: () => store.loadHistories(),
|
|
79
|
+
createNewChat: () => store.createNewChat(t),
|
|
80
|
+
setCurrentChat: (chatId: string) => store.setCurrentChat(chatId, t),
|
|
81
|
+
addMessage: store.addMessage.bind(store),
|
|
82
|
+
setChatTitle: store.setChatTitle.bind(store),
|
|
83
|
+
refreshChatTitleFromServer: store.refreshChatTitleFromServer.bind(store),
|
|
84
|
+
updateMessage: store.updateMessage.bind(store),
|
|
85
|
+
setChatMessages: store.setChatMessages.bind(store),
|
|
86
|
+
incrementChatTokens: store.incrementChatTokens.bind(store),
|
|
87
|
+
setChatContextWindowTokens: store.setChatContextWindowTokens.bind(store),
|
|
88
|
+
deleteChat: (chatId: string) => store.deleteChat(chatId, t),
|
|
89
|
+
renameChat: (chatId: string, title: string) => store.renameChat(chatId, title),
|
|
90
|
+
closeChatTab: (chatId: string) => store.closeChatTab(chatId, t),
|
|
91
|
+
openChat: () => store.openChat(t),
|
|
92
|
+
closeChat: () => store.closeChat(),
|
|
93
|
+
minimizeChat: () => store.minimizeChat(),
|
|
94
|
+
maximizeChat: () => store.maximizeChat(),
|
|
95
|
+
setLoading: (loading: boolean) => store.setLoading(loading),
|
|
96
|
+
};
|
|
97
|
+
}
|