@epam/ai-dial-chat-hooks 1.2.0-dev.2 → 1.2.0-dev.201

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 (92) hide show
  1. package/api-error/api-error.js +5 -4
  2. package/attachment/useAttachmentValidation/useAttachmentValidation.js +26 -19
  3. package/attachments.d.ts +10 -4
  4. package/catalog/catalog-derivations.js +1 -1
  5. package/catalog/deployment-id.js +8 -2
  6. package/catalog/map-deployment-limits-to-input.js +81 -9
  7. package/catalog/map-deployment-to-catalog-item.js +34 -34
  8. package/catalog/map-entity-details-to-catalog.js +7 -0
  9. package/catalog/map-skill-to-catalog-item.js +30 -27
  10. package/catalog/publish.js +6 -5
  11. package/catalog/useApplicationCredentials/useApplicationCredentials.js +39 -0
  12. package/catalog/useSkillDetailsPanelData/useSkillDetailsPanelData.js +39 -39
  13. package/catalog/useSkillItemDetails.js +19 -17
  14. package/catalog.d.ts +134 -20
  15. package/catalog.js +23 -22
  16. package/conversation/announcement-message.js +16 -5
  17. package/conversation/conversation-transfer/export-conversation.js +24 -16
  18. package/conversation/conversation-transfer/import-conversation.js +80 -31
  19. package/conversation/conversation-transfer/queue.js +8 -5
  20. package/conversation/create-chat-stream-api.js +85 -49
  21. package/conversation/message-utils.js +44 -2
  22. package/conversation/stage.js +23 -0
  23. package/conversation/useAttachmentUpload/useAttachmentUpload.js +12 -5
  24. package/conversation/useConversationExport/useConversationExport.js +9 -9
  25. package/conversation/useConversationHandlers/useConversationHandlers.js +13 -17
  26. package/conversation/useConversationImport/useConversationImport.js +123 -121
  27. package/conversation/useConversationPanelItems/useConversationPanelItems.js +2 -3
  28. package/conversation/useConversationScroll/useConversationScroll.js +68 -64
  29. package/conversation/useConversationStream/apply-chunk.js +1 -1
  30. package/conversation/useConversationStream/generation-resume.js +104 -63
  31. package/conversation/useConversationStream/useConversationStream.js +183 -108
  32. package/conversation/useMessageSelectionReply/useMessageSelectionReply.js +189 -0
  33. package/conversation/useTranscribeAudio/transcription-retry.js +5 -4
  34. package/conversation-overlay.d.ts +7 -0
  35. package/conversation-overlay.js +2 -0
  36. package/conversation-sources/useConversationSources/useConversationSources.js +31 -24
  37. package/conversation-sources.d.ts +1 -1
  38. package/conversation-transfer.d.ts +2 -1
  39. package/conversation.d.ts +274 -17
  40. package/conversation.js +32 -30
  41. package/file-manager-canvas.d.ts +398 -0
  42. package/file-manager-canvas.js +2 -0
  43. package/file-manager.d.ts +153 -348
  44. package/file-manager.js +25 -24
  45. package/files/attachment-canvas.js +51 -13
  46. package/files/attachment-types.js +14 -13
  47. package/files/dial-file-manager-mapping.util.js +2 -1
  48. package/files/dial-file-manager-path.util.js +23 -1
  49. package/files/dial-file-manager.model.js +23 -19
  50. package/files/dial-file-manager.types.js +3 -3
  51. package/files/useDialFileListing/useDialFileListing.js +157 -145
  52. package/files/useDialFileManager/useDialFileManager.js +132 -128
  53. package/files/useDialFileManagerSections/useDialFileManagerSections.js +155 -0
  54. package/files/useDialFileManagerTabConfig/useDialFileManagerTabConfig.js +20 -19
  55. package/files/useDialFileMutations/useDialFileMutations.js +33 -32
  56. package/files/useDialFileUploadBatch/useDialFileUploadBatch.js +117 -110
  57. package/files/useFileAttachmentPicker/useFileAttachmentPicker.js +43 -0
  58. package/index.d.ts +1124 -90
  59. package/index.js +136 -122
  60. package/mcp-apps/useMcpAppHostAdapter/useMcpAppHostAdapter.js +7 -5
  61. package/mcp-apps/useMcpAppHostContext/useMcpAppHostContext.js +1 -1
  62. package/mcp-apps/useMcpAppTools/useMcpAppTools.js +1 -1
  63. package/mcp-apps/useOpenMcpAppCanvas/useOpenMcpAppCanvas.js +25 -23
  64. package/mcp-apps.d.ts +8 -6
  65. package/oauth/toolset-id.js +5 -3
  66. package/oauth/useToolsetLogin/useToolsetLogin.js +8 -8
  67. package/oauth.d.ts +32 -0
  68. package/oauth.js +9 -9
  69. package/package.json +36 -21
  70. package/scheduled-task/scheduled-task-description.js +77 -0
  71. package/scheduled-task/scheduled-task-preparation.js +24 -0
  72. package/scheduled-task/scheduled-task-trigger.js +7 -2
  73. package/scheduled-task/scheduled-tasks-api-client.js +19 -0
  74. package/scheduled-task/use-scheduled-task-runs.js +194 -0
  75. package/scheduled-task/use-scheduled-tasks.js +93 -0
  76. package/scheduled-tasks.d.ts +195 -3
  77. package/scheduled-tasks.js +7 -2
  78. package/skill/skill-archive.js +19 -0
  79. package/skill/skill-types.js +8 -7
  80. package/skill/skill.js +42 -27
  81. package/skill/useSkillArchiveImport/useSkillArchiveImport.js +75 -0
  82. package/skill/useSkillEditorLoad.js +29 -28
  83. package/skill/useSkillEditorSubmit.js +108 -84
  84. package/skill/useSkillFileActions.js +70 -58
  85. package/skill-editor.d.ts +131 -3
  86. package/skill-editor.js +9 -8
  87. package/usage/map-usage-data-to-dashboard.js +66 -0
  88. package/usage/map-user-usage-to-model-limits.js +202 -0
  89. package/usage.d.ts +125 -0
  90. package/usage.js +3 -0
  91. package/usePageFileDrag/usePageFileDrag.js +3 -3
  92. package/utils.d.ts +8 -6
