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.
Files changed (55) hide show
  1. package/README.md +327 -0
  2. package/dist/ChatUI.d.ts +2 -0
  3. package/dist/ChatUI.js +1781 -0
  4. package/dist/components/Composer.d.ts +35 -0
  5. package/dist/components/Composer.js +19 -0
  6. package/dist/components/DocumentViewer.d.ts +24 -0
  7. package/dist/components/DocumentViewer.js +16 -0
  8. package/dist/components/FormattedText.d.ts +9 -0
  9. package/dist/components/FormattedText.js +98 -0
  10. package/dist/components/InitPanel.d.ts +41 -0
  11. package/dist/components/InitPanel.js +20 -0
  12. package/dist/components/MessageItem.d.ts +19 -0
  13. package/dist/components/MessageItem.js +50 -0
  14. package/dist/components/MessageList.d.ts +22 -0
  15. package/dist/components/MessageList.js +19 -0
  16. package/dist/components/TakeActionModal.d.ts +26 -0
  17. package/dist/components/TakeActionModal.js +26 -0
  18. package/dist/components/TaskCardsModal.d.ts +13 -0
  19. package/dist/components/TaskCardsModal.js +17 -0
  20. package/dist/components/ToolResultOverlay.d.ts +9 -0
  21. package/dist/components/ToolResultOverlay.js +14 -0
  22. package/dist/components/TopBar.d.ts +13 -0
  23. package/dist/components/TopBar.js +9 -0
  24. package/dist/components/TypingDots.d.ts +1 -0
  25. package/dist/components/TypingDots.js +8 -0
  26. package/dist/components/VoiceOverlay.d.ts +11 -0
  27. package/dist/components/VoiceOverlay.js +9 -0
  28. package/dist/config.d.ts +179 -0
  29. package/dist/config.js +24 -0
  30. package/dist/constants/chatDefaults.d.ts +19 -0
  31. package/dist/constants/chatDefaults.js +234 -0
  32. package/dist/helpers/api.d.ts +12 -0
  33. package/dist/helpers/api.js +104 -0
  34. package/dist/helpers/taskAttributes.d.ts +11 -0
  35. package/dist/helpers/taskAttributes.js +41 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +14 -0
  38. package/dist/models/chat.types.d.ts +72 -0
  39. package/dist/models/chat.types.js +2 -0
  40. package/dist/sdkUtilities.d.ts +27 -0
  41. package/dist/sdkUtilities.js +188 -0
  42. package/dist/styles.css +1412 -0
  43. package/dist/utils/classNames.d.ts +1 -0
  44. package/dist/utils/classNames.js +6 -0
  45. package/dist/utils/format.d.ts +2 -0
  46. package/dist/utils/format.js +18 -0
  47. package/dist/utils/generateGuid.d.ts +1 -0
  48. package/dist/utils/generateGuid.js +10 -0
  49. package/dist/utils/localStorage.d.ts +6 -0
  50. package/dist/utils/localStorage.js +39 -0
  51. package/dist/utils/storageKeys.d.ts +16 -0
  52. package/dist/utils/storageKeys.js +25 -0
  53. package/dist/utils/textDirection.d.ts +2 -0
  54. package/dist/utils/textDirection.js +20 -0
  55. package/package.json +52 -0
