@botonic/react 0.54.0 → 0.55.1-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/components/index-types.d.ts +0 -2
- package/lib/cjs/components/message/index.js +2 -4
- package/lib/cjs/components/message/index.js.map +1 -1
- package/lib/cjs/components/message/message-footer.d.ts +1 -4
- package/lib/cjs/components/message/message-footer.js +2 -3
- package/lib/cjs/components/message/message-footer.js.map +1 -1
- package/lib/cjs/components/system-debug-trace/debug-message.js +0 -2
- package/lib/cjs/components/system-debug-trace/debug-message.js.map +1 -1
- package/lib/cjs/components/system-debug-trace/events/ai-agent/ai-agent.d.ts +1 -1
- package/lib/cjs/components/system-debug-trace/events/ai-agent/ai-agent.js +6 -2
- package/lib/cjs/components/system-debug-trace/events/ai-agent/ai-agent.js.map +1 -1
- package/lib/cjs/components/system-debug-trace/events/ai-agent/rehydrate-ai-agent-event.d.ts +6 -0
- package/lib/cjs/components/system-debug-trace/events/ai-agent/rehydrate-ai-agent-event.js +55 -0
- package/lib/cjs/components/system-debug-trace/events/ai-agent/rehydrate-ai-agent-event.js.map +1 -0
- package/lib/cjs/components/system-debug-trace/events/ai-agent/types.d.ts +2 -0
- package/lib/cjs/components/system-debug-trace/events/ai-agent/use-rehydrated-ai-agent-event.d.ts +8 -0
- package/lib/cjs/components/system-debug-trace/events/ai-agent/use-rehydrated-ai-agent-event.js +41 -0
- package/lib/cjs/components/system-debug-trace/events/ai-agent/use-rehydrated-ai-agent-event.js.map +1 -0
- package/lib/cjs/components/system-debug-trace/events/constants.d.ts +0 -2
- package/lib/cjs/components/system-debug-trace/events/constants.js +0 -2
- package/lib/cjs/components/system-debug-trace/events/constants.js.map +1 -1
- package/lib/cjs/components/system-debug-trace/events/index.d.ts +0 -1
- package/lib/cjs/components/system-debug-trace/events/index.js +0 -1
- package/lib/cjs/components/system-debug-trace/events/index.js.map +1 -1
- package/lib/cjs/components/system-debug-trace/hooks/use-knowledge-base-info.d.ts +1 -4
- package/lib/cjs/components/system-debug-trace/hooks/use-knowledge-base-info.js +2 -24
- package/lib/cjs/components/system-debug-trace/hooks/use-knowledge-base-info.js.map +1 -1
- package/lib/cjs/components/system-debug-trace/types.d.ts +2 -2
- package/lib/cjs/components/text.js +0 -2
- package/lib/cjs/components/text.js.map +1 -1
- package/lib/cjs/debug-system-messages.d.ts +0 -22
- package/lib/cjs/debug-system-messages.js +0 -22
- package/lib/cjs/debug-system-messages.js.map +1 -1
- package/lib/cjs/dev-app.d.ts +0 -22
- package/lib/cjs/index-types.d.ts +5 -1
- package/lib/cjs/index-types.js.map +1 -1
- package/lib/cjs/webchat/input-panel/index.js +7 -17
- package/lib/cjs/webchat/input-panel/index.js.map +1 -1
- package/lib/cjs/webchat/input-panel/textarea.d.ts +3 -2
- package/lib/cjs/webchat/input-panel/textarea.js +16 -46
- package/lib/cjs/webchat/input-panel/textarea.js.map +1 -1
- package/lib/cjs/webchat/input-panel/typing-network-sender.d.ts +52 -0
- package/lib/cjs/webchat/input-panel/typing-network-sender.js +122 -0
- package/lib/cjs/webchat/input-panel/typing-network-sender.js.map +1 -0
- package/lib/cjs/webchat/input-panel/use-typing-chat-event-sender.d.ts +16 -0
- package/lib/cjs/webchat/input-panel/use-typing-chat-event-sender.js +45 -0
- package/lib/cjs/webchat/input-panel/use-typing-chat-event-sender.js.map +1 -0
- package/lib/cjs/webchat/input-panel/use-typing-session.d.ts +15 -0
- package/lib/cjs/webchat/input-panel/use-typing-session.js +98 -0
- package/lib/cjs/webchat/input-panel/use-typing-session.js.map +1 -0
- package/lib/cjs/webchat/tracking.d.ts +0 -10
- package/lib/cjs/webchat/tracking.js +1 -32
- package/lib/cjs/webchat/tracking.js.map +1 -1
- package/lib/esm/components/index-types.d.ts +0 -2
- package/lib/esm/components/message/index.js +2 -4
- package/lib/esm/components/message/index.js.map +1 -1
- package/lib/esm/components/message/message-footer.d.ts +1 -4
- package/lib/esm/components/message/message-footer.js +2 -3
- package/lib/esm/components/message/message-footer.js.map +1 -1
- package/lib/esm/components/system-debug-trace/debug-message.js +0 -2
- package/lib/esm/components/system-debug-trace/debug-message.js.map +1 -1
- package/lib/esm/components/system-debug-trace/events/ai-agent/ai-agent.d.ts +1 -1
- package/lib/esm/components/system-debug-trace/events/ai-agent/ai-agent.js +6 -2
- package/lib/esm/components/system-debug-trace/events/ai-agent/ai-agent.js.map +1 -1
- package/lib/esm/components/system-debug-trace/events/ai-agent/rehydrate-ai-agent-event.d.ts +6 -0
- package/lib/esm/components/system-debug-trace/events/ai-agent/rehydrate-ai-agent-event.js +55 -0
- package/lib/esm/components/system-debug-trace/events/ai-agent/rehydrate-ai-agent-event.js.map +1 -0
- package/lib/esm/components/system-debug-trace/events/ai-agent/types.d.ts +2 -0
- package/lib/esm/components/system-debug-trace/events/ai-agent/use-rehydrated-ai-agent-event.d.ts +8 -0
- package/lib/esm/components/system-debug-trace/events/ai-agent/use-rehydrated-ai-agent-event.js +41 -0
- package/lib/esm/components/system-debug-trace/events/ai-agent/use-rehydrated-ai-agent-event.js.map +1 -0
- package/lib/esm/components/system-debug-trace/events/constants.d.ts +0 -2
- package/lib/esm/components/system-debug-trace/events/constants.js +0 -2
- package/lib/esm/components/system-debug-trace/events/constants.js.map +1 -1
- package/lib/esm/components/system-debug-trace/events/index.d.ts +0 -1
- package/lib/esm/components/system-debug-trace/events/index.js +0 -1
- package/lib/esm/components/system-debug-trace/events/index.js.map +1 -1
- package/lib/esm/components/system-debug-trace/hooks/use-knowledge-base-info.d.ts +1 -4
- package/lib/esm/components/system-debug-trace/hooks/use-knowledge-base-info.js +2 -24
- package/lib/esm/components/system-debug-trace/hooks/use-knowledge-base-info.js.map +1 -1
- package/lib/esm/components/system-debug-trace/types.d.ts +2 -2
- package/lib/esm/components/text.js +0 -2
- package/lib/esm/components/text.js.map +1 -1
- package/lib/esm/debug-system-messages.d.ts +0 -22
- package/lib/esm/debug-system-messages.js +0 -22
- package/lib/esm/debug-system-messages.js.map +1 -1
- package/lib/esm/dev-app.d.ts +0 -22
- package/lib/esm/index-types.d.ts +5 -1
- package/lib/esm/index-types.js.map +1 -1
- package/lib/esm/webchat/input-panel/index.js +7 -17
- package/lib/esm/webchat/input-panel/index.js.map +1 -1
- package/lib/esm/webchat/input-panel/textarea.d.ts +3 -2
- package/lib/esm/webchat/input-panel/textarea.js +16 -46
- package/lib/esm/webchat/input-panel/textarea.js.map +1 -1
- package/lib/esm/webchat/input-panel/typing-network-sender.d.ts +52 -0
- package/lib/esm/webchat/input-panel/typing-network-sender.js +122 -0
- package/lib/esm/webchat/input-panel/typing-network-sender.js.map +1 -0
- package/lib/esm/webchat/input-panel/use-typing-chat-event-sender.d.ts +16 -0
- package/lib/esm/webchat/input-panel/use-typing-chat-event-sender.js +45 -0
- package/lib/esm/webchat/input-panel/use-typing-chat-event-sender.js.map +1 -0
- package/lib/esm/webchat/input-panel/use-typing-session.d.ts +15 -0
- package/lib/esm/webchat/input-panel/use-typing-session.js +98 -0
- package/lib/esm/webchat/input-panel/use-typing-session.js.map +1 -0
- package/lib/esm/webchat/tracking.d.ts +0 -10
- package/lib/esm/webchat/tracking.js +1 -32
- package/lib/esm/webchat/tracking.js.map +1 -1
- package/package.json +2 -2
- package/src/components/index-types.ts +0 -2
- package/src/components/message/index.jsx +1 -8
- package/src/components/message/message-footer.tsx +0 -14
- package/src/components/system-debug-trace/debug-message.tsx +0 -3
- package/src/components/system-debug-trace/events/ai-agent/ai-agent.tsx +22 -10
- package/src/components/system-debug-trace/events/ai-agent/rehydrate-ai-agent-event.ts +70 -0
- package/src/components/system-debug-trace/events/ai-agent/types.ts +2 -0
- package/src/components/system-debug-trace/events/ai-agent/use-rehydrated-ai-agent-event.ts +67 -0
- package/src/components/system-debug-trace/events/constants.ts +0 -2
- package/src/components/system-debug-trace/events/index.ts +0 -1
- package/src/components/system-debug-trace/hooks/use-knowledge-base-info.tsx +2 -28
- package/src/components/system-debug-trace/types.ts +0 -2
- package/src/components/text.tsx +0 -2
- package/src/debug-system-messages.ts +0 -25
- package/src/index-types.ts +9 -1
- package/src/webchat/input-panel/index.tsx +7 -17
- package/src/webchat/input-panel/textarea.tsx +20 -60
- package/src/webchat/input-panel/typing-network-sender.ts +168 -0
- package/src/webchat/input-panel/use-typing-chat-event-sender.ts +67 -0
- package/src/webchat/input-panel/use-typing-session.ts +124 -0
- package/src/webchat/tracking.ts +2 -56
- package/lib/cjs/components/message/message-feedback.d.ts +0 -7
- package/lib/cjs/components/message/message-feedback.js +0 -55
- package/lib/cjs/components/message/message-feedback.js.map +0 -1
- package/lib/cjs/components/system-debug-trace/events/knowledge-base.d.ts +0 -17
- package/lib/cjs/components/system-debug-trace/events/knowledge-base.js +0 -42
- package/lib/cjs/components/system-debug-trace/events/knowledge-base.js.map +0 -1
- package/lib/esm/components/message/message-feedback.d.ts +0 -7
- package/lib/esm/components/message/message-feedback.js +0 -55
- package/lib/esm/components/message/message-feedback.js.map +0 -1
- package/lib/esm/components/system-debug-trace/events/knowledge-base.d.ts +0 -17
- package/lib/esm/components/system-debug-trace/events/knowledge-base.js +0 -42
- package/lib/esm/components/system-debug-trace/events/knowledge-base.js.map +0 -1
- package/src/components/message/message-feedback.tsx +0 -90
- package/src/components/system-debug-trace/events/knowledge-base.tsx +0 -115
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TYPING_IDLE_MS = void 0;
|
|
4
|
+
exports.useTypingSession = useTypingSession;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const index_types_1 = require("../../index-types");
|
|
7
|
+
/** Local UI inactivity before the textarea stops emitting typing events. */
|
|
8
|
+
exports.TYPING_IDLE_MS = 10 * 1000;
|
|
9
|
+
/**
|
|
10
|
+
* UI-layer typing session for the textarea.
|
|
11
|
+
*
|
|
12
|
+
* Decides *when* the user is typing and requests typing_on / typing_off.
|
|
13
|
+
* Deduplication and network debouncing live in TypingNetworkSender instead.
|
|
14
|
+
*/
|
|
15
|
+
function useTypingSession(sendChatEvent) {
|
|
16
|
+
const isTyping = (0, react_1.useRef)(false);
|
|
17
|
+
// Bumps on each start/stop so stale async stopTyping() calls can be ignored.
|
|
18
|
+
const startOrStopTypingCount = (0, react_1.useRef)(0);
|
|
19
|
+
const idleTimer = (0, react_1.useRef)(null);
|
|
20
|
+
// Shares one in-flight typing_on while delivery is still pending.
|
|
21
|
+
const pendingTypingOn = (0, react_1.useRef)(null);
|
|
22
|
+
const stopTyping = (0, react_1.useCallback)(async () => {
|
|
23
|
+
const countWhenStopWasRequested = ++startOrStopTypingCount.current;
|
|
24
|
+
if (idleTimer.current) {
|
|
25
|
+
clearTimeout(idleTimer.current);
|
|
26
|
+
idleTimer.current = null;
|
|
27
|
+
}
|
|
28
|
+
// Wait for typing_on to settle before deciding whether to send typing_off.
|
|
29
|
+
if (pendingTypingOn.current) {
|
|
30
|
+
await pendingTypingOn.current;
|
|
31
|
+
}
|
|
32
|
+
// Let same-turn input events (e.g. Enter then type next message) bump the counter first.
|
|
33
|
+
await Promise.resolve();
|
|
34
|
+
if (countWhenStopWasRequested !== startOrStopTypingCount.current) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!isTyping.current) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
isTyping.current = false;
|
|
41
|
+
await sendChatEvent(index_types_1.Typing.Off);
|
|
42
|
+
}, [sendChatEvent]);
|
|
43
|
+
const startTyping = (0, react_1.useCallback)(async () => {
|
|
44
|
+
if (isTyping.current) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (pendingTypingOn.current) {
|
|
48
|
+
return pendingTypingOn.current;
|
|
49
|
+
}
|
|
50
|
+
pendingTypingOn.current = (async () => {
|
|
51
|
+
try {
|
|
52
|
+
const accepted = await sendChatEvent(index_types_1.Typing.On);
|
|
53
|
+
// Only mark active after the network layer confirms delivery.
|
|
54
|
+
if (accepted) {
|
|
55
|
+
isTyping.current = true;
|
|
56
|
+
}
|
|
57
|
+
return accepted;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
pendingTypingOn.current = null;
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
return pendingTypingOn.current;
|
|
64
|
+
}, [sendChatEvent]);
|
|
65
|
+
const onTextChange = (0, react_1.useCallback)(async (value) => {
|
|
66
|
+
if (value === '') {
|
|
67
|
+
await stopTyping();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const countWhenUserTyped = ++startOrStopTypingCount.current;
|
|
71
|
+
await startTyping();
|
|
72
|
+
if (countWhenUserTyped !== startOrStopTypingCount.current) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!isTyping.current) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Reset the idle timer on every keystroke.
|
|
79
|
+
if (idleTimer.current) {
|
|
80
|
+
clearTimeout(idleTimer.current);
|
|
81
|
+
}
|
|
82
|
+
idleTimer.current = setTimeout(() => {
|
|
83
|
+
stopTyping().catch(() => { });
|
|
84
|
+
}, exports.TYPING_IDLE_MS);
|
|
85
|
+
}, [startTyping, stopTyping]);
|
|
86
|
+
const stopTypingRef = (0, react_1.useRef)(stopTyping);
|
|
87
|
+
stopTypingRef.current = stopTyping;
|
|
88
|
+
(0, react_1.useEffect)(() => {
|
|
89
|
+
return () => {
|
|
90
|
+
if (idleTimer.current) {
|
|
91
|
+
clearTimeout(idleTimer.current);
|
|
92
|
+
}
|
|
93
|
+
stopTypingRef.current().catch(() => { });
|
|
94
|
+
};
|
|
95
|
+
}, []);
|
|
96
|
+
return { stopTyping, onTextChange };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=use-typing-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-typing-session.js","sourceRoot":"","sources":["../../../../src/webchat/input-panel/use-typing-session.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import type { EventCustom, EventFeedback } from '@botonic/core';
|
|
2
|
-
export declare enum EventAction {
|
|
3
|
-
FeedbackKnowledgebase = "feedback_knowledgebase"
|
|
4
|
-
}
|
|
5
|
-
interface TrackKnowledgebaseFeedbackArgs {
|
|
6
|
-
messageId: string;
|
|
7
|
-
isUseful: boolean;
|
|
8
|
-
botInteractionId?: string;
|
|
9
|
-
inferenceId?: string;
|
|
10
|
-
}
|
|
11
2
|
interface UseTracking {
|
|
12
|
-
trackKnowledgebaseFeedback: ({ messageId, isUseful, botInteractionId, inferenceId, }: TrackKnowledgebaseFeedbackArgs) => Promise<void>;
|
|
13
3
|
trackCustomEvent: (event: EventCustom) => Promise<void>;
|
|
14
4
|
trackFeedbackEvent: (event: EventFeedback) => Promise<void>;
|
|
15
5
|
}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventAction = void 0;
|
|
4
3
|
exports.useTracking = useTracking;
|
|
5
4
|
const react_1 = require("react");
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
7
5
|
const context_1 = require("./context");
|
|
8
|
-
var EventAction;
|
|
9
|
-
(function (EventAction) {
|
|
10
|
-
EventAction["FeedbackKnowledgebase"] = "feedback_knowledgebase";
|
|
11
|
-
})(EventAction || (exports.EventAction = EventAction = {}));
|
|
12
|
-
var FeedbackOption;
|
|
13
|
-
(function (FeedbackOption) {
|
|
14
|
-
FeedbackOption["ThumbsUp"] = "thumbsUp";
|
|
15
|
-
FeedbackOption["ThumbsDown"] = "thumbsDown";
|
|
16
|
-
})(FeedbackOption || (FeedbackOption = {}));
|
|
17
6
|
function useTracking() {
|
|
18
7
|
const { webchatState, trackEvent } = (0, react_1.useContext)(context_1.WebchatContext);
|
|
19
8
|
const getRequest = () => {
|
|
@@ -29,26 +18,6 @@ function useTracking() {
|
|
|
29
18
|
};
|
|
30
19
|
return request;
|
|
31
20
|
};
|
|
32
|
-
const trackKnowledgebaseFeedback = async ({ messageId, isUseful, botInteractionId, inferenceId, }) => {
|
|
33
|
-
if (!trackEvent) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const request = getRequest();
|
|
37
|
-
// inferenceId and botInteractionId are strings, but in local development they are undefined
|
|
38
|
-
const event = {
|
|
39
|
-
action: EventAction.FeedbackKnowledgebase,
|
|
40
|
-
knowledgebaseInferenceId: inferenceId,
|
|
41
|
-
feedbackBotInteractionId: botInteractionId,
|
|
42
|
-
feedbackTargetId: messageId,
|
|
43
|
-
feedbackGroupId: (0, uuid_1.v7)(),
|
|
44
|
-
possibleOptions: [FeedbackOption.ThumbsDown, FeedbackOption.ThumbsUp],
|
|
45
|
-
possibleValues: [0, 1],
|
|
46
|
-
option: isUseful ? FeedbackOption.ThumbsUp : FeedbackOption.ThumbsDown,
|
|
47
|
-
value: isUseful ? 1 : 0,
|
|
48
|
-
};
|
|
49
|
-
const { action, ...eventArgs } = event;
|
|
50
|
-
await trackEvent(request, action, eventArgs);
|
|
51
|
-
};
|
|
52
21
|
const trackCustomEvent = async (event) => {
|
|
53
22
|
if (!trackEvent) {
|
|
54
23
|
return;
|
|
@@ -65,6 +34,6 @@ function useTracking() {
|
|
|
65
34
|
const { action, ...eventArgs } = event;
|
|
66
35
|
await trackEvent(request, action, eventArgs);
|
|
67
36
|
};
|
|
68
|
-
return {
|
|
37
|
+
return { trackCustomEvent, trackFeedbackEvent };
|
|
69
38
|
}
|
|
70
39
|
//# sourceMappingURL=tracking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../../src/webchat/tracking.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tracking.js","sourceRoot":"","sources":["../../../src/webchat/tracking.ts"],"names":[],"mappings":";;AAWA,kCAuCC;AAjDD,iCAAkC;AAGlC,uCAA0C;AAO1C,SAAgB,WAAW;IACzB,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,IAAA,kBAAU,EAAC,wBAAc,CAAC,CAAA;IAE/D,MAAM,UAAU,GAAG,GAAG,EAAE;QACtB,MAAM,OAAO,GAAG;YACd,OAAO,EAAE;gBACP,GAAG,YAAY,CAAC,OAAO;aACxB;YACD,cAAc,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE;YAC9D,aAAa,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE;YAC5D,eAAe,EAAE,GAAG,EAAE;gBACpB,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,IAAI,EAAE,CAAA;YACvD,CAAC;SAC0B,CAAA;QAE7B,OAAO,OAAO,CAAA;IAChB,CAAC,CAAA;IAED,MAAM,gBAAgB,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;QACpD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAM;QACR,CAAC;QAED,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;QAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAA;QACtC,MAAM,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IAC9C,CAAC,CAAA;IAED,MAAM,kBAAkB,GAAG,KAAK,EAAE,KAAoB,EAAE,EAAE;QACxD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAM;QACR,CAAC;QAED,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;QAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAA;QACtC,MAAM,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IAC9C,CAAC,CAAA;IAED,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAA;AACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.1-alpha.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Build Chatbots using React",
|
|
6
6
|
"main": "./lib/cjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"format": "biome format --write src/ tests/"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@botonic/core": "^0.
|
|
23
|
+
"@botonic/core": "^0.55.0",
|
|
24
24
|
"axios": "^1.18.1",
|
|
25
25
|
"emoji-picker-react": "^4.12.0",
|
|
26
26
|
"lodash.merge": "^4.6.2",
|
|
@@ -38,8 +38,6 @@ export const Message = props => {
|
|
|
38
38
|
style,
|
|
39
39
|
imagestyle = props.imagestyle || props.imageStyle,
|
|
40
40
|
isUnread = true,
|
|
41
|
-
feedbackEnabled,
|
|
42
|
-
inferenceId,
|
|
43
41
|
botInteractionId,
|
|
44
42
|
markdown,
|
|
45
43
|
...otherProps
|
|
@@ -126,8 +124,6 @@ export const Message = props => {
|
|
|
126
124
|
customTypeName: decomposedChildren.customTypeName,
|
|
127
125
|
ack: ack,
|
|
128
126
|
isUnread: isUnread === 1 || isUnread === true,
|
|
129
|
-
feedbackEnabled,
|
|
130
|
-
inferenceId,
|
|
131
127
|
botInteractionId,
|
|
132
128
|
}
|
|
133
129
|
addMessage(message)
|
|
@@ -276,14 +272,11 @@ export const Message = props => {
|
|
|
276
272
|
{Boolean(blob) && hasBlobTick() && getBlobTick(5)}
|
|
277
273
|
</BlobContainer>
|
|
278
274
|
</MessageContainer>
|
|
279
|
-
{timestampsEnabled
|
|
275
|
+
{timestampsEnabled ? (
|
|
280
276
|
<MessageFooter
|
|
281
277
|
enabletimestamps={timestampsEnabled}
|
|
282
278
|
messageJSON={messageJSON}
|
|
283
279
|
sentBy={sentBy}
|
|
284
|
-
feedbackEnabled={feedbackEnabled}
|
|
285
|
-
inferenceId={inferenceId}
|
|
286
|
-
botInteractionId={botInteractionId}
|
|
287
280
|
/>
|
|
288
281
|
) : null}
|
|
289
282
|
</ConditionalWrapper>
|
|
@@ -2,7 +2,6 @@ import { useContext } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import { SENDERS } from '../../index-types'
|
|
4
4
|
import { WebchatContext } from '../../webchat/context'
|
|
5
|
-
import { MessageFeedback } from './message-feedback'
|
|
6
5
|
import { MessageFooterContainer } from './styles'
|
|
7
6
|
import { MessageTimestamp, resolveMessageTimestamps } from './timestamps'
|
|
8
7
|
|
|
@@ -10,18 +9,12 @@ interface MessageFooterProps {
|
|
|
10
9
|
enabletimestamps: boolean
|
|
11
10
|
messageJSON: any
|
|
12
11
|
sentBy: SENDERS
|
|
13
|
-
feedbackEnabled: boolean
|
|
14
|
-
inferenceId?: string
|
|
15
|
-
botInteractionId?: string
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
export const MessageFooter = ({
|
|
19
15
|
enabletimestamps,
|
|
20
16
|
messageJSON,
|
|
21
17
|
sentBy,
|
|
22
|
-
feedbackEnabled,
|
|
23
|
-
inferenceId,
|
|
24
|
-
botInteractionId,
|
|
25
18
|
}: MessageFooterProps) => {
|
|
26
19
|
const { getThemeProperty } = useContext(WebchatContext)
|
|
27
20
|
|
|
@@ -46,13 +39,6 @@ export const MessageFooter = ({
|
|
|
46
39
|
timestamp={messageJSON.timestamp}
|
|
47
40
|
/>
|
|
48
41
|
) : null}
|
|
49
|
-
{feedbackEnabled ? (
|
|
50
|
-
<MessageFeedback
|
|
51
|
-
inferenceId={inferenceId}
|
|
52
|
-
messageId={messageJSON.id}
|
|
53
|
-
botInteractionId={botInteractionId}
|
|
54
|
-
/>
|
|
55
|
-
) : null}
|
|
56
42
|
</MessageFooterContainer>
|
|
57
43
|
)
|
|
58
44
|
}
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
getFallbackEventConfig,
|
|
15
15
|
getHandoffSuccessEventConfig,
|
|
16
16
|
getKeywordEventConfig,
|
|
17
|
-
getKnowledgeBaseEventConfig,
|
|
18
17
|
getRedirectFlowEventConfig,
|
|
19
18
|
getSmartIntentEventConfig,
|
|
20
19
|
getWebviewActionTriggeredEventConfig,
|
|
@@ -46,8 +45,6 @@ const getEventConfig = (
|
|
|
46
45
|
return getAiAgentEventConfig(debugEvent)
|
|
47
46
|
case EventAction.AiAgentRouter:
|
|
48
47
|
return getAiAgentRouterEventConfig(debugEvent)
|
|
49
|
-
case EventAction.Knowledgebase:
|
|
50
|
-
return getKnowledgeBaseEventConfig(debugEvent)
|
|
51
48
|
case EventAction.Fallback:
|
|
52
49
|
return getFallbackEventConfig(debugEvent)
|
|
53
50
|
case EventAction.BotAction:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventAction, type ToolExecution } from '@botonic/core'
|
|
2
2
|
import { useContext, useMemo } from 'react'
|
|
3
|
+
|
|
3
4
|
import { WebchatContext } from '../../../../webchat/context'
|
|
4
5
|
import { useKnowledgeBaseInfo } from '../../hooks/use-knowledge-base-info'
|
|
5
6
|
import { AiSpecialistSvg } from '../../icons'
|
|
@@ -14,17 +15,25 @@ import { LABELS } from '../constants'
|
|
|
14
15
|
import { ExecutedTools } from './executed-tools'
|
|
15
16
|
import { parseTools } from './parse-tools'
|
|
16
17
|
import type { AiAgentDebugEvent, ToolExecuted } from './types'
|
|
18
|
+
import { useRehydratedAiAgentEvent } from './use-rehydrated-ai-agent-event'
|
|
17
19
|
|
|
18
|
-
export const AiAgent = ({
|
|
19
|
-
tools_executed,
|
|
20
|
-
input_guardrails_triggered,
|
|
21
|
-
output_guardrails_triggered,
|
|
22
|
-
exit,
|
|
23
|
-
error,
|
|
24
|
-
messageId,
|
|
25
|
-
knowledge_base_chunks_with_sources,
|
|
26
|
-
}: AiAgentDebugEvent) => {
|
|
20
|
+
export const AiAgent = (props: AiAgentDebugEvent) => {
|
|
27
21
|
const { previewUtils } = useContext(WebchatContext)
|
|
22
|
+
const { resolvedEvent, isRehydrating } = useRehydratedAiAgentEvent(
|
|
23
|
+
props,
|
|
24
|
+
previewUtils
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
tools_executed,
|
|
29
|
+
input_guardrails_triggered,
|
|
30
|
+
output_guardrails_triggered,
|
|
31
|
+
exit,
|
|
32
|
+
error,
|
|
33
|
+
messageId,
|
|
34
|
+
knowledge_base_chunks_with_sources,
|
|
35
|
+
truncated,
|
|
36
|
+
} = resolvedEvent
|
|
28
37
|
|
|
29
38
|
const { otherTools, allSourcesIds, allChunksIds, query } = useMemo(
|
|
30
39
|
() => parseTools(tools_executed),
|
|
@@ -57,6 +66,9 @@ export const AiAgent = ({
|
|
|
57
66
|
previewUtils?.onClickOpenToolResults?.(toolExecution)
|
|
58
67
|
}
|
|
59
68
|
|
|
69
|
+
const showNoToolsExecuted =
|
|
70
|
+
!isRehydrating && !tools_executed.length && !truncated
|
|
71
|
+
|
|
60
72
|
return (
|
|
61
73
|
<>
|
|
62
74
|
{query && (
|
|
@@ -79,7 +91,7 @@ export const AiAgent = ({
|
|
|
79
91
|
onSeeToolDetails={handleSeeToolDetails}
|
|
80
92
|
/>
|
|
81
93
|
|
|
82
|
-
{
|
|
94
|
+
{showNoToolsExecuted && (
|
|
83
95
|
<StyledDebugDetail>
|
|
84
96
|
<StyledDebugLabel>{LABELS.NO_TOOLS_EXECUTED}</StyledDebugLabel>
|
|
85
97
|
</StyledDebugDetail>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { PreviewUtils } from '../../../../index-types'
|
|
2
|
+
import type { AiAgentDebugEvent } from './types'
|
|
3
|
+
|
|
4
|
+
const rehydratedEventsCache = new Map<string, AiAgentDebugEvent>()
|
|
5
|
+
const rehydrationInFlight = new Map<string, Promise<AiAgentDebugEvent | null>>()
|
|
6
|
+
|
|
7
|
+
export const clearRehydrationCacheForTests = () => {
|
|
8
|
+
rehydratedEventsCache.clear()
|
|
9
|
+
rehydrationInFlight.clear()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const getCachedRehydratedEvent = (
|
|
13
|
+
hubtypeMessageId: string
|
|
14
|
+
): AiAgentDebugEvent | undefined => rehydratedEventsCache.get(hubtypeMessageId)
|
|
15
|
+
|
|
16
|
+
export const rehydrateTruncatedEvent = async (
|
|
17
|
+
props: AiAgentDebugEvent,
|
|
18
|
+
previewUtils: PreviewUtils,
|
|
19
|
+
hubtypeMessageId: string
|
|
20
|
+
): Promise<AiAgentDebugEvent | null> => {
|
|
21
|
+
const message = await previewUtils.getMessageById(hubtypeMessageId, {
|
|
22
|
+
includeDebugEvents: true,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
if (!message?.event_data) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const eventData = message.event_data as Partial<AiAgentDebugEvent>
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
...props,
|
|
33
|
+
...eventData,
|
|
34
|
+
action: props.action,
|
|
35
|
+
messageId: props.messageId,
|
|
36
|
+
truncated: false,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const getOrStartRehydration = (
|
|
41
|
+
props: AiAgentDebugEvent,
|
|
42
|
+
previewUtils: PreviewUtils,
|
|
43
|
+
hubtypeMessageId: string
|
|
44
|
+
): Promise<AiAgentDebugEvent | null> => {
|
|
45
|
+
const cached = rehydratedEventsCache.get(hubtypeMessageId)
|
|
46
|
+
if (cached) {
|
|
47
|
+
return Promise.resolve(cached)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const inFlight = rehydrationInFlight.get(hubtypeMessageId)
|
|
51
|
+
if (inFlight) {
|
|
52
|
+
return inFlight
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const promise = rehydrateTruncatedEvent(props, previewUtils, hubtypeMessageId)
|
|
56
|
+
.then(mergedEvent => {
|
|
57
|
+
if (mergedEvent) {
|
|
58
|
+
rehydratedEventsCache.set(hubtypeMessageId, mergedEvent)
|
|
59
|
+
}
|
|
60
|
+
rehydrationInFlight.delete(hubtypeMessageId)
|
|
61
|
+
return mergedEvent
|
|
62
|
+
})
|
|
63
|
+
.catch(error => {
|
|
64
|
+
rehydrationInFlight.delete(hubtypeMessageId)
|
|
65
|
+
throw error
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
rehydrationInFlight.set(hubtypeMessageId, promise)
|
|
69
|
+
return promise
|
|
70
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import type { PreviewUtils } from '../../../../index-types'
|
|
4
|
+
import {
|
|
5
|
+
getCachedRehydratedEvent,
|
|
6
|
+
getOrStartRehydration,
|
|
7
|
+
} from './rehydrate-ai-agent-event'
|
|
8
|
+
import type { AiAgentDebugEvent } from './types'
|
|
9
|
+
|
|
10
|
+
interface UseRehydratedAiAgentEventResult {
|
|
11
|
+
resolvedEvent: AiAgentDebugEvent
|
|
12
|
+
isRehydrating: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const useRehydratedAiAgentEvent = (
|
|
16
|
+
props: AiAgentDebugEvent,
|
|
17
|
+
previewUtils?: PreviewUtils
|
|
18
|
+
): UseRehydratedAiAgentEventResult => {
|
|
19
|
+
const hubtypeMessageId = props.hubtype_message_id
|
|
20
|
+
const needsRehydration = Boolean(
|
|
21
|
+
props.truncated && hubtypeMessageId && previewUtils
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const cachedEvent =
|
|
25
|
+
hubtypeMessageId && needsRehydration
|
|
26
|
+
? getCachedRehydratedEvent(hubtypeMessageId)
|
|
27
|
+
: undefined
|
|
28
|
+
|
|
29
|
+
const [resolvedEvent, setResolvedEvent] = useState<AiAgentDebugEvent>(
|
|
30
|
+
() => cachedEvent ?? props
|
|
31
|
+
)
|
|
32
|
+
const [isRehydrating, setIsRehydrating] = useState(
|
|
33
|
+
() => needsRehydration && !cachedEvent
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
const fetchStartedRef = useRef(false)
|
|
37
|
+
|
|
38
|
+
if (!needsRehydration) {
|
|
39
|
+
return { resolvedEvent: props, isRehydrating: false }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
!cachedEvent &&
|
|
44
|
+
!fetchStartedRef.current &&
|
|
45
|
+
hubtypeMessageId &&
|
|
46
|
+
previewUtils
|
|
47
|
+
) {
|
|
48
|
+
fetchStartedRef.current = true
|
|
49
|
+
|
|
50
|
+
getOrStartRehydration(props, previewUtils, hubtypeMessageId)
|
|
51
|
+
.then(mergedEvent => {
|
|
52
|
+
if (mergedEvent) {
|
|
53
|
+
setResolvedEvent(mergedEvent)
|
|
54
|
+
}
|
|
55
|
+
setIsRehydrating(false)
|
|
56
|
+
})
|
|
57
|
+
.catch(error => {
|
|
58
|
+
console.error('Error rehydrating truncated AI agent event:', error)
|
|
59
|
+
setIsRehydrating(false)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
resolvedEvent: cachedEvent ?? resolvedEvent,
|
|
65
|
+
isRehydrating: cachedEvent ? false : isRehydrating,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export const LABELS = {
|
|
2
2
|
GUARDRAIL_TRIGGERED: 'Guardrail triggered',
|
|
3
|
-
KNOWLEDGE_FOUND: 'Knowledge found',
|
|
4
3
|
FAITHFUL_ANSWER: 'Faithful answer',
|
|
5
4
|
QUERY: 'Query',
|
|
6
5
|
SOURCES: 'Sources',
|
|
@@ -16,7 +15,6 @@ export const LABELS = {
|
|
|
16
15
|
QUEUE: 'Queue',
|
|
17
16
|
AUTO_ASSIGN: 'Auto-assign',
|
|
18
17
|
NOTE: 'Note',
|
|
19
|
-
KNOWLEDGE_BASE_FAIL_REASON: 'Knowledge Base Fail Reason',
|
|
20
18
|
SEE_CHUNKS_BUTTON: 'See chunks',
|
|
21
19
|
SEE_TOOL_DETAILS: 'Details',
|
|
22
20
|
STATUS: 'Status',
|
|
@@ -8,7 +8,6 @@ export * from './conditional-queue-status'
|
|
|
8
8
|
export * from './fallback'
|
|
9
9
|
export * from './handoff-success'
|
|
10
10
|
export * from './keyword'
|
|
11
|
-
export * from './knowledge-base'
|
|
12
11
|
export * from './knowledge-bases-types'
|
|
13
12
|
export * from './redirect-flow'
|
|
14
13
|
export * from './smart-intent'
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useContext, useEffect, useMemo, useState } from 'react'
|
|
1
|
+
import { useContext, useEffect, useState } from 'react'
|
|
3
2
|
|
|
4
3
|
import type { ChunkIdsGroupedBySourceData } from '../../../index-types'
|
|
5
4
|
import { WebchatContext } from '../../../webchat/context'
|
|
@@ -14,7 +13,6 @@ interface UseKnowledgeBaseInfoParams {
|
|
|
14
13
|
chunkIds: string[]
|
|
15
14
|
messageId?: string
|
|
16
15
|
existingChunksWithSources?: ChunkIdsGroupedBySourceData[]
|
|
17
|
-
failReason?: string
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
export const useKnowledgeBaseInfo = ({
|
|
@@ -22,7 +20,6 @@ export const useKnowledgeBaseInfo = ({
|
|
|
22
20
|
chunkIds,
|
|
23
21
|
messageId,
|
|
24
22
|
existingChunksWithSources,
|
|
25
|
-
failReason,
|
|
26
23
|
}: UseKnowledgeBaseInfoParams) => {
|
|
27
24
|
const { updateMessage, webchatState, previewUtils } =
|
|
28
25
|
useContext(WebchatContext)
|
|
@@ -108,27 +105,6 @@ export const useKnowledgeBaseInfo = ({
|
|
|
108
105
|
}
|
|
109
106
|
}
|
|
110
107
|
|
|
111
|
-
const { hasKnowledge, isFaithful } = useMemo(() => {
|
|
112
|
-
const typedFailReason = failReason as unknown as KnowledgebaseFailReason
|
|
113
|
-
|
|
114
|
-
if (typedFailReason === KnowledgebaseFailReason.NoKnowledge) {
|
|
115
|
-
return {
|
|
116
|
-
hasKnowledge: false,
|
|
117
|
-
isFaithful: false,
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (typedFailReason === KnowledgebaseFailReason.Hallucination) {
|
|
121
|
-
return {
|
|
122
|
-
hasKnowledge: true,
|
|
123
|
-
isFaithful: false,
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
hasKnowledge: true,
|
|
128
|
-
isFaithful: true,
|
|
129
|
-
}
|
|
130
|
-
}, [failReason])
|
|
131
|
-
|
|
132
108
|
useEffect(() => {
|
|
133
109
|
// If we already have cached data (even if empty), don't fetch again
|
|
134
110
|
if (hasCachedData) {
|
|
@@ -160,7 +136,7 @@ export const useKnowledgeBaseInfo = ({
|
|
|
160
136
|
}
|
|
161
137
|
|
|
162
138
|
fetchData()
|
|
163
|
-
}, [])
|
|
139
|
+
}, [chunkIds])
|
|
164
140
|
|
|
165
141
|
return {
|
|
166
142
|
sources,
|
|
@@ -168,7 +144,5 @@ export const useKnowledgeBaseInfo = ({
|
|
|
168
144
|
chunksWithSources,
|
|
169
145
|
isLoading,
|
|
170
146
|
getIconForSourceType,
|
|
171
|
-
hasKnowledge,
|
|
172
|
-
isFaithful,
|
|
173
147
|
}
|
|
174
148
|
}
|
|
@@ -11,7 +11,6 @@ import type {
|
|
|
11
11
|
FallbackDebugEvent,
|
|
12
12
|
HandoffSuccessDebugEvent,
|
|
13
13
|
KeywordDebugEvent,
|
|
14
|
-
KnowledgeBaseDebugEvent,
|
|
15
14
|
RedirectFlowDebugEvent,
|
|
16
15
|
SmartIntentDebugEvent,
|
|
17
16
|
WebviewActionTriggeredDebugEvent,
|
|
@@ -26,7 +25,6 @@ export type DebugEvent =
|
|
|
26
25
|
| KeywordDebugEvent
|
|
27
26
|
| AiAgentDebugEvent
|
|
28
27
|
| AiAgentRouterDebugEvent
|
|
29
|
-
| KnowledgeBaseDebugEvent
|
|
30
28
|
| FallbackDebugEvent
|
|
31
29
|
| SmartIntentDebugEvent
|
|
32
30
|
| HandoffSuccessDebugEvent
|
package/src/components/text.tsx
CHANGED
|
@@ -34,8 +34,6 @@ const serialize = (textProps: TextProps) => {
|
|
|
34
34
|
export const Text = (props: TextProps) => {
|
|
35
35
|
const defaultTextProps = {
|
|
36
36
|
markdown: props.markdown === undefined ? true : props.markdown,
|
|
37
|
-
feedbackEnabled: props.feedbackEnabled,
|
|
38
|
-
inferenceId: props.inferenceId,
|
|
39
37
|
botInteractionId: props.botInteractionId,
|
|
40
38
|
}
|
|
41
39
|
|
|
@@ -24,7 +24,6 @@ import type {
|
|
|
24
24
|
FallbackDebugEvent,
|
|
25
25
|
HandoffSuccessDebugEvent,
|
|
26
26
|
KeywordDebugEvent,
|
|
27
|
-
KnowledgeBaseDebugEvent,
|
|
28
27
|
RedirectFlowDebugEvent,
|
|
29
28
|
SmartIntentDebugEvent,
|
|
30
29
|
WebviewActionTriggeredDebugEvent,
|
|
@@ -88,30 +87,6 @@ export const DEBUG_SYSTEM_MESSAGES = {
|
|
|
88
87
|
payload: 'custom-action-result',
|
|
89
88
|
} satisfies BotActionDebugEvent,
|
|
90
89
|
|
|
91
|
-
knowledgeBase: {
|
|
92
|
-
action: EventAction.Knowledgebase,
|
|
93
|
-
flow_id: 'flow-mock-001',
|
|
94
|
-
flow_node_id: 'node-mock-004',
|
|
95
|
-
knowledgebase_inference_id: 'inf-mock-001',
|
|
96
|
-
knowledgebase_fail_reason: '',
|
|
97
|
-
knowledgebase_sources_ids: ['src-mock-001'],
|
|
98
|
-
knowledgebase_chunks_ids: ['chunk-mock-001'],
|
|
99
|
-
user_input: 'How do I reset my password?',
|
|
100
|
-
knowledge_base_chunks_with_sources: mockChunksWithSources,
|
|
101
|
-
} satisfies KnowledgeBaseDebugEvent,
|
|
102
|
-
|
|
103
|
-
knowledgeBaseFailed: {
|
|
104
|
-
action: EventAction.Knowledgebase,
|
|
105
|
-
flow_id: 'flow-mock-001',
|
|
106
|
-
flow_node_id: 'node-mock-004',
|
|
107
|
-
knowledgebase_inference_id: 'inf-mock-002',
|
|
108
|
-
knowledgebase_fail_reason: 'no_relevant_content',
|
|
109
|
-
knowledgebase_sources_ids: [],
|
|
110
|
-
knowledgebase_chunks_ids: [],
|
|
111
|
-
user_input: 'What is the meaning of life?',
|
|
112
|
-
knowledge_base_chunks_with_sources: [],
|
|
113
|
-
} satisfies KnowledgeBaseDebugEvent,
|
|
114
|
-
|
|
115
90
|
conditionalChannel: {
|
|
116
91
|
action: EventAction.ConditionalChannel,
|
|
117
92
|
channel: 'whatsapp',
|