@aikaara/chat-sdk 0.2.0 → 0.3.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
@@ -8,14 +8,39 @@ export declare class AikaaraChatBubble extends HTMLElement {
8
8
 
9
9
  declare class AikaaraChatClient extends EventEmitter<ChatEvents> {
10
10
  private connection;
11
+ private tiledesk;
11
12
  private api;
12
13
  private messageStore;
13
14
  private conversationManager;
14
15
  private subscription;
15
16
  private config;
16
- constructor(config: ChatClientConfig_2);
17
+ private mode;
18
+ private uploadAdapter;
19
+ private tiledeskUnsubs;
20
+ constructor(config: ChatClientConfig_2, opts?: {
21
+ uploadAdapter?: UploadAdapter_2;
22
+ });
23
+ private usesAikaara;
24
+ private usesTiledesk;
25
+ private initTiledeskTransport;
17
26
  connect(): Promise<void>;
18
27
  sendMessage(content: string): Promise<void>;
28
+ /**
29
+ * Upload a file via the configured UploadAdapter (client-side: file goes
30
+ * to the tenant's own backend, never through Aikaara). Then publish the
31
+ * Tiledesk file-message envelope so hooks_controller picks it up.
32
+ */
33
+ sendFile(file: File | Blob, opts?: {
34
+ caption?: string;
35
+ }): Promise<void>;
36
+ /**
37
+ * Trigger Tiledesk's CHAT_INITIATED event — required to kick off a bot flow
38
+ * for newly-created Tiledesk request groups.
39
+ */
40
+ initiateTiledeskChat(extraAttributes?: Record<string, unknown>): void;
41
+ /** Mark a Tiledesk message as read (publishes status=300 update). */
42
+ markTiledeskRead(messageId: string): void;
43
+ setUploadAdapter(adapter: UploadAdapter_2): void;
19
44
  sendUserEvent(eventKey: string, value?: object, source?: string): Promise<void>;
20
45
  loadHistory(): Promise<Message_2[]>;
21
46
  get messages(): Message_2[];
@@ -40,6 +65,8 @@ declare class AikaaraChatClient extends EventEmitter<ChatEvents> {
40
65
  */
41
66
  setContext(context: AppContext): Promise<void>;
42
67
  disconnect(): Promise<void>;
68
+ private handleTiledeskMessage;
69
+ private handleTiledeskStatusUpdate;
43
70
  /**
44
71
  * Parse structured action results from tool execution output.
45
72
  * When the agent calls tools like `edit_current_entity`, `save_current_entity`,
@@ -87,6 +114,7 @@ export declare class AikaaraChatWidget extends HTMLElement {
87
114
  attributeChangedCallback(_name: string, oldVal: string, newVal: string): void;
88
115
  configure(config: Partial<WidgetConfig>): void;
89
116
  private getConfig;
117
+ setUploadAdapter(adapter: UploadAdapter): void;
90
118
  private render;
91
119
  private initController;
92
120
  sendUserEvent(eventKey: string, value?: Record<string, unknown>, source?: string): void;
@@ -106,11 +134,19 @@ export declare class AikaaraErrorBanner extends HTMLElement {
106
134
 
107
135
  export declare class AikaaraMessageBubble extends HTMLElement {
108
136
  private shadow;
137
+ private templatePayload;
138
+ private attachments;
109
139
  static get observedAttributes(): string[];
110
140
  constructor();
111
141
  connectedCallback(): void;
112
142
  attributeChangedCallback(): void;
143
+ setTemplatePayload(payload: unknown): void;
144
+ setAttachments(attachments: Array<{
145
+ fileName: string;
146
+ fileUrl: string;
147
+ }>): void;
113
148
  private render;
149
+ private renderAttachments;
114
150
  }
115
151
 
116
152
  export declare class AikaaraMessageList extends HTMLElement {
@@ -129,6 +165,13 @@ export declare class AikaaraMessageList extends HTMLElement {
129
165
  showTypingIndicator(): void;
130
166
  removeTypingIndicator(): void;
131
167
  private appendMessageElement;
168
+ /**
169
+ * Replace an existing rendered message (matched by id or externalId) in place.
170
+ * Used when a Tiledesk self-echo reconciles with an optimistic bubble or when
171
+ * a status update flips delivered → read.
172
+ */
173
+ upsertMessage(message: Message): void;
174
+ private findRenderedMessage;
132
175
  private scrollToBottom;
133
176
  private formatTime;
134
177
  }
@@ -142,6 +185,27 @@ export declare class AikaaraStreamingMessage extends HTMLElement {
142
185
  finalize(): void;
143
186
  }
144
187
 
188
+ /**
189
+ * Renders Tiledesk contentType=300 template payloads.
190
+ *
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.
196
+ */
197
+ export declare class AikaaraTemplateRenderer extends HTMLElement {
198
+ private shadow;
199
+ private payloadData;
200
+ private innerMessage;
201
+ static get observedAttributes(): string[];
202
+ constructor();
203
+ connectedCallback(): void;
204
+ attributeChangedCallback(): void;
205
+ setPayload(payload: unknown, innerMessage?: string): void;
206
+ private render;
207
+ }
208
+
145
209
  export declare class AikaaraTypingIndicator extends HTMLElement {
146
210
  private shadow;
147
211
  constructor();
@@ -172,11 +236,30 @@ declare interface ChatClientConfig extends ConnectionConfig {
172
236
  conversationId?: string;
173
237
  systemPromptId?: number;
174
238
  channel?: 'widget' | 'api' | 'sidekick';
239
+ /**
240
+ * Transport selection.
241
+ * - `aikaara` (default): ActionCable to Aikaara Rails (AI streaming).
242
+ * - `tiledesk`: MQTT direct to a self-hosted Tiledesk + chat21 stack.
243
+ * - `dual`: both — Aikaara cable for AI, Tiledesk MQTT for live-agent + file events.
244
+ */
245
+ transport?: TransportMode;
246
+ /**
247
+ * Tiledesk-side identity. Required when `transport` is `tiledesk` or `dual`.
248
+ * `userId` here is the Tiledesk user `_id` and is also used as the SDK conversation
249
+ * subject — Aikaara conversations bound to this user via ext_uid mapping.
250
+ */
251
+ tiledeskIdentity?: {
252
+ userId: string;
253
+ userName?: string;
254
+ departmentId?: string;
255
+ senderFullname?: string;
256
+ };
175
257
  onMessage?: (message: Message) => void;
176
258
  onStatusChange?: (status: string) => void;
177
259
  onError?: (error: Error) => void;
178
260
  onStreamUpdate?: (delta: string, fullContent: string) => void;
179
261
  onConnectionStateChange?: (state: ConnectionState) => void;
262
+ onTemplateMessage?: (template: TemplateMessageEvent) => void;
180
263
  }
181
264
 
182
265
  declare interface ChatClientConfig_2 extends ConnectionConfig_2 {
@@ -186,11 +269,30 @@ declare interface ChatClientConfig_2 extends ConnectionConfig_2 {
186
269
  conversationId?: string;
187
270
  systemPromptId?: number;
188
271
  channel?: 'widget' | 'api' | 'sidekick';
272
+ /**
273
+ * Transport selection.
274
+ * - `aikaara` (default): ActionCable to Aikaara Rails (AI streaming).
275
+ * - `tiledesk`: MQTT direct to a self-hosted Tiledesk + chat21 stack.
276
+ * - `dual`: both — Aikaara cable for AI, Tiledesk MQTT for live-agent + file events.
277
+ */
278
+ transport?: TransportMode_2;
279
+ /**
280
+ * Tiledesk-side identity. Required when `transport` is `tiledesk` or `dual`.
281
+ * `userId` here is the Tiledesk user `_id` and is also used as the SDK conversation
282
+ * subject — Aikaara conversations bound to this user via ext_uid mapping.
283
+ */
284
+ tiledeskIdentity?: {
285
+ userId: string;
286
+ userName?: string;
287
+ departmentId?: string;
288
+ senderFullname?: string;
289
+ };
189
290
  onMessage?: (message: Message_2) => void;
190
291
  onStatusChange?: (status: string) => void;
191
292
  onError?: (error: Error) => void;
192
293
  onStreamUpdate?: (delta: string, fullContent: string) => void;
193
294
  onConnectionStateChange?: (state: ConnectionState_2) => void;
295
+ onTemplateMessage?: (template: TemplateMessageEvent_2) => void;
194
296
  }
195
297
 
196
298
  declare interface ChatEvents {
@@ -279,7 +381,7 @@ declare interface FieldUpdate {
279
381
  declare interface Message {
280
382
  id: string;
281
383
  conversationId: string;
282
- role: 'user' | 'assistant' | 'system' | 'tool';
384
+ role: 'user' | 'assistant' | 'system' | 'tool' | 'agent';
283
385
  content: string;
284
386
  toolCalls?: ToolCall[];
285
387
  toolCallResults?: ToolCallResult;
@@ -287,13 +389,25 @@ declare interface Message {
287
389
  tokensOutput?: number;
288
390
  metadata?: Record<string, unknown>;
289
391
  createdAt: string;
290
- status?: 'sending' | 'sent' | 'streaming' | 'complete' | 'error';
392
+ status?: 'sending' | 'sent' | 'delivered' | 'read' | 'streaming' | 'complete' | 'error';
393
+ externalId?: string;
394
+ template?: {
395
+ contentType?: string;
396
+ templateId?: string;
397
+ payload?: unknown;
398
+ };
399
+ attachments?: Array<{
400
+ fileName: string;
401
+ fileUrl: string;
402
+ cloudFileId?: string;
403
+ contentType?: string;
404
+ }>;
291
405
  }
292
406
 
293
407
  declare interface Message_2 {
294
408
  id: string;
295
409
  conversationId: string;
296
- role: 'user' | 'assistant' | 'system' | 'tool';
410
+ role: 'user' | 'assistant' | 'system' | 'tool' | 'agent';
297
411
  content: string;
298
412
  toolCalls?: ToolCall_2[];
299
413
  toolCallResults?: ToolCallResult_2;
@@ -301,7 +415,19 @@ declare interface Message_2 {
301
415
  tokensOutput?: number;
302
416
  metadata?: Record<string, unknown>;
303
417
  createdAt: string;
304
- status?: 'sending' | 'sent' | 'streaming' | 'complete' | 'error';
418
+ status?: 'sending' | 'sent' | 'delivered' | 'read' | 'streaming' | 'complete' | 'error';
419
+ externalId?: string;
420
+ template?: {
421
+ contentType?: string;
422
+ templateId?: string;
423
+ payload?: unknown;
424
+ };
425
+ attachments?: Array<{
426
+ fileName: string;
427
+ fileUrl: string;
428
+ cloudFileId?: string;
429
+ contentType?: string;
430
+ }>;
305
431
  }
306
432
 
307
433
  declare interface NavigateAction {
@@ -314,18 +440,112 @@ declare interface SaveEntityAction {
314
440
  action: 'save_entity';
315
441
  }
316
442
 
443
+ declare interface TemplateMessageEvent {
444
+ messageId: string;
445
+ conversationId: string;
446
+ role: 'user' | 'assistant' | 'system' | 'agent';
447
+ contentType?: string;
448
+ templateId?: string;
449
+ payload?: unknown;
450
+ innerMessage?: string;
451
+ raw: unknown;
452
+ }
453
+
454
+ declare interface TemplateMessageEvent_2 {
455
+ messageId: string;
456
+ conversationId: string;
457
+ role: 'user' | 'assistant' | 'system' | 'agent';
458
+ contentType?: string;
459
+ templateId?: string;
460
+ payload?: unknown;
461
+ innerMessage?: string;
462
+ raw: unknown;
463
+ }
464
+
317
465
  declare interface TestToolAction {
318
466
  action: 'test_tool';
319
467
  tool_id: number;
320
468
  parameters: Record<string, unknown>;
321
469
  }
322
470
 
471
+ declare interface TiledeskFileTemplateConfig {
472
+ templateId: string;
473
+ headerImgSrc?: string;
474
+ type?: 'link' | 'image';
475
+ isDeepLink?: boolean;
476
+ }
477
+
478
+ declare interface TiledeskFileTemplateConfig_2 {
479
+ templateId: string;
480
+ headerImgSrc?: string;
481
+ type?: 'link' | 'image';
482
+ isDeepLink?: boolean;
483
+ }
484
+
485
+ declare interface TiledeskMessageDefaults {
486
+ channelType?: string;
487
+ channel?: string;
488
+ requestChannel?: string;
489
+ platform?: string;
490
+ medium?: string;
491
+ departmentId?: string;
492
+ attributes?: Record<string, unknown>;
493
+ }
494
+
495
+ declare interface TiledeskMessageDefaults_2 {
496
+ channelType?: string;
497
+ channel?: string;
498
+ requestChannel?: string;
499
+ platform?: string;
500
+ medium?: string;
501
+ departmentId?: string;
502
+ attributes?: Record<string, unknown>;
503
+ }
504
+
505
+ declare interface TiledeskTopicTemplates {
506
+ inbound?: string;
507
+ inboundUpdate?: string;
508
+ outbound?: string;
509
+ presence?: string;
510
+ wildcardSubscribe?: string;
511
+ }
512
+
513
+ declare interface TiledeskTopicTemplates_2 {
514
+ inbound?: string;
515
+ inboundUpdate?: string;
516
+ outbound?: string;
517
+ presence?: string;
518
+ wildcardSubscribe?: string;
519
+ }
520
+
323
521
  declare interface TiledeskTransportConfig {
324
522
  mqttEndpoint: string;
325
523
  jwtToken: string;
326
524
  userId: string;
327
525
  userName?: string;
328
526
  projectId: string;
527
+ appId?: string;
528
+ clientId?: string;
529
+ protocolVersion?: 3 | 4 | 5;
530
+ protocolId?: 'MQIsdp' | 'MQTT';
531
+ mqttUsername?: string;
532
+ connectTimeoutMs?: number;
533
+ keepAliveSec?: number;
534
+ maxReconnectAttempts?: number;
535
+ reconnectMaxDelayMs?: number;
536
+ tokenProvider?: () => Promise<string>;
537
+ wildcardSubscribe?: boolean;
538
+ subscribeQos?: 0 | 1 | 2;
539
+ publishQos?: 0 | 1 | 2;
540
+ publishRetain?: boolean;
541
+ enablePresence?: boolean;
542
+ presencePayloadConnected?: Record<string, unknown>;
543
+ presencePayloadDisconnected?: Record<string, unknown>;
544
+ topicTemplates?: TiledeskTopicTemplates;
545
+ messageDefaults?: TiledeskMessageDefaults;
546
+ fileTemplate?: TiledeskFileTemplateConfig;
547
+ recipientFullnameResolver?: (conversationId: string) => string | undefined;
548
+ senderFullname?: string;
329
549
  }
330
550
 
331
551
  declare interface TiledeskTransportConfig_2 {
@@ -334,6 +554,28 @@ declare interface TiledeskTransportConfig_2 {
334
554
  userId: string;
335
555
  userName?: string;
336
556
  projectId: string;
557
+ appId?: string;
558
+ clientId?: string;
559
+ protocolVersion?: 3 | 4 | 5;
560
+ protocolId?: 'MQIsdp' | 'MQTT';
561
+ mqttUsername?: string;
562
+ connectTimeoutMs?: number;
563
+ keepAliveSec?: number;
564
+ maxReconnectAttempts?: number;
565
+ reconnectMaxDelayMs?: number;
566
+ tokenProvider?: () => Promise<string>;
567
+ wildcardSubscribe?: boolean;
568
+ subscribeQos?: 0 | 1 | 2;
569
+ publishQos?: 0 | 1 | 2;
570
+ publishRetain?: boolean;
571
+ enablePresence?: boolean;
572
+ presencePayloadConnected?: Record<string, unknown>;
573
+ presencePayloadDisconnected?: Record<string, unknown>;
574
+ topicTemplates?: TiledeskTopicTemplates_2;
575
+ messageDefaults?: TiledeskMessageDefaults_2;
576
+ fileTemplate?: TiledeskFileTemplateConfig_2;
577
+ recipientFullnameResolver?: (conversationId: string) => string | undefined;
578
+ senderFullname?: string;
337
579
  }
338
580
 
339
581
  declare interface ToolCall {
@@ -364,6 +606,52 @@ declare interface ToolCallResult_2 {
364
606
  content: string;
365
607
  }
366
608
 
609
+ declare type TransportMode = 'aikaara' | 'tiledesk' | 'dual';
610
+
611
+ declare type TransportMode_2 = 'aikaara' | 'tiledesk' | 'dual';
612
+
613
+ declare interface UploadAdapter {
614
+ upload(file: File | Blob, ctx: UploadAdapterContext): Promise<UploadAdapterResult>;
615
+ }
616
+
617
+ declare interface UploadAdapter_2 {
618
+ upload(file: File | Blob, ctx: UploadAdapterContext_2): Promise<UploadAdapterResult_2>;
619
+ }
620
+
621
+ declare interface UploadAdapterContext {
622
+ conversationId: string;
623
+ userId: string;
624
+ projectId?: string;
625
+ appId?: string;
626
+ }
627
+
628
+ declare interface UploadAdapterContext_2 {
629
+ conversationId: string;
630
+ userId: string;
631
+ projectId?: string;
632
+ appId?: string;
633
+ }
634
+
635
+ declare interface UploadAdapterResult {
636
+ url: string;
637
+ fileName: string;
638
+ cloudFileId?: string;
639
+ relativePath?: string;
640
+ contentType?: string;
641
+ byteSize?: number;
642
+ meta?: Record<string, unknown>;
643
+ }
644
+
645
+ declare interface UploadAdapterResult_2 {
646
+ url: string;
647
+ fileName: string;
648
+ cloudFileId?: string;
649
+ relativePath?: string;
650
+ contentType?: string;
651
+ byteSize?: number;
652
+ meta?: Record<string, unknown>;
653
+ }
654
+
367
655
  declare interface WidgetConfig extends ChatClientConfig {
368
656
  position?: 'bottom-right' | 'bottom-left';
369
657
  offset?: {
@@ -386,6 +674,7 @@ declare interface WidgetConfig extends ChatClientConfig {
386
674
  showBubble?: boolean;
387
675
  bubbleText?: string;
388
676
  bubbleIcon?: string;
677
+ uploadAdapter?: UploadAdapter;
389
678
  }
390
679
 
391
680
  export { }