You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.7 KiB
95 lines
3.7 KiB
import {
|
|
personaName,
|
|
PersonaPrompt,
|
|
personaPronounObject,
|
|
personaPronounPossessive,
|
|
personaVerb
|
|
} from "../../datatypes/Persona.js";
|
|
import {InquireFunction, ShowFunction} from "../Inquire.js";
|
|
import {EmpathyGuide} from "../../datatypes/EmpathyGuide.js";
|
|
import {isPopulatedArray} from "../../utils/Arrays.js";
|
|
import {Separator} from "../Inquire.js";
|
|
import {EmpathyGroup} from "../../datatypes/EmpathyGroup.js";
|
|
import {GuidedEmpathy, guidedEmpathyToString, isPopulatedGuidedEmpathy} from "../../datatypes/GuidedEmpathy.js";
|
|
import {HierarchicalCheckboxChildChoice, HierarchicalCheckboxParentChoice, HierarchicalCheckboxQuestion, MultiTextInputQuestion } from "inquirer";
|
|
|
|
export interface GuidedEmpathyPromptOptions extends PersonaPrompt {
|
|
readonly default?: GuidedEmpathy
|
|
}
|
|
|
|
export interface GuidedEmpathyPromptDependencies {
|
|
readonly inquire: InquireFunction<HierarchicalCheckboxQuestion, readonly string[]> & InquireFunction<MultiTextInputQuestion, readonly string[]>
|
|
readonly guideFactory: () => EmpathyGuide,
|
|
readonly show: ShowFunction,
|
|
}
|
|
|
|
export function guidedEmpathyPrompt(deps: GuidedEmpathyPromptDependencies): (options: GuidedEmpathyPromptOptions) => Promise<GuidedEmpathy | null> {
|
|
return (options) => promptForGuidedEmpathy(options, deps)
|
|
}
|
|
|
|
function toChoices(item: EmpathyGroup): HierarchicalCheckboxParentChoice | HierarchicalCheckboxChildChoice {
|
|
const children = item.items
|
|
if (isPopulatedArray(children)) {
|
|
return {
|
|
name: item.header,
|
|
children: item.items.map((child) => ({
|
|
name: child,
|
|
value: child,
|
|
})) as [HierarchicalCheckboxChildChoice, ...HierarchicalCheckboxChildChoice[]],
|
|
showChildren: true,
|
|
}
|
|
} else {
|
|
return {
|
|
name: item.header,
|
|
value: null
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function promptForGuidedEmpathy(options: GuidedEmpathyPromptOptions, deps: GuidedEmpathyPromptDependencies): Promise<GuidedEmpathy | null> {
|
|
const {inquire, guideFactory, show} = deps
|
|
const guide = guideFactory()
|
|
const {default: value = {}, persona} = options
|
|
if (isPopulatedGuidedEmpathy(value)) {
|
|
await show(guidedEmpathyToString(value, persona))
|
|
}
|
|
const feelings = await inquire({
|
|
type: "hierarchical-checkbox",
|
|
message: `What ${personaVerb(persona, "are", "is")} ${personaName(persona)} feeling?`,
|
|
default: value.feelings,
|
|
choices: [
|
|
...guide.feelings?.pleasant?.map(toChoices) || [],
|
|
...isPopulatedArray(guide.feelings?.pleasant) && isPopulatedArray(guide.feelings?.unpleasant) ? [new Separator()] : [],
|
|
...guide.feelings?.unpleasant?.map(toChoices) || [],
|
|
]
|
|
})
|
|
const needs = await inquire({
|
|
type: "hierarchical-checkbox",
|
|
message: `What ${personaVerb(persona, "do", "does")} ${personaName(persona)} need that causes ${personaPronounObject(persona)} to feel that way?`,
|
|
default: value.needs,
|
|
choices: [
|
|
...guide.needs?.map(toChoices) || [],
|
|
]
|
|
})
|
|
const events = await inquire({
|
|
type: "multitext",
|
|
message: `What happened that interacted with ${personaPronounPossessive(persona)} needs?`,
|
|
default: value.events,
|
|
})
|
|
const requests = await inquire({
|
|
type: "multitext",
|
|
message: `What would help get the best outcomes for ${personaPronounObject(persona)} in the future?`,
|
|
default: value.requests,
|
|
})
|
|
const result: GuidedEmpathy = {
|
|
feelings,
|
|
needs,
|
|
events,
|
|
requests,
|
|
}
|
|
if (isPopulatedGuidedEmpathy(result)) {
|
|
return result
|
|
} else {
|
|
return null
|
|
}
|
|
} |