import React, { useEffect, useState } from 'react'; import DialogTemplate from '../../ui/DialogTemplate'; import { Dialog } from '../../ui/Dialog.tsx'; import { Input } from '../../ui/Input.tsx'; import { Label } from '../../ui/Label.tsx'; import { cn } from '~/utils/'; import FileUpload from '../NewConversationMenu/FileUpload'; import store from '~/store'; const SetTokenDialog = ({ open, onOpenChange, endpoint }) => { const [token, setToken] = useState(''); const { getToken, saveToken } = store.useToken(endpoint); const defaultTextProps = 'rounded-md border border-gray-300 bg-transparent text-sm shadow-[0_0_10px_rgba(0,0,0,0.10)] outline-none placeholder:text-gray-400 focus:outline-none focus:ring-gray-400 focus:ring-opacity-20 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-400 dark:bg-gray-700 dark:text-gray-50 dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] dark:focus:border-gray-400 dark:focus:outline-none dark:focus:ring-0 dark:focus:ring-gray-400 dark:focus:ring-offset-0'; const submit = () => { saveToken(token); onOpenChange(false); }; useEffect(() => { setToken(getToken() ?? ''); }, [open]); const helpText = { bingAI: ( The Bing Access Token is the "_U" cookie from bing.com. Use dev tools or an extension while logged into the site to view it. ), chatGPTBrowser: ( To get your Access token For ChatGPT 'Free Version', login to{' '} https://chat.openai.com , then visit{' '} https://chat.openai.com/api/auth/session . Copy access token. ), google: ( You need to{' '} Enable Vertex AI {' '} API on Google Cloud, then{' '} Create a Service Account . Make sure to click 'Create and Continue' to give at least the 'Vertex AI User' role. Lastly, create a JSON key to import here. ) }; return ( {endpoint === 'google' ? ( { if (!credentials) { return false; } if ( !credentials.client_email || typeof credentials.client_email !== 'string' || credentials.client_email.length <= 2 ) { return false; } if ( !credentials.project_id || typeof credentials.project_id !== 'string' || credentials.project_id.length <= 2 ) { return false; } if ( !credentials.private_key || typeof credentials.private_key !== 'string' || credentials.private_key.length <= 600 ) { return false; } return true; }} onFileSelected={data => { setToken(JSON.stringify(data)); }} /> ) : ( setToken(e.target.value || '')} placeholder="Set the token." className={cn( defaultTextProps, 'flex h-10 max-h-10 w-full resize-none px-3 py-2 focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0' )} /> )} Your token will be sent to the server, but not saved. {helpText?.[endpoint]} } selection={{ selectHandler: submit, selectClasses: 'bg-green-600 hover:bg-green-700 dark:hover:bg-green-800 text-white', selectText: 'Submit' }} /> ); }; export default SetTokenDialog;