@box/box-ai-content-answers 0.57.2 → 0.57.4
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,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import t, { useCallback as
|
|
3
|
-
import { useAgentsDispatch as
|
|
4
|
-
import { A as m, C as
|
|
5
|
-
import { SET_NEW_ITEM as
|
|
6
|
-
import { QuestionRecord as
|
|
7
|
-
import { defaultFormatSuggestions as
|
|
8
|
-
import { getAnswerRequest as
|
|
1
|
+
import K from "lodash/camelCase";
|
|
2
|
+
import t, { useCallback as X } from "react";
|
|
3
|
+
import { useAgentsDispatch as Y } from "../../../contexts/AgentsContext.js";
|
|
4
|
+
import { A as m, C as z, R as F } from "../../../../../chunks/types.js";
|
|
5
|
+
import { SET_NEW_ITEM as B, UPDATE_QUESTION as Z, SET_MODAL_ERROR as h, SET_MODAL_SUCCESS as w, SET_IS_LOADING as U, CLEAR_CONVERSATION_HISTORY as ss, SET_SUGGESTED_QUESTIONS_REQUEST_STATE as q, SET_SUGGESTED_QUESTIONS as es } from "../actions.js";
|
|
6
|
+
import { QuestionRecord as os } from "../records.js";
|
|
7
|
+
import { defaultFormatSuggestions as ts, defaultFormatCitations as ns } from "../utils/format.js";
|
|
8
|
+
import { getAnswerRequest as as } from "../utils/request.js";
|
|
9
9
|
import p from "../utils/stream.js";
|
|
10
|
-
const
|
|
11
|
-
function
|
|
10
|
+
const is = /Too Many Requests/i;
|
|
11
|
+
function Os({
|
|
12
12
|
contentAnswers: a,
|
|
13
13
|
createSessionRequest: Q,
|
|
14
14
|
dispatchStateUpdate: o,
|
|
@@ -17,16 +17,16 @@ function ms({
|
|
|
17
17
|
getAnswerStreaming: k,
|
|
18
18
|
getAnswer: G,
|
|
19
19
|
getSuggestedQuestions: N,
|
|
20
|
-
isCitationsEnabled:
|
|
20
|
+
isCitationsEnabled: us,
|
|
21
21
|
isStreamingEnabled: T,
|
|
22
22
|
itemID: u,
|
|
23
|
-
formatCitations: I =
|
|
23
|
+
formatCitations: I = ns
|
|
24
24
|
}) {
|
|
25
|
-
const P = t.useRef(null), A =
|
|
25
|
+
const P = t.useRef(null), A = Y(), g = X((s) => Array.isArray(s) ? I(s) : null, [I]);
|
|
26
26
|
t.useEffect(
|
|
27
27
|
(s) => {
|
|
28
28
|
u && u !== a.item.id && o({
|
|
29
|
-
type:
|
|
29
|
+
type: B,
|
|
30
30
|
itemID: u,
|
|
31
31
|
fileVersionID: s
|
|
32
32
|
});
|
|
@@ -36,13 +36,13 @@ function ms({
|
|
|
36
36
|
);
|
|
37
37
|
const R = t.useCallback((s, e) => {
|
|
38
38
|
o({
|
|
39
|
-
type:
|
|
39
|
+
type: Z,
|
|
40
40
|
newQuestion: s,
|
|
41
41
|
session: e
|
|
42
42
|
}), P.current = s;
|
|
43
43
|
}, [o]), M = t.useCallback((s) => {
|
|
44
44
|
o({
|
|
45
|
-
type:
|
|
45
|
+
type: h,
|
|
46
46
|
error: s
|
|
47
47
|
});
|
|
48
48
|
}, [o]), S = t.useCallback((s, e, i) => {
|
|
@@ -70,7 +70,7 @@ function ms({
|
|
|
70
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
71
|
(s, e) => {
|
|
72
72
|
var c, _, C;
|
|
73
|
-
const i = (s == null ? void 0 : s.message) || "", r = ((c = s == null ? void 0 : s.response) == null ? void 0 : c.status) === 429 ||
|
|
73
|
+
const i = (s == null ? void 0 : s.message) || "", r = ((c = s == null ? void 0 : s.response) == null ? void 0 : c.status) === 429 || is.test(i), l = ((_ = s == null ? void 0 : s.response) == null ? void 0 : _.status) === 204, n = ((C = s == null ? void 0 : s.response) == null ? void 0 : C.status) === 412, E = l ? m.NO_CONTENT : r ? m.RATE_LIMITING : n ? m.PRECONDITION_FAILED : m.GENERAL, f = e.merge({
|
|
74
74
|
error: E,
|
|
75
75
|
isLoading: !1,
|
|
76
76
|
isCompleted: !0
|
|
@@ -86,27 +86,29 @@ function ms({
|
|
|
86
86
|
}, r = `content-answers-${s.id}`;
|
|
87
87
|
let l;
|
|
88
88
|
T && (l = p.createAbortRequest(r));
|
|
89
|
-
const n = await
|
|
89
|
+
const n = await as(i, T, r, u, a, G, k, l, O);
|
|
90
90
|
T ? n.ok && n.status === 200 ? p.receiveStreamedResponse(r, n, (E) => {
|
|
91
91
|
const {
|
|
92
92
|
data: f,
|
|
93
93
|
error: c,
|
|
94
94
|
citations: _,
|
|
95
95
|
contextSession: C,
|
|
96
|
-
isCompleted: H
|
|
96
|
+
isCompleted: H,
|
|
97
|
+
createdAt: J
|
|
97
98
|
} = E;
|
|
98
99
|
S({
|
|
99
100
|
...{
|
|
100
101
|
answer: f,
|
|
101
102
|
citations: _,
|
|
102
103
|
error: c,
|
|
103
|
-
contextSession: C
|
|
104
|
+
contextSession: C,
|
|
105
|
+
createdAt: J
|
|
104
106
|
}
|
|
105
107
|
}, s, H);
|
|
106
108
|
}, void 0, O) : d({
|
|
107
109
|
response: n
|
|
108
110
|
}, s) : (Object.entries(n).forEach(([E, f]) => {
|
|
109
|
-
const c =
|
|
111
|
+
const c = K(E);
|
|
110
112
|
delete n[E], n[c] = f;
|
|
111
113
|
}), S(n, s, !0));
|
|
112
114
|
} catch (i) {
|
|
@@ -115,7 +117,7 @@ function ms({
|
|
|
115
117
|
}, [T, u, a, G, k, O, S, d]), L = t.useCallback((s, e, i = !0) => {
|
|
116
118
|
const r = (a == null ? void 0 : a.questions) || [];
|
|
117
119
|
i && (s.id = `${r.length}`);
|
|
118
|
-
const l = new
|
|
120
|
+
const l = new os(s);
|
|
119
121
|
return R(l), b(l, e), l;
|
|
120
122
|
}, [a == null ? void 0 : a.questions, b, R]), v = t.useCallback((s) => {
|
|
121
123
|
const {
|
|
@@ -127,14 +129,14 @@ function ms({
|
|
|
127
129
|
}
|
|
128
130
|
} = s;
|
|
129
131
|
o({
|
|
130
|
-
type:
|
|
132
|
+
type: w,
|
|
131
133
|
encodedSession: e,
|
|
132
134
|
isLargeFile: i
|
|
133
135
|
});
|
|
134
136
|
}, [o]), j = t.useCallback(async () => {
|
|
135
137
|
try {
|
|
136
138
|
o({
|
|
137
|
-
type:
|
|
139
|
+
type: U,
|
|
138
140
|
isLoading: !0
|
|
139
141
|
});
|
|
140
142
|
const s = await Q({
|
|
@@ -142,11 +144,11 @@ function ms({
|
|
|
142
144
|
}, u);
|
|
143
145
|
v(s);
|
|
144
146
|
} catch {
|
|
145
|
-
M(
|
|
147
|
+
M(z.GENERAL);
|
|
146
148
|
}
|
|
147
149
|
}, [o, Q, a.item, u, v, M]), x = t.useCallback(() => {
|
|
148
150
|
o({
|
|
149
|
-
type:
|
|
151
|
+
type: ss
|
|
150
152
|
});
|
|
151
153
|
}, [o]), $ = t.useCallback(async (s, e) => {
|
|
152
154
|
L({
|
|
@@ -176,9 +178,9 @@ function ms({
|
|
|
176
178
|
requestState: F.IN_PROGRESS
|
|
177
179
|
});
|
|
178
180
|
try {
|
|
179
|
-
const s =
|
|
181
|
+
const s = ts(await N(u));
|
|
180
182
|
o({
|
|
181
|
-
type:
|
|
183
|
+
type: es,
|
|
182
184
|
suggestedQuestions: s
|
|
183
185
|
});
|
|
184
186
|
} catch {
|
|
@@ -202,5 +204,5 @@ function ms({
|
|
|
202
204
|
};
|
|
203
205
|
}
|
|
204
206
|
export {
|
|
205
|
-
|
|
207
|
+
Os as useContentAnswers
|
|
206
208
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/box-ai-content-answers",
|
|
3
|
-
"version": "0.57.
|
|
3
|
+
"version": "0.57.4",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@box/blueprint-web": "^7.8.0",
|
|
6
6
|
"@box/blueprint-web-assets": "^4.16.0",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"remarkable": "^2.0.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@box/blueprint-web": "^7.33.
|
|
16
|
+
"@box/blueprint-web": "^7.33.1",
|
|
17
17
|
"@box/blueprint-web-assets": "^4.27.0",
|
|
18
18
|
"@box/storybook-utils": "^0.6.1",
|
|
19
19
|
"@testing-library/react": "^15.0.6",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"**/*.css"
|
|
53
53
|
],
|
|
54
54
|
"license": "SEE LICENSE IN LICENSE",
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "e77ce4a2951397e35430076450d0390e3ef81d46"
|
|
56
56
|
}
|