@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/dist/main.d.ts
ADDED
|
File without changes
|
package/dist/test.html
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Chatbot Web Component Test</title>
|
|
8
|
+
</head>
|
|
9
|
+
<style>
|
|
10
|
+
body {
|
|
11
|
+
margin: 0;
|
|
12
|
+
min-height: 100dvh;
|
|
13
|
+
background-color: rgb(229, 231, 235);
|
|
14
|
+
}
|
|
15
|
+
</style>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
<!-- Use the web component -->
|
|
19
|
+
<tiva-chatbot ui-key="..." api-key="..." base-url="..."></tiva-chatbot>
|
|
20
|
+
|
|
21
|
+
<!-- Load the bundle -->
|
|
22
|
+
<script src="./index.umd.js"></script>
|
|
23
|
+
</body>
|
|
24
|
+
|
|
25
|
+
</html>
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export interface Message {
|
|
2
|
+
id: string;
|
|
3
|
+
content: string;
|
|
4
|
+
sender: "user" | "assistant";
|
|
5
|
+
time?: string;
|
|
6
|
+
feedback?: 0 | 1 | -1;
|
|
7
|
+
kwargs?: Record<string, unknown>;
|
|
8
|
+
loading?: boolean;
|
|
9
|
+
streaming?: boolean;
|
|
10
|
+
chunks?: string[];
|
|
11
|
+
error?: boolean;
|
|
12
|
+
voice_content?: string | null;
|
|
13
|
+
}
|
|
14
|
+
export declare class ApiError extends Error {
|
|
15
|
+
status: number;
|
|
16
|
+
constructor(message: string, status: number);
|
|
17
|
+
}
|
|
18
|
+
export interface LanguageDefinition {
|
|
19
|
+
title: string;
|
|
20
|
+
srCode: string;
|
|
21
|
+
dir: "ltr" | "rtl";
|
|
22
|
+
}
|
|
23
|
+
export interface StaticConfig {
|
|
24
|
+
supportedLanguages: {
|
|
25
|
+
[key: string]: LanguageDefinition;
|
|
26
|
+
};
|
|
27
|
+
texts: {
|
|
28
|
+
main: {
|
|
29
|
+
[key: string]: {
|
|
30
|
+
[lang: string]: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
modals: {
|
|
34
|
+
[key: string]: {
|
|
35
|
+
[lang: string]: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
reportCategories: {
|
|
39
|
+
[key: string]: {
|
|
40
|
+
[lang: string]: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
messages: {
|
|
44
|
+
[key: string]: {
|
|
45
|
+
[lang: string]: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
notifications: {
|
|
49
|
+
[key: string]: {
|
|
50
|
+
[lang: string]: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
placeholders: {
|
|
54
|
+
[key: string]: {
|
|
55
|
+
[lang: string]: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
toolbar: {
|
|
59
|
+
[key: string]: {
|
|
60
|
+
[lang: string]: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface ThemeDefinition {
|
|
66
|
+
backgrounds: {
|
|
67
|
+
[key: string]: string;
|
|
68
|
+
};
|
|
69
|
+
texts: {
|
|
70
|
+
[key: string]: string;
|
|
71
|
+
};
|
|
72
|
+
icons: {
|
|
73
|
+
[key: string]: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface SettingsDefinition {
|
|
77
|
+
logo: string;
|
|
78
|
+
languages: string[];
|
|
79
|
+
twoSuggestionsCols: boolean;
|
|
80
|
+
randomizeSuggestions: boolean;
|
|
81
|
+
sendSuggestionOnClick: boolean;
|
|
82
|
+
sendOnEnter: boolean;
|
|
83
|
+
showButtonTooltip: boolean;
|
|
84
|
+
showAboutUs: boolean;
|
|
85
|
+
playUnreadBeep: boolean;
|
|
86
|
+
useGoToBottom: boolean;
|
|
87
|
+
useASR: boolean;
|
|
88
|
+
useTTS: boolean;
|
|
89
|
+
useFeedback: boolean;
|
|
90
|
+
useCopy: boolean;
|
|
91
|
+
useReport: boolean;
|
|
92
|
+
useMessageTime: boolean;
|
|
93
|
+
useFAQ: boolean;
|
|
94
|
+
useSuggestions: boolean;
|
|
95
|
+
}
|
|
96
|
+
export type Theme = "system" | "light" | "dark";
|
|
97
|
+
export interface PreferencesDefinition {
|
|
98
|
+
theme?: Theme;
|
|
99
|
+
language?: "system" | string;
|
|
100
|
+
dir?: "system" | "ltr" | "rtl";
|
|
101
|
+
direction?: "system" | "ltr" | "rtl";
|
|
102
|
+
userMessagesPosition?: "system" | "left" | "right";
|
|
103
|
+
buttonPosition?: "system" | "left" | "right";
|
|
104
|
+
unreadFlagPosition?: "system" | "left" | "right";
|
|
105
|
+
}
|
|
106
|
+
export interface APIConfig {
|
|
107
|
+
themes: {
|
|
108
|
+
light: ThemeDefinition;
|
|
109
|
+
dark: ThemeDefinition;
|
|
110
|
+
};
|
|
111
|
+
content: {
|
|
112
|
+
[key: string]: {
|
|
113
|
+
[lang: string]: string;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
suggestions: {
|
|
117
|
+
title: string;
|
|
118
|
+
query: string;
|
|
119
|
+
lang: string;
|
|
120
|
+
}[];
|
|
121
|
+
faqs: {
|
|
122
|
+
question: string;
|
|
123
|
+
answer?: string;
|
|
124
|
+
lang: string;
|
|
125
|
+
}[];
|
|
126
|
+
settings: SettingsDefinition;
|
|
127
|
+
preferences: PreferencesDefinition;
|
|
128
|
+
}
|
|
129
|
+
export type ProcessedTexts<T> = {
|
|
130
|
+
[P in keyof T]: T[P] extends {
|
|
131
|
+
[lang: string]: string;
|
|
132
|
+
} ? string : T[P] extends object ? ProcessedTexts<T[P]> : T[P];
|
|
133
|
+
};
|
|
134
|
+
export interface FinalConfig extends Omit<APIConfig, "content">, Omit<StaticConfig, "texts"> {
|
|
135
|
+
content: ProcessedTexts<APIConfig["content"]>;
|
|
136
|
+
texts: ProcessedTexts<StaticConfig["texts"]>;
|
|
137
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { APIConfig as UiConfig, Message, ApiError } from '../types/ChatbotConfig';
|
|
2
|
+
interface StreamStartData {
|
|
3
|
+
message_id: string;
|
|
4
|
+
session_id: string;
|
|
5
|
+
}
|
|
6
|
+
interface StreamProgressData {
|
|
7
|
+
message_id: string;
|
|
8
|
+
session_id: string;
|
|
9
|
+
response: string;
|
|
10
|
+
}
|
|
11
|
+
interface StreamStatusData {
|
|
12
|
+
message_id: string;
|
|
13
|
+
session_id: string;
|
|
14
|
+
status: string;
|
|
15
|
+
}
|
|
16
|
+
interface StreamCompleteData {
|
|
17
|
+
message_id: string;
|
|
18
|
+
session_id: string;
|
|
19
|
+
response: string;
|
|
20
|
+
kwargs: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
type OnStartCallback = (data: StreamStartData) => void;
|
|
23
|
+
type OnStreamCallback = (data: StreamProgressData) => void;
|
|
24
|
+
type OnStatusCallback = (data: StreamStatusData) => void;
|
|
25
|
+
type OnCompleteCallback = (data: StreamCompleteData) => void;
|
|
26
|
+
type OnErrorCallback = (error: ApiError) => void;
|
|
27
|
+
interface GetResponseParams {
|
|
28
|
+
message: string;
|
|
29
|
+
sessionId: string | null;
|
|
30
|
+
language: string;
|
|
31
|
+
version?: string;
|
|
32
|
+
apiKey?: string;
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
signal: AbortSignal;
|
|
35
|
+
onStart: OnStartCallback;
|
|
36
|
+
onStream: OnStreamCallback;
|
|
37
|
+
onStatus: OnStatusCallback;
|
|
38
|
+
onComplete: OnCompleteCallback;
|
|
39
|
+
onError: OnErrorCallback;
|
|
40
|
+
}
|
|
41
|
+
export type ReportCategory = "inaccurate_information" | "offensive_or_harmful" | "not_relevant_spam" | "technical_issue" | "other";
|
|
42
|
+
export interface ReportData {
|
|
43
|
+
message_id: string;
|
|
44
|
+
title: string;
|
|
45
|
+
category: ReportCategory;
|
|
46
|
+
description: string;
|
|
47
|
+
}
|
|
48
|
+
export type FeedbackType = "like" | "dislike" | "none";
|
|
49
|
+
export interface FeedbackData {
|
|
50
|
+
message_id: string;
|
|
51
|
+
feedback: FeedbackType;
|
|
52
|
+
}
|
|
53
|
+
export declare const getHistory: (sessionId: string, version?: string, apiKey?: string, baseUrl?: string) => Promise<Message[]>;
|
|
54
|
+
export declare const resetHistory: (sessionId: string, version?: string, apiKey?: string, baseUrl?: string) => Promise<Response>;
|
|
55
|
+
export declare const getResponse: ({ message, sessionId, language, version, apiKey, baseUrl, signal, onStart, onStream, onStatus, onComplete, onError, }: GetResponseParams) => Promise<void>;
|
|
56
|
+
export declare const getVoice: (messageId: string, version?: string, apiKey?: string, baseUrl?: string) => Promise<Blob>;
|
|
57
|
+
export declare const submitFeedback: (feedbackData: FeedbackData, version?: string, apiKey?: string, baseUrl?: string) => Promise<void>;
|
|
58
|
+
export declare const submitReport: (reportData: ReportData, version?: string, apiKey?: string, baseUrl?: string) => Promise<void>;
|
|
59
|
+
export declare const fetchAPIConfig: (ui_key: string, version?: string, apiKey?: string, baseUrl?: string) => Promise<UiConfig | null>;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FinalConfig } from '../types/ChatbotConfig';
|
|
3
|
+
export interface CSSVariables extends React.CSSProperties {
|
|
4
|
+
[key: `--${string}`]: string | number;
|
|
5
|
+
}
|
|
6
|
+
export declare const createThemeStyles: (config: FinalConfig, activeTheme: "light" | "dark") => CSSVariables;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deeply merges two objects, preserving the type of the target object.
|
|
3
|
+
* @param target The target object (providing the type structure).
|
|
4
|
+
* @param source The source object (providing new values).
|
|
5
|
+
* @returns A new object of the same type as the target.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mergeDeep: <T extends object>(target: T, source: object) => T;
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tivagent/tiva-chat",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "Mahyar Amiri <mmaahhyyaarr@gmail.com>",
|
|
5
|
+
"private": false,
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.cjs.js",
|
|
10
|
+
"module": "dist/index.esm.js",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/tivagent/tiva-chatbot.git"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.esm.js",
|
|
19
|
+
"require": "./dist/index.cjs.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"build": "vite build",
|
|
29
|
+
"preview": "vite preview",
|
|
30
|
+
"lint": "eslint .",
|
|
31
|
+
"tw:add-prefix": "node scripts/add-prefix.js",
|
|
32
|
+
"tw:build": "npx @tailwindcss/cli -i src/index.css -o src/styles.css",
|
|
33
|
+
"tw:build-minify": "npx @tailwindcss/cli -i src/index.css -o src/styles.min.css --minify"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@babel/preset-react": "^7.28.5",
|
|
37
|
+
"@r2wc/react-to-web-component": "^2.1.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^19.0.0",
|
|
41
|
+
"react-dom": "^19.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@eslint/eslintrc": "^3",
|
|
45
|
+
"@eslint/js": "^9.39.2",
|
|
46
|
+
"@playwright/test": "^1.57.0",
|
|
47
|
+
"@svgr/rollup": "^8.1.0",
|
|
48
|
+
"@tailwindcss/postcss": "^4",
|
|
49
|
+
"@types/dom-speech-recognition": "^0.0.7",
|
|
50
|
+
"@types/node": "^25",
|
|
51
|
+
"@types/react": "^19.2.10",
|
|
52
|
+
"@types/react-dom": "^19.2.3",
|
|
53
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
54
|
+
"autoprefixer": "^10.4.23",
|
|
55
|
+
"eslint": "^9",
|
|
56
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
57
|
+
"eslint-plugin-react-refresh": "^0.5.0",
|
|
58
|
+
"globals": "^17.3.0",
|
|
59
|
+
"postcss": "^8.5.6",
|
|
60
|
+
"react": "^19.2.3",
|
|
61
|
+
"react-dom": "^19.2.3",
|
|
62
|
+
"tailwindcss": "^4.1.18",
|
|
63
|
+
"tslib": "^2.8.1",
|
|
64
|
+
"typescript": "^5",
|
|
65
|
+
"typescript-eslint": "^8.54.0",
|
|
66
|
+
"vite": "^7.3.1",
|
|
67
|
+
"vite-plugin-dts": "^4.5.4",
|
|
68
|
+
"vite-plugin-svgr": "^4.5.0"
|
|
69
|
+
}
|
|
70
|
+
}
|