@epam/ai-dial-chat-hooks 1.2.0-dev.15 → 1.2.0-dev.152
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-limits-to-input.js +81 -9
- 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 +86 -19
- 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/useConversationPanelItems/useConversationPanelItems.js +2 -3
- 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 +147 -15
- 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 +784 -57
- 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 +93 -75
- package/skill-editor.d.ts +110 -1
- 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,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 };
|
|
@@ -1,152 +1,195 @@
|
|
|
1
1
|
import { safeDecodeURI as e } from "../../shared/string-utils.js";
|
|
2
|
-
import { DEFAULT_GENERATION_CONFLICT_MESSAGE as t,
|
|
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, DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE as n, GenerationConflictError as r, GenerationPersistenceError as i, StreamUpstreamError as a } from "../create-chat-stream-api.js";
|
|
3
|
+
import { getConversationPath as o } from "./conversation-path.js";
|
|
4
|
+
import { applyChunkToMessages as s } from "./apply-chunk.js";
|
|
5
|
+
import { restoreBufferedMessage as c } from "./buffered-generation.js";
|
|
6
|
+
import { createResumeIfAwaitingGeneration as l, hasGeneratedPayload as u, isAwaitingGenerationResume as d } from "./generation-resume.js";
|
|
7
|
+
import { generateUUID as f } from "@epam/ai-dial-chat-shared";
|
|
8
|
+
import { useCallback as p, useEffect as m, useMemo as h, useRef as g, useState as _ } from "react";
|
|
9
|
+
import { SendCompletionDtoModeEnum as v } 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 y = 2e4, b = (e, t, n) => e instanceof i ? n : e instanceof r ? t : e instanceof a ? e.message : "", x = ({ conversationId: r, state: { setConversation: a, conversationRef: x }, transport: S, generation: { startGeneration: C, completeGeneration: w }, channel: T, overlay: E, onStopError: D, generationConflictMessage: O = t, generationPersistenceErrorMessage: k = n, onStreamError: A }) => {
|
|
12
|
+
let j = g(A);
|
|
13
|
+
m(() => {
|
|
14
|
+
j.current = A;
|
|
15
|
+
}, [A]);
|
|
16
|
+
let [M, N] = _(() => /* @__PURE__ */ new Set()), [P, F] = _(null), I = g(null), L = g(null), R = g(/* @__PURE__ */ new Set()), z = g(/* @__PURE__ */ new Map()), B = g(/* @__PURE__ */ new Set()), V = g(/* @__PURE__ */ new Map()), H = g(r);
|
|
17
|
+
m(() => {
|
|
18
|
+
H.current = r;
|
|
19
|
+
}, [r]);
|
|
20
|
+
let U = p((e) => o(H.current ?? "") === e, []), W = p((e) => {
|
|
21
|
+
N((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
|
+
}, []), G = p((e) => {
|
|
27
|
+
N((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
|
-
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
generationId:
|
|
36
|
-
messageIndex:
|
|
37
|
-
message:
|
|
38
|
-
}) :
|
|
39
|
-
let
|
|
40
|
-
|
|
32
|
+
}, []), K = p((t, n, r, l, p, m, h = v.Append) => {
|
|
33
|
+
let g = m ?? f(), _ = o(t);
|
|
34
|
+
R.current.delete(_), I.current = g, L.current = _, V.current.set(_, g), F(_);
|
|
35
|
+
let D;
|
|
36
|
+
h === v.Regenerate ? D = r : h === v.Edit && (D = r - 1);
|
|
37
|
+
let A = () => V.current.get(_) !== g, M = C(_, g), N = x.current?.messages[r];
|
|
38
|
+
N ? z.current.set(_, {
|
|
39
|
+
generationId: g,
|
|
40
|
+
messageIndex: r,
|
|
41
|
+
message: N
|
|
42
|
+
}) : z.current.delete(_), W(_), E?.notifyGenerationStart?.(), T?.ensureConnected();
|
|
43
|
+
let P = () => {
|
|
44
|
+
if (A()) return;
|
|
45
|
+
let e = z.current.get(_);
|
|
46
|
+
!e || e.generationId !== g || (e.message = {
|
|
47
|
+
...e.message,
|
|
48
|
+
streamErrorMessage: k
|
|
49
|
+
}, j.current?.(new i()), U(_) && a((t) => {
|
|
50
|
+
if (!t || A() || !U(_)) return t;
|
|
51
|
+
let n = c(t, e);
|
|
52
|
+
return x.current = n, n;
|
|
53
|
+
}));
|
|
54
|
+
}, H = {
|
|
55
|
+
signal: M.signal,
|
|
41
56
|
onChunk: (e) => {
|
|
42
|
-
if (
|
|
43
|
-
let t =
|
|
44
|
-
if (t?.generationId ===
|
|
45
|
-
let n =
|
|
57
|
+
if (I.current !== g) return;
|
|
58
|
+
let t = z.current.get(_);
|
|
59
|
+
if (t?.generationId === g) {
|
|
60
|
+
let n = s([t.message], 0, e);
|
|
46
61
|
n && (t.message = n[0]);
|
|
47
62
|
}
|
|
48
|
-
|
|
63
|
+
U(_) && a((t) => {
|
|
49
64
|
if (!t) return t;
|
|
50
|
-
let n =
|
|
51
|
-
if (n?.generationId ===
|
|
65
|
+
let n = z.current.get(_), i;
|
|
66
|
+
if (n?.generationId === g) i = c(t, n);
|
|
52
67
|
else {
|
|
53
|
-
let n =
|
|
68
|
+
let n = s(t.messages, r, e);
|
|
54
69
|
if (!n) return t;
|
|
55
|
-
|
|
70
|
+
i = {
|
|
56
71
|
...t,
|
|
57
72
|
messages: n
|
|
58
73
|
};
|
|
59
74
|
}
|
|
60
|
-
return
|
|
75
|
+
return x.current = i, i;
|
|
61
76
|
});
|
|
62
77
|
},
|
|
63
78
|
onComplete: async () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
let n = z.current.get(_), r = n?.generationId === g ? n : void 0;
|
|
80
|
+
if (A() || G(_), I.current === g && (I.current = null, L.current = null, F(null)), w(_, g), T?.notifyGenerationSettled?.(), B.current.has(g) ? B.current.delete(g) : A() || E?.notifyGenerationEnd?.(), !A()) {
|
|
81
|
+
if (!U(_)) {
|
|
82
|
+
r && z.current.delete(_);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
let n = await S.getConversation(e(t));
|
|
87
|
+
if (A()) return;
|
|
88
|
+
if (!U(_)) {
|
|
89
|
+
r && z.current.delete(_);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (r && r.messageIndex === n.messages.length - 1 && d(n) && u(r.message)) {
|
|
93
|
+
P();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
r && z.current.delete(_), a(n), x.current = n;
|
|
97
|
+
} catch {
|
|
98
|
+
A() || P();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
69
101
|
},
|
|
70
102
|
onError: (e) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
103
|
+
j.current?.(e);
|
|
104
|
+
let t = z.current.get(_), n = t?.generationId === g ? t : void 0;
|
|
105
|
+
if (n && (e instanceof i ? n.message = {
|
|
106
|
+
...n.message,
|
|
107
|
+
streamErrorMessage: k
|
|
108
|
+
} : z.current.delete(_)), A() || G(_), I.current === g && (I.current = null, L.current = null, F(null)), w(_, g), T?.notifyGenerationSettled?.(), A() || !U(_)) return;
|
|
109
|
+
let o = b(e, O, k);
|
|
110
|
+
a((e) => {
|
|
111
|
+
if (!e || A() || !U(_)) return e;
|
|
112
|
+
let t = n?.generationId === g ? c(e, n) : e, i = {
|
|
77
113
|
...t,
|
|
78
|
-
messages: t.messages.map((e, t) => t ===
|
|
114
|
+
messages: t.messages.map((e, t) => t === r ? {
|
|
79
115
|
...e,
|
|
80
|
-
streamErrorMessage:
|
|
116
|
+
streamErrorMessage: o
|
|
81
117
|
} : e)
|
|
82
118
|
};
|
|
83
|
-
return
|
|
119
|
+
return x.current = i, i;
|
|
84
120
|
});
|
|
85
121
|
}
|
|
86
122
|
};
|
|
87
123
|
(async () => {
|
|
88
124
|
try {
|
|
89
|
-
let e =
|
|
90
|
-
|
|
125
|
+
let e = T?.channelId ?? await T?.waitForChannel(y) ?? void 0, t = B.current.has(g);
|
|
126
|
+
if (M.signal.aborted || A() || t) {
|
|
127
|
+
z.current.get(_)?.generationId === g && z.current.delete(_), A() || G(_), I.current === g && (I.current = null, L.current = null, F(null)), w(_, g), T?.notifyGenerationSettled?.(), t ? B.current.delete(g) : A() || E?.notifyGenerationEnd?.();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
S.streamCompletion(_, n, l, H, p, g, h, D, e);
|
|
91
131
|
} catch (e) {
|
|
92
|
-
|
|
132
|
+
H.onError(e instanceof Error ? e : Error(String(e)));
|
|
93
133
|
}
|
|
94
134
|
})();
|
|
95
135
|
}, [
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
136
|
+
C,
|
|
137
|
+
w,
|
|
138
|
+
W,
|
|
139
|
+
G,
|
|
140
|
+
U,
|
|
141
|
+
T?.channelId,
|
|
142
|
+
T?.ensureConnected,
|
|
143
|
+
T?.waitForChannel,
|
|
144
|
+
T?.notifyGenerationSettled,
|
|
145
|
+
E,
|
|
105
146
|
S,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
]),
|
|
109
|
-
let n =
|
|
110
|
-
return
|
|
111
|
-
}, []),
|
|
112
|
-
let e =
|
|
113
|
-
if (!e || !
|
|
114
|
-
let t = r
|
|
115
|
-
|
|
147
|
+
O,
|
|
148
|
+
k
|
|
149
|
+
]), q = p((e, t) => {
|
|
150
|
+
let n = o(e), r = z.current.get(n);
|
|
151
|
+
return r ? c(t, r) : t;
|
|
152
|
+
}, []), J = p(() => {
|
|
153
|
+
let e = I.current;
|
|
154
|
+
if (!e || !r) return;
|
|
155
|
+
let t = o(r);
|
|
156
|
+
L.current === t && (B.current.add(e), E?.notifyStopGenerating?.(), S.stopCompletion({
|
|
116
157
|
generationId: e,
|
|
117
158
|
path: t
|
|
118
159
|
}).catch((e) => {
|
|
119
160
|
let t = e instanceof Error ? e : Error(String(e));
|
|
120
|
-
|
|
161
|
+
D?.(t);
|
|
121
162
|
}));
|
|
122
163
|
}, [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
]),
|
|
128
|
-
transport:
|
|
129
|
-
setConversation:
|
|
130
|
-
conversationRef:
|
|
131
|
-
resumingPathsRef:
|
|
132
|
-
bufferedGenerationsRef:
|
|
133
|
-
addStreamingPath:
|
|
134
|
-
removeStreamingPath:
|
|
135
|
-
isPathDisplayed:
|
|
164
|
+
r,
|
|
165
|
+
D,
|
|
166
|
+
E,
|
|
167
|
+
S
|
|
168
|
+
]), Y = h(() => l({
|
|
169
|
+
transport: S,
|
|
170
|
+
setConversation: a,
|
|
171
|
+
conversationRef: x,
|
|
172
|
+
resumingPathsRef: R,
|
|
173
|
+
bufferedGenerationsRef: z,
|
|
174
|
+
addStreamingPath: W,
|
|
175
|
+
removeStreamingPath: G,
|
|
176
|
+
isPathDisplayed: U,
|
|
177
|
+
generationPersistenceErrorMessage: k
|
|
136
178
|
}), [
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
179
|
+
W,
|
|
180
|
+
G,
|
|
181
|
+
U,
|
|
182
|
+
S,
|
|
183
|
+
k
|
|
184
|
+
]), X = r != null && M.has(o(r)), Z = r == null ? null : o(r);
|
|
142
185
|
return {
|
|
143
|
-
startStream:
|
|
144
|
-
handleStop:
|
|
145
|
-
resumeIfAwaitingGeneration:
|
|
146
|
-
restoreBufferedGeneration:
|
|
147
|
-
isStreaming:
|
|
148
|
-
canStopStreaming:
|
|
186
|
+
startStream: K,
|
|
187
|
+
handleStop: J,
|
|
188
|
+
resumeIfAwaitingGeneration: Y,
|
|
189
|
+
restoreBufferedGeneration: q,
|
|
190
|
+
isStreaming: X,
|
|
191
|
+
canStopStreaming: Z != null && P === Z
|
|
149
192
|
};
|
|
150
193
|
};
|
|
151
194
|
//#endregion
|
|
152
|
-
export {
|
|
195
|
+
export { x 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 { }
|
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
import { MessageRole as e, messageAttachmentToDisplayAttachment as t } from "@epam/ai-dial-chat-shared";
|
|
2
|
-
import {
|
|
3
|
-
import { useMemo as
|
|
2
|
+
import { getAnnotationPdfPage as n, isReferenceOnlyAttachment as r, parsePdfPageReference as i, resolveMessageAnnotations as a } from "@epam/ai-dial-quotations";
|
|
3
|
+
import { useMemo as o } from "react";
|
|
4
4
|
//#region src/conversation-sources/useConversationSources/useConversationSources.ts
|
|
5
|
-
var
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
var s = {}, c = (e, t) => {
|
|
6
|
+
let r = n(e);
|
|
7
|
+
if (r == null) return t;
|
|
8
|
+
let a = i(t);
|
|
9
|
+
return a == null || a.page != null ? t : `${t}#page=${r}`;
|
|
10
|
+
}, l = (n, i = s) => o(() => {
|
|
11
|
+
let o = [], s = [], l = [], u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
|
|
12
|
+
for (let p of n) {
|
|
13
|
+
let n = p.custom_content?.attachments;
|
|
14
|
+
if (p.role === e.User) for (let e of n ?? []) {
|
|
15
|
+
let n = t(e, i);
|
|
16
|
+
d.has(n.id) || (d.add(n.id), o.push(n));
|
|
12
17
|
}
|
|
13
|
-
else if (
|
|
14
|
-
let e =
|
|
18
|
+
else if (p.role === e.Assistant) {
|
|
19
|
+
let e = n?.filter((e) => !r(e));
|
|
15
20
|
for (let n of e ?? []) {
|
|
16
|
-
let e = t(n,
|
|
17
|
-
|
|
21
|
+
let e = t(n, i);
|
|
22
|
+
f.has(e.id) || (f.add(e.id), s.push(e));
|
|
18
23
|
}
|
|
19
|
-
for (let e of
|
|
20
|
-
if (!
|
|
24
|
+
for (let e of n ?? []) {
|
|
25
|
+
if (!r(e)) continue;
|
|
21
26
|
let t = e.reference_url;
|
|
22
|
-
|
|
27
|
+
u.has(t) || (u.add(t), l.push({
|
|
23
28
|
url: t,
|
|
24
29
|
title: e.title ?? t,
|
|
25
30
|
contentType: e.reference_type ?? e.type ?? "",
|
|
26
31
|
quote: e.data
|
|
27
32
|
}));
|
|
28
33
|
}
|
|
29
|
-
for (let e of
|
|
34
|
+
for (let e of a(p)) {
|
|
30
35
|
let t = e?.body?.source?.attachment, n = t?.url;
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
if (!n) continue;
|
|
37
|
+
let r = c(e, n);
|
|
38
|
+
u.has(r) || (u.add(r), l.push({
|
|
39
|
+
url: r,
|
|
33
40
|
title: t?.title ?? n.split("/").pop() ?? n,
|
|
34
41
|
contentType: t?.type ?? "",
|
|
35
42
|
quote: e.body?.quote
|
|
@@ -38,10 +45,10 @@ var a = {}, o = (o, s = a) => i(() => {
|
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
return {
|
|
41
|
-
uploaded:
|
|
42
|
-
generated:
|
|
43
|
-
sources:
|
|
48
|
+
uploaded: o,
|
|
49
|
+
generated: s,
|
|
50
|
+
sources: l
|
|
44
51
|
};
|
|
45
|
-
}, [
|
|
52
|
+
}, [n, i]);
|
|
46
53
|
//#endregion
|
|
47
|
-
export {
|
|
54
|
+
export { l as useConversationSources };
|
|
@@ -18,7 +18,7 @@ export declare interface UseConversationSourcesResult {
|
|
|
18
18
|
uploaded: DisplayAttachment[];
|
|
19
19
|
/** Deduplicated attachments the assistant generated across the conversation. */
|
|
20
20
|
generated: DisplayAttachment[];
|
|
21
|
-
/** Quotation sources referenced by assistant messages, deduplicated by URL
|
|
21
|
+
/** Quotation sources referenced by assistant messages, deduplicated by URL; PDF sources are qualified with `#page=N`. */
|
|
22
22
|
sources: QuotationSource[];
|
|
23
23
|
}
|
|
24
24
|
|