@nlxai/core 1.1.8-alpha.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/lib/index.d.ts ADDED
@@ -0,0 +1,755 @@
1
+ /**
2
+ * Package version
3
+ */
4
+ export declare const version: string;
5
+ /**
6
+ * [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
7
+ */
8
+ export type Context = Record<string, any>;
9
+ /**
10
+ * Values to fill an intent's [attached slots](https://docs.studio.nlx.ai/intents/documentation-intents/intents-attached-slots).
11
+ *
12
+ * An array of `SlotValue` objects is equivalent to a {@link SlotsRecord}.
13
+ */
14
+ export interface SlotValue {
15
+ /**
16
+ * The attached slot's name
17
+ */
18
+ slotId: string;
19
+ /**
20
+ * Usually this will be a discrete value matching the slots's [type](https://docs.studio.nlx.ai/slots/documentation-slots/slots-values#system-slots).
21
+ * for custom slots, this can optionally be the value's ID.
22
+ */
23
+ value: any;
24
+ }
25
+ /**
26
+ * Response type
27
+ */
28
+ export declare enum ResponseType {
29
+ /**
30
+ * Response from the application
31
+ */
32
+ Application = "bot",
33
+ /**
34
+ * Response from the user
35
+ */
36
+ User = "user",
37
+ /**
38
+ * Generic failure (cannot be attributed to the application)
39
+ */
40
+ Failure = "failure"
41
+ }
42
+ /**
43
+ * Values to fill an intent's [attached slots](https://docs.studio.nlx.ai/intents/documentation-intents/intents-attached-slots).
44
+ *
45
+ * `SlotRecord` Keys are the attached slot's name
46
+ *
47
+ * `SlotRecord` Values are usually a discrete value matching the slots's [type](https://docs.studio.nlx.ai/slots/documentation-slots/slots-values#system-slots).
48
+ * for custom slots, this can optionally be the value's ID.
49
+ *
50
+ * A `SlotsRecord` is equivalent to an array of {@link SlotValue} objects.
51
+ */
52
+ export type SlotsRecord = Record<string, any>;
53
+ /**
54
+ * Values to fill an intent's [attached slots](https://docs.studio.nlx.ai/intents/documentation-intents/intents-attached-slots).
55
+ *
56
+ * Supports either a {@link SlotsRecord} or an array of {@link SlotValue} objects
57
+ */
58
+ export type SlotsRecordOrArray = SlotsRecord | SlotValue[];
59
+ /**
60
+ * A message from the application
61
+ *
62
+ * See also:
63
+ * - {@link UserResponse}
64
+ * - {@link FailureMessage}
65
+ * - {@link Response}
66
+ */
67
+ export interface ApplicationResponse {
68
+ /**
69
+ * The application response type
70
+ */
71
+ type: ResponseType.Application;
72
+ /**
73
+ * When the response was received
74
+ */
75
+ receivedAt: Time;
76
+ /**
77
+ * The payload of the response
78
+ */
79
+ payload: ApplicationResponsePayload;
80
+ }
81
+ /**
82
+ * The payload of the application response
83
+ */
84
+ export interface ApplicationResponsePayload {
85
+ /**
86
+ * If there isn't some interaction by this time, the conversation will expire.
87
+ */
88
+ expirationTimestamp?: number;
89
+ /**
90
+ * The active conversation ID. If not set, a new conversation will be started.
91
+ */
92
+ conversationId?: string;
93
+ /**
94
+ * Any messages from the application.
95
+ */
96
+ messages: ApplicationMessage[];
97
+ /**
98
+ * Global state about the current conversation
99
+ * as well as whether the client should poll for more application responses.
100
+ */
101
+ metadata?: ApplicationResponseMetadata;
102
+ /**
103
+ * If configured, the [node's payload.](See: https://docs.studio.nlx.ai/intentflows/documentation-flows/flows-build-mode/advanced-messaging-+-functionality#add-functionality)
104
+ */
105
+ payload?: string;
106
+ /**
107
+ * If configured, the node's modalities and their payloads.
108
+ */
109
+ modalities?: ModalityPayloads;
110
+ /**
111
+ * If the node is set to send context, the whole context associated with the conversation.
112
+ */
113
+ context?: Context;
114
+ }
115
+ /**
116
+ * Payloads for modalities as a key-value pair by modality name
117
+ */
118
+ export type ModalityPayloads = Record<string, any>;
119
+ /**
120
+ * Global state about the current conversation
121
+ * as well as whether the client should poll for more application responses.
122
+ */
123
+ export interface ApplicationResponseMetadata {
124
+ /**
125
+ * The conversation's intent
126
+ */
127
+ intentId?: string;
128
+ /**
129
+ * Whether the current conversation has been marked as incomprehension.
130
+ */
131
+ escalation?: boolean;
132
+ /**
133
+ * Whether the current conversation has been marked frustrated
134
+ */
135
+ frustration?: boolean;
136
+ /**
137
+ * Whether the current conversation has been marked as incomprehension.
138
+ */
139
+ incomprehension?: boolean;
140
+ /**
141
+ * Upload URL's
142
+ */
143
+ uploadUrls: UploadUrl[];
144
+ /**
145
+ * Whether the client should poll for more application responses.
146
+ */
147
+ hasPendingDataRequest?: boolean;
148
+ /**
149
+ * Knowledge base sources
150
+ */
151
+ sources?: KnowledgeBaseResponseSource[];
152
+ }
153
+ /**
154
+ * Response for knowlege base sources
155
+ */
156
+ export interface KnowledgeBaseResponseSource {
157
+ /**
158
+ * File name
159
+ */
160
+ fileName?: string;
161
+ /**
162
+ * Page number
163
+ */
164
+ pageNumber?: number;
165
+ /**
166
+ * Content
167
+ */
168
+ content?: string;
169
+ /**
170
+ * Metadata
171
+ */
172
+ metadata?: Record<string, unknown>;
173
+ /**
174
+ * Presigned URL for direct retrieval
175
+ */
176
+ presignedUrl?: string;
177
+ }
178
+ /**
179
+ * Metadata for the individual application message
180
+ * as well as whether the client should poll for more application responses.
181
+ */
182
+ export interface ApplicationMessageMetadata {
183
+ /**
184
+ * The message node's intent
185
+ */
186
+ intentId?: string;
187
+ }
188
+ /**
189
+ * A message from the application, as well as any choices the user can make.
190
+ */
191
+ export interface ApplicationMessage {
192
+ /**
193
+ * A unique identifier for the message.
194
+ */
195
+ messageId?: string;
196
+ /**
197
+ * The node id that this message is associated with.
198
+ * This is must be sent with a choice when the user is changing a previously sent choice.
199
+ */
200
+ nodeId?: string;
201
+ /**
202
+ * The body of the message. Show this to the user.
203
+ */
204
+ text: string;
205
+ /**
206
+ * A selection of choices to show to the user. They may choose one of them.
207
+ */
208
+ choices: Choice[];
209
+ /**
210
+ * Metadata
211
+ */
212
+ metadata?: ApplicationMessageMetadata;
213
+ /**
214
+ * After a choice has been made by the user, this will be updated locally to the selected choice id.
215
+ * This field is set locally and does not come from the application.
216
+ */
217
+ selectedChoiceId?: string;
218
+ }
219
+ /**
220
+ * The upload destination for handling conversing with files
221
+ */
222
+ export interface UploadUrl {
223
+ /**
224
+ * The URL of the upload
225
+ */
226
+ url: string;
227
+ /**
228
+ * The ID of the upload
229
+ */
230
+ uploadId: string;
231
+ }
232
+ /**
233
+ * A choices to show to the user.
234
+ */
235
+ export interface Choice {
236
+ /**
237
+ * `choiceId` is used by `sendChoice` to let the user choose this choice.
238
+ */
239
+ choiceId: string;
240
+ /**
241
+ * The text of the choice
242
+ */
243
+ choiceText: string;
244
+ /**
245
+ * An optional, schemaless payload for the choice.
246
+ */
247
+ choicePayload?: any;
248
+ }
249
+ /**
250
+ * A message from the user
251
+ *
252
+ * See also:
253
+ * - {@link ApplicationResponse}
254
+ * - {@link FailureMessage}
255
+ * - {@link Response}
256
+ *
257
+ */
258
+ export interface UserResponse {
259
+ /**
260
+ * The user response type
261
+ */
262
+ type: ResponseType.User;
263
+ /**
264
+ * When the response was received
265
+ */
266
+ receivedAt: Time;
267
+ /**
268
+ * The payload of the response
269
+ */
270
+ payload: UserResponsePayload;
271
+ }
272
+ /**
273
+ * The payload of the user response
274
+ */
275
+ export type UserResponsePayload = {
276
+ /**
277
+ * Set when `sendText` is called.
278
+ */
279
+ type: "text";
280
+ /**
281
+ * The user's message
282
+ */
283
+ text: string;
284
+ /**
285
+ * [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
286
+ */
287
+ context?: Context;
288
+ } | {
289
+ /**
290
+ * Set when `sendChoice` is called.
291
+ */
292
+ type: "choice";
293
+ /**
294
+ * The `choiceId` passed to `sendChoice`
295
+ * Correlates to a `choiceId` in the {@link ApplicationResponse}'s `.payload.messages[].choices[].choiceId` fields
296
+ */
297
+ choiceId: string;
298
+ /**
299
+ * [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
300
+ */
301
+ context?: Context;
302
+ } | ({
303
+ /**
304
+ * Set when `sendStructured` is called.
305
+ */
306
+ type: "structured";
307
+ /**
308
+ * [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
309
+ */
310
+ context?: Context;
311
+ } & StructuredRequest);
312
+ /**
313
+ * A failure message is received when the NLX api is unreachable, or sends an unparsable response.
314
+ */
315
+ export interface FailureMessage {
316
+ /**
317
+ * The failure response type
318
+ */
319
+ type: ResponseType.Failure;
320
+ /**
321
+ * The payload only includes an error message.
322
+ */
323
+ payload: {
324
+ /**
325
+ * The error message is either the default, or the `failureMessage` set in the {@link Config}.
326
+ */
327
+ text: string;
328
+ };
329
+ /**
330
+ * When the failure occurred.
331
+ */
332
+ receivedAt: Time;
333
+ }
334
+ /**
335
+ * A response from the application or the user.
336
+ */
337
+ export type Response = ApplicationResponse | UserResponse | FailureMessage;
338
+ /**
339
+ * The time value in milliseconds since midnight, January 1, 1970 UTC.
340
+ */
341
+ export type Time = number;
342
+ /**
343
+ * @hidden
344
+ */
345
+ export type Environment = "production" | "development";
346
+ /**
347
+ * The configuration to create a conversation.
348
+ */
349
+ export interface Config {
350
+ /**
351
+ * Fetch this from the application's Deployment page.
352
+ */
353
+ applicationUrl?: string;
354
+ /**
355
+ * Headers to forward to the NLX API.
356
+ */
357
+ headers: Record<string, string> & {
358
+ /**
359
+ * The `nlx-api-key` is required. Fetch this from the application's Deployment page.
360
+ */
361
+ "nlx-api-key": string;
362
+ };
363
+ /**
364
+ * Set `conversationId` to continue an existing conversation. If not set, a new conversation will be started.
365
+ */
366
+ conversationId?: string;
367
+ /**
368
+ * Setting the `userID` allows it to be searchable in application history, as well as usable via `{System.userId}` in the intent.
369
+ */
370
+ userId?: string;
371
+ /**
372
+ * When `responses` is set, initialize the chatHandler with historical messages.
373
+ */
374
+ responses?: Response[];
375
+ /**
376
+ * When set, this overrides the default failure message ("We encountered an issue. Please try again soon.").
377
+ */
378
+ failureMessage?: string;
379
+ /**
380
+ * The language code to use for the application. In the browser this can be fetched with `navigator.language`.
381
+ * If you don't have translations, hard-code this to the language code you support.
382
+ */
383
+ languageCode: LanguageCode;
384
+ /**
385
+ * @hidden
386
+ * this should only be used for NLX internal testing.
387
+ */
388
+ environment?: Environment;
389
+ /**
390
+ * Specifies whether the conversation is bidirectional
391
+ */
392
+ bidirectional?: boolean;
393
+ /**
394
+ * Experimental settings
395
+ */
396
+ experimental?: {
397
+ /**
398
+ * Simulate alternative channel types
399
+ */
400
+ channelType?: string;
401
+ /**
402
+ * Prevent the `languageCode` parameter to be appended to the application URL - used in special deployment environments such as the sandbox chat inside Dialog Studio
403
+ */
404
+ completeApplicationUrl?: boolean;
405
+ };
406
+ }
407
+ /**
408
+ * The body of `sendStructured`
409
+ * Includes a combination of choice, slots, and intent in one request.
410
+ */
411
+ export interface StructuredRequest {
412
+ /**
413
+ * The `choiceId` is in the {@link ApplicationResponse}'s `.payload.messages[].choices[].choiceId` fields
414
+ */
415
+ choiceId?: string;
416
+ /**
417
+ * Required if you want to change a choice that's already been sent.
418
+ * The `nodeId` can be found in the corresponding {@link ApplicationMessage}.
419
+ */
420
+ nodeId?: string;
421
+ /**
422
+ * The intent to trigger. The `intentId` is the name under the application's _Intents_.
423
+ * @deprecated use `flowId` instead.
424
+ */
425
+ intentId?: string;
426
+ /**
427
+ * The flow to trigger. The `flowId` is the name under the application's _Flows_.
428
+ */
429
+ flowId?: string;
430
+ /**
431
+ * The slots to populate
432
+ */
433
+ slots?: SlotsRecordOrArray;
434
+ /**
435
+ * Upload ID
436
+ */
437
+ uploadIds?: string[];
438
+ /**
439
+ * Upload utterance
440
+ */
441
+ utterance?: string;
442
+ /**
443
+ * @hidden
444
+ * This is used internally to indicate that the client is polling the application for more data.
445
+ */
446
+ poll?: boolean;
447
+ }
448
+ /**
449
+ * Normalized structured request with a single way to represent slots
450
+ */
451
+ export type NormalizedStructuredRequest = StructuredRequest & {
452
+ /**
453
+ * Only array-form slots are allowed for the purposes of sending to the backend
454
+ */
455
+ slots?: SlotValue[];
456
+ };
457
+ /**
458
+ * The request data actually sent to the application, slightly different from {@link UserResponsePayload}, which includes some UI-specific information
459
+ */
460
+ export interface ApplicationRequest {
461
+ /**
462
+ * The current conversation ID
463
+ */
464
+ conversationId?: string;
465
+ /**
466
+ * The current user ID
467
+ */
468
+ userId?: string;
469
+ /**
470
+ * Request context, if applicable
471
+ */
472
+ context?: Context;
473
+ /**
474
+ * Main request
475
+ */
476
+ request: {
477
+ /**
478
+ * Unstructured request
479
+ */
480
+ unstructured?: {
481
+ /**
482
+ * Request body text
483
+ */
484
+ text: string;
485
+ };
486
+ /**
487
+ * Structured request
488
+ */
489
+ structured?: StructuredRequest & {
490
+ /**
491
+ * Only array-form slots are allowed for the purposes of sending to the backend
492
+ */
493
+ slots?: SlotValue[];
494
+ };
495
+ };
496
+ }
497
+ /**
498
+ * Credentials to connect to a Voice channel
499
+ */
500
+ export interface VoiceCredentials {
501
+ /**
502
+ * Voice Connection URL
503
+ */
504
+ url: string;
505
+ /**
506
+ * Voice room name
507
+ */
508
+ roomName: string;
509
+ /**
510
+ * Voice token
511
+ */
512
+ token: string;
513
+ /**
514
+ * Voice participant name
515
+ */
516
+ participantName: string;
517
+ }
518
+ /**
519
+ * Helps link the choice to the specific message in the conversation.
520
+ */
521
+ export interface ChoiceRequestMetadata {
522
+ /**
523
+ * The index of the {@link Response} associated with this choice.
524
+ * Setting this ensures that local state's `selectedChoiceId` on the corresponding {@link ApplicationResponse} is set.
525
+ * It is not sent to the application.
526
+ */
527
+ responseIndex?: number;
528
+ /**
529
+ * The index of the {@link ApplicationMessage} associated with this choice.
530
+ * Setting this ensures that local state's `selectedChoiceId` on the corresponding {@link ApplicationResponse} is set.
531
+ * It is not sent to the application.
532
+ */
533
+ messageIndex?: number;
534
+ /**
535
+ * Required if you want to change a choice that's already been sent.
536
+ * The `nodeId` can be found in the corresponding {@link ApplicationMessage}.
537
+ */
538
+ nodeId?: string;
539
+ /**
540
+ * Intent ID, used for sending to the NLU to allow it to double-check
541
+ */
542
+ intentId?: string;
543
+ }
544
+ /**
545
+ * Language code named for clarity, may restrict it to a finite list
546
+ */
547
+ export type LanguageCode = string;
548
+ /**
549
+ * Instead of sending a request to the application, handle it in a custom fashion
550
+ * @param applicationRequest - The {@link ApplicationRequest} that is being overridden
551
+ * @param appendResponse - A method to append the {@link ApplicationResponsePayload} to the message history
552
+ */
553
+ export type RequestOverride = (applicationRequest: ApplicationRequest, appendResponse: (res: ApplicationResponsePayload) => void) => void;
554
+ /**
555
+ * Voice+ context, type to be defined
556
+ */
557
+ export type VoicePlusContext = any;
558
+ /**
559
+ * Messages sent to the Voice+ socket
560
+ */
561
+ export interface VoicePlusMessage {
562
+ /**
563
+ * Voice+ context
564
+ */
565
+ context: VoicePlusContext;
566
+ }
567
+ /**
568
+ * Handler events
569
+ */
570
+ export type ConversationHandlerEvent = "voicePlusCommand";
571
+ /**
572
+ * Dictionary of handler methods per event
573
+ */
574
+ export interface EventHandlers {
575
+ /**
576
+ * Voice+ command event handler
577
+ */
578
+ voicePlusCommand: (payload: any) => void;
579
+ }
580
+ /**
581
+ * A bundle of functions to interact with a conversation, created by {@link createConversation}.
582
+ */
583
+ export interface ConversationHandler {
584
+ /**
585
+ * Send user's message
586
+ * @param text - the user's message
587
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
588
+ */
589
+ sendText: (text: string, context?: Context) => void;
590
+ /**
591
+ * Send [slots](https://docs.studio.nlx.ai/workspacesettings/introduction-to-settings) to the application.
592
+ * @param slots - The slots to populate
593
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
594
+ */
595
+ sendSlots: (slots: SlotsRecordOrArray, context?: Context) => void;
596
+ /**
597
+ * Respond to [a choice](https://docs.studio.nlx.ai/intentflows/documentation-flows/flows-build-mode/nodes#user-choice) from the application.
598
+ * @param choidId - The `choiceId` is in the {@link ApplicationResponse}'s `.payload.messages[].choices[].choiceId` fields
599
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
600
+ * @param metadata - links the choice to the specific message and node in the conversation.
601
+ */
602
+ sendChoice: (choiceId: string, context?: Context, metadata?: ChoiceRequestMetadata) => void;
603
+ /**
604
+ * Trigger the welcome flow. This should be done when the user starts interacting with the chat.
605
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
606
+ */
607
+ sendWelcomeFlow: (context?: Context) => void;
608
+ /**
609
+ * Trigger the welcome [intent](https://docs.studio.nlx.ai/intents/introduction-to-intents). This should be done when the user starts interacting with the chat.
610
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
611
+ * @deprecated use `sendWelcomeFlow` instead
612
+ */
613
+ sendWelcomeIntent: (context?: Context) => void;
614
+ /**
615
+ * Trigger a specific flow.
616
+ * @param flowId - the flow to trigger. The id is the name under the application's _Intents_.
617
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
618
+ */
619
+ sendFlow: (flowId: string, context?: Context) => void;
620
+ /**
621
+ * Trigger a specific [intent](https://docs.studio.nlx.ai/intents/introduction-to-intents).
622
+ * @param intentId - the intent to trigger. The id is the name under the application's _Intents_.
623
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
624
+ * @deprecated use `sendFlow` instead
625
+ */
626
+ sendIntent: (intentId: string, context?: Context) => void;
627
+ /**
628
+ * Send context without sending a message
629
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
630
+ */
631
+ sendContext: (context: Context) => Promise<void>;
632
+ /**
633
+ * Obtain Voice credentials to run the experience in voice.
634
+ * @internal
635
+ * @returns Voice credentials in promise form
636
+ */
637
+ getVoiceCredentials: (context?: Context) => Promise<VoiceCredentials>;
638
+ /**
639
+ * Send a combination of choice, slots, and intent in one request.
640
+ * @param request -
641
+ * @param context - [Context](https://docs.studio.nlx.ai/workspacesettings/documentation-settings/settings-context-attributes) for usage later in the intent.
642
+ */
643
+ sendStructured: (request: StructuredRequest, context?: Context) => void;
644
+ /**
645
+ * Subscribe a callback to the conversation. On subscribe, the subscriber will receive all of the Responses that the conversation has already received.
646
+ * @param subscriber - The callback to subscribe
647
+ */
648
+ subscribe: (subscriber: Subscriber) => () => void;
649
+ /**
650
+ * Unsubscribe a callback from the conversation.
651
+ * @param subscriber - The callback to unsubscribe
652
+ */
653
+ unsubscribe: (subscriber: Subscriber) => void;
654
+ /**
655
+ * Unsubscribe all callback from the conversation.
656
+ */
657
+ unsubscribeAll: () => void;
658
+ /**
659
+ * Get the current conversation ID if it's set, or undefined if there is no conversation.
660
+ */
661
+ currentConversationId: () => string | undefined;
662
+ /**
663
+ * Get the current language code
664
+ */
665
+ currentLanguageCode: () => LanguageCode;
666
+ /**
667
+ * Set the language code
668
+ */
669
+ setLanguageCode: (languageCode: LanguageCode) => void;
670
+ /**
671
+ * Forces a new conversation. If `clearResponses` is set to true, will also clear historical responses passed to subscribers.
672
+ * Retains all existing subscribers.
673
+ */
674
+ reset: (options?: {
675
+ /**
676
+ * If set to true, will clear historical responses passed to subscribers.
677
+ */
678
+ clearResponses?: boolean;
679
+ }) => void;
680
+ /**
681
+ * Removes all subscribers and, if using websockets, closes the connection.
682
+ */
683
+ destroy: () => void;
684
+ /**
685
+ * Optional {@link RequestOverride} function used to bypass the application request and handle them in a custom fashion
686
+ */
687
+ setRequestOverride: (override: RequestOverride | undefined) => void;
688
+ /**
689
+ * Add a listener to one of the handler's custom events
690
+ */
691
+ addEventListener: (event: ConversationHandlerEvent, handler: EventHandlers[ConversationHandlerEvent]) => void;
692
+ /**
693
+ * Remove a listener to one of the handler's custom events
694
+ */
695
+ removeEventListener: (event: ConversationHandlerEvent, handler: EventHandlers[ConversationHandlerEvent]) => void;
696
+ /**
697
+ * Send voicePlus message
698
+ */
699
+ sendVoicePlusContext: (context: VoicePlusContext) => void;
700
+ }
701
+ /**
702
+ * The callback function for listening to all responses.
703
+ */
704
+ export type Subscriber = (response: Response[], newResponse?: Response) => void;
705
+ /**
706
+ * Helper method to decide when a new {@link Config} requires creating a new {@link ConversationHandler} or whether the old `Config`'s
707
+ * `ConversationHandler` can be used.
708
+ *
709
+ * The order of configs doesn't matter.
710
+ * @param config1 -
711
+ * @param config2 -
712
+ * @returns true if `createConversation` should be called again
713
+ */
714
+ export declare const shouldReinitialize: (config1: Config, config2: Config) => boolean;
715
+ /**
716
+ * Check whether a configuration is value.
717
+ * @param config - Chat configuration
718
+ * @returns isValid - Whether the configuration is valid
719
+ */
720
+ export declare const isConfigValid: (config: Config) => boolean;
721
+ /**
722
+ * Call this to create a conversation handler.
723
+ * @param config -
724
+ * @returns The {@link ConversationHandler} is a bundle of functions to interact with the conversation.
725
+ */
726
+ export declare function createConversation(config: Config): ConversationHandler;
727
+ /**
728
+ * Get current expiration timestamp from the current list of reponses
729
+ * @param responses - the current list of user and application responses (first argument in the subscribe callback)
730
+ * @returns an expiration timestamp in Unix Epoch (`new Date().getTime()`), or `null` if this is not known (typically occurs if the application has not responded yet)
731
+ */
732
+ export declare const getCurrentExpirationTimestamp: (responses: Response[]) => number | null;
733
+ /**
734
+ * This package is intentionally designed with a subscription-based API as opposed to a promise-based one where each message corresponds to a single application response, available asynchronously.
735
+ *
736
+ * If you need a promise-based wrapper, you can use the `promisify` helper available in the package:
737
+ * @example
738
+ * ```typescript
739
+ * import { createConversation, promisify } from "@nlxai/core";
740
+ *
741
+ * const convo = createConversation(config);
742
+ *
743
+ * const sendTextWrapped = promisify(convo.sendText, convo);
744
+ *
745
+ * sendTextWrapped("Hello").then((response) => {
746
+ * console.log(response);
747
+ * });
748
+ * ```
749
+ * @typeParam T - the type of the function's params, e.g. for `sendText` it's `text: string, context?: Context`
750
+ * @param fn - the function to wrap (e.g. `convo.sendText`, `convo.sendChoice`, etc.)
751
+ * @param convo - the `ConversationHandler` (from {@link createConversation})
752
+ * @param timeout - the timeout in milliseconds
753
+ * @returns A promise-wrapped version of the function. The function, when called, returns a promise that resolves to the Conversation's next response.
754
+ */
755
+ export declare function promisify<T>(fn: (payload: T) => void, convo: ConversationHandler, timeout?: number): (payload: T) => Promise<Response | null>;