@aikaara/chat-sdk 0.3.0 → 0.4.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/dist/ui.d.ts CHANGED
@@ -1,3 +1,37 @@
1
+ /**
2
+ * `<aikaara-chat>` declarative web component — the framework-agnostic entry.
3
+ *
4
+ * Use any framework / template engine / static HTML:
5
+ *
6
+ * <aikaara-chat
7
+ * slug="bandhan-itr"
8
+ * user-id="33568"
9
+ * user-name="G. Iyer"
10
+ * user-token="eyJhbGc..."
11
+ * ></aikaara-chat>
12
+ *
13
+ * For dynamic tokens (refresh on expiry), set the `tokenGetter` property
14
+ * instead of the attribute:
15
+ *
16
+ * document.querySelector('aikaara-chat').tokenGetter = () => getJwt();
17
+ *
18
+ * The element calls `mountFromSlug()` internally — host code is reduced to
19
+ * a single tag.
20
+ */
21
+ export declare class AikaaraChat extends HTMLElement {
22
+ static get observedAttributes(): string[];
23
+ /** Set programmatically when the session token must be refreshed dynamically. */
24
+ tokenGetter?: () => string | Promise<string>;
25
+ private mounted;
26
+ private mountInflight;
27
+ connectedCallback(): void;
28
+ disconnectedCallback(): void;
29
+ attributeChangedCallback(): void;
30
+ /** Force a fresh /chatbuddy/auth-style refetch. */
31
+ refreshAuth(): Promise<void>;
32
+ private tryMount;
33
+ }
34
+
1
35
  export declare class AikaaraChatBubble extends HTMLElement {
2
36
  private shadow;
3
37
  constructor();
@@ -16,15 +50,21 @@ declare class AikaaraChatClient extends EventEmitter<ChatEvents> {
16
50
  private config;
17
51
  private mode;
18
52
  private uploadAdapter;
53
+ private historyAdapter;
19
54
  private tiledeskUnsubs;
20
55
  constructor(config: ChatClientConfig_2, opts?: {
21
56
  uploadAdapter?: UploadAdapter_2;
57
+ historyAdapter?: ConversationHistoryAdapter_2;
22
58
  });
23
59
  private usesAikaara;
24
60
  private usesTiledesk;
25
61
  private initTiledeskTransport;
26
62
  connect(): Promise<void>;
27
- sendMessage(content: string): Promise<void>;
63
+ private hydrateTiledeskHistory;
64
+ sendMessage(content: string, opts?: {
65
+ attributes?: Record<string, unknown>;
66
+ metadata?: Record<string, unknown>;
67
+ }): Promise<void>;
28
68
  /**
29
69
  * Upload a file via the configured UploadAdapter (client-side: file goes
30
70
  * to the tenant's own backend, never through Aikaara). Then publish the
@@ -88,17 +128,38 @@ export declare class AikaaraChatHeader extends HTMLElement {
88
128
  setStatus(status: string): void;
89
129
  }
90
130
 
131
+ /**
132
+ * Chat input box. Composes a textarea + send button + optional attach button.
133
+ *
134
+ * Events fired (composed:true so they cross shadow boundaries):
135
+ * - `send` `{ content: string }` — user pressed enter / clicked send
136
+ * - `file-pick` `{ file: File }` — user selected a file to upload
137
+ *
138
+ * Attributes:
139
+ * - `placeholder` placeholder text
140
+ * - `disable-attach` hides the attach button (set when host has no uploadAdapter)
141
+ * - `accept` forwarded to the hidden <input type="file">
142
+ * - `multiple` allow selecting multiple files
143
+ */
91
144
  export declare class AikaaraChatInput extends HTMLElement {
92
145
  private shadow;
93
146
  private textarea;
94
147
  private sendBtn;
148
+ private attachBtn;
149
+ private fileInput;
95
150
  private _disabled;
151
+ private _uploading;
96
152
  constructor();
153
+ static get observedAttributes(): string[];
97
154
  connectedCallback(): void;
98
155
  set disabled(val: boolean);
99
156
  get disabled(): boolean;
157
+ /** Toggle the attach button into a "uploading…" spinner state. */
158
+ set uploading(val: boolean);
159
+ get uploading(): boolean;
100
160
  focus(): void;
101
161
  clear(): void;
162
+ private refreshSendDisabled;
102
163
  private handleSend;
103
164
  private autoGrow;
104
165
  }
@@ -115,6 +176,7 @@ export declare class AikaaraChatWidget extends HTMLElement {
115
176
  configure(config: Partial<WidgetConfig>): void;
116
177
  private getConfig;
117
178
  setUploadAdapter(adapter: UploadAdapter): void;
179
+ setHistoryAdapter(adapter: ConversationHistoryAdapter): void;
118
180
  private render;
119
181
  private initController;
120
182
  sendUserEvent(eventKey: string, value?: Record<string, unknown>, source?: string): void;
@@ -176,6 +238,35 @@ export declare class AikaaraMessageList extends HTMLElement {
176
238
  private formatTime;
177
239
  }
178
240
 
241
+ export declare class AikaaraModalAction extends HTMLElement {
242
+ private shadow;
243
+ private data;
244
+ private dismissed;
245
+ constructor();
246
+ connectedCallback(): void;
247
+ setPayload(payload: ModalActionPayload): void;
248
+ dismiss(): void;
249
+ private handleOk;
250
+ private render;
251
+ }
252
+
253
+ export declare class AikaaraOptionList extends HTMLElement {
254
+ private shadow;
255
+ private data;
256
+ private selected;
257
+ constructor();
258
+ connectedCallback(): void;
259
+ setPayload(payload: OptionListPayload): void;
260
+ /** Read selected values — used by parent submit action to collect form state. */
261
+ getValues(): {
262
+ name: string;
263
+ values: string[];
264
+ type: string;
265
+ };
266
+ private toggle;
267
+ private render;
268
+ }
269
+
179
270
  export declare class AikaaraStreamingMessage extends HTMLElement {
180
271
  private shadow;
181
272
  private bubble;
@@ -185,14 +276,49 @@ export declare class AikaaraStreamingMessage extends HTMLElement {
185
276
  finalize(): void;
186
277
  }
187
278
 
279
+ export declare class AikaaraSubmitAction extends HTMLElement {
280
+ private shadow;
281
+ private data;
282
+ constructor();
283
+ connectedCallback(): void;
284
+ setPayload(payload: SubmitActionPayload): void;
285
+ private collectFormValues;
286
+ private handleClick;
287
+ private render;
288
+ }
289
+
188
290
  /**
189
- * Renders Tiledesk contentType=300 template payloads.
291
+ * Centered grey pill used for system / metadata messages
292
+ * (e.g. "Group created", "Assigned to Taxbuddy AI").
190
293
  *
191
- * Slot-based override system tenants ship a cloud-hosted bundle that
192
- * registers `<aikaara-template-{templateId}>` custom elements; this component
193
- * looks one up by `template-id` attribute and mounts it as a child. If no
194
- * tenant override is registered, a no-op fallback renders the inner message
195
- * (TaxBuddy-style nested envelope) so the chat at least shows readable text.
294
+ * Theming knobs (CSS custom properties on :host or any ancestor):
295
+ * --aikaara-system-pill-bg
296
+ * --aikaara-system-pill-color
297
+ * --aikaara-system-pill-radius
298
+ * --aikaara-system-pill-padding
299
+ * --aikaara-system-pill-font-size
300
+ * --aikaara-system-pill-font-weight
301
+ * --aikaara-system-pill-border
302
+ */
303
+ export declare class AikaaraSystemPill extends HTMLElement {
304
+ private shadow;
305
+ static get observedAttributes(): string[];
306
+ constructor();
307
+ connectedCallback(): void;
308
+ attributeChangedCallback(): void;
309
+ private render;
310
+ }
311
+
312
+ /**
313
+ * Renders the payload of a contentType=300 Tiledesk template. Walks the
314
+ * payload structure and mounts the right child component(s):
315
+ * - { type: 'checkbox' | 'radio' | 'button' } → <aikaara-option-list>
316
+ * - { type: 'submit' } → <aikaara-submit-action>
317
+ * - { type: 'modal' } / single object with `message + ok` → <aikaara-modal-action>
318
+ *
319
+ * Tenants can override per-template UI by registering a custom element named
320
+ * `aikaara-template-{templateId}` (or by templateId-based slot). The renderer
321
+ * checks for that first; if present, it delegates the whole payload there.
196
322
  */
197
323
  export declare class AikaaraTemplateRenderer extends HTMLElement {
198
324
  private shadow;
@@ -204,6 +330,8 @@ export declare class AikaaraTemplateRenderer extends HTMLElement {
204
330
  attributeChangedCallback(): void;
205
331
  setPayload(payload: unknown, innerMessage?: string): void;
206
332
  private render;
333
+ private mountField;
334
+ private mountModal;
207
335
  }
208
336
 
209
337
  export declare class AikaaraTypingIndicator extends HTMLElement {
@@ -254,6 +382,13 @@ declare interface ChatClientConfig extends ConnectionConfig {
254
382
  departmentId?: string;
255
383
  senderFullname?: string;
256
384
  };
385
+ /**
386
+ * Tenant-level defaults merged into the `action` object of every template
387
+ * postback (e.g. submit-action click). Useful for app-specific keys like
388
+ * `serviceType: 'ITR'` that the bot expects on every form submission.
389
+ * Per-submit values from the form take precedence over these defaults.
390
+ */
391
+ templateActionAttributes?: Record<string, unknown>;
257
392
  onMessage?: (message: Message) => void;
258
393
  onStatusChange?: (status: string) => void;
259
394
  onError?: (error: Error) => void;
@@ -287,6 +422,13 @@ declare interface ChatClientConfig_2 extends ConnectionConfig_2 {
287
422
  departmentId?: string;
288
423
  senderFullname?: string;
289
424
  };
425
+ /**
426
+ * Tenant-level defaults merged into the `action` object of every template
427
+ * postback (e.g. submit-action click). Useful for app-specific keys like
428
+ * `serviceType: 'ITR'` that the bot expects on every form submission.
429
+ * Per-submit values from the form take precedence over these defaults.
430
+ */
431
+ templateActionAttributes?: Record<string, unknown>;
290
432
  onMessage?: (message: Message_2) => void;
291
433
  onStatusChange?: (status: string) => void;
292
434
  onError?: (error: Error) => void;
@@ -357,6 +499,32 @@ declare type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 're
357
499
 
358
500
  declare type ConnectionState_2 = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
359
501
 
502
+ /**
503
+ * Pluggable adapter that hydrates prior conversation messages on connect.
504
+ * The SDK calls this once after MQTT subscribes so the user sees existing
505
+ * history before any new live messages arrive.
506
+ */
507
+ declare interface ConversationHistoryAdapter {
508
+ fetchMessages(conversationId: string, ctx: {
509
+ userId: string;
510
+ appId?: string;
511
+ projectId?: string;
512
+ }): Promise<TiledeskMessage[]>;
513
+ }
514
+
515
+ /**
516
+ * Pluggable adapter that hydrates prior conversation messages on connect.
517
+ * The SDK calls this once after MQTT subscribes so the user sees existing
518
+ * history before any new live messages arrive.
519
+ */
520
+ declare interface ConversationHistoryAdapter_2 {
521
+ fetchMessages(conversationId: string, ctx: {
522
+ userId: string;
523
+ appId?: string;
524
+ projectId?: string;
525
+ }): Promise<TiledeskMessage_2[]>;
526
+ }
527
+
360
528
  declare interface EditEntityAction {
361
529
  action: 'edit_entity';
362
530
  entity_type: string;
@@ -430,16 +598,103 @@ declare interface Message_2 {
430
598
  }>;
431
599
  }
432
600
 
601
+ /**
602
+ * Modal-style action dialog. Bandhan uses these for blocking confirms
603
+ * (e.g. "Please tick the checkbox to proceed" with an Ok button).
604
+ *
605
+ * Payload shape (flexible — matches several bandhan modal templates):
606
+ * { message: 'Please tick…', okLabel?: 'Ok', cancelLabel?: 'Cancel',
607
+ * action?: { message, requestType } }
608
+ *
609
+ * On Ok the component fires `template-action` with the configured message
610
+ * (or the modal text itself) and dismisses. Cancel just dismisses.
611
+ *
612
+ * Theming:
613
+ * --aikaara-modal-overlay-bg, --aikaara-modal-bg, --aikaara-modal-color,
614
+ * --aikaara-modal-radius, --aikaara-modal-padding, --aikaara-modal-shadow,
615
+ * --aikaara-modal-button-bg, --aikaara-modal-button-color,
616
+ * --aikaara-modal-button-radius, --aikaara-modal-cancel-color
617
+ */
618
+ declare interface ModalActionPayload {
619
+ message: string;
620
+ okLabel?: string;
621
+ cancelLabel?: string;
622
+ action?: {
623
+ message?: string;
624
+ requestType?: string;
625
+ };
626
+ }
627
+
433
628
  declare interface NavigateAction {
434
629
  navigate_to: string;
435
630
  }
436
631
 
632
+ /**
633
+ * Rendering for contentType=300 form fields with `type: 'checkbox' | 'radio' | 'button'`.
634
+ *
635
+ * Bandhan envelope:
636
+ * { data: { name: 'IncomeSources', title: 'Income Sources',
637
+ * options: [{ label, value }, ...] },
638
+ * type: 'checkbox' | 'radio' | 'button' }
639
+ *
640
+ * Emits a `template-action` CustomEvent on selection. For `button` type the
641
+ * action fires immediately on click. For `checkbox`/`radio` the parent submit
642
+ * action collects values via `getValues()`.
643
+ *
644
+ * Theming:
645
+ * --aikaara-option-bg, --aikaara-option-color, --aikaara-option-border,
646
+ * --aikaara-option-radius, --aikaara-option-padding, --aikaara-option-gap,
647
+ * --aikaara-option-selected-bg, --aikaara-option-selected-color,
648
+ * --aikaara-option-selected-border, --aikaara-option-title-color,
649
+ * --aikaara-option-title-font-size, --aikaara-option-title-font-weight
650
+ */
651
+ declare interface OptionItem {
652
+ label: string;
653
+ value: string;
654
+ }
655
+
656
+ declare interface OptionListPayload {
657
+ name: string;
658
+ title?: string;
659
+ options: OptionItem[];
660
+ type: 'checkbox' | 'radio' | 'button';
661
+ }
662
+
437
663
  export declare function registerComponents(): void;
438
664
 
439
665
  declare interface SaveEntityAction {
440
666
  action: 'save_entity';
441
667
  }
442
668
 
669
+ /**
670
+ * Primary CTA submit button for contentType=300 forms.
671
+ *
672
+ * Bandhan envelope:
673
+ * { data: { name: 'Confirm Income Sources', type: 'submit',
674
+ * action: { message, formAction, requestType } },
675
+ * type: 'submit' }
676
+ *
677
+ * On click, collects values from sibling AikaaraOptionList components
678
+ * (queried by walking up to the parent template renderer's children) and
679
+ * fires `template-action` with the action message + collected attributes.
680
+ *
681
+ * Theming:
682
+ * --aikaara-submit-bg, --aikaara-submit-color, --aikaara-submit-border,
683
+ * --aikaara-submit-radius, --aikaara-submit-padding,
684
+ * --aikaara-submit-hover-bg, --aikaara-submit-disabled-opacity,
685
+ * --aikaara-submit-font-size, --aikaara-submit-font-weight
686
+ */
687
+ declare interface SubmitActionPayload {
688
+ name: string;
689
+ action: {
690
+ message: string;
691
+ formAction?: string;
692
+ requestType?: string;
693
+ };
694
+ /** id of the bot prompt that triggered this form, stamped on the postback */
695
+ messageId?: string;
696
+ }
697
+
443
698
  declare interface TemplateMessageEvent {
444
699
  messageId: string;
445
700
  conversationId: string;
@@ -482,6 +737,42 @@ declare interface TiledeskFileTemplateConfig_2 {
482
737
  isDeepLink?: boolean;
483
738
  }
484
739
 
740
+ declare interface TiledeskMessage {
741
+ text?: string;
742
+ type?: string;
743
+ sender?: string;
744
+ senderFullname?: string;
745
+ sender_fullname?: string;
746
+ recipient?: string;
747
+ recipient_fullname?: string;
748
+ channel_type?: string;
749
+ timestamp?: number;
750
+ app_id?: string;
751
+ message_id?: string;
752
+ status?: number;
753
+ attributes?: Record<string, unknown>;
754
+ metadata?: Record<string, unknown>;
755
+ [key: string]: unknown;
756
+ }
757
+
758
+ declare interface TiledeskMessage_2 {
759
+ text?: string;
760
+ type?: string;
761
+ sender?: string;
762
+ senderFullname?: string;
763
+ sender_fullname?: string;
764
+ recipient?: string;
765
+ recipient_fullname?: string;
766
+ channel_type?: string;
767
+ timestamp?: number;
768
+ app_id?: string;
769
+ message_id?: string;
770
+ status?: number;
771
+ attributes?: Record<string, unknown>;
772
+ metadata?: Record<string, unknown>;
773
+ [key: string]: unknown;
774
+ }
775
+
485
776
  declare interface TiledeskMessageDefaults {
486
777
  channelType?: string;
487
778
  channel?: string;
@@ -546,6 +837,20 @@ declare interface TiledeskTransportConfig {
546
837
  fileTemplate?: TiledeskFileTemplateConfig;
547
838
  recipientFullnameResolver?: (conversationId: string) => string | undefined;
548
839
  senderFullname?: string;
840
+ /**
841
+ * If true (default), AikaaraChatClient publishes a `CHAT_INITIATED` event
842
+ * to the conversation's outbound topic on first connect — but only when
843
+ * the conversation history is empty (so reload of an in-flight chat
844
+ * doesn't replay the kickoff).
845
+ */
846
+ autoInitiateOnEmpty?: boolean;
847
+ /** Extra attributes merged into the auto-fired CHAT_INITIATED envelope. */
848
+ chatInitiatedAttributes?: Record<string, unknown>;
849
+ /**
850
+ * Log decoded MQTT frames to console as they're sent/received.
851
+ * Off by default — set true for debugging Tiledesk wire traffic.
852
+ */
853
+ debug?: boolean;
549
854
  }
550
855
 
551
856
  declare interface TiledeskTransportConfig_2 {
@@ -576,6 +881,20 @@ declare interface TiledeskTransportConfig_2 {
576
881
  fileTemplate?: TiledeskFileTemplateConfig_2;
577
882
  recipientFullnameResolver?: (conversationId: string) => string | undefined;
578
883
  senderFullname?: string;
884
+ /**
885
+ * If true (default), AikaaraChatClient publishes a `CHAT_INITIATED` event
886
+ * to the conversation's outbound topic on first connect — but only when
887
+ * the conversation history is empty (so reload of an in-flight chat
888
+ * doesn't replay the kickoff).
889
+ */
890
+ autoInitiateOnEmpty?: boolean;
891
+ /** Extra attributes merged into the auto-fired CHAT_INITIATED envelope. */
892
+ chatInitiatedAttributes?: Record<string, unknown>;
893
+ /**
894
+ * Log decoded MQTT frames to console as they're sent/received.
895
+ * Off by default — set true for debugging Tiledesk wire traffic.
896
+ */
897
+ debug?: boolean;
579
898
  }
580
899
 
581
900
  declare interface ToolCall {
@@ -675,6 +994,14 @@ declare interface WidgetConfig extends ChatClientConfig {
675
994
  bubbleText?: string;
676
995
  bubbleIcon?: string;
677
996
  uploadAdapter?: UploadAdapter;
997
+ historyAdapter?: ConversationHistoryAdapter;
998
+ /**
999
+ * Display mode:
1000
+ * - `popup` (default): floating bubble in the corner, click to open panel.
1001
+ * - `embed`: render the chat panel inline at the host element's location,
1002
+ * filling its container. Bubble + open/close animation are skipped.
1003
+ */
1004
+ display?: 'popup' | 'embed';
678
1005
  }
679
1006
 
680
1007
  export { }