@lumerahq/ui 0.10.0 → 0.11.0-dev.0

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.
@@ -860,6 +860,100 @@ function accumulateTokenUsage(current, incoming) {
860
860
  } : current.cost
861
861
  };
862
862
  }
863
+ function useAgentChatSessions({
864
+ agentId,
865
+ transport,
866
+ disabled = false,
867
+ autoLoad = true,
868
+ onError
869
+ }) {
870
+ const [sessions, setSessions] = useState([]);
871
+ const [activeSessionId, setActiveSessionId] = useState(void 0);
872
+ const [error, setError] = useState(null);
873
+ const [isLoading, setIsLoading] = useState(false);
874
+ const [isRenaming, setIsRenaming] = useState(false);
875
+ const handleError = useCallback(
876
+ (err) => {
877
+ setError(err);
878
+ onError?.(err);
879
+ },
880
+ [onError]
881
+ );
882
+ const loadSessions = useCallback(async () => {
883
+ if (disabled) return void 0;
884
+ if (!transport.listSessions) {
885
+ const err = new Error("Agent chat transport does not support listing sessions.");
886
+ handleError(err);
887
+ return void 0;
888
+ }
889
+ setIsLoading(true);
890
+ setError(null);
891
+ try {
892
+ const result = await transport.listSessions({ agentId });
893
+ setSessions(result.sessions);
894
+ setActiveSessionId(result.activeSessionId ?? result.sessions[0]?.id);
895
+ return result;
896
+ } catch (err) {
897
+ handleError(err);
898
+ return void 0;
899
+ } finally {
900
+ setIsLoading(false);
901
+ }
902
+ }, [agentId, disabled, handleError, transport]);
903
+ const renameSession = useCallback(
904
+ async (sessionId, name) => {
905
+ if (disabled) return void 0;
906
+ if (!transport.renameSession) {
907
+ const err = new Error("Agent chat transport does not support renaming sessions.");
908
+ handleError(err);
909
+ return void 0;
910
+ }
911
+ const trimmedName = name.trim();
912
+ if (!trimmedName) {
913
+ const err = new Error("Session name is required.");
914
+ handleError(err);
915
+ return void 0;
916
+ }
917
+ setIsRenaming(true);
918
+ setError(null);
919
+ try {
920
+ const session = await transport.renameSession({ agentId, sessionId, name: trimmedName });
921
+ setSessions((current) => replaceSession(current, session));
922
+ setActiveSessionId((current) => current ?? session.id);
923
+ return session;
924
+ } catch (err) {
925
+ handleError(err);
926
+ return void 0;
927
+ } finally {
928
+ setIsRenaming(false);
929
+ }
930
+ },
931
+ [agentId, disabled, handleError, transport]
932
+ );
933
+ useEffect(() => {
934
+ if (!autoLoad || disabled) return;
935
+ void loadSessions();
936
+ }, [autoLoad, disabled, loadSessions]);
937
+ return {
938
+ sessions,
939
+ activeSessionId,
940
+ error,
941
+ isLoading,
942
+ isRenaming,
943
+ setSessions,
944
+ loadSessions,
945
+ renameSession
946
+ };
947
+ }
948
+ function replaceSession(sessions, next) {
949
+ let found = false;
950
+ const updated = sessions.map((session) => {
951
+ if (session.id !== next.id) return session;
952
+ found = true;
953
+ return next;
954
+ });
955
+ return found ? updated : [next, ...updated];
956
+ }
863
957
  function useAutomationRun(options) {
864
958
  const {
865
959
  agentId,
@@ -989,6 +1083,7 @@ function useAutomationRun(options) {
989
1083
  };
990
1084
  }
991
1085
  export {
992
- useAutomationRun as a,
1086
+ useAgentChatSessions as a,
1087
+ useAutomationRun as b,
993
1088
  useAgentChat as u
994
1089
  };
@@ -1,100 +1,6 @@
1
- import { useState, useCallback, useEffect, useMemo } from "react";
2
1
  import { useQueryClient, useQuery, useMutation } from "@tanstack/react-query";
2
+ import { useState, useCallback, useEffect, useMemo } from "react";
3
3
  import { T as listRunsByAgent, z as automationStatuses, F as createAutomationRun, y as uploadFile, o as onInitMessage, t as pbSql, v as pbUpdateRecord } from "./automations-Bb9nlU05.js";
4
- function useAgentChatSessions({
5
- agentId,
6
- transport,
7
- disabled = false,
8
- autoLoad = true,
9
- onError
10
- }) {
11
- const [sessions, setSessions] = useState([]);
12
- const [activeSessionId, setActiveSessionId] = useState(void 0);
13
- const [error, setError] = useState(null);
14
- const [isLoading, setIsLoading] = useState(false);
15
- const [isRenaming, setIsRenaming] = useState(false);
16
- const handleError = useCallback(
17
- (err) => {
18
- setError(err);
19
- onError?.(err);
20
- },
21
- [onError]
22
- );
23
- const loadSessions = useCallback(async () => {
24
- if (disabled) return void 0;
25
- if (!transport.listSessions) {
26
- const err = new Error("Agent chat transport does not support listing sessions.");
27
- handleError(err);
28
- return void 0;
29
- }
30
- setIsLoading(true);
31
- setError(null);
32
- try {
33
- const result = await transport.listSessions({ agentId });
34
- setSessions(result.sessions);
35
- setActiveSessionId(result.activeSessionId ?? result.sessions[0]?.id);
36
- return result;
37
- } catch (err) {
38
- handleError(err);
39
- return void 0;
40
- } finally {
41
- setIsLoading(false);
42
- }
43
- }, [agentId, disabled, handleError, transport]);
44
- const renameSession = useCallback(
45
- async (sessionId, name) => {
46
- if (disabled) return void 0;
47
- if (!transport.renameSession) {
48
- const err = new Error("Agent chat transport does not support renaming sessions.");
49
- handleError(err);
50
- return void 0;
51
- }
52
- const trimmedName = name.trim();
53
- if (!trimmedName) {
54
- const err = new Error("Session name is required.");
55
- handleError(err);
56
- return void 0;
57
- }
58
- setIsRenaming(true);
59
- setError(null);
60
- try {
61
- const session = await transport.renameSession({ agentId, sessionId, name: trimmedName });
62
- setSessions((current) => replaceSession(current, session));
63
- setActiveSessionId((current) => current ?? session.id);
64
- return session;
65
- } catch (err) {
66
- handleError(err);
67
- return void 0;
68
- } finally {
69
- setIsRenaming(false);
70
- }
71
- },
72
- [agentId, disabled, handleError, transport]
73
- );
74
- useEffect(() => {
75
- if (!autoLoad || disabled) return;
76
- void loadSessions();
77
- }, [autoLoad, disabled, loadSessions]);
78
- return {
79
- sessions,
80
- activeSessionId,
81
- error,
82
- isLoading,
83
- isRenaming,
84
- setSessions,
85
- loadSessions,
86
- renameSession
87
- };
88
- }
89
- function replaceSession(sessions, next) {
90
- let found = false;
91
- const updated = sessions.map((session) => {
92
- if (session.id !== next.id) return session;
93
- found = true;
94
- return next;
95
- });
96
- return found ? updated : [next, ...updated];
97
- }
98
4
  function useAutomationAgent({
99
5
  agentId,
100
6
  limit = 5,
@@ -427,11 +333,10 @@ function useSqlTable(options) {
427
333
  };
428
334
  }
429
335
  export {
430
- useAutomationAgent as a,
431
- useFileUpload as b,
432
- useLumeraUser as c,
433
- usePbSql as d,
434
- usePbUpdate as e,
435
- useSqlTable as f,
436
- useAgentChatSessions as u
336
+ useFileUpload as a,
337
+ useLumeraUser as b,
338
+ usePbSql as c,
339
+ usePbUpdate as d,
340
+ useSqlTable as e,
341
+ useAutomationAgent as u
437
342
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumerahq/ui",
3
- "version": "0.10.0",
3
+ "version": "0.11.0-dev.0",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -1,4 +0,0 @@
1
- import { p } from "./RecordSheet-BhWMav4R.js";
2
- export {
3
- p as Mermaid
4
- };