@box/box-ai-content-answers 0.68.0 → 0.69.1
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 +90 -87
- 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/suggested-questions/suggested-questions.js +34 -34
- package/package.json +2 -2
- 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,110 +1,113 @@
|
|
|
1
|
-
import { useReducer as
|
|
2
|
-
import { R as
|
|
3
|
-
import { useContentAnswers as
|
|
4
|
-
import { ContentAnswersRecord as
|
|
5
|
-
import
|
|
6
|
-
import { jsx as
|
|
7
|
-
const
|
|
8
|
-
WrappedComponent:
|
|
9
|
-
createSessionRequest:
|
|
10
|
-
getAgentConfig:
|
|
11
|
-
getAIStudioAgents:
|
|
12
|
-
fetchTimeout:
|
|
13
|
-
formatCitations:
|
|
14
|
-
getAnswer:
|
|
15
|
-
getAnswerStreaming:
|
|
1
|
+
import { useReducer as M, useEffect as V } from "react";
|
|
2
|
+
import { R as d } from "../../../../chunks/types.js";
|
|
3
|
+
import { useContentAnswers as W } from "./hooks/useContentAnswers.js";
|
|
4
|
+
import { ContentAnswersRecord as X, ContentAnswersItemRecord as Y } from "./records.js";
|
|
5
|
+
import Z from "./reducer.js";
|
|
6
|
+
import { jsx as $ } from "react/jsx-runtime";
|
|
7
|
+
const re = ({
|
|
8
|
+
WrappedComponent: f,
|
|
9
|
+
createSessionRequest: m,
|
|
10
|
+
getAgentConfig: S,
|
|
11
|
+
getAIStudioAgents: g,
|
|
12
|
+
fetchTimeout: A,
|
|
13
|
+
formatCitations: p,
|
|
14
|
+
getAnswer: C,
|
|
15
|
+
getAnswerStreaming: R,
|
|
16
16
|
getSuggestedQuestions: e,
|
|
17
|
-
hostAppName:
|
|
18
|
-
isAgentSelectorEnabled:
|
|
19
|
-
isAIStudioAgentSelectorEnabled:
|
|
17
|
+
hostAppName: w,
|
|
18
|
+
isAgentSelectorEnabled: Q,
|
|
19
|
+
isAIStudioAgentSelectorEnabled: T,
|
|
20
20
|
isCitationsEnabled: n,
|
|
21
|
-
isDebugModeEnabled:
|
|
22
|
-
isMarkdownEnabled:
|
|
21
|
+
isDebugModeEnabled: h,
|
|
22
|
+
isMarkdownEnabled: l,
|
|
23
23
|
isOpen: s,
|
|
24
|
-
isResetChatEnabled:
|
|
25
|
-
isStopResponseEnabled:
|
|
24
|
+
isResetChatEnabled: q,
|
|
25
|
+
isStopResponseEnabled: E,
|
|
26
26
|
isStreamingEnabled: r,
|
|
27
27
|
itemID: o,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
itemIDs: u,
|
|
29
|
+
onCloseModal: j,
|
|
30
|
+
shouldRenderProviders: U = !0,
|
|
31
|
+
suggestedQuestions: _,
|
|
32
|
+
warningNotice: v,
|
|
33
|
+
warningNoticeAriaLabel: x
|
|
33
34
|
}) => {
|
|
34
|
-
const [
|
|
35
|
-
item: new
|
|
35
|
+
const [c, y] = M(Z, new X({
|
|
36
|
+
item: new Y({
|
|
36
37
|
id: o
|
|
37
38
|
})
|
|
38
39
|
})), {
|
|
39
|
-
clearConversation:
|
|
40
|
-
createSession:
|
|
41
|
-
fetchAgentConfig:
|
|
42
|
-
fetchSuggestedQuestions:
|
|
43
|
-
retryQuestion:
|
|
44
|
-
sendQuestion:
|
|
45
|
-
stopQuestion:
|
|
46
|
-
} =
|
|
47
|
-
contentAnswers:
|
|
48
|
-
createSessionRequest:
|
|
49
|
-
dispatchStateUpdate:
|
|
50
|
-
fetchTimeout:
|
|
51
|
-
formatCitations:
|
|
52
|
-
getAgentConfig:
|
|
53
|
-
getAnswerStreaming:
|
|
54
|
-
getAnswer:
|
|
40
|
+
clearConversation: L,
|
|
41
|
+
createSession: N,
|
|
42
|
+
fetchAgentConfig: i,
|
|
43
|
+
fetchSuggestedQuestions: a,
|
|
44
|
+
retryQuestion: O,
|
|
45
|
+
sendQuestion: P,
|
|
46
|
+
stopQuestion: b
|
|
47
|
+
} = W({
|
|
48
|
+
contentAnswers: c,
|
|
49
|
+
createSessionRequest: m,
|
|
50
|
+
dispatchStateUpdate: y,
|
|
51
|
+
fetchTimeout: A,
|
|
52
|
+
formatCitations: p,
|
|
53
|
+
getAgentConfig: S,
|
|
54
|
+
getAnswerStreaming: R,
|
|
55
|
+
getAnswer: C,
|
|
55
56
|
getSuggestedQuestions: e,
|
|
56
57
|
isCitationsEnabled: n,
|
|
57
|
-
isStopResponseEnabled:
|
|
58
|
+
isStopResponseEnabled: E,
|
|
58
59
|
isStreamingEnabled: r,
|
|
59
|
-
itemID: o
|
|
60
|
+
itemID: o,
|
|
61
|
+
itemIDs: u
|
|
60
62
|
}), {
|
|
61
|
-
encodedSession:
|
|
62
|
-
error:
|
|
63
|
-
isLoading:
|
|
64
|
-
hasRequestInProgress:
|
|
65
|
-
questions:
|
|
63
|
+
encodedSession: k,
|
|
64
|
+
error: z,
|
|
65
|
+
isLoading: B,
|
|
66
|
+
hasRequestInProgress: F = !1,
|
|
67
|
+
questions: G,
|
|
66
68
|
suggestedQuestions: t
|
|
67
|
-
} =
|
|
68
|
-
|
|
69
|
-
s && t.requestState ===
|
|
70
|
-
}, [s,
|
|
71
|
-
const
|
|
72
|
-
createSession:
|
|
73
|
-
encodedSession:
|
|
74
|
-
error:
|
|
75
|
-
getAIStudioAgents:
|
|
76
|
-
hostAppName:
|
|
69
|
+
} = c;
|
|
70
|
+
V(() => {
|
|
71
|
+
s && t.requestState === d.NOT_STARTED && a();
|
|
72
|
+
}, [s, a, t.requestState]);
|
|
73
|
+
const H = {
|
|
74
|
+
createSession: N,
|
|
75
|
+
encodedSession: k,
|
|
76
|
+
error: z,
|
|
77
|
+
getAIStudioAgents: g,
|
|
78
|
+
hostAppName: w,
|
|
77
79
|
hasCustomSuggestedQuestions: !!e,
|
|
78
|
-
hasRequestInProgress:
|
|
79
|
-
isAgentSelectorEnabled:
|
|
80
|
-
isAIStudioAgentSelectorEnabled:
|
|
80
|
+
hasRequestInProgress: F,
|
|
81
|
+
isAgentSelectorEnabled: Q,
|
|
82
|
+
isAIStudioAgentSelectorEnabled: T,
|
|
81
83
|
isCitationsEnabled: n,
|
|
82
|
-
isDebugModeEnabled:
|
|
83
|
-
isMarkdownEnabled:
|
|
84
|
-
isLoading:
|
|
84
|
+
isDebugModeEnabled: h,
|
|
85
|
+
isMarkdownEnabled: l,
|
|
86
|
+
isLoading: B,
|
|
85
87
|
isOpen: s,
|
|
86
|
-
isResetChatEnabled:
|
|
88
|
+
isResetChatEnabled: q,
|
|
87
89
|
isStreamingEnabled: r,
|
|
88
90
|
itemID: o,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
itemIDs: u,
|
|
92
|
+
onClearAction: L,
|
|
93
|
+
onCloseModal: j,
|
|
94
|
+
onSelectAgent: i,
|
|
95
|
+
onAgentEditorToggle: i,
|
|
96
|
+
questions: G,
|
|
97
|
+
retryQuestion: O,
|
|
98
|
+
sendQuestion: P,
|
|
99
|
+
shouldRenderProviders: U,
|
|
100
|
+
stopQuestion: b,
|
|
101
|
+
suggestedQuestionsRequestState: e ? t.requestState : d.SUCCESS,
|
|
102
|
+
suggestedQuestions: e ? t.suggestions : _,
|
|
103
|
+
warningNotice: v,
|
|
104
|
+
warningNoticeAriaLabel: x
|
|
105
|
+
}, J = Object.fromEntries(Object.entries(H).filter(([D, K]) => K !== void 0));
|
|
106
|
+
return /* @__PURE__ */ $(f, {
|
|
107
|
+
...J
|
|
105
108
|
});
|
|
106
109
|
};
|
|
107
110
|
export {
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
re as ContentAnswersComponent,
|
|
112
|
+
re as default
|
|
110
113
|
};
|
|
@@ -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,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.1",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@box/blueprint-web": "^7.8.0",
|
|
6
6
|
"@box/blueprint-web-assets": "^4.16.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"**/*.css"
|
|
55
55
|
],
|
|
56
56
|
"license": "SEE LICENSE IN LICENSE",
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "be7f7c7fdf17d8843ca75e4d28e6d8e3109dc9ee"
|
|
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 };
|