@epam/ai-dial-chat-hooks 1.3.0-dev.249 → 1.3.0-dev.253

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 (35) hide show
  1. package/entry-points/project.d.ts +10 -0
  2. package/entry-points/project.d.ts.map +1 -0
  3. package/index.d.ts +9 -0
  4. package/index.d.ts.map +1 -1
  5. package/index.js +118 -109
  6. package/package.json +25 -16
  7. package/project/project-form-errors.d.ts +23 -0
  8. package/project/project-form-errors.d.ts.map +1 -0
  9. package/project/project-form-errors.js +46 -0
  10. package/project/project-limits.d.ts +17 -0
  11. package/project/project-limits.d.ts.map +1 -0
  12. package/project/project-limits.js +11 -0
  13. package/project/project-mapping.d.ts +11 -0
  14. package/project/project-mapping.d.ts.map +1 -0
  15. package/project/project-mapping.js +36 -0
  16. package/project/projects-api-client.d.ts +157 -0
  17. package/project/projects-api-client.d.ts.map +1 -0
  18. package/project/projects-api-client.js +81 -0
  19. package/project/use-project-actions.d.ts +49 -0
  20. package/project/use-project-actions.d.ts.map +1 -0
  21. package/project/use-project-actions.js +102 -0
  22. package/project/use-project-conversations.d.ts +27 -0
  23. package/project/use-project-conversations.d.ts.map +1 -0
  24. package/project/use-project-conversations.js +109 -0
  25. package/project/use-project-submit.d.ts +49 -0
  26. package/project/use-project-submit.d.ts.map +1 -0
  27. package/project/use-project-submit.js +73 -0
  28. package/project/use-project.d.ts +20 -0
  29. package/project/use-project.d.ts.map +1 -0
  30. package/project/use-project.js +48 -0
  31. package/project/use-projects.d.ts +19 -0
  32. package/project/use-projects.d.ts.map +1 -0
  33. package/project/use-projects.js +46 -0
  34. package/project.d.ts +2 -0
  35. package/project.js +10 -0
