@epam/ai-dial-chat-hooks 1.2.0-dev.20 → 1.2.0-dev.207
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-error/api-error.js +5 -4
- package/attachment/useAttachmentValidation/useAttachmentValidation.js +26 -19
- package/attachments.d.ts +10 -4
- package/catalog/catalog-derivations.js +1 -1
- package/catalog/deployment-id.js +8 -2
- package/catalog/map-deployment-limits-to-input.js +81 -9
- package/catalog/map-deployment-to-catalog-item.js +34 -34
- package/catalog/map-entity-details-to-catalog.js +7 -0
- package/catalog/map-skill-to-catalog-item.js +30 -27
- package/catalog/publish.js +6 -5
- package/catalog/useApplicationCredentials/useApplicationCredentials.js +39 -0
- package/catalog/useSkillDetailsPanelData/useSkillDetailsPanelData.js +39 -39
- package/catalog/useSkillItemDetails.js +17 -13
- package/catalog.d.ts +116 -20
- package/catalog.js +23 -22
- package/conversation/conversation-transfer/export-conversation.js +24 -16
- package/conversation/conversation-transfer/import-conversation.js +80 -31
- package/conversation/conversation-transfer/queue.js +8 -5
- package/conversation/create-chat-stream-api.js +85 -49
- package/conversation/message-utils.js +44 -2
- package/conversation/stage.js +23 -0
- package/conversation/useConversationExport/useConversationExport.js +9 -9
- package/conversation/useConversationHandlers/useConversationHandlers.js +16 -5
- package/conversation/useConversationImport/useConversationImport.js +123 -121
- package/conversation/useConversationPanelItems/useConversationPanelItems.js +2 -3
- package/conversation/useConversationScroll/useConversationScroll.js +68 -64
- package/conversation/useConversationStream/apply-chunk.js +1 -1
- package/conversation/useConversationStream/generation-resume.js +104 -63
- package/conversation/useConversationStream/useConversationStream.js +183 -108
- package/conversation/useMessageSelectionReply/useMessageSelectionReply.js +189 -0
- package/conversation-overlay.d.ts +7 -0
- package/conversation-overlay.js +2 -0
- package/conversation-sources/useConversationSources/useConversationSources.js +31 -24
- package/conversation-sources.d.ts +1 -1
- package/conversation-transfer.d.ts +2 -1
- package/conversation.d.ts +241 -13
- package/conversation.js +32 -30
- package/file-manager-canvas.d.ts +398 -0
- package/file-manager-canvas.js +2 -0
- package/file-manager.d.ts +153 -350
- package/file-manager.js +25 -24
- package/files/attachment-canvas.js +40 -1
- package/files/attachment-types.js +14 -13
- package/files/dial-file-manager-mapping.util.js +2 -1
- package/files/dial-file-manager-path.util.js +23 -1
- package/files/dial-file-manager.model.js +23 -19
- package/files/dial-file-manager.types.js +3 -3
- package/files/useDialFileListing/useDialFileListing.js +157 -145
- package/files/useDialFileManager/useDialFileManager.js +132 -128
- package/files/useDialFileManagerSections/useDialFileManagerSections.js +155 -0
- package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.js +20 -19
- package/files/useDialFileMutations/useDialFileMutations.js +33 -32
- package/files/useDialFileUploadBatch/useDialFileUploadBatch.js +117 -110
- package/files/useFileAttachmentPicker/useFileAttachmentPicker.js +43 -0
- package/index.d.ts +1068 -81
- package/index.js +136 -122
- package/mcp-apps/useMcpAppHostAdapter/useMcpAppHostAdapter.js +7 -5
- package/mcp-apps/useMcpAppHostContext/useMcpAppHostContext.js +1 -1
- package/mcp-apps/useMcpAppTools/useMcpAppTools.js +1 -1
- package/mcp-apps/useOpenMcpAppCanvas/useOpenMcpAppCanvas.js +25 -23
- package/mcp-apps.d.ts +8 -6
- package/oauth/toolset-id.js +5 -3
- package/oauth/useToolsetLogin/useToolsetLogin.js +8 -8
- package/oauth.d.ts +32 -0
- package/oauth.js +9 -9
- package/package.json +36 -21
- package/scheduled-task/scheduled-task-description.js +77 -0
- package/scheduled-task/scheduled-task-preparation.js +24 -0
- package/scheduled-task/scheduled-task-trigger.js +7 -2
- package/scheduled-task/scheduled-tasks-api-client.js +19 -0
- package/scheduled-task/use-scheduled-task-runs.js +194 -0
- package/scheduled-task/use-scheduled-tasks.js +93 -0
- package/scheduled-tasks.d.ts +195 -3
- package/scheduled-tasks.js +7 -2
- package/skill/skill-archive.js +19 -0
- package/skill/skill-types.js +8 -7
- package/skill/skill.js +42 -27
- package/skill/useSkillArchiveImport/useSkillArchiveImport.js +79 -0
- package/skill/useSkillEditorLoad.js +29 -28
- package/skill/useSkillEditorSubmit.js +108 -84
- package/skill/useSkillFileActions.js +70 -58
- package/skill-editor.d.ts +133 -3
- package/skill-editor.js +9 -8
- package/usage/map-usage-data-to-dashboard.js +66 -0
- package/usage/map-user-usage-to-model-limits.js +202 -0
- package/usage.d.ts +125 -0
- package/usage.js +3 -0
- package/usePageFileDrag/usePageFileDrag.js +3 -3
- package/utils.d.ts +8 -6
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { safeDecodeURI as e } from "../../shared/string-utils.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE as t, GenerationPersistenceError as n } from "../create-chat-stream-api.js";
|
|
3
|
+
import { getConversationPath as r } from "./conversation-path.js";
|
|
4
|
+
import { applyChunkToMessages as i } from "./apply-chunk.js";
|
|
5
|
+
import { restoreBufferedMessage as a } from "./buffered-generation.js";
|
|
6
|
+
import { MessageRole as o } from "@epam/ai-dial-chat-shared";
|
|
6
7
|
//#region src/conversation/useConversationStream/generation-resume.ts
|
|
7
|
-
var
|
|
8
|
+
var s = (e) => {
|
|
8
9
|
let t = e.custom_content;
|
|
9
10
|
return !!e.content || e.responseId != null || !!t?.attachments?.length || !!t?.stages?.length || !!t?.annotations?.length || !!t?.form_schema || t?.state != null;
|
|
10
|
-
},
|
|
11
|
+
}, c = (e) => {
|
|
11
12
|
let t = e.messages[e.messages.length - 1];
|
|
12
|
-
return !!t && t.role ===
|
|
13
|
-
},
|
|
13
|
+
return !!t && t.role === o.Assistant && !s(t) && t.streamErrorMessage == null && !t.wasStoppedByUser;
|
|
14
|
+
}, l = 300 * 1e3, u = "awaiting-resume", d = [
|
|
15
|
+
1e3,
|
|
16
|
+
2e3,
|
|
17
|
+
4e3,
|
|
18
|
+
8e3,
|
|
19
|
+
16e3
|
|
20
|
+
], f = (e) => new Promise((t) => {
|
|
21
|
+
let n = typeof window < "u", r = () => {
|
|
22
|
+
clearTimeout(i), n && window.removeEventListener("online", r), t();
|
|
23
|
+
}, i = setTimeout(r, e);
|
|
24
|
+
n && window.addEventListener("online", r);
|
|
25
|
+
}), p = async (e, t) => {
|
|
26
|
+
for (let n = 0; n <= d.length; n++) {
|
|
27
|
+
if (t()) return null;
|
|
28
|
+
try {
|
|
29
|
+
return await e();
|
|
30
|
+
} catch {
|
|
31
|
+
if (n === d.length) return null;
|
|
32
|
+
await f(d[n]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}, m = async (e, t) => {
|
|
14
37
|
let n = e.getReader(), r = new TextDecoder(), i = "";
|
|
15
38
|
try {
|
|
16
39
|
for (;;) {
|
|
@@ -39,88 +62,106 @@ var a = (e) => {
|
|
|
39
62
|
} catch {} finally {
|
|
40
63
|
n.releaseLock();
|
|
41
64
|
}
|
|
42
|
-
},
|
|
43
|
-
if (!
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
}, h = ({ transport: o, setConversation: d, conversationRef: f, resumingPathsRef: p, bufferedGenerationsRef: h, addStreamingPath: g, removeStreamingPath: _, isPathDisplayed: v, generationPersistenceErrorMessage: y = t }) => (t, b, x = {}) => {
|
|
66
|
+
if (!c(b)) {
|
|
67
|
+
x.onSettled?.();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
let S = r(t);
|
|
71
|
+
if (!x.skipDedupe && p.current.has(S)) return;
|
|
72
|
+
p.current.add(S), g(S);
|
|
73
|
+
let C = b.messages.length - 1, w = {
|
|
74
|
+
generationId: u,
|
|
75
|
+
messageIndex: C,
|
|
76
|
+
message: x.seedMessage ?? b.messages[C]
|
|
77
|
+
};
|
|
78
|
+
h.current.set(S, w);
|
|
79
|
+
let T = () => h.current.get(S) === w, E = (e, t = !1) => {
|
|
80
|
+
if (!T()) return;
|
|
81
|
+
p.current.delete(S), _(S);
|
|
82
|
+
let n = e && e.messages.length - 1 === C && c(e) && s(w.message);
|
|
83
|
+
if (t || n) {
|
|
84
|
+
w.message = {
|
|
85
|
+
...w.message,
|
|
86
|
+
streamErrorMessage: y
|
|
87
|
+
}, v(S) && d((e) => {
|
|
88
|
+
if (!e || !T() || !v(S)) return e;
|
|
89
|
+
let t = a(e, w);
|
|
90
|
+
return f.current = t, t;
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
h.current.delete(S), e && v(S) && (d(e), f.current = e);
|
|
95
|
+
}, D = async () => {
|
|
50
96
|
try {
|
|
51
|
-
|
|
97
|
+
E(await o.getConversation(e(t)));
|
|
52
98
|
} catch {
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}, S = (e) => {
|
|
56
|
-
let t = {
|
|
57
|
-
generationId: c,
|
|
58
|
-
messageIndex: y,
|
|
59
|
-
message: e
|
|
60
|
-
};
|
|
61
|
-
f.current.set(v, t), h(v) && a((e) => {
|
|
62
|
-
if (!e) return e;
|
|
63
|
-
let n = r(e, t);
|
|
64
|
-
return u.current = n, n;
|
|
65
|
-
});
|
|
66
|
-
}, C = (e) => {
|
|
67
|
-
let t = f.current.get(v);
|
|
68
|
-
if (t?.generationId === c) {
|
|
69
|
-
let r = n([t.message], 0, e);
|
|
70
|
-
r && (t.message = r[0]);
|
|
99
|
+
E(void 0, s(w.message));
|
|
71
100
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
101
|
+
}, O = (e) => {
|
|
102
|
+
T() && (w.message = e, v(S) && d((e) => {
|
|
103
|
+
if (!e || !T() || !v(S)) return e;
|
|
104
|
+
let t = a(e, w);
|
|
105
|
+
return f.current = t, t;
|
|
106
|
+
}));
|
|
107
|
+
}, k = (e) => {
|
|
108
|
+
if (!T()) return;
|
|
109
|
+
let t = i([w.message], 0, e);
|
|
110
|
+
t && (w.message = t[0]), v(S) && d((e) => {
|
|
111
|
+
if (!e || !T() || !v(S)) return e;
|
|
112
|
+
let t = a(e, w);
|
|
113
|
+
return f.current = t, t;
|
|
78
114
|
});
|
|
79
|
-
},
|
|
80
|
-
let
|
|
115
|
+
}, A = async () => {
|
|
116
|
+
let n = new AbortController(), r;
|
|
81
117
|
try {
|
|
82
|
-
|
|
118
|
+
r = await o.watchConversation(S, n.signal);
|
|
83
119
|
} catch {
|
|
84
|
-
await
|
|
120
|
+
await D();
|
|
85
121
|
return;
|
|
86
122
|
}
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
},
|
|
123
|
+
let i = !1, a = window.setTimeout(() => {
|
|
124
|
+
n.abort();
|
|
125
|
+
}, l);
|
|
90
126
|
try {
|
|
91
|
-
await
|
|
92
|
-
if (
|
|
127
|
+
await m(r, async (n) => {
|
|
128
|
+
if (n?.action !== "UPDATE") return !1;
|
|
93
129
|
try {
|
|
94
|
-
let
|
|
95
|
-
if (!
|
|
130
|
+
let n = await o.getConversation(e(t));
|
|
131
|
+
if (!c(n)) return E(n), i = !0, !0;
|
|
96
132
|
} catch {}
|
|
97
133
|
return !1;
|
|
98
134
|
});
|
|
99
135
|
} finally {
|
|
100
136
|
clearTimeout(a);
|
|
101
137
|
}
|
|
102
|
-
|
|
103
|
-
},
|
|
138
|
+
i || await D();
|
|
139
|
+
}, j = async () => {
|
|
104
140
|
let e = new AbortController(), t;
|
|
105
141
|
try {
|
|
106
|
-
t = await
|
|
142
|
+
t = await o.attachToGeneration(S, e.signal);
|
|
107
143
|
} catch {
|
|
108
144
|
return !1;
|
|
109
145
|
}
|
|
110
|
-
let
|
|
111
|
-
return await
|
|
146
|
+
let r = !1, i = !1;
|
|
147
|
+
return await m(t, (e) => {
|
|
148
|
+
if (!T()) return !0;
|
|
112
149
|
switch (e.type) {
|
|
113
|
-
case "snapshot": return
|
|
114
|
-
case "chunk": return
|
|
150
|
+
case "snapshot": return O(e.message), !1;
|
|
151
|
+
case "chunk": return k(e.chunk), !1;
|
|
115
152
|
case "done":
|
|
116
153
|
case "error":
|
|
117
|
-
case "stopped": return n = !0, !0;
|
|
154
|
+
case "stopped": return i = e.type === "error" && e.errorType === n.type, r = !0, !0;
|
|
118
155
|
}
|
|
119
|
-
}),
|
|
156
|
+
}), r ? (i ? E(void 0, !0) : await D(), !0) : !T();
|
|
120
157
|
};
|
|
121
158
|
(async () => {
|
|
122
|
-
|
|
159
|
+
try {
|
|
160
|
+
await j() || await A();
|
|
161
|
+
} finally {
|
|
162
|
+
x.onSettled?.();
|
|
163
|
+
}
|
|
123
164
|
})();
|
|
124
165
|
};
|
|
125
166
|
//#endregion
|
|
126
|
-
export {
|
|
167
|
+
export { h as createResumeIfAwaitingGeneration, p as fetchConversationForRecovery, s as hasGeneratedPayload, c as isAwaitingGenerationResume };
|
|
@@ -1,152 +1,227 @@
|
|
|
1
1
|
import { safeDecodeURI as e } from "../../shared/string-utils.js";
|
|
2
|
-
import { DEFAULT_GENERATION_CONFLICT_MESSAGE as t,
|
|
3
|
-
import { getConversationPath as
|
|
4
|
-
import { applyChunkToMessages as
|
|
5
|
-
import { restoreBufferedMessage as
|
|
6
|
-
import { createResumeIfAwaitingGeneration as
|
|
7
|
-
import { generateUUID as
|
|
8
|
-
import { useCallback as
|
|
9
|
-
import { SendCompletionDtoModeEnum as
|
|
2
|
+
import { DEFAULT_GENERATION_CONFLICT_MESSAGE as t, DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE as n, GenerationConflictError as r, GenerationPersistenceError as i, StreamInterruptedError as a, StreamUpstreamError as o } from "../create-chat-stream-api.js";
|
|
3
|
+
import { getConversationPath as s } from "./conversation-path.js";
|
|
4
|
+
import { applyChunkToMessages as c } from "./apply-chunk.js";
|
|
5
|
+
import { restoreBufferedMessage as l } from "./buffered-generation.js";
|
|
6
|
+
import { createResumeIfAwaitingGeneration as u, fetchConversationForRecovery as d, hasGeneratedPayload as f, isAwaitingGenerationResume as p } from "./generation-resume.js";
|
|
7
|
+
import { MessageRole as m, generateUUID as h } from "@epam/ai-dial-chat-shared";
|
|
8
|
+
import { useCallback as g, useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
|
|
9
|
+
import { SendCompletionDtoModeEnum as x } from "@epam/ai-dial-chat-api-client";
|
|
10
10
|
//#region src/conversation/useConversationStream/useConversationStream.ts
|
|
11
|
-
var
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, [
|
|
16
|
-
let
|
|
17
|
-
|
|
11
|
+
var S = 2e4, ee = (e, t, n) => e instanceof i ? n : e instanceof r ? t : e instanceof o ? e.message : "", C = ({ conversationId: r, state: { setConversation: o, conversationRef: C }, transport: w, generation: { startGeneration: T, completeGeneration: E }, channel: D, overlay: O, onStopError: k, generationConflictMessage: A = t, generationPersistenceErrorMessage: j = n, onStreamError: M }) => {
|
|
12
|
+
let N = y(M);
|
|
13
|
+
_(() => {
|
|
14
|
+
N.current = M;
|
|
15
|
+
}, [M]);
|
|
16
|
+
let [P, F] = b(() => /* @__PURE__ */ new Set()), [I, L] = b(null), R = y(null), z = y(null), B = y(/* @__PURE__ */ new Set()), V = y(/* @__PURE__ */ new Map()), H = y(/* @__PURE__ */ new Set()), U = y(/* @__PURE__ */ new Map()), W = y(r);
|
|
17
|
+
_(() => {
|
|
18
|
+
W.current = r;
|
|
19
|
+
}, [r]);
|
|
20
|
+
let G = g((e) => s(W.current ?? "") === e, []), K = g((e) => {
|
|
21
|
+
F((t) => {
|
|
18
22
|
if (t.has(e)) return t;
|
|
19
23
|
let n = new Set(t);
|
|
20
24
|
return n.add(e), n;
|
|
21
25
|
});
|
|
22
|
-
}, []),
|
|
23
|
-
|
|
26
|
+
}, []), q = g((e) => {
|
|
27
|
+
F((t) => {
|
|
24
28
|
if (!t.has(e)) return t;
|
|
25
29
|
let n = new Set(t);
|
|
26
30
|
return n.delete(e), n;
|
|
27
31
|
});
|
|
28
|
-
}, []),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
}, []), J = v(() => u({
|
|
33
|
+
transport: w,
|
|
34
|
+
setConversation: o,
|
|
35
|
+
conversationRef: C,
|
|
36
|
+
resumingPathsRef: B,
|
|
37
|
+
bufferedGenerationsRef: V,
|
|
38
|
+
addStreamingPath: K,
|
|
39
|
+
removeStreamingPath: q,
|
|
40
|
+
isPathDisplayed: G,
|
|
41
|
+
generationPersistenceErrorMessage: j
|
|
42
|
+
}), [
|
|
43
|
+
K,
|
|
44
|
+
q,
|
|
45
|
+
G,
|
|
46
|
+
w,
|
|
47
|
+
j
|
|
48
|
+
]), Y = g((t, n, r, u, g, _, v = x.Append) => {
|
|
49
|
+
let y = _ ?? h(), b = s(t);
|
|
50
|
+
B.current.delete(b), R.current = y, z.current = b, U.current.set(b, y), L(b);
|
|
51
|
+
let k;
|
|
52
|
+
v === x.Regenerate ? k = r : v === x.Edit && (k = r - 1);
|
|
53
|
+
let M = () => U.current.get(b) !== y, P = T(b, y), F = C.current?.messages[r];
|
|
54
|
+
F ? V.current.set(b, {
|
|
55
|
+
generationId: y,
|
|
56
|
+
messageIndex: r,
|
|
57
|
+
message: F
|
|
58
|
+
}) : V.current.delete(b), K(b), O?.notifyGenerationStart?.(), D?.ensureConnected();
|
|
59
|
+
let I = () => {
|
|
60
|
+
M() || q(b), R.current === y && (R.current = null, z.current = null, L(null)), E(b, y), D?.notifyGenerationSettled?.();
|
|
61
|
+
}, W = () => {
|
|
62
|
+
if (M()) return;
|
|
63
|
+
let e = V.current.get(b);
|
|
64
|
+
!e || e.generationId !== y || (e.message = {
|
|
65
|
+
...e.message,
|
|
66
|
+
streamErrorMessage: j
|
|
67
|
+
}, N.current?.(new i()), G(b) && o((t) => {
|
|
68
|
+
if (!t || M() || !G(b)) return t;
|
|
69
|
+
let n = l(t, e);
|
|
70
|
+
return C.current = n, n;
|
|
71
|
+
}));
|
|
72
|
+
}, Y = {
|
|
73
|
+
signal: P.signal,
|
|
41
74
|
onChunk: (e) => {
|
|
42
|
-
if (
|
|
43
|
-
let t =
|
|
44
|
-
if (t?.generationId ===
|
|
45
|
-
let n =
|
|
75
|
+
if (R.current !== y) return;
|
|
76
|
+
let t = V.current.get(b);
|
|
77
|
+
if (t?.generationId === y) {
|
|
78
|
+
let n = c([t.message], 0, e);
|
|
46
79
|
n && (t.message = n[0]);
|
|
47
80
|
}
|
|
48
|
-
|
|
81
|
+
G(b) && o((t) => {
|
|
49
82
|
if (!t) return t;
|
|
50
|
-
let n =
|
|
51
|
-
if (n?.generationId ===
|
|
83
|
+
let n = V.current.get(b), i;
|
|
84
|
+
if (n?.generationId === y) i = l(t, n);
|
|
52
85
|
else {
|
|
53
|
-
let n =
|
|
86
|
+
let n = c(t.messages, r, e);
|
|
54
87
|
if (!n) return t;
|
|
55
|
-
|
|
88
|
+
i = {
|
|
56
89
|
...t,
|
|
57
90
|
messages: n
|
|
58
91
|
};
|
|
59
92
|
}
|
|
60
|
-
return
|
|
93
|
+
return C.current = i, i;
|
|
61
94
|
});
|
|
62
95
|
},
|
|
63
96
|
onComplete: async () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
97
|
+
let n = V.current.get(b), r = n?.generationId === y ? n : void 0;
|
|
98
|
+
if (I(), H.current.has(y) ? H.current.delete(y) : M() || O?.notifyGenerationEnd?.(), !M()) {
|
|
99
|
+
if (!G(b)) {
|
|
100
|
+
r && V.current.delete(b);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
let n = await w.getConversation(e(t));
|
|
105
|
+
if (M()) return;
|
|
106
|
+
if (!G(b)) {
|
|
107
|
+
r && V.current.delete(b);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (r && r.messageIndex === n.messages.length - 1 && p(n) && f(r.message)) {
|
|
111
|
+
W();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
r && V.current.delete(b), o(n), C.current = n;
|
|
115
|
+
} catch {
|
|
116
|
+
M() || W();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
69
119
|
},
|
|
70
120
|
onError: (e) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
121
|
+
if (N.current?.(e), e instanceof a && !M()) {
|
|
122
|
+
Q(e);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
X(e);
|
|
126
|
+
}
|
|
127
|
+
}, X = (e) => {
|
|
128
|
+
let t = V.current.get(b), n = t?.generationId === y ? t : void 0;
|
|
129
|
+
if (n && (e instanceof i ? n.message = {
|
|
130
|
+
...n.message,
|
|
131
|
+
streamErrorMessage: j
|
|
132
|
+
} : V.current.delete(b)), I(), M() || !G(b)) return;
|
|
133
|
+
let a = ee(e, A, j);
|
|
134
|
+
o((e) => {
|
|
135
|
+
if (!e || M() || !G(b)) return e;
|
|
136
|
+
let t = n?.generationId === y ? l(e, n) : e, i = {
|
|
137
|
+
...t,
|
|
138
|
+
messages: t.messages.map((e, t) => t === r ? {
|
|
139
|
+
...e,
|
|
140
|
+
streamErrorMessage: a
|
|
141
|
+
} : e)
|
|
142
|
+
};
|
|
143
|
+
return C.current = i, i;
|
|
144
|
+
});
|
|
145
|
+
}, Z = () => {
|
|
146
|
+
I(), H.current.has(y) ? H.current.delete(y) : M() || O?.notifyGenerationEnd?.();
|
|
147
|
+
}, Q = async (n) => {
|
|
148
|
+
B.current.add(b);
|
|
149
|
+
let i = await d(() => w.getConversation(e(t)), M);
|
|
150
|
+
if (M()) {
|
|
151
|
+
I();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
let a = i?.messages[i.messages.length - 1], s = i != null && i.messages.length - 1 === r && a?.role === m.Assistant;
|
|
155
|
+
if (!i || !s) {
|
|
156
|
+
B.current.delete(b), X(n);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
let c = V.current.get(b), l = c?.generationId === y ? c : void 0;
|
|
160
|
+
if (p(i)) {
|
|
161
|
+
J(t, i, {
|
|
162
|
+
seedMessage: l?.message,
|
|
163
|
+
skipDedupe: !0,
|
|
164
|
+
onSettled: Z
|
|
84
165
|
});
|
|
166
|
+
return;
|
|
85
167
|
}
|
|
168
|
+
B.current.delete(b), l && V.current.delete(b), G(b) && (o(i), C.current = i), Z();
|
|
86
169
|
};
|
|
87
170
|
(async () => {
|
|
88
171
|
try {
|
|
89
|
-
let e =
|
|
90
|
-
|
|
172
|
+
let e = D?.channelId ?? await D?.waitForChannel(S) ?? void 0, t = H.current.has(y);
|
|
173
|
+
if (P.signal.aborted || M() || t) {
|
|
174
|
+
V.current.get(b)?.generationId === y && V.current.delete(b), M() || q(b), R.current === y && (R.current = null, z.current = null, L(null)), E(b, y), D?.notifyGenerationSettled?.(), t ? H.current.delete(y) : M() || O?.notifyGenerationEnd?.();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
w.streamCompletion(b, n, u, Y, g, y, v, k, e);
|
|
91
178
|
} catch (e) {
|
|
92
|
-
|
|
179
|
+
Y.onError(e instanceof Error ? e : Error(String(e)));
|
|
93
180
|
}
|
|
94
181
|
})();
|
|
95
182
|
}, [
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
let
|
|
115
|
-
|
|
183
|
+
T,
|
|
184
|
+
E,
|
|
185
|
+
K,
|
|
186
|
+
q,
|
|
187
|
+
G,
|
|
188
|
+
D?.channelId,
|
|
189
|
+
D?.ensureConnected,
|
|
190
|
+
D?.waitForChannel,
|
|
191
|
+
D?.notifyGenerationSettled,
|
|
192
|
+
O,
|
|
193
|
+
w,
|
|
194
|
+
J,
|
|
195
|
+
A,
|
|
196
|
+
j
|
|
197
|
+
]), X = g((e, t) => {
|
|
198
|
+
let n = s(e), r = V.current.get(n);
|
|
199
|
+
return r ? l(t, r) : t;
|
|
200
|
+
}, []), Z = g(() => {
|
|
201
|
+
let e = R.current;
|
|
202
|
+
if (!e || !r) return;
|
|
203
|
+
let t = s(r);
|
|
204
|
+
z.current === t && (H.current.add(e), O?.notifyStopGenerating?.(), w.stopCompletion({
|
|
116
205
|
generationId: e,
|
|
117
206
|
path: t
|
|
118
207
|
}).catch((e) => {
|
|
119
208
|
let t = e instanceof Error ? e : Error(String(e));
|
|
120
|
-
|
|
209
|
+
k?.(t);
|
|
121
210
|
}));
|
|
122
211
|
}, [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
]),
|
|
128
|
-
transport: v,
|
|
129
|
-
setConversation: g,
|
|
130
|
-
conversationRef: _,
|
|
131
|
-
resumingPathsRef: j,
|
|
132
|
-
bufferedGenerationsRef: M,
|
|
133
|
-
addStreamingPath: L,
|
|
134
|
-
removeStreamingPath: R,
|
|
135
|
-
isPathDisplayed: I
|
|
136
|
-
}), [
|
|
137
|
-
L,
|
|
138
|
-
R,
|
|
139
|
-
I,
|
|
140
|
-
v
|
|
141
|
-
]), U = h != null && T.has(r(h)), W = h == null ? null : r(h);
|
|
212
|
+
r,
|
|
213
|
+
k,
|
|
214
|
+
O,
|
|
215
|
+
w
|
|
216
|
+
]), Q = g((e, t) => J(e, t), [J]), te = r != null && P.has(s(r)), $ = r == null ? null : s(r);
|
|
142
217
|
return {
|
|
143
|
-
startStream:
|
|
144
|
-
handleStop:
|
|
145
|
-
resumeIfAwaitingGeneration:
|
|
146
|
-
restoreBufferedGeneration:
|
|
147
|
-
isStreaming:
|
|
148
|
-
canStopStreaming:
|
|
218
|
+
startStream: Y,
|
|
219
|
+
handleStop: Z,
|
|
220
|
+
resumeIfAwaitingGeneration: Q,
|
|
221
|
+
restoreBufferedGeneration: X,
|
|
222
|
+
isStreaming: te,
|
|
223
|
+
canStopStreaming: $ != null && I === $
|
|
149
224
|
};
|
|
150
225
|
};
|
|
151
226
|
//#endregion
|
|
152
|
-
export {
|
|
227
|
+
export { C as useConversationStream };
|