@epam/ai-dial-chat-hooks 1.3.0-dev.311 → 1.3.0-dev.317

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.
@@ -1,73 +1,70 @@
1
- import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
1
+ import { applyViewedMark as e } from "./project-viewed-marks.js";
2
+ import { useCallback as t, useEffect as n, useMemo as r, useRef as i, useState as a } from "react";
2
3
  //#region src/project/use-project-conversations.ts
3
- var a = 20, o = 100, s = {
4
+ var o = 20, s = 100, c = {
4
5
  rows: [],
5
- visibleCount: a,
6
+ visibleCount: o,
6
7
  isLoading: !0,
7
8
  hasError: !1,
8
9
  isLoadingMore: !1
9
- }, c = {
10
- ...s,
10
+ }, l = {
11
+ ...c,
11
12
  isLoading: !1
12
- }, l = (e, t) => e.map(({ id: e, name: n, title: r, author: i, updatedAt: a, isUnread: o, isTitlePending: s }) => {
13
- let c = o;
14
- if (t.has(e)) {
15
- let n = t.get(e);
16
- a != null && n != null && a > n ? t.delete(e) : c = !1;
17
- }
13
+ }, u = (t, n) => t.map((t) => {
14
+ let { id: r, name: i, title: a, author: o, isTitlePending: s } = t;
18
15
  return {
19
- id: e,
20
- name: n,
21
- title: r,
22
- authorName: i,
16
+ id: r,
17
+ name: i,
18
+ title: a,
19
+ authorName: o,
23
20
  isTitlePending: s === !0,
24
- ...c ? { isUnread: !0 } : {}
21
+ ...e(n, t) ? { isUnread: !0 } : {}
25
22
  };
26
- }), u = (e, t) => {
23
+ }), d = (e, t) => {
27
24
  if (t.length === 0) return e;
28
25
  let n = new Map(t.map((e) => [e.id, e]));
29
26
  return e.map((e) => n.get(e.id) ?? e);
30
- }, d = ({ id: e, title: t, authorName: n, isUnread: r }) => ({
27
+ }, f = ({ id: e, title: t, authorName: n, isUnread: r }) => ({
31
28
  id: e,
32
29
  title: t,
33
30
  authorName: n,
34
31
  ...r ? { isUnread: !0 } : {}
35
- }), f = (f, p) => {
36
- let [m, h] = i(s), [g, _] = i(0), v = r(null), y = r(null), b = r(!1), x = r(/* @__PURE__ */ new Map()), S = r(/* @__PURE__ */ new Map()), C = r(m);
37
- t(() => {
32
+ }), p = (e, p) => {
33
+ let [m, h] = a(c), [g, _] = a(0), v = i(null), y = i(null), b = i(!1), x = i(/* @__PURE__ */ new Map()), S = i(/* @__PURE__ */ new Map()), C = i(m);
34
+ n(() => {
38
35
  C.current = m;
39
36
  });
40
- let w = e((e) => {
37
+ let w = t((e) => {
41
38
  for (let { id: t, updatedAt: n } of e) S.current.set(t, n);
42
- }, []), T = e(async (e, t) => {
39
+ }, []), T = t(async (t, n) => {
43
40
  if (p == null) return [];
44
- let n = e.filter((e) => e.isTitlePending).map((e) => e.name), r = [];
45
- for (let e = 0; e < n.length; e += o) {
46
- let { items: i } = await f.getProjectConversationTitles(p, n.slice(e, e + o), t);
47
- r.push(...i);
41
+ let r = t.filter((e) => e.isTitlePending).map((e) => e.name), i = [];
42
+ for (let t = 0; t < r.length; t += s) {
43
+ let { items: a } = await e.getProjectConversationTitles(p, r.slice(t, t + s), n);
44
+ i.push(...a);
48
45
  }
49
- return w(r), l(r, x.current);
46
+ return w(i), u(i, x.current);
50
47
  }, [
51
- f,
48
+ e,
52
49
  p,
53
50
  w
54
- ]), E = e(async (e, t, n) => {
51
+ ]), E = t(async (e, t, n) => {
55
52
  try {
56
53
  let r = await T(e.slice(0, t), n);
57
54
  if (n.aborted) return;
58
55
  h((e) => ({
59
56
  ...e,
60
- rows: u(e.rows, r)
57
+ rows: d(e.rows, r)
61
58
  }));
62
59
  } catch {}
63
60
  }, [T]);
64
- t(() => {
61
+ n(() => {
65
62
  if (x.current = /* @__PURE__ */ new Map(), S.current = /* @__PURE__ */ new Map(), p == null) {
66
- h(c);
63
+ h(l);
67
64
  return;
68
65
  }
69
- let e = new AbortController();
70
- return v.current = e, (async () => {
66
+ let t = new AbortController();
67
+ return v.current = t, (async () => {
71
68
  h((e) => ({
72
69
  ...e,
73
70
  isLoading: !0,
@@ -75,33 +72,33 @@ var a = 20, o = 100, s = {
75
72
  isLoadingMore: !1
76
73
  }));
77
74
  try {
78
- let { items: t } = await f.listProjectConversations(p, e.signal);
79
- if (e.signal.aborted) return;
80
- w(t), h({
81
- ...c,
82
- rows: l(t, x.current)
75
+ let { items: n } = await e.listProjectConversations(p, t.signal);
76
+ if (t.signal.aborted) return;
77
+ w(n), h({
78
+ ...l,
79
+ rows: u(n, x.current)
83
80
  });
84
81
  } catch {
85
- if (e.signal.aborted) return;
82
+ if (t.signal.aborted) return;
86
83
  h({
87
- ...c,
84
+ ...l,
88
85
  hasError: !0
89
86
  });
90
87
  }
91
88
  })(), () => {
92
- e.abort(), y.current?.abort();
89
+ t.abort(), y.current?.abort();
93
90
  };
94
91
  }, [
95
- f,
92
+ e,
96
93
  p,
97
94
  g,
98
95
  w
99
96
  ]);
100
- let D = e(() => _((e) => e + 1), []), O = e(async () => {
97
+ let D = t(() => _((e) => e + 1), []), O = t(async () => {
101
98
  let e = v.current, t = C.current;
102
99
  if (p == null || e == null || b.current) return;
103
100
  b.current = !0;
104
- let n = t.visibleCount + a, r = t.rows.slice(t.visibleCount, n);
101
+ let n = t.visibleCount + o, r = t.rows.slice(t.visibleCount, n);
105
102
  h((e) => ({
106
103
  ...e,
107
104
  isLoadingMore: !0
@@ -111,7 +108,7 @@ var a = 20, o = 100, s = {
111
108
  if (e.signal.aborted) return;
112
109
  h((e) => ({
113
110
  ...e,
114
- rows: u(e.rows, t),
111
+ rows: d(e.rows, t),
115
112
  visibleCount: Math.max(e.visibleCount, n),
116
113
  isLoadingMore: !1
117
114
  }));
@@ -124,65 +121,65 @@ var a = 20, o = 100, s = {
124
121
  } finally {
125
122
  b.current = !1;
126
123
  }
127
- }, [p, T]), k = e(async () => {
128
- let e = C.current;
129
- if (p == null || e.isLoading || e.hasError) return;
124
+ }, [p, T]), k = t(async () => {
125
+ let t = C.current;
126
+ if (p == null || t.isLoading || t.hasError) return;
130
127
  y.current?.abort();
131
- let t = new AbortController();
132
- y.current = t;
133
- let n;
128
+ let n = new AbortController();
129
+ y.current = n;
130
+ let r;
134
131
  try {
135
- let { items: e } = await f.listProjectConversations(p, t.signal);
136
- if (t.signal.aborted) return;
137
- w(e), n = l(e, x.current);
132
+ let { items: t } = await e.listProjectConversations(p, n.signal);
133
+ if (n.signal.aborted) return;
134
+ w(t), r = u(t, x.current);
138
135
  } catch {
139
136
  return;
140
137
  }
141
138
  h((e) => ({
142
139
  ...e,
143
- rows: n
144
- })), await E(n, C.current.visibleCount, t.signal);
140
+ rows: r
141
+ })), await E(r, C.current.visibleCount, n.signal);
145
142
  }, [
146
- f,
143
+ e,
147
144
  E,
148
145
  p,
149
146
  w
150
147
  ]);
151
- t(() => () => y.current?.abort(), []);
152
- let A = e((e) => {
153
- x.current.set(e, S.current.get(e)), h((t) => ({
154
- ...t,
155
- rows: t.rows.map((t) => t.id === e && t.isUnread ? {
156
- ...t,
148
+ n(() => () => y.current?.abort(), []);
149
+ let A = t((t) => {
150
+ x.current.set(t, S.current.get(t)), h((e) => ({
151
+ ...e,
152
+ rows: e.rows.map((e) => e.id === t && e.isUnread ? {
153
+ ...e,
157
154
  isUnread: !1
158
- } : t)
155
+ } : e)
159
156
  })), (async () => {
160
157
  try {
161
- await f.markProjectConversationViewed?.(e);
158
+ await e.markProjectConversationViewed?.(t);
162
159
  } catch {}
163
160
  })();
164
- }, [f]), j = e(async (e, t) => {
165
- let { name: n } = await f.renameProjectConversation(e, t);
166
- h((t) => ({
167
- ...t,
168
- rows: t.rows.map((t) => t.id === e ? {
169
- ...t,
170
- title: n,
161
+ }, [e]), j = t(async (t, n) => {
162
+ let { name: r } = await e.renameProjectConversation(t, n);
163
+ h((e) => ({
164
+ ...e,
165
+ rows: e.rows.map((e) => e.id === t ? {
166
+ ...e,
167
+ title: r,
171
168
  isTitlePending: !1
172
- } : t)
169
+ } : e)
173
170
  }));
174
- }, [f]), M = e(async (e) => {
175
- await f.deleteProjectConversation(e);
176
- let { rows: t, visibleCount: n } = C.current, r = t.filter((t) => t.id !== e);
177
- h((t) => ({
178
- ...t,
179
- rows: t.rows.filter((t) => t.id !== e)
171
+ }, [e]), M = t(async (t) => {
172
+ await e.deleteProjectConversation(t);
173
+ let { rows: n, visibleCount: r } = C.current, i = n.filter((e) => e.id !== t);
174
+ h((e) => ({
175
+ ...e,
176
+ rows: e.rows.filter((e) => e.id !== t)
180
177
  }));
181
- let i = v.current;
182
- i != null && E(r, n, i.signal);
183
- }, [f, E]), { rows: N, visibleCount: P, isLoading: F, hasError: I, isLoadingMore: L } = m;
178
+ let a = v.current;
179
+ a != null && E(i, r, a.signal);
180
+ }, [e, E]), { rows: N, visibleCount: P, isLoading: F, hasError: I, isLoadingMore: L } = m;
184
181
  return {
185
- items: n(() => N.slice(0, P).map(d), [N, P]),
182
+ items: r(() => N.slice(0, P).map(f), [N, P]),
186
183
  isLoading: F,
187
184
  hasError: I,
188
185
  hasMore: P < N.length,
@@ -196,4 +193,4 @@ var a = 20, o = 100, s = {
196
193
  };
197
194
  };
198
195
  //#endregion
199
- export { f as useProjectConversations };
196
+ export { p as useProjectConversations };
package/project.js CHANGED
@@ -1,19 +1,20 @@
1
1
  import { buildCreateConversationDto as e, createProjectsApiClient as t, splitProjectConversationId as n } from "./project/projects-api-client.js";
2
- import { mapProjectArtifactsToOutputs as r, mapProjectDetailsToViewModel as i, mapProjectDtoToItem as a, mapProjectSource as o, mapStoredContextFiles as s } from "./project/project-mapping.js";
3
- import { DEFAULT_PROJECT_CONTEXT_ALLOWED_EXTENSIONS as c, DEFAULT_PROJECT_CONTEXT_FILE_MAX_BYTES as l, DEFAULT_PROJECT_CONTEXT_TOTAL_MAX_BYTES as u, getMimeTypesForExtensions as d, resolveByteLimit as f, resolveExtensionList as p } from "./project/project-limits.js";
4
- import { ProjectFormErrorField as m, ProjectFormErrorReason as h, getProjectFormError as g } from "./project/project-form-errors.js";
5
- import { fromProjectOutputCardId as _, fromProjectPreviewKey as v, toProjectContextFileAttachment as y, toProjectOutputAttachment as b, toProjectOutputCardId as x, toProjectPreviewKey as S, toStoredProjectFileAttachment as C } from "./project/project-file-preview.js";
6
- import { useProjectFilePreview as w } from "./project/use-project-file-preview.js";
7
- import { ProjectDraftMode as T, useProjectDraft as E } from "./project/use-project-draft.js";
8
- import { ProjectChatCreateFailure as D, classifyProjectChatCreateError as O, createProjectChat as k } from "./project/create-project-chat.js";
9
- import { createProjectConversationDataSource as A } from "./project/project-conversation-data-source.js";
10
- import { useProjects as j } from "./project/use-projects.js";
11
- import { ProjectRefreshOutcome as M } from "./project/project-refresh.js";
12
- import { useProject as N } from "./project/use-project.js";
13
- import { useProjectWatch as P } from "./project/use-project-watch.js";
14
- import { useCreateProject as F, useSaveProject as I } from "./project/use-project-submit.js";
15
- import { useProjectConversations as L } from "./project/use-project-conversations.js";
16
- import { useProjectArtifacts as R } from "./project/use-project-artifacts.js";
17
- import { ProjectActionError as z, useProjectActions as B } from "./project/use-project-actions.js";
18
- import { createSerializedKeyedWriter as V } from "./shared/serialized-writer.js";
19
- export { c as DEFAULT_PROJECT_CONTEXT_ALLOWED_EXTENSIONS, l as DEFAULT_PROJECT_CONTEXT_FILE_MAX_BYTES, u as DEFAULT_PROJECT_CONTEXT_TOTAL_MAX_BYTES, z as ProjectActionError, D as ProjectChatCreateFailure, T as ProjectDraftMode, m as ProjectFormErrorField, h as ProjectFormErrorReason, M as ProjectRefreshOutcome, e as buildCreateConversationDto, O as classifyProjectChatCreateError, k as createProjectChat, A as createProjectConversationDataSource, t as createProjectsApiClient, V as createSerializedKeyedWriter, _ as fromProjectOutputCardId, v as fromProjectPreviewKey, d as getMimeTypesForExtensions, g as getProjectFormError, r as mapProjectArtifactsToOutputs, i as mapProjectDetailsToViewModel, a as mapProjectDtoToItem, o as mapProjectSource, s as mapStoredContextFiles, f as resolveByteLimit, p as resolveExtensionList, n as splitProjectConversationId, y as toProjectContextFileAttachment, b as toProjectOutputAttachment, x as toProjectOutputCardId, S as toProjectPreviewKey, C as toStoredProjectFileAttachment, F as useCreateProject, N as useProject, B as useProjectActions, R as useProjectArtifacts, L as useProjectConversations, E as useProjectDraft, w as useProjectFilePreview, P as useProjectWatch, j as useProjects, I as useSaveProject };
2
+ import { mapProjectArtifactsToOutputs as r, mapProjectDetailsToViewModel as i, mapProjectDtoToItem as a, mapProjectSource as o, mapProjectSourceToFilterTab as s, mapStoredContextFiles as c } from "./project/project-mapping.js";
3
+ import { DEFAULT_PROJECT_CONTEXT_ALLOWED_EXTENSIONS as l, DEFAULT_PROJECT_CONTEXT_FILE_MAX_BYTES as u, DEFAULT_PROJECT_CONTEXT_TOTAL_MAX_BYTES as d, getMimeTypesForExtensions as f, resolveByteLimit as p, resolveExtensionList as m } from "./project/project-limits.js";
4
+ import { ProjectFormErrorField as h, ProjectFormErrorReason as g, getProjectFormError as _ } from "./project/project-form-errors.js";
5
+ import { fromProjectOutputCardId as v, fromProjectPreviewKey as y, toProjectContextFileAttachment as b, toProjectOutputAttachment as x, toProjectOutputCardId as S, toProjectPreviewKey as C, toStoredProjectFileAttachment as w } from "./project/project-file-preview.js";
6
+ import { useProjectFilePreview as T } from "./project/use-project-file-preview.js";
7
+ import { ProjectDraftMode as E, useProjectDraft as D } from "./project/use-project-draft.js";
8
+ import { ProjectChatCreateFailure as O, classifyProjectChatCreateError as k, createProjectChat as A } from "./project/create-project-chat.js";
9
+ import { createProjectConversationDataSource as j } from "./project/project-conversation-data-source.js";
10
+ import { useProjects as M } from "./project/use-projects.js";
11
+ import { ProjectRefreshOutcome as N } from "./project/project-refresh.js";
12
+ import { useProject as P } from "./project/use-project.js";
13
+ import { useProjectWatch as F } from "./project/use-project-watch.js";
14
+ import { useCreateProject as I, useSaveProject as L } from "./project/use-project-submit.js";
15
+ import { useProjectConversations as R } from "./project/use-project-conversations.js";
16
+ import { PINNED_PROJECT_CHATS_LIMIT as z, usePinnedProjectChats as B } from "./project/use-pinned-project-chats.js";
17
+ import { useProjectArtifacts as V } from "./project/use-project-artifacts.js";
18
+ import { ProjectActionError as H, useProjectActions as U } from "./project/use-project-actions.js";
19
+ import { createSerializedKeyedWriter as W } from "./shared/serialized-writer.js";
20
+ export { l as DEFAULT_PROJECT_CONTEXT_ALLOWED_EXTENSIONS, u as DEFAULT_PROJECT_CONTEXT_FILE_MAX_BYTES, d as DEFAULT_PROJECT_CONTEXT_TOTAL_MAX_BYTES, z as PINNED_PROJECT_CHATS_LIMIT, H as ProjectActionError, O as ProjectChatCreateFailure, E as ProjectDraftMode, h as ProjectFormErrorField, g as ProjectFormErrorReason, N as ProjectRefreshOutcome, e as buildCreateConversationDto, k as classifyProjectChatCreateError, A as createProjectChat, j as createProjectConversationDataSource, t as createProjectsApiClient, W as createSerializedKeyedWriter, v as fromProjectOutputCardId, y as fromProjectPreviewKey, f as getMimeTypesForExtensions, _ as getProjectFormError, r as mapProjectArtifactsToOutputs, i as mapProjectDetailsToViewModel, a as mapProjectDtoToItem, o as mapProjectSource, s as mapProjectSourceToFilterTab, c as mapStoredContextFiles, p as resolveByteLimit, m as resolveExtensionList, n as splitProjectConversationId, b as toProjectContextFileAttachment, x as toProjectOutputAttachment, S as toProjectOutputCardId, C as toProjectPreviewKey, w as toStoredProjectFileAttachment, I as useCreateProject, B as usePinnedProjectChats, P as useProject, U as useProjectActions, V as useProjectArtifacts, R as useProjectConversations, D as useProjectDraft, T as useProjectFilePreview, F as useProjectWatch, M as useProjects, L as useSaveProject };
@@ -4,6 +4,8 @@ export interface SerializedKeyedWriter {
4
4
  enqueue: (key: string) => Promise<void>;
5
5
  /** Drops the write queued for `key` if it has not started; its promise resolves without writing. */
6
6
  drop: (key: string) => void;
7
+ /** Calls `listener` with the key of every write that succeeded; returns the function that removes it. */
8
+ subscribe: (listener: (key: string) => void) => () => void;
7
9
  }
8
10
  /** Returns a {@link SerializedKeyedWriter} over `write`; a failed write rejects only its own callers. */
9
11
  export declare const createSerializedKeyedWriter: (write: (key: string) => Promise<void>) => SerializedKeyedWriter;
@@ -1 +1 @@
1
- {"version":3,"file":"serialized-writer.d.ts","sourceRoot":"","sources":["../../src/shared/serialized-writer.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,MAAM,WAAW,qBAAqB;IACpC,6GAA6G;IAC7G,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,oGAAoG;IACpG,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAQD,yGAAyG;AACzG,eAAO,MAAM,2BAA2B,GACtC,OAAO,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,KACpC,qBAuCF,CAAC"}
1
+ {"version":3,"file":"serialized-writer.d.ts","sourceRoot":"","sources":["../../src/shared/serialized-writer.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,MAAM,WAAW,qBAAqB;IACpC,6GAA6G;IAC7G,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,oGAAoG;IACpG,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,yGAAyG;IACzG,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;CAC5D;AAQD,yGAAyG;AACzG,eAAO,MAAM,2BAA2B,GACtC,OAAO,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,KACpC,qBA4DF,CAAC"}
@@ -1,34 +1,43 @@
1
1
  //#region src/shared/serialized-writer.ts
2
2
  var e = (e) => {
3
- let t = /* @__PURE__ */ new Map(), n = Promise.resolve();
3
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = Promise.resolve(), i = (e) => {
4
+ for (let t of [...n]) try {
5
+ t(e);
6
+ } catch {}
7
+ };
4
8
  return {
5
- enqueue: (r) => {
6
- let i = t.get(r);
7
- if (i) return i.promise;
8
- let a, o, s = new Promise((e, t) => {
9
- a = e, o = t;
10
- }), c = {
11
- promise: s,
12
- resolve: a,
13
- reject: o
9
+ enqueue: (n) => {
10
+ let a = t.get(n);
11
+ if (a) return a.promise;
12
+ let o, s, c = new Promise((e, t) => {
13
+ o = e, s = t;
14
+ }), l = {
15
+ promise: c,
16
+ resolve: o,
17
+ reject: s
14
18
  };
15
- t.set(r, c);
16
- let l = n;
17
- return n = (async () => {
18
- if (await l, t.get(r) !== c) c.resolve();
19
+ t.set(n, l);
20
+ let u = r;
21
+ return r = (async () => {
22
+ if (await u, t.get(n) !== l) l.resolve();
19
23
  else {
20
- t.delete(r);
24
+ t.delete(n);
21
25
  try {
22
- await e(r), c.resolve();
26
+ await e(n);
23
27
  } catch (e) {
24
- c.reject(e);
28
+ l.reject(e);
29
+ return;
25
30
  }
31
+ i(n), l.resolve();
26
32
  }
27
- })(), s;
33
+ })(), c;
28
34
  },
29
35
  drop: (e) => {
30
36
  t.delete(e);
31
- }
37
+ },
38
+ subscribe: (e) => (n.add(e), () => {
39
+ n.delete(e);
40
+ })
32
41
  };
33
42
  };
34
43
  //#endregion