2023-05-18 11:09:31 -07:00
|
|
|
import * as React from 'react';
|
|
|
|
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
|
|
|
|
import { Check, ChevronRight, Circle } from 'lucide-react';
|
refactor: Encrypt & Expire User Provided Keys, feat: Rate Limiting (#874)
* docs: make_your_own.md formatting fix for mkdocs
* feat: add express-mongo-sanitize
feat: add login/registration rate limiting
* chore: remove unnecessary console log
* wip: remove token handling from localStorage to encrypted DB solution
* refactor: minor change to UserService
* fix mongo query and add keys route to server
* fix backend controllers and simplify schema/crud
* refactor: rename token to key to separate from access/refresh tokens, setTokenDialog -> setKeyDialog
* refactor(schemas): TEndpointOption token -> key
* refactor(api): use new encrypted key retrieval system
* fix(SetKeyDialog): fix key prop error
* fix(abortMiddleware): pass random UUID if messageId is not generated yet for proper error display on frontend
* fix(getUserKey): wrong prop passed in arg, adds error handling
* fix: prevent message without conversationId from saving to DB, prevents branching on the frontend to a new top-level branch
* refactor: change wording of multiple display messages
* refactor(checkExpiry -> checkUserKeyExpiry): move to UserService file
* fix: type imports from common
* refactor(SubmitButton): convert to TS
* refactor(key.ts): change localStorage map key name
* refactor: add new custom tailwind classes to better match openAI colors
* chore: remove unnecessary warning and catch ScreenShot error
* refactor: move userKey frontend logic to hooks and remove use of localStorage and instead query the DB
* refactor: invalidate correct query key, memoize userKey hook, conditionally render SetKeyDialog to avoid unnecessary calls, refactor SubmitButton props and useEffect for showing 'provide key first'
* fix(SetKeyDialog): use enum-like object for expiry values
feat(Dropdown): add optionsClassName to dynamically change dropdown options container classes
* fix: handle edge case where user had provided a key but the server changes to env variable for keys
* refactor(OpenAI/titleConvo): move titling to client to retain authorized credentials in message lifecycle for titling
* fix(azure): handle user_provided keys correctly for azure
* feat: send user Id to OpenAI to differentiate users in completion requests
* refactor(OpenAI/titleConvo): adding tokens helps minimize LLM from using the language in title response
* feat: add delete endpoint for keys
* chore: remove throttling of title
* feat: add 'Data controls' to Settings, add 'Revoke' keys feature in Key Dialog and Data controls
* refactor: reorganize PluginsClient files in langchain format
* feat: use langchain for titling convos
* chore: cleanup titling convo, with fallback to original method, escape braces, use only snippet for language detection
* refactor: move helper functions to appropriate langchain folders for reusability
* fix: userProvidesKey handling for gptPlugins
* fix: frontend handling of plugins key
* chore: cleanup logging and ts-ignore SSE
* fix: forwardRef misuse in DangerButton
* fix(GoogleConfig/FileUpload): localize errors and simplify validation with zod
* fix: cleanup google logging and fix user provided key handling
* chore: remove titling from google
* chore: removing logging from browser endpoint
* wip: fix menu flicker
* feat: useLocalStorage hook
* feat: add Tooltip for UI
* refactor(EndpointMenu): utilize Tooltip and useLocalStorage, remove old 'New Chat' slide-over
* fix(e2e): use testId for endpoint menu trigger
* chore: final touches to EndpointMenu before future refactor to declutter component
* refactor(localization): change select endpoint to open menu and add translations
* chore: add final prop to error message response
* ci: minor edits to facilitate testing
* ci: new e2e test which tests for new key setting/revoking features
2023-09-06 10:46:27 -04:00
|
|
|
import { cn } from '~/utils';
|
2023-02-13 15:58:35 -05:00
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const DropdownMenu = DropdownMenuPrimitive.Root;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
const DropdownMenuSubTrigger = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
2023-05-18 11:09:31 -07:00
|
|
|
inset?: boolean;
|
2023-02-13 15:58:35 -05:00
|
|
|
}
|
2023-08-06 21:30:16 -04:00
|
|
|
>(({ className = '', inset, children, ...props }, ref) => (
|
2023-02-13 15:58:35 -05:00
|
|
|
<DropdownMenuPrimitive.SubTrigger
|
|
|
|
|
ref={ref}
|
|
|
|
|
className={cn(
|
2023-05-19 20:21:34 +05:30
|
|
|
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100 dark:focus:bg-gray-900 dark:data-[state=open]:bg-gray-900',
|
2023-08-06 21:30:16 -04:00
|
|
|
inset ? 'pl-8' : '',
|
2023-07-14 09:36:49 -04:00
|
|
|
className,
|
2023-02-13 15:58:35 -05:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
<ChevronRight className="ml-auto h-4 w-4" />
|
|
|
|
|
</DropdownMenuPrimitive.SubTrigger>
|
2023-05-18 11:09:31 -07:00
|
|
|
));
|
|
|
|
|
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
const DropdownMenuSubContent = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
2023-08-06 21:30:16 -04:00
|
|
|
>(({ className = '', ...props }, ref) => (
|
2023-02-13 15:58:35 -05:00
|
|
|
<DropdownMenuPrimitive.SubContent
|
|
|
|
|
ref={ref}
|
|
|
|
|
className={cn(
|
2023-08-06 21:30:16 -04:00
|
|
|
'z-50 min-w-[8rem] overflow-hidden rounded-md border border-slate-100 bg-white p-1 text-slate-700 shadow-md animate-in slide-in-from-left-1 dark:border-slate-800 dark:bg-slate-800 dark:text-slate-400',
|
2023-07-14 09:36:49 -04:00
|
|
|
className,
|
2023-02-13 15:58:35 -05:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-05-18 11:09:31 -07:00
|
|
|
));
|
|
|
|
|
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
const DropdownMenuContent = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
2023-08-06 21:30:16 -04:00
|
|
|
>(({ className = '', sideOffset = 4, ...props }, ref) => (
|
2023-02-13 15:58:35 -05:00
|
|
|
<DropdownMenuPrimitive.Portal>
|
|
|
|
|
<DropdownMenuPrimitive.Content
|
|
|
|
|
ref={ref}
|
|
|
|
|
sideOffset={sideOffset}
|
|
|
|
|
className={cn(
|
2023-08-06 21:30:16 -04:00
|
|
|
'z-50 min-w-[8rem] overflow-hidden rounded-md border border-slate-100 bg-white p-1 text-slate-700 shadow-md animate-in data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-slate-800 dark:bg-slate-800 dark:text-slate-400',
|
2023-07-14 09:36:49 -04:00
|
|
|
className,
|
2023-02-13 15:58:35 -05:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
</DropdownMenuPrimitive.Portal>
|
2023-05-18 11:09:31 -07:00
|
|
|
));
|
|
|
|
|
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
const DropdownMenuItem = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
2023-05-18 11:09:31 -07:00
|
|
|
inset?: boolean;
|
2023-02-13 15:58:35 -05:00
|
|
|
}
|
2023-08-06 21:30:16 -04:00
|
|
|
>(({ className = '', inset, ...props }, ref) => (
|
2023-02-13 15:58:35 -05:00
|
|
|
<DropdownMenuPrimitive.Item
|
|
|
|
|
ref={ref}
|
|
|
|
|
className={cn(
|
2023-05-19 20:21:34 +05:30
|
|
|
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-gray-900',
|
2023-08-06 21:30:16 -04:00
|
|
|
inset ? 'pl-8' : '',
|
2023-07-14 09:36:49 -04:00
|
|
|
className,
|
2023-02-13 15:58:35 -05:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-05-18 11:09:31 -07:00
|
|
|
));
|
|
|
|
|
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
const DropdownMenuCheckboxItem = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
2023-08-06 21:30:16 -04:00
|
|
|
>(({ className = '', children, checked, ...props }, ref) => (
|
2023-02-13 15:58:35 -05:00
|
|
|
<DropdownMenuPrimitive.CheckboxItem
|
|
|
|
|
ref={ref}
|
|
|
|
|
className={cn(
|
2023-05-19 20:21:34 +05:30
|
|
|
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-gray-900',
|
2023-07-14 09:36:49 -04:00
|
|
|
className,
|
2023-02-13 15:58:35 -05:00
|
|
|
)}
|
|
|
|
|
checked={checked}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
|
|
|
<DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
|
<Check className="h-4 w-4" />
|
|
|
|
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
|
</span>
|
|
|
|
|
{children}
|
|
|
|
|
</DropdownMenuPrimitive.CheckboxItem>
|
2023-05-18 11:09:31 -07:00
|
|
|
));
|
|
|
|
|
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
const DropdownMenuRadioItem = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
2023-08-06 21:30:16 -04:00
|
|
|
>(({ className = '', children, ...props }, ref) => (
|
2023-02-13 15:58:35 -05:00
|
|
|
<DropdownMenuPrimitive.RadioItem
|
|
|
|
|
ref={ref}
|
|
|
|
|
className={cn(
|
2023-06-11 16:34:42 -04:00
|
|
|
className,
|
2023-07-14 09:36:49 -04:00
|
|
|
'relative flex cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm font-medium outline-none focus:bg-slate-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-gray-800',
|
2023-02-13 15:58:35 -05:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
|
|
|
<DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
|
<Circle className="h-2 w-2 fill-current" />
|
|
|
|
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
|
|
|
</span>
|
|
|
|
|
{children}
|
|
|
|
|
</DropdownMenuPrimitive.RadioItem>
|
2023-05-18 11:09:31 -07:00
|
|
|
));
|
|
|
|
|
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
const DropdownMenuLabel = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
2023-05-18 11:09:31 -07:00
|
|
|
inset?: boolean;
|
2023-02-13 15:58:35 -05:00
|
|
|
}
|
2023-08-06 21:30:16 -04:00
|
|
|
>(({ className = '', inset, ...props }, ref) => (
|
2023-02-13 15:58:35 -05:00
|
|
|
<DropdownMenuPrimitive.Label
|
|
|
|
|
ref={ref}
|
|
|
|
|
className={cn(
|
2023-05-18 11:09:31 -07:00
|
|
|
'px-2 py-1.5 text-sm font-semibold text-slate-900 dark:text-slate-300',
|
2023-08-06 21:30:16 -04:00
|
|
|
inset ? 'pl-8' : '',
|
2023-07-14 09:36:49 -04:00
|
|
|
className,
|
2023-02-13 15:58:35 -05:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-05-18 11:09:31 -07:00
|
|
|
));
|
|
|
|
|
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
const DropdownMenuSeparator = React.forwardRef<
|
|
|
|
|
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
|
|
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
2023-08-06 21:30:16 -04:00
|
|
|
>(({ className = '', ...props }, ref) => (
|
2023-02-13 15:58:35 -05:00
|
|
|
<DropdownMenuPrimitive.Separator
|
|
|
|
|
ref={ref}
|
2023-05-19 20:21:34 +05:30
|
|
|
className={cn('-mx-1 my-1 h-px bg-slate-100 dark:bg-gray-900', className)}
|
2023-02-13 15:58:35 -05:00
|
|
|
{...props}
|
|
|
|
|
/>
|
2023-05-18 11:09:31 -07:00
|
|
|
));
|
|
|
|
|
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
|
2023-02-13 15:58:35 -05:00
|
|
|
|
2023-08-06 21:30:16 -04:00
|
|
|
const DropdownMenuShortcut = ({
|
|
|
|
|
className = '',
|
|
|
|
|
...props
|
|
|
|
|
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
2023-02-13 15:58:35 -05:00
|
|
|
return (
|
2023-05-18 11:09:31 -07:00
|
|
|
<span className={cn('ml-auto text-xs tracking-widest text-slate-500', className)} {...props} />
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
DropdownMenuShortcut.displayName = 'DropdownMenuShortcut';
|
2023-02-13 15:58:35 -05:00
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuCheckboxItem,
|
|
|
|
|
DropdownMenuRadioItem,
|
|
|
|
|
DropdownMenuLabel,
|
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
|
DropdownMenuShortcut,
|
|
|
|
|
DropdownMenuGroup,
|
|
|
|
|
DropdownMenuPortal,
|
|
|
|
|
DropdownMenuSub,
|
|
|
|
|
DropdownMenuSubContent,
|
|
|
|
|
DropdownMenuSubTrigger,
|
2023-07-14 09:36:49 -04:00
|
|
|
DropdownMenuRadioGroup,
|
2023-05-18 11:09:31 -07:00
|
|
|
};
|