-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(persona): role templates for the guided persona builder (#4253, PR2) #4416
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
Open
M3gA-Mind
wants to merge
3
commits into
tinyhumansai:main
Choose a base branch
from
M3gA-Mind:feat/GH-4253-persona-templates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
101 changes: 101 additions & 0 deletions
101
app/src/components/settings/panels/persona/PersonaGuidedFields.tsx
This file contains hidden or 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,101 @@ | ||
| import { useT } from '../../../../lib/i18n/I18nContext'; | ||
| import { SettingsRow, SettingsTextArea } from '../../controls'; | ||
| import { useSettingsNavigation } from '../../hooks/useSettingsNavigation'; | ||
| import { applyPersonaField, parsePersonaFields, type PersonaFieldKey } from './personaSections'; | ||
| import PersonaTemplatePicker from './PersonaTemplatePicker'; | ||
|
|
||
| interface PersonaGuidedFieldsProps { | ||
| /** The raw SOUL.md text — the single source of truth this view edits. */ | ||
| value: string; | ||
| /** Emit the updated SOUL.md text after a managed section is spliced. */ | ||
| onChange: (nextSoul: string) => void; | ||
| disabled?: boolean; | ||
| } | ||
|
|
||
| interface FieldDef { | ||
| key: PersonaFieldKey; | ||
| labelKey: string; | ||
| placeholderKey: string; | ||
| testId: string; | ||
| } | ||
|
|
||
| const FIELDS: readonly FieldDef[] = [ | ||
| { | ||
| key: 'personality', | ||
| labelKey: 'settings.persona.builder.personalityLabel', | ||
| placeholderKey: 'settings.persona.builder.personalityPlaceholder', | ||
| testId: 'persona-guided-personality', | ||
| }, | ||
| { | ||
| key: 'voice', | ||
| labelKey: 'settings.persona.builder.voiceLabel', | ||
| placeholderKey: 'settings.persona.builder.voicePlaceholder', | ||
| testId: 'persona-guided-voice', | ||
| }, | ||
| { | ||
| key: 'about', | ||
| labelKey: 'settings.persona.builder.aboutLabel', | ||
| placeholderKey: 'settings.persona.builder.aboutPlaceholder', | ||
| testId: 'persona-guided-about', | ||
| }, | ||
| ] as const; | ||
|
|
||
| /** | ||
| * Structured persona editor (issue #4253, PR1). Presents a few friendly fields | ||
| * that map to named `SOUL.md` sections so non-technical users never touch raw | ||
| * markdown. The raw text stays the source of truth: each edit is spliced back | ||
| * into `value` via {@link applyPersonaField} and emitted through `onChange`. | ||
| */ | ||
| const PersonaGuidedFields = ({ value, onChange, disabled = false }: PersonaGuidedFieldsProps) => { | ||
| const { t } = useT(); | ||
| const { navigateToSettings } = useSettingsNavigation(); | ||
| const fields = parsePersonaFields(value); | ||
|
|
||
| return ( | ||
| <div className="px-4 py-3 space-y-4"> | ||
| <p className="text-xs text-content-muted leading-relaxed"> | ||
| {t('settings.persona.builder.intro')} | ||
| </p> | ||
|
|
||
| <PersonaTemplatePicker value={value} onChange={onChange} disabled={disabled} /> | ||
|
|
||
| {FIELDS.map(field => ( | ||
| <SettingsRow | ||
| key={field.key} | ||
| htmlFor={field.testId} | ||
| label={t(field.labelKey)} | ||
| stacked | ||
| control={ | ||
| <SettingsTextArea | ||
| id={field.testId} | ||
| data-testid={field.testId} | ||
| aria-label={t(field.labelKey)} | ||
| value={fields[field.key]} | ||
| rows={3} | ||
| disabled={disabled} | ||
| placeholder={t(field.placeholderKey)} | ||
| onChange={e => onChange(applyPersonaField(value, field.key, e.target.value))} | ||
| /> | ||
| } | ||
| /> | ||
| ))} | ||
|
|
||
| <p className="text-xs text-content-muted leading-relaxed"> | ||
| {t('settings.persona.builder.preservedNote')} | ||
| </p> | ||
|
|
||
| <p className="text-xs text-content-muted leading-relaxed"> | ||
| {t('settings.persona.builder.securityNote')}{' '} | ||
| <button | ||
| type="button" | ||
| data-testid="persona-guided-agent-access" | ||
| className="text-primary-700 hover:underline dark:text-primary-300" | ||
| onClick={() => navigateToSettings('agent-access')}> | ||
| {t('settings.persona.builder.securityLink')} | ||
| </button> | ||
| </p> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default PersonaGuidedFields; |
57 changes: 57 additions & 0 deletions
57
app/src/components/settings/panels/persona/PersonaTemplatePicker.tsx
This file contains hidden or 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,57 @@ | ||
| import { useT } from '../../../../lib/i18n/I18nContext'; | ||
| import { applyTemplate, PERSONA_TEMPLATES } from './personaTemplates'; | ||
|
|
||
| interface PersonaTemplatePickerProps { | ||
| /** Current raw SOUL.md text a template is spliced into. */ | ||
| value: string; | ||
| /** Emit the updated SOUL.md text after a template is applied. */ | ||
| onChange: (nextSoul: string) => void; | ||
| disabled?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Role starting-points for the guided persona builder (issue #4253, PR2). | ||
| * | ||
| * Applying a template fills the Personality and Communication-style fields for a | ||
| * common role (doctor, researcher, executive, teacher, student, family) and | ||
| * leaves the rest of SOUL.md — including the user-specific "About you" — intact. | ||
| * Nothing is persisted until the user saves, so this is a safe starting point. | ||
| */ | ||
| const PersonaTemplatePicker = ({ | ||
| value, | ||
| onChange, | ||
| disabled = false, | ||
| }: PersonaTemplatePickerProps) => { | ||
| const { t } = useT(); | ||
|
|
||
| return ( | ||
| <div className="space-y-2"> | ||
| <div> | ||
| <p className="text-sm font-medium text-content"> | ||
| {t('settings.persona.templates.heading')} | ||
| </p> | ||
| <p className="text-xs text-content-muted leading-relaxed"> | ||
| {t('settings.persona.templates.desc')} | ||
| </p> | ||
| </div> | ||
| <div className="grid grid-cols-2 gap-2 sm:grid-cols-3"> | ||
| {PERSONA_TEMPLATES.map(template => ( | ||
| <button | ||
| key={template.id} | ||
| type="button" | ||
| disabled={disabled} | ||
| data-testid={`persona-template-${template.id}`} | ||
| onClick={() => onChange(applyTemplate(value, template))} | ||
| className="flex flex-col items-start gap-0.5 rounded-lg border border-line-strong bg-surface px-3 py-2 text-left transition-colors hover:border-primary-400 hover:bg-surface-hover disabled:opacity-50"> | ||
| <span className="text-sm font-medium text-content">{t(template.labelKey)}</span> | ||
| <span className="text-[11px] text-content-muted leading-snug"> | ||
| {t(template.descriptionKey)} | ||
| </span> | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default PersonaTemplatePicker; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a new user-facing Persona template action, but the repo instructions require updating
src/openhuman/about_app/for user-facing features, andcatalog_data.rsstill describes Persona Pack only as display name/SOUL editing/mascot settings. Any about/help/capability surface backed by that catalog will omit the template workflow, so please extend the Persona Pack catalog entry/tests alongside this UI addition.Useful? React with 👍 / 👎.