@autobe/ui 0.29.2 → 0.30.0-dev.20260315

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 (151) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +261 -0
  3. package/lib/components/AutoBeChatMain.js +5 -5
  4. package/lib/components/AutoBeChatMain.js.map +1 -1
  5. package/lib/components/AutoBeConfigModal.js +9 -9
  6. package/lib/components/AutoBeStatusModal.js +4 -4
  7. package/lib/components/AutoBeStatusModal.js.map +1 -1
  8. package/lib/components/AutoBeUserMessageMovie.d.ts +2 -2
  9. package/lib/components/common/ChatBubble.d.ts +2 -2
  10. package/lib/components/common/openai/OpenAIContent.d.ts +2 -2
  11. package/lib/components/common/openai/OpenAIContent.js.map +1 -1
  12. package/lib/components/common/openai/OpenAIUserAudioContent.js +1 -1
  13. package/lib/components/common/openai/OpenAIUserAudioContent.js.map +1 -1
  14. package/lib/components/common/openai/OpenAIUserFileContent.js +1 -1
  15. package/lib/components/common/openai/OpenAIUserFileContent.js.map +1 -1
  16. package/lib/components/common/openai/OpenAIUserImageContent.d.ts +2 -2
  17. package/lib/components/events/AutoBeCompleteEventMovie.d.ts +2 -2
  18. package/lib/components/events/AutoBeCompleteEventMovie.js +5 -5
  19. package/lib/components/events/AutoBeCompleteEventMovie.js.map +1 -1
  20. package/lib/components/events/AutoBeCorrectEventMovie.d.ts +2 -2
  21. package/lib/components/events/AutoBeCorrectEventMovie.js +4 -4
  22. package/lib/components/events/AutoBeCorrectEventMovie.js.map +1 -1
  23. package/lib/components/events/AutoBeEventMovie.js +38 -17
  24. package/lib/components/events/AutoBeEventMovie.js.map +1 -1
  25. package/lib/components/events/AutoBeProgressEventMovie.js +73 -13
  26. package/lib/components/events/AutoBeProgressEventMovie.js.map +1 -1
  27. package/lib/components/events/AutoBeScenarioEventMovie.d.ts +2 -2
  28. package/lib/components/events/AutoBeScenarioEventMovie.js +18 -5
  29. package/lib/components/events/AutoBeScenarioEventMovie.js.map +1 -1
  30. package/lib/components/events/AutoBeStartEventMovie.d.ts +2 -2
  31. package/lib/components/events/AutoBeStartEventMovie.js +2 -2
  32. package/lib/components/events/AutoBeStartEventMovie.js.map +1 -1
  33. package/lib/components/events/AutoBeValidateEventMovie.d.ts +2 -2
  34. package/lib/components/events/AutoBeValidateEventMovie.js +3 -11
  35. package/lib/components/events/AutoBeValidateEventMovie.js.map +1 -1
  36. package/lib/components/events/groups/CorrectEventGroup.d.ts +2 -2
  37. package/lib/components/events/groups/CorrectEventGroup.js +1 -1
  38. package/lib/components/events/groups/CorrectEventGroup.js.map +1 -1
  39. package/lib/components/events/groups/ValidateEventGroup.d.ts +2 -2
  40. package/lib/components/events/groups/ValidateEventGroup.js +1 -2
  41. package/lib/components/events/groups/ValidateEventGroup.js.map +1 -1
  42. package/lib/components/events/utils/eventGrouper.js +1 -2
  43. package/lib/components/events/utils/eventGrouper.js.map +1 -1
  44. package/lib/components/upload/AutoBeChatUploadBox.d.ts +3 -4
  45. package/lib/components/upload/AutoBeChatUploadBox.js +2 -1
  46. package/lib/components/upload/AutoBeChatUploadBox.js.map +1 -1
  47. package/lib/components/upload/AutoBeChatUploadSendButton.js +1 -1
  48. package/lib/components/upload/AutoBeChatUploadSendButton.js.map +1 -1
  49. package/lib/context/AutoBeAgentContext.d.ts +1 -3
  50. package/lib/context/AutoBeAgentContext.js +0 -4
  51. package/lib/context/AutoBeAgentContext.js.map +1 -1
  52. package/lib/hooks/useSessionStorage.d.ts +4 -0
  53. package/lib/hooks/useSessionStorage.js +16 -0
  54. package/lib/hooks/useSessionStorage.js.map +1 -0
  55. package/lib/index.d.ts +1 -0
  56. package/lib/index.js +1 -0
  57. package/lib/index.js.map +1 -1
  58. package/lib/strategy/AutoBeAgentSessionStorageStrategy.d.ts +10 -0
  59. package/lib/strategy/AutoBeAgentSessionStorageStrategy.js +117 -0
  60. package/lib/strategy/AutoBeAgentSessionStorageStrategy.js.map +1 -0
  61. package/lib/structure/AutoBeListener.js +91 -23
  62. package/lib/structure/AutoBeListener.js.map +1 -1
  63. package/lib/structure/AutoBeListenerState.d.ts +3 -3
  64. package/lib/structure/AutoBeListenerState.js +4 -4
  65. package/lib/structure/AutoBeListenerState.js.map +1 -1
  66. package/lib/structure/IAutoBeAgentSessionStorageStrategy.js +1 -1
  67. package/lib/structure/IAutoBeAgentSessionStorageStrategy.js.map +1 -1
  68. package/lib/utils/AutoBeFileUploader.d.ts +2 -2
  69. package/lib/utils/AutoBeFileUploader.js.map +1 -1
  70. package/package.json +3 -4
  71. package/src/components/AutoBeAssistantMessageMovie.tsx +22 -22
  72. package/src/components/AutoBeChatMain.tsx +376 -376
  73. package/src/components/AutoBeChatSidebar.tsx +414 -414
  74. package/src/components/AutoBeConfigButton.tsx +83 -83
  75. package/src/components/AutoBeConfigModal.tsx +443 -443
  76. package/src/components/AutoBeStatusButton.tsx +75 -75
  77. package/src/components/AutoBeStatusModal.tsx +486 -484
  78. package/src/components/AutoBeUserMessageMovie.tsx +27 -27
  79. package/src/components/common/ActionButton.tsx +205 -205
  80. package/src/components/common/ActionButtonGroup.tsx +80 -80
  81. package/src/components/common/AutoBeConfigInput.tsx +185 -185
  82. package/src/components/common/ChatBubble.tsx +119 -119
  83. package/src/components/common/Collapsible.tsx +95 -95
  84. package/src/components/common/CompactSessionIndicator.tsx +73 -73
  85. package/src/components/common/CompactSessionList.tsx +82 -82
  86. package/src/components/common/index.ts +8 -8
  87. package/src/components/common/openai/OpenAIContent.tsx +53 -53
  88. package/src/components/common/openai/OpenAIUserAudioContent.tsx +70 -70
  89. package/src/components/common/openai/OpenAIUserFileContent.tsx +76 -76
  90. package/src/components/common/openai/OpenAIUserImageContent.tsx +34 -34
  91. package/src/components/common/openai/OpenAIUserTextContent.tsx +15 -15
  92. package/src/components/common/openai/index.ts +5 -5
  93. package/src/components/events/AutoBeCompleteEventMovie.tsx +402 -402
  94. package/src/components/events/AutoBeCorrectEventMovie.tsx +354 -368
  95. package/src/components/events/AutoBeEventGroupMovie.tsx +18 -18
  96. package/src/components/events/AutoBeEventMovie.tsx +158 -139
  97. package/src/components/events/AutoBeProgressEventMovie.tsx +217 -157
  98. package/src/components/events/AutoBeScenarioEventMovie.tsx +135 -95
  99. package/src/components/events/AutoBeStartEventMovie.tsx +82 -82
  100. package/src/components/events/AutoBeValidateEventMovie.tsx +249 -286
  101. package/src/components/events/README.md +300 -300
  102. package/src/components/events/common/CollapsibleEventGroup.tsx +211 -211
  103. package/src/components/events/common/EventCard.tsx +61 -61
  104. package/src/components/events/common/EventContent.tsx +31 -31
  105. package/src/components/events/common/EventHeader.tsx +85 -85
  106. package/src/components/events/common/EventIcon.tsx +82 -82
  107. package/src/components/events/common/ProgressBar.tsx +64 -64
  108. package/src/components/events/common/index.ts +13 -13
  109. package/src/components/events/groups/CorrectEventGroup.tsx +183 -183
  110. package/src/components/events/groups/ValidateEventGroup.tsx +143 -146
  111. package/src/components/events/groups/index.ts +8 -8
  112. package/src/components/events/index.ts +16 -16
  113. package/src/components/events/utils/eventGrouper.tsx +116 -117
  114. package/src/components/events/utils/index.ts +1 -1
  115. package/src/components/index.ts +13 -13
  116. package/src/components/upload/AutoBeChatUploadBox.tsx +425 -424
  117. package/src/components/upload/AutoBeChatUploadSendButton.tsx +66 -66
  118. package/src/components/upload/AutoBeFileUploadBox.tsx +123 -123
  119. package/src/components/upload/AutoBeUploadConfig.ts +5 -5
  120. package/src/components/upload/AutoBeVoiceRecoderButton.tsx +100 -100
  121. package/src/components/upload/index.ts +5 -5
  122. package/src/constant/color.ts +28 -28
  123. package/src/context/AutoBeAgentContext.tsx +245 -258
  124. package/src/context/AutoBeAgentSessionList.tsx +58 -58
  125. package/src/context/SearchParamsContext.tsx +49 -49
  126. package/src/hooks/index.ts +3 -3
  127. package/src/hooks/useEscapeKey.ts +24 -24
  128. package/src/hooks/useIsomorphicLayoutEffect.ts +8 -8
  129. package/src/hooks/useMediaQuery.ts +73 -73
  130. package/src/hooks/useSessionStorage.ts +10 -0
  131. package/src/icons/Receipt.tsx +74 -74
  132. package/src/index.ts +9 -8
  133. package/src/strategy/AutoBeAgentSessionStorageStrategy.ts +127 -0
  134. package/src/structure/AutoBeListener.ts +373 -304
  135. package/src/structure/AutoBeListenerState.ts +53 -53
  136. package/src/structure/IAutoBeAgentSessionStorageStrategy.ts +87 -87
  137. package/src/structure/IAutoBeEventGroup.ts +6 -6
  138. package/src/structure/index.ts +4 -4
  139. package/src/types/config.ts +44 -44
  140. package/src/types/index.ts +1 -1
  141. package/src/utils/AutoBeFileUploader.ts +279 -279
  142. package/src/utils/AutoBeVoiceRecorder.ts +95 -95
  143. package/src/utils/__tests__/crypto.test.ts +286 -286
  144. package/src/utils/__tests__/storage.test.ts +229 -229
  145. package/src/utils/crypto.ts +95 -95
  146. package/src/utils/index.ts +6 -6
  147. package/src/utils/number.ts +17 -17
  148. package/src/utils/storage.ts +96 -96
  149. package/src/utils/time.ts +14 -14
  150. package/tsconfig.json +9 -9
  151. package/vitest.config.ts +15 -15
