@epam/ai-dial-chat-hooks 1.2.0-dev.12 → 1.2.0-dev.120
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 +18 -14
- package/conversation/stage.js +23 -0
- package/conversation/useAttachmentUpload/useAttachmentUpload.js +12 -5
- package/conversation/useConversationHandlers/useConversationHandlers.js +13 -17
- 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/useConversationStream.js +87 -78
- package/conversation-overlay.d.ts +7 -0
- package/conversation-overlay.js +2 -0
- package/conversation.d.ts +127 -6
- package/conversation.js +30 -29
- 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 +736 -32
- 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
|
@@ -3,20 +3,24 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
3
3
|
constructor(e = n) {
|
|
4
4
|
super(e), this.name = "GenerationConflictError";
|
|
5
5
|
}
|
|
6
|
-
}, i =
|
|
6
|
+
}, i = class extends Error {
|
|
7
|
+
constructor(e) {
|
|
8
|
+
super(e), this.name = "StreamUpstreamError";
|
|
9
|
+
}
|
|
10
|
+
}, a = (e, t, n) => {
|
|
7
11
|
let r = e.trim();
|
|
8
12
|
if (!r || r.startsWith(":") || !r.startsWith("data: ")) return;
|
|
9
|
-
let
|
|
10
|
-
if (
|
|
11
|
-
let e = JSON.parse(
|
|
13
|
+
let a = r.slice(6);
|
|
14
|
+
if (a !== "[DONE]") try {
|
|
15
|
+
let e = JSON.parse(a);
|
|
12
16
|
if (e.error) {
|
|
13
|
-
n(
|
|
17
|
+
n(new i(e.error.message));
|
|
14
18
|
return;
|
|
15
19
|
}
|
|
16
20
|
t(e);
|
|
17
21
|
} catch {}
|
|
18
|
-
},
|
|
19
|
-
let { completionsBasePath:
|
|
22
|
+
}, o = (n) => {
|
|
23
|
+
let { completionsBasePath: i } = n, o = (...e) => (n.fetchImpl ?? fetch)(...e);
|
|
20
24
|
return {
|
|
21
25
|
streamCompletion: (s, c, l, u, d, f, p, m, h) => {
|
|
22
26
|
let { onChunk: g, onComplete: _, onError: v, signal: y } = u;
|
|
@@ -24,7 +28,7 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
24
28
|
let u;
|
|
25
29
|
try {
|
|
26
30
|
let t = n.getTimezone?.();
|
|
27
|
-
u = await o(`${
|
|
31
|
+
u = await o(`${i}/completions`, {
|
|
28
32
|
method: "POST",
|
|
29
33
|
credentials: "include",
|
|
30
34
|
signal: y,
|
|
@@ -69,13 +73,13 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
69
73
|
for (;;) {
|
|
70
74
|
let { done: e, value: t } = await x.read();
|
|
71
75
|
if (e) {
|
|
72
|
-
C.trim() &&
|
|
76
|
+
C.trim() && a(C, g, T);
|
|
73
77
|
break;
|
|
74
78
|
}
|
|
75
79
|
C += S.decode(t, { stream: !0 });
|
|
76
80
|
let n = C.split("\n");
|
|
77
81
|
C = n.pop() ?? "";
|
|
78
|
-
for (let e of n)
|
|
82
|
+
for (let e of n) a(e, g, T);
|
|
79
83
|
}
|
|
80
84
|
w || _();
|
|
81
85
|
} catch (e) {
|
|
@@ -87,7 +91,7 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
87
91
|
})();
|
|
88
92
|
},
|
|
89
93
|
stopCompletion: async (t) => {
|
|
90
|
-
let r = await o(`${
|
|
94
|
+
let r = await o(`${i}/completions/stop`, {
|
|
91
95
|
method: "POST",
|
|
92
96
|
credentials: "include",
|
|
93
97
|
headers: {
|
|
@@ -95,10 +99,10 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
|
|
|
95
99
|
...n.getCsrfToken() == null ? {} : { "X-CSRF-Token": n.getCsrfToken() }
|
|
96
100
|
},
|
|
97
101
|
body: JSON.stringify(t)
|
|
98
|
-
}),
|
|
99
|
-
if (
|
|
102
|
+
}), a = r.headers.get("x-csrf-token");
|
|
103
|
+
if (a && n.setCsrfToken(a), !r.ok) throw Error(`stopCompletion failed: ${r.status}`);
|
|
100
104
|
}
|
|
101
105
|
};
|
|
102
106
|
};
|
|
103
107
|
//#endregion
|
|
104
|
-
export { n as DEFAULT_GENERATION_CONFLICT_MESSAGE, r as GenerationConflictError,
|
|
108
|
+
export { n as DEFAULT_GENERATION_CONFLICT_MESSAGE, r as GenerationConflictError, i as StreamUpstreamError, o 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,
|
|
@@ -44,23 +44,19 @@ var p = ({ conversation: p, conversationId: m, bucket: h, isStreaming: g, startS
|
|
|
44
44
|
if (g || !m || !p || e === -1 || p.messages[e]?.role !== c.Assistant) return;
|
|
45
45
|
let t = p.messages[e - 1];
|
|
46
46
|
if (!t || t.role !== c.User) return;
|
|
47
|
-
let n = C()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
messages: [...t.messages.slice(0, e), r]
|
|
61
|
-
};
|
|
62
|
-
return y.current = i, i;
|
|
63
|
-
}), A((t) => new Set([...t].filter((t) => t < e))), _(m, t.content, e, n, t.custom_content, l(), f.Regenerate);
|
|
47
|
+
let n = C(), r = {
|
|
48
|
+
...p.messages[e],
|
|
49
|
+
content: "",
|
|
50
|
+
custom_content: void 0,
|
|
51
|
+
wasStoppedByUser: void 0,
|
|
52
|
+
stoppedWithoutContent: void 0,
|
|
53
|
+
streamErrorMessage: void 0,
|
|
54
|
+
deploymentId: n
|
|
55
|
+
}, i = {
|
|
56
|
+
...p,
|
|
57
|
+
messages: [...p.messages.slice(0, e), r]
|
|
58
|
+
};
|
|
59
|
+
y.current = i, v(i), A((t) => new Set([...t].filter((t) => t < e))), _(m, t.content, e, n, t.custom_content, l(), f.Regenerate);
|
|
64
60
|
}, [
|
|
65
61
|
p,
|
|
66
62
|
m,
|
|
@@ -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,56 +1,60 @@
|
|
|
1
1
|
import { safeDecodeURI as e } from "../../shared/string-utils.js";
|
|
2
|
-
import { DEFAULT_GENERATION_CONFLICT_MESSAGE as t, GenerationConflictError as n } from "../create-chat-stream-api.js";
|
|
3
|
-
import { getConversationPath as
|
|
4
|
-
import { applyChunkToMessages as
|
|
5
|
-
import { restoreBufferedMessage as
|
|
6
|
-
import { createResumeIfAwaitingGeneration as
|
|
7
|
-
import { generateUUID as
|
|
8
|
-
import { useCallback as
|
|
9
|
-
import { SendCompletionDtoModeEnum as
|
|
2
|
+
import { DEFAULT_GENERATION_CONFLICT_MESSAGE as t, GenerationConflictError as n, StreamUpstreamError as r } from "../create-chat-stream-api.js";
|
|
3
|
+
import { getConversationPath as i } from "./conversation-path.js";
|
|
4
|
+
import { applyChunkToMessages as a } from "./apply-chunk.js";
|
|
5
|
+
import { restoreBufferedMessage as o } from "./buffered-generation.js";
|
|
6
|
+
import { createResumeIfAwaitingGeneration as s } from "./generation-resume.js";
|
|
7
|
+
import { generateUUID as c } from "@epam/ai-dial-chat-shared";
|
|
8
|
+
import { useCallback as l, useEffect as u, useMemo as d, useRef as f, useState as p } from "react";
|
|
9
|
+
import { SendCompletionDtoModeEnum as m } from "@epam/ai-dial-chat-api-client";
|
|
10
10
|
//#region src/conversation/useConversationStream/useConversationStream.ts
|
|
11
|
-
var
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, [
|
|
16
|
-
let
|
|
17
|
-
|
|
11
|
+
var h = 2e4, g = (e, t) => e instanceof n ? t : e instanceof r ? e.message : "", _ = ({ conversationId: n, state: { setConversation: r, conversationRef: _ }, transport: v, generation: { startGeneration: y, completeGeneration: b }, channel: x, overlay: S, onStopError: C, generationConflictMessage: w = t, onStreamError: T }) => {
|
|
12
|
+
let E = f(T);
|
|
13
|
+
u(() => {
|
|
14
|
+
E.current = T;
|
|
15
|
+
}, [T]);
|
|
16
|
+
let [D, O] = p(() => /* @__PURE__ */ new Set()), [k, A] = p(null), j = f(null), M = f(null), N = f(/* @__PURE__ */ new Set()), P = f(/* @__PURE__ */ new Map()), F = f(/* @__PURE__ */ new Set()), I = f(/* @__PURE__ */ new Map()), L = f(n);
|
|
17
|
+
u(() => {
|
|
18
|
+
L.current = n;
|
|
19
|
+
}, [n]);
|
|
20
|
+
let R = l((e) => i(L.current ?? "") === e, []), z = l((e) => {
|
|
21
|
+
O((t) => {
|
|
18
22
|
if (t.has(e)) return t;
|
|
19
23
|
let n = new Set(t);
|
|
20
24
|
return n.add(e), n;
|
|
21
25
|
});
|
|
22
|
-
}, []),
|
|
23
|
-
|
|
26
|
+
}, []), B = l((e) => {
|
|
27
|
+
O((t) => {
|
|
24
28
|
if (!t.has(e)) return t;
|
|
25
29
|
let n = new Set(t);
|
|
26
30
|
return n.delete(e), n;
|
|
27
31
|
});
|
|
28
|
-
}, []),
|
|
29
|
-
let
|
|
30
|
-
|
|
32
|
+
}, []), V = l((t, n, s, l, u, d, f = m.Append) => {
|
|
33
|
+
let p = d ?? c(), C = i(t);
|
|
34
|
+
j.current = p, M.current = C, I.current.set(C, p), A(C);
|
|
31
35
|
let T;
|
|
32
|
-
f ===
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
generationId:
|
|
36
|
-
messageIndex:
|
|
37
|
-
message:
|
|
38
|
-
}) :
|
|
39
|
-
let
|
|
40
|
-
signal:
|
|
36
|
+
f === m.Regenerate ? T = s : f === m.Edit && (T = s - 1);
|
|
37
|
+
let D = () => I.current.get(C) !== p, O = y(C, p), k = _.current?.messages[s];
|
|
38
|
+
k ? P.current.set(C, {
|
|
39
|
+
generationId: p,
|
|
40
|
+
messageIndex: s,
|
|
41
|
+
message: k
|
|
42
|
+
}) : P.current.delete(C), z(C), S?.notifyGenerationStart?.(), x?.ensureConnected();
|
|
43
|
+
let N = {
|
|
44
|
+
signal: O.signal,
|
|
41
45
|
onChunk: (e) => {
|
|
42
|
-
if (
|
|
43
|
-
let t =
|
|
44
|
-
if (t?.generationId ===
|
|
45
|
-
let n =
|
|
46
|
+
if (j.current !== p) return;
|
|
47
|
+
let t = P.current.get(C);
|
|
48
|
+
if (t?.generationId === p) {
|
|
49
|
+
let n = a([t.message], 0, e);
|
|
46
50
|
n && (t.message = n[0]);
|
|
47
51
|
}
|
|
48
|
-
|
|
52
|
+
R(C) && r((t) => {
|
|
49
53
|
if (!t) return t;
|
|
50
|
-
let n =
|
|
51
|
-
if (n?.generationId ===
|
|
54
|
+
let n = P.current.get(C), r;
|
|
55
|
+
if (n?.generationId === p) r = o(t, n);
|
|
52
56
|
else {
|
|
53
|
-
let n =
|
|
57
|
+
let n = a(t.messages, s, e);
|
|
54
58
|
if (!n) return t;
|
|
55
59
|
r = {
|
|
56
60
|
...t,
|
|
@@ -61,43 +65,48 @@ var m = 2e4, h = ({ conversationId: h, state: { setConversation: g, conversation
|
|
|
61
65
|
});
|
|
62
66
|
},
|
|
63
67
|
onComplete: async () => {
|
|
64
|
-
if (
|
|
68
|
+
if (P.current.get(C)?.generationId === p && P.current.delete(C), D() || B(C), j.current === p && (j.current = null, M.current = null, A(null)), b(C, p), x?.notifyGenerationSettled?.(), F.current.has(p) ? F.current.delete(p) : D() || S?.notifyGenerationEnd?.(), !D() && R(C)) try {
|
|
65
69
|
let n = await v.getConversation(e(t));
|
|
66
|
-
if (
|
|
67
|
-
|
|
70
|
+
if (D() || !R(C)) return;
|
|
71
|
+
r(n), _.current = n;
|
|
68
72
|
} catch {}
|
|
69
73
|
},
|
|
70
74
|
onError: (e) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
g(
|
|
75
|
+
E.current?.(e);
|
|
76
|
+
let t = P.current.get(C), n = t?.generationId === p ? t : void 0;
|
|
77
|
+
if (n && P.current.delete(C), D() || B(C), j.current === p && (j.current = null, M.current = null, A(null)), b(C, p), x?.notifyGenerationSettled?.(), D() || !R(C)) return;
|
|
78
|
+
let i = g(e, w);
|
|
79
|
+
r((e) => {
|
|
75
80
|
if (!e) return e;
|
|
76
|
-
let t =
|
|
81
|
+
let t = n?.generationId === p ? o(e, n) : e, r = {
|
|
77
82
|
...t,
|
|
78
|
-
messages: t.messages.map((e, t) => t ===
|
|
83
|
+
messages: t.messages.map((e, t) => t === s ? {
|
|
79
84
|
...e,
|
|
80
85
|
streamErrorMessage: i
|
|
81
86
|
} : e)
|
|
82
87
|
};
|
|
83
|
-
return _.current =
|
|
88
|
+
return _.current = r, r;
|
|
84
89
|
});
|
|
85
90
|
}
|
|
86
91
|
};
|
|
87
92
|
(async () => {
|
|
88
93
|
try {
|
|
89
|
-
let e = x?.channelId ?? await x?.waitForChannel(
|
|
90
|
-
|
|
94
|
+
let e = x?.channelId ?? await x?.waitForChannel(h) ?? void 0, t = F.current.has(p);
|
|
95
|
+
if (O.signal.aborted || D() || t) {
|
|
96
|
+
P.current.get(C)?.generationId === p && P.current.delete(C), D() || B(C), j.current === p && (j.current = null, M.current = null, A(null)), b(C, p), x?.notifyGenerationSettled?.(), t ? F.current.delete(p) : D() || S?.notifyGenerationEnd?.();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
v.streamCompletion(C, n, l, N, u, p, f, T, e);
|
|
91
100
|
} catch (e) {
|
|
92
|
-
|
|
101
|
+
N.onError(e instanceof Error ? e : Error(String(e)));
|
|
93
102
|
}
|
|
94
103
|
})();
|
|
95
104
|
}, [
|
|
96
105
|
y,
|
|
97
106
|
b,
|
|
98
|
-
|
|
107
|
+
z,
|
|
108
|
+
B,
|
|
99
109
|
R,
|
|
100
|
-
I,
|
|
101
110
|
x?.channelId,
|
|
102
111
|
x?.ensureConnected,
|
|
103
112
|
x?.waitForChannel,
|
|
@@ -105,14 +114,14 @@ var m = 2e4, h = ({ conversationId: h, state: { setConversation: g, conversation
|
|
|
105
114
|
S,
|
|
106
115
|
v,
|
|
107
116
|
w
|
|
108
|
-
]),
|
|
109
|
-
let n =
|
|
110
|
-
return
|
|
111
|
-
}, []),
|
|
112
|
-
let e =
|
|
113
|
-
if (!e || !
|
|
114
|
-
let t =
|
|
115
|
-
|
|
117
|
+
]), H = l((e, t) => {
|
|
118
|
+
let n = i(e), r = P.current.get(n);
|
|
119
|
+
return r ? o(t, r) : t;
|
|
120
|
+
}, []), U = l(() => {
|
|
121
|
+
let e = j.current;
|
|
122
|
+
if (!e || !n) return;
|
|
123
|
+
let t = i(n);
|
|
124
|
+
M.current === t && (F.current.add(e), S?.notifyStopGenerating?.(), v.stopCompletion({
|
|
116
125
|
generationId: e,
|
|
117
126
|
path: t
|
|
118
127
|
}).catch((e) => {
|
|
@@ -120,33 +129,33 @@ var m = 2e4, h = ({ conversationId: h, state: { setConversation: g, conversation
|
|
|
120
129
|
C?.(t);
|
|
121
130
|
}));
|
|
122
131
|
}, [
|
|
123
|
-
|
|
132
|
+
n,
|
|
124
133
|
C,
|
|
125
134
|
S,
|
|
126
135
|
v
|
|
127
|
-
]),
|
|
136
|
+
]), W = d(() => s({
|
|
128
137
|
transport: v,
|
|
129
|
-
setConversation:
|
|
138
|
+
setConversation: r,
|
|
130
139
|
conversationRef: _,
|
|
131
|
-
resumingPathsRef:
|
|
132
|
-
bufferedGenerationsRef:
|
|
133
|
-
addStreamingPath:
|
|
134
|
-
removeStreamingPath:
|
|
135
|
-
isPathDisplayed:
|
|
140
|
+
resumingPathsRef: N,
|
|
141
|
+
bufferedGenerationsRef: P,
|
|
142
|
+
addStreamingPath: z,
|
|
143
|
+
removeStreamingPath: B,
|
|
144
|
+
isPathDisplayed: R
|
|
136
145
|
}), [
|
|
137
|
-
|
|
146
|
+
z,
|
|
147
|
+
B,
|
|
138
148
|
R,
|
|
139
|
-
I,
|
|
140
149
|
v
|
|
141
|
-
]),
|
|
150
|
+
]), G = n != null && D.has(i(n)), K = n == null ? null : i(n);
|
|
142
151
|
return {
|
|
143
|
-
startStream:
|
|
144
|
-
handleStop:
|
|
145
|
-
resumeIfAwaitingGeneration:
|
|
146
|
-
restoreBufferedGeneration:
|
|
147
|
-
isStreaming:
|
|
148
|
-
canStopStreaming:
|
|
152
|
+
startStream: V,
|
|
153
|
+
handleStop: U,
|
|
154
|
+
resumeIfAwaitingGeneration: W,
|
|
155
|
+
restoreBufferedGeneration: H,
|
|
156
|
+
isStreaming: G,
|
|
157
|
+
canStopStreaming: K != null && k === K
|
|
149
158
|
};
|
|
150
159
|
};
|
|
151
160
|
//#endregion
|
|
152
|
-
export {
|
|
161
|
+
export { _ as useConversationStream };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Message } from '@epam/ai-dial-chat-shared';
|
|
2
|
+
import { OverlayChatMessage } from '@epam/ai-dial-chat-overlay';
|
|
3
|
+
|
|
4
|
+
/** Maps chat messages to the DIAL Chat Overlay protocol's message shape. */
|
|
5
|
+
export declare const toOverlayMessages: (messages: Message[]) => OverlayChatMessage[];
|
|
6
|
+
|
|
7
|
+
export { }
|