@epam/ai-dial-chat-hooks 1.1.0-dev.267 → 1.1.0-dev.268

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 (44) hide show
  1. package/files/dial-file-manager-copy-move.util.d.ts +15 -0
  2. package/files/dial-file-manager-copy-move.util.d.ts.map +1 -0
  3. package/files/dial-file-manager-mapping.util.d.ts +35 -0
  4. package/files/dial-file-manager-mapping.util.d.ts.map +1 -0
  5. package/files/dial-file-manager-path.util.d.ts +39 -0
  6. package/files/dial-file-manager-path.util.d.ts.map +1 -0
  7. package/files/dial-file-manager.model.d.ts +26 -0
  8. package/files/dial-file-manager.model.d.ts.map +1 -0
  9. package/files/dial-file-manager.types.d.ts +320 -0
  10. package/files/dial-file-manager.types.d.ts.map +1 -0
  11. package/files/dial-files-api.d.ts +71 -0
  12. package/files/dial-files-api.d.ts.map +1 -0
  13. package/files/download-destination.d.ts +31 -0
  14. package/files/download-destination.d.ts.map +1 -0
  15. package/files/file-manager-variant.d.ts +22 -0
  16. package/files/file-manager-variant.d.ts.map +1 -0
  17. package/files/file-name.d.ts +19 -0
  18. package/files/file-name.d.ts.map +1 -0
  19. package/files/resolve-dial-file-api-path.d.ts +17 -0
  20. package/files/resolve-dial-file-api-path.d.ts.map +1 -0
  21. package/files/string-utils.d.ts +3 -0
  22. package/files/string-utils.d.ts.map +1 -0
  23. package/files/upload-batch.types.d.ts +22 -0
  24. package/files/upload-batch.types.d.ts.map +1 -0
  25. package/files/useDialFileListing/useDialFileListing.d.ts +73 -0
  26. package/files/useDialFileListing/useDialFileListing.d.ts.map +1 -0
  27. package/files/useDialFileManager/useDialFileManager.d.ts +16 -0
  28. package/files/useDialFileManager/useDialFileManager.d.ts.map +1 -0
  29. package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.d.ts +14 -0
  30. package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.d.ts.map +1 -0
  31. package/files/useDialFileMetadata/useDialFileMetadata.d.ts +28 -0
  32. package/files/useDialFileMetadata/useDialFileMetadata.d.ts.map +1 -0
  33. package/files/useDialFileMutations/useDialFileMutations.d.ts +68 -0
  34. package/files/useDialFileMutations/useDialFileMutations.d.ts.map +1 -0
  35. package/files/useDialFileSharing/useDialFileSharing.d.ts +30 -0
  36. package/files/useDialFileSharing/useDialFileSharing.d.ts.map +1 -0
  37. package/files/useDialFileUploadBatch/useDialFileUploadBatch.d.ts +45 -0
  38. package/files/useDialFileUploadBatch/useDialFileUploadBatch.d.ts.map +1 -0
  39. package/files/useGridEditingScroll/useGridEditingScroll.d.ts +27 -0
  40. package/files/useGridEditingScroll/useGridEditingScroll.d.ts.map +1 -0
  41. package/index.d.ts +18 -0
  42. package/index.d.ts.map +1 -1
  43. package/index.js +1780 -406
  44. package/package.json +10 -8
package/index.js CHANGED
@@ -1,32 +1,34 @@
1
1
  import { AttachmentContentType as e, useAttachmentCanvas as t } from "@epam/ai-dial-attachment-canvas";
2
- import { AttachmentErrorReason as n, MIMEType as r, MessageRole as i, ResponseFormat as a, base64ToBlob as o, messageAttachmentToDisplayAttachment as s, triggerAnchorDownload as c, triggerBlobDownload as l } from "@epam/ai-dial-chat-shared";
3
- import { isReferenceOnlyAttachment as u, normalizeRawAnnotations as d, parsePdfPageReference as f, resolveMessageAnnotations as p } from "@epam/ai-dial-quotations";
4
- import { useCallback as m, useEffect as h, useLayoutEffect as g, useMemo as _, useRef as v, useState as y } from "react";
5
- import { isMimeTypeAllowed as b, mimeTypesToExtensionLabels as x } from "@epam/ai-dial-attachment-input";
6
- import { strFromU8 as S, strToU8 as C, unzipSync as w, zipSync as T } from "fflate";
7
- import { SendCompletionDtoModeEnum as E, ShareLinkResponseDtoAccessEnum as D } from "@epam/ai-dial-chat-api-client";
8
- import { ShareLinkAccess as O } from "@epam/ai-dial-share";
2
+ import { AttachmentErrorReason as n, HIDDEN_FILE as r, MIMEType as i, MessageRole as a, ResponseFormat as o, base64ToBlob as s, getUtf8ByteLength as c, messageAttachmentToDisplayAttachment as l, triggerAnchorDownload as u, triggerBlobDownload as d, truncateToUtf8Bytes as f } from "@epam/ai-dial-chat-shared";
3
+ import { isReferenceOnlyAttachment as p, normalizeRawAnnotations as m, parsePdfPageReference as h, resolveMessageAnnotations as g } from "@epam/ai-dial-quotations";
4
+ import { useCallback as _, useEffect as v, useLayoutEffect as y, useMemo as b, useRef as x, useState as S } from "react";
5
+ import { isMimeTypeAllowed as C, mimeTypesToExtensionLabels as w } from "@epam/ai-dial-attachment-input";
6
+ import { strFromU8 as T, strToU8 as E, unzipSync as D, zipSync as O } from "fflate";
7
+ import { ArchiveItemDtoNodeTypeEnum as k, CopyItemDtoNodeTypeEnum as A, DeleteItemDtoNodeTypeEnum as j, ListFilesItemDtoNodeTypeEnum as M, MoveItemDtoNodeTypeEnum as N, RenameItemDtoNodeTypeEnum as P, SendCompletionDtoModeEnum as F, ShareLinkResponseDtoAccessEnum as I } from "@epam/ai-dial-chat-api-client";
8
+ import { DialFileManagerActions as L, DialFileManagerTabs as R, DialFileNodeType as z, DialFilePermission as ee, FileManagerColumnKey as B } from "@epam/ai-dial-react-file-manager";
9
+ import { NOT_ALLOWED_SYMBOLS as te, NOT_ALLOWED_SYMBOLS_REGEXP as ne, NotificationVariant as V } from "@epam/ai-dial-ui-kit";
10
+ import { ShareLinkAccess as re } from "@epam/ai-dial-share";
9
11
  //#region src/attachment/useAttachmentAction/useAttachmentAction.ts
