diff --git a/src/human-feedback/cli.ts b/src/human-feedback/cli.ts index 39fac158..ad795bfe 100644 --- a/src/human-feedback/cli.ts +++ b/src/human-feedback/cli.ts @@ -6,8 +6,8 @@ import select from '@inquirer/select' import { HumanFeedbackMechanism, HumanFeedbackType, - UserActionMessages, - UserActions + HumanFeedbackUserActionMessages, + HumanFeedbackUserActions } from './feedback' export class HumanFeedbackMechanismCLI< @@ -18,12 +18,12 @@ export class HumanFeedbackMechanismCLI< */ protected async askUser( message: string, - choices: UserActions[] - ): Promise { + choices: HumanFeedbackUserActions[] + ): Promise { return select({ message, choices: choices.map((choice) => ({ - name: UserActionMessages[choice], + name: HumanFeedbackUserActionMessages[choice], value: choice })) }) diff --git a/src/human-feedback/feedback.ts b/src/human-feedback/feedback.ts index 7d1e69dd..f53923d5 100644 --- a/src/human-feedback/feedback.ts +++ b/src/human-feedback/feedback.ts @@ -6,7 +6,7 @@ import { HumanFeedbackMechanismCLI } from './cli' /** * Actions the user can take in the feedback selection prompt. */ -export const UserActions = { +export const HumanFeedbackUserActions = { Accept: 'accept', Edit: 'edit', Decline: 'decline', @@ -14,14 +14,18 @@ export const UserActions = { Exit: 'exit' } as const -export type UserActions = (typeof UserActions)[keyof typeof UserActions] +export type HumanFeedbackUserActions = + (typeof HumanFeedbackUserActions)[keyof typeof HumanFeedbackUserActions] -export const UserActionMessages: Record = { - [UserActions.Accept]: 'Accept the output', - [UserActions.Edit]: 'Edit the output', - [UserActions.Decline]: 'Decline the output', - [UserActions.Select]: 'Select outputs to keep', - [UserActions.Exit]: 'Exit' +export const HumanFeedbackUserActionMessages: Record< + HumanFeedbackUserActions, + string +> = { + [HumanFeedbackUserActions.Accept]: 'Accept the output', + [HumanFeedbackUserActions.Edit]: 'Edit the output', + [HumanFeedbackUserActions.Decline]: 'Decline the output', + [HumanFeedbackUserActions.Select]: 'Select outputs to keep', + [HumanFeedbackUserActions.Exit]: 'Exit' } /** @@ -147,8 +151,8 @@ export abstract class HumanFeedbackMechanism { protected abstract askUser( message: string, - choices: UserActions[] - ): Promise + choices: HumanFeedbackUserActions[] + ): Promise public async interact(response: any): Promise> { const stringified = JSON.stringify(response, null, 2) @@ -160,49 +164,49 @@ export abstract class HumanFeedbackMechanism { 'What would you like to do?' ].join('\n') - const choices: UserActions[] = [] + const choices: HumanFeedbackUserActions[] = [] if ( this._options.type === 'selectN' || this._options.type === 'selectOne' ) { - choices.push(UserActions.Select) + choices.push(HumanFeedbackUserActions.Select) } else { // Case: confirm - choices.push(UserActions.Accept) - choices.push(UserActions.Decline) + choices.push(HumanFeedbackUserActions.Accept) + choices.push(HumanFeedbackUserActions.Decline) } if (this._options.editing) { - choices.push(UserActions.Edit) + choices.push(HumanFeedbackUserActions.Edit) } if (this._options.bail) { - choices.push(UserActions.Exit) + choices.push(HumanFeedbackUserActions.Exit) } const choice = choices.length === 1 - ? UserActions.Select + ? HumanFeedbackUserActions.Select : await this.askUser(msg, choices) const feedback: Record = {} switch (choice) { - case UserActions.Accept: + case HumanFeedbackUserActions.Accept: feedback.accepted = true break - case UserActions.Edit: { + case HumanFeedbackUserActions.Edit: { const editedOutput = await this.edit(stringified) feedback.editedOutput = editedOutput break } - case UserActions.Decline: + case HumanFeedbackUserActions.Decline: feedback.accepted = false break - case UserActions.Select: + case HumanFeedbackUserActions.Select: if (this._options.type === 'selectN') { feedback.selected = await this.selectN(response) } else if (this._options.type === 'selectOne') { @@ -211,7 +215,7 @@ export abstract class HumanFeedbackMechanism { break - case UserActions.Exit: + case HumanFeedbackUserActions.Exit: throw new Error('Exiting...') default: diff --git a/src/human-feedback/slack.ts b/src/human-feedback/slack.ts index d344001a..55e30d3a 100644 --- a/src/human-feedback/slack.ts +++ b/src/human-feedback/slack.ts @@ -5,8 +5,8 @@ import { HumanFeedbackMechanism, HumanFeedbackOptions, HumanFeedbackType, - UserActionMessages, - UserActions + HumanFeedbackUserActionMessages, + HumanFeedbackUserActions } from './feedback' export class HumanFeedbackMechanismSlack< @@ -48,11 +48,13 @@ export class HumanFeedbackMechanismSlack< protected async askUser( message: string, - choices: UserActions[] - ): Promise { + choices: HumanFeedbackUserActions[] + ): Promise { message += '\n\n' message += choices - .map((choice, idx) => `*${idx}* - ${UserActionMessages[choice]}`) + .map( + (choice, idx) => `*${idx}* - ${HumanFeedbackUserActionMessages[choice]}` + ) .join('\n') message += '\n\n' message += 'Reply with the number of your choice.' diff --git a/src/human-feedback/twilio.ts b/src/human-feedback/twilio.ts index 45ae8cbd..42e4085a 100644 --- a/src/human-feedback/twilio.ts +++ b/src/human-feedback/twilio.ts @@ -5,8 +5,8 @@ import { HumanFeedbackMechanism, HumanFeedbackOptions, HumanFeedbackType, - UserActionMessages, - UserActions + HumanFeedbackUserActionMessages, + HumanFeedbackUserActions } from './feedback' export class HumanFeedbackMechanismTwilio< @@ -50,11 +50,13 @@ export class HumanFeedbackMechanismTwilio< protected async askUser( message: string, - choices: UserActions[] - ): Promise { + choices: HumanFeedbackUserActions[] + ): Promise { message += '\n\n' message += choices - .map((choice, idx) => `${idx} - ${UserActionMessages[choice]}`) + .map( + (choice, idx) => `${idx} - ${HumanFeedbackUserActionMessages[choice]}` + ) .join('\n') message += '\n\n' message += 'Reply with the number of your choice.'