Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(eliza): WIP - settings page + review page revamp #476

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/components/Eliza/CoreEliza.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Text } from './components/Text';
import { pages } from './settings';
import { NewsletterSubscriber } from './components/NewsletterSubscriber';
import type { CaptureEventFn } from './types';
import { FormProviderCharacterBuilder } from './hooks/useElizaForm';

interface ElizaCoreProps {
isLoggedIn: UseDeployAIAgentProps['isLoggedIn'];
Expand Down Expand Up @@ -202,12 +203,14 @@ export const CoreEliza: React.FC<ElizaCoreProps> = ({
<IllustrationIcon className="h-304 animate-pulse pt-48" />
</div>
)}
{steps.map(
(step) =>
step.condition && (
<React.Fragment key={step.id}>{step.content}</React.Fragment>
),
)}
<FormProviderCharacterBuilder>
{steps.map(
(step) =>
step.condition && (
<React.Fragment key={step.id}>{step.content}</React.Fragment>
),
)}
</FormProviderCharacterBuilder>
</Layout>
);
};
28 changes: 1 addition & 27 deletions src/components/Eliza/components/Characterfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import type { GoToProps, Step, Template } from '../utils/types';
import type React from 'react';
import {
INITIAL_FORM,
SECRETS_CLIENT_MAP,
SECRETS_MODEL_PROVIDER_MAP,
SECRETS_PLUGIN_MAP,
TEMPLATE_CHARACTERFILES_MAP,
TEMPLATES,
TEMPLATES_MAP,
Expand All @@ -27,7 +24,6 @@ import { StyleForm } from './StyleForm';
import { FaChevronLeft } from 'react-icons/fa6';
import { useState } from 'react';
import { Input } from './Input';
import type { CharacterFormSchema } from '../utils/schema';
import { pages } from '../settings';
import { PluginsDropdown } from './PluginsDropdown';

Expand Down Expand Up @@ -136,42 +132,20 @@ export const Characterfile: React.FC<CharacterfileProps> = ({
handleSubmit,
formState: { errors },
reset,
setValue,
} = useElizaForm();

const hasErrors = Object.entries(errors).length > 0;

const mapSettingsSecretsAndUpdateForm = (data: CharacterFormSchema) => {
const { modelProvider, clients, plugins } = data;
const model = { ...SECRETS_MODEL_PROVIDER_MAP[modelProvider] };
const client = clients.reduce((acc, client) => {
const clientData = SECRETS_CLIENT_MAP[client];
return { ...acc, ...clientData };
}, {});
const plugin = plugins.reduce((acc, plugin) => {
const pluginData = SECRETS_PLUGIN_MAP[plugin];
return { ...acc, ...pluginData };
}, {});
const updatedSecrets = {
...model,
...client,
...plugin,
...data.settings.secrets,
};
setValue('settings.secrets', updatedSecrets);
};

const onPrevious = () => {
completeStep(0);
reset(INITIAL_FORM);
goTo('getStarted');
};

const onSubmit = (data: CharacterFormSchema) => {
const onSubmit = () => {
if (completedStep === 0) {
completeStep(1);
}
mapSettingsSecretsAndUpdateForm(data);
goTo('settings');
};

Expand Down
30 changes: 26 additions & 4 deletions src/components/Eliza/components/Collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,34 @@ import { cn } from '@utils/cn';
type CollapsibleProps = {
header: React.ReactNode;
details: React.ReactNode;
defaultOpen?: boolean;
container?: boolean;
};

export const Collapsible: React.FC<CollapsibleProps> = ({
header,
details,
defaultOpen = false,
container = false,
}) => {
const [isOpen, setIsOpen] = useState(false);
const [isOpen, setIsOpen] = useState(defaultOpen);

return (
<Box className="gap-4">
<Box
className={cn({
'gap-4': !container,
'gap-0 p-0': container,
})}
variant={container ? 'container' : undefined}
>
<Box
className="cursor-pointer select-none flex-row items-center justify-between gap-16"
className={cn(
'cursor-pointer select-none flex-row items-center justify-between gap-16',
{
'p-16 hover:bg-elz-neutral-2': container,
'border-b border-elz-neutral-6': container && isOpen,
},
)}
onClick={() => setIsOpen((prev) => !prev)}
>
{header}
Expand All @@ -27,7 +43,13 @@ export const Collapsible: React.FC<CollapsibleProps> = ({
/>
</Box>
{isOpen && (
<Box className="duration-200 animate-in fade-in-50 slide-in-from-top-4">
<Box
className={cn({
'duration-200 animate-in fade-in-50 slide-in-from-top-4':
!defaultOpen,
'gap-16 p-16': container,
})}
>
{details}
</Box>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Eliza/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const inputVariants = cva(
isLoading: 'border-elz-neutral-4 animate-pulse bg-elz-neutral-4',
error:
'border-elz-danger-8 focus-within:border-elz-danger-8 focus-within:outline-elz-danger-8',
disabled: 'cursor-not-allowed bg-elz-neutral-3 border-elz-neutral-7',
disabled:
'cursor-not-allowed bg-elz-neutral-3 border-elz-neutral-7 text-elz-neutral-11',
},
},
compoundVariants: [
Expand Down
7 changes: 1 addition & 6 deletions src/components/Eliza/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
type NavigationState,
} from '../utils/types';
import { Characterfile } from './Characterfile';
import { FormProviderCharacterBuilder } from '../hooks/useElizaForm';
import type { UseDeployAIAgentProps } from '../hooks/useDeployAIAgent';
import { SettingsPage } from './SettingsPage';
import { ReviewPage } from './ReviewPage';
Expand Down Expand Up @@ -103,9 +102,5 @@ export const Navigation: React.FC<NavigationProps> = ({
),
};

return (
<FormProviderCharacterBuilder>
{pages[navigationState.page]}
</FormProviderCharacterBuilder>
);
return pages[navigationState.page];
};
Loading