@botonic/plugin-flow-builder 0.45.0 → 0.46.0-alpha.1
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 -0
- package/lib/cjs/action/ai-agent.js.map +1 -1
- package/lib/cjs/action/first-interaction.js +1 -1
- package/lib/cjs/action/first-interaction.js.map +1 -1
- package/lib/cjs/action/index.js +1 -1
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.js +1 -1
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/api.d.ts +1 -0
- package/lib/cjs/api.js +4 -0
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/content-fields/flow-ai-agent.d.ts +3 -1
- package/lib/cjs/content-fields/flow-ai-agent.js +5 -0
- package/lib/cjs/content-fields/flow-ai-agent.js.map +1 -1
- package/lib/cjs/content-fields/flow-go-to-flow.d.ts +1 -0
- package/lib/cjs/content-fields/flow-go-to-flow.js +8 -0
- package/lib/cjs/content-fields/flow-go-to-flow.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/ai-agent.d.ts +3 -0
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +7 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/user-input/capture-user-input-api.d.ts +2 -1
- package/lib/cjs/user-input/capture-user-input-api.js +6 -5
- package/lib/cjs/user-input/capture-user-input-api.js.map +1 -1
- package/lib/cjs/user-input/index.js +6 -4
- package/lib/cjs/user-input/index.js.map +1 -1
- package/lib/cjs/user-input/keyword.d.ts +4 -2
- package/lib/cjs/user-input/keyword.js +5 -4
- package/lib/cjs/user-input/keyword.js.map +1 -1
- package/lib/cjs/user-input/smart-intent.d.ts +2 -2
- package/lib/cjs/user-input/smart-intent.js +5 -5
- package/lib/cjs/user-input/smart-intent.js.map +1 -1
- package/lib/cjs/utils.d.ts +2 -1
- package/lib/cjs/utils.js +16 -3
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/action/ai-agent.js +2 -0
- package/lib/esm/action/ai-agent.js.map +1 -1
- package/lib/esm/action/first-interaction.js +1 -1
- package/lib/esm/action/first-interaction.js.map +1 -1
- package/lib/esm/action/index.js +1 -1
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.js +1 -1
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/api.d.ts +1 -0
- package/lib/esm/api.js +4 -0
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/content-fields/flow-ai-agent.d.ts +3 -1
- package/lib/esm/content-fields/flow-ai-agent.js +5 -0
- package/lib/esm/content-fields/flow-ai-agent.js.map +1 -1
- package/lib/esm/content-fields/flow-go-to-flow.d.ts +1 -0
- package/lib/esm/content-fields/flow-go-to-flow.js +8 -0
- package/lib/esm/content-fields/flow-go-to-flow.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/ai-agent.d.ts +3 -0
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +7 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/user-input/capture-user-input-api.d.ts +2 -1
- package/lib/esm/user-input/capture-user-input-api.js +6 -5
- package/lib/esm/user-input/capture-user-input-api.js.map +1 -1
- package/lib/esm/user-input/index.js +6 -4
- package/lib/esm/user-input/index.js.map +1 -1
- package/lib/esm/user-input/keyword.d.ts +4 -2
- package/lib/esm/user-input/keyword.js +5 -4
- package/lib/esm/user-input/keyword.js.map +1 -1
- package/lib/esm/user-input/smart-intent.d.ts +2 -2
- package/lib/esm/user-input/smart-intent.js +5 -5
- package/lib/esm/user-input/smart-intent.js.map +1 -1
- package/lib/esm/utils.d.ts +2 -1
- package/lib/esm/utils.js +16 -3
- package/lib/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/action/ai-agent.ts +2 -0
- package/src/action/first-interaction.ts +2 -2
- package/src/action/index.tsx +2 -2
- package/src/action/knowledge-bases.ts +2 -2
- package/src/api.ts +5 -0
- package/src/content-fields/flow-ai-agent.tsx +5 -1
- package/src/content-fields/flow-go-to-flow.tsx +13 -1
- package/src/content-fields/hubtype-fields/ai-agent.ts +3 -0
- package/src/index.ts +18 -4
- package/src/user-input/capture-user-input-api.ts +12 -6
- package/src/user-input/index.ts +9 -7
- package/src/user-input/keyword.ts +10 -4
- package/src/user-input/smart-intent.ts +4 -4
- package/src/utils.ts +18 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";;;AAAA,wCAAuE;AAIvE,4CAA8C;AAK9C,0CAGoB;
|
|
1
|
+
{"version":3,"file":"keyword.js","sourceRoot":"","sources":["../../../src/user-input/keyword.ts"],"names":[],"mappings":";;;AAAA,wCAAuE;AAIvE,4CAA8C;AAK9C,0CAGoB;AAQpB,MAAa,cAAc;IAUzB,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAgB;QACzE,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;QACrB,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;IAClD,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAA;QAClD,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,CACvC,IAAI,CAAC,oBAAoB,EACzB,YAAY,CACb,CAAA;QACD,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzC,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAA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,QAAQ;YAChC,mBAAmB,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU;YAClD,SAAS,EAAE,IAAI,CAAC,oBAAoB;SACrC,CAAA;QACD,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAA;QACtC,MAAM,IAAA,qBAAU,EAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IACnD,CAAC;CACF;AAjHD,wCAiHC"}
|
|
@@ -15,8 +15,8 @@ export declare class SmartIntentsApi {
|
|
|
15
15
|
cmsApi: FlowBuilderApi;
|
|
16
16
|
currentRequest: ActionRequest;
|
|
17
17
|
smartIntentsConfig: SmartIntentsInferenceConfig;
|
|
18
|
-
|
|
19
|
-
constructor(cmsApi: FlowBuilderApi, currentRequest: ActionRequest, smartIntentsConfig: SmartIntentsInferenceConfig,
|
|
18
|
+
userTextOrTranscript: string;
|
|
19
|
+
constructor(cmsApi: FlowBuilderApi, currentRequest: ActionRequest, smartIntentsConfig: SmartIntentsInferenceConfig, userTextOrTranscript: string);
|
|
20
20
|
getNodeByInput(): Promise<HtSmartIntentNode | undefined>;
|
|
21
21
|
private resolveUseLatest;
|
|
22
22
|
private getInference;
|
|
@@ -7,14 +7,14 @@ const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
|
7
7
|
const helpers_1 = require("../helpers");
|
|
8
8
|
const tracking_1 = require("../tracking");
|
|
9
9
|
class SmartIntentsApi {
|
|
10
|
-
constructor(cmsApi, currentRequest, smartIntentsConfig,
|
|
10
|
+
constructor(cmsApi, currentRequest, smartIntentsConfig, userTextOrTranscript) {
|
|
11
11
|
this.cmsApi = cmsApi;
|
|
12
12
|
this.currentRequest = currentRequest;
|
|
13
13
|
this.smartIntentsConfig = smartIntentsConfig;
|
|
14
|
-
this.
|
|
14
|
+
this.userTextOrTranscript = userTextOrTranscript;
|
|
15
15
|
}
|
|
16
16
|
async getNodeByInput() {
|
|
17
|
-
if (!this.
|
|
17
|
+
if (!this.userTextOrTranscript) {
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
const smartIntentNodes = this.cmsApi.getSmartIntentNodes();
|
|
@@ -23,7 +23,7 @@ class SmartIntentsApi {
|
|
|
23
23
|
}
|
|
24
24
|
const params = {
|
|
25
25
|
bot_id: this.currentRequest.session.bot.id,
|
|
26
|
-
text: this.
|
|
26
|
+
text: this.userTextOrTranscript,
|
|
27
27
|
num_smart_intents_to_use: this.smartIntentsConfig.numSmartIntentsToUse,
|
|
28
28
|
use_latest: this.resolveUseLatest(),
|
|
29
29
|
};
|
|
@@ -43,7 +43,7 @@ class SmartIntentsApi {
|
|
|
43
43
|
nluIntentSmartTitle: response.data.smart_intent_title,
|
|
44
44
|
nluIntentSmartNumUsed: response.data.smart_intents_used.length,
|
|
45
45
|
nluIntentSmartMessageId: this.currentRequest.input.message_id,
|
|
46
|
-
userInput: this.
|
|
46
|
+
userInput: this.userTextOrTranscript,
|
|
47
47
|
flowThreadId: this.currentRequest.session.flow_thread_id,
|
|
48
48
|
flowId,
|
|
49
49
|
flowName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";;;;AAAA,wCAA2E;AAE3E,0DAAyB;AAIzB,wCAAiD;AACjD,0CAGoB;AAepB,MAAa,eAAe;IAC1B,YACS,MAAsB,EACtB,cAA6B,EAC7B,kBAA+C,EAC/C,
|
|
1
|
+
{"version":3,"file":"smart-intent.js","sourceRoot":"","sources":["../../../src/user-input/smart-intent.ts"],"names":[],"mappings":";;;;AAAA,wCAA2E;AAE3E,0DAAyB;AAIzB,wCAAiD;AACjD,0CAGoB;AAepB,MAAa,eAAe;IAC1B,YACS,MAAsB,EACtB,cAA6B,EAC7B,kBAA+C,EAC/C,oBAA4B;QAH5B,WAAM,GAAN,MAAM,CAAgB;QACtB,mBAAc,GAAd,cAAc,CAAe;QAC7B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,MAAM,IAAA,eAAK,EAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,0CAA0C;YAC7E,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;gBAChC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,KAAK;SACf,CAAC,CAAA;IACJ,CAAC;CACF;AA7FD,0CA6FC"}
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type Input, type Session } from '@botonic/core';
|
|
2
2
|
import type { ActionRequest } from '@botonic/react';
|
|
3
3
|
export declare function resolveGetAccessToken(getAccessToken: (session: Session) => string): (session: Session) => string;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function inputHasTextOrTranscript(input: Input): boolean;
|
|
5
|
+
export declare function getTextOrTranscript(input: Input): string | undefined;
|
|
5
6
|
export declare function isKeywordsAllowed(request: ActionRequest): boolean;
|
|
6
7
|
export declare function isSmartIntentsAllowed(request: ActionRequest): boolean;
|
|
7
8
|
export declare function isKnowledgeBasesAllowed(request: ActionRequest): boolean;
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveGetAccessToken = resolveGetAccessToken;
|
|
4
|
-
exports.
|
|
4
|
+
exports.inputHasTextOrTranscript = inputHasTextOrTranscript;
|
|
5
|
+
exports.getTextOrTranscript = getTextOrTranscript;
|
|
5
6
|
exports.isKeywordsAllowed = isKeywordsAllowed;
|
|
6
7
|
exports.isSmartIntentsAllowed = isSmartIntentsAllowed;
|
|
7
8
|
exports.isKnowledgeBasesAllowed = isKnowledgeBasesAllowed;
|
|
@@ -24,8 +25,20 @@ function resolveGetAccessToken(getAccessToken) {
|
|
|
24
25
|
throw new Error('No method defined for getting access token');
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
28
|
+
function inputHasTextOrTranscript(input) {
|
|
29
|
+
const isTextInput = Boolean(input.data) && input.type === core_1.INPUT.TEXT;
|
|
30
|
+
const isTranscriptText = Boolean(input.transcript) && input.type === core_1.INPUT.AUDIO;
|
|
31
|
+
return isTextInput || isTranscriptText;
|
|
32
|
+
}
|
|
33
|
+
function getTextOrTranscript(input) {
|
|
34
|
+
if (input.type === core_1.INPUT.TEXT && input.data) {
|
|
35
|
+
return input.data;
|
|
36
|
+
}
|
|
37
|
+
if (input.type === core_1.INPUT.AUDIO && input.transcript) {
|
|
38
|
+
return input.transcript;
|
|
39
|
+
}
|
|
40
|
+
console.error('No text or transcript found in input', input);
|
|
41
|
+
return undefined;
|
|
29
42
|
}
|
|
30
43
|
function isNluAllowed(request, nluFlag) {
|
|
31
44
|
const shadowing = Boolean(request.session._shadowing);
|
package/lib/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;AAaA,sDAWC;AAED,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;AAaA,sDAWC;AAED,4DAMC;AAED,kDAUC;AAWD,8CAEC;AAED,sDAEC;AAED,0DAEC;AAjED,wCAA+D;AAG/D,uCAAgD;AAChD,mCAAoE;AAEpE,SAAS,yBAAyB,CAAC,OAAgB;IACjD,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IACrD,CAAC;IACD,OAAO,OAAO,CAAC,aAAa,CAAA;AAC9B,CAAC;AAED,SAAgB,qBAAqB,CACnC,cAA4C;IAE5C,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC7B,KAAK,0BAAkB,CAAC,UAAU;YAChC,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OAAO,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;AAC/C,CAAC;AAED,SAAgB,qBAAqB,CAAC,OAAsB;IAC1D,OAAO,YAAY,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAA;AACnD,CAAC;AAED,SAAgB,uBAAuB,CAAC,OAAsB;IAC5D,OAAO,YAAY,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAA;AACrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0-alpha.1",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use Flow Builder to show your contents",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"format": "biome format --write src/ tests/"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@botonic/react": "^0.
|
|
18
|
+
"@botonic/react": "^0.46.0-alpha.1",
|
|
19
19
|
"axios": "^1.13.6",
|
|
20
20
|
"uuid": "^10.0.0"
|
|
21
21
|
},
|
package/src/action/ai-agent.ts
CHANGED
|
@@ -47,6 +47,8 @@ export async function getContentsByAiAgent({
|
|
|
47
47
|
{
|
|
48
48
|
name: aiAgentContent.name,
|
|
49
49
|
instructions: aiAgentContent.instructions,
|
|
50
|
+
model: aiAgentContent.model,
|
|
51
|
+
verbosity: aiAgentContent.verbosity,
|
|
50
52
|
activeTools: aiAgentContent.activeTools,
|
|
51
53
|
inputGuardrailRules: activeInputGuardrailRules,
|
|
52
54
|
sourceIds: aiAgentContent.sources?.map(source => source.id),
|
|
@@ -2,7 +2,7 @@ import type { FlowBuilderApi } from '../api'
|
|
|
2
2
|
import { MAIN_FLOW_NAME } from '../constants'
|
|
3
3
|
import { FlowBotAction, type FlowContent } from '../content-fields'
|
|
4
4
|
import type BotonicPluginFlowBuilder from '../index'
|
|
5
|
-
import {
|
|
5
|
+
import { inputHasTextOrTranscript } from '../utils'
|
|
6
6
|
import { getContentsByAiAgent } from './ai-agent'
|
|
7
7
|
import type { FlowBuilderContext } from './index'
|
|
8
8
|
import { getContentsByKnowledgeBase } from './knowledge-bases'
|
|
@@ -44,7 +44,7 @@ export async function getContentsByFirstInteraction(
|
|
|
44
44
|
return firstInteractionContents
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
if (request.input.nluResolution ||
|
|
47
|
+
if (request.input.nluResolution || inputHasTextOrTranscript(request.input)) {
|
|
48
48
|
const contentsByUserInput = await getContentsByUserInput(context)
|
|
49
49
|
|
|
50
50
|
return [...firstInteractionContents, ...contentsByUserInput]
|
package/src/action/index.tsx
CHANGED
|
@@ -15,7 +15,7 @@ import { FlowBotAction } from '../content-fields/flow-bot-action'
|
|
|
15
15
|
import { ContentFilterExecutor } from '../filters'
|
|
16
16
|
import { getFlowBuilderPlugin } from '../helpers'
|
|
17
17
|
import type BotonicPluginFlowBuilder from '../index'
|
|
18
|
-
import {
|
|
18
|
+
import { inputHasTextOrTranscript } from '../utils'
|
|
19
19
|
import { getContentsByAiAgent } from './ai-agent'
|
|
20
20
|
import { getContentsByFallback } from './fallback'
|
|
21
21
|
import { getContentsByFirstInteraction } from './first-interaction'
|
|
@@ -147,7 +147,7 @@ async function getContents(
|
|
|
147
147
|
return await getContentsByFallback(context)
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
if (
|
|
150
|
+
if (inputHasTextOrTranscript(request.input)) {
|
|
151
151
|
const aiAgentContents = await getContentsByAiAgent(context)
|
|
152
152
|
if (aiAgentContents.length > 0) {
|
|
153
153
|
return aiAgentContents
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
trackEvent,
|
|
18
18
|
} from '../tracking'
|
|
19
19
|
import type { KnowledgeBaseFunction } from '../types'
|
|
20
|
-
import {
|
|
20
|
+
import { inputHasTextOrTranscript, isKnowledgeBasesAllowed } from '../utils'
|
|
21
21
|
import type { FlowBuilderContext } from './index'
|
|
22
22
|
|
|
23
23
|
export async function getContentsByKnowledgeBase({
|
|
@@ -49,7 +49,7 @@ export async function getContentsByKnowledgeBase({
|
|
|
49
49
|
|
|
50
50
|
if (
|
|
51
51
|
flowBuilderPlugin.getKnowledgeBaseResponse &&
|
|
52
|
-
|
|
52
|
+
inputHasTextOrTranscript(request.input) &&
|
|
53
53
|
sourceIds.length > 0
|
|
54
54
|
) {
|
|
55
55
|
const contentsWithKnowledgeResponse =
|
package/src/api.ts
CHANGED
|
@@ -204,6 +204,11 @@ export class FlowBuilderApi {
|
|
|
204
204
|
return UUID_REGEXP.test(str)
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
isGotToFlow(id: string): boolean {
|
|
208
|
+
const node = this.getNodeById(id)
|
|
209
|
+
return node?.type === HtNodeWithContentType.GO_TO_FLOW
|
|
210
|
+
}
|
|
211
|
+
|
|
207
212
|
createPayloadWithParams(botActionNode: HtBotActionNode): string {
|
|
208
213
|
const payloadId = botActionNode.content.payload_id
|
|
209
214
|
const payloadNode = this.getNodeById<HtPayloadNode>(payloadId)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AgenticOutputMessage, VerbosityLevel } from '@botonic/core'
|
|
2
2
|
import type { ActionRequest } from '@botonic/react'
|
|
3
3
|
|
|
4
4
|
import { trackOneContent } from '../tracking'
|
|
@@ -13,6 +13,8 @@ import type {
|
|
|
13
13
|
export class FlowAiAgent extends ContentFieldsBase {
|
|
14
14
|
public name: string = ''
|
|
15
15
|
public instructions: string = ''
|
|
16
|
+
public model: string = ''
|
|
17
|
+
public verbosity: VerbosityLevel = VerbosityLevel.Medium
|
|
16
18
|
public activeTools?: { name: string }[]
|
|
17
19
|
public inputGuardrailRules: HtInputGuardrailRule[]
|
|
18
20
|
public sources?: { id: string; name: string }[]
|
|
@@ -24,6 +26,8 @@ export class FlowAiAgent extends ContentFieldsBase {
|
|
|
24
26
|
newAiAgent.code = component.code
|
|
25
27
|
newAiAgent.name = component.content.name
|
|
26
28
|
newAiAgent.instructions = component.content.instructions
|
|
29
|
+
newAiAgent.model = component.content.model
|
|
30
|
+
newAiAgent.verbosity = component.content.verbosity
|
|
27
31
|
newAiAgent.activeTools = component.content.active_tools
|
|
28
32
|
newAiAgent.inputGuardrailRules =
|
|
29
33
|
component.content.input_guardrail_rules || []
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventAction, type EventRedirectFlow } from '@botonic/core'
|
|
2
2
|
import type { ActionRequest } from '@botonic/react'
|
|
3
|
-
|
|
4
3
|
import type { FlowBuilderApi } from '../api'
|
|
4
|
+
import { AI_AGENTS_FLOW_NAME } from '../constants'
|
|
5
5
|
import {
|
|
6
6
|
getCommonFlowContentEventArgsForContentId,
|
|
7
7
|
trackEvent,
|
|
@@ -29,6 +29,18 @@ export class FlowGoToFlow extends ContentFieldsBase {
|
|
|
29
29
|
return newGoToFlow
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
static async resolveGoToFlowAiAgents(
|
|
33
|
+
botContext: ActionRequest,
|
|
34
|
+
component: HtGoToFlow,
|
|
35
|
+
cmsApi: FlowBuilderApi
|
|
36
|
+
): Promise<void> {
|
|
37
|
+
const goToFlowContent = FlowGoToFlow.fromHubtypeCMS(component, cmsApi)
|
|
38
|
+
if (goToFlowContent.flowTargetName === AI_AGENTS_FLOW_NAME) {
|
|
39
|
+
await goToFlowContent.trackFlow(botContext)
|
|
40
|
+
botContext.input.payload = undefined
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
32
44
|
async trackFlow(request: ActionRequest): Promise<void> {
|
|
33
45
|
const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } =
|
|
34
46
|
getCommonFlowContentEventArgsForContentId(request, this.id)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { VerbosityLevel } from '@botonic/core'
|
|
1
2
|
import type { HtBaseNode } from './common'
|
|
2
3
|
import type { HtNodeWithContentType } from './node-types'
|
|
3
4
|
|
|
@@ -12,6 +13,8 @@ export interface HtAiAgentNode extends HtBaseNode {
|
|
|
12
13
|
content: {
|
|
13
14
|
name: string
|
|
14
15
|
instructions: string
|
|
16
|
+
model: string
|
|
17
|
+
verbosity: VerbosityLevel
|
|
15
18
|
active_tools?: { name: string }[]
|
|
16
19
|
input_guardrail_rules?: HtInputGuardrailRule[]
|
|
17
20
|
sources?: { id: string; name: string }[]
|
package/src/index.ts
CHANGED
|
@@ -16,10 +16,11 @@ import {
|
|
|
16
16
|
SEPARATOR,
|
|
17
17
|
SOURCE_INFO_SEPARATOR,
|
|
18
18
|
} from './constants'
|
|
19
|
-
import type
|
|
19
|
+
import { type FlowContent, FlowGoToFlow } from './content-fields'
|
|
20
20
|
import {
|
|
21
21
|
type HtBotActionNode,
|
|
22
22
|
type HtFlowBuilderData,
|
|
23
|
+
type HtGoToFlow,
|
|
23
24
|
type HtNodeWithContent,
|
|
24
25
|
HtNodeWithContentType,
|
|
25
26
|
} from './content-fields/hubtype-fields'
|
|
@@ -38,7 +39,7 @@ import {
|
|
|
38
39
|
} from './types'
|
|
39
40
|
import { getNextPayloadByUserInput } from './user-input'
|
|
40
41
|
import type { SmartIntentsInferenceConfig } from './user-input/smart-intent'
|
|
41
|
-
import {
|
|
42
|
+
import { inputHasTextOrTranscript, resolveGetAccessToken } from './utils'
|
|
42
43
|
|
|
43
44
|
// TODO: Create a proper service to wrap all calls and allow api versioning
|
|
44
45
|
|
|
@@ -109,7 +110,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
109
110
|
})
|
|
110
111
|
|
|
111
112
|
const checkUserTextInput =
|
|
112
|
-
|
|
113
|
+
inputHasTextOrTranscript(request.input) && !request.input.payload
|
|
113
114
|
|
|
114
115
|
if (checkUserTextInput) {
|
|
115
116
|
const resolvedLocale = this.cmsApi.getResolvedLocale()
|
|
@@ -138,7 +139,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
|
|
141
|
-
private updateRequestBeforeRoutes(
|
|
142
|
+
private async updateRequestBeforeRoutes(
|
|
143
|
+
request: PluginPreRequest
|
|
144
|
+
): Promise<void> {
|
|
142
145
|
this.cmsApi.removeCaptureUserInputId()
|
|
143
146
|
if (request.input.payload) {
|
|
144
147
|
request.input.payload = this.removeSourceSuffix(request.input.payload)
|
|
@@ -155,6 +158,17 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
155
158
|
// the case that a BotAction has a payload equals to EMPTY_PAYLOAD
|
|
156
159
|
this.convertWhatsappAiAgentEmptyPayloads(request)
|
|
157
160
|
}
|
|
161
|
+
|
|
162
|
+
if (this.cmsApi.isGotToFlow(request.input.payload)) {
|
|
163
|
+
const cmsGoToFlow = this.cmsApi.getNodeById<HtGoToFlow>(
|
|
164
|
+
request.input.payload
|
|
165
|
+
)
|
|
166
|
+
await FlowGoToFlow.resolveGoToFlowAiAgents(
|
|
167
|
+
request,
|
|
168
|
+
cmsGoToFlow,
|
|
169
|
+
this.cmsApi
|
|
170
|
+
)
|
|
171
|
+
}
|
|
158
172
|
}
|
|
159
173
|
}
|
|
160
174
|
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
getCommonFlowContentEventArgsForContentId,
|
|
14
14
|
trackEvent,
|
|
15
15
|
} from '../tracking'
|
|
16
|
-
import {
|
|
16
|
+
import { inputHasTextOrTranscript } from '../utils'
|
|
17
17
|
|
|
18
18
|
interface AiCaptureResponseSuccess {
|
|
19
19
|
success: true
|
|
@@ -29,19 +29,25 @@ type AiCaptureResponse = AiCaptureResponseSuccess | AiCaptureResponseFailure
|
|
|
29
29
|
export class CaptureUserInputApi {
|
|
30
30
|
private cmsApi: FlowBuilderApi
|
|
31
31
|
private request: ActionRequest
|
|
32
|
+
private textOrTranscript: string
|
|
32
33
|
|
|
33
|
-
constructor(
|
|
34
|
+
constructor(
|
|
35
|
+
cmsApi: FlowBuilderApi,
|
|
36
|
+
request: ActionRequest,
|
|
37
|
+
textOrTranscript: string
|
|
38
|
+
) {
|
|
34
39
|
this.cmsApi = cmsApi
|
|
35
40
|
this.request = request
|
|
41
|
+
this.textOrTranscript = textOrTranscript
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
async getNextNodeId(): Promise<string | undefined> {
|
|
39
45
|
if (
|
|
40
|
-
|
|
46
|
+
inputHasTextOrTranscript(this.request.input) &&
|
|
41
47
|
this.cmsApi.shouldCaptureUserInput()
|
|
42
48
|
) {
|
|
43
49
|
const captureUserInputNode = this.cmsApi.getCaptureUserInputNode()
|
|
44
|
-
if (!captureUserInputNode) {
|
|
50
|
+
if (!captureUserInputNode || !this.textOrTranscript) {
|
|
45
51
|
return undefined
|
|
46
52
|
}
|
|
47
53
|
const captureUserInput =
|
|
@@ -50,7 +56,7 @@ export class CaptureUserInputApi {
|
|
|
50
56
|
if (captureUserInput.aiValidationType === HtAiValidationType.NONE) {
|
|
51
57
|
this.cmsApi.setUserExtraDataVariable(
|
|
52
58
|
captureUserInputNode.content.field_name,
|
|
53
|
-
this.
|
|
59
|
+
this.textOrTranscript
|
|
54
60
|
)
|
|
55
61
|
await this.trackUserInputCapture(captureUserInputNode, true)
|
|
56
62
|
return captureUserInput.captureSuccessId
|
|
@@ -82,7 +88,7 @@ export class CaptureUserInputApi {
|
|
|
82
88
|
field_name: captureUserInputNode.content.field_name,
|
|
83
89
|
validation_instructions:
|
|
84
90
|
captureUserInputNode.content.ai_validation_instructions,
|
|
85
|
-
user_input: this.
|
|
91
|
+
user_input: this.textOrTranscript,
|
|
86
92
|
}
|
|
87
93
|
const pluginFlowBuilder = getFlowBuilderPlugin(this.request.plugins)
|
|
88
94
|
const token = pluginFlowBuilder.getAccessToken(this.request.session)
|
package/src/user-input/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ActionRequest } from '@botonic/react'
|
|
|
2
2
|
|
|
3
3
|
import type { FlowBuilderApi } from '../api'
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
getTextOrTranscript,
|
|
6
6
|
isKeywordsAllowed,
|
|
7
7
|
isSmartIntentsAllowed,
|
|
8
8
|
} from '../utils'
|
|
@@ -19,11 +19,13 @@ export async function getNextPayloadByUserInput(
|
|
|
19
19
|
request: ActionRequest,
|
|
20
20
|
smartIntentsConfig: SmartIntentsInferenceConfig
|
|
21
21
|
): Promise<string | undefined> {
|
|
22
|
-
|
|
22
|
+
const userTextOrTranscript = getTextOrTranscript(request.input)
|
|
23
|
+
if (userTextOrTranscript) {
|
|
23
24
|
if (cmsApi.shouldCaptureUserInput()) {
|
|
24
25
|
const captureUserInputApi = new CaptureUserInputApi(
|
|
25
26
|
cmsApi,
|
|
26
|
-
request
|
|
27
|
+
request,
|
|
28
|
+
userTextOrTranscript
|
|
27
29
|
)
|
|
28
30
|
return await captureUserInputApi.getNextNodeId()
|
|
29
31
|
}
|
|
@@ -33,10 +35,9 @@ export async function getNextPayloadByUserInput(
|
|
|
33
35
|
cmsApi,
|
|
34
36
|
locale,
|
|
35
37
|
request,
|
|
38
|
+
userTextOrTranscript,
|
|
36
39
|
})
|
|
37
|
-
const keywordNode = await keywordMatcher.getNodeByInput(
|
|
38
|
-
request.input.data!
|
|
39
|
-
)
|
|
40
|
+
const keywordNode = await keywordMatcher.getNodeByInput()
|
|
40
41
|
if (keywordNode) {
|
|
41
42
|
return cmsApi.getPayload(keywordNode.target)
|
|
42
43
|
}
|
|
@@ -46,7 +47,8 @@ export async function getNextPayloadByUserInput(
|
|
|
46
47
|
const smartIntentsApi = new SmartIntentsApi(
|
|
47
48
|
cmsApi,
|
|
48
49
|
request,
|
|
49
|
-
smartIntentsConfig
|
|
50
|
+
smartIntentsConfig,
|
|
51
|
+
userTextOrTranscript
|
|
50
52
|
)
|
|
51
53
|
const smartIntentNode = await smartIntentsApi.getNodeByInput()
|
|
52
54
|
if (smartIntentNode) {
|
|
@@ -16,6 +16,7 @@ interface KeywordProps {
|
|
|
16
16
|
cmsApi: FlowBuilderApi
|
|
17
17
|
locale: string
|
|
18
18
|
request: ActionRequest
|
|
19
|
+
userTextOrTranscript: string
|
|
19
20
|
}
|
|
20
21
|
export class KeywordMatcher {
|
|
21
22
|
public cmsApi: FlowBuilderApi
|
|
@@ -25,17 +26,22 @@ export class KeywordMatcher {
|
|
|
25
26
|
public matchedKeyword?: string
|
|
26
27
|
public keywordNodeId?: string
|
|
27
28
|
public flowId?: string
|
|
29
|
+
public userTextOrTranscript: string
|
|
28
30
|
|
|
29
|
-
constructor({ cmsApi, locale, request }: KeywordProps) {
|
|
31
|
+
constructor({ cmsApi, locale, request, userTextOrTranscript }: KeywordProps) {
|
|
30
32
|
this.cmsApi = cmsApi
|
|
31
33
|
this.locale = locale
|
|
32
34
|
this.request = request
|
|
33
35
|
this.isRegExp = false
|
|
36
|
+
this.userTextOrTranscript = userTextOrTranscript
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
async getNodeByInput(
|
|
39
|
+
async getNodeByInput(): Promise<HtKeywordNode | undefined> {
|
|
37
40
|
const keywordNodes = this.cmsApi.getKeywordNodes()
|
|
38
|
-
const keywordNode = this.getNodeByKeyword(
|
|
41
|
+
const keywordNode = this.getNodeByKeyword(
|
|
42
|
+
this.userTextOrTranscript,
|
|
43
|
+
keywordNodes
|
|
44
|
+
)
|
|
39
45
|
if (!keywordNode || !this.matchedKeyword) {
|
|
40
46
|
return undefined
|
|
41
47
|
}
|
|
@@ -120,7 +126,7 @@ export class KeywordMatcher {
|
|
|
120
126
|
nluKeywordName: this.matchedKeyword as string,
|
|
121
127
|
nluKeywordIsRegex: this.isRegExp,
|
|
122
128
|
nluKeywordMessageId: this.request.input.message_id,
|
|
123
|
-
userInput: this.
|
|
129
|
+
userInput: this.userTextOrTranscript,
|
|
124
130
|
}
|
|
125
131
|
const { action, ...eventArgs } = event
|
|
126
132
|
await trackEvent(this.request, action, eventArgs)
|
|
@@ -28,11 +28,11 @@ export class SmartIntentsApi {
|
|
|
28
28
|
public cmsApi: FlowBuilderApi,
|
|
29
29
|
public currentRequest: ActionRequest,
|
|
30
30
|
public smartIntentsConfig: SmartIntentsInferenceConfig,
|
|
31
|
-
public
|
|
31
|
+
public userTextOrTranscript: string
|
|
32
32
|
) {}
|
|
33
33
|
|
|
34
34
|
async getNodeByInput(): Promise<HtSmartIntentNode | undefined> {
|
|
35
|
-
if (!this.
|
|
35
|
+
if (!this.userTextOrTranscript) {
|
|
36
36
|
return undefined
|
|
37
37
|
}
|
|
38
38
|
const smartIntentNodes = this.cmsApi.getSmartIntentNodes()
|
|
@@ -42,7 +42,7 @@ export class SmartIntentsApi {
|
|
|
42
42
|
|
|
43
43
|
const params = {
|
|
44
44
|
bot_id: this.currentRequest.session.bot.id,
|
|
45
|
-
text: this.
|
|
45
|
+
text: this.userTextOrTranscript,
|
|
46
46
|
num_smart_intents_to_use: this.smartIntentsConfig.numSmartIntentsToUse,
|
|
47
47
|
use_latest: this.resolveUseLatest(),
|
|
48
48
|
}
|
|
@@ -73,7 +73,7 @@ export class SmartIntentsApi {
|
|
|
73
73
|
nluIntentSmartTitle: response.data.smart_intent_title,
|
|
74
74
|
nluIntentSmartNumUsed: response.data.smart_intents_used.length,
|
|
75
75
|
nluIntentSmartMessageId: this.currentRequest.input.message_id,
|
|
76
|
-
userInput: this.
|
|
76
|
+
userInput: this.userTextOrTranscript,
|
|
77
77
|
flowThreadId: this.currentRequest.session.flow_thread_id as string,
|
|
78
78
|
flowId,
|
|
79
79
|
flowName,
|
package/src/utils.ts
CHANGED
|
@@ -24,8 +24,24 @@ export function resolveGetAccessToken(
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function
|
|
28
|
-
|
|
27
|
+
export function inputHasTextOrTranscript(input: Input): boolean {
|
|
28
|
+
const isTextInput = Boolean(input.data) && input.type === INPUT.TEXT
|
|
29
|
+
const isTranscriptText =
|
|
30
|
+
Boolean(input.transcript) && input.type === INPUT.AUDIO
|
|
31
|
+
|
|
32
|
+
return isTextInput || isTranscriptText
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getTextOrTranscript(input: Input): string | undefined {
|
|
36
|
+
if (input.type === INPUT.TEXT && input.data) {
|
|
37
|
+
return input.data
|
|
38
|
+
}
|
|
39
|
+
if (input.type === INPUT.AUDIO && input.transcript) {
|
|
40
|
+
return input.transcript
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.error('No text or transcript found in input', input)
|
|
44
|
+
return undefined
|
|
29
45
|
}
|
|
30
46
|
|
|
31
47
|
function isNluAllowed(
|