@bavard/agent-config
Advanced tools
Comparing version 0.0.64 to 0.0.65
import { BaseAgentAction } from './actions/agent/base-action'; | ||
import { IIntent, IAgentConfig, ISlot, IAgentAction } from './types'; | ||
import { GraphPolicy } from './graph-policy'; | ||
import { GraphPolicyV2 } from './graph-policy-v2'; | ||
export declare enum EPolicyType { | ||
DEFAULT_ACTION = "DEFAULT_ACTION", | ||
LEARNED_ACTION = "LEARNED_ACTION", | ||
GRAPH = "GRAPH" | ||
GRAPH = "GRAPH", | ||
GRAPH_V2 = "GRAPH_V2" | ||
} | ||
@@ -20,2 +22,3 @@ export declare class AgentConfig { | ||
private graphPolicies; | ||
private graphPoliciesV2; | ||
private activePolicyName?; | ||
@@ -45,2 +48,7 @@ constructor(projectId: string, uname: string); | ||
setActivePolicyName(name: string): void; | ||
addGraphPolicyV2(policy: GraphPolicyV2): AgentConfig; | ||
deleteGraphPolicyV2(name: string): AgentConfig; | ||
getGraphPoliciesV2(): GraphPolicyV2[]; | ||
getGraphPolicyV2(name: string): GraphPolicyV2 | undefined; | ||
getActiveGraphPolicyV2(): GraphPolicyV2 | undefined; | ||
toJsonObj(): IAgentConfig; | ||
@@ -47,0 +55,0 @@ copy(): AgentConfig; |
@@ -20,2 +20,3 @@ "use strict"; | ||
EPolicyType["GRAPH"] = "GRAPH"; | ||
EPolicyType["GRAPH_V2"] = "GRAPH_V2"; | ||
})(EPolicyType = exports.EPolicyType || (exports.EPolicyType = {})); | ||
@@ -32,2 +33,3 @@ class AgentConfig { | ||
this.graphPolicies = new Map(); | ||
this.graphPoliciesV2 = new Map(); | ||
this.projectId = projectId; | ||
@@ -50,2 +52,6 @@ this.uname = uname; | ||
} | ||
if (this.activePolicyName && | ||
this.graphPoliciesV2.has(this.activePolicyName)) { | ||
return EPolicyType.GRAPH_V2; | ||
} | ||
return EPolicyType.DEFAULT_ACTION; | ||
@@ -163,2 +169,27 @@ } | ||
} | ||
// graph policies V2 | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
addGraphPolicyV2(policy) { | ||
if (this.graphPoliciesV2.size >= constants_1.MAX_GRAPH_POLICY_COUNT) { | ||
throw new Error(`Graph Policy count exceeds maximum count: ${constants_1.MAX_GRAPH_POLICY_COUNT}`); | ||
} | ||
this.graphPoliciesV2.set(policy.name, policy); | ||
return this; | ||
} | ||
deleteGraphPolicyV2(name) { | ||
this.graphPoliciesV2.delete(name); | ||
return this; | ||
} | ||
getGraphPoliciesV2() { | ||
return [...this.graphPoliciesV2.values()]; | ||
} | ||
getGraphPolicyV2(name) { | ||
return this.graphPoliciesV2.get(name); | ||
} | ||
getActiveGraphPolicyV2() { | ||
if (this.activePolicyName && | ||
this.graphPoliciesV2.has(this.activePolicyName)) { | ||
return this.graphPoliciesV2.get(this.activePolicyName); | ||
} | ||
} | ||
// serialization | ||
@@ -165,0 +196,0 @@ toJsonObj() { |
@@ -9,2 +9,3 @@ export declare enum EResponseOptionTypes { | ||
type: EResponseOptionTypes; | ||
nodeId?: number; | ||
intent?: string; | ||
@@ -15,3 +16,3 @@ } | ||
text: string; | ||
intent: string; | ||
intent?: string; | ||
} | ||
@@ -24,3 +25,3 @@ export interface IImageOption extends IResponseOptionBase { | ||
caption?: string; | ||
hyperlink?: string; | ||
targetLink?: string; | ||
imageUrl?: string; | ||
@@ -27,0 +28,0 @@ } |
{ | ||
"name": "@bavard/agent-config", | ||
"version": "0.0.64", | ||
"version": "0.0.65", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -9,2 +9,3 @@ import { BaseAgentAction } from './actions/agent/base-action'; | ||
import { FormAction } from './actions/agent/form-action'; | ||
import { GraphPolicyV2 } from './graph-policy-v2'; | ||
const packageJson = require('../package.json'); | ||
@@ -16,2 +17,3 @@ | ||
GRAPH = 'GRAPH', | ||
GRAPH_V2 = 'GRAPH_V2', | ||
} | ||
@@ -30,2 +32,4 @@ | ||
private graphPolicies: Map<string, GraphPolicy> = new Map(); | ||
private graphPoliciesV2: Map<string, GraphPolicyV2> = new Map(); | ||
private activePolicyName?: string; | ||
@@ -56,2 +60,8 @@ | ||
} | ||
if ( | ||
this.activePolicyName && | ||
this.graphPoliciesV2.has(this.activePolicyName) | ||
) { | ||
return EPolicyType.GRAPH_V2; | ||
} | ||
return EPolicyType.DEFAULT_ACTION; | ||
@@ -196,2 +206,34 @@ } | ||
// graph policies V2 | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
addGraphPolicyV2(policy: GraphPolicyV2): AgentConfig { | ||
if (this.graphPoliciesV2.size >= MAX_GRAPH_POLICY_COUNT) { | ||
throw new Error(`Graph Policy count exceeds maximum count: ${MAX_GRAPH_POLICY_COUNT}`); | ||
} | ||
this.graphPoliciesV2.set(policy.name, policy); | ||
return this; | ||
} | ||
deleteGraphPolicyV2(name: string): AgentConfig { | ||
this.graphPoliciesV2.delete(name); | ||
return this; | ||
} | ||
getGraphPoliciesV2(): GraphPolicyV2[] { | ||
return [...this.graphPoliciesV2.values()]; | ||
} | ||
getGraphPolicyV2(name: string): GraphPolicyV2 | undefined { | ||
return this.graphPoliciesV2.get(name); | ||
} | ||
getActiveGraphPolicyV2(): GraphPolicyV2 | undefined { | ||
if ( | ||
this.activePolicyName && | ||
this.graphPoliciesV2.has(this.activePolicyName) | ||
) { | ||
return this.graphPoliciesV2.get(this.activePolicyName); | ||
} | ||
} | ||
// serialization | ||
@@ -198,0 +240,0 @@ toJsonObj(): IAgentConfig { |
@@ -10,2 +10,3 @@ export enum EResponseOptionTypes { | ||
type: EResponseOptionTypes; | ||
nodeId?: number; | ||
intent?: string; | ||
@@ -17,3 +18,3 @@ } | ||
text: string; | ||
intent: string; | ||
intent?: string; | ||
} | ||
@@ -27,3 +28,3 @@ | ||
caption?: string; | ||
hyperlink?: string; | ||
targetLink?: string; | ||
imageUrl?: string; | ||
@@ -30,0 +31,0 @@ } |
291391
199
8154