@@ -1,49 +1,49 @@
1
- import {
2
- ReactNode,
3
- createContext,
4
- useContext,
5
- useEffect,
6
- useState,
7
- } from "react";
8
-
9
- interface SearchParamsContextType {
10
- searchParams: URLSearchParams;
11
- setSearchParams: React.Dispatch<React.SetStateAction<URLSearchParams>>;
12
- }
13
-
14
- const SearchParamsContext = createContext<SearchParamsContextType | null>(null);
15
-
16
- export function SearchParamsProvider({ children }: { children: ReactNode }) {
17
- const [searchParams, setSearchParams] = useState<URLSearchParams>(
18
- new URLSearchParams(window.location.search),
19
- );
20
-
21
- useEffect(() => {
22
- const url = new URL(`${window.location.origin}${window.location.pathname}`);
23
- searchParams.forEach((value, key) => {
24
- url.searchParams.set(key, value);
25
- });
26
- window.history.pushState({}, "", url);
27
- }, [searchParams]);
28
-
29
- return (
30
- <SearchParamsContext
31
- value={{
32
- searchParams,
33
- setSearchParams,
34
- }}
35
- >
36
- {children}
37
- </SearchParamsContext>
38
- );
39
- }
40
-
41
- export function useSearchParams() {
42
- const context = useContext(SearchParamsContext);
43
- if (!context) {
44
- throw new Error(
45
- "useSearchParams must be used within a SearchParamsProvider",
46
- );
47
- }
48
- return context;
49
- }
1
+ import {
2
+ ReactNode,
3
+ createContext,
4
+ useContext,
5
+ useEffect,
6
+ useState,
7
+ } from "react";
8
+
9
+ interface SearchParamsContextType {
10
+ searchParams: URLSearchParams;
11
+ setSearchParams: React.Dispatch<React.SetStateAction<URLSearchParams>>;
12
+ }
13
+
14
+ const SearchParamsContext = createContext<SearchParamsContextType | null>(null);
15
+
16
+ export function SearchParamsProvider({ children }: { children: ReactNode }) {
17
+ const [searchParams, setSearchParams] = useState<URLSearchParams>(
18
+ new URLSearchParams(window.location.search),
19
+ );
20
+
21
+ useEffect(() => {
22
+ const url = new URL(`${window.location.origin}${window.location.pathname}`);
23
+ searchParams.forEach((value, key) => {
24
+ url.searchParams.set(key, value);
25
+ });
26
+ window.history.pushState({}, "", url);
27
+ }, [searchParams]);
28
+
29
+ return (
30
+ <SearchParamsContext
31
+ value={{
32
+ searchParams,
33
+ setSearchParams,
34
+ }}
35
+ >
36
+ {children}
37
+ </SearchParamsContext>
38
+ );
39
+ }
40
+
41
+ export function useSearchParams() {
42
+ const context = useContext(SearchParamsContext);
43
+ if (!context) {
44
+ throw new Error(
45
+ "useSearchParams must be used within a SearchParamsProvider",
46
+ );
47
+ }
48
+ return context;
49
+ }
@@ -1,3 +1,3 @@
1
- export * from "./useEscapeKey";
2
- export * from "./useIsomorphicLayoutEffect";
3
- export * from "./useMediaQuery";
1
+ export * from "./useEscapeKey";
2
+ export * from "./useIsomorphicLayoutEffect";
3
+ export * from "./useMediaQuery";
@@ -1,24 +1,24 @@
1
- import { useEffect } from "react";
2
-
3
- /**
4
- * Hook to handle ESC key press to close modal or overlay
5
- *
6
- * @param isOpen - Whether the modal/overlay is open
7
- * @param onClose - Callback function to close the modal/overlay
8
- */
9
- export const useEscapeKey = (isOpen: boolean, onClose: () => void): void => {
10
- useEffect(() => {
11
- const handleKeyDown = (event: KeyboardEvent) => {
12
- if (event.key === "Escape" && isOpen) {
13
- onClose();
14
- }
15
- };
16
-
17
- if (isOpen) {
18
- document.addEventListener("keydown", handleKeyDown);
19
- return () => {
20
- document.removeEventListener("keydown", handleKeyDown);
21
- };
22
- }
23
- }, [isOpen, onClose]);
24
- };
1
+ import { useEffect } from "react";
2
+
3
+ /**
4
+ * Hook to handle ESC key press to close modal or overlay
5
+ *
6
+ * @param isOpen - Whether the modal/overlay is open
7
+ * @param onClose - Callback function to close the modal/overlay
8
+ */
9
+ export const useEscapeKey = (isOpen: boolean, onClose: () => void): void => {
10
+ useEffect(() => {
11
+ const handleKeyDown = (event: KeyboardEvent) => {
12
+ if (event.key === "Escape" && isOpen) {
13
+ onClose();
14
+ }
15
+ };
16
+
17
+ if (isOpen) {
18
+ document.addEventListener("keydown", handleKeyDown);
19
+ return () => {
20
+ document.removeEventListener("keydown", handleKeyDown);
21
+ };
22
+ }
23
+ }, [isOpen, onClose]);
24
+ };
@@ -1,8 +1,8 @@
1
- /**
2
- * From usehooks-ts
3
- * https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect
4
- */
5
- import { useEffect, useLayoutEffect } from "react";
6
-
7
- export const useIsomorphicLayoutEffect =
8
- typeof window !== "undefined" ? useLayoutEffect : useEffect;
1
+ /**
2
+ * From usehooks-ts
3
+ * https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect
4
+ */
5
+ import { useEffect, useLayoutEffect } from "react";
6
+
7
+ export const useIsomorphicLayoutEffect =
8
+ typeof window !== "undefined" ? useLayoutEffect : useEffect;
@@ -1,73 +1,73 @@
1
- /** From usehooks-ts https://usehooks-ts.com/react-hook/use-media-query */
2
- import { useState } from "react";
3
-
4
- import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
5
-
6
- type UseMediaQueryOptions = {
7
- defaultValue?: boolean;
8
- initializeWithValue?: boolean;
9
- };
10
-
11
- const IS_SERVER = typeof window === "undefined";
12
-
13
- export function useMediaQuery(
14
- query: string,
15
- {
16
- defaultValue = false,
17
- initializeWithValue = true,
18
- }: UseMediaQueryOptions = {},
19
- ): boolean {
20
- const getMatches = (query: string): boolean => {
21
- if (IS_SERVER) {
22
- return defaultValue;
23
- }
24
- return window.matchMedia(query).matches;
25
- };
26
-
27
- const [matches, setMatches] = useState<boolean>(() => {
28
- if (initializeWithValue) {
29
- return getMatches(query);
30
- }
31
- return defaultValue;
32
- });
33
-
34
- // Handles the change event of the media query.
35
- function handleChange() {
36
- setMatches(getMatches(query));
37
- }
38
-
39
- useIsomorphicLayoutEffect(() => {
40
- const matchMedia = window.matchMedia(query);
41
-
42
- // Triggered at the first client-side load and if query changes
43
- handleChange();
44
-
45
- // Use deprecated `addListener` and `removeListener` to support Safari < 14 (#135)
46
- if (matchMedia.addListener) {
47
- matchMedia.addListener(handleChange);
48
- } else {
49
- matchMedia.addEventListener("change", handleChange);
50
- }
51
-
52
- return () => {
53
- if (matchMedia.removeListener) {
54
- matchMedia.removeListener(handleChange);
55
- } else {
56
- matchMedia.removeEventListener("change", handleChange);
57
- }
58
- };
59
- }, [query]);
60
-
61
- return matches;
62
- }
63
-
64
- export namespace useMediaQuery {
65
- export const WIDTH_XL = "80rem";
66
- export const WIDTH_LG = "64rem";
67
- export const WIDTH_MD = "48rem";
68
- export const WIDTH_SM = "40rem";
69
- export const MIN_WIDTH_XL = `(min-width: ${WIDTH_XL})`;
70
- export const MIN_WIDTH_LG = `(min-width: ${WIDTH_LG})`;
71
- export const MIN_WIDTH_MD = `(min-width: ${WIDTH_MD})`;
72
- export const MIN_WIDTH_SM = `(min-width: ${WIDTH_SM})`;
73
- }
1
+ /** From usehooks-ts https://usehooks-ts.com/react-hook/use-media-query */
2
+ import { useState } from "react";
3
+
4
+ import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
5
+
6
+ type UseMediaQueryOptions = {
7
+ defaultValue?: boolean;
8
+ initializeWithValue?: boolean;
9
+ };
10
+
11
+ const IS_SERVER = typeof window === "undefined";
12
+
13
+ export function useMediaQuery(
14
+ query: string,
15
+ {
16
+ defaultValue = false,
17
+ initializeWithValue = true,
18
+ }: UseMediaQueryOptions = {},
19
+ ): boolean {
20
+ const getMatches = (query: string): boolean => {
21
+ if (IS_SERVER) {
22
+ return defaultValue;
23
+ }
24
+ return window.matchMedia(query).matches;
25
+ };
26
+
27
+ const [matches, setMatches] = useState<boolean>(() => {
28
+ if (initializeWithValue) {
29
+ return getMatches(query);
30
+ }
31
+ return defaultValue;
32
+ });
33
+
34
+ // Handles the change event of the media query.
35
+ function handleChange() {
36
+ setMatches(getMatches(query));
37
+ }
38
+
39
+ useIsomorphicLayoutEffect(() => {
40
+ const matchMedia = window.matchMedia(query);
41
+
42
+ // Triggered at the first client-side load and if query changes
43
+ handleChange();
44
+
45
+ // Use deprecated `addListener` and `removeListener` to support Safari < 14 (#135)
46
+ if (matchMedia.addListener) {
47
+ matchMedia.addListener(handleChange);
48
+ } else {
49
+ matchMedia.addEventListener("change", handleChange);
50
+ }
51
+
52
+ return () => {
53
+ if (matchMedia.removeListener) {
54
+ matchMedia.removeListener(handleChange);
55
+ } else {
56
+ matchMedia.removeEventListener("change", handleChange);
57
+ }
58
+ };
59
+ }, [query]);
60
+
61
+ return matches;
62
+ }
63
+
64
+ export namespace useMediaQuery {
65
+ export const WIDTH_XL = "80rem";
66
+ export const WIDTH_LG = "64rem";
67
+ export const WIDTH_MD = "48rem";
68
+ export const WIDTH_SM = "40rem";
69
+ export const MIN_WIDTH_XL = `(min-width: ${WIDTH_XL})`;
70
+ export const MIN_WIDTH_LG = `(min-width: ${WIDTH_LG})`;
71
+ export const MIN_WIDTH_MD = `(min-width: ${WIDTH_MD})`;
72
+ export const MIN_WIDTH_SM = `(min-width: ${WIDTH_SM})`;
73
+ }
@@ -0,0 +1,10 @@
1
+ export const useSessionStorage = () => {
2
+ return {
3
+ getItem: (key: string): string => {
4
+ return sessionStorage.getItem(key) ?? "";
5
+ },
6
+ setItem: (key: string, value: string): void => {
7
+ sessionStorage.setItem(key, value);
8
+ },
9
+ };
10
+ };
@@ -1,74 +1,74 @@
1
- import { COLORS } from "../constant/color";
2
-
3
- /** Props interface for ReceiptIcon component */
4
- interface IReceiptIconProps {
5
- /** Width of the icon */
6
- width?: number;
7
- /** Height of the icon */
8
- height?: number;
9
- /** Color of the icon */
10
- color?: string;
11
- }
12
-
13
- /** Receipt SVG icon component */
14
- export const ReceiptIcon = ({
15
- width = 24,
16
- height = 30,
17
- color = COLORS.GRAY_TEXT_DARK,
18
- }: IReceiptIconProps) => (
19
- <svg
20
- width={width}
21
- height={height}
22
- viewBox="0 0 24 30"
23
- fill="none"
24
- xmlns="http://www.w3.org/2000/svg"
25
- >
26
- {/* Receipt Body */}
27
- <path
28
- d="M2 2H22V24L20 22L18 24L16 22L14 24L12 22L10 24L8 22L6 24L4 22L2 24V2Z"
29
- fill={color}
30
- fillOpacity="0.1"
31
- stroke={color}
32
- strokeWidth="1.5"
33
- strokeLinecap="round"
34
- strokeLinejoin="round"
35
- />
36
- {/* Receipt Lines */}
37
- <line
38
- x1="6"
39
- y1="7"
40
- x2="18"
41
- y2="7"
42
- stroke={color}
43
- strokeWidth="1"
44
- strokeLinecap="round"
45
- />
46
- <line
47
- x1="6"
48
- y1="11"
49
- x2="18"
50
- y2="11"
51
- stroke={color}
52
- strokeWidth="1"
53
- strokeLinecap="round"
54
- />
55
- <line
56
- x1="6"
57
- y1="15"
58
- x2="14"
59
- y2="15"
60
- stroke={color}
61
- strokeWidth="1"
62
- strokeLinecap="round"
63
- />
64
- <line
65
- x1="6"
66
- y1="19"
67
- x2="16"
68
- y2="19"
69
- stroke={color}
70
- strokeWidth="1"
71
- strokeLinecap="round"
72
- />
73
- </svg>
74
- );
1
+ import { COLORS } from "../constant/color";
2
+
3
+ /** Props interface for ReceiptIcon component */
4
+ interface IReceiptIconProps {
5
+ /** Width of the icon */
6
+ width?: number;
7
+ /** Height of the icon */
8
+ height?: number;
9
+ /** Color of the icon */
10
+ color?: string;
11
+ }
12
+
13
+ /** Receipt SVG icon component */
14
+ export const ReceiptIcon = ({
15
+ width = 24,
16
+ height = 30,
17
+ color = COLORS.GRAY_TEXT_DARK,
18
+ }: IReceiptIconProps) => (
19
+ <svg
20
+ width={width}
21
+ height={height}
22
+ viewBox="0 0 24 30"
23
+ fill="none"
24
+ xmlns="http://www.w3.org/2000/svg"
25
+ >
26
+ {/* Receipt Body */}
27
+ <path
28
+ d="M2 2H22V24L20 22L18 24L16 22L14 24L12 22L10 24L8 22L6 24L4 22L2 24V2Z"
29
+ fill={color}
30
+ fillOpacity="0.1"
31
+ stroke={color}
32
+ strokeWidth="1.5"
33
+ strokeLinecap="round"
34
+ strokeLinejoin="round"
35
+ />
36
+ {/* Receipt Lines */}
37
+ <line
38
+ x1="6"
39
+ y1="7"
40
+ x2="18"
41
+ y2="7"
42
+ stroke={color}
43
+ strokeWidth="1"
44
+ strokeLinecap="round"
45
+ />
46
+ <line
47
+ x1="6"
48
+ y1="11"
49
+ x2="18"
50
+ y2="11"
51
+ stroke={color}
52
+ strokeWidth="1"
53
+ strokeLinecap="round"
54
+ />
55
+ <line
56
+ x1="6"
57
+ y1="15"
58
+ x2="14"
59
+ y2="15"
60
+ stroke={color}
61
+ strokeWidth="1"
62
+ strokeLinecap="round"
63
+ />
64
+ <line
65
+ x1="6"
66
+ y1="19"
67
+ x2="16"
68
+ y2="19"
69
+ stroke={color}
70
+ strokeWidth="1"
71
+ strokeLinecap="round"
72
+ />
73
+ </svg>
74
+ );
package/src/index.ts CHANGED
@@ -1,8 +1,9 @@
1
- export * from "./components";
2
- export * from "./hooks";
3
- export * from "./utils";
4
- export * from "./structure";
5
- export * from "./types";
6
- export * from "./context/AutoBeAgentContext";
7
- export * from "./context/AutoBeAgentSessionList";
8
- export * from "./context/SearchParamsContext";
1
+ export * from "./components";
2
+ export * from "./hooks";
3
+ export * from "./utils";
4
+ export * from "./structure";
5
+ export * from "./types";
6
+ export * from "./context/AutoBeAgentContext";
7
+ export * from "./context/AutoBeAgentSessionList";
8
+ export * from "./context/SearchParamsContext";
9
+ export * from "./strategy/AutoBeAgentSessionStorageStrategy";
@@ -0,0 +1,127 @@
1
+ import { AutoBeEventSnapshot } from "@autobe/interface";
2
+
3
+ import { useSessionStorage } from "../hooks/useSessionStorage";
4
+ import {
5
+ IAutoBeAgentSession,
6
+ IAutoBeAgentSessionStorageStrategy,
7
+ } from "../structure";
8
+
9
+ const SESSION_KEY = "autobe_session_list";
10
+
11
+ export class AutoBeAgentSessionStorageStrategy implements IAutoBeAgentSessionStorageStrategy {
12
+ appendEvent(): Promise<void> {
13
+ return Promise.resolve();
14
+ }
15
+ setTokenUsage(): Promise<void> {
16
+ return Promise.resolve();
17
+ }
18
+
19
+ async getSession(
20
+ props: Pick<IAutoBeAgentSession, "id">,
21
+ ): Promise<IAutoBeAgentSession> {
22
+ const { getItem } = useSessionStorage();
23
+
24
+ const session = getItem(SESSION_KEY);
25
+ if (!session) {
26
+ throw new Error("Session not found");
27
+ }
28
+
29
+ const sessionList = JSON.parse(session);
30
+
31
+ if (sessionList instanceof Array === false) {
32
+ throw new Error("Session list is not an array");
33
+ }
34
+
35
+ const result = sessionList.find(
36
+ (s: IAutoBeAgentSession) => s.id === props.id,
37
+ );
38
+
39
+ return {
40
+ id: result.id,
41
+ title: result.participant.name,
42
+ history: result.histories,
43
+ tokenUsage: result.token_usage,
44
+ createdAt: new Date(result.created_at),
45
+ updatedAt: new Date(result.completed_at ?? result.created_at),
46
+ events: result.event_snapshots.map((event: AutoBeEventSnapshot) => ({
47
+ type: event.event.type,
48
+ events: [event.event],
49
+ })),
50
+ };
51
+ }
52
+
53
+ async getSessionList(): Promise<IAutoBeAgentSession[]> {
54
+ const { getItem } = useSessionStorage();
55
+ const sessionList = getItem(SESSION_KEY);
56
+ if (!sessionList) {
57
+ throw new Error("Session list not found");
58
+ }
59
+
60
+ const result = JSON.parse(sessionList);
61
+ if (result instanceof Array === false) {
62
+ throw new Error("Session list is not an array");
63
+ }
64
+
65
+ return result.map((session) => ({
66
+ id: session.id,
67
+ title: session.title ?? "Untitled",
68
+ history: [],
69
+ tokenUsage: session.token_usage,
70
+ createdAt: new Date(session.created_at),
71
+ updatedAt: new Date(session.completed_at ?? session.created_at),
72
+ completedAt: session.completed_at,
73
+ events: [],
74
+ phase: session.phase,
75
+ model: session.model,
76
+ }));
77
+ }
78
+
79
+ async deleteSession(props: Pick<IAutoBeAgentSession, "id">): Promise<void> {
80
+ const { getItem, setItem } = useSessionStorage();
81
+
82
+ const sessionList = getItem(SESSION_KEY);
83
+ if (!sessionList) {
84
+ throw new Error("Session list not found");
85
+ }
86
+
87
+ const result = JSON.parse(sessionList);
88
+ if (result instanceof Array === false) {
89
+ throw new Error("Session list is not an array");
90
+ }
91
+
92
+ setItem(
93
+ SESSION_KEY,
94
+ JSON.stringify(
95
+ result.filter((s: IAutoBeAgentSession) => s.id !== props.id),
96
+ ),
97
+ );
98
+ }
99
+
100
+ async appendHistory(): Promise<void> {
101
+ return Promise.resolve();
102
+ }
103
+
104
+ async editSessionTitle(
105
+ props: Pick<IAutoBeAgentSession, "id" | "title">,
106
+ ): Promise<void> {
107
+ const { getItem, setItem } = useSessionStorage();
108
+
109
+ const sessionList = getItem(SESSION_KEY);
110
+ if (!sessionList) {
111
+ throw new Error("Session list not found");
112
+ }
113
+
114
+ const result = JSON.parse(sessionList);
115
+ if (result instanceof Array === false) {
116
+ throw new Error("Session list is not an array");
117
+ }
118
+
119
+ const session = result.find((s: IAutoBeAgentSession) => s.id === props.id);
120
+ if (!session) {
121
+ throw new Error("Session not found");
122
+ }
123
+
124
+ session.title = props.title;
125
+ setItem(SESSION_KEY, JSON.stringify(result));
126
+ }
127
+ }