@epam/ai-dial-chat-hooks 1.3.0-dev.152 → 1.3.0-dev.159
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/create-chat-stream-api.d.ts +11 -1
- package/conversation/create-chat-stream-api.d.ts.map +1 -1
- package/conversation/create-chat-stream-api.js +50 -41
- 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 +213 -199
- package/package.json +16 -16
|
@@ -2,16 +2,26 @@ import { SendCompletionDtoModeEnum } from '@epam/ai-dial-chat-api-client';
|
|
|
2
2
|
import { MessageCustomContent, StreamChunk } from '@epam/ai-dial-chat-shared';
|
|
3
3
|
/** Safe fallback for hosts that do not supply a translated persistence warning. */
|
|
4
4
|
export declare const DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE = "The response could not be saved. It is still shown here, but may be lost if you reload or leave this page. Copy it before continuing.";
|
|
5
|
+
/** Terminal markers the rejected write of a stopped, aborted, or failed answer carried. */
|
|
6
|
+
export interface GenerationPersistenceTerminalMarker {
|
|
7
|
+
/** Error text the failed write stored; `''` asks the host for its localized fallback. */
|
|
8
|
+
streamErrorMessage?: string;
|
|
9
|
+
/** `true` when the rejected write recorded a user stop. */
|
|
10
|
+
wasStoppedByUser?: boolean;
|
|
11
|
+
}
|
|
5
12
|
/** Identifies a failed terminal save independently of the model's generation outcome. */
|
|
6
13
|
export declare class GenerationPersistenceError extends Error {
|
|
7
14
|
static readonly type = "conversation_save_failed";
|
|
8
15
|
/** HTTP status of the rejected terminal write, when the backend reported one. */
|
|
9
16
|
readonly status?: number;
|
|
17
|
+
/** Terminal markers of an answer that did not complete; `undefined` for a completed one. */
|
|
18
|
+
readonly terminalMarker?: GenerationPersistenceTerminalMarker;
|
|
10
19
|
/**
|
|
11
20
|
* Creates the error with the default persistence message.
|
|
12
21
|
* @param status - HTTP status of the rejected terminal write, if known
|
|
22
|
+
* @param terminalMarker - markers the rejected write of an answer that did not complete carried
|
|
13
23
|
*/
|
|
14
|
-
constructor(status?: number);
|
|
24
|
+
constructor(status?: number, terminalMarker?: GenerationPersistenceTerminalMarker);
|
|
15
25
|
}
|
|
16
26
|
/** Fallback text of a {@link GenerationConflictError} when no message is supplied. */
|
|
17
27
|
export declare const DEFAULT_GENERATION_CONFLICT_MESSAGE = "A response is already being generated in this conversation. Wait for it to finish or stop it before sending another message.";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-chat-stream-api.d.ts","sourceRoot":"","sources":["../../src/conversation/create-chat-stream-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAOnC,mFAAmF;AACnF,eAAO,MAAM,4CAA4C,0IACgF,CAAC;AAE1I,yFAAyF;AACzF,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,QAAQ,CAAC,IAAI,8BAA8B;IAElD,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB
|
|
1
|
+
{"version":3,"file":"create-chat-stream-api.d.ts","sourceRoot":"","sources":["../../src/conversation/create-chat-stream-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAOnC,mFAAmF;AACnF,eAAO,MAAM,4CAA4C,0IACgF,CAAC;AAE1I,2FAA2F;AAC3F,MAAM,WAAW,mCAAmC;IAClD,yFAAyF;IACzF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,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EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC7C,iFAAiF;IACjF,mBAAmB,EAAE,MAAM,CAAC;IAC5B,uFAAuF;IACvF,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACvC,wFAAwF;IACxF,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAkID,wFAAwF;AACxF,MAAM,WAAW,aAAa;IAC5B,gBAAgB,EAAE,CAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,2BAA2B,EACpC,aAAa,CAAC,EAAE,oBAAoB,EACpC,YAAY,CAAC,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,yBAAyB,EAChC,YAAY,CAAC,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,MAAM,KACrB,IAAI,CAAC;IACV,cAAc,EAAE,CAAC,GAAG,EAAE;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,MAAM,uBAAuB,KAC5B,aAyLF,CAAC"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
var e = { "Content-Type": "application/json" }, t = 409, n = "The response could not be saved. It is still shown here, but may be lost if you reload or leave this page. Copy it before continuing.", r = class extends Error {
|
|
3
3
|
static type = "conversation_save_failed";
|
|
4
4
|
status;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
terminalMarker;
|
|
6
|
+
constructor(e, t) {
|
|
7
|
+
super(n), this.name = "GenerationPersistenceError", this.status = e, this.terminalMarker = t;
|
|
7
8
|
}
|
|
8
9
|
}, i = "A response is already being generated in this conversation. Wait for it to finish or stop it before sending another message.", a = class extends Error {
|
|
9
10
|
constructor(e = i) {
|
|
@@ -41,89 +42,97 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "The response could
|
|
|
41
42
|
}, d = (e) => typeof e == "object" && !!e && e.name === "AbortError", f = (e) => {
|
|
42
43
|
let { status: t } = e;
|
|
43
44
|
return typeof t == "number" ? t : void 0;
|
|
44
|
-
}, p = (e
|
|
45
|
+
}, p = (e) => {
|
|
46
|
+
let { streamErrorMessage: t, wasStoppedByUser: n } = e;
|
|
47
|
+
if (n === !0) return { wasStoppedByUser: !0 };
|
|
48
|
+
if (typeof t == "string") return { streamErrorMessage: t };
|
|
49
|
+
}, m = (e, t, n) => {
|
|
45
50
|
let i = e.trim();
|
|
46
51
|
if (!i || i.startsWith(":") || !i.startsWith("data: ")) return;
|
|
47
52
|
let a = i.slice(6);
|
|
48
53
|
if (a !== "[DONE]") try {
|
|
49
54
|
let e = JSON.parse(a);
|
|
50
55
|
if (e.error) {
|
|
51
|
-
n(e.error.type === r.type ? new r(f(e.error)) : new o(e.error.display_message ?? e.error.message));
|
|
56
|
+
n(e.error.type === r.type ? new r(f(e.error), p(e.error)) : new o(e.error.display_message ?? e.error.message));
|
|
52
57
|
return;
|
|
53
58
|
}
|
|
54
59
|
t(e);
|
|
55
60
|
} catch {}
|
|
56
|
-
},
|
|
61
|
+
}, h = (n) => {
|
|
57
62
|
let { completionsBasePath: r } = n, i = (...e) => (n.fetchImpl ?? fetch)(...e);
|
|
58
63
|
return {
|
|
59
|
-
streamCompletion: (
|
|
60
|
-
let { onChunk:
|
|
64
|
+
streamCompletion: (c, l, f, p, h, g, _, v, y) => {
|
|
65
|
+
let { onChunk: b, onComplete: x, onError: S, signal: C } = p;
|
|
61
66
|
(async () => {
|
|
62
|
-
let
|
|
67
|
+
let p;
|
|
63
68
|
try {
|
|
64
69
|
let t = n.getTimezone?.();
|
|
65
|
-
|
|
70
|
+
p = await i(`${r}/completions`, {
|
|
66
71
|
method: "POST",
|
|
67
72
|
credentials: "include",
|
|
68
|
-
signal:
|
|
73
|
+
signal: C,
|
|
69
74
|
headers: {
|
|
70
75
|
...e,
|
|
71
76
|
...n.getCsrfToken() == null ? {} : { "X-CSRF-Token": n.getCsrfToken() },
|
|
72
77
|
...t ? { "X-Timezone": t } : {}
|
|
73
78
|
},
|
|
74
79
|
body: JSON.stringify({
|
|
75
|
-
path:
|
|
76
|
-
message:
|
|
77
|
-
model:
|
|
78
|
-
custom_content:
|
|
79
|
-
...
|
|
80
|
-
...
|
|
81
|
-
...
|
|
82
|
-
...
|
|
80
|
+
path: c,
|
|
81
|
+
message: l ?? "",
|
|
82
|
+
model: f,
|
|
83
|
+
custom_content: h || {},
|
|
84
|
+
...g != null && { generationId: g },
|
|
85
|
+
..._ != null && { mode: _ },
|
|
86
|
+
...v != null && { messageIndex: v },
|
|
87
|
+
...y != null && { clientChannelId: y }
|
|
83
88
|
})
|
|
84
89
|
});
|
|
85
90
|
} catch (e) {
|
|
86
91
|
if (d(e)) return;
|
|
87
|
-
|
|
92
|
+
S(new s(e));
|
|
88
93
|
return;
|
|
89
94
|
}
|
|
90
|
-
let
|
|
91
|
-
if (
|
|
92
|
-
if (
|
|
93
|
-
|
|
95
|
+
let w = p.headers.get("x-csrf-token");
|
|
96
|
+
if (w && n.setCsrfToken(w), !p.ok) {
|
|
97
|
+
if (p.status === t) {
|
|
98
|
+
S(new a());
|
|
94
99
|
return;
|
|
95
100
|
}
|
|
96
|
-
|
|
101
|
+
S(/* @__PURE__ */ Error(`Stream request failed with status ${p.status}`));
|
|
97
102
|
return;
|
|
98
103
|
}
|
|
99
|
-
if (!
|
|
100
|
-
|
|
104
|
+
if (!p.body) {
|
|
105
|
+
S(/* @__PURE__ */ Error("No response body"));
|
|
101
106
|
return;
|
|
102
107
|
}
|
|
103
|
-
let
|
|
104
|
-
|
|
105
|
-
},
|
|
106
|
-
|
|
108
|
+
let T = p.body.getReader(), E = new TextDecoder(), D = "", O = !1, k = !1, A, j = (e) => {
|
|
109
|
+
O || (O = !0, P.stop(), S(e));
|
|
110
|
+
}, M = (e) => {
|
|
111
|
+
e instanceof o ? A ??= e : j(e);
|
|
112
|
+
}, N = (e) => {
|
|
113
|
+
A ?? b(e);
|
|
114
|
+
}, P = u(n.idleTimeoutMs ?? 45e3, () => {
|
|
115
|
+
k = !0, j(A ?? new s()), T.cancel().catch(() => void 0);
|
|
107
116
|
});
|
|
108
117
|
try {
|
|
109
118
|
for (;;) {
|
|
110
|
-
let { done: e, value: t } = await
|
|
111
|
-
if (
|
|
119
|
+
let { done: e, value: t } = await T.read();
|
|
120
|
+
if (k) break;
|
|
112
121
|
if (e) {
|
|
113
|
-
|
|
122
|
+
D.trim() && m(D, N, M);
|
|
114
123
|
break;
|
|
115
124
|
}
|
|
116
|
-
|
|
117
|
-
let n =
|
|
118
|
-
|
|
119
|
-
for (let e of n)
|
|
125
|
+
P.touch(), D += E.decode(t, { stream: !0 });
|
|
126
|
+
let n = D.split("\n");
|
|
127
|
+
D = n.pop() ?? "";
|
|
128
|
+
for (let e of n) m(e, N, M);
|
|
120
129
|
}
|
|
121
|
-
|
|
130
|
+
A ? j(A) : O || (O = !0, x());
|
|
122
131
|
} catch (e) {
|
|
123
132
|
if (d(e)) return;
|
|
124
|
-
|
|
133
|
+
j(A ?? new s(e));
|
|
125
134
|
} finally {
|
|
126
|
-
|
|
135
|
+
P.stop(), T.releaseLock();
|
|
127
136
|
}
|
|
128
137
|
})();
|
|
129
138
|
},
|
|
@@ -142,4 +151,4 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "The response could
|
|
|
142
151
|
};
|
|
143
152
|
};
|
|
144
153
|
//#endregion
|
|
145
|
-
export { i as DEFAULT_GENERATION_CONFLICT_MESSAGE, n as DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE, l as DEFAULT_STREAM_IDLE_TIMEOUT_MS, a as GenerationConflictError, r as GenerationPersistenceError, c as StopCompletionError, s as StreamInterruptedError, o as StreamUpstreamError,
|
|
154
|
+
export { i as DEFAULT_GENERATION_CONFLICT_MESSAGE, n as DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE, l as DEFAULT_STREAM_IDLE_TIMEOUT_MS, a as GenerationConflictError, r as GenerationPersistenceError, c as StopCompletionError, s as StreamInterruptedError, o as StreamUpstreamError, h as createChatStreamApi };
|
|
@@ -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,GAC5C,cAAc,YAAY,KACzB,MAKA,CAAC;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,GACrC,cAAc,YAAY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,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;;;OAGG;IACH,cAAc,CAAC,MAAM,EAAE;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QAC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zB,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,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC1C,6GAA6G;IAC7G,gB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C/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,2BAw9BhC,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,163 @@ 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 =
|
|
215
|
-
|
|
216
|
-
|
|
222
|
+
let s = n.terminalMarker ? {
|
|
223
|
+
...r,
|
|
224
|
+
message: {
|
|
225
|
+
...r.message,
|
|
226
|
+
...n.terminalMarker
|
|
227
|
+
}
|
|
228
|
+
} : r, c = await i(g, u(o, s));
|
|
229
|
+
if (!a() || (R.current.delete(g), !q(g))) return;
|
|
230
|
+
S(c), C.current = c;
|
|
217
231
|
} catch {
|
|
218
|
-
a() &&
|
|
232
|
+
a() && P(n, r);
|
|
219
233
|
}
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
},
|
|
223
|
-
|
|
224
|
-
let r = await te(() =>
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
let r = await te(() =>
|
|
229
|
-
|
|
230
|
-
},
|
|
231
|
-
if (
|
|
232
|
-
|
|
234
|
+
}, I = () => {
|
|
235
|
+
x(), z.current.has(h) ? z.current.delete(h) : v() || E?.notifyGenerationEnd?.();
|
|
236
|
+
}, B = async (n) => {
|
|
237
|
+
L.current.add(g);
|
|
238
|
+
let r = await te(() => w.getConversation(e(t)), v);
|
|
239
|
+
U(r, n, !1);
|
|
240
|
+
}, H = async (n) => {
|
|
241
|
+
F.current.get(g) === h && X(g, !1), L.current.add(g);
|
|
242
|
+
let r = await te(() => w.getConversation(e(t)), v, (e) => e.messages.length === a && e.messages.at(-1)?.role === ie.User);
|
|
243
|
+
U(r, n, !0);
|
|
244
|
+
}, U = (e, n, r) => {
|
|
245
|
+
if (v()) {
|
|
246
|
+
x();
|
|
233
247
|
return;
|
|
234
248
|
}
|
|
235
|
-
let i = e?.messages[e.messages.length - 1], o = e != null && e.messages.length - 1 === a && i?.role ===
|
|
249
|
+
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
250
|
if (!e || !o && !s) {
|
|
237
|
-
|
|
251
|
+
L.current.delete(g), N(n);
|
|
238
252
|
return;
|
|
239
253
|
}
|
|
240
|
-
let c =
|
|
241
|
-
f(e) ?
|
|
254
|
+
let c = R.current.get(g), l = c?.generationId === h ? c : void 0;
|
|
255
|
+
f(e) ? Z(t, e, {
|
|
242
256
|
seedMessage: o ? l?.message : void 0,
|
|
243
257
|
skipDedupe: !0,
|
|
244
|
-
onSettled:
|
|
245
|
-
}) : (
|
|
258
|
+
onSettled: I
|
|
259
|
+
}) : (L.current.delete(g), l && R.current.delete(g), q(g) && (S(e), C.current = e), I());
|
|
246
260
|
};
|
|
247
261
|
(async () => {
|
|
248
262
|
try {
|
|
249
|
-
let e =
|
|
250
|
-
if (
|
|
251
|
-
|
|
263
|
+
let e = T?.channelId ?? await T?.waitForChannel(se) ?? void 0, t = z.current.has(h);
|
|
264
|
+
if (y.signal.aborted || v() || t) {
|
|
265
|
+
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
266
|
return;
|
|
253
267
|
}
|
|
254
|
-
|
|
268
|
+
w.streamCompletion(g, n, s, M, ee, h, p, _, e);
|
|
255
269
|
} catch (e) {
|
|
256
|
-
|
|
270
|
+
M.onError(e instanceof Error ? e : Error(String(e)));
|
|
257
271
|
}
|
|
258
272
|
})();
|
|
259
273
|
}, [
|
|
260
|
-
|
|
261
|
-
|
|
274
|
+
ue,
|
|
275
|
+
de,
|
|
276
|
+
J,
|
|
262
277
|
Y,
|
|
263
278
|
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,
|
|
279
|
+
Ce,
|
|
277
280
|
q,
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
T?.channelId,
|
|
282
|
+
T?.ensureConnected,
|
|
283
|
+
T?.waitForChannel,
|
|
284
|
+
T?.notifyGenerationSettled,
|
|
285
|
+
E,
|
|
286
|
+
w,
|
|
287
|
+
Z,
|
|
288
|
+
pe,
|
|
289
|
+
D,
|
|
290
|
+
A,
|
|
291
|
+
K,
|
|
292
|
+
G
|
|
293
|
+
]), De = p((e, t) => {
|
|
294
|
+
let n = c(e), r = R.current.get(n);
|
|
295
|
+
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;
|
|
296
|
+
}, [G]), Oe = p(() => {
|
|
283
297
|
if (!s) return;
|
|
284
|
-
let e = c(s), t =
|
|
285
|
-
if (!n ||
|
|
286
|
-
|
|
287
|
-
let r =
|
|
288
|
-
let e =
|
|
298
|
+
let e = c(s), t = F.current.get(e), n = t ?? x(C.current) ?? I.current.get(e);
|
|
299
|
+
if (!n || B.current.has(n)) return;
|
|
300
|
+
B.current.add(n), z.current.add(n), A.flush(e), E?.notifyStopGenerating?.();
|
|
301
|
+
let r = R.current.get(e)?.message.content, i = () => F.current.get(e) === n || t == null && N.current.has(e), o = async () => {
|
|
302
|
+
let e = y / b;
|
|
289
303
|
for (let t = 0; t < e; t++) {
|
|
290
|
-
if (!i() || !
|
|
291
|
-
await new Promise((e) => setTimeout(e,
|
|
304
|
+
if (!i() || !V.current) return !0;
|
|
305
|
+
await new Promise((e) => setTimeout(e, b));
|
|
292
306
|
}
|
|
293
307
|
return !i();
|
|
294
308
|
};
|
|
295
309
|
(async () => {
|
|
296
310
|
try {
|
|
297
|
-
await
|
|
311
|
+
await w.stopCompletion({
|
|
298
312
|
generationId: n,
|
|
299
313
|
path: e,
|
|
300
314
|
content: r
|
|
301
315
|
});
|
|
302
316
|
} catch (e) {
|
|
303
317
|
let t = e instanceof Error ? e : Error(String(e));
|
|
304
|
-
if (t instanceof a && t.status ===
|
|
305
|
-
|
|
318
|
+
if (t instanceof a && t.status === v && await o()) return;
|
|
319
|
+
B.current.delete(n), fe?.(t);
|
|
306
320
|
}
|
|
307
321
|
})();
|
|
308
322
|
}, [
|
|
309
323
|
s,
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
]),
|
|
324
|
+
C,
|
|
325
|
+
A,
|
|
326
|
+
fe,
|
|
327
|
+
E,
|
|
328
|
+
w
|
|
329
|
+
]), 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
330
|
return {
|
|
317
|
-
hasConversationReloadError:
|
|
318
|
-
isReloadingConversation:
|
|
319
|
-
retryConversationReload:
|
|
320
|
-
startStream:
|
|
321
|
-
handleStop:
|
|
322
|
-
resumeIfAwaitingGeneration:
|
|
323
|
-
restoreBufferedGeneration:
|
|
324
|
-
isStreaming:
|
|
325
|
-
canStopStreaming:
|
|
331
|
+
hasConversationReloadError: Me,
|
|
332
|
+
isReloadingConversation: !!$ && Me && ye.has($),
|
|
333
|
+
retryConversationReload: xe,
|
|
334
|
+
startStream: Ee,
|
|
335
|
+
handleStop: Oe,
|
|
336
|
+
resumeIfAwaitingGeneration: ke,
|
|
337
|
+
restoreBufferedGeneration: De,
|
|
338
|
+
isStreaming: Ae,
|
|
339
|
+
canStopStreaming: je
|
|
326
340
|
};
|
|
327
341
|
};
|
|
328
342
|
//#endregion
|
|
329
|
-
export {
|
|
343
|
+
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.159",
|
|
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.159",
|
|
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.159",
|
|
134
|
+
"@epam/ai-dial-attachment-input": "1.3.0-dev.159",
|
|
135
|
+
"@epam/ai-dial-catalog": "1.3.0-dev.159",
|
|
136
|
+
"@epam/ai-dial-chat-overlay": "1.3.0-dev.159",
|
|
137
|
+
"@epam/ai-dial-chat-shared": "1.3.0-dev.159",
|
|
138
|
+
"@epam/ai-dial-conversation-input": "1.3.0-dev.159",
|
|
139
|
+
"@epam/ai-dial-mcp-apps": "1.3.0-dev.159",
|
|
140
|
+
"@epam/ai-dial-publish-panel": "1.3.0-dev.159",
|
|
141
|
+
"@epam/ai-dial-quotations": "1.3.0-dev.159",
|
|
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.159",
|
|
144
|
+
"@epam/ai-dial-share": "1.3.0-dev.159",
|
|
145
|
+
"@epam/ai-dial-skill-editor": "1.3.0-dev.159",
|
|
146
|
+
"@epam/ai-dial-source-panel": "1.3.0-dev.159",
|
|
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.159",
|
|
149
149
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
150
150
|
"@epam/pdf-highlighter-kit": "^0.0.19",
|
|
151
151
|
"@mcp-ui/client": "^7.1.1"
|