@epam/ai-dial-chat-hooks 1.1.0-dev.423 → 1.1.0-dev.426

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/{api-error-DuLNy43N.js → api-error/api-error.js} +1 -1
  2. package/api-transport/create-csrf-middleware.js +21 -0
  3. package/api-transport/create-unauthorized-middleware.js +41 -0
  4. package/attachment/useAttachmentAction/useAttachmentAction.js +74 -0
  5. package/attachment/useAttachmentValidation/useAttachmentValidation.js +35 -0
  6. package/attachments.js +3 -2
  7. package/catalog/catalog-derivations.js +10 -0
  8. package/catalog/catalog-primary-action.js +21 -0
  9. package/catalog/create-publish-api.js +27 -0
  10. package/catalog/deployment-endpoint-url.js +34 -0
  11. package/{deployment-id-CxWgJTs9.js → catalog/deployment-id.js} +1 -1
  12. package/catalog/entity-details.js +6 -0
  13. package/catalog/map-deployment-limits-to-catalog.js +73 -0
  14. package/catalog/map-deployment-limits-to-input.js +14 -0
  15. package/catalog/map-deployment-to-catalog-item.js +92 -0
  16. package/catalog/map-entity-details-to-catalog.js +350 -0
  17. package/catalog/map-prompt-to-catalog-item.js +49 -0
  18. package/catalog/map-skill-to-catalog-item.js +123 -0
  19. package/catalog/mcp-endpoint-url.js +26 -0
  20. package/catalog/publish.js +18 -0
  21. package/catalog/useCatalogEditNavigation/useCatalogEditNavigation.js +109 -0
  22. package/catalog/useCatalogItemDetails.js +101 -0
  23. package/catalog/useCatalogToolsetCredentials/useCatalogToolsetCredentials.js +146 -0
  24. package/catalog/useFavoriteEntitiesState/useFavoriteEntitiesState.js +50 -0
  25. package/catalog/usePublishFolders/usePublishFolders.js +72 -0
  26. package/catalog.js +22 -3
  27. package/conversation/announcement-message.js +42 -0
  28. package/conversation/conversation-transfer/async.js +18 -0
  29. package/conversation/conversation-transfer/attachment-refs.js +11 -0
  30. package/conversation/conversation-transfer/build-upload-path.js +27 -0
  31. package/{date-BeuD8G79.js → conversation/conversation-transfer/date.js} +1 -1
  32. package/conversation/conversation-transfer/dial-file-resolve.js +18 -0
  33. package/conversation/conversation-transfer/export-conversation.js +32 -0
  34. package/conversation/conversation-transfer/import-conversation.js +93 -0
  35. package/conversation/conversation-transfer/progress.js +39 -0
  36. package/conversation/conversation-transfer/queue.js +84 -0
  37. package/conversation/conversation-transfer/types.js +9 -0
  38. package/conversation/conversation-transfer/zip-export.js +19 -0
  39. package/conversation/conversation-transfer/zip-import.js +29 -0
  40. package/conversation/create-chat-stream-api.js +96 -0
  41. package/conversation/deriveConversationRowActionState/deriveConversationRowActionState.js +14 -0
  42. package/conversation/display-name-watch.js +5 -0
  43. package/conversation/footer-message.js +23 -0
  44. package/conversation/get-model-id-from-conversation-id.js +14 -0
  45. package/conversation/greeting.js +7 -0
  46. package/conversation/message-factory.js +19 -0
  47. package/conversation/message-utils.js +13 -0
  48. package/conversation/overlay-messages.js +8 -0
  49. package/conversation/quick-app-conversation-starters.js +29 -0
  50. package/conversation/starter-option.js +27 -0
  51. package/conversation/useActiveConversationSync/useActiveConversationSync.js +19 -0
  52. package/conversation/useAsyncConfirmDialog/useAsyncConfirmDialog.js +39 -0
  53. package/conversation/useAttachmentUpload/useAttachmentUpload.js +33 -0
  54. package/conversation/useConversationExport/useConversationExport.js +285 -0
  55. package/conversation/useConversationHandlers/attachment-to-dto.js +13 -0
  56. package/conversation/useConversationHandlers/message-factory.js +21 -0
  57. package/conversation/useConversationHandlers/message-utils.js +8 -0
  58. package/conversation/useConversationHandlers/starter-option.js +11 -0
  59. package/conversation/useConversationHandlers/useConversationHandlers.js +263 -0
  60. package/conversation/useConversationImport/useConversationImport.js +239 -0
  61. package/conversation/useConversationLookupMaps/useConversationLookupMaps.js +11 -0
  62. package/conversation/useConversationPanelItems/useConversationPanelItems.js +35 -0
  63. package/{useConversationScroll-CliIMnjP.js → conversation/useConversationScroll/useConversationScroll.js} +1 -1
  64. package/conversation/useConversationStream/apply-chunk.js +78 -0
  65. package/conversation/useConversationStream/buffered-generation.js +18 -0
  66. package/conversation/useConversationStream/conversation-path.js +8 -0
  67. package/conversation/useConversationStream/generation-resume.js +126 -0
  68. package/conversation/useConversationStream/useConversationStream.js +148 -0
  69. package/conversation/useImportFilePicker/useImportFilePicker.js +20 -0
  70. package/conversation/useTranscribeAudio/audio-transcription-error.js +12 -0
  71. package/conversation/useTranscribeAudio/transcription-retry.js +38 -0
  72. package/conversation/useTranscribeAudio/useTranscribeAudio.js +41 -0
  73. package/{useConversationSources-DKaKvjXZ.js → conversation-sources/useConversationSources/useConversationSources.js} +1 -1
  74. package/conversation-sources.js +1 -1
  75. package/conversation-transfer.js +7 -3
  76. package/conversation.d.ts +66 -0
  77. package/conversation.js +31 -2
  78. package/file-manager.d.ts +3 -4
  79. package/file-manager.js +28 -3
  80. package/files/annotation.js +15 -0
  81. package/files/attachment-canvas.js +218 -0
  82. package/files/attachment-dto-to-display.js +15 -0
  83. package/files/attachment-types.js +16 -0
  84. package/files/create-files-api.js +40 -0
  85. package/files/create-upload-file-with-progress.js +42 -0
  86. package/files/dial-file-manager-copy-move.util.js +55 -0
  87. package/files/dial-file-manager-mapping.util.js +140 -0
  88. package/files/dial-file-manager-path.util.js +72 -0
  89. package/files/dial-file-manager.model.js +25 -0
  90. package/files/dial-file-manager.types.js +10 -0
  91. package/files/dial-file-to-attachment.js +37 -0
  92. package/files/dial-file.js +30 -0
  93. package/files/dial-files-api.js +6 -0
  94. package/files/download-destination.js +6 -0
  95. package/files/file-manager-variant.js +11 -0
  96. package/files/file-name.js +19 -0
  97. package/files/prepare-download-destination.js +24 -0
  98. package/files/resolve-dial-file-api-path.js +33 -0
  99. package/files/source-content.js +37 -0
  100. package/files/useDialFileListing/useDialFileListing.js +295 -0
  101. package/files/useDialFileManager/useDialFileManager.js +146 -0
  102. package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.js +23 -0
  103. package/files/useDialFileMetadata/useDialFileMetadata.js +42 -0
  104. package/files/useDialFileMutations/useDialFileMutations.js +359 -0
  105. package/files/useDialFileSharing/useDialFileSharing.js +70 -0
  106. package/files/useDialFileUploadBatch/useDialFileUploadBatch.js +156 -0
  107. package/index.d.ts +69 -4
  108. package/index.js +134 -28
  109. package/mcp-apps/mcp-apps-api-client.js +48 -0
  110. package/mcp-apps/useMcpAppHostAdapter/useMcpAppHostAdapter.js +26 -0
  111. package/mcp-apps/useMcpAppHostContext/useMcpAppHostContext.js +26 -0
  112. package/mcp-apps/useMcpAppTools/useMcpAppTools.js +71 -0
  113. package/mcp-apps/useOpenMcpAppCanvas/useOpenMcpAppCanvas.js +58 -0
  114. package/mcp-apps.js +6 -2
  115. package/oauth/authorize-url.js +12 -0
  116. package/oauth/handshake.js +65 -0
  117. package/oauth/popup.js +29 -0
  118. package/oauth/toolset-id.js +10 -0
  119. package/oauth/types.js +24 -0
  120. package/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.js +94 -0
  121. package/oauth/useToolsetLogin/useToolsetLogin.js +73 -0
  122. package/oauth.js +9 -3
  123. package/package.json +35 -23
  124. package/prompt/export-prompt.js +28 -0
  125. package/prompt/prompt-resource.js +15 -0
  126. package/prompt/prompt.js +12 -0
  127. package/prompt/usePromptsState/usePromptsState.js +42 -0
  128. package/scheduled-task/scheduled-task-mapping.js +6 -0
  129. package/{scheduled-task-trigger-D9RZCk52.js → scheduled-task/scheduled-task-trigger.js} +39 -40
  130. package/scheduled-tasks.js +3 -2
  131. package/scroll-anchoring.js +1 -1
  132. package/shared/application-schema.js +4 -0
  133. package/shared/browser-timezone.js +10 -0
  134. package/{cron-weekday-B4w29eAC.js → shared/cron-weekday.js} +1 -1
  135. package/shared/custom-apps.js +30 -0
  136. package/shared/external-services.js +18 -0
  137. package/{formatting-CZyyxBG3.js → shared/formatting.js} +1 -1
  138. package/{prompt-resource-Bt1I-8ri.js → shared/locale.js} +2 -13
  139. package/{string-utils-iBi2Y55C.js → shared/string-utils.js} +1 -1
  140. package/shared/toolset-login-events.js +13 -0
  141. package/sharing.js +3 -3
  142. package/skill/skill-file-batch-validation.js +48 -0
  143. package/skill/skill-file-preview.js +15 -0
  144. package/skill/skill-manifest.js +70 -0
  145. package/skill/skill-types.js +15 -0
  146. package/skill/skill.js +48 -0
  147. package/skill/useSkillEditorLoad.js +103 -0
  148. package/skill/useSkillEditorSubmit.js +135 -0
  149. package/skill/useSkillFileActions.js +99 -0
  150. package/skill/useSkillFilePreview.js +29 -0
  151. package/{useSkillsState-BoLlwmzb.js → skill/useSkillsState/useSkillsState.js} +1 -1
  152. package/skill-editor.js +8 -3
  153. package/skills-state.js +1 -1
  154. package/source-content.d.ts +29 -0
  155. package/source-content.js +2 -0
  156. package/usage/useUsageData/useUsageData.js +32 -0
  157. package/useChatSettingsFormConfig/useChatSettingsFormConfig.js +74 -0
  158. package/{usePanelMaxWidth-BEZYuqF9.js → usePageFileDrag/usePageFileDrag.js} +1 -11
  159. package/usePanelMaxWidth/usePanelMaxWidth.js +8 -0
  160. package/{useShareLink-xkiaxATt.js → useShareLink/useShareLink.js} +1 -1
  161. package/{useShareRecipientsCount-BgwCLKY0.js → useShareRecipientsCount/useShareRecipientsCount.js} +1 -1
  162. package/useToolsMenu/useToolsMenu.js +50 -0
  163. package/useViewportWidth/useViewportWidth.js +12 -0
  164. package/utils.js +17 -7
  165. package/viewport-layout.js +4 -2
  166. package/attachment-types-AAoN9E95.js +0 -7760
  167. package/browser-Btsa0Lmr.js +0 -607
  168. package/skill-manifest-CeG6-WSK.js +0 -4056
  169. package/useAttachmentValidation-CkMTd5lA.js +0 -102
  170. package/useConversationImport-CDRs7JF1.js +0 -826
  171. package/useDialFileManagerTabConfig-CjI46lMo.js +0 -2291
  172. package/useOAuthCallbackCompletion-CvyTKLER.js +0 -93
  173. package/useOpenMcpAppCanvas-C7-AMseH.js +0 -207
  174. package/useSkillFileActions-B-VaGD20.js +0 -373
  175. package/useSkillFilePreview-B5o1n_0F.js +0 -1244
  176. package/useToolsMenu-zURpMEn1.js +0 -1882
  177. package/useToolsetLogin-B05m134e.js +0 -195
  178. package/useUsageData-D7BxloKZ.js +0 -201
