@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,93 +0,0 @@
1
- import { _ as e, c as t, g as n, p as r, v as i, x as a, y as o } from "./useToolsetLogin-B05m134e.js";
2
- import { useEffect as s, useRef as c, useState as l } from "react";
3
- //#region src/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.ts
4
- var u = 500, d = (e) => typeof e == "object" && !!e && "type" in e && e.type === i.ResultAcknowledged, f = () => {
5
- let e = sessionStorage.getItem(r);
6
- if (!e) return null;
7
- try {
8
- return JSON.parse(e);
9
- } catch {
10
- return null;
11
- }
12
- }, p = (e) => {
13
- try {
14
- window.history.replaceState({}, document.title, `${e.pathname}${e.search}`);
15
- } catch {}
16
- }, m = (n, r) => {
17
- let i = new URL(window.location.pathname, window.location.origin);
18
- if (i.searchParams.set(e.Result, r.type), r.type === a.Failure && i.searchParams.set(e.FailureReason, r.reason), p(i), !n) {
19
- window.close();
20
- return;
21
- }
22
- try {
23
- let e = new BroadcastChannel(t(n));
24
- e.postMessage(r);
25
- let i = setInterval(() => {
26
- e.postMessage(r);
27
- }, u);
28
- e.onmessage = (t) => {
29
- d(t.data) && (clearInterval(i), e.close(), window.close());
30
- };
31
- } catch {}
32
- }, h = ({ searchParams: e, callbackPath: t, exchange: i }) => {
33
- let [u, d] = l(!0), [h, g] = l(null), _ = c(!1), v = c(i);
34
- v.current = i;
35
- let y = c(t);
36
- return y.current = t, s(() => {
37
- if (_.current) return;
38
- _.current = !0;
39
- let t = (e, t) => {
40
- m(e, t), d(!1), g(t.type === a.Failure ? t.reason : null);
41
- };
42
- (async () => {
43
- let i = e.get("code"), s = e.get("state"), c = f();
44
- sessionStorage.removeItem(r);
45
- let l = c?.state ?? s ?? void 0;
46
- if (p(new URL(window.location.pathname, window.location.origin)), !i || !c?.toolsetId) {
47
- t(l, {
48
- type: a.Failure,
49
- reason: c?.toolsetId ? o.MissingCode : o.MissingRedirectState
50
- });
51
- return;
52
- }
53
- if (c.state != null && c.state !== s) {
54
- t(l, {
55
- type: a.Failure,
56
- reason: o.StateMismatch
57
- });
58
- return;
59
- }
60
- let u = c.credentialsLevel ?? n.User, d = c.redirectUri ?? `${window.location.origin}${y.current}`;
61
- try {
62
- let e = await v.current({
63
- code: i,
64
- redirectUri: d,
65
- credentialsLevel: u,
66
- redirectState: c
67
- });
68
- if (e != null) {
69
- t(l, {
70
- type: a.Failure,
71
- reason: e
72
- });
73
- return;
74
- }
75
- t(l, {
76
- type: a.Success,
77
- toolsetId: c.toolsetId,
78
- credentialsLevel: u
79
- });
80
- } catch {
81
- t(l, {
82
- type: a.Failure,
83
- reason: o.LoginRequestFailed
84
- });
85
- }
86
- })();
87
- }, [e]), {
88
- isInProgress: u,
89
- failureReason: h
90
- };
91
- };
92
- //#endregion
93
- export { h as t };
@@ -1,207 +0,0 @@
1
- import { n as e } from "./api-error-DuLNy43N.js";
2
- import { r as t } from "./string-utils-iBi2Y55C.js";
3
- import { AttachmentContentType as n, AttachmentErrorType as r, useAttachmentCanvas as i } from "@epam/ai-dial-attachment-canvas";
4
- import { useCallback as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
5
- import { ResponseError as u } from "@epam/ai-dial-chat-api-client";
6
- import { collectToolCallNames as d, computeMcpAppSeedKey as f, resolveMcpAppToolResult as p } from "@epam/ai-dial-mcp-apps";
7
- //#region src/mcp-apps/mcp-apps-api-client.ts
8
- var m = class extends Error {
9
- status;
10
- constructor(e) {
11
- super(`Failed to fetch MCP app resource: HTTP ${e}`), this.status = e;
12
- }
13
- }, h = (e) => ({
14
- fetchResourceHtml: async (n, r) => {
15
- try {
16
- let { raw: i } = await e.getToolsetMcpAppResourceRaw({
17
- toolsetName: t(n),
18
- resourceUri: r
19
- });
20
- return await i.text();
21
- } catch (e) {
22
- throw e instanceof u ? new m(e.response.status) : e;
23
- }
24
- },
25
- callTool: async (n, r, i, a) => {
26
- let { result: o } = await e.callToolsetMcpAppTool({
27
- toolsetName: t(n),
28
- mcpAppToolCallRequestDto: {
29
- toolName: r,
30
- arguments: i,
31
- kind: a
32
- }
33
- });
34
- return o;
35
- },
36
- listAppTools: async (n, r) => {
37
- let { tools: i } = await e.listMcpAppTools({
38
- deploymentId: t(n),
39
- kind: r
40
- });
41
- return i;
42
- },
43
- listToolNames: async (n, r) => {
44
- let { toolNames: i } = await e.listMcpToolNames({
45
- deploymentId: t(n),
46
- kind: r
47
- });
48
- return i;
49
- }
50
- }), g = (e, t, n, r) => {
51
- let [i, a] = l([]), [u, f] = l([]), p = c(/* @__PURE__ */ new Set());
52
- o(() => {
53
- if (p.current = /* @__PURE__ */ new Set(), f([]), t?.features?.mcp !== !0) {
54
- a([]);
55
- return;
56
- }
57
- if (t.type !== "toolset" && t.type !== "application") {
58
- a([]);
59
- return;
60
- }
61
- let n = t.id, r = t.type;
62
- (async () => {
63
- try {
64
- a((await e.listAppTools(n, r)).map(({ resourceUri: e, toolName: t }) => ({
65
- toolsetId: n,
66
- resourceUri: e,
67
- toolName: t,
68
- mcpToolName: t,
69
- kind: r,
70
- discovery: "direct"
71
- })));
72
- } catch {
73
- a([]);
74
- }
75
- })();
76
- }, [
77
- t?.id,
78
- t?.type,
79
- t?.features?.mcp,
80
- e
81
- ]);
82
- let m = s(() => d(n), [n]);
83
- return o(() => {
84
- if (m.size === 0) return;
85
- let t = r.filter((e) => {
86
- if (p.current.has(e.id)) return !1;
87
- let t = `${e.displayName ?? e.id}_`;
88
- return [...m].some((e) => e.startsWith(t));
89
- });
90
- if (t.length !== 0) {
91
- for (let e of t) p.current.add(e.id);
92
- (async () => {
93
- let n = await Promise.all(t.map(async (t) => {
94
- try {
95
- return (await e.listAppTools(t.id, "toolset")).map(({ resourceUri: e, toolName: n }) => ({
96
- toolsetId: t.id,
97
- resourceUri: e,
98
- toolName: `${t.displayName ?? t.id}_${n}`,
99
- mcpToolName: n,
100
- kind: "toolset",
101
- discovery: "indirect"
102
- }));
103
- } catch {
104
- return [];
105
- }
106
- }));
107
- f((e) => [...e, ...n.flat()]);
108
- })();
109
- }
110
- }, [
111
- m,
112
- r,
113
- e
114
- ]), [...i, ...u];
115
- }, _ = /* @__PURE__ */ "--color-background-primary.--color-background-secondary.--color-background-tertiary.--color-background-inverse.--color-background-ghost.--color-background-info.--color-background-danger.--color-background-success.--color-background-warning.--color-background-disabled.--color-text-primary.--color-text-secondary.--color-text-tertiary.--color-text-inverse.--color-text-ghost.--color-text-info.--color-text-danger.--color-text-success.--color-text-warning.--color-text-disabled.--color-border-primary.--color-border-secondary.--color-border-tertiary.--color-border-inverse.--color-border-ghost.--color-border-info.--color-border-danger.--color-border-success.--color-border-warning.--color-border-disabled.--color-ring-primary.--color-ring-secondary.--color-ring-inverse.--color-ring-info.--color-ring-danger.--color-ring-success.--color-ring-warning.--font-sans.--font-mono.--font-weight-normal.--font-weight-medium.--font-weight-semibold.--font-weight-bold.--font-text-xs-size.--font-text-sm-size.--font-text-md-size.--font-text-lg-size.--font-heading-xs-size.--font-heading-sm-size.--font-heading-md-size.--font-heading-lg-size.--font-heading-xl-size.--font-heading-2xl-size.--font-heading-3xl-size.--font-text-xs-line-height.--font-text-sm-line-height.--font-text-md-line-height.--font-text-lg-line-height.--font-heading-xs-line-height.--font-heading-sm-line-height.--font-heading-md-line-height.--font-heading-lg-line-height.--font-heading-xl-line-height.--font-heading-2xl-line-height.--font-heading-3xl-line-height.--border-radius-xs.--border-radius-sm.--border-radius-md.--border-radius-lg.--border-radius-xl.--border-radius-full.--border-width-regular.--shadow-hairline.--shadow-sm.--shadow-md.--shadow-lg".split("."), v = () => {
116
- let e = getComputedStyle(document.documentElement), t = {};
117
- for (let n of _) {
118
- let r = e.getPropertyValue(n).trim();
119
- r && (t[n] = r);
120
- }
121
- return t;
122
- }, y = (e, { theme: t, mcpAppTheme: n, locale: r, mcpAppUserAgent: i }) => s(() => ({
123
- theme: n ?? t,
124
- locale: r,
125
- timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
126
- userAgent: i ?? "ai-dial-chat",
127
- platform: "web",
128
- displayMode: e,
129
- styles: { variables: v() }
130
- }), [
131
- n,
132
- t,
133
- r,
134
- i,
135
- e
136
- ]), b = (t, n, r, i) => {
137
- let a = y(t, i), o = s(() => async (t, r, i, a) => {
138
- try {
139
- return await n.callTool(t, r, i, a);
140
- } catch (t) {
141
- throw Error(await e(t) ?? `Tool call "${r}" failed`);
142
- }
143
- }, [n]);
144
- return s(() => ({
145
- hostContext: a,
146
- sandboxUrl: r,
147
- fetchResourceHtml: n.fetchResourceHtml,
148
- callTool: o
149
- }), [
150
- a,
151
- r,
152
- n.fetchResourceHtml,
153
- o
154
- ]);
155
- }, x = (e, t, s, l) => {
156
- let { openCanvas: u, openCanvasLoading: d } = i(), { hostContext: h, sandboxUrl: g, fetchResourceHtml: _, callTool: v } = t, y = c(null), b = a(async (t, i, a, o = !1) => {
157
- if (g == null) return !1;
158
- l?.(), d(s.title, i);
159
- try {
160
- let r = f(a), c = async () => {
161
- let [e, n] = await Promise.all([_(t.toolsetId, t.resourceUri), p(t, a, v)]);
162
- return {
163
- html: e,
164
- toolResult: n
165
- };
166
- }, l, d;
167
- return i != null && !o ? {html: l, toolResult: d} = await e.getOrFetch(i, r, c) : ({html: l, toolResult: d} = await c(), i != null && e.set(i, {
168
- html: l,
169
- toolResult: d
170
- }, r)), u({
171
- type: n.McpApp,
172
- html: l,
173
- sandboxUrl: g,
174
- toolName: t.mcpToolName,
175
- toolInput: a?.toolInput,
176
- toolResult: d,
177
- hostContext: h,
178
- onToolCall: (e, n) => v(t.toolsetId, e, n, t.kind),
179
- onReload: () => {
180
- i != null && e.invalidate(i), y.current?.(t, i, a, !0);
181
- }
182
- }, s.title, i), !0;
183
- } catch (e) {
184
- let t = e instanceof m && e.status === 403;
185
- return u({
186
- type: n.Error,
187
- errorType: t ? r.Forbidden : r.LoadFailed,
188
- label: t ? s.forbiddenErrorLabel : s.loadErrorLabel
189
- }, s.title, i), !1;
190
- }
191
- }, [
192
- u,
193
- d,
194
- l,
195
- g,
196
- h,
197
- _,
198
- v,
199
- e,
200
- s
201
- ]);
202
- return o(() => {
203
- y.current = b;
204
- }, [b]), { openMcpAppCanvas: b };
205
- };
206
- //#endregion
207
- export { m as a, g as i, b as n, h as o, y as r, x as t };
@@ -1,373 +0,0 @@
1
- import { r as e, t } from "./api-error-DuLNy43N.js";
2
- import { i as n } from "./string-utils-iBi2Y55C.js";
3
- import { c as r, d as i, f as a, h as o, l as s, n as c, o as l, p as u, r as d, s as f, u as p } from "./skill-manifest-CeG6-WSK.js";
4
- import { RequestStatus as m, formatFileSize as h, getAttachmentTypeFromMime as g, getUtf8ByteLength as _, inferMimeTypeFromPath as v } from "@epam/ai-dial-chat-shared";
5
- import { useCallback as y, useEffect as b, useMemo as x, useRef as S, useState as C } from "react";
6
- import { SkillFileCandidateKind as w, SkillFileNodeKind as T, SkillFileValidationStatus as E } from "@epam/ai-dial-skill-editor";
7
- import { NotificationVariant as D } from "@epam/ai-dial-ui-kit";
8
- //#region src/skill/skill-file-batch-validation.ts
9
- var O = async (e, t) => {
10
- let { existingPaths: n, existingTotalBytes: r, manifestByteLength: i, messages: a } = t, o = [], s = [], l = new Set(n), d = /* @__PURE__ */ new Map();
11
- for (let { path: t } of e) t !== "SKILL.md" && d.set(t, (d.get(t) ?? 0) + 1);
12
- let f = 0, m = /* @__PURE__ */ new Set(), g, _ = i, v = 0;
13
- for (let t of e) {
14
- let { id: e, file: n, path: r } = t, i, s = w.SupportingFile;
15
- if (r.toLowerCase() === "skill.md" && r !== "SKILL.md") i = a.manifestCasingInvalid;
16
- else if (r === "SKILL.md") if (s = w.Manifest, v += 1, n.size > 1048576) i = a.fileTooLarge(h(c));
17
- else try {
18
- let t = await n.text();
19
- if (t.includes("�")) i = a.manifestInvalidUtf8;
20
- else {
21
- let { frontmatter: r, instructions: o } = u(t), s = typeof r.name == "string" ? r.name : "", c = typeof r.description == "string" ? r.description : "";
22
- !s.trim() || !c.trim() ? i = a.manifestInvalidFrontmatter : v === 1 && (g = {
23
- candidateId: e,
24
- name: s,
25
- description: c,
26
- frontmatter: r,
27
- instructions: o
28
- }, _ = n.size);
29
- }
30
- } catch {
31
- i = a.manifestInvalidFrontmatter;
32
- }
33
- else r ? p(r) ? l.has(r) || (d.get(r) ?? 0) > 1 ? i = a.pathDuplicate : n.size > 1048576 && (i = a.fileTooLarge(h(c))) : i = a.pathInvalid : i = a.required;
34
- !i && s === w.SupportingFile && (m.add(r), f += n.size), o.push({
35
- candidateId: e,
36
- status: i ? E.Invalid : E.Valid,
37
- kind: s,
38
- error: i
39
- });
40
- }
41
- if (v > 1) {
42
- s.push({ message: a.manifestDuplicate }), g = void 0, _ = i;
43
- for (let e of o) e.kind === w.Manifest && !e.error && (e.status = E.Invalid, e.error = a.manifestDuplicate);
44
- }
45
- return r + f + _ > 16777216 && s.push({ message: a.totalSizeExceeded }), l.size + m.size + 1 > 100 && s.push({ message: a.totalCountExceeded }), {
46
- results: o,
47
- batchErrors: s,
48
- manifestCandidate: g
49
- };
50
- }, k = (e, t) => {
51
- let n = t.mimeType || v(e.path) || "", r = new File([new Uint8Array(t.bytes)], e.name, n ? { type: n } : void 0);
52
- return {
53
- id: e.path,
54
- name: e.name,
55
- contentType: n,
56
- type: g(n),
57
- status: m.Idle,
58
- file: r
59
- };
60
- }, A = /* @__PURE__ */ function(e) {
61
- return e.Loading = "loading", e.Loaded = "loaded", e.Error = "error", e.Forbidden = "forbidden", e.NotFound = "not-found", e;
62
- }({}), j = class extends Error {}, M = (e, t) => {
63
- let r = e.parentPath ? n(e.parentPath) : "", i = `${t.replace(/\/+$/g, "")}/files`;
64
- return r === i ? e.name : r.startsWith(`${i}/`) ? `${r.slice(i.length + 1)}/${e.name}` : r === "files" ? e.name : r.startsWith("files/") ? `${r.slice(6)}/${e.name}` : null;
65
- }, N = async (e, t, n) => {
66
- let r = await e.downloadSkill(t, n), i = r.headers.get("etag");
67
- if (!i) throw new j("Skill ETag is missing");
68
- try {
69
- let e = await r.arrayBuffer(), { manifestText: t, files: n } = o(new Uint8Array(e));
70
- return {
71
- etag: i,
72
- manifestText: t,
73
- files: n
74
- };
75
- } catch {
76
- throw new j("Skill ZIP is invalid");
77
- }
78
- }, P = async (e, t, n) => {
79
- let [r, i] = await Promise.all([e.downloadSkillFile(t, n, d), e.listSkillFiles({
80
- bucket: t,
81
- path: n,
82
- filePath: "",
83
- recursive: !0
84
- })]), a = i.items.find((e) => e.nodeType === "item" && M(e, n) === "SKILL.md"), o = r.headers.get("etag") ?? a?.etag;
85
- if (!o) throw Error("Skill ETag is missing");
86
- let s = i.items.filter((e) => e.nodeType === "item").map((e) => ({
87
- item: e,
88
- path: M(e, n)
89
- })).filter((e) => e.path != null && e.path !== "SKILL.md"), c = await Promise.all(s.map(async ({ path: r }) => {
90
- let i = await e.downloadSkillFile(t, n, r);
91
- return [r, new Uint8Array(await i.arrayBuffer())];
92
- }));
93
- return {
94
- etag: o,
95
- manifestText: await r.text(),
96
- files: new Map(c)
97
- };
98
- }, F = ({ isEditMode: t, bucket: n, skillPath: r, client: a }) => {
99
- let [o, s] = C(t ? "loading" : "loaded"), [c, l] = C(0), [d, f] = C(), p = S(void 0), m = S({}), h = S(void 0), [g, _] = C([]), v = S(/* @__PURE__ */ new Map());
100
- return b(() => {
101
- if (!t || !n) return;
102
- if (r == null) {
103
- s("error");
104
- return;
105
- }
106
- let o = !1;
107
- return s("loading"), (async () => {
108
- if (await Promise.resolve(), !o) try {
109
- let t;
110
- try {
111
- t = await N(a, n, r);
112
- } catch (i) {
113
- let o = e(i);
114
- if (!(i instanceof j) && o !== 400) throw i;
115
- t = await P(a, n, r);
116
- }
117
- let { frontmatter: c, instructions: l } = u(t.manifestText);
118
- if (o) return;
119
- p.current = t.etag, m.current = c, h.current = r, v.current = new Map([...t.files].map(([e, t]) => [e, { bytes: t }])), _([...t.files.keys()].map((e) => ({
120
- path: e,
121
- name: i(e),
122
- kind: T.File
123
- }))), f({
124
- name: typeof c.name == "string" ? c.name : "",
125
- description: typeof c.description == "string" ? c.description : "",
126
- instructions: l
127
- }), s("loaded");
128
- } catch (t) {
129
- if (o) return;
130
- let n = e(t);
131
- s(n === 403 ? "forbidden" : n === 404 ? "not-found" : "error");
132
- }
133
- })(), () => {
134
- o = !0;
135
- };
136
- }, [
137
- t,
138
- n,
139
- r,
140
- c,
141
- a
142
- ]), {
143
- loadState: o,
144
- loadedValues: d,
145
- setLoadedValues: f,
146
- files: g,
147
- setFiles: _,
148
- filesContentRef: v,
149
- frontmatterRef: m,
150
- etagRef: p,
151
- loadedPathRef: h,
152
- retryLoad: () => l((e) => e + 1)
153
- };
154
- }, I = (e, t) => JSON.stringify({
155
- values: e,
156
- files: [...t].sort((e, t) => e.path.localeCompare(t.path))
157
- }), L = ({ bucket: n, isEditMode: i, files: o, filesContentRef: s, frontmatterRef: c, loadedPathRef: u, etagRef: d, returnUrl: f, refetchSkills: m, client: h, messages: g, onNavigate: _, onNotify: v }) => {
158
- let [b, x] = C({}), [w, T] = C(), [E, O] = C(), [k, A] = C("idle"), j = S(null), M = y(async (n) => {
159
- switch (e(n)) {
160
- case 409:
161
- x({ name: g.nameConflict });
162
- return;
163
- case 412:
164
- x({ name: g.nameConflict });
165
- return;
166
- case 413:
167
- T(g.archiveTooLarge);
168
- return;
169
- case 503:
170
- T(g.serviceUnavailable);
171
- return;
172
- case 400: {
173
- let { message: e } = await t(n);
174
- T(e ?? g.pathInvalid);
175
- return;
176
- }
177
- default: {
178
- let { traceId: e } = await t(n);
179
- T(g.saveError), v({
180
- variant: D.Error,
181
- message: g.saveError,
182
- requestId: e
183
- });
184
- }
185
- }
186
- }, [g, v]), N = y(async (e) => {
187
- let t = a(e.name);
188
- if (!t || !p(t)) {
189
- x({ name: g.nameInvalid });
190
- return;
191
- }
192
- let i = I(e, o), u = j.current, d = u != null && u.fingerprint === i, y = t, b, S, C;
193
- d ? {skillManifest: b, filePaths: S, files: C} = u : (b = r(c.current, t, e.description, e.instructions), {filePaths: S, files: C} = l(o, s.current)), A("submitting"), j.current = {
194
- fingerprint: i,
195
- bucket: n,
196
- path: y,
197
- skillManifest: b,
198
- filePaths: S,
199
- files: C
200
- };
201
- try {
202
- await h.createSkill(n, y, b, S, C), await m(), A("success"), v({
203
- variant: D.Success,
204
- title: g.saveSuccessTitle,
205
- message: g.createSuccess(t)
206
- }), _(f);
207
- } catch (e) {
208
- A("failure"), await M(e);
209
- }
210
- }, [
211
- n,
212
- o,
213
- s,
214
- c,
215
- g,
216
- h,
217
- v,
218
- _,
219
- f,
220
- m,
221
- M
222
- ]), P = y(async (t) => {
223
- let i = u.current, a = d.current;
224
- if (!i || !a) {
225
- T(g.saveError);
226
- return;
227
- }
228
- let p = r(c.current, t.name, t.description, t.instructions), { filePaths: y, files: b } = l(o, s.current);
229
- A("submitting");
230
- try {
231
- d.current = (await h.updateSkill(n, i, p, y, b, a)).etag ?? a, await m(), A("success"), v({
232
- variant: D.Success,
233
- title: g.updateSuccessTitle,
234
- message: g.updateSuccess(t.name)
235
- }), _(f);
236
- } catch (t) {
237
- if (A("failure"), e(t) === 412) {
238
- O({ message: g.conflictMessage });
239
- return;
240
- }
241
- await M(t);
242
- }
243
- }, [
244
- n,
245
- o,
246
- s,
247
- c,
248
- u,
249
- d,
250
- g,
251
- h,
252
- v,
253
- _,
254
- f,
255
- m,
256
- M
257
- ]);
258
- return {
259
- phase: k,
260
- errors: b,
261
- submitError: w,
262
- conflict: E,
263
- clearConflict: () => O(void 0),
264
- handleSubmit: y(async (e) => {
265
- if (k === "submitting" || !n) return;
266
- let t = {};
267
- if (e.name.trim() || (t.name = g.required), e.description.trim() || (t.description = g.required), e.instructions.trim() || (t.instructions = g.required), Object.keys(t).length > 0) {
268
- x(t);
269
- return;
270
- }
271
- x({}), T(void 0), O(void 0), i ? await P(e) : await N(e);
272
- }, [
273
- k,
274
- n,
275
- g,
276
- i,
277
- P,
278
- N
279
- ])
280
- };
281
- }, R = ({ files: e, setFiles: t, filesContentRef: n, frontmatterRef: r, loadedValues: a, setLoadedValues: o, isEditMode: c, isDirty: l, setSelectedPath: u, messages: p }) => {
282
- let [m, h] = C(!1), g = S(null), v = y(() => {
283
- let t = e.filter((e) => e.kind === T.File).map((e) => e.path), i = 0;
284
- for (let e of t) i += n.current.get(e)?.bytes.length ?? 0;
285
- let o = {
286
- name: a?.name ?? "",
287
- description: a?.description ?? "",
288
- instructions: a?.instructions ?? ""
289
- }, l = c ? s(r.current, o.name, o.description, o.instructions) : f(o);
290
- return {
291
- existingPaths: t,
292
- existingTotalBytes: i,
293
- manifestByteLength: _(l),
294
- messages: p
295
- };
296
- }, [
297
- e,
298
- n,
299
- c,
300
- r,
301
- a,
302
- p
303
- ]), b = y(() => new Promise((e) => {
304
- g.current = e, h(!0);
305
- }), []), w = y((e) => {
306
- h(!1), g.current?.(e), g.current = null;
307
- }, []);
308
- return {
309
- fileActions: x(() => ({
310
- validateBatch: async (e) => {
311
- let { results: t, batchErrors: n } = await O(e, v());
312
- return {
313
- results: t,
314
- batchErrors: n
315
- };
316
- },
317
- commitBatch: async (e) => {
318
- let { results: s, batchErrors: u, manifestCandidate: d } = await O(e, v());
319
- if (s.some((e) => e.error !== void 0) || u.length > 0) return { error: u[0]?.message ?? p.saveError };
320
- if (d) {
321
- if (c && d.name !== (a?.name ?? "")) return { error: p.manifestNameMismatch };
322
- if ((c || l) && !await b()) return { error: p.manifestImportDeclined };
323
- }
324
- try {
325
- let s = e.filter((e) => e.id !== d?.candidateId), l = await Promise.all(s.map(async (e) => ({
326
- path: e.path,
327
- bytes: new Uint8Array(await e.file.arrayBuffer()),
328
- mimeType: e.file.type || void 0
329
- })));
330
- for (let e of l) n.current.set(e.path, {
331
- bytes: e.bytes,
332
- mimeType: e.mimeType
333
- });
334
- return l.length > 0 && t((e) => [...e, ...l.map((e) => ({
335
- path: e.path,
336
- name: i(e.path),
337
- kind: T.File
338
- }))]), d && (r.current = c ? {
339
- ...r.current,
340
- ...d.frontmatter
341
- } : d.frontmatter, o({
342
- name: c ? a?.name ?? d.name : d.name,
343
- description: d.description,
344
- instructions: d.instructions
345
- })), {};
346
- } catch (e) {
347
- return { error: e instanceof Error ? e.message : String(e) };
348
- }
349
- },
350
- onRemoveNode: (e) => {
351
- t((t) => t.filter((t) => t.path !== e && !t.path.startsWith(`${e}/`)));
352
- for (let t of [...n.current.keys()]) (t === e || t.startsWith(`${e}/`)) && n.current.delete(t);
353
- u((t) => t === e || t.startsWith(`${e}/`) ? d : t);
354
- }
355
- }), [
356
- v,
357
- c,
358
- l,
359
- a,
360
- b,
361
- n,
362
- r,
363
- t,
364
- o,
365
- u,
366
- p
367
- ]),
368
- pendingManifestImport: m,
369
- resolveManifestImport: w
370
- };
371
- };
372
- //#endregion
373
- export { k as a, F as i, L as n, O as o, A as r, R as t };