@box/box-ai-content-answers 1.16.1 → 1.16.3
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,92 @@
|
|
|
1
1
|
import b from "lodash/camelCase";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as E } from "../../../../../chunks/types.js";
|
|
3
3
|
const d = {
|
|
4
4
|
chunk: 15 * 1e3,
|
|
5
5
|
// fetch timeout for each chunk. We need to abort the fetch if needed.
|
|
6
6
|
initial: 45 * 1e3
|
|
7
7
|
// latency p99 (30s) + buffer. Other host integrations can override this value.
|
|
8
8
|
}, N = {
|
|
9
|
-
RESPONSE_FAILED:
|
|
10
|
-
RESPONSE_INTERRUPTED:
|
|
11
|
-
RESPONSE_STOPPED:
|
|
9
|
+
RESPONSE_FAILED: E.RESPONSE_FAILED,
|
|
10
|
+
RESPONSE_INTERRUPTED: E.RESPONSE_INTERRUPTED,
|
|
11
|
+
RESPONSE_STOPPED: E.RESPONSE_STOPPED
|
|
12
12
|
}, O = {
|
|
13
13
|
CONTINUE: "continue",
|
|
14
14
|
DONE: "done",
|
|
15
15
|
ERROR: "error"
|
|
16
16
|
};
|
|
17
|
-
class
|
|
17
|
+
class f {
|
|
18
18
|
constructor() {
|
|
19
19
|
this.abortControllerMap = /* @__PURE__ */ new Map(), this.chunkTimeout = d.chunk;
|
|
20
20
|
}
|
|
21
|
-
abortRequest(r,
|
|
21
|
+
abortRequest(r, e = !1) {
|
|
22
22
|
const t = this.abortControllerMap.get(r);
|
|
23
|
-
t && (t.isAbortFunctionCalled = !0, t.isUserInitiatedAbort =
|
|
23
|
+
t && (t.isAbortFunctionCalled = !0, t.isUserInitiatedAbort = e, this.abortControllerMap.set(r, t), t.abortController.abort());
|
|
24
24
|
}
|
|
25
25
|
createAbortRequest(r) {
|
|
26
|
-
const
|
|
26
|
+
const e = {
|
|
27
27
|
abortController: new AbortController(),
|
|
28
28
|
isAbortFunctionCalled: !1,
|
|
29
29
|
isUserInitiatedAbort: !1
|
|
30
30
|
};
|
|
31
|
-
return this.abortControllerMap.set(r,
|
|
31
|
+
return this.abortControllerMap.set(r, e), e.abortController;
|
|
32
32
|
}
|
|
33
33
|
// eslint-disable-next-line class-methods-use-this
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
34
|
+
handleCompleteLine(r, e) {
|
|
35
|
+
const t = r.trim();
|
|
36
|
+
t && e.push(t);
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39
|
+
tryParsePartialLine(r, e, t) {
|
|
40
|
+
if (e || !r.trim().endsWith("}"))
|
|
41
|
+
return r;
|
|
42
|
+
const o = r.trim();
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(o), t.push(o), "";
|
|
45
|
+
} catch {
|
|
46
|
+
return r;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line class-methods-use-this
|
|
50
|
+
parseChunk(r, e) {
|
|
51
|
+
let t = "", o = !1, i = !1;
|
|
52
|
+
for (const n of r)
|
|
53
|
+
i ? (t += n, i = !1) : n === "\\" ? (t += n, i = !0) : n === '"' ? (t += n, o = !o) : (n === `
|
|
54
|
+
` || n === "\r") && !o ? (this.handleCompleteLine(t, e), t = "") : t += n;
|
|
55
|
+
return this.tryParsePartialLine(t, o, e);
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line class-methods-use-this
|
|
58
|
+
parseNDJSON(r, e, t) {
|
|
59
|
+
const o = new TextDecoder().decode(e), i = r.partialData + o, n = [], l = this.parseChunk(i, n);
|
|
60
|
+
r.partialData = l;
|
|
61
|
+
let s = "";
|
|
62
|
+
n.forEach((h) => {
|
|
63
|
+
try {
|
|
64
|
+
const a = JSON.parse(h);
|
|
65
|
+
a[t] && (s += a[t]), a.thinking_answer && (r.thinkingAnswer || (r.thinkingAnswer = ""), r.thinkingAnswer += a.thinking_answer), Object.entries(a).forEach(([u, c]) => {
|
|
66
|
+
const C = b(u);
|
|
67
|
+
C !== t && C !== "thinkingAnswer" && (r[C] = c);
|
|
68
|
+
});
|
|
69
|
+
} catch (a) {
|
|
70
|
+
console.error("Failed to parse NDJSON line:", a);
|
|
71
|
+
}
|
|
72
|
+
}), r.data += s;
|
|
46
73
|
}
|
|
47
|
-
receiveStreamedResponse(r,
|
|
74
|
+
receiveStreamedResponse(r, e, t, o = "answer", i, n) {
|
|
48
75
|
var u;
|
|
49
|
-
const
|
|
50
|
-
if (this.chunkTimeout = (
|
|
51
|
-
this.handleNoResponseBody(t,
|
|
76
|
+
const l = this.initializeStreamedResponseState(), s = (u = e.body) == null ? void 0 : u.getReader();
|
|
77
|
+
if (this.chunkTimeout = (i == null ? void 0 : i.chunk) || d.chunk, !s) {
|
|
78
|
+
this.handleNoResponseBody(t, l);
|
|
52
79
|
return;
|
|
53
80
|
}
|
|
54
81
|
let h;
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
this.handleChunkSuccess(h, t, c, r,
|
|
82
|
+
const a = () => {
|
|
83
|
+
s.read().then((c) => {
|
|
84
|
+
this.handleChunkSuccess(h, t, c, r, l, o), c.done || (h = this.setChunkTimeout(r, n), a());
|
|
58
85
|
}).catch((c) => {
|
|
59
|
-
this.handleChunkError(h, t, r,
|
|
86
|
+
this.handleChunkError(h, t, r, l);
|
|
60
87
|
});
|
|
61
88
|
};
|
|
62
|
-
|
|
89
|
+
a();
|
|
63
90
|
}
|
|
64
91
|
// eslint-disable-next-line class-methods-use-this
|
|
65
92
|
initializeStreamedResponseState() {
|
|
@@ -73,30 +100,30 @@ class T {
|
|
|
73
100
|
partialData: ""
|
|
74
101
|
};
|
|
75
102
|
}
|
|
76
|
-
handleChunkSuccess(r,
|
|
103
|
+
handleChunkSuccess(r, e, t, o, i, n) {
|
|
77
104
|
if (!t)
|
|
78
105
|
return;
|
|
79
106
|
clearTimeout(r);
|
|
80
107
|
const {
|
|
81
|
-
completionReason:
|
|
82
|
-
} =
|
|
83
|
-
|
|
108
|
+
completionReason: l
|
|
109
|
+
} = i;
|
|
110
|
+
i.isCompleted = t.done || l !== null, t.value && this.parseNDJSON(i, t.value, n), i.isCompleted && (this.removeAbortController(o), l !== O.DONE && (i.data ? i.error = l === O.CONTINUE ? N.RESPONSE_INTERRUPTED : N.RESPONSE_FAILED : i.error = E.NO_CONTENT)), e(i);
|
|
84
111
|
}
|
|
85
|
-
handleChunkError(r,
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
112
|
+
handleChunkError(r, e, t, o) {
|
|
113
|
+
o.error = N.RESPONSE_FAILED;
|
|
114
|
+
const i = this.abortControllerMap.get(t);
|
|
115
|
+
i && i.isUserInitiatedAbort && (o.error = N.RESPONSE_STOPPED, o.isAborted = i.isUserInitiatedAbort), o.isCompleted = !0, this.removeAbortController(t), clearTimeout(r), e(o);
|
|
89
116
|
}
|
|
90
117
|
// eslint-disable-next-line class-methods-use-this
|
|
91
|
-
handleNoResponseBody(r,
|
|
92
|
-
|
|
118
|
+
handleNoResponseBody(r, e) {
|
|
119
|
+
e.error = E.NO_CONTENT, e.isCompleted = !0, r(e);
|
|
93
120
|
}
|
|
94
121
|
removeAbortController(r) {
|
|
95
122
|
this.abortControllerMap.delete(r);
|
|
96
123
|
}
|
|
97
|
-
setChunkTimeout(r,
|
|
124
|
+
setChunkTimeout(r, e) {
|
|
98
125
|
return setTimeout(() => {
|
|
99
|
-
this.abortRequest(r),
|
|
126
|
+
this.abortRequest(r), e && e({
|
|
100
127
|
eventType: "ai-client-chunk-streaming-timeout-error",
|
|
101
128
|
message: "Chunk streaming timeout error",
|
|
102
129
|
origin: "AIClientErrorLog"
|
|
@@ -104,10 +131,10 @@ class T {
|
|
|
104
131
|
}, this.chunkTimeout);
|
|
105
132
|
}
|
|
106
133
|
}
|
|
107
|
-
const
|
|
134
|
+
const R = new f();
|
|
108
135
|
export {
|
|
109
136
|
d as FETCH_TIMEOUT,
|
|
110
137
|
O as STREAMING_COMPLETION_REASON,
|
|
111
138
|
N as STREAM_ERROR,
|
|
112
|
-
|
|
139
|
+
R as default
|
|
113
140
|
};
|
|
@@ -16,7 +16,10 @@ declare class StreamUtils {
|
|
|
16
16
|
chunkTimeout: number;
|
|
17
17
|
abortRequest(requestID: string, userAborted?: boolean): void;
|
|
18
18
|
createAbortRequest(requestID: string): AbortController;
|
|
19
|
-
|
|
19
|
+
private handleCompleteLine;
|
|
20
|
+
private tryParsePartialLine;
|
|
21
|
+
parseChunk(rawNDJSON: string, lines: string[]): string;
|
|
22
|
+
parseNDJSON(responseState: StreamResponseProps, rawChunk: Uint8Array, streamingProperty: string): void;
|
|
20
23
|
receiveStreamedResponse(requestID: string, response: ReadableStreamResponse, onStreamResponse: (responseState: StreamResponseProps) => void, streamingProperty?: string, fetchTimeout?: StreamResponseTimeout, sendErrorLog?: SendErrorLog): void;
|
|
21
24
|
initializeStreamedResponseState(): StreamResponseProps;
|
|
22
25
|
handleChunkSuccess(chunkTimeoutId: number, onStreamResponse: (responseState: StreamResponseProps) => void, result: ExtendedReadableStreamReadResult, requestID: string, streamedResponseState: StreamResponseProps, streamingProperty: any): void;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/box-ai-content-answers",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@box/blueprint-web": "^7.8.0",
|
|
6
|
-
"@box/blueprint-web-assets": "^4.
|
|
6
|
+
"@box/blueprint-web-assets": "^4.80.0",
|
|
7
7
|
"@box/box-ai-agent-selector": "^0.51.1",
|
|
8
8
|
"@box/item-icon": "^0.9.44",
|
|
9
9
|
"formik": "^2.0.3",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@box/babel-plugin-target-attributes": "1.4.0",
|
|
20
|
-
"@box/blueprint-web": "^12.
|
|
21
|
-
"@box/blueprint-web-assets": "^4.
|
|
22
|
-
"@box/box-ai-agent-selector": "^1.12.
|
|
23
|
-
"@box/item-icon": "^2.2.
|
|
24
|
-
"@box/storybook-utils": "^0.14.
|
|
20
|
+
"@box/blueprint-web": "^12.99.0",
|
|
21
|
+
"@box/blueprint-web-assets": "^4.82.0",
|
|
22
|
+
"@box/box-ai-agent-selector": "^1.12.3",
|
|
23
|
+
"@box/item-icon": "^2.2.3",
|
|
24
|
+
"@box/storybook-utils": "^0.14.19",
|
|
25
25
|
"@testing-library/react": "^15.0.6",
|
|
26
26
|
"react": "^18.3.0",
|
|
27
27
|
"react-dom": "^18.3.0",
|