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