mcp-chat-ui 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 +327 -0
- package/dist/ChatUI.d.ts +2 -0
- package/dist/ChatUI.js +1781 -0
- package/dist/components/Composer.d.ts +35 -0
- package/dist/components/Composer.js +19 -0
- package/dist/components/DocumentViewer.d.ts +24 -0
- package/dist/components/DocumentViewer.js +16 -0
- package/dist/components/FormattedText.d.ts +9 -0
- package/dist/components/FormattedText.js +98 -0
- package/dist/components/InitPanel.d.ts +41 -0
- package/dist/components/InitPanel.js +20 -0
- package/dist/components/MessageItem.d.ts +19 -0
- package/dist/components/MessageItem.js +50 -0
- package/dist/components/MessageList.d.ts +22 -0
- package/dist/components/MessageList.js +19 -0
- package/dist/components/TakeActionModal.d.ts +26 -0
- package/dist/components/TakeActionModal.js +26 -0
- package/dist/components/TaskCardsModal.d.ts +13 -0
- package/dist/components/TaskCardsModal.js +17 -0
- package/dist/components/ToolResultOverlay.d.ts +9 -0
- package/dist/components/ToolResultOverlay.js +14 -0
- package/dist/components/TopBar.d.ts +13 -0
- package/dist/components/TopBar.js +9 -0
- package/dist/components/TypingDots.d.ts +1 -0
- package/dist/components/TypingDots.js +8 -0
- package/dist/components/VoiceOverlay.d.ts +11 -0
- package/dist/components/VoiceOverlay.js +9 -0
- package/dist/config.d.ts +179 -0
- package/dist/config.js +24 -0
- package/dist/constants/chatDefaults.d.ts +19 -0
- package/dist/constants/chatDefaults.js +234 -0
- package/dist/helpers/api.d.ts +12 -0
- package/dist/helpers/api.js +104 -0
- package/dist/helpers/taskAttributes.d.ts +11 -0
- package/dist/helpers/taskAttributes.js +41 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +14 -0
- package/dist/models/chat.types.d.ts +72 -0
- package/dist/models/chat.types.js +2 -0
- package/dist/sdkUtilities.d.ts +27 -0
- package/dist/sdkUtilities.js +188 -0
- package/dist/styles.css +1412 -0
- package/dist/utils/classNames.d.ts +1 -0
- package/dist/utils/classNames.js +6 -0
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.js +18 -0
- package/dist/utils/generateGuid.d.ts +1 -0
- package/dist/utils/generateGuid.js +10 -0
- package/dist/utils/localStorage.d.ts +6 -0
- package/dist/utils/localStorage.js +39 -0
- package/dist/utils/storageKeys.d.ts +16 -0
- package/dist/utils/storageKeys.js +25 -0
- package/dist/utils/textDirection.d.ts +2 -0
- package/dist/utils/textDirection.js +20 -0
- package/package.json +52 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InitializeChatSession = exports.InitializeChatClients = exports.FinalizeSession = exports.GetConfig = exports.Init = exports.ChatUI = void 0;
|
|
7
|
+
var ChatUI_1 = require("./ChatUI");
|
|
8
|
+
Object.defineProperty(exports, "ChatUI", { enumerable: true, get: function () { return __importDefault(ChatUI_1).default; } });
|
|
9
|
+
var sdkUtilities_1 = require("./sdkUtilities");
|
|
10
|
+
Object.defineProperty(exports, "Init", { enumerable: true, get: function () { return sdkUtilities_1.Init; } });
|
|
11
|
+
Object.defineProperty(exports, "GetConfig", { enumerable: true, get: function () { return sdkUtilities_1.GetConfig; } });
|
|
12
|
+
Object.defineProperty(exports, "FinalizeSession", { enumerable: true, get: function () { return sdkUtilities_1.FinalizeSession; } });
|
|
13
|
+
Object.defineProperty(exports, "InitializeChatClients", { enumerable: true, get: function () { return sdkUtilities_1.InitializeChatClients; } });
|
|
14
|
+
Object.defineProperty(exports, "InitializeChatSession", { enumerable: true, get: function () { return sdkUtilities_1.InitializeChatSession; } });
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ChatUIFontConfig, ChatUITheme, ChatUIInitPresets, ChatUITaskCardSize, ChatUITextConfigInput } from "../config";
|
|
2
|
+
export type Role = "User" | "Assistant";
|
|
3
|
+
export interface ChatMessage {
|
|
4
|
+
role: Role;
|
|
5
|
+
content: string;
|
|
6
|
+
ts?: number;
|
|
7
|
+
attachments?: Array<{
|
|
8
|
+
name: string;
|
|
9
|
+
}>;
|
|
10
|
+
availableTasksCards?: AvailableTasksCard[];
|
|
11
|
+
}
|
|
12
|
+
export interface UploadAttachmentItem {
|
|
13
|
+
AttachmentName: string;
|
|
14
|
+
AttachmentSAS: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AvailableTaskCardDetails {
|
|
17
|
+
RequestSummary: string | null;
|
|
18
|
+
TaskSummary: string | null;
|
|
19
|
+
DocumentUrl: string | null;
|
|
20
|
+
}
|
|
21
|
+
export interface RequestStepAttribute {
|
|
22
|
+
AttributeTypeId: number;
|
|
23
|
+
Name: string;
|
|
24
|
+
Value: string | number | null;
|
|
25
|
+
Alias: string;
|
|
26
|
+
IsRequired: boolean;
|
|
27
|
+
PageNumber: number;
|
|
28
|
+
SequenceNo: number;
|
|
29
|
+
IsProviderVisible: boolean;
|
|
30
|
+
IsProviderEditable: boolean;
|
|
31
|
+
Options?: Array<{
|
|
32
|
+
Name: string;
|
|
33
|
+
interactorSignatureId: number;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
export interface TaskCardMetaData {
|
|
37
|
+
IsSignDocument?: boolean;
|
|
38
|
+
DocumentTemplate?: string | null;
|
|
39
|
+
DocumentAttributeName?: string | null;
|
|
40
|
+
SignatureAttributeAlias?: string | null;
|
|
41
|
+
}
|
|
42
|
+
export interface UserSignatureOption {
|
|
43
|
+
Name: string;
|
|
44
|
+
interactorSignatureId: number;
|
|
45
|
+
}
|
|
46
|
+
export interface AvailableTasksCard {
|
|
47
|
+
RequestId: string | number;
|
|
48
|
+
RequestStepId?: string | number;
|
|
49
|
+
RequesterName: string;
|
|
50
|
+
ServiceName: string;
|
|
51
|
+
SubmitDate: string;
|
|
52
|
+
Details: AvailableTaskCardDetails;
|
|
53
|
+
RequestAttributeList?: RequestStepAttribute[];
|
|
54
|
+
MetaData?: TaskCardMetaData;
|
|
55
|
+
}
|
|
56
|
+
export type ChatUIProps = {
|
|
57
|
+
initServiceId?: string | number;
|
|
58
|
+
initRequestStepId?: string | number;
|
|
59
|
+
initPresets?: ChatUIInitPresets;
|
|
60
|
+
initialInitPreset?: "requester" | "provider" | "custom";
|
|
61
|
+
speechRegion?: string;
|
|
62
|
+
speechKey?: string;
|
|
63
|
+
speechLanguage?: string;
|
|
64
|
+
speechLang?: string;
|
|
65
|
+
ttsLanguage?: string;
|
|
66
|
+
ttsLang?: string;
|
|
67
|
+
ttsVoiceMap?: Record<string, string>;
|
|
68
|
+
theme?: ChatUITheme;
|
|
69
|
+
fonts?: ChatUIFontConfig;
|
|
70
|
+
text?: ChatUITextConfigInput;
|
|
71
|
+
taskCardSize?: ChatUITaskCardSize;
|
|
72
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ChatUISDKConfig } from "./config";
|
|
2
|
+
export declare function Init(config: ChatUISDKConfig): void;
|
|
3
|
+
export declare function GetConfig(): ChatUISDKConfig;
|
|
4
|
+
export declare function GetConfigValue<Key extends keyof ChatUISDKConfig>(key: Key): ChatUISDKConfig[Key];
|
|
5
|
+
export type InitializeChatOptions = {
|
|
6
|
+
initServiceId?: string | number;
|
|
7
|
+
initRequestStepId?: string | number;
|
|
8
|
+
contextWindow?: string;
|
|
9
|
+
domain?: string;
|
|
10
|
+
token?: string;
|
|
11
|
+
};
|
|
12
|
+
export type InitializeChatClientsOptions = {
|
|
13
|
+
domain?: string;
|
|
14
|
+
token?: string;
|
|
15
|
+
};
|
|
16
|
+
export type InitializeChatResult = {
|
|
17
|
+
initialized: boolean;
|
|
18
|
+
sessionId: string;
|
|
19
|
+
payload?: any;
|
|
20
|
+
};
|
|
21
|
+
export declare function InitializeChatSession(options?: InitializeChatOptions): Promise<InitializeChatResult>;
|
|
22
|
+
export declare function InitializeChatClients(options?: InitializeChatClientsOptions): Promise<boolean>;
|
|
23
|
+
export type FinalizeSessionOptions = {
|
|
24
|
+
token?: string;
|
|
25
|
+
domain?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function FinalizeSession(options?: FinalizeSessionOptions): Promise<boolean>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Init = Init;
|
|
13
|
+
exports.GetConfig = GetConfig;
|
|
14
|
+
exports.GetConfigValue = GetConfigValue;
|
|
15
|
+
exports.InitializeChatSession = InitializeChatSession;
|
|
16
|
+
exports.InitializeChatClients = InitializeChatClients;
|
|
17
|
+
exports.FinalizeSession = FinalizeSession;
|
|
18
|
+
const config_1 = require("./config");
|
|
19
|
+
const chatDefaults_1 = require("./constants/chatDefaults");
|
|
20
|
+
const generateGuid_1 = require("./utils/generateGuid");
|
|
21
|
+
const localStorage_1 = require("./utils/localStorage");
|
|
22
|
+
const storageKeys_1 = require("./utils/storageKeys");
|
|
23
|
+
const normalizeAuthToken = (value) => {
|
|
24
|
+
const trimmed = (value !== null && value !== void 0 ? value : "").trim();
|
|
25
|
+
if (!trimmed)
|
|
26
|
+
return "";
|
|
27
|
+
return /^bearer\s+/i.test(trimmed) ? trimmed : `Bearer ${trimmed}`;
|
|
28
|
+
};
|
|
29
|
+
function Init(config) {
|
|
30
|
+
const missing = [];
|
|
31
|
+
if (config.baseUrl === undefined)
|
|
32
|
+
missing.push("baseUrl");
|
|
33
|
+
if (config.apiSubscriptionKey === undefined)
|
|
34
|
+
missing.push("apiSubscriptionKey");
|
|
35
|
+
if (config.loginSubscriptionKey === undefined)
|
|
36
|
+
missing.push("loginSubscriptionKey");
|
|
37
|
+
if (config.token === undefined)
|
|
38
|
+
missing.push("token");
|
|
39
|
+
if (config.isDab === undefined)
|
|
40
|
+
missing.push("isDab");
|
|
41
|
+
if (config.initializeChat === undefined)
|
|
42
|
+
missing.push("initializeChat");
|
|
43
|
+
if (config.contextWindow === undefined)
|
|
44
|
+
missing.push("contextWindow");
|
|
45
|
+
if (missing.length) {
|
|
46
|
+
throw new Error(`Init() missing required config: ${missing.join(", ")}`);
|
|
47
|
+
}
|
|
48
|
+
config_1.ChatUISDKConfigStoreInstance.setConfig(config);
|
|
49
|
+
}
|
|
50
|
+
function GetConfig() {
|
|
51
|
+
return config_1.ChatUISDKConfigStoreInstance.getConfig();
|
|
52
|
+
}
|
|
53
|
+
function GetConfigValue(key) {
|
|
54
|
+
return config_1.ChatUISDKConfigStoreInstance.getValue(key);
|
|
55
|
+
}
|
|
56
|
+
function InitializeChatSession() {
|
|
57
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
58
|
+
var _a, _b, _c, _d, _e;
|
|
59
|
+
const config = GetConfig();
|
|
60
|
+
const apiBase = chatDefaults_1.DEFAULT_API_BASE;
|
|
61
|
+
const apiKey = chatDefaults_1.DEFAULT_API_KEY;
|
|
62
|
+
let sessionId = localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.sessionId, "");
|
|
63
|
+
if (!sessionId) {
|
|
64
|
+
sessionId = (0, generateGuid_1.generateGuid)();
|
|
65
|
+
localStorage_1.ls.set(storageKeys_1.STORAGE_KEYS.sessionId, sessionId);
|
|
66
|
+
}
|
|
67
|
+
if (!apiBase || !apiKey || !sessionId) {
|
|
68
|
+
throw new Error("Missing chat API configuration or session ID.");
|
|
69
|
+
}
|
|
70
|
+
const existingInit = localStorage_1.ls.get((0, storageKeys_1.getInitCompletedKey)(sessionId), false);
|
|
71
|
+
if (existingInit) {
|
|
72
|
+
return { initialized: false, sessionId };
|
|
73
|
+
}
|
|
74
|
+
const authToken = normalizeAuthToken((_b = (_a = options.token) !== null && _a !== void 0 ? _a : config.token) !== null && _b !== void 0 ? _b : localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.authToken, ""));
|
|
75
|
+
if (!authToken) {
|
|
76
|
+
throw new Error("Auth token is required to initialize chat.");
|
|
77
|
+
}
|
|
78
|
+
localStorage_1.ls.set(storageKeys_1.STORAGE_KEYS.authToken, authToken);
|
|
79
|
+
const defaultDomain = config.isDab ? chatDefaults_1.DEFAULT_DOMAIN : "";
|
|
80
|
+
const domain = ((_c = options.domain) !== null && _c !== void 0 ? _c : localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.domain, defaultDomain)).trim();
|
|
81
|
+
const contextWindow = (_d = options.contextWindow) !== null && _d !== void 0 ? _d : config.contextWindow;
|
|
82
|
+
const bodyPayload = {
|
|
83
|
+
Domain: domain,
|
|
84
|
+
ContextWindow: contextWindow || "ComposeRequest",
|
|
85
|
+
InitializeLangauge: "ar-JO",
|
|
86
|
+
};
|
|
87
|
+
if (options.initServiceId !== undefined && options.initServiceId !== null) {
|
|
88
|
+
const n = Number(options.initServiceId);
|
|
89
|
+
if (!Number.isNaN(n))
|
|
90
|
+
bodyPayload.ServiceId = n;
|
|
91
|
+
}
|
|
92
|
+
if (options.initRequestStepId !== undefined &&
|
|
93
|
+
options.initRequestStepId !== null) {
|
|
94
|
+
const n = Number(options.initRequestStepId);
|
|
95
|
+
if (!Number.isNaN(n))
|
|
96
|
+
bodyPayload.RequestStepId = n;
|
|
97
|
+
}
|
|
98
|
+
const initRes = yield fetch(new URL("/api/initializeChat", apiBase).toString(), {
|
|
99
|
+
method: "POST",
|
|
100
|
+
headers: {
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
"api-key": apiKey,
|
|
103
|
+
Authorization: authToken,
|
|
104
|
+
},
|
|
105
|
+
credentials: "include",
|
|
106
|
+
body: JSON.stringify(bodyPayload),
|
|
107
|
+
});
|
|
108
|
+
if (!initRes.ok) {
|
|
109
|
+
let msg = "";
|
|
110
|
+
try {
|
|
111
|
+
msg = yield initRes.text();
|
|
112
|
+
}
|
|
113
|
+
catch (_f) { }
|
|
114
|
+
throw new Error(`initializeChat failed: ${initRes.status} ${initRes.statusText}${msg ? ` - ${msg}` : ""}`);
|
|
115
|
+
}
|
|
116
|
+
const initPayload = yield initRes.json().catch(() => ({}));
|
|
117
|
+
const resolvedSessionId = (_e = initPayload === null || initPayload === void 0 ? void 0 : initPayload.SessionId) !== null && _e !== void 0 ? _e : sessionId;
|
|
118
|
+
if (initPayload === null || initPayload === void 0 ? void 0 : initPayload.SessionId) {
|
|
119
|
+
localStorage_1.ls.set(storageKeys_1.STORAGE_KEYS.sessionId, initPayload.SessionId);
|
|
120
|
+
}
|
|
121
|
+
localStorage_1.ls.set((0, storageKeys_1.getInitCompletedKey)(resolvedSessionId), true);
|
|
122
|
+
return { initialized: true, sessionId: resolvedSessionId, payload: initPayload };
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function InitializeChatClients() {
|
|
126
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
127
|
+
var _a, _b, _c;
|
|
128
|
+
const config = GetConfig();
|
|
129
|
+
const apiBase = chatDefaults_1.DEFAULT_API_BASE;
|
|
130
|
+
const apiKey = chatDefaults_1.DEFAULT_API_KEY;
|
|
131
|
+
const authToken = normalizeAuthToken((_b = (_a = options.token) !== null && _a !== void 0 ? _a : config.token) !== null && _b !== void 0 ? _b : localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.authToken, ""));
|
|
132
|
+
if (!authToken) {
|
|
133
|
+
throw new Error("Auth token is required to initialize chat clients.");
|
|
134
|
+
}
|
|
135
|
+
localStorage_1.ls.set(storageKeys_1.STORAGE_KEYS.authToken, authToken);
|
|
136
|
+
const defaultDomain = config.isDab ? chatDefaults_1.DEFAULT_DOMAIN : "";
|
|
137
|
+
const domain = ((_c = options.domain) !== null && _c !== void 0 ? _c : localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.domain, defaultDomain)).trim();
|
|
138
|
+
const initClientsRes = yield fetch(new URL("/api/initializeChatClients", apiBase).toString(), {
|
|
139
|
+
method: "POST",
|
|
140
|
+
headers: {
|
|
141
|
+
"Content-Type": "application/json",
|
|
142
|
+
"api-key": apiKey,
|
|
143
|
+
Authorization: authToken,
|
|
144
|
+
},
|
|
145
|
+
body: JSON.stringify({ Domain: domain }),
|
|
146
|
+
});
|
|
147
|
+
if (!initClientsRes.ok) {
|
|
148
|
+
let msg = "";
|
|
149
|
+
try {
|
|
150
|
+
msg = yield initClientsRes.text();
|
|
151
|
+
}
|
|
152
|
+
catch (_d) { }
|
|
153
|
+
throw new Error(`initializeChatClients failed: ${initClientsRes.status} ${initClientsRes.statusText}${msg ? ` - ${msg}` : ""}`);
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function FinalizeSession() {
|
|
159
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
160
|
+
var _a, _b, _c;
|
|
161
|
+
const config = GetConfig();
|
|
162
|
+
const apiBase = chatDefaults_1.DEFAULT_API_BASE;
|
|
163
|
+
const apiKey = chatDefaults_1.DEFAULT_API_KEY;
|
|
164
|
+
const sessionId = localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.sessionId, "");
|
|
165
|
+
const domain = ((_a = options.domain) !== null && _a !== void 0 ? _a : localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.domain, "")).trim();
|
|
166
|
+
const authToken = normalizeAuthToken((_c = (_b = options.token) !== null && _b !== void 0 ? _b : config.token) !== null && _c !== void 0 ? _c : localStorage_1.ls.get(storageKeys_1.STORAGE_KEYS.authToken, ""));
|
|
167
|
+
if (!apiBase || !apiKey || !sessionId)
|
|
168
|
+
return false;
|
|
169
|
+
try {
|
|
170
|
+
yield fetch(new URL(`/api/deleteSessionContext`, apiBase).toString(), {
|
|
171
|
+
method: "POST",
|
|
172
|
+
headers: Object.assign({ "Content-Type": "application/json", "api-key": apiKey }, (authToken ? { Authorization: authToken } : {})),
|
|
173
|
+
body: JSON.stringify({
|
|
174
|
+
Domain: domain,
|
|
175
|
+
SessionId: sessionId,
|
|
176
|
+
}),
|
|
177
|
+
});
|
|
178
|
+
localStorage_1.ls.remove((0, storageKeys_1.getMessagesKey)(sessionId));
|
|
179
|
+
localStorage_1.ls.remove((0, storageKeys_1.getInitCompletedKey)(sessionId));
|
|
180
|
+
localStorage_1.ls.set(storageKeys_1.STORAGE_KEYS.authToken, "");
|
|
181
|
+
localStorage_1.ls.set(storageKeys_1.STORAGE_KEYS.initUsername, "");
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
catch (_d) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|