@epam/ai-dial-chat-hooks 1.2.0-dev.99 → 1.3.0-dev.5

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 (84) hide show
  1. package/api-error/api-error.js +7 -4
  2. package/catalog/catalog-derivations.js +1 -1
  3. package/catalog/deployment-id.js +8 -2
  4. package/catalog/map-deployment-limits-to-catalog.js +16 -24
  5. package/catalog/map-deployment-limits-to-input.js +81 -9
  6. package/catalog/map-deployment-to-catalog-item.js +34 -34
  7. package/catalog/map-entity-details-to-catalog.js +237 -192
  8. package/catalog/map-skill-to-catalog-item.js +61 -54
  9. package/catalog/publish.js +4 -4
  10. package/catalog/useCatalogEditNavigation/useCatalogEditNavigation.js +122 -101
  11. package/catalog/useCatalogItemDetails.js +9 -8
  12. package/catalog/usePublishFolders/usePublishFolders.js +1 -1
  13. package/catalog.d.ts +171 -34
  14. package/catalog.js +23 -23
  15. package/conversation/conversation-transfer/export-conversation.js +24 -16
  16. package/conversation/conversation-transfer/import-conversation.js +80 -31
  17. package/conversation/create-chat-stream-api.js +89 -49
  18. package/conversation/get-model-id-from-conversation-id.js +15 -9
  19. package/conversation/message-utils.js +44 -2
  20. package/conversation/stage.js +6 -2
  21. package/conversation/useActiveConversationSync/useActiveConversationSync.js +7 -8
  22. package/conversation/useConversationExport/useConversationExport.js +9 -9
  23. package/conversation/useConversationHandlers/message-utils.js +8 -5
  24. package/conversation/useConversationHandlers/useConversationHandlers.js +181 -167
  25. package/conversation/useConversationImport/useConversationImport.js +123 -121
  26. package/conversation/useConversationPanelItems/useConversationPanelItems.js +49 -31
  27. package/conversation/useConversationStream/frame-scheduler.js +39 -0
  28. package/conversation/useConversationStream/generation-resume.js +122 -64
  29. package/conversation/useConversationStream/useConversationStream.js +298 -118
  30. package/conversation/useMessageSelectionReply/useMessageSelectionReply.js +189 -0
  31. package/conversation-sources/useConversationSources/useConversationSources.js +31 -24
  32. package/conversation-sources.d.ts +1 -1
  33. package/conversation-transfer.d.ts +2 -1
  34. package/conversation.d.ts +218 -22
  35. package/conversation.js +32 -31
  36. package/file-manager-canvas.d.ts +27 -7
  37. package/file-manager.d.ts +87 -32
  38. package/file-manager.js +25 -24
  39. package/files/attachment-canvas.js +67 -44
  40. package/files/dial-file-manager-copy-move.util.js +9 -8
  41. package/files/dial-file-manager-mapping.util.js +2 -1
  42. package/files/dial-file-manager-path.util.js +24 -2
  43. package/files/dial-file-manager.model.js +23 -19
  44. package/files/dial-file-manager.types.js +3 -3
  45. package/files/file-manager-variant.js +1 -1
  46. package/files/resolve-dial-file-api-path.js +11 -12
  47. package/files/useDialFileListing/useDialFileListing.js +140 -127
  48. package/files/useDialFileManager/useDialFileManager.js +139 -135
  49. package/files/useDialFileManagerSections/useDialFileManagerSections.js +155 -0
  50. package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.js +20 -15
  51. package/files/useDialFileMutations/useDialFileMutations.js +65 -60
  52. package/files/useDialFileUploadBatch/useDialFileUploadBatch.js +117 -110
  53. package/files/useFileAttachmentPicker/useFileAttachmentPicker.js +28 -23
  54. package/index.d.ts +643 -128
  55. package/index.js +136 -134
  56. package/mcp-apps/useMcpAppTools/useMcpAppTools.js +1 -1
  57. package/oauth/authorize-url.js +3 -3
  58. package/oauth/toolset-id.js +5 -3
  59. package/oauth/useToolsetLogin/useToolsetLogin.js +8 -8
  60. package/oauth.d.ts +34 -2
  61. package/oauth.js +9 -9
  62. package/package.json +19 -23
  63. package/scheduled-task/scheduled-task-description.js +43 -39
  64. package/scheduled-task/scheduled-task-trigger.js +74 -71
  65. package/scheduled-task/use-scheduled-task-runs.js +162 -50
  66. package/scheduled-task/use-scheduled-tasks.js +52 -48
  67. package/scheduled-tasks.d.ts +27 -6
  68. package/scheduled-tasks.js +2 -2
  69. package/shared/application-schema.js +5 -2
  70. package/shared/cron-day-of-month.js +13 -0
  71. package/skill/skill-archive.js +19 -0
  72. package/skill/skill-types.js +8 -7
  73. package/skill/skill.js +52 -29
  74. package/skill/useSkillArchiveImport/useSkillArchiveImport.js +38 -34
  75. package/skill/useSkillEditorLoad.js +65 -59
  76. package/skill/useSkillEditorSubmit.js +105 -93
  77. package/skill/useSkillFileActions.js +70 -58
  78. package/skill-editor.d.ts +62 -13
  79. package/skill-editor.js +9 -9
  80. package/usage/map-user-usage-to-model-limits.js +137 -95
  81. package/usage.d.ts +8 -3
  82. package/usePageFileDrag/usePageFileDrag.js +3 -3
  83. package/utils.d.ts +26 -6
  84. package/utils.js +10 -10