package/README.md ADDED
@@ -0,0 +1,327 @@
1
+ # MCP Chat UI SDK
2
+
3
+ A React UI SDK that bundles a full chat experience with speech (STT/TTS), file
4
+ uploads, document viewing, and task actions.
5
+
6
+ ## Requirements
7
+
8
+ - React 18+ or 19 and React DOM.
9
+ - Node 18+ for build/demo workflows.
10
+
11
+
12
+
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install mcp-chat-ui
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ Import CSS in App.tsx
23
+
24
+ ```App.tsx
25
+ import "mcp-chat-ui/styles.css";
26
+
27
+ ```
28
+
29
+ Initialize the SDK (required):
30
+
31
+ ```ts
32
+ import { Init } from "mcp-chat-ui";
33
+
34
+ const initConfig = {
35
+ baseUrl: "https://apim.octopian.cloud",
36
+ apiSubscriptionKey: "<apim-subscription-key>",
37
+ loginSubscriptionKey: "<login-subscription-key>",
38
+ token: "Bearer <token>",
39
+ isDab: false,
40
+ initializeChat: false,
41
+ showInitPanel: true,
42
+ contextWindow: "ComposeRequest",
43
+ };
44
+
45
+ Init(initConfig);
46
+ ```
47
+
48
+ Render the UI (view config goes here):
49
+
50
+ ```tsx
51
+ import { ChatUI } from "mcp-chat-ui";
52
+
53
+ export default function App() {
54
+ return (
55
+ <ChatUI
56
+ speechRegion="swedencentral"
57
+ speechKey="<your-speech-key>"
58
+ theme={{
59
+ brand: "#0b1f33",
60
+ panelBackground: "#ffffff",
61
+ appBackground: "#f7f7f2",
62
+ textMain: "#0b1f33",
63
+ }}
64
+ fonts={{
65
+ base: "\"DM Sans\", system-ui, sans-serif",
66
+ }}
67
+ />
68
+ );
69
+ }
70
+ ```
71
+
72
+ Finalize a session (same API used by the Logout button):
73
+
74
+ ```ts
75
+ import { FinalizeSession } from "mcp-chat-ui";
76
+
77
+ await FinalizeSession({
78
+ domain: "dab.ae",
79
+ token: "Bearer <token>",
80
+ });
81
+ ```
82
+
83
+ Initialize a session with service/request IDs (one-time per session):
84
+
85
+ ```ts
86
+ import { InitializeChatSession } from "mcp-chat-ui";
87
+
88
+ await InitializeChatSession({
89
+ initServiceId: 1001,
90
+ initRequestStepId: 2001,
91
+ });
92
+ ```
93
+
94
+ ## Service Base URL
95
+
96
+ - Provide `baseUrl` and the SDK derives RequestStep, TransactionCatalog, Storage,
97
+ Signature, and the login endpoint from it.
98
+ - Provide `apiSubscriptionKey` for APIM calls to those services.
99
+
100
+ ## Initialize (Login) Flow
101
+
102
+ - The login endpoint is derived from `baseUrl`.
103
+ - `apiSubscriptionKey` is sent to the login endpoint (or override with `loginSubscriptionKey`).
104
+ - `token` is required in `Init` (use an empty string if you plan to sign in via the
105
+ panel and let it set the token).
106
+ - `initializeChat: true` triggers the init flow on load and calls
107
+ `initializeChatClients` only (cache setup).
108
+ - `InitializeChatSession` calls `initializeChat` only. Messages are blocked until
109
+ it runs once per session.
110
+ - The login panel runs `initializeChatClients` followed by `InitializeChatSession`.
111
+ - If `initializeChat` is `false`, call `InitializeChatSession` manually after
112
+ login (or before rendering the view) to enable messaging.
113
+
114
+ ## Login From The UI
115
+
116
+ The SDK ships a Login panel (enabled by default). Click **Login** in
117
+ the top bar, fill the fields (domain, username, password, context window, optional
118
+ service/request step IDs, languages), then submit. The SDK stores common values
119
+ in `localStorage` (session ID, auth token, domain, username) to keep continuity.
120
+
121
+ To hide the panel:
122
+
123
+ ```ts
124
+ Init({ ...initConfig, showInitPanel: false });
125
+ ```
126
+
127
+ To auto-initialize on load:
128
+
129
+ ```ts
130
+ Init({ ...initConfig, initializeChat: true });
131
+ ```
132
+
133
+ ## Configuration Reference
134
+
135
+ Init (global):
136
+ - `baseUrl` (required): base URL for RequestStep/TransactionCatalog/Storage/Signature/login.
137
+ - `apiSubscriptionKey` (required): subscription key for the base URL.
138
+ - `loginSubscriptionKey` (required): login endpoint subscription key.
139
+ - `token` (required): pre-set auth header value (include scheme).
140
+ - `isDab` (required): if `true`, default domain is `dab.ae`, otherwise blank.
141
+ - `showInitPanel` (optional, default `true`)
142
+ - `initializeChat` (required)
143
+ - `contextWindow` (required)
144
+
145
+ ChatUI props (view):
146
+ - `initServiceId`, `initRequestStepId`
147
+ - `initPresets`: optional `{ requester, provider }` credentials used to prefill the preset buttons.
148
+ - `speechRegion`, `speechKey`
149
+ - `speechLanguage` (transcription)
150
+ - `ttsLanguage`
151
+ - `ttsVoiceMap`
152
+ - `theme`: see tokens below.
153
+ - `fonts`: `{ base, heading, mono }`.
154
+ - `text`: UI strings (login panel text is fixed and not configurable).
155
+ - `taskCardSize`: `{ width?: number; height?: number }` for task cards in the chat list.
156
+
157
+ ## Theme Tokens
158
+
159
+ You can override any subset:
160
+
161
+ - `appBackground`: main page background behind the chat surface.
162
+ - `panelBackground`: main chat panel surface color.
163
+ - `panelBackgroundMuted`: muted surface for translucent panels (top bar, composer).
164
+ - `panelBackgroundSubtle`: lighter surface tint for subtle sections.
165
+ - `brand`: primary brand color for buttons and accents.
166
+ - `brandHover`: hover color for brand buttons.
167
+ - `brandAlpha30`: brand color with ~30% alpha (badges/overlays).
168
+ - `brandAlpha40`: brand color with ~40% alpha.
169
+ - `brandAlpha50`: brand color with ~50% alpha.
170
+ - `textMain`: primary text color.
171
+ - `textEmphasis`: stronger text emphasis for headings.
172
+ - `textSupporting`: secondary text color.
173
+ - `textMuted`: muted body text color.
174
+ - `textSubtle`: subtle labels and placeholders.
175
+ - `textDisabled`: disabled or faint text color.
176
+ - `textOnBrand`: text color used on brand backgrounds.
177
+ - `userMessageBackground`: background color for user chat bubbles.
178
+ - `userMessageText`: text color for user chat bubbles.
179
+ - `neutralLightest`: light neutral background (50).
180
+ - `neutralLighter`: light neutral background (100).
181
+ - `neutralMedium`: neutral mid tone (400).
182
+ - `neutralDark`: dark neutral (800).
183
+ - `neutralDarker`: darkest neutral (900).
184
+ - `neutralDarker80`: darkest neutral with ~80% alpha.
185
+ - `borderDefault`: default border color.
186
+ - `accentBackground`: accent background for info callouts.
187
+ - `accentText`: accent text color for info callouts.
188
+ - `warningBackground`: warning background for alerts.
189
+ - `warningText`: warning text color for alerts.
190
+ - `errorBackground`: error background for alerts.
191
+ - `errorText`: error text color for alerts.
192
+ - `focusRing`: subtle focus ring color.
193
+ - `focusRingStrong`: stronger focus ring color.
194
+ - `outlineShadow`: outline shadow color for buttons.
195
+ - `elevatedShadow`: elevated shadow color for modals/cards.
196
+ - `selectOptionHover`: select option hover/selected background color.
197
+ - `cardSelectedBackground`: selected task card background color.
198
+
199
+ Legacy theme keys (e.g. `primary`, `background`, `surface`) are still accepted,
200
+ but prefer the names above for new work.
201
+
202
+ ## Text Tokens
203
+
204
+ Override any subset of strings (login panel text is fixed):
205
+
206
+ ```tsx
207
+ <ChatUI
208
+ text={{
209
+ topBar: { clearButton: "Reset" },
210
+ emptyState: { title: "Whats on the agenda today?" },
211
+ composer: { placeholderDefault: "Ask me anything" },
212
+ }}
213
+ />;
214
+ ```
215
+
216
+ Top bar:
217
+ - `topBar.sessionLabel`
218
+ - `topBar.clearButton`
219
+ - `topBar.clearTitle`
220
+ - `topBar.logoutButton`
221
+ - `topBar.logoutTitle`
222
+ - `topBar.loginButton`
223
+ - `topBar.loginTitle`
224
+
225
+ Empty state:
226
+ - `emptyState.title`
227
+
228
+ Composer:
229
+ - `composer.selectedTaskPrefix`
230
+ - `composer.selectionLineTemplate` (supports `{id}`)
231
+ - `composer.selectedTaskClearTitle`
232
+ - `composer.attachTitle`
233
+ - `composer.placeholderAuthRequired`
234
+ - `composer.placeholderDefault`
235
+ - `composer.voiceStartTitle`
236
+ - `composer.voiceStopTitle`
237
+ - `composer.sendTitle`
238
+
239
+ Voice overlay:
240
+ - `voiceOverlay.cancelTitle`
241
+ - `voiceOverlay.confirmTitle`
242
+
243
+ Message item:
244
+ - `messageItem.moreButton`
245
+ - `messageItem.selectCardTitle`
246
+ - `messageItem.stopReadingTitle`
247
+ - `messageItem.readMessageTitle`
248
+ - `messageItem.linkButtonLabel`
249
+
250
+ Task cards:
251
+ - `taskCards.modalTitle`
252
+ - `taskCards.takeActionButton`
253
+ - `taskCards.showDocumentButton`
254
+
255
+ Document viewer:
256
+ - `documentViewer.title`
257
+ - `documentViewer.downloadButton`
258
+ - `documentViewer.loading`
259
+ - `documentViewer.iframeTitle`
260
+ - `documentViewer.useGoogleViewer`
261
+ - `documentViewer.useDirectViewer`
262
+ - `documentViewer.errorSuffix`
263
+ - `documentViewer.proceedButton`
264
+
265
+ Take action:
266
+ - `takeAction.backAriaLabel`
267
+ - `takeAction.closeAriaLabel`
268
+ - `takeAction.actionTypeLabel`
269
+ - `takeAction.selectActionPlaceholder`
270
+ - `takeAction.approveOption`
271
+ - `takeAction.rejectOption`
272
+ - `takeAction.commentsLabel`
273
+ - `takeAction.commentsPlaceholder`
274
+ - `takeAction.noEditableAttributes`
275
+ - `takeAction.selectSignaturePlaceholder`
276
+ - `takeAction.selectOptionPlaceholder`
277
+ - `takeAction.signaturePlaceholder`
278
+ - `takeAction.cancelButton`
279
+ - `takeAction.submitButton`
280
+ - `takeAction.nextButton`
281
+
282
+ Tool result:
283
+ - `toolResult.title`
284
+
285
+ Alerts:
286
+ - `alerts.clearConfirm`
287
+ - `alerts.clearFailedTemplate` (supports `{error}`)
288
+ - `alerts.fetchHistoryFailed`
289
+ - `alerts.initMissingCredentials`
290
+ - `alerts.initMissingBaseUrl`
291
+ - `alerts.initMissingSubscriptionKey`
292
+ - `alerts.initMissingEndpoint`
293
+ - `alerts.initFailed`
294
+ - `alerts.initNoToken`
295
+ - `alerts.initChatFailedTemplate` (supports `{status}`, `{statusText}`, `{details}`)
296
+ - `alerts.initChatNetworkError`
297
+ - `alerts.initChatErrorTemplate` (supports `{error}`)
298
+ - `alerts.initRequired`
299
+ - `alerts.initNetworkError`
300
+ - `alerts.initErrorTemplate` (supports `{error}`)
301
+
302
+ Errors:
303
+ - `errors.assistantMessageTemplate` (supports `{error}`)
304
+ - `errors.microphoneAccess`
305
+ - `errors.transcriptionStart`
306
+ - `errors.sasRequestFailedTemplate` (supports `{status}`, `{statusText}`, `{details}`)
307
+ - `errors.noSasEntries`
308
+ - `errors.invalidSasEntry`
309
+ - `errors.chatFailedTemplate` (supports `{status}`, `{statusText}`, `{details}`)
310
+ - `errors.takeActionAuthRequired`
311
+ - `errors.takeActionMissingRequestStep`
312
+ - `errors.takeActionMissingSignature`
313
+ - `errors.takeActionNoDocument`
314
+
315
+ ## Demo App (repo only)
316
+
317
+ ```bash
318
+ cd demo
319
+ npm install
320
+ npm run dev
321
+ ```
322
+
323
+ ## Build
324
+
325
+ ```bash
326
+ npm run build
327
+ ```
@@ -0,0 +1,2 @@
1
+ import type { ChatUIProps } from "./models/chat.types";
2
+ export default function ChatUI(props: ChatUIProps): import("react/jsx-runtime").JSX.Element;