diff --git a/packages/models/src/Action.ts b/packages/models/src/Action.ts index c7c7a93c..e88b41b3 100644 --- a/packages/models/src/Action.ts +++ b/packages/models/src/Action.ts @@ -102,12 +102,12 @@ export class ActionBase { // safety for those places which should require it. // TODO: Remove ScoredAction since it doesn't have payload static GetPayload(action: ActionBase | ScoredBase, entityValues: Map): string { - + if (this.useSimplePayload(action)) { let simpleAction = new SimpleAction(action as ActionBase) return simpleAction.renderValue(entityValues) } - + switch (action.actionType) { case ActionTypes.TEXT: { /** @@ -122,8 +122,7 @@ export class ActionBase { } catch (e) { const error = e as Error throw new Error( - `Error when attempting to parse text action payload. This might be an old action which was saved as a string. Please create a new action. ${ - error.message + `Error when attempting to parse text action payload. This might be an old action which was saved as a string. Please create a new action. ${error.message }` ) } @@ -166,7 +165,7 @@ export class ActionBase { return false } - // Return true if text action contains simple payload and no slate document + // Return true if text action contains simple payload and no slate document static useSimplePayload(action: Partial | undefined): boolean { if (action === undefined) { return false @@ -396,7 +395,7 @@ export class SessionAction extends ActionBase { } export class SimpleAction extends ActionBase { - value: string + value: string constructor(action: ActionBase) { super(action) @@ -411,9 +410,8 @@ export class SimpleAction extends ActionBase { renderValue(entityValues: Map): string { let output = this.value - entityValues.forEach((value: string, key: string) => - { - output = output.replace(`{${key}}`, value) + entityValues.forEach((value: string, key: string) => { + output = output.replace(new RegExp(`{${key}}`, 'g'), value) }) return output } diff --git a/packages/ui/src/routes/Apps/App/LogDialogs.tsx b/packages/ui/src/routes/Apps/App/LogDialogs.tsx index 9cc9741e..923d23f6 100644 --- a/packages/ui/src/routes/Apps/App/LogDialogs.tsx +++ b/packages/ui/src/routes/Apps/App/LogDialogs.tsx @@ -279,7 +279,10 @@ class LogDialogs extends React.Component { } @autobind - onCloseChatSessionWindow() { + async onCloseChatSessionWindow() { + // fetch all actions and entities for dynamically generated actions by generative predictor + await ((this.props.fetchAllEntitiesThunkAsync(this.props.app.appId) as any) as Promise) + await ((this.props.fetchAllActionsThunkAsync(this.props.app.appId) as any) as Promise) this.setState({ chatSession: null, isChatSessionWindowOpen: false, @@ -548,7 +551,9 @@ const mapDispatchToProps = (dispatch: any) => { createChatSessionThunkAsync: actionTypes.chat.createChatSessionThunkAsync, deleteLogDialogsThunkAsync: actionTypes.log.deleteLogDialogsThunkAsync, fetchLogDialogAsync: actionTypes.log.fetchLogDialogThunkAsync, - fetchLogDialogsThunkAsync: actionTypes.log.fetchLogDialogsThunkAsync + fetchLogDialogsThunkAsync: actionTypes.log.fetchLogDialogsThunkAsync, + fetchAllActionsThunkAsync: actionTypes.action.fetchAllActionsThunkAsync, + fetchAllEntitiesThunkAsync: actionTypes.entity.fetchAllEntitiesThunkAsync }, dispatch) } const mapStateToProps = (state: State) => {