10
- var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e.data != null, j = (e, t) => {
11
- let { url: n, name: i, contentType: a, data: s } = e;
12
- if (n != null && k(n)) {
12
+ var H = (e) => e.startsWith("files/"), ie = (e) => e.url != null && H(e.url) || e.data != null, ae = (e, t) => {
13
+ let { url: n, name: r, contentType: a, data: o } = e;
14
+ if (n != null && H(n)) {
13
15
  let e = t(n);
14
- return e == null ? !1 : (c(e, i), !0);
16
+ return e == null ? !1 : (u(e, r), !0);
15
17
  }
16
- return s == null ? !1 : (l(o(s, a || r.Plain), i), !0);
17
- }, M = (e, t) => {
18
+ return o == null ? !1 : (d(s(o, a || i.Plain), r), !0);
19
+ }, oe = (e, t) => {
18
20
  let { url: n } = e;
19
21
  if (n == null) return;
20
22
  let r = n.split("#")[0];
21
- if (k(r)) {
23
+ if (H(r)) {
22
24
  let n = t(r);
23
25
  if (n == null) return;
24
- c(n, e.title ?? r.split("/").pop() ?? "");
26
+ u(n, e.title ?? r.split("/").pop() ?? "");
25
27
  } else window.open(n, "_blank", "noopener,noreferrer");
26
- }, N = (t, n) => {
27
- let r = f(t.url);
28
+ }, se = (t, n) => {
29
+ let r = h(t.url);
28
30
  if (r == null) return null;
29
- let i = k(r.baseUrl) ? n(r.baseUrl) : r.baseUrl;
31
+ let i = H(r.baseUrl) ? n(r.baseUrl) : r.baseUrl;
30
32
  if (i == null) return null;
31
33
  if (r.page == null) return {
32
34
  type: e.Pdf,
@@ -52,12 +54,12 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
52
54
  }],
53
55
  selectedHighlightId: a
54
56
  };
55
- }, P = ({ resolveDownloadUrl: e }) => {
57
+ }, ce = ({ resolveDownloadUrl: e }) => {
56
58
  let { openCanvas: n } = t();
57
- return { handleAttachmentClick: m((t) => {
59
+ return { handleAttachmentClick: _((t) => {
58
60
  let { url: r, referenceUrl: i, data: a, name: o } = t;
59
61
  if (r != null || a != null) {
60
- j(t, e);
62
+ ae(t, e);
61
63
  return;
62
64
  }
63
65
  if (i == null) return;
@@ -65,34 +67,34 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
65
67
  type: t.contentType,
66
68
  url: i,
67
69
  title: o
68
- }, c = N(s, e);
70
+ }, c = se(s, e);
69
71
  if (c) {
70
72
  n(c, o);
71
73
  return;
72
74
  }
73
- M(s, e);
75
+ oe(s, e);
74
76
  }, [n, e]) };
75
- }, F = 100, I = "*/*", ee = (e) => e.startsWith(".") || e.includes("/"), te = (e) => {
76
- if (e != null) return e.map((e) => e === "*" ? I : e).filter(ee);
77
- }, ne = (e) => {
78
- let t = te(e);
79
- if (!(t == null || t.length === 0) && !t.some((e) => e === I)) return t.join(",");
80
- }, re = /* @__PURE__ */ function(e) {
77
+ }, le = 100, ue = "*/*", de = (e) => e.startsWith(".") || e.includes("/"), fe = (e) => {
78
+ if (e != null) return e.map((e) => e === "*" ? ue : e).filter(de);
79
+ }, pe = (e) => {
80
+ let t = fe(e);
81
+ if (!(t == null || t.length === 0) && !t.some((e) => e === ue)) return t.join(",");
82
+ }, me = /* @__PURE__ */ function(e) {
81
83
  return e.NoTypesAllowed = "noTypesAllowed", e.UnsupportedType = "unsupportedType", e;
82
- }({}), ie = ({ allowedMimeTypes: e, onValidationError: t, debounceMs: r = F }) => {
83
- let i = e.length > 0, a = _(() => ne(e), [e]), o = v(null);
84
- return h(() => () => {
84
+ }({}), he = ({ allowedMimeTypes: e, onValidationError: t, debounceMs: r = le }) => {
85
+ let i = e.length > 0, a = b(() => pe(e), [e]), o = x(null);
86
+ return v(() => () => {
85
87
  o.current != null && clearTimeout(o.current);
86
88
  }, []), {
87
89
  inputAttachmentTypes: e,
88
90
  isAttachmentsAllowed: i,
89
- validateAttachment: m((i) => {
90
- if (!b(i.contentType, e)) return o.current != null && clearTimeout(o.current), o.current = setTimeout(() => {
91
+ validateAttachment: _((i) => {
92
+ if (!C(i.contentType, e)) return o.current != null && clearTimeout(o.current), o.current = setTimeout(() => {
91
93
  let n = e.length === 0;
92
94
  t?.({
93
95
  reason: n ? "noTypesAllowed" : "unsupportedType",
94
96
  allowedMimeTypes: e,
95
- ...n ? {} : { formats: x(e) }
97
+ ...n ? {} : { formats: w(e) }
96
98
  }), o.current = null;
97
99
  }, r), n.UnsupportedType;
98
100
  }, [
@@ -102,35 +104,35 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
102
104
  ]),
103
105
  fileAccept: a
104
106
  };
105
- }, ae = (e) => `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`, L = (e) => `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}`, oe = /* @__PURE__ */ function(e) {
107
+ }, ge = (e) => `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`, _e = (e) => `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}`, ve = /* @__PURE__ */ function(e) {
106
108
  return e.WithAttachments = "withAttachments", e.WithoutAttachments = "withoutAttachments", e;
107
- }({}), R = /* @__PURE__ */ function(e) {
109
+ }({}), U = /* @__PURE__ */ function(e) {
108
110
  return e.SingleConversation = "chat_conversation", e.SingleConversationWithAttachments = "chat_with_attachments", e.AllConversationsHistory = "chat_conversations_history", e;
109
- }({}), z = /* @__PURE__ */ function(e) {
111
+ }({}), W = /* @__PURE__ */ function(e) {
110
112
  return e.InProgress = "inProgress", e.Success = "success", e.Failed = "failed", e;
111
- }({}), B = /* @__PURE__ */ function(e) {
113
+ }({}), ye = /* @__PURE__ */ function(e) {
112
114
  return e.Single = "single", e.All = "all", e;
113
- }({}), V = /* @__PURE__ */ function(e) {
115
+ }({}), G = /* @__PURE__ */ function(e) {
114
116
  return e.Unauthorized = "unauthorized", e.NotFound = "notFound", e.UnsupportedFormat = "unsupportedFormat", e.MissingBucket = "missingBucket", e.Unknown = "unknown", e;
115
- }({}), H = /* @__PURE__ */ function(e) {
117
+ }({}), be = /* @__PURE__ */ function(e) {
116
118
  return e.AttachmentSkipped = "attachmentSkipped", e;
117
- }({}), U = "ai_dial", W = (e, t = []) => ({
119
+ }({}), xe = "ai_dial", Se = (e, t = []) => ({
118
120
  version: 5,
119
121
  history: e,
120
122
  folders: t
121
- }), se = (e) => new Blob([JSON.stringify(e, null, 2)], { type: "application/json" }), ce = {
122
- [R.SingleConversation]: "json",
123
- [R.SingleConversationWithAttachments]: "dial",
124
- [R.AllConversationsHistory]: "json"
125
- }, G = (e, t, n = /* @__PURE__ */ new Date()) => `${ae(n)}_${t}_${e}.${ce[e]}`, le = (e) => e.startsWith("files/"), ue = (e) => {
123
+ }), Ce = (e) => new Blob([JSON.stringify(e, null, 2)], { type: "application/json" }), we = {
124
+ [U.SingleConversation]: "json",
125
+ [U.SingleConversationWithAttachments]: "dial",
126
+ [U.AllConversationsHistory]: "json"
127
+ }, Te = (e, t, n = /* @__PURE__ */ new Date()) => `${ge(n)}_${t}_${e}.${we[e]}`, Ee = (e) => e.startsWith("files/"), De = (e) => {
126
128
  let t = /* @__PURE__ */ new Set();
127
129
  for (let n of e.messages) for (let e of n.custom_content?.attachments ?? []) {
128
130
  let n = e.url ?? e.reference_url;
129
- n != null && le(n) && t.add(n);
131
+ n != null && Ee(n) && t.add(n);
130
132
  }
131
133
  return Array.from(t, (e) => ({ fileId: e }));
132
- }, de = (e) => e.startsWith("files/"), fe = (e) => {
133
- if (!de(e)) return;
134
+ }, Oe = (e) => e.startsWith("files/"), ke = (e) => {
135
+ if (!Oe(e)) return;
134
136
  let t = e.slice(6), n = t.indexOf("/");
135
137
  if (n < 0) return;
136
138
  let r = t.slice(0, n), i = t.slice(n + 1), a;
@@ -143,31 +145,31 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
143
145
  bucket: r,
144
146
  path: a
145
147
  };
146
- }, K = class extends Error {
148
+ }, Ae = class extends Error {
147
149
  constructor(e) {
148
150
  super(e), this.name = "UnsupportedImportFormatError";
149
151
  }
150
- }, pe = (e) => typeof e == "object" && !!e, me = 5, he = (e) => {
152
+ }, je = (e) => typeof e == "object" && !!e, Me = 5, Ne = (e) => {
151
153
  let t;
152
154
  try {
153
155
  t = JSON.parse(e);
154
156
  } catch {
155
- throw new K("Import file is not valid JSON");
157
+ throw new Ae("Import file is not valid JSON");
156
158
  }
157
- if (!pe(t) || t.version !== me || !Array.isArray(t.history)) throw new K("Import file is not a supported export format");
159
+ if (!je(t) || t.version !== Me || !Array.isArray(t.history)) throw new Ae("Import file is not a supported export format");
158
160
  let n = Array.isArray(t.folders) ? t.folders : [];
159
161
  return {
160
- version: me,
162
+ version: Me,
161
163
  history: t.history,
162
164
  folders: n
163
165
  };
164
- }, ge = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, _e = (e) => {
166
+ }, Pe = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, Fe = (e) => {
165
167
  let t = e.lastIndexOf("__");
166
168
  if (t < 0) return e;
167
169
  let n = e.slice(t + 2);
168
- return ge.test(n) ? e.slice(0, t) : e;
169
- }, ve = "conversations/", q = (e) => e.startsWith(ve) ? e.slice(14) : e, ye = (e, t) => {
170
- let n = q(e.id), r = n.split("/"), i = q(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 = `${_e(s.at(-1) ?? r.at(-1) ?? n)}__${crypto.randomUUID()}`, u = [
170
+ return Pe.test(n) ? e.slice(0, t) : e;
171
+ }, Ie = "conversations/", Le = (e) => e.startsWith(Ie) ? e.slice(14) : e, Re = (e, t) => {
172
+ let n = Le(e.id), r = n.split("/"), i = Le(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 = `${Fe(s.at(-1) ?? r.at(-1) ?? n)}__${crypto.randomUUID()}`, u = [
171
173
  ...o,
172
174
  ...c,
173
175
  l
@@ -180,10 +182,10 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
180
182
  },
181
183
  subPath: u
182
184
  };
183
- }, be = (e) => {
184
- let t = q(e.folderId).split("/").filter(Boolean).slice(1);
185
+ }, ze = (e) => {
186
+ let t = Le(e.folderId).split("/").filter(Boolean).slice(1);
185
187
  return t.length ? t.join(" / ") : void 0;
186
- }, xe = (e) => e.map((e) => `"${e}"`).join(", "), Se = (e, t) => ({
188
+ }, Be = (e) => e.map((e) => `"${e}"`).join(", "), Ve = (e, t) => ({
187
189
  ...e,
188
190
  messages: e.messages.map((e) => {
189
191
  let n = e.custom_content?.attachments;
@@ -205,12 +207,12 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
205
207
  }
206
208
  } : e;
207
209
  })
208
- }), Ce = (e) => e.split("/").pop() || e, we = (e, t, n) => {
210
+ }), He = (e) => e.split("/").pop() || e, Ue = (e, t, n) => {
209
211
  let r = [], i = [];
210
- for (let a of ue(e)) {
211
- let e = fe(a.fileId);
212
+ for (let a of De(e)) {
213
+ let e = ke(a.fileId);
212
214
  if (!e) {
213
- i.push(Ce(a.fileId));
215
+ i.push(He(a.fileId));
214
216
  continue;
215
217
  }
216
218
  let o = e.path.split("/").pop() ?? e.path, s = t.get(e.path);
@@ -229,14 +231,14 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
229
231
  plan: r,
230
232
  skippedNames: i
231
233
  };
232
- }, Te = 700, Ee = (e) => (e.split(/[\\/]/).filter(Boolean).pop() ?? "file").replace(/\.\.+/g, ".").replace(/^\.+/, "") || "file", De = (e, t = /* @__PURE__ */ new Date()) => `uploads/${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, "0")}/${encodeURIComponent(Ee(e))}`, Oe = ({ filesApi: e, bucket: t, onNetworkError: r, debounceMs: i = Te }) => {
233
- let a = v([]), o = v(null);
234
- return { handleUploadAttachment: m(async (s) => {
234
+ }, We = 700, Ge = (e) => (e.split(/[\\/]/).filter(Boolean).pop() ?? "file").replace(/\.\.+/g, ".").replace(/^\.+/, "") || "file", Ke = (e, t = /* @__PURE__ */ new Date()) => `uploads/${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, "0")}/${encodeURIComponent(Ge(e))}`, qe = ({ filesApi: e, bucket: t, onNetworkError: r, debounceMs: i = We }) => {
235
+ let a = x([]), o = x(null);
236
+ return { handleUploadAttachment: _(async (s) => {
235
237
  if (!t) throw Error("User bucket is not available");
236
238
  try {
237
239
  return (await e.uploadFile({
238
240
  bucket: t,
239
- path: De(s.name),
241
+ path: Ke(s.name),
240
242
  file: s.file
241
243
  })).url;
242
244
  } catch (e) {
@@ -256,7 +258,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
256
258
  e,
257
259
  r
258
260
  ]) };
259
- }, ke = async (e, t, n) => {
261
+ }, Je = async (e, t, n) => {
260
262
  let r = [], i = 0, a = async () => {
261
263
  let t = i;
262
264
  if (i += 1, !(t >= e.length)) {
@@ -270,34 +272,34 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
270
272
  }
271
273
  };
272
274
  return await Promise.all(Array.from({ length: Math.min(t, e.length) }, a)), r;
273
- }, Ae = () => {
274
- let [e, t] = y([]), n = v(/* @__PURE__ */ new Map()), r = v(/* @__PURE__ */ new Map()), i = m((e, n) => {
275
+ }, Ye = () => {
276
+ let [e, t] = S([]), n = x(/* @__PURE__ */ new Map()), r = x(/* @__PURE__ */ new Map()), i = _((e, n) => {
275
277
  t((t) => t.map((t) => t.id === e ? {
276
278
  ...t,
277
279
  ...n
278
280
  } : t));
279
- }, []), a = m((e) => {
281
+ }, []), a = _((e) => {
280
282
  let n = crypto.randomUUID();
281
283
  return t((t) => [...t, {
282
284
  id: n,
283
285
  subject: e,
284
- status: z.InProgress
286
+ status: W.InProgress
285
287
  }]), n;
286
- }, []), o = m((e) => {
288
+ }, []), o = _((e) => {
287
289
  n.current.get(e)?.abort(), n.current.delete(e), r.current.delete(e), t((t) => t.filter((t) => t.id !== e));
288
- }, []), s = m((e) => {
290
+ }, []), s = _((e) => {
289
291
  r.current.get(e)?.();
290
- }, []), c = m(() => {
292
+ }, []), c = _(() => {
291
293
  for (let e of n.current.values()) e.abort();
292
294
  n.current.clear(), r.current.clear(), t([]);
293
- }, []), l = m((e, t) => {
295
+ }, []), l = _((e, t) => {
294
296
  let a = () => {
295
297
  let r = new AbortController();
296
298
  return n.current.set(e, r), t(r.signal);
297
299
  };
298
- return r.current.set(e, () => (i(e, { status: z.InProgress }), a())), a();
300
+ return r.current.set(e, () => (i(e, { status: W.InProgress }), a())), a();
299
301
  }, [i]);
300
- return h(() => {
302
+ return v(() => {
301
303
  let e = n.current;
302
304
  return () => {
303
305
  for (let t of e.values()) t.abort();
@@ -311,27 +313,27 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
311
313
  dismissAll: c,
312
314
  startJob: l
313
315
  };
314
- }, je = C("", !0).constructor, Me = (e) => e instanceof je ? e : new je(e), Ne = (e) => e.length > 0 && e.split("/").every((e) => e !== "" && e !== "." && e !== ".."), Pe = (e, t) => {
315
- let n = [], r = { "conversation.json": Me(C(JSON.stringify(e, null, 2))) };
316
+ }, Xe = E("", !0).constructor, Ze = (e) => e instanceof Xe ? e : new Xe(e), Qe = (e) => e.length > 0 && e.split("/").every((e) => e !== "" && e !== "." && e !== ".."), $e = (e, t) => {
317
+ let n = [], r = { "conversation.json": Ze(E(JSON.stringify(e, null, 2))) };
316
318
  for (let e of t) {
317
- if (!Ne(e.path)) {
319
+ if (!Qe(e.path)) {
318
320
  n.push(e.path);
319
321
  continue;
320
322
  }
321
- r[`res/${e.path}`] = Me(e.data);
323
+ r[`res/${e.path}`] = Ze(e.data);
322
324
  }
323
- let i = T(r);
325
+ let i = O(r);
324
326
  return {
325
327
  blob: new Blob([new Uint8Array(i)], { type: "application/zip" }),
326
328
  skippedPaths: n
327
329
  };
328
- }, Fe = 5, Ie = (e) => !e.sharedWithMe && !e.publishedWithMe, Le = ({ conversationsApi: e, filesApi: t, normalizeConversationPath: n, classifyTransferError: r = () => ({}), resolveErrorTraceId: i = async () => void 0, onSuccess: a, onWarning: o, onError: s }) => {
329
- let c = Ae(), u = m(async (e, n) => {
330
+ }, et = 5, tt = (e) => !e.sharedWithMe && !e.publishedWithMe, nt = ({ conversationsApi: e, filesApi: t, normalizeConversationPath: n, classifyTransferError: r = () => ({}), resolveErrorTraceId: i = async () => void 0, onSuccess: a, onWarning: o, onError: s }) => {
331
+ let c = Ye(), l = _(async (e, n) => {
330
332
  let i = !1, a = !1;
331
333
  return {
332
- entries: await ke(e, Fe, async (e) => {
334
+ entries: await Je(e, et, async (e) => {
333
335
  if (n.aborted || a) return;
334
- let o = fe(e.fileId);
336
+ let o = ke(e.fileId);
335
337
  if (!o) {
336
338
  i = !0;
337
339
  return;
@@ -358,110 +360,110 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
358
360
  anySkipped: !n.aborted && !a && i,
359
361
  isUnauthorized: !n.aborted && a
360
362
  };
361
- }, [r, t]), d = m(async (t, d, f, p, m) => {
363
+ }, [r, t]), u = _(async (t, u, f, p, m) => {
362
364
  let h;
363
365
  try {
364
- h = await e.getConversation({ path: n(d) }, { signal: m });
366
+ h = await e.getConversation({ path: n(u) }, { signal: m });
365
367
  } catch (e) {
366
368
  if (m.aborted) return;
367
369
  if (r(e).isUnauthorized) s?.({
368
370
  jobId: t,
369
- code: V.Unauthorized
371
+ code: G.Unauthorized
370
372
  });
371
373
  else {
372
374
  let n = await i(e);
373
375
  s?.({
374
376
  jobId: t,
375
- code: V.Unknown,
377
+ code: G.Unknown,
376
378
  titles: [f],
377
379
  traceId: n
378
380
  });
379
381
  }
380
- c.updateJob(t, { status: z.Failed }), console.error("Failed to fetch conversation for export", e);
382
+ c.updateJob(t, { status: W.Failed }), console.error("Failed to fetch conversation for export", e);
381
383
  return;
382
384
  }
383
385
  if (!m.aborted) try {
384
- if (p === oe.WithoutAttachments) {
385
- l(se(W([h], [])), G(R.SingleConversation, U)), a?.({
386
+ if (p === ve.WithoutAttachments) {
387
+ d(Ce(Se([h], [])), Te(U.SingleConversation, xe)), a?.({
386
388
  jobId: t,
387
389
  titles: [f]
388
- }), c.updateJob(t, { status: z.Success });
390
+ }), c.updateJob(t, { status: W.Success });
389
391
  return;
390
392
  }
391
- let { entries: e, anySkipped: n, isUnauthorized: r } = await u(ue(h), m);
393
+ let { entries: e, anySkipped: n, isUnauthorized: r } = await l(De(h), m);
392
394
  if (m.aborted) return;
393
395
  if (r) {
394
396
  s?.({
395
397
  jobId: t,
396
- code: V.Unauthorized
397
- }), c.updateJob(t, { status: z.Failed });
398
+ code: G.Unauthorized
399
+ }), c.updateJob(t, { status: W.Failed });
398
400
  return;
399
401
  }
400
- let { blob: i, skippedPaths: d } = Pe(W([h], []), e);
401
- (n || d.length > 0) && o?.({
402
+ let { blob: i, skippedPaths: u } = $e(Se([h], []), e);
403
+ (n || u.length > 0) && o?.({
402
404
  jobId: t,
403
- code: H.AttachmentSkipped
404
- }), l(i, G(R.SingleConversationWithAttachments, U)), a?.({
405
+ code: be.AttachmentSkipped
406
+ }), d(i, Te(U.SingleConversationWithAttachments, xe)), a?.({
405
407
  jobId: t,
406
408
  titles: [f]
407
- }), c.updateJob(t, { status: z.Success });
409
+ }), c.updateJob(t, { status: W.Success });
408
410
  } catch (e) {
409
411
  if (m.aborted) return;
410
412
  let n = await i(e);
411
413
  s?.({
412
414
  jobId: t,
413
- code: V.Unknown,
415
+ code: G.Unknown,
414
416
  titles: [f],
415
417
  traceId: n
416
- }), c.updateJob(t, { status: z.Failed }), console.error("Failed to build conversation export archive", e);
418
+ }), c.updateJob(t, { status: W.Failed }), console.error("Failed to build conversation export archive", e);
417
419
  }
418
420
  }, [
419
421
  r,
420
422
  e,
421
- u,
423
+ l,
422
424
  n,
423
425
  s,
424
426
  a,
425
427
  o,
426
428
  c,
427
429
  i
428
- ]), f = m((e, t, n) => {
430
+ ]), f = _((e, t, n) => {
429
431
  let r = c.addJob({
430
- kind: B.Single,
432
+ kind: ye.Single,
431
433
  title: t
432
434
  });
433
- return c.startJob(r, (i) => d(r, e, t, n, i));
434
- }, [c, d]), p = m(async (t, o) => {
435
- let u = [], d;
435
+ return c.startJob(r, (i) => u(r, e, t, n, i));
436
+ }, [c, u]), p = _(async (t, o) => {
437
+ let l = [], u;
436
438
  do {
437
439
  if (o.aborted) return;
438
440
  let n;
439
441
  try {
440
- n = await e.listConversations({ nextToken: d }, { signal: o });
442
+ n = await e.listConversations({ nextToken: u }, { signal: o });
441
443
  } catch (e) {
442
444
  if (o.aborted) return;
443
445
  if (r(e).isUnauthorized) s?.({
444
446
  jobId: t,
445
- code: V.Unauthorized
447
+ code: G.Unauthorized
446
448
  });
447
449
  else {
448
450
  let n = await i(e);
449
451
  s?.({
450
452
  jobId: t,
451
- code: V.Unknown,
453
+ code: G.Unknown,
452
454
  traceId: n
453
455
  });
454
456
  }
455
- c.updateJob(t, { status: z.Failed }), console.error("Failed to list conversations for export", e);
457
+ c.updateJob(t, { status: W.Failed }), console.error("Failed to list conversations for export", e);
456
458
  return;
457
459
  }
458
- u.push(...n.items.filter(Ie).map((e) => ({
460
+ l.push(...n.items.filter(tt).map((e) => ({
459
461
  id: e.id,
460
462
  title: e.title
461
- }))), d = n.nextToken;
462
- } while (d);
463
+ }))), u = n.nextToken;
464
+ } while (u);
463
465
  let f = [];
464
- for (let a of u) {
466
+ for (let a of l) {
465
467
  if (o.aborted) return;
466
468
  try {
467
469
  let t = await e.getConversation({ path: n(a.id) }, { signal: o });
@@ -472,15 +474,15 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
472
474
  if (n.isUnauthorized) {
473
475
  s?.({
474
476
  jobId: t,
475
- code: V.Unauthorized
476
- }), c.updateJob(t, { status: z.Failed });
477
+ code: G.Unauthorized
478
+ }), c.updateJob(t, { status: W.Failed });
477
479
  return;
478
480
  }
479
481
  if (n.isNotFound) {
480
482
  let n = await i(e);
481
483
  s?.({
482
484
  jobId: t,
483
- code: V.NotFound,
485
+ code: G.NotFound,
484
486
  titles: [a.title],
485
487
  traceId: n
486
488
  }), console.error("Skipped a conversation during export-all: not found", e);
@@ -489,21 +491,21 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
489
491
  let l = await i(e);
490
492
  s?.({
491
493
  jobId: t,
492
- code: V.Unknown,
494
+ code: G.Unknown,
493
495
  traceId: l
494
- }), c.updateJob(t, { status: z.Failed }), console.error("Aborted export-all: failed to fetch conversation", e);
496
+ }), c.updateJob(t, { status: W.Failed }), console.error("Aborted export-all: failed to fetch conversation", e);
495
497
  return;
496
498
  }
497
499
  }
498
500
  if (!o.aborted) try {
499
- l(se(W(f, [])), G(R.AllConversationsHistory, U)), a?.({ jobId: t }), c.updateJob(t, { status: z.Success });
501
+ d(Ce(Se(f, [])), Te(U.AllConversationsHistory, xe)), a?.({ jobId: t }), c.updateJob(t, { status: W.Success });
500
502
  } catch (e) {
501
503
  let n = await i(e);
502
504
  s?.({
503
505
  jobId: t,
504
- code: V.Unknown,
506
+ code: G.Unknown,
505
507
  traceId: n
506
- }), c.updateJob(t, { status: z.Failed }), console.error("Failed to build export-all archive", e);
508
+ }), c.updateJob(t, { status: W.Failed }), console.error("Failed to build export-all archive", e);
507
509
  }
508
510
  }, [
509
511
  r,
@@ -513,73 +515,73 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
513
515
  a,
514
516
  c,
515
517
  i
516
- ]), h = m(() => {
517
- let e = c.addJob({ kind: B.All });
518
+ ]), m = _(() => {
519
+ let e = c.addJob({ kind: ye.All });
518
520
  return c.startJob(e, (t) => p(e, t));
519
521
  }, [c, p]);
520
522
  return {
521
523
  jobs: c.jobs,
522
524
  exportSingle: f,
523
- exportAll: h,
525
+ exportAll: m,
524
526
  dismissJob: c.dismissJob,
525
527
  retryJob: c.retryJob,
526
528
  dismissAll: c.dismissAll
527
529
  };
528
- }, Re = (e) => {
530
+ }, rt = (e) => {
529
531
  if (!e.url) throw Error(`Attachment "${e.name}" has not been uploaded`);
530
532
  return {
531
533
  type: e.contentType,
532
534
  title: e.name,
533
535
  url: e.url
534
536
  };
535
- }, J = (e) => {
536
- if (e.length) return e.map(Re);
537
- }, Y = (e, t, n) => {
537
+ }, it = (e) => {
538
+ if (e.length) return e.map(rt);
539
+ }, at = (e, t, n) => {
538
540
  let r = new Date(Date.now()).toISOString();
539
541
  return {
540
542
  userMessage: {
541
- role: i.User,
543
+ role: a.User,
542
544
  content: e,
543
545
  timestamp: r,
544
546
  ...t && Object.keys(t).length ? { custom_content: t } : {}
545
547
  },
546
548
  assistantMessage: {
547
- role: i.Assistant,
549
+ role: a.Assistant,
548
550
  content: "",
549
551
  timestamp: r,
550
552
  ...n ? { deploymentId: n } : {}
551
553
  }
552
554
  };
553
- }, X = (e) => e != null && Object.keys(e).length > 0, ze = (e, t, n, r) => {
555
+ }, ot = (e) => e != null && Object.keys(e).length > 0, st = (e, t, n, r) => {
554
556
  if (t !== e.content || r.length > 0) return !0;
555
557
  let i = e.custom_content?.attachments?.length ?? 0;
556
558
  return n.length !== i;
557
- }, Be = (e) => e["dial:widgetOptions"].populateText || e.title, Ve = (e, t) => {
559
+ }, ct = (e) => e["dial:widgetOptions"].populateText || e.title, lt = (e, t) => {
558
560
  let { populateText: n } = e["dial:widgetOptions"];
559
- return n == null && t ? t : Be(e);
560
- }, He = (e, t) => {
561
+ return n == null && t ? t : ct(e);
562
+ }, ut = (e, t) => {
561
563
  let { populateText: n, submit: r } = e["dial:widgetOptions"];
562
- return r && n == null ? "" : t ?? Be(e);
563
- }, Z = (e) => {
564
+ return r && n == null ? "" : t ?? ct(e);
565
+ }, dt = (e) => {
564
566
  try {
565
567
  return decodeURIComponent(e);
566
568
  } catch {
567
569
  return e;
568
570
  }
569
- }, Q = (e) => {
571
+ }, K = (e) => {
570
572
  let t = e.indexOf("/");
571
- return Z(t === -1 ? e : e.substring(t + 1));
572
- }, Ue = ({ conversation: e, conversationId: t, bucket: n, isStreaming: r, startStream: a, state: { setConversation: o, conversationRef: s }, filesApi: c, conversationsApi: l, rateApi: u, resolveModelId: d, onConversationDeleted: f, showNetworkError: p, toolConfigurationValue: h }) => {
573
- let [g, _] = y(null), [v, b] = y(/* @__PURE__ */ new Set()), [x, S] = y(null), { handleUploadAttachment: C } = Oe({
573
+ return dt(t === -1 ? e : e.substring(t + 1));
574
+ }, ft = ({ conversation: e, conversationId: t, bucket: n, isStreaming: r, startStream: i, state: { setConversation: o, conversationRef: s }, filesApi: c, conversationsApi: l, rateApi: u, resolveModelId: d, onConversationDeleted: f, showNetworkError: p, toolConfigurationValue: m }) => {
575
+ let [h, g] = S(null), [v, y] = S(/* @__PURE__ */ new Set()), [b, x] = S(null), { handleUploadAttachment: C } = qe({
574
576
  filesApi: c,
575
577
  bucket: n,
576
578
  onNetworkError: p
577
- }), w = m(async (n, r) => {
579
+ }), w = _(async (n, r) => {
578
580
  if (!t || !e) return;
579
- let i = J(r), c = X(h), l = i?.length || c ? {
580
- ...i?.length ? { attachments: i } : {},
581
- ...c ? { configuration_value: h } : {}
582
- } : void 0, u = d(), { userMessage: f, assistantMessage: p } = Y(n, l, u);
581
+ let a = it(r), c = ot(m), l = a?.length || c ? {
582
+ ...a?.length ? { attachments: a } : {},
583
+ ...c ? { configuration_value: m } : {}
584
+ } : void 0, u = d(), { userMessage: f, assistantMessage: p } = at(n, l, u);
583
585
  o((e) => {
584
586
  if (!e) return e;
585
587
  let t = {
@@ -591,19 +593,19 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
591
593
  ]
592
594
  };
593
595
  return s.current = t, t;
594
- }), a(t, n, e.messages.length + 1, u, l, crypto.randomUUID(), E.Append);
596
+ }), i(t, n, e.messages.length + 1, u, l, crypto.randomUUID(), F.Append);
595
597
  }, [
596
598
  e,
597
599
  t,
598
600
  s,
599
601
  d,
600
602
  o,
601
- a,
602
- h
603
- ]), T = m((n) => {
604
- if (r || !t || !e || n === -1 || e.messages[n]?.role !== i.Assistant) return;
603
+ i,
604
+ m
605
+ ]), T = _((n) => {
606
+ if (r || !t || !e || n === -1 || e.messages[n]?.role !== a.Assistant) return;
605
607
  let c = e.messages[n - 1];
606
- if (!c || c.role !== i.User) return;
608
+ if (!c || c.role !== a.User) return;
607
609
  let l = d();
608
610
  o((e) => {
609
611
  if (!e) return e;
@@ -620,7 +622,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
620
622
  messages: [...e.messages.slice(0, n), t]
621
623
  };
622
624
  return s.current = r, r;
623
- }), b((e) => new Set([...e].filter((e) => e < n))), a(t, c.content, n, l, c.custom_content, crypto.randomUUID(), E.Regenerate);
625
+ }), y((e) => new Set([...e].filter((e) => e < n))), i(t, c.content, n, l, c.custom_content, crypto.randomUUID(), F.Regenerate);
624
626
  }, [
625
627
  e,
626
628
  t,
@@ -628,36 +630,36 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
628
630
  r,
629
631
  d,
630
632
  o,
631
- a
632
- ]), D = m((e) => {
633
- r || _(e);
634
- }, [r]), O = m(() => {
635
- if (!t || g == null) return;
636
- _(null);
637
- let e = Q(t);
633
+ i
634
+ ]), E = _((e) => {
635
+ r || g(e);
636
+ }, [r]), D = _(() => {
637
+ if (!t || h == null) return;
638
+ g(null);
639
+ let e = K(t);
638
640
  o((t) => {
639
641
  if (!t) return t;
640
- let n = g;
642
+ let n = h;
641
643
  if (n === -1) return t;
642
- let r = t.messages[n + 1]?.role === i.Assistant ? t.messages.filter((e, t) => t !== n && t !== n + 1) : t.messages.filter((e, t) => t !== n);
643
- if (r.length === 0 || r.length === 1 && r[0].role === i.Status) return l.deleteConversation({ path: e }), f?.(), t;
644
- let a = {
644
+ let r = t.messages[n + 1]?.role === a.Assistant ? t.messages.filter((e, t) => t !== n && t !== n + 1) : t.messages.filter((e, t) => t !== n);
645
+ if (r.length === 0 || r.length === 1 && r[0].role === a.Status) return l.deleteConversation({ path: e }), f?.(), t;
646
+ let i = {
645
647
  ...t,
646
648
  messages: r
647
649
  };
648
- return s.current = a, l.saveConversation({
650
+ return s.current = i, l.saveConversation({
649
651
  path: e,
650
- saveConversationBodyDto: { conversation: a }
651
- }), a;
652
+ saveConversationBodyDto: { conversation: i }
653
+ }), i;
652
654
  });
653
655
  }, [
654
656
  t,
655
657
  s,
656
658
  l,
657
659
  f,
658
- g,
660
+ h,
659
661
  o
660
- ]), k = m(async (n, r, i) => {
662
+ ]), O = _(async (n, r, i) => {
661
663
  if (!t || !e) return !1;
662
664
  let a = e.messages[n];
663
665
  if (!a) return !1;
@@ -669,7 +671,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
669
671
  } : e)
670
672
  };
671
673
  o(() => (s.current = d, d));
672
- let f = Q(t), p = () => {
674
+ let f = K(t), p = () => {
673
675
  o((e) => e && {
674
676
  ...e,
675
677
  messages: e.messages.map((e, t) => t === n ? {
@@ -707,12 +709,12 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
707
709
  l,
708
710
  u,
709
711
  o
710
- ]), A = m((n, r, i) => {
712
+ ]), k = _((n, r, a) => {
711
713
  if (!t || !e) return;
712
- let c = i ?? n.title, l = He(n, i), u = r ? { [r]: n.const } : void 0, f = X(h), p = u || f ? {
714
+ let c = a ?? n.title, l = ut(n, a), u = r ? { [r]: n.const } : void 0, f = ot(m), p = u || f ? {
713
715
  ...u ? { form_value: u } : {},
714
- ...f ? { configuration_value: h } : {}
715
- } : void 0, m = d(), { userMessage: g, assistantMessage: _ } = Y(c, p, m);
716
+ ...f ? { configuration_value: m } : {}
717
+ } : void 0, h = d(), { userMessage: g, assistantMessage: _ } = at(c, p, h);
716
718
  o((e) => {
717
719
  if (!e) return e;
718
720
  let t = {
@@ -724,73 +726,73 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
724
726
  ]
725
727
  };
726
728
  return s.current = t, t;
727
- }), a(t, l, e.messages.length + 1, m, p, crypto.randomUUID(), E.Append);
729
+ }), i(t, l, e.messages.length + 1, h, p, crypto.randomUUID(), F.Append);
728
730
  }, [
729
731
  e,
730
732
  t,
731
733
  s,
732
734
  d,
733
735
  o,
734
- a,
735
- h
736
+ i,
737
+ m
736
738
  ]);
737
739
  return {
738
740
  handleSend: w,
739
741
  handleUploadAttachment: C,
740
742
  handleRegenerateMessage: T,
741
- handleDeleteMessage: D,
742
- handleConfirmDelete: O,
743
- handleRateMessage: k,
744
- handleButtonSelect: m((n, i, a) => {
745
- !t || !e || r || (n["dial:widgetOptions"].confirmationMessage ? S({
743
+ handleDeleteMessage: E,
744
+ handleConfirmDelete: D,
745
+ handleRateMessage: O,
746
+ handleButtonSelect: _((n, i, a) => {
747
+ !t || !e || r || (n["dial:widgetOptions"].confirmationMessage ? x({
746
748
  starter: n,
747
749
  propertyKey: i,
748
750
  description: a
749
- }) : A(n, i, a));
751
+ }) : k(n, i, a));
750
752
  }, [
751
753
  e,
752
754
  t,
753
755
  r,
754
- A
756
+ k
755
757
  ]),
756
- handleConfirmStarter: m(() => {
757
- if (!x) return;
758
- let { starter: e, propertyKey: t, description: n } = x;
759
- S(null), A(e, t, n);
760
- }, [x, A]),
761
- handleStartEdit: m((e) => {
762
- b((t) => new Set([...t, e]));
758
+ handleConfirmStarter: _(() => {
759
+ if (!b) return;
760
+ let { starter: e, propertyKey: t, description: n } = b;
761
+ x(null), k(e, t, n);
762
+ }, [b, k]),
763
+ handleStartEdit: _((e) => {
764
+ y((t) => new Set([...t, e]));
763
765
  }, []),
764
- handleCancelEdit: m((e) => {
765
- b((t) => {
766
+ handleCancelEdit: _((e) => {
767
+ y((t) => {
766
768
  let n = new Set(t);
767
769
  return n.delete(e), n;
768
770
  });
769
771
  }, []),
770
- handleEditMessage: m(async (n, c, l, u) => {
772
+ handleEditMessage: _(async (n, c, l, u) => {
771
773
  if (r || !t || !e) return;
772
774
  let f = n;
773
- if (f === -1 || e.messages[f].role !== i.User) return;
775
+ if (f === -1 || e.messages[f].role !== a.User) return;
774
776
  let p = e.messages[f];
775
- if (!ze(p, c, l, u)) {
776
- b((e) => {
777
+ if (!st(p, c, l, u)) {
778
+ y((e) => {
777
779
  let t = new Set(e);
778
780
  return t.delete(f), t;
779
781
  });
780
782
  return;
781
783
  }
782
- let m = J(u), h = new Set(l.map((e) => e.id)), g = [...(p.custom_content?.attachments ?? []).filter((e) => {
784
+ let m = it(u), h = new Set(l.map((e) => e.id)), g = [...(p.custom_content?.attachments ?? []).filter((e) => {
783
785
  let t = e.url ?? e.data ?? e.title;
784
786
  return h.has(t);
785
- }), ...m ?? []], { attachments: _, ...v } = p.custom_content ?? {}, y = g.length > 0 ? {
787
+ }), ...m ?? []], { attachments: _, ...v } = p.custom_content ?? {}, b = g.length > 0 ? {
786
788
  ...v,
787
789
  attachments: g
788
790
  } : Object.keys(v).length > 0 ? v : void 0, x = {
789
791
  ...p,
790
792
  content: c,
791
- custom_content: y
793
+ custom_content: b
792
794
  }, S = Date.now(), C = {
793
- role: i.Assistant,
795
+ role: a.Assistant,
794
796
  content: "",
795
797
  timestamp: new Date(S).toISOString()
796
798
  }, w = [
@@ -802,8 +804,8 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
802
804
  messages: w
803
805
  };
804
806
  o(() => (s.current = T, T));
805
- let D = d();
806
- a(t, c, w.length - 1, D, y, crypto.randomUUID(), E.Edit), b(/* @__PURE__ */ new Set());
807
+ let E = d();
808
+ i(t, c, w.length - 1, E, b, crypto.randomUUID(), F.Edit), y(/* @__PURE__ */ new Set());
807
809
  }, [
808
810
  e,
809
811
  t,
@@ -811,28 +813,28 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
811
813
  r,
812
814
  d,
813
815
  o,
814
- a
816
+ i
815
817
  ]),
816
818
  editingMessageIndexes: v,
817
- pendingDeleteIndex: g,
818
- setPendingDeleteIndex: _,
819
- pendingStarterContext: x,
820
- setPendingStarterContext: S
819
+ pendingDeleteIndex: h,
820
+ setPendingDeleteIndex: g,
821
+ pendingStarterContext: b,
822
+ setPendingStarterContext: x
821
823
  };
822
- }, We = (e) => {
824
+ }, pt = (e) => {
823
825
  let t = e.lastIndexOf("."), n = t > 0;
824
826
  return {
825
827
  base: n ? e.slice(0, t) : e,
826
828
  extension: n ? e.slice(t) : ""
827
829
  };
828
- }, Ge = (e) => (e.split(/[\\/]/).filter(Boolean).pop() ?? "file").replace(/\.\.+/g, ".").replace(/^\.+/, "") || "file", Ke = (e, t, n) => n === 0 ? `${e}${t}` : `${e} (${n})${t}`, qe = (e) => {
830
+ }, mt = (e) => (e.split(/[\\/]/).filter(Boolean).pop() ?? "file").replace(/\.\.+/g, ".").replace(/^\.+/, "") || "file", ht = (e, t, n) => n === 0 ? `${e}${t}` : `${e} (${n})${t}`, gt = (e) => {
829
831
  let t = e?.date ?? /* @__PURE__ */ new Date(), n = new Set(e?.existingNames);
830
832
  return {
831
833
  allocate: (e) => {
832
- let { base: r, extension: i } = We(Ge(e)), a = 0, o = Ke(r, i, a);
833
- for (; n.has(o);) a += 1, o = Ke(r, i, a);
834
+ let { base: r, extension: i } = pt(mt(e)), a = 0, o = ht(r, i, a);
835
+ for (; n.has(o);) a += 1, o = ht(r, i, a);
834
836
  return n.add(o), {
835
- path: `uploads/${L(t)}/${encodeURIComponent(o)}`,
837
+ path: `uploads/${_e(t)}/${encodeURIComponent(o)}`,
836
838
  fileName: o,
837
839
  isRenamed: a > 0
838
840
  };
@@ -841,34 +843,34 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
841
843
  n.add(e);
842
844
  }
843
845
  };
844
- }, Je = "conversation.json", Ye = /^conversations\/.*\.json$/, Xe = "res/", Ze = (e) => e.find((e) => e === Je) ?? e.find((e) => Ye.test(e)) ?? e.find((e) => !e.includes("/") && e.toLowerCase().endsWith(".json")), Qe = (e) => new Promise((t, n) => {
846
+ }, _t = "conversation.json", vt = /^conversations\/.*\.json$/, yt = "res/", bt = (e) => e.find((e) => e === _t) ?? e.find((e) => vt.test(e)) ?? e.find((e) => !e.includes("/") && e.toLowerCase().endsWith(".json")), xt = (e) => new Promise((t, n) => {
845
847
  let r = new FileReader();
846
848
  r.onload = () => t(new Uint8Array(r.result)), r.onerror = () => n(r.error), r.readAsArrayBuffer(e);
847
- }), $e = async (e) => {
848
- let t = await Qe(e), n;
849
+ }), St = async (e) => {
850
+ let t = await xt(e), n;
849
851
  try {
850
- n = w(t);
852
+ n = D(t);
851
853
  } catch {
852
- throw new K("Import file is not a valid archive");
854
+ throw new Ae("Import file is not a valid archive");
853
855
  }
854
- let r = Object.keys(n), i = Ze(r);
855
- if (!i) throw new K("Archive does not contain a readable conversation-JSON entry");
856
- let a = he(S(n[i])), o = /* @__PURE__ */ new Map();
856
+ let r = Object.keys(n), i = bt(r);
857
+ if (!i) throw new Ae("Archive does not contain a readable conversation-JSON entry");
858
+ let a = Ne(T(n[i])), o = /* @__PURE__ */ new Map();
857
859
  for (let e of r) {
858
- if (e.endsWith("/") || !e.startsWith(Xe)) continue;
860
+ if (e.endsWith("/") || !e.startsWith(yt)) continue;
859
861
  let t = e.slice(4);
860
- !t || !Ne(t) || o.set(t, n[e]);
862
+ !t || !Qe(t) || o.set(t, n[e]);
861
863
  }
862
864
  return {
863
865
  envelope: a,
864
866
  attachments: o
865
867
  };
866
- }, et = 5, tt = 5, nt = (e) => /\.(dial|zip)$/i.test(e.name), rt = (e) => new Promise((t, n) => {
868
+ }, Ct = 5, wt = 5, Tt = (e) => /\.(dial|zip)$/i.test(e.name), Et = (e) => new Promise((t, n) => {
867
869
  let r = new FileReader();
868
870
  r.onload = () => t(r.result), r.onerror = () => n(r.error), r.readAsText(e);
869
- }), it = async (e) => {
870
- if (nt(e)) {
871
- let { envelope: t, attachments: n } = await $e(e);
871
+ }), Dt = async (e) => {
872
+ if (Tt(e)) {
873
+ let { envelope: t, attachments: n } = await St(e);
872
874
  return {
873
875
  history: t.history,
874
876
  attachments: n,
@@ -876,15 +878,15 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
876
878
  };
877
879
  }
878
880
  return {
879
- history: he(await rt(e)).history,
881
+ history: Ne(await Et(e)).history,
880
882
  attachments: /* @__PURE__ */ new Map(),
881
883
  isArchive: !1
882
884
  };
883
- }, at = async (e, t, n, r, i, a, o) => {
884
- let { plan: s, skippedNames: c } = we(e, t, r), l = !1, u = await ke(s, et, async (e) => {
885
+ }, Ot = async (e, t, n, r, i, a, o) => {
886
+ let { plan: s, skippedNames: c } = Ue(e, t, r), l = !1, u = await Je(s, Ct, async (e) => {
885
887
  if (o.aborted || l) return;
886
888
  let t = e.allocated;
887
- for (let s = 0; s <= tt; s += 1) try {
889
+ for (let s = 0; s <= wt; s += 1) try {
888
890
  let r = new File([new Uint8Array(e.bytes)], t.fileName), a = await i.uploadFile({
889
891
  bucket: n,
890
892
  path: t.path,
@@ -903,7 +905,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
903
905
  l = !0;
904
906
  return;
905
907
  }
906
- if (!(typeof n == "object" && n && "response" in n && n.response?.status === 409) || s === tt) return {
908
+ if (!(typeof n == "object" && n && "response" in n && n.response?.status === 409) || s === wt) return {
907
909
  kind: "skipped",
908
910
  name: e.originalFileName
909
911
  };
@@ -923,18 +925,18 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
923
925
  skippedNames: o.aborted || l ? [] : f,
924
926
  isUnauthorized: !o.aborted && l
925
927
  };
926
- }, ot = ({ conversationsApi: e, filesApi: t, bucket: n, onImported: r, classifyTransferError: i = () => ({}), resolveErrorTraceId: a = async () => void 0, onSuccess: o, onWarning: s, onError: c }) => {
927
- let l = Ae(), u = m(async (u, d, f) => {
928
+ }, kt = ({ conversationsApi: e, filesApi: t, bucket: n, onImported: r, classifyTransferError: i = () => ({}), resolveErrorTraceId: a = async () => void 0, onSuccess: o, onWarning: s, onError: c }) => {
929
+ let l = Ye(), u = _(async (u, d, f) => {
928
930
  if (!n) {
929
931
  c?.({
930
932
  jobId: u,
931
- code: V.MissingBucket
932
- }), l.updateJob(u, { status: z.Failed });
933
+ code: G.MissingBucket
934
+ }), l.updateJob(u, { status: W.Failed });
933
935
  return;
934
936
  }
935
937
  let p = [], m = [], h = [], g = !1, _, v = /* @__PURE__ */ new Date(), y = (e) => !!i(e).isUnauthorized, b;
936
938
  if (d.isArchive) {
937
- let e = `uploads/${L(v)}`, r = [];
939
+ let e = `uploads/${_e(v)}`, r = [];
938
940
  try {
939
941
  r = (await t.listFiles({
940
942
  bucket: n,
@@ -945,13 +947,13 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
945
947
  if (y(e)) {
946
948
  c?.({
947
949
  jobId: u,
948
- code: V.Unauthorized
949
- }), l.updateJob(u, { status: z.Failed });
950
+ code: G.Unauthorized
951
+ }), l.updateJob(u, { status: W.Failed });
950
952
  return;
951
953
  }
952
954
  console.error("Failed to list the upload folder for attachment name disambiguation", e);
953
955
  }
954
- b = qe({
956
+ b = gt({
955
957
  date: v,
956
958
  existingNames: r
957
959
  });
@@ -962,7 +964,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
962
964
  try {
963
965
  let i = /* @__PURE__ */ new Map();
964
966
  if (d.isArchive && b) {
965
- let e = await at(r, d.attachments, n, b, t, y, f);
967
+ let e = await Ot(r, d.attachments, n, b, t, y, f);
966
968
  if (f.aborted) return;
967
969
  if (e.isUnauthorized) {
968
970
  g = !0;
@@ -970,7 +972,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
970
972
  }
971
973
  e.skippedNames.length > 0 && h.push(...e.skippedNames), i = e.targetMap;
972
974
  }
973
- let { conversation: a, subPath: o } = ye(Se(r, i), n);
975
+ let { conversation: a, subPath: o } = Re(Ve(r, i), n);
974
976
  if (await e.saveConversation({
975
977
  path: o,
976
978
  saveConversationBodyDto: { conversation: {
@@ -992,8 +994,8 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
992
994
  if (g) {
993
995
  c?.({
994
996
  jobId: u,
995
- code: V.Unauthorized
996
- }), l.updateJob(u, { status: z.Failed });
997
+ code: G.Unauthorized
998
+ }), l.updateJob(u, { status: W.Failed });
997
999
  return;
998
1000
  }
999
1001
  if (p.length > 0) {
@@ -1007,14 +1009,14 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1007
1009
  }
1008
1010
  m.length > 0 && c?.({
1009
1011
  jobId: u,
1010
- code: V.Unknown,
1012
+ code: G.Unknown,
1011
1013
  titles: m,
1012
1014
  traceId: _
1013
1015
  }), h.length > 0 && s?.({
1014
1016
  jobId: u,
1015
- code: H.AttachmentSkipped,
1017
+ code: be.AttachmentSkipped,
1016
1018
  names: h
1017
- }), l.updateJob(u, { status: m.length > 0 ? z.Failed : z.Success });
1019
+ }), l.updateJob(u, { status: m.length > 0 ? W.Failed : W.Success });
1018
1020
  }
1019
1021
  }, [
1020
1022
  n,
@@ -1027,21 +1029,21 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1027
1029
  s,
1028
1030
  l,
1029
1031
  a
1030
- ]), d = m(async (e) => {
1032
+ ]), d = _(async (e) => {
1031
1033
  let t;
1032
1034
  try {
1033
- t = await it(e);
1035
+ t = await Dt(e);
1034
1036
  } catch (e) {
1035
1037
  c?.({
1036
1038
  jobId: crypto.randomUUID(),
1037
- code: V.UnsupportedFormat
1038
- }), e instanceof K || console.error("Failed to parse import file", e);
1039
+ code: G.UnsupportedFormat
1040
+ }), e instanceof Ae || console.error("Failed to parse import file", e);
1039
1041
  return;
1040
1042
  }
1041
- let n = t.history.length > 1, r = t.history[0], i = n ? { kind: B.All } : {
1042
- kind: B.Single,
1043
+ let n = t.history.length > 1, r = t.history[0], i = n ? { kind: ye.All } : {
1044
+ kind: ye.Single,
1043
1045
  title: r?.name ?? e.name,
1044
- sourceBreadcrumb: r ? be(r) : void 0
1046
+ sourceBreadcrumb: r ? ze(r) : void 0
1045
1047
  }, a = l.addJob(i);
1046
1048
  return l.startJob(a, (e) => u(a, t, e));
1047
1049
  }, [
@@ -1056,75 +1058,75 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1056
1058
  retryJob: l.retryJob,
1057
1059
  dismissAll: l.dismissAll
1058
1060
  };
1059
- }, st = 80, ct = 1, lt = ({ messages: e, isAssistantTyping: t, conversationId: n }) => {
1060
- let [r, i] = y(!1), a = v(null), o = v(null), s = v(null), c = v(!1), l = v(!1), u = v(null), d = v(/* @__PURE__ */ new Map()), f = m((e, t) => {
1061
+ }, At = 80, jt = 1, Mt = ({ messages: e, isAssistantTyping: t, conversationId: n }) => {
1062
+ let [r, i] = S(!1), a = x(null), o = x(null), s = x(null), c = x(!1), l = x(!1), u = x(null), d = x(/* @__PURE__ */ new Map()), f = _((e, t) => {
1061
1063
  t ? d.current.set(e, t) : d.current.delete(e);
1062
- }, []), p = v(null), _ = m((e) => {
1064
+ }, []), p = x(null), m = _((e) => {
1063
1065
  p.current = e;
1064
- }, []), b = m((e, t) => {
1066
+ }, []), h = _((e, t) => {
1065
1067
  let n = a.current;
1066
1068
  n && n.scrollTo({
1067
1069
  top: e,
1068
1070
  behavior: t ? "instant" : "smooth"
1069
1071
  });
1070
- }, []), x = m(() => {
1072
+ }, []), g = _(() => {
1071
1073
  s.current && (s.current.style.height = "0px"), c.current = !1, l.current = !1, u.current = null;
1072
- }, []), S = m(() => {
1074
+ }, []), b = _(() => {
1073
1075
  let e = a.current, t = o.current;
1074
1076
  if (!e || !t) return null;
1075
1077
  let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
1076
1078
  return e.scrollTop + (r.bottom - n.top) - e.clientHeight;
1077
- }, []), C = m((e = !1) => {
1078
- let t = S();
1079
- t != null && b(Math.max(t, 0), e);
1080
- }, [b, S]), w = m(() => {
1079
+ }, []), C = _((e = !1) => {
1080
+ let t = b();
1081
+ t != null && h(Math.max(t, 0), e);
1082
+ }, [h, b]), w = _(() => {
1081
1083
  let e = a.current, t = o.current;
1082
1084
  if (!e || !t) return null;
1083
1085
  let n = e.getBoundingClientRect();
1084
1086
  return t.getBoundingClientRect().bottom - n.top - e.clientHeight;
1085
- }, []), T = m(() => {
1087
+ }, []), T = _(() => {
1086
1088
  if (!l.current) return;
1087
1089
  let e = w();
1088
- e == null || e < -1 || x();
1089
- }, [x, w]), E = m((e) => {
1090
+ e == null || e < -1 || g();
1091
+ }, [g, w]), E = _((e) => {
1090
1092
  let t = a.current, n = d.current.get(e);
1091
1093
  if (!t || !n) return null;
1092
1094
  let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), o = t.scrollTop + (i.top - r.top);
1093
1095
  return Math.max(o, 0);
1094
- }, []), D = m((e, t = !1) => {
1096
+ }, []), D = _((e, t = !1) => {
1095
1097
  let n = E(e);
1096
- n != null && b(n, t);
1097
- }, [E, b]), O = m(() => {
1098
- let e = S();
1098
+ n != null && h(n, t);
1099
+ }, [E, h]), O = _(() => {
1100
+ let e = b();
1099
1101
  return e == null ? null : Math.max(e, 0);
1100
- }, [S]), k = m(() => {
1102
+ }, [b]), k = _(() => {
1101
1103
  if (!c.current) return null;
1102
1104
  let e = u.current, t = O();
1103
1105
  return e == null || t == null ? null : Math.max(e, t);
1104
- }, [O]), A = m(() => {
1106
+ }, [O]), A = _(() => {
1105
1107
  let e = a.current, t = k();
1106
- !e || t == null || e.scrollTop > t + ct && (e.scrollTop = t);
1107
- }, [k]), j = m((e) => {
1108
+ !e || t == null || e.scrollTop > t + jt && (e.scrollTop = t);
1109
+ }, [k]), j = _((e) => {
1108
1110
  let t = s.current, n = O();
1109
1111
  if (!t || n == null) return;
1110
1112
  let r = Math.max(e - n, 0);
1111
1113
  t.style.height = `${r}px`, c.current = r > 0, l.current = !1, u.current = r > 0 ? e : null;
1112
- }, [O]), M = m((e) => {
1114
+ }, [O]), M = _((e) => {
1113
1115
  let t = E(e);
1114
1116
  t != null && (j(t), D(e, !1));
1115
1117
  }, [
1116
1118
  j,
1117
1119
  E,
1118
1120
  D
1119
- ]), N = m(() => {
1121
+ ]), N = _(() => {
1120
1122
  let e = w();
1121
- e != null && i(e >= st);
1122
- }, [w]), P = v(e.length), F = v(null);
1123
- g(() => {
1123
+ e != null && i(e >= At);
1124
+ }, [w]), P = x(e.length), F = x(null);
1125
+ y(() => {
1124
1126
  let r = e.length !== P.current, i = n !== F.current, a = () => {
1125
1127
  P.current = e.length, F.current = n;
1126
1128
  };
1127
- i && x();
1129
+ i && g();
1128
1130
  let o = p.current;
1129
1131
  if (o != null && d.current.has(o)) {
1130
1132
  p.current = null, M(o), a();
@@ -1137,21 +1139,21 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1137
1139
  n,
1138
1140
  C,
1139
1141
  M,
1140
- x
1141
- ]), g(() => {
1142
+ g
1143
+ ]), y(() => {
1142
1144
  !t && c.current && (l.current = !0, T());
1143
1145
  }, [t, T]);
1144
- let I = m(() => {
1146
+ let I = _(() => {
1145
1147
  A(), T(), N();
1146
1148
  }, [
1147
1149
  A,
1148
1150
  T,
1149
1151
  N
1150
1152
  ]);
1151
- return h(() => {
1153
+ return v(() => {
1152
1154
  let e = a.current;
1153
1155
  if (e) return e.addEventListener("scroll", I, { passive: !0 }), () => e.removeEventListener("scroll", I);
1154
- }, [I]), h(() => {
1156
+ }, [I]), v(() => {
1155
1157
  let e = o.current;
1156
1158
  if (!e) return;
1157
1159
  let t = new ResizeObserver(() => {
@@ -1168,15 +1170,15 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1168
1170
  spacerRef: s,
1169
1171
  setMessageRef: f,
1170
1172
  isScrollButtonVisible: r,
1171
- scrollToBottom: m(() => {
1173
+ scrollToBottom: _(() => {
1172
1174
  C(!1);
1173
1175
  }, [C]),
1174
- armAnchor: _
1176
+ armAnchor: m
1175
1177
  };
1176
- }, $ = (e) => {
1178
+ }, Nt = (e) => {
1177
1179
  let t = e.messages[e.messages.length - 1];
1178
- return !!t && t.role === i.Assistant && !t.content && t.streamErrorMessage == null && !t.wasStoppedByUser;
1179
- }, ut = (e, t) => {
1180
+ return !!t && t.role === a.Assistant && !t.content && t.streamErrorMessage == null && !t.wasStoppedByUser;
1181
+ }, Pt = (e, t) => {
1180
1182
  let n = [...e];
1181
1183
  for (let e of t) {
1182
1184
  let t = n.findIndex((t) => t.index === e.index);
@@ -1195,7 +1197,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1195
1197
  } else n.push(e);
1196
1198
  }
1197
1199
  return n;
1198
- }, dt = (e, t) => {
1200
+ }, Ft = (e, t) => {
1199
1201
  let n = [...e];
1200
1202
  for (let e of t) {
1201
1203
  let t = e.index == null ? -1 : n.findIndex((t) => t.index === e.index);
@@ -1207,7 +1209,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1207
1209
  } : n.push(e);
1208
1210
  }
1209
1211
  return n;
1210
- }, ft = (e, t) => {
1212
+ }, It = (e, t) => {
1211
1213
  let n = [...e];
1212
1214
  for (let e of t) {
1213
1215
  let t = n.findIndex((t) => t.index === e.index);
@@ -1216,61 +1218,61 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1216
1218
  ...e,
1217
1219
  name: (n[t].name ?? "") + (e.name ?? ""),
1218
1220
  content: (n[t].content ?? "") + (e.content ?? "") || void 0,
1219
- attachments: e.attachments?.length ? dt(n[t].attachments ?? [], e.attachments) : n[t].attachments
1221
+ attachments: e.attachments?.length ? Ft(n[t].attachments ?? [], e.attachments) : n[t].attachments
1220
1222
  } : n.push({
1221
1223
  ...e,
1222
1224
  name: e.name ?? ""
1223
1225
  });
1224
1226
  }
1225
1227
  return n;
1226
- }, pt = (e, t, n) => {
1227
- let r = n.choices[0]?.delta, i = r?.content ?? "", a = r?.custom_content?.form_schema, o = r?.custom_content?.attachments, s = r?.custom_content?.stages, c = r?.custom_content?.annotations, l = r?.custom_fields?.annotations, u = r?.custom_content?.state, f = !!i || !!a || !!o?.length || !!s?.length || !!c?.length || !!l?.length || !!u, p = r?.responseId ?? (f ? n.id : void 0);
1228
- return !f && !p ? null : e.map((e, n) => {
1228
+ }, Lt = (e, t, n) => {
1229
+ let r = n.choices[0]?.delta, i = r?.content ?? "", a = r?.custom_content?.form_schema, o = r?.custom_content?.attachments, s = r?.custom_content?.stages, c = r?.custom_content?.annotations, l = r?.custom_fields?.annotations, u = r?.custom_content?.state, d = !!i || !!a || !!o?.length || !!s?.length || !!c?.length || !!l?.length || !!u, f = r?.responseId ?? (d ? n.id : void 0);
1230
+ return !d && !f ? null : e.map((e, n) => {
1229
1231
  if (n !== t) return e;
1230
- let r = [...e.custom_content?.attachments ?? [], ...o ?? []], f = l?.length ? d(l, r) : [], m = [...c ?? [], ...f], h = a || o?.length || s?.length || m.length || u;
1232
+ let r = [...e.custom_content?.attachments ?? [], ...o ?? []], d = l?.length ? m(l, r) : [], p = [...c ?? [], ...d], h = a || o?.length || s?.length || p.length || u;
1231
1233
  return {
1232
1234
  ...e,
1233
1235
  content: i ? e.content + i : e.content,
1234
- ...p && { responseId: p },
1236
+ ...f && { responseId: f },
1235
1237
  ...h && { custom_content: {
1236
1238
  ...e.custom_content,
1237
1239
  ...a && { form_schema: a },
1238
1240
  ...o?.length && { attachments: r },
1239
- ...s?.length && { stages: ft(e.custom_content?.stages ?? [], s) },
1240
- ...m.length && { annotations: ut(e.custom_content?.annotations ?? [], m) },
1241
+ ...s?.length && { stages: It(e.custom_content?.stages ?? [], s) },
1242
+ ...p.length && { annotations: Pt(e.custom_content?.annotations ?? [], p) },
1241
1243
  ...u && { state: u }
1242
1244
  } }
1243
1245
  };
1244
1246
  });
1245
- }, mt = 300 * 1e3, ht = ({ conversationId: e, state: { setConversation: t, conversationRef: n }, transport: r, generation: { startGeneration: i, completeGeneration: a }, channel: o, overlay: s, onStopError: c }) => {
1246
- let [l, u] = y(() => /* @__PURE__ */ new Set()), [d, f] = y(null), p = v(null), g = v(null), _ = v(/* @__PURE__ */ new Set()), b = v(/* @__PURE__ */ new Set()), x = v(e);
1247
- h(() => {
1248
- x.current = e;
1247
+ }, Rt = 300 * 1e3, zt = ({ conversationId: e, state: { setConversation: t, conversationRef: n }, transport: r, generation: { startGeneration: i, completeGeneration: a }, channel: o, overlay: s, onStopError: c }) => {
1248
+ let [l, u] = S(() => /* @__PURE__ */ new Set()), [d, f] = S(null), p = x(null), m = x(null), h = x(/* @__PURE__ */ new Set()), g = x(/* @__PURE__ */ new Set()), y = x(e);
1249
+ v(() => {
1250
+ y.current = e;
1249
1251
  }, [e]);
1250
- let S = m((e) => Q(x.current ?? "") === e, []), C = m((e) => {
1252
+ let b = _((e) => K(y.current ?? "") === e, []), C = _((e) => {
1251
1253
  u((t) => {
1252
1254
  if (t.has(e)) return t;
1253
1255
  let n = new Set(t);
1254
1256
  return n.add(e), n;
1255
1257
  });
1256
- }, []), w = m((e) => {
1258
+ }, []), w = _((e) => {
1257
1259
  u((t) => {
1258
1260
  if (!t.has(e)) return t;
1259
1261
  let n = new Set(t);
1260
1262
  return n.delete(e), n;
1261
1263
  });
1262
- }, []), T = m((e, c, l, u, d, m, h = E.Append) => {
1263
- let _ = m ?? crypto.randomUUID(), v = Q(e);
1264
- p.current = _, g.current = v, f(v);
1265
- let y;
1266
- h === E.Regenerate ? y = l : h === E.Edit && (y = l - 1);
1267
- let x = i(v, _);
1268
- C(v), s?.notifyGenerationStart?.(), o?.ensureConnected(), r.streamCompletion(v, c, u, {
1269
- signal: x.signal,
1264
+ }, []), T = _((e, c, l, u, d, h, _ = F.Append) => {
1265
+ let v = h ?? crypto.randomUUID(), y = K(e);
1266
+ p.current = v, m.current = y, f(y);
1267
+ let x;
1268
+ _ === F.Regenerate ? x = l : _ === F.Edit && (x = l - 1);
1269
+ let S = i(y, v);
1270
+ C(y), s?.notifyGenerationStart?.(), o?.ensureConnected(), r.streamCompletion(y, c, u, {
1271
+ signal: S.signal,
1270
1272
  onChunk: (e) => {
1271
- p.current === _ && S(v) && t((t) => {
1273
+ p.current === v && b(y) && t((t) => {
1272
1274
  if (!t) return t;
1273
- let r = pt(t.messages, l, e);
1275
+ let r = Lt(t.messages, l, e);
1274
1276
  if (!r) return t;
1275
1277
  let i = {
1276
1278
  ...t,
@@ -1280,14 +1282,14 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1280
1282
  });
1281
1283
  },
1282
1284
  onComplete: async () => {
1283
- if (w(v), p.current === _ && (p.current = null, g.current = null, f(null)), a(v, _), b.current.has(_) ? b.current.delete(_) : s?.notifyGenerationEnd?.(), S(v)) try {
1284
- let i = await r.getConversation(Z(e));
1285
- if (!S(v)) return;
1285
+ if (w(y), p.current === v && (p.current = null, m.current = null, f(null)), a(y, v), g.current.has(v) ? g.current.delete(v) : s?.notifyGenerationEnd?.(), b(y)) try {
1286
+ let i = await r.getConversation(dt(e));
1287
+ if (!b(y)) return;
1286
1288
  t(i), n.current = i;
1287
1289
  } catch {}
1288
1290
  },
1289
1291
  onError: (e) => {
1290
- w(v), p.current === _ && (p.current = null, g.current = null, f(null)), S(v) && t((t) => {
1292
+ w(y), p.current === v && (p.current = null, m.current = null, f(null)), b(y) && t((t) => {
1291
1293
  if (!t) return t;
1292
1294
  let r = {
1293
1295
  ...t,
@@ -1299,22 +1301,22 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1299
1301
  return n.current = r, r;
1300
1302
  });
1301
1303
  }
1302
- }, d, _, h, y, o?.channelId ?? void 0);
1304
+ }, d, v, _, x, o?.channelId ?? void 0);
1303
1305
  }, [
1304
1306
  i,
1305
1307
  a,
1306
1308
  C,
1307
1309
  w,
1308
- S,
1310
+ b,
1309
1311
  o?.channelId,
1310
1312
  o?.ensureConnected,
1311
1313
  s,
1312
1314
  r
1313
- ]), D = m(() => {
1315
+ ]), E = _(() => {
1314
1316
  let t = p.current;
1315
1317
  if (!t || !e) return;
1316
- let n = Q(e);
1317
- g.current === n && (b.current.add(t), s?.notifyStopGenerating?.(), r.stopCompletion({
1318
+ let n = K(e);
1319
+ m.current === n && (g.current.add(t), s?.notifyStopGenerating?.(), r.stopCompletion({
1318
1320
  generationId: t,
1319
1321
  path: n
1320
1322
  }).catch((e) => {
@@ -1326,16 +1328,16 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1326
1328
  c,
1327
1329
  s,
1328
1330
  r
1329
- ]), O = m((e, i) => {
1330
- if (!$(i)) return;
1331
- let a = Q(e);
1332
- if (_.current.has(a)) return;
1333
- _.current.add(a), C(a);
1331
+ ]), D = _((e, i) => {
1332
+ if (!Nt(i)) return;
1333
+ let a = K(e);
1334
+ if (h.current.has(a)) return;
1335
+ h.current.add(a), C(a);
1334
1336
  let o = new AbortController(), s = (e) => {
1335
- _.current.delete(a), w(a), e && S(a) && (t(e), n.current = e);
1337
+ h.current.delete(a), w(a), e && b(a) && (t(e), n.current = e);
1336
1338
  }, c = async () => {
1337
1339
  try {
1338
- s(await r.getConversation(Z(e)));
1340
+ s(await r.getConversation(dt(e)));
1339
1341
  } catch {
1340
1342
  s();
1341
1343
  }
@@ -1350,7 +1352,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1350
1352
  }
1351
1353
  let n = t.getReader(), i = new TextDecoder(), l = "", u = window.setTimeout(() => {
1352
1354
  o.abort();
1353
- }, mt);
1355
+ }, Rt);
1354
1356
  try {
1355
1357
  for (;;) {
1356
1358
  let { done: t, value: a } = await n.read();
@@ -1368,8 +1370,8 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1368
1370
  continue;
1369
1371
  }
1370
1372
  if (a?.action === "UPDATE") try {
1371
- let t = await r.getConversation(Z(e));
1372
- if (!$(t)) {
1373
+ let t = await r.getConversation(dt(e));
1374
+ if (!Nt(t)) {
1373
1375
  s(t);
1374
1376
  return;
1375
1377
  }
@@ -1384,43 +1386,43 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1384
1386
  }, [
1385
1387
  C,
1386
1388
  w,
1387
- S,
1389
+ b,
1388
1390
  r
1389
- ]), k = e != null && l.has(Q(e)), A = e == null ? null : Q(e);
1391
+ ]), O = e != null && l.has(K(e)), k = e == null ? null : K(e);
1390
1392
  return {
1391
1393
  startStream: T,
1392
- handleStop: D,
1393
- resumeIfAwaitingGeneration: O,
1394
- isStreaming: k,
1395
- canStopStreaming: A != null && d === A
1394
+ handleStop: E,
1395
+ resumeIfAwaitingGeneration: D,
1396
+ isStreaming: O,
1397
+ canStopStreaming: k != null && d === k
1396
1398
  };
1397
- }, gt = {}, _t = (e, t = gt) => _(() => {
1398
- let n = [], r = [], a = [], o = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
1399
- for (let d of e) {
1400
- let e = d.custom_content?.attachments;
1401
- if (d.role === i.User) for (let r of e ?? []) {
1402
- let e = s(r, t);
1403
- c.has(e.id) || (c.add(e.id), n.push(e));
1399
+ }, Bt = {}, Vt = (e, t = Bt) => b(() => {
1400
+ let n = [], r = [], i = [], o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
1401
+ for (let u of e) {
1402
+ let e = u.custom_content?.attachments;
1403
+ if (u.role === a.User) for (let r of e ?? []) {
1404
+ let e = l(r, t);
1405
+ s.has(e.id) || (s.add(e.id), n.push(e));
1404
1406
  }
1405
- else if (d.role === i.Assistant) {
1406
- let n = e?.filter((e) => !u(e));
1407
+ else if (u.role === a.Assistant) {
1408
+ let n = e?.filter((e) => !p(e));
1407
1409
  for (let e of n ?? []) {
1408
- let n = s(e, t);
1409
- l.has(n.id) || (l.add(n.id), r.push(n));
1410
+ let n = l(e, t);
1411
+ c.has(n.id) || (c.add(n.id), r.push(n));
1410
1412
  }
1411
1413
  for (let t of e ?? []) {
1412
- if (!u(t)) continue;
1414
+ if (!p(t)) continue;
1413
1415
  let e = t.reference_url;
1414
- o.has(e) || (o.add(e), a.push({
1416
+ o.has(e) || (o.add(e), i.push({
1415
1417
  url: e,
1416
1418
  title: t.title ?? e,
1417
1419
  contentType: t.reference_type ?? t.type ?? "",
1418
1420
  quote: t.data
1419
1421
  }));
1420
1422
  }
1421
- for (let e of p(d)) {
1423
+ for (let e of g(u)) {
1422
1424
  let t = e?.body?.source?.attachment, n = t?.url;
1423
- !n || o.has(n) || (o.add(n), a.push({
1425
+ !n || o.has(n) || (o.add(n), i.push({
1424
1426
  url: n,
1425
1427
  title: t?.title ?? n.split("/").pop() ?? n,
1426
1428
  contentType: t?.type ?? "",
@@ -1432,9 +1434,1381 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1432
1434
  return {
1433
1435
  uploaded: n,
1434
1436
  generated: r,
1435
- sources: a
1437
+ sources: i
1438
+ };
1439
+ }, [e, t]), Ht = /* @__PURE__ */ function(e) {
1440
+ return e.Overwrite = "overwrite", e.CreateOnly = "create-only", e;
1441
+ }({}), q = /* @__PURE__ */ function(e) {
1442
+ return e.FolderLoadFailed = "folderLoadFailed", e.MetadataLoadFailed = "metadataLoadFailed", e.FolderCreateFailed = "folderCreateFailed", e.DownloadFileFailed = "downloadFileFailed", e.DownloadFilesFailed = "downloadFilesFailed", e.FilesDeleted = "filesDeleted", e.FilesDeletePartiallyFailed = "filesDeletePartiallyFailed", e.DeleteFailed = "deleteFailed", e.RenameFailed = "renameFailed", e.RenamePartiallyFailed = "renamePartiallyFailed", e.MoveFailed = "moveFailed", e.MovePartiallyFailed = "movePartiallyFailed", e.CopyFailed = "copyFailed", e.CopyPartiallyFailed = "copyPartiallyFailed", e.UnshareFailed = "unshareFailed", e.RemoveAccessFailed = "removeAccessFailed", e.UploadFailed = "uploadFailed", e.UploadCompleted = "uploadCompleted", e.UploadArchiveFailed = "uploadArchiveFailed", e.UploadArchivePartiallyFailed = "uploadArchivePartiallyFailed", e.UploadArchiveRequestFailed = "uploadArchiveRequestFailed", e;
1443
+ }({}), J = /* @__PURE__ */ function(e) {
1444
+ return e.Empty = "empty", e.ForbiddenSymbols = "forbiddenSymbols", e.ReservedName = "reservedName", e.TooLong = "tooLong", e.DuplicateName = "duplicateName", e.LeadingDot = "leadingDot", e;
1445
+ }({}), Y = /* @__PURE__ */ function(e) {
1446
+ return e.FolderCreated = "folderCreated", e.FileRenamed = "fileRenamed", e.FileDownloaded = "fileDownloaded", e.FilesDownloaded = "filesDownloaded", e.FileCopied = "fileCopied", e.FilesCopied = "filesCopied", e.FileMoved = "fileMoved", e.FilesMoved = "filesMoved", e;
1447
+ }({}), Ut = 3, Wt = r, Gt = /[/\\]/, Kt = {
1448
+ year: "numeric",
1449
+ month: "short",
1450
+ day: "2-digit"
1451
+ }, qt = [
1452
+ B.Name,
1453
+ B.UpdatedAt,
1454
+ B.Size,
1455
+ B.Actions
1456
+ ], Jt = [
1457
+ B.Name,
1458
+ B.UpdatedAt,
1459
+ B.Size,
1460
+ B.Author,
1461
+ B.Actions
1462
+ ], Yt = {
1463
+ READ: ee.READ,
1464
+ WRITE: ee.WRITE,
1465
+ SHARE: ee.SHARE
1466
+ }, Xt = /* @__PURE__ */ function(e) {
1467
+ return e.Attach = "attach", e.Standalone = "standalone", e.FolderPicker = "folder-picker", e;
1468
+ }({}), Zt = /* @__PURE__ */ function(e) {
1469
+ return e.Attach = "attach", e.Browse = "browse", e.Full = "full", e;
1470
+ }({}), Qt = (e) => {
1471
+ switch (e) {
1472
+ case "attach": return "attach";
1473
+ case "standalone": return "browse";
1474
+ case "folder-picker": return "full";
1475
+ }
1476
+ }, X = (e) => {
1477
+ try {
1478
+ return decodeURIComponent(e);
1479
+ } catch {
1480
+ return e;
1481
+ }
1482
+ }, $t = (e, t) => {
1483
+ if (Gt.test(e)) return !0;
1484
+ if (t == null) return !1;
1485
+ t.lastIndex = 0;
1486
+ let n = t.test(e);
1487
+ return t.lastIndex = 0, n;
1488
+ }, Z = (e) => e.replace(/\/+$/, "") || "/", en = (e, t) => {
1489
+ let n = e.split("/").filter(Boolean);
1490
+ return X(n[n.length - 1] ?? t);
1491
+ }, tn = (e, t) => Z(e || `/${t}`).replace(/^\/+/, "") || t, nn = (e, t) => {
1492
+ let n = Z(t);
1493
+ for (let r of e) {
1494
+ if (r.nodeType !== z.FOLDER) continue;
1495
+ if (Z(r.path) === n) return r;
1496
+ let e = nn(r.items ?? [], t);
1497
+ if (e) return e;
1498
+ }
1499
+ }, rn = (e) => e?.permissions?.includes(ee.WRITE) ?? !1, an = (e, t) => {
1500
+ for (let n of e) {
1501
+ if (n.path === t || n.id === t) return n;
1502
+ let e = an(n.items ?? [], t);
1503
+ if (e) return e;
1504
+ }
1505
+ }, on = (e) => {
1506
+ switch (e) {
1507
+ case Zt.Attach: return !1;
1508
+ case Zt.Browse:
1509
+ case Zt.Full: return !0;
1510
+ default: throw Error(`Unhandled actionProfile: ${String(e)}`);
1511
+ }
1512
+ }, sn = (e) => e === Zt.Full, cn = (e, t) => {
1513
+ let n = e.replace(/\/$/, ""), r = n.lastIndexOf("/");
1514
+ if (r <= 0) {
1515
+ let e = r === 0 ? n.slice(1) : n;
1516
+ return {
1517
+ parentVirtualPath: `/${t}`,
1518
+ name: e
1519
+ };
1520
+ }
1521
+ return {
1522
+ parentVirtualPath: n.slice(0, r),
1523
+ name: n.slice(r + 1)
1524
+ };
1525
+ }, ln = (e, t) => {
1526
+ let n = `files/${t}/`;
1527
+ return e.startsWith(n) ? e.slice(n.length) : e;
1528
+ }, un = (e, t, n) => {
1529
+ let r = e.replace(/\/+$/, "").split("/").filter(Boolean).map(X).join("/"), i = r ? `/${t}/${r}` : `/${t}`;
1530
+ return n ? `${i}/` : i;
1531
+ }, dn = (e, t, n) => {
1532
+ if (!e) return {
1533
+ bucket: n,
1534
+ path: e
1535
+ };
1536
+ let r = e.indexOf("/"), i = r === -1 ? e : e.slice(0, r), a = t.get(i);
1537
+ if (!a) return {
1538
+ bucket: n,
1539
+ path: e
1540
+ };
1541
+ let o = ln(a.dialCorePath, a.bucket), s = r === -1 ? "" : e.slice(r + 1);
1542
+ return {
1543
+ bucket: a.bucket,
1544
+ path: o + s
1545
+ };
1546
+ }, fn = (e) => e.startsWith("files/"), pn = (e, t) => {
1547
+ let n = `files/${t}/`;
1548
+ if (e.startsWith(n)) return X(e.slice(n.length));
1549
+ if (fn(e)) {
1550
+ let n = e.slice(6), r = n.indexOf("/");
1551
+ if (r >= 0) {
1552
+ let e = n.slice(0, r), i = n.slice(r + 1);
1553
+ if (e === t) return X(i);
1554
+ }
1555
+ }
1556
+ return e;
1557
+ }, Q = (e, t) => {
1558
+ let n = `/${t}`, r = `/${t}/`, i = `${t}/`;
1559
+ if (e === n || e === `${t}` || e === r || e === i) return "";
1560
+ let a;
1561
+ if (e.startsWith(r)) a = e.slice(r.length);
1562
+ else if (e.startsWith(i)) a = e.slice(i.length);
1563
+ else {
1564
+ let t = e.replace(/^\//, "");
1565
+ a = t.startsWith(i) ? t.slice(i.length) : t;
1566
+ }
1567
+ let o = a.replace(/\/{2,}/g, "/");
1568
+ return o && !o.endsWith("/") ? `${o}/` : o;
1569
+ }, mn = (e) => {
1570
+ let t = e.replace(/\/$/, ""), n = t.lastIndexOf("/");
1571
+ return n > 0 ? t.slice(0, n + 1) : "";
1572
+ }, hn = (e, t) => e.startsWith("/") || e === t || e.startsWith(`${t}/`), gn = (e, t, n) => {
1573
+ let r = e.nodeType === z.FOLDER, i = e.id ? pn(e.id, t) : null, a = i != null && !hn(i, n) ? i : Q(e.path, n);
1574
+ return r ? a.endsWith("/") ? a : `${a}/` : a.replace(/\/$/, "");
1575
+ }, _n = (e, t, n) => e.map((e) => {
1576
+ let r = e.nodeType === z.FOLDER, i = Q(e.sourceUrl, n), a = Q(e.destinationUrl, n), o = en(e.sourceUrl, i);
1577
+ return {
1578
+ destinationName: en(e.destinationUrl, a),
1579
+ dto: {
1580
+ bucket: t,
1581
+ sourcePath: r ? i.endsWith("/") ? i : `${i}/` : i.replace(/\/$/, ""),
1582
+ destinationPath: r ? a.endsWith("/") ? a : `${a}/` : a.replace(/\/$/, ""),
1583
+ overwrite: e.overwrite === !0,
1584
+ nodeType: r ? A.Folder : A.Item,
1585
+ name: o
1586
+ }
1587
+ };
1588
+ }), vn = (e, t, n) => {
1589
+ let r = e.map((e) => {
1590
+ let t = e.nodeType === z.FOLDER, r = Q(e.sourceUrl, n), i = Q(e.destinationUrl, n), a = en(e.sourceUrl, r), o = en(e.destinationUrl, i), s = t ? r.endsWith("/") ? r : `${r}/` : r.replace(/\/$/, ""), c = t ? i.endsWith("/") ? i : `${i}/` : i.replace(/\/$/, "");
1591
+ return {
1592
+ isFolder: t,
1593
+ name: a,
1594
+ destinationName: o,
1595
+ overwrite: e.overwrite === !0,
1596
+ sourcePath: s,
1597
+ destinationPath: c,
1598
+ sourceParent: mn(s),
1599
+ destinationParent: mn(c)
1600
+ };
1601
+ });
1602
+ return {
1603
+ renameDtos: r.filter((e) => e.sourceParent === e.destinationParent).map((e) => ({
1604
+ bucket: t,
1605
+ sourcePath: e.sourcePath,
1606
+ destinationPath: e.destinationPath,
1607
+ nodeType: e.isFolder ? P.Folder : P.Item,
1608
+ name: e.name
1609
+ })),
1610
+ preparedMoveItems: r.filter((e) => e.sourceParent !== e.destinationParent).map((e) => ({
1611
+ destinationName: e.destinationName,
1612
+ dto: {
1613
+ bucket: t,
1614
+ sourcePath: e.sourcePath,
1615
+ destinationPath: e.destinationPath,
1616
+ overwrite: e.overwrite,
1617
+ nodeType: e.isFolder ? N.Folder : N.Item,
1618
+ name: e.name
1619
+ }
1620
+ }))
1621
+ };
1622
+ }, yn = (e) => {
1623
+ if (!e?.length) return;
1624
+ let t = e.map((e) => Yt[e.toUpperCase()]).filter((e) => e != null);
1625
+ return t.length > 0 ? t : void 0;
1626
+ }, bn = (e, t) => {
1627
+ let n = t.find((e) => e.success);
1628
+ if (n != null) return e.find(({ dto: e }) => e.sourcePath === n.sourcePath && e.destinationPath === n.destinationPath) ?? e.find(({ dto: e }) => e.destinationPath === n.destinationPath) ?? e[0];
1629
+ }, xn = (e, t, n, r, i) => {
1630
+ let a = e.get(n);
1631
+ if (a == null) return [];
1632
+ let o = r.replace(/\/$/, "");
1633
+ return a.map((a) => {
1634
+ let s = a.nodeType === M.Folder, c = X(a.name), l = s ? `${o}/${c}/` : `${o}/${c}`, u = {
1635
+ id: a.path,
1636
+ name: c,
1637
+ path: l,
1638
+ url: a.url,
1639
+ parentPath: r,
1640
+ nodeType: s ? z.FOLDER : z.ITEM,
1641
+ folderId: i,
1642
+ bucket: a.bucket,
1643
+ author: a.author,
1644
+ resourceType: a.resourceType,
1645
+ contentLength: a.contentLength,
1646
+ contentType: a.contentType,
1647
+ updatedAt: a.updatedAt ? new Date(a.updatedAt).toISOString() : void 0
1648
+ };
1649
+ if (s) {
1650
+ let r = `${n}${c}/`;
1651
+ u.permissions = yn(a.permissions) ?? yn(t.get(r)), u.items = xn(e, t, r, l, a.path);
1652
+ }
1653
+ return u;
1654
+ });
1655
+ }, Sn = (e, t, n, r) => {
1656
+ let i = new Map(e), a = [...i.get(t) ?? []], o = {
1657
+ name: n.name,
1658
+ path: n.path,
1659
+ folderId: n.folderId,
1660
+ nodeType: M.Folder,
1661
+ bucket: n.bucket,
1662
+ parentPath: n.parentPath || void 0,
1663
+ url: n.path,
1664
+ permissions: r
1665
+ };
1666
+ return a.some((e) => e.name.toLowerCase() === n.name.toLowerCase()) || a.push(o), i.set(t, a), i;
1667
+ }, Cn = (e, t, n) => {
1668
+ if (!e) return e;
1669
+ let r = typeof n == "string" ? { status: n } : n, i = e.files.map((e, n) => n === t ? {
1670
+ ...e,
1671
+ ...r
1672
+ } : e);
1673
+ return {
1674
+ ...e,
1675
+ files: i
1676
+ };
1677
+ }, wn = (e, t, n, r, i) => {
1678
+ if (t === R.Shared) {
1679
+ if (r === "") return e.listSharedFiles({ path: void 0 }).then((e) => ({ items: e.items }));
1680
+ let t = r.indexOf("/"), n = t === -1 ? r : r.slice(0, t), a = i.get(n);
1681
+ if (a) {
1682
+ let n = ln(a.dialCorePath, a.bucket) + (t === -1 ? "" : r.slice(t + 1));
1683
+ return e.listFiles({
1684
+ bucket: a.bucket,
1685
+ path: n,
1686
+ permissions: !0
1687
+ }).then((e) => ({
1688
+ items: e.items,
1689
+ permissions: e.permissions
1690
+ }));
1691
+ }
1692
+ return Promise.resolve({ items: [] });
1693
+ }
1694
+ return t === R.Organization ? e.listPublicFiles({ path: r || void 0 }).then((e) => ({ items: e.items })) : e.listFiles({
1695
+ bucket: n,
1696
+ path: r,
1697
+ permissions: !0
1698
+ }).then((e) => ({
1699
+ items: e.items,
1700
+ permissions: e.permissions
1701
+ }));
1702
+ }, Tn = async (e, t, n, r, i) => {
1703
+ if (t === R.Shared) {
1704
+ let t = r.indexOf("/"), n = t === -1 ? r : r.slice(0, t), a = i.get(n);
1705
+ if (!a) return { items: [] };
1706
+ let o = ln(a.dialCorePath, a.bucket) + (t === -1 ? "" : r.slice(t + 1)), { items: s } = await e.listFiles({
1707
+ bucket: a.bucket,
1708
+ path: o,
1709
+ permissions: !0,
1710
+ recursive: !0
1711
+ });
1712
+ return { items: s };
1713
+ }
1714
+ if (t === R.Organization) {
1715
+ let { items: t } = await e.listPublicFiles({
1716
+ path: r || void 0,
1717
+ recursive: !0
1718
+ });
1719
+ return { items: t };
1720
+ }
1721
+ let { items: a } = await e.listFiles({
1722
+ bucket: n,
1723
+ path: r,
1724
+ permissions: !0,
1725
+ recursive: !0
1726
+ });
1727
+ return { items: a };
1728
+ }, En = (e, t, n) => {
1729
+ let r = e.nodeType === M.Folder, i = X(e.name), a = e.bucket ?? t, o = ln(e.url ?? e.path ?? "", a).replace(/\/$/, ""), s = o.lastIndexOf("/"), c = s > 0 ? o.slice(0, s) : "", l = c ? `/${n}/${c}` : `/${n}`, u = r ? `${l}/${i}/` : `${l}/${i}`;
1730
+ return {
1731
+ id: e.path,
1732
+ name: i,
1733
+ path: u,
1734
+ url: e.url,
1735
+ parentPath: l,
1736
+ nodeType: r ? z.FOLDER : z.ITEM,
1737
+ folderId: e.folderId,
1738
+ bucket: a,
1739
+ author: e.author,
1740
+ contentLength: e.contentLength,
1741
+ contentType: e.contentType,
1742
+ updatedAt: e.updatedAt ? new Date(e.updatedAt).toISOString() : void 0
1743
+ };
1744
+ }, Dn = (e, t) => ({
1745
+ ...t,
1746
+ bucket: e.bucket ?? t.bucket,
1747
+ author: e.author,
1748
+ contentLength: e.contentLength,
1749
+ contentType: e.contentType,
1750
+ resourceType: e.resourceType ?? t.resourceType,
1751
+ permissions: yn(e.permissions) ?? t.permissions,
1752
+ updatedAt: e.updatedAt ? new Date(e.updatedAt).toISOString() : t.updatedAt,
1753
+ createdAt: e.createdAt ? new Date(e.createdAt).toISOString() : t.createdAt
1754
+ }), On = /* @__PURE__ */ function(e) {
1755
+ return e.Blob = "blob", e.Stream = "stream", e.Cancelled = "cancelled", e;
1756
+ }({}), kn = (e) => {
1757
+ let t = e.lastIndexOf("."), n = t > 0;
1758
+ return {
1759
+ base: n ? e.slice(0, t) : e,
1760
+ extension: n ? e.slice(t) : ""
1761
+ };
1762
+ }, An = (e, t = 255) => {
1763
+ if (c(e) <= t) return e;
1764
+ let { base: n, extension: r } = kn(e), i = t - c(r);
1765
+ return i <= 0 ? f(e, t) : `${f(n, i)}${r}`;
1766
+ }, jn = (e) => {
1767
+ let { base: t, extension: n } = kn(e), r = t.replace(new RegExp(ne.source, "g"), "_").replace(/[.\s]+$/, "");
1768
+ return r === "" ? e : An(`${r}${n}`);
1769
+ }, $ = /* @__PURE__ */ function(e) {
1770
+ return e.Queued = "queued", e.Uploading = "uploading", e.Completed = "completed", e.Failed = "failed", e.Cancelled = "cancelled", e;
1771
+ }({}), Mn = ({ filesApi: e, bucket: t, rootLabel: n, activeTab: r, onNotification: i }) => {
1772
+ let [a, o] = S(""), [s, c] = S(() => /* @__PURE__ */ new Map()), l = x(s);
1773
+ v(() => {
1774
+ l.current = s;
1775
+ }, [s]);
1776
+ let [u, d] = S(() => /* @__PURE__ */ new Map()), [f, p] = S(!0), [m, h] = S(null), [g, y] = S(0), [C, w] = S(void 0), [T, E] = S(() => /* @__PURE__ */ new Set()), D = x(/* @__PURE__ */ new Map()), [O, k] = S(!1), [A, j] = S(null), N = x(null), P = x(null), F = x(/* @__PURE__ */ new Set()), I = x(/* @__PURE__ */ new Set()), [L, ee] = S(() => /* @__PURE__ */ new Set()), [B, te] = S(() => /* @__PURE__ */ new Set()), ne = x(r);
1777
+ v(() => {
1778
+ ne.current !== r && (ne.current = r, c(/* @__PURE__ */ new Map()), d(/* @__PURE__ */ new Map()), o(""), w(void 0), D.current = /* @__PURE__ */ new Map(), F.current = /* @__PURE__ */ new Set(), I.current = /* @__PURE__ */ new Set(), te(/* @__PURE__ */ new Set()), N.current != null && (clearTimeout(N.current), N.current = null), P.current?.(), P.current = null, j(null), k(!1), ee(/* @__PURE__ */ new Set()));
1779
+ }, [r]), v(() => () => {
1780
+ N.current != null && clearTimeout(N.current), P.current?.();
1781
+ }, []), v(() => {
1782
+ let i = !1;
1783
+ return p(!0), h(null), wn(e, r, t, a, D.current).then(({ items: e, permissions: t }) => {
1784
+ i || (c((t) => {
1785
+ let n = new Map(t);
1786
+ return n.set(a, e), n;
1787
+ }), d((e) => new Map(e).set(a, t)), r === R.Shared && a === "" && (w(e.map((e) => un(ln(e.path, e.bucket ?? ""), n, e.nodeType === M.Folder))), D.current = new Map(e.map((e) => [X(e.name), {
1788
+ bucket: e.bucket ?? "",
1789
+ dialCorePath: e.path
1790
+ }]))));
1791
+ }).catch(() => {
1792
+ i || h("dialFileManager.error");
1793
+ }).finally(() => {
1794
+ i || p(!1);
1795
+ }), () => {
1796
+ i = !0;
1797
+ };
1798
+ }, [
1799
+ r,
1800
+ t,
1801
+ e,
1802
+ a,
1803
+ g,
1804
+ n
1805
+ ]), v(() => {
1806
+ if (r !== R.MyFiles) {
1807
+ E(/* @__PURE__ */ new Set());
1808
+ return;
1809
+ }
1810
+ let i = !1;
1811
+ return e.listSharedByMe(t).then((e) => {
1812
+ i || E(new Set(e.items.map((e) => un(ln(e.path, t), n, e.nodeType === M.Folder))));
1813
+ }).catch(() => {
1814
+ i || E(/* @__PURE__ */ new Set());
1815
+ }), () => {
1816
+ i = !0;
1817
+ };
1818
+ }, [
1819
+ r,
1820
+ t,
1821
+ e,
1822
+ g,
1823
+ n
1824
+ ]);
1825
+ let re = b(() => [{
1826
+ id: t,
1827
+ name: n,
1828
+ path: `/${n}`,
1829
+ parentPath: "",
1830
+ nodeType: z.FOLDER,
1831
+ folderId: t,
1832
+ permissions: yn(u.get("")),
1833
+ items: xn(s, u, "", `/${n}`, t)
1834
+ }], [
1835
+ s,
1836
+ u,
1837
+ n,
1838
+ t
1839
+ ]), H = _((e) => {
1840
+ if (e == null) {
1841
+ o("");
1842
+ return;
1843
+ }
1844
+ let t = `/${n}/`, r = `${n}/`;
1845
+ if (e === `/${n}` || e === t || e === n || e === r) {
1846
+ o("");
1847
+ return;
1848
+ }
1849
+ let i;
1850
+ if (e.startsWith(t)) i = e.slice(t.length);
1851
+ else if (e.startsWith(r)) i = e.slice(r.length);
1852
+ else {
1853
+ let t = e.replace(/^\//, "");
1854
+ i = t.startsWith(r) ? t.slice(r.length) : t;
1855
+ }
1856
+ o(i && !i.endsWith("/") ? `${i}/` : i);
1857
+ }, [n]), ie = _(() => {
1858
+ y((e) => e + 1);
1859
+ }, []), ae = ie, oe = _((o) => {
1860
+ if (o.length === 0) return;
1861
+ let s = new Set([...L].map((e) => Q(e, n))), l = (e) => e === a || a.startsWith(e) || s.has(e), u = o.filter((e) => !l(e)), f = o.filter((e) => l(e) && e !== a);
1862
+ u.length > 0 && (c((e) => {
1863
+ let t = new Map(e);
1864
+ return u.forEach((e) => t.delete(e)), t;
1865
+ }), d((e) => {
1866
+ let t = new Map(e);
1867
+ return u.forEach((e) => t.delete(e)), t;
1868
+ })), f.forEach((n) => {
1869
+ (async () => {
1870
+ try {
1871
+ let { items: i, permissions: a } = await wn(e, r, t, n, D.current);
1872
+ c((e) => new Map(e).set(n, i)), a != null && d((e) => new Map(e).set(n, a));
1873
+ } catch {
1874
+ i?.({
1875
+ variant: V.Error,
1876
+ reason: q.FolderLoadFailed
1877
+ });
1878
+ }
1879
+ })();
1880
+ });
1881
+ }, [
1882
+ r,
1883
+ t,
1884
+ e,
1885
+ a,
1886
+ L,
1887
+ n,
1888
+ i
1889
+ ]), se = _((e, t, n) => {
1890
+ c((r) => Sn(r, e, t, n));
1891
+ }, []), ce = _((a) => {
1892
+ let o = a == null ? "" : Q(a, n), s = a == null ? `/${n}` : Z(a);
1893
+ if (!l.current.has(o)) {
1894
+ if (F.current.has(o)) {
1895
+ te((e) => {
1896
+ let t = new Set(e);
1897
+ return t.add(s), t;
1898
+ });
1899
+ return;
1900
+ }
1901
+ F.current.add(o), te((e) => {
1902
+ let t = new Set(e);
1903
+ return t.add(s), t;
1904
+ }), (async () => {
1905
+ try {
1906
+ let { items: n, permissions: i } = await wn(e, r, t, o, D.current);
1907
+ c((e) => new Map(e).set(o, n)), i != null && d((e) => new Map(e).set(o, i)), I.current.delete(o);
1908
+ } catch {
1909
+ i?.({
1910
+ variant: V.Error,
1911
+ reason: q.FolderLoadFailed
1912
+ });
1913
+ } finally {
1914
+ F.current.delete(o), te((e) => {
1915
+ let t = new Set(e);
1916
+ return t.delete(s), t;
1917
+ });
1918
+ }
1919
+ })();
1920
+ }
1921
+ }, [
1922
+ r,
1923
+ t,
1924
+ e,
1925
+ i,
1926
+ n
1927
+ ]), le = b(() => {
1928
+ let e = /* @__PURE__ */ new Set();
1929
+ for (let t of L) {
1930
+ let r = Q(t, n);
1931
+ s.has(r) && e.add(t);
1932
+ }
1933
+ return e;
1934
+ }, [
1935
+ L,
1936
+ s,
1937
+ n
1938
+ ]), ue = _((a) => {
1939
+ L.forEach((e) => {
1940
+ a.has(e) || I.current.delete(Q(e, n));
1941
+ }), ee(a), [...a].filter((e) => {
1942
+ let t = Q(e, n);
1943
+ return !l.current.has(t) && !F.current.has(t) && !I.current.has(t);
1944
+ }).forEach((a) => {
1945
+ let o = Q(a, n);
1946
+ F.current.add(o), (async () => {
1947
+ try {
1948
+ let { items: n, permissions: i } = await wn(e, r, t, o, D.current);
1949
+ c((e) => new Map(e).set(o, n)), i != null && d((e) => new Map(e).set(o, i));
1950
+ } catch {
1951
+ I.current.add(o), i?.({
1952
+ variant: V.Error,
1953
+ reason: q.FolderLoadFailed
1954
+ });
1955
+ } finally {
1956
+ F.current.delete(o), te((e) => {
1957
+ let t = new Set(e);
1958
+ return t.delete(Z(a)), t;
1959
+ });
1960
+ }
1961
+ })();
1962
+ });
1963
+ }, [
1964
+ r,
1965
+ t,
1966
+ e,
1967
+ L,
1968
+ i,
1969
+ n
1970
+ ]), de = _(() => {
1971
+ N.current != null && (clearTimeout(N.current), N.current = null), P.current?.(), P.current = null, j(null), k(!1);
1972
+ }, []), fe = _((i, o) => {
1973
+ if (N.current != null && (clearTimeout(N.current), N.current = null), P.current?.(), P.current = null, !o.trim()) {
1974
+ j(null), k(!1);
1975
+ return;
1976
+ }
1977
+ N.current = setTimeout(() => {
1978
+ N.current = null;
1979
+ let i = o.toLowerCase();
1980
+ if (r === R.Shared && a === "") {
1981
+ P.current?.(), P.current = null, k(!0), j((s.get("") ?? []).filter((e) => X(e.name).toLowerCase().includes(i)).map((e) => En(e, e.bucket ?? t, n))), k(!1);
1982
+ return;
1983
+ }
1984
+ let c = !1;
1985
+ P.current = () => {
1986
+ c = !0;
1987
+ }, k(!0), (async () => {
1988
+ try {
1989
+ let { items: o } = await Tn(e, r, t, a, D.current);
1990
+ if (c) return;
1991
+ j(o.filter((e) => X(e.name).toLowerCase().includes(i)).map((e) => En(e, e.bucket ?? t, n)));
1992
+ } catch {
1993
+ c || j([]);
1994
+ } finally {
1995
+ c || k(!1);
1996
+ }
1997
+ })();
1998
+ }, 300);
1999
+ }, [
2000
+ r,
2001
+ t,
2002
+ s,
2003
+ e,
2004
+ a,
2005
+ n
2006
+ ]), pe = a ? `/${n}/${a}` : `/${n}`, me = b(() => {
2007
+ let e = re[0];
2008
+ if (e) return Z(pe) === Z(`/${n}`) ? e : nn(e.items ?? [], pe);
2009
+ }, [
2010
+ re,
2011
+ pe,
2012
+ n
2013
+ ]);
2014
+ return {
2015
+ items: re,
2016
+ isLoading: f,
2017
+ error: m,
2018
+ path: pe,
2019
+ folderPath: a,
2020
+ onPathChange: H,
2021
+ retry: ie,
2022
+ onSearchFiles: fe,
2023
+ isSearching: O,
2024
+ searchResults: A,
2025
+ clearSearchResults: de,
2026
+ expandedPaths: L,
2027
+ loadedPaths: le,
2028
+ onExpandedPathsChange: ue,
2029
+ onFolderPopupPathChange: ce,
2030
+ folderPopupLoadingPaths: B,
2031
+ sharedWithMeIds: b(() => r === R.Shared ? C : void 0, [r, C]),
2032
+ sharedByMePaths: T,
2033
+ currentFolder: me,
2034
+ cache: s,
2035
+ listingPermissionsCache: u,
2036
+ sharedRootMetaRef: D,
2037
+ setFolderPath: o,
2038
+ invalidateFolders: oe,
2039
+ mergeCreatedFolder: se,
2040
+ bumpRetry: ae
2041
+ };
2042
+ }, Nn = ({ filesApi: e, bucket: t, rootLabel: n, onNotification: r }) => {
2043
+ let [i, a] = S(void 0), [o, s] = S(!1);
2044
+ return {
2045
+ fileMetadata: i,
2046
+ isFileMetadataLoading: o,
2047
+ onGetInfo: _((i) => {
2048
+ (async () => {
2049
+ s(!0);
2050
+ try {
2051
+ let r = i.bucket ?? t, o = gn(i, r, n);
2052
+ a(Dn(await e.getFileMetadata({
2053
+ bucket: r,
2054
+ path: o
2055
+ }), i));
2056
+ } catch {
2057
+ r?.({
2058
+ variant: V.Error,
2059
+ reason: q.MetadataLoadFailed
2060
+ });
2061
+ } finally {
2062
+ s(!1);
2063
+ }
2064
+ })();
2065
+ }, [
2066
+ t,
2067
+ e,
2068
+ n,
2069
+ r
2070
+ ]),
2071
+ clearMetadata: _(() => {
2072
+ a(void 0), s(!1);
2073
+ }, [])
2074
+ };
2075
+ }, Pn = ({ filesApi: e, bucket: t, rootLabel: n, activeTab: r, folderPath: i, currentFolder: a, sharedRootMetaRef: o, listingPermissionsCache: s, invalidateFolders: c, bumpRetry: l, mergeCreatedFolder: u, setFolderPath: d, onNotification: f, onOperationSuccess: p, downloadDestination: m, forbiddenSymbolsRegExp: h }) => {
2076
+ let [g, v] = S(!1), [y, b] = S(!1), [C, w] = S(!1), [T, E] = S(!1), [D, O] = S(!1), [A, M] = S(!1), N = x(null), F = x(null), I = _((e, t) => {
2077
+ let n = null;
2078
+ if (!e || e.trim() === "") n = { reason: J.Empty };
2079
+ else if ($t(e, h)) n = {
2080
+ reason: J.ForbiddenSymbols,
2081
+ symbols: te
2082
+ };
2083
+ else if (e.startsWith(".")) n = { reason: J.LeadingDot };
2084
+ else if (e === Wt) n = { reason: J.ReservedName };
2085
+ else if (e.length > 255) n = {
2086
+ reason: J.TooLong,
2087
+ maxLength: 255
2088
+ };
2089
+ else {
2090
+ let r = t.items ?? [], i = e.toLowerCase(), a = r.find((e) => e.name.toLowerCase() === i);
2091
+ a && (n = {
2092
+ reason: J.DuplicateName,
2093
+ existingName: a.name
2094
+ });
2095
+ }
2096
+ return F.current = n, n;
2097
+ }, [h]), L = _(async (c, d, m) => {
2098
+ let { parentVirtualPath: h, name: g } = cn(d, n), _ = Q(h, n), y = a && i === _ ? a : {
2099
+ id: _,
2100
+ path: _,
2101
+ name: h.split("/").filter(Boolean).pop() ?? "",
2102
+ folderId: _,
2103
+ nodeType: z.FOLDER,
2104
+ items: []
2105
+ }, b = F.current;
2106
+ if (F.current = null, I(g, y) || b) return;
2107
+ v(!0);
2108
+ let { bucket: x, path: S } = r === R.Shared ? dn(_, o.current, t) : {
2109
+ bucket: t,
2110
+ path: _
2111
+ };
2112
+ try {
2113
+ u(_, await e.createFolder({
2114
+ bucket: x,
2115
+ parentPath: S || void 0,
2116
+ name: g
2117
+ }), s.get(_)), l(), p?.({
2118
+ kind: Y.FolderCreated,
2119
+ name: g
2120
+ });
2121
+ } catch {
2122
+ f?.({
2123
+ variant: V.Error,
2124
+ reason: q.FolderCreateFailed
2125
+ });
2126
+ } finally {
2127
+ v(!1);
2128
+ }
2129
+ }, [
2130
+ r,
2131
+ t,
2132
+ a,
2133
+ e,
2134
+ i,
2135
+ I,
2136
+ n,
2137
+ s,
2138
+ u,
2139
+ l,
2140
+ p,
2141
+ o,
2142
+ f
2143
+ ]), ee = _((r) => {
2144
+ (async () => {
2145
+ b(!0);
2146
+ try {
2147
+ let i = r.length === 1 ? r[0].nodeType === z.ITEM ? r[0].name : `${r[0].name}.zip` : "files.zip", a = await m.resolveDestination(i, r.length === 1 && r[0].nodeType === z.ITEM ? r[0].contentType ?? "application/octet-stream" : "application/zip");
2148
+ if (a.type === On.Cancelled) return;
2149
+ if (r.length === 1 && r[0].nodeType === z.ITEM) {
2150
+ let t = r[0];
2151
+ if (!t.bucket) throw Error("File is missing bucket");
2152
+ let i = gn(t, t.bucket, n), o = await e.downloadFile(t.bucket, i);
2153
+ if (!o.ok) throw Error(`Download failed with status ${o.status}`);
2154
+ let s = await m.triggerDownload(o, t.name, a);
2155
+ p?.({
2156
+ kind: Y.FileDownloaded,
2157
+ name: s,
2158
+ count: 1
2159
+ });
2160
+ } else {
2161
+ let o = r.map((e) => ({
2162
+ bucket: e.bucket ?? t,
2163
+ path: gn(e, e.bucket ?? t, n),
2164
+ name: e.name,
2165
+ nodeType: e.nodeType === z.FOLDER ? k.Folder : k.Item
2166
+ })), s = await e.downloadArchive(o);
2167
+ if (!s.ok) throw Error(`Download failed with status ${s.status}`);
2168
+ let c = await m.triggerDownload(s, i, a);
2169
+ r.length === 1 ? p?.({
2170
+ kind: Y.FileDownloaded,
2171
+ name: c
2172
+ }) : p?.({
2173
+ kind: Y.FilesDownloaded,
2174
+ count: r.length
2175
+ });
2176
+ }
2177
+ } catch {
2178
+ f?.({
2179
+ variant: V.Error,
2180
+ reason: r.length === 1 ? q.DownloadFileFailed : q.DownloadFilesFailed
2181
+ });
2182
+ } finally {
2183
+ b(!1);
2184
+ }
2185
+ })();
2186
+ }, [
2187
+ t,
2188
+ n,
2189
+ p,
2190
+ f,
2191
+ e,
2192
+ m
2193
+ ]), B = _((a, s) => {
2194
+ a.length !== 0 && (async () => {
2195
+ w(!0);
2196
+ let u = a.map((e) => {
2197
+ let i = e.nodeType === z.FOLDER, a = Q(e.sourceUrl, n), s = i ? a : a.replace(/\/$/, ""), c = en(e.sourceUrl, s), { bucket: l, path: u } = r === R.Shared ? dn(s, o.current, t) : {
2198
+ bucket: t,
2199
+ path: s
2200
+ };
2201
+ return {
2202
+ bucket: l,
2203
+ path: u,
2204
+ name: c,
2205
+ nodeType: i ? j.Folder : j.Item
2206
+ };
2207
+ });
2208
+ try {
2209
+ let { results: t } = await e.deleteFiles(u), r = t.filter((e) => !e.success), i = r.length, a = t.length - i, o = t.find((e) => e.success), c = u.find((e) => e.path === o?.path) ?? u[0];
2210
+ if (a > 0 && f?.({
2211
+ variant: V.Success,
2212
+ reason: q.FilesDeleted,
2213
+ count: a,
2214
+ name: c?.name,
2215
+ folder: s || n
2216
+ }), i > 0) {
2217
+ let e = r.slice(0, 3).map((e) => u.find((t) => t.path === e.path)?.name ?? e.path), t = i - e.length;
2218
+ f?.({
2219
+ variant: V.Error,
2220
+ reason: q.FilesDeletePartiallyFailed,
2221
+ names: e,
2222
+ restCount: t
2223
+ });
2224
+ }
2225
+ } catch {
2226
+ f?.({
2227
+ variant: V.Error,
2228
+ reason: q.DeleteFailed
2229
+ });
2230
+ }
2231
+ let p = u.filter((e) => e.nodeType === j.Folder).map((e) => e.path.endsWith("/") ? e.path : `${e.path}/`);
2232
+ c([...new Set(u.map((e) => {
2233
+ if (e.nodeType === j.Folder) return e.path.endsWith("/") ? e.path : `${e.path}/`;
2234
+ let t = e.path.lastIndexOf("/");
2235
+ return t > 0 ? e.path.slice(0, t + 1) : "";
2236
+ }))]), p.some((e) => i === e || i.startsWith(e)) && d((e) => e.replace(/[^/]+\/$/, "")), l(), w(!1);
2237
+ })();
2238
+ }, [
2239
+ r,
2240
+ t,
2241
+ n,
2242
+ i,
2243
+ f,
2244
+ e,
2245
+ o,
2246
+ c,
2247
+ l,
2248
+ d
2249
+ ]), ne = _((e, t) => {
2250
+ if (!e || e.trim() === "") return { reason: J.Empty };
2251
+ if (e === Wt) return { reason: J.ReservedName };
2252
+ if ($t(e, h)) return {
2253
+ reason: J.ForbiddenSymbols,
2254
+ symbols: te
2255
+ };
2256
+ if (e.length > 255) return {
2257
+ reason: J.TooLong,
2258
+ maxLength: 255
2259
+ };
2260
+ let n = a?.items ?? [], r = e.toLowerCase(), i = n.find((e) => e.path !== t.path && e.name.toLowerCase() === r);
2261
+ return i ? {
2262
+ reason: J.DuplicateName,
2263
+ existingName: i.name
2264
+ } : null;
2265
+ }, [h, a]), re = _((r, i) => {
2266
+ if (r.length === 0 || D || A) return;
2267
+ let a = new AbortController();
2268
+ N.current = a, (async () => {
2269
+ O(!0);
2270
+ let o = _n(r, t, n), s = o.map(({ dto: e }) => e);
2271
+ try {
2272
+ let { results: t } = await e.copyFiles(s, a.signal), r = t.filter((e) => !e.success).length, c = t.length - r;
2273
+ if (c > 0) {
2274
+ let e = bn(o, t);
2275
+ p?.({
2276
+ kind: c === 1 ? Y.FileCopied : Y.FilesCopied,
2277
+ name: e?.destinationName,
2278
+ count: c,
2279
+ destinationFolderName: tn(i, n)
2280
+ });
2281
+ }
2282
+ r > 0 && r < t.length ? f?.({
2283
+ variant: V.Error,
2284
+ reason: q.CopyPartiallyFailed,
2285
+ count: r
2286
+ }) : r === t.length && f?.({
2287
+ variant: V.Error,
2288
+ reason: q.CopyFailed
2289
+ });
2290
+ } catch {
2291
+ a.signal.aborted || f?.({
2292
+ variant: V.Error,
2293
+ reason: q.CopyFailed
2294
+ });
2295
+ } finally {
2296
+ c([...new Set(s.flatMap((e) => [mn(e.sourcePath), mn(e.destinationPath)]))]), l(), O(!1), N.current = null;
2297
+ }
2298
+ })();
2299
+ }, [
2300
+ t,
2301
+ n,
2302
+ f,
2303
+ p,
2304
+ e,
2305
+ D,
2306
+ A,
2307
+ c,
2308
+ l
2309
+ ]), H = _(() => {
2310
+ N.current?.abort();
2311
+ }, []);
2312
+ return {
2313
+ isCreatingFolder: g,
2314
+ isDownloading: y,
2315
+ isDeleting: C,
2316
+ isRenaming: T,
2317
+ isCopying: D,
2318
+ isMoving: A,
2319
+ onCreateFolder: L,
2320
+ onCreateFolderValidate: I,
2321
+ onDownloadFiles: ee,
2322
+ onDeleteFiles: B,
2323
+ onRenameValidate: ne,
2324
+ onMoveToFiles: _((r, a, o) => {
2325
+ if (r.length === 0 || D || A || T) return;
2326
+ let { renameDtos: s, preparedMoveItems: u } = vn(r, t, n), m = u.map(({ dto: e }) => e), h = new AbortController();
2327
+ m.length > 0 && (N.current = h), (async () => {
2328
+ s.length > 0 && E(!0), m.length > 0 && M(!0);
2329
+ let [t, r] = await Promise.all([(async () => {
2330
+ if (s.length === 0) return {
2331
+ results: [],
2332
+ threw: !1
2333
+ };
2334
+ try {
2335
+ let { results: t } = await e.renameFiles(s);
2336
+ return {
2337
+ results: t,
2338
+ threw: !1
2339
+ };
2340
+ } catch {
2341
+ return {
2342
+ results: [],
2343
+ threw: !0
2344
+ };
2345
+ }
2346
+ })(), (async () => {
2347
+ if (m.length === 0) return {
2348
+ results: [],
2349
+ threw: !1,
2350
+ aborted: !1
2351
+ };
2352
+ try {
2353
+ let { results: t } = await e.moveFiles(m, h.signal);
2354
+ return {
2355
+ results: t,
2356
+ threw: !1,
2357
+ aborted: !1
2358
+ };
2359
+ } catch {
2360
+ return {
2361
+ results: [],
2362
+ threw: !0,
2363
+ aborted: h.signal.aborted
2364
+ };
2365
+ }
2366
+ })()]), a = t.threw ? s.length : t.results.filter((e) => !e.success).length, g = r.threw && r.aborted, _ = g ? 0 : m.length, v = g ? 0 : r.threw ? m.length : r.results.filter((e) => !e.success).length, y = r.threw ? 0 : r.results.filter((e) => e.success).length, b = s.length + _, x = a + v, S = v > 0;
2367
+ if (y > 0) {
2368
+ let e = bn(u, r.results);
2369
+ p?.({
2370
+ kind: y === 1 ? Y.FileMoved : Y.FilesMoved,
2371
+ name: e?.destinationName,
2372
+ count: y,
2373
+ destinationFolderName: tn(o, n)
2374
+ });
2375
+ }
2376
+ if (s.length === 1 && a === 0) {
2377
+ let [e] = s;
2378
+ p?.({
2379
+ kind: Y.FileRenamed,
2380
+ name: en(e.destinationPath, e.destinationPath),
2381
+ isFolder: e.nodeType === P.Folder
2382
+ });
2383
+ }
2384
+ x > 0 && (x === b ? f?.({
2385
+ variant: V.Error,
2386
+ reason: S ? q.MoveFailed : q.RenameFailed
2387
+ }) : f?.({
2388
+ variant: V.Error,
2389
+ reason: S ? q.MovePartiallyFailed : q.RenamePartiallyFailed,
2390
+ count: x
2391
+ }));
2392
+ let C = s.find((e) => e.nodeType === P.Folder && t.results.some((t) => t.success && t.sourcePath === e.sourcePath));
2393
+ if (C != null) {
2394
+ let e = C.sourcePath.endsWith("/") ? C.sourcePath : `${C.sourcePath}/`;
2395
+ if (i === e || i.startsWith(e)) {
2396
+ let t = C.destinationPath.endsWith("/") ? C.destinationPath : `${C.destinationPath}/`;
2397
+ d(i.replace(e, t));
2398
+ }
2399
+ }
2400
+ c([...new Set([...s, ...m].flatMap((e) => [mn(e.sourcePath), mn(e.destinationPath)]))]), l(), E(!1), M(!1), m.length > 0 && (N.current = null);
2401
+ })();
2402
+ }, [
2403
+ t,
2404
+ n,
2405
+ i,
2406
+ p,
2407
+ f,
2408
+ e,
2409
+ D,
2410
+ A,
2411
+ T,
2412
+ c,
2413
+ l,
2414
+ d
2415
+ ]),
2416
+ onCopyFiles: re,
2417
+ cancelCopyMove: H
2418
+ };
2419
+ }, Fn = ({ filesApi: e, bucket: t, rootLabel: n, bumpRetry: r, onNotification: i }) => {
2420
+ let [a, o] = S(!1), [s, c] = S(!1);
2421
+ return {
2422
+ isUnsharing: a,
2423
+ isRemovingAccess: s,
2424
+ onUnshareFiles: _((a) => {
2425
+ a.length !== 0 && (async () => {
2426
+ o(!0);
2427
+ let s = a.map((e) => {
2428
+ let r = e.bucket ?? t;
2429
+ return {
2430
+ bucket: r,
2431
+ path: gn(e, r, n)
2432
+ };
2433
+ });
2434
+ try {
2435
+ await e.discardShared(s), r();
2436
+ } catch {
2437
+ i?.({
2438
+ variant: V.Error,
2439
+ reason: q.UnshareFailed
2440
+ });
2441
+ } finally {
2442
+ o(!1);
2443
+ }
2444
+ })();
2445
+ }, [
2446
+ t,
2447
+ n,
2448
+ i,
2449
+ e,
2450
+ r
2451
+ ]),
2452
+ onRemoveFilesAccess: _((a) => {
2453
+ a.length !== 0 && (async () => {
2454
+ c(!0);
2455
+ let o = a.map((e) => {
2456
+ let r = e.bucket ?? t;
2457
+ return {
2458
+ bucket: r,
2459
+ path: gn(e, r, n)
2460
+ };
2461
+ });
2462
+ try {
2463
+ await e.revokeAccess(o), r();
2464
+ } catch {
2465
+ i?.({
2466
+ variant: V.Error,
2467
+ reason: q.RemoveAccessFailed
2468
+ });
2469
+ } finally {
2470
+ c(!1);
2471
+ }
2472
+ })();
2473
+ }, [
2474
+ t,
2475
+ n,
2476
+ i,
2477
+ e,
2478
+ r
2479
+ ])
2480
+ };
2481
+ }, In = 5, Ln = (e) => e.error ? `${e.path} (${e.error})` : e.path, Rn = (e) => {
2482
+ let t = e.slice(0, In);
2483
+ return {
2484
+ names: t.map(Ln),
2485
+ restCount: e.length - t.length
2486
+ };
2487
+ }, zn = (e, t) => `${e}${t}/`, Bn = (e) => /\.zip$/i.test(e), Vn = (e) => {
2488
+ let [t] = e;
2489
+ if (!(e.length !== 1 || t == null)) return Bn(t.fileContent.name) && !Bn(t.name) ? t : void 0;
2490
+ }, Hn = ({ filesApi: e, bucket: t, rootLabel: n, activeTab: r, cache: i, sharedRootMetaRef: a, invalidateFolders: o, bumpRetry: s, onNotification: c }) => {
2491
+ let [l, u] = S(null), d = x(null), f = _((r, i, a) => {
2492
+ let l = Q(a, n);
2493
+ u({
2494
+ files: [{
2495
+ id: `${Date.now()}-archive`,
2496
+ name: i,
2497
+ status: $.Uploading
2498
+ }],
2499
+ isOpen: !0
2500
+ }), (async () => {
2501
+ try {
2502
+ let { results: n } = await e.uploadArchive(r, t, zn(l, i)), a = n.filter((e) => e.success).length, o = n.filter((e) => !e.success), s = o.length, { names: u, restCount: d } = Rn(o);
2503
+ n.length > 0 && a === 0 ? c?.({
2504
+ variant: V.Error,
2505
+ reason: q.UploadArchiveFailed,
2506
+ names: u,
2507
+ restCount: d
2508
+ }) : s > 0 && c?.({
2509
+ variant: V.Error,
2510
+ reason: q.UploadArchivePartiallyFailed,
2511
+ count: s,
2512
+ names: u,
2513
+ restCount: d
2514
+ });
2515
+ } catch {
2516
+ c?.({
2517
+ variant: V.Error,
2518
+ reason: q.UploadArchiveRequestFailed
2519
+ });
2520
+ } finally {
2521
+ o([l]), s(), u(null);
2522
+ }
2523
+ })();
2524
+ }, [
2525
+ t,
2526
+ n,
2527
+ c,
2528
+ e,
2529
+ o,
2530
+ s
2531
+ ]);
2532
+ return {
2533
+ onUploadFiles: _((l, p) => {
2534
+ if (l.length === 0) return;
2535
+ let m = Vn(l);
2536
+ if (m != null) {
2537
+ f(m.fileContent, m.name, p);
2538
+ return;
2539
+ }
2540
+ let h = new AbortController();
2541
+ d.current = h, u({
2542
+ files: l.map((e, t) => ({
2543
+ id: `${Date.now()}-${t}`,
2544
+ name: e.name,
2545
+ status: $.Queued
2546
+ })),
2547
+ isOpen: !0
2548
+ });
2549
+ let g = Q(p, n), { bucket: _, path: v } = r === R.Shared ? dn(g, a.current, t) : {
2550
+ bucket: t,
2551
+ path: g
2552
+ }, y = new Set((i.get(g) ?? []).map((e) => e.name.toLowerCase()));
2553
+ (async () => {
2554
+ let t = 0, r = 0, i = 0, a = async () => {
2555
+ for (; t < l.length;) {
2556
+ let n = t++, a = l[n];
2557
+ if (h.signal.aborted) {
2558
+ u((e) => Cn(e, n, $.Cancelled));
2559
+ continue;
2560
+ }
2561
+ u((e) => Cn(e, n, {
2562
+ status: $.Uploading,
2563
+ percent: 0
2564
+ }));
2565
+ let o = y.has(a.name.toLowerCase()) ? Ht.Overwrite : Ht.CreateOnly;
2566
+ try {
2567
+ await e.uploadFile(_, `${v}${a.name}`, a.fileContent, {
2568
+ signal: h.signal,
2569
+ uploadMode: o,
2570
+ onProgress: (e) => {
2571
+ u((t) => Cn(t, n, {
2572
+ status: $.Uploading,
2573
+ percent: e
2574
+ }));
2575
+ }
2576
+ }), u((e) => Cn(e, n, {
2577
+ status: $.Completed,
2578
+ percent: 100
2579
+ })), r += 1;
2580
+ } catch {
2581
+ let e = h.signal.aborted ? $.Cancelled : $.Failed;
2582
+ e === $.Failed && (i += 1), u((t) => Cn(t, n, e));
2583
+ }
2584
+ }
2585
+ };
2586
+ await Promise.all(Array.from({ length: 3 }, () => a())), h.signal.aborted || (r === 0 && i > 0 ? c?.({
2587
+ variant: V.Error,
2588
+ reason: q.UploadFailed
2589
+ }) : c?.({
2590
+ variant: V.Success,
2591
+ reason: q.UploadCompleted,
2592
+ folder: v || n
2593
+ })), o([g]), s(), d.current = null, u(null);
2594
+ })();
2595
+ }, [
2596
+ r,
2597
+ t,
2598
+ i,
2599
+ n,
2600
+ c,
2601
+ e,
2602
+ a,
2603
+ o,
2604
+ s,
2605
+ f
2606
+ ]),
2607
+ onUploadArchive: _((e, t, n) => {
2608
+ f(e, t, n);
2609
+ }, [f]),
2610
+ onValidateUpload: _(async (e, t, n) => {
2611
+ for (let t of e) t.name = jn(t.name);
2612
+ return { valid: !0 };
2613
+ }, []),
2614
+ uploadBatchState: l,
2615
+ cancelUpload: _(() => {
2616
+ d.current?.abort();
2617
+ }, []),
2618
+ clearUploadBatch: _(() => {
2619
+ u(null);
2620
+ }, [])
2621
+ };
2622
+ }, Un = ({ filesApi: e, bucket: t, rootLabel: n = "My files", activeTab: r = R.MyFiles, onNotification: i, onOperationSuccess: a, forbiddenSymbolsRegExp: o, variant: s = Xt.Attach, actionProfile: c, labels: l, locale: u, disabledNewButtonTooltip: d, downloadDestination: f, buildValidationErrorMessage: p }) => {
2623
+ let m = c ?? Qt(s), h = Mn({
2624
+ filesApi: e,
2625
+ bucket: t,
2626
+ rootLabel: n,
2627
+ activeTab: r,
2628
+ onNotification: i
2629
+ }), g = Hn({
2630
+ filesApi: e,
2631
+ bucket: t,
2632
+ rootLabel: n,
2633
+ activeTab: r,
2634
+ cache: h.cache,
2635
+ sharedRootMetaRef: h.sharedRootMetaRef,
2636
+ invalidateFolders: h.invalidateFolders,
2637
+ bumpRetry: h.bumpRetry,
2638
+ onNotification: i
2639
+ }), v = Pn({
2640
+ filesApi: e,
2641
+ bucket: t,
2642
+ rootLabel: n,
2643
+ activeTab: r,
2644
+ folderPath: h.folderPath,
2645
+ currentFolder: h.currentFolder,
2646
+ sharedRootMetaRef: h.sharedRootMetaRef,
2647
+ listingPermissionsCache: h.listingPermissionsCache,
2648
+ invalidateFolders: h.invalidateFolders,
2649
+ bumpRetry: h.bumpRetry,
2650
+ mergeCreatedFolder: h.mergeCreatedFolder,
2651
+ setFolderPath: h.setFolderPath,
2652
+ onNotification: i,
2653
+ onOperationSuccess: a,
2654
+ downloadDestination: f,
2655
+ forbiddenSymbolsRegExp: o
2656
+ }), y = Fn({
2657
+ filesApi: e,
2658
+ bucket: t,
2659
+ rootLabel: n,
2660
+ bumpRetry: h.bumpRetry,
2661
+ onNotification: i
2662
+ }), x = Nn({
2663
+ filesApi: e,
2664
+ bucket: t,
2665
+ rootLabel: n,
2666
+ onNotification: i
2667
+ }), S = rn(h.currentFolder), C = b(() => r === R.Organization || r === R.Shared && h.folderPath === "" ? !1 : S, [
2668
+ r,
2669
+ h.folderPath,
2670
+ S
2671
+ ]), w = b(() => r === R.Shared ? Jt : qt, [r]), T = b(() => {
2672
+ let e = {}, t = (t) => {
2673
+ let n = l[t];
2674
+ n != null && (e[t] = n);
2675
+ };
2676
+ return t(L.Download), r === R.MyFiles ? (t(L.Delete), C && (t(L.Rename), on(m) && (t(L.Copy), t(L.Move), t(L.Duplicate))), sn(m) && t(L.RemoveAccess)) : r === R.Shared && sn(m) && t(L.Unshare), m === Zt.Full && t(L.Info), e;
2677
+ }, [
2678
+ r,
2679
+ C,
2680
+ m,
2681
+ l
2682
+ ]), E = b(() => v.isCreatingFolder || v.isDownloading || v.isDeleting || v.isRenaming || v.isCopying || v.isMoving || y.isUnsharing || y.isRemovingAccess || g.uploadBatchState != null, [
2683
+ v.isCreatingFolder,
2684
+ v.isDownloading,
2685
+ v.isDeleting,
2686
+ v.isRenaming,
2687
+ v.isCopying,
2688
+ v.isMoving,
2689
+ y.isUnsharing,
2690
+ y.isRemovingAccess,
2691
+ g.uploadBatchState
2692
+ ]), D = _((e, t) => {
2693
+ let n = v.onCreateFolderValidate(e, t);
2694
+ return n ? p(n) : null;
2695
+ }, [v, p]), O = _((e, t) => {
2696
+ let n = v.onRenameValidate(e, t);
2697
+ return n ? p(n, t) : null;
2698
+ }, [v, p]);
2699
+ return {
2700
+ items: h.items,
2701
+ isLoading: h.isLoading,
2702
+ error: h.error,
2703
+ path: h.path,
2704
+ onPathChange: h.onPathChange,
2705
+ retry: h.retry,
2706
+ onSearchFiles: h.onSearchFiles,
2707
+ isSearching: h.isSearching,
2708
+ searchResults: h.searchResults,
2709
+ clearSearchResults: h.clearSearchResults,
2710
+ expandedPaths: h.expandedPaths,
2711
+ loadedPaths: h.loadedPaths,
2712
+ onExpandedPathsChange: h.onExpandedPathsChange,
2713
+ onFolderPopupPathChange: h.onFolderPopupPathChange,
2714
+ folderPopupLoadingPaths: h.folderPopupLoadingPaths,
2715
+ onUploadFiles: g.onUploadFiles,
2716
+ onUploadArchive: g.onUploadArchive,
2717
+ onValidateUpload: g.onValidateUpload,
2718
+ uploadBatchState: g.uploadBatchState,
2719
+ cancelUpload: g.cancelUpload,
2720
+ clearUploadBatch: g.clearUploadBatch,
2721
+ onCreateFolder: v.onCreateFolder,
2722
+ onCreateFolderValidate: D,
2723
+ isCreatingFolder: v.isCreatingFolder,
2724
+ onDownloadFiles: v.onDownloadFiles,
2725
+ isDownloading: v.isDownloading,
2726
+ onDeleteFiles: v.onDeleteFiles,
2727
+ isDeleting: v.isDeleting,
2728
+ onRenameValidate: O,
2729
+ onMoveToFiles: v.onMoveToFiles,
2730
+ isRenaming: v.isRenaming,
2731
+ onCopyFiles: v.onCopyFiles,
2732
+ isCopying: v.isCopying,
2733
+ isMoving: v.isMoving,
2734
+ cancelCopyMove: v.cancelCopyMove,
2735
+ uploadEnabled: C,
2736
+ isNewButtonDisabled: !C,
2737
+ disabledNewButtonTooltip: d,
2738
+ visibleColumns: w,
2739
+ dateLocale: u,
2740
+ dateOptions: Kt,
2741
+ actionLabels: T,
2742
+ sharedWithMeIds: h.sharedWithMeIds,
2743
+ sharedByMePaths: h.sharedByMePaths,
2744
+ onUnshareFiles: y.onUnshareFiles,
2745
+ isUnsharing: y.isUnsharing,
2746
+ onRemoveFilesAccess: y.onRemoveFilesAccess,
2747
+ isRemovingAccess: y.isRemovingAccess,
2748
+ fileMetadata: x.fileMetadata,
2749
+ isFileMetadataLoading: x.isFileMetadataLoading,
2750
+ onGetInfo: x.onGetInfo,
2751
+ clearMetadata: x.clearMetadata,
2752
+ isAnyOperationInProgress: E
2753
+ };
2754
+ }, Wn = [
2755
+ R.MyFiles,
2756
+ R.Shared,
2757
+ R.Organization
2758
+ ], Gn = (e, t, n, r) => {
2759
+ let i = _((e) => r == null || r.includes(e), [r]), a = b(() => n?.filter((e) => i(e.id)).flatMap(({ id: e, label: t, disabled: n }) => typeof t == "string" ? [{
2760
+ id: e,
2761
+ label: t,
2762
+ disabled: n
2763
+ }] : []), [n, i]);
2764
+ return v(() => {
2765
+ i(e) || t(Wn.find((e) => i(e)) ?? R.MyFiles);
2766
+ }, [
2767
+ i,
2768
+ e,
2769
+ t
2770
+ ]), { tabs: a };
2771
+ }, Kn = (e) => {
2772
+ if (e.id) {
2773
+ let t = document.querySelector(`[row-id="${e.id}"]`);
2774
+ if (t) return t;
2775
+ }
2776
+ return e.rowIndex == null ? null : document.querySelector(`[row-index="${e.rowIndex}"]`);
2777
+ }, qn = (e, t) => {
2778
+ requestAnimationFrame(() => {
2779
+ requestAnimationFrame(() => {
2780
+ !e.isDestroyed() && t.rowIndex != null && e.ensureNodeVisible(t, "middle"), Kn(t)?.scrollIntoView({
2781
+ block: "center",
2782
+ behavior: "auto"
2783
+ });
2784
+ });
2785
+ });
2786
+ }, Jn = (e) => e.find((e) => e.data?.isTemporary) ?? e[0] ?? null, Yn = ({ resolveTargetNode: e = Jn } = {}) => {
2787
+ let t = x(/* @__PURE__ */ new Set()), n = x(!1), r = x(null), i = _(() => {
2788
+ t.current = /* @__PURE__ */ new Set(), n.current = !1;
2789
+ }, []), a = _((e) => {
2790
+ let { api: t } = e;
2791
+ !t.isDestroyed() && e.rowIndex != null && t.ensureIndexVisible(e.rowIndex);
2792
+ }, []), o = _((r) => {
2793
+ let { api: i } = r, a = /* @__PURE__ */ new Set(), o = [];
2794
+ i.forEachNode((e) => {
2795
+ let r = e.data?.id;
2796
+ r && (a.add(r), n.current && !t.current.has(r) && o.push(e));
2797
+ }), t.current = a, n.current = !0;
2798
+ let s = e(o);
2799
+ s && qn(i, s);
2800
+ }, [e]), s = _((e) => {
2801
+ let t = r.current;
2802
+ t !== e && (t != null && (t.removeEventListener("cellEditingStarted", a), t.removeEventListener("rowDataUpdated", o)), e.addEventListener("cellEditingStarted", a), e.addEventListener("rowDataUpdated", o), r.current = e);
2803
+ }, [a, o]);
2804
+ return v(() => () => {
2805
+ let e = r.current;
2806
+ e != null && !e.isDestroyed() && (e.removeEventListener("cellEditingStarted", a), e.removeEventListener("rowDataUpdated", o)), r.current = null;
2807
+ }, [a, o]), {
2808
+ handleGridApiChange: s,
2809
+ reset: i
1436
2810
  };
1437
- }, [e, t]), vt = {
2811
+ }, Xn = {
1438
2812
  settings: "Settings",
1439
2813
  savedNotification: "Chat settings have been saved",
1440
2814
  responseFormatLabel: "Response format",
@@ -1450,11 +2824,11 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1450
2824
  temperatureHint: "Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.",
1451
2825
  saveLabel: "Apply changes",
1452
2826
  saveDisabledTooltip: "Please select a response format"
1453
- }, yt = (e) => (e ?? "").toLowerCase().replace(/[^a-z]/g, "") === "plaintext" ? a.PlainText : a.Markdown, bt = (e) => {
1454
- let t = _(() => ({
1455
- ...vt,
2827
+ }, Zn = (e) => (e ?? "").toLowerCase().replace(/[^a-z]/g, "") === "plaintext" ? o.PlainText : o.Markdown, Qn = (e) => {
2828
+ let t = b(() => ({
2829
+ ...Xn,
1456
2830
  ...e.labels
1457
- }), [e.labels]), { onSaved: n } = e, r = e.mode === "local" ? e.values.responseFormat : yt(e.conversation.responseFormat), i = e.mode === "local" ? e.values.systemPrompt : e.conversation.prompt ?? "", a = e.mode === "local" ? e.values.temperature : e.conversation.temperature ?? .5, o = m((t) => {
2831
+ }), [e.labels]), { onSaved: n } = e, r = e.mode === "local" ? e.values.responseFormat : Zn(e.conversation.responseFormat), i = e.mode === "local" ? e.values.systemPrompt : e.conversation.prompt ?? "", a = e.mode === "local" ? e.values.temperature : e.conversation.temperature ?? .5, o = _((t) => {
1458
2832
  e.mode === "local" ? e.onValuesChange({
1459
2833
  responseFormat: t.responseFormat ?? e.values.responseFormat,
1460
2834
  systemPrompt: t.systemPrompt ?? e.values.systemPrompt,
@@ -1466,7 +2840,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1466
2840
  ...t.temperature != null && { temperature: t.temperature }
1467
2841
  }), n?.();
1468
2842
  }, [n, e]), s = e.deploymentFeatures?.systemPrompt ?? !1, c = !e.isQuickApp && (e.deploymentFeatures?.temperature ?? !1);
1469
- return _(() => ({
2843
+ return b(() => ({
1470
2844
  features: {
1471
2845
  systemPrompt: s,
1472
2846
  temperature: c,
@@ -1502,15 +2876,15 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1502
2876
  i,
1503
2877
  a
1504
2878
  ]);
1505
- }, xt = (e = !0, t = !0) => {
1506
- let [n, r] = y(!1), [i, a] = y([]), o = v(0), s = v(e), c = v(t);
1507
- g(() => {
2879
+ }, $n = (e = !0, t = !0) => {
2880
+ let [n, r] = S(!1), [i, a] = S([]), o = x(0), s = x(e), c = x(t);
2881
+ y(() => {
1508
2882
  s.current = e, c.current = t, t || (o.current = 0, r(!1));
1509
2883
  }, [e, t]);
1510
- let l = m(() => {
2884
+ let l = _(() => {
1511
2885
  a([]);
1512
2886
  }, []);
1513
- return h(() => {
2887
+ return v(() => {
1514
2888
  let e = (e) => !!e.dataTransfer?.types.includes("Files"), t = (t) => {
1515
2889
  !c.current || !e(t) || (o.current += 1, r(!0));
1516
2890
  }, n = (t) => {
@@ -1531,21 +2905,21 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1531
2905
  pendingFiles: i,
1532
2906
  onFilesConsumed: l
1533
2907
  };
1534
- }, St = () => typeof window < "u" ? window.innerWidth : 1024, Ct = () => {
1535
- let [e, t] = y(St);
1536
- return h(() => {
2908
+ }, er = () => typeof window < "u" ? window.innerWidth : 1024, tr = () => {
2909
+ let [e, t] = S(er);
2910
+ return v(() => {
1537
2911
  if (typeof window > "u") return;
1538
2912
  let e = () => t(window.innerWidth);
1539
2913
  return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
1540
2914
  }, []), e;
1541
- }, wt = (e) => {
1542
- let t = Ct();
2915
+ }, nr = (e) => {
2916
+ let t = tr();
1543
2917
  return Math.max(0, t - e);
1544
- }, Tt = (e) => e.map((e) => e === D.Edit ? O.Edit : O.View), Et = (e, t) => {
2918
+ }, rr = (e) => e.map((e) => e === I.Edit ? re.Edit : re.View), ir = (e, t) => {
1545
2919
  let n = new URL(e, t);
1546
2920
  return `${t}${n.pathname}${n.search}${n.hash}`;
1547
- }, Dt = (e, t, n, r = window.location.origin) => {
1548
- let [i, a] = y(), [o, s] = y(!0), [c, l] = y(null), u = v(0), d = m(async (i = [O.View]) => {
2921
+ }, ar = (e, t, n, r = window.location.origin) => {
2922
+ let [i, a] = S(), [o, s] = S(!0), [c, l] = S(null), u = x(0), d = _(async (i = [re.View]) => {
1549
2923
  let o = ++u.current;
1550
2924
  s(!0), l(null);
1551
2925
  try {
@@ -1555,9 +2929,9 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1555
2929
  access: i
1556
2930
  } });
1557
2931
  u.current === o && a({
1558
- url: Et(s.url, r),
2932
+ url: ir(s.url, r),
1559
2933
  expiresInDays: s.expiresInDays,
1560
- access: Tt(s.access)
2934
+ access: rr(s.access)
1561
2935
  });
1562
2936
  } catch (e) {
1563
2937
  u.current === o && l(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to create share link"));
@@ -1570,22 +2944,22 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1570
2944
  n,
1571
2945
  e
1572
2946
  ]);
1573
- return h(() => {
2947
+ return v(() => {
1574
2948
  a(void 0), d();
1575
2949
  }, [t, d]), {
1576
2950
  data: i,
1577
2951
  isLoading: o,
1578
2952
  error: c,
1579
- setAccess: m((e) => {
2953
+ setAccess: _((e) => {
1580
2954
  d(e);
1581
2955
  }, [d])
1582
2956
  };
1583
- }, Ot = /* @__PURE__ */ function(e) {
2957
+ }, or = /* @__PURE__ */ function(e) {
1584
2958
  return e.Idle = "idle", e.Loading = "loading", e.Resolved = "resolved", e.Unknown = "unknown", e;
1585
- }({}), kt = { status: "idle" }, At = (e) => {
1586
- let [t, n] = y({}), r = v(/* @__PURE__ */ new Set());
2959
+ }({}), sr = { status: "idle" }, cr = (e) => {
2960
+ let [t, n] = S({}), r = x(/* @__PURE__ */ new Set());
1587
2961
  return {
1588
- requestRecipientsCount: m((t) => {
2962
+ requestRecipientsCount: _((t) => {
1589
2963
  r.current.has(t) || (r.current.add(t), n((e) => ({
1590
2964
  ...e,
1591
2965
  [t]: { status: "loading" }
@@ -1607,32 +2981,32 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1607
2981
  }
1608
2982
  })());
1609
2983
  }, [e]),
1610
- getRecipientsCount: m((e) => t[e] ?? kt, [t]),
1611
- invalidateRecipientsCount: m((e) => {
2984
+ getRecipientsCount: _((e) => t[e] ?? sr, [t]),
2985
+ invalidateRecipientsCount: _((e) => {
1612
2986
  r.current.delete(e), n(({ [e]: t, ...n }) => n);
1613
2987
  }, [])
1614
2988
  };
1615
- }, jt = { deepResearchFallback: "Deep research" }, Mt = (e) => {
1616
- let { deepResearchToolId: t, selectedItemId: n, selectedDeploymentConfiguration: r } = e, i = _(() => ({
1617
- ...jt,
2989
+ }, lr = { deepResearchFallback: "Deep research" }, ur = (e) => {
2990
+ let { deepResearchToolId: t, selectedItemId: n, selectedDeploymentConfiguration: r } = e, i = b(() => ({
2991
+ ...lr,
1618
2992
  ...e.labels
1619
- }), [e.labels]), a = e.toolIcon, o = _(() => {
2993
+ }), [e.labels]), a = e.toolIcon, o = b(() => {
1620
2994
  if (t == null || r == null) return null;
1621
2995
  let e = r.properties?.[t];
1622
2996
  return e == null || !(e.type === "boolean" || e.type == null && typeof e.default == "boolean") ? null : e;
1623
- }, [t, r]), s = _(() => typeof o?.default == "boolean" ? o.default : !1, [o]), [c, l] = y(s);
1624
- h(() => {
2997
+ }, [t, r]), s = b(() => typeof o?.default == "boolean" ? o.default : !1, [o]), [c, l] = S(s);
2998
+ v(() => {
1625
2999
  l(s);
1626
3000
  }, [n, s]);
1627
- let u = m((e) => {
3001
+ let u = _((e) => {
1628
3002
  e === t && l((e) => !e);
1629
- }, [t]), d = m((e) => {
3003
+ }, [t]), d = _((e) => {
1630
3004
  if (t == null) return;
1631
3005
  let n = e?.[t];
1632
3006
  typeof n == "boolean" && l(n);
1633
3007
  }, [t]);
1634
3008
  return {
1635
- toolsMenuItems: _(() => o == null || t == null ? [] : [{
3009
+ toolsMenuItems: b(() => o == null || t == null ? [] : [{
1636
3010
  id: t,
1637
3011
  label: typeof o.title == "string" && o.title || i.deepResearchFallback,
1638
3012
  icon: a ?? null,
@@ -1645,7 +3019,7 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1645
3019
  a
1646
3020
  ]),
1647
3021
  onToolToggle: u,
1648
- toolConfigurationValue: _(() => t == null || o == null ? {} : { [t]: c }, [
3022
+ toolConfigurationValue: b(() => t == null || o == null ? {} : { [t]: c }, [
1649
3023
  t,
1650
3024
  o,
1651
3025
  c
@@ -1654,4 +3028,4 @@ var k = (e) => e.startsWith("files/"), A = (e) => e.url != null && k(e.url) || e
1654
3028
  };
1655
3029
  };
1656
3030
  //#endregion
1657
- export { re as AttachmentValidationErrorReason, oe as ConversationExportMode, V as ConversationTransferErrorCode, z as ConversationTransferJobStatus, B as ConversationTransferSubjectKind, H as ConversationTransferWarningCode, U as EXPORT_APP_NAME, R as ExportFileNameKind, Ot as RecipientsCountStatus, Re as attachmentToDto, J as attachmentsToDtos, Y as createMessagePair, j as downloadAttachment, L as formatDateYM, ae as formatDateYMD, xe as formatQuotedNameList, Q as getConversationPath, Ve as getStarterConversationText, He as getStarterSubmitText, X as hasActiveToolConfig, $ as isAwaitingGenerationResume, k as isDialFileId, A as isDownloadableAttachment, ze as isMessageChanged, P as useAttachmentAction, Oe as useAttachmentUpload, ie as useAttachmentValidation, bt as useChatSettingsFormConfig, Le as useConversationExport, Ue as useConversationHandlers, ot as useConversationImport, lt as useConversationScroll, _t as useConversationSources, ht as useConversationStream, xt as usePageFileDrag, wt as usePanelMaxWidth, Dt as useShareLink, At as useShareRecipientsCount, Mt as useToolsMenu, Ct as useViewportWidth };
3031
+ export { me as AttachmentValidationErrorReason, qt as COLUMNS_WITHOUT_AUTHOR, Jt as COLUMNS_WITH_AUTHOR, Yt as CORE_PERMISSION_MAP, ve as ConversationExportMode, G as ConversationTransferErrorCode, W as ConversationTransferJobStatus, ye as ConversationTransferSubjectKind, be as ConversationTransferWarningCode, Kt as DATE_OPTIONS, Zt as DialFileManagerActionProfile, Xt as DialFileManagerVariant, Ht as DialFilesApiUploadMode, On as DownloadDestinationType, xe as EXPORT_APP_NAME, U as ExportFileNameKind, q as FileManagerNotificationReason, J as FileNameValidationErrorReason, Y as FileOperationKind, $ as FileUploadStatus, Gt as PATH_SEPARATOR_REGEXP, Wt as RESERVED_MARKER_NAME, or as RecipientsCountStatus, Ut as UPLOAD_CONCURRENCY, rt as attachmentToDto, it as attachmentsToDtos, xn as buildFromCache, un as buildSharedItemVirtualPath, at as createMessagePair, Qt as deriveActionProfile, ln as dialCorePathToRelative, ae as downloadAttachment, wn as fetchByTab, Tn as fetchForSearch, an as findDialFileByPath, bn as findFirstSuccessfulCopyMoveItem, nn as findFolderByVirtualPath, _e as formatDateYM, ge as formatDateYMD, tn as formatOperationFolderName, Be as formatQuotedNameList, K as getConversationPath, lt as getStarterConversationText, ut as getStarterSubmitText, en as getVirtualPathName, ot as hasActiveToolConfig, rn as hasDialFileWritePermission, $t as hasForbiddenNameSymbols, Nt as isAwaitingGenerationResume, on as isCopyMoveDuplicateAllowed, H as isDialFileId, ie as isDownloadableAttachment, st as isMessageChanged, sn as isShareActionsAllowed, yn as mapCorePermissions, Dn as mapFileMetadataToDialFile, En as mapSearchItem, Sn as mergeCreatedFolderIntoCache, Z as normalizeVirtualPath, cn as parseNewFolderVirtualPath, _n as prepareCopyItems, vn as prepareMoveRenameItems, dn as resolveOwnerCoords, jn as sanitizeFileName, Cn as updateEntry, ce as useAttachmentAction, qe as useAttachmentUpload, he as useAttachmentValidation, Qn as useChatSettingsFormConfig, nt as useConversationExport, ft as useConversationHandlers, kt as useConversationImport, Mt as useConversationScroll, Vt as useConversationSources, zt as useConversationStream, Mn as useDialFileListing, Un as useDialFileManager, Gn as useDialFileManagerTabConfig, Nn as useDialFileMetadata, Pn as useDialFileMutations, Fn as useDialFileSharing, Hn as useDialFileUploadBatch, Yn as useGridEditingScroll, $n as usePageFileDrag, nr as usePanelMaxWidth, ar as useShareLink, cr as useShareRecipientsCount, ur as useToolsMenu, tr as useViewportWidth };