@aikaara/chat-sdk 0.3.0 → 0.3.3

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
@@ -16,15 +16,21 @@ declare class AikaaraChatClient extends EventEmitter<ChatEvents> {
16
16
  private config;
17
17
  private mode;
18
18
  private uploadAdapter;
19
+ private historyAdapter;
19
20
  private tiledeskUnsubs;
20
21
  constructor(config: ChatClientConfig_2, opts?: {
21
22
  uploadAdapter?: UploadAdapter_2;
23
+ historyAdapter?: ConversationHistoryAdapter_2;
22
24
  });
23
25
  private usesAikaara;
24
26
  private usesTiledesk;
25
27
  private initTiledeskTransport;
26
28
  connect(): Promise<void>;
27
- sendMessage(content: string): Promise<void>;
29
+ private hydrateTiledeskHistory;
30
+ sendMessage(content: string, opts?: {
31
+ attributes?: Record<string, unknown>;
32
+ metadata?: Record<string, unknown>;
33
+ }): Promise<void>;
28
34
  /**
29
35
  * Upload a file via the configured UploadAdapter (client-side: file goes
30
36
  * to the tenant's own backend, never through Aikaara). Then publish the
@@ -88,17 +94,38 @@ export declare class AikaaraChatHeader extends HTMLElement {
88
94
  setStatus(status: string): void;
89
95
  }
90
96
 
97
+ /**
98
+ * Chat input box. Composes a textarea + send button + optional attach button.
99
+ *
100
+ * Events fired (composed:true so they cross shadow boundaries):
101
+ * - `send` `{ content: string }` — user pressed enter / clicked send
102
+ * - `file-pick` `{ file: File }` — user selected a file to upload
103
+ *
104
+ * Attributes:
105
+ * - `placeholder` placeholder text
106
+ * - `disable-attach` hides the attach button (set when host has no uploadAdapter)
107
+ * - `accept` forwarded to the hidden <input type="file">
108
+ * - `multiple` allow selecting multiple files
109
+ */
91
110
  export declare class AikaaraChatInput extends HTMLElement {
92
111
  private shadow;
93
112
  private textarea;
94
113
  private sendBtn;
114
+ private attachBtn;
115
+ private fileInput;
95
116
  private _disabled;
117
+ private _uploading;
96
118
  constructor();
119
+ static get observedAttributes(): string[];
97
120
  connectedCallback(): void;
98
121
  set disabled(val: boolean);
99
122
  get disabled(): boolean;
123
+ /** Toggle the attach button into a "uploading…" spinner state. */
124
+ set uploading(val: boolean);
125
+ get uploading(): boolean;
100
126
  focus(): void;
101
127
  clear(): void;
128
+ private refreshSendDisabled;
102
129
  private handleSend;
103
130
  private autoGrow;
104
131
  }
@@ -115,6 +142,7 @@ export declare class AikaaraChatWidget extends HTMLElement {
115
142
  configure(config: Partial<WidgetConfig>): void;
116
143
  private getConfig;
117
144
  setUploadAdapter(adapter: UploadAdapter): void;
145
+ setHistoryAdapter(adapter: ConversationHistoryAdapter): void;
118
146
  private render;
119
147
  private initController;
120
148
  sendUserEvent(eventKey: string, value?: Record<string, unknown>, source?: string): void;
@@ -176,6 +204,35 @@ export declare class AikaaraMessageList extends HTMLElement {
176
204
  private formatTime;
177
205
  }
178
206
 
207
+ export declare class AikaaraModalAction extends HTMLElement {
208
+ private shadow;
209
+ private data;
210
+ private dismissed;
211
+ constructor();
212
+ connectedCallback(): void;
213
+ setPayload(payload: ModalActionPayload): void;
214
+ dismiss(): void;
215
+ private handleOk;
216
+ private render;
217
+ }
218
+
219
+ export declare class AikaaraOptionList extends HTMLElement {
220
+ private shadow;
221
+ private data;
222
+ private selected;
223
+ constructor();
224
+ connectedCallback(): void;
225
+ setPayload(payload: OptionListPayload): void;
226
+ /** Read selected values — used by parent submit action to collect form state. */
227
+ getValues(): {
228
+ name: string;
229
+ values: string[];
230
+ type: string;
231
+ };
232
+ private toggle;
233
+ private render;
234
+ }
235
+
179
236
  export declare class AikaaraStreamingMessage extends HTMLElement {
180
237
  private shadow;
181
238
  private bubble;
@@ -185,14 +242,49 @@ export declare class AikaaraStreamingMessage extends HTMLElement {
185
242
  finalize(): void;
186
243
  }
187
244
 
245
+ export declare class AikaaraSubmitAction extends HTMLElement {
246
+ private shadow;
247
+ private data;
248
+ constructor();
249
+ connectedCallback(): void;
250
+ setPayload(payload: SubmitActionPayload): void;
251
+ private collectFormValues;
252
+ private handleClick;
253
+ private render;
254
+ }
255
+
256
+ /**
257
+ * Centered grey pill used for system / metadata messages
258
+ * (e.g. "Group created", "Assigned to Taxbuddy AI").
259
+ *
260
+ * Theming knobs (CSS custom properties on :host or any ancestor):
261
+ * --aikaara-system-pill-bg
262
+ * --aikaara-system-pill-color
263
+ * --aikaara-system-pill-radius
264
+ * --aikaara-system-pill-padding
265
+ * --aikaara-system-pill-font-size
266
+ * --aikaara-system-pill-font-weight
267
+ * --aikaara-system-pill-border
268
+ */
269
+ export declare class AikaaraSystemPill extends HTMLElement {
270
+ private shadow;
271
+ static get observedAttributes(): string[];
272
+ constructor();
273
+ connectedCallback(): void;
274
+ attributeChangedCallback(): void;
275
+ private render;
276
+ }
277
+
188
278
  /**
189
- * Renders Tiledesk contentType=300 template payloads.
279
+ * Renders the payload of a contentType=300 Tiledesk template. Walks the
280
+ * payload structure and mounts the right child component(s):
281
+ * - { type: 'checkbox' | 'radio' | 'button' } → <aikaara-option-list>
282
+ * - { type: 'submit' } → <aikaara-submit-action>
283
+ * - { type: 'modal' } / single object with `message + ok` → <aikaara-modal-action>
190
284
  *
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.
285
+ * Tenants can override per-template UI by registering a custom element named
286
+ * `aikaara-template-{templateId}` (or by templateId-based slot). The renderer
287
+ * checks for that first; if present, it delegates the whole payload there.
196
288
  */
197
289
  export declare class AikaaraTemplateRenderer extends HTMLElement {
198
290
  private shadow;
@@ -204,6 +296,8 @@ export declare class AikaaraTemplateRenderer extends HTMLElement {
204
296
  attributeChangedCallback(): void;
205
297
  setPayload(payload: unknown, innerMessage?: string): void;
206
298
  private render;
299
+ private mountField;
300
+ private mountModal;
207
301
  }
208
302
 
209
303
  export declare class AikaaraTypingIndicator extends HTMLElement {
@@ -254,6 +348,13 @@ declare interface ChatClientConfig extends ConnectionConfig {
254
348
  departmentId?: string;
255
349
  senderFullname?: string;
256
350
  };
351
+ /**
352
+ * Tenant-level defaults merged into the `action` object of every template
353
+ * postback (e.g. submit-action click). Useful for app-specific keys like
354
+ * `serviceType: 'ITR'` that the bot expects on every form submission.
355
+ * Per-submit values from the form take precedence over these defaults.
356
+ */
357
+ templateActionAttributes?: Record<string, unknown>;
257
358
  onMessage?: (message: Message) => void;
258
359
  onStatusChange?: (status: string) => void;
259
360
  onError?: (error: Error) => void;
@@ -287,6 +388,13 @@ declare interface ChatClientConfig_2 extends ConnectionConfig_2 {
287
388
  departmentId?: string;
288
389
  senderFullname?: string;
289
390
  };
391
+ /**
392
+ * Tenant-level defaults merged into the `action` object of every template
393
+ * postback (e.g. submit-action click). Useful for app-specific keys like
394
+ * `serviceType: 'ITR'` that the bot expects on every form submission.
395
+ * Per-submit values from the form take precedence over these defaults.
396
+ */
397
+ templateActionAttributes?: Record<string, unknown>;
290
398
  onMessage?: (message: Message_2) => void;
291
399
  onStatusChange?: (status: string) => void;
292
400
  onError?: (error: Error) => void;
@@ -357,6 +465,32 @@ declare type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 're
357
465
 
358
466
  declare type ConnectionState_2 = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
359
467
 
468
+ /**
469
+ * Pluggable adapter that hydrates prior conversation messages on connect.
470
+ * The SDK calls this once after MQTT subscribes so the user sees existing
471
+ * history before any new live messages arrive.
472
+ */
473
+ declare interface ConversationHistoryAdapter {
474
+ fetchMessages(conversationId: string, ctx: {
475
+ userId: string;
476
+ appId?: string;
477
+ projectId?: string;
478
+ }): Promise<TiledeskMessage[]>;
479
+ }
480
+
481
+ /**
482
+ * Pluggable adapter that hydrates prior conversation messages on connect.
483
+ * The SDK calls this once after MQTT subscribes so the user sees existing
484
+ * history before any new live messages arrive.
485
+ */
486
+ declare interface ConversationHistoryAdapter_2 {
487
+ fetchMessages(conversationId: string, ctx: {
488
+ userId: string;
489
+ appId?: string;
490
+ projectId?: string;
491
+ }): Promise<TiledeskMessage_2[]>;
492
+ }
493
+
360
494
  declare interface EditEntityAction {
361
495
  action: 'edit_entity';
362
496
  entity_type: string;
@@ -430,16 +564,103 @@ declare interface Message_2 {
430
564
  }>;
431
565
  }
432
566
 
567
+ /**
568
+ * Modal-style action dialog. Bandhan uses these for blocking confirms
569
+ * (e.g. "Please tick the checkbox to proceed" with an Ok button).
570
+ *
571
+ * Payload shape (flexible — matches several bandhan modal templates):
572
+ * { message: 'Please tick…', okLabel?: 'Ok', cancelLabel?: 'Cancel',
573
+ * action?: { message, requestType } }
574
+ *
575
+ * On Ok the component fires `template-action` with the configured message
576
+ * (or the modal text itself) and dismisses. Cancel just dismisses.
577
+ *
578
+ * Theming:
579
+ * --aikaara-modal-overlay-bg, --aikaara-modal-bg, --aikaara-modal-color,
580
+ * --aikaara-modal-radius, --aikaara-modal-padding, --aikaara-modal-shadow,
581
+ * --aikaara-modal-button-bg, --aikaara-modal-button-color,
582
+ * --aikaara-modal-button-radius, --aikaara-modal-cancel-color
583
+ */
584
+ declare interface ModalActionPayload {
585
+ message: string;
586
+ okLabel?: string;
587
+ cancelLabel?: string;
588
+ action?: {
589
+ message?: string;
590
+ requestType?: string;
591
+ };
592
+ }
593
+
433
594
  declare interface NavigateAction {
434
595
  navigate_to: string;
435
596
  }
436
597
 
598
+ /**
599
+ * Rendering for contentType=300 form fields with `type: 'checkbox' | 'radio' | 'button'`.
600
+ *
601
+ * Bandhan envelope:
602
+ * { data: { name: 'IncomeSources', title: 'Income Sources',
603
+ * options: [{ label, value }, ...] },
604
+ * type: 'checkbox' | 'radio' | 'button' }
605
+ *
606
+ * Emits a `template-action` CustomEvent on selection. For `button` type the
607
+ * action fires immediately on click. For `checkbox`/`radio` the parent submit
608
+ * action collects values via `getValues()`.
609
+ *
610
+ * Theming:
611
+ * --aikaara-option-bg, --aikaara-option-color, --aikaara-option-border,
612
+ * --aikaara-option-radius, --aikaara-option-padding, --aikaara-option-gap,
613
+ * --aikaara-option-selected-bg, --aikaara-option-selected-color,
614
+ * --aikaara-option-selected-border, --aikaara-option-title-color,
615
+ * --aikaara-option-title-font-size, --aikaara-option-title-font-weight
616
+ */
617
+ declare interface OptionItem {
618
+ label: string;
619
+ value: string;
620
+ }
621
+
622
+ declare interface OptionListPayload {
623
+ name: string;
624
+ title?: string;
625
+ options: OptionItem[];
626
+ type: 'checkbox' | 'radio' | 'button';
627
+ }
628
+
437
629
  export declare function registerComponents(): void;
438
630
 
439
631
  declare interface SaveEntityAction {
440
632
  action: 'save_entity';
441
633
  }
442
634
 
635
+ /**
636
+ * Primary CTA submit button for contentType=300 forms.
637
+ *
638
+ * Bandhan envelope:
639
+ * { data: { name: 'Confirm Income Sources', type: 'submit',
640
+ * action: { message, formAction, requestType } },
641
+ * type: 'submit' }
642
+ *
643
+ * On click, collects values from sibling AikaaraOptionList components
644
+ * (queried by walking up to the parent template renderer's children) and
645
+ * fires `template-action` with the action message + collected attributes.
646
+ *
647
+ * Theming:
648
+ * --aikaara-submit-bg, --aikaara-submit-color, --aikaara-submit-border,
649
+ * --aikaara-submit-radius, --aikaara-submit-padding,
650
+ * --aikaara-submit-hover-bg, --aikaara-submit-disabled-opacity,
651
+ * --aikaara-submit-font-size, --aikaara-submit-font-weight
652
+ */
653
+ declare interface SubmitActionPayload {
654
+ name: string;
655
+ action: {
656
+ message: string;
657
+ formAction?: string;
658
+ requestType?: string;
659
+ };
660
+ /** id of the bot prompt that triggered this form, stamped on the postback */
661
+ messageId?: string;
662
+ }
663
+
443
664
  declare interface TemplateMessageEvent {
444
665
  messageId: string;
445
666
  conversationId: string;
@@ -482,6 +703,42 @@ declare interface TiledeskFileTemplateConfig_2 {
482
703
  isDeepLink?: boolean;
483
704
  }
484
705
 
706
+ declare interface TiledeskMessage {
707
+ text?: string;
708
+ type?: string;
709
+ sender?: string;
710
+ senderFullname?: string;
711
+ sender_fullname?: string;
712
+ recipient?: string;
713
+ recipient_fullname?: string;
714
+ channel_type?: string;
715
+ timestamp?: number;
716
+ app_id?: string;
717
+ message_id?: string;
718
+ status?: number;
719
+ attributes?: Record<string, unknown>;
720
+ metadata?: Record<string, unknown>;
721
+ [key: string]: unknown;
722
+ }
723
+
724
+ declare interface TiledeskMessage_2 {
725
+ text?: string;
726
+ type?: string;
727
+ sender?: string;
728
+ senderFullname?: string;
729
+ sender_fullname?: string;
730
+ recipient?: string;
731
+ recipient_fullname?: string;
732
+ channel_type?: string;
733
+ timestamp?: number;
734
+ app_id?: string;
735
+ message_id?: string;
736
+ status?: number;
737
+ attributes?: Record<string, unknown>;
738
+ metadata?: Record<string, unknown>;
739
+ [key: string]: unknown;
740
+ }
741
+
485
742
  declare interface TiledeskMessageDefaults {
486
743
  channelType?: string;
487
744
  channel?: string;
@@ -546,6 +803,20 @@ declare interface TiledeskTransportConfig {
546
803
  fileTemplate?: TiledeskFileTemplateConfig;
547
804
  recipientFullnameResolver?: (conversationId: string) => string | undefined;
548
805
  senderFullname?: string;
806
+ /**
807
+ * If true (default), AikaaraChatClient publishes a `CHAT_INITIATED` event
808
+ * to the conversation's outbound topic on first connect — but only when
809
+ * the conversation history is empty (so reload of an in-flight chat
810
+ * doesn't replay the kickoff).
811
+ */
812
+ autoInitiateOnEmpty?: boolean;
813
+ /** Extra attributes merged into the auto-fired CHAT_INITIATED envelope. */
814
+ chatInitiatedAttributes?: Record<string, unknown>;
815
+ /**
816
+ * Log decoded MQTT frames to console as they're sent/received.
817
+ * Off by default — set true for debugging Tiledesk wire traffic.
818
+ */
819
+ debug?: boolean;
549
820
  }
550
821
 
551
822
  declare interface TiledeskTransportConfig_2 {
@@ -576,6 +847,20 @@ declare interface TiledeskTransportConfig_2 {
576
847
  fileTemplate?: TiledeskFileTemplateConfig_2;
577
848
  recipientFullnameResolver?: (conversationId: string) => string | undefined;
578
849
  senderFullname?: string;
850
+ /**
851
+ * If true (default), AikaaraChatClient publishes a `CHAT_INITIATED` event
852
+ * to the conversation's outbound topic on first connect — but only when
853
+ * the conversation history is empty (so reload of an in-flight chat
854
+ * doesn't replay the kickoff).
855
+ */
856
+ autoInitiateOnEmpty?: boolean;
857
+ /** Extra attributes merged into the auto-fired CHAT_INITIATED envelope. */
858
+ chatInitiatedAttributes?: Record<string, unknown>;
859
+ /**
860
+ * Log decoded MQTT frames to console as they're sent/received.
861
+ * Off by default — set true for debugging Tiledesk wire traffic.
862
+ */
863
+ debug?: boolean;
579
864
  }
580
865
 
581
866
  declare interface ToolCall {
@@ -675,6 +960,14 @@ declare interface WidgetConfig extends ChatClientConfig {
675
960
  bubbleText?: string;
676
961
  bubbleIcon?: string;
677
962
  uploadAdapter?: UploadAdapter;
963
+ historyAdapter?: ConversationHistoryAdapter;
964
+ /**
965
+ * Display mode:
966
+ * - `popup` (default): floating bubble in the corner, click to open panel.
967
+ * - `embed`: render the chat panel inline at the host element's location,
968
+ * filling its container. Bubble + open/close animation are skipped.
969
+ */
970
+ display?: 'popup' | 'embed';
678
971
  }
679
972
 
680
973
  export { }