@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
@@ -1,826 +0,0 @@
1
- import { n as e, t } from "./date-BeuD8G79.js";
2
- import { i as n, n as r, r as i, t as a } from "./browser-Btsa0Lmr.js";
3
- import { ConversationTransferErrorCode as o, ConversationTransferErrorCode as s, ConversationTransferJobStatus as c, ConversationTransferSubjectKind as l, ConversationTransferUnitKind as u, ConversationTransferWarningCode as d, generateUUID as f, triggerBlobDownload as p } from "@epam/ai-dial-chat-shared";
4
- import { useCallback as m, useEffect as h, useRef as g, useState as _ } from "react";
5
- import { ResponseError as v } from "@epam/ai-dial-chat-api-client";
6
- //#region src/conversation/conversation-transfer/types.ts
7
- var y = /* @__PURE__ */ function(e) {
8
- return e.WithAttachments = "withAttachments", e.WithoutAttachments = "withoutAttachments", e;
9
- }({}), b = /* @__PURE__ */ function(e) {
10
- return e.SingleConversation = "chat_conversation", e.SingleConversationWithAttachments = "chat_with_attachments", e.AllConversationsHistory = "chat_conversations_history", e;
11
- }({}), x = "ai_dial", S = (e) => e.map(({ attachments: e, ...t }) => t), C = (e) => {
12
- let t = e.custom_content;
13
- if (!t) return e;
14
- let { attachments: n, stages: r, ...i } = t;
15
- if (n == null && r == null) return e;
16
- let a = {
17
- ...i,
18
- ...r ? { stages: S(r) } : {}
19
- };
20
- if (Object.keys(a).length > 0) return {
21
- ...e,
22
- custom_content: a
23
- };
24
- let { custom_content: o, ...s } = e;
25
- return s;
26
- }, w = (e) => ({
27
- ...e,
28
- messages: e.messages.map(C)
29
- }), T = (e, t = []) => ({
30
- version: 5,
31
- history: e,
32
- folders: t
33
- }), E = (e) => new Blob([JSON.stringify(e, null, 2)], { type: "application/json" }), D = {
34
- [b.SingleConversation]: "json",
35
- [b.SingleConversationWithAttachments]: "dial",
36
- [b.AllConversationsHistory]: "json"
37
- }, O = (t, n, r = /* @__PURE__ */ new Date()) => `${e(r)}_${n}_${t}.${D[t]}`, k = (e) => e.startsWith("files/"), A = (e) => {
38
- let t = /* @__PURE__ */ new Set();
39
- for (let n of e.messages) for (let e of n.custom_content?.attachments ?? []) {
40
- let n = e.url ?? e.reference_url;
41
- n != null && k(n) && t.add(n);
42
- }
43
- return Array.from(t, (e) => ({ fileId: e }));
44
- }, ee = (e) => e.startsWith("files/"), j = (e) => {
45
- if (!ee(e)) return;
46
- let t = e.slice(6), n = t.indexOf("/");
47
- if (n < 0) return;
48
- let r = t.slice(0, n), i = t.slice(n + 1), a;
49
- try {
50
- a = decodeURIComponent(i);
51
- } catch {
52
- a = i;
53
- }
54
- return {
55
- bucket: r,
56
- path: a
57
- };
58
- }, M = class extends Error {
59
- constructor(e) {
60
- super(e), this.name = "UnsupportedImportFormatError";
61
- }
62
- }, te = (e) => typeof e == "object" && !!e, N = 5, P = (e) => {
63
- let t;
64
- try {
65
- t = JSON.parse(e);
66
- } catch {
67
- throw new M("Import file is not valid JSON");
68
- }
69
- if (!te(t) || t.version !== N || !Array.isArray(t.history)) throw new M("Import file is not a supported export format");
70
- let n = Array.isArray(t.folders) ? t.folders : [];
71
- return {
72
- version: N,
73
- history: t.history,
74
- folders: n
75
- };
76
- }, ne = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, re = (e) => {
77
- let t = e.lastIndexOf("__");
78
- if (t < 0) return e;
79
- let n = e.slice(t + 2);
80
- return ne.test(n) ? e.slice(0, t) : e;
81
- }, ie = "conversations/", F = (e) => e.startsWith(ie) ? e.slice(14) : e, I = (e, t) => {
82
- let n = F(e.id), r = n.split("/"), i = F(e.folderId), a = r[0], o = i.startsWith(`${a}/`) ? i.slice(a.length + 1).split("/").filter(Boolean) : [], s = r.slice(1).slice(o.length), c = s.slice(0, -1), l = `${re(s.at(-1) ?? r.at(-1) ?? n)}__${f()}`, u = [
83
- ...o,
84
- ...c,
85
- l
86
- ].join("/"), d = o.length ? `${t}/${o.join("/")}` : t;
87
- return {
88
- conversation: {
89
- ...e,
90
- id: `${t}/${u}`,
91
- folderId: d
92
- },
93
- subPath: u
94
- };
95
- }, ae = (e) => {
96
- let t = F(e.folderId).split("/").filter(Boolean).slice(1);
97
- return t.length ? t.join(" / ") : void 0;
98
- }, oe = (e) => e.map((e) => `"${e}"`).join(", "), se = (e, t) => ({
99
- ...e,
100
- messages: e.messages.map((e) => {
101
- let n = e.custom_content?.attachments;
102
- return n?.length ? {
103
- ...e,
104
- custom_content: {
105
- ...e.custom_content,
106
- attachments: n.map((e) => {
107
- let n = e.url ? t.get(e.url) : void 0, r = e.reference_url ? t.get(e.reference_url) : void 0;
108
- if (n == null && r == null) return e;
109
- let i = n?.title ?? r?.title;
110
- return {
111
- ...e,
112
- ...n == null ? {} : { url: n.url },
113
- ...r == null ? {} : { reference_url: r.url },
114
- ...i == null ? {} : { title: i }
115
- };
116
- })
117
- }
118
- } : e;
119
- })
120
- }), ce = (e) => e.split("/").pop() || e, le = (e, t, n) => {
121
- let r = [], i = [];
122
- for (let a of A(e)) {
123
- let e = j(a.fileId);
124
- if (!e) {
125
- i.push(ce(a.fileId));
126
- continue;
127
- }
128
- let o = e.path.split("/").pop() ?? e.path, s = t.get(e.path);
129
- if (!s) {
130
- i.push(o);
131
- continue;
132
- }
133
- r.push({
134
- fileId: a.fileId,
135
- bytes: s,
136
- originalFileName: o,
137
- allocated: n.allocate(o)
138
- });
139
- }
140
- return {
141
- plan: r,
142
- skippedNames: i
143
- };
144
- }, L = async (e, t, n) => {
145
- let r = [], i = 0, a = async () => {
146
- let t = i;
147
- if (i += 1, !(t >= e.length)) {
148
- try {
149
- let i = await n(e[t]);
150
- i !== void 0 && r.push(i);
151
- } catch (e) {
152
- console.error("runWithConcurrency: worker failed for item", e);
153
- }
154
- await a();
155
- }
156
- };
157
- return await Promise.all(Array.from({ length: Math.min(t, e.length) }, a)), r;
158
- }, R = /* @__PURE__ */ function(e) {
159
- return e.Prepare = "prepare", e.Transfer = "transfer", e.Finalize = "finalize", e;
160
- }({}), z = /* @__PURE__ */ function(e) {
161
- return e.ExportSingle = "exportSingle", e.ExportSingleWithAttachments = "exportSingleWithAttachments", e.ExportAll = "exportAll", e.Import = "import", e;
162
- }({}), ue = {
163
- exportSingle: {
164
- prepare: 20,
165
- transfer: 0,
166
- finalize: 80
167
- },
168
- exportSingleWithAttachments: {
169
- prepare: 15,
170
- transfer: 70,
171
- finalize: 15
172
- },
173
- exportAll: {
174
- prepare: 20,
175
- transfer: 70,
176
- finalize: 10
177
- },
178
- import: {
179
- prepare: 10,
180
- transfer: 70,
181
- finalize: 20
182
- }
183
- }, B = [
184
- "prepare",
185
- "transfer",
186
- "finalize"
187
- ], V = (e, t) => B.slice(0, B.indexOf(t)).reduce((t, n) => t + e[n], 0), H = ({ kind: e, phase: t, completed: n = 0, total: r = 0 }) => {
188
- let i = ue[e], a = r > 0 ? Math.min(n / r, 1) : 1, o = V(i, t) + i[t] * a;
189
- return Math.round(Math.min(Math.max(o, 0), 100));
190
- }, U = (e, t) => ({
191
- percent: H(e),
192
- units: t
193
- }), W = () => {
194
- let [e, t] = _([]), n = g(/* @__PURE__ */ new Map()), r = g(/* @__PURE__ */ new Map()), i = m((e, n) => {
195
- t((t) => t.map((t) => t.id === e ? {
196
- ...t,
197
- ...n
198
- } : t));
199
- }, []), a = m((e, n) => {
200
- t((t) => t.map((t) => t.id !== e || t.status !== c.InProgress || n.percent < t.progress.percent ? t : {
201
- ...t,
202
- progress: n
203
- }));
204
- }, []), o = m((e, n) => {
205
- let r = f();
206
- return t((t) => [...t, {
207
- id: r,
208
- subject: e,
209
- status: c.InProgress,
210
- fileName: n,
211
- progress: { percent: 0 }
212
- }]), r;
213
- }, []), s = m((e) => {
214
- i(e, {
215
- status: c.Success,
216
- progress: { percent: 100 },
217
- errorCode: void 0
218
- });
219
- }, [i]), l = m((e, n) => {
220
- t((t) => t.map((t) => t.id !== e || t.status !== c.InProgress ? t : {
221
- ...t,
222
- status: c.Warning,
223
- progress: { percent: 100 },
224
- errorCode: void 0,
225
- warningCode: n
226
- }));
227
- }, []), u = m((e, t) => {
228
- i(e, {
229
- status: c.Failed,
230
- errorCode: t
231
- });
232
- }, [i]), d = m((e) => {
233
- n.current.get(e)?.abort(), n.current.delete(e), i(e, { status: c.Canceled });
234
- }, [i]), p = m((e) => {
235
- n.current.get(e)?.abort(), n.current.delete(e), r.current.delete(e), t((t) => t.filter((t) => t.id !== e));
236
- }, []), v = m((e) => {
237
- r.current.get(e)?.();
238
- }, []), y = m(() => {
239
- for (let e of n.current.values()) e.abort();
240
- n.current.clear(), r.current.clear(), t([]);
241
- }, []), b = m((e, t) => {
242
- let a = () => {
243
- let r = new AbortController();
244
- return n.current.set(e, r), t(r.signal);
245
- };
246
- return r.current.set(e, () => (i(e, {
247
- status: c.InProgress,
248
- progress: { percent: 0 },
249
- errorCode: void 0
250
- }), a())), a();
251
- }, [i]);
252
- return h(() => {
253
- let e = n.current;
254
- return () => {
255
- for (let t of e.values()) t.abort();
256
- };
257
- }, []), {
258
- jobs: e,
259
- addJob: o,
260
- updateJob: i,
261
- setJobProgress: a,
262
- succeedJob: s,
263
- warnJob: l,
264
- failJob: u,
265
- cancelJob: d,
266
- dismissJob: p,
267
- retryJob: v,
268
- dismissAll: y,
269
- startJob: b
270
- };
271
- }, G = r("", !0).constructor, K = (e) => e instanceof G ? e : new G(e), q = (e) => e.length > 0 && e.split("/").every((e) => e !== "" && e !== "." && e !== ".."), de = (e, t) => {
272
- let i = [], a = { "conversation.json": K(r(JSON.stringify(e, null, 2))) };
273
- for (let e of t) {
274
- if (!q(e.path)) {
275
- i.push(e.path);
276
- continue;
277
- }
278
- a[`res/${e.path}`] = K(e.data);
279
- }
280
- let o = n(a);
281
- return {
282
- blob: new Blob([new Uint8Array(o)], { type: "application/zip" }),
283
- skippedPaths: i
284
- };
285
- }, fe = 5, J = 512 * 1024 * 1024, pe = 429, me = 5, he = 2e3, ge = (e) => e instanceof v && e.response.status === pe, _e = (e, t) => {
286
- let n = Number(e.response.headers.get("Retry-After"));
287
- return Number.isFinite(n) && n > 0 ? n * 1e3 : he * t;
288
- }, ve = (e, t) => new Promise((n) => {
289
- if (t.aborted) {
290
- n();
291
- return;
292
- }
293
- let r = setTimeout(n, e);
294
- t.addEventListener("abort", () => {
295
- clearTimeout(r), n();
296
- }, { once: !0 });
297
- }), Y = async (e, t, n) => {
298
- for (let r = 1;; r += 1) try {
299
- return await e.getConversation({ path: t }, { signal: n });
300
- } catch (e) {
301
- if (n.aborted || !ge(e) || r >= me) throw e;
302
- await ve(_e(e, r), n);
303
- }
304
- }, ye = (e) => !e.sharedWithMe && !e.publishedWithMe, X = (e) => e instanceof RangeError, be = (e) => e === y.WithoutAttachments ? z.ExportSingle : z.ExportSingleWithAttachments, xe = ({ conversationsApi: e, filesApi: t, normalizeConversationPath: n, classifyTransferError: r = () => ({}), resolveErrorTraceId: i = async () => void 0, maxArchiveBytes: a = J, onSuccess: s, onWarning: c, onError: f }) => {
305
- let h = W(), g = m(async (e, n, i) => {
306
- let a = !1, o = !1, s = 0, c = () => {
307
- s += 1, i(s, e.length);
308
- };
309
- return {
310
- entries: await L(e, fe, async (e) => {
311
- if (n.aborted || o) return;
312
- let i = j(e.fileId);
313
- if (!i) {
314
- a = !0, c();
315
- return;
316
- }
317
- try {
318
- let e = await t.downloadFileRaw({
319
- bucket: i.bucket,
320
- path: i.path
321
- }, { signal: n }), r = new Uint8Array(await e.raw.arrayBuffer());
322
- return c(), {
323
- path: i.path,
324
- data: r
325
- };
326
- } catch (e) {
327
- if (n.aborted) return;
328
- if (r(e).isUnauthorized) {
329
- o = !0;
330
- return;
331
- }
332
- a = !0, c();
333
- return;
334
- }
335
- }),
336
- anySkipped: !n.aborted && !o && a,
337
- isUnauthorized: !n.aborted && o
338
- };
339
- }, [r, t]), _ = m(async (t, l, m, _, v, b) => {
340
- let x = be(_), S;
341
- try {
342
- S = await Y(e, n(l), b);
343
- } catch (e) {
344
- if (b.aborted) return;
345
- if (r(e).isUnauthorized) f?.({
346
- jobId: t,
347
- code: o.Unauthorized
348
- }), h.failJob(t, o.Unauthorized);
349
- else {
350
- let n = await i(e);
351
- f?.({
352
- jobId: t,
353
- code: o.Unknown,
354
- titles: [m],
355
- traceId: n
356
- }), h.failJob(t, o.Unknown);
357
- }
358
- console.error("Failed to fetch conversation for export", e);
359
- return;
360
- }
361
- if (!b.aborted) {
362
- h.setJobProgress(t, U({
363
- kind: x,
364
- phase: R.Prepare
365
- }));
366
- try {
367
- if (_ === y.WithoutAttachments) {
368
- p(E(T([w(S)], [])), v), s?.({
369
- jobId: t,
370
- titles: [m]
371
- }), h.succeedJob(t);
372
- return;
373
- }
374
- let e = A(S), { entries: n, anySkipped: r, isUnauthorized: i } = await g(e, b, (e, n) => {
375
- h.setJobProgress(t, U({
376
- kind: x,
377
- phase: R.Transfer,
378
- completed: e,
379
- total: n
380
- }, {
381
- completed: e,
382
- total: n,
383
- kind: u.Attachment
384
- }));
385
- });
386
- if (b.aborted) return;
387
- if (i) {
388
- f?.({
389
- jobId: t,
390
- code: o.Unauthorized
391
- }), h.failJob(t, o.Unauthorized);
392
- return;
393
- }
394
- h.setJobProgress(t, U({
395
- kind: x,
396
- phase: R.Transfer,
397
- completed: e.length,
398
- total: e.length
399
- }));
400
- let l = n.reduce((e, t) => e + t.data.byteLength, 0);
401
- if (l > a) {
402
- f?.({
403
- jobId: t,
404
- code: o.FileTooLarge,
405
- titles: [m]
406
- }), h.failJob(t, o.FileTooLarge), console.error(`Refused to build an export archive of ${l} bytes: over the ${a}-byte limit`);
407
- return;
408
- }
409
- let { blob: C, skippedPaths: D } = de(T([S], []), n), O = r || D.length > 0;
410
- O && c?.({
411
- jobId: t,
412
- code: d.AttachmentSkipped
413
- }), p(C, v), s?.({
414
- jobId: t,
415
- titles: [m]
416
- }), O ? h.warnJob(t, d.AttachmentSkipped) : h.succeedJob(t);
417
- } catch (e) {
418
- if (b.aborted) return;
419
- let n = X(e) ? o.FileTooLarge : o.Unknown, r = await i(e);
420
- f?.({
421
- jobId: t,
422
- code: n,
423
- titles: [m],
424
- traceId: r
425
- }), h.failJob(t, n), console.error("Failed to build conversation export archive", e);
426
- }
427
- }
428
- }, [
429
- r,
430
- e,
431
- g,
432
- a,
433
- n,
434
- f,
435
- s,
436
- c,
437
- h,
438
- i
439
- ]), v = m((e, t, n) => {
440
- let r = O(n === y.WithoutAttachments ? b.SingleConversation : b.SingleConversationWithAttachments, x), i = h.addJob({
441
- kind: l.Single,
442
- title: t
443
- }, r);
444
- return h.startJob(i, (a) => _(i, e, t, n, r, a));
445
- }, [h, _]), S = m(async (t, a, c) => {
446
- let l = z.ExportAll, d = [], m;
447
- do {
448
- if (c.aborted) return;
449
- let n;
450
- try {
451
- n = await e.listConversations({ nextToken: m }, { signal: c });
452
- } catch (e) {
453
- if (c.aborted) return;
454
- if (r(e).isUnauthorized) f?.({
455
- jobId: t,
456
- code: o.Unauthorized
457
- }), h.failJob(t, o.Unauthorized);
458
- else {
459
- let n = await i(e);
460
- f?.({
461
- jobId: t,
462
- code: o.Unknown,
463
- traceId: n
464
- }), h.failJob(t, o.Unknown);
465
- }
466
- console.error("Failed to list conversations for export", e);
467
- return;
468
- }
469
- d.push(...n.items.filter(ye).map((e) => ({
470
- id: e.id,
471
- title: e.title
472
- }))), m = n.nextToken;
473
- } while (m);
474
- h.setJobProgress(t, U({
475
- kind: l,
476
- phase: R.Prepare
477
- }));
478
- let g = [];
479
- for (let a of d) {
480
- if (c.aborted) return;
481
- try {
482
- let t = await Y(e, n(a.id), c);
483
- g.push(t);
484
- } catch (e) {
485
- if (c.aborted) return;
486
- let n = r(e);
487
- if (n.isUnauthorized) {
488
- f?.({
489
- jobId: t,
490
- code: o.Unauthorized
491
- }), h.failJob(t, o.Unauthorized);
492
- return;
493
- }
494
- if (n.isNotFound) {
495
- let n = await i(e);
496
- f?.({
497
- jobId: t,
498
- code: o.NotFound,
499
- titles: [a.title],
500
- traceId: n
501
- }), console.error("Skipped a conversation during export-all: not found", e);
502
- continue;
503
- }
504
- let s = await i(e);
505
- f?.({
506
- jobId: t,
507
- code: o.Unknown,
508
- traceId: s
509
- }), h.failJob(t, o.Unknown), console.error("Aborted export-all: failed to fetch conversation", e);
510
- return;
511
- } finally {
512
- h.setJobProgress(t, U({
513
- kind: l,
514
- phase: R.Transfer,
515
- completed: g.length,
516
- total: d.length
517
- }, {
518
- completed: g.length,
519
- total: d.length,
520
- kind: u.Conversation
521
- }));
522
- }
523
- }
524
- if (!c.aborted) try {
525
- p(E(T(g, [])), a), s?.({ jobId: t }), h.succeedJob(t);
526
- } catch (e) {
527
- let n = X(e) ? o.FileTooLarge : o.Unknown, r = await i(e);
528
- f?.({
529
- jobId: t,
530
- code: n,
531
- traceId: r
532
- }), h.failJob(t, n), console.error("Failed to build export-all archive", e);
533
- }
534
- }, [
535
- r,
536
- e,
537
- n,
538
- f,
539
- s,
540
- h,
541
- i
542
- ]), C = m(() => {
543
- let e = O(b.AllConversationsHistory, x), t = h.addJob({ kind: l.All }, e);
544
- return h.startJob(t, (n) => S(t, e, n));
545
- }, [h, S]);
546
- return {
547
- jobs: h.jobs,
548
- exportSingle: v,
549
- exportAll: C,
550
- cancelJob: h.cancelJob,
551
- dismissJob: h.dismissJob,
552
- retryJob: h.retryJob,
553
- dismissAll: h.dismissAll
554
- };
555
- }, Se = (e) => {
556
- let t = e.lastIndexOf("."), n = t > 0;
557
- return {
558
- base: n ? e.slice(0, t) : e,
559
- extension: n ? e.slice(t) : ""
560
- };
561
- }, Ce = (e) => (e.split(/[\\/]/).filter(Boolean).pop() ?? "file").replace(/\.\.+/g, ".").replace(/^\.+/, "") || "file", Z = (e, t, n) => n === 0 ? `${e}${t}` : `${e} (${n})${t}`, we = (e) => {
562
- let n = e?.date ?? /* @__PURE__ */ new Date(), r = new Set(e?.existingNames);
563
- return {
564
- allocate: (e) => {
565
- let { base: i, extension: a } = Se(Ce(e)), o = 0, s = Z(i, a, o);
566
- for (; r.has(s);) o += 1, s = Z(i, a, o);
567
- return r.add(s), {
568
- path: `uploads/${t(n)}/${encodeURIComponent(s)}`,
569
- fileName: s,
570
- isRenamed: o > 0
571
- };
572
- },
573
- markTaken: (e) => {
574
- r.add(e);
575
- }
576
- };
577
- }, Te = "conversation.json", Q = /^conversations\/.*\.json$/, Ee = "res/", De = (e) => e.find((e) => e === Te) ?? e.find((e) => Q.test(e)) ?? e.find((e) => !e.includes("/") && e.toLowerCase().endsWith(".json")), Oe = (e) => new Promise((t, n) => {
578
- let r = new FileReader();
579
- r.onload = () => t(new Uint8Array(r.result)), r.onerror = () => n(r.error), r.readAsArrayBuffer(e);
580
- }), ke = async (e) => {
581
- let t = await Oe(e), n;
582
- try {
583
- n = i(t);
584
- } catch {
585
- throw new M("Import file is not a valid archive");
586
- }
587
- let r = Object.keys(n), o = De(r);
588
- if (!o) throw new M("Archive does not contain a readable conversation-JSON entry");
589
- let s = P(a(n[o])), c = /* @__PURE__ */ new Map();
590
- for (let e of r) {
591
- if (e.endsWith("/") || !e.startsWith(Ee)) continue;
592
- let t = e.slice(4);
593
- !t || !q(t) || c.set(t, n[e]);
594
- }
595
- return {
596
- envelope: s,
597
- attachments: c
598
- };
599
- }, Ae = 5, $ = 5, je = (e) => /\.(dial|zip)$/i.test(e.name), Me = (e) => new Promise((t, n) => {
600
- let r = new FileReader();
601
- r.onload = () => t(r.result), r.onerror = () => n(r.error), r.readAsText(e);
602
- }), Ne = async (e) => {
603
- if (je(e)) {
604
- let { envelope: t, attachments: n } = await ke(e);
605
- return {
606
- history: t.history,
607
- attachments: n,
608
- isArchive: !0
609
- };
610
- }
611
- return {
612
- history: P(await Me(e)).history,
613
- attachments: /* @__PURE__ */ new Map(),
614
- isArchive: !1
615
- };
616
- }, Pe = async (e, t, n, r, i, a, o, s) => {
617
- let { plan: c, skippedNames: l } = le(e, t, r), u = !1, d = await L(c, Ae, async (e) => {
618
- if (s.aborted || u) return;
619
- let t = e.allocated;
620
- for (let c = 0; c <= $; c += 1) try {
621
- let r = new File([new Uint8Array(e.bytes)], t.fileName), a = await i.uploadFile({
622
- bucket: n,
623
- path: t.path,
624
- file: r,
625
- uploadMode: "create-only"
626
- }, { signal: s });
627
- return o(), {
628
- kind: "uploaded",
629
- oldFileId: e.fileId,
630
- newFileId: a.url,
631
- newTitle: t.isRenamed ? t.fileName : void 0
632
- };
633
- } catch (n) {
634
- if (s.aborted) return;
635
- if (a(n)) {
636
- u = !0;
637
- return;
638
- }
639
- if (!(typeof n == "object" && n && "response" in n && n.response?.status === 409) || c === $) return o(), {
640
- kind: "skipped",
641
- name: e.originalFileName
642
- };
643
- r.markTaken(t.fileName), t = r.allocate(e.originalFileName);
644
- }
645
- return {
646
- kind: "skipped",
647
- name: e.originalFileName
648
- };
649
- }), f = /* @__PURE__ */ new Map(), p = [...l];
650
- for (let e of d) e.kind === "uploaded" ? f.set(e.oldFileId, {
651
- url: e.newFileId,
652
- ...e.newTitle == null ? {} : { title: e.newTitle }
653
- }) : p.push(e.name);
654
- return {
655
- targetMap: f,
656
- skippedNames: s.aborted || u ? [] : p,
657
- isUnauthorized: !s.aborted && u
658
- };
659
- }, Fe = ({ conversationsApi: e, filesApi: n, bucket: r, onImported: i, classifyTransferError: a = () => ({}), resolveErrorTraceId: s = async () => void 0, onSuccess: c, onWarning: p, onError: h }) => {
660
- let g = W(), _ = m(async (l, f, m) => {
661
- if (!r) {
662
- h?.({
663
- jobId: l,
664
- code: o.MissingBucket
665
- }), g.failJob(l, o.MissingBucket);
666
- return;
667
- }
668
- let _ = z.Import, v = f.attachments.size, y = 0, b = () => {
669
- y += 1, g.setJobProgress(l, U({
670
- kind: _,
671
- phase: R.Transfer,
672
- completed: y,
673
- total: v
674
- }, {
675
- completed: Math.min(y, v),
676
- total: v,
677
- kind: u.Attachment
678
- }));
679
- }, x = (e) => {
680
- g.setJobProgress(l, U({
681
- kind: _,
682
- phase: R.Finalize,
683
- completed: e,
684
- total: f.history.length
685
- }, {
686
- completed: e,
687
- total: f.history.length,
688
- kind: u.Conversation
689
- }));
690
- }, S = [], C = [], w = /* @__PURE__ */ new Set(), T = !1, E, D = /* @__PURE__ */ new Date(), O = (e) => !!a(e).isUnauthorized, k;
691
- if (f.isArchive) {
692
- let e = `uploads/${t(D)}`, i = [];
693
- try {
694
- i = (await n.listFiles({
695
- bucket: r,
696
- path: e
697
- }, { signal: m })).items.map((e) => e.name);
698
- } catch (e) {
699
- if (m.aborted) return;
700
- if (O(e)) {
701
- h?.({
702
- jobId: l,
703
- code: o.Unauthorized
704
- }), g.failJob(l, o.Unauthorized);
705
- return;
706
- }
707
- console.error("Failed to list the upload folder for attachment name disambiguation", e);
708
- }
709
- k = we({
710
- date: D,
711
- existingNames: i
712
- });
713
- }
714
- g.setJobProgress(l, U({
715
- kind: _,
716
- phase: R.Prepare
717
- })), v === 0 && g.setJobProgress(l, U({
718
- kind: _,
719
- phase: R.Transfer
720
- }));
721
- for (let t of f.history) {
722
- if (m.aborted) return;
723
- if (T) break;
724
- try {
725
- let i = /* @__PURE__ */ new Map();
726
- if (f.isArchive && k) {
727
- let e = await Pe(t, f.attachments, r, k, n, O, b, m);
728
- if (m.aborted) return;
729
- if (e.isUnauthorized) {
730
- T = !0;
731
- break;
732
- }
733
- for (let t of e.skippedNames) w.add(t);
734
- i = e.targetMap;
735
- }
736
- let { conversation: a, subPath: o } = I(se(t, i), r);
737
- if (await e.saveConversation({
738
- path: o,
739
- saveConversationBodyDto: { conversation: {
740
- ...a,
741
- llmNamingDone: !0
742
- } }
743
- }, { signal: m }), m.aborted) return;
744
- S.push(t.name);
745
- } catch (e) {
746
- if (m.aborted) return;
747
- if (O(e)) {
748
- T = !0;
749
- break;
750
- }
751
- C.push(t.name), E === void 0 && (E = await s(e)), console.error("Failed to import a conversation", e);
752
- }
753
- x(S.length + C.length);
754
- }
755
- if (!m.aborted) {
756
- if (T) {
757
- h?.({
758
- jobId: l,
759
- code: o.Unauthorized
760
- }), g.failJob(l, o.Unauthorized);
761
- return;
762
- }
763
- if (S.length > 0) {
764
- try {
765
- await i?.();
766
- } catch {}
767
- c?.({
768
- jobId: l,
769
- titles: S
770
- });
771
- }
772
- C.length > 0 && h?.({
773
- jobId: l,
774
- code: o.Unknown,
775
- titles: C,
776
- traceId: E
777
- }), w.size > 0 && p?.({
778
- jobId: l,
779
- code: d.AttachmentSkipped,
780
- names: [...w]
781
- }), C.length > 0 ? g.failJob(l, o.Unknown) : w.size > 0 ? g.warnJob(l, d.AttachmentSkipped) : g.succeedJob(l);
782
- }
783
- }, [
784
- r,
785
- a,
786
- e,
787
- n,
788
- h,
789
- i,
790
- c,
791
- p,
792
- g,
793
- s
794
- ]), v = m(async (e) => {
795
- let t;
796
- try {
797
- t = await Ne(e);
798
- } catch (e) {
799
- h?.({
800
- jobId: f(),
801
- code: o.UnsupportedFormat
802
- }), e instanceof M || console.error("Failed to parse import file", e);
803
- return;
804
- }
805
- let n = t.history.length > 1, r = t.history[0], i = n ? { kind: l.All } : {
806
- kind: l.Single,
807
- title: r?.name ?? e.name,
808
- sourceBreadcrumb: r ? ae(r) : void 0
809
- }, a = g.addJob(i, e.name);
810
- return g.startJob(a, (e) => _(a, t, e));
811
- }, [
812
- h,
813
- g,
814
- _
815
- ]);
816
- return {
817
- jobs: g.jobs,
818
- importConversations: v,
819
- cancelJob: g.cancelJob,
820
- dismissJob: g.dismissJob,
821
- retryJob: g.retryJob,
822
- dismissAll: g.dismissAll
823
- };
824
- };
825
- //#endregion
826
- export { x as a, d as c, oe as i, b as l, J as n, y as o, xe as r, s, Fe as t };