@box/box-ai-content-answers 0.148.1 → 0.148.2
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.
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { useAgentsDispatch as
|
|
2
|
-
import
|
|
3
|
-
import t, { useMemo as is, useCallback as
|
|
4
|
-
import { A as R, C as
|
|
5
|
-
import { SET_NEW_ITEM as
|
|
6
|
-
import { QuestionRecord as
|
|
7
|
-
import { defaultFormatSuggestions as
|
|
8
|
-
import { getAnswerRequest as
|
|
9
|
-
import
|
|
10
|
-
const
|
|
1
|
+
import { useAgentsDispatch as as, ACTIONS as ns } from "@box/box-ai-agent-selector";
|
|
2
|
+
import us from "lodash/camelCase";
|
|
3
|
+
import t, { useMemo as is, useCallback as cs } from "react";
|
|
4
|
+
import { A as R, C as Es, R as V } from "../../../../../chunks/types.js";
|
|
5
|
+
import { SET_NEW_ITEM as fs, UPDATE_QUESTION as rs, SET_MODAL_ERROR as Cs, SET_MODAL_SUCCESS as _s, SET_IS_LOADING as X, SET_ANSWER_FEEDBACK as Ts, CLEAR_CONVERSATION_HISTORY as Rs, SET_SUGGESTED_QUESTIONS_REQUEST_STATE as Y, SET_SUGGESTED_QUESTIONS as ds } from "../actions.js";
|
|
6
|
+
import { QuestionRecord as Ns } from "../records.js";
|
|
7
|
+
import { defaultFormatSuggestions as Os, defaultFormatCitations as ys } from "../utils/format.js";
|
|
8
|
+
import { getAnswerRequest as Ss } from "../utils/request.js";
|
|
9
|
+
import F from "../utils/stream.js";
|
|
10
|
+
const Ls = /Too Many Requests/i, z = "Agent not found";
|
|
11
11
|
function Ms({
|
|
12
|
-
contentAnswers:
|
|
12
|
+
contentAnswers: n,
|
|
13
13
|
createSessionRequest: O,
|
|
14
14
|
dispatchStateUpdate: o,
|
|
15
|
-
enterpriseId:
|
|
15
|
+
enterpriseId: D,
|
|
16
16
|
fetchTimeout: k,
|
|
17
|
-
formatCitations: v =
|
|
18
|
-
getAnswerStreaming:
|
|
19
|
-
getAnswer:
|
|
20
|
-
getSuggestedQuestions:
|
|
21
|
-
isStopResponseEnabled:
|
|
22
|
-
isStreamingEnabled:
|
|
23
|
-
itemID:
|
|
24
|
-
items:
|
|
25
|
-
onSuggestedQuestionsFetched:
|
|
17
|
+
formatCitations: v = ys,
|
|
18
|
+
getAnswerStreaming: j,
|
|
19
|
+
getAnswer: x,
|
|
20
|
+
getSuggestedQuestions: I,
|
|
21
|
+
isStopResponseEnabled: K,
|
|
22
|
+
isStreamingEnabled: S,
|
|
23
|
+
itemID: E,
|
|
24
|
+
items: i,
|
|
25
|
+
onSuggestedQuestionsFetched: P,
|
|
26
26
|
sendErrorLog: G,
|
|
27
27
|
shouldPreinitSession: d = !0,
|
|
28
|
-
userId:
|
|
28
|
+
userId: W
|
|
29
29
|
}) {
|
|
30
|
-
const y = t.useRef(null),
|
|
30
|
+
const y = t.useRef(null), $ = as(), L = is(() => Array.isArray(i) && i.length > 1, [i]), B = cs((s) => Array.isArray(s) ? v(s) : null, [v]);
|
|
31
31
|
t.useEffect(
|
|
32
32
|
(s) => {
|
|
33
|
-
|
|
34
|
-
type:
|
|
35
|
-
itemID:
|
|
33
|
+
E && E !== n.item.id && o({
|
|
34
|
+
type: fs,
|
|
35
|
+
itemID: E,
|
|
36
36
|
fileVersionID: s
|
|
37
37
|
});
|
|
38
38
|
},
|
|
39
39
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
-
[
|
|
40
|
+
[E]
|
|
41
41
|
);
|
|
42
|
-
const
|
|
42
|
+
const c = t.useCallback((s, e) => {
|
|
43
43
|
o({
|
|
44
|
-
type:
|
|
44
|
+
type: rs,
|
|
45
45
|
newQuestion: s,
|
|
46
46
|
session: e
|
|
47
47
|
}), y.current = s;
|
|
48
|
-
}, [o]),
|
|
48
|
+
}, [o]), H = t.useCallback((s) => {
|
|
49
49
|
o({
|
|
50
|
-
type:
|
|
50
|
+
type: Cs,
|
|
51
51
|
error: s
|
|
52
52
|
});
|
|
53
53
|
}, [o]), Q = t.useCallback((s, e, a) => {
|
|
54
54
|
const {
|
|
55
|
-
answer:
|
|
55
|
+
answer: u,
|
|
56
56
|
error: f,
|
|
57
57
|
citations: l = [],
|
|
58
58
|
createdAt: r = null,
|
|
59
59
|
encodedSession: C = void 0,
|
|
60
60
|
contextSession: _ = void 0
|
|
61
|
-
} = s, N = e.set("citations",
|
|
62
|
-
answer:
|
|
61
|
+
} = s, N = e.set("citations", B(l)).merge({
|
|
62
|
+
answer: u,
|
|
63
63
|
error: f,
|
|
64
64
|
created_at: r,
|
|
65
65
|
isLoading: !1,
|
|
@@ -70,68 +70,68 @@ function Ms({
|
|
|
70
70
|
encodedSession: C
|
|
71
71
|
}), _ && (T = {
|
|
72
72
|
contextSession: _
|
|
73
|
-
}),
|
|
74
|
-
}, [
|
|
73
|
+
}), c(N, T);
|
|
74
|
+
}, [c, B]), g = t.useCallback(
|
|
75
75
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
76
|
(s, e) => {
|
|
77
|
-
var N, T,
|
|
78
|
-
const a = (s == null ? void 0 : s.message) || "",
|
|
77
|
+
var N, T, m;
|
|
78
|
+
const a = (s == null ? void 0 : s.message) || "", u = ((N = s == null ? void 0 : s.response) == null ? void 0 : N.status) === 429 || Ls.test(a), f = (s == null ? void 0 : s.code) === z || (s == null ? void 0 : s.errorCode) === z, l = ((T = s == null ? void 0 : s.response) == null ? void 0 : T.status) === 204, r = ((m = s == null ? void 0 : s.response) == null ? void 0 : m.status) === 412, C = l ? R.NO_CONTENT : u ? R.RATE_LIMITING : r ? R.PRECONDITION_FAILED : f ? R.AGENT_NOT_FOUND : R.GENERAL, _ = e.merge({
|
|
79
79
|
error: C,
|
|
80
80
|
isLoading: !1,
|
|
81
81
|
isCompleted: !0
|
|
82
82
|
});
|
|
83
|
-
|
|
83
|
+
c(_, void 0);
|
|
84
84
|
},
|
|
85
|
-
[
|
|
85
|
+
[c]
|
|
86
86
|
), A = t.useCallback(async (s, e) => {
|
|
87
87
|
try {
|
|
88
88
|
const a = {
|
|
89
89
|
prompt: s.prompt,
|
|
90
90
|
aiAgent: e || void 0,
|
|
91
|
-
userId:
|
|
92
|
-
enterpriseId:
|
|
93
|
-
},
|
|
91
|
+
userId: W,
|
|
92
|
+
enterpriseId: D
|
|
93
|
+
}, u = `content-answers-${s.id}`;
|
|
94
94
|
let f;
|
|
95
|
-
|
|
96
|
-
const l = await
|
|
97
|
-
|
|
95
|
+
S && (f = F.createAbortRequest(u));
|
|
96
|
+
const l = await Ss(a, S, u, E, i, n, x, j, f, k, G);
|
|
97
|
+
S ? F.receiveStreamedResponse(u, l, (r) => {
|
|
98
98
|
const {
|
|
99
99
|
code: C,
|
|
100
100
|
data: _,
|
|
101
101
|
error: N,
|
|
102
102
|
citations: T,
|
|
103
|
-
contextSession:
|
|
104
|
-
isCompleted:
|
|
105
|
-
createdAt:
|
|
106
|
-
} = r,
|
|
103
|
+
contextSession: m,
|
|
104
|
+
isCompleted: os,
|
|
105
|
+
createdAt: ts
|
|
106
|
+
} = r, ls = {
|
|
107
107
|
answer: _,
|
|
108
108
|
citations: T,
|
|
109
109
|
error: N,
|
|
110
|
-
contextSession:
|
|
111
|
-
createdAt:
|
|
110
|
+
contextSession: m,
|
|
111
|
+
createdAt: ts
|
|
112
112
|
};
|
|
113
113
|
l.ok && l.status === 200 ? Q({
|
|
114
|
-
...
|
|
115
|
-
}, s,
|
|
114
|
+
...ls
|
|
115
|
+
}, s, os) : g({
|
|
116
116
|
response: l,
|
|
117
117
|
code: C
|
|
118
118
|
}, s);
|
|
119
119
|
}, void 0, k, G) : (Object.entries(l).forEach(([r, C]) => {
|
|
120
|
-
const _ =
|
|
120
|
+
const _ = us(r);
|
|
121
121
|
delete l[r], l[_] = C;
|
|
122
122
|
}), Q(l, s, !0));
|
|
123
123
|
} catch (a) {
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
124
|
+
if (K && a instanceof Error && a.name === "AbortError") {
|
|
125
|
+
const u = s.set("error", []).merge({
|
|
126
126
|
error: R.RESPONSE_STOPPED,
|
|
127
127
|
isLoading: !1,
|
|
128
128
|
isCompleted: !0
|
|
129
129
|
});
|
|
130
|
-
u
|
|
130
|
+
c(u);
|
|
131
131
|
} else
|
|
132
132
|
g(a, s);
|
|
133
133
|
}
|
|
134
|
-
}, [
|
|
134
|
+
}, [W, D, S, E, i, n, x, j, k, G, Q, g, K, c]), J = t.useCallback((s) => {
|
|
135
135
|
const {
|
|
136
136
|
encoded_session: e,
|
|
137
137
|
metadata: {
|
|
@@ -141,95 +141,102 @@ function Ms({
|
|
|
141
141
|
}
|
|
142
142
|
} = s;
|
|
143
143
|
o({
|
|
144
|
-
type:
|
|
144
|
+
type: _s,
|
|
145
145
|
encodedSession: e,
|
|
146
146
|
isLargeFile: a
|
|
147
147
|
});
|
|
148
|
-
}, [o]),
|
|
148
|
+
}, [o]), p = t.useCallback(async (s = !0, e = !0) => {
|
|
149
149
|
try {
|
|
150
150
|
s && o({
|
|
151
|
-
type:
|
|
151
|
+
type: X,
|
|
152
152
|
isLoading: !0
|
|
153
153
|
});
|
|
154
154
|
const a = await O({
|
|
155
|
-
items:
|
|
156
|
-
},
|
|
157
|
-
|
|
155
|
+
items: i
|
|
156
|
+
}, E);
|
|
157
|
+
J(a);
|
|
158
158
|
} catch {
|
|
159
|
-
if (e &&
|
|
160
|
-
type:
|
|
159
|
+
if (e && H(Es.GENERAL), !d && (o({
|
|
160
|
+
type: X,
|
|
161
161
|
isLoading: !1
|
|
162
162
|
}), y.current)) {
|
|
163
|
-
const
|
|
163
|
+
const u = y.current.set("error", R.GENERAL).merge({
|
|
164
164
|
isLoading: !1,
|
|
165
165
|
isCompleted: !0
|
|
166
166
|
});
|
|
167
|
-
u
|
|
167
|
+
c(u);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
-
}, [O,
|
|
171
|
-
const
|
|
172
|
-
a && (s.id = `${f.length}`), !d &&
|
|
173
|
-
const l = new
|
|
174
|
-
return
|
|
175
|
-
}, [
|
|
170
|
+
}, [O, i, E, J, o, d, H, c]), M = t.useCallback((s, e, a = !0) => {
|
|
171
|
+
const u = !n.isLoading && !n.encodedSession && !L && O, f = (n == null ? void 0 : n.questions) || [];
|
|
172
|
+
a && (s.id = `${f.length}`), !d && u && (s.error = R.GENERAL, s.isLoading = !1, s.isCompleted = !0);
|
|
173
|
+
const l = new Ns(s);
|
|
174
|
+
return c(l), d || n.encodedSession ? A(l, e) : !n.isLoading && !d && O && p(!0, !1), l;
|
|
175
|
+
}, [n.encodedSession, n.isLoading, n == null ? void 0 : n.questions, p, O, L, A, d, c]), Z = t.useCallback((s, e) => {
|
|
176
176
|
o({
|
|
177
|
-
type:
|
|
177
|
+
type: Ts,
|
|
178
178
|
questionId: s,
|
|
179
179
|
feedbackValue: e
|
|
180
180
|
});
|
|
181
|
-
}, [o]),
|
|
181
|
+
}, [o]), q = t.useCallback(() => {
|
|
182
182
|
o({
|
|
183
|
-
type:
|
|
183
|
+
type: Rs
|
|
184
184
|
});
|
|
185
|
-
}, [o]),
|
|
186
|
-
|
|
185
|
+
}, [o]), w = t.useCallback(async (s, e) => {
|
|
186
|
+
M({
|
|
187
187
|
...s.toJS(),
|
|
188
188
|
answer: "",
|
|
189
189
|
isLoading: !0,
|
|
190
190
|
isCompleted: !1,
|
|
191
191
|
error: null
|
|
192
192
|
}, e, !1);
|
|
193
|
-
}, [
|
|
193
|
+
}, [M]), U = t.useCallback((s) => {
|
|
194
194
|
let e;
|
|
195
|
-
s ? e = s.id : y.current && (e = y.current.id), e &&
|
|
196
|
-
}, []),
|
|
197
|
-
s &&
|
|
198
|
-
type:
|
|
195
|
+
s ? e = s.id : y.current && (e = y.current.id), e && F.abortRequest(`content-answers-${e}`, !0);
|
|
196
|
+
}, []), h = t.useCallback(async (s) => {
|
|
197
|
+
s && $({
|
|
198
|
+
type: ns.SET_ASK_CONFIG,
|
|
199
199
|
id: s.id,
|
|
200
200
|
ask: s == null ? void 0 : s.ask
|
|
201
201
|
});
|
|
202
|
-
}, [
|
|
203
|
-
|
|
202
|
+
}, [$]), [b, ss] = t.useState("");
|
|
203
|
+
t.useEffect(() => {
|
|
204
|
+
if (!i || i.length === 0)
|
|
205
|
+
return;
|
|
206
|
+
const s = i.map((e) => e.id).join(",");
|
|
207
|
+
s !== b && ss(s);
|
|
208
|
+
}, [i, b]);
|
|
209
|
+
const es = t.useCallback(async () => {
|
|
210
|
+
if (!(!b || !I || L)) {
|
|
204
211
|
o({
|
|
205
|
-
type:
|
|
206
|
-
requestState:
|
|
212
|
+
type: Y,
|
|
213
|
+
requestState: V.IN_PROGRESS
|
|
207
214
|
});
|
|
208
215
|
try {
|
|
209
|
-
const s =
|
|
210
|
-
|
|
211
|
-
type:
|
|
216
|
+
const s = Os(await I(E, i));
|
|
217
|
+
P && P(s), o({
|
|
218
|
+
type: ds,
|
|
212
219
|
suggestedQuestions: s
|
|
213
220
|
});
|
|
214
221
|
} catch {
|
|
215
222
|
o({
|
|
216
|
-
type:
|
|
217
|
-
requestState:
|
|
223
|
+
type: Y,
|
|
224
|
+
requestState: V.ERROR
|
|
218
225
|
});
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
|
-
}, [o,
|
|
228
|
+
}, [o, I, L, E, b]);
|
|
222
229
|
return {
|
|
223
|
-
clearConversation:
|
|
224
|
-
createSession:
|
|
225
|
-
fetchAgentConfig:
|
|
226
|
-
fetchSuggestedQuestions:
|
|
227
|
-
retryQuestion:
|
|
228
|
-
sendQuestion:
|
|
230
|
+
clearConversation: q,
|
|
231
|
+
createSession: p,
|
|
232
|
+
fetchAgentConfig: h,
|
|
233
|
+
fetchSuggestedQuestions: es,
|
|
234
|
+
retryQuestion: w,
|
|
235
|
+
sendQuestion: M,
|
|
229
236
|
sendQuestionAnswerRequest: A,
|
|
230
|
-
setAnswerFeedback:
|
|
231
|
-
stopQuestion:
|
|
232
|
-
updateQuestionInState:
|
|
237
|
+
setAnswerFeedback: Z,
|
|
238
|
+
stopQuestion: U,
|
|
239
|
+
updateQuestionInState: c
|
|
233
240
|
};
|
|
234
241
|
}
|
|
235
242
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/box-ai-content-answers",
|
|
3
|
-
"version": "0.148.
|
|
3
|
+
"version": "0.148.2",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@box/blueprint-web": "^7.8.0",
|
|
6
6
|
"@box/blueprint-web-assets": "^4.56.1",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@box/babel-plugin-target-attributes": "1.3.0",
|
|
20
|
-
"@box/blueprint-web": "^12.64.
|
|
20
|
+
"@box/blueprint-web": "^12.64.1",
|
|
21
21
|
"@box/blueprint-web-assets": "^4.64.8",
|
|
22
|
-
"@box/box-ai-agent-selector": "^0.58.
|
|
23
|
-
"@box/item-icon": "^0.23.
|
|
22
|
+
"@box/box-ai-agent-selector": "^0.58.2",
|
|
23
|
+
"@box/item-icon": "^0.23.2",
|
|
24
24
|
"@box/storybook-utils": "^0.14.0",
|
|
25
25
|
"@testing-library/react": "^15.0.6",
|
|
26
26
|
"react": "^18.3.0",
|