@@ -1,57 +1,57 @@
1
1
  import { collectAttachmentRefs as e, splitFileIdAnchor as t } from "./attachment-refs.js";
2
2
  import { resolveDialFileBucketAndPath as n } from "./dial-file-resolve.js";
3
- import { generateUUID as r, sanitizeConversationName as i, stripTrailingDots as a, truncateToUtf8Bytes as o } from "@epam/ai-dial-chat-shared";
3
+ import { PUBLIC_BUCKET as r, generateUUID as i, sanitizeConversationName as a, stripTrailingDots as o, truncateToUtf8Bytes as s } from "@epam/ai-dial-chat-shared";
4
4
  //#region src/conversation/conversation-transfer/import-conversation.ts
5
- var s = class extends Error {
5
+ var c = class extends Error {
6
6
  constructor(e) {
7
7
  super(e), this.name = "UnsupportedImportFormatError";
8
8
  }
9
- }, c = (e) => typeof e == "object" && !!e, l = 5, u = (e) => {
9
+ }, l = (e) => typeof e == "object" && !!e, u = 5, d = (e) => {
10
10
  let t;
11
11
  try {
12
12
  t = JSON.parse(e);
13
13
  } catch {
14
- throw new s("Import file is not valid JSON");
14
+ throw new c("Import file is not valid JSON");
15
15
  }
16
- if (!c(t) || t.version !== l || !Array.isArray(t.history)) throw new s("Import file is not a supported export format");
16
+ if (!l(t) || t.version !== u || !Array.isArray(t.history)) throw new c("Import file is not a supported export format");
17
17
  let n = Array.isArray(t.folders) ? t.folders : [];
18
18
  return {
19
- version: l,
19
+ version: u,
20
20
  history: t.history,
21
21
  folders: n
22
22
  };
23
- }, d = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, f = "__", p = 255, m = "applications", h = /[-+]/, g = /^\d+$/, _ = (e) => e ? e.split(h)[0].split(".").every((e) => g.test(e)) : !1, v = (e) => a(o(e.replace(/\r\n|\r/g, "\n").split("\n").map((e) => i(e).trim()).filter(Boolean)[0] ?? "", p)).trimEnd(), y = (e, t, n) => {
24
- let i = e.split(f);
25
- if (i.length < 2) return [e, r()].join(f);
26
- let a = n && _(i[1]) ? i.slice(0, 2) : i.slice(0, 1), o = a.length > 1 ? d.test(i[i.length - 1]) : i.length >= 3, s = i.slice(a.length, o ? -1 : void 0).join(f);
23
+ }, f = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, p = "__", m = 255, h = "applications", g = /[-+]/, _ = /^\d+$/, v = (e) => e ? e.split(g)[0].split(".").every((e) => _.test(e)) : !1, y = (e) => o(s(e.replace(/\r\n|\r/g, "\n").split("\n").map((e) => a(e).trim()).filter(Boolean)[0] ?? "", m)).trimEnd(), b = (e, t, n) => {
24
+ let r = e.split(p);
25
+ if (r.length < 2) return [e, i()].join(p);
26
+ let a = n && v(r[1]) ? r.slice(0, 2) : r.slice(0, 1), o = a.length > 1 ? f.test(r[r.length - 1]) : r.length >= 3, s = r.slice(a.length, o ? -1 : void 0).join(p);
27
27
  return [
28
28
  ...a,
29
29
  t || s,
30
- r()
31
- ].join(f);
32
- }, b = "conversations/", x = (e) => e.startsWith(b) ? e.slice(14) : e, S = (e, t) => {
33
- let n = x(e.id), r = n.split("/"), i = x(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 = s.at(-1) ?? r.at(-1) ?? n, u = [...o, ...c], d = v(e.name), f = y(l, d, u[0] === m), p = [...u, f].join("/"), h = o.length ? `${t}/${o.join("/")}` : t;
30
+ i()
31
+ ].join(p);
32
+ }, x = "conversations/", S = (e) => e.startsWith(x) ? e.slice(14) : e, C = (e, t) => {
33
+ let n = S(e.id), r = n.split("/"), i = S(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 = s.at(-1) ?? r.at(-1) ?? n, u = [...o, ...c], d = y(e.name), f = b(l, d, u[0] === h), p = [...u, f].join("/"), m = o.length ? `${t}/${o.join("/")}` : t;
34
34
  return {
35
35
  conversation: {
36
36
  ...e,
37
37
  ...d ? { name: d } : {},
38
38
  id: `${t}/${p}`,
39
- folderId: h
39
+ folderId: m
40
40
  },
41
41
  subPath: p
42
42
  };
43
- }, C = (e) => {
44
- let t = x(e.folderId).split("/").filter(Boolean).slice(1);
43
+ }, w = (e) => {
44
+ let t = S(e.folderId).split("/").filter(Boolean).slice(1);
45
45
  return t.length ? t.join(" / ") : void 0;
46
- }, w = (e) => e.map((e) => `"${e}"`).join(", "), T = (e, n) => {
46
+ }, T = (e) => e.map((e) => `"${e}"`).join(", "), E = (e, n) => {
47
47
  if (!e) return;
48
48
  let { fileId: r, anchor: i } = t(e), a = n.get(r);
49
49
  if (a != null) return {
50
50
  ...a,
51
51
  url: `${a.url}${i}`
52
52
  };
53
- }, E = (e, t) => {
54
- let n = T(e.url, t), r = T(e.reference_url, t);
53
+ }, D = (e, t) => {
54
+ let n = E(e.url, t), r = E(e.reference_url, t);
55
55
  if (n == null && r == null) return;
56
56
  let i = n?.title ?? r?.title;
57
57
  return {
@@ -59,19 +59,19 @@ var s = class extends Error {
59
59
  ...r == null ? {} : { reference_url: r.url },
60
60
  ...i == null ? {} : { title: i }
61
61
  };
62
- }, D = (e, t) => e.map((e) => e.attachments?.length ? {
62
+ }, O = (e, t) => e.map((e) => e.attachments?.length ? {
63
63
  ...e,
64
64
  attachments: e.attachments.map((e) => {
65
- let n = E(e, t);
65
+ let n = D(e, t);
66
66
  return n ? {
67
67
  ...e,
68
68
  ...n
69
69
  } : e;
70
70
  })
71
- } : e), O = (e, t) => e.map((e) => {
71
+ } : e), k = (e, t) => e.map((e) => {
72
72
  let n = e.body?.source;
73
73
  if (n?.attachment == null) return e;
74
- let r = E(n.attachment, t);
74
+ let r = D(n.attachment, t);
75
75
  return r == null ? e : {
76
76
  ...e,
77
77
  body: {
@@ -85,7 +85,7 @@ var s = class extends Error {
85
85
  }
86
86
  }
87
87
  };
88
- }), k = (e, t) => ({
88
+ }), A = (e, t) => ({
89
89
  ...e,
90
90
  messages: e.messages.map((e) => {
91
91
  let n = e.custom_content;
@@ -96,23 +96,72 @@ var s = class extends Error {
96
96
  custom_content: {
97
97
  ...n,
98
98
  ...r?.length ? { attachments: r.map((e) => {
99
- let n = E(e, t);
99
+ let n = D(e, t);
100
100
  return n ? {
101
101
  ...e,
102
102
  ...n
103
103
  } : e;
104
104
  }) } : {},
105
- ...i?.length ? { stages: D(i, t) } : {},
106
- ...a?.length ? { annotations: O(a, t) } : {}
105
+ ...i?.length ? { stages: O(i, t) } : {},
106
+ ...a?.length ? { annotations: k(a, t) } : {}
107
107
  }
108
108
  };
109
109
  })
110
- }), A = (e) => e.split("/").pop() || e, j = (t, r, i) => {
110
+ }), j = (e, i) => {
111
+ if (!e) return;
112
+ let a = n(t(e).fileId);
113
+ if (!(!a || a.bucket === i || a.bucket === r)) return a.path.split("/").pop() || a.path;
114
+ }, M = (e, t, n) => e.flatMap((e) => {
115
+ let r = j(e.url, t);
116
+ if (r != null) return n.push(r), [];
117
+ let i = j(e.reference_url, t);
118
+ if (i == null) return [e];
119
+ n.push(i);
120
+ let { reference_url: a, reference_type: o, ...s } = e;
121
+ return s.url == null && s.data == null ? [] : [s];
122
+ }), N = (e, t, n) => e.map((e) => {
123
+ let r = e.body, i = j(r?.source?.attachment?.url, t);
124
+ if (r == null || i == null) return e;
125
+ n.push(i);
126
+ let { source: a, ...o } = r;
127
+ return {
128
+ ...e,
129
+ body: o
130
+ };
131
+ }), P = (e, t) => {
132
+ let n = [], r = e.messages.map((e) => {
133
+ let r = e.custom_content;
134
+ if (!r) return e;
135
+ let { attachments: i, stages: a, annotations: o } = r;
136
+ return !i?.length && !a?.length && !o?.length ? e : {
137
+ ...e,
138
+ custom_content: {
139
+ ...r,
140
+ ...i?.length ? { attachments: M(i, t, n) } : {},
141
+ ...a?.length ? { stages: a.map((e) => e.attachments?.length ? {
142
+ ...e,
143
+ attachments: M(e.attachments, t, n)
144
+ } : e) } : {},
145
+ ...o?.length ? { annotations: N(o, t, n) } : {}
146
+ }
147
+ };
148
+ });
149
+ return n.length ? {
150
+ conversation: {
151
+ ...e,
152
+ messages: r
153
+ },
154
+ droppedNames: n
155
+ } : {
156
+ conversation: e,
157
+ droppedNames: n
158
+ };
159
+ }, F = (e) => e.split("/").pop() || e, I = (t, r, i) => {
111
160
  let a = [], o = [];
112
161
  for (let s of e(t)) {
113
162
  let e = n(s.fileId);
114
163
  if (!e) {
115
- o.push(A(s.fileId));
164
+ o.push(F(s.fileId));
116
165
  continue;
117
166
  }
118
167
  let t = e.path.split("/").pop() ?? e.path, c = r.get(e.path);
@@ -133,4 +182,4 @@ var s = class extends Error {
133
182
  };
134
183
  };
135
184
  //#endregion
136
- export { s as UnsupportedImportFormatError, w as formatQuotedNameList, C as getFolderBreadcrumb, u as parseImportEnvelope, j as planAttachmentUploads, S as rebaseConversationId, k as rewriteAttachmentUrls };
185
+ export { c as UnsupportedImportFormatError, P as dropForeignAttachmentRefs, T as formatQuotedNameList, w as getFolderBreadcrumb, d as parseImportEnvelope, I as planAttachmentUploads, C as rebaseConversationId, A as rewriteAttachmentUrls };
@@ -27,13 +27,14 @@ var o = () => {
27
27
  progress: { percent: 100 },
28
28
  errorCode: void 0
29
29
  });
30
- }, [u]), m = n((t, n) => {
31
- s((r) => r.map((r) => r.id !== t || r.status !== e.InProgress ? r : {
32
- ...r,
30
+ }, [u]), m = n((t, n, r) => {
31
+ s((i) => i.map((i) => i.id !== t || i.status !== e.InProgress ? i : {
32
+ ...i,
33
33
  status: e.Warning,
34
34
  progress: { percent: 100 },
35
35
  errorCode: void 0,
36
- warningCode: n
36
+ warningCode: n,
37
+ warningNames: r
37
38
  }));
38
39
  }, []), h = n((t, n) => {
39
40
  u(t, {
@@ -57,7 +58,9 @@ var o = () => {
57
58
  return l.current.set(t, () => (u(t, {
58
59
  status: e.InProgress,
59
60
  progress: { percent: 0 },
60
- errorCode: void 0
61
+ errorCode: void 0,
62
+ warningCode: void 0,
63
+ warningNames: void 0
61
64
  }), r())), r();
62
65
  }, [u]);
63
66
  return r(() => {
@@ -1,93 +1,129 @@
1
1
  //#region src/conversation/create-chat-stream-api.ts
2
- var e = { "Content-Type": "application/json" }, t = 409, n = "A response is already being generated in this conversation. Wait for it to finish or stop it before sending another message.", r = class extends Error {
3
- constructor(e = n) {
2
+ var e = { "Content-Type": "application/json" }, t = 409, n = "The response could not be saved. It is still shown here, but may be lost if you reload or leave this page. Copy it before continuing.", r = class extends Error {
3
+ static type = "conversation_save_failed";
4
+ constructor() {
5
+ super(n), this.name = "GenerationPersistenceError";
6
+ }
7
+ }, i = "A response is already being generated in this conversation. Wait for it to finish or stop it before sending another message.", a = class extends Error {
8
+ constructor(e = i) {
4
9
  super(e), this.name = "GenerationConflictError";
5
10
  }
6
- }, i = (e, t, n) => {
7
- let r = e.trim();
8
- if (!r || r.startsWith(":") || !r.startsWith("data: ")) return;
9
- let i = r.slice(6);
10
- if (i !== "[DONE]") try {
11
- let e = JSON.parse(i);
11
+ }, o = class extends Error {
12
+ constructor(e) {
13
+ super(e), this.name = "StreamUpstreamError";
14
+ }
15
+ }, s = class extends Error {
16
+ constructor(e) {
17
+ super("The completion stream was interrupted", { cause: e }), this.name = "StreamInterruptedError";
18
+ }
19
+ }, c = 45e3, l = (e, t) => {
20
+ let n = Date.now(), r, i = !1, a = () => {
21
+ if (i) return;
22
+ let o = Date.now() - n;
23
+ if (o >= e) {
24
+ t();
25
+ return;
26
+ }
27
+ clearTimeout(r), r = setTimeout(a, e - o);
28
+ }, o = () => {
29
+ document.visibilityState === "visible" && a();
30
+ }, s = typeof window < "u" && typeof document < "u";
31
+ return s && (document.addEventListener("visibilitychange", o), window.addEventListener("online", a), window.addEventListener("pageshow", a)), r = setTimeout(a, e), {
32
+ touch: () => {
33
+ n = Date.now();
34
+ },
35
+ stop: () => {
36
+ i || (i = !0, clearTimeout(r), s && (document.removeEventListener("visibilitychange", o), window.removeEventListener("online", a), window.removeEventListener("pageshow", a)));
37
+ }
38
+ };
39
+ }, u = (e) => typeof e == "object" && !!e && e.name === "AbortError", d = (e, t, n) => {
40
+ let i = e.trim();
41
+ if (!i || i.startsWith(":") || !i.startsWith("data: ")) return;
42
+ let a = i.slice(6);
43
+ if (a !== "[DONE]") try {
44
+ let e = JSON.parse(a);
12
45
  if (e.error) {
13
- n(Error(e.error.message));
46
+ n(e.error.type === r.type ? new r() : new o(e.error.message));
14
47
  return;
15
48
  }
16
49
  t(e);
17
50
  } catch {}
18
- }, a = (n) => {
19
- let { completionsBasePath: a } = n, o = (...e) => (n.fetchImpl ?? fetch)(...e);
51
+ }, f = (n) => {
52
+ let { completionsBasePath: r } = n, i = (...e) => (n.fetchImpl ?? fetch)(...e);
20
53
  return {
21
- streamCompletion: (s, c, l, u, d, f, p, m, h) => {
22
- let { onChunk: g, onComplete: _, onError: v, signal: y } = u;
54
+ streamCompletion: (o, c, f, p, m, h, g, _, v) => {
55
+ let { onChunk: y, onComplete: b, onError: x, signal: S } = p;
23
56
  (async () => {
24
- let u;
57
+ let p;
25
58
  try {
26
59
  let t = n.getTimezone?.();
27
- u = await o(`${a}/completions`, {
60
+ p = await i(`${r}/completions`, {
28
61
  method: "POST",
29
62
  credentials: "include",
30
- signal: y,
63
+ signal: S,
31
64
  headers: {
32
65
  ...e,
33
66
  ...n.getCsrfToken() == null ? {} : { "X-CSRF-Token": n.getCsrfToken() },
34
67
  ...t ? { "X-Timezone": t } : {}
35
68
  },
36
69
  body: JSON.stringify({
37
- path: s,
70
+ path: o,
38
71
  message: c ?? "",
39
- model: l,
40
- custom_content: d || {},
41
- ...f != null && { generationId: f },
42
- ...p != null && { mode: p },
43
- ...m != null && { messageIndex: m },
44
- ...h != null && { clientChannelId: h }
72
+ model: f,
73
+ custom_content: m || {},
74
+ ...h != null && { generationId: h },
75
+ ...g != null && { mode: g },
76
+ ..._ != null && { messageIndex: _ },
77
+ ...v != null && { clientChannelId: v }
45
78
  })
46
79
  });
47
80
  } catch (e) {
48
- if (e instanceof Error && e.name === "AbortError") return;
49
- v(e instanceof Error ? e : Error(String(e)));
81
+ if (u(e)) return;
82
+ x(new s(e));
50
83
  return;
51
84
  }
52
- let b = u.headers.get("x-csrf-token");
53
- if (b && n.setCsrfToken(b), !u.ok) {
54
- if (u.status === t) {
55
- v(new r());
85
+ let C = p.headers.get("x-csrf-token");
86
+ if (C && n.setCsrfToken(C), !p.ok) {
87
+ if (p.status === t) {
88
+ x(new a());
56
89
  return;
57
90
  }
58
- v(/* @__PURE__ */ Error(`Stream request failed with status ${u.status}`));
91
+ x(/* @__PURE__ */ Error(`Stream request failed with status ${p.status}`));
59
92
  return;
60
93
  }
61
- if (!u.body) {
62
- v(/* @__PURE__ */ Error("No response body"));
94
+ if (!p.body) {
95
+ x(/* @__PURE__ */ Error("No response body"));
63
96
  return;
64
97
  }
65
- let x = u.body.getReader(), S = new TextDecoder(), C = "", w = !1, T = (e) => {
66
- w = !0, v(e);
67
- };
98
+ let w = p.body.getReader(), T = new TextDecoder(), E = "", D = !1, O = !1, k = (e) => {
99
+ D || (D = !0, A.stop(), x(e));
100
+ }, A = l(n.idleTimeoutMs ?? 45e3, () => {
101
+ O = !0, k(new s()), w.cancel().catch(() => void 0);
102
+ });
68
103
  try {
69
104
  for (;;) {
70
- let { done: e, value: t } = await x.read();
105
+ let { done: e, value: t } = await w.read();
106
+ if (O) break;
71
107
  if (e) {
72
- C.trim() && i(C, g, T);
108
+ E.trim() && d(E, y, k);
73
109
  break;
74
110
  }
75
- C += S.decode(t, { stream: !0 });
76
- let n = C.split("\n");
77
- C = n.pop() ?? "";
78
- for (let e of n) i(e, g, T);
111
+ A.touch(), E += T.decode(t, { stream: !0 });
112
+ let n = E.split("\n");
113
+ E = n.pop() ?? "";
114
+ for (let e of n) d(e, y, k);
79
115
  }
80
- w || _();
116
+ D || (D = !0, b());
81
117
  } catch (e) {
82
- if (e instanceof Error && e.name === "AbortError") return;
83
- v(e instanceof Error ? e : Error(String(e)));
118
+ if (u(e)) return;
119
+ k(new s(e));
84
120
  } finally {
85
- x.releaseLock();
121
+ A.stop(), w.releaseLock();
86
122
  }
87
123
  })();
88
124
  },
89
125
  stopCompletion: async (t) => {
90
- let r = await o(`${a}/completions/stop`, {
126
+ let a = await i(`${r}/completions/stop`, {
91
127
  method: "POST",
92
128
  credentials: "include",
93
129
  headers: {
@@ -95,10 +131,10 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "A response is alre
95
131
  ...n.getCsrfToken() == null ? {} : { "X-CSRF-Token": n.getCsrfToken() }
96
132
  },
97
133
  body: JSON.stringify(t)
98
- }), i = r.headers.get("x-csrf-token");
99
- if (i && n.setCsrfToken(i), !r.ok) throw Error(`stopCompletion failed: ${r.status}`);
134
+ }), o = a.headers.get("x-csrf-token");
135
+ if (o && n.setCsrfToken(o), !a.ok) throw Error(`stopCompletion failed: ${a.status}`);
100
136
  }
101
137
  };
102
138
  };
103
139
  //#endregion
104
- export { n as DEFAULT_GENERATION_CONFLICT_MESSAGE, r as GenerationConflictError, a as createChatStreamApi };
140
+ export { i as DEFAULT_GENERATION_CONFLICT_MESSAGE, n as DEFAULT_GENERATION_PERSISTENCE_ERROR_MESSAGE, c as DEFAULT_STREAM_IDLE_TIMEOUT_MS, a as GenerationConflictError, r as GenerationPersistenceError, s as StreamInterruptedError, o as StreamUpstreamError, f as createChatStreamApi };
@@ -9,6 +9,48 @@ var i = (t, n, r, i) => i && n === r - 1 && t.role === e.Assistant, a = (e) => {
9
9
  return null;
10
10
  }, o = (t) => t.role === e.Assistant && (t.custom_content?.stages?.length ?? 0) > 0, s = (t) => {
11
11
  for (let n = t.length - 1; n >= 0; n--) if (t[n].role === e.User) return t[n].custom_content?.configuration_value;
12
- }, c = (e) => (e ?? "").toLowerCase().replace(/[^a-z]/g, "") === "plaintext" ? t.PlainText : t.Markdown;
12
+ }, c = (e) => {
13
+ if (typeof e.default == "boolean") return e.default;
14
+ let t = e.oneOf;
15
+ if (Array.isArray(t) && t.length === 1) {
16
+ let e = t[0];
17
+ if (typeof e == "object" && e && "const" in e && typeof e.const == "boolean") return e.const;
18
+ }
19
+ }, l = (e) => {
20
+ let t = e?.properties;
21
+ if (t == null) return;
22
+ let n = Object.entries(t).flatMap(([e, t]) => {
23
+ let n = c(t);
24
+ return n === void 0 ? [] : [[e, n]];
25
+ });
26
+ return n.length > 0 ? Object.fromEntries(n) : void 0;
27
+ }, u = (t) => {
28
+ let n = -1;
29
+ for (let r = t.length - 1; r >= 0; r--) if (t[r].role === e.User) {
30
+ n = r;
31
+ break;
32
+ }
33
+ let r = t[n]?.custom_content?.configuration_value;
34
+ for (let i = n + 1; i < t.length; i++) {
35
+ let n = t[i];
36
+ if (n.role !== e.Assistant) continue;
37
+ let a = l(n.custom_content?.form_schema);
38
+ a && (r = {
39
+ ...r,
40
+ ...a
41
+ });
42
+ }
43
+ return r;
44
+ }, d = (t, n, r) => {
45
+ let i = n.length - 1, a = n[i];
46
+ if (a?.role !== e.Assistant) return;
47
+ let o = l(a.custom_content?.form_schema);
48
+ if (!o) return;
49
+ let s = Object.fromEntries(r.filter((e) => e in o).sort().map((e) => [e, o[e]]));
50
+ if (Object.keys(s).length !== 0) return {
51
+ key: `${t}|${i}|${JSON.stringify(s)}`,
52
+ values: s
53
+ };
54
+ }, f = (e) => (e ?? "").toLowerCase().replace(/[^a-z]/g, "") === "plaintext" ? t.PlainText : t.Markdown;
13
55
  //#endregion
14
- export { a as getLastDeploymentId, s as getLastUserMessageToolConfiguration, i as isMessageStreaming, o as messageHasStages, c as normalizeResponseFormat };
56
+ export { d as getFormSchemaToolSyncKey, a as getLastDeploymentId, s as getLastUserMessageToolConfiguration, u as getLatestToolConfiguration, l as getToolConfigurationFromFormSchema, i as isMessageStreaming, o as messageHasStages, f as normalizeResponseFormat };
@@ -0,0 +1,23 @@
1
+ import { StageStatus as e } from "@epam/ai-dial-chat-shared";
2
+ //#region src/conversation/stage.ts
3
+ var t = (t) => t === e.Completed ? e.Completed : t === e.Failed ? e.Failed : null, n = (e) => ({
4
+ title: e.title ?? "",
5
+ ...e.index != null && { index: e.index },
6
+ ...e.type != null && { type: e.type },
7
+ ...e.data != null && { data: e.data },
8
+ ...e.url != null && { url: e.url },
9
+ ...e.reference_type != null && { reference_type: e.reference_type },
10
+ ...e.reference_url != null && { reference_url: e.reference_url }
11
+ }), r = (e) => ({
12
+ index: e.index ?? 0,
13
+ name: e.name ?? "",
14
+ status: t(e.status),
15
+ ...e.content != null && { content: e.content },
16
+ ...e.tag != null && { tag: e.tag },
17
+ ...e.attachments?.length && { attachments: e.attachments.map(n) }
18
+ }), i = (e) => {
19
+ let t = Array.isArray(e) ? e : e?.custom_content?.stages ?? e?.customContent?.stages;
20
+ if (t?.length) return t.map(r);
21
+ };
22
+ //#endregion
23
+ export { i as mapStages, r as toStage };
@@ -26,9 +26,16 @@ var o = 700, s = 5, c = (e) => t(e.split("/").filter(Boolean).pop() ?? "file").r
26
26
  })).url,
27
27
  name: a.fileName
28
28
  };
29
- } catch (t) {
30
- if (l(t)) {
29
+ } catch (c) {
30
+ if (l(c)) {
31
31
  if (i.markTaken(a.fileName), o < s) {
32
+ if (t.listFiles) try {
33
+ let e = await t.listFiles({
34
+ bucket: u,
35
+ path: a.path.slice(0, a.path.lastIndexOf("/"))
36
+ });
37
+ for (let t of e.items) i.markTaken(t.name);
38
+ } catch {}
32
39
  a = i.allocate(n);
33
40
  continue;
34
41
  }
@@ -38,10 +45,10 @@ var o = 700, s = 5, c = (e) => t(e.split("/").filter(Boolean).pop() ?? "file").r
38
45
  let e = p.current.splice(0);
39
46
  d?.(e), m.current = null;
40
47
  }, f);
41
- let n = t instanceof Error ? t : /* @__PURE__ */ Error("Network upload failed");
42
- throw n.errorReason = r.Network, n;
48
+ let t = c instanceof Error ? c : /* @__PURE__ */ Error("Network upload failed");
49
+ throw t.errorReason = r.Network, t;
43
50
  }
44
- throw t;
51
+ throw c;
45
52
  }
46
53
  }, [
47
54
  u,
@@ -171,12 +171,12 @@ var S = 5, C = 512 * 1024 * 1024, w = 429, T = 5, E = 2e3, D = (e) => e instance
171
171
  }, s);
172
172
  return I.startJob(c, (e) => R(c, t, i, o, s, e));
173
173
  }, [I, R]), B = b(async (e, t, n) => {
174
- let r = d.ExportAll, a = [], s;
174
+ let r = d.ExportAll, a = [], c;
175
175
  do {
176
176
  if (n.aborted) return;
177
177
  let t;
178
178
  try {
179
- t = await x.listConversations({ nextToken: s }, { signal: n });
179
+ t = await x.listConversations({ nextToken: c }, { signal: n });
180
180
  } catch (t) {
181
181
  if (n.aborted) return;
182
182
  if (E(t).isUnauthorized) F?.({
@@ -197,18 +197,18 @@ var S = 5, C = 512 * 1024 * 1024, w = 429, T = 5, E = 2e3, D = (e) => e instance
197
197
  a.push(...t.items.filter(j).map((e) => ({
198
198
  id: e.id,
199
199
  title: e.title
200
- }))), s = t.nextToken;
201
- } while (s);
200
+ }))), c = t.nextToken;
201
+ } while (c);
202
202
  I.setJobProgress(e, p({
203
203
  kind: r,
204
204
  phase: f.Prepare
205
205
  }));
206
- let c = [];
206
+ let l = [];
207
207
  for (let t of a) {
208
208
  if (n.aborted) return;
209
209
  try {
210
210
  let e = await A(x, T(t.id), n);
211
- c.push(e);
211
+ l.push(e);
212
212
  } catch (r) {
213
213
  if (n.aborted) return;
214
214
  let i = E(r);
@@ -240,17 +240,17 @@ var S = 5, C = 512 * 1024 * 1024, w = 429, T = 5, E = 2e3, D = (e) => e instance
240
240
  I.setJobProgress(e, p({
241
241
  kind: r,
242
242
  phase: f.Transfer,
243
- completed: c.length,
243
+ completed: l.length,
244
244
  total: a.length
245
245
  }, {
246
- completed: c.length,
246
+ completed: l.length,
247
247
  total: a.length,
248
248
  kind: v.Conversation
249
249
  }));
250
250
  }
251
251
  }
252
252
  if (!n.aborted) try {
253
- y(o(i(c, [])), t), k?.({ jobId: e }), I.succeedJob(e);
253
+ y(o(i(l.map(s), [])), t), k?.({ jobId: e }), I.succeedJob(e);
254
254
  } catch (t) {
255
255
  let n = M(t) ? g.FileTooLarge : g.Unknown, r = await D(t);
256
256
  F?.({
@@ -44,23 +44,19 @@ var p = ({ conversation: p, conversationId: m, bucket: h, isStreaming: g, startS
44
44
  if (g || !m || !p || e === -1 || p.messages[e]?.role !== c.Assistant) return;
45
45
  let t = p.messages[e - 1];
46
46
  if (!t || t.role !== c.User) return;
47
- let n = C();
48
- v((t) => {
49
- if (!t) return t;
50
- let r = {
51
- ...t.messages[e],
52
- content: "",
53
- custom_content: void 0,
54
- wasStoppedByUser: void 0,
55
- stoppedWithoutContent: void 0,
56
- streamErrorMessage: void 0,
57
- deploymentId: n
58
- }, i = {
59
- ...t,
60
- messages: [...t.messages.slice(0, e), r]
61
- };
62
- return y.current = i, i;
63
- }), A((t) => new Set([...t].filter((t) => t < e))), _(m, t.content, e, n, t.custom_content, l(), f.Regenerate);
47
+ let n = C(), r = {
48
+ ...p.messages[e],
49
+ content: "",
50
+ custom_content: void 0,
51
+ wasStoppedByUser: void 0,
52
+ stoppedWithoutContent: void 0,
53
+ streamErrorMessage: void 0,
54
+ deploymentId: n
55
+ }, i = {
56
+ ...p,
57
+ messages: [...p.messages.slice(0, e), r]
58
+ };
59
+ y.current = i, v(i), A((t) => new Set([...t].filter((t) => t < e))), _(m, t.content, e, n, t.custom_content, l(), f.Regenerate);
64
60
  }, [
65
61
  p,
66
62
  m,