@box/box-ai-content-answers 0.67.2 → 0.69.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/esm/lib/components/api-wrapper/content-answers-component.js +49 -47
- package/esm/lib/components/api-wrapper/hooks/useContentAnswers.js +106 -104
- package/esm/lib/components/api-wrapper/utils/request.js +7 -7
- package/esm/lib/components/footer/footer.js +28 -28
- package/esm/lib/components/suggested-questions/suggested-questions.js +34 -34
- package/package.json +4 -4
- package/types/lib/components/api-wrapper/content-answers-component.d.ts +1 -1
- package/types/lib/components/api-wrapper/hooks/useContentAnswers.d.ts +1 -1
- package/types/lib/components/api-wrapper/types.d.ts +8 -2
- package/types/lib/components/api-wrapper/utils/request.d.ts +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useReducer as
|
|
1
|
+
import { useReducer as J, useEffect as K } from "react";
|
|
2
2
|
import { R as a } from "../../../../chunks/types.js";
|
|
3
|
-
import { useContentAnswers as
|
|
4
|
-
import { ContentAnswersRecord as
|
|
5
|
-
import
|
|
6
|
-
import { jsx as
|
|
7
|
-
const
|
|
3
|
+
import { useContentAnswers as M } from "./hooks/useContentAnswers.js";
|
|
4
|
+
import { ContentAnswersRecord as V, ContentAnswersItemRecord as W } from "./records.js";
|
|
5
|
+
import X from "./reducer.js";
|
|
6
|
+
import { jsx as Y } from "react/jsx-runtime";
|
|
7
|
+
const re = ({
|
|
8
8
|
WrappedComponent: d,
|
|
9
9
|
createSessionRequest: f,
|
|
10
10
|
getAgentConfig: m,
|
|
@@ -25,28 +25,29 @@ const ne = ({
|
|
|
25
25
|
isStopResponseEnabled: q,
|
|
26
26
|
isStreamingEnabled: r,
|
|
27
27
|
itemID: o,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
itemIDs: E,
|
|
29
|
+
onCloseModal: j,
|
|
30
|
+
shouldRenderProviders: U = !0,
|
|
31
|
+
suggestedQuestions: _,
|
|
32
|
+
warningNotice: v,
|
|
33
|
+
warningNoticeAriaLabel: x
|
|
33
34
|
}) => {
|
|
34
|
-
const [u,
|
|
35
|
-
item: new
|
|
35
|
+
const [u, y] = J(X, new V({
|
|
36
|
+
item: new W({
|
|
36
37
|
id: o
|
|
37
38
|
})
|
|
38
39
|
})), {
|
|
39
|
-
clearConversation:
|
|
40
|
-
createSession:
|
|
40
|
+
clearConversation: L,
|
|
41
|
+
createSession: N,
|
|
41
42
|
fetchAgentConfig: c,
|
|
42
43
|
fetchSuggestedQuestions: i,
|
|
43
|
-
retryQuestion:
|
|
44
|
-
sendQuestion:
|
|
45
|
-
stopQuestion:
|
|
46
|
-
} =
|
|
44
|
+
retryQuestion: O,
|
|
45
|
+
sendQuestion: P,
|
|
46
|
+
stopQuestion: b
|
|
47
|
+
} = M({
|
|
47
48
|
contentAnswers: u,
|
|
48
49
|
createSessionRequest: f,
|
|
49
|
-
dispatchStateUpdate:
|
|
50
|
+
dispatchStateUpdate: y,
|
|
50
51
|
fetchTimeout: g,
|
|
51
52
|
formatCitations: A,
|
|
52
53
|
getAgentConfig: m,
|
|
@@ -58,53 +59,54 @@ const ne = ({
|
|
|
58
59
|
isStreamingEnabled: r,
|
|
59
60
|
itemID: o
|
|
60
61
|
}), {
|
|
61
|
-
encodedSession:
|
|
62
|
-
error:
|
|
63
|
-
isLoading:
|
|
64
|
-
hasRequestInProgress:
|
|
65
|
-
questions:
|
|
62
|
+
encodedSession: k,
|
|
63
|
+
error: z,
|
|
64
|
+
isLoading: B,
|
|
65
|
+
hasRequestInProgress: D = !1,
|
|
66
|
+
questions: F,
|
|
66
67
|
suggestedQuestions: t
|
|
67
68
|
} = u;
|
|
68
|
-
|
|
69
|
+
K(() => {
|
|
69
70
|
s && t.requestState === a.NOT_STARTED && i();
|
|
70
71
|
}, [s, i, t.requestState]);
|
|
71
|
-
const
|
|
72
|
-
createSession:
|
|
73
|
-
encodedSession:
|
|
74
|
-
error:
|
|
72
|
+
const G = {
|
|
73
|
+
createSession: N,
|
|
74
|
+
encodedSession: k,
|
|
75
|
+
error: z,
|
|
75
76
|
getAIStudioAgents: S,
|
|
76
77
|
hostAppName: R,
|
|
77
78
|
hasCustomSuggestedQuestions: !!e,
|
|
78
|
-
hasRequestInProgress:
|
|
79
|
+
hasRequestInProgress: D,
|
|
79
80
|
isAgentSelectorEnabled: w,
|
|
80
81
|
isAIStudioAgentSelectorEnabled: Q,
|
|
81
82
|
isCitationsEnabled: n,
|
|
82
83
|
isDebugModeEnabled: T,
|
|
83
84
|
isMarkdownEnabled: h,
|
|
84
|
-
isLoading:
|
|
85
|
+
isLoading: B,
|
|
85
86
|
isOpen: s,
|
|
86
87
|
isResetChatEnabled: l,
|
|
87
88
|
isStreamingEnabled: r,
|
|
88
89
|
itemID: o,
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
itemIDs: E,
|
|
91
|
+
onClearAction: L,
|
|
92
|
+
onCloseModal: j,
|
|
91
93
|
onSelectAgent: c,
|
|
92
94
|
onAgentEditorToggle: c,
|
|
93
|
-
questions:
|
|
94
|
-
retryQuestion:
|
|
95
|
-
sendQuestion:
|
|
96
|
-
shouldRenderProviders:
|
|
97
|
-
stopQuestion:
|
|
95
|
+
questions: F,
|
|
96
|
+
retryQuestion: O,
|
|
97
|
+
sendQuestion: P,
|
|
98
|
+
shouldRenderProviders: U,
|
|
99
|
+
stopQuestion: b,
|
|
98
100
|
suggestedQuestionsRequestState: e ? t.requestState : a.SUCCESS,
|
|
99
|
-
suggestedQuestions: e ? t.suggestions :
|
|
100
|
-
warningNotice:
|
|
101
|
-
warningNoticeAriaLabel:
|
|
102
|
-
},
|
|
103
|
-
return /* @__PURE__ */
|
|
104
|
-
...
|
|
101
|
+
suggestedQuestions: e ? t.suggestions : _,
|
|
102
|
+
warningNotice: v,
|
|
103
|
+
warningNoticeAriaLabel: x
|
|
104
|
+
}, H = Object.fromEntries(Object.entries(G).filter(([Z, I]) => I !== void 0));
|
|
105
|
+
return /* @__PURE__ */ Y(d, {
|
|
106
|
+
...H
|
|
105
107
|
});
|
|
106
108
|
};
|
|
107
109
|
export {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
re as ContentAnswersComponent,
|
|
111
|
+
re as default
|
|
110
112
|
};
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import B from "lodash/camelCase";
|
|
2
|
-
import
|
|
3
|
-
import { useAgentsDispatch as
|
|
4
|
-
import { A as T, C as
|
|
5
|
-
import { SET_NEW_ITEM as
|
|
6
|
-
import { QuestionRecord as
|
|
7
|
-
import { defaultFormatSuggestions as
|
|
8
|
-
import { getAnswerRequest as
|
|
9
|
-
import
|
|
10
|
-
const Es = /Too Many Requests/i,
|
|
11
|
-
function
|
|
2
|
+
import t, { useCallback as Z } from "react";
|
|
3
|
+
import { useAgentsDispatch as w } from "../../../contexts/AgentsContext.js";
|
|
4
|
+
import { A as T, C as U, R as j } from "../../../../../chunks/types.js";
|
|
5
|
+
import { SET_NEW_ITEM as ss, UPDATE_QUESTION as es, SET_MODAL_ERROR as os, SET_MODAL_SUCCESS as ts, SET_IS_LOADING as ns, CLEAR_CONVERSATION_HISTORY as as, SET_SUGGESTED_QUESTIONS_REQUEST_STATE as x, SET_SUGGESTED_QUESTIONS as is } from "../actions.js";
|
|
6
|
+
import { QuestionRecord as us } from "../records.js";
|
|
7
|
+
import { defaultFormatSuggestions as ls, defaultFormatCitations as cs } from "../utils/format.js";
|
|
8
|
+
import { getAnswerRequest as rs } from "../utils/request.js";
|
|
9
|
+
import G from "../utils/stream.js";
|
|
10
|
+
const Es = /Too Many Requests/i, $ = "Agent not found";
|
|
11
|
+
function ms({
|
|
12
12
|
contentAnswers: i,
|
|
13
|
-
createSessionRequest:
|
|
14
|
-
dispatchStateUpdate:
|
|
15
|
-
fetchTimeout:
|
|
16
|
-
getAgentConfig:
|
|
13
|
+
createSessionRequest: g,
|
|
14
|
+
dispatchStateUpdate: o,
|
|
15
|
+
fetchTimeout: S,
|
|
16
|
+
getAgentConfig: y,
|
|
17
17
|
getAnswerStreaming: k,
|
|
18
|
-
getAnswer:
|
|
19
|
-
getSuggestedQuestions:
|
|
20
|
-
isCitationsEnabled:
|
|
21
|
-
isStopResponseEnabled:
|
|
22
|
-
isStreamingEnabled:
|
|
18
|
+
getAnswer: p,
|
|
19
|
+
getSuggestedQuestions: m,
|
|
20
|
+
isCitationsEnabled: fs,
|
|
21
|
+
isStopResponseEnabled: M,
|
|
22
|
+
isStreamingEnabled: N,
|
|
23
23
|
itemID: l,
|
|
24
|
-
|
|
24
|
+
itemIDs: O,
|
|
25
|
+
formatCitations: F = cs
|
|
25
26
|
}) {
|
|
26
|
-
const
|
|
27
|
-
|
|
27
|
+
const V = t.useRef(null), I = w(), P = Z((s) => Array.isArray(s) ? F(s) : null, [F]);
|
|
28
|
+
t.useEffect(
|
|
28
29
|
(s) => {
|
|
29
|
-
l && l !== i.item.id &&
|
|
30
|
-
type:
|
|
30
|
+
l && l !== i.item.id && o({
|
|
31
|
+
type: ss,
|
|
31
32
|
itemID: l,
|
|
32
33
|
fileVersionID: s
|
|
33
34
|
});
|
|
@@ -35,29 +36,29 @@ function ds({
|
|
|
35
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
37
|
[l]
|
|
37
38
|
);
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
type:
|
|
39
|
+
const r = t.useCallback((s, e) => {
|
|
40
|
+
o({
|
|
41
|
+
type: es,
|
|
41
42
|
newQuestion: s,
|
|
42
43
|
session: e
|
|
43
|
-
}),
|
|
44
|
-
}, [
|
|
45
|
-
|
|
46
|
-
type:
|
|
44
|
+
}), V.current = s;
|
|
45
|
+
}, [o]), v = t.useCallback((s) => {
|
|
46
|
+
o({
|
|
47
|
+
type: os,
|
|
47
48
|
error: s
|
|
48
49
|
});
|
|
49
|
-
}, [
|
|
50
|
+
}, [o]), A = t.useCallback((s, e, n) => {
|
|
50
51
|
const {
|
|
51
52
|
answer: u,
|
|
52
53
|
error: c,
|
|
53
54
|
citations: a = [],
|
|
54
|
-
createdAt:
|
|
55
|
+
createdAt: E = null,
|
|
55
56
|
encodedSession: f = void 0,
|
|
56
57
|
contextSession: _ = void 0
|
|
57
|
-
} = s, R = e.set("citations",
|
|
58
|
+
} = s, R = e.set("citations", P(a)).merge({
|
|
58
59
|
answer: u,
|
|
59
60
|
error: c,
|
|
60
|
-
created_at:
|
|
61
|
+
created_at: E,
|
|
61
62
|
isLoading: !1,
|
|
62
63
|
isCompleted: n
|
|
63
64
|
});
|
|
@@ -66,71 +67,71 @@ function ds({
|
|
|
66
67
|
encodedSession: f
|
|
67
68
|
}), _ && (C = {
|
|
68
69
|
contextSession: _
|
|
69
|
-
}),
|
|
70
|
-
}, [
|
|
70
|
+
}), r(R, C);
|
|
71
|
+
}, [r, P]), b = t.useCallback(
|
|
71
72
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
73
|
(s, e) => {
|
|
73
|
-
var R, C,
|
|
74
|
-
const n = (s == null ? void 0 : s.message) || "", u = ((R = s == null ? void 0 : s.response) == null ? void 0 : R.status) === 429 || Es.test(n), c = (s == null ? void 0 : s.code) ===
|
|
74
|
+
var R, C, d;
|
|
75
|
+
const n = (s == null ? void 0 : s.message) || "", u = ((R = s == null ? void 0 : s.response) == null ? void 0 : R.status) === 429 || Es.test(n), c = (s == null ? void 0 : s.code) === $ || (s == null ? void 0 : s.errorCode) === $, a = ((C = s == null ? void 0 : s.response) == null ? void 0 : C.status) === 204, E = ((d = s == null ? void 0 : s.response) == null ? void 0 : d.status) === 412, f = a ? T.NO_CONTENT : u ? T.RATE_LIMITING : E ? T.PRECONDITION_FAILED : c ? T.AGENT_NOT_FOUND : T.GENERAL, _ = e.merge({
|
|
75
76
|
error: f,
|
|
76
77
|
isLoading: !1,
|
|
77
78
|
isCompleted: !0
|
|
78
79
|
});
|
|
79
|
-
|
|
80
|
+
r(_, void 0);
|
|
80
81
|
},
|
|
81
|
-
[
|
|
82
|
-
),
|
|
82
|
+
[r]
|
|
83
|
+
), L = t.useCallback(async (s, e) => {
|
|
83
84
|
try {
|
|
84
85
|
const n = {
|
|
85
86
|
prompt: s.prompt,
|
|
86
87
|
aiAgent: e || void 0
|
|
87
88
|
}, u = `content-answers-${s.id}`;
|
|
88
89
|
let c;
|
|
89
|
-
|
|
90
|
-
const a = await
|
|
91
|
-
|
|
90
|
+
N && (c = G.createAbortRequest(u));
|
|
91
|
+
const a = await rs(n, N, u, l, O, i, p, k, c, S);
|
|
92
|
+
N ? G.receiveStreamedResponse(u, a, (E) => {
|
|
92
93
|
const {
|
|
93
94
|
code: f,
|
|
94
95
|
data: _,
|
|
95
96
|
error: R,
|
|
96
97
|
citations: C,
|
|
97
|
-
contextSession:
|
|
98
|
-
isCompleted:
|
|
99
|
-
createdAt:
|
|
100
|
-
} =
|
|
98
|
+
contextSession: d,
|
|
99
|
+
isCompleted: Y,
|
|
100
|
+
createdAt: h
|
|
101
|
+
} = E, z = {
|
|
101
102
|
answer: _,
|
|
102
103
|
citations: C,
|
|
103
104
|
error: R,
|
|
104
|
-
contextSession:
|
|
105
|
-
createdAt:
|
|
105
|
+
contextSession: d,
|
|
106
|
+
createdAt: h
|
|
106
107
|
};
|
|
107
|
-
a.ok && a.status === 200 ?
|
|
108
|
+
a.ok && a.status === 200 ? A({
|
|
108
109
|
...z
|
|
109
|
-
}, s,
|
|
110
|
+
}, s, Y) : b({
|
|
110
111
|
response: a,
|
|
111
112
|
code: f
|
|
112
113
|
}, s);
|
|
113
|
-
}, void 0,
|
|
114
|
-
const _ = B(
|
|
115
|
-
delete a[
|
|
116
|
-
}),
|
|
114
|
+
}, void 0, S) : (Object.entries(a).forEach(([E, f]) => {
|
|
115
|
+
const _ = B(E);
|
|
116
|
+
delete a[E], a[_] = f;
|
|
117
|
+
}), A(a, s, !0));
|
|
117
118
|
} catch (n) {
|
|
118
|
-
if (
|
|
119
|
+
if (M && n instanceof Error && n.name === "AbortError") {
|
|
119
120
|
const u = s.set("error", []).merge({
|
|
120
121
|
error: T.RESPONSE_STOPPED,
|
|
121
122
|
isLoading: !1,
|
|
122
123
|
isCompleted: !0
|
|
123
124
|
});
|
|
124
|
-
|
|
125
|
+
r(u);
|
|
125
126
|
} else
|
|
126
127
|
b(n, s);
|
|
127
128
|
}
|
|
128
|
-
}, [
|
|
129
|
+
}, [N, l, O, i, p, k, S, A, b, M, r]), Q = t.useCallback((s, e, n = !0) => {
|
|
129
130
|
const u = (i == null ? void 0 : i.questions) || [];
|
|
130
131
|
n && (s.id = `${u.length}`);
|
|
131
|
-
const c = new
|
|
132
|
-
return
|
|
133
|
-
}, [i == null ? void 0 : i.questions,
|
|
132
|
+
const c = new us(s);
|
|
133
|
+
return r(c), L(c, e), c;
|
|
134
|
+
}, [i == null ? void 0 : i.questions, L, r]), q = t.useCallback((s) => {
|
|
134
135
|
const {
|
|
135
136
|
encoded_session: e,
|
|
136
137
|
metadata: {
|
|
@@ -139,81 +140,82 @@ function ds({
|
|
|
139
140
|
is_large_file: !1
|
|
140
141
|
}
|
|
141
142
|
} = s;
|
|
142
|
-
|
|
143
|
+
o({
|
|
143
144
|
type: ts,
|
|
144
145
|
encodedSession: e,
|
|
145
146
|
isLargeFile: n
|
|
146
147
|
});
|
|
147
|
-
}, [
|
|
148
|
+
}, [o]), W = t.useCallback(async () => {
|
|
148
149
|
try {
|
|
149
|
-
|
|
150
|
-
type:
|
|
150
|
+
o({
|
|
151
|
+
type: ns,
|
|
151
152
|
isLoading: !0
|
|
152
153
|
});
|
|
153
|
-
const s = await
|
|
154
|
+
const s = await g({
|
|
154
155
|
items: [i.item]
|
|
155
156
|
}, l);
|
|
156
|
-
|
|
157
|
+
q(s);
|
|
157
158
|
} catch {
|
|
158
|
-
|
|
159
|
+
v(U.GENERAL);
|
|
159
160
|
}
|
|
160
|
-
}, [
|
|
161
|
-
|
|
162
|
-
type:
|
|
161
|
+
}, [o, g, i.item, l, q, v]), D = t.useCallback(() => {
|
|
162
|
+
o({
|
|
163
|
+
type: as
|
|
163
164
|
});
|
|
164
|
-
}, [
|
|
165
|
-
|
|
165
|
+
}, [o]), H = t.useCallback(async (s, e) => {
|
|
166
|
+
Q({
|
|
166
167
|
...s.toJS(),
|
|
167
168
|
answer: "",
|
|
168
169
|
isLoading: !0,
|
|
169
170
|
isCompleted: !1,
|
|
170
171
|
error: null
|
|
171
172
|
}, e, !1);
|
|
172
|
-
}, [
|
|
173
|
-
|
|
174
|
-
}, []),
|
|
175
|
-
if (
|
|
173
|
+
}, [Q]), J = t.useCallback((s) => {
|
|
174
|
+
G.abortRequest(`content-answers-${s.id}`, !0);
|
|
175
|
+
}, []), K = t.useCallback(async (s) => {
|
|
176
|
+
if (y)
|
|
176
177
|
try {
|
|
177
|
-
const e = await
|
|
178
|
-
|
|
178
|
+
const e = await y(s);
|
|
179
|
+
I({
|
|
179
180
|
type: "OVERRIDE_AGENT_CONFIG",
|
|
180
181
|
agentName: s.name,
|
|
181
182
|
agentConfig: e
|
|
182
183
|
});
|
|
183
184
|
} catch {
|
|
184
185
|
}
|
|
185
|
-
}, [
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
186
|
+
}, [I, y]), X = t.useCallback(async () => {
|
|
187
|
+
const s = Array.isArray(O) && O.length > 1;
|
|
188
|
+
if (!(!m || s)) {
|
|
189
|
+
o({
|
|
190
|
+
type: x,
|
|
191
|
+
requestState: j.IN_PROGRESS
|
|
190
192
|
});
|
|
191
193
|
try {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
type:
|
|
195
|
-
suggestedQuestions:
|
|
194
|
+
const e = ls(await m(l));
|
|
195
|
+
o({
|
|
196
|
+
type: is,
|
|
197
|
+
suggestedQuestions: e
|
|
196
198
|
});
|
|
197
199
|
} catch {
|
|
198
|
-
|
|
199
|
-
type:
|
|
200
|
-
requestState:
|
|
200
|
+
o({
|
|
201
|
+
type: x,
|
|
202
|
+
requestState: j.ERROR
|
|
201
203
|
});
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
|
-
}, [
|
|
206
|
+
}, [o, m, l, O]);
|
|
205
207
|
return {
|
|
206
|
-
clearConversation:
|
|
207
|
-
createSession:
|
|
208
|
-
fetchAgentConfig:
|
|
209
|
-
fetchSuggestedQuestions:
|
|
210
|
-
retryQuestion:
|
|
211
|
-
sendQuestion:
|
|
212
|
-
sendQuestionAnswerRequest:
|
|
213
|
-
stopQuestion:
|
|
214
|
-
updateQuestionInState:
|
|
208
|
+
clearConversation: D,
|
|
209
|
+
createSession: W,
|
|
210
|
+
fetchAgentConfig: K,
|
|
211
|
+
fetchSuggestedQuestions: X,
|
|
212
|
+
retryQuestion: H,
|
|
213
|
+
sendQuestion: Q,
|
|
214
|
+
sendQuestionAnswerRequest: L,
|
|
215
|
+
stopQuestion: J,
|
|
216
|
+
updateQuestionInState: r
|
|
215
217
|
};
|
|
216
218
|
}
|
|
217
219
|
export {
|
|
218
|
-
|
|
220
|
+
ms as useContentAnswers
|
|
219
221
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
}, s),
|
|
1
|
+
import p, { FETCH_TIMEOUT as q } from "./stream.js";
|
|
2
|
+
const E = (i, s) => setTimeout(() => {
|
|
3
|
+
p.abortRequest(i);
|
|
4
|
+
}, s), m = async (i, s = !1, u, a, o, r, e, l, T, t) => {
|
|
5
5
|
let n;
|
|
6
|
-
const
|
|
7
|
-
return s &&
|
|
6
|
+
const w = (t == null ? void 0 : t.initial) || q.initial, b = E(u, w);
|
|
7
|
+
return s && l ? n = await l(i, a, o, T, r) : e && (n = await e(i, a, o, r)), clearTimeout(b), n;
|
|
8
8
|
};
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
m as getAnswerRequest
|
|
11
11
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "../../../../styles/footer.css";
|
|
2
2
|
import * as e from "react";
|
|
3
3
|
import { useIntl as D } from "react-intl";
|
|
4
|
-
import { useBreakpoint as S, Breakpoint as Y, Avatar as
|
|
5
|
-
import { ArrowUp as
|
|
6
|
-
import { useAgents as
|
|
7
|
-
import { useAgents as
|
|
4
|
+
import { useBreakpoint as S, Breakpoint as Y, Avatar as q, TextArea as J, Button as Q } from "@box/blueprint-web";
|
|
5
|
+
import { ArrowUp as V } from "@box/blueprint-web-assets/icons/Line";
|
|
6
|
+
import { useAgents as Z } from "@box/box-ai-agent-selector";
|
|
7
|
+
import { useAgents as g } from "../../contexts/AgentsContext.js";
|
|
8
8
|
import { FooterActions as P } from "./footer-actions.js";
|
|
9
9
|
import tt from "../../messages.js";
|
|
10
10
|
import { getAIAgentConfig as X } from "../common/agentUtils.js";
|
|
@@ -19,48 +19,48 @@ const st = "_questionInput_1pdo1_1", it = "_avatar_1pdo1_11", nt = "_submitButto
|
|
|
19
19
|
submitButton: nt,
|
|
20
20
|
textArea: mt,
|
|
21
21
|
submitButtonTooltip: ut
|
|
22
|
-
},
|
|
22
|
+
}, Tt = ({
|
|
23
23
|
askSuggestedQuestion: h,
|
|
24
|
-
contentType:
|
|
24
|
+
contentType: x,
|
|
25
25
|
enableDebugMode: b = !1,
|
|
26
26
|
hasRequestInProgress: r,
|
|
27
27
|
isAgentSelectorEnabled: f,
|
|
28
28
|
isAIStudioAgentSelectorEnabled: _,
|
|
29
|
-
isDebugModeShown:
|
|
29
|
+
isDebugModeShown: L,
|
|
30
30
|
isSidebarOpen: H = !1,
|
|
31
31
|
isStopResponseEnabled: y,
|
|
32
32
|
isStreamingEnabled: F,
|
|
33
|
-
lastQuestion:
|
|
34
|
-
onRetryQuestion:
|
|
33
|
+
lastQuestion: M,
|
|
34
|
+
onRetryQuestion: T,
|
|
35
35
|
onStopQuestion: I,
|
|
36
36
|
recordAction: o,
|
|
37
|
-
sendQuestion:
|
|
37
|
+
sendQuestion: E,
|
|
38
38
|
setAskSuggestedQuestion: B,
|
|
39
39
|
toggleDebugMode: n,
|
|
40
40
|
user: G
|
|
41
41
|
}) => {
|
|
42
42
|
const s = D(), K = S(), a = /* @__PURE__ */ e.createRef(), v = K <= Y.Medium || H, [c, N] = e.useState(!0), [j, O] = e.useState(!1), {
|
|
43
43
|
selectedAgent: d
|
|
44
|
-
} =
|
|
44
|
+
} = g(), {
|
|
45
45
|
selectedAgent: C
|
|
46
|
-
} =
|
|
46
|
+
} = Z(), k = e.useCallback(() => {
|
|
47
47
|
a.current && a.current.focus();
|
|
48
48
|
}, [a]), U = e.useCallback(() => {
|
|
49
49
|
var m;
|
|
50
50
|
let t = ((m = a.current) == null ? void 0 : m.value) ?? "";
|
|
51
51
|
a.current && t.length > i.MAX_LENGTH && (a.current.value = t.slice(0, i.MAX_LENGTH), t = a.current.value), O(t.length >= i.MAX_LENGTH), N(t.trim().length === 0);
|
|
52
52
|
}, [a]), l = e.useCallback(() => {
|
|
53
|
-
if (
|
|
53
|
+
if (k(), !r && a.current) {
|
|
54
54
|
const t = {
|
|
55
55
|
prompt: a.current.value
|
|
56
56
|
};
|
|
57
57
|
if (t.prompt && t.prompt.trim()) {
|
|
58
58
|
const m = X(f, d, _, C);
|
|
59
|
-
|
|
59
|
+
E(t, m), a.current.value = "", N(!0), O(!1);
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
L && n && n();
|
|
62
62
|
}
|
|
63
|
-
}, [C,
|
|
63
|
+
}, [C, k, r, a, _, f, L, d, E, n]), W = e.useCallback((t) => {
|
|
64
64
|
t.preventDefault(), !r && !c && o && o({
|
|
65
65
|
...R,
|
|
66
66
|
action: rt,
|
|
@@ -74,17 +74,17 @@ const st = "_questionInput_1pdo1_1", it = "_avatar_1pdo1_11", nt = "_submitButto
|
|
|
74
74
|
}), l());
|
|
75
75
|
}, [b, r, c, o, l, n]), z = e.useCallback((t) => {
|
|
76
76
|
const m = X(f, d, _, C);
|
|
77
|
-
|
|
78
|
-
}, [C, _, f,
|
|
77
|
+
T(t, m);
|
|
78
|
+
}, [C, _, f, T, d]);
|
|
79
79
|
return e.useEffect(() => {
|
|
80
|
-
|
|
80
|
+
queueMicrotask(k);
|
|
81
81
|
}, []), e.useEffect(() => {
|
|
82
82
|
h && a.current && !r && B && (a.current.value = h, l(), B(null));
|
|
83
83
|
}, [h]), /* @__PURE__ */ w("div", {
|
|
84
|
-
children: [
|
|
84
|
+
children: [M && /* @__PURE__ */ p(P, {
|
|
85
85
|
isStopResponseEnabled: y,
|
|
86
86
|
isStreamingEnabled: F,
|
|
87
|
-
lastQuestion:
|
|
87
|
+
lastQuestion: M,
|
|
88
88
|
onRetryQuestion: z,
|
|
89
89
|
onStopQuestion: I,
|
|
90
90
|
recordAction: o
|
|
@@ -93,13 +93,13 @@ const st = "_questionInput_1pdo1_1", it = "_avatar_1pdo1_11", nt = "_submitButto
|
|
|
93
93
|
children: [!v && /* @__PURE__ */ p("div", {
|
|
94
94
|
className: A.avatar,
|
|
95
95
|
"data-testid": "content-answers-question-input-avatar",
|
|
96
|
-
children: /* @__PURE__ */ p(
|
|
96
|
+
children: /* @__PURE__ */ p(q, {
|
|
97
97
|
alt: s.formatMessage(tt.userAvatar),
|
|
98
98
|
colorIndex: 0,
|
|
99
99
|
src: G.avatarURL,
|
|
100
100
|
text: G.name.charAt(0)
|
|
101
101
|
})
|
|
102
|
-
}), /* @__PURE__ */ p(
|
|
102
|
+
}), /* @__PURE__ */ p(J, {
|
|
103
103
|
ref: a,
|
|
104
104
|
className: A.textArea,
|
|
105
105
|
"data-testid": "content-answers-question-input",
|
|
@@ -108,21 +108,21 @@ const st = "_questionInput_1pdo1_1", it = "_avatar_1pdo1_11", nt = "_submitButto
|
|
|
108
108
|
}),
|
|
109
109
|
hideLabel: !0,
|
|
110
110
|
label: s.formatMessage(u.askQuestionPlaceholder, {
|
|
111
|
-
type:
|
|
111
|
+
type: x
|
|
112
112
|
}),
|
|
113
113
|
maxLength: i.MAX_LENGTH,
|
|
114
114
|
maxRows: v ? i.MAX_ROWS_MOBILE : i.MAX_ROWS,
|
|
115
115
|
onChange: U,
|
|
116
116
|
onKeyDown: $,
|
|
117
117
|
placeholder: s.formatMessage(u.askQuestionPlaceholder, {
|
|
118
|
-
type:
|
|
118
|
+
type: x
|
|
119
119
|
})
|
|
120
|
-
}), /* @__PURE__ */ p(
|
|
120
|
+
}), /* @__PURE__ */ p(Q, {
|
|
121
121
|
"aria-label": s.formatMessage(u.ask),
|
|
122
122
|
className: A.submitButton,
|
|
123
123
|
"data-testid": "content-answers-submit-button",
|
|
124
124
|
disabled: c || r,
|
|
125
|
-
icon: v ?
|
|
125
|
+
icon: v ? V : void 0,
|
|
126
126
|
loading: r,
|
|
127
127
|
loadingAriaLabel: s.formatMessage(u.askDisabledTooltip),
|
|
128
128
|
onClick: W,
|
|
@@ -133,5 +133,5 @@ const st = "_questionInput_1pdo1_1", it = "_avatar_1pdo1_11", nt = "_submitButto
|
|
|
133
133
|
});
|
|
134
134
|
};
|
|
135
135
|
export {
|
|
136
|
-
|
|
136
|
+
Tt as Footer
|
|
137
137
|
};
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import "../../../../styles/suggested-questions.css";
|
|
2
|
-
import { Text as
|
|
3
|
-
import { AlertTriangle as
|
|
4
|
-
import { Gray65 as
|
|
5
|
-
import
|
|
6
|
-
import * as
|
|
7
|
-
import { useIntl as
|
|
2
|
+
import { Text as E, LoadingIndicator as O } from "@box/blueprint-web";
|
|
3
|
+
import { AlertTriangle as R } from "@box/blueprint-web-assets/icons/Line";
|
|
4
|
+
import { Gray65 as b, Size4 as m } from "@box/blueprint-web-assets/tokens/tokens";
|
|
5
|
+
import g from "clsx";
|
|
6
|
+
import * as h from "react";
|
|
7
|
+
import { useIntl as u } from "react-intl";
|
|
8
8
|
import { Suggestions as v } from "./suggestions.js";
|
|
9
9
|
import { R as r } from "../../../../chunks/types.js";
|
|
10
|
-
import { LOGGER_BASE_CONFIG as
|
|
10
|
+
import { LOGGER_BASE_CONFIG as N } from "../common/constants.js";
|
|
11
11
|
import i from "./messages.js";
|
|
12
|
-
import { jsxs as
|
|
13
|
-
const
|
|
14
|
-
wrapper:
|
|
15
|
-
isSidebarOpen:
|
|
12
|
+
import { jsxs as w, jsx as n } from "react/jsx-runtime";
|
|
13
|
+
const x = "_wrapper_10vng_1", C = "_isSidebarOpen_10vng_5", G = "_label_10vng_9", T = "_loadingIndicator_10vng_20", y = "_alertIcon_10vng_28", a = {
|
|
14
|
+
wrapper: x,
|
|
15
|
+
isSidebarOpen: C,
|
|
16
16
|
label: G,
|
|
17
17
|
loadingIndicator: T,
|
|
18
18
|
alertIcon: y
|
|
19
19
|
}, H = ({
|
|
20
|
-
askSuggestedQuestion:
|
|
21
|
-
hasCustomSuggestedQuestions:
|
|
20
|
+
askSuggestedQuestion: p,
|
|
21
|
+
hasCustomSuggestedQuestions: d,
|
|
22
22
|
isLoading: _,
|
|
23
23
|
isSidebarOpen: t = !1,
|
|
24
24
|
recordAction: s,
|
|
25
25
|
setAskSuggestedQuestion: l,
|
|
26
|
-
suggestedQuestions:
|
|
27
|
-
suggestedQuestionsRequestState:
|
|
26
|
+
suggestedQuestions: f,
|
|
27
|
+
suggestedQuestionsRequestState: o = r.SUCCESS
|
|
28
28
|
}) => {
|
|
29
29
|
const {
|
|
30
30
|
formatMessage: e
|
|
31
|
-
} =
|
|
31
|
+
} = u(), S = h.useCallback((c) => {
|
|
32
32
|
l && (l(c), s && c && s({
|
|
33
|
-
...
|
|
33
|
+
...N,
|
|
34
34
|
target: "suggested_questions",
|
|
35
35
|
data: {
|
|
36
|
-
selectedQuestion:
|
|
36
|
+
selectedQuestion: d ? "dynamic" : c
|
|
37
37
|
}
|
|
38
38
|
}));
|
|
39
|
-
}, [l, s]), I = () => {
|
|
40
|
-
switch (
|
|
39
|
+
}, [l, s, d]), I = () => {
|
|
40
|
+
switch (o) {
|
|
41
41
|
case r.IN_PROGRESS:
|
|
42
42
|
return e(i.loadingSuggestedQuestions);
|
|
43
43
|
case r.ERROR:
|
|
@@ -46,33 +46,33 @@ const w = "_wrapper_10vng_1", x = "_isSidebarOpen_10vng_5", G = "_label_10vng_9"
|
|
|
46
46
|
return e(i.suggestedQuestions);
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
return /* @__PURE__ */
|
|
50
|
-
className:
|
|
51
|
-
children: [/* @__PURE__ */
|
|
49
|
+
return /* @__PURE__ */ w("div", {
|
|
50
|
+
className: g(a.wrapper, t && a.isSidebarOpen),
|
|
51
|
+
children: [/* @__PURE__ */ n(E, {
|
|
52
52
|
as: "p",
|
|
53
|
-
className:
|
|
53
|
+
className: g(a.label, t && a.isSidebarOpen),
|
|
54
54
|
color: "textOnLightSecondary",
|
|
55
55
|
children: I()
|
|
56
|
-
}),
|
|
57
|
-
askSuggestedQuestion:
|
|
56
|
+
}), o === r.SUCCESS && /* @__PURE__ */ n(v, {
|
|
57
|
+
askSuggestedQuestion: p,
|
|
58
58
|
isLoading: _,
|
|
59
59
|
isSidebarOpen: t,
|
|
60
|
-
onSuggestedQuestionClick:
|
|
61
|
-
suggestedQuestions:
|
|
62
|
-
}),
|
|
60
|
+
onSuggestedQuestionClick: S,
|
|
61
|
+
suggestedQuestions: f
|
|
62
|
+
}), o === r.IN_PROGRESS && /* @__PURE__ */ n("div", {
|
|
63
63
|
className: a.loadingIndicator,
|
|
64
|
-
children: /* @__PURE__ */
|
|
64
|
+
children: /* @__PURE__ */ n(O, {
|
|
65
65
|
"aria-label": e(i.loadingSuggestedQuestions),
|
|
66
66
|
className: a.loadingIndicator,
|
|
67
67
|
variant: "dark"
|
|
68
68
|
})
|
|
69
|
-
}),
|
|
69
|
+
}), o === r.ERROR && /* @__PURE__ */ n(R, {
|
|
70
70
|
className: a.alertIcon,
|
|
71
|
-
color:
|
|
71
|
+
color: b,
|
|
72
72
|
"data-testid": "content-answers-suggested-questions-failed-alert-icon",
|
|
73
|
-
height:
|
|
73
|
+
height: m,
|
|
74
74
|
role: "presentation",
|
|
75
|
-
width:
|
|
75
|
+
width: m
|
|
76
76
|
})]
|
|
77
77
|
});
|
|
78
78
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/box-ai-content-answers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.69.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@box/blueprint-web": "^7.8.0",
|
|
6
6
|
"@box/blueprint-web-assets": "^4.16.0",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"remarkable": "^2.0.1"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@box/blueprint-web": "^
|
|
17
|
+
"@box/blueprint-web": "^9.0.0",
|
|
18
18
|
"@box/blueprint-web-assets": "^4.30.0",
|
|
19
|
-
"@box/box-ai-agent-selector": "^0.
|
|
19
|
+
"@box/box-ai-agent-selector": "^0.17.0",
|
|
20
20
|
"@box/storybook-utils": "^0.7.0",
|
|
21
21
|
"@testing-library/react": "^15.0.6",
|
|
22
22
|
"react": "^18.3.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"**/*.css"
|
|
55
55
|
],
|
|
56
56
|
"license": "SEE LICENSE IN LICENSE",
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "b4a64fc7d3792a0bcf1ab8f2e75b7f4a989a6d7a"
|
|
58
58
|
}
|
|
@@ -2,5 +2,5 @@ import { type ApiWrapperProps } from './types';
|
|
|
2
2
|
export type ContentAnswersComponentProps = ApiWrapperProps & {
|
|
3
3
|
WrappedComponent: React.ComponentType<ApiWrapperProps>;
|
|
4
4
|
};
|
|
5
|
-
export declare const ContentAnswersComponent: ({ WrappedComponent, createSessionRequest, getAgentConfig, getAIStudioAgents, fetchTimeout, formatCitations, getAnswer, getAnswerStreaming, getSuggestedQuestions, hostAppName, isAgentSelectorEnabled, isAIStudioAgentSelectorEnabled, isCitationsEnabled, isDebugModeEnabled, isMarkdownEnabled, isOpen, isResetChatEnabled, isStopResponseEnabled, isStreamingEnabled, itemID, onCloseModal, shouldRenderProviders, suggestedQuestions, warningNotice, warningNoticeAriaLabel, }: ContentAnswersComponentProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare const ContentAnswersComponent: ({ WrappedComponent, createSessionRequest, getAgentConfig, getAIStudioAgents, fetchTimeout, formatCitations, getAnswer, getAnswerStreaming, getSuggestedQuestions, hostAppName, isAgentSelectorEnabled, isAIStudioAgentSelectorEnabled, isCitationsEnabled, isDebugModeEnabled, isMarkdownEnabled, isOpen, isResetChatEnabled, isStopResponseEnabled, isStreamingEnabled, itemID, itemIDs, onCloseModal, shouldRenderProviders, suggestedQuestions, warningNotice, warningNoticeAriaLabel, }: ContentAnswersComponentProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export default ContentAnswersComponent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AgentType, type QuestionType } from '../../../types';
|
|
2
2
|
import { type QuestionRecordType } from '../records';
|
|
3
3
|
import { type UseContentAnswersProps } from '../types';
|
|
4
|
-
export declare function useContentAnswers({ contentAnswers, createSessionRequest, dispatchStateUpdate, fetchTimeout, getAgentConfig, getAnswerStreaming, getAnswer, getSuggestedQuestions, isCitationsEnabled, isStopResponseEnabled, isStreamingEnabled, itemID, formatCitations, }: UseContentAnswersProps): {
|
|
4
|
+
export declare function useContentAnswers({ contentAnswers, createSessionRequest, dispatchStateUpdate, fetchTimeout, getAgentConfig, getAnswerStreaming, getAnswer, getSuggestedQuestions, isCitationsEnabled, isStopResponseEnabled, isStreamingEnabled, itemID, itemIDs, formatCitations, }: UseContentAnswersProps): {
|
|
5
5
|
clearConversation: () => void;
|
|
6
6
|
createSession: () => Promise<void>;
|
|
7
7
|
fetchAgentConfig: (agent: AgentType) => Promise<void>;
|
|
@@ -43,8 +43,8 @@ export type PremissionsResponse = {
|
|
|
43
43
|
};
|
|
44
44
|
export type agentFetcherType = (payload: Record<string, unknown>) => Promise<unknown>;
|
|
45
45
|
export type SuggestedQuestionFetcherType = (itemID?: string) => Promise<SuggestedQuestionsResponse>;
|
|
46
|
-
export type fetcherType = (payload: Record<string, unknown>, itemID?: string, state?: ContentAnswersRecordType) => Promise<unknown>;
|
|
47
|
-
export type fetcherStreamingType = (payload: Record<string, unknown>, itemID?: string, abortController?: AbortController, state?: ContentAnswersRecordType) => Promise<unknown>;
|
|
46
|
+
export type fetcherType = (payload: Record<string, unknown>, itemID?: string, itemIDs?: Array<string>, state?: ContentAnswersRecordType) => Promise<unknown>;
|
|
47
|
+
export type fetcherStreamingType = (payload: Record<string, unknown>, itemID?: string, itemIDs?: Array<string>, abortController?: AbortController, state?: ContentAnswersRecordType) => Promise<unknown>;
|
|
48
48
|
export type fetchError = {
|
|
49
49
|
message?: string;
|
|
50
50
|
response?: {
|
|
@@ -76,7 +76,13 @@ export type ApiWrapperProps = {
|
|
|
76
76
|
isMarkdownEnabled?: boolean;
|
|
77
77
|
isOpen?: boolean;
|
|
78
78
|
isStreamingEnabled?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Item ID for the content answers
|
|
81
|
+
* Prefer passing itemIDs instead since this prop will be removed soon
|
|
82
|
+
* @deprecated
|
|
83
|
+
*/
|
|
79
84
|
itemID?: string;
|
|
85
|
+
itemIDs?: Array<string>;
|
|
80
86
|
onCloseModal?: () => void;
|
|
81
87
|
shouldRenderProviders?: boolean;
|
|
82
88
|
suggestedQuestionsRequestState?: REQUEST_STATE;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ContentAnswersRecordType } from '../records';
|
|
2
2
|
import { type fetcherStreamingType, type fetcherType, type StreamResponseTimeout } from '../types';
|
|
3
|
-
declare const getAnswerRequest: (payload: Record<string, unknown>, isStreamingRequest: boolean, requestID: string, itemID?: string, state?: ContentAnswersRecordType, fetcher?: fetcherType, fetcherStreaming?: fetcherStreamingType, abortController?: AbortController, fetchTimeout?: StreamResponseTimeout) => Promise<any>;
|
|
3
|
+
declare const getAnswerRequest: (payload: Record<string, unknown>, isStreamingRequest: boolean, requestID: string, itemID?: string, itemIDs?: Array<string>, state?: ContentAnswersRecordType, fetcher?: fetcherType, fetcherStreaming?: fetcherStreamingType, abortController?: AbortController, fetchTimeout?: StreamResponseTimeout) => Promise<any>;
|
|
4
4
|
export { getAnswerRequest };
|