-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38df225
commit fcf33dc
Showing
15 changed files
with
219 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Container, View, Text } from "reshaped"; | ||
import { PropsWithChildren } from "react"; | ||
|
||
interface PageProps { | ||
title: string; | ||
} | ||
|
||
export const Page = ({ children, title }: PropsWithChildren<PageProps>) => { | ||
return ( | ||
<Container> | ||
<View gap={4} padding={4}> | ||
<Text variant="title-4">{title}</Text> | ||
{children} | ||
</View> | ||
</Container> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {Text, View, Avatar} from 'reshaped' | ||
export {Page} from './Page' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './base' | ||
export * from "./narrative"; | ||
export * from './elements' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
export {Icebreaker, WithMessages, IceBreakers, ChatPane, MessageInput} from './panes/chat' | ||
export {Message} from './messages/plain' | ||
export { | ||
Icebreaker, | ||
WithMessages, | ||
IceBreakers, | ||
ChatPane, | ||
MessageInput, | ||
} from "./panes/chat"; | ||
export { Message } from "./messages/plain"; | ||
export { ChatHistory } from "./panes/history"; |
49 changes: 49 additions & 0 deletions
49
packages/chat-ui/src/narrative/panes/history/ChatHistory.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { PropsWithChildren } from "react"; | ||
import * as React from "react"; | ||
import { Card, Text, View, ViewProps } from "reshaped"; | ||
import { List } from "./List"; | ||
|
||
interface Props { | ||
href: string; | ||
selected: boolean; | ||
description: string; | ||
} | ||
|
||
const Entry = ({ selected = false, description, href }: Props) => { | ||
return ( | ||
<Card selected={selected} href={href}> | ||
<View padding={2}> | ||
<Text variant="body-3">{description}</Text> | ||
</View> | ||
</Card> | ||
); | ||
}; | ||
|
||
interface WrapperProps { | ||
layout?: ViewProps; | ||
} | ||
|
||
export const ListWrapper = ({ | ||
children, | ||
layout, | ||
}: PropsWithChildren<WrapperProps>) => { | ||
return ( | ||
<View gap={2} {...layout}> | ||
{children} | ||
</View> | ||
); | ||
}; | ||
|
||
interface ListProps { | ||
convos: Props[]; | ||
} | ||
|
||
export const ChatHistory = ({ convos }: ListProps) => { | ||
return ( | ||
<ListWrapper> | ||
<List items={convos} component={Entry} /> | ||
</ListWrapper> | ||
); | ||
}; | ||
ChatHistory.ListWrapper = ListWrapper; | ||
ChatHistory.Entry = Entry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
|
||
interface ListProps<T> { | ||
items: T[]; | ||
component: React.ComponentType<T>; | ||
} | ||
|
||
|
||
export function List<T>({ items, component: Component }: ListProps<T>) { | ||
return ( | ||
<> | ||
{items.map((item, index) => ( | ||
<Component key={index} {...item} /> | ||
))} | ||
</> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ChatHistory } from "./ChatHistory"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
import type {PayloadRequest} from 'payload' | ||
import type {Chat} from "../../payload-types"; | ||
import type { PayloadRequest } from "payload"; | ||
import type { Chat } from "../../payload-types"; | ||
import { get } from "radash"; | ||
|
||
export const queryChats = async (req: PayloadRequest):Promise<Chat[]> => { | ||
const records = await req.payload.find({ | ||
overrideAccess: false, | ||
user: req.user, | ||
collection: 'chats', | ||
where: { "user.email": { equals: req.user?.email } }, | ||
sort: '-sent', | ||
}) | ||
|
||
return records.docs | ||
interface QueryResult { | ||
chats: Chat[]; | ||
transform: (chatId?: string) => Array<{ | ||
description: string; | ||
href: string; | ||
selected: boolean; | ||
}>; | ||
} | ||
|
||
export const queryChats = async (req: PayloadRequest): Promise<QueryResult> => { | ||
const records = await req.payload.find({ | ||
overrideAccess: false, | ||
user: req.user, | ||
collection: "chats", | ||
where: { "user.email": { equals: req.user?.email } }, | ||
sort: "-sent", | ||
}); | ||
|
||
return { | ||
chats: records.docs, | ||
transform: (chatId) => | ||
records.docs.map((c) => ({ | ||
description: c.description ?? "", | ||
href: `/admin/chat/${get(c, "id")}`, | ||
selected: String(get(c, "id")) === chatId, | ||
})), | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import * as React from 'react' | ||
import {use} from 'react' | ||
import {get} from 'radash' | ||
import type {PayloadRequest} from 'payload' | ||
import {queryChats} from '../hooks/queryConversations' | ||
import * as React from "react"; | ||
import { Suspense, use } from "react"; | ||
import type { AdminViewProps, PayloadRequest } from "payload"; | ||
import { queryChats } from "../hooks/queryConversations"; | ||
import { ChatHistory, Page } from "@payload-llm-plugins/chat-ui"; | ||
import { getChatIdFromParams } from "../../payload/getChatIdFromParams"; | ||
import { shake } from "radash"; | ||
|
||
interface ConversationsListProps { | ||
req: PayloadRequest | ||
chatId: undefined | string | number | ||
req: PayloadRequest; | ||
chatId?: string; | ||
} | ||
|
||
export const ConversationsList = ({ req, chatId }: ConversationsListProps) => { | ||
const conversations = queryChats(req) | ||
const UnsafeConvoList = ({ req, chatId }: ConversationsListProps) => { | ||
const conversations = queryChats(req); | ||
|
||
const convos = use(conversations) | ||
return ( | ||
<div className="conversations-list space-y-2"> | ||
{convos?.map((convo) => ( | ||
<a | ||
key={get(convo, 'id')} | ||
href={`./${get(convo, 'id')}`} | ||
data-selected={String(get(convo, 'id')) === String(chatId)} | ||
className="block p-2 bg-white rounded shadow hover:bg-gray-200 " | ||
> | ||
<div className="conversation"> | ||
<p className="text-gray-800">{convo.description}</p> | ||
</div> | ||
</a> | ||
))} | ||
</div> | ||
) | ||
} | ||
const convos = use(conversations); | ||
return <ChatHistory convos={convos.transform(chatId)} />; | ||
}; | ||
|
||
export const ConversationsList = ({ | ||
initPageResult, | ||
params, | ||
}: Pick<AdminViewProps, "params" | "initPageResult">) => { | ||
const chatId = getChatIdFromParams(params); | ||
console.table({ chatId }); | ||
const rest = shake({ chatId }); | ||
return ( | ||
<Page title="Chat History"> | ||
<Suspense fallback={<p>Loading</p>}> | ||
<UnsafeConvoList req={initPageResult.req} {...rest} /> | ||
</Suspense> | ||
</Page> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { AdminViewProps } from "payload"; | ||
|
||
const AfterNavLinks = (props:AdminViewProps) => { | ||
return ( | ||
<ul> | ||
<li> | ||
<a href="/admin/chat/">Chat</a> | ||
</li> | ||
<li> | ||
<a href="/admin/history">History</a> | ||
</li> | ||
</ul> | ||
) | ||
} | ||
|
||
export default AfterNavLinks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ConversationsList } from '@payload-llm-plugins/chat/ChatView' | ||
import { DefaultTemplate } from '@payloadcms/next/templates' | ||
import { AdminViewProps } from 'payload' | ||
|
||
const History: React.FC<AdminViewProps> = (props) => { | ||
const { initPageResult, params, searchParams } = props | ||
|
||
return ( | ||
<DefaultTemplate | ||
i18n={initPageResult.req.i18n} | ||
locale={initPageResult.locale} | ||
params={params} | ||
payload={initPageResult.req.payload} | ||
permissions={initPageResult.permissions} | ||
searchParams={searchParams} | ||
user={initPageResult.req.user || undefined} | ||
visibleEntities={initPageResult.visibleEntities} | ||
> | ||
<ConversationsList {...props} /> | ||
</DefaultTemplate> | ||
) | ||
} | ||
|
||
export default History |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters