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

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 (75) hide show
  1. package/api-error/api-error.d.ts +2 -0
  2. package/api-error/api-error.d.ts.map +1 -1
  3. package/api-error/api-error.js +31 -23
  4. package/catalog/map-skill-to-catalog-item.js +19 -19
  5. package/catalog/useCatalogEditNavigation/useCatalogEditNavigation.d.ts +2 -4
  6. package/catalog/useCatalogEditNavigation/useCatalogEditNavigation.d.ts.map +1 -1
  7. package/catalog/useCatalogEditNavigation/useCatalogEditNavigation.js +94 -112
  8. package/catalog/useCatalogItemDelete/useCatalogItemDelete.d.ts +41 -0
  9. package/catalog/useCatalogItemDelete/useCatalogItemDelete.d.ts.map +1 -0
  10. package/catalog/useCatalogItemDelete/useCatalogItemDelete.js +37 -0
  11. package/catalog/usePublishFolders/usePublishFolders.d.ts +8 -0
  12. package/catalog/usePublishFolders/usePublishFolders.d.ts.map +1 -1
  13. package/catalog/usePublishFolders/usePublishFolders.js +32 -29
  14. package/catalog.js +11 -10
  15. package/conversation/conversation-title-stream.d.ts +33 -0
  16. package/conversation/conversation-title-stream.d.ts.map +1 -0
  17. package/conversation/conversation-title-stream.js +103 -0
  18. package/conversation/useConversationExport/useConversationExport.js +46 -46
  19. package/conversation/useConversationHandlers/useConversationHandlers.js +39 -39
  20. package/conversation/useConversationStream/useConversationStream.js +93 -93
  21. package/conversation.js +5 -4
  22. package/entry-points/catalog.d.ts +1 -0
  23. package/entry-points/catalog.d.ts.map +1 -1
  24. package/entry-points/conversation.d.ts +1 -0
  25. package/entry-points/conversation.d.ts.map +1 -1
  26. package/entry-points/project.d.ts +3 -0
  27. package/entry-points/project.d.ts.map +1 -1
  28. package/files/dial-file-manager-copy-move.util.js +16 -16
  29. package/files/dial-file-manager-mapping.util.js +17 -17
  30. package/files/useDialFileListing/useDialFileListing.js +113 -113
  31. package/files/useDialFileMutations/useDialFileMutations.js +47 -47
  32. package/index.d.ts +5 -0
  33. package/index.d.ts.map +1 -1
  34. package/index.js +213 -208
  35. package/oauth/useToolsetLogin/useToolsetLogin.d.ts +7 -1
  36. package/oauth/useToolsetLogin/useToolsetLogin.d.ts.map +1 -1
  37. package/oauth/useToolsetLogin/useToolsetLogin.js +40 -21
  38. package/offline-credentials/useOfflineCredentialsGate/useOfflineCredentialsGate.js +10 -10
  39. package/package.json +18 -18
  40. package/project/project-events.d.ts +2 -2
  41. package/project/project-events.d.ts.map +1 -1
  42. package/project/project-events.js +3 -2
  43. package/project/project-mapping.js +12 -12
  44. package/project/project-refresh.d.ts +12 -0
  45. package/project/project-refresh.d.ts.map +1 -0
  46. package/project/project-refresh.js +6 -0
  47. package/project/project-watch-stream.d.ts +26 -0
  48. package/project/project-watch-stream.d.ts.map +1 -0
  49. package/project/project-watch-stream.js +39 -0
  50. package/project/projects-api-client.d.ts +6 -0
  51. package/project/projects-api-client.d.ts.map +1 -1
  52. package/project/projects-api-client.js +1 -0
  53. package/project/use-project-actions.js +12 -12
  54. package/project/use-project-conversations.d.ts +8 -6
  55. package/project/use-project-conversations.d.ts.map +1 -1
  56. package/project/use-project-conversations.js +129 -56
  57. package/project/use-project-watch.d.ts +24 -0
  58. package/project/use-project-watch.d.ts.map +1 -0
  59. package/project/use-project-watch.js +41 -0
  60. package/project/use-project.d.ts +4 -1
  61. package/project/use-project.d.ts.map +1 -1
  62. package/project/use-project.js +47 -22
  63. package/project/use-projects.d.ts.map +1 -1
  64. package/project/use-projects.js +49 -68
  65. package/project.js +8 -5
  66. package/prompt/prompt.d.ts +11 -0
  67. package/prompt/prompt.d.ts.map +1 -1
  68. package/prompt/prompt.js +7 -3
  69. package/scheduled-task/use-scheduled-task-runs.js +13 -13
  70. package/shared/serialized-writer.d.ts +10 -0
  71. package/shared/serialized-writer.d.ts.map +1 -0
  72. package/shared/serialized-writer.js +35 -0
  73. package/usage/map-user-usage-to-model-limits.js +21 -21
  74. package/useShareLink/useShareLink.js +18 -18
  75. package/utils.js +21 -21
