@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.
Files changed (63) hide show
  1. package/api-error/api-error.js +5 -4
  2. package/attachment/useAttachmentValidation/useAttachmentValidation.js +26 -19
  3. package/attachments.d.ts +10 -4
  4. package/catalog/map-deployment-limits-to-input.js +81 -9
  5. package/catalog/map-deployment-to-catalog-item.js +2 -2
  6. package/catalog/map-skill-to-catalog-item.js +30 -27
  7. package/catalog/publish.js +2 -1
  8. package/catalog/useApplicationCredentials/useApplicationCredentials.js +39 -0
  9. package/catalog/useSkillDetailsPanelData/useSkillDetailsPanelData.js +39 -39
  10. package/catalog/useSkillItemDetails.js +17 -13
  11. package/catalog.d.ts +86 -19
  12. package/catalog.js +6 -5
  13. package/conversation/conversation-transfer/queue.js +8 -5
  14. package/conversation/create-chat-stream-api.js +30 -21
  15. package/conversation/stage.js +23 -0
  16. package/conversation/useAttachmentUpload/useAttachmentUpload.js +12 -5
  17. package/conversation/useConversationImport/useConversationImport.js +1 -1
  18. package/conversation/useConversationPanelItems/useConversationPanelItems.js +2 -3
  19. package/conversation/useConversationScroll/useConversationScroll.js +68 -64
  20. package/conversation/useConversationStream/apply-chunk.js +1 -1
  21. package/conversation/useConversationStream/generation-resume.js +75 -63
  22. package/conversation/useConversationStream/useConversationStream.js +145 -102
  23. package/conversation-overlay.d.ts +7 -0
  24. package/conversation-overlay.js +2 -0
  25. package/conversation-sources/useConversationSources/useConversationSources.js +31 -24
  26. package/conversation-sources.d.ts +1 -1
  27. package/conversation.d.ts +147 -15
  28. package/conversation.js +31 -30
  29. package/file-manager-canvas.d.ts +398 -0
  30. package/file-manager-canvas.js +2 -0
  31. package/file-manager.d.ts +71 -330
  32. package/file-manager.js +15 -15
  33. package/files/attachment-canvas.js +51 -13
  34. package/files/attachment-types.js +14 -13
  35. package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.js +1 -5
  36. package/files/useFileAttachmentPicker/useFileAttachmentPicker.js +43 -0
  37. package/index.d.ts +784 -57
  38. package/index.js +123 -111
  39. package/mcp-apps/useMcpAppHostAdapter/useMcpAppHostAdapter.js +7 -5
  40. package/mcp-apps/useMcpAppHostContext/useMcpAppHostContext.js +1 -1
  41. package/mcp-apps/useMcpAppTools/useMcpAppTools.js +1 -1
  42. package/mcp-apps/useOpenMcpAppCanvas/useOpenMcpAppCanvas.js +25 -23
  43. package/mcp-apps.d.ts +8 -6
  44. package/package.json +37 -18
  45. package/scheduled-task/scheduled-task-description.js +77 -0
  46. package/scheduled-task/scheduled-task-preparation.js +24 -0
  47. package/scheduled-task/scheduled-task-trigger.js +7 -2
  48. package/scheduled-task/scheduled-tasks-api-client.js +19 -0
  49. package/scheduled-task/use-scheduled-task-runs.js +82 -0
  50. package/scheduled-task/use-scheduled-tasks.js +93 -0
  51. package/scheduled-tasks.d.ts +180 -3
  52. package/scheduled-tasks.js +7 -2
  53. package/skill/skill.js +10 -7
  54. package/skill/useSkillArchiveImport/useSkillArchiveImport.js +75 -0
  55. package/skill/useSkillEditorLoad.js +29 -28
  56. package/skill/useSkillEditorSubmit.js +93 -75
  57. package/skill-editor.d.ts +110 -1
  58. package/skill-editor.js +9 -8
  59. package/usage/map-usage-data-to-dashboard.js +66 -0
  60. package/usage/map-user-usage-to-model-limits.js +160 -0
  61. package/usage.d.ts +120 -0
  62. package/usage.js +3 -0
  63. package/utils.d.ts +3 -1
