@aikaara/chat-sdk 0.2.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/index.d.ts CHANGED
@@ -41,14 +41,45 @@ export declare class AikaaraChatBubble extends HTMLElement {
41
41
 
42
42
  export declare class AikaaraChatClient extends EventEmitter<ChatEvents> {
43
43
  private connection;
44
+ private tiledesk;
44
45
  private api;
45
46
  private messageStore;
46
47
  private conversationManager;
47
48
  private subscription;
48
49
  private config;
49
- constructor(config: ChatClientConfig);
50
+ private mode;
51
+ private uploadAdapter;
52
+ private historyAdapter;
53
+ private tiledeskUnsubs;
54
+ constructor(config: ChatClientConfig, opts?: {
55
+ uploadAdapter?: UploadAdapter;
56
+ historyAdapter?: ConversationHistoryAdapter;
57
+ });
58
+ private usesAikaara;
59
+ private usesTiledesk;
60
+ private initTiledeskTransport;
50
61
  connect(): Promise<void>;
51
- sendMessage(content: string): Promise<void>;
62
+ private hydrateTiledeskHistory;
63
+ sendMessage(content: string, opts?: {
64
+ attributes?: Record<string, unknown>;
65
+ metadata?: Record<string, unknown>;
66
+ }): Promise<void>;
67
+ /**
68
+ * Upload a file via the configured UploadAdapter (client-side: file goes
69
+ * to the tenant's own backend, never through Aikaara). Then publish the
70
+ * Tiledesk file-message envelope so hooks_controller picks it up.
71
+ */
72
+ sendFile(file: File | Blob, opts?: {
73
+ caption?: string;
74
+ }): Promise<void>;
75
+ /**
76
+ * Trigger Tiledesk's CHAT_INITIATED event — required to kick off a bot flow
77
+ * for newly-created Tiledesk request groups.
78
+ */
79
+ initiateTiledeskChat(extraAttributes?: Record<string, unknown>): void;
80
+ /** Mark a Tiledesk message as read (publishes status=300 update). */
81
+ markTiledeskRead(messageId: string): void;
82
+ setUploadAdapter(adapter: UploadAdapter): void;
52
83
  sendUserEvent(eventKey: string, value?: object, source?: string): Promise<void>;
53
84
  loadHistory(): Promise<Message[]>;
54
85
  get messages(): Message[];
@@ -73,6 +104,8 @@ export declare class AikaaraChatClient extends EventEmitter<ChatEvents> {
73
104
  */
74
105
  setContext(context: AppContext): Promise<void>;
75
106
  disconnect(): Promise<void>;
107
+ private handleTiledeskMessage;
108
+ private handleTiledeskStatusUpdate;
76
109
  /**
77
110
  * Parse structured action results from tool execution output.
78
111
  * When the agent calls tools like `edit_current_entity`, `save_current_entity`,
@@ -94,17 +127,38 @@ export declare class AikaaraChatHeader extends HTMLElement {
94
127
  setStatus(status: string): void;
95
128
  }
96
129
 
130
+ /**
131
+ * Chat input box. Composes a textarea + send button + optional attach button.
132
+ *
133
+ * Events fired (composed:true so they cross shadow boundaries):
134
+ * - `send` `{ content: string }` — user pressed enter / clicked send
135
+ * - `file-pick` `{ file: File }` — user selected a file to upload
136
+ *
137
+ * Attributes:
138
+ * - `placeholder` placeholder text
139
+ * - `disable-attach` hides the attach button (set when host has no uploadAdapter)
140
+ * - `accept` forwarded to the hidden <input type="file">
141
+ * - `multiple` allow selecting multiple files
142
+ */
97
143
  export declare class AikaaraChatInput extends HTMLElement {
98
144
  private shadow;
99
145
  private textarea;
100
146
  private sendBtn;
147
+ private attachBtn;
148
+ private fileInput;
101
149
  private _disabled;
150
+ private _uploading;
102
151
  constructor();
152
+ static get observedAttributes(): string[];
103
153
  connectedCallback(): void;
104
154
  set disabled(val: boolean);
105
155
  get disabled(): boolean;
156
+ /** Toggle the attach button into a "uploading…" spinner state. */
157
+ set uploading(val: boolean);
158
+ get uploading(): boolean;
106
159
  focus(): void;
107
160
  clear(): void;
161
+ private refreshSendDisabled;
108
162
  private handleSend;
109
163
  private autoGrow;
110
164
  }
@@ -120,6 +174,8 @@ export declare class AikaaraChatWidget extends HTMLElement {
120
174
  attributeChangedCallback(_name: string, oldVal: string, newVal: string): void;
121
175
  configure(config: Partial<WidgetConfig>): void;
122
176
  private getConfig;
177
+ setUploadAdapter(adapter: UploadAdapter): void;
178
+ setHistoryAdapter(adapter: ConversationHistoryAdapter): void;
123
179
  private render;
124
180
  private initController;
125
181
  sendUserEvent(eventKey: string, value?: Record<string, unknown>, source?: string): void;
@@ -139,11 +195,19 @@ export declare class AikaaraErrorBanner extends HTMLElement {
139
195
 
140
196
  export declare class AikaaraMessageBubble extends HTMLElement {
141
197
  private shadow;
198
+ private templatePayload;
199
+ private attachments;
142
200
  static get observedAttributes(): string[];
143
201
  constructor();
144
202
  connectedCallback(): void;
145
203
  attributeChangedCallback(): void;
204
+ setTemplatePayload(payload: unknown): void;
205
+ setAttachments(attachments: Array<{
206
+ fileName: string;
207
+ fileUrl: string;
208
+ }>): void;
146
209
  private render;
210
+ private renderAttachments;
147
211
  }
148
212
 
149
213
  export declare class AikaaraMessageList extends HTMLElement {
@@ -162,6 +226,13 @@ export declare class AikaaraMessageList extends HTMLElement {
162
226
  showTypingIndicator(): void;
163
227
  removeTypingIndicator(): void;
164
228
  private appendMessageElement;
229
+ /**
230
+ * Replace an existing rendered message (matched by id or externalId) in place.
231
+ * Used when a Tiledesk self-echo reconciles with an optimistic bubble or when
232
+ * a status update flips delivered → read.
233
+ */
234
+ upsertMessage(message: Message): void;
235
+ private findRenderedMessage;
165
236
  private scrollToBottom;
166
237
  private formatTime;
167
238
  }
@@ -239,11 +310,37 @@ export declare interface ChatClientConfig extends ConnectionConfig {
239
310
  conversationId?: string;
240
311
  systemPromptId?: number;
241
312
  channel?: 'widget' | 'api' | 'sidekick';
313
+ /**
314
+ * Transport selection.
315
+ * - `aikaara` (default): ActionCable to Aikaara Rails (AI streaming).
316
+ * - `tiledesk`: MQTT direct to a self-hosted Tiledesk + chat21 stack.
317
+ * - `dual`: both — Aikaara cable for AI, Tiledesk MQTT for live-agent + file events.
318
+ */
319
+ transport?: TransportMode;
320
+ /**
321
+ * Tiledesk-side identity. Required when `transport` is `tiledesk` or `dual`.
322
+ * `userId` here is the Tiledesk user `_id` and is also used as the SDK conversation
323
+ * subject — Aikaara conversations bound to this user via ext_uid mapping.
324
+ */
325
+ tiledeskIdentity?: {
326
+ userId: string;
327
+ userName?: string;
328
+ departmentId?: string;
329
+ senderFullname?: string;
330
+ };
331
+ /**
332
+ * Tenant-level defaults merged into the `action` object of every template
333
+ * postback (e.g. submit-action click). Useful for app-specific keys like
334
+ * `serviceType: 'ITR'` that the bot expects on every form submission.
335
+ * Per-submit values from the form take precedence over these defaults.
336
+ */
337
+ templateActionAttributes?: Record<string, unknown>;
242
338
  onMessage?: (message: Message) => void;
243
339
  onStatusChange?: (status: string) => void;
244
340
  onError?: (error: Error) => void;
245
341
  onStreamUpdate?: (delta: string, fullContent: string) => void;
246
342
  onConnectionStateChange?: (state: ConnectionState) => void;
343
+ onTemplateMessage?: (template: TemplateMessageEvent) => void;
247
344
  }
248
345
 
249
346
  export declare interface ChatEvents {
@@ -284,6 +381,8 @@ export declare interface ChatEvents {
284
381
  };
285
382
  }
286
383
 
384
+ export declare function clearPersistedConversationId(userId: string, projectId: string): void;
385
+
287
386
  export declare interface ConnectionConfig {
288
387
  baseUrl: string;
289
388
  wsUrl?: string;
@@ -315,6 +414,19 @@ export declare class ConnectionManager extends EventEmitter<ChatEvents> {
315
414
 
316
415
  export declare type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
317
416
 
417
+ /**
418
+ * Pluggable adapter that hydrates prior conversation messages on connect.
419
+ * The SDK calls this once after MQTT subscribes so the user sees existing
420
+ * history before any new live messages arrive.
421
+ */
422
+ export declare interface ConversationHistoryAdapter {
423
+ fetchMessages(conversationId: string, ctx: {
424
+ userId: string;
425
+ appId?: string;
426
+ projectId?: string;
427
+ }): Promise<TiledeskMessage[]>;
428
+ }
429
+
318
430
  export declare class ConversationManager {
319
431
  private _conversationId;
320
432
  private persist;
@@ -331,6 +443,10 @@ declare interface CreateConversationResponse {
331
443
  status: string;
332
444
  }
333
445
 
446
+ export declare function createFetchUploadAdapter(config: FetchUploadAdapterConfig): UploadAdapter;
447
+
448
+ export declare function createTiledeskHistoryAdapter(config: TiledeskHistoryAdapterConfig): ConversationHistoryAdapter;
449
+
334
450
  export declare interface EditEntityAction {
335
451
  action: 'edit_entity';
336
452
  entity_type: string;
@@ -346,6 +462,18 @@ export declare class EventEmitter<Events extends Record<string, any>> {
346
462
  removeAllListeners(): void;
347
463
  }
348
464
 
465
+ export declare function extractTiledeskFileEnvelope(message: TiledeskMessage): TiledeskFileEnvelope | null;
466
+
467
+ export declare interface FetchUploadAdapterConfig {
468
+ endpoint: string;
469
+ method?: 'POST' | 'PUT';
470
+ fieldName?: string;
471
+ headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
472
+ credentials?: RequestCredentials;
473
+ extraFields?: Record<string, string> | ((ctx: UploadAdapterContext) => Record<string, string>);
474
+ parseResponse?: (raw: unknown, ctx: UploadAdapterContext) => UploadAdapterResult;
475
+ }
476
+
349
477
  export declare interface FieldUpdate {
350
478
  field: string;
351
479
  value: unknown;
@@ -468,10 +596,19 @@ export declare interface FormRegistration {
468
596
  getCurrentValues: () => Record<string, unknown>;
469
597
  }
470
598
 
599
+ export declare function inferTiledeskRole(message: TiledeskMessage, cfg: TiledeskRoleConfig): TiledeskRole;
600
+
601
+ /**
602
+ * Self-echo detector — Tiledesk fans the user's outgoing publish back
603
+ * as a `clientadded` event on the same connection. UI must dedupe against
604
+ * the optimistic local message rather than rendering twice.
605
+ */
606
+ export declare function isTiledeskSelfEcho(message: TiledeskMessage, userId: string): boolean;
607
+
471
608
  export declare interface Message {
472
609
  id: string;
473
610
  conversationId: string;
474
- role: 'user' | 'assistant' | 'system' | 'tool';
611
+ role: 'user' | 'assistant' | 'system' | 'tool' | 'agent';
475
612
  content: string;
476
613
  toolCalls?: ToolCall[];
477
614
  toolCallResults?: ToolCallResult;
@@ -479,7 +616,19 @@ export declare interface Message {
479
616
  tokensOutput?: number;
480
617
  metadata?: Record<string, unknown>;
481
618
  createdAt: string;
482
- status?: 'sending' | 'sent' | 'streaming' | 'complete' | 'error';
619
+ status?: 'sending' | 'sent' | 'delivered' | 'read' | 'streaming' | 'complete' | 'error';
620
+ externalId?: string;
621
+ template?: {
622
+ contentType?: string;
623
+ templateId?: string;
624
+ payload?: unknown;
625
+ };
626
+ attachments?: Array<{
627
+ fileName: string;
628
+ fileUrl: string;
629
+ cloudFileId?: string;
630
+ contentType?: string;
631
+ }>;
483
632
  }
484
633
 
485
634
  export declare class MessageStore {
@@ -487,6 +636,22 @@ export declare class MessageStore {
487
636
  private optimisticCounter;
488
637
  get messages(): Message[];
489
638
  addOptimistic(role: 'user', content: string, conversationId: string): Message;
639
+ /**
640
+ * Reconcile a remote message against an outstanding optimistic message.
641
+ * Tiledesk fans the user's outgoing publish back as an inbound clientadded —
642
+ * dedupe by exact content + recency window so the optimistic bubble keeps
643
+ * its position and we don't render duplicates.
644
+ */
645
+ reconcileOptimistic(remote: Message, recencyMs?: number): Message | null;
646
+ /**
647
+ * Append a remote-originated message (e.g. from Tiledesk MQTT). If a matching
648
+ * optimistic message exists it is reconciled in place; otherwise appended.
649
+ */
650
+ upsertRemoteMessage(remote: Message): {
651
+ message: Message;
652
+ deduped: boolean;
653
+ };
654
+ updateMessageStatus(externalId: string, status: Message['status']): Message | undefined;
490
655
  confirmOptimistic(tempId: string): void;
491
656
  addStreamingMessage(conversationId: string): Message;
492
657
  updateStreaming(content: string): void;
@@ -503,10 +668,26 @@ export declare class MessageStore {
503
668
 
504
669
  export declare function mount(config: WidgetConfig): AikaaraChatWidget;
505
670
 
671
+ export declare interface MountedTenantWidget {
672
+ widget: AikaaraChatWidget;
673
+ requestId: string;
674
+ config: WidgetConfig;
675
+ destroy: () => void;
676
+ }
677
+
678
+ /**
679
+ * Standard tenant mount. Fetches the descriptor (when `configUrl` is set),
680
+ * merges per-mount overrides, builds default adapters from the descriptor's
681
+ * endpoint URLs (when no override is supplied), and mounts the widget.
682
+ */
683
+ export declare function mountTenantWidget(opts: TenantMountOptions): Promise<MountedTenantWidget>;
684
+
506
685
  export declare interface NavigateAction {
507
686
  navigate_to: string;
508
687
  }
509
688
 
689
+ export declare function parseTiledeskTemplate(message: TiledeskMessage): TiledeskParsedTemplate;
690
+
510
691
  export declare function registerComponents(): void;
511
692
 
512
693
  export declare interface SaveEntityAction {
@@ -515,44 +696,231 @@ export declare interface SaveEntityAction {
515
696
 
516
697
  declare type SubscriptionCallback = (data: unknown) => void;
517
698
 
699
+ declare interface TemplateMessageEvent {
700
+ messageId: string;
701
+ conversationId: string;
702
+ role: 'user' | 'assistant' | 'system' | 'agent';
703
+ contentType?: string;
704
+ templateId?: string;
705
+ payload?: unknown;
706
+ innerMessage?: string;
707
+ raw: unknown;
708
+ }
709
+
710
+ export declare interface TenantMountOptions {
711
+ container: HTMLElement;
712
+ /** Fetched from this URL when `config` is omitted. */
713
+ configUrl?: string;
714
+ /** Pre-resolved descriptor — skip the fetch. */
715
+ config?: WidgetConfigDescriptor;
716
+ /** Headers attached when fetching `configUrl` (e.g. tenant-API auth). */
717
+ configHeaders?: Record<string, string>;
718
+ identity: {
719
+ userId: string;
720
+ userName?: string;
721
+ departmentId?: string;
722
+ senderFullname?: string;
723
+ };
724
+ /** Returns a raw Tiledesk JWT (no Bearer/JWT prefix) for MQTT password. */
725
+ tokenProvider: () => Promise<string>;
726
+ /** Authorization value for the history fetch. Defaults to `tokenProvider()`. */
727
+ historyTokenProvider?: () => Promise<string>;
728
+ /**
729
+ * Optional override adapters. If omitted and the descriptor specifies the
730
+ * matching endpoint, the SDK builds default fetch-based adapters.
731
+ */
732
+ uploadAdapter?: UploadAdapter;
733
+ historyAdapter?: ConversationHistoryAdapter;
734
+ /**
735
+ * Pin a conversationId. When omitted we look up
736
+ * `aikaara_chat:requestId:{userId}:{projectId}` in localStorage and reuse
737
+ * any persisted value; only mint a fresh `requestId` when nothing is stored.
738
+ */
739
+ conversationId?: string;
740
+ forceNewConversation?: boolean;
741
+ /** Per-mount overrides that take precedence over the descriptor. */
742
+ overrides?: Partial<WidgetConfigDescriptor>;
743
+ /** Surfaced from the SDK. */
744
+ onError?: (err: Error) => void;
745
+ }
746
+
518
747
  export declare interface TestToolAction {
519
748
  action: 'test_tool';
520
749
  tool_id: number;
521
750
  parameters: Record<string, unknown>;
522
751
  }
523
752
 
753
+ export declare interface TiledeskFileEnvelope {
754
+ fileName?: string;
755
+ fileUrl?: string;
756
+ cloudFileId?: string;
757
+ templateId?: string;
758
+ }
759
+
760
+ export declare interface TiledeskFileMessageInput {
761
+ fileName: string;
762
+ fileUrl: string;
763
+ cloudFileId?: string;
764
+ templateId?: string;
765
+ headerImgSrc?: string;
766
+ type?: 'link' | 'image';
767
+ isDeepLink?: boolean;
768
+ description?: string;
769
+ attributes?: Record<string, unknown>;
770
+ metadata?: Record<string, unknown>;
771
+ }
772
+
773
+ export declare interface TiledeskFileTemplateConfig {
774
+ templateId: string;
775
+ headerImgSrc?: string;
776
+ type?: 'link' | 'image';
777
+ isDeepLink?: boolean;
778
+ }
779
+
780
+ export declare interface TiledeskHistoryAdapterConfig {
781
+ /**
782
+ * Base URL of the Tiledesk chat API, e.g. `https://uat-tiledesk.taxbuddy.com/chatapi/api`
783
+ * (no trailing slash). Final URL is composed as
784
+ * `{apiBase}/tilechat/{userId}/conversations/{conversationId}/messages?pageSize={pageSize}`
785
+ */
786
+ apiBase: string;
787
+ pageSize?: number;
788
+ /**
789
+ * Async getter for the bearer token. Most Tiledesk-fronted gateways accept
790
+ * the same JWT used for the MQTT connection. Return `null` to omit the
791
+ * `Authorization` header.
792
+ */
793
+ getToken?: () => string | null | Promise<string | null>;
794
+ /** Override the path template. Default mirrors bandhan's chatapi route. */
795
+ pathTemplate?: string;
796
+ /** Extra static headers to attach (e.g. `partnerid`, `environment`). */
797
+ extraHeaders?: Record<string, string>;
798
+ /**
799
+ * Optional response shape mapper. Default expects
800
+ * `{ success: true, result: TiledeskMessage[] }`
801
+ * which matches the bandhan `/chatapi/api/tilechat/.../messages` response.
802
+ */
803
+ parseResponse?: (raw: unknown) => TiledeskMessage[];
804
+ }
805
+
524
806
  export declare interface TiledeskMessage {
525
807
  text?: string;
526
808
  type?: string;
527
809
  sender?: string;
528
810
  senderFullname?: string;
811
+ sender_fullname?: string;
529
812
  recipient?: string;
813
+ recipient_fullname?: string;
814
+ channel_type?: string;
530
815
  timestamp?: number;
816
+ app_id?: string;
817
+ message_id?: string;
818
+ status?: number;
531
819
  attributes?: Record<string, unknown>;
532
820
  metadata?: Record<string, unknown>;
533
821
  [key: string]: unknown;
534
822
  }
535
823
 
824
+ export declare interface TiledeskMessageContext {
825
+ topic: string;
826
+ conversationId?: string;
827
+ messageId?: string;
828
+ kind: 'clientadded' | 'update' | 'unknown';
829
+ }
830
+
831
+ export declare interface TiledeskMessageDefaults {
832
+ channelType?: string;
833
+ channel?: string;
834
+ requestChannel?: string;
835
+ platform?: string;
836
+ medium?: string;
837
+ departmentId?: string;
838
+ attributes?: Record<string, unknown>;
839
+ }
840
+
841
+ export declare interface TiledeskParsedTemplate {
842
+ contentType?: string;
843
+ templateId?: string;
844
+ payload?: unknown;
845
+ innerMessage?: string;
846
+ raw: TiledeskMessage;
847
+ }
848
+
849
+ export declare type TiledeskRole = 'user' | 'assistant' | 'system' | 'agent';
850
+
851
+ export declare interface TiledeskRoleConfig {
852
+ userId: string;
853
+ systemSenders?: string[];
854
+ botSenderPrefix?: string;
855
+ }
856
+
857
+ export declare interface TiledeskStatusUpdate {
858
+ conversationId: string;
859
+ messageId: string;
860
+ status: number;
861
+ raw: Record<string, unknown>;
862
+ }
863
+
864
+ export declare interface TiledeskTopicTemplates {
865
+ inbound?: string;
866
+ inboundUpdate?: string;
867
+ outbound?: string;
868
+ presence?: string;
869
+ wildcardSubscribe?: string;
870
+ }
871
+
536
872
  export declare class TiledeskTransport {
537
873
  private client;
538
874
  private config;
875
+ private currentToken;
876
+ private clientId;
877
+ private appId;
878
+ private topics;
539
879
  private messageHandlers;
540
880
  private stateHandlers;
881
+ private statusUpdateHandlers;
541
882
  private subscribedTopics;
542
883
  private reconnectAttempt;
543
884
  private maxReconnectAttempts;
885
+ private reconnectMaxDelayMs;
544
886
  private disposed;
887
+ private reconnectTimer;
888
+ private inboundRegex;
889
+ private inboundUpdateRegex;
545
890
  constructor(config: TiledeskTransportConfig);
546
891
  connect(): Promise<void>;
892
+ private debugLog;
893
+ subscribeWildcard(): void;
547
894
  subscribeToConversation(conversationId: string): void;
548
895
  unsubscribeFromConversation(conversationId: string): void;
549
- publishMessage(conversationId: string, text: string): void;
896
+ publishMessage(conversationId: string, text: string, overrides?: Partial<TiledeskMessage>): void;
897
+ publishFileMessage(conversationId: string, file: TiledeskFileMessageInput): void;
898
+ publishRaw(conversationId: string, message: TiledeskMessage): void;
899
+ /**
900
+ * Send a read receipt for a message. Tiledesk widgets publish
901
+ * `{"status":300}` to apps/{appId}/users/{userId}/messages/{convId}/{msgId}/update.
902
+ */
903
+ publishReadReceipt(conversationId: string, messageId: string, status?: number): void;
904
+ /**
905
+ * Trigger conversation kickoff. Tiledesk bot routing waits for the
906
+ * widget to publish a CHAT_INITIATED event before the bot replies.
907
+ */
908
+ publishChatInitiated(conversationId: string, extraAttributes?: Record<string, unknown>): void;
550
909
  onMessage(handler: TransportMessageHandler): () => void;
551
910
  onStateChange(handler: TransportStateHandler): () => void;
911
+ onStatusUpdate(handler: TransportStatusUpdateHandler): () => void;
552
912
  disconnect(): void;
553
913
  get isConnected(): boolean;
554
914
  private scheduleReconnect;
555
915
  private notifyStateChange;
916
+ private dispatchInbound;
917
+ private buildOutgoingEnvelope;
918
+ private publishEnvelope;
919
+ private renderInboundTopic;
920
+ private renderOutboundTopic;
921
+ private renderPresenceTopic;
922
+ private renderTemplate;
923
+ private buildTopicRegex;
556
924
  }
557
925
 
558
926
  export declare interface TiledeskTransportConfig {
@@ -561,6 +929,42 @@ export declare interface TiledeskTransportConfig {
561
929
  userId: string;
562
930
  userName?: string;
563
931
  projectId: string;
932
+ appId?: string;
933
+ clientId?: string;
934
+ protocolVersion?: 3 | 4 | 5;
935
+ protocolId?: 'MQIsdp' | 'MQTT';
936
+ mqttUsername?: string;
937
+ connectTimeoutMs?: number;
938
+ keepAliveSec?: number;
939
+ maxReconnectAttempts?: number;
940
+ reconnectMaxDelayMs?: number;
941
+ tokenProvider?: () => Promise<string>;
942
+ wildcardSubscribe?: boolean;
943
+ subscribeQos?: 0 | 1 | 2;
944
+ publishQos?: 0 | 1 | 2;
945
+ publishRetain?: boolean;
946
+ enablePresence?: boolean;
947
+ presencePayloadConnected?: Record<string, unknown>;
948
+ presencePayloadDisconnected?: Record<string, unknown>;
949
+ topicTemplates?: TiledeskTopicTemplates;
950
+ messageDefaults?: TiledeskMessageDefaults;
951
+ fileTemplate?: TiledeskFileTemplateConfig;
952
+ recipientFullnameResolver?: (conversationId: string) => string | undefined;
953
+ senderFullname?: string;
954
+ /**
955
+ * If true (default), AikaaraChatClient publishes a `CHAT_INITIATED` event
956
+ * to the conversation's outbound topic on first connect — but only when
957
+ * the conversation history is empty (so reload of an in-flight chat
958
+ * doesn't replay the kickoff).
959
+ */
960
+ autoInitiateOnEmpty?: boolean;
961
+ /** Extra attributes merged into the auto-fired CHAT_INITIATED envelope. */
962
+ chatInitiatedAttributes?: Record<string, unknown>;
963
+ /**
964
+ * Log decoded MQTT frames to console as they're sent/received.
965
+ * Off by default — set true for debugging Tiledesk wire traffic.
966
+ */
967
+ debug?: boolean;
564
968
  }
565
969
 
566
970
  export declare interface ToolCall {
@@ -577,12 +981,37 @@ export declare interface ToolCallResult {
577
981
  content: string;
578
982
  }
579
983
 
580
- export declare type TransportMessageHandler = (message: TiledeskMessage) => void;
984
+ export declare type TransportMessageHandler = (message: TiledeskMessage, ctx: TiledeskMessageContext) => void;
985
+
986
+ declare type TransportMode = 'aikaara' | 'tiledesk' | 'dual';
581
987
 
582
988
  export declare type TransportStateHandler = (connected: boolean) => void;
583
989
 
990
+ export declare type TransportStatusUpdateHandler = (update: TiledeskStatusUpdate) => void;
991
+
584
992
  export declare function unmount(): void;
585
993
 
994
+ export declare interface UploadAdapter {
995
+ upload(file: File | Blob, ctx: UploadAdapterContext): Promise<UploadAdapterResult>;
996
+ }
997
+
998
+ export declare interface UploadAdapterContext {
999
+ conversationId: string;
1000
+ userId: string;
1001
+ projectId?: string;
1002
+ appId?: string;
1003
+ }
1004
+
1005
+ export declare interface UploadAdapterResult {
1006
+ url: string;
1007
+ fileName: string;
1008
+ cloudFileId?: string;
1009
+ relativePath?: string;
1010
+ contentType?: string;
1011
+ byteSize?: number;
1012
+ meta?: Record<string, unknown>;
1013
+ }
1014
+
586
1015
  export declare interface WidgetConfig extends ChatClientConfig {
587
1016
  position?: 'bottom-right' | 'bottom-left';
588
1017
  offset?: {
@@ -605,6 +1034,71 @@ export declare interface WidgetConfig extends ChatClientConfig {
605
1034
  showBubble?: boolean;
606
1035
  bubbleText?: string;
607
1036
  bubbleIcon?: string;
1037
+ uploadAdapter?: UploadAdapter;
1038
+ historyAdapter?: ConversationHistoryAdapter;
1039
+ /**
1040
+ * Display mode:
1041
+ * - `popup` (default): floating bubble in the corner, click to open panel.
1042
+ * - `embed`: render the chat panel inline at the host element's location,
1043
+ * filling its container. Bubble + open/close animation are skipped.
1044
+ */
1045
+ display?: 'popup' | 'embed';
1046
+ }
1047
+
1048
+ export declare interface WidgetConfigDescriptor {
1049
+ /** Visuals */
1050
+ display?: 'popup' | 'embed';
1051
+ position?: 'bottom-right' | 'bottom-left';
1052
+ primaryColor?: string;
1053
+ title?: string;
1054
+ subtitle?: string;
1055
+ avatarUrl?: string;
1056
+ width?: number;
1057
+ height?: number;
1058
+ borderRadius?: number;
1059
+ fontFamily?: string;
1060
+ welcomeMessage?: string;
1061
+ placeholder?: string;
1062
+ showTimestamps?: boolean;
1063
+ persistConversation?: boolean;
1064
+ /** Transport selection */
1065
+ transport?: TransportMode;
1066
+ /** Tiledesk wire config (JSON-serializable subset of TiledeskTransportConfig) */
1067
+ tiledesk?: {
1068
+ mqttEndpoint: string;
1069
+ appId?: string;
1070
+ projectId: string;
1071
+ mqttUsername?: string;
1072
+ protocolId?: 'MQIsdp' | 'MQTT';
1073
+ protocolVersion?: 3 | 4 | 5;
1074
+ keepAliveSec?: number;
1075
+ connectTimeoutMs?: number;
1076
+ maxReconnectAttempts?: number;
1077
+ reconnectMaxDelayMs?: number;
1078
+ wildcardSubscribe?: boolean;
1079
+ enablePresence?: boolean;
1080
+ autoInitiateOnEmpty?: boolean;
1081
+ chatInitiatedAttributes?: Record<string, unknown>;
1082
+ messageDefaults?: TiledeskMessageDefaults;
1083
+ fileTemplate?: TiledeskFileTemplateConfig;
1084
+ topicTemplates?: TiledeskTopicTemplates;
1085
+ debug?: boolean;
1086
+ /**
1087
+ * Pattern for `support-group-…` requestId minted on first chat. Use
1088
+ * `{projectId}` and `{uuid}` placeholders. Defaults to bandhan's
1089
+ * `support-group-{projectId}-{uuid}`.
1090
+ */
1091
+ requestIdTemplate?: string;
1092
+ };
1093
+ /** Defaults merged into every form-action postback */
1094
+ templateActionAttributes?: Record<string, unknown>;
1095
+ /** Adapter endpoints — SDK builds the actual fetch calls */
1096
+ uploadEndpoint?: string;
1097
+ uploadFieldName?: string;
1098
+ uploadExtraFields?: Record<string, string>;
1099
+ historyApiBase?: string;
1100
+ historyPageSize?: number;
1101
+ historyPathTemplate?: string;
608
1102
  }
609
1103
 
610
1104
  export { }