@epam/ai-dial-chat-hooks 1.2.0-dev.14 → 1.2.0-dev.142
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/api-error/api-error.js +5 -4
- package/attachment/useAttachmentValidation/useAttachmentValidation.js +26 -19
- package/attachments.d.ts +10 -4
- package/catalog/map-deployment-to-catalog-item.js +2 -2
- package/catalog/map-skill-to-catalog-item.js +30 -27
- package/catalog/publish.js +2 -1
- package/catalog/useApplicationCredentials/useApplicationCredentials.js +39 -0
- package/catalog/useSkillDetailsPanelData/useSkillDetailsPanelData.js +39 -39
- package/catalog/useSkillItemDetails.js +17 -13
- package/catalog.d.ts +42 -5
- package/catalog.js +6 -5
- package/conversation/conversation-transfer/queue.js +8 -5
- package/conversation/create-chat-stream-api.js +30 -21
- package/conversation/stage.js +23 -0
- package/conversation/useAttachmentUpload/useAttachmentUpload.js +12 -5
- package/conversation/useConversationImport/useConversationImport.js +1 -1
- package/conversation/useConversationScroll/useConversationScroll.js +68 -64
- package/conversation/useConversationStream/apply-chunk.js +1 -1
- package/conversation/useConversationStream/generation-resume.js +75 -63
- package/conversation/useConversationStream/useConversationStream.js +145 -102
- package/conversation-overlay.d.ts +7 -0
- package/conversation-overlay.js +2 -0
- package/conversation-sources/useConversationSources/useConversationSources.js +31 -24
- package/conversation-sources.d.ts +1 -1
- package/conversation.d.ts +140 -8
- package/conversation.js +31 -30
- package/file-manager-canvas.d.ts +398 -0
- package/file-manager-canvas.js +2 -0
- package/file-manager.d.ts +71 -330
- package/file-manager.js +15 -15
- package/files/attachment-canvas.js +51 -13
- package/files/attachment-types.js +14 -13
- package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.js +1 -5
- package/files/useFileAttachmentPicker/useFileAttachmentPicker.js +43 -0
- package/index.d.ts +750 -35
- package/index.js +123 -111
- package/mcp-apps/useMcpAppHostAdapter/useMcpAppHostAdapter.js +7 -5
- package/mcp-apps/useMcpAppHostContext/useMcpAppHostContext.js +1 -1
- package/mcp-apps/useMcpAppTools/useMcpAppTools.js +1 -1
- package/mcp-apps/useOpenMcpAppCanvas/useOpenMcpAppCanvas.js +25 -23
- package/mcp-apps.d.ts +8 -6
- package/package.json +37 -18
- package/scheduled-task/scheduled-task-description.js +77 -0
- package/scheduled-task/scheduled-task-preparation.js +24 -0
- package/scheduled-task/scheduled-task-trigger.js +7 -2
- package/scheduled-task/scheduled-tasks-api-client.js +19 -0
- package/scheduled-task/use-scheduled-task-runs.js +82 -0
- package/scheduled-task/use-scheduled-tasks.js +93 -0
- package/scheduled-tasks.d.ts +180 -3
- package/scheduled-tasks.js +7 -2
- package/skill/skill.js +10 -7
- package/skill/useSkillArchiveImport/useSkillArchiveImport.js +75 -0
- package/skill/useSkillEditorLoad.js +29 -28
- package/skill/useSkillEditorSubmit.js +92 -75
- package/skill-editor.d.ts +107 -0
- package/skill-editor.js +9 -8
- package/usage/map-usage-data-to-dashboard.js +66 -0
- package/usage/map-user-usage-to-model-limits.js +160 -0
- package/usage.d.ts +120 -0
- package/usage.js +3 -0
- package/utils.d.ts +3 -1
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
//#region src/conversation/create-chat-stream-api.ts
|
|
2
|
-
var e = { "Content-Type": "application/json" }, t = 409, n = "
|
|
3
|
-
|
|
2
|
+
var e = { "Content-Type": "application/json" }, t = 409, n = "The response could not be saved. It is still shown here, but may be lost if you reload or leave this page. Copy it before continuing.", r = class extends Error {
|
|
3
|
+
static type = "conversation_save_failed";
|
|
4
|
+
constructor() {
|
|
5
|
+
super(n), this.name = "GenerationPersistenceError";
|
|
6
|
+
}
|
|
7
|
+
}, i = "A response is already being generated in this conversation. Wait for it to finish or stop it before sending another message.", a = class extends Error {
|
|
8
|
+
constructor(e = i) {
|
|
4
9
|
super(e), this.name = "GenerationConflictError";
|
|
5
10
|
}
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
}, o = class extends Error {
|
|
12
|
+
constructor(e) {
|
|
13
|
+
super(e), this.name = "StreamUpstreamError";
|
|
14
|
+
}
|
|
15
|
+
}, s = (e, t, n) => {
|
|
16
|
+
let i = e.trim();
|
|
17
|
+
if (!i || i.startsWith(":") || !i.startsWith("data: ")) return;
|
|
18
|
+
let a = i.slice(6);
|
|
19
|
+
if (a !== "[DONE]") try {
|
|
20
|
+
let e = JSON.parse(a);
|
|
12
21
|
if (e.error) {
|
|
13
|
-
n(
|
|
22
|
+
n(e.error.type === r.type ? new r() : new o(e.error.message));
|
|
14
23
|
return;
|
|
15
24
|
}
|
|
16
25
|
t(e);
|
|
17
26
|
} catch {}
|
|
18
|
-
},
|
|
19
|
-
let { completionsBasePath:
|
|
27
|
+
}, c = (n) => {
|
|
28
|
+
let { completionsBasePath: r } = n, i = (...e) => (n.fetchImpl ?? fetch)(...e);
|
|
20
29
|
return {
|
|
21
|
-
streamCompletion: (
|
|
30
|
+
streamCompletion: (o, c, l, u, d, f, p, m, h) => {
|
|
22
31
|
let { onChunk: g, onComplete: _, onError: v, signal: y } = u;
|
|
23
32
|
(async () => {
|
|
24
33
|
let u;
|
|
25
34
|
try {
|
|
26
35
|
let t = n.getTimezone?.();
|
|
27
|
-
u = await
|
|
36
|
+
u = await i(`${r}/completions`, {
|
|
28
37
|
method: "POST",
|
|
29
38
|
credentials: "include",
|
|
30
39
|
signal: y,
|
|
@@ -34,7 +43,7 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
34
43
|
...t ? { "X-Timezone": t } : {}
|
|
35
44
|
},
|
|
36
45
|
body: JSON.stringify({
|
|
37
|
-
path:
|
|
46
|
+
path: o,
|
|
38
47
|
message: c ?? "",
|
|
39
48
|
model: l,
|
|
40
49
|
custom_content: d || {},
|
|
@@ -52,7 +61,7 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
52
61
|
let b = u.headers.get("x-csrf-token");
|
|
53
62
|
if (b && n.setCsrfToken(b), !u.ok) {
|
|
54
63
|
if (u.status === t) {
|
|
55
|
-
v(new
|
|
64
|
+
v(new a());
|
|
56
65
|
return;
|
|
57
66
|
}
|
|
58
67
|
v(/* @__PURE__ */ Error(`Stream request failed with status ${u.status}`));
|
|
@@ -69,13 +78,13 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
69
78
|
for (;;) {
|
|
70
79
|
let { done: e, value: t } = await x.read();
|
|
71
80
|
if (e) {
|
|
72
|
-
C.trim() &&
|
|
81
|
+
C.trim() && s(C, g, T);
|
|
73
82
|
break;
|
|
74
83
|
}
|
|
75
84
|
C += S.decode(t, { stream: !0 });
|
|
76
85
|
let n = C.split("\n");
|
|
77
86
|
C = n.pop() ?? "";
|
|
78
|
-
for (let e of n)
|
|
87
|
+
for (let e of n) s(e, g, T);
|
|
79
88
|
}
|
|
80
89
|
w || _();
|
|
81
90
|
} catch (e) {
|
|
@@ -87,7 +96,7 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
87
96
|
})();
|
|
88
97
|
},
|
|
89
98
|
stopCompletion: async (t) => {
|
|
90
|
-
let
|
|
99
|
+
let a = await i(`${r}/completions/stop`, {
|
|
91
100
|
method: "POST",
|
|
92
101
|
credentials: "include",
|
|
93
102
|
headers: {
|
|
@@ -95,10 +104,10 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
95
104
|
...n.getCsrfToken() == null ? {} : { "X-CSRF-Token": n.getCsrfToken() }
|
|
96
105
|
},
|
|
97
106
|
body: JSON.stringify(t)
|
|
98
|
-
}),
|
|
99
|
-
if (
|
|
107
|
+
}), o = a.headers.get("x-csrf-token");
|
|
108
|
+
if (o && n.setCsrfToken(o), !a.ok) throw Error(`stopCompletion failed: ${a.status}`);
|
|
100
109
|
}
|
|
101
110
|
};
|
|
102
111
|
};
|
|
103
112
|
//#endregion
|
|
104
|
-
export {
|
|
113
|
+
export { i as DEFAULT_GENERATION_CONFLICT_MESSAGE, n as DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE, a as GenerationConflictError, r as GenerationPersistenceError, o as StreamUpstreamError, c as createChatStreamApi };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StageStatus as e } from "@epam/ai-dial-chat-shared";
|
|
2
|
+
//#region src/conversation/stage.ts
|
|
3
|
+
var t = (t) => t === e.Completed ? e.Completed : t === e.Failed ? e.Failed : null, n = (e) => ({
|
|
4
|
+
title: e.title ?? "",
|
|
5
|
+
...e.index != null && { index: e.index },
|
|
6
|
+
...e.type != null && { type: e.type },
|
|
7
|
+
...e.data != null && { data: e.data },
|
|
8
|
+
...e.url != null && { url: e.url },
|
|
9
|
+
...e.reference_type != null && { reference_type: e.reference_type },
|
|
10
|
+
...e.reference_url != null && { reference_url: e.reference_url }
|
|
11
|
+
}), r = (e) => ({
|
|
12
|
+
index: e.index ?? 0,
|
|
13
|
+
name: e.name ?? "",
|
|
14
|
+
status: t(e.status),
|
|
15
|
+
...e.content != null && { content: e.content },
|
|
16
|
+
...e.tag != null && { tag: e.tag },
|
|
17
|
+
...e.attachments?.length && { attachments: e.attachments.map(n) }
|
|
18
|
+
}), i = (e) => {
|
|
19
|
+
let t = Array.isArray(e) ? e : e?.custom_content?.stages ?? e?.customContent?.stages;
|
|
20
|
+
if (t?.length) return t.map(r);
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { i as mapStages, r as toStage };
|
|
@@ -26,9 +26,16 @@ var o = 700, s = 5, c = (e) => t(e.split("/").filter(Boolean).pop() ?? "file").r
|
|
|
26
26
|
})).url,
|
|
27
27
|
name: a.fileName
|
|
28
28
|
};
|
|
29
|
-
} catch (
|
|
30
|
-
if (l(
|
|
29
|
+
} catch (c) {
|
|
30
|
+
if (l(c)) {
|
|
31
31
|
if (i.markTaken(a.fileName), o < s) {
|
|
32
|
+
if (t.listFiles) try {
|
|
33
|
+
let e = await t.listFiles({
|
|
34
|
+
bucket: u,
|
|
35
|
+
path: a.path.slice(0, a.path.lastIndexOf("/"))
|
|
36
|
+
});
|
|
37
|
+
for (let t of e.items) i.markTaken(t.name);
|
|
38
|
+
} catch {}
|
|
32
39
|
a = i.allocate(n);
|
|
33
40
|
continue;
|
|
34
41
|
}
|
|
@@ -38,10 +45,10 @@ var o = 700, s = 5, c = (e) => t(e.split("/").filter(Boolean).pop() ?? "file").r
|
|
|
38
45
|
let e = p.current.splice(0);
|
|
39
46
|
d?.(e), m.current = null;
|
|
40
47
|
}, f);
|
|
41
|
-
let
|
|
42
|
-
throw
|
|
48
|
+
let t = c instanceof Error ? c : /* @__PURE__ */ Error("Network upload failed");
|
|
49
|
+
throw t.errorReason = r.Network, t;
|
|
43
50
|
}
|
|
44
|
-
throw
|
|
51
|
+
throw c;
|
|
45
52
|
}
|
|
46
53
|
}, [
|
|
47
54
|
u,
|
|
@@ -191,7 +191,7 @@ var b = 5, x = 5, S = (e) => /\.(dial|zip)$/i.test(e.name), C = (e) => new Promi
|
|
|
191
191
|
jobId: n,
|
|
192
192
|
code: t.AttachmentSkipped,
|
|
193
193
|
names: [...j]
|
|
194
|
-
}), A.length > 0 ? D.failJob(n, h.Unknown) : j.size > 0 ? D.warnJob(n, t.AttachmentSkipped) : D.succeedJob(n);
|
|
194
|
+
}), A.length > 0 ? D.failJob(n, h.Unknown) : j.size > 0 ? D.warnJob(n, t.AttachmentSkipped, [...j]) : D.succeedJob(n);
|
|
195
195
|
}
|
|
196
196
|
}, [
|
|
197
197
|
l,
|
|
@@ -1,121 +1,125 @@
|
|
|
1
1
|
import { useCallback as e, useEffect as t, useLayoutEffect as n, useRef as r, useState as i } from "react";
|
|
2
2
|
//#region src/conversation/useConversationScroll/useConversationScroll.ts
|
|
3
3
|
var a = 80, o = 1, s = ({ messages: s, isAssistantTyping: c, conversationId: l }) => {
|
|
4
|
-
let [u, d] = i(!1), f = r(null), p = r(null), m = r(null), h = r(!1), g = r(!1), _ = r(null), v = r(/* @__PURE__ */ new Map()),
|
|
5
|
-
t ?
|
|
6
|
-
}, []),
|
|
7
|
-
|
|
8
|
-
}, []),
|
|
4
|
+
let [u, d] = i(!1), f = r(null), p = r(null), m = r(null), h = r(!1), g = r(!1), _ = r(null), v = r(!0), y = r(/* @__PURE__ */ new Map()), b = e((e, t) => {
|
|
5
|
+
t ? y.current.set(e, t) : y.current.delete(e);
|
|
6
|
+
}, []), x = r(null), S = e((e) => {
|
|
7
|
+
x.current = e;
|
|
8
|
+
}, []), C = e((e, t) => {
|
|
9
9
|
let n = f.current;
|
|
10
10
|
n && n.scrollTo({
|
|
11
11
|
top: e,
|
|
12
12
|
behavior: t ? "instant" : "smooth"
|
|
13
13
|
});
|
|
14
|
-
}, []), C = e(() => {
|
|
15
|
-
m.current && (m.current.style.height = "0px"), h.current = !1, g.current = !1, _.current = null;
|
|
16
14
|
}, []), w = e(() => {
|
|
15
|
+
m.current && (m.current.style.height = "0px"), h.current = !1, g.current = !1, _.current = null;
|
|
16
|
+
}, []), T = e(() => {
|
|
17
17
|
let e = f.current, t = p.current;
|
|
18
18
|
if (!e || !t) return null;
|
|
19
19
|
let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
|
|
20
20
|
return e.scrollTop + (r.bottom - n.top) - e.clientHeight;
|
|
21
|
-
}, []),
|
|
22
|
-
let t =
|
|
23
|
-
t != null &&
|
|
24
|
-
}, [
|
|
21
|
+
}, []), E = e((e = !1) => {
|
|
22
|
+
let t = T();
|
|
23
|
+
t != null && C(Math.max(t, 0), e);
|
|
24
|
+
}, [C, T]), D = e(() => {
|
|
25
25
|
let e = f.current, t = p.current;
|
|
26
26
|
if (!e || !t) return null;
|
|
27
27
|
let n = e.getBoundingClientRect();
|
|
28
28
|
return t.getBoundingClientRect().bottom - n.top - e.clientHeight;
|
|
29
|
-
}, []),
|
|
29
|
+
}, []), O = e(() => {
|
|
30
30
|
if (!g.current) return;
|
|
31
|
-
let e =
|
|
32
|
-
e == null || e < -1 ||
|
|
33
|
-
}, [
|
|
34
|
-
let t = f.current, n =
|
|
31
|
+
let e = D();
|
|
32
|
+
e == null || e < -1 || w();
|
|
33
|
+
}, [w, D]), k = e((e) => {
|
|
34
|
+
let t = f.current, n = y.current.get(e);
|
|
35
35
|
if (!t || !n) return null;
|
|
36
36
|
let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), a = t.scrollTop + (i.top - r.top);
|
|
37
37
|
return Math.max(a, 0);
|
|
38
|
-
}, []),
|
|
39
|
-
let n =
|
|
40
|
-
n != null &&
|
|
41
|
-
}, [
|
|
42
|
-
let e =
|
|
38
|
+
}, []), A = e((e, t = !1) => {
|
|
39
|
+
let n = k(e);
|
|
40
|
+
n != null && C(n, t);
|
|
41
|
+
}, [k, C]), j = e(() => {
|
|
42
|
+
let e = T();
|
|
43
43
|
return e == null ? null : Math.max(e, 0);
|
|
44
|
-
}, [
|
|
44
|
+
}, [T]), M = e(() => {
|
|
45
45
|
if (!h.current) return null;
|
|
46
|
-
let e = _.current, t =
|
|
46
|
+
let e = _.current, t = j();
|
|
47
47
|
return e == null || t == null ? null : Math.max(e, t);
|
|
48
|
-
}, [
|
|
49
|
-
let e = f.current, t =
|
|
48
|
+
}, [j]), N = e(() => {
|
|
49
|
+
let e = f.current, t = M();
|
|
50
50
|
!e || t == null || e.scrollTop > t + o && (e.scrollTop = t);
|
|
51
|
-
}, [
|
|
52
|
-
let t = m.current, n =
|
|
51
|
+
}, [M]), P = e((e) => {
|
|
52
|
+
let t = m.current, n = j();
|
|
53
53
|
if (!t || n == null) return;
|
|
54
54
|
let r = Math.max(e - n, 0);
|
|
55
55
|
t.style.height = `${r}px`, h.current = r > 0, g.current = !1, _.current = r > 0 ? e : null;
|
|
56
|
-
}, [
|
|
57
|
-
let t =
|
|
58
|
-
t != null && (
|
|
56
|
+
}, [j]), F = e((e) => {
|
|
57
|
+
let t = k(e);
|
|
58
|
+
t != null && (P(t), A(e, !1));
|
|
59
59
|
}, [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
]),
|
|
64
|
-
let e =
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
P,
|
|
61
|
+
k,
|
|
62
|
+
A
|
|
63
|
+
]), I = e(() => {
|
|
64
|
+
let e = D();
|
|
65
|
+
if (e == null) return;
|
|
66
|
+
let t = e < a;
|
|
67
|
+
v.current = t, d(!t);
|
|
68
|
+
}, [D]), L = r(s.length), R = r(null);
|
|
67
69
|
n(() => {
|
|
68
|
-
let e = s.length !==
|
|
69
|
-
|
|
70
|
+
let e = s.length !== L.current, t = l !== R.current, n = () => {
|
|
71
|
+
L.current = s.length, R.current = l;
|
|
70
72
|
};
|
|
71
|
-
t &&
|
|
72
|
-
let r =
|
|
73
|
-
if (r != null &&
|
|
74
|
-
|
|
73
|
+
t && w();
|
|
74
|
+
let r = x.current;
|
|
75
|
+
if (r != null && y.current.has(r)) {
|
|
76
|
+
x.current = null, F(r), n();
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
77
|
-
c || ((e || t) &&
|
|
79
|
+
c || ((e || t) && E(!1), n());
|
|
78
80
|
}, [
|
|
79
81
|
s,
|
|
80
82
|
c,
|
|
81
83
|
l,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
E,
|
|
85
|
+
F,
|
|
86
|
+
w
|
|
85
87
|
]), n(() => {
|
|
86
|
-
!c && h.current && (g.current = !0,
|
|
87
|
-
}, [c,
|
|
88
|
-
let
|
|
89
|
-
|
|
88
|
+
!c && h.current && (g.current = !0, O());
|
|
89
|
+
}, [c, O]);
|
|
90
|
+
let z = e(() => {
|
|
91
|
+
N(), O(), I();
|
|
90
92
|
}, [
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
N,
|
|
94
|
+
O,
|
|
95
|
+
I
|
|
94
96
|
]);
|
|
95
97
|
return t(() => {
|
|
96
98
|
let e = f.current;
|
|
97
|
-
if (e) return e.addEventListener("scroll",
|
|
98
|
-
}, [
|
|
99
|
+
if (e) return e.addEventListener("scroll", z, { passive: !0 }), () => e.removeEventListener("scroll", z);
|
|
100
|
+
}, [z]), t(() => {
|
|
99
101
|
let e = p.current;
|
|
100
102
|
if (!e) return;
|
|
101
103
|
let t = new ResizeObserver(() => {
|
|
102
|
-
|
|
104
|
+
let e = v.current && !h.current;
|
|
105
|
+
N(), e && E(!0), O(), I();
|
|
103
106
|
});
|
|
104
107
|
return t.observe(e), () => t.disconnect();
|
|
105
108
|
}, [
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
N,
|
|
110
|
+
O,
|
|
111
|
+
I,
|
|
112
|
+
E
|
|
109
113
|
]), {
|
|
110
114
|
containerRef: f,
|
|
111
115
|
contentRef: p,
|
|
112
116
|
spacerRef: m,
|
|
113
|
-
setMessageRef:
|
|
117
|
+
setMessageRef: b,
|
|
114
118
|
isScrollButtonVisible: u,
|
|
115
119
|
scrollToBottom: e(() => {
|
|
116
|
-
|
|
117
|
-
}, [
|
|
118
|
-
armAnchor:
|
|
120
|
+
E(!1);
|
|
121
|
+
}, [E]),
|
|
122
|
+
armAnchor: S
|
|
119
123
|
};
|
|
120
124
|
};
|
|
121
125
|
//#endregion
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { safeDecodeURI as e } from "../../shared/string-utils.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE as t, GenerationPersistenceError as n } from "../create-chat-stream-api.js";
|
|
3
|
+
import { getConversationPath as r } from "./conversation-path.js";
|
|
4
|
+
import { applyChunkToMessages as i } from "./apply-chunk.js";
|
|
5
|
+
import { restoreBufferedMessage as a } from "./buffered-generation.js";
|
|
6
|
+
import { MessageRole as o } from "@epam/ai-dial-chat-shared";
|
|
6
7
|
//#region src/conversation/useConversationStream/generation-resume.ts
|
|
7
|
-
var
|
|
8
|
+
var s = (e) => {
|
|
8
9
|
let t = e.custom_content;
|
|
9
10
|
return !!e.content || e.responseId != null || !!t?.attachments?.length || !!t?.stages?.length || !!t?.annotations?.length || !!t?.form_schema || t?.state != null;
|
|
10
|
-
},
|
|
11
|
+
}, c = (e) => {
|
|
11
12
|
let t = e.messages[e.messages.length - 1];
|
|
12
|
-
return !!t && t.role ===
|
|
13
|
-
},
|
|
13
|
+
return !!t && t.role === o.Assistant && !s(t) && t.streamErrorMessage == null && !t.wasStoppedByUser;
|
|
14
|
+
}, l = 300 * 1e3, u = "awaiting-resume", d = async (e, t) => {
|
|
14
15
|
let n = e.getReader(), r = new TextDecoder(), i = "";
|
|
15
16
|
try {
|
|
16
17
|
for (;;) {
|
|
@@ -39,88 +40,99 @@ var a = (e) => {
|
|
|
39
40
|
} catch {} finally {
|
|
40
41
|
n.releaseLock();
|
|
41
42
|
}
|
|
42
|
-
},
|
|
43
|
-
if (!
|
|
44
|
-
let
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
}, f = ({ transport: o, setConversation: f, conversationRef: p, resumingPathsRef: m, bufferedGenerationsRef: h, addStreamingPath: g, removeStreamingPath: _, isPathDisplayed: v, generationPersistenceErrorMessage: y = t }) => (t, b) => {
|
|
44
|
+
if (!c(b)) return;
|
|
45
|
+
let x = r(t);
|
|
46
|
+
if (m.current.has(x)) return;
|
|
47
|
+
m.current.add(x), g(x);
|
|
48
|
+
let S = b.messages.length - 1, C = {
|
|
49
|
+
generationId: u,
|
|
50
|
+
messageIndex: S,
|
|
51
|
+
message: b.messages[S]
|
|
52
|
+
};
|
|
53
|
+
h.current.set(x, C);
|
|
54
|
+
let w = () => h.current.get(x) === C, T = (e, t = !1) => {
|
|
55
|
+
if (!w()) return;
|
|
56
|
+
m.current.delete(x), _(x);
|
|
57
|
+
let n = e && e.messages.length - 1 === S && c(e) && s(C.message);
|
|
58
|
+
if (t || n) {
|
|
59
|
+
C.message = {
|
|
60
|
+
...C.message,
|
|
61
|
+
streamErrorMessage: y
|
|
62
|
+
}, v(x) && f((e) => {
|
|
63
|
+
if (!e || !w() || !v(x)) return e;
|
|
64
|
+
let t = a(e, C);
|
|
65
|
+
return p.current = t, t;
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
h.current.delete(x), e && v(x) && (f(e), p.current = e);
|
|
70
|
+
}, E = async () => {
|
|
50
71
|
try {
|
|
51
|
-
|
|
72
|
+
T(await o.getConversation(e(t)));
|
|
52
73
|
} catch {
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}, S = (e) => {
|
|
56
|
-
let t = {
|
|
57
|
-
generationId: c,
|
|
58
|
-
messageIndex: y,
|
|
59
|
-
message: e
|
|
60
|
-
};
|
|
61
|
-
f.current.set(v, t), h(v) && a((e) => {
|
|
62
|
-
if (!e) return e;
|
|
63
|
-
let n = r(e, t);
|
|
64
|
-
return u.current = n, n;
|
|
65
|
-
});
|
|
66
|
-
}, C = (e) => {
|
|
67
|
-
let t = f.current.get(v);
|
|
68
|
-
if (t?.generationId === c) {
|
|
69
|
-
let r = n([t.message], 0, e);
|
|
70
|
-
r && (t.message = r[0]);
|
|
74
|
+
T(void 0, s(C.message));
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
}, D = (e) => {
|
|
77
|
+
w() && (C.message = e, v(x) && f((e) => {
|
|
78
|
+
if (!e || !w() || !v(x)) return e;
|
|
79
|
+
let t = a(e, C);
|
|
80
|
+
return p.current = t, t;
|
|
81
|
+
}));
|
|
82
|
+
}, O = (e) => {
|
|
83
|
+
if (!w()) return;
|
|
84
|
+
let t = i([C.message], 0, e);
|
|
85
|
+
t && (C.message = t[0]), v(x) && f((e) => {
|
|
86
|
+
if (!e || !w() || !v(x)) return e;
|
|
87
|
+
let t = a(e, C);
|
|
88
|
+
return p.current = t, t;
|
|
78
89
|
});
|
|
79
|
-
},
|
|
80
|
-
let
|
|
90
|
+
}, k = async () => {
|
|
91
|
+
let n = new AbortController(), r;
|
|
81
92
|
try {
|
|
82
|
-
|
|
93
|
+
r = await o.watchConversation(x, n.signal);
|
|
83
94
|
} catch {
|
|
84
|
-
await
|
|
95
|
+
await E();
|
|
85
96
|
return;
|
|
86
97
|
}
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
},
|
|
98
|
+
let i = !1, a = window.setTimeout(() => {
|
|
99
|
+
n.abort();
|
|
100
|
+
}, l);
|
|
90
101
|
try {
|
|
91
|
-
await
|
|
92
|
-
if (
|
|
102
|
+
await d(r, async (n) => {
|
|
103
|
+
if (n?.action !== "UPDATE") return !1;
|
|
93
104
|
try {
|
|
94
|
-
let
|
|
95
|
-
if (!
|
|
105
|
+
let n = await o.getConversation(e(t));
|
|
106
|
+
if (!c(n)) return T(n), i = !0, !0;
|
|
96
107
|
} catch {}
|
|
97
108
|
return !1;
|
|
98
109
|
});
|
|
99
110
|
} finally {
|
|
100
111
|
clearTimeout(a);
|
|
101
112
|
}
|
|
102
|
-
|
|
103
|
-
},
|
|
113
|
+
i || await E();
|
|
114
|
+
}, A = async () => {
|
|
104
115
|
let e = new AbortController(), t;
|
|
105
116
|
try {
|
|
106
|
-
t = await
|
|
117
|
+
t = await o.attachToGeneration(x, e.signal);
|
|
107
118
|
} catch {
|
|
108
119
|
return !1;
|
|
109
120
|
}
|
|
110
|
-
let
|
|
111
|
-
return await
|
|
121
|
+
let r = !1, i = !1;
|
|
122
|
+
return await d(t, (e) => {
|
|
123
|
+
if (!w()) return !0;
|
|
112
124
|
switch (e.type) {
|
|
113
|
-
case "snapshot": return
|
|
114
|
-
case "chunk": return
|
|
125
|
+
case "snapshot": return D(e.message), !1;
|
|
126
|
+
case "chunk": return O(e.chunk), !1;
|
|
115
127
|
case "done":
|
|
116
128
|
case "error":
|
|
117
|
-
case "stopped": return n = !0, !0;
|
|
129
|
+
case "stopped": return i = e.type === "error" && e.errorType === n.type, r = !0, !0;
|
|
118
130
|
}
|
|
119
|
-
}),
|
|
131
|
+
}), r ? (i ? T(void 0, !0) : await E(), !0) : !w();
|
|
120
132
|
};
|
|
121
133
|
(async () => {
|
|
122
|
-
await
|
|
134
|
+
await A() || await k();
|
|
123
135
|
})();
|
|
124
136
|
};
|
|
125
137
|
//#endregion
|
|
126
|
-
export {
|
|
138
|
+
export { f as createResumeIfAwaitingGeneration, s as hasGeneratedPayload, c as isAwaitingGenerationResume };
|