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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/{api-error-DuLNy43N.js → api-error/api-error.js} +1 -1
  2. package/api-transport/create-csrf-middleware.js +21 -0
  3. package/api-transport/create-unauthorized-middleware.js +41 -0
  4. package/attachment/useAttachmentAction/useAttachmentAction.js +74 -0
  5. package/attachment/useAttachmentValidation/useAttachmentValidation.js +35 -0
  6. package/attachments.js +3 -2
  7. package/catalog/catalog-derivations.js +10 -0
  8. package/catalog/catalog-primary-action.js +21 -0
  9. package/catalog/create-publish-api.js +27 -0
  10. package/catalog/deployment-endpoint-url.js +34 -0
  11. package/{deployment-id-CxWgJTs9.js → catalog/deployment-id.js} +1 -1
  12. package/catalog/entity-details.js +6 -0
  13. package/catalog/map-deployment-limits-to-catalog.js +73 -0
  14. package/catalog/map-deployment-limits-to-input.js +14 -0
  15. package/catalog/map-deployment-to-catalog-item.js +92 -0
  16. package/catalog/map-entity-details-to-catalog.js +350 -0
  17. package/catalog/map-prompt-to-catalog-item.js +49 -0
  18. package/catalog/map-skill-to-catalog-item.js +123 -0
  19. package/catalog/mcp-endpoint-url.js +26 -0
  20. package/catalog/publish.js +18 -0
  21. package/catalog/useCatalogEditNavigation/useCatalogEditNavigation.js +109 -0
  22. package/catalog/useCatalogItemDetails.js +101 -0
  23. package/catalog/useCatalogToolsetCredentials/useCatalogToolsetCredentials.js +146 -0
  24. package/catalog/useFavoriteEntitiesState/useFavoriteEntitiesState.js +50 -0
  25. package/catalog/usePublishFolders/usePublishFolders.js +72 -0
  26. package/catalog.js +22 -3
  27. package/conversation/announcement-message.js +42 -0
  28. package/conversation/conversation-transfer/async.js +18 -0
  29. package/conversation/conversation-transfer/attachment-refs.js +11 -0
  30. package/conversation/conversation-transfer/build-upload-path.js +27 -0
  31. package/{date-BeuD8G79.js → conversation/conversation-transfer/date.js} +1 -1
  32. package/conversation/conversation-transfer/dial-file-resolve.js +18 -0
  33. package/conversation/conversation-transfer/export-conversation.js +32 -0
  34. package/conversation/conversation-transfer/import-conversation.js +93 -0
  35. package/conversation/conversation-transfer/progress.js +39 -0
  36. package/conversation/conversation-transfer/queue.js +84 -0
  37. package/conversation/conversation-transfer/types.js +9 -0
  38. package/conversation/conversation-transfer/zip-export.js +19 -0
  39. package/conversation/conversation-transfer/zip-import.js +29 -0
  40. package/conversation/create-chat-stream-api.js +96 -0
  41. package/conversation/deriveConversationRowActionState/deriveConversationRowActionState.js +14 -0
  42. package/conversation/display-name-watch.js +5 -0
  43. package/conversation/footer-message.js +23 -0
  44. package/conversation/get-model-id-from-conversation-id.js +14 -0
  45. package/conversation/greeting.js +7 -0
  46. package/conversation/message-factory.js +19 -0
  47. package/conversation/message-utils.js +13 -0
  48. package/conversation/overlay-messages.js +8 -0
  49. package/conversation/quick-app-conversation-starters.js +29 -0
  50. package/conversation/starter-option.js +27 -0
  51. package/conversation/useActiveConversationSync/useActiveConversationSync.js +19 -0
  52. package/conversation/useAsyncConfirmDialog/useAsyncConfirmDialog.js +39 -0
  53. package/conversation/useAttachmentUpload/useAttachmentUpload.js +33 -0
  54. package/conversation/useConversationExport/useConversationExport.js +285 -0
  55. package/conversation/useConversationHandlers/attachment-to-dto.js +13 -0
  56. package/conversation/useConversationHandlers/message-factory.js +21 -0
  57. package/conversation/useConversationHandlers/message-utils.js +8 -0
  58. package/conversation/useConversationHandlers/starter-option.js +11 -0
  59. package/conversation/useConversationHandlers/useConversationHandlers.js +263 -0
  60. package/conversation/useConversationImport/useConversationImport.js +239 -0
  61. package/conversation/useConversationLookupMaps/useConversationLookupMaps.js +11 -0
  62. package/conversation/useConversationPanelItems/useConversationPanelItems.js +35 -0
  63. package/{useConversationScroll-CliIMnjP.js → conversation/useConversationScroll/useConversationScroll.js} +1 -1
  64. package/conversation/useConversationStream/apply-chunk.js +78 -0
  65. package/conversation/useConversationStream/buffered-generation.js +18 -0
  66. package/conversation/useConversationStream/conversation-path.js +8 -0
  67. package/conversation/useConversationStream/generation-resume.js +126 -0
  68. package/conversation/useConversationStream/useConversationStream.js +148 -0
  69. package/conversation/useImportFilePicker/useImportFilePicker.js +20 -0
  70. package/conversation/useTranscribeAudio/audio-transcription-error.js +12 -0
  71. package/conversation/useTranscribeAudio/transcription-retry.js +38 -0
  72. package/conversation/useTranscribeAudio/useTranscribeAudio.js +41 -0
  73. package/{useConversationSources-DKaKvjXZ.js → conversation-sources/useConversationSources/useConversationSources.js} +1 -1
  74. package/conversation-sources.js +1 -1
  75. package/conversation-transfer.js +7 -3
  76. package/conversation.d.ts +66 -0
  77. package/conversation.js +31 -2
  78. package/file-manager.d.ts +3 -4
  79. package/file-manager.js +28 -3
  80. package/files/annotation.js +15 -0
  81. package/files/attachment-canvas.js +218 -0
  82. package/files/attachment-dto-to-display.js +15 -0
  83. package/files/attachment-types.js +16 -0
  84. package/files/create-files-api.js +40 -0
  85. package/files/create-upload-file-with-progress.js +42 -0
  86. package/files/dial-file-manager-copy-move.util.js +55 -0
  87. package/files/dial-file-manager-mapping.util.js +140 -0
  88. package/files/dial-file-manager-path.util.js +72 -0
  89. package/files/dial-file-manager.model.js +25 -0
  90. package/files/dial-file-manager.types.js +10 -0
  91. package/files/dial-file-to-attachment.js +37 -0
  92. package/files/dial-file.js +30 -0
  93. package/files/dial-files-api.js +6 -0
  94. package/files/download-destination.js +6 -0
  95. package/files/file-manager-variant.js +11 -0
  96. package/files/file-name.js +19 -0
  97. package/files/prepare-download-destination.js +24 -0
  98. package/files/resolve-dial-file-api-path.js +33 -0
  99. package/files/source-content.js +37 -0
  100. package/files/useDialFileListing/useDialFileListing.js +295 -0
  101. package/files/useDialFileManager/useDialFileManager.js +146 -0
  102. package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.js +23 -0
  103. package/files/useDialFileMetadata/useDialFileMetadata.js +42 -0
  104. package/files/useDialFileMutations/useDialFileMutations.js +359 -0
  105. package/files/useDialFileSharing/useDialFileSharing.js +70 -0
  106. package/files/useDialFileUploadBatch/useDialFileUploadBatch.js +156 -0
  107. package/index.d.ts +69 -4
  108. package/index.js +134 -28
  109. package/mcp-apps/mcp-apps-api-client.js +48 -0
  110. package/mcp-apps/useMcpAppHostAdapter/useMcpAppHostAdapter.js +26 -0
  111. package/mcp-apps/useMcpAppHostContext/useMcpAppHostContext.js +26 -0
  112. package/mcp-apps/useMcpAppTools/useMcpAppTools.js +71 -0
  113. package/mcp-apps/useOpenMcpAppCanvas/useOpenMcpAppCanvas.js +58 -0
  114. package/mcp-apps.js +6 -2
  115. package/oauth/authorize-url.js +12 -0
  116. package/oauth/handshake.js +65 -0
  117. package/oauth/popup.js +29 -0
  118. package/oauth/toolset-id.js +10 -0
  119. package/oauth/types.js +24 -0
  120. package/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.js +94 -0
  121. package/oauth/useToolsetLogin/useToolsetLogin.js +73 -0
  122. package/oauth.js +9 -3
  123. package/package.json +35 -23
  124. package/prompt/export-prompt.js +28 -0
  125. package/prompt/prompt-resource.js +15 -0
  126. package/prompt/prompt.js +12 -0
  127. package/prompt/usePromptsState/usePromptsState.js +42 -0
  128. package/scheduled-task/scheduled-task-mapping.js +6 -0
  129. package/{scheduled-task-trigger-D9RZCk52.js → scheduled-task/scheduled-task-trigger.js} +39 -40
  130. package/scheduled-tasks.js +3 -2
  131. package/scroll-anchoring.js +1 -1
  132. package/shared/application-schema.js +4 -0
  133. package/shared/browser-timezone.js +10 -0
  134. package/{cron-weekday-B4w29eAC.js → shared/cron-weekday.js} +1 -1
  135. package/shared/custom-apps.js +30 -0
  136. package/shared/external-services.js +18 -0
  137. package/{formatting-CZyyxBG3.js → shared/formatting.js} +1 -1
  138. package/{prompt-resource-Bt1I-8ri.js → shared/locale.js} +2 -13
  139. package/{string-utils-iBi2Y55C.js → shared/string-utils.js} +1 -1
  140. package/shared/toolset-login-events.js +13 -0
  141. package/sharing.js +3 -3
  142. package/skill/skill-file-batch-validation.js +48 -0
  143. package/skill/skill-file-preview.js +15 -0
  144. package/skill/skill-manifest.js +70 -0
  145. package/skill/skill-types.js +15 -0
  146. package/skill/skill.js +48 -0
  147. package/skill/useSkillEditorLoad.js +103 -0
  148. package/skill/useSkillEditorSubmit.js +135 -0
  149. package/skill/useSkillFileActions.js +99 -0
  150. package/skill/useSkillFilePreview.js +29 -0
  151. package/{useSkillsState-BoLlwmzb.js → skill/useSkillsState/useSkillsState.js} +1 -1
  152. package/skill-editor.js +8 -3
  153. package/skills-state.js +1 -1
  154. package/source-content.d.ts +29 -0
  155. package/source-content.js +2 -0
  156. package/usage/useUsageData/useUsageData.js +32 -0
  157. package/useChatSettingsFormConfig/useChatSettingsFormConfig.js +74 -0
  158. package/{usePanelMaxWidth-BEZYuqF9.js → usePageFileDrag/usePageFileDrag.js} +1 -11
  159. package/usePanelMaxWidth/usePanelMaxWidth.js +8 -0
  160. package/{useShareLink-xkiaxATt.js → useShareLink/useShareLink.js} +1 -1
  161. package/{useShareRecipientsCount-BgwCLKY0.js → useShareRecipientsCount/useShareRecipientsCount.js} +1 -1
  162. package/useToolsMenu/useToolsMenu.js +50 -0
  163. package/useViewportWidth/useViewportWidth.js +12 -0
  164. package/utils.js +17 -7
  165. package/viewport-layout.js +4 -2
  166. package/attachment-types-AAoN9E95.js +0 -7760
  167. package/browser-Btsa0Lmr.js +0 -607
  168. package/skill-manifest-CeG6-WSK.js +0 -4056
  169. package/useAttachmentValidation-CkMTd5lA.js +0 -102
  170. package/useConversationImport-CDRs7JF1.js +0 -826
  171. package/useDialFileManagerTabConfig-CjI46lMo.js +0 -2291
  172. package/useOAuthCallbackCompletion-CvyTKLER.js +0 -93
  173. package/useOpenMcpAppCanvas-C7-AMseH.js +0 -207
  174. package/useSkillFileActions-B-VaGD20.js +0 -373
  175. package/useSkillFilePreview-B5o1n_0F.js +0 -1244
  176. package/useToolsMenu-zURpMEn1.js +0 -1882
  177. package/useToolsetLogin-B05m134e.js +0 -195
  178. package/useUsageData-D7BxloKZ.js +0 -201