@@ -0,0 +1,73 @@
1
+ import { getApiErrorDetails as e } from "../api-error/api-error.js";
2
+ import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
3
+ //#region src/project/use-project-submit.ts
4
+ var a = () => {
5
+ let [a, o] = i(!1), s = r(null);
6
+ return n(() => () => {
7
+ s.current?.abort();
8
+ }, []), {
9
+ run: t(async (t) => {
10
+ s.current?.abort();
11
+ let n = new AbortController();
12
+ s.current = n, o(!0);
13
+ try {
14
+ return {
15
+ isOk: !0,
16
+ value: await t(n.signal)
17
+ };
18
+ } catch (t) {
19
+ if (n.signal.aborted) return {
20
+ isOk: !1,
21
+ isAborted: !0
22
+ };
23
+ let { status: r, code: i, traceId: a } = await e(t);
24
+ return {
25
+ isOk: !1,
26
+ isAborted: !1,
27
+ status: r,
28
+ code: i,
29
+ requestId: a
30
+ };
31
+ } finally {
32
+ n.signal.aborted || o(!1), s.current === n && (s.current = null);
33
+ }
34
+ }, []),
35
+ isSubmitting: a
36
+ };
37
+ }, o = (e) => {
38
+ let { run: n, isSubmitting: r } = a();
39
+ return {
40
+ create: t(async (t, r) => {
41
+ let i = await n((n) => e.createProject(t, r, n));
42
+ if (i.isOk) return {
43
+ isCreated: !0,
44
+ project: i.value
45
+ };
46
+ let { isOk: a, ...o } = i;
47
+ return {
48
+ isCreated: !1,
49
+ ...o
50
+ };
51
+ }, [e, n]),
52
+ isSubmitting: r
53
+ };
54
+ }, s = (e) => {
55
+ let { run: n, isSubmitting: r } = a();
56
+ return {
57
+ save: t(async (t) => {
58
+ let r = await n((n) => e.updateProject(t, n));
59
+ if (r.isOk) return {
60
+ isSaved: !0,
61
+ project: r.value
62
+ };
63
+ let { isOk: i, ...a } = r;
64
+ return {
65
+ isSaved: !1,
66
+ ...a
67
+ };
68
+ }, [e, n]),
69
+ isSubmitting: r
70
+ };
71
+ };
72
+ //#endregion
73
+ export { o as useCreateProject, s as useSaveProject };
@@ -0,0 +1,20 @@
1
+ import { ProjectDetailsDto } from '@epam/ai-dial-chat-api-client';
2
+ import { ProjectsApiClient } from './projects-api-client';
3
+ /**
4
+ * Loads one project's details. Loading is derived from whether a result
5
+ * answers the current id and reload token, so a page never renders a stale
6
+ * project for a new id. A `404` is a not-found result, every other failure an
7
+ * error; the request is aborted on unmount and on an id change.
8
+ *
9
+ * @param client - Configured project requests, from `createProjectsApiClient`; it must be referentially stable, because a new object reloads.
10
+ * @param id - The project's DIAL id, or `null` when the route names none.
11
+ * @param enabled - Whether the page is enabled; no request is sent while `false`.
12
+ */
13
+ export declare const useProject: (client: Pick<ProjectsApiClient, "getProject">, id: string | null, enabled: boolean) => {
14
+ project: ProjectDetailsDto | null;
15
+ isLoading: boolean;
16
+ hasError: boolean;
17
+ isNotFound: boolean;
18
+ retry: () => void;
19
+ };
20
+ //# sourceMappingURL=use-project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-project.d.ts","sourceRoot":"","sources":["../../src/project/use-project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAGvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAU/D;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GACrB,QAAQ,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,EAC7C,IAAI,MAAM,GAAG,IAAI,EACjB,SAAS,OAAO;;;;;;CAuCjB,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { getApiErrorStatus as e } from "../api-error/api-error.js";
2
+ import { useCallback as t, useEffect as n, useState as r } from "react";
3
+ //#region src/project/use-project.ts
4
+ var i = (i, a, o) => {
5
+ let [s, c] = r(0), [l, u] = r(), d = `${s}:${a ?? ""}`;
6
+ n(() => {
7
+ if (!o || a == null) return;
8
+ let t = new AbortController();
9
+ return (async () => {
10
+ try {
11
+ let e = await i.getProject(a, t.signal);
12
+ if (t.signal.aborted) return;
13
+ u({
14
+ key: d,
15
+ project: e,
16
+ hasError: !1,
17
+ isNotFound: !1
18
+ });
19
+ } catch (n) {
20
+ if (t.signal.aborted) return;
21
+ let r = e(n) === 404;
22
+ u({
23
+ key: d,
24
+ project: null,
25
+ hasError: !r,
26
+ isNotFound: r
27
+ });
28
+ }
29
+ })(), () => t.abort();
30
+ }, [
31
+ i,
32
+ o,
33
+ a,
34
+ d
35
+ ]);
36
+ let f = t(() => {
37
+ c((e) => e + 1);
38
+ }, []), p = l?.key === d ? l : void 0;
39
+ return {
40
+ project: p?.project ?? null,
41
+ isLoading: o && a != null && p == null,
42
+ hasError: p?.hasError ?? !1,
43
+ isNotFound: p?.isNotFound ?? !1,
44
+ retry: f
45
+ };
46
+ };
47
+ //#endregion
48
+ export { i as useProject };
@@ -0,0 +1,19 @@
1
+ import { ProjectItem, ProjectSource } from '@epam/ai-dial-projects';
2
+ import { ProjectsApiClient } from './projects-api-client';
3
+ /**
4
+ * Loads the projects the session user can see, mapped to the Projects lib's
5
+ * cards. Loading is derived from whether a result answers the current reload
6
+ * token, so an enabled page is loading from its very first render. The
7
+ * request is aborted on unmount or when `enabled` turns false.
8
+ *
9
+ * @param client - Configured project requests, from `createProjectsApiClient`; it must be referentially stable, because a new object reloads.
10
+ * @param enabled - Whether the page is enabled; no request is sent while `false`.
11
+ */
12
+ export declare const useProjects: (client: Pick<ProjectsApiClient, "listProjects">, enabled: boolean) => {
13
+ projects: ProjectItem[];
14
+ incompleteSources: ProjectSource[];
15
+ isLoading: boolean;
16
+ hasError: boolean;
17
+ retry: () => void;
18
+ };
19
+ //# sourceMappingURL=use-projects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-projects.d.ts","sourceRoot":"","sources":["../../src/project/use-projects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAU/D;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,IAAI,CAAC,iBAAiB,EAAE,cAAc,CAAC,EAC/C,SAAS,OAAO;;;;;;CAiDjB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { mapProjectDtoToItem as e, mapProjectSource as t } from "./project-mapping.js";
2
+ import { useCallback as n, useEffect as r, useState as i } from "react";
3
+ //#region src/project/use-projects.ts
4
+ var a = (a, o) => {
5
+ let [s, c] = i(0), [l, u] = i();
6
+ r(() => {
7
+ if (!o) return;
8
+ let n = new AbortController();
9
+ return (async () => {
10
+ try {
11
+ let { items: r, incompleteSources: i } = await a.listProjects(n.signal);
12
+ if (n.signal.aborted) return;
13
+ u({
14
+ reloadToken: s,
15
+ projects: r.map(e),
16
+ incompleteSources: i.map(t),
17
+ hasError: !1
18
+ });
19
+ } catch {
20
+ if (n.signal.aborted) return;
21
+ u({
22
+ reloadToken: s,
23
+ projects: [],
24
+ incompleteSources: [],
25
+ hasError: !0
26
+ });
27
+ }
28
+ })(), () => n.abort();
29
+ }, [
30
+ a,
31
+ o,
32
+ s
33
+ ]);
34
+ let d = n(() => {
35
+ c((e) => e + 1);
36
+ }, []), f = l?.reloadToken === s ? l : void 0;
37
+ return {
38
+ projects: f?.projects ?? [],
39
+ incompleteSources: f?.incompleteSources ?? [],
40
+ isLoading: o && f == null,
41
+ hasError: f?.hasError ?? !1,
42
+ retry: d
43
+ };
44
+ };
45
+ //#endregion
46
+ export { a as useProjects };
package/project.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './entry-points/project.js'
2
+ export {}
package/project.js ADDED
@@ -0,0 +1,10 @@
1
+ import { buildCreateConversationDto as e, createProjectsApiClient as t, splitProjectConversationId as n } from "./project/projects-api-client.js";
2
+ import { mapProjectDetailsToViewModel as r, mapProjectDtoToItem as i, mapProjectSource as a, mapStoredContextFiles as o } from "./project/project-mapping.js";
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
+ import { ProjectFormErrorField as p, ProjectFormErrorReason as m, getProjectFormError as h } from "./project/project-form-errors.js";
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 };