refactor: rename symbols

old-agentic-v1^2
Philipp Burckhardt 2023-06-13 18:16:29 -04:00 zatwierdzone przez Travis Fischer
rodzic e722c5b9d7
commit feb95a2665
4 zmienionych plików z 45 dodań i 37 usunięć

Wyświetl plik

@ -6,8 +6,8 @@ import select from '@inquirer/select'
import { import {
HumanFeedbackMechanism, HumanFeedbackMechanism,
HumanFeedbackType, HumanFeedbackType,
UserActionMessages, HumanFeedbackUserActionMessages,
UserActions HumanFeedbackUserActions
} from './feedback' } from './feedback'
export class HumanFeedbackMechanismCLI< export class HumanFeedbackMechanismCLI<
@ -18,12 +18,12 @@ export class HumanFeedbackMechanismCLI<
*/ */
protected async askUser( protected async askUser(
message: string, message: string,
choices: UserActions[] choices: HumanFeedbackUserActions[]
): Promise<UserActions> { ): Promise<HumanFeedbackUserActions> {
return select({ return select({
message, message,
choices: choices.map((choice) => ({ choices: choices.map((choice) => ({
name: UserActionMessages[choice], name: HumanFeedbackUserActionMessages[choice],
value: choice value: choice
})) }))
}) })

Wyświetl plik

@ -6,7 +6,7 @@ import { HumanFeedbackMechanismCLI } from './cli'
/** /**
* Actions the user can take in the feedback selection prompt. * Actions the user can take in the feedback selection prompt.
*/ */
export const UserActions = { export const HumanFeedbackUserActions = {
Accept: 'accept', Accept: 'accept',
Edit: 'edit', Edit: 'edit',
Decline: 'decline', Decline: 'decline',
@ -14,14 +14,18 @@ export const UserActions = {
Exit: 'exit' Exit: 'exit'
} as const } as const
export type UserActions = (typeof UserActions)[keyof typeof UserActions] export type HumanFeedbackUserActions =
(typeof HumanFeedbackUserActions)[keyof typeof HumanFeedbackUserActions]
export const UserActionMessages: Record<UserActions, string> = { export const HumanFeedbackUserActionMessages: Record<
[UserActions.Accept]: 'Accept the output', HumanFeedbackUserActions,
[UserActions.Edit]: 'Edit the output', string
[UserActions.Decline]: 'Decline the output', > = {
[UserActions.Select]: 'Select outputs to keep', [HumanFeedbackUserActions.Accept]: 'Accept the output',
[UserActions.Exit]: 'Exit' [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<T extends HumanFeedbackType> {
protected abstract askUser( protected abstract askUser(
message: string, message: string,
choices: UserActions[] choices: HumanFeedbackUserActions[]
): Promise<UserActions> ): Promise<HumanFeedbackUserActions>
public async interact(response: any): Promise<FeedbackTypeToMetadata<T>> { public async interact(response: any): Promise<FeedbackTypeToMetadata<T>> {
const stringified = JSON.stringify(response, null, 2) const stringified = JSON.stringify(response, null, 2)
@ -160,49 +164,49 @@ export abstract class HumanFeedbackMechanism<T extends HumanFeedbackType> {
'What would you like to do?' 'What would you like to do?'
].join('\n') ].join('\n')
const choices: UserActions[] = [] const choices: HumanFeedbackUserActions[] = []
if ( if (
this._options.type === 'selectN' || this._options.type === 'selectN' ||
this._options.type === 'selectOne' this._options.type === 'selectOne'
) { ) {
choices.push(UserActions.Select) choices.push(HumanFeedbackUserActions.Select)
} else { } else {
// Case: confirm // Case: confirm
choices.push(UserActions.Accept) choices.push(HumanFeedbackUserActions.Accept)
choices.push(UserActions.Decline) choices.push(HumanFeedbackUserActions.Decline)
} }
if (this._options.editing) { if (this._options.editing) {
choices.push(UserActions.Edit) choices.push(HumanFeedbackUserActions.Edit)
} }
if (this._options.bail) { if (this._options.bail) {
choices.push(UserActions.Exit) choices.push(HumanFeedbackUserActions.Exit)
} }
const choice = const choice =
choices.length === 1 choices.length === 1
? UserActions.Select ? HumanFeedbackUserActions.Select
: await this.askUser(msg, choices) : await this.askUser(msg, choices)
const feedback: Record<string, any> = {} const feedback: Record<string, any> = {}
switch (choice) { switch (choice) {
case UserActions.Accept: case HumanFeedbackUserActions.Accept:
feedback.accepted = true feedback.accepted = true
break break
case UserActions.Edit: { case HumanFeedbackUserActions.Edit: {
const editedOutput = await this.edit(stringified) const editedOutput = await this.edit(stringified)
feedback.editedOutput = editedOutput feedback.editedOutput = editedOutput
break break
} }
case UserActions.Decline: case HumanFeedbackUserActions.Decline:
feedback.accepted = false feedback.accepted = false
break break
case UserActions.Select: case HumanFeedbackUserActions.Select:
if (this._options.type === 'selectN') { if (this._options.type === 'selectN') {
feedback.selected = await this.selectN(response) feedback.selected = await this.selectN(response)
} else if (this._options.type === 'selectOne') { } else if (this._options.type === 'selectOne') {
@ -211,7 +215,7 @@ export abstract class HumanFeedbackMechanism<T extends HumanFeedbackType> {
break break
case UserActions.Exit: case HumanFeedbackUserActions.Exit:
throw new Error('Exiting...') throw new Error('Exiting...')
default: default:

Wyświetl plik

@ -5,8 +5,8 @@ import {
HumanFeedbackMechanism, HumanFeedbackMechanism,
HumanFeedbackOptions, HumanFeedbackOptions,
HumanFeedbackType, HumanFeedbackType,
UserActionMessages, HumanFeedbackUserActionMessages,
UserActions HumanFeedbackUserActions
} from './feedback' } from './feedback'
export class HumanFeedbackMechanismSlack< export class HumanFeedbackMechanismSlack<
@ -48,11 +48,13 @@ export class HumanFeedbackMechanismSlack<
protected async askUser( protected async askUser(
message: string, message: string,
choices: UserActions[] choices: HumanFeedbackUserActions[]
): Promise<UserActions> { ): Promise<HumanFeedbackUserActions> {
message += '\n\n' message += '\n\n'
message += choices message += choices
.map((choice, idx) => `*${idx}* - ${UserActionMessages[choice]}`) .map(
(choice, idx) => `*${idx}* - ${HumanFeedbackUserActionMessages[choice]}`
)
.join('\n') .join('\n')
message += '\n\n' message += '\n\n'
message += 'Reply with the number of your choice.' message += 'Reply with the number of your choice.'

Wyświetl plik

@ -5,8 +5,8 @@ import {
HumanFeedbackMechanism, HumanFeedbackMechanism,
HumanFeedbackOptions, HumanFeedbackOptions,
HumanFeedbackType, HumanFeedbackType,
UserActionMessages, HumanFeedbackUserActionMessages,
UserActions HumanFeedbackUserActions
} from './feedback' } from './feedback'
export class HumanFeedbackMechanismTwilio< export class HumanFeedbackMechanismTwilio<
@ -50,11 +50,13 @@ export class HumanFeedbackMechanismTwilio<
protected async askUser( protected async askUser(
message: string, message: string,
choices: UserActions[] choices: HumanFeedbackUserActions[]
): Promise<UserActions> { ): Promise<HumanFeedbackUserActions> {
message += '\n\n' message += '\n\n'
message += choices message += choices
.map((choice, idx) => `${idx} - ${UserActionMessages[choice]}`) .map(
(choice, idx) => `${idx} - ${HumanFeedbackUserActionMessages[choice]}`
)
.join('\n') .join('\n')
message += '\n\n' message += '\n\n'
message += 'Reply with the number of your choice.' message += 'Reply with the number of your choice.'