@nlxai/touchpoint-ui 1.1.8-alpha.1 → 1.1.8-alpha.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.
@@ -0,0 +1,408 @@
1
+ import { Config, ApplicationMessage, ConversationHandler, Context } from '@nlxai/core';
2
+ import { ComponentType } from 'react';
3
+ import { InteractiveElementInfo } from './bidirectional/analyzePageForms';
4
+ /**
5
+ * Window size configuration
6
+ */
7
+ export type WindowSize = "half" | "full";
8
+ /**
9
+ * Color mode configuration (light/dark modes)
10
+ */
11
+ export type ColorMode = "light" | "dark";
12
+ /**
13
+ * Choice message with metadata
14
+ */
15
+ export interface ChoiceMessage {
16
+ /**
17
+ * Message contents
18
+ */
19
+ message: ApplicationMessage;
20
+ /**
21
+ * Index in the response transcript history
22
+ */
23
+ responseIndex: number;
24
+ /**
25
+ * Message index in the current response
26
+ */
27
+ messageIndex: number;
28
+ }
29
+ /**
30
+ * Custom Modalities allow rendering of rich components from nodes.
31
+ * See: https://docs.studio.nlx.ai/build/resources/modalities
32
+ */
33
+ export type CustomModalityComponent<Data> = ComponentType<{
34
+ /**
35
+ * The payload of the Custom Modality. The schema is defined in Dialog Studio settings.
36
+ */
37
+ data: Data;
38
+ /**
39
+ * Conversation handler instance
40
+ */
41
+ conversationHandler: ConversationHandler;
42
+ /**
43
+ * Whether the component is enabled
44
+ * We should probably use context and handle disabling interactive components automatically for the user
45
+ * @internal
46
+ */
47
+ enabled: boolean;
48
+ /**
49
+ * Class name to propagate to the container
50
+ */
51
+ className?: string;
52
+ }>;
53
+ /**
54
+ * The full theme expressed as CSS custom properties
55
+ */
56
+ export interface Theme {
57
+ /**
58
+ * Font family
59
+ */
60
+ fontFamily: string;
61
+ /**
62
+ * Primary color with 80% opacity
63
+ */
64
+ primary80: string;
65
+ /**
66
+ * Primary color with 60% opacity
67
+ */
68
+ primary60: string;
69
+ /**
70
+ * Primary color with 40% opacity
71
+ */
72
+ primary40: string;
73
+ /**
74
+ * Primary color with 20% opacity
75
+ */
76
+ primary20: string;
77
+ /**
78
+ * Primary color with 10% opacity
79
+ */
80
+ primary10: string;
81
+ /**
82
+ * Primary color with 5% opacity
83
+ */
84
+ primary5: string;
85
+ /**
86
+ * Primary color with 1% opacity
87
+ */
88
+ primary1: string;
89
+ /**
90
+ * Secondary color with 80% opacity
91
+ */
92
+ secondary80: string;
93
+ /**
94
+ * Secondary color with 60% opacity
95
+ */
96
+ secondary60: string;
97
+ /**
98
+ * Secondary color with 40% opacity
99
+ */
100
+ secondary40: string;
101
+ /**
102
+ * Secondary color with 20% opacity
103
+ */
104
+ secondary20: string;
105
+ /**
106
+ * Secondary color with 10% opacity
107
+ */
108
+ secondary10: string;
109
+ /**
110
+ * Secondary color with 5% opacity
111
+ */
112
+ secondary5: string;
113
+ /**
114
+ * Secondary color with 1% opacity
115
+ */
116
+ secondary1: string;
117
+ /**
118
+ * Accent color used e.g. for prominent buttons, the loader animation as well as selected card outlines
119
+ */
120
+ accent: string;
121
+ /**
122
+ * Accent color with 20% opacity
123
+ */
124
+ accent20: string;
125
+ /**
126
+ * The background color of the main Touchpoint interface
127
+ */
128
+ background: string;
129
+ /**
130
+ * The color of the overlay covering the visible portion of the website when the Touchpoint interface does not cover the full screen
131
+ */
132
+ overlay: string;
133
+ /**
134
+ * Primary warning color
135
+ */
136
+ warningPrimary: string;
137
+ /**
138
+ * Secondary warning color
139
+ */
140
+ warningSecondary: string;
141
+ /**
142
+ * Primary error color
143
+ */
144
+ errorPrimary: string;
145
+ /**
146
+ * Secondary error color
147
+ */
148
+ errorSecondary: string;
149
+ /**
150
+ * Inner border radius: used for most buttons
151
+ */
152
+ innerBorderRadius: string;
153
+ /**
154
+ * Outer border radius: generally used for elements that contain buttons that have inner border radius. Also used by the launch button.
155
+ */
156
+ outerBorderRadius: string;
157
+ }
158
+ /**
159
+ * Custom conversation init method. Defaults to sending the welcome intent
160
+ * @param handler - the conversation handler.
161
+ * @param context - context set via TouchpointConfiguration.initialContext
162
+ */
163
+ export type InitializeConversation = (handler: ConversationHandler, context?: Context) => void;
164
+ /**
165
+ * Fully custom launch icon
166
+ */
167
+ export type CustomLaunchButton = ComponentType<{
168
+ /**
169
+ * Class name injected into the component mainly to take care of positioning and z-index. Can be combined with more presentational and sizing-related class names.
170
+ */
171
+ className?: string;
172
+ /**
173
+ * Click handler that expands Touchpoint, without the caller having to implement this based on Touchpoint instance methods.
174
+ */
175
+ onClick?: () => void;
176
+ }>;
177
+ /**
178
+ * Input type for the experience
179
+ */
180
+ export type Input = "text" | "voice" | "voiceMini";
181
+ /**
182
+ * Input field value
183
+ */
184
+ export interface InputField {
185
+ /**
186
+ * Field ID
187
+ */
188
+ id: string;
189
+ /**
190
+ * Field value
191
+ */
192
+ value: string | boolean;
193
+ }
194
+ /**
195
+ * Internal state that the automatic context maintains.
196
+ */
197
+ export interface PageState {
198
+ /** Mapping from form element IDs to their DOM elements */
199
+ formElements: Record<string, Element>;
200
+ /** Mapping from link element names to their URLs */
201
+ links: Record<string, string>;
202
+ /** Mapping from custom commands to their handlers */
203
+ customCommands: Map<string, (arg: any) => void>;
204
+ }
205
+ /**
206
+ * Bidirectional context information that is sent to the LLM.
207
+ */
208
+ export interface BidirectionalContext {
209
+ /** Identifier for which page you are currently on. This can be used to filter the relevant KB pages. */
210
+ uri?: string;
211
+ /** The active form fields that can be filled in. */
212
+ fields?: InteractiveElementInfo[];
213
+ /** Human readable location names that can be navigated to. */
214
+ destinations?: string[];
215
+ /**
216
+ * Custom actions that can be performed.
217
+ */
218
+ actions?: Array<{
219
+ /** The name of the command, used to invoke it. */
220
+ action: string;
221
+ /** A short description of the command */
222
+ description?: string;
223
+ /** A schema for validating the command's input. Should follow the JSON Schema specification. */
224
+ schema?: any;
225
+ }>;
226
+ }
227
+ /**
228
+ * Configuration for bidirectional mode of voice+.
229
+ */
230
+ export type BidirectionalConfig = {
231
+ /**
232
+ * Attempt to gather and send page context automatically. This will work well on semantically coded pages without too many custom form controls.
233
+ * This enables a number of automatic features.
234
+ *
235
+ * Defaults to `true`.
236
+ */
237
+ automaticContext?: true;
238
+ /**
239
+ * Navigation handler for bidirectional mode.
240
+ *
241
+ * If automatic context gathering is enabled, the default implementation will navigate to those pages using standard `window.location` APIs.
242
+ * @param action - The navigation action to perform.
243
+ * @param destination - The name of the destination to navigate to if `action` is `"page_custom"`.
244
+ * @param destinations - A map of destination names to URLs for custom navigation. Only present if `automaticContext` is enabled.
245
+ */
246
+ navigation?: (action: "page_next" | "page_previous" | "page_custom" | "page_unknown", destination: string | undefined, destinations: Record<string, string>) => void;
247
+ /**
248
+ * A callback for filling out form fields in bidirectional mode.
249
+ *
250
+ * If automatic context gathering is enabled, the default implementation will fill out the form fields using standard DOM APIs.
251
+ * @param fields - An array of field objects with `id` and `value` properties.
252
+ * @param pageFields - A map of field IDs to DOM elements for custom form filling. Only present if `automaticContext` is enabled.
253
+ */
254
+ input?: (fields: InputField[], pageFields: Record<string, Element>) => void;
255
+ /**
256
+ * A callback for custom actions in bidirectional mode.
257
+ * @param action - The custom name of your action.
258
+ * @param payload - The payload defined for the custom action.
259
+ * @deprecated Use {@link TouchpointInstance.setCustomBidirectionalCommands} instead.
260
+ * @returns
261
+ */
262
+ custom?: (action: string, payload: unknown) => void;
263
+ /**
264
+ * A callback for customizing the automatic context gathering.
265
+ *
266
+ * This allows you to modify the context and state before they are sent to the LLM.
267
+ * @param arg - An object containing the current context and state.
268
+ * @returns The modified context and state. If the state is identical to the previous state, the call to the server will be skipped.
269
+ */
270
+ customizeAutomaticContext?: (arg: {
271
+ context: BidirectionalContext;
272
+ state: PageState;
273
+ }) => {
274
+ /**
275
+ * The current context being sent to the LLM
276
+ */
277
+ context: BidirectionalContext;
278
+ /**
279
+ * The current state of the page - this is stuff not sent to the LLM, but needed to connect the results back to actions to take on the page.
280
+ */
281
+ state: PageState;
282
+ };
283
+ } | {
284
+ /**
285
+ * Attempt to gather and send page context automatically. This will work well on semantically coded pages without too many custom form controls.
286
+ * This enables a number of automatic features.
287
+ *
288
+ * Defaults to `true`.
289
+ */
290
+ automaticContext: false;
291
+ /**
292
+ * Navigation handler for bidirectional mode.
293
+ *
294
+ * If automatic context gathering is enabled, the default implementation will navigate to those pages using standard `window.location` APIs.
295
+ * @param action - The navigation action to perform.
296
+ * @param destination - The name of the destination to navigate to if `action` is `"page_custom"`.
297
+ */
298
+ navigation?: (action: "page_next" | "page_previous" | "page_custom" | "page_unknown", destination?: string) => void;
299
+ /**
300
+ * A callback for filling out form fields in bidirectional mode.
301
+ *
302
+ * If automatic context gathering is enabled, the default implementation will fill out the form fields using standard DOM APIs.
303
+ * @param fields - An array of field objects with `id` and `value` properties.
304
+ */
305
+ input?: (fields: InputField[]) => void;
306
+ /**
307
+ * A callback for custom actions in bidirectional mode.
308
+ * @param action - The custom name of your action.
309
+ * @param payload - The payload defined for the custom action.
310
+ * @returns
311
+ */
312
+ custom?: (action: string, payload: unknown) => void;
313
+ };
314
+ /**
315
+ * Main Touchpoint creation properties object
316
+ */
317
+ export interface TouchpointConfiguration {
318
+ /**
319
+ * Connection information for the \@nlxai/core conversation handler
320
+ */
321
+ config: Config;
322
+ /**
323
+ * Optional window size for the chat window, defaults to `half`
324
+ */
325
+ windowSize?: WindowSize;
326
+ /**
327
+ * Optional color mode for the chat window, defaults to `dark`
328
+ */
329
+ colorMode?: ColorMode;
330
+ /**
331
+ * URL of icon used to display the brand in the chat header
332
+ */
333
+ brandIcon?: string;
334
+ /**
335
+ * URL of icon used on the launch icon in the bottom right when the experience is collapsed.
336
+ *
337
+ * When set to `false`, no launch button is shown at all. When not set or set to `true`, the default launch icon is rendered.
338
+ */
339
+ launchIcon?: string | boolean | CustomLaunchButton;
340
+ /**
341
+ * Specifies whether the user message has bubbles or not
342
+ */
343
+ userMessageBubble?: boolean;
344
+ /**
345
+ * Specifies whether the agent message has bubbles or not
346
+ */
347
+ agentMessageBubble?: boolean;
348
+ /**
349
+ * Enables chat mode, a classic chat experience with inline loaders and the chat history visible at all times.
350
+ */
351
+ chatMode?: boolean;
352
+ /**
353
+ * Optional theme object to override default theme values
354
+ */
355
+ theme?: Partial<Theme>;
356
+ /**
357
+ * Optional custom modality components to render in Touchpoint
358
+ */
359
+ customModalities?: Record<string, CustomModalityComponent<unknown>>;
360
+ /**
361
+ * Custom conversation init method. Defaults to sending the welcome intent
362
+ * @param handler - the conversation handler.
363
+ * @param context - the context object
364
+ */
365
+ initializeConversation?: InitializeConversation;
366
+ /**
367
+ * Controls the ways in which the user can communicate with the application. Defaults to `"text"`
368
+ */
369
+ input?: Input;
370
+ /**
371
+ * Context sent with the initial request.
372
+ */
373
+ initialContext?: Context;
374
+ /**
375
+ * Enables bidirectional mode of voice+. Will automatically set the bidirectional flag in the config.
376
+ *
377
+ */
378
+ bidirectional?: BidirectionalConfig;
379
+ }
380
+ /**
381
+ * During a Voice+ bidirectional conversation, you can indicate to the application the availability of
382
+ * custom commands that the user can invoke.
383
+ * @typeParam T - Commands can take a single parameter which will be generated from this schema.
384
+ */
385
+ export interface BidirectionalCustomCommand {
386
+ /**
387
+ * The name of the command, used to invoke it. Should be unique and descriptive in the context of the LLM.
388
+ */
389
+ action: string;
390
+ /**
391
+ * A short description of the command, used to help the LLM understand its purpose.
392
+ */
393
+ description?: string;
394
+ /**
395
+ * A JSON Schema that defines the structure of the command's input.
396
+ *
397
+ * Use descriptive names and `description` fields to give the underlying LLM plenty of context for
398
+ * it to generate reasonable parameters. Note that the LLM output will be validated (and transformed)
399
+ * with this schema, so you are guaranteed type safe inputs to your handler.
400
+ *
401
+ * Should follow the JSONSchema specification.
402
+ */
403
+ schema: any;
404
+ /**
405
+ * A handler that will be called with an argument matching the schema when the command is invoked.
406
+ */
407
+ handler: (value: any) => void;
408
+ }
package/lib/preview.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FC, ReactNode } from 'react';
2
- import { ColorMode, Theme } from './types';
2
+ import { ColorMode, Theme } from './interface';
3
3
  /**
4
4
  * @internal
5
5
  */