@@ -1,195 +0,0 @@
1
- import { generateUUID as e } from "@epam/ai-dial-chat-shared";
2
- import { useCallback as t } from "react";
3
- //#region src/oauth/toolset-id.ts
4
- var n = "toolsets/", r = "public", i = (e) => e.split("/").map((e) => encodeURIComponent(e)).join("/"), a = (e) => e.split("/").map((e) => {
5
- try {
6
- return decodeURIComponent(e);
7
- } catch {
8
- return e;
9
- }
10
- }).join("/"), o = (e) => e.startsWith(n) ? e.slice(9).split("/")[0] === r : !1, s = /* @__PURE__ */ function(e) {
11
- return e.None = "NONE", e.ApiKey = "API_KEY", e.OAuth = "OAUTH", e;
12
- }({}), c = /* @__PURE__ */ function(e) {
13
- return e.SignedIn = "SIGNED_IN", e.SignedOut = "SIGNED_OUT", e.Failed = "FAILED", e;
14
- }({}), l = /* @__PURE__ */ function(e) {
15
- return e.Global = "GLOBAL", e.User = "USER", e.App = "APP", e;
16
- }({}), u = /* @__PURE__ */ function(e) {
17
- return e.WithLogin = "with-login", e.WithoutLogin = "without-login", e.WithConfig = "with-config", e;
18
- }({}), d = /* @__PURE__ */ function(e) {
19
- return e.Toolset = "toolset", e.ExternalService = "external-service", e.OfflineCredentials = "offline-credentials", e;
20
- }({}), f = /* @__PURE__ */ function(e) {
21
- return e.Started = "started", e.Blocked = "blocked", e.InvalidConfig = "invalid-config", e;
22
- }({}), p = /* @__PURE__ */ function(e) {
23
- return e.Success = "success", e.Failure = "failure", e.Cancelled = "cancelled", e;
24
- }({}), m = /* @__PURE__ */ function(e) {
25
- return e.MissingCode = "missing-code", e.MissingRedirectState = "missing-redirect-state", e.StateMismatch = "state-mismatch", e.LoginRequestFailed = "login-request-failed", e;
26
- }({}), h = /* @__PURE__ */ function(e) {
27
- return e.ResultAcknowledged = "result-acknowledged", e;
28
- }({}), g = /* @__PURE__ */ function(e) {
29
- return e.Result = "toolsetOAuthResult", e.FailureReason = "toolsetOAuthFailureReason", e;
30
- }({}), _ = "toolset-redirect-state", v = "toolset-login-success", y = new EventTarget(), b = (e) => {
31
- y.dispatchEvent(new CustomEvent(v, { detail: e }));
32
- }, x = (e) => {
33
- let t = (t) => {
34
- e(t.detail);
35
- };
36
- return y.addEventListener(v, t), () => {
37
- y.removeEventListener(v, t);
38
- };
39
- }, S = "toolset-oauth-", C = (e) => `${S}${e}`, w = 300 * 1e3, T = 500, E = (e) => {
40
- switch (e) {
41
- case m.MissingCode:
42
- case m.MissingRedirectState:
43
- case m.StateMismatch:
44
- case m.LoginRequestFailed: return e;
45
- default: return m.LoginRequestFailed;
46
- }
47
- }, D = (e) => typeof e == "object" && !!e && "type" in e && (e.type === p.Success || e.type === p.Failure), O = (e, t, { toolsetId: n, credentialsLevel: r, callbackPath: i, timeoutMs: a = w, pollIntervalMs: o = T }) => new Promise((s) => {
48
- let c, l = !1, u = () => {
49
- let e = c;
50
- c = void 0, e != null && setTimeout(() => e.close(), 0);
51
- }, d = (e) => {
52
- l || (l = !0, clearInterval(v), clearTimeout(y), window.removeEventListener("focus", _), u(), s(e));
53
- }, f = (t) => {
54
- c?.postMessage({ type: h.ResultAcknowledged });
55
- try {
56
- e.close();
57
- } catch {}
58
- d(t);
59
- }, m = () => {
60
- try {
61
- let t = new URL(e.location.href);
62
- if (t.origin !== window.location.origin || t.pathname !== i) return null;
63
- let a = t.searchParams.get(g.Result);
64
- if (a === p.Success) return {
65
- type: p.Success,
66
- toolsetId: n,
67
- credentialsLevel: r
68
- };
69
- if (a === p.Failure) return {
70
- type: p.Failure,
71
- reason: E(t.searchParams.get(g.FailureReason))
72
- };
73
- } catch {}
74
- return null;
75
- }, _ = () => {
76
- let t = m();
77
- if (t != null) {
78
- f(t);
79
- return;
80
- }
81
- e.closed && d({ type: p.Cancelled });
82
- };
83
- try {
84
- c = new BroadcastChannel(C(t)), c.onmessage = (e) => {
85
- D(e.data) && f(e.data);
86
- };
87
- } catch {}
88
- window.addEventListener("focus", _);
89
- let v = setInterval(() => {
90
- let e = m();
91
- if (e != null) {
92
- f(e);
93
- return;
94
- }
95
- }, o), y = setTimeout(() => {
96
- e.close(), d({ type: p.Cancelled });
97
- }, a), b = m();
98
- b != null && f(b);
99
- }), k = (e) => `${window.location.origin}${e}`, A = (e) => e === "localhost" || e === "[::1]" || /^127(?:\.\d{1,3}){3}$/.test(e), j = (e) => e.protocol === "https:" ? !0 : e.protocol === "http:" && A(e.hostname), M = (e, t, n) => {
100
- if (!e.authorizationEndpoint?.trim() || !e.clientId?.trim()) return null;
101
- try {
102
- let r = new URL(e.authorizationEndpoint.trim());
103
- return j(r) ? (r.searchParams.set("response_type", "code"), r.searchParams.set("client_id", e.clientId.trim()), r.searchParams.set("redirect_uri", t), e.codeChallenge && r.searchParams.set("code_challenge", e.codeChallenge), e.codeChallengeMethod && r.searchParams.set("code_challenge_method", e.codeChallengeMethod), r.searchParams.set("state", n), e.scopes && e.scopes.length > 0 && r.searchParams.set("scope", e.scopes.join(" ")), r.toString()) : null;
104
- } catch {
105
- return null;
106
- }
107
- }, N = (e, t, n, r, i, a, o = d.Toolset, s) => {
108
- let c = {
109
- toolsetId: r,
110
- credentialsLevel: i,
111
- redirectUri: a,
112
- state: n,
113
- resourceKind: o,
114
- offlineUsageConsent: s
115
- };
116
- return e.sessionStorage.setItem(_, JSON.stringify(c)), e.opener = null, e.location.href = t, {
117
- type: f.Started,
118
- popup: e,
119
- flowId: n
120
- };
121
- }, P = () => window.open("", "_blank"), F = (t, n, r, i, a = l.User, o = d.Toolset, s) => {
122
- let c = k(i), u = e(), p = M(n, c, u);
123
- return p ? N(t, p, u, r, a, c, o, s) : (t.close(), { type: f.InvalidConfig });
124
- }, I = (t, n, r, i = l.User, a) => {
125
- let o = k(r), s = e(), c = M(t, o, s);
126
- if (!c) return { type: f.InvalidConfig };
127
- let u = P();
128
- return u ? N(u, c, s, n, i, o, d.Toolset, a) : { type: f.Blocked };
129
- }, L = /* @__PURE__ */ function(e) {
130
- return e.Success = "success", e.Failure = "failure", e.PopupBlocked = "popup-blocked", e.Cancelled = "cancelled", e;
131
- }({}), R = ({ callbackPath: e, loginToolset: n, logoutToolset: r, getToolset: i }) => {
132
- let a = t(async (e, t, n) => {
133
- try {
134
- await r(e, {
135
- url: e,
136
- credentialsLevel: t,
137
- authenticationType: n
138
- });
139
- } catch {}
140
- }, [r]), o = t(async (t) => {
141
- let { toolsetId: n, credentialsLevel: r, oauthSettings: o, forceStale: u, offlineUsageConsent: m } = t, h = {
142
- clientId: o?.clientId,
143
- authorizationEndpoint: o?.authorizationEndpoint,
144
- scopes: o?.scopes,
145
- codeChallenge: o?.codeChallenge,
146
- codeChallengeMethod: o?.codeChallengeMethod
147
- }, g = u ? await (async () => {
148
- let t = P();
149
- return t ? (await a(n, r, s.OAuth), F(t, h, n, e, r, d.Toolset, m)) : { type: f.Blocked };
150
- })() : I(h, n, e, r, m);
151
- if (g.type === f.Blocked) return { type: "popup-blocked" };
152
- if (g.type !== f.Started) return { type: "failure" };
153
- let _ = await O(g.popup, g.flowId, {
154
- toolsetId: n,
155
- credentialsLevel: r,
156
- callbackPath: e
157
- });
158
- if (_.type === p.Success) return b({
159
- toolsetId: n,
160
- credentialsLevel: r
161
- }), { type: "success" };
162
- if (_.type === p.Failure) return { type: "failure" };
163
- try {
164
- let e = await i(n);
165
- if ((r === l.User ? e.authSettings?.userLevelAuthStatus : e.authSettings?.globalAuthStatus) === c.SignedIn) return b({
166
- toolsetId: n,
167
- credentialsLevel: r
168
- }), { type: "success" };
169
- } catch {}
170
- return { type: "cancelled" };
171
- }, [
172
- e,
173
- i,
174
- a
175
- ]), u = t(async (e) => {
176
- let { toolsetId: t, credentialsLevel: r, authenticationType: i, apiKey: o, isCurrentlyFailed: s, forceStale: c, offlineUsageConsent: l } = e;
177
- try {
178
- return (c || s) && await a(t, r, i), await n(t, {
179
- url: t,
180
- credentialsLevel: r,
181
- authenticationType: i,
182
- apiKey: o?.trim(),
183
- offlineUsageConsent: l
184
- }), b({
185
- toolsetId: t,
186
- credentialsLevel: r
187
- }), { type: "success" };
188
- } catch {
189
- return { type: "failure" };
190
- }
191
- }, [n, a]);
192
- return { login: t((e) => e.authenticationType === s.OAuth ? o(e) : u(e), [o, u]) };
193
- };
194
- //#endregion
195
- export { a as C, u as S, o as T, g as _, P as a, f as b, C as c, x as d, d as f, l as g, s as h, F as i, O as l, c as m, R as n, M as o, _ as p, I as r, k as s, L as t, b as u, h as v, i as w, p as x, m as y };
@@ -1,201 +0,0 @@
1
- import { n as e } from "./date-BeuD8G79.js";
2
- import { useCallback as t, useEffect as n, useMemo as r, useState as i } from "react";
3
- //#region src/api-transport/create-csrf-middleware.ts
4
- var a = (e) => ({
5
- pre: async (t) => {
6
- let n = e.getCsrfToken();
7
- if (t.init.method === "GET" || n === null) return t;
8
- let r = new Headers(t.init.headers);
9
- return r.set("X-CSRF-Token", n), {
10
- ...t,
11
- init: {
12
- ...t.init,
13
- headers: r
14
- }
15
- };
16
- },
17
- post: async (t) => {
18
- let n = t.response.headers.get("x-csrf-token");
19
- return n && e.setCsrfToken(n), t.response;
20
- }
21
- }), o = async (e) => {
22
- try {
23
- return await e.clone().text();
24
- } catch {
25
- return "";
26
- }
27
- }, s = (e) => new Headers(e.headers).get("X-CSRF-Token"), c = (e, t) => {
28
- let n = new Headers(e.init.headers);
29
- return e.init.method !== "GET" && n.set("X-CSRF-Token", t), fetch(e.url, {
30
- ...e.init,
31
- headers: n
32
- });
33
- }, l = (e) => {
34
- let t = async (t) => {
35
- let n = s(t.init), r = e.getCsrfToken();
36
- if (r !== null && r !== n) return c(t, r);
37
- let i = await e.refreshCsrfToken();
38
- if (i.status === "unauthorized") throw e.notifyUnauthorized(t.url), e.createUnauthorizedError(t.url);
39
- if (i.status !== "ok") throw Error(`CSRF refresh failed for ${t.url}`);
40
- return c(t, i.token);
41
- }, n = async (t, n) => {
42
- let r = n.headers.get("x-csrf-token");
43
- if (r && e.setCsrfToken(r), n.status === 401) throw e.notifyUnauthorized(t.url), e.createUnauthorizedError(t.url);
44
- if (!n.ok) {
45
- let r = await o(n);
46
- throw n.status === 403 && e.isInvalidCsrfErrorBody(r) ? (e.notifyUnauthorized(t.url), e.createUnauthorizedError(t.url)) : Error(`Request failed with status ${n.status} for ${t.init.method ?? "GET"} ${t.url}: ${r}`);
47
- }
48
- return n;
49
- };
50
- return { post: async (r) => {
51
- if (r.response.status === 401) throw e.notifyUnauthorized(r.url), e.createUnauthorizedError(r.url);
52
- if (r.response.status === 403) {
53
- let i = await o(r.response);
54
- if (e.isInvalidCsrfErrorBody(i)) return n(r, await t(r));
55
- }
56
- return r.response;
57
- } };
58
- }, u = (e) => {
59
- let t = e.split("/").filter(Boolean);
60
- return t.map((e, n) => {
61
- let r = t.slice(0, n).join("/");
62
- return {
63
- id: t.slice(0, n + 1).join("/"),
64
- name: e,
65
- ...r ? { folderId: r } : void 0
66
- };
67
- });
68
- }, d = (e) => ({
69
- version: 5,
70
- prompts: [{
71
- id: e.id,
72
- name: e.name,
73
- description: e.description ?? "",
74
- content: e.content,
75
- ...e.folderId ? { folderId: e.folderId } : void 0
76
- }],
77
- folders: u(e.folderId)
78
- }), f = (e) => new Blob([JSON.stringify(e, null, 2)], { type: "application/json" }), p = /[^a-zA-Z0-9._-]+/g, m = (t, n, r = /* @__PURE__ */ new Date()) => {
79
- let i = t.replace(p, "_");
80
- return `${e(r)}_${n}_prompt_${i}.json`;
81
- }, h = /* @__PURE__ */ function(e) {
82
- return e.Required = "required", e.TooLong = "tooLong", e.InvalidName = "invalidName", e.Conflict = "conflict", e;
83
- }({}), g = /^(?!\.{1,2}$)[a-zA-Z0-9 _.-]+$/, _ = 256, v = 2e3, y = 5e4, b = 10, x = (e) => {
84
- let t = e.trim();
85
- return t.length === 0 ? "required" : t.length > 256 ? "tooLong" : g.test(t) ? null : "invalidName";
86
- }, S = (e) => e.length > 2e3 ? "tooLong" : null, C = (e) => e.trim().length === 0 ? "required" : e.length > 5e4 ? "tooLong" : null, w = (e, t) => {
87
- let n = t - e.length;
88
- return n <= 10 ? n : null;
89
- }, T = (e, t) => e ? `${e}/${t}` : t, E = ({ listPrompts: e }) => {
90
- let [a, o] = i([]), [s, c] = i([]), [l, u] = i([]), [d, f] = i([]), [p, m] = i([]), [h, g] = i(!0), [_, v] = i(null), y = t(async () => {
91
- try {
92
- let t = await e();
93
- o(t.prompts), c(t.folders), u(t.sharedWithMe), f(t.publicPrompts ?? []), m(t.publicFolders ?? []), v(null);
94
- } catch (e) {
95
- v(e);
96
- }
97
- }, [e]);
98
- return n(() => {
99
- let t = { value: !1 };
100
- return (async () => {
101
- let n = await e().catch((e) => (t.value || v(e), null));
102
- t.value || (n != null && (o(n.prompts), c(n.folders), u(n.sharedWithMe), f(n.publicPrompts ?? []), m(n.publicFolders ?? []), v(null)), g(!1));
103
- })(), () => {
104
- t.value = !0;
105
- };
106
- }, [e]), r(() => ({
107
- prompts: a,
108
- folders: s,
109
- sharedWithMe: l,
110
- publicPrompts: d,
111
- publicFolders: p,
112
- isLoading: h,
113
- error: _,
114
- refetch: y,
115
- refetchPublicPrompts: y
116
- }), [
117
- a,
118
- s,
119
- l,
120
- d,
121
- p,
122
- h,
123
- _,
124
- y
125
- ]);
126
- }, D = "custom_app", O = (e) => !!e && e.id === D, k = (e) => !!e && (!!e.id?.endsWith("quickapps2") || e.displayName === "Quick app 2.0"), A = () => {
127
- try {
128
- return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
129
- } catch {
130
- return;
131
- }
132
- }, j = (e) => {
133
- let t = e.trim();
134
- if (!t || !/^https?:\/\//.test(t)) return !1;
135
- try {
136
- return !!new URL(t);
137
- } catch {
138
- return !1;
139
- }
140
- }, M = (e) => {
141
- let t = e.trim();
142
- if (t) try {
143
- return JSON.parse(t);
144
- } catch {
145
- return;
146
- }
147
- }, N = ["rate_endpoint", "configuration_endpoint"], P = (e) => {
148
- let t = e.trim();
149
- if (!t) return !0;
150
- try {
151
- let e = JSON.parse(t);
152
- if (typeof e != "object" || !e || Array.isArray(e)) return !1;
153
- let n = Object.keys(e);
154
- return n.length > 0 && n.every((e) => N.includes(e));
155
- } catch {
156
- return !1;
157
- }
158
- }, F = "/external_services/", I = (e) => {
159
- let t = e.indexOf(F);
160
- if (t === -1) return null;
161
- let n = e.slice(0, t), r = e.slice(t + 19);
162
- return !n || !r ? null : {
163
- appId: n,
164
- serviceName: r
165
- };
166
- }, L = (e, t) => `${e}${F}${t}`, R = (e) => {
167
- try {
168
- return decodeURIComponent(e);
169
- } catch {
170
- return e;
171
- }
172
- }, z = (e) => e instanceof Error ? e : Error(String(e)), B = (e, t = !0) => {
173
- let [r, a] = i(), [o, s] = i(t), [c, l] = i();
174
- return n(() => {
175
- if (!t) {
176
- s(!1);
177
- return;
178
- }
179
- let n = !1;
180
- return s(!0), (async () => {
181
- try {
182
- let t = await e();
183
- if (n) return;
184
- a(t);
185
- } catch (e) {
186
- if (n) return;
187
- l(z(e));
188
- } finally {
189
- n || s(!1);
190
- }
191
- })(), () => {
192
- n = !0;
193
- };
194
- }, [t, e]), {
195
- usage: r,
196
- isLoading: o,
197
- usageError: c
198
- };
199
- };
200
- //#endregion
201
- export { m as C, a as E, d as S, l as T, T as _, j as a, S as b, A as c, E as d, y as f, h as g, _ as h, I as i, O as l, v as m, L as n, P as o, b as p, R as r, M as s, B as t, k as u, w as v, f as w, x, C as y };