Skip to content

Commit

Permalink
ai search!
Browse files Browse the repository at this point in the history
  • Loading branch information
traviskuhl committed Jun 2, 2024
1 parent d73dc62 commit 23b15fc
Show file tree
Hide file tree
Showing 24 changed files with 1,788 additions and 672 deletions.
4 changes: 2 additions & 2 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"@elwood/typescript-config": "workspace:*",
"@elwood/ui": "workspace:*",
"@tanstack/react-query": "^5.40.0",
"@types/node": "^20.12.13",
"@types/node": "^20.13.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.0",
"autoprefixer": "^10.4.19",
"electron": "^30.0.8",
"electron": "^30.0.9",
"electron-builder": "^24.13.3",
"electron-log": "^5.1.5",
"electron-vite": "^2.2.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"@markdoc/next.js": "^0.3.7",
"@sindresorhus/slugify": "^2.2.1",
"@tailwindcss/typography": "^0.5.13",
"@types/node": "^20.12.13",
"@types/node": "^20.13.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-highlight-words": "^0.16.7",
"@types/react-highlight-words": "^0.20.0",
"@vercel/analytics": "^1.3.1",
"autoprefixer": "^10.4.19",
"clsx": "^2.1.1",
Expand Down
3 changes: 1 addition & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
"@elwood/eslint-config": "workspace:*",
"@elwood/typescript-config": "workspace:*",
"@next/eslint-plugin-next": "^14.2.3",
"@types/node": "^20.12.13",
"@types/node": "^20.13.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"prettier-plugin-tailwindcss": "^0.5.14",
"typescript": "^5.4.5"
},
"license": "Apache-2.0"
Expand Down
3 changes: 1 addition & 2 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
"@elwood/eslint-config": "workspace:*",
"@elwood/typescript-config": "workspace:*",
"@next/eslint-plugin-next": "^14.2.3",
"@types/node": "^20.12.13",
"@types/node": "^20.13.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"prettier-plugin-tailwindcss": "^0.5.14",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion config/jest-presets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ts-jest": "^29.1.4"
},
"devDependencies": {
"@types/node": "^20.12.13",
"@types/node": "^20.13.0",
"jest-environment-jsdom": "^29.7.0"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@elwood/jest-presets": "workspace:*",
"@elwood/typescript-config": "workspace:*",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.13",
"@types/node": "^20.13.0",
"jest": "^29.7.0",
"tsup": "^8.0.2",
"typescript": "^5.4.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@elwood/jest-presets": "workspace:*",
"@elwood/typescript-config": "workspace:*",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.13",
"@types/node": "^20.13.0",
"jest": "^29.7.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"tsup": "^8.0.2",
Expand Down
27 changes: 15 additions & 12 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,37 @@
"javascript-time-ago": "^2.5.10",
"react-accessible-treeview": "^2.9.0",
"react-dropzone": "^14.2.3",
"react-markdown": "^9.0.1",
"react-pdf": "^9.0.0",
"react-router-dom": "^6.23.1",
"react-time-ago": "^7.3.3",
"react-use": "^17.5.0"
"react-use": "^17.5.0",
"remark-gfm": "^4.0.0",
"sse.js": "^2.4.1"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.5.0",
"@elwood/eslint-config": "workspace:*",
"@elwood/jest-presets": "workspace:*",
"@elwood/typescript-config": "workspace:*",
"@storybook/addon-essentials": "^8.1.4",
"@storybook/addon-interactions": "^8.1.4",
"@storybook/addon-links": "^8.1.4",
"@storybook/addon-onboarding": "^8.1.4",
"@storybook/addon-themes": "^8.1.4",
"@storybook/blocks": "^8.1.4",
"@storybook/react": "^8.1.4",
"@storybook/react-vite": "^8.1.4",
"@storybook/test": "^8.1.4",
"@storybook/addon-essentials": "^8.1.5",
"@storybook/addon-interactions": "^8.1.5",
"@storybook/addon-links": "^8.1.5",
"@storybook/addon-onboarding": "^8.1.5",
"@storybook/addon-themes": "^8.1.5",
"@storybook/blocks": "^8.1.5",
"@storybook/react": "^8.1.5",
"@storybook/react-vite": "^8.1.5",
"@storybook/test": "^8.1.5",
"@types/crypto-js": "^4.2.2",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.13",
"@types/node": "^20.13.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"jest": "^29.7.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"storybook": "^8.1.4",
"storybook": "^8.1.5",
"tailwindcss": "^3.4.3",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
Expand Down
38 changes: 38 additions & 0 deletions packages/react/src/components/assistant/assistant.stories.tsx
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>
),
};
96 changes: 96 additions & 0 deletions packages/react/src/components/assistant/assistant.tsx
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>
);
}
Loading

0 comments on commit 23b15fc

Please sign in to comment.