@@ -1,16 +1,17 @@
1
1
  import { safeDecodeURI as e } from "../../shared/string-utils.js";
2
- import { getConversationPath as t } from "./conversation-path.js";
3
- import { applyChunkToMessages as n } from "./apply-chunk.js";
4
- import { restoreBufferedMessage as r } from "./buffered-generation.js";
5
- import { MessageRole as i } from "@epam/ai-dial-chat-shared";
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 a = (e) => {
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
- }, o = (e) => {
11
+ }, c = (e) => {
11
12
  let t = e.messages[e.messages.length - 1];
12
- return !!t && t.role === i.Assistant && !a(t) && t.streamErrorMessage == null && !t.wasStoppedByUser;
13
- }, s = 300 * 1e3, c = "awaiting-resume", l = async (e, t) => {
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
- }, u = ({ transport: i, setConversation: a, conversationRef: u, resumingPathsRef: d, bufferedGenerationsRef: f, addStreamingPath: p, removeStreamingPath: m, isPathDisplayed: h }) => (g, _) => {
43
- if (!o(_)) return;
44
- let v = t(g);
45
- if (d.current.has(v)) return;
46
- d.current.add(v), p(v);
47
- let y = _.messages.length - 1, b = (e) => {
48
- d.current.delete(v), m(v), f.current.delete(v), e && h(v) && (a(e), u.current = e);
49
- }, x = async () => {
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
- b(await i.getConversation(e(g)));
72
+ T(await o.getConversation(e(t)));
52
73
  } catch {
53
- b();
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
- h(v) && a((e) => {
73
- if (!e) return e;
74
- let t = f.current.get(v);
75
- if (t?.generationId !== c) return e;
76
- let n = r(e, t);
77
- return u.current = n, n;
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
- }, w = async () => {
80
- let t = new AbortController(), n;
90
+ }, k = async () => {
91
+ let n = new AbortController(), r;
81
92
  try {
82
- n = await i.watchConversation(v, t.signal);
93
+ r = await o.watchConversation(x, n.signal);
83
94
  } catch {
84
- await x();
95
+ await E();
85
96
  return;
86
97
  }
87
- let r = !1, a = window.setTimeout(() => {
88
- t.abort();
89
- }, s);
98
+ let i = !1, a = window.setTimeout(() => {
99
+ n.abort();
100
+ }, l);
90
101
  try {
91
- await l(n, async (t) => {
92
- if (t?.action !== "UPDATE") return !1;
102
+ await d(r, async (n) => {
103
+ if (n?.action !== "UPDATE") return !1;
93
104
  try {
94
- let t = await i.getConversation(e(g));
95
- if (!o(t)) return b(t), r = !0, !0;
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
- r || await x();
103
- }, T = async () => {
113
+ i || await E();
114
+ }, A = async () => {
104
115
  let e = new AbortController(), t;
105
116
  try {
106
- t = await i.attachToGeneration(v, e.signal);
117
+ t = await o.attachToGeneration(x, e.signal);
107
118
  } catch {
108
119
  return !1;
109
120
  }
110
- let n = !1;
111
- return await l(t, (e) => {
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 S(e.message), !1;
114
- case "chunk": return C(e.chunk), !1;
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
- }), n ? (await x(), !0) : !1;
131
+ }), r ? (i ? T(void 0, !0) : await E(), !0) : !w();
120
132
  };
121
133
  (async () => {
122
- await T() || await w();
134
+ await A() || await k();
123
135
  })();
124
136
  };
125
137
  //#endregion
126
- export { u as createResumeIfAwaitingGeneration, o as isAwaitingGenerationResume };
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, GenerationConflictError 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 { createResumeIfAwaitingGeneration as o } from "./generation-resume.js";
7
- import { generateUUID as s } from "@epam/ai-dial-chat-shared";
8
- import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
9
- import { SendCompletionDtoModeEnum as p } from "@epam/ai-dial-chat-api-client";
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 m = 2e4, h = ({ conversationId: h, state: { setConversation: g, conversationRef: _ }, transport: v, generation: { startGeneration: y, completeGeneration: b }, channel: x, overlay: S, onStopError: C, generationConflictMessage: w = t }) => {
12
- let [T, E] = f(() => /* @__PURE__ */ new Set()), [D, O] = f(null), k = d(null), A = d(null), j = d(/* @__PURE__ */ new Set()), M = d(/* @__PURE__ */ new Map()), N = d(/* @__PURE__ */ new Set()), P = d(/* @__PURE__ */ new Map()), F = d(h);
13
- l(() => {
14
- F.current = h;
15
- }, [h]);
16
- let I = c((e) => r(F.current ?? "") === e, []), L = c((e) => {
17
- E((t) => {
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
- }, []), R = c((e) => {
23
- E((t) => {
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
- }, []), z = c((t, o, c, l, u, d, f = p.Append) => {
29
- let h = d ?? s(), C = r(t);
30
- k.current = h, A.current = C, P.current.set(C, h), O(C);
31
- let T;
32
- f === p.Regenerate ? T = c : f === p.Edit && (T = c - 1);
33
- let E = () => P.current.get(C) !== h, D = y(C, h), j = _.current?.messages[c];
34
- j ? M.current.set(C, {
35
- generationId: h,
36
- messageIndex: c,
37
- message: j
38
- }) : M.current.delete(C), L(C), S?.notifyGenerationStart?.(), x?.ensureConnected();
39
- let F = {
40
- signal: D.signal,
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 (k.current !== h) return;
43
- let t = M.current.get(C);
44
- if (t?.generationId === h) {
45
- let n = i([t.message], 0, e);
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
- I(C) && g((t) => {
63
+ U(_) && a((t) => {
49
64
  if (!t) return t;
50
- let n = M.current.get(C), r;
51
- if (n?.generationId === h) r = a(t, n);
65
+ let n = z.current.get(_), i;
66
+ if (n?.generationId === g) i = c(t, n);
52
67
  else {
53
- let n = i(t.messages, c, e);
68
+ let n = s(t.messages, r, e);
54
69
  if (!n) return t;
55
- r = {
70
+ i = {
56
71
  ...t,
57
72
  messages: n
58
73
  };
59
74
  }
60
- return _.current = r, r;
75
+ return x.current = i, i;
61
76
  });
62
77
  },
63
78
  onComplete: async () => {
64
- if (M.current.get(C)?.generationId === h && M.current.delete(C), E() || R(C), k.current === h && (k.current = null, A.current = null, O(null)), b(C, h), x?.notifyGenerationSettled?.(), N.current.has(h) ? N.current.delete(h) : E() || S?.notifyGenerationEnd?.(), !E() && I(C)) try {
65
- let n = await v.getConversation(e(t));
66
- if (E() || !I(C)) return;
67
- g(n), _.current = n;
68
- } catch {}
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
- let t = M.current.get(C), r = t?.generationId === h ? t : void 0;
72
- if (r && M.current.delete(C), E() || R(C), k.current === h && (k.current = null, A.current = null, O(null)), b(C, h), x?.notifyGenerationSettled?.(), E() || !I(C)) return;
73
- let i = e instanceof n ? w : e.message;
74
- g((e) => {
75
- if (!e) return e;
76
- let t = r?.generationId === h ? a(e, r) : e, n = {
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 === c ? {
114
+ messages: t.messages.map((e, t) => t === r ? {
79
115
  ...e,
80
- streamErrorMessage: i
116
+ streamErrorMessage: o
81
117
  } : e)
82
118
  };
83
- return _.current = n, n;
119
+ return x.current = i, i;
84
120
  });
85
121
  }
86
122
  };
87
123
  (async () => {
88
124
  try {
89
- let e = x?.channelId ?? await x?.waitForChannel(m) ?? void 0;
90
- v.streamCompletion(C, o, l, F, u, h, f, T, e);
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
- F.onError(e instanceof Error ? e : Error(String(e)));
132
+ H.onError(e instanceof Error ? e : Error(String(e)));
93
133
  }
94
134
  })();
95
135
  }, [
96
- y,
97
- b,
98
- L,
99
- R,
100
- I,
101
- x?.channelId,
102
- x?.ensureConnected,
103
- x?.waitForChannel,
104
- x?.notifyGenerationSettled,
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
- v,
107
- w
108
- ]), B = c((e, t) => {
109
- let n = r(e), i = M.current.get(n);
110
- return i ? a(t, i) : t;
111
- }, []), V = c(() => {
112
- let e = k.current;
113
- if (!e || !h) return;
114
- let t = r(h);
115
- A.current === t && (N.current.add(e), S?.notifyStopGenerating?.(), v.stopCompletion({
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
- C?.(t);
161
+ D?.(t);
121
162
  }));
122
163
  }, [
123
- h,
124
- C,
125
- S,
126
- v
127
- ]), H = u(() => o({
128
- transport: v,
129
- setConversation: g,
130
- conversationRef: _,
131
- resumingPathsRef: j,
132
- bufferedGenerationsRef: M,
133
- addStreamingPath: L,
134
- removeStreamingPath: R,
135
- isPathDisplayed: I
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
- L,
138
- R,
139
- I,
140
- v
141
- ]), U = h != null && T.has(r(h)), W = h == null ? null : r(h);
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: z,
144
- handleStop: V,
145
- resumeIfAwaitingGeneration: H,
146
- restoreBufferedGeneration: B,
147
- isStreaming: U,
148
- canStopStreaming: W != null && D === W
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 { h as useConversationStream };
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 { }
@@ -0,0 +1,2 @@
1
+ import { toOverlayMessages as e } from "./conversation/overlay-messages.js";
2
+ export { e as toOverlayMessages };
@@ -1,35 +1,42 @@
1
1
  import { MessageRole as e, messageAttachmentToDisplayAttachment as t } from "@epam/ai-dial-chat-shared";
2
- import { isReferenceOnlyAttachment as n, resolveMessageAnnotations as r } from "@epam/ai-dial-quotations";
3
- import { useMemo as i } from "react";
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 a = {}, o = (o, s = a) => i(() => {
6
- let i = [], a = [], c = [], l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
7
- for (let f of o) {
8
- let o = f.custom_content?.attachments;
9
- if (f.role === e.User) for (let e of o ?? []) {
10
- let n = t(e, s);
11
- u.has(n.id) || (u.add(n.id), i.push(n));
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 (f.role === e.Assistant) {
14
- let e = o?.filter((e) => !n(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, s);
17
- d.has(e.id) || (d.add(e.id), a.push(e));
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 o ?? []) {
20
- if (!n(e)) continue;
24
+ for (let e of n ?? []) {
25
+ if (!r(e)) continue;
21
26
  let t = e.reference_url;
22
- l.has(t) || (l.add(t), c.push({
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 r(f)) {
34
+ for (let e of a(p)) {
30
35
  let t = e?.body?.source?.attachment, n = t?.url;
31
- !n || l.has(n) || (l.add(n), c.push({
32
- url: n,
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: i,
42
- generated: a,
43
- sources: c
48
+ uploaded: o,
49
+ generated: s,
50
+ sources: l
44
51
  };
45
- }, [o, s]);
52
+ }, [n, i]);
46
53
  //#endregion
47
- export { o as useConversationSources };
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