@box/box-ai-content-answers 0.54.3 → 0.54.5
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/hooks/useContentAnswers.js +71 -71
- package/esm/lib/components/api-wrapper/utils/request.js +8 -4
- package/esm/lib/components/api-wrapper/utils/stream.js +54 -50
- package/package.json +3 -3
- package/types/lib/components/api-wrapper/types.d.ts +5 -4
- package/types/lib/components/api-wrapper/utils/request.d.ts +2 -2
- package/types/lib/components/api-wrapper/utils/stream.d.ts +6 -6
|
@@ -1,76 +1,76 @@
|
|
|
1
1
|
import K from "lodash/camelCase";
|
|
2
2
|
import t, { useCallback as X } from "react";
|
|
3
3
|
import { useAgentsDispatch as Y } from "../../../contexts/AgentsContext.js";
|
|
4
|
-
import { A as
|
|
5
|
-
import { SET_NEW_ITEM as
|
|
4
|
+
import { A as L, C as z, R as q } from "../../../../../chunks/types.js";
|
|
5
|
+
import { SET_NEW_ITEM as B, UPDATE_QUESTION as D, SET_MODAL_ERROR as Z, SET_MODAL_SUCCESS as h, SET_IS_LOADING as w, CLEAR_CONVERSATION_HISTORY as U, SET_SUGGESTED_QUESTIONS_REQUEST_STATE as F, SET_SUGGESTED_QUESTIONS as ss } from "../actions.js";
|
|
6
6
|
import { QuestionRecord as es } from "../records.js";
|
|
7
7
|
import { defaultFormatSuggestions as os, defaultFormatCitations as ts } from "../utils/format.js";
|
|
8
8
|
import { getAnswerRequest as as } from "../utils/request.js";
|
|
9
|
-
import
|
|
9
|
+
import Q from "../utils/stream.js";
|
|
10
10
|
const ns = /Too Many Requests/i;
|
|
11
11
|
function ms({
|
|
12
12
|
contentAnswers: n,
|
|
13
|
-
createSessionRequest:
|
|
13
|
+
createSessionRequest: k,
|
|
14
14
|
dispatchStateUpdate: o,
|
|
15
|
-
fetchTimeout:
|
|
16
|
-
getAgentConfig:
|
|
15
|
+
fetchTimeout: T,
|
|
16
|
+
getAgentConfig: m,
|
|
17
17
|
getAnswerStreaming: p,
|
|
18
18
|
getAnswer: G,
|
|
19
|
-
getSuggestedQuestions:
|
|
19
|
+
getSuggestedQuestions: y,
|
|
20
20
|
isCitationsEnabled: rs,
|
|
21
21
|
isStreamingEnabled: _,
|
|
22
|
-
itemID:
|
|
22
|
+
itemID: l,
|
|
23
23
|
formatCitations: g = ts
|
|
24
24
|
}) {
|
|
25
25
|
const P = t.useRef(null), A = Y(), I = X((s) => Array.isArray(s) ? g(s) : null, [g]);
|
|
26
26
|
t.useEffect(
|
|
27
27
|
(s) => {
|
|
28
|
-
|
|
29
|
-
type:
|
|
30
|
-
itemID:
|
|
28
|
+
l && l !== n.item.id && o({
|
|
29
|
+
type: B,
|
|
30
|
+
itemID: l,
|
|
31
31
|
fileVersionID: s
|
|
32
32
|
});
|
|
33
33
|
},
|
|
34
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
[
|
|
35
|
+
[l]
|
|
36
36
|
);
|
|
37
37
|
const C = t.useCallback((s, e) => {
|
|
38
38
|
o({
|
|
39
|
-
type:
|
|
39
|
+
type: D,
|
|
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: Z,
|
|
46
46
|
error: s
|
|
47
47
|
});
|
|
48
|
-
}, [o]),
|
|
48
|
+
}, [o]), S = t.useCallback((s, e, r) => {
|
|
49
49
|
const {
|
|
50
|
-
answer:
|
|
51
|
-
error:
|
|
50
|
+
answer: i,
|
|
51
|
+
error: u,
|
|
52
52
|
citations: a = [],
|
|
53
53
|
createdAt: f = null,
|
|
54
|
-
encodedSession:
|
|
55
|
-
contextSession:
|
|
56
|
-
} = s,
|
|
57
|
-
answer:
|
|
58
|
-
error:
|
|
54
|
+
encodedSession: c = void 0,
|
|
55
|
+
contextSession: E = void 0
|
|
56
|
+
} = s, b = e.set("citations", I(a)).merge({
|
|
57
|
+
answer: i,
|
|
58
|
+
error: u,
|
|
59
59
|
created_at: f,
|
|
60
60
|
isLoading: !1,
|
|
61
61
|
isCompleted: r
|
|
62
62
|
});
|
|
63
63
|
let R;
|
|
64
|
-
|
|
65
|
-
encodedSession:
|
|
66
|
-
}),
|
|
67
|
-
contextSession:
|
|
68
|
-
}), C(
|
|
69
|
-
}, [C, I]),
|
|
64
|
+
c && (R = {
|
|
65
|
+
encodedSession: c
|
|
66
|
+
}), E && (R = {
|
|
67
|
+
contextSession: E
|
|
68
|
+
}), C(b, R);
|
|
69
|
+
}, [C, I]), O = t.useCallback(
|
|
70
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
71
|
(s, e) => {
|
|
72
|
-
var
|
|
73
|
-
const r = (s == null ? void 0 : s.message) || "",
|
|
72
|
+
var c, E;
|
|
73
|
+
const r = (s == null ? void 0 : s.message) || "", i = ((c = s == null ? void 0 : s.response) == null ? void 0 : c.status) === 429 || ns.test(r), u = ((E = s == null ? void 0 : s.response) == null ? void 0 : E.status) === 204, a = u ? L.NO_CONTENT : i ? L.RATE_LIMITING : L.GENERAL, f = e.merge({
|
|
74
74
|
error: a,
|
|
75
75
|
isLoading: !1,
|
|
76
76
|
isCompleted: !0
|
|
@@ -78,46 +78,46 @@ function ms({
|
|
|
78
78
|
C(f, void 0);
|
|
79
79
|
},
|
|
80
80
|
[C]
|
|
81
|
-
),
|
|
81
|
+
), N = t.useCallback(async (s, e) => {
|
|
82
82
|
try {
|
|
83
83
|
const r = {
|
|
84
84
|
prompt: s.prompt,
|
|
85
85
|
aiAgent: e || void 0
|
|
86
|
-
},
|
|
87
|
-
let
|
|
88
|
-
_ && (
|
|
89
|
-
const a = await as(r, _,
|
|
90
|
-
_ ? a.ok && a.status === 200 ?
|
|
86
|
+
}, i = `content-answers-${s.id}`;
|
|
87
|
+
let u;
|
|
88
|
+
_ && (u = Q.createAbortRequest(i));
|
|
89
|
+
const a = await as(r, _, i, l, n, G, p, u, T);
|
|
90
|
+
_ ? a.ok && a.status === 200 ? Q.receiveStreamedResponse(i, a, (f) => {
|
|
91
91
|
const {
|
|
92
|
-
data:
|
|
93
|
-
error:
|
|
94
|
-
citations:
|
|
92
|
+
data: c,
|
|
93
|
+
error: E,
|
|
94
|
+
citations: b,
|
|
95
95
|
contextSession: R,
|
|
96
96
|
isCompleted: J
|
|
97
97
|
} = f;
|
|
98
|
-
|
|
98
|
+
S({
|
|
99
99
|
...{
|
|
100
|
-
answer:
|
|
101
|
-
citations:
|
|
102
|
-
error:
|
|
100
|
+
answer: c,
|
|
101
|
+
citations: b,
|
|
102
|
+
error: E,
|
|
103
103
|
contextSession: R
|
|
104
104
|
}
|
|
105
105
|
}, s, J);
|
|
106
|
-
}, void 0,
|
|
106
|
+
}, void 0, T) : O({
|
|
107
107
|
response: a
|
|
108
|
-
}, s) : (Object.entries(a).forEach(([f,
|
|
109
|
-
const
|
|
110
|
-
delete a[f], a[
|
|
111
|
-
}),
|
|
108
|
+
}, s) : (Object.entries(a).forEach(([f, c]) => {
|
|
109
|
+
const E = K(f);
|
|
110
|
+
delete a[f], a[E] = c;
|
|
111
|
+
}), S(a, s, !0));
|
|
112
112
|
} catch (r) {
|
|
113
|
-
|
|
113
|
+
O(r, s);
|
|
114
114
|
}
|
|
115
|
-
}, [_,
|
|
116
|
-
const
|
|
117
|
-
r && (s.id = `${
|
|
118
|
-
const
|
|
119
|
-
return C(
|
|
120
|
-
}, [n == null ? void 0 : n.questions,
|
|
115
|
+
}, [_, l, n, G, p, T, S, O]), d = t.useCallback((s, e, r = !0) => {
|
|
116
|
+
const i = (n == null ? void 0 : n.questions) || [];
|
|
117
|
+
r && (s.id = `${i.length}`);
|
|
118
|
+
const u = new es(s);
|
|
119
|
+
return C(u), N(u, e), u;
|
|
120
|
+
}, [n == null ? void 0 : n.questions, N, C]), v = t.useCallback((s) => {
|
|
121
121
|
const {
|
|
122
122
|
encoded_session: e,
|
|
123
123
|
metadata: {
|
|
@@ -127,7 +127,7 @@ function ms({
|
|
|
127
127
|
}
|
|
128
128
|
} = s;
|
|
129
129
|
o({
|
|
130
|
-
type:
|
|
130
|
+
type: h,
|
|
131
131
|
encodedSession: e,
|
|
132
132
|
isLargeFile: r
|
|
133
133
|
});
|
|
@@ -137,31 +137,31 @@ function ms({
|
|
|
137
137
|
type: w,
|
|
138
138
|
isLoading: !0
|
|
139
139
|
});
|
|
140
|
-
const s = await
|
|
140
|
+
const s = await k({
|
|
141
141
|
items: [n.item]
|
|
142
|
-
},
|
|
142
|
+
}, l);
|
|
143
143
|
v(s);
|
|
144
144
|
} catch {
|
|
145
|
-
M(
|
|
145
|
+
M(z.GENERAL);
|
|
146
146
|
}
|
|
147
|
-
}, [o,
|
|
147
|
+
}, [o, k, n.item, l, v, M]), x = t.useCallback(() => {
|
|
148
148
|
o({
|
|
149
149
|
type: U
|
|
150
150
|
});
|
|
151
151
|
}, [o]), $ = t.useCallback(async (s, e) => {
|
|
152
|
-
|
|
152
|
+
d({
|
|
153
153
|
...s.toJS(),
|
|
154
154
|
answer: "",
|
|
155
155
|
isLoading: !0,
|
|
156
156
|
isCompleted: !1,
|
|
157
157
|
error: null
|
|
158
158
|
}, e, !1);
|
|
159
|
-
}, [
|
|
160
|
-
|
|
159
|
+
}, [d]), V = t.useCallback((s) => {
|
|
160
|
+
Q.abortRequest(`content-answers-${s.id}`, !0);
|
|
161
161
|
}, []), W = t.useCallback(async (s) => {
|
|
162
|
-
if (
|
|
162
|
+
if (m)
|
|
163
163
|
try {
|
|
164
|
-
const e = await
|
|
164
|
+
const e = await m(s);
|
|
165
165
|
A({
|
|
166
166
|
type: "OVERRIDE_AGENT_CONFIG",
|
|
167
167
|
agentName: s.name,
|
|
@@ -169,14 +169,14 @@ function ms({
|
|
|
169
169
|
});
|
|
170
170
|
} catch {
|
|
171
171
|
}
|
|
172
|
-
}, [A,
|
|
173
|
-
if (
|
|
172
|
+
}, [A, m]), H = t.useCallback(async () => {
|
|
173
|
+
if (y) {
|
|
174
174
|
o({
|
|
175
175
|
type: F,
|
|
176
176
|
requestState: q.IN_PROGRESS
|
|
177
177
|
});
|
|
178
178
|
try {
|
|
179
|
-
const s = os(await
|
|
179
|
+
const s = os(await y(l));
|
|
180
180
|
o({
|
|
181
181
|
type: ss,
|
|
182
182
|
suggestedQuestions: s
|
|
@@ -188,15 +188,15 @@ function ms({
|
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
|
-
}, [o,
|
|
191
|
+
}, [o, y, l]);
|
|
192
192
|
return {
|
|
193
193
|
clearConversation: x,
|
|
194
194
|
createSession: j,
|
|
195
195
|
fetchAgentConfig: W,
|
|
196
196
|
fetchSuggestedQuestions: H,
|
|
197
197
|
retryQuestion: $,
|
|
198
|
-
sendQuestion:
|
|
199
|
-
sendQuestionAnswerRequest:
|
|
198
|
+
sendQuestion: d,
|
|
199
|
+
sendQuestionAnswerRequest: N,
|
|
200
200
|
stopQuestion: V,
|
|
201
201
|
updateQuestionInState: C
|
|
202
202
|
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import b, { FETCH_TIMEOUT as m } from "./stream.js";
|
|
2
|
+
const p = (i, s) => setTimeout(() => {
|
|
3
|
+
b.abortRequest(i);
|
|
4
|
+
}, s), E = async (i, s = !1, l, a, o, r, e, u, t) => {
|
|
5
|
+
let n;
|
|
6
|
+
const T = (t == null ? void 0 : t.initial) || m.initial, w = p(l, T);
|
|
7
|
+
return s && e ? n = await e(i, a, u, o) : r && (n = await r(i, a, o)), clearTimeout(w), n;
|
|
4
8
|
};
|
|
5
9
|
export {
|
|
6
|
-
|
|
10
|
+
E as getAnswerRequest
|
|
7
11
|
};
|
|
@@ -1,58 +1,62 @@
|
|
|
1
1
|
import b from "lodash/camelCase";
|
|
2
2
|
import { A as s } from "../../../../../chunks/types.js";
|
|
3
|
-
const
|
|
3
|
+
const C = {
|
|
4
|
+
chunk: 15 * 1e3,
|
|
5
|
+
// fetch timeout for each chunk. We need to abort the fetch if needed.
|
|
6
|
+
initial: 45 * 1e3
|
|
7
|
+
// latency p99 (30s) + buffer. Other host integrations can override this value.
|
|
8
|
+
}, u = {
|
|
4
9
|
RESPONSE_FAILED: s.RESPONSE_FAILED,
|
|
5
10
|
RESPONSE_INTERRUPTED: s.RESPONSE_INTERRUPTED,
|
|
6
11
|
RESPONSE_STOPPED: s.RESPONSE_STOPPED
|
|
7
|
-
},
|
|
12
|
+
}, d = {
|
|
8
13
|
CONTINUE: "continue",
|
|
9
14
|
DONE: "done",
|
|
10
15
|
ERROR: "error"
|
|
11
16
|
};
|
|
12
17
|
class T {
|
|
13
18
|
constructor() {
|
|
14
|
-
this.abortControllerMap = /* @__PURE__ */ new Map(), this.
|
|
19
|
+
this.abortControllerMap = /* @__PURE__ */ new Map(), this.chunkTimeout = C.chunk;
|
|
15
20
|
}
|
|
16
|
-
abortRequest(
|
|
17
|
-
const
|
|
18
|
-
|
|
21
|
+
abortRequest(o, i = !1) {
|
|
22
|
+
const r = this.abortControllerMap.get(o);
|
|
23
|
+
r && (r.isAbortFunctionCalled = !0, r.isUserInitiatedAbort = i, this.abortControllerMap.set(o, r), r.abortController.abort());
|
|
19
24
|
}
|
|
20
|
-
createAbortRequest(
|
|
21
|
-
const
|
|
25
|
+
createAbortRequest(o) {
|
|
26
|
+
const i = {
|
|
22
27
|
abortController: new AbortController(),
|
|
23
28
|
isAbortFunctionCalled: !1,
|
|
24
29
|
isUserInitiatedAbort: !1
|
|
25
30
|
};
|
|
26
|
-
return this.abortControllerMap.set(
|
|
31
|
+
return this.abortControllerMap.set(o, i), i.abortController;
|
|
27
32
|
}
|
|
28
33
|
// eslint-disable-next-line class-methods-use-this
|
|
29
|
-
parseNDJSON(
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
`) ||
|
|
34
|
+
parseNDJSON(o, i, r) {
|
|
35
|
+
const n = new TextDecoder().decode(i), t = o.partialData + n, l = /\r?\n/, e = t.trim().split(l);
|
|
36
|
+
o.partialData = t.endsWith(`
|
|
37
|
+
`) || t.endsWith("}") ? "" : e.pop() || "";
|
|
33
38
|
let a = "";
|
|
34
|
-
|
|
39
|
+
e.forEach((h) => {
|
|
35
40
|
const E = JSON.parse(h);
|
|
36
|
-
E[
|
|
37
|
-
const
|
|
38
|
-
|
|
41
|
+
E[r] && (a += E[r]), Object.entries(E).forEach(([c, O]) => {
|
|
42
|
+
const N = b(c);
|
|
43
|
+
N !== r && (o[N] = O);
|
|
39
44
|
});
|
|
40
|
-
}),
|
|
45
|
+
}), o.data += a;
|
|
41
46
|
}
|
|
42
|
-
receiveStreamedResponse(
|
|
47
|
+
receiveStreamedResponse(o, i, r, n = "answer", t) {
|
|
43
48
|
var E;
|
|
44
|
-
const l = this.initializeStreamedResponseState(),
|
|
45
|
-
if (this.
|
|
46
|
-
this.handleNoResponseBody(
|
|
49
|
+
const l = this.initializeStreamedResponseState(), e = (E = i.body) == null ? void 0 : E.getReader();
|
|
50
|
+
if (this.chunkTimeout = (t == null ? void 0 : t.chunk) || C.chunk, !e) {
|
|
51
|
+
this.handleNoResponseBody(r, l);
|
|
47
52
|
return;
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.handleChunkSuccess(a, o, c, t, l, i), c.done || (a.id = this.setChunkTimeout(t), h());
|
|
54
|
+
let a;
|
|
55
|
+
const h = () => {
|
|
56
|
+
e.read().then((c) => {
|
|
57
|
+
this.handleChunkSuccess(a, r, c, o, l, n), c.done || (a = this.setChunkTimeout(o), h());
|
|
54
58
|
}).catch((c) => {
|
|
55
|
-
this.handleChunkError(a,
|
|
59
|
+
this.handleChunkError(a, r, o, l);
|
|
56
60
|
});
|
|
57
61
|
};
|
|
58
62
|
h();
|
|
@@ -69,37 +73,37 @@ class T {
|
|
|
69
73
|
partialData: ""
|
|
70
74
|
};
|
|
71
75
|
}
|
|
72
|
-
handleChunkSuccess(
|
|
73
|
-
if (!
|
|
76
|
+
handleChunkSuccess(o, i, r, n, t, l) {
|
|
77
|
+
if (!r)
|
|
74
78
|
return;
|
|
75
|
-
clearTimeout(
|
|
79
|
+
clearTimeout(o);
|
|
76
80
|
const {
|
|
77
|
-
completionReason:
|
|
78
|
-
} =
|
|
79
|
-
|
|
81
|
+
completionReason: e
|
|
82
|
+
} = t;
|
|
83
|
+
t.isCompleted = r.done || e !== null, r.value && this.parseNDJSON(t, r.value, l), t.isCompleted && (this.removeAbortController(n), e !== d.DONE && (t.data ? t.error = e === d.CONTINUE ? u.RESPONSE_INTERRUPTED : u.RESPONSE_FAILED : t.error = s.NO_CONTENT)), i(t);
|
|
80
84
|
}
|
|
81
|
-
handleChunkError(
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
+
handleChunkError(o, i, r, n) {
|
|
86
|
+
n.error = u.RESPONSE_FAILED;
|
|
87
|
+
const t = this.abortControllerMap.get(r);
|
|
88
|
+
t && t.isUserInitiatedAbort && (n.error = u.RESPONSE_STOPPED, n.isAborted = t.isUserInitiatedAbort), n.isCompleted = !0, this.removeAbortController(r), clearTimeout(o), i(n);
|
|
85
89
|
}
|
|
86
90
|
// eslint-disable-next-line class-methods-use-this
|
|
87
|
-
handleNoResponseBody(
|
|
88
|
-
|
|
91
|
+
handleNoResponseBody(o, i) {
|
|
92
|
+
i.error = s.NO_CONTENT, i.isCompleted = !0, o(i);
|
|
89
93
|
}
|
|
90
|
-
removeAbortController(
|
|
91
|
-
this.abortControllerMap.delete(
|
|
94
|
+
removeAbortController(o) {
|
|
95
|
+
this.abortControllerMap.delete(o);
|
|
92
96
|
}
|
|
93
|
-
setChunkTimeout(
|
|
97
|
+
setChunkTimeout(o) {
|
|
94
98
|
return setTimeout(() => {
|
|
95
|
-
this.abortRequest(
|
|
96
|
-
}, this.
|
|
99
|
+
this.abortRequest(o);
|
|
100
|
+
}, this.chunkTimeout);
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
|
-
const
|
|
103
|
+
const P = new T();
|
|
100
104
|
export {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
C as FETCH_TIMEOUT,
|
|
106
|
+
d as STREAMING_COMPLETION_REASON,
|
|
107
|
+
u as STREAM_ERROR,
|
|
108
|
+
P as default
|
|
105
109
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/box-ai-content-answers",
|
|
3
|
-
"version": "0.54.
|
|
3
|
+
"version": "0.54.5",
|
|
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.31.
|
|
16
|
+
"@box/blueprint-web": "^7.31.1",
|
|
17
17
|
"@box/blueprint-web-assets": "^4.26.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": "d76dca7d74745cd366345066918901888e7d76d2"
|
|
56
56
|
}
|
|
@@ -36,9 +36,6 @@ export type StreamResponseProps = {
|
|
|
36
36
|
isCompleted: boolean;
|
|
37
37
|
partialData: string;
|
|
38
38
|
};
|
|
39
|
-
export type ChunkTimeout = {
|
|
40
|
-
id?: ReturnType<typeof setTimeout>;
|
|
41
|
-
};
|
|
42
39
|
export type PremissionsResponse = {
|
|
43
40
|
is_valid_user: boolean;
|
|
44
41
|
};
|
|
@@ -54,7 +51,7 @@ export type fetchError = {
|
|
|
54
51
|
};
|
|
55
52
|
export type ApiWrapperProps = {
|
|
56
53
|
createSessionRequest?: (payload: Record<string, unknown>, itemID: string) => Promise<CreateSessionResponse>;
|
|
57
|
-
fetchTimeout?:
|
|
54
|
+
fetchTimeout?: StreamResponseTimeout;
|
|
58
55
|
formatCitations?: (citations: Array<CitationResponse>) => Array<CitationType>;
|
|
59
56
|
getAgentConfig?: agentFetcherType;
|
|
60
57
|
getAnswer?: fetcherType;
|
|
@@ -95,3 +92,7 @@ export type ApiWrapperWithInjectedProps = ApiWrapperProps & {
|
|
|
95
92
|
shouldRenderProviders: boolean;
|
|
96
93
|
stopQuestion: StopQuestion;
|
|
97
94
|
};
|
|
95
|
+
export type StreamResponseTimeout = {
|
|
96
|
+
chunk: number;
|
|
97
|
+
initial: number;
|
|
98
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ContentAnswersRecordType } from '../records';
|
|
2
|
-
import { type fetcherStreamingType, type fetcherType } from '../types';
|
|
3
|
-
declare const getAnswerRequest: (payload: Record<string, unknown>, isStreamingRequest
|
|
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>;
|
|
4
4
|
export { getAnswerRequest };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ANSWER_ERROR } from '../../../types';
|
|
2
|
-
import { type
|
|
3
|
-
export declare const
|
|
2
|
+
import { type ExtendedReadableStreamReadResult, type ReadableStreamResponse, type StreamAbort, type StreamResponseProps, type StreamResponseTimeout } from '../types';
|
|
3
|
+
export declare const FETCH_TIMEOUT: StreamResponseTimeout;
|
|
4
4
|
export declare const STREAM_ERROR: {
|
|
5
5
|
RESPONSE_FAILED: ANSWER_ERROR;
|
|
6
6
|
RESPONSE_INTERRUPTED: ANSWER_ERROR;
|
|
@@ -13,14 +13,14 @@ export declare const STREAMING_COMPLETION_REASON: {
|
|
|
13
13
|
};
|
|
14
14
|
declare class StreamUtils {
|
|
15
15
|
abortControllerMap: Map<string, StreamAbort>;
|
|
16
|
-
|
|
16
|
+
chunkTimeout: number;
|
|
17
17
|
abortRequest(requestID: string, userAborted?: boolean): void;
|
|
18
18
|
createAbortRequest(requestID: string): AbortController;
|
|
19
19
|
parseNDJSON(responseState: StreamResponseProps, rawChunk: Uint8Array, streamingProperty: any): void;
|
|
20
|
-
receiveStreamedResponse(requestID: string, response: ReadableStreamResponse, onStreamResponse: (responseState: StreamResponseProps) => void, streamingProperty?: string, fetchTimeout?:
|
|
20
|
+
receiveStreamedResponse(requestID: string, response: ReadableStreamResponse, onStreamResponse: (responseState: StreamResponseProps) => void, streamingProperty?: string, fetchTimeout?: StreamResponseTimeout): void;
|
|
21
21
|
initializeStreamedResponseState(): StreamResponseProps;
|
|
22
|
-
handleChunkSuccess(
|
|
23
|
-
handleChunkError(
|
|
22
|
+
handleChunkSuccess(chunkTimeoutId: number, onStreamResponse: (responseState: StreamResponseProps) => void, result: ExtendedReadableStreamReadResult, requestID: string, streamedResponseState: StreamResponseProps, streamingProperty: any): void;
|
|
23
|
+
handleChunkError(chunkTimeoutId: any, onStreamResponse: (responseState: StreamResponseProps) => void, requestID: string, streamedResponseState: StreamResponseProps): void;
|
|
24
24
|
handleNoResponseBody(onStreamResponse: (responseState: StreamResponseProps) => void, streamedResponseState: StreamResponseProps): void;
|
|
25
25
|
removeAbortController(requestID: string): void;
|
|
26
26
|
setChunkTimeout(requestID: string): ReturnType<typeof setTimeout>;
|