@tivagent/tiva-chat 1.0.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.
- package/README.md +156 -0
- package/dist/App.d.ts +2 -0
- package/dist/beep.mp3 +0 -0
- package/dist/components/body/LoadingText.d.ts +13 -0
- package/dist/components/body/body.d.ts +1 -0
- package/dist/components/body/toast.d.ts +15 -0
- package/dist/components/body/toolbar.d.ts +4 -0
- package/dist/components/body/tooltip.d.ts +9 -0
- package/dist/components/body/welcome.d.ts +1 -0
- package/dist/components/chatbot.d.ts +11 -0
- package/dist/components/footer/footer.d.ts +1 -0
- package/dist/components/footer/speechRecognitionButton.d.ts +7 -0
- package/dist/components/header/header.d.ts +1 -0
- package/dist/components/header/menuButton.d.ts +1 -0
- package/dist/components/header/menuThemeSwitcher.d.ts +1 -0
- package/dist/components/main/button.d.ts +1 -0
- package/dist/components/main/frame.d.ts +1 -0
- package/dist/components/modals/aboutUs.d.ts +1 -0
- package/dist/components/modals/changeLanguage.d.ts +1 -0
- package/dist/components/modals/reportMessage.d.ts +1 -0
- package/dist/components/modals/resetChat.d.ts +1 -0
- package/dist/contexts/ChatbotContext.d.ts +64 -0
- package/dist/fonts/Roboto/Roboto-Black.woff2 +0 -0
- package/dist/fonts/Roboto/Roboto-Bold.woff2 +0 -0
- package/dist/fonts/Roboto/Roboto-Light.woff2 +0 -0
- package/dist/fonts/Roboto/Roboto-Medium.woff2 +0 -0
- package/dist/fonts/Roboto/Roboto-Regular.woff2 +0 -0
- package/dist/fonts/Roboto/Roboto-Thin.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-Black.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-Bold.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-ExtraBold.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-ExtraLight.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-Light.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-Medium.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-Regular.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-SemiBold.woff2 +0 -0
- package/dist/fonts/Vazirmatn/Vazirmatn-Thin.woff2 +0 -0
- package/dist/index.cjs.js +98 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.esm.js +14551 -0
- package/dist/index.umd.js +98 -0
- package/dist/main.d.ts +0 -0
- package/dist/test.html +25 -0
- package/dist/types/ChatbotConfig.d.ts +137 -0
- package/dist/utils/APIRequests.d.ts +60 -0
- package/dist/utils/Configs.d.ts +3 -0
- package/dist/utils/CreateThemeStyles.d.ts +6 -0
- package/dist/utils/MergeDeep.d.ts +7 -0
- package/dist/utils/ProcessTexts.d.ts +2 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# `@tivagent/tiva-chat`
|
|
2
|
+
|
|
3
|
+
Tiva chatbot widget package for web apps.
|
|
4
|
+
|
|
5
|
+
This package provides:
|
|
6
|
+
|
|
7
|
+
- A React component: `Chatbot`
|
|
8
|
+
- A Web Component: `<tiva-chatbot>`
|
|
9
|
+
- ESM, CJS, and UMD build outputs
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @tivagent/tiva-chat react react-dom
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start (React, recommended)
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { Chatbot } from "@tivagent/tiva-chat";
|
|
21
|
+
|
|
22
|
+
export default function App() {
|
|
23
|
+
return (
|
|
24
|
+
<Chatbot
|
|
25
|
+
uiKey="YOUR_UI_KEY"
|
|
26
|
+
baseUrl="https://api.example.com/v1"
|
|
27
|
+
apiKey="YOUR_API_KEY"
|
|
28
|
+
configurations={{
|
|
29
|
+
theme: "system",
|
|
30
|
+
language: "system",
|
|
31
|
+
buttonPosition: "right",
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start (Web Component in a bundled app)
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import "@tivagent/tiva-chat/dist/index.esm.js";
|
|
42
|
+
|
|
43
|
+
export default function App() {
|
|
44
|
+
return (
|
|
45
|
+
<tiva-chatbot
|
|
46
|
+
ui-key="YOUR_UI_KEY"
|
|
47
|
+
base-url="https://api.example.com/v1"
|
|
48
|
+
api-key="YOUR_API_KEY"
|
|
49
|
+
configurations='{"theme":"system","buttonPosition":"right"}'
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Plain HTML Example (UMD)
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<!doctype html>
|
|
59
|
+
<html lang="en">
|
|
60
|
+
<head>
|
|
61
|
+
<meta charset="UTF-8" />
|
|
62
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
63
|
+
<title>Tiva Chat Demo</title>
|
|
64
|
+
</head>
|
|
65
|
+
<body>
|
|
66
|
+
<tiva-chatbot
|
|
67
|
+
ui-key="YOUR_UI_KEY"
|
|
68
|
+
api-key="YOUR_API_KEY"
|
|
69
|
+
base-url="https://api.example.com/v1"
|
|
70
|
+
configurations='{"theme":"system"}'
|
|
71
|
+
></tiva-chatbot>
|
|
72
|
+
|
|
73
|
+
<script src="https://unpkg.com/@tivagent/tiva-chat/dist/index.umd.js"></script>
|
|
74
|
+
</body>
|
|
75
|
+
</html>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## React Props
|
|
79
|
+
|
|
80
|
+
| Prop | Type | Required | Description |
|
|
81
|
+
| ---------------- | ----------------------- | -------- | ---------------------------------------------------- |
|
|
82
|
+
| `uiKey` | `string` | Yes | UI key used to fetch UI configuration. |
|
|
83
|
+
| `version` | `string` | No | API version (default backend behavior usually `v1`). |
|
|
84
|
+
| `apiKey` | `string` | No | API key sent with requests. |
|
|
85
|
+
| `baseUrl` | `string` | No | Backend base URL. |
|
|
86
|
+
| `configurations` | `PreferencesDefinition` | No | User preference overrides. |
|
|
87
|
+
|
|
88
|
+
## Web Component Attributes
|
|
89
|
+
|
|
90
|
+
| Attribute | Type | Required | Description |
|
|
91
|
+
| ---------------- | ------------- | -------- | ------------------------------------- |
|
|
92
|
+
| `ui-key` | `string` | Yes | Same as `uiKey`. |
|
|
93
|
+
| `version` | `string` | No | Same as `version`. |
|
|
94
|
+
| `api-key` | `string` | No | Same as `apiKey`. |
|
|
95
|
+
| `base-url` | `string` | No | Same as `baseUrl`. |
|
|
96
|
+
| `configurations` | `JSON string` | No | JSON form of `PreferencesDefinition`. |
|
|
97
|
+
|
|
98
|
+
Example:
|
|
99
|
+
|
|
100
|
+
```html
|
|
101
|
+
<tiva-chatbot
|
|
102
|
+
ui-key="YOUR_UI_KEY"
|
|
103
|
+
api-key="YOUR_API_KEY"
|
|
104
|
+
base-url="https://api.example.com/v1"
|
|
105
|
+
configurations='{"theme":"dark","language":"en","buttonPosition":"left"}'
|
|
106
|
+
></tiva-chatbot>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Backend API Requirements
|
|
110
|
+
|
|
111
|
+
The widget expects specific backend endpoints, including:
|
|
112
|
+
|
|
113
|
+
- `POST /messages` (SSE stream)
|
|
114
|
+
- `POST /get_session`
|
|
115
|
+
- `POST /deactivate_session`
|
|
116
|
+
- `POST /voices`
|
|
117
|
+
- `POST /feedback`
|
|
118
|
+
- `POST /reports`
|
|
119
|
+
- `GET /get_ui_config`
|
|
120
|
+
|
|
121
|
+
Full contract: `CHATBOT_API.md` in the GitHub repository `https://github.com/tivagent/tiva-chatbot`.
|
|
122
|
+
|
|
123
|
+
## Styling and Shadow DOM
|
|
124
|
+
|
|
125
|
+
`<tiva-chatbot>` uses open Shadow DOM and injects its own styles, so host page styles do not leak into the widget UI.
|
|
126
|
+
|
|
127
|
+
## Build Outputs
|
|
128
|
+
|
|
129
|
+
When building the library, `dist/` includes:
|
|
130
|
+
|
|
131
|
+
- `index.esm.js`
|
|
132
|
+
- `index.cjs.js`
|
|
133
|
+
- `index.umd.js`
|
|
134
|
+
- `index.d.ts`
|
|
135
|
+
|
|
136
|
+
## Local Development
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm install
|
|
140
|
+
npm run dev
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Useful commands:
|
|
144
|
+
|
|
145
|
+
- `npm run build`
|
|
146
|
+
- `npm run lint`
|
|
147
|
+
- `npm run preview`
|
|
148
|
+
|
|
149
|
+
## Publishing
|
|
150
|
+
|
|
151
|
+
For release workflow and npm publish steps, see `PUBLISHING.md` in `https://github.com/tivagent/tiva-chatbot`.
|
|
152
|
+
|
|
153
|
+
## Additional Notes
|
|
154
|
+
|
|
155
|
+
- Consumer-focused usage is in this README.
|
|
156
|
+
- Contributor and developer workflow notes are in `INSTRUCTIONS.md` in `https://github.com/tivagent/tiva-chatbot`.
|
package/dist/App.d.ts
ADDED
package/dist/beep.mp3
ADDED
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface LoadingTextProps {
|
|
2
|
+
text: string;
|
|
3
|
+
direction: "ltr" | "rtl";
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A component that renders text with a "shining" animation.
|
|
8
|
+
* The animation is achieved purely with CSS.
|
|
9
|
+
* The text color is defined by a gradient that animates its position.
|
|
10
|
+
* When the text changes, it performs a "push up" animation.
|
|
11
|
+
*/
|
|
12
|
+
export declare function LoadingText({ text, direction, className, }: LoadingTextProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function CBBody(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode, FC } from 'react';
|
|
2
|
+
export type ToastType = {
|
|
3
|
+
id: number;
|
|
4
|
+
text: string | ReactNode;
|
|
5
|
+
type: "message" | "info" | "success" | "warning" | "error";
|
|
6
|
+
duration: number;
|
|
7
|
+
closeButton?: boolean;
|
|
8
|
+
measuredHeight?: number;
|
|
9
|
+
remaining?: number;
|
|
10
|
+
start?: number;
|
|
11
|
+
pause?: () => void;
|
|
12
|
+
resume?: () => void;
|
|
13
|
+
closing?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare const ToastContainer: FC;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
interface TooltipProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
text: string;
|
|
5
|
+
position?: "top" | "bottom" | "left" | "right";
|
|
6
|
+
disableOnTouch?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function Tooltip({ children, text, position, disableOnTouch, }: TooltipProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Welcome(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { PreferencesDefinition } from '../types/ChatbotConfig';
|
|
3
|
+
export interface ChatbotProps {
|
|
4
|
+
uiKey: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
configurations?: PreferencesDefinition;
|
|
9
|
+
}
|
|
10
|
+
declare const Chatbot: FC<ChatbotProps>;
|
|
11
|
+
export default Chatbot;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function CBFooter(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface SpeechRecognitionButtonProps {
|
|
2
|
+
onTranscript: (transcript: string) => void;
|
|
3
|
+
isListening: boolean;
|
|
4
|
+
setIsListening: (isListening: boolean) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function SpeechRecognitionButton({ onTranscript, isListening, setIsListening, }: SpeechRecognitionButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function CBHeader(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function HeaderMenu(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ThemeSwitcher(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ChatButton(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ChatFrame(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AboutUsModal(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function LanguageModal(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ReportModal(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ResetChatModal(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ReactNode, SetStateAction, Dispatch } from 'react';
|
|
2
|
+
import { Theme, Message, FinalConfig, PreferencesDefinition } from '../types/ChatbotConfig';
|
|
3
|
+
import { ToastType } from '../components/body/toast';
|
|
4
|
+
import { CSSVariables } from '../utils/CreateThemeStyles';
|
|
5
|
+
interface ChatbotContextType {
|
|
6
|
+
config: FinalConfig;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
isOpen: boolean;
|
|
9
|
+
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
|
10
|
+
showContent: boolean;
|
|
11
|
+
showScrollButton: boolean;
|
|
12
|
+
setShowScrollButton: Dispatch<SetStateAction<boolean>>;
|
|
13
|
+
hasUnreadMessages: boolean;
|
|
14
|
+
activeTheme: Theme;
|
|
15
|
+
themeStyles: CSSVariables;
|
|
16
|
+
setActiveTheme: (theme: Theme) => void;
|
|
17
|
+
setLanguage: (language: string) => void;
|
|
18
|
+
isThemeSwitchable: boolean;
|
|
19
|
+
isLanguageSwitchable: boolean;
|
|
20
|
+
messages: Message[];
|
|
21
|
+
setMessages: Dispatch<SetStateAction<Message[]>>;
|
|
22
|
+
sendMessage: (text: string) => Promise<void>;
|
|
23
|
+
setRecalledInput: Dispatch<SetStateAction<string>>;
|
|
24
|
+
isResetChatAllowed: boolean;
|
|
25
|
+
manageSession: (session?: string) => Promise<void>;
|
|
26
|
+
isThinking: boolean;
|
|
27
|
+
thinkingStatus: string | null;
|
|
28
|
+
isStreaming: boolean;
|
|
29
|
+
stopStreaming: () => void;
|
|
30
|
+
recalledInput: string;
|
|
31
|
+
clearRecalledInput: () => void;
|
|
32
|
+
setSelectedMessageId: Dispatch<SetStateAction<string | null>>;
|
|
33
|
+
isLangModalOpen: boolean;
|
|
34
|
+
setIsLangModalOpen: Dispatch<SetStateAction<boolean>>;
|
|
35
|
+
isAboutModalOpen: boolean;
|
|
36
|
+
setIsAboutModalOpen: Dispatch<SetStateAction<boolean>>;
|
|
37
|
+
isResetModalOpen: boolean;
|
|
38
|
+
setIsResetModalOpen: Dispatch<SetStateAction<boolean>>;
|
|
39
|
+
isReportModalOpen: boolean;
|
|
40
|
+
setIsReportModalOpen: Dispatch<SetStateAction<boolean>>;
|
|
41
|
+
selectedMessageId: string | null;
|
|
42
|
+
updateMessage: (messageId: string, updates: Partial<Message>) => void;
|
|
43
|
+
currentlyPlayingId: string | null;
|
|
44
|
+
setCurrentlyPlayingId: Dispatch<SetStateAction<string | null>>;
|
|
45
|
+
toasts: ToastType[];
|
|
46
|
+
addToast: (text: string | ReactNode, type?: ToastType["type"], duration?: number, closeButton?: boolean) => void;
|
|
47
|
+
removeToast: (id: number) => void;
|
|
48
|
+
pauseToast: (id: number) => void;
|
|
49
|
+
resumeToast: (id: number) => void;
|
|
50
|
+
uiKey: string;
|
|
51
|
+
apiKey?: string;
|
|
52
|
+
baseUrl?: string;
|
|
53
|
+
version?: string;
|
|
54
|
+
}
|
|
55
|
+
export declare function ChatbotProvider({ children, uiKey, version, apiKey, baseUrl, userPreferences, }: {
|
|
56
|
+
children: ReactNode;
|
|
57
|
+
uiKey: string;
|
|
58
|
+
version?: string;
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
baseUrl?: string;
|
|
61
|
+
userPreferences?: PreferencesDefinition;
|
|
62
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
63
|
+
export declare function useChatbot(): ChatbotContextType;
|
|
64
|
+
export {};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|