@epam/ai-dial-chat-hooks 1.3.0-dev.152 → 1.3.0-dev.157

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.
@@ -42,6 +42,12 @@ export interface ResumeGenerationOptions {
42
42
  onSettled?: () => void;
43
43
  /** Resumes even though the path is already in `resumingPathsRef`, for a caller that reserved it itself. */
44
44
  skipDedupe?: boolean;
45
+ /**
46
+ * Takes the `generationId` the attach `snapshot` carries so Stop can reach a resumed
47
+ * non-background generation. Set only by the public entry point: stream recovery
48
+ * already knows its local id, and the conflict handover keeps Stop unavailable.
49
+ */
50
+ trackAttachGenerationId?: boolean;
45
51
  }
46
52
  /** Host-owned state {@link createResumeIfAwaitingGeneration} reads/writes through. */
47
53
  export interface ResumeIfAwaitingGenerationDeps {
@@ -66,6 +72,13 @@ export interface ResumeIfAwaitingGenerationDeps {
66
72
  * its id is removed when the resume settles.
67
73
  */
68
74
  stoppedGenerationIdsRef?: MutableRefObject<Set<string>>;
75
+ /** Records the id an attach `snapshot` supplied for `path`, so the host can offer Stop for it. */
76
+ rememberResumedGenerationId?: (path: string, generationId: string) => void;
77
+ /**
78
+ * Drops that id again once the resume no longer owns an attached generation. Compare-and-clear:
79
+ * the host removes the entry only while it still holds `generationId`.
80
+ */
81
+ forgetResumedGenerationId?: (path: string, generationId: string) => void;
69
82
  }
70
83
  /**
71
84
  * Builds `resumeIfAwaitingGeneration`: a hard refresh mid-generation loads a
@@ -81,5 +94,5 @@ export interface ResumeIfAwaitingGenerationDeps {
81
94
  * backend's finalize save resolves the placeholder whenever attach is
82
95
  * unavailable or ends without a terminal event.
83
96
  */
84
- export declare const createResumeIfAwaitingGeneration: ({ transport, setConversation, conversationRef, resumingPathsRef, bufferedGenerationsRef, addStreamingPath, removeStreamingPath, isPathDisplayed, generationPersistenceErrorMessage, frameScheduler, stoppedGenerationIdsRef, onReloadError, onReloadSuccess, }: ResumeIfAwaitingGenerationDeps) => (currentConversationId: string, conversation: Conversation, options?: ResumeGenerationOptions) => void;
97
+ export declare const createResumeIfAwaitingGeneration: ({ transport, setConversation, conversationRef, resumingPathsRef, bufferedGenerationsRef, addStreamingPath, removeStreamingPath, isPathDisplayed, generationPersistenceErrorMessage, frameScheduler, stoppedGenerationIdsRef, rememberResumedGenerationId, forgetResumedGenerationId, onReloadError, onReloadSuccess, }: ResumeIfAwaitingGenerationDeps) => (currentConversationId: string, conversation: Conversation, options?: ResumeGenerationOptions) => void;
85
98
  //# sourceMappingURL=generation-resume.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generation-resume.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationStream/generation-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,OAAO,EAEb,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAOxE,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAE3E;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,KAAG,OAWtD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAC5C,cAAc,YAAY,KACzB,MAKA,CAAC;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,GACrC,cAAc,YAAY,KACzB,OAUF,CAAC;AA6BF,eAAO,MAAM,0BAA0B,UAAkC,CAAC;AAe1E;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,GACvC,MAAM,MAAM,OAAO,CAAC,YAAY,CAAC,EACjC,YAAY,MAAM,OAAO,EACzB,YAAY,CAAC,YAAY,EAAE,YAAY,KAAK,OAAO,KAClD,OAAO,CAAC,Y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;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,GAAI,gQAc9C,8BAA8B,MAE7B,uBAAuB,MAAM,EAC7B,cAAc,YAAY,EAC1B,UAAS,uBAA4B,KACpC,IA8QJ,CAAC"}
1
+ {"version":3,"file":"generation-resume.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationStream/generation-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,OAAO,EAEb,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAOxE,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAE3E;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,KAAG,OAWtD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAC5C,cAAc,YAAY,KACzB,MAKA,CAAC;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,GACrC,cAAc,YAAY,KACzB,OAUF,CAAC;AA6BF,eAAO,MAAM,0BAA0B,UAAkC,CAAC;AAe1E;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,GACvC,MAAM,MAAM,OAAO,CAAC,YAAY,CAAC,EACjC,YAAY,MAAM,OAAO,EACzB,YAAY,CAAC,YAAY,EAAE,YAAY,KAAK,OAAO,KAClD,OAAO,CAAC,YAAY,GAAG,IAAI,CAiB7B,CAAC;AAgEF,sGAAsG;AACtG,MAAM,WAAW,uBAAuB;IACtC,qIAAqI;IACrI,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oGAAoG;IACpG,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,2GAA2G;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,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1E;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,GAAI,wTAgB9C,8BAA8B,MAE7B,uBAAuB,MAAM,EAC7B,cAAc,YAAY,EAC1B,UAAS,uBAA4B,KACpC,IA6SJ,CAAC"}
@@ -63,67 +63,76 @@ var c = (e) => {
63
63
  } catch {} finally {
64
64
  n.releaseLock();
65
65
  }
66
- }, _ = ({ transport: o, setConversation: s, conversationRef: p, resumingPathsRef: m, bufferedGenerationsRef: h, addStreamingPath: _, removeStreamingPath: v, isPathDisplayed: y, generationPersistenceErrorMessage: b = t, frameScheduler: x, stoppedGenerationIdsRef: S, onReloadError: C, onReloadSuccess: w }) => (t, T, E = {}) => {
67
- if (!u(T)) {
68
- E.onSettled?.();
66
+ }, _ = ({ transport: o, setConversation: s, conversationRef: p, resumingPathsRef: m, bufferedGenerationsRef: h, addStreamingPath: _, removeStreamingPath: v, isPathDisplayed: y, generationPersistenceErrorMessage: b = t, frameScheduler: x, stoppedGenerationIdsRef: S, rememberResumedGenerationId: C, forgetResumedGenerationId: w, onReloadError: T, onReloadSuccess: E }) => (t, D, O = {}) => {
67
+ if (!u(D)) {
68
+ O.onSettled?.();
69
69
  return;
70
70
  }
71
- let D = r(t);
72
- if (!E.skipDedupe && m.current.has(D)) return;
73
- m.current.add(D), _(D);
74
- let O = l(T), k = O !== -1, A = k ? O : T.messages.length - 1, j = {
71
+ let k = r(t);
72
+ if (!O.skipDedupe && m.current.has(k)) return;
73
+ m.current.add(k), _(k);
74
+ let A = l(D), j = A !== -1, M = j ? A : D.messages.length - 1, N = {
75
75
  generationId: f,
76
- messageIndex: A,
77
- message: E.seedMessage ?? T.messages[A]
76
+ messageIndex: M,
77
+ message: O.seedMessage ?? D.messages[M]
78
78
  };
79
- h.current.set(D, j);
80
- let M = () => h.current.get(D) === j, N = k ? T.messages[A].backgroundGeneration?.generationId : void 0, P = () => N != null && (S?.current.has(N) ?? !1), F = (e, t = !1) => {
81
- if (x?.flush(D), N != null && S?.current.delete(N), !M()) return;
82
- m.current.delete(D), v(D);
83
- let n = !k && e && e.messages.length - 1 === A && u(e) && c(j.message);
84
- t || n ? (j.message = {
85
- ...j.message,
79
+ h.current.set(k, N);
80
+ let P = () => h.current.get(k) === N, F = j ? D.messages[M].backgroundGeneration?.generationId : void 0, I, L = () => {
81
+ let e = F ?? I;
82
+ return e != null && (S?.current.has(e) ?? !1);
83
+ }, R = (e) => {
84
+ O.trackAttachGenerationId && !j && e != null && P() && (I = e, C?.(k, e));
85
+ }, z = () => {
86
+ if (I == null) return;
87
+ let e = I;
88
+ I = void 0, S?.current.delete(e), w?.(k, e);
89
+ }, B = (e, t = !1) => {
90
+ if (x?.flush(k), F != null && S?.current.delete(F), z(), !P()) return;
91
+ m.current.delete(k), v(k);
92
+ let n = !j && e && e.messages.length - 1 === M && u(e) && c(N.message);
93
+ t || n ? (N.message = {
94
+ ...N.message,
86
95
  streamErrorMessage: b
87
- }, y(D) && s((e) => {
88
- if (!e || !M() || !y(D)) return e;
89
- let t = a(e, j);
96
+ }, y(k) && s((e) => {
97
+ if (!e || !P() || !y(k)) return e;
98
+ let t = a(e, N);
90
99
  return p.current = t, t;
91
- })) : (h.current.delete(D), e && y(D) && (s(e), p.current = e));
92
- }, I = async () => {
93
- if (M()) try {
100
+ })) : (h.current.delete(k), e && y(k) && (s(e), p.current = e));
101
+ }, V = async () => {
102
+ if (P()) try {
94
103
  let n = await o.getConversation(e(t));
95
- if (!M()) return;
96
- w?.(D), F(n);
104
+ if (!P()) return;
105
+ E?.(k), B(n);
97
106
  } catch {
98
- if (!M()) return;
99
- x?.flush(D), m.current.delete(D), v(D), N != null && S?.current.delete(N), C?.(D, I, M);
107
+ if (!P()) return;
108
+ x?.flush(k), m.current.delete(k), v(k), F != null && S?.current.delete(F), z(), T?.(k, V, P);
100
109
  }
101
- }, L = (e) => {
102
- x?.cancel(D), M() && (j.message = e, y(D) && s((e) => {
103
- if (!e || !M() || !y(D)) return e;
104
- let t = a(e, j);
110
+ }, H = (e) => {
111
+ x?.cancel(k), P() && (N.message = e, y(k) && s((e) => {
112
+ if (!e || !P() || !y(k)) return e;
113
+ let t = a(e, N);
105
114
  return p.current = t, t;
106
115
  }));
107
- }, R = () => s((e) => {
108
- if (!e || !M() || !y(D)) return e;
109
- let t = a(e, j);
116
+ }, U = () => s((e) => {
117
+ if (!e || !P() || !y(k)) return e;
118
+ let t = a(e, N);
110
119
  return p.current = t, t;
111
- }), z = (e) => {
112
- if (!M() || P()) return;
113
- let t = i([j.message], 0, e);
114
- t && (j.message = t[0]), y(D) && (x ? x.schedule(D, R) : R());
115
- }, B = async () => {
120
+ }), W = (e) => {
121
+ if (!P() || L()) return;
122
+ let t = i([N.message], 0, e);
123
+ t && (N.message = t[0]), y(k) && (x ? x.schedule(k, U) : U());
124
+ }, G = async () => {
116
125
  let n = new AbortController(), r;
117
126
  try {
118
- r = await o.watchConversation(D, n.signal);
127
+ r = await o.watchConversation(k, n.signal);
119
128
  } catch {
120
- await I();
129
+ await V();
121
130
  return;
122
131
  }
123
132
  try {
124
133
  let i = await o.getConversation(e(t));
125
134
  if (!u(i)) {
126
- n.abort(), r.cancel().catch(() => void 0), F(i);
135
+ n.abort(), r.cancel().catch(() => void 0), B(i);
127
136
  return;
128
137
  }
129
138
  } catch {}
@@ -135,38 +144,38 @@ var c = (e) => {
135
144
  if (n?.action !== "UPDATE") return !1;
136
145
  try {
137
146
  let n = await o.getConversation(e(t));
138
- if (!u(n)) return F(n), i = !0, !0;
147
+ if (!u(n)) return B(n), i = !0, !0;
139
148
  } catch {}
140
149
  return !1;
141
150
  });
142
151
  } finally {
143
152
  clearTimeout(a);
144
153
  }
145
- i || await I();
146
- }, V = async () => {
154
+ i || await V();
155
+ }, K = async () => {
147
156
  let e = new AbortController(), t;
148
157
  try {
149
- t = await o.attachToGeneration(D, e.signal);
158
+ t = await o.attachToGeneration(k, e.signal);
150
159
  } catch {
151
160
  return !1;
152
161
  }
153
162
  let r = !1, i = !1;
154
163
  return await g(t, (e) => {
155
- if (!M()) return !0;
164
+ if (!P()) return !0;
156
165
  switch (e.type) {
157
- case "snapshot": return L(e.message), !1;
158
- case "chunk": return z(e.chunk), !1;
166
+ case "snapshot": return R(e.generationId), H(e.message), !1;
167
+ case "chunk": return W(e.chunk), !1;
159
168
  case "done":
160
169
  case "error":
161
170
  case "stopped": return i = e.type === "error" && e.errorType === n.type, r = !0, !0;
162
171
  }
163
- }), r ? (i ? F(void 0, !0) : await I(), !0) : !M();
172
+ }), r ? (i ? B(void 0, !0) : await V(), !0) : (z(), !P());
164
173
  };
165
174
  (async () => {
166
175
  try {
167
- await V() || await B();
176
+ await K() || await G();
168
177
  } finally {
169
- E.onSettled?.();
178
+ O.onSettled?.();
170
179
  }
171
180
  })();
172
181
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useConversationStream.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationStream/useConversationStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,oBAAoB,EAEzB,KAAK,WAAW,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,cAAc,EAMpB,MAAM,OAAO,CAAC;AA6Cf,gFAAgF;AAChF,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACtC,UAAU,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC1C,6GAA6G;IAC7G,gBAAgB,CAC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BD,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,qDAAqD;AACrD,MAAM,WAAW,2BAA2B;IAC1C,WAAW,EAAE,CACX,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,oBAAoB,EACpC,YAAY,CAAC,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,yBAAyB,EAChC,OAAO,CAAC,EAAE,kBAAkB,KACzB,IAAI,CAAC;IACV,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,0BAA0B,EAAE,CAC1B,qBAAqB,EAAE,MAAM,EAC7B,YAAY,EAAE,YAAY,KACvB,IAAI,CAAC;IACV,+GAA+G;IAC/G,yBAAyB,EAAE,CACzB,qBAAqB,EAAE,MAAM,EAC7B,YAAY,EAAE,YAAY,KACvB,YAAY,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iEAAiE;IACjE,0BAA0B,EAAE,OAAO,CAAC;IACpC,iDAAiD;IACjD,uBAAuB,EAAE,OAAO,CAAC;IACjC,yEAAyE;IACzE,uBAAuB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAkBD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAAI,mQAYnC,2BAA2B,KAAG,2BAm6BhC,CAAC"}
1
+ {"version":3,"file":"useConversationStream.d.ts","sourceRoot":"","sources":["../../../src/conversation/useConversationStream/useConversationStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,oBAAoB,EAEzB,KAAK,WAAW,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,QAAQ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M,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAkBD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAAI,mQAYnC,2BAA2B,KAAG,2BA88BhC,CAAC"}
@@ -5,166 +5,174 @@ import { applyChunkToMessages as l } from "./apply-chunk.js";
5
5
  import { restoreBufferedMessage as u } from "./buffered-generation.js";
6
6
  import { createResumeIfAwaitingGeneration as ee, fetchConversationForRecovery as te, findPendingBackgroundMessageIndex as d, hasGeneratedPayload as ne, isAwaitingGenerationResume as f } from "./generation-resume.js";
7
7
  import { createFrameScheduler as re } from "./frame-scheduler.js";
8
- import { MessageRole as p, generateUUID as ie } from "@epam/ai-dial-chat-shared";
9
- import { useCallback as m, useEffect as h, useMemo as g, useRef as _, useState as v } from "react";
10
- import { SendCompletionDtoModeEnum as y } from "@epam/ai-dial-chat-api-client";
8
+ import { MessageRole as ie, generateUUID as ae } from "@epam/ai-dial-chat-shared";
9
+ import { useCallback as p, useEffect as m, useMemo as h, useRef as g, useState as _ } from "react";
10
+ import { SendCompletionDtoModeEnum as oe } from "@epam/ai-dial-chat-api-client";
11
11
  //#region src/conversation/useConversationStream/useConversationStream.ts
12
- var ae = 2e4, oe = 401, b = 404, x = 2e3, S = 100, se = (e, t, n) => e instanceof i ? n : e instanceof r ? t : e instanceof s ? e.message : "", C = (e) => {
12
+ var se = 2e4, ce = 401, v = 404, y = 2e3, b = 100, le = (e, t, n) => e instanceof i ? n : e instanceof r ? t : e instanceof s ? e.message : "", x = (e) => {
13
13
  if (!e) return;
14
14
  let t = d(e);
15
15
  return t === -1 ? void 0 : e.messages[t].backgroundGeneration?.generationId;
16
- }, w = ({ conversationId: s, state: { setConversation: w, conversationRef: T }, transport: E, generation: { startGeneration: ce, completeGeneration: le }, channel: D, overlay: O, onStopError: ue, generationConflictMessage: de = t, generationPersistenceErrorMessage: k = n, onStreamError: A, batchChunksPerFrame: j = !1 }) => {
17
- let fe = _(A);
18
- h(() => {
19
- fe.current = A;
20
- }, [A]);
21
- let pe = _(j);
22
- h(() => {
23
- pe.current = j;
24
- }, [j]);
25
- let [M] = v(re), [N, P] = v(() => /* @__PURE__ */ new Set()), F = _(N);
26
- F.current = N;
27
- let [I, me] = v(() => /* @__PURE__ */ new Set()), L = _(/* @__PURE__ */ new Map()), R = _(/* @__PURE__ */ new Set()), z = _(/* @__PURE__ */ new Map()), B = _(/* @__PURE__ */ new Set()), V = _(/* @__PURE__ */ new Set()), he = _(/* @__PURE__ */ new Map()), H = _(!0), U = _(/* @__PURE__ */ new Map()), [ge, W] = v(U.current), G = _(/* @__PURE__ */ new Set()), [_e, ve] = v(G.current);
28
- h(() => (H.current = !0, () => {
29
- H.current = !1;
16
+ }, S = ({ conversationId: s, state: { setConversation: S, conversationRef: C }, transport: w, generation: { startGeneration: ue, completeGeneration: de }, channel: T, overlay: E, onStopError: fe, generationConflictMessage: pe = t, generationPersistenceErrorMessage: D = n, onStreamError: O, batchChunksPerFrame: k = !1 }) => {
17
+ let me = g(O);
18
+ m(() => {
19
+ me.current = O;
20
+ }, [O]);
21
+ let he = g(k);
22
+ m(() => {
23
+ he.current = k;
24
+ }, [k]);
25
+ let [A] = _(re), [j, M] = _(() => /* @__PURE__ */ new Set()), N = g(j);
26
+ N.current = j;
27
+ let [P, ge] = _(() => /* @__PURE__ */ new Set()), F = g(/* @__PURE__ */ new Map()), I = g(/* @__PURE__ */ new Map()), L = g(/* @__PURE__ */ new Set()), R = g(/* @__PURE__ */ new Map()), z = g(/* @__PURE__ */ new Set()), B = g(/* @__PURE__ */ new Set()), _e = g(/* @__PURE__ */ new Map()), V = g(!0), H = g(/* @__PURE__ */ new Map()), [U, ve] = _(H.current), W = g(/* @__PURE__ */ new Set()), [ye, be] = _(W.current);
28
+ m(() => (V.current = !0, () => {
29
+ V.current = !1;
30
30
  }), []);
31
- let K = m((e) => {
32
- if (!U.current.has(e)) return;
33
- let t = new Map(U.current);
34
- t.delete(e), U.current = t, H.current && W(t);
35
- }, []), q = m((e, t, n) => {
36
- if (!H.current || !n()) return;
37
- let r = new Map(U.current);
31
+ let G = p((e) => {
32
+ if (!H.current.has(e)) return;
33
+ let t = new Map(H.current);
34
+ t.delete(e), H.current = t, V.current && ve(t);
35
+ }, []), K = p((e, t, n) => {
36
+ if (!V.current || !n()) return;
37
+ let r = new Map(H.current);
38
38
  r.set(e, {
39
39
  retry: t,
40
40
  isCurrent: n
41
- }), U.current = r, W(r);
42
- }, []), ye = m(async () => {
41
+ }), H.current = r, ve(r);
42
+ }, []), xe = p(async () => {
43
43
  if (!s) return;
44
- let e = U.current.get(c(s));
45
- if (e && e.isCurrent() && !G.current.has(e)) {
46
- G.current.add(e), ve(new Set(G.current));
44
+ let e = H.current.get(c(s));
45
+ if (e && e.isCurrent() && !W.current.has(e)) {
46
+ W.current.add(e), be(new Set(W.current));
47
47
  try {
48
48
  await e.retry();
49
49
  } finally {
50
- G.current.delete(e), H.current && ve(new Set(G.current));
50
+ W.current.delete(e), V.current && be(new Set(W.current));
51
51
  }
52
52
  }
53
- }, [s]), be = _(s);
54
- h(() => (be.current = s, () => M.cancelAll()), [s, M]);
55
- let J = m((e) => H.current && c(be.current ?? "") === e, []), Y = m((e) => {
56
- K(e), P((t) => {
53
+ }, [s]), Se = g(s);
54
+ m(() => (Se.current = s, () => A.cancelAll()), [s, A]);
55
+ let q = p((e) => V.current && c(Se.current ?? "") === e, []), J = p((e) => {
56
+ G(e), M((t) => {
57
57
  if (t.has(e)) return t;
58
58
  let n = new Set(t);
59
59
  return n.add(e), n;
60
60
  });
61
- }, [K]), X = m((e) => {
62
- P((t) => {
61
+ }, [G]), Y = p((e) => {
62
+ M((t) => {
63
63
  if (!t.has(e)) return t;
64
64
  let n = new Set(t);
65
65
  return n.delete(e), n;
66
66
  });
67
- }, []), Z = m((e, t) => {
68
- me((n) => {
67
+ }, []), X = p((e, t) => {
68
+ ge((n) => {
69
69
  if (n.has(e) === t) return n;
70
70
  let r = new Set(n);
71
71
  return t ? r.add(e) : r.delete(e), r;
72
72
  });
73
- }, []), xe = m((e, t) => {
74
- L.current.get(e) === t && (L.current.delete(e), Z(e, !1));
75
- }, [Z]), Q = g(() => ee({
76
- transport: E,
77
- setConversation: w,
78
- conversationRef: T,
79
- resumingPathsRef: R,
80
- bufferedGenerationsRef: z,
81
- addStreamingPath: Y,
82
- removeStreamingPath: X,
83
- isPathDisplayed: J,
84
- generationPersistenceErrorMessage: k,
85
- frameScheduler: j ? M : void 0,
86
- stoppedGenerationIdsRef: B,
87
- onReloadError: q,
88
- onReloadSuccess: K
73
+ }, []), Ce = p((e, t) => {
74
+ F.current.get(e) === t && (F.current.delete(e), X(e, !1));
75
+ }, [X]), we = p((e, t) => {
76
+ F.current.has(e) || (I.current.set(e, t), X(e, !0));
77
+ }, [X]), Te = p((e, t) => {
78
+ I.current.get(e) === t && (I.current.delete(e), F.current.has(e) || X(e, !1));
79
+ }, [X]), Z = h(() => ee({
80
+ transport: w,
81
+ setConversation: S,
82
+ conversationRef: C,
83
+ resumingPathsRef: L,
84
+ bufferedGenerationsRef: R,
85
+ addStreamingPath: J,
86
+ removeStreamingPath: Y,
87
+ isPathDisplayed: q,
88
+ generationPersistenceErrorMessage: D,
89
+ frameScheduler: k ? A : void 0,
90
+ stoppedGenerationIdsRef: z,
91
+ rememberResumedGenerationId: we,
92
+ forgetResumedGenerationId: Te,
93
+ onReloadError: K,
94
+ onReloadSuccess: G
89
95
  }), [
90
- Y,
91
- X,
92
96
  J,
93
- E,
94
- k,
95
- j,
96
- M,
97
+ Y,
97
98
  q,
98
- K
99
- ]), Se = m((t, n, a, s, ee, re, m = y.Append, h = {}) => {
100
- let g = re ?? ie(), _ = c(t);
101
- M.flush(_), R.current.delete(_), L.current.set(_, g), he.current.set(_, g), Z(_, !0);
102
- let v;
103
- m === y.Regenerate ? v = a : m === y.Edit && (v = a - 1);
104
- let b = () => he.current.get(_) !== g, x = ce(_, g), S = T.current?.messages[a];
105
- S ? z.current.set(_, {
106
- generationId: g,
99
+ w,
100
+ D,
101
+ k,
102
+ A,
103
+ we,
104
+ Te,
105
+ K,
106
+ G
107
+ ]), Ee = p((t, n, a, s, ee, re, p = oe.Append, m = {}) => {
108
+ let h = re ?? ae(), g = c(t);
109
+ A.flush(g), L.current.delete(g), F.current.set(g, h), _e.current.set(g, h), X(g, !0);
110
+ let _;
111
+ p === oe.Regenerate ? _ = a : p === oe.Edit && (_ = a - 1);
112
+ let v = () => _e.current.get(g) !== h, y = ue(g, h), b = C.current?.messages[a];
113
+ b ? R.current.set(g, {
114
+ generationId: h,
107
115
  messageIndex: a,
108
- message: S
109
- }) : z.current.delete(_), Y(_), O?.notifyGenerationStart?.(), D?.ensureConnected();
110
- let C = () => {
111
- b() || X(_), xe(_, g), le(_, g), D?.notifyGenerationSettled?.();
112
- }, ue = () => {
113
- if (b()) return;
114
- let e = z.current.get(_);
115
- e && e.generationId === g && (e.message = {
116
+ message: b
117
+ }) : R.current.delete(g), J(g), E?.notifyGenerationStart?.(), T?.ensureConnected();
118
+ let x = () => {
119
+ v() || Y(g), Ce(g, h), de(g, h), T?.notifyGenerationSettled?.();
120
+ }, fe = () => {
121
+ if (v()) return;
122
+ let e = R.current.get(g);
123
+ e && e.generationId === h && (e.message = {
116
124
  ...e.message,
117
- streamErrorMessage: k
118
- }, fe.current?.(new i()), J(_) && w((t) => {
119
- if (!t || b() || !J(_)) return t;
125
+ streamErrorMessage: D
126
+ }, me.current?.(new i()), q(g) && S((t) => {
127
+ if (!t || v() || !q(g)) return t;
120
128
  let n = u(t, e);
121
- return T.current = n, n;
129
+ return C.current = n, n;
122
130
  }));
123
- }, A = z.current.get(_), j = () => H.current && !b() && z.current.get(_) === A, N = async () => {
124
- if (j()) {
125
- if (!J(_)) A && z.current.delete(_);
131
+ }, O = R.current.get(g), k = () => V.current && !v() && R.current.get(g) === O, j = async () => {
132
+ if (k()) {
133
+ if (!q(g)) O && R.current.delete(g);
126
134
  else try {
127
- let n = await E.getConversation(e(t));
128
- if (!j()) return;
129
- if (K(_), !J(_)) {
130
- A && z.current.delete(_);
135
+ let n = await w.getConversation(e(t));
136
+ if (!k()) return;
137
+ if (G(g), !q(g)) {
138
+ O && R.current.delete(g);
131
139
  return;
132
140
  }
133
141
  if (d(n) !== -1) {
134
- Q(t, n, { seedMessage: A?.message });
142
+ Z(t, n, { seedMessage: O?.message });
135
143
  return;
136
144
  }
137
- if (A && A.messageIndex === n.messages.length - 1 && f(n) && ne(A.message)) {
138
- ue();
145
+ if (O && O.messageIndex === n.messages.length - 1 && f(n) && ne(O.message)) {
146
+ fe();
139
147
  return;
140
148
  }
141
- A && z.current.delete(_), w(n), T.current = n;
149
+ O && R.current.delete(g), S(n), C.current = n;
142
150
  } catch {
143
- j() && q(_, N, j);
151
+ k() && K(g, j, k);
144
152
  }
145
153
  }
146
- }, P = {
147
- signal: x.signal,
154
+ }, M = {
155
+ signal: y.signal,
148
156
  onChunk: (e) => {
149
- if (b()) return;
150
- let t = z.current.get(_);
151
- if (t?.generationId === g) {
157
+ if (v()) return;
158
+ let t = R.current.get(g);
159
+ if (t?.generationId === h) {
152
160
  let n = l([t.message], 0, e);
153
161
  n && (t.message = n[0]);
154
162
  }
155
- J(_) && (pe.current && t?.generationId === g ? M.schedule(_, () => {
156
- let e = z.current.get(_);
157
- if (b() || !J(_) || e?.generationId !== g) return;
163
+ q(g) && (he.current && t?.generationId === h ? A.schedule(g, () => {
164
+ let e = R.current.get(g);
165
+ if (v() || !q(g) || e?.generationId !== h) return;
158
166
  let t = { ...e };
159
- w((e) => {
167
+ S((e) => {
160
168
  if (!e) return e;
161
169
  let n = u(e, t);
162
- return T.current = n, n;
170
+ return C.current = n, n;
163
171
  });
164
- }) : w((t) => {
172
+ }) : S((t) => {
165
173
  if (!t) return t;
166
- let n = z.current.get(_), r;
167
- if (n?.generationId === g) r = u(t, n);
174
+ let n = R.current.get(g), r;
175
+ if (n?.generationId === h) r = u(t, n);
168
176
  else {
169
177
  let n = l(t.messages, a, e);
170
178
  if (!n) return t;
@@ -173,157 +181,157 @@ var ae = 2e4, oe = 401, b = 404, x = 2e3, S = 100, se = (e, t, n) => e instanceo
173
181
  messages: n
174
182
  };
175
183
  }
176
- return T.current = r, r;
184
+ return C.current = r, r;
177
185
  }));
178
186
  },
179
187
  onComplete: async () => {
180
- M.flush(_), C(), B.current.has(g) ? B.current.delete(g) : b() || O?.notifyGenerationEnd?.(), await N();
188
+ A.flush(g), x(), z.current.has(h) ? z.current.delete(h) : v() || E?.notifyGenerationEnd?.(), await j();
181
189
  },
182
190
  onError: (e) => {
183
- M.flush(_), fe.current?.(e), e instanceof o && !b() ? U(e) : e instanceof r && h.resumeOnConflict && !b() ? ge(e) : F(e);
191
+ A.flush(g), me.current?.(e), e instanceof o && !v() ? B(e) : e instanceof r && m.resumeOnConflict && !v() ? H(e) : N(e);
184
192
  }
185
- }, F = (e) => {
186
- let t = z.current.get(_), n = t?.generationId === g ? t : void 0;
187
- n && !(e instanceof i) && z.current.delete(_), C(), n && E.saveConversation && e instanceof i && e.status === oe ? me(e, n, E.saveConversation.bind(E)) : I(e, n);
188
- }, I = (e, t) => {
193
+ }, N = (e) => {
194
+ let t = R.current.get(g), n = t?.generationId === h ? t : void 0;
195
+ n && !(e instanceof i) && R.current.delete(g), x(), n && w.saveConversation && e instanceof i && e.status === ce ? ge(e, n, w.saveConversation.bind(w)) : P(e, n);
196
+ }, P = (e, t) => {
189
197
  if (t && e instanceof i && (t.message = {
190
198
  ...t.message,
191
- streamErrorMessage: k
192
- }), b() || !J(_)) return;
193
- let n = se(e, de, k);
194
- w((e) => {
195
- if (!e || b() || !J(_)) return e;
196
- let r = t?.generationId === g ? u(e, t) : e, i = {
199
+ streamErrorMessage: D
200
+ }), v() || !q(g)) return;
201
+ let n = le(e, pe, D);
202
+ S((e) => {
203
+ if (!e || v() || !q(g)) return e;
204
+ let r = t?.generationId === h ? u(e, t) : e, i = {
197
205
  ...r,
198
206
  messages: r.messages.map((e, t) => t === a ? {
199
207
  ...e,
200
208
  streamErrorMessage: n
201
209
  } : e)
202
210
  };
203
- return T.current = i, i;
211
+ return C.current = i, i;
204
212
  });
205
- }, me = async (n, r, i) => {
206
- let a = () => H.current && !b() && z.current.get(_) === r;
213
+ }, ge = async (n, r, i) => {
214
+ let a = () => V.current && !v() && R.current.get(g) === r;
207
215
  try {
208
- let o = await E.getConversation(e(t));
216
+ let o = await w.getConversation(e(t));
209
217
  if (!a()) return;
210
218
  if (r.messageIndex !== o.messages.length - 1 || !f(o)) {
211
- I(n, r);
219
+ P(n, r);
212
220
  return;
213
221
  }
214
- let s = await i(_, u(o, r));
215
- if (!a() || (z.current.delete(_), !J(_))) return;
216
- w(s), T.current = s;
222
+ let s = await i(g, u(o, r));
223
+ if (!a() || (R.current.delete(g), !q(g))) return;
224
+ S(s), C.current = s;
217
225
  } catch {
218
- a() && I(n, r);
226
+ a() && P(n, r);
219
227
  }
220
- }, V = () => {
221
- C(), B.current.has(g) ? B.current.delete(g) : b() || O?.notifyGenerationEnd?.();
222
- }, U = async (n) => {
223
- R.current.add(_);
224
- let r = await te(() => E.getConversation(e(t)), b);
225
- W(r, n, !1);
226
- }, ge = async (n) => {
227
- L.current.get(_) === g && Z(_, !1), R.current.add(_);
228
- let r = await te(() => E.getConversation(e(t)), b, (e) => e.messages.length === a && e.messages.at(-1)?.role === p.User);
229
- W(r, n, !0);
230
- }, W = (e, n, r) => {
231
- if (b()) {
232
- C();
228
+ }, I = () => {
229
+ x(), z.current.has(h) ? z.current.delete(h) : v() || E?.notifyGenerationEnd?.();
230
+ }, B = async (n) => {
231
+ L.current.add(g);
232
+ let r = await te(() => w.getConversation(e(t)), v);
233
+ U(r, n, !1);
234
+ }, H = async (n) => {
235
+ F.current.get(g) === h && X(g, !1), L.current.add(g);
236
+ let r = await te(() => w.getConversation(e(t)), v, (e) => e.messages.length === a && e.messages.at(-1)?.role === ie.User);
237
+ U(r, n, !0);
238
+ }, U = (e, n, r) => {
239
+ if (v()) {
240
+ x();
233
241
  return;
234
242
  }
235
- let i = e?.messages[e.messages.length - 1], o = e != null && e.messages.length - 1 === a && i?.role === p.Assistant, s = r && e != null && d(e) !== -1;
243
+ let i = e?.messages[e.messages.length - 1], o = e != null && e.messages.length - 1 === a && i?.role === ie.Assistant, s = r && e != null && d(e) !== -1;
236
244
  if (!e || !o && !s) {
237
- R.current.delete(_), F(n);
245
+ L.current.delete(g), N(n);
238
246
  return;
239
247
  }
240
- let c = z.current.get(_), l = c?.generationId === g ? c : void 0;
241
- f(e) ? Q(t, e, {
248
+ let c = R.current.get(g), l = c?.generationId === h ? c : void 0;
249
+ f(e) ? Z(t, e, {
242
250
  seedMessage: o ? l?.message : void 0,
243
251
  skipDedupe: !0,
244
- onSettled: V
245
- }) : (R.current.delete(_), l && z.current.delete(_), J(_) && (w(e), T.current = e), V());
252
+ onSettled: I
253
+ }) : (L.current.delete(g), l && R.current.delete(g), q(g) && (S(e), C.current = e), I());
246
254
  };
247
255
  (async () => {
248
256
  try {
249
- let e = D?.channelId ?? await D?.waitForChannel(ae) ?? void 0, t = B.current.has(g);
250
- if (x.signal.aborted || b() || t) {
251
- z.current.get(_)?.generationId === g && z.current.delete(_), b() || X(_), xe(_, g), le(_, g), D?.notifyGenerationSettled?.(), t ? B.current.delete(g) : b() || O?.notifyGenerationEnd?.();
257
+ let e = T?.channelId ?? await T?.waitForChannel(se) ?? void 0, t = z.current.has(h);
258
+ if (y.signal.aborted || v() || t) {
259
+ R.current.get(g)?.generationId === h && R.current.delete(g), v() || Y(g), Ce(g, h), de(g, h), T?.notifyGenerationSettled?.(), t ? z.current.delete(h) : v() || E?.notifyGenerationEnd?.();
252
260
  return;
253
261
  }
254
- E.streamCompletion(_, n, s, P, ee, g, m, v, e);
262
+ w.streamCompletion(g, n, s, M, ee, h, p, _, e);
255
263
  } catch (e) {
256
- P.onError(e instanceof Error ? e : Error(String(e)));
264
+ M.onError(e instanceof Error ? e : Error(String(e)));
257
265
  }
258
266
  })();
259
267
  }, [
260
- ce,
261
- le,
268
+ ue,
269
+ de,
270
+ J,
262
271
  Y,
263
272
  X,
264
- Z,
265
- xe,
266
- J,
267
- D?.channelId,
268
- D?.ensureConnected,
269
- D?.waitForChannel,
270
- D?.notifyGenerationSettled,
271
- O,
272
- E,
273
- Q,
274
- de,
275
- k,
276
- M,
273
+ Ce,
277
274
  q,
278
- K
279
- ]), Ce = m((e, t) => {
280
- let n = c(e), r = z.current.get(n);
281
- return U.current.get(n)?.isCurrent() && r && t.messages.length - 1 >= r.messageIndex && t.messages[r.messageIndex].role === p.Assistant && !f(t) ? (K(n), z.current.delete(n), t) : r ? u(t, r) : t;
282
- }, [K]), we = m(() => {
275
+ T?.channelId,
276
+ T?.ensureConnected,
277
+ T?.waitForChannel,
278
+ T?.notifyGenerationSettled,
279
+ E,
280
+ w,
281
+ Z,
282
+ pe,
283
+ D,
284
+ A,
285
+ K,
286
+ G
287
+ ]), De = p((e, t) => {
288
+ let n = c(e), r = R.current.get(n);
289
+ return H.current.get(n)?.isCurrent() && r && t.messages.length - 1 >= r.messageIndex && t.messages[r.messageIndex].role === ie.Assistant && !f(t) ? (G(n), R.current.delete(n), t) : r ? u(t, r) : t;
290
+ }, [G]), Oe = p(() => {
283
291
  if (!s) return;
284
- let e = c(s), t = L.current.get(e), n = t ?? C(T.current);
285
- if (!n || V.current.has(n)) return;
286
- V.current.add(n), B.current.add(n), M.flush(e), O?.notifyStopGenerating?.();
287
- let r = z.current.get(e)?.message.content, i = () => L.current.get(e) === n || t == null && F.current.has(e), o = async () => {
288
- let e = x / S;
292
+ let e = c(s), t = F.current.get(e), n = t ?? x(C.current) ?? I.current.get(e);
293
+ if (!n || B.current.has(n)) return;
294
+ B.current.add(n), z.current.add(n), A.flush(e), E?.notifyStopGenerating?.();
295
+ let r = R.current.get(e)?.message.content, i = () => F.current.get(e) === n || t == null && N.current.has(e), o = async () => {
296
+ let e = y / b;
289
297
  for (let t = 0; t < e; t++) {
290
- if (!i() || !H.current) return !0;
291
- await new Promise((e) => setTimeout(e, S));
298
+ if (!i() || !V.current) return !0;
299
+ await new Promise((e) => setTimeout(e, b));
292
300
  }
293
301
  return !i();
294
302
  };
295
303
  (async () => {
296
304
  try {
297
- await E.stopCompletion({
305
+ await w.stopCompletion({
298
306
  generationId: n,
299
307
  path: e,
300
308
  content: r
301
309
  });
302
310
  } catch (e) {
303
311
  let t = e instanceof Error ? e : Error(String(e));
304
- if (t instanceof a && t.status === b && await o()) return;
305
- V.current.delete(n), ue?.(t);
312
+ if (t instanceof a && t.status === v && await o()) return;
313
+ B.current.delete(n), fe?.(t);
306
314
  }
307
315
  })();
308
316
  }, [
309
317
  s,
310
- T,
311
- M,
312
- ue,
313
- O,
314
- E
315
- ]), Te = m((e, t) => Q(e, t), [Q]), Ee = s != null && N.has(c(s)), $ = s == null ? null : c(s), De = $ != null && (I.has($) || Ee && C(T.current) != null), Oe = $ ? ge.get($) : void 0, ke = Oe?.isCurrent() ?? !1;
318
+ C,
319
+ A,
320
+ fe,
321
+ E,
322
+ w
323
+ ]), ke = p((e, t) => Z(e, t, { trackAttachGenerationId: !0 }), [Z]), Ae = s != null && j.has(c(s)), Q = s == null ? null : c(s), je = Q != null && (P.has(Q) || Ae && x(C.current) != null), $ = Q ? U.get(Q) : void 0, Me = $?.isCurrent() ?? !1;
316
324
  return {
317
- hasConversationReloadError: ke,
318
- isReloadingConversation: !!Oe && ke && _e.has(Oe),
319
- retryConversationReload: ye,
320
- startStream: Se,
321
- handleStop: we,
322
- resumeIfAwaitingGeneration: Te,
323
- restoreBufferedGeneration: Ce,
324
- isStreaming: Ee,
325
- canStopStreaming: De
325
+ hasConversationReloadError: Me,
326
+ isReloadingConversation: !!$ && Me && ye.has($),
327
+ retryConversationReload: xe,
328
+ startStream: Ee,
329
+ handleStop: Oe,
330
+ resumeIfAwaitingGeneration: ke,
331
+ restoreBufferedGeneration: De,
332
+ isStreaming: Ae,
333
+ canStopStreaming: je
326
334
  };
327
335
  };
328
336
  //#endregion
329
- export { w as useConversationStream };
337
+ export { S as useConversationStream };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@epam/ai-dial-chat-hooks",
3
3
  "description": "Framework-level React hooks extracted from AI DIAL Chat for building custom chat interfaces",
4
- "version": "1.3.0-dev.152",
4
+ "version": "1.3.0-dev.157",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "main": "./index.js",
@@ -121,7 +121,7 @@
121
121
  }
122
122
  },
123
123
  "dependencies": {
124
- "@epam/ai-dial-chat-api-client": "1.3.0-dev.152",
124
+ "@epam/ai-dial-chat-api-client": "1.3.0-dev.157",
125
125
  "dompurify": "3.4.16",
126
126
  "fflate": "^0.8.3",
127
127
  "lru-cache": "^10.4.3",
@@ -130,22 +130,22 @@
130
130
  },
131
131
  "peerDependencies": {
132
132
  "react": "^19.2.8",
133
- "@epam/ai-dial-attachment-canvas": "1.3.0-dev.152",
134
- "@epam/ai-dial-attachment-input": "1.3.0-dev.152",
135
- "@epam/ai-dial-catalog": "1.3.0-dev.152",
136
- "@epam/ai-dial-chat-overlay": "1.3.0-dev.152",
137
- "@epam/ai-dial-chat-shared": "1.3.0-dev.152",
138
- "@epam/ai-dial-conversation-input": "1.3.0-dev.152",
139
- "@epam/ai-dial-mcp-apps": "1.3.0-dev.152",
140
- "@epam/ai-dial-publish-panel": "1.3.0-dev.152",
141
- "@epam/ai-dial-quotations": "1.3.0-dev.152",
133
+ "@epam/ai-dial-attachment-canvas": "1.3.0-dev.157",
134
+ "@epam/ai-dial-attachment-input": "1.3.0-dev.157",
135
+ "@epam/ai-dial-catalog": "1.3.0-dev.157",
136
+ "@epam/ai-dial-chat-overlay": "1.3.0-dev.157",
137
+ "@epam/ai-dial-chat-shared": "1.3.0-dev.157",
138
+ "@epam/ai-dial-conversation-input": "1.3.0-dev.157",
139
+ "@epam/ai-dial-mcp-apps": "1.3.0-dev.157",
140
+ "@epam/ai-dial-publish-panel": "1.3.0-dev.157",
141
+ "@epam/ai-dial-quotations": "1.3.0-dev.157",
142
142
  "@epam/ai-dial-react-file-manager": "^0.4.0-dev.11",
143
- "@epam/ai-dial-scheduled-tasks": "1.3.0-dev.152",
144
- "@epam/ai-dial-share": "1.3.0-dev.152",
145
- "@epam/ai-dial-skill-editor": "1.3.0-dev.152",
146
- "@epam/ai-dial-source-panel": "1.3.0-dev.152",
143
+ "@epam/ai-dial-scheduled-tasks": "1.3.0-dev.157",
144
+ "@epam/ai-dial-share": "1.3.0-dev.157",
145
+ "@epam/ai-dial-skill-editor": "1.3.0-dev.157",
146
+ "@epam/ai-dial-source-panel": "1.3.0-dev.157",
147
147
  "@epam/ai-dial-ui-kit": "^0.16.0-dev.22",
148
- "@epam/ai-dial-usage-dashboard": "1.3.0-dev.152",
148
+ "@epam/ai-dial-usage-dashboard": "1.3.0-dev.157",
149
149
  "@modelcontextprotocol/sdk": "^1.32.1",
150
150
  "@epam/pdf-highlighter-kit": "^0.0.19",
151
151
  "@mcp-ui/client": "^7.1.1"