@epam/ai-dial-chat-hooks 1.3.0-dev.282 → 1.3.0-dev.288

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,37 +1,31 @@
1
1
  import { mapProjectDtoToItem as e, mapProjectSource as t } from "./project-mapping.js";
2
- import { readSseEvents as n } from "../shared/read-sse-events.js";
3
- import { applyProjectEvent as r, parseProjectWatchEvent as i } from "./project-events.js";
4
- import { useCallback as a, useEffect as o, useRef as s, useState as c } from "react";
2
+ import { applyProjectEvent as n } from "./project-events.js";
3
+ import { runProjectWatch as r } from "./project-watch-stream.js";
4
+ import { useCallback as i, useEffect as a, useRef as o, useState as s } from "react";
5
5
  //#region src/project/use-projects.ts
6
- var l = 1e3, u = [
7
- 1e3,
8
- 2e3,
9
- 4e3,
10
- 8e3,
11
- 16e3
12
- ], d = "\n", f = ({ items: n, incompleteSources: r }, i) => {
6
+ var c = 1e3, l = "\n", u = ({ items: n, incompleteSources: r }, i) => {
13
7
  let a = n.map(e);
14
8
  return {
15
9
  reloadToken: i,
16
10
  projects: a,
17
11
  incompleteSources: r.map(t),
18
12
  hasError: !1,
19
- watchKey: a.slice(0, l).map(({ id: e }) => e).sort().join(d)
13
+ watchKey: a.slice(0, c).map(({ id: e }) => e).sort().join(l)
20
14
  };
21
- }, p = (e, t) => {
22
- let [l, p] = c(0), [m, h] = c(), g = s(!1), _ = s(void 0);
23
- o(() => {
15
+ }, d = (e, t) => {
16
+ let [c, d] = s(0), [f, p] = s(), m = o(!1), h = o(void 0);
17
+ a(() => {
24
18
  if (!t) return;
25
19
  let n = new AbortController();
26
20
  return (async () => {
27
21
  try {
28
22
  let t = await e.listProjects(n.signal);
29
23
  if (n.signal.aborted) return;
30
- h(f(t, l));
24
+ p(u(t, c));
31
25
  } catch {
32
26
  if (n.signal.aborted) return;
33
- h({
34
- reloadToken: l,
27
+ p({
28
+ reloadToken: c,
35
29
  projects: [],
36
30
  incompleteSources: [],
37
31
  hasError: !0,
@@ -42,70 +36,57 @@ var l = 1e3, u = [
42
36
  }, [
43
37
  e,
44
38
  t,
45
- l
39
+ c
46
40
  ]);
47
- let v = a(async () => {
48
- _.current?.abort();
41
+ let g = i(async () => {
42
+ h.current?.abort();
49
43
  let t = new AbortController();
50
- _.current = t;
44
+ h.current = t;
51
45
  try {
52
46
  let n = await e.listProjects(t.signal);
53
47
  if (t.signal.aborted) return;
54
- h((e) => e == null || e.hasError ? e : f(n, e.reloadToken));
48
+ p((e) => e == null || e.hasError ? e : u(n, e.reloadToken));
55
49
  } catch {}
56
50
  }, [e]);
57
- o(() => () => _.current?.abort(), []);
58
- let y = m?.reloadToken === l ? m : void 0, b = t ? y?.watchKey ?? "" : "", { watchProjects: x } = e;
59
- o(() => {
60
- if (x == null || b === "" || g.current) return;
61
- let e = b.split(d), t = new AbortController(), a, o = (e) => {
62
- let n = i(e);
63
- return n != null && h((e) => {
64
- if (e == null) return e;
65
- let t = r(e.projects, n);
66
- return t === e.projects ? e : {
67
- ...e,
68
- projects: t
51
+ a(() => () => h.current?.abort(), []);
52
+ let _ = f?.reloadToken === c ? f : void 0, v = t ? _?.watchKey ?? "" : "", { watchProjects: y } = e;
53
+ a(() => {
54
+ if (y == null || v === "" || m.current) return;
55
+ let e = new AbortController();
56
+ return r({
57
+ watchProjects: y,
58
+ ids: v.split(l),
59
+ signal: e.signal,
60
+ onEvent: (e) => p((t) => {
61
+ if (t == null) return t;
62
+ let r = n(t.projects, e);
63
+ return r === t.projects ? t : {
64
+ ...t,
65
+ projects: r
69
66
  };
70
- }), t.signal.aborted;
71
- }, s = async (r, i) => {
72
- let a;
73
- try {
74
- a = await x(e, t.signal);
75
- } catch {
76
- if (t.signal.aborted) return;
77
- if (!i) {
78
- g.current = !0;
79
- return;
80
- }
81
- c(r + 1);
82
- return;
67
+ }),
68
+ onReconnected: () => {
69
+ g();
70
+ },
71
+ onUnavailable: () => {
72
+ m.current = !0;
83
73
  }
84
- i && v(), await n(a, o), !t.signal.aborted && c(0);
85
- }, c = (e) => {
86
- let t = u[e];
87
- t == null ? g.current = !0 : a = setTimeout(() => {
88
- s(e, !0);
89
- }, t);
90
- };
91
- return s(0, !1), () => {
92
- t.abort(), clearTimeout(a);
93
- };
74
+ }), () => e.abort();
94
75
  }, [
95
- x,
96
- b,
97
- v
76
+ y,
77
+ v,
78
+ g
98
79
  ]);
99
- let S = a(() => {
100
- p((e) => e + 1);
80
+ let b = i(() => {
81
+ d((e) => e + 1);
101
82
  }, []);
102
83
  return {
103
- projects: y?.projects ?? [],
104
- incompleteSources: y?.incompleteSources ?? [],
105
- isLoading: t && y == null,
106
- hasError: y?.hasError ?? !1,
107
- retry: S
84
+ projects: _?.projects ?? [],
85
+ incompleteSources: _?.incompleteSources ?? [],
86
+ isLoading: t && _ == null,
87
+ hasError: _?.hasError ?? !1,
88
+ retry: b
108
89
  };
109
90
  };
110
91
  //#endregion
111
- export { p as useProjects };
92
+ export { d as useProjects };
package/project.js CHANGED
@@ -3,8 +3,11 @@ import { mapProjectDetailsToViewModel as r, mapProjectDtoToItem as i, mapProject
3
3
  import { DEFAULT_PROJECT_CONTEXT_ALLOWED_EXTENSIONS as s, DEFAULT_PROJECT_CONTEXT_FILE_MAX_BYTES as c, DEFAULT_PROJECT_CONTEXT_TOTAL_MAX_BYTES as l, getMimeTypesForExtensions as u, resolveByteLimit as d, resolveExtensionList as f } from "./project/project-limits.js";
4
4
  import { ProjectFormErrorField as p, ProjectFormErrorReason as m, getProjectFormError as h } from "./project/project-form-errors.js";
5
5
  import { useProjects as g } from "./project/use-projects.js";
6
- import { useProject as _ } from "./project/use-project.js";
7
- import { useCreateProject as v, useSaveProject as y } from "./project/use-project-submit.js";
8
- import { useProjectConversations as b } from "./project/use-project-conversations.js";
9
- import { ProjectActionError as x, useProjectActions as S } from "./project/use-project-actions.js";
10
- export { s as DEFAULT_PROJECT_CONTEXT_ALLOWED_EXTENSIONS, c as DEFAULT_PROJECT_CONTEXT_FILE_MAX_BYTES, l as DEFAULT_PROJECT_CONTEXT_TOTAL_MAX_BYTES, x as ProjectActionError, p as ProjectFormErrorField, m as ProjectFormErrorReason, e as buildCreateConversationDto, t as createProjectsApiClient, u as getMimeTypesForExtensions, h as getProjectFormError, r as mapProjectDetailsToViewModel, i as mapProjectDtoToItem, a as mapProjectSource, o as mapStoredContextFiles, d as resolveByteLimit, f as resolveExtensionList, n as splitProjectConversationId, v as useCreateProject, _ as useProject, S as useProjectActions, b as useProjectConversations, g as useProjects, y as useSaveProject };
6
+ import { ProjectRefreshOutcome as _ } from "./project/project-refresh.js";
7
+ import { useProject as v } from "./project/use-project.js";
8
+ import { useProjectWatch as y } from "./project/use-project-watch.js";
9
+ import { useCreateProject as b, useSaveProject as x } from "./project/use-project-submit.js";
10
+ import { useProjectConversations as S } from "./project/use-project-conversations.js";
11
+ import { ProjectActionError as C, useProjectActions as w } from "./project/use-project-actions.js";
12
+ import { createSerializedKeyedWriter as T } from "./shared/serialized-writer.js";
13
+ export { s as DEFAULT_PROJECT_CONTEXT_ALLOWED_EXTENSIONS, c as DEFAULT_PROJECT_CONTEXT_FILE_MAX_BYTES, l as DEFAULT_PROJECT_CONTEXT_TOTAL_MAX_BYTES, C as ProjectActionError, p as ProjectFormErrorField, m as ProjectFormErrorReason, _ as ProjectRefreshOutcome, e as buildCreateConversationDto, t as createProjectsApiClient, T as createSerializedKeyedWriter, u as getMimeTypesForExtensions, h as getProjectFormError, r as mapProjectDetailsToViewModel, i as mapProjectDtoToItem, a as mapProjectSource, o as mapStoredContextFiles, d as resolveByteLimit, f as resolveExtensionList, n as splitProjectConversationId, b as useCreateProject, v as useProject, w as useProjectActions, S as useProjectConversations, y as useProjectWatch, g as useProjects, x as useSaveProject };
@@ -0,0 +1,10 @@
1
+ /** A write queue that runs one write at a time, in call order, and never queues a key twice. */
2
+ export interface SerializedKeyedWriter {
3
+ /** Queues a write for `key`, or joins the one already queued; settles when that write ran or was dropped. */
4
+ enqueue: (key: string) => Promise<void>;
5
+ /** Drops the write queued for `key` if it has not started; its promise resolves without writing. */
6
+ drop: (key: string) => void;
7
+ }
8
+ /** Returns a {@link SerializedKeyedWriter} over `write`; a failed write rejects only its own callers. */
9
+ export declare const createSerializedKeyedWriter: (write: (key: string) => Promise<void>) => SerializedKeyedWriter;
10
+ //# sourceMappingURL=serialized-writer.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,35 @@
1
+ //#region src/shared/serialized-writer.ts
2
+ var e = (e) => {
3
+ let t = /* @__PURE__ */ new Map(), n = Promise.resolve();
4
+ 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
14
+ };
15
+ t.set(r, c);
16
+ let l = n;
17
+ return n = (async () => {
18
+ if (await l, t.get(r) !== c) c.resolve();
19
+ else {
20
+ t.delete(r);
21
+ try {
22
+ await e(r), c.resolve();
23
+ } catch (e) {
24
+ c.reject(e);
25
+ }
26
+ }
27
+ })(), s;
28
+ },
29
+ drop: (e) => {
30
+ t.delete(e);
31
+ }
32
+ };
33
+ };
34
+ //#endregion
35
+ export { e as createSerializedKeyedWriter };