|
| 1 | +declare module '@nlpjs/nlg' { |
| 2 | + import { Clonable, Container } from '@nlpjs/core'; |
| 3 | + |
| 4 | + interface Answer { |
| 5 | + response: string; |
| 6 | + opts?: Record<string, any>; |
| 7 | + } |
| 8 | + |
| 9 | + interface FindAnswerOptions { |
| 10 | + skipIfSameInput?: boolean; |
| 11 | + ignoreCase?: boolean; |
| 12 | + ignoreStopWords?: boolean; |
| 13 | + } |
| 14 | + |
| 15 | + interface NlgManagerSettings { |
| 16 | + settingsPerLocale?: Record<string, NlgManagerSettings>; |
| 17 | + useNearestLocale?: boolean; |
| 18 | + } |
| 19 | + |
| 20 | + interface NlgManagerAnswer { |
| 21 | + answer: string; |
| 22 | + score: number; |
| 23 | + opts?: Record<string, any>; |
| 24 | + context?: Record<string, any>; |
| 25 | + } |
| 26 | + |
| 27 | + class NlgManager { |
| 28 | + constructor(settings?: NlgManagerSettings, container?: Container); |
| 29 | + |
| 30 | + add(locale: string, intent: string, answer: string, opts?: Record<string, any>): void; |
| 31 | + addAnswer(locale: string, intent: string, answer: string, opts?: Record<string, any>): void; |
| 32 | + filterAnswers(srcInput: {answer: string, opts: string}[]): {answers: {answer: string, opts: string}[]}; |
| 33 | + find(locale: string, intent: string, context?: Record<string, any>, options?: FindAnswerOptions): Promise<NlgManagerAnswer>; |
| 34 | + |
| 35 | + findAnswer(locale: string, intent: string, context?: Record<string, any>, options?: FindAnswerOptions): Promise<Answer | undefined>; |
| 36 | + |
| 37 | + findAllAnswers(locale?: string, intent?: string, context?: Record<string, any>): Array<{answer: string, opts: string}>; |
| 38 | + |
| 39 | + remove(locale: string, intent: string, answer: string, opts?: Record<string, any>): void; |
| 40 | + removeAnswer(locale: string, intent: string, answer: string, opts?: Record<string, any>): void; |
| 41 | + |
| 42 | + isValid(condition: string, context?: Record<string, any>): boolean; |
| 43 | + |
| 44 | + container: Container; |
| 45 | + } |
| 46 | + |
| 47 | + interface ActionManagerSettings { |
| 48 | + container?: Container; |
| 49 | + tag?: string; |
| 50 | + } |
| 51 | + |
| 52 | + interface ActionBundle { |
| 53 | + action: string; |
| 54 | + parameters: any[]; |
| 55 | + } |
| 56 | + |
| 57 | + interface ProcessedAnswer { |
| 58 | + answer?: string | object; |
| 59 | + actions?: ActionBundle[]; |
| 60 | + } |
| 61 | + |
| 62 | + type ActionFunction = (input: ProcessedAnswer, ...parameters: any[]) => Promise<ProcessedAnswer>; |
| 63 | + |
| 64 | + class ActionManager extends Clonable { |
| 65 | + constructor(settings?: ActionManagerSettings, container?: Container); |
| 66 | + |
| 67 | + actions: Record<string, ActionBundle[]>; |
| 68 | + actionsMap: Record<string, ActionFunction>; |
| 69 | + |
| 70 | + registerDefault(): void; |
| 71 | + |
| 72 | + posAction(intent: string, action: string, parameters: any[]): number; |
| 73 | + |
| 74 | + findActions(intent: string): { action: string; parameters: any[]; fn: ActionFunction }[]; |
| 75 | + |
| 76 | + processActions(intent: string, input: string | object): Promise<ProcessedAnswer>; |
| 77 | + |
| 78 | + addAction(intent: string, action: string, parameters: any[], fn?: ActionFunction): void; |
| 79 | + |
| 80 | + removeAction(intent: string, action: string, parameters: any[]): void; |
| 81 | + |
| 82 | + removeActions(intent: string): void; |
| 83 | + |
| 84 | + registerActionInMap(action: string, fn: ActionFunction): void; |
| 85 | + |
| 86 | + removeActionFromMap(action: string): void; |
| 87 | + |
| 88 | + run(srcInput: { intent: string; }, settings?: any): Promise<ProcessedAnswer>; |
| 89 | + |
| 90 | + toJSON(): { settings: ActionManagerSettings; actions: Record<string, ActionBundle[]> }; |
| 91 | + |
| 92 | + fromJSON(json: { settings: ActionManagerSettings; actions: Record<string, ActionBundle[]> }): void; |
| 93 | + } |
| 94 | + |
| 95 | + export { ActionManagerSettings, ActionManager }; |
| 96 | + |
| 97 | + export default NlgManager; |
| 98 | +} |
0 commit comments