@botonic/plugin-flow-builder 0.40.0-alpha.3 → 0.41.0-alpha.0
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.js +2 -1
- package/lib/cjs/action/ai-agent.js.map +1 -1
- package/lib/cjs/action/fallback.js +5 -0
- package/lib/cjs/action/fallback.js.map +1 -1
- package/lib/cjs/action/index.js +2 -5
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.js +5 -5
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -2
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/flow-ai-agent.d.ts +4 -0
- package/lib/cjs/content-fields/flow-ai-agent.js +5 -1
- package/lib/cjs/content-fields/flow-ai-agent.js.map +1 -1
- package/lib/cjs/content-fields/flow-element.d.ts +2 -4
- package/lib/cjs/content-fields/flow-element.js.map +1 -1
- package/lib/cjs/content-fields/flow-handoff.js +6 -3
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/content-fields/flow-rating.js +1 -1
- package/lib/cjs/content-fields/flow-rating.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/ai-agent.d.ts +4 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +15 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/tracking.d.ts +8 -0
- package/lib/cjs/tracking.js +23 -6
- package/lib/cjs/tracking.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -13
- package/lib/cjs/types.js.map +1 -1
- package/lib/cjs/user-input/keyword.js +5 -2
- package/lib/cjs/user-input/keyword.js.map +1 -1
- package/lib/cjs/user-input/smart-intent.js +5 -2
- package/lib/cjs/user-input/smart-intent.js.map +1 -1
- package/lib/cjs/utils.js +1 -1
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/action/ai-agent.js +2 -1
- package/lib/esm/action/ai-agent.js.map +1 -1
- package/lib/esm/action/fallback.js +6 -1
- package/lib/esm/action/fallback.js.map +1 -1
- package/lib/esm/action/index.js +3 -6
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.js +6 -6
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/flow-ai-agent.d.ts +4 -0
- package/lib/esm/content-fields/flow-ai-agent.js +5 -1
- package/lib/esm/content-fields/flow-ai-agent.js.map +1 -1
- package/lib/esm/content-fields/flow-element.d.ts +2 -4
- package/lib/esm/content-fields/flow-element.js.map +1 -1
- package/lib/esm/content-fields/flow-handoff.js +6 -3
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/content-fields/flow-rating.js +1 -1
- package/lib/esm/content-fields/flow-rating.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/ai-agent.d.ts +4 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +16 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/tracking.d.ts +8 -0
- package/lib/esm/tracking.js +21 -5
- package/lib/esm/tracking.js.map +1 -1
- package/lib/esm/types.d.ts +2 -13
- package/lib/esm/types.js.map +1 -1
- package/lib/esm/user-input/keyword.js +6 -3
- package/lib/esm/user-input/keyword.js.map +1 -1
- package/lib/esm/user-input/smart-intent.js +6 -3
- package/lib/esm/user-input/smart-intent.js.map +1 -1
- package/lib/esm/utils.js +1 -1
- package/lib/esm/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/action/ai-agent.ts +1 -0
- package/src/action/fallback.ts +11 -1
- package/src/action/index.tsx +2 -6
- package/src/action/knowledge-bases.ts +11 -10
- package/src/constants.ts +1 -1
- package/src/content-fields/flow-ai-agent.tsx +13 -8
- package/src/content-fields/flow-element.tsx +2 -2
- package/src/content-fields/flow-handoff.tsx +10 -4
- package/src/content-fields/flow-rating.tsx +1 -0
- package/src/content-fields/hubtype-fields/ai-agent.ts +1 -0
- package/src/index.ts +21 -6
- package/src/tracking.ts +39 -5
- package/src/types.ts +4 -11
- package/src/user-input/keyword.ts +14 -3
- package/src/user-input/smart-intent.ts +14 -3
- package/src/utils.ts +1 -1
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BotContext, InferenceResponse, KnowledgeBasesResponse, PluginPreRequest, ResolvedPlugins } from '@botonic/core';
|
|
1
|
+
import { AiAgentArgs, BotContext, GuardrailRule, InferenceResponse, KnowledgeBasesResponse, PluginPreRequest, ResolvedPlugins } from '@botonic/core';
|
|
2
2
|
import { FlowContent } from './content-fields';
|
|
3
3
|
import { HtFlowBuilderData, HtRatingButton } from './content-fields/hubtype-fields';
|
|
4
4
|
export interface InShadowingConfig {
|
|
@@ -25,18 +25,6 @@ export interface BotonicPluginFlowBuilderOptions<TPlugins extends ResolvedPlugin
|
|
|
25
25
|
export type TrackEventFunction<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = (request: BotContext<TPlugins, TExtraData>, eventAction: string, args?: Record<string, any>) => Promise<void>;
|
|
26
26
|
export type KnowledgeBaseFunction<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = (request: BotContext<TPlugins, TExtraData>, sources: string[], instructions: string, messageId: string, memoryLength: number) => Promise<KnowledgeBasesResponse>;
|
|
27
27
|
export type AiAgentFunction<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = (request: BotContext<TPlugins, TExtraData>, aiAgentArgs: AiAgentArgs) => Promise<InferenceResponse>;
|
|
28
|
-
export interface GuardrailRule {
|
|
29
|
-
name: string;
|
|
30
|
-
description: string;
|
|
31
|
-
}
|
|
32
|
-
export interface AiAgentArgs {
|
|
33
|
-
name: string;
|
|
34
|
-
instructions: string;
|
|
35
|
-
activeTools?: {
|
|
36
|
-
name: string;
|
|
37
|
-
}[];
|
|
38
|
-
inputGuardrailRules?: GuardrailRule[];
|
|
39
|
-
}
|
|
40
28
|
export type ContentFilter<TPlugins extends ResolvedPlugins = ResolvedPlugins, TExtraData = any> = (request: BotContext<TPlugins, TExtraData>, content: FlowContent) => Promise<FlowContent> | FlowContent;
|
|
41
29
|
export interface FlowBuilderApiOptions {
|
|
42
30
|
url: string;
|
|
@@ -70,3 +58,4 @@ export interface RatingSubmittedInfo extends HtRatingButton {
|
|
|
70
58
|
possibleOptions: string[];
|
|
71
59
|
possibleValues: number[];
|
|
72
60
|
}
|
|
61
|
+
export { AiAgentArgs, GuardrailRule };
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAoFA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED,MAAM,CAAN,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;AACnB,CAAC,EAHW,sBAAsB,KAAtB,sBAAsB,QAGjC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __rest } from "tslib";
|
|
2
2
|
import { EventAction, NluType } from '@botonic/core';
|
|
3
3
|
import { REG_EXP_PATTERN } from '../constants';
|
|
4
|
-
import { trackEvent } from '../tracking';
|
|
4
|
+
import { getCommonFlowContentEventArgsForContentId, trackEvent, } from '../tracking';
|
|
5
5
|
export class KeywordMatcher {
|
|
6
6
|
constructor({ cmsApi, locale, request }) {
|
|
7
7
|
this.cmsApi = cmsApi;
|
|
@@ -63,11 +63,14 @@ export class KeywordMatcher {
|
|
|
63
63
|
}
|
|
64
64
|
trackKeywordEvent() {
|
|
65
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const { flowId, flowName, flowNodeId, flowNodeContentId } = getCommonFlowContentEventArgsForContentId(this.request, this.keywordNodeId);
|
|
66
67
|
const event = {
|
|
67
68
|
action: EventAction.Keyword,
|
|
69
|
+
flowNodeId,
|
|
70
|
+
flowId,
|
|
71
|
+
flowName,
|
|
72
|
+
flowNodeContentId,
|
|
68
73
|
flowThreadId: this.request.session.flow_thread_id,
|
|
69
|
-
flowNodeId: this.keywordNodeId,
|
|
70
|
-
flowId: this.flowId,
|
|
71
74
|
nluKeywordName: this.matchedKeyword,
|
|
72
75
|
nluKeywordIsRegex: this.isRegExp,
|
|
73
76
|
nluKeywordMessageId: this.request.input.message_id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAgB,OAAO,EAAE,MAAM,eAAe,CAAA;AAIlE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAK9C,OAAO,
|
|
1
|
+
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAgB,OAAO,EAAE,MAAM,eAAe,CAAA;AAIlE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAK9C,OAAO,EACL,yCAAyC,EACzC,UAAU,GACX,MAAM,aAAa,CAAA;AAOpB,MAAM,OAAO,cAAc;IASzB,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAgB;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;IAC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,EAAE,UAAU,EAAE,iBAAiB,EAAE,GACvD,yCAAyC,CACvC,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,aAAuB,CAC7B,CAAA;YAEH,MAAM,KAAK,GAAiB;gBAC1B,MAAM,EAAE,WAAW,CAAC,OAAO;gBAC3B,UAAU;gBACV,MAAM;gBACN,QAAQ;gBACR,iBAAiB;gBACjB,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,cAAwB;gBAC3D,cAAc,EAAE,IAAI,CAAC,cAAwB;gBAC7C,iBAAiB,EAAE,IAAI,CAAC,QAAQ;gBAChC,mBAAmB,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU;gBAClD,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAc;aAC7C,CAAA;YACD,MAAM,EAAE,MAAM,KAAmB,KAAK,EAAnB,SAAS,UAAK,KAAK,EAAhC,UAAwB,CAAQ,CAAA;YACtC,MAAM,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACnD,CAAC;KAAA;CACF"}
|
|
@@ -2,7 +2,7 @@ import { __awaiter, __rest } from "tslib";
|
|
|
2
2
|
import { EventAction, NluType } from '@botonic/core';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import { getFlowBuilderPlugin } from '../helpers';
|
|
5
|
-
import { trackEvent } from '../tracking';
|
|
5
|
+
import { getCommonFlowContentEventArgsForContentId, trackEvent, } from '../tracking';
|
|
6
6
|
export class SmartIntentsApi {
|
|
7
7
|
constructor(cmsApi, currentRequest, smartIntentsConfig, flowId) {
|
|
8
8
|
this.cmsApi = cmsApi;
|
|
@@ -33,6 +33,7 @@ export class SmartIntentsApi {
|
|
|
33
33
|
matchedValue: smartIntentNode.content.title,
|
|
34
34
|
payload: targetPayload,
|
|
35
35
|
};
|
|
36
|
+
const { flowId, flowName, flowNodeId, flowNodeContentId } = getCommonFlowContentEventArgsForContentId(this.currentRequest, smartIntentNode.id);
|
|
36
37
|
const event = {
|
|
37
38
|
action: EventAction.IntentSmart,
|
|
38
39
|
nluIntentSmartTitle: response.data.smart_intent_title,
|
|
@@ -40,8 +41,10 @@ export class SmartIntentsApi {
|
|
|
40
41
|
nluIntentSmartMessageId: this.currentRequest.input.message_id,
|
|
41
42
|
userInput: this.currentRequest.input.data,
|
|
42
43
|
flowThreadId: this.currentRequest.session.flow_thread_id,
|
|
43
|
-
flowId
|
|
44
|
-
|
|
44
|
+
flowId,
|
|
45
|
+
flowName,
|
|
46
|
+
flowNodeContentId,
|
|
47
|
+
flowNodeId,
|
|
45
48
|
};
|
|
46
49
|
const { action } = event, eventArgs = __rest(event, ["action"]);
|
|
47
50
|
yield trackEvent(this.currentRequest, action, eventArgs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAoB,OAAO,EAAE,MAAM,eAAe,CAAA;AAEtE,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAoB,OAAO,EAAE,MAAM,eAAe,CAAA;AAEtE,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EACL,yCAAyC,EACzC,UAAU,GACX,MAAM,aAAa,CAAA;AAepB,MAAM,OAAO,eAAe;IAC1B,YACS,MAAsB,EACtB,cAA6B,EAC7B,kBAA+C,EAC/C,MAAe;QAHf,WAAM,GAAN,MAAM,CAAgB;QACtB,mBAAc,GAAd,cAAc,CAAe;QAC7B,uBAAkB,GAAlB,kBAAkB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AO,CAAC,GAAG,CAAC,eAAe,0CAA0C;gBAC7E,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,KAAK,EAAE;oBAChC,cAAc,EAAE,kBAAkB;iBACnC;gBACD,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,KAAK;aACf,CAAC,CAAA;QACJ,CAAC;KAAA;CACF"}
|
package/lib/esm/utils.js
CHANGED
|
@@ -18,7 +18,7 @@ export function resolveGetAccessToken(getAccessToken) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
export function getValueFromKeyPath(request, keyPath) {
|
|
21
|
-
if (keyPath.startsWith('input') || keyPath.startsWith('session')) {
|
|
21
|
+
if (keyPath.startsWith('input.') || keyPath.startsWith('session.')) {
|
|
22
22
|
return keyPath
|
|
23
23
|
.split('.')
|
|
24
24
|
.reduce((object, key) => resolveObjectKey(object, key), request);
|
package/lib/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,eAAe,CAAA;AAGrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAqB,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE/D,SAAS,yBAAyB,CAAC,OAAgB;IACjD,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;KACpD;IACD,OAAO,OAAO,CAAC,aAAa,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,cAA4C;IAE5C,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QAC5B,KAAK,kBAAkB,CAAC,UAAU;YAChC,OAAO,yBAAyB,CAAA;QAClC,KAAK,kBAAkB,CAAC,WAAW;YACjC,OAAO,cAAc,CAAA;QACvB;YACE,MAAM,IAAI,KAAK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alpha.0",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use Flow Builder to show your contents",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@botonic/react": "
|
|
18
|
-
"axios": "^1.
|
|
17
|
+
"@botonic/react": "0.41.0-alpha.0",
|
|
18
|
+
"axios": "^1.12.2",
|
|
19
19
|
"uuid": "^10.0.0"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"README.md"
|
|
33
33
|
],
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
35
|
+
"node": ">=22.19.0",
|
|
36
36
|
"npm": ">=10.0.0"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
package/src/action/ai-agent.ts
CHANGED
|
@@ -49,6 +49,7 @@ export async function getContentsByAiAgent({
|
|
|
49
49
|
instructions: aiAgentContent.instructions,
|
|
50
50
|
activeTools: aiAgentContent.activeTools,
|
|
51
51
|
inputGuardrailRules: activeInputGuardrailRules,
|
|
52
|
+
sourceIds: aiAgentContent.sources?.map(source => source.id),
|
|
52
53
|
}
|
|
53
54
|
)
|
|
54
55
|
|
package/src/action/fallback.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { ActionRequest } from '@botonic/react'
|
|
|
3
3
|
|
|
4
4
|
import { FlowBuilderApi } from '../api'
|
|
5
5
|
import { FlowContent } from '../content-fields'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getCommonFlowContentEventArgsForContentId,
|
|
8
|
+
trackEvent,
|
|
9
|
+
} from '../tracking'
|
|
7
10
|
import { FlowBuilderContext } from './index'
|
|
8
11
|
|
|
9
12
|
export async function getContentsByFallback({
|
|
@@ -31,8 +34,15 @@ async function getFallbackNode(cmsApi: FlowBuilderApi, request: ActionRequest) {
|
|
|
31
34
|
const fallbackNode = cmsApi.getFallbackNode(isFirstFallbackOption)
|
|
32
35
|
request.session.user.extra_data.isFirstFallbackOption = !isFirstFallbackOption
|
|
33
36
|
|
|
37
|
+
const { flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
38
|
+
getCommonFlowContentEventArgsForContentId(request, fallbackNode.id)
|
|
39
|
+
|
|
34
40
|
const event: EventFallback = {
|
|
35
41
|
action: EventAction.Fallback,
|
|
42
|
+
flowId,
|
|
43
|
+
flowName,
|
|
44
|
+
flowNodeId,
|
|
45
|
+
flowNodeContentId,
|
|
36
46
|
userInput: request.input.data as string,
|
|
37
47
|
fallbackOut: isFirstFallbackOption ? 1 : 2,
|
|
38
48
|
fallbackMessageId: request.input.message_id,
|
package/src/action/index.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import React from 'react'
|
|
10
10
|
|
|
11
11
|
import { FlowBuilderApi } from '../api'
|
|
12
|
-
import {
|
|
12
|
+
import { EMPTY_PAYLOAD } from '../constants'
|
|
13
13
|
import { FlowContent, FlowHandoff } from '../content-fields'
|
|
14
14
|
import { FlowBotAction } from '../content-fields/flow-bot-action'
|
|
15
15
|
import { ContentFilterExecutor } from '../filters'
|
|
@@ -126,11 +126,7 @@ async function getContents(
|
|
|
126
126
|
return []
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
if (request.input.payload?.startsWith(
|
|
130
|
-
request.input.payload = undefined
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (request.input.payload?.startsWith('AI_AGENT_PAYLOAD_')) {
|
|
129
|
+
if (request.input.payload?.startsWith(EMPTY_PAYLOAD)) {
|
|
134
130
|
request.input.payload = undefined
|
|
135
131
|
}
|
|
136
132
|
|
|
@@ -12,9 +12,10 @@ import {
|
|
|
12
12
|
FlowContent,
|
|
13
13
|
FlowKnowledgeBase,
|
|
14
14
|
} from '../content-fields'
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
import {
|
|
16
|
+
getCommonFlowContentEventArgsForContentId,
|
|
17
|
+
trackEvent,
|
|
18
|
+
} from '../tracking'
|
|
18
19
|
import { KnowledgeBaseFunction } from '../types'
|
|
19
20
|
import { inputHasTextData, isKnowledgeBasesAllowed } from '../utils'
|
|
20
21
|
import { FlowBuilderContext } from './index'
|
|
@@ -121,11 +122,6 @@ async function trackKnowledgeBase(
|
|
|
121
122
|
request: BotContext,
|
|
122
123
|
knowledgeBaseContent: FlowKnowledgeBase
|
|
123
124
|
) {
|
|
124
|
-
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
125
|
-
const flowId = flowBuilderPlugin.cmsApi.getNodeById<HtNodeWithContent>(
|
|
126
|
-
knowledgeBaseContent.id
|
|
127
|
-
).flow_id
|
|
128
|
-
|
|
129
125
|
const getKnowledgeFailReason = (): KnowledgebaseFailReason | undefined => {
|
|
130
126
|
let knowledgebaseFailReason: KnowledgebaseFailReason | undefined
|
|
131
127
|
|
|
@@ -139,6 +135,9 @@ async function trackKnowledgeBase(
|
|
|
139
135
|
return knowledgebaseFailReason
|
|
140
136
|
}
|
|
141
137
|
|
|
138
|
+
const { flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
139
|
+
getCommonFlowContentEventArgsForContentId(request, knowledgeBaseContent.id)
|
|
140
|
+
|
|
142
141
|
const event: EventKnowledgeBase = {
|
|
143
142
|
action: EventAction.Knowledgebase,
|
|
144
143
|
knowledgebaseInferenceId: response.inferenceId,
|
|
@@ -150,8 +149,10 @@ async function trackKnowledgeBase(
|
|
|
150
149
|
knowledgebaseMessageId: request.input.message_id,
|
|
151
150
|
userInput: request.input.data as string,
|
|
152
151
|
flowThreadId: request.session.flow_thread_id as string,
|
|
153
|
-
flowId
|
|
154
|
-
|
|
152
|
+
flowId,
|
|
153
|
+
flowName,
|
|
154
|
+
flowNodeId,
|
|
155
|
+
flowNodeContentId,
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
const { action, ...eventArgs } = event
|
package/src/constants.ts
CHANGED
|
@@ -2,7 +2,7 @@ export const FLOW_BUILDER_API_URL_PROD =
|
|
|
2
2
|
process.env.HUBTYPE_API_URL || 'https://api.hubtype.com'
|
|
3
3
|
export const SEPARATOR = '|'
|
|
4
4
|
export const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_`
|
|
5
|
-
export const
|
|
5
|
+
export const EMPTY_PAYLOAD = 'fb-empty-payload'
|
|
6
6
|
export const VARIABLE_PATTERN = /{([^}]+)}/g
|
|
7
7
|
export const ACCESS_TOKEN_VARIABLE_KEY = '_access_token'
|
|
8
8
|
export const REG_EXP_PATTERN = /^\/(.*)\/([gimyus]*)$/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AgenticOutputMessage } from '@botonic/core'
|
|
2
2
|
import { Button, Carousel, Text } from '@botonic/react'
|
|
3
3
|
|
|
4
|
+
import { EMPTY_PAYLOAD, SOURCE_INFO_SEPARATOR } from '../constants'
|
|
4
5
|
import { ContentFieldsBase } from './content-fields-base'
|
|
5
6
|
import { FlowElement } from './flow-element'
|
|
6
7
|
import { HtAiAgentNode, HtInputGuardrailRule } from './hubtype-fields/ai-agent'
|
|
@@ -11,6 +12,7 @@ export class FlowAiAgent extends ContentFieldsBase {
|
|
|
11
12
|
public instructions: string = ''
|
|
12
13
|
public activeTools?: { name: string }[]
|
|
13
14
|
public inputGuardrailRules: HtInputGuardrailRule[]
|
|
15
|
+
public sources?: { id: string; name: string }[]
|
|
14
16
|
|
|
15
17
|
public responses: AgenticOutputMessage[] = []
|
|
16
18
|
|
|
@@ -21,6 +23,7 @@ export class FlowAiAgent extends ContentFieldsBase {
|
|
|
21
23
|
newAiAgent.activeTools = component.content.active_tools
|
|
22
24
|
newAiAgent.inputGuardrailRules =
|
|
23
25
|
component.content.input_guardrail_rules || []
|
|
26
|
+
newAiAgent.sources = component.content.sources
|
|
24
27
|
return newAiAgent
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -36,14 +39,16 @@ export class FlowAiAgent extends ContentFieldsBase {
|
|
|
36
39
|
return (
|
|
37
40
|
<Text key={id}>
|
|
38
41
|
{response.content.text}
|
|
39
|
-
{response.content.buttons.map((button, buttonIndex) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
{response.content.buttons.map((button, buttonIndex) => {
|
|
43
|
+
return (
|
|
44
|
+
<Button
|
|
45
|
+
key={buttonIndex}
|
|
46
|
+
payload={`${EMPTY_PAYLOAD}${SOURCE_INFO_SEPARATOR}${buttonIndex}`}
|
|
47
|
+
>
|
|
48
|
+
{button.text}
|
|
49
|
+
</Button>
|
|
50
|
+
)
|
|
51
|
+
})}
|
|
47
52
|
</Text>
|
|
48
53
|
)
|
|
49
54
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Button } from '@botonic/core'
|
|
1
2
|
import { Element, Pic, Subtitle, Title } from '@botonic/react'
|
|
2
|
-
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { FlowBuilderApi } from '../api'
|
|
5
5
|
import { ContentFieldsBase } from './content-fields-base'
|
|
@@ -36,7 +36,7 @@ export class FlowElement extends ContentFieldsBase {
|
|
|
36
36
|
title: string
|
|
37
37
|
subtitle: string
|
|
38
38
|
image: string
|
|
39
|
-
button:
|
|
39
|
+
button: Button
|
|
40
40
|
}
|
|
41
41
|
) {
|
|
42
42
|
const newElement = new FlowElement(id)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { HandOffBuilder, HelpdeskEvent, isDev, isWebchat } from '@botonic/core'
|
|
2
2
|
import { ActionRequest, WebchatSettings } from '@botonic/react'
|
|
3
|
-
import React from 'react'
|
|
4
3
|
|
|
5
4
|
import { FlowBuilderApi } from '../api'
|
|
5
|
+
import { getCommonFlowContentEventArgsForContentId } from '../tracking'
|
|
6
6
|
import { ContentFieldsBase } from './content-fields-base'
|
|
7
7
|
import { HtHandoffNode, HtQueueLocale } from './hubtype-fields'
|
|
8
8
|
|
|
@@ -56,13 +56,19 @@ export class FlowHandoff extends ContentFieldsBase {
|
|
|
56
56
|
|
|
57
57
|
if (this.queue) {
|
|
58
58
|
const language = request.getSystemLocale()
|
|
59
|
-
const country = request.getUserCountry()
|
|
60
59
|
|
|
61
60
|
handOffBuilder.withQueue(this.queue.id)
|
|
61
|
+
|
|
62
|
+
const { flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
63
|
+
getCommonFlowContentEventArgsForContentId(request, this.id)
|
|
64
|
+
|
|
62
65
|
handOffBuilder.withBotEvent({
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
flowId,
|
|
67
|
+
flowName,
|
|
68
|
+
flowNodeId,
|
|
69
|
+
flowNodeContentId,
|
|
65
70
|
})
|
|
71
|
+
|
|
66
72
|
handOffBuilder.withExtraData({
|
|
67
73
|
language,
|
|
68
74
|
})
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
INPUT,
|
|
2
3
|
Plugin,
|
|
3
4
|
PluginPreRequest,
|
|
5
|
+
PROVIDER,
|
|
4
6
|
ResolvedPlugins,
|
|
5
7
|
Session,
|
|
6
8
|
} from '@botonic/core'
|
|
@@ -9,6 +11,7 @@ import { v7 as uuidv7 } from 'uuid'
|
|
|
9
11
|
|
|
10
12
|
import { FlowBuilderApi } from './api'
|
|
11
13
|
import {
|
|
14
|
+
EMPTY_PAYLOAD,
|
|
12
15
|
FLOW_BUILDER_API_URL_PROD,
|
|
13
16
|
SEPARATOR,
|
|
14
17
|
SOURCE_INFO_SEPARATOR,
|
|
@@ -105,6 +108,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
async pre(request: PluginPreRequest): Promise<void> {
|
|
111
|
+
// When AI Agent is executed in Whatsapp, button payloads come as referral and must be converted to text being processed by the agent.
|
|
112
|
+
this.convertWhatsappAiAgentEmptyPayloads(request)
|
|
113
|
+
|
|
108
114
|
this.currentRequest = request
|
|
109
115
|
this.cmsApi = await FlowBuilderApi.create({
|
|
110
116
|
flowUrl: this.resolveFlowUrl(request),
|
|
@@ -114,12 +120,8 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
114
120
|
request: this.currentRequest,
|
|
115
121
|
})
|
|
116
122
|
|
|
117
|
-
const
|
|
118
|
-
request.input.payload
|
|
119
|
-
|
|
120
|
-
const checkPayload = !request.input.payload || checkAiAgentPayload
|
|
121
|
-
|
|
122
|
-
const checkUserTextInput = inputHasTextData(request.input) && checkPayload
|
|
123
|
+
const checkUserTextInput =
|
|
124
|
+
inputHasTextData(request.input) && !request.input.payload
|
|
123
125
|
|
|
124
126
|
if (checkUserTextInput) {
|
|
125
127
|
const resolvedLocale = this.cmsApi.getResolvedLocale()
|
|
@@ -135,6 +137,19 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
135
137
|
this.updateRequestBeforeRoutes(request)
|
|
136
138
|
}
|
|
137
139
|
|
|
140
|
+
private convertWhatsappAiAgentEmptyPayloads(request: PluginPreRequest): void {
|
|
141
|
+
if (request.session.user.provider === PROVIDER.WHATSAPP) {
|
|
142
|
+
const shouldUseReferral =
|
|
143
|
+
request.input.referral &&
|
|
144
|
+
request.input.payload?.startsWith(EMPTY_PAYLOAD)
|
|
145
|
+
|
|
146
|
+
if (shouldUseReferral) {
|
|
147
|
+
request.input.type = INPUT.TEXT
|
|
148
|
+
request.input.data = request.input.referral
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
138
153
|
private updateRequestBeforeRoutes(request: PluginPreRequest): void {
|
|
139
154
|
if (request.input.payload) {
|
|
140
155
|
request.input.payload = this.removeSourceSuffix(request.input.payload)
|
package/src/tracking.ts
CHANGED
|
@@ -44,18 +44,52 @@ function getContentEventArgs(
|
|
|
44
44
|
request: ActionRequest,
|
|
45
45
|
nodeContent: HtNodeWithContent
|
|
46
46
|
): EventFlow {
|
|
47
|
-
const
|
|
48
|
-
|
|
47
|
+
const { flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
48
|
+
getCommonFlowContentEventArgs(request, nodeContent)
|
|
49
|
+
|
|
49
50
|
const flowThreadId = request.session.flow_thread_id ?? uuidv7()
|
|
50
51
|
request.session.flow_thread_id = flowThreadId
|
|
51
52
|
|
|
52
53
|
return {
|
|
53
54
|
action: EventAction.FlowNode,
|
|
55
|
+
flowId,
|
|
56
|
+
flowName,
|
|
57
|
+
flowNodeId,
|
|
58
|
+
flowNodeContentId,
|
|
54
59
|
flowThreadId,
|
|
60
|
+
flowNodeIsMeaningful: nodeContent.is_meaningful ?? false,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type CommonFlowContentEventArgs = {
|
|
65
|
+
flowId: string
|
|
66
|
+
flowName: string
|
|
67
|
+
flowNodeId: string
|
|
68
|
+
flowNodeContentId: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getCommonFlowContentEventArgs(
|
|
72
|
+
request: ActionRequest,
|
|
73
|
+
nodeContent: HtNodeWithContent
|
|
74
|
+
): CommonFlowContentEventArgs {
|
|
75
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
76
|
+
const flowName = flowBuilderPlugin.getFlowName(nodeContent.flow_id)
|
|
77
|
+
|
|
78
|
+
return {
|
|
55
79
|
flowId: nodeContent.flow_id,
|
|
56
|
-
flowName
|
|
80
|
+
flowName,
|
|
57
81
|
flowNodeId: nodeContent.id,
|
|
58
|
-
flowNodeContentId: nodeContent.code,
|
|
59
|
-
flowNodeIsMeaningful: nodeContent.is_meaningful ?? false,
|
|
82
|
+
flowNodeContentId: nodeContent.code ?? '',
|
|
60
83
|
}
|
|
61
84
|
}
|
|
85
|
+
|
|
86
|
+
export function getCommonFlowContentEventArgsForContentId(
|
|
87
|
+
request: ActionRequest,
|
|
88
|
+
contentId: string
|
|
89
|
+
): CommonFlowContentEventArgs {
|
|
90
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
91
|
+
const cmsApi = flowBuilderPlugin.cmsApi
|
|
92
|
+
const nodeContent = cmsApi.getNodeById<HtNodeWithContent>(contentId)
|
|
93
|
+
|
|
94
|
+
return getCommonFlowContentEventArgs(request, nodeContent)
|
|
95
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AiAgentArgs,
|
|
2
3
|
BotContext,
|
|
4
|
+
GuardrailRule,
|
|
3
5
|
InferenceResponse,
|
|
4
6
|
KnowledgeBasesResponse,
|
|
5
7
|
PluginPreRequest,
|
|
@@ -64,17 +66,6 @@ export type AiAgentFunction<
|
|
|
64
66
|
aiAgentArgs: AiAgentArgs
|
|
65
67
|
) => Promise<InferenceResponse>
|
|
66
68
|
|
|
67
|
-
export interface GuardrailRule {
|
|
68
|
-
name: string
|
|
69
|
-
description: string
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface AiAgentArgs {
|
|
73
|
-
name: string
|
|
74
|
-
instructions: string
|
|
75
|
-
activeTools?: { name: string }[]
|
|
76
|
-
inputGuardrailRules?: GuardrailRule[]
|
|
77
|
-
}
|
|
78
69
|
export type ContentFilter<
|
|
79
70
|
TPlugins extends ResolvedPlugins = ResolvedPlugins,
|
|
80
71
|
TExtraData = any,
|
|
@@ -120,3 +111,5 @@ export interface RatingSubmittedInfo extends HtRatingButton {
|
|
|
120
111
|
possibleOptions: string[]
|
|
121
112
|
possibleValues: number[]
|
|
122
113
|
}
|
|
114
|
+
|
|
115
|
+
export { AiAgentArgs, GuardrailRule }
|
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
HtKeywordNode,
|
|
8
8
|
HtNodeWithContent,
|
|
9
9
|
} from '../content-fields/hubtype-fields'
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
getCommonFlowContentEventArgsForContentId,
|
|
12
|
+
trackEvent,
|
|
13
|
+
} from '../tracking'
|
|
11
14
|
|
|
12
15
|
interface KeywordProps {
|
|
13
16
|
cmsApi: FlowBuilderApi
|
|
@@ -101,11 +104,19 @@ export class KeywordMatcher {
|
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
private async trackKeywordEvent() {
|
|
107
|
+
const { flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
108
|
+
getCommonFlowContentEventArgsForContentId(
|
|
109
|
+
this.request,
|
|
110
|
+
this.keywordNodeId as string
|
|
111
|
+
)
|
|
112
|
+
|
|
104
113
|
const event: EventKeyword = {
|
|
105
114
|
action: EventAction.Keyword,
|
|
115
|
+
flowNodeId,
|
|
116
|
+
flowId,
|
|
117
|
+
flowName,
|
|
118
|
+
flowNodeContentId,
|
|
106
119
|
flowThreadId: this.request.session.flow_thread_id as string,
|
|
107
|
-
flowNodeId: this.keywordNodeId as string,
|
|
108
|
-
flowId: this.flowId as string,
|
|
109
120
|
nluKeywordName: this.matchedKeyword as string,
|
|
110
121
|
nluKeywordIsRegex: this.isRegExp,
|
|
111
122
|
nluKeywordMessageId: this.request.input.message_id,
|
|
@@ -5,7 +5,10 @@ import axios from 'axios'
|
|
|
5
5
|
import { FlowBuilderApi } from '../api'
|
|
6
6
|
import { HtSmartIntentNode } from '../content-fields/hubtype-fields/smart-intent'
|
|
7
7
|
import { getFlowBuilderPlugin } from '../helpers'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getCommonFlowContentEventArgsForContentId,
|
|
10
|
+
trackEvent,
|
|
11
|
+
} from '../tracking'
|
|
9
12
|
import { SmartIntentResponse } from '../types'
|
|
10
13
|
|
|
11
14
|
export interface SmartIntentsInferenceParams {
|
|
@@ -55,6 +58,12 @@ export class SmartIntentsApi {
|
|
|
55
58
|
payload: targetPayload,
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
const { flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
62
|
+
getCommonFlowContentEventArgsForContentId(
|
|
63
|
+
this.currentRequest,
|
|
64
|
+
smartIntentNode.id
|
|
65
|
+
)
|
|
66
|
+
|
|
58
67
|
const event: EventIntentSmart = {
|
|
59
68
|
action: EventAction.IntentSmart,
|
|
60
69
|
nluIntentSmartTitle: response.data.smart_intent_title,
|
|
@@ -62,8 +71,10 @@ export class SmartIntentsApi {
|
|
|
62
71
|
nluIntentSmartMessageId: this.currentRequest.input.message_id,
|
|
63
72
|
userInput: this.currentRequest.input.data,
|
|
64
73
|
flowThreadId: this.currentRequest.session.flow_thread_id as string,
|
|
65
|
-
flowId
|
|
66
|
-
|
|
74
|
+
flowId,
|
|
75
|
+
flowName,
|
|
76
|
+
flowNodeContentId,
|
|
77
|
+
flowNodeId,
|
|
67
78
|
}
|
|
68
79
|
const { action, ...eventArgs } = event
|
|
69
80
|
|
package/src/utils.ts
CHANGED
|
@@ -28,7 +28,7 @@ export function getValueFromKeyPath(
|
|
|
28
28
|
request: ActionRequest,
|
|
29
29
|
keyPath: string
|
|
30
30
|
): any {
|
|
31
|
-
if (keyPath.startsWith('input') || keyPath.startsWith('session')) {
|
|
31
|
+
if (keyPath.startsWith('input.') || keyPath.startsWith('session.')) {
|
|
32
32
|
return keyPath
|
|
33
33
|
.split('.')
|
|
34
34
|
.reduce((object, key) => resolveObjectKey(object, key), request)
|