@@ -1,103 +1,109 @@
1
1
  import { getApiErrorStatus as e } from "../api-error/api-error.js";
2
2
  import { stripSurroundingSlashes as t, stripTrailingSlashes as n } from "../shared/string-utils.js";
3
- import { SKILL_MANIFEST_FILE as r, nameFromPath as i, parseSkillManifest as a, unpackSkillArchive as o } from "./skill.js";
4
- import { useEffect as s, useRef as c, useState as l } from "react";
5
- import { SkillFileNodeKind as u } from "@epam/ai-dial-skill-editor";
3
+ import { SKILL_FOLDER_MARKER as r, SKILL_MANIFEST_FILE as i, isSkillFolderMarkerPath as a, nameFromPath as o, parseSkillManifest as s, skillFolderMarkerParent as c, unpackSkillArchive as l } from "./skill.js";
4
+ import { useEffect as u, useRef as d, useState as f } from "react";
5
+ import { SkillFileNodeKind as p } from "@epam/ai-dial-skill-editor";
6
6
  //#region src/skill/useSkillEditorLoad.ts
7
- var d = /* @__PURE__ */ function(e) {
7
+ var m = /* @__PURE__ */ function(e) {
8
8
  return e.Loading = "loading", e.Loaded = "loaded", e.Error = "error", e.Forbidden = "forbidden", e.NotFound = "not-found", e;
9
- }({}), f = class extends Error {}, p = (e, r) => {
9
+ }({}), h = class extends Error {}, g = class extends Error {}, _ = (e, r) => {
10
10
  let i = e.parentPath ? t(e.parentPath) : "", a = `${n(r)}/files`;
11
11
  return i === a ? e.name : i.startsWith(`${a}/`) ? `${i.slice(a.length + 1)}/${e.name}` : i === "files" ? e.name : i.startsWith("files/") ? `${i.slice(6)}/${e.name}` : null;
12
- }, m = async (e, t, n) => {
12
+ }, v = async (e, t, n) => {
13
13
  let r = await e.downloadSkill(t, n), i = r.headers.get("etag");
14
- if (!i) throw new f("Skill ETag is missing");
14
+ if (!i) throw new g("Skill ETag is missing");
15
15
  try {
16
- let e = await r.arrayBuffer(), { manifestText: t, files: n } = o(new Uint8Array(e));
16
+ let e = await r.arrayBuffer(), { manifestText: t, files: n, folders: a } = l(new Uint8Array(e));
17
17
  return {
18
18
  etag: i,
19
19
  manifestText: t,
20
- files: n
20
+ files: n,
21
+ folders: a
21
22
  };
22
23
  } catch {
23
- throw new f("Skill ZIP is invalid");
24
+ throw new h("Skill ZIP is invalid");
24
25
  }
25
- }, h = async (e, t, n) => {
26
- let [i, a] = await Promise.all([e.downloadSkillFile(t, n, r), e.listSkillFiles({
26
+ }, y = async (e, t, n) => {
27
+ let [s, l] = await Promise.all([e.downloadSkillFile(t, n, i), e.listSkillFiles({
27
28
  bucket: t,
28
29
  path: n,
29
30
  filePath: "",
30
31
  recursive: !0
31
- })]), o = a.items.find((e) => e.nodeType === "item" && p(e, n) === "SKILL.md"), s = i.headers.get("etag") ?? o?.etag;
32
- if (!s) throw Error("Skill ETag is missing");
33
- let c = a.items.filter((e) => e.nodeType === "item").map((e) => ({
34
- item: e,
35
- path: p(e, n)
36
- })).filter((e) => e.path != null && e.path !== "SKILL.md"), l = await Promise.all(c.map(async ({ path: r }) => {
32
+ })]), u = l.items.find((e) => e.nodeType === "item" && _(e, n) === "SKILL.md"), d = s.headers.get("etag") ?? u?.etag;
33
+ if (!d) throw new g("Skill ETag is missing");
34
+ let f = l.items.filter((e) => e.nodeType === "item").map((e) => _(e, n)).filter((e) => e != null && e !== "SKILL.md"), p = f.filter(a).map(c), m = f.filter((e) => o(e) !== r), h = await Promise.all(m.map(async (r) => {
37
35
  let i = await e.downloadSkillFile(t, n, r);
38
36
  return [r, new Uint8Array(await i.arrayBuffer())];
39
37
  }));
40
38
  return {
41
- etag: s,
42
- manifestText: await i.text(),
43
- files: new Map(l)
39
+ etag: d,
40
+ manifestText: await s.text(),
41
+ files: new Map(h),
42
+ folders: p
44
43
  };
45
- }, g = ({ isEditMode: t, bucket: n, skillPath: r, client: o }) => {
46
- let [d, p] = l(t ? "loading" : "loaded"), [g, _] = l(0), [v, y] = l(), b = c(void 0), x = c({}), S = c(void 0), [C, w] = l([]), T = c(/* @__PURE__ */ new Map());
47
- return s(() => {
44
+ }, b = ({ isEditMode: t, bucket: n, skillPath: r, client: i }) => {
45
+ let [a, c] = f(t ? "loading" : "loaded"), [l, m] = f(0), [_, b] = f(), x = d(void 0), S = d({}), C = d(void 0), [w, T] = f([]), E = d(/* @__PURE__ */ new Map());
46
+ return u(() => {
48
47
  if (!t || !n) return;
49
48
  if (r == null) {
50
- p("error");
49
+ c("error");
51
50
  return;
52
51
  }
53
- let s = !1;
54
- return p("loading"), (async () => {
55
- if (await Promise.resolve(), !s) try {
52
+ let a = !1;
53
+ return c("loading"), (async () => {
54
+ if (await Promise.resolve(), !a) try {
56
55
  let t;
57
56
  try {
58
- t = await m(o, n, r);
59
- } catch (i) {
60
- let a = e(i);
61
- if (!(i instanceof f) && a !== 400) throw i;
62
- t = await h(o, n, r);
57
+ t = await v(i, n, r);
58
+ } catch (a) {
59
+ if (a instanceof g) throw a;
60
+ let o = e(a);
61
+ if (!(a instanceof h) && o !== 400) throw a;
62
+ t = await y(i, n, r);
63
63
  }
64
- let { frontmatter: c, instructions: l } = a(t.manifestText);
65
- if (s) return;
66
- b.current = t.etag, x.current = c, S.current = r, T.current = new Map([...t.files].map(([e, t]) => [e, { bytes: t }])), w([...t.files.keys()].map((e) => ({
64
+ let { frontmatter: l, instructions: u } = s(t.manifestText);
65
+ if (a) return;
66
+ x.current = t.etag, S.current = l, C.current = r, E.current = new Map([...t.files].map(([e, t]) => [e, { bytes: t }]));
67
+ let d = [...t.files.keys()].map((e) => ({
67
68
  path: e,
68
- name: i(e),
69
- kind: u.File
70
- }))), y({
71
- name: typeof c.name == "string" ? c.name : "",
72
- description: typeof c.description == "string" ? c.description : "",
73
- instructions: l
74
- }), p("loaded");
69
+ name: o(e),
70
+ kind: p.File
71
+ })), f = t.folders.filter((e) => !t.files.has(e)).map((e) => ({
72
+ path: e,
73
+ name: o(e),
74
+ kind: p.Folder
75
+ }));
76
+ T([...d, ...f]), b({
77
+ name: typeof l.name == "string" ? l.name : "",
78
+ description: typeof l.description == "string" ? l.description : "",
79
+ instructions: u
80
+ }), c("loaded");
75
81
  } catch (t) {
76
- if (s) return;
82
+ if (a) return;
77
83
  let n = e(t);
78
- p(n === 403 ? "forbidden" : n === 404 ? "not-found" : "error");
84
+ c(n === 403 ? "forbidden" : n === 404 ? "not-found" : "error");
79
85
  }
80
86
  })(), () => {
81
- s = !0;
87
+ a = !0;
82
88
  };
83
89
  }, [
84
90
  t,
85
91
  n,
86
92
  r,
87
- g,
88
- o
93
+ l,
94
+ i
89
95
  ]), {
90
- loadState: d,
91
- loadedValues: v,
92
- setLoadedValues: y,
93
- files: C,
94
- setFiles: w,
95
- filesContentRef: T,
96
- frontmatterRef: x,
97
- etagRef: b,
98
- loadedPathRef: S,
99
- retryLoad: () => _((e) => e + 1)
96
+ loadState: a,
97
+ loadedValues: _,
98
+ setLoadedValues: b,
99
+ files: w,
100
+ setFiles: T,
101
+ filesContentRef: E,
102
+ frontmatterRef: S,
103
+ etagRef: x,
104
+ loadedPathRef: C,
105
+ retryLoad: () => m((e) => e + 1)
100
106
  };
101
107
  };
102
108
  //#endregion
103
- export { d as SkillEditorLoadState, g as useSkillEditorLoad };
109
+ export { m as SkillEditorLoadState, b as useSkillEditorLoad };
@@ -1,147 +1,159 @@
1
1
  import { getApiErrorDetails as e, getApiErrorStatus as t } from "../api-error/api-error.js";
2
- import { buildSkillFilesPayload as n, buildSkillManifestForSubmit as r, isValidSkillRelativePath as i, normalizeSkillName as a, startsWithFrontmatterBlock as o } from "./skill.js";
3
- import { useCallback as s, useRef as c, useState as l } from "react";
4
- import { NotificationVariant as u } from "@epam/ai-dial-ui-kit";
2
+ import { SKILL_TEXT_FIELD_MAX_LENGTHS as n, buildSkillFilesPayload as r, buildSkillManifestForSubmit as i, getSkillFieldLengthViolations as a, isValidSkillRelativePath as o, normalizeSkillName as s, startsWithFrontmatterBlock as c } from "./skill.js";
3
+ import { useCallback as l, useRef as u, useState as d } from "react";
4
+ import { NotificationVariant as f } from "@epam/ai-dial-ui-kit";
5
5
  //#region src/skill/useSkillEditorSubmit.ts
6
- var d = (e, t) => JSON.stringify({
6
+ var p = (e, t) => JSON.stringify({
7
7
  values: e,
8
8
  files: [...t].sort((e, t) => e.path.localeCompare(t.path))
9
- }), f = ({ bucket: f, isEditMode: p, files: m, filesContentRef: h, frontmatterRef: g, loadedPathRef: _, etagRef: v, returnUrl: y, refetchSkills: b, client: x, messages: S, onNavigate: C, onNotify: w }) => {
10
- let [T, E] = l({}), [D, O] = l(), [k, A] = l(), [j, M] = l("idle"), N = c(null), P = s(async (n) => {
9
+ }), m = ({ bucket: m, isEditMode: h, files: g, filesContentRef: _, frontmatterRef: v, loadedPathRef: y, etagRef: b, returnUrl: x, getCreateReturnUrl: S, refetchSkills: C, client: w, messages: T, onNavigate: E, onNotify: D }) => {
10
+ let [O, k] = d({}), [A, j] = d(), [M, N] = d(!1), [P, F] = d(), [I, L] = d("idle"), R = u(null), z = u(null), B = l(async (n) => {
11
11
  switch (t(n)) {
12
12
  case 409:
13
- E({ name: S.nameConflict });
13
+ k({ name: T.nameConflict });
14
14
  return;
15
15
  case 412:
16
- E({ name: S.nameConflict });
16
+ k({ name: T.nameConflict });
17
17
  return;
18
18
  case 413:
19
- O(S.archiveTooLarge);
19
+ j(T.archiveTooLarge);
20
20
  return;
21
21
  case 503:
22
- O(S.serviceUnavailable);
22
+ j(T.serviceUnavailable), N(!0);
23
23
  return;
24
24
  case 400: {
25
25
  let { message: t } = await e(n);
26
- O(t ?? S.pathInvalid);
26
+ j(t ?? T.pathInvalid);
27
27
  return;
28
28
  }
29
29
  default: {
30
30
  let { traceId: t } = await e(n);
31
- O(S.saveError), w({
32
- variant: u.Error,
33
- message: S.saveError,
31
+ j(T.saveError), D({
32
+ variant: f.Error,
33
+ message: T.saveError,
34
34
  requestId: t
35
35
  });
36
36
  }
37
37
  }
38
- }, [S, w]), F = s(async (e) => {
39
- let t = a(e.name);
40
- if (!t || !i(t)) {
41
- E({ name: S.nameInvalid });
38
+ }, [T, D]), V = l(async (e) => {
39
+ let t = s(e.name);
40
+ if (!t || !o(t)) {
41
+ k({ name: T.nameInvalid });
42
42
  return;
43
43
  }
44
- let o = d(e, m), s = N.current, c = s != null && s.fingerprint === o, l = t, p, _, v;
45
- c ? {skillManifest: p, filePaths: _, files: v} = s : (p = r(g.current, t, e.description, e.instructions), {filePaths: _, files: v} = n(m, h.current)), M("submitting"), N.current = {
46
- fingerprint: o,
47
- bucket: f,
44
+ let n = p(e, g), a = R.current, c = a != null && a.fingerprint === n, l = t, u, d, h;
45
+ c ? {skillManifest: u, filePaths: d, files: h} = a : (u = i(v.current, t, e.description, e.instructions), {filePaths: d, files: h} = r(g, _.current)), L("submitting"), R.current = {
46
+ fingerprint: n,
47
+ bucket: m,
48
48
  path: l,
49
- skillManifest: p,
50
- filePaths: _,
51
- files: v
49
+ skillManifest: u,
50
+ filePaths: d,
51
+ files: h
52
52
  };
53
53
  try {
54
- await x.createSkill(f, l, p, _, v), await b(), M("success"), w({
55
- variant: u.Success,
56
- title: S.saveSuccessTitle,
57
- message: S.createSuccess(t)
58
- }), C(y);
54
+ await w.createSkill(m, l, u, d, h), await C(), L("success"), D({
55
+ variant: f.Success,
56
+ title: T.saveSuccessTitle,
57
+ message: T.createSuccess(t)
58
+ }), E(S?.(l) ?? x);
59
59
  } catch (e) {
60
- M("failure"), await P(e);
60
+ L("failure"), await B(e);
61
61
  }
62
62
  }, [
63
- f,
64
63
  m,
65
- h,
66
64
  g,
67
- S,
68
- x,
65
+ _,
66
+ v,
67
+ T,
69
68
  w,
69
+ D,
70
+ E,
71
+ x,
72
+ S,
70
73
  C,
71
- y,
72
- b,
73
- P
74
- ]), I = s(async (e) => {
75
- let i = _.current, a = v.current;
76
- if (!i || !a) {
77
- O(S.saveError);
74
+ B
75
+ ]), H = l(async (e) => {
76
+ let n = y.current, a = b.current;
77
+ if (!n || !a) {
78
+ j(T.saveError);
78
79
  return;
79
80
  }
80
- let o = r(g.current, e.name, e.description, e.instructions), { filePaths: s, files: c } = n(m, h.current);
81
- M("submitting");
81
+ let o = i(v.current, e.name, e.description, e.instructions), { filePaths: s, files: c } = r(g, _.current);
82
+ L("submitting");
82
83
  try {
83
- v.current = (await x.updateSkill(f, i, o, s, c, a)).etag ?? a, await b(), M("success"), w({
84
- variant: u.Success,
85
- title: S.updateSuccessTitle,
86
- message: S.updateSuccess(e.name)
87
- }), C(y);
84
+ b.current = (await w.updateSkill(m, n, o, s, c, a)).etag ?? a, await C(), L("success"), D({
85
+ variant: f.Success,
86
+ title: T.updateSuccessTitle,
87
+ message: T.updateSuccess(e.name)
88
+ }), E(x);
88
89
  } catch (e) {
89
- if (M("failure"), t(e) === 412) {
90
- A({ message: S.conflictMessage });
90
+ if (L("failure"), t(e) === 412) {
91
+ F({ message: T.conflictMessage });
91
92
  return;
92
93
  }
93
- await P(e);
94
+ await B(e);
94
95
  }
95
96
  }, [
96
- f,
97
97
  m,
98
- h,
99
98
  g,
100
99
  _,
101
100
  v,
102
- S,
103
- x,
104
- w,
105
- C,
106
101
  y,
107
102
  b,
108
- P
109
- ]), L = s((e) => {
110
- let t = o(e.instructions);
111
- E((e) => {
112
- if (t === (e.instructions === S.instructionsFrontmatter)) return e;
113
- if (t) return {
114
- ...e,
115
- instructions: S.instructionsFrontmatter
116
- };
117
- let n = { ...e };
118
- return delete n.instructions, n;
103
+ T,
104
+ w,
105
+ D,
106
+ E,
107
+ x,
108
+ C,
109
+ B
110
+ ]), U = l((e) => {
111
+ let t = c(e.instructions), r = a(e);
112
+ k((e) => {
113
+ let i = { ...e };
114
+ for (let e of Object.keys(n)) {
115
+ let t = T.tooLong(n[e]);
116
+ r[e] ? i[e] = t : i[e] === t && delete i[e];
117
+ }
118
+ if (!r.instructions) {
119
+ let e = i.instructions === T.instructionsFrontmatter;
120
+ t && !e ? i.instructions = T.instructionsFrontmatter : !t && e && delete i.instructions;
121
+ }
122
+ return Object.keys(i).length === Object.keys(e).length && Object.keys(i).every((t) => i[t] === e[t]) ? e : i;
119
123
  });
120
- }, [S]);
124
+ }, [T]), W = l(async (e) => {
125
+ if (I === "submitting" || !m) return;
126
+ let t = {};
127
+ e.name.trim() || (t.name = T.required), e.description.trim() || (t.description = T.required), e.instructions.trim() ? c(e.instructions) && (t.instructions = T.instructionsFrontmatter) : t.instructions = T.required;
128
+ let r = a(e);
129
+ for (let e of Object.keys(r)) t[e] ??= T.tooLong(n[e]);
130
+ if (Object.keys(t).length > 0) {
131
+ k(t);
132
+ return;
133
+ }
134
+ k({}), j(void 0), N(!1), F(void 0), z.current = e, h ? await H(e) : await V(e);
135
+ }, [
136
+ I,
137
+ m,
138
+ T,
139
+ h,
140
+ H,
141
+ V
142
+ ]);
121
143
  return {
122
- phase: j,
123
- errors: T,
124
- submitError: D,
125
- conflict: k,
126
- clearConflict: () => A(void 0),
127
- handleSubmit: s(async (e) => {
128
- if (j === "submitting" || !f) return;
129
- let t = {};
130
- if (e.name.trim() || (t.name = S.required), e.description.trim() || (t.description = S.required), e.instructions.trim() ? o(e.instructions) && (t.instructions = S.instructionsFrontmatter) : t.instructions = S.required, Object.keys(t).length > 0) {
131
- E(t);
132
- return;
133
- }
134
- E({}), O(void 0), A(void 0), p ? await I(e) : await F(e);
135
- }, [
136
- j,
137
- f,
138
- S,
139
- p,
140
- I,
141
- F
142
- ]),
143
- handleValuesChange: L
144
+ phase: I,
145
+ errors: O,
146
+ submitError: A,
147
+ isSubmitErrorRetryable: M,
148
+ retrySubmit: l(() => {
149
+ let e = z.current;
150
+ e != null && W(e);
151
+ }, [W]),
152
+ conflict: P,
153
+ clearConflict: () => F(void 0),
154
+ handleSubmit: W,
155
+ handleValuesChange: U
144
156
  };
145
157
  };
146
158
  //#endregion
147
- export { f as useSkillEditorSubmit };
159
+ export { m as useSkillEditorSubmit };
@@ -1,99 +1,111 @@
1
- import { SKILL_MANIFEST_FILE as e, buildSkillManifest as t, buildSkillManifestFromFrontmatter as n, nameFromPath as r } from "./skill.js";
2
- import { validateSkillFileBatch as i } from "./skill-file-batch-validation.js";
3
- import { getUtf8ByteLength as a } from "@epam/ai-dial-chat-shared";
4
- import { useCallback as o, useMemo as s, useRef as c, useState as l } from "react";
5
- import { SkillFileNodeKind as u } from "@epam/ai-dial-skill-editor";
1
+ import { SKILL_MANIFEST_FILE as e, buildSkillManifest as t, buildSkillManifestFromFrontmatter as n, isValidSkillRelativePath as r, nameFromPath as i } from "./skill.js";
2
+ import { validateSkillFileBatch as a } from "./skill-file-batch-validation.js";
3
+ import { extractSkillArchive as o } from "./skill-archive.js";
4
+ import { getUtf8ByteLength as s } from "@epam/ai-dial-chat-shared";
5
+ import { useCallback as c, useMemo as l, useRef as u, useState as d } from "react";
6
+ import { SkillFileNodeKind as f } from "@epam/ai-dial-skill-editor";
6
7
  //#region src/skill/useSkillFileActions.ts
7
- var d = ({ files: d, setFiles: f, filesContentRef: p, frontmatterRef: m, loadedValues: h, setLoadedValues: g, isEditMode: _, isDirty: v, setSelectedPath: y, messages: b }) => {
8
- let [x, S] = l(!1), C = c(null), w = o(() => {
9
- let e = d.filter((e) => e.kind === u.File).map((e) => e.path), r = 0;
10
- for (let t of e) r += p.current.get(t)?.bytes.length ?? 0;
8
+ var p = "probe", m = ({ files: m, setFiles: h, filesContentRef: g, frontmatterRef: _, loadedValues: v, setLoadedValues: y, isEditMode: b, isDirty: x, setSelectedPath: S, messages: C, pickFromFileSystem: w }) => {
9
+ let [T, E] = d(!1), D = u(null), O = c(() => {
10
+ let e = m.filter((e) => e.kind === f.File).map((e) => e.path), r = 0;
11
+ for (let t of e) r += g.current.get(t)?.bytes.length ?? 0;
11
12
  let i = {
12
- name: h?.name ?? "",
13
- description: h?.description ?? "",
14
- instructions: h?.instructions ?? ""
15
- }, o = _ ? n(m.current, i.name, i.description, i.instructions) : t(i);
13
+ name: v?.name ?? "",
14
+ description: v?.description ?? "",
15
+ instructions: v?.instructions ?? ""
16
+ }, a = b ? n(_.current, i.name, i.description, i.instructions) : t(i);
16
17
  return {
17
18
  existingPaths: e,
18
19
  existingTotalBytes: r,
19
- manifestByteLength: a(o),
20
- messages: b
20
+ manifestByteLength: s(a),
21
+ messages: C
21
22
  };
22
23
  }, [
23
- d,
24
- p,
25
- _,
26
24
  m,
27
- h,
28
- b
29
- ]), T = o(() => new Promise((e) => {
30
- C.current = e, S(!0);
31
- }), []), E = o((e) => {
32
- S(!1), C.current?.(e), C.current = null;
25
+ g,
26
+ b,
27
+ _,
28
+ v,
29
+ C
30
+ ]), k = c(() => new Promise((e) => {
31
+ D.current = e, E(!0);
32
+ }), []), A = c((e) => {
33
+ E(!1), D.current?.(e), D.current = null;
33
34
  }, []);
34
35
  return {
35
- fileActions: s(() => ({
36
+ fileActions: l(() => ({
36
37
  validateBatch: async (e) => {
37
- let { results: t, batchErrors: n } = await i(e, w());
38
+ let { results: t, batchErrors: n } = await a(e, O());
38
39
  return {
39
40
  results: t,
40
41
  batchErrors: n
41
42
  };
42
43
  },
43
44
  commitBatch: async (e) => {
44
- let { results: t, batchErrors: n, manifestCandidate: a } = await i(e, w());
45
- if (t.some((e) => e.error !== void 0) || n.length > 0) return { error: n[0]?.message ?? b.saveError };
46
- if (a) {
47
- if (_ && a.name !== (h?.name ?? "")) return { error: b.manifestNameMismatch };
48
- if ((_ || v) && !await T()) return { error: b.manifestImportDeclined };
45
+ let { results: t, batchErrors: n, manifestCandidate: r } = await a(e, O());
46
+ if (t.some((e) => e.error !== void 0) || n.length > 0) return { error: n[0]?.message ?? C.saveError };
47
+ if (r) {
48
+ if (b && r.name !== (v?.name ?? "")) return { error: C.manifestNameMismatch };
49
+ if ((b || x) && !await k()) return { error: C.manifestImportDeclined };
49
50
  }
50
51
  try {
51
- let t = e.filter((e) => e.id !== a?.candidateId), n = await Promise.all(t.map(async (e) => ({
52
+ let t = e.filter((e) => e.id !== r?.candidateId), n = await Promise.all(t.map(async (e) => ({
52
53
  path: e.path,
53
54
  bytes: new Uint8Array(await e.file.arrayBuffer()),
54
55
  mimeType: e.file.type || void 0
55
56
  })));
56
- for (let e of n) p.current.set(e.path, {
57
+ for (let e of n) g.current.set(e.path, {
57
58
  bytes: e.bytes,
58
59
  mimeType: e.mimeType
59
60
  });
60
- return n.length > 0 && f((e) => [...e, ...n.map((e) => ({
61
+ return n.length > 0 && h((e) => [...e, ...n.map((e) => ({
61
62
  path: e.path,
62
- name: r(e.path),
63
- kind: u.File
64
- }))]), a && (m.current = _ ? {
65
- ...m.current,
66
- ...a.frontmatter
67
- } : a.frontmatter, g({
68
- name: _ ? h?.name ?? a.name : a.name,
69
- description: a.description,
70
- instructions: a.instructions
63
+ name: i(e.path),
64
+ kind: f.File
65
+ }))]), r && (_.current = b ? {
66
+ ..._.current,
67
+ ...r.frontmatter
68
+ } : r.frontmatter, y({
69
+ name: b ? v?.name ?? r.name : r.name,
70
+ description: r.description,
71
+ instructions: r.instructions
71
72
  })), {};
72
73
  } catch (e) {
73
74
  return { error: e instanceof Error ? e.message : String(e) };
74
75
  }
75
76
  },
76
77
  onRemoveNode: (t) => {
77
- f((e) => e.filter((e) => e.path !== t && !e.path.startsWith(`${t}/`)));
78
- for (let e of [...p.current.keys()]) (e === t || e.startsWith(`${t}/`)) && p.current.delete(e);
79
- y((n) => n === t || n.startsWith(`${t}/`) ? e : n);
80
- }
78
+ h((e) => e.filter((e) => e.path !== t && !e.path.startsWith(`${t}/`)));
79
+ for (let e of [...g.current.keys()]) (e === t || e.startsWith(`${t}/`)) && g.current.delete(e);
80
+ S((n) => n === t || n.startsWith(`${t}/`) ? e : n);
81
+ },
82
+ onCreateFolder: (e) => {
83
+ h((t) => t.some((t) => t.path === e) ? t : [...t, {
84
+ path: e,
85
+ name: i(e),
86
+ kind: f.Folder
87
+ }]);
88
+ },
89
+ validateFolderPath: (e) => r(`${e}/${p}`) ? void 0 : C.pathInvalid,
90
+ extractArchive: o,
91
+ pickFromFileSystem: w
81
92
  }), [
82
- w,
83
- _,
93
+ O,
94
+ b,
95
+ x,
84
96
  v,
85
- h,
86
- T,
87
- p,
88
- m,
89
- f,
97
+ k,
90
98
  g,
99
+ _,
100
+ h,
91
101
  y,
92
- b
102
+ S,
103
+ C,
104
+ w
93
105
  ]),
94
- pendingManifestImport: x,
95
- resolveManifestImport: E
106
+ pendingManifestImport: T,
107
+ resolveManifestImport: A
96
108
  };
97
109
  };
98
110
  //#endregion
99
- export { d as useSkillFileActions };
111
+ export { m as useSkillFileActions };