@@ -9,30 +9,44 @@ var i = {
9
9
  }, a = {
10
10
  ...i,
11
11
  isLoading: !1
12
- }, o = ({ items: e }) => e.map(({ id: e, title: t, author: n }) => ({
13
- id: e,
14
- title: t,
15
- authorName: n
16
- })), s = (s, c) => {
17
- let [l, u] = r(i), [d, f] = r(0), p = n(null);
12
+ }, o = 50, s = 100, c = (e, t) => e.map(({ id: e, title: n, author: r, updatedAt: i, isUnread: a }) => {
13
+ let o = a;
14
+ if (t.has(e)) {
15
+ let n = t.get(e);
16
+ i != null && n != null && i > n ? t.delete(e) : o = !1;
17
+ }
18
+ return {
19
+ id: e,
20
+ title: n,
21
+ authorName: r,
22
+ ...o ? { isUnread: !0 } : {}
23
+ };
24
+ }), l = (l, u) => {
25
+ let [d, f] = r(i), [p, m] = r(0), h = n(null), g = n(null), _ = n(0), v = n(/* @__PURE__ */ new Map()), y = n(/* @__PURE__ */ new Map()), b = n(d);
18
26
  t(() => {
19
- if (c == null) {
20
- u(a);
27
+ b.current = d;
28
+ });
29
+ let x = e((e) => {
30
+ for (let { id: t, updatedAt: n } of e) y.current.set(t, n);
31
+ }, []);
32
+ t(() => {
33
+ if (v.current = /* @__PURE__ */ new Map(), y.current = /* @__PURE__ */ new Map(), u == null) {
34
+ f(a);
21
35
  return;
22
36
  }
23
37
  let e = new AbortController();
24
- return p.current = e, (async () => {
25
- u((e) => ({
38
+ return h.current = e, (async () => {
39
+ f((e) => ({
26
40
  ...e,
27
41
  isLoading: !0,
28
42
  hasError: !1,
29
43
  isLoadingMore: !1
30
44
  }));
31
45
  try {
32
- let t = await s.listProjectConversations(c, e.signal);
46
+ let t = await l.listProjectConversations(u, e.signal);
33
47
  if (e.signal.aborted) return;
34
- u({
35
- items: o(t),
48
+ x(t.items), f({
49
+ items: c(t.items, v.current),
36
50
  isLoading: !1,
37
51
  hasError: !1,
38
52
  hasMore: t.hasMore,
@@ -40,70 +54,129 @@ var i = {
40
54
  });
41
55
  } catch {
42
56
  if (e.signal.aborted) return;
43
- u({
57
+ f({
44
58
  ...a,
45
59
  hasError: !0
46
60
  });
47
61
  }
48
- })(), () => e.abort();
62
+ })(), () => {
63
+ e.abort(), g.current?.abort();
64
+ };
49
65
  }, [
50
- s,
51
- c,
52
- d
66
+ l,
67
+ u,
68
+ p,
69
+ x
53
70
  ]);
54
- let m = e(() => f((e) => e + 1), []), h = e(async () => {
55
- let e = p.current;
56
- if (c != null && e != null) {
57
- u((e) => ({
58
- ...e,
59
- isLoadingMore: !0
60
- }));
61
- try {
62
- let t = await s.listProjectConversations(c, e.signal, { offset: l.items.length });
63
- if (e.signal.aborted) return;
64
- u((e) => {
65
- let n = new Set(e.items.map((e) => e.id));
66
- return {
67
- ...e,
68
- items: [...e.items, ...o(t).filter((e) => !n.has(e.id))],
69
- hasMore: t.hasMore,
70
- isLoadingMore: !1
71
- };
72
- });
73
- } catch (t) {
74
- if (e.signal.aborted) return;
75
- throw u((e) => ({
71
+ let S = e(() => m((e) => e + 1), []), C = e(async () => {
72
+ let e = h.current;
73
+ if (u == null || e == null) return;
74
+ let t = _.current;
75
+ f((e) => ({
76
+ ...e,
77
+ isLoadingMore: !0
78
+ }));
79
+ try {
80
+ let n = await l.listProjectConversations(u, e.signal, { offset: d.items.length });
81
+ if (e.signal.aborted) return;
82
+ if (t !== _.current) {
83
+ f((e) => ({
76
84
  ...e,
77
85
  isLoadingMore: !1
78
- })), t;
86
+ }));
87
+ return;
79
88
  }
89
+ x(n.items), f((e) => {
90
+ let t = new Set(e.items.map((e) => e.id));
91
+ return {
92
+ ...e,
93
+ items: [...e.items, ...c(n.items, v.current).filter((e) => !t.has(e.id))],
94
+ hasMore: n.hasMore,
95
+ isLoadingMore: !1
96
+ };
97
+ });
98
+ } catch (t) {
99
+ if (e.signal.aborted) return;
100
+ throw f((e) => ({
101
+ ...e,
102
+ isLoadingMore: !1
103
+ })), t;
104
+ }
105
+ }, [
106
+ l,
107
+ u,
108
+ x,
109
+ d.items.length
110
+ ]), w = e(async () => {
111
+ let e = b.current;
112
+ if (u == null || e.isLoading || e.hasError) return;
113
+ g.current?.abort();
114
+ let t = new AbortController();
115
+ g.current = t, _.current += 1;
116
+ let n = Math.max(e.items.length, o), r = [], i = !0;
117
+ try {
118
+ for (; r.length < n && i;) {
119
+ let e = await l.listProjectConversations(u, t.signal, {
120
+ offset: r.length,
121
+ limit: Math.min(s, n - r.length)
122
+ });
123
+ if (t.signal.aborted) return;
124
+ if (r.push(...e.items), i = e.hasMore, e.items.length === 0) break;
125
+ }
126
+ } catch {
127
+ return;
80
128
  }
129
+ if (t.signal.aborted) return;
130
+ x(r);
131
+ let a = /* @__PURE__ */ new Set(), d = c(r, v.current).filter((e) => !a.has(e.id) && (a.add(e.id), !0));
132
+ f((e) => ({
133
+ ...e,
134
+ items: d,
135
+ hasMore: i,
136
+ isLoadingMore: !1
137
+ }));
81
138
  }, [
82
- s,
83
- c,
84
- l.items.length
85
- ]), g = e(async (e, t) => {
86
- let { name: n } = await s.renameProjectConversation(e, t);
87
- u((t) => ({
139
+ l,
140
+ u,
141
+ x
142
+ ]);
143
+ t(() => () => g.current?.abort(), []);
144
+ let T = e((e) => {
145
+ v.current.set(e, y.current.get(e)), f((t) => ({
146
+ ...t,
147
+ items: t.items.map((t) => t.id === e && t.isUnread ? {
148
+ ...t,
149
+ isUnread: !1
150
+ } : t)
151
+ })), (async () => {
152
+ try {
153
+ await l.markProjectConversationViewed?.(e);
154
+ } catch {}
155
+ })();
156
+ }, [l]), E = e(async (e, t) => {
157
+ let { name: n } = await l.renameProjectConversation(e, t);
158
+ f((t) => ({
88
159
  ...t,
89
160
  items: t.items.map((t) => t.id === e ? {
90
161
  ...t,
91
162
  title: n
92
163
  } : t)
93
164
  }));
94
- }, [s]), _ = e(async (e) => {
95
- await s.deleteProjectConversation(e), u((t) => ({
165
+ }, [l]), D = e(async (e) => {
166
+ await l.deleteProjectConversation(e), f((t) => ({
96
167
  ...t,
97
168
  items: t.items.filter((t) => t.id !== e)
98
169
  }));
99
- }, [s]);
170
+ }, [l]);
100
171
  return {
101
- ...l,
102
- retry: m,
103
- loadMore: h,
104
- rename: g,
105
- remove: _
172
+ ...d,
173
+ retry: S,
174
+ loadMore: C,
175
+ rename: E,
176
+ remove: D,
177
+ refresh: w,
178
+ markViewed: T
106
179
  };
107
180
  };
108
181
  //#endregion
109
- export { s as useProjectConversations };
182
+ export { l as useProjectConversations };
@@ -0,0 +1,24 @@
1
+ import { ProjectsApiClient } from './projects-api-client';
2
+ /** What `useProjectWatch` reports to the page that shows one project. */
3
+ export interface ProjectWatchOptions {
4
+ /** The loaded snapshot's aggregate ETag; the watch opens once it is known, and an event carrying it is skipped. */
5
+ etag: string | undefined;
6
+ /** Silent refresh of everything the page shows; at most one runs at a time, and a rejection is ignored. */
7
+ onChange: () => Promise<void>;
8
+ /** The project was deleted elsewhere; called at most once per project id. */
9
+ onDelete: () => void;
10
+ }
11
+ /**
12
+ * Keeps a page showing one project current: it watches that project, runs
13
+ * `onChange` for each change the page has not loaded yet — one at a time,
14
+ * plus one trailing run for whatever arrived meanwhile — and `onDelete` once
15
+ * when the project is deleted. A dropped stream is reopened with a bounded
16
+ * backoff and followed by one `onChange`; a watch that cannot be opened is
17
+ * not retried for the rest of the visit.
18
+ *
19
+ * @param client - Configured project requests, from `createProjectsApiClient`; it must be referentially stable, because a new object resubscribes.
20
+ * @param projectId - The watched project's DIAL id, or `null` while none is known.
21
+ * @param options - The loaded ETag and the page's callbacks; read at event time, so new identities never resubscribe.
22
+ */
23
+ export declare const useProjectWatch: (client: Pick<ProjectsApiClient, "watchProjects">, projectId: string | null, options: ProjectWatchOptions) => void;
24
+ //# sourceMappingURL=use-project-watch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-project-watch.d.ts","sourceRoot":"","sources":["../../src/project/use-project-watch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,yEAAyE;AACzE,MAAM,WAAW,mBAAmB;IAClC,mHAAmH;IACnH,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,2GAA2G;IAC3G,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAC1B,QAAQ,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EAChD,WAAW,MAAM,GAAG,IAAI,EACxB,SAAS,mBAAmB,KAC3B,IAwEF,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { runProjectWatch as e } from "./project-watch-stream.js";
2
+ import { ProjectWatchAction as t } from "@epam/ai-dial-chat-api-client";
3
+ import { useEffect as n, useRef as r } from "react";
4
+ //#region src/project/use-project-watch.ts
5
+ var i = (i, a, o) => {
6
+ let s = r(o);
7
+ n(() => {
8
+ s.current = o;
9
+ });
10
+ let c = r(null), l = o.etag != null, { watchProjects: u } = i;
11
+ n(() => {
12
+ if (u == null || a == null || !l || c.current === a) return;
13
+ let n = new AbortController(), r = !1, i = !1, o = () => {
14
+ n.signal.aborted || (r ? i = !0 : (r = !0, (async () => {
15
+ try {
16
+ await s.current.onChange();
17
+ } catch {} finally {
18
+ r = !1, i && (i = !1, o());
19
+ }
20
+ })()));
21
+ };
22
+ return e({
23
+ watchProjects: u,
24
+ ids: [a],
25
+ signal: n.signal,
26
+ onEvent: (e) => {
27
+ e.id !== a || n.signal.aborted || (e.action === t.Delete ? (i = !1, n.abort(), s.current.onDelete()) : (e.etag == null || e.etag !== s.current.etag) && o());
28
+ },
29
+ onReconnected: o,
30
+ onUnavailable: () => {
31
+ c.current = a;
32
+ }
33
+ }), () => n.abort();
34
+ }, [
35
+ u,
36
+ a,
37
+ l
38
+ ]);
39
+ };
40
+ //#endregion
41
+ export { i as useProjectWatch };
@@ -1,10 +1,12 @@
1
1
  import { ProjectDetailsDto } from '@epam/ai-dial-chat-api-client';
2
+ import { ProjectRefreshOutcome } from './project-refresh';
2
3
  import { ProjectsApiClient } from './projects-api-client';
3
4
  /**
4
5
  * Loads one project's details. Loading is derived from whether a result
5
6
  * answers the current id and reload token, so a page never renders a stale
6
7
  * 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
+ * error; the request is aborted on unmount and on an id change. `refresh`
9
+ * re-reads the loaded project without the loading state, for live updates.
8
10
  *
9
11
  * @param client - Configured project requests, from `createProjectsApiClient`; it must be referentially stable, because a new object reloads.
10
12
  * @param id - The project's DIAL id, or `null` when the route names none.
@@ -16,5 +18,6 @@ export declare const useProject: (client: Pick<ProjectsApiClient, "getProject">,
16
18
  hasError: boolean;
17
19
  isNotFound: boolean;
18
20
  retry: () => void;
21
+ refresh: () => Promise<ProjectRefreshOutcome>;
19
22
  };
20
23
  //# sourceMappingURL=use-project.d.ts.map
@@ -1 +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"}
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,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAU/D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GACrB,QAAQ,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,EAC7C,IAAI,MAAM,GAAG,IAAI,EACjB,SAAS,OAAO;;;;;;mBA2CsB,OAAO,CAAC,qBAAqB,CAAC;CA8BrE,CAAC"}
@@ -1,17 +1,18 @@
1
1
  import { getApiErrorStatus as e } from "../api-error/api-error.js";
2
- import { useCallback as t, useEffect as n, useState as r } from "react";
2
+ import { ProjectRefreshOutcome as t } from "./project-refresh.js";
3
+ import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
3
4
  //#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;
5
+ var o = (o, s, c) => {
6
+ let [l, u] = a(0), [d, f] = a(), p = `${l}:${s ?? ""}`;
7
+ r(() => {
8
+ if (!c || s == null) return;
8
9
  let t = new AbortController();
9
10
  return (async () => {
10
11
  try {
11
- let e = await i.getProject(a, t.signal);
12
+ let e = await o.getProject(s, t.signal);
12
13
  if (t.signal.aborted) return;
13
- u({
14
- key: d,
14
+ f({
15
+ key: p,
15
16
  project: e,
16
17
  hasError: !1,
17
18
  isNotFound: !1
@@ -19,8 +20,8 @@ var i = (i, a, o) => {
19
20
  } catch (n) {
20
21
  if (t.signal.aborted) return;
21
22
  let r = e(n) === 404;
22
- u({
23
- key: d,
23
+ f({
24
+ key: p,
24
25
  project: null,
25
26
  hasError: !r,
26
27
  isNotFound: r
@@ -28,21 +29,45 @@ var i = (i, a, o) => {
28
29
  }
29
30
  })(), () => t.abort();
30
31
  }, [
31
- i,
32
32
  o,
33
- a,
34
- d
33
+ c,
34
+ s,
35
+ p
36
+ ]);
37
+ let m = n(() => {
38
+ u((e) => e + 1);
39
+ }, []), h = d?.key === p ? d : void 0, g = h?.project ?? null, _ = i(null);
40
+ r(() => () => {
41
+ _.current?.abort(), _.current = null;
42
+ }, [p]);
43
+ let v = n(async () => {
44
+ if (g == null || s == null) return t.Skipped;
45
+ _.current?.abort();
46
+ let n = new AbortController();
47
+ _.current = n;
48
+ try {
49
+ let e = await o.getProject(s, n.signal);
50
+ return n.signal.aborted ? t.Skipped : (f((t) => t?.key === p ? {
51
+ ...t,
52
+ project: e
53
+ } : t), t.Updated);
54
+ } catch (r) {
55
+ return n.signal.aborted ? t.Skipped : e(r) === 404 ? t.NotFound : t.Failed;
56
+ }
57
+ }, [
58
+ o,
59
+ s,
60
+ p,
61
+ g
35
62
  ]);
36
- let f = t(() => {
37
- c((e) => e + 1);
38
- }, []), p = l?.key === d ? l : void 0;
39
63
  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
64
+ project: g,
65
+ isLoading: c && s != null && h == null,
66
+ hasError: h?.hasError ?? !1,
67
+ isNotFound: h?.isNotFound ?? !1,
68
+ retry: m,
69
+ refresh: v
45
70
  };
46
71
  };
47
72
  //#endregion
48
- export { i as useProject };
73
+ export { o as useProject };
@@ -1 +1 @@
1
- {"version":3,"file":"use-projects.d.ts","sourceRoot":"","sources":["../../src/project/use-projects.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAKzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAuC/D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,IAAI,CAAC,iBAAiB,EAAE,cAAc,GAAG,eAAe,CAAC,EACjE,SAAS,OAAO;;;;;;CAoIjB,CAAC"}
1
+ {"version":3,"file":"use-projects.d.ts","sourceRoot":"","sources":["../../src/project/use-projects.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAKzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAoC/D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,IAAI,CAAC,iBAAiB,EAAE,cAAc,GAAG,eAAe,CAAC,EACjE,SAAS,OAAO;;;;;;CAmGjB,CAAC"}
@@ -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 };
@@ -23,6 +23,17 @@ export declare const validatePromptName: (name: string) => PromptFieldError | nu
23
23
  export declare const validatePromptDescription: (description: string) => PromptFieldError | null;
24
24
  /** Validates a prompt body: required, and within the backend's length limit. */
25
25
  export declare const validatePromptContent: (content: string) => PromptFieldError | null;
26
+ /** Field errors of a prompt form, keyed by field. */
27
+ export interface PromptFieldErrors {
28
+ /** Error of the name field. */
29
+ name?: PromptFieldError;
30
+ /** Error of the description field. */
31
+ description?: PromptFieldError;
32
+ /** Error of the prompt body field. */
33
+ content?: PromptFieldError;
34
+ }
35
+ /** The validator of each prompt form field. */
36
+ export declare const PROMPT_FIELD_VALIDATORS: Record<keyof PromptFieldErrors, (value: string) => PromptFieldError | null>;
26
37
  /**
27
38
  * Returns the characters left before a limit, or `null` while still further
28
39
  * away than the announce threshold — a counter that fires on every keystroke
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/prompt/prompt.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,oBAAY,gBAAgB;IAC1B,gDAAgD;IAChD,QAAQ,aAAa;IACrB,kEAAkE;IAClE,OAAO,YAAY;IACnB,oEAAoE;IACpE,WAAW,gBAAgB;IAC3B,4EAA4E;IAC5E,QAAQ,aAAa;CACtB;AAiBD,8DAA8D;AAC9D,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,4EAA4E;AAC5E,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD,iEAAiE;AACjE,eAAO,MAAM,yBAAyB,QAAQ,CAAC;AAE/C,sFAAsF;AACtF,eAAO,MAAM,iCAAiC,KAAK,CAAC;AAEpD,yEAAyE;AACzE,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,gBAAgB,GAAG,IAMpE,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,yBAAyB,GACpC,aAAa,MAAM,KAClB,gBAAgB,GAAG,IAGZ,CAAC;AAEX,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,KACd,gBAAgB,GAAG,IAMrB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,MAAM,EACb,WAAW,MAAM,KAChB,MAAM,GAAG,IAGX,CAAC;AAEF,qFAAqF;AACrF,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,MAAM,MAAM,KAAG,MACxB,CAAC"}
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/prompt/prompt.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,oBAAY,gBAAgB;IAC1B,gDAAgD;IAChD,QAAQ,aAAa;IACrB,kEAAkE;IAClE,OAAO,YAAY;IACnB,oEAAoE;IACpE,WAAW,gBAAgB;IAC3B,4EAA4E;IAC5E,QAAQ,aAAa;CACtB;AAiBD,8DAA8D;AAC9D,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,4EAA4E;AAC5E,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD,iEAAiE;AACjE,eAAO,MAAM,yBAAyB,QAAQ,CAAC;AAE/C,sFAAsF;AACtF,eAAO,MAAM,iCAAiC,KAAK,CAAC;AAEpD,yEAAyE;AACzE,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,gBAAgB,GAAG,IAMpE,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,yBAAyB,GACpC,aAAa,MAAM,KAClB,gBAAgB,GAAG,IAGZ,CAAC;AAEX,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,KACd,gBAAgB,GAAG,IAMrB,CAAC;AAEF,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,sCAAsC;IACtC,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,sCAAsC;IACtC,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED,+CAA+C;AAC/C,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,MAAM,iBAAiB,EACvB,CAAC,KAAK,EAAE,MAAM,KAAK,gBAAgB,GAAG,IAAI,CAK3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,MAAM,EACb,WAAW,MAAM,KAChB,MAAM,GAAG,IAGX,CAAC;AAEF,qFAAqF;AACrF,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,MAAM,MAAM,KAAG,MACxB,CAAC"}
package/prompt/prompt.js CHANGED
@@ -4,9 +4,13 @@ var e = /* @__PURE__ */ function(e) {
4
4
  }({}), t = /^(?!\.{1,2}$)[a-zA-Z0-9 _.-]+$/, n = 256, r = 2e3, i = 5e4, a = 10, o = (e) => {
5
5
  let n = e.trim();
6
6
  return n.length === 0 ? "required" : n.length > 256 ? "tooLong" : t.test(n) ? null : "invalidName";
7
- }, s = (e) => e.length > 2e3 ? "tooLong" : null, c = (e) => e.trim().length === 0 ? "required" : e.length > 5e4 ? "tooLong" : null, l = (e, t) => {
7
+ }, s = (e) => e.length > 2e3 ? "tooLong" : null, c = (e) => e.trim().length === 0 ? "required" : e.length > 5e4 ? "tooLong" : null, l = {
8
+ name: o,
9
+ description: s,
10
+ content: c
11
+ }, u = (e, t) => {
8
12
  let n = t - e.length;
9
13
  return n <= 10 ? n : null;
10
- }, u = (e, t) => e ? `${e}/${t}` : t;
14
+ }, d = (e, t) => e ? `${e}/${t}` : t;
11
15
  //#endregion
12
- export { i as PROMPT_CONTENT_MAX_LENGTH, a as PROMPT_COUNTER_ANNOUNCE_THRESHOLD, r as PROMPT_DESCRIPTION_MAX_LENGTH, n as PROMPT_NAME_MAX_LENGTH, e as PromptFieldError, u as buildPromptPath, l as getRemainingCharacters, c as validatePromptContent, s as validatePromptDescription, o as validatePromptName };
16
+ export { i as PROMPT_CONTENT_MAX_LENGTH, a as PROMPT_COUNTER_ANNOUNCE_THRESHOLD, r as PROMPT_DESCRIPTION_MAX_LENGTH, l as PROMPT_FIELD_VALIDATORS, n as PROMPT_NAME_MAX_LENGTH, e as PromptFieldError, d as buildPromptPath, u as getRemainingCharacters, c as validatePromptContent, s as validatePromptDescription, o as validatePromptName };