@nextclaw/ui 0.6.10 → 0.6.11
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/.eslintrc.cjs +10 -0
- package/CHANGELOG.md +9 -0
- package/dist/assets/{ChannelsList-TyMb5Mgz.js → ChannelsList-C49JQ-Zt.js} +1 -1
- package/dist/assets/ChatPage-DIx05c6s.js +36 -0
- package/dist/assets/{DocBrowser-CNtrA0ps.js → DocBrowser-CpOosDEI.js} +1 -1
- package/dist/assets/{LogoBadge-BLqiOM5D.js → LogoBadge-CL_8ZPXU.js} +1 -1
- package/dist/assets/MarketplacePage-BOzko5s9.js +49 -0
- package/dist/assets/{ModelConfig-CCsQ8KFq.js → ModelConfig-BZ4ZfaQB.js} +1 -1
- package/dist/assets/ProvidersList-fPpJ5gl6.js +1 -0
- package/dist/assets/{RuntimeConfig-BO6s-ls-.js → RuntimeConfig-Dt9pLB9P.js} +1 -1
- package/dist/assets/{SecretsConfig-mayFdxpM.js → SecretsConfig-C1PU0Yy8.js} +2 -2
- package/dist/assets/{SessionsConfig-DAIczdBj.js → SessionsConfig-EskBOofQ.js} +2 -2
- package/dist/assets/{card-BP5YnL-G.js → card-C7Gtw2Vs.js} +1 -1
- package/dist/assets/index-Cn6_2To7.js +8 -0
- package/dist/assets/{index-BUiahmWm.css → index-nEYGCJTC.css} +1 -1
- package/dist/assets/{input-B1D2QX0O.js → input-oBvxsnV9.js} +1 -1
- package/dist/assets/{label-DW0j-fXA.js → label-C7F8lMpQ.js} +1 -1
- package/dist/assets/{page-layout-Ch-H9gD-.js → page-layout-DO8BlScF.js} +1 -1
- package/dist/assets/session-run-status-Kg0FwAPn.js +3 -0
- package/dist/assets/{switch-_cZHlGKB.js → switch-C6a5GyZB.js} +1 -1
- package/dist/assets/{tabs-custom-ARxqYYjG.js → tabs-custom-BatFap5k.js} +1 -1
- package/dist/assets/{useConfirmDialog-BaU7nIat.js → useConfirmDialog-zJzVKMdu.js} +2 -2
- package/dist/assets/{vendor-C--HHaLf.js → vendor-TlME1INH.js} +84 -84
- package/dist/index.html +3 -3
- package/package.json +4 -2
- package/src/App.tsx +1 -2
- package/src/api/config.ts +199 -200
- package/src/api/types.ts +36 -24
- package/src/components/chat/ChatConversationPanel.tsx +102 -121
- package/src/components/chat/ChatPage.tsx +165 -437
- package/src/components/chat/ChatSidebar.tsx +30 -36
- package/src/components/chat/ChatThread.tsx +73 -131
- package/src/components/chat/chat-input/ChatInputBarView.tsx +82 -0
- package/src/components/chat/chat-input/ChatInputBottomToolbar.tsx +71 -0
- package/src/components/chat/chat-input/components/ChatInputModelStateHint.tsx +39 -0
- package/src/components/chat/chat-input/components/ChatInputSelectedSkillsSection.tsx +31 -0
- package/src/components/chat/chat-input/components/ChatInputSlashPanelSection.tsx +112 -0
- package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputAttachButton.tsx +24 -0
- package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputModelSelector.tsx +58 -0
- package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputSendControls.tsx +56 -0
- package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputSessionTypeSelector.tsx +40 -0
- package/src/components/chat/chat-input/useChatInputBarController.ts +313 -0
- package/src/components/chat/chat-input.types.ts +15 -0
- package/src/components/chat/chat-page-data.ts +121 -0
- package/src/components/chat/chat-page-runtime.ts +221 -0
- package/src/components/chat/chat-session-route.ts +59 -0
- package/src/components/chat/chat-stream/nextbot-parsers.ts +52 -0
- package/src/components/chat/chat-stream/nextbot-runtime-agent.ts +413 -0
- package/src/components/chat/chat-stream/stream-event-adapter.ts +98 -0
- package/src/components/chat/chat-stream/transport.ts +159 -0
- package/src/components/chat/chat-stream/types.ts +76 -0
- package/src/components/chat/managers/chat-input.manager.ts +142 -0
- package/src/components/chat/managers/chat-run-status.manager.ts +32 -0
- package/src/components/chat/managers/chat-session-list.manager.ts +77 -0
- package/src/components/chat/managers/chat-stream-actions.manager.ts +34 -0
- package/src/components/chat/managers/chat-thread.manager.ts +86 -0
- package/src/components/chat/managers/chat-ui.manager.ts +65 -0
- package/src/components/chat/presenter/chat-presenter-context.tsx +25 -0
- package/src/components/chat/presenter/chat.presenter.ts +32 -0
- package/src/components/chat/stores/chat-input.store.ts +62 -0
- package/src/components/chat/stores/chat-run-status.store.ts +30 -0
- package/src/components/chat/stores/chat-session-list.store.ts +34 -0
- package/src/components/chat/stores/chat-thread.store.ts +52 -0
- package/src/components/chat/useChatRuntimeController.ts +134 -0
- package/src/components/chat/useChatSessionTypeState.ts +148 -0
- package/src/components/common/MaskedInput.tsx +1 -1
- package/src/hooks/useConfig.ts +31 -1
- package/src/hooks/useObservable.ts +20 -0
- package/src/lib/chat-message.ts +2 -202
- package/src/lib/chat-runtime-utils.ts +250 -0
- package/src/lib/i18n.ts +9 -0
- package/tsconfig.json +2 -1
- package/vite.config.ts +2 -1
- package/dist/assets/ChatPage-CQerYqvy.js +0 -34
- package/dist/assets/MarketplacePage-CotZxxNe.js +0 -49
- package/dist/assets/ProvidersList-BYYX5K_g.js +0 -1
- package/dist/assets/index-D6_5HaDl.js +0 -7
- package/dist/assets/session-run-status-BUYsQeWs.js +0 -5
- package/src/components/chat/ChatInputBar.tsx +0 -590
- package/src/components/chat/useChatStreamController.ts +0 -591
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { X } from 'lucide-react';
|
|
2
|
+
|
|
3
|
+
type ChatInputSelectedSkillsSectionProps = {
|
|
4
|
+
records: Array<{ spec: string; label: string }>;
|
|
5
|
+
selectedSkills: string[];
|
|
6
|
+
onSelectedSkillsChange: (next: string[]) => void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function ChatInputSelectedSkillsSection(props: ChatInputSelectedSkillsSectionProps) {
|
|
10
|
+
if (props.records.length === 0) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div className="px-4 pb-2">
|
|
16
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
17
|
+
{props.records.map((record) => (
|
|
18
|
+
<button
|
|
19
|
+
key={record.spec}
|
|
20
|
+
type="button"
|
|
21
|
+
onClick={() => props.onSelectedSkillsChange(props.selectedSkills.filter((skill) => skill !== record.spec))}
|
|
22
|
+
className="inline-flex max-w-[200px] items-center gap-1.5 rounded-full bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary"
|
|
23
|
+
>
|
|
24
|
+
<span className="truncate">{record.label}</span>
|
|
25
|
+
<X className="h-3 w-3 shrink-0" />
|
|
26
|
+
</button>
|
|
27
|
+
))}
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
import type { ChatInputBarSlashItem } from '@/components/chat/chat-input.types';
|
|
3
|
+
import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover';
|
|
4
|
+
import { t } from '@/lib/i18n';
|
|
5
|
+
|
|
6
|
+
type ChatInputSlashPanelSectionProps = {
|
|
7
|
+
slashAnchorRef: MutableRefObject<HTMLDivElement | null>;
|
|
8
|
+
slashListRef: MutableRefObject<HTMLDivElement | null>;
|
|
9
|
+
isSlashPanelOpen: boolean;
|
|
10
|
+
isSlashPanelLoading: boolean;
|
|
11
|
+
resolvedSlashPanelWidth?: number;
|
|
12
|
+
skillSlashItems: ChatInputBarSlashItem[];
|
|
13
|
+
activeSlashIndex: number;
|
|
14
|
+
activeSlashItem: ChatInputBarSlashItem | null;
|
|
15
|
+
onSelectSlashItem: (item: ChatInputBarSlashItem) => void;
|
|
16
|
+
onSlashPanelOpenChange: (open: boolean) => void;
|
|
17
|
+
onSetActiveSlashIndex: (index: number) => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function ChatInputSlashPanelSection({
|
|
21
|
+
slashAnchorRef,
|
|
22
|
+
slashListRef,
|
|
23
|
+
isSlashPanelOpen,
|
|
24
|
+
isSlashPanelLoading,
|
|
25
|
+
resolvedSlashPanelWidth,
|
|
26
|
+
skillSlashItems,
|
|
27
|
+
activeSlashIndex,
|
|
28
|
+
activeSlashItem,
|
|
29
|
+
onSelectSlashItem,
|
|
30
|
+
onSlashPanelOpenChange,
|
|
31
|
+
onSetActiveSlashIndex
|
|
32
|
+
}: ChatInputSlashPanelSectionProps) {
|
|
33
|
+
return (
|
|
34
|
+
<Popover open={isSlashPanelOpen} onOpenChange={onSlashPanelOpenChange}>
|
|
35
|
+
<PopoverAnchor asChild>
|
|
36
|
+
<div ref={slashAnchorRef} className="pointer-events-none absolute left-3 right-3 bottom-full h-0" />
|
|
37
|
+
</PopoverAnchor>
|
|
38
|
+
<PopoverContent
|
|
39
|
+
side="top"
|
|
40
|
+
align="start"
|
|
41
|
+
sideOffset={10}
|
|
42
|
+
className="z-[70] max-w-[calc(100vw-1.5rem)] overflow-hidden rounded-2xl border border-gray-200 bg-white/95 p-0 shadow-2xl backdrop-blur-md"
|
|
43
|
+
onOpenAutoFocus={(event) => event.preventDefault()}
|
|
44
|
+
style={resolvedSlashPanelWidth ? { width: `${resolvedSlashPanelWidth}px` } : undefined}
|
|
45
|
+
>
|
|
46
|
+
<div className="grid min-h-[240px] grid-cols-[minmax(260px,340px)_minmax(0,1fr)]">
|
|
47
|
+
<div
|
|
48
|
+
ref={slashListRef}
|
|
49
|
+
className="max-h-[320px] overflow-y-auto border-r border-gray-200 p-3 custom-scrollbar"
|
|
50
|
+
>
|
|
51
|
+
{isSlashPanelLoading ? (
|
|
52
|
+
<div className="p-2 text-xs text-gray-500">{t('chatSlashLoading')}</div>
|
|
53
|
+
) : (
|
|
54
|
+
<>
|
|
55
|
+
<div className="mb-2 px-2 text-[11px] font-semibold uppercase tracking-wide text-gray-500">
|
|
56
|
+
{t('chatSlashSectionSkills')}
|
|
57
|
+
</div>
|
|
58
|
+
{skillSlashItems.length === 0 ? (
|
|
59
|
+
<div className="px-2 text-xs text-gray-400">{t('chatSlashNoResult')}</div>
|
|
60
|
+
) : (
|
|
61
|
+
<div className="space-y-1">
|
|
62
|
+
{skillSlashItems.map((item, index) => {
|
|
63
|
+
const isActive = index === activeSlashIndex;
|
|
64
|
+
return (
|
|
65
|
+
<button
|
|
66
|
+
key={item.key}
|
|
67
|
+
type="button"
|
|
68
|
+
data-slash-index={index}
|
|
69
|
+
onMouseEnter={() => onSetActiveSlashIndex(index)}
|
|
70
|
+
onClick={() => onSelectSlashItem(item)}
|
|
71
|
+
className={`flex w-full items-start gap-2 rounded-lg px-2 py-1.5 text-left transition ${
|
|
72
|
+
isActive ? 'bg-gray-100 text-gray-900' : 'text-gray-700 hover:bg-gray-50'
|
|
73
|
+
}`}
|
|
74
|
+
>
|
|
75
|
+
<span className="truncate text-xs font-semibold">{item.title}</span>
|
|
76
|
+
<span className="truncate text-xs text-gray-500">{item.subtitle}</span>
|
|
77
|
+
</button>
|
|
78
|
+
);
|
|
79
|
+
})}
|
|
80
|
+
</div>
|
|
81
|
+
)}
|
|
82
|
+
</>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
<div className="p-4">
|
|
86
|
+
{activeSlashItem ? (
|
|
87
|
+
<div className="space-y-3">
|
|
88
|
+
<div className="flex items-center gap-2">
|
|
89
|
+
<span className="inline-flex rounded-full bg-primary/10 px-2 py-0.5 text-[11px] font-semibold text-primary">
|
|
90
|
+
{activeSlashItem.subtitle}
|
|
91
|
+
</span>
|
|
92
|
+
<span className="text-sm font-semibold text-gray-900">{activeSlashItem.title}</span>
|
|
93
|
+
</div>
|
|
94
|
+
<p className="text-xs leading-5 text-gray-600">{activeSlashItem.description}</p>
|
|
95
|
+
<div className="space-y-1">
|
|
96
|
+
{activeSlashItem.detailLines.map((line) => (
|
|
97
|
+
<div key={line} className="rounded-md bg-gray-50 px-2 py-1 text-[11px] text-gray-600">
|
|
98
|
+
{line}
|
|
99
|
+
</div>
|
|
100
|
+
))}
|
|
101
|
+
</div>
|
|
102
|
+
<div className="pt-1 text-[11px] text-gray-500">{t('chatSlashSkillHint')}</div>
|
|
103
|
+
</div>
|
|
104
|
+
) : (
|
|
105
|
+
<div className="text-xs text-gray-500">{t('chatSlashHint')}</div>
|
|
106
|
+
)}
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
</PopoverContent>
|
|
110
|
+
</Popover>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
2
|
+
import { t } from '@/lib/i18n';
|
|
3
|
+
import { Paperclip } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
export function ChatInputAttachButton() {
|
|
6
|
+
return (
|
|
7
|
+
<TooltipProvider>
|
|
8
|
+
<Tooltip>
|
|
9
|
+
<TooltipTrigger asChild>
|
|
10
|
+
<button
|
|
11
|
+
type="button"
|
|
12
|
+
disabled
|
|
13
|
+
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-gray-400 cursor-not-allowed"
|
|
14
|
+
>
|
|
15
|
+
<Paperclip className="h-4 w-4" />
|
|
16
|
+
</button>
|
|
17
|
+
</TooltipTrigger>
|
|
18
|
+
<TooltipContent side="top">
|
|
19
|
+
<p className="text-xs">{t('chatInputAttachComingSoon')}</p>
|
|
20
|
+
</TooltipContent>
|
|
21
|
+
</Tooltip>
|
|
22
|
+
</TooltipProvider>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ChatModelOption } from '@/components/chat/chat-input.types';
|
|
2
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
|
3
|
+
import { t } from '@/lib/i18n';
|
|
4
|
+
import { Sparkles } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
type ChatInputModelSelectorProps = {
|
|
7
|
+
modelOptions: ChatModelOption[];
|
|
8
|
+
selectedModel: string;
|
|
9
|
+
selectedModelOption?: ChatModelOption;
|
|
10
|
+
onSelectedModelChange: (value: string) => void;
|
|
11
|
+
isModelOptionsLoading: boolean;
|
|
12
|
+
hasModelOptions: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function ChatInputModelSelector(props: ChatInputModelSelectorProps) {
|
|
16
|
+
return (
|
|
17
|
+
<Select
|
|
18
|
+
value={props.hasModelOptions ? props.selectedModel : undefined}
|
|
19
|
+
onValueChange={props.onSelectedModelChange}
|
|
20
|
+
disabled={!props.hasModelOptions}
|
|
21
|
+
>
|
|
22
|
+
<SelectTrigger className="h-8 w-auto min-w-[220px] rounded-lg border-0 bg-transparent shadow-none text-xs font-medium text-gray-600 hover:bg-gray-100 focus:ring-0 px-3">
|
|
23
|
+
{props.selectedModelOption ? (
|
|
24
|
+
<div className="flex min-w-0 items-center gap-2 text-left">
|
|
25
|
+
<Sparkles className="h-3.5 w-3.5 shrink-0 text-primary" />
|
|
26
|
+
<span className="truncate text-xs font-semibold text-gray-700">
|
|
27
|
+
{props.selectedModelOption.providerLabel}/{props.selectedModelOption.modelLabel}
|
|
28
|
+
</span>
|
|
29
|
+
</div>
|
|
30
|
+
) : props.isModelOptionsLoading ? (
|
|
31
|
+
<div className="h-3 w-24 animate-pulse rounded bg-gray-200" />
|
|
32
|
+
) : (
|
|
33
|
+
<SelectValue placeholder={t('chatSelectModel')} />
|
|
34
|
+
)}
|
|
35
|
+
</SelectTrigger>
|
|
36
|
+
<SelectContent className="w-[320px]">
|
|
37
|
+
{props.modelOptions.length === 0 &&
|
|
38
|
+
(props.isModelOptionsLoading ? (
|
|
39
|
+
<div className="space-y-2 px-3 py-2">
|
|
40
|
+
<div className="h-3 w-36 animate-pulse rounded bg-gray-200" />
|
|
41
|
+
<div className="h-3 w-28 animate-pulse rounded bg-gray-200" />
|
|
42
|
+
<div className="h-3 w-32 animate-pulse rounded bg-gray-200" />
|
|
43
|
+
</div>
|
|
44
|
+
) : (
|
|
45
|
+
<div className="px-3 py-2 text-xs text-gray-500">{t('chatModelNoOptions')}</div>
|
|
46
|
+
))}
|
|
47
|
+
{props.modelOptions.map((option) => (
|
|
48
|
+
<SelectItem key={option.value} value={option.value} className="py-2">
|
|
49
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
50
|
+
<span className="truncate text-xs font-semibold text-gray-800">{option.modelLabel}</span>
|
|
51
|
+
<span className="truncate text-[11px] text-gray-500">{option.providerLabel}</span>
|
|
52
|
+
</div>
|
|
53
|
+
</SelectItem>
|
|
54
|
+
))}
|
|
55
|
+
</SelectContent>
|
|
56
|
+
</Select>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Button } from '@/components/ui/button';
|
|
2
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
3
|
+
import { ArrowUp, Square } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
type ChatInputSendControlsProps = {
|
|
6
|
+
sendError?: string | null;
|
|
7
|
+
draft: string;
|
|
8
|
+
hasModelOptions: boolean;
|
|
9
|
+
sessionTypeUnavailable: boolean;
|
|
10
|
+
isSending: boolean;
|
|
11
|
+
canStopGeneration: boolean;
|
|
12
|
+
resolvedStopHint: string;
|
|
13
|
+
onSend: () => Promise<void> | void;
|
|
14
|
+
onStop: () => Promise<void> | void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function ChatInputSendControls(props: ChatInputSendControlsProps) {
|
|
18
|
+
return (
|
|
19
|
+
<div className="flex flex-col items-end gap-1">
|
|
20
|
+
{props.sendError?.trim() && <div className="max-w-[420px] text-right text-[11px] text-red-600">{props.sendError}</div>}
|
|
21
|
+
<div className="flex items-center gap-2">
|
|
22
|
+
{props.isSending ? (
|
|
23
|
+
props.canStopGeneration ? (
|
|
24
|
+
<Button size="icon" variant="outline" className="h-8 w-8 rounded-full" onClick={() => void props.onStop()}>
|
|
25
|
+
<Square className="h-3 w-3 fill-current" />
|
|
26
|
+
</Button>
|
|
27
|
+
) : (
|
|
28
|
+
<TooltipProvider>
|
|
29
|
+
<Tooltip>
|
|
30
|
+
<TooltipTrigger asChild>
|
|
31
|
+
<span>
|
|
32
|
+
<Button size="icon" variant="outline" className="h-8 w-8 rounded-full" disabled>
|
|
33
|
+
<Square className="h-3 w-3 fill-current" />
|
|
34
|
+
</Button>
|
|
35
|
+
</span>
|
|
36
|
+
</TooltipTrigger>
|
|
37
|
+
<TooltipContent side="top">
|
|
38
|
+
<p className="text-xs">{props.resolvedStopHint}</p>
|
|
39
|
+
</TooltipContent>
|
|
40
|
+
</Tooltip>
|
|
41
|
+
</TooltipProvider>
|
|
42
|
+
)
|
|
43
|
+
) : (
|
|
44
|
+
<Button
|
|
45
|
+
size="icon"
|
|
46
|
+
className="h-8 w-8 rounded-full"
|
|
47
|
+
onClick={() => void props.onSend()}
|
|
48
|
+
disabled={props.draft.trim().length === 0 || !props.hasModelOptions || props.sessionTypeUnavailable}
|
|
49
|
+
>
|
|
50
|
+
<ArrowUp className="h-5 w-5" />
|
|
51
|
+
</Button>
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
package/src/components/chat/chat-input/components/bottom-toolbar/ChatInputSessionTypeSelector.tsx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
|
2
|
+
import { t } from '@/lib/i18n';
|
|
3
|
+
|
|
4
|
+
type ChatInputSessionTypeSelectorProps = {
|
|
5
|
+
shouldShowSessionTypeSelector: boolean;
|
|
6
|
+
selectedSessionType?: string;
|
|
7
|
+
selectedSessionTypeOption: { value: string; label: string } | null;
|
|
8
|
+
sessionTypeOptions: Array<{ value: string; label: string }>;
|
|
9
|
+
onSelectedSessionTypeChange: (value: string) => void;
|
|
10
|
+
canEditSessionType: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function ChatInputSessionTypeSelector(props: ChatInputSessionTypeSelectorProps) {
|
|
14
|
+
if (!props.shouldShowSessionTypeSelector) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Select
|
|
20
|
+
value={props.selectedSessionType}
|
|
21
|
+
onValueChange={props.onSelectedSessionTypeChange}
|
|
22
|
+
disabled={!props.canEditSessionType}
|
|
23
|
+
>
|
|
24
|
+
<SelectTrigger className="h-8 w-auto min-w-[140px] rounded-lg border-0 bg-transparent shadow-none text-xs font-medium text-gray-600 hover:bg-gray-100 focus:ring-0 px-3">
|
|
25
|
+
{props.selectedSessionTypeOption ? (
|
|
26
|
+
<span className="truncate text-xs font-semibold text-gray-700">{props.selectedSessionTypeOption.label}</span>
|
|
27
|
+
) : (
|
|
28
|
+
<SelectValue placeholder={t('chatSessionTypeLabel')} />
|
|
29
|
+
)}
|
|
30
|
+
</SelectTrigger>
|
|
31
|
+
<SelectContent className="w-[220px]">
|
|
32
|
+
{props.sessionTypeOptions.map((option) => (
|
|
33
|
+
<SelectItem key={option.value} value={option.value} className="py-2">
|
|
34
|
+
<span className="truncate text-xs font-semibold text-gray-800">{option.label}</span>
|
|
35
|
+
</SelectItem>
|
|
36
|
+
))}
|
|
37
|
+
</SelectContent>
|
|
38
|
+
</Select>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { KeyboardEvent } from 'react';
|
|
3
|
+
import type { MarketplaceInstalledRecord } from '@/api/types';
|
|
4
|
+
import { t } from '@/lib/i18n';
|
|
5
|
+
import type { ChatInputBarSlashItem } from '@/components/chat/chat-input.types';
|
|
6
|
+
|
|
7
|
+
const SLASH_PANEL_MAX_WIDTH = 920;
|
|
8
|
+
|
|
9
|
+
type RankedSkill = {
|
|
10
|
+
record: MarketplaceInstalledRecord;
|
|
11
|
+
score: number;
|
|
12
|
+
order: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type UseChatInputBarControllerParams = {
|
|
16
|
+
draft: string;
|
|
17
|
+
onDraftChange: (value: string) => void;
|
|
18
|
+
onSend: () => Promise<void> | void;
|
|
19
|
+
onStop: () => Promise<void> | void;
|
|
20
|
+
canStopGeneration: boolean;
|
|
21
|
+
isSending: boolean;
|
|
22
|
+
skillRecords: MarketplaceInstalledRecord[];
|
|
23
|
+
isSkillsLoading: boolean;
|
|
24
|
+
selectedSkills: string[];
|
|
25
|
+
onSelectedSkillsChange: (next: string[]) => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type SlashPanelControllerParams = {
|
|
29
|
+
draft: string;
|
|
30
|
+
onDraftChange: (value: string) => void;
|
|
31
|
+
onSend: () => Promise<void> | void;
|
|
32
|
+
onStop: () => Promise<void> | void;
|
|
33
|
+
isSending: boolean;
|
|
34
|
+
canStopGeneration: boolean;
|
|
35
|
+
isSkillsLoading: boolean;
|
|
36
|
+
selectedSkills: string[];
|
|
37
|
+
onSelectedSkillsChange: (next: string[]) => void;
|
|
38
|
+
skillRecords: MarketplaceInstalledRecord[];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function resolveSlashQuery(draft: string): string | null {
|
|
42
|
+
const match = /^\/([^\s]*)$/.exec(draft);
|
|
43
|
+
if (!match) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return (match[1] ?? '').trim().toLowerCase();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function normalizeSearchText(value: string | null | undefined): string {
|
|
50
|
+
return (value ?? '').trim().toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isSubsequenceMatch(query: string, target: string): boolean {
|
|
54
|
+
if (!query || !target) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
let pointer = 0;
|
|
58
|
+
for (const char of target) {
|
|
59
|
+
if (char === query[pointer]) {
|
|
60
|
+
pointer += 1;
|
|
61
|
+
if (pointer >= query.length) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function scoreSkillRecord(record: MarketplaceInstalledRecord, query: string): number {
|
|
70
|
+
const normalizedQuery = normalizeSearchText(query);
|
|
71
|
+
if (!normalizedQuery) {
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const spec = normalizeSearchText(record.spec);
|
|
76
|
+
const label = normalizeSearchText(record.label || record.spec);
|
|
77
|
+
const description = normalizeSearchText(`${record.descriptionZh ?? ''} ${record.description ?? ''}`);
|
|
78
|
+
const labelTokens = label.split(/[\s/_-]+/).filter(Boolean);
|
|
79
|
+
|
|
80
|
+
if (spec === normalizedQuery) {
|
|
81
|
+
return 1200;
|
|
82
|
+
}
|
|
83
|
+
if (label === normalizedQuery) {
|
|
84
|
+
return 1150;
|
|
85
|
+
}
|
|
86
|
+
if (spec.startsWith(normalizedQuery)) {
|
|
87
|
+
return 1000;
|
|
88
|
+
}
|
|
89
|
+
if (label.startsWith(normalizedQuery)) {
|
|
90
|
+
return 950;
|
|
91
|
+
}
|
|
92
|
+
if (labelTokens.some((token) => token.startsWith(normalizedQuery))) {
|
|
93
|
+
return 900;
|
|
94
|
+
}
|
|
95
|
+
if (spec.includes(normalizedQuery)) {
|
|
96
|
+
return 800;
|
|
97
|
+
}
|
|
98
|
+
if (label.includes(normalizedQuery)) {
|
|
99
|
+
return 760;
|
|
100
|
+
}
|
|
101
|
+
if (description.includes(normalizedQuery)) {
|
|
102
|
+
return 500;
|
|
103
|
+
}
|
|
104
|
+
if (isSubsequenceMatch(normalizedQuery, label) || isSubsequenceMatch(normalizedQuery, spec)) {
|
|
105
|
+
return 300;
|
|
106
|
+
}
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function buildSkillSlashItems(skillRecords: MarketplaceInstalledRecord[], normalizedSlashQuery: string): ChatInputBarSlashItem[] {
|
|
111
|
+
const skillSortCollator = new Intl.Collator(undefined, { sensitivity: 'base', numeric: true });
|
|
112
|
+
const rankedRecords: RankedSkill[] = skillRecords
|
|
113
|
+
.map((record, order) => ({
|
|
114
|
+
record,
|
|
115
|
+
score: scoreSkillRecord(record, normalizedSlashQuery),
|
|
116
|
+
order
|
|
117
|
+
}))
|
|
118
|
+
.filter((entry) => entry.score > 0)
|
|
119
|
+
.sort((left, right) => {
|
|
120
|
+
if (right.score !== left.score) {
|
|
121
|
+
return right.score - left.score;
|
|
122
|
+
}
|
|
123
|
+
const leftLabel = (left.record.label || left.record.spec).trim();
|
|
124
|
+
const rightLabel = (right.record.label || right.record.spec).trim();
|
|
125
|
+
const labelCompare = skillSortCollator.compare(leftLabel, rightLabel);
|
|
126
|
+
if (labelCompare !== 0) {
|
|
127
|
+
return labelCompare;
|
|
128
|
+
}
|
|
129
|
+
return left.order - right.order;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return rankedRecords
|
|
133
|
+
.map((entry) => entry.record)
|
|
134
|
+
.map((record) => ({
|
|
135
|
+
kind: 'skill',
|
|
136
|
+
key: `skill:${record.spec}`,
|
|
137
|
+
title: record.label || record.spec,
|
|
138
|
+
subtitle: t('chatSlashTypeSkill'),
|
|
139
|
+
description: (record.descriptionZh ?? record.description ?? '').trim() || t('chatSkillsPickerNoDescription'),
|
|
140
|
+
detailLines: [`${t('chatSlashSkillSpec')}: ${record.spec}`],
|
|
141
|
+
skillSpec: record.spec
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function useSlashPanelController(params: SlashPanelControllerParams) {
|
|
146
|
+
const [activeSlashIndex, setActiveSlashIndex] = useState(0);
|
|
147
|
+
const [dismissedSlashPanel, setDismissedSlashPanel] = useState(false);
|
|
148
|
+
const [slashPanelWidth, setSlashPanelWidth] = useState<number | null>(null);
|
|
149
|
+
|
|
150
|
+
const slashAnchorRef = useRef<HTMLDivElement | null>(null);
|
|
151
|
+
const slashListRef = useRef<HTMLDivElement | null>(null);
|
|
152
|
+
|
|
153
|
+
const slashQuery = useMemo(() => resolveSlashQuery(params.draft), [params.draft]);
|
|
154
|
+
const startsWithSlash = params.draft.startsWith('/');
|
|
155
|
+
const normalizedSlashQuery = slashQuery ?? '';
|
|
156
|
+
|
|
157
|
+
const skillSlashItems = useMemo(
|
|
158
|
+
() => buildSkillSlashItems(params.skillRecords, normalizedSlashQuery),
|
|
159
|
+
[normalizedSlashQuery, params.skillRecords]
|
|
160
|
+
);
|
|
161
|
+
const slashItems = useMemo(() => [...skillSlashItems], [skillSlashItems]);
|
|
162
|
+
const isSlashPanelOpen = slashQuery !== null && !dismissedSlashPanel;
|
|
163
|
+
const activeSlashItem = slashItems[activeSlashIndex] ?? null;
|
|
164
|
+
const isSlashPanelLoading = params.isSkillsLoading;
|
|
165
|
+
const resolvedSlashPanelWidth = slashPanelWidth ? Math.min(slashPanelWidth, SLASH_PANEL_MAX_WIDTH) : undefined;
|
|
166
|
+
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
const anchor = slashAnchorRef.current;
|
|
169
|
+
if (!anchor || typeof ResizeObserver === 'undefined') {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const update = () => {
|
|
173
|
+
setSlashPanelWidth(anchor.getBoundingClientRect().width);
|
|
174
|
+
};
|
|
175
|
+
update();
|
|
176
|
+
const observer = new ResizeObserver(() => update());
|
|
177
|
+
observer.observe(anchor);
|
|
178
|
+
return () => observer.disconnect();
|
|
179
|
+
}, []);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (!isSlashPanelOpen || slashItems.length === 0) {
|
|
183
|
+
setActiveSlashIndex(0);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
setActiveSlashIndex((current) => {
|
|
187
|
+
if (current < 0) {
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
if (current >= slashItems.length) {
|
|
191
|
+
return slashItems.length - 1;
|
|
192
|
+
}
|
|
193
|
+
return current;
|
|
194
|
+
});
|
|
195
|
+
}, [isSlashPanelOpen, slashItems.length]);
|
|
196
|
+
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
if (!startsWithSlash && dismissedSlashPanel) {
|
|
199
|
+
setDismissedSlashPanel(false);
|
|
200
|
+
}
|
|
201
|
+
}, [dismissedSlashPanel, startsWithSlash]);
|
|
202
|
+
|
|
203
|
+
useEffect(() => {
|
|
204
|
+
if (!isSlashPanelOpen || isSlashPanelLoading || slashItems.length === 0) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const container = slashListRef.current;
|
|
208
|
+
if (!container) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const active = container.querySelector<HTMLElement>(`[data-slash-index="${activeSlashIndex}"]`);
|
|
212
|
+
active?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
213
|
+
}, [activeSlashIndex, isSlashPanelLoading, isSlashPanelOpen, slashItems.length]);
|
|
214
|
+
|
|
215
|
+
const handleSelectSlashItem = useCallback((item: ChatInputBarSlashItem) => {
|
|
216
|
+
if (item.kind === 'skill' && item.skillSpec) {
|
|
217
|
+
if (!params.selectedSkills.includes(item.skillSpec)) {
|
|
218
|
+
params.onSelectedSkillsChange([...params.selectedSkills, item.skillSpec]);
|
|
219
|
+
}
|
|
220
|
+
params.onDraftChange('');
|
|
221
|
+
setDismissedSlashPanel(false);
|
|
222
|
+
}
|
|
223
|
+
}, [params]);
|
|
224
|
+
|
|
225
|
+
const onTextareaKeyDown = useCallback((event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
226
|
+
if (isSlashPanelOpen && !event.nativeEvent.isComposing && (event.key === ' ' || event.code === 'Space')) {
|
|
227
|
+
setDismissedSlashPanel(true);
|
|
228
|
+
}
|
|
229
|
+
if (isSlashPanelOpen && slashItems.length > 0) {
|
|
230
|
+
if (event.key === 'ArrowDown') {
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
setActiveSlashIndex((current) => (current + 1) % slashItems.length);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (event.key === 'ArrowUp') {
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
setActiveSlashIndex((current) => (current - 1 + slashItems.length) % slashItems.length);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if ((event.key === 'Enter' && !event.shiftKey) || event.key === 'Tab') {
|
|
241
|
+
event.preventDefault();
|
|
242
|
+
const selected = slashItems[activeSlashIndex];
|
|
243
|
+
if (selected) {
|
|
244
|
+
handleSelectSlashItem(selected);
|
|
245
|
+
}
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (event.key === 'Escape') {
|
|
250
|
+
if (isSlashPanelOpen) {
|
|
251
|
+
event.preventDefault();
|
|
252
|
+
setDismissedSlashPanel(true);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (params.isSending && params.canStopGeneration) {
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
void params.onStop();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
void params.onSend();
|
|
264
|
+
}
|
|
265
|
+
}, [activeSlashIndex, handleSelectSlashItem, isSlashPanelOpen, params, slashItems]);
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
slashAnchorRef,
|
|
269
|
+
slashListRef,
|
|
270
|
+
isSlashPanelOpen,
|
|
271
|
+
isSlashPanelLoading,
|
|
272
|
+
resolvedSlashPanelWidth,
|
|
273
|
+
skillSlashItems,
|
|
274
|
+
activeSlashIndex,
|
|
275
|
+
activeSlashItem,
|
|
276
|
+
onSelectSlashItem: handleSelectSlashItem,
|
|
277
|
+
onSlashPanelOpenChange: (open: boolean) => {
|
|
278
|
+
if (!open) {
|
|
279
|
+
setDismissedSlashPanel(true);
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
onSetActiveSlashIndex: setActiveSlashIndex,
|
|
283
|
+
onTextareaKeyDown
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export function useChatInputBarController(params: UseChatInputBarControllerParams) {
|
|
288
|
+
const selectedSkillRecords = params.selectedSkills.map((spec) => {
|
|
289
|
+
const matched = params.skillRecords.find((record) => record.spec === spec);
|
|
290
|
+
return {
|
|
291
|
+
spec,
|
|
292
|
+
label: matched?.label || spec
|
|
293
|
+
};
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const slashController = useSlashPanelController({
|
|
297
|
+
draft: params.draft,
|
|
298
|
+
onDraftChange: params.onDraftChange,
|
|
299
|
+
onSend: params.onSend,
|
|
300
|
+
onStop: params.onStop,
|
|
301
|
+
isSending: params.isSending,
|
|
302
|
+
canStopGeneration: params.canStopGeneration,
|
|
303
|
+
isSkillsLoading: params.isSkillsLoading,
|
|
304
|
+
selectedSkills: params.selectedSkills,
|
|
305
|
+
onSelectedSkillsChange: params.onSelectedSkillsChange,
|
|
306
|
+
skillRecords: params.skillRecords
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
selectedSkillRecords,
|
|
311
|
+
...slashController
|
|
312
|
+
};
|
|
313
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ChatModelOption = {
|
|
2
|
+
value: string;
|
|
3
|
+
modelLabel: string;
|
|
4
|
+
providerLabel: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ChatInputBarSlashItem = {
|
|
8
|
+
kind: 'skill';
|
|
9
|
+
key: string;
|
|
10
|
+
title: string;
|
|
11
|
+
subtitle: string;
|
|
12
|
+
description: string;
|
|
13
|
+
detailLines: string[];
|
|
14
|
+
skillSpec?: string;
|
|
15
|
+
};
|