-
Notifications
You must be signed in to change notification settings - Fork 3
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
d73dc62
commit 23b15fc
Showing
24 changed files
with
1,788 additions
and
672 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
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
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
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 |
---|---|---|
|
@@ -21,10 +21,10 @@ | |
"husky": "^9.0.11", | ||
"prettier": "^3.2.5", | ||
"prettier-plugin-sql-cst": "^0.11.5", | ||
"prettier-plugin-tailwindcss": "^0.5.14", | ||
"prettier-plugin-tailwindcss": "^0.6.1", | ||
"turbo": "latest" | ||
}, | ||
"packageManager": "[email protected].3", | ||
"packageManager": "[email protected].4", | ||
"engines": { | ||
"node": ">=20" | ||
}, | ||
|
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
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
38 changes: 38 additions & 0 deletions
38
packages/react/src/components/assistant/assistant.stories.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,38 @@ | ||
import type {Meta, StoryObj} from '@storybook/react'; | ||
|
||
import {Assistant as Component} from './assistant'; | ||
|
||
const meta: Meta<typeof Component> = { | ||
component: Component, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Component>; | ||
|
||
export const Main: Story = { | ||
args: { | ||
messages: [ | ||
{ | ||
id: '1', | ||
text: 'this is a message', | ||
role: 'user', | ||
status: 'sent', | ||
avatarUrl: | ||
'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80', | ||
}, | ||
{ | ||
id: '2', | ||
text: 'this is an answer', | ||
role: 'assistant', | ||
status: 'sent', | ||
avatarUrl: | ||
'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80', | ||
}, | ||
], | ||
}, | ||
render: args => ( | ||
<div className="h-screen w-[400px] p-6"> | ||
<Component {...args} /> | ||
</div> | ||
), | ||
}; |
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,96 @@ | ||
import {useState} from 'react'; | ||
import {BotIcon, Button, cn, Spinner} from '@elwood/ui'; | ||
|
||
import ReactMarkdown from 'react-markdown'; | ||
import remarkGfm from 'remark-gfm'; | ||
|
||
export type AssistantMessage = { | ||
id: string | number; | ||
text: string; | ||
role: 'user' | 'them' | 'assistant'; | ||
from?: string; | ||
avatarUrl?: string; | ||
status: 'pending' | 'processing' | 'sent'; | ||
}; | ||
|
||
export type AssistantProps = { | ||
messages: AssistantMessage[]; | ||
className?: string; | ||
footerClassName?: string; | ||
onSubmit(term: string): void; | ||
}; | ||
|
||
export function Assistant(props: AssistantProps) { | ||
const [value, setValue] = useState(''); | ||
|
||
return ( | ||
<div className={cn(props.className, 'size-full flex flex-col')}> | ||
<div className="flex-grow overflow-auto space-y-3"> | ||
{props.messages.map(message => { | ||
return ( | ||
<div | ||
key={`assistant-${message.id}`} | ||
className={cn( | ||
'flex', | ||
message.role === 'user' && 'text-muted-foreground', | ||
)}> | ||
{message.role === 'assistant' && ( | ||
<div className="mr-3 w-6"> | ||
<div className="size-6 flex items-center justify-center text-muted-foreground"> | ||
<BotIcon className="size-6 stroke-current" /> | ||
</div> | ||
</div> | ||
)} | ||
<div> | ||
<header className="font-semibold"> | ||
{message.role === 'user' && 'You'} | ||
{message.role === 'them' && message.from} | ||
{message.role === 'assistant' && 'File Manager'} | ||
</header> | ||
{message.status === 'pending' && ( | ||
<Spinner className="size-3 text-muted" /> | ||
)} | ||
|
||
<ReactMarkdown | ||
remarkPlugins={[remarkGfm]} | ||
components={{}} | ||
className="prose dark:prose-dark"> | ||
{message.text} | ||
</ReactMarkdown> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
|
||
<footer className={cn('', props.footerClassName)}> | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
props.onSubmit(value); | ||
setValue(''); | ||
}}> | ||
<textarea | ||
onChange={e => setValue(e.target.value)} | ||
value={value} | ||
placeholder="Ask File Manager AI a question..." | ||
className="bg-transparent resize-none p-2 flex w-full border rounded text-sm outline-none placeholder:border" | ||
onKeyDown={e => { | ||
switch (e.key) { | ||
case 'Enter': | ||
if (value) { | ||
e.preventDefault(); | ||
props.onSubmit(value); | ||
setValue(''); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
}} | ||
/> | ||
</form> | ||
</footer> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.