@@ -0,0 +1,285 @@
1
+ import { ConversationExportMode as e, ConversationTransferWarningCode as t, ExportFileNameKind as n } from "../conversation-transfer/types.js";
2
+ import { EXPORT_APP_NAME as r, buildExportEnvelope as i, buildExportFileName as a, serializeExportEnvelope as o, stripConversationAttachments as s } from "../conversation-transfer/export-conversation.js";
3
+ import { collectAttachmentRefs as c } from "../conversation-transfer/attachment-refs.js";
4
+ import { resolveDialFileBucketAndPath as l } from "../conversation-transfer/dial-file-resolve.js";
5
+ import { runWithConcurrency as u } from "../conversation-transfer/async.js";
6
+ import { ConversationTransferKind as d, ConversationTransferPhase as f, buildTransferProgress as p } from "../conversation-transfer/progress.js";
7
+ import { useConversationTransferQueue as m } from "../conversation-transfer/queue.js";
8
+ import { buildDialArchive as h } from "../conversation-transfer/zip-export.js";
9
+ import { ConversationTransferErrorCode as g, ConversationTransferSubjectKind as _, ConversationTransferUnitKind as v, triggerBlobDownload as y } from "@epam/ai-dial-chat-shared";
10
+ import { useCallback as b } from "react";
11
+ import { ResponseError as x } from "@epam/ai-dial-chat-api-client";
12
+ //#region src/conversation/useConversationExport/useConversationExport.ts
13
+ var S = 5, C = 512 * 1024 * 1024, w = 429, T = 5, E = 2e3, D = (e) => e instanceof x && e.response.status === w, O = (e, t) => {
14
+ let n = Number(e.response.headers.get("Retry-After"));
15
+ return Number.isFinite(n) && n > 0 ? n * 1e3 : E * t;
16
+ }, k = (e, t) => new Promise((n) => {
17
+ if (t.aborted) {
18
+ n();
19
+ return;
20
+ }
21
+ let r = setTimeout(n, e);
22
+ t.addEventListener("abort", () => {
23
+ clearTimeout(r), n();
24
+ }, { once: !0 });
25
+ }), A = async (e, t, n) => {
26
+ for (let r = 1;; r += 1) try {
27
+ return await e.getConversation({ path: t }, { signal: n });
28
+ } catch (e) {
29
+ if (n.aborted || !D(e) || r >= T) throw e;
30
+ await k(O(e, r), n);
31
+ }
32
+ }, j = (e) => !e.sharedWithMe && !e.publishedWithMe, M = (e) => e instanceof RangeError, N = (t) => t === e.WithoutAttachments ? d.ExportSingle : d.ExportSingleWithAttachments, P = ({ conversationsApi: x, filesApi: w, normalizeConversationPath: T, classifyTransferError: E = () => ({}), resolveErrorTraceId: D = async () => void 0, maxArchiveBytes: O = C, onSuccess: k, onWarning: P, onError: F }) => {
33
+ let I = m(), L = b(async (e, t, n) => {
34
+ let r = !1, i = !1, a = 0, o = () => {
35
+ a += 1, n(a, e.length);
36
+ };
37
+ return {
38
+ entries: await u(e, S, async (e) => {
39
+ if (t.aborted || i) return;
40
+ let n = l(e.fileId);
41
+ if (!n) {
42
+ r = !0, o();
43
+ return;
44
+ }
45
+ try {
46
+ let e = await w.downloadFileRaw({
47
+ bucket: n.bucket,
48
+ path: n.path
49
+ }, { signal: t }), r = new Uint8Array(await e.raw.arrayBuffer());
50
+ return o(), {
51
+ path: n.path,
52
+ data: r
53
+ };
54
+ } catch (e) {
55
+ if (t.aborted) return;
56
+ if (E(e).isUnauthorized) {
57
+ i = !0;
58
+ return;
59
+ }
60
+ r = !0, o();
61
+ return;
62
+ }
63
+ }),
64
+ anySkipped: !t.aborted && !i && r,
65
+ isUnauthorized: !t.aborted && i
66
+ };
67
+ }, [E, w]), R = b(async (n, r, a, l, u, d) => {
68
+ let m = N(l), _;
69
+ try {
70
+ _ = await A(x, T(r), d);
71
+ } catch (e) {
72
+ if (d.aborted) return;
73
+ if (E(e).isUnauthorized) F?.({
74
+ jobId: n,
75
+ code: g.Unauthorized
76
+ }), I.failJob(n, g.Unauthorized);
77
+ else {
78
+ let t = await D(e);
79
+ F?.({
80
+ jobId: n,
81
+ code: g.Unknown,
82
+ titles: [a],
83
+ traceId: t
84
+ }), I.failJob(n, g.Unknown);
85
+ }
86
+ console.error("Failed to fetch conversation for export", e);
87
+ return;
88
+ }
89
+ if (!d.aborted) {
90
+ I.setJobProgress(n, p({
91
+ kind: m,
92
+ phase: f.Prepare
93
+ }));
94
+ try {
95
+ if (l === e.WithoutAttachments) {
96
+ y(o(i([s(_)], [])), u), k?.({
97
+ jobId: n,
98
+ titles: [a]
99
+ }), I.succeedJob(n);
100
+ return;
101
+ }
102
+ let r = c(_), { entries: b, anySkipped: x, isUnauthorized: S } = await L(r, d, (e, t) => {
103
+ I.setJobProgress(n, p({
104
+ kind: m,
105
+ phase: f.Transfer,
106
+ completed: e,
107
+ total: t
108
+ }, {
109
+ completed: e,
110
+ total: t,
111
+ kind: v.Attachment
112
+ }));
113
+ });
114
+ if (d.aborted) return;
115
+ if (S) {
116
+ F?.({
117
+ jobId: n,
118
+ code: g.Unauthorized
119
+ }), I.failJob(n, g.Unauthorized);
120
+ return;
121
+ }
122
+ I.setJobProgress(n, p({
123
+ kind: m,
124
+ phase: f.Transfer,
125
+ completed: r.length,
126
+ total: r.length
127
+ }));
128
+ let C = b.reduce((e, t) => e + t.data.byteLength, 0);
129
+ if (C > O) {
130
+ F?.({
131
+ jobId: n,
132
+ code: g.FileTooLarge,
133
+ titles: [a]
134
+ }), I.failJob(n, g.FileTooLarge), console.error(`Refused to build an export archive of ${C} bytes: over the ${O}-byte limit`);
135
+ return;
136
+ }
137
+ let { blob: w, skippedPaths: T } = h(i([_], []), b), E = x || T.length > 0;
138
+ E && P?.({
139
+ jobId: n,
140
+ code: t.AttachmentSkipped
141
+ }), y(w, u), k?.({
142
+ jobId: n,
143
+ titles: [a]
144
+ }), E ? I.warnJob(n, t.AttachmentSkipped) : I.succeedJob(n);
145
+ } catch (e) {
146
+ if (d.aborted) return;
147
+ let t = M(e) ? g.FileTooLarge : g.Unknown, r = await D(e);
148
+ F?.({
149
+ jobId: n,
150
+ code: t,
151
+ titles: [a],
152
+ traceId: r
153
+ }), I.failJob(n, t), console.error("Failed to build conversation export archive", e);
154
+ }
155
+ }
156
+ }, [
157
+ E,
158
+ x,
159
+ L,
160
+ O,
161
+ T,
162
+ F,
163
+ k,
164
+ P,
165
+ I,
166
+ D
167
+ ]), z = b((t, i, o) => {
168
+ let s = a(o === e.WithoutAttachments ? n.SingleConversation : n.SingleConversationWithAttachments, r), c = I.addJob({
169
+ kind: _.Single,
170
+ title: i
171
+ }, s);
172
+ return I.startJob(c, (e) => R(c, t, i, o, s, e));
173
+ }, [I, R]), B = b(async (e, t, n) => {
174
+ let r = d.ExportAll, a = [], s;
175
+ do {
176
+ if (n.aborted) return;
177
+ let t;
178
+ try {
179
+ t = await x.listConversations({ nextToken: s }, { signal: n });
180
+ } catch (t) {
181
+ if (n.aborted) return;
182
+ if (E(t).isUnauthorized) F?.({
183
+ jobId: e,
184
+ code: g.Unauthorized
185
+ }), I.failJob(e, g.Unauthorized);
186
+ else {
187
+ let n = await D(t);
188
+ F?.({
189
+ jobId: e,
190
+ code: g.Unknown,
191
+ traceId: n
192
+ }), I.failJob(e, g.Unknown);
193
+ }
194
+ console.error("Failed to list conversations for export", t);
195
+ return;
196
+ }
197
+ a.push(...t.items.filter(j).map((e) => ({
198
+ id: e.id,
199
+ title: e.title
200
+ }))), s = t.nextToken;
201
+ } while (s);
202
+ I.setJobProgress(e, p({
203
+ kind: r,
204
+ phase: f.Prepare
205
+ }));
206
+ let c = [];
207
+ for (let t of a) {
208
+ if (n.aborted) return;
209
+ try {
210
+ let e = await A(x, T(t.id), n);
211
+ c.push(e);
212
+ } catch (r) {
213
+ if (n.aborted) return;
214
+ let i = E(r);
215
+ if (i.isUnauthorized) {
216
+ F?.({
217
+ jobId: e,
218
+ code: g.Unauthorized
219
+ }), I.failJob(e, g.Unauthorized);
220
+ return;
221
+ }
222
+ if (i.isNotFound) {
223
+ let n = await D(r);
224
+ F?.({
225
+ jobId: e,
226
+ code: g.NotFound,
227
+ titles: [t.title],
228
+ traceId: n
229
+ }), console.error("Skipped a conversation during export-all: not found", r);
230
+ continue;
231
+ }
232
+ let a = await D(r);
233
+ F?.({
234
+ jobId: e,
235
+ code: g.Unknown,
236
+ traceId: a
237
+ }), I.failJob(e, g.Unknown), console.error("Aborted export-all: failed to fetch conversation", r);
238
+ return;
239
+ } finally {
240
+ I.setJobProgress(e, p({
241
+ kind: r,
242
+ phase: f.Transfer,
243
+ completed: c.length,
244
+ total: a.length
245
+ }, {
246
+ completed: c.length,
247
+ total: a.length,
248
+ kind: v.Conversation
249
+ }));
250
+ }
251
+ }
252
+ if (!n.aborted) try {
253
+ y(o(i(c, [])), t), k?.({ jobId: e }), I.succeedJob(e);
254
+ } catch (t) {
255
+ let n = M(t) ? g.FileTooLarge : g.Unknown, r = await D(t);
256
+ F?.({
257
+ jobId: e,
258
+ code: n,
259
+ traceId: r
260
+ }), I.failJob(e, n), console.error("Failed to build export-all archive", t);
261
+ }
262
+ }, [
263
+ E,
264
+ x,
265
+ T,
266
+ F,
267
+ k,
268
+ I,
269
+ D
270
+ ]), V = b(() => {
271
+ let e = a(n.AllConversationsHistory, r), t = I.addJob({ kind: _.All }, e);
272
+ return I.startJob(t, (n) => B(t, e, n));
273
+ }, [I, B]);
274
+ return {
275
+ jobs: I.jobs,
276
+ exportSingle: z,
277
+ exportAll: V,
278
+ cancelJob: I.cancelJob,
279
+ dismissJob: I.dismissJob,
280
+ retryJob: I.retryJob,
281
+ dismissAll: I.dismissAll
282
+ };
283
+ };
284
+ //#endregion
285
+ export { C as DEFAULT_MAX_ARCHIVE_BYTES, P as useConversationExport };
@@ -0,0 +1,13 @@
1
+ //#region src/conversation/useConversationHandlers/attachment-to-dto.ts
2
+ var e = (e) => {
3
+ if (!e.url) throw Error(`Attachment "${e.name}" has not been uploaded`);
4
+ return {
5
+ type: e.contentType,
6
+ title: e.name,
7
+ url: e.url
8
+ };
9
+ }, t = (t) => {
10
+ if (t.length) return t.map(e);
11
+ };
12
+ //#endregion
13
+ export { e as attachmentToDto, t as attachmentsToDtos };
@@ -0,0 +1,21 @@
1
+ import { MessageRole as e } from "@epam/ai-dial-chat-shared";
2
+ //#region src/conversation/useConversationHandlers/message-factory.ts
3
+ var t = (t, n, r) => {
4
+ let i = new Date(Date.now()).toISOString();
5
+ return {
6
+ userMessage: {
7
+ role: e.User,
8
+ content: t,
9
+ timestamp: i,
10
+ ...n && Object.keys(n).length ? { custom_content: n } : {}
11
+ },
12
+ assistantMessage: {
13
+ role: e.Assistant,
14
+ content: "",
15
+ timestamp: i,
16
+ ...r ? { deploymentId: r } : {}
17
+ }
18
+ };
19
+ };
20
+ //#endregion
21
+ export { t as createMessagePair };
@@ -0,0 +1,8 @@
1
+ //#region src/conversation/useConversationHandlers/message-utils.ts
2
+ var e = (e) => e != null && Object.keys(e).length > 0, t = (e, t, n, r) => {
3
+ if (t !== e.content || r.length > 0) return !0;
4
+ let i = e.custom_content?.attachments?.length ?? 0;
5
+ return n.length !== i;
6
+ };
7
+ //#endregion
8
+ export { e as hasActiveToolConfig, t as isMessageChanged };
@@ -0,0 +1,11 @@
1
+ import { getStarterPopulateText as e } from "../starter-option.js";
2
+ //#region src/conversation/useConversationHandlers/starter-option.ts
3
+ var t = (t, n) => {
4
+ let { populateText: r } = t["dial:widgetOptions"];
5
+ return r == null && n ? n : e(t);
6
+ }, n = (t, n) => {
7
+ let { populateText: r, submit: i } = t["dial:widgetOptions"];
8
+ return i && r == null ? "" : n ?? e(t);
9
+ };
10
+ //#endregion
11
+ export { t as getStarterConversationText, n as getStarterSubmitText };
@@ -0,0 +1,263 @@
1
+ import { useAttachmentUpload as e } from "../useAttachmentUpload/useAttachmentUpload.js";
2
+ import { attachmentsToDtos as t } from "./attachment-to-dto.js";
3
+ import { createMessagePair as n } from "./message-factory.js";
4
+ import { hasActiveToolConfig as r, isMessageChanged as i } from "./message-utils.js";
5
+ import { getStarterSubmitText as a } from "./starter-option.js";
6
+ import { getConversationPath as o } from "../useConversationStream/conversation-path.js";
7
+ import { MessageRole as s, generateUUID as c } from "@epam/ai-dial-chat-shared";
8
+ import { useCallback as l, useState as u } from "react";
9
+ import { SendCompletionDtoModeEnum as d } from "@epam/ai-dial-chat-api-client";
10
+ //#region src/conversation/useConversationHandlers/useConversationHandlers.ts
11
+ var f = ({ conversation: f, conversationId: p, bucket: m, isStreaming: h, startStream: g, state: { setConversation: _, conversationRef: v }, filesApi: y, conversationsApi: b, rateApi: x, resolveModelId: S, onConversationDeleted: C, showNetworkError: w, toolConfigurationValue: T }) => {
12
+ let [E, D] = u(null), [O, k] = u(/* @__PURE__ */ new Set()), [A, j] = u(null), { handleUploadAttachment: M } = e({
13
+ filesApi: y,
14
+ bucket: m,
15
+ onNetworkError: w
16
+ }), N = l(async (e, i) => {
17
+ if (!p || !f) return;
18
+ let a = t(i), o = r(T), s = a?.length || o ? {
19
+ ...a?.length ? { attachments: a } : {},
20
+ ...o ? { configuration_value: T } : {}
21
+ } : void 0, l = S(), { userMessage: u, assistantMessage: m } = n(e, s, l);
22
+ _((e) => {
23
+ if (!e) return e;
24
+ let t = {
25
+ ...e,
26
+ messages: [
27
+ ...e.messages,
28
+ u,
29
+ m
30
+ ]
31
+ };
32
+ return v.current = t, t;
33
+ }), g(p, e, f.messages.length + 1, l, s, c(), d.Append);
34
+ }, [
35
+ f,
36
+ p,
37
+ v,
38
+ S,
39
+ _,
40
+ g,
41
+ T
42
+ ]), P = l((e) => {
43
+ if (h || !p || !f || e === -1 || f.messages[e]?.role !== s.Assistant) return;
44
+ let t = f.messages[e - 1];
45
+ if (!t || t.role !== s.User) return;
46
+ let n = S();
47
+ _((t) => {
48
+ if (!t) return t;
49
+ let r = {
50
+ ...t.messages[e],
51
+ content: "",
52
+ custom_content: void 0,
53
+ wasStoppedByUser: void 0,
54
+ stoppedWithoutContent: void 0,
55
+ streamErrorMessage: void 0,
56
+ deploymentId: n
57
+ }, i = {
58
+ ...t,
59
+ messages: [...t.messages.slice(0, e), r]
60
+ };
61
+ return v.current = i, i;
62
+ }), k((t) => new Set([...t].filter((t) => t < e))), g(p, t.content, e, n, t.custom_content, c(), d.Regenerate);
63
+ }, [
64
+ f,
65
+ p,
66
+ v,
67
+ h,
68
+ S,
69
+ _,
70
+ g
71
+ ]), F = l((e) => {
72
+ h || D(e);
73
+ }, [h]), I = l(() => {
74
+ if (!p || E == null) return;
75
+ let e = E;
76
+ D(null);
77
+ let t = v.current;
78
+ if (!t || e === -1) return;
79
+ let n = o(p), r = t.messages[e + 1]?.role === s.Assistant ? t.messages.filter((t, n) => n !== e && n !== e + 1) : t.messages.filter((t, n) => n !== e);
80
+ if (r.length === 0 || r.length === 1 && r[0].role === s.Status) {
81
+ b.deleteConversation({ path: n }), C?.();
82
+ return;
83
+ }
84
+ let i = {
85
+ ...t,
86
+ messages: r
87
+ };
88
+ v.current = i, _(i), b.saveConversation({
89
+ path: n,
90
+ saveConversationBodyDto: { conversation: i }
91
+ });
92
+ }, [
93
+ p,
94
+ v,
95
+ b,
96
+ C,
97
+ E,
98
+ _
99
+ ]), L = l(async (e, t, n) => {
100
+ if (!p || !f) return !1;
101
+ let r = f.messages[e];
102
+ if (!r) return !1;
103
+ let i = r.rating, a = {
104
+ ...f,
105
+ messages: f.messages.map((n, r) => r === e ? {
106
+ ...n,
107
+ rating: t ?? void 0
108
+ } : n)
109
+ };
110
+ _(() => (v.current = a, a));
111
+ let s = o(p), c = () => {
112
+ _((t) => t && {
113
+ ...t,
114
+ messages: t.messages.map((t, n) => n === e ? {
115
+ ...t,
116
+ rating: i
117
+ } : t)
118
+ });
119
+ }, l = () => b.saveConversation({
120
+ path: s,
121
+ saveConversationBodyDto: { conversation: a }
122
+ });
123
+ if (t != null) {
124
+ let e = r.responseId;
125
+ if (!e) return c(), !1;
126
+ try {
127
+ return await x.rateMessage({ rateMessageDto: {
128
+ conversationId: f.id,
129
+ responseId: e,
130
+ modelId: f.model.id,
131
+ rate: t,
132
+ ...n ? { comment: n } : {}
133
+ } }), await l(), !0;
134
+ } catch {
135
+ return c(), !1;
136
+ }
137
+ } else try {
138
+ return await l(), !0;
139
+ } catch {
140
+ return c(), !1;
141
+ }
142
+ }, [
143
+ f,
144
+ p,
145
+ v,
146
+ b,
147
+ x,
148
+ _
149
+ ]), R = l((e, t, i) => {
150
+ if (!p || !f) return;
151
+ let o = i ?? e.title, s = a(e, i), l = t ? { [t]: e.const } : void 0, u = r(T), m = l || u ? {
152
+ ...l ? { form_value: l } : {},
153
+ ...u ? { configuration_value: T } : {}
154
+ } : void 0, h = S(), { userMessage: y, assistantMessage: b } = n(o, m, h);
155
+ _((e) => {
156
+ if (!e) return e;
157
+ let t = {
158
+ ...e,
159
+ messages: [
160
+ ...e.messages,
161
+ y,
162
+ b
163
+ ]
164
+ };
165
+ return v.current = t, t;
166
+ }), g(p, s, f.messages.length + 1, h, m, c(), d.Append);
167
+ }, [
168
+ f,
169
+ p,
170
+ v,
171
+ S,
172
+ _,
173
+ g,
174
+ T
175
+ ]);
176
+ return {
177
+ handleSend: N,
178
+ handleUploadAttachment: M,
179
+ handleRegenerateMessage: P,
180
+ handleDeleteMessage: F,
181
+ handleConfirmDelete: I,
182
+ handleRateMessage: L,
183
+ handleButtonSelect: l((e, t, n) => {
184
+ !p || !f || h || (e["dial:widgetOptions"].confirmationMessage ? j({
185
+ starter: e,
186
+ propertyKey: t,
187
+ description: n
188
+ }) : R(e, t, n));
189
+ }, [
190
+ f,
191
+ p,
192
+ h,
193
+ R
194
+ ]),
195
+ handleConfirmStarter: l(() => {
196
+ if (!A) return;
197
+ let { starter: e, propertyKey: t, description: n } = A;
198
+ j(null), R(e, t, n);
199
+ }, [A, R]),
200
+ handleStartEdit: l((e) => {
201
+ k((t) => new Set([...t, e]));
202
+ }, []),
203
+ handleCancelEdit: l((e) => {
204
+ k((t) => {
205
+ let n = new Set(t);
206
+ return n.delete(e), n;
207
+ });
208
+ }, []),
209
+ handleEditMessage: l(async (e, n, r, a) => {
210
+ if (h || !p || !f) return;
211
+ let o = e;
212
+ if (o === -1 || f.messages[o].role !== s.User) return;
213
+ let l = f.messages[o];
214
+ if (!i(l, n, r, a)) {
215
+ k((e) => {
216
+ let t = new Set(e);
217
+ return t.delete(o), t;
218
+ });
219
+ return;
220
+ }
221
+ let u = t(a), m = new Set(r.map((e) => e.id)), y = [...(l.custom_content?.attachments ?? []).filter((e) => {
222
+ let t = e.url ?? e.data ?? e.title;
223
+ return m.has(t);
224
+ }), ...u ?? []], { attachments: b, ...x } = l.custom_content ?? {}, C = y.length > 0 ? {
225
+ ...x,
226
+ attachments: y
227
+ } : Object.keys(x).length > 0 ? x : void 0, w = {
228
+ ...l,
229
+ content: n,
230
+ custom_content: C
231
+ }, T = Date.now(), E = {
232
+ role: s.Assistant,
233
+ content: "",
234
+ timestamp: new Date(T).toISOString()
235
+ }, D = [
236
+ ...f.messages.slice(0, o),
237
+ w,
238
+ E
239
+ ], O = {
240
+ ...f,
241
+ messages: D
242
+ };
243
+ _(() => (v.current = O, O));
244
+ let A = S();
245
+ g(p, n, D.length - 1, A, C, c(), d.Edit), k(/* @__PURE__ */ new Set());
246
+ }, [
247
+ f,
248
+ p,
249
+ v,
250
+ h,
251
+ S,
252
+ _,
253
+ g
254
+ ]),
255
+ editingMessageIndexes: O,
256
+ pendingDeleteIndex: E,
257
+ setPendingDeleteIndex: D,
258
+ pendingStarterContext: A,
259
+ setPendingStarterContext: j
260
+ };
261
+ };
262
+ //#endregion
263
+ export { f as useConversationHandlers };