@bavard/agent-config
Advanced tools
Comparing version 0.0.30 to 0.0.32
@@ -1,8 +0,8 @@ | ||
import { IAgentAction } from '../types'; | ||
import { EAgentActionTypes, IAgentAction } from '../types'; | ||
import { IResponseOption } from '../response-options'; | ||
export declare abstract class BaseAgentAction { | ||
readonly name: string; | ||
readonly type: string; | ||
options: IResponseOption[]; | ||
constructor(name: string, type: string); | ||
abstract readonly type: EAgentActionTypes; | ||
constructor(name: string); | ||
abstract toJsonObj(): IAgentAction; | ||
@@ -9,0 +9,0 @@ addHyperlinkOption(text: string, targetLink: string): void; |
@@ -6,5 +6,4 @@ "use strict"; | ||
class BaseAgentAction { | ||
constructor(name, type) { | ||
constructor(name) { | ||
this.name = name; | ||
this.type = type; | ||
this.options = []; | ||
@@ -11,0 +10,0 @@ } |
import { EAgentActionTypes, IEmailAction } from '../types'; | ||
import { BaseAgentAction } from './base-action'; | ||
export declare class EmailAction extends BaseAgentAction { | ||
export declare class EmailAction extends BaseAgentAction implements IEmailAction { | ||
to: string; | ||
from: string; | ||
prompt: string; | ||
static readonly type = EAgentActionTypes.EMAIL_ACTION; | ||
readonly type = EAgentActionTypes.EMAIL_ACTION; | ||
constructor(name: string, to: string, from: string, prompt?: string); | ||
toJsonObj(): IEmailAction; | ||
} |
@@ -12,6 +12,7 @@ "use strict"; | ||
constructor(name, to, from, prompt = '') { | ||
super(name, EmailAction.type); | ||
super(name); | ||
this.to = to; | ||
this.from = from; | ||
this.prompt = prompt; | ||
this.type = types_1.EAgentActionTypes.EMAIL_ACTION; | ||
this.prompt = sanitize_html_1.default(prompt); | ||
@@ -22,3 +23,3 @@ } | ||
return { | ||
type: EmailAction.type, | ||
type: this.type, | ||
name: this.name, | ||
@@ -33,2 +34,1 @@ to: this.to, | ||
exports.EmailAction = EmailAction; | ||
EmailAction.type = types_1.EAgentActionTypes.EMAIL_ACTION; |
import { BaseAgentAction } from './base-action'; | ||
import { EAgentActionTypes, IUtteranceAction } from '../types'; | ||
export declare class UtteranceAction extends BaseAgentAction { | ||
export declare class UtteranceAction extends BaseAgentAction implements IUtteranceAction { | ||
utterance: string; | ||
static readonly type = EAgentActionTypes.UTTERANCE_ACTION; | ||
readonly type = EAgentActionTypes.UTTERANCE_ACTION; | ||
constructor(name: string, utterance: string); | ||
toJsonObj(): IUtteranceAction; | ||
} |
@@ -12,4 +12,5 @@ "use strict"; | ||
constructor(name, utterance) { | ||
super(name, UtteranceAction.type); | ||
super(name); | ||
this.utterance = utterance; | ||
this.type = types_1.EAgentActionTypes.UTTERANCE_ACTION; | ||
this.utterance = sanitize_html_1.default(utterance); | ||
@@ -20,3 +21,3 @@ } | ||
return { | ||
type: UtteranceAction.type, | ||
type: this.type, | ||
name: this.name, | ||
@@ -29,2 +30,1 @@ utterance: this.utterance, | ||
exports.UtteranceAction = UtteranceAction; | ||
UtteranceAction.type = types_1.EAgentActionTypes.UTTERANCE_ACTION; |
import { BaseAgentAction } from './actions/base-action'; | ||
import { IIntent, IAgentConfig, ISlot } from './types'; | ||
import { IResponseOption } from './response-options'; | ||
import { GraphPolicy } from './graph-policy'; | ||
@@ -20,3 +19,2 @@ export declare enum EPolicyType { | ||
private activePolicyName?; | ||
presetResponseOptions: IResponseOption[]; | ||
constructor(projectId: string, uname: string); | ||
@@ -23,0 +21,0 @@ getDefaultPolicyType(): EPolicyType; |
@@ -25,3 +25,2 @@ "use strict"; | ||
this.graphPolicies = new Map(); | ||
this.presetResponseOptions = []; | ||
this.projectId = projectId; | ||
@@ -137,3 +136,2 @@ this.uname = uname; | ||
graphPolicies: [...this.graphPolicies.values()].map((x) => x.toJsonObj()), | ||
presetResponseOptions: [...this.presetResponseOptions], | ||
}; | ||
@@ -165,3 +163,2 @@ return jsonObj; | ||
} | ||
config.presetResponseOptions = jsonObj.presetResponseOptions || []; | ||
jsonObj.activePolicyName && config.setActivePolicyName(jsonObj.activePolicyName); | ||
@@ -168,0 +165,0 @@ return config; |
@@ -41,5 +41,4 @@ import { IResponseOption } from './response-options'; | ||
graphPolicies: IGraphPolicy[]; | ||
presetResponseOptions: IResponseOption[]; | ||
slots: ISlot[]; | ||
} | ||
export {}; |
@@ -6,10 +6,11 @@ "use strict"; | ||
const utterance_action_1 = require("./actions/utterance-action"); | ||
const types_1 = require("./types"); | ||
exports.actionfromJson = (jsonObj) => { | ||
// @TODO: validate jsonObj as an IAgentAction. | ||
switch (jsonObj.type) { | ||
case email_action_1.EmailAction.type: { | ||
case types_1.EAgentActionTypes.EMAIL_ACTION: { | ||
const emailJson = jsonObj; | ||
return new email_action_1.EmailAction(emailJson.name, emailJson.to, emailJson.from, emailJson.prompt); | ||
} | ||
case utterance_action_1.UtteranceAction.type: { | ||
case types_1.EAgentActionTypes.UTTERANCE_ACTION: { | ||
const utteranceJson = jsonObj; | ||
@@ -16,0 +17,0 @@ return new utterance_action_1.UtteranceAction(utteranceJson.name, utteranceJson.utterance); |
{ | ||
"policyName": "Life Apps Bot", | ||
"version": "0.0.30", | ||
"version": "0.0.31", | ||
"rootNode": { | ||
@@ -5,0 +5,0 @@ "nodeId": 1, |
{ | ||
"name": "@bavard/agent-config", | ||
"version": "0.0.30", | ||
"version": "0.0.32", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
{ | ||
"policyName": "Car Bot", | ||
"version": "0.0.30", | ||
"version": "0.0.31", | ||
"rootNode": { | ||
@@ -5,0 +5,0 @@ "nodeId": 1, |
@@ -1,2 +0,2 @@ | ||
import { IAgentAction } from '../types'; | ||
import { EAgentActionTypes, IAgentAction } from '../types'; | ||
import { IResponseOption, IHyperlinkOption } from '../response-options'; | ||
@@ -7,6 +7,6 @@ import { isDeepStrictEqual } from 'util'; | ||
options: IResponseOption[] = []; | ||
abstract readonly type: EAgentActionTypes | ||
constructor( | ||
public readonly name: string, | ||
public readonly type: string | ||
) { } | ||
@@ -13,0 +13,0 @@ |
@@ -5,4 +5,4 @@ import { EAgentActionTypes, IEmailAction } from '../types'; | ||
export class EmailAction extends BaseAgentAction { | ||
public static readonly type = EAgentActionTypes.EMAIL_ACTION; | ||
export class EmailAction extends BaseAgentAction implements IEmailAction { | ||
readonly type = EAgentActionTypes.EMAIL_ACTION; | ||
@@ -14,3 +14,3 @@ constructor( | ||
public prompt = '') { | ||
super(name, EmailAction.type); | ||
super(name); | ||
this.prompt = sanitize(prompt); | ||
@@ -22,3 +22,3 @@ } | ||
return { | ||
type: EmailAction.type, | ||
type: this.type, | ||
name: this.name, | ||
@@ -25,0 +25,0 @@ to: this.to, |
@@ -5,9 +5,9 @@ import { BaseAgentAction } from './base-action'; | ||
export class UtteranceAction extends BaseAgentAction { | ||
public static readonly type = EAgentActionTypes.UTTERANCE_ACTION; | ||
export class UtteranceAction extends BaseAgentAction implements IUtteranceAction { | ||
readonly type = EAgentActionTypes.UTTERANCE_ACTION; | ||
constructor( | ||
name: string, | ||
name: string, | ||
public utterance: string) { | ||
super(name, UtteranceAction.type); | ||
super(name); | ||
this.utterance = sanitize(utterance); | ||
@@ -19,3 +19,3 @@ } | ||
return { | ||
type: UtteranceAction.type, | ||
type: this.type, | ||
name: this.name, | ||
@@ -22,0 +22,0 @@ utterance: this.utterance, |
import { BaseAgentAction } from './actions/base-action'; | ||
import { IIntent, IAgentConfig, ISlot } from './types'; | ||
import { actionfromJson } from './utils'; | ||
import { IResponseOption } from './response-options'; | ||
import { GraphPolicy } from './graph-policy'; | ||
@@ -25,3 +24,2 @@ import _ from 'lodash'; | ||
private activePolicyName?: string; | ||
presetResponseOptions: IResponseOption[] = []; | ||
@@ -163,3 +161,2 @@ constructor(projectId: string, uname: string) { | ||
graphPolicies: [...this.graphPolicies.values()].map((x) => x.toJsonObj()), | ||
presetResponseOptions: [...this.presetResponseOptions], | ||
}; | ||
@@ -201,3 +198,2 @@ return jsonObj; | ||
config.presetResponseOptions = jsonObj.presetResponseOptions || []; | ||
jsonObj.activePolicyName && config.setActivePolicyName(jsonObj.activePolicyName); | ||
@@ -204,0 +200,0 @@ |
@@ -49,4 +49,3 @@ import { IResponseOption } from './response-options'; | ||
graphPolicies: IGraphPolicy[]; | ||
presetResponseOptions: IResponseOption[]; | ||
slots: ISlot[]; | ||
} |
@@ -5,2 +5,3 @@ import { BaseAgentAction } from './actions/base-action'; | ||
import { UtteranceAction } from './actions/utterance-action'; | ||
import { EAgentActionTypes } from './types'; | ||
@@ -10,3 +11,3 @@ export const actionfromJson = (jsonObj: any): BaseAgentAction => { | ||
switch (jsonObj.type) { | ||
case EmailAction.type: { | ||
case EAgentActionTypes.EMAIL_ACTION: { | ||
const emailJson = jsonObj as IEmailAction; | ||
@@ -19,3 +20,3 @@ return new EmailAction( | ||
} | ||
case UtteranceAction.type: { | ||
case EAgentActionTypes.UTTERANCE_ACTION: { | ||
const utteranceJson = jsonObj as IUtteranceAction; | ||
@@ -22,0 +23,0 @@ return new UtteranceAction( |
135172
4118