@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.
- package/conversation/useConversationStream/generation-resume.d.ts +14 -1
- package/conversation/useConversationStream/generation-resume.d.ts.map +1 -1
- package/conversation/useConversationStream/generation-resume.js +60 -51
- package/conversation/useConversationStream/useConversationStream.d.ts.map +1 -1
- package/conversation/useConversationStream/useConversationStream.js +207 -199
- package/package.json +16 -16
|
@@ -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,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;IAC3G,UAAU,CAAC,EAAE,OAAO,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,GAC5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EAAuE;IACvE,aAAa,CAAC,EAAE,CACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAC1B,SAAS,EAAE,MAAM,OAAO,KACrB,IAAI,CAAC;IACV,2DAA2D;IAC3D,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,iFAAiF;IACjF,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,kGAAkG;IAClG,2BAA2B,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3E;;;OAGG;IACH,yBAAyB,CAAC,EAAE,CAAC,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,
|
|
67
|
-
if (!u(
|
|
68
|
-
|
|
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
|
|
72
|
-
if (!
|
|
73
|
-
m.current.add(
|
|
74
|
-
let
|
|
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:
|
|
77
|
-
message:
|
|
76
|
+
messageIndex: M,
|
|
77
|
+
message: O.seedMessage ?? D.messages[M]
|
|
78
78
|
};
|
|
79
|
-
h.current.set(
|
|
80
|
-
let
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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(
|
|
88
|
-
if (!e || !
|
|
89
|
-
let t = a(e,
|
|
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(
|
|
92
|
-
},
|
|
93
|
-
if (
|
|
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 (!
|
|
96
|
-
|
|
104
|
+
if (!P()) return;
|
|
105
|
+
E?.(k), B(n);
|
|
97
106
|
} catch {
|
|
98
|
-
if (!
|
|
99
|
-
x?.flush(
|
|
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
|
-
},
|
|
102
|
-
x?.cancel(
|
|
103
|
-
if (!e || !
|
|
104
|
-
let t = a(e,
|
|
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
|
-
},
|
|
108
|
-
if (!e || !
|
|
109
|
-
let t = a(e,
|
|
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
|
-
}),
|
|
112
|
-
if (!
|
|
113
|
-
let t = i([
|
|
114
|
-
t && (
|
|
115
|
-
},
|
|
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(
|
|
127
|
+
r = await o.watchConversation(k, n.signal);
|
|
119
128
|
} catch {
|
|
120
|
-
await
|
|
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),
|
|
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
|
|
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
|
|
146
|
-
},
|
|
154
|
+
i || await V();
|
|
155
|
+
}, K = async () => {
|
|
147
156
|
let e = new AbortController(), t;
|
|
148
157
|
try {
|
|
149
|
-
t = await o.attachToGeneration(
|
|
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 (!
|
|
164
|
+
if (!P()) return !0;
|
|
156
165
|
switch (e.type) {
|
|
157
|
-
case "snapshot": return
|
|
158
|
-
case "chunk": return
|
|
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 ?
|
|
172
|
+
}), r ? (i ? B(void 0, !0) : await V(), !0) : (z(), !P());
|
|
164
173
|
};
|
|
165
174
|
(async () => {
|
|
166
175
|
try {
|
|
167
|
-
await
|
|
176
|
+
await K() || await G();
|
|
168
177
|
} finally {
|
|
169
|
-
|
|
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,CACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uBAAuB,EAChC,aAAa,CAAC,EAAE,oBAAoB,EACpC,YAAY,CAAC,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,yBAAyB,EAChC,YAAY,CAAC,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,MAAM,GACvB,IAAI,CAAC;IACR;;;OA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pC,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,
|
|
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,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C,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACvC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAqBD,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,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
|
|
9
|
-
import { useCallback as
|
|
10
|
-
import { SendCompletionDtoModeEnum as
|
|
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
|
|
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
|
-
},
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}, [
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, [
|
|
25
|
-
let [
|
|
26
|
-
|
|
27
|
-
let [
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
32
|
-
if (!
|
|
33
|
-
let t = new Map(
|
|
34
|
-
t.delete(e),
|
|
35
|
-
}, []),
|
|
36
|
-
if (!
|
|
37
|
-
let r = new Map(
|
|
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
|
-
}),
|
|
42
|
-
}, []),
|
|
41
|
+
}), H.current = r, ve(r);
|
|
42
|
+
}, []), xe = p(async () => {
|
|
43
43
|
if (!s) return;
|
|
44
|
-
let e =
|
|
45
|
-
if (e && e.isCurrent() && !
|
|
46
|
-
|
|
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
|
-
|
|
50
|
+
W.current.delete(e), V.current && be(new Set(W.current));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
}, [s]),
|
|
54
|
-
|
|
55
|
-
let
|
|
56
|
-
|
|
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
|
-
}, [
|
|
62
|
-
|
|
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
|
-
}, []),
|
|
68
|
-
|
|
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
|
-
}, []),
|
|
74
|
-
|
|
75
|
-
}, [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
94
|
-
k,
|
|
95
|
-
j,
|
|
96
|
-
M,
|
|
97
|
+
Y,
|
|
97
98
|
q,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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:
|
|
109
|
-
}) :
|
|
110
|
-
let
|
|
111
|
-
|
|
112
|
-
},
|
|
113
|
-
if (
|
|
114
|
-
let e =
|
|
115
|
-
e && e.generationId ===
|
|
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:
|
|
118
|
-
},
|
|
119
|
-
if (!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
|
|
129
|
+
return C.current = n, n;
|
|
122
130
|
}));
|
|
123
|
-
},
|
|
124
|
-
if (
|
|
125
|
-
if (!
|
|
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
|
|
128
|
-
if (!
|
|
129
|
-
if (
|
|
130
|
-
|
|
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
|
-
|
|
142
|
+
Z(t, n, { seedMessage: O?.message });
|
|
135
143
|
return;
|
|
136
144
|
}
|
|
137
|
-
if (
|
|
138
|
-
|
|
145
|
+
if (O && O.messageIndex === n.messages.length - 1 && f(n) && ne(O.message)) {
|
|
146
|
+
fe();
|
|
139
147
|
return;
|
|
140
148
|
}
|
|
141
|
-
|
|
149
|
+
O && R.current.delete(g), S(n), C.current = n;
|
|
142
150
|
} catch {
|
|
143
|
-
|
|
151
|
+
k() && K(g, j, k);
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
|
-
},
|
|
147
|
-
signal:
|
|
154
|
+
}, M = {
|
|
155
|
+
signal: y.signal,
|
|
148
156
|
onChunk: (e) => {
|
|
149
|
-
if (
|
|
150
|
-
let t =
|
|
151
|
-
if (t?.generationId ===
|
|
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
|
-
|
|
156
|
-
let e =
|
|
157
|
-
if (
|
|
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
|
-
|
|
167
|
+
S((e) => {
|
|
160
168
|
if (!e) return e;
|
|
161
169
|
let n = u(e, t);
|
|
162
|
-
return
|
|
170
|
+
return C.current = n, n;
|
|
163
171
|
});
|
|
164
|
-
}) :
|
|
172
|
+
}) : S((t) => {
|
|
165
173
|
if (!t) return t;
|
|
166
|
-
let n =
|
|
167
|
-
if (n?.generationId ===
|
|
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
|
|
184
|
+
return C.current = r, r;
|
|
177
185
|
}));
|
|
178
186
|
},
|
|
179
187
|
onComplete: async () => {
|
|
180
|
-
|
|
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
|
-
|
|
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
|
-
},
|
|
186
|
-
let t =
|
|
187
|
-
n && !(e instanceof i) &&
|
|
188
|
-
},
|
|
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:
|
|
192
|
-
}),
|
|
193
|
-
let n =
|
|
194
|
-
|
|
195
|
-
if (!e ||
|
|
196
|
-
let r = t?.generationId ===
|
|
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
|
|
211
|
+
return C.current = i, i;
|
|
204
212
|
});
|
|
205
|
-
},
|
|
206
|
-
let a = () =>
|
|
213
|
+
}, ge = async (n, r, i) => {
|
|
214
|
+
let a = () => V.current && !v() && R.current.get(g) === r;
|
|
207
215
|
try {
|
|
208
|
-
let o = await
|
|
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
|
-
|
|
219
|
+
P(n, r);
|
|
212
220
|
return;
|
|
213
221
|
}
|
|
214
|
-
let s = await i(
|
|
215
|
-
if (!a() || (
|
|
216
|
-
|
|
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() &&
|
|
226
|
+
a() && P(n, r);
|
|
219
227
|
}
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
},
|
|
223
|
-
|
|
224
|
-
let r = await te(() =>
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
let r = await te(() =>
|
|
229
|
-
|
|
230
|
-
},
|
|
231
|
-
if (
|
|
232
|
-
|
|
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 ===
|
|
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
|
-
|
|
245
|
+
L.current.delete(g), N(n);
|
|
238
246
|
return;
|
|
239
247
|
}
|
|
240
|
-
let c =
|
|
241
|
-
f(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:
|
|
245
|
-
}) : (
|
|
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 =
|
|
250
|
-
if (
|
|
251
|
-
|
|
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
|
-
|
|
262
|
+
w.streamCompletion(g, n, s, M, ee, h, p, _, e);
|
|
255
263
|
} catch (e) {
|
|
256
|
-
|
|
264
|
+
M.onError(e instanceof Error ? e : Error(String(e)));
|
|
257
265
|
}
|
|
258
266
|
})();
|
|
259
267
|
}, [
|
|
260
|
-
|
|
261
|
-
|
|
268
|
+
ue,
|
|
269
|
+
de,
|
|
270
|
+
J,
|
|
262
271
|
Y,
|
|
263
272
|
X,
|
|
264
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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 =
|
|
285
|
-
if (!n ||
|
|
286
|
-
|
|
287
|
-
let r =
|
|
288
|
-
let e =
|
|
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() || !
|
|
291
|
-
await new Promise((e) => setTimeout(e,
|
|
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
|
|
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 ===
|
|
305
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
]),
|
|
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:
|
|
318
|
-
isReloadingConversation:
|
|
319
|
-
retryConversationReload:
|
|
320
|
-
startStream:
|
|
321
|
-
handleStop:
|
|
322
|
-
resumeIfAwaitingGeneration:
|
|
323
|
-
restoreBufferedGeneration:
|
|
324
|
-
isStreaming:
|
|
325
|
-
canStopStreaming:
|
|
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 {
|
|
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.
|
|
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.
|
|
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.
|
|
134
|
-
"@epam/ai-dial-attachment-input": "1.3.0-dev.
|
|
135
|
-
"@epam/ai-dial-catalog": "1.3.0-dev.
|
|
136
|
-
"@epam/ai-dial-chat-overlay": "1.3.0-dev.
|
|
137
|
-
"@epam/ai-dial-chat-shared": "1.3.0-dev.
|
|
138
|
-
"@epam/ai-dial-conversation-input": "1.3.0-dev.
|
|
139
|
-
"@epam/ai-dial-mcp-apps": "1.3.0-dev.
|
|
140
|
-
"@epam/ai-dial-publish-panel": "1.3.0-dev.
|
|
141
|
-
"@epam/ai-dial-quotations": "1.3.0-dev.
|
|
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.
|
|
144
|
-
"@epam/ai-dial-share": "1.3.0-dev.
|
|
145
|
-
"@epam/ai-dial-skill-editor": "1.3.0-dev.
|
|
146
|
-
"@epam/ai-dial-source-panel": "1.3.0-dev.
|
|
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.
|
|
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"
|