-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathchat-engines-table.tsx
More file actions
113 lines (106 loc) · 3.34 KB
/
chat-engines-table.tsx
File metadata and controls
113 lines (106 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use client';
import { type ChatEngine, createChatEngine, deleteChatEngine, listChatEngines } from '@/api/chat-engines';
import { actions } from '@/components/cells/actions';
import { boolean } from '@/components/cells/boolean';
import { datetime } from '@/components/cells/datetime';
import { mono } from '@/components/cells/mono';
import { DataTableRemote } from '@/components/data-table-remote';
import { useBootstrapStatus } from '@/components/system/BootstrapStatusProvider';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import type { ColumnDef } from '@tanstack/react-table';
import { createColumnHelper } from '@tanstack/table-core';
import { AlertTriangleIcon, CopyIcon, TrashIcon } from 'lucide-react';
import Link from 'next/link';
import { toast } from 'sonner';
const helper = createColumnHelper<ChatEngine>();
const columns = [
helper.accessor('id', {
header: 'ID',
cell: mono
}),
helper.accessor('name', {
header: 'NAME',
cell: context => <NameLink chatEngine={context.row.original} />
}),
helper.accessor('created_at', {
header: 'CREATED AT',
cell: datetime
}),
helper.accessor('updated_at', {
header: 'UPDATED AT',
cell: datetime
}),
helper.accessor('is_default', {
header: 'IS DEFAULT',
cell: boolean
}),
helper.accessor('is_public', {
header: 'IS PUBLIC',
cell: boolean
}),
helper.display({
header: 'ACTIONS',
cell: actions((chatEngine) => [
{
key: 'clone',
action: async ({ startTransition, router }) => {
const { name, llm_id, fast_llm_id, engine_options } = chatEngine;
createChatEngine({
name: `${name} Copy`, llm_id, fast_llm_id, engine_options,
})
.then(newEngine => {
toast.success('Chat Engine successfully cloned.');
startTransition(() => {
router.push(`/chat-engines/${newEngine.id}`);
});
});
},
icon: <CopyIcon className="size-3" />,
title: 'Clone',
},
{
key: 'delete',
action: async ({ table, setDropdownOpen }) => {
await deleteChatEngine(chatEngine.id);
table.reload?.();
setDropdownOpen(false);
},
title: 'Delete',
icon: <TrashIcon className="size-3" />,
dangerous: {},
},
]),
}),
] as ColumnDef<ChatEngine>[];
export function ChatEnginesTable () {
return (
<DataTableRemote
columns={columns}
apiKey="api.chat-engines.list"
api={listChatEngines}
idColumn="id"
/>
);
}
function NameLink ({ chatEngine }: { chatEngine: ChatEngine }) {
const { need_migration } = useBootstrapStatus();
const kbNotConfigured = !!need_migration.chat_engines_without_kb_configured?.includes(chatEngine.id);
return (
<Link
className="underline font-mono"
href={`/chat-engines/${chatEngine.id}`}
>
{kbNotConfigured && <TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<AlertTriangleIcon className="text-warning inline-flex mr-1 size-3" />
</TooltipTrigger>
<TooltipContent className="text-xs" align="start">
Knowledge Base not configured.
</TooltipContent>
</Tooltip>
</TooltipProvider>}
{chatEngine.name}
</Link>
);
}