mcp-chat-ui 1.0.1 → 1.0.2
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 +38 -0
- package/dist/ChatUI.js +11 -5
- package/dist/components/MessageItem.js +1 -1
- package/dist/components/MessageList.js +1 -1
- package/dist/components/TypingDots.d.ts +5 -1
- package/dist/components/TypingDots.js +2 -2
- package/dist/config.d.ts +1 -0
- package/dist/sdkUtilities.js +5 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,13 +19,51 @@ npm install mcp-chat-ui
|
|
|
19
19
|
|
|
20
20
|
## Quick Start
|
|
21
21
|
|
|
22
|
+
### For React Projects
|
|
23
|
+
|
|
22
24
|
Import CSS in App.tsx
|
|
23
25
|
|
|
24
26
|
```App.tsx
|
|
25
27
|
import "mcp-chat-ui/styles.css";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### For Angular Projects
|
|
31
|
+
|
|
32
|
+
**Option 1: Import in global styles.css (Recommended)**
|
|
33
|
+
|
|
34
|
+
Open your `src/styles.css` file and add this import at the top:
|
|
26
35
|
|
|
36
|
+
```css
|
|
37
|
+
@import "mcp-chat-ui/dist/styles.css";
|
|
27
38
|
```
|
|
28
39
|
|
|
40
|
+
**Option 2: Add to angular.json**
|
|
41
|
+
|
|
42
|
+
If Option 1 doesn't work, add the CSS file to your `angular.json` configuration:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"projects": {
|
|
47
|
+
"your-app-name": {
|
|
48
|
+
"architect": {
|
|
49
|
+
"build": {
|
|
50
|
+
"options": {
|
|
51
|
+
"styles": [
|
|
52
|
+
"src/styles.css",
|
|
53
|
+
"node_modules/mcp-chat-ui/dist/styles.css"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Important:** Do **not** import the CSS in TypeScript/component files for Angular projects. After making changes, restart your Angular dev server (`ng serve`).
|
|
64
|
+
|
|
65
|
+
### Initialize the SDK
|
|
66
|
+
|
|
29
67
|
Initialize the SDK (required):
|
|
30
68
|
|
|
31
69
|
```ts
|
package/dist/ChatUI.js
CHANGED
|
@@ -576,6 +576,8 @@ function ChatUI(props) {
|
|
|
576
576
|
(0, react_1.useEffect)(() => {
|
|
577
577
|
if (!apiBase || !apiKey || !sessionId)
|
|
578
578
|
return;
|
|
579
|
+
if (!authToken || !initCompleted)
|
|
580
|
+
return;
|
|
579
581
|
const controller = new AbortController();
|
|
580
582
|
let cancelled = false;
|
|
581
583
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -655,7 +657,7 @@ function ChatUI(props) {
|
|
|
655
657
|
cancelled = true;
|
|
656
658
|
controller.abort();
|
|
657
659
|
};
|
|
658
|
-
}, [apiBase, apiKey, authToken, sessionId, domain]);
|
|
660
|
+
}, [apiBase, apiKey, authToken, sessionId, domain, initCompleted]);
|
|
659
661
|
const canSend = (0, react_1.useMemo)(() => (!!input.trim() || selectedFiles.length > 0 || !!selectedTaskCard) &&
|
|
660
662
|
!!sessionId &&
|
|
661
663
|
!!apiBase &&
|
|
@@ -979,6 +981,10 @@ function ChatUI(props) {
|
|
|
979
981
|
function sendMessage() {
|
|
980
982
|
return __awaiter(this, void 0, void 0, function* () {
|
|
981
983
|
var _a, _b;
|
|
984
|
+
const selectedTask = selectedTaskCard;
|
|
985
|
+
if (selectedTask) {
|
|
986
|
+
setSelectedTaskCard(null);
|
|
987
|
+
}
|
|
982
988
|
if (!sessionId)
|
|
983
989
|
return;
|
|
984
990
|
if (!initCompleted) {
|
|
@@ -991,7 +997,7 @@ function ChatUI(props) {
|
|
|
991
997
|
const promptText = input.trim();
|
|
992
998
|
const hasText = !!promptText;
|
|
993
999
|
const hasFiles = selectedFiles.length > 0;
|
|
994
|
-
const hasSelectedCard = !!
|
|
1000
|
+
const hasSelectedCard = !!selectedTask;
|
|
995
1001
|
if (!hasText && !hasFiles && !hasSelectedCard)
|
|
996
1002
|
return;
|
|
997
1003
|
const filesToUpload = selectedFiles;
|
|
@@ -1000,7 +1006,7 @@ function ChatUI(props) {
|
|
|
1000
1006
|
}));
|
|
1001
1007
|
const selectionLine = hasSelectedCard
|
|
1002
1008
|
? formatText(text.composer.selectionLineTemplate, {
|
|
1003
|
-
id: String((_a =
|
|
1009
|
+
id: String((_a = selectedTask === null || selectedTask === void 0 ? void 0 : selectedTask.RequestId) !== null && _a !== void 0 ? _a : ""),
|
|
1004
1010
|
})
|
|
1005
1011
|
: "";
|
|
1006
1012
|
const userContent = selectionLine
|
|
@@ -1075,8 +1081,8 @@ function ChatUI(props) {
|
|
|
1075
1081
|
SessionId: sessionId,
|
|
1076
1082
|
UserMessage: userContent,
|
|
1077
1083
|
};
|
|
1078
|
-
if ((
|
|
1079
|
-
payload.RequestId =
|
|
1084
|
+
if ((selectedTask === null || selectedTask === void 0 ? void 0 : selectedTask.RequestId) !== undefined && (selectedTask === null || selectedTask === void 0 ? void 0 : selectedTask.RequestId) !== null) {
|
|
1085
|
+
payload.RequestId = selectedTask.RequestId;
|
|
1080
1086
|
}
|
|
1081
1087
|
if (initServiceId && initServiceId.trim() !== "") {
|
|
1082
1088
|
const n = Number(initServiceId);
|
|
@@ -12,7 +12,7 @@ const classNames_1 = require("../utils/classNames");
|
|
|
12
12
|
const format_1 = require("../utils/format");
|
|
13
13
|
function MessageItem({ m, openOverlay, isRtl, onOpenTaskCard, onSelectTaskCard, selectedTaskCardId, canSpeak, isSpeaking, onSpeak, onStopSpeak, textButtonTheme, text, taskCardSize, }) {
|
|
14
14
|
const isUser = m.role === "User";
|
|
15
|
-
const alignRight = isUser;
|
|
15
|
+
const alignRight = isUser || isRtl;
|
|
16
16
|
return ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { initial: { opacity: 0, y: 6 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -6 }, transition: { duration: 0.18 }, className: (0, classNames_1.classNames)("flex w-full", alignRight ? "justify-end" : "justify-start"), children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)("max-w-[85%]", isUser ? "" : "w-full"), children: [(0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(isUser
|
|
17
17
|
? "rounded-2xl px-4 py-3 shadow-sm"
|
|
18
18
|
: "px-1 py-0"), style: Object.assign({ direction: isRtl ? "rtl" : "ltr", textAlign: isRtl ? "right" : "left" }, (isUser
|
|
@@ -15,5 +15,5 @@ function MessageList({ messages, pending, openOverlay, onOpenTaskCard, onSelectT
|
|
|
15
15
|
!!m.content &&
|
|
16
16
|
m.content.trim() !== "";
|
|
17
17
|
return ((0, jsx_runtime_1.jsx)(MessageItem_1.default, { m: m, openOverlay: openOverlay, onOpenTaskCard: onOpenTaskCard, onSelectTaskCard: onSelectTaskCard, selectedTaskCardId: selectedTaskCardId, isRtl: isRtl, canSpeak: canSpeak, isSpeaking: canSpeak && speakingMessageIndex === i, onSpeak: canSpeak ? () => onSpeak(m.content, i) : undefined, onStopSpeak: canSpeak ? onStopSpeak : undefined, textButtonTheme: textButtonTheme, text: messageItemText, taskCardSize: taskCardSize }, `${(_a = m.ts) !== null && _a !== void 0 ? _a : i}-${i}`));
|
|
18
|
-
}), pending && (0, jsx_runtime_1.jsx)(TypingDots_1.default, {}, "typing")] }) }), (0, jsx_runtime_1.jsx)("div", { ref: listEndRef })] }) }));
|
|
18
|
+
}), pending && (0, jsx_runtime_1.jsx)(TypingDots_1.default, { alignRight: isRtl }, "typing")] }) }), (0, jsx_runtime_1.jsx)("div", { ref: listEndRef })] }) }));
|
|
19
19
|
}
|
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = TypingDots;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const framer_motion_1 = require("framer-motion");
|
|
6
|
-
function TypingDots() {
|
|
7
|
-
return ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { initial: { opacity: 0, y: 6 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -6 }, transition: { duration: 0.18 }, className:
|
|
6
|
+
function TypingDots({ alignRight }) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { initial: { opacity: 0, y: 6 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -6 }, transition: { duration: 0.18 }, className: `flex w-full ${alignRight ? "justify-end" : "justify-start"}`, children: (0, jsx_runtime_1.jsxs)("div", { className: "text-[1rem] leading-7 text-gray-900", children: [(0, jsx_runtime_1.jsx)("span", { className: "inline-block h-1.5 w-1.5 animate-bounce rounded-full bg-gray-400 [animation-delay:0ms]" }), (0, jsx_runtime_1.jsx)("span", { className: "ml-1 inline-block h-1.5 w-1.5 animate-bounce rounded-full bg-gray-400 [animation-delay:150ms]" }), (0, jsx_runtime_1.jsx)("span", { className: "ml-1 inline-block h-1.5 w-1.5 animate-bounce rounded-full bg-gray-400 [animation-delay:300ms]" })] }) }));
|
|
8
8
|
}
|
package/dist/config.d.ts
CHANGED
package/dist/sdkUtilities.js
CHANGED
|
@@ -55,7 +55,7 @@ function GetConfigValue(key) {
|
|
|
55
55
|
}
|
|
56
56
|
function InitializeChatSession() {
|
|
57
57
|
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
58
|
-
var _a, _b, _c, _d, _e;
|
|
58
|
+
var _a, _b, _c, _d, _e, _f;
|
|
59
59
|
const config = GetConfig();
|
|
60
60
|
const apiBase = chatDefaults_1.DEFAULT_API_BASE;
|
|
61
61
|
const apiKey = chatDefaults_1.DEFAULT_API_KEY;
|
|
@@ -79,10 +79,11 @@ function InitializeChatSession() {
|
|
|
79
79
|
const defaultDomain = config.isDab ? chatDefaults_1.DEFAULT_DOMAIN : "";
|
|
80
80
|
const domain = ((_c = options.domain) !== null && _c !== void 0 ? _c : localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.domain, defaultDomain)).trim();
|
|
81
81
|
const contextWindow = (_d = options.contextWindow) !== null && _d !== void 0 ? _d : config.contextWindow;
|
|
82
|
+
const initializeLanguage = ((_e = config.initializeLanguage) !== null && _e !== void 0 ? _e : "").trim() || "ar-JO";
|
|
82
83
|
const bodyPayload = {
|
|
83
84
|
Domain: domain,
|
|
84
85
|
ContextWindow: contextWindow || "ComposeRequest",
|
|
85
|
-
InitializeLangauge:
|
|
86
|
+
InitializeLangauge: initializeLanguage,
|
|
86
87
|
};
|
|
87
88
|
if (options.initServiceId !== undefined && options.initServiceId !== null) {
|
|
88
89
|
const n = Number(options.initServiceId);
|
|
@@ -110,11 +111,11 @@ function InitializeChatSession() {
|
|
|
110
111
|
try {
|
|
111
112
|
msg = yield initRes.text();
|
|
112
113
|
}
|
|
113
|
-
catch (
|
|
114
|
+
catch (_g) { }
|
|
114
115
|
throw new Error(`initializeChat failed: ${initRes.status} ${initRes.statusText}${msg ? ` - ${msg}` : ""}`);
|
|
115
116
|
}
|
|
116
117
|
const initPayload = yield initRes.json().catch(() => ({}));
|
|
117
|
-
const resolvedSessionId = (
|
|
118
|
+
const resolvedSessionId = (_f = initPayload === null || initPayload === void 0 ? void 0 : initPayload.SessionId) !== null && _f !== void 0 ? _f : sessionId;
|
|
118
119
|
if (initPayload === null || initPayload === void 0 ? void 0 : initPayload.SessionId) {
|
|
119
120
|
localStorage_1.ls.set(storageKeys_1.STORAGE_KEYS.sessionId, initPayload.SessionId);
|
|
120
121
|
}
|