Skip to content

Commit 995c092

Browse files
authoredMar 14, 2025··
feat(content-sidebar): added onUserInteraction prop to BoxAISidebar (#4027)
* feat(content-sidebar): added onUserInteraction prop to BoxAISidebar * feat(content-sidebar): added onUserInteraction prop to BoxAISidebar
1 parent 55eddef commit 995c092

File tree

6 files changed

+37
-39
lines changed

6 files changed

+37
-39
lines changed
 

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"@box/blueprint-web": "^9.18.11",
126126
"@box/blueprint-web-assets": "4.36.0",
127127
"@box/box-ai-agent-selector": "^0.31.0",
128-
"@box/box-ai-content-answers": "^0.109.4",
128+
"@box/box-ai-content-answers": "^0.112.1",
129129
"@box/cldr-data": "^34.2.0",
130130
"@box/combobox-with-api": "^0.28.4",
131131
"@box/frontend": "^10.0.1",
@@ -308,7 +308,7 @@
308308
"@box/blueprint-web": "^9.18.11",
309309
"@box/blueprint-web-assets": "^4.36.0",
310310
"@box/box-ai-agent-selector": "^0.31.0",
311-
"@box/box-ai-content-answers": "^0.109.4",
311+
"@box/box-ai-content-answers": "^0.112.1",
312312
"@box/cldr-data": ">=34.2.0",
313313
"@box/combobox-with-api": "^0.28.4",
314314
"@box/item-icon": "^0.9.58",

‎src/elements/content-sidebar/BoxAISidebar.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface BoxAISidebarProps {
5151
items: Array<ItemType>;
5252
itemSize?: string;
5353
localizedQuestions: Array<{ id: string; label: string; prompt: string }>;
54+
onUserInteraction?: () => void;
5455
recordAction: (params: RecordActionType) => void;
5556
setCacheValue: BoxAISidebarCacheSetter;
5657
shouldPreinitSession?: boolean;
@@ -71,6 +72,7 @@ const BoxAISidebar = (props: BoxAISidebarProps) => {
7172
items,
7273
itemSize,
7374
localizedQuestions,
75+
onUserInteraction,
7476
recordAction,
7577
setCacheValue,
7678
shouldPreinitSession = true,
@@ -89,8 +91,9 @@ const BoxAISidebar = (props: BoxAISidebarProps) => {
8991
isStopResponseEnabled,
9092
items,
9193
itemSize,
92-
setCacheValue,
94+
onUserInteraction,
9395
recordAction,
96+
setCacheValue,
9497
shouldPreinitSession,
9598
}),
9699
[
@@ -102,8 +105,9 @@ const BoxAISidebar = (props: BoxAISidebarProps) => {
102105
isStopResponseEnabled,
103106
items,
104107
itemSize,
105-
setCacheValue,
108+
onUserInteraction,
106109
recordAction,
110+
setCacheValue,
107111
shouldPreinitSession,
108112
],
109113
);

‎src/elements/content-sidebar/BoxAISidebarContent.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
ClearConversationButton,
1515
IntelligenceModal,
1616
withApiWrapper,
17-
// @ts-expect-error - TS2305 - Module '"@box/box-ai-content-answers"' has no exported member 'ApiWrapperWithInjectedProps'.
1817
type ApiWrapperWithInjectedProps,
1918
} from '@box/box-ai-content-answers';
2019
import SidebarContent from './SidebarContent';
@@ -35,7 +34,7 @@ const MARK_NAME_JS_READY: string = `${ORIGIN_BOXAI_SIDEBAR}_${EVENT_JS_READY}`;
3534

3635
mark(MARK_NAME_JS_READY);
3736

38-
function BoxAISidebarContent(props: ApiWrapperWithInjectedProps) {
37+
function BoxAISidebarContent(props: ApiWrapperWithInjectedProps & { shouldShowLandingPage: boolean }) {
3938
const {
4039
createSession,
4140
encodedSession,
@@ -65,6 +64,7 @@ function BoxAISidebarContent(props: ApiWrapperWithInjectedProps) {
6564
isStopResponseEnabled,
6665
items,
6766
itemSize,
67+
onUserInteraction,
6868
recordAction,
6969
setCacheValue,
7070
shouldPreinitSession,
@@ -88,11 +88,14 @@ function BoxAISidebarContent(props: ApiWrapperWithInjectedProps) {
8888
setCacheValue('agents', { agents, requestState, selectedAgent });
8989
}
9090

91-
const handleUserIntentToUseAI = () => {
91+
const handleUserIntentToUseAI = (userHasInteracted: boolean = false) => {
9292
// Create session if not already created or loading
9393
if (!shouldPreinitSession && !encodedSession && !isLoading && createSession) {
9494
createSession(true, false);
9595
}
96+
if (userHasInteracted && onUserInteraction) {
97+
onUserInteraction();
98+
}
9699
};
97100

98101
const handleModalClose = () => {
@@ -199,6 +202,7 @@ function BoxAISidebarContent(props: ApiWrapperWithInjectedProps) {
199202
<div className="bcs-BoxAISidebar-content">
200203
<BoxAiContentAnswers
201204
className="bcs-BoxAISidebar-contentAnswers"
205+
contentName={contentName}
202206
contentType={formatMessage(messages.sidebarBoxAIContent)}
203207
hostAppName={hostAppName}
204208
isAIStudioAgentSelectorEnabled={isAIStudioAgentSelectorEnabled}

‎src/elements/content-sidebar/__tests__/BoxAISidebar.test.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ describe('elements/content-sidebar/BoxAISidebar', () => {
113113
isResetChatEnabled: true,
114114
isStopResponseEnabled: true,
115115
isStreamingEnabled: true,
116+
onUserInteraction: jest.fn(),
116117
recordAction: jest.fn(),
117118
sendQuestion: jest.fn(),
118119
setCacheValue: jest.fn(),
@@ -423,4 +424,14 @@ describe('elements/content-sidebar/BoxAISidebar', () => {
423424
expect(mockSendQuestion).not.toHaveBeenCalled();
424425
},
425426
);
427+
428+
test('should call onUserInteraction when user takes action', async () => {
429+
await renderComponent();
430+
431+
const input = screen.getByTestId('content-answers-question-input');
432+
input.focus();
433+
await userEvent.keyboard('foo');
434+
435+
expect(mockProps.onUserInteraction).toHaveBeenCalled();
436+
});
426437
});

‎src/elements/content-sidebar/context/BoxAISidebarContext.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface BoxAISidebarContextValues {
2323
isStopResponseEnabled: boolean;
2424
items: Array<ItemType>;
2525
itemSize?: string;
26+
onUserInteraction?: () => void;
2627
recordAction: (params: BoxAISidebarRecordActionType) => void;
2728
setCacheValue: BoxAISidebarCacheSetter;
2829
shouldPreinitSession: boolean;

‎yarn.lock

+10-32
Original file line numberDiff line numberDiff line change
@@ -1498,10 +1498,10 @@
14981498
resolved "https://registry.yarnpkg.com/@box/box-ai-agent-selector/-/box-ai-agent-selector-0.31.0.tgz#a2ef6c3c7284529ae268b609d04b6000348bb294"
14991499
integrity sha512-4+M/4g8LHJfZkP+7ISBKveQs2q5HeGvXv8B6/N8yFb9cpYuOjpKFxRvHyILdQWjwictHZbgY2XrNrpxbYGEXRQ==
15001500

1501-
"@box/box-ai-content-answers@^0.109.4":
1502-
version "0.109.4"
1503-
resolved "https://registry.yarnpkg.com/@box/box-ai-content-answers/-/box-ai-content-answers-0.109.4.tgz#62aa53ddada3f60e308807035045b9e51185ca00"
1504-
integrity sha512-8p7km9MgODjIXYlDvlwsQ1+1pfqNVkdvVf5DtGhSHvwqoMccRNsbDSMk1vHg8dQ8BSD0eexKxUl2rzCUxyxS5A==
1501+
"@box/box-ai-content-answers@^0.112.1":
1502+
version "0.112.1"
1503+
resolved "https://registry.yarnpkg.com/@box/box-ai-content-answers/-/box-ai-content-answers-0.112.1.tgz#1fd2b062e811ca20fd9911edd6b901c35e97abca"
1504+
integrity sha512-gMNi9CiJAEbtpttOpDLxqUJFKM6vMvIaaIpyZm3zNdri3nWuzF22X4c7WjND0ebm8Q9F1L0+NGLKdzyvH/avxw==
15051505

15061506
"@box/cldr-data@^34.2.0":
15071507
version "34.8.0"
@@ -22393,7 +22393,8 @@ string-replace-loader@^3.1.0:
2239322393
loader-utils "^2.0.0"
2239422394
schema-utils "^3.0.0"
2239522395

22396-
"string-width-cjs@npm:string-width@^4.2.0":
22396+
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
22397+
name string-width-cjs
2239722398
version "4.2.3"
2239822399
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
2239922400
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -22411,15 +22412,6 @@ string-width@^1.0.1:
2241122412
is-fullwidth-code-point "^1.0.0"
2241222413
strip-ansi "^3.0.0"
2241322414

22414-
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
22415-
version "4.2.3"
22416-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
22417-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
22418-
dependencies:
22419-
emoji-regex "^8.0.0"
22420-
is-fullwidth-code-point "^3.0.0"
22421-
strip-ansi "^6.0.1"
22422-
2242322415
string-width@^2.0.0, string-width@^2.1.0, string-width@^2.1.1:
2242422416
version "2.1.1"
2242522417
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
@@ -22558,7 +22550,8 @@ stringify-package@^1.0.0, stringify-package@^1.0.1:
2255822550
resolved "https://registry.yarnpkg.com/stringify-package/-/stringify-package-1.0.1.tgz#e5aa3643e7f74d0f28628b72f3dad5cecfc3ba85"
2255922551
integrity sha512-sa4DUQsYciMP1xhKWGuFM04fB0LG/9DlluZoSVywUMRNvzid6XucHK0/90xGxRoHrAaROrcHK1aPKaijCtSrhg==
2256022552

22561-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
22553+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
22554+
name strip-ansi-cjs
2256222555
version "6.0.1"
2256322556
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
2256422557
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -22586,13 +22579,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
2258622579
dependencies:
2258722580
ansi-regex "^4.1.0"
2258822581

22589-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
22590-
version "6.0.1"
22591-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
22592-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
22593-
dependencies:
22594-
ansi-regex "^5.0.1"
22595-
2259622582
strip-ansi@^7.0.1, strip-ansi@^7.1.0:
2259722583
version "7.1.0"
2259822584
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -24797,7 +24783,8 @@ worker-farm@^1.6.0, worker-farm@^1.7.0:
2479724783
dependencies:
2479824784
errno "~0.1.7"
2479924785

24800-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
24786+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
24787+
name wrap-ansi-cjs
2480124788
version "7.0.0"
2480224789
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
2480324790
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -24840,15 +24827,6 @@ wrap-ansi@^6.2.0:
2484024827
string-width "^4.1.0"
2484124828
strip-ansi "^6.0.0"
2484224829

24843-
wrap-ansi@^7.0.0:
24844-
version "7.0.0"
24845-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
24846-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
24847-
dependencies:
24848-
ansi-styles "^4.0.0"
24849-
string-width "^4.1.0"
24850-
strip-ansi "^6.0.0"
24851-
2485224830
wrap-ansi@^8.1.0:
2485324831
version "8.1.0"
2485424832
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)
Please sign in to comment.