@botonic/plugin-flow-builder 0.35.2-alpha.0 → 0.35.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/action/ai-agent.d.ts +3 -0
- package/lib/cjs/action/ai-agent.js +37 -0
- package/lib/cjs/action/ai-agent.js.map +1 -0
- package/lib/cjs/action/index.d.ts +3 -2
- package/lib/cjs/action/index.js +33 -11
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/api.d.ts +1 -0
- package/lib/cjs/api.js +7 -0
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/flow-ai-agent.d.ts +11 -0
- package/lib/cjs/content-fields/flow-ai-agent.js +26 -0
- package/lib/cjs/content-fields/flow-ai-agent.js.map +1 -0
- package/lib/cjs/content-fields/hubtype-fields/ai-agent.d.ts +9 -0
- package/lib/cjs/content-fields/hubtype-fields/ai-agent.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/ai-agent.js.map +1 -0
- package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +2 -1
- package/lib/cjs/content-fields/hubtype-fields/node-types.js +1 -0
- package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +2 -1
- package/lib/cjs/content-fields/index.d.ts +3 -4
- package/lib/cjs/content-fields/index.js +7 -5
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/filters/index.d.ts +12 -0
- package/lib/cjs/filters/index.js +20 -0
- package/lib/cjs/filters/index.js.map +1 -0
- package/lib/cjs/index.d.ts +4 -2
- package/lib/cjs/index.js +5 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +15 -0
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/action/ai-agent.d.ts +3 -0
- package/lib/esm/action/ai-agent.js +33 -0
- package/lib/esm/action/ai-agent.js.map +1 -0
- package/lib/esm/action/index.d.ts +3 -2
- package/lib/esm/action/index.js +36 -14
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/api.d.ts +1 -0
- package/lib/esm/api.js +8 -1
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/flow-ai-agent.d.ts +11 -0
- package/lib/esm/content-fields/flow-ai-agent.js +22 -0
- package/lib/esm/content-fields/flow-ai-agent.js.map +1 -0
- package/lib/esm/content-fields/hubtype-fields/ai-agent.d.ts +9 -0
- package/lib/esm/content-fields/hubtype-fields/ai-agent.js +2 -0
- package/lib/esm/content-fields/hubtype-fields/ai-agent.js.map +1 -0
- package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +2 -1
- package/lib/esm/content-fields/hubtype-fields/node-types.js +1 -0
- package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +2 -1
- package/lib/esm/content-fields/index.d.ts +3 -4
- package/lib/esm/content-fields/index.js +4 -3
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/filters/index.d.ts +12 -0
- package/lib/esm/filters/index.js +16 -0
- package/lib/esm/filters/index.js.map +1 -0
- package/lib/esm/index.d.ts +4 -2
- package/lib/esm/index.js +6 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +15 -0
- package/lib/esm/types.js.map +1 -1
- package/package.json +1 -1
- package/src/action/ai-agent.ts +52 -0
- package/src/action/index.tsx +55 -14
- package/src/api.ts +18 -1
- package/src/constants.ts +1 -0
- package/src/content-fields/flow-ai-agent.tsx +23 -0
- package/src/content-fields/hubtype-fields/ai-agent.ts +10 -0
- package/src/content-fields/hubtype-fields/node-types.ts +1 -0
- package/src/content-fields/hubtype-fields/nodes.ts +2 -0
- package/src/content-fields/index.ts +5 -3
- package/src/filters/index.ts +27 -0
- package/src/index.ts +12 -0
- package/src/types.ts +28 -6
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FlowContent } from '../content-fields'
|
|
2
|
+
import { FlowAiAgent } from '../content-fields/flow-ai-agent'
|
|
3
|
+
import { AiAgentResponse } from '../types'
|
|
4
|
+
import { FlowBuilderContext } from './index'
|
|
5
|
+
|
|
6
|
+
export async function getContentsByAiAgent({
|
|
7
|
+
cmsApi,
|
|
8
|
+
flowBuilderPlugin,
|
|
9
|
+
request,
|
|
10
|
+
}: FlowBuilderContext): Promise<FlowContent[]> {
|
|
11
|
+
const startNodeAiAgentFlow = cmsApi.getStartNodeAiAgentFlow()
|
|
12
|
+
if (!startNodeAiAgentFlow) {
|
|
13
|
+
return []
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const contents =
|
|
17
|
+
await flowBuilderPlugin.getContentsByNode(startNodeAiAgentFlow)
|
|
18
|
+
const aiAgentContent = contents.find(
|
|
19
|
+
content => content instanceof FlowAiAgent
|
|
20
|
+
) as FlowAiAgent
|
|
21
|
+
|
|
22
|
+
if (!aiAgentContent) {
|
|
23
|
+
return []
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const aiAgentResponse = await flowBuilderPlugin.getAiAgentResponse?.(
|
|
27
|
+
request,
|
|
28
|
+
{
|
|
29
|
+
name: aiAgentContent.name,
|
|
30
|
+
instructions: aiAgentContent.instructions,
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
if (!aiAgentResponse) {
|
|
35
|
+
return []
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return updateContentsWithAiAgentResponse(contents, aiAgentResponse)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function updateContentsWithAiAgentResponse(
|
|
42
|
+
contents: FlowContent[],
|
|
43
|
+
aiAgentResponse: AiAgentResponse
|
|
44
|
+
): FlowContent[] {
|
|
45
|
+
return contents.map(content => {
|
|
46
|
+
if (content instanceof FlowAiAgent) {
|
|
47
|
+
content.text = aiAgentResponse.message.content
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return content
|
|
51
|
+
})
|
|
52
|
+
}
|
package/src/action/index.tsx
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { INPUT } from '@botonic/core'
|
|
2
|
-
import {
|
|
1
|
+
import { BotContext, INPUT, isDev, isWebchat } from '@botonic/core'
|
|
2
|
+
import {
|
|
3
|
+
ActionRequest,
|
|
4
|
+
Multichannel,
|
|
5
|
+
RequestContext,
|
|
6
|
+
WebchatSettings,
|
|
7
|
+
WebchatSettingsProps,
|
|
8
|
+
} from '@botonic/react'
|
|
3
9
|
import React from 'react'
|
|
4
10
|
|
|
5
11
|
import { FlowBuilderApi } from '../api'
|
|
6
12
|
import { FlowContent, FlowHandoff } from '../content-fields'
|
|
7
13
|
import { FlowBotAction } from '../content-fields/flow-bot-action'
|
|
14
|
+
import { ContentFilterExecutor } from '../filters'
|
|
8
15
|
import { getFlowBuilderPlugin } from '../helpers'
|
|
9
16
|
import BotonicPluginFlowBuilder from '../index'
|
|
10
17
|
import { trackFlowContent } from '../tracking'
|
|
11
18
|
import { inputHasTextData } from '../utils'
|
|
19
|
+
import { getContentsByAiAgent } from './ai-agent'
|
|
12
20
|
import { getContentsByFallback } from './fallback'
|
|
13
21
|
import { getContentsByFirstInteraction } from './first-interaction'
|
|
14
22
|
import { getContentsByKnowledgeBase } from './knowledge-bases'
|
|
@@ -16,6 +24,7 @@ import { getContentsByPayload } from './payload'
|
|
|
16
24
|
|
|
17
25
|
export type FlowBuilderActionProps = {
|
|
18
26
|
contents: FlowContent[]
|
|
27
|
+
webchatSettingsParams?: WebchatSettingsProps
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
@@ -27,10 +36,11 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
|
27
36
|
): Promise<FlowBuilderActionProps> {
|
|
28
37
|
const context = getContext(request)
|
|
29
38
|
const contents = await getContentsByFirstInteraction(context)
|
|
30
|
-
await
|
|
31
|
-
await
|
|
39
|
+
const filteredContents = await filterContents(request, contents)
|
|
40
|
+
await trackFlowContent(request, filteredContents)
|
|
41
|
+
await FlowBuilderAction.doHandoffAndBotActions(request, filteredContents)
|
|
32
42
|
|
|
33
|
-
return { contents }
|
|
43
|
+
return { contents: filteredContents }
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
static async botonicInit(
|
|
@@ -38,13 +48,14 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
|
38
48
|
contentID?: string
|
|
39
49
|
): Promise<FlowBuilderActionProps> {
|
|
40
50
|
const contents = await getContents(request, contentID)
|
|
41
|
-
await
|
|
42
|
-
await
|
|
51
|
+
const filteredContents = await filterContents(request, contents)
|
|
52
|
+
await trackFlowContent(request, filteredContents)
|
|
53
|
+
await FlowBuilderAction.doHandoffAndBotActions(request, filteredContents)
|
|
43
54
|
|
|
44
|
-
return { contents }
|
|
55
|
+
return { contents: filteredContents }
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
|
|
58
|
+
static async doHandoffAndBotActions(
|
|
48
59
|
request: ActionRequest,
|
|
49
60
|
contents: FlowContent[]
|
|
50
61
|
) {
|
|
@@ -64,19 +75,26 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
render(): JSX.Element | JSX.Element[] {
|
|
67
|
-
const { contents } = this.props
|
|
78
|
+
const { contents, webchatSettingsParams } = this.props
|
|
68
79
|
const request = this.context as ActionRequest
|
|
69
|
-
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<>
|
|
83
|
+
{(isWebchat(request.session) || isDev(request.session)) &&
|
|
84
|
+
!!webchatSettingsParams && (
|
|
85
|
+
<WebchatSettings {...webchatSettingsParams} />
|
|
86
|
+
)}
|
|
87
|
+
{contents.map(content => content.toBotonic(content.id, request))}
|
|
88
|
+
</>
|
|
89
|
+
)
|
|
70
90
|
}
|
|
71
91
|
}
|
|
72
92
|
|
|
73
93
|
export class FlowBuilderMultichannelAction extends FlowBuilderAction {
|
|
74
94
|
render(): JSX.Element | JSX.Element[] {
|
|
75
|
-
const { contents } = this.props
|
|
76
|
-
const request = this.context as ActionRequest
|
|
77
95
|
return (
|
|
78
96
|
<Multichannel text={{ buttonsAsText: false }}>
|
|
79
|
-
{
|
|
97
|
+
<FlowBuilderAction {...this.props} />
|
|
80
98
|
</Multichannel>
|
|
81
99
|
)
|
|
82
100
|
}
|
|
@@ -106,6 +124,10 @@ async function getContents(
|
|
|
106
124
|
}
|
|
107
125
|
|
|
108
126
|
if (inputHasTextData(request.input)) {
|
|
127
|
+
const aiAgentContents = await getContentsByAiAgent(context)
|
|
128
|
+
if (aiAgentContents.length > 0) {
|
|
129
|
+
return aiAgentContents
|
|
130
|
+
}
|
|
109
131
|
const knowledgeBaseContents = await getContentsByKnowledgeBase(context)
|
|
110
132
|
if (knowledgeBaseContents.length > 0) {
|
|
111
133
|
return knowledgeBaseContents
|
|
@@ -115,6 +137,25 @@ async function getContents(
|
|
|
115
137
|
return await getContentsByFallback(context)
|
|
116
138
|
}
|
|
117
139
|
|
|
140
|
+
async function filterContents(
|
|
141
|
+
request: BotContext,
|
|
142
|
+
contents: FlowContent[]
|
|
143
|
+
): Promise<FlowContent[]> {
|
|
144
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
145
|
+
const contentFilters = flowBuilderPlugin.contentFilters
|
|
146
|
+
const contentFilterExecutor = new ContentFilterExecutor({
|
|
147
|
+
filters: contentFilters,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const filteredContents: FlowContent[] = []
|
|
151
|
+
for (const content of contents) {
|
|
152
|
+
const filteredContent = await contentFilterExecutor.filter(request, content)
|
|
153
|
+
filteredContents.push(filteredContent)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return filteredContents
|
|
157
|
+
}
|
|
158
|
+
|
|
118
159
|
export interface FlowBuilderContext {
|
|
119
160
|
cmsApi: FlowBuilderApi
|
|
120
161
|
flowBuilderPlugin: BotonicPluginFlowBuilder
|
package/src/api.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Input, PluginPreRequest } from '@botonic/core'
|
|
2
2
|
import axios from 'axios'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AI_AGENTS_FLOW_NAME,
|
|
6
|
+
KNOWLEDGE_BASE_FLOW_NAME,
|
|
7
|
+
SEPARATOR,
|
|
8
|
+
UUID_REGEXP,
|
|
9
|
+
} from './constants'
|
|
5
10
|
import {
|
|
6
11
|
HtBotActionNode,
|
|
7
12
|
HtFallbackNode,
|
|
@@ -202,6 +207,18 @@ export class FlowBuilderApi {
|
|
|
202
207
|
return this.getNodeById<HtNodeWithContent>(knowledgeBaseFlow.start_node_id)
|
|
203
208
|
}
|
|
204
209
|
|
|
210
|
+
getStartNodeAiAgentFlow(): HtNodeWithContent | undefined {
|
|
211
|
+
const aiAgentFlow = this.flow.flows.find(
|
|
212
|
+
flow => flow.name === AI_AGENTS_FLOW_NAME
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
if (!aiAgentFlow) {
|
|
216
|
+
return undefined
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return this.getNodeById<HtNodeWithContent>(aiAgentFlow.start_node_id)
|
|
220
|
+
}
|
|
221
|
+
|
|
205
222
|
isKnowledgeBaseEnabled(): boolean {
|
|
206
223
|
return this.flow.is_knowledge_base_active || false
|
|
207
224
|
}
|
package/src/constants.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Text } from '@botonic/react'
|
|
2
|
+
|
|
3
|
+
import { ContentFieldsBase } from './content-fields-base'
|
|
4
|
+
import { HtAiAgentNode } from './hubtype-fields/ai-agent'
|
|
5
|
+
|
|
6
|
+
export class FlowAiAgent extends ContentFieldsBase {
|
|
7
|
+
public code: string = ''
|
|
8
|
+
public name: string = ''
|
|
9
|
+
public instructions: string = ''
|
|
10
|
+
public text: string = ''
|
|
11
|
+
|
|
12
|
+
static fromHubtypeCMS(component: HtAiAgentNode): FlowAiAgent {
|
|
13
|
+
const newAiAgent = new FlowAiAgent(component.id)
|
|
14
|
+
newAiAgent.name = component.content.name
|
|
15
|
+
newAiAgent.instructions = component.content.instructions
|
|
16
|
+
|
|
17
|
+
return newAiAgent
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toBotonic(id: string): JSX.Element {
|
|
21
|
+
return <Text key={id}>{this.text}</Text>
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HtAiAgentNode } from './ai-agent'
|
|
1
2
|
import { HtBotActionNode } from './bot-action'
|
|
2
3
|
import { HtCarouselNode } from './carousel'
|
|
3
4
|
import { HtFallbackNode } from './fallback'
|
|
@@ -29,6 +30,7 @@ export type HtNodeWithContent =
|
|
|
29
30
|
| HtSmartIntentNode
|
|
30
31
|
| HtKnowledgeBaseNode
|
|
31
32
|
| HtBotActionNode
|
|
33
|
+
| HtAiAgentNode
|
|
32
34
|
|
|
33
35
|
export type HtNodeWithoutContent = HtUrlNode | HtPayloadNode | HtGoToFlow
|
|
34
36
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FlowAiAgent } from './flow-ai-agent'
|
|
1
2
|
import { FlowBotAction } from './flow-bot-action'
|
|
2
3
|
import { FlowCarousel } from './flow-carousel'
|
|
3
4
|
import { FlowHandoff } from './flow-handoff'
|
|
@@ -10,21 +11,21 @@ import { FlowText } from './flow-text'
|
|
|
10
11
|
import { FlowVideo } from './flow-video'
|
|
11
12
|
import { FlowWhatsappCtaUrlButtonNode } from './flow-whatsapp-cta-url-button'
|
|
12
13
|
import { FlowWhatsappButtonList } from './whatsapp-button-list/flow-whatsapp-button-list'
|
|
13
|
-
|
|
14
14
|
export { ContentFieldsBase } from './content-fields-base'
|
|
15
15
|
export { FlowButton } from './flow-button'
|
|
16
16
|
export { FlowElement } from './flow-element'
|
|
17
17
|
export {
|
|
18
|
+
FlowAiAgent,
|
|
18
19
|
FlowBotAction,
|
|
19
20
|
FlowCarousel,
|
|
21
|
+
FlowHandoff,
|
|
20
22
|
FlowImage,
|
|
21
23
|
FlowKnowledgeBase,
|
|
22
24
|
FlowText,
|
|
23
25
|
FlowVideo,
|
|
24
26
|
FlowWhatsappButtonList,
|
|
27
|
+
FlowWhatsappCtaUrlButtonNode,
|
|
25
28
|
}
|
|
26
|
-
export { FlowHandoff } from './flow-handoff'
|
|
27
|
-
export { FlowWhatsappCtaUrlButtonNode } from './flow-whatsapp-cta-url-button'
|
|
28
29
|
|
|
29
30
|
export type FlowContent =
|
|
30
31
|
| FlowCarousel
|
|
@@ -36,5 +37,6 @@ export type FlowContent =
|
|
|
36
37
|
| FlowHandoff
|
|
37
38
|
| FlowKnowledgeBase
|
|
38
39
|
| FlowBotAction
|
|
40
|
+
| FlowAiAgent
|
|
39
41
|
|
|
40
42
|
export { DISABLED_MEMORY_LENGTH }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BotContext } from '@botonic/core'
|
|
2
|
+
|
|
3
|
+
import { FlowContent } from '../content-fields'
|
|
4
|
+
import { ContentFilter } from '../types'
|
|
5
|
+
|
|
6
|
+
interface ContentFilterExecutorOptions {
|
|
7
|
+
filters: ContentFilter[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class ContentFilterExecutor {
|
|
11
|
+
private filters: ContentFilter[] = []
|
|
12
|
+
|
|
13
|
+
constructor(options: ContentFilterExecutorOptions) {
|
|
14
|
+
this.filters = options.filters
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async filter(
|
|
18
|
+
request: BotContext,
|
|
19
|
+
content: FlowContent
|
|
20
|
+
): Promise<FlowContent> {
|
|
21
|
+
for (const filter of this.filters) {
|
|
22
|
+
content = await filter(request, content)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return content
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
SOURCE_INFO_SEPARATOR,
|
|
15
15
|
} from './constants'
|
|
16
16
|
import {
|
|
17
|
+
FlowAiAgent,
|
|
17
18
|
FlowBotAction,
|
|
18
19
|
FlowCarousel,
|
|
19
20
|
FlowContent,
|
|
@@ -37,7 +38,9 @@ import {
|
|
|
37
38
|
} from './content-fields/hubtype-fields'
|
|
38
39
|
import { DEFAULT_FUNCTIONS } from './functions'
|
|
39
40
|
import {
|
|
41
|
+
AiAgentFunction,
|
|
40
42
|
BotonicPluginFlowBuilderOptions,
|
|
43
|
+
ContentFilter,
|
|
41
44
|
FlowBuilderJSONVersion,
|
|
42
45
|
InShadowingConfig,
|
|
43
46
|
KnowledgeBaseFunction,
|
|
@@ -58,8 +61,10 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
58
61
|
public getAccessToken: (session: Session) => string
|
|
59
62
|
public trackEvent?: TrackEventFunction
|
|
60
63
|
public getKnowledgeBaseResponse?: KnowledgeBaseFunction
|
|
64
|
+
public getAiAgentResponse?: AiAgentFunction
|
|
61
65
|
public smartIntentsConfig: SmartIntentsInferenceConfig
|
|
62
66
|
public inShadowing: InShadowingConfig
|
|
67
|
+
public contentFilters: ContentFilter[]
|
|
63
68
|
|
|
64
69
|
// TODO: Rethink how we construct FlowBuilderApi to be simpler
|
|
65
70
|
public jsonVersion: FlowBuilderJSONVersion
|
|
@@ -72,6 +77,8 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
72
77
|
this.getAccessToken = resolveGetAccessToken(options.getAccessToken)
|
|
73
78
|
this.trackEvent = options.trackEvent
|
|
74
79
|
this.getKnowledgeBaseResponse = options.getKnowledgeBaseResponse
|
|
80
|
+
// TODO: Add getAiAgentResponse before publish 0.36.0
|
|
81
|
+
this.getAiAgentResponse = undefined //options.getAiAgentResponse
|
|
75
82
|
this.smartIntentsConfig = {
|
|
76
83
|
...options?.smartIntentsConfig,
|
|
77
84
|
useLatest: this.jsonVersion === FlowBuilderJSONVersion.LATEST,
|
|
@@ -83,6 +90,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
83
90
|
allowSmartIntents: options.inShadowing?.allowSmartIntents || false,
|
|
84
91
|
allowKnowledgeBases: options.inShadowing?.allowKnowledgeBases || false,
|
|
85
92
|
}
|
|
93
|
+
this.contentFilters = options.contentFilters || []
|
|
86
94
|
}
|
|
87
95
|
|
|
88
96
|
resolveFlowUrl(request: PluginPreRequest): string {
|
|
@@ -230,6 +238,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
230
238
|
case HtNodeWithContentType.KNOWLEDGE_BASE:
|
|
231
239
|
return FlowKnowledgeBase.fromHubtypeCMS(hubtypeContent)
|
|
232
240
|
|
|
241
|
+
case HtNodeWithContentType.AI_AGENT:
|
|
242
|
+
return FlowAiAgent.fromHubtypeCMS(hubtypeContent)
|
|
243
|
+
|
|
233
244
|
case HtNodeWithContentType.BOT_ACTION:
|
|
234
245
|
return FlowBotAction.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi)
|
|
235
246
|
|
|
@@ -305,6 +316,7 @@ export { HtBotActionNode } from './content-fields/hubtype-fields'
|
|
|
305
316
|
export { trackFlowContent } from './tracking'
|
|
306
317
|
export {
|
|
307
318
|
BotonicPluginFlowBuilderOptions,
|
|
319
|
+
ContentFilter,
|
|
308
320
|
FlowBuilderJSONVersion,
|
|
309
321
|
PayloadParamsBase,
|
|
310
322
|
} from './types'
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BotContext,
|
|
3
|
-
PluginPreRequest,
|
|
4
|
-
ResolvedPlugins,
|
|
5
|
-
Session,
|
|
6
|
-
} from '@botonic/core'
|
|
1
|
+
import { BotContext, PluginPreRequest, ResolvedPlugins } from '@botonic/core'
|
|
7
2
|
|
|
3
|
+
import { FlowContent } from './content-fields'
|
|
8
4
|
import { HtFlowBuilderData } from './content-fields/hubtype-fields'
|
|
9
5
|
|
|
10
6
|
export interface InShadowingConfig {
|
|
@@ -24,8 +20,10 @@ export interface BotonicPluginFlowBuilderOptions<
|
|
|
24
20
|
getAccessToken: () => string
|
|
25
21
|
trackEvent?: TrackEventFunction<TPlugins, TExtraData>
|
|
26
22
|
getKnowledgeBaseResponse?: KnowledgeBaseFunction<TPlugins, TExtraData>
|
|
23
|
+
getAiAgentResponse?: AiAgentFunction<TPlugins, TExtraData>
|
|
27
24
|
smartIntentsConfig?: { numSmartIntentsToUse: number }
|
|
28
25
|
inShadowing?: Partial<InShadowingConfig>
|
|
26
|
+
contentFilters?: ContentFilter<TPlugins, TExtraData>[]
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export type TrackEventFunction<
|
|
@@ -48,6 +46,26 @@ export type KnowledgeBaseFunction<
|
|
|
48
46
|
memoryLength: number
|
|
49
47
|
) => Promise<KnowledgeBaseResponse>
|
|
50
48
|
|
|
49
|
+
export type AiAgentFunction<
|
|
50
|
+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
51
|
+
TExtraData = any,
|
|
52
|
+
> = (
|
|
53
|
+
request: BotContext<TPlugins, TExtraData>,
|
|
54
|
+
aiAgentArgs: AiAgentArgs
|
|
55
|
+
) => Promise<AiAgentResponse>
|
|
56
|
+
|
|
57
|
+
export interface AiAgentArgs {
|
|
58
|
+
name: string
|
|
59
|
+
instructions: string
|
|
60
|
+
}
|
|
61
|
+
export type ContentFilter<
|
|
62
|
+
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
63
|
+
TExtraData = any,
|
|
64
|
+
> = (
|
|
65
|
+
request: BotContext<TPlugins, TExtraData>,
|
|
66
|
+
content: FlowContent
|
|
67
|
+
) => Promise<FlowContent> | FlowContent
|
|
68
|
+
|
|
51
69
|
export interface FlowBuilderApiOptions {
|
|
52
70
|
url: string
|
|
53
71
|
flowUrl: string
|
|
@@ -74,6 +92,10 @@ export interface KnowledgeBaseResponse {
|
|
|
74
92
|
answer: string
|
|
75
93
|
}
|
|
76
94
|
|
|
95
|
+
export interface AiAgentResponse {
|
|
96
|
+
message: { role: string; content: string }
|
|
97
|
+
}
|
|
98
|
+
|
|
77
99
|
export interface SmartIntentResponse {
|
|
78
100
|
data: {
|
|
79
101
|
smart_intent_title: string
|