@aikaara/chat-sdk 0.3.3 → 0.4.1
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/{cdn/aikaara-chat.iife.js → MountTenant-B4Py61gI.cjs} +33 -33
- package/dist/{ui-BMGa0gZH.mjs → MountTenant-DT5Vr6Yr.mjs} +4415 -3957
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.ts +175 -0
- package/dist/headless.mjs +54 -251
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +175 -0
- package/dist/index.mjs +31 -28
- package/dist/ui.cjs +1 -1
- package/dist/ui.d.ts +34 -0
- package/dist/ui.mjs +14 -13
- package/package.json +1 -1
- package/dist/ui-B0-Np9Dn.cjs +0 -792
package/dist/index.d.ts
CHANGED
|
@@ -445,6 +445,8 @@ declare interface CreateConversationResponse {
|
|
|
445
445
|
|
|
446
446
|
export declare function createFetchUploadAdapter(config: FetchUploadAdapterConfig): UploadAdapter;
|
|
447
447
|
|
|
448
|
+
export declare function createPresigned3StepUploadAdapter(config: Presigned3StepAdapterConfig): UploadAdapter;
|
|
449
|
+
|
|
448
450
|
export declare function createTiledeskHistoryAdapter(config: TiledeskHistoryAdapterConfig): ConversationHistoryAdapter;
|
|
449
451
|
|
|
450
452
|
export declare interface EditEntityAction {
|
|
@@ -675,6 +677,22 @@ export declare interface MountedTenantWidget {
|
|
|
675
677
|
destroy: () => void;
|
|
676
678
|
}
|
|
677
679
|
|
|
680
|
+
/**
|
|
681
|
+
* Single-call mount. Pulls the descriptor from `widget_configs/:slug`, runs
|
|
682
|
+
* descriptor.auth to mint chat JWT + requestId, builds upload + history
|
|
683
|
+
* adapters from descriptor.upload, and mounts the web component. Host app
|
|
684
|
+
* supplies only the user id + their session JWT.
|
|
685
|
+
*
|
|
686
|
+
* import { mountFromSlug } from '@aikaara/chat-sdk';
|
|
687
|
+
*
|
|
688
|
+
* await mountFromSlug({
|
|
689
|
+
* container: '#chat',
|
|
690
|
+
* slug: 'bandhan-itr',
|
|
691
|
+
* user: { id: '33568', token: () => getCognitoJwt() },
|
|
692
|
+
* });
|
|
693
|
+
*/
|
|
694
|
+
export declare function mountFromSlug(opts: SlugMountOptions): Promise<SlugMountedWidget>;
|
|
695
|
+
|
|
678
696
|
/**
|
|
679
697
|
* Standard tenant mount. Fetches the descriptor (when `configUrl` is set),
|
|
680
698
|
* merges per-mount overrides, builds default adapters from the descriptor's
|
|
@@ -688,12 +706,147 @@ export declare interface NavigateAction {
|
|
|
688
706
|
|
|
689
707
|
export declare function parseTiledeskTemplate(message: TiledeskMessage): TiledeskParsedTemplate;
|
|
690
708
|
|
|
709
|
+
/**
|
|
710
|
+
* Three-step presigned-S3 upload (sign → PUT → register). Driven entirely
|
|
711
|
+
* by descriptor — no tenant-specific code in host apps.
|
|
712
|
+
*/
|
|
713
|
+
export declare interface Presigned3StepAdapterConfig {
|
|
714
|
+
/** GET endpoint that returns a presigned URL. `{fileName}` placeholder. */
|
|
715
|
+
signEndpoint: string;
|
|
716
|
+
signMethod?: 'GET' | 'POST';
|
|
717
|
+
/** Dot path into the response JSON for the presigned URL. Default `data.s3SignedUrl`. */
|
|
718
|
+
signedUrlPath?: string;
|
|
719
|
+
/** Optional POST registering the upload (e.g. `/chatbuddy/file-upload`). */
|
|
720
|
+
registerEndpoint?: string;
|
|
721
|
+
/**
|
|
722
|
+
* Body JSON for the register POST. Tokens: `{fileName}`, `{userId}`,
|
|
723
|
+
* `{requestId}` (alias `{conversationId}`).
|
|
724
|
+
*/
|
|
725
|
+
registerBody?: Record<string, unknown>;
|
|
726
|
+
/**
|
|
727
|
+
* Final URL the chat message will carry. Tokens: `{fileName}`, `{userId}`,
|
|
728
|
+
* `{requestId}`. When omitted the presigned URL itself is used.
|
|
729
|
+
*/
|
|
730
|
+
viewerTemplate?: string;
|
|
731
|
+
/**
|
|
732
|
+
* Rewrite the host portion of the presigned URL before PUTting (used for
|
|
733
|
+
* dev proxies). E.g. `/s3-upload`. Leave empty for direct.
|
|
734
|
+
*/
|
|
735
|
+
s3HostRewrite?: string;
|
|
736
|
+
/** Bearer token getter for sign + register calls. */
|
|
737
|
+
authHeader?: () => string | Promise<string>;
|
|
738
|
+
/** Static extra headers for sign + register. */
|
|
739
|
+
extraHeaders?: Record<string, string>;
|
|
740
|
+
}
|
|
741
|
+
|
|
691
742
|
export declare function registerComponents(): void;
|
|
692
743
|
|
|
693
744
|
export declare interface SaveEntityAction {
|
|
694
745
|
action: 'save_entity';
|
|
695
746
|
}
|
|
696
747
|
|
|
748
|
+
export declare class SessionAuthAdapter {
|
|
749
|
+
private readonly descriptor;
|
|
750
|
+
private readonly sessionToken;
|
|
751
|
+
private cache;
|
|
752
|
+
private inflight;
|
|
753
|
+
constructor(descriptor: SessionAuthDescriptor, sessionToken: SessionTokenProvider);
|
|
754
|
+
/** Force-refresh by clearing cache. Next `get()` call refetches. */
|
|
755
|
+
reset(): void;
|
|
756
|
+
get(): Promise<SessionAuthData>;
|
|
757
|
+
private fetchOnce;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
export declare interface SessionAuthData {
|
|
761
|
+
token: string;
|
|
762
|
+
requestId: string;
|
|
763
|
+
fullName: string;
|
|
764
|
+
expiresAt: number;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Descriptor-driven session auth.
|
|
769
|
+
*
|
|
770
|
+
* The host app supplies a "session token" — typically a JWT issued by their
|
|
771
|
+
* own auth (Cognito/Auth0/firebase/etc) — and the descriptor declares how to
|
|
772
|
+
* exchange it for a chat-platform JWT + conversation requestId. The SDK runs
|
|
773
|
+
* the exchange itself, caches the result, and refreshes when the chat JWT
|
|
774
|
+
* approaches expiry. The original requestId is preserved across refreshes so
|
|
775
|
+
* the conversation thread is stable.
|
|
776
|
+
*/
|
|
777
|
+
export declare interface SessionAuthDescriptor {
|
|
778
|
+
/** Absolute or same-origin URL — POSTed with the session token as bearer. */
|
|
779
|
+
endpoint: string;
|
|
780
|
+
method?: 'POST' | 'GET';
|
|
781
|
+
/** JSON body for the request. POST only. */
|
|
782
|
+
body?: Record<string, unknown>;
|
|
783
|
+
/** Extra static headers (e.g. partnerid). */
|
|
784
|
+
headers?: Record<string, string>;
|
|
785
|
+
/** Header carrying the session token. Default `Authorization`. */
|
|
786
|
+
authHeader?: string;
|
|
787
|
+
/**
|
|
788
|
+
* Template for the session-token header value. `{token}` is replaced.
|
|
789
|
+
* Default: `Bearer {token}`. Use `JWT {token}` etc. when required.
|
|
790
|
+
*/
|
|
791
|
+
authHeaderTemplate?: string;
|
|
792
|
+
/** Dot path into the response JSON for the chat JWT. Default `data.token`. */
|
|
793
|
+
tokenPath?: string;
|
|
794
|
+
/** Stripped from the extracted token before use (e.g. `JWT `). */
|
|
795
|
+
tokenStripPrefix?: string;
|
|
796
|
+
/** Dot path for the conversation requestId. Default `data.requestId`. */
|
|
797
|
+
requestIdPath?: string;
|
|
798
|
+
/** Dot path for the user display name. Default `data.fullName`. */
|
|
799
|
+
fullNamePath?: string;
|
|
800
|
+
/** Refetch when the JWT is within this many ms of expiry. Default 60_000. */
|
|
801
|
+
expiryBufferMs?: number;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
export declare type SessionTokenProvider = string | (() => string | Promise<string>);
|
|
805
|
+
|
|
806
|
+
export declare interface SlugMountedWidget extends MountedTenantWidget {
|
|
807
|
+
fullName: string;
|
|
808
|
+
/** Force a fresh /chatbuddy/auth-style refetch (clears cached requestId). */
|
|
809
|
+
refreshAuth(): Promise<void>;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
export declare interface SlugMountOptions {
|
|
813
|
+
/** Container element or CSS selector (e.g. `#chat`). */
|
|
814
|
+
container: HTMLElement | string;
|
|
815
|
+
/** Tenant identifier — the SDK fetches `${configBase}/widget_configs/${slug}`. */
|
|
816
|
+
slug: string;
|
|
817
|
+
/** Defaults to `https://api.aikaara.com`. Override for self-hosted aikaara. */
|
|
818
|
+
configBase?: string;
|
|
819
|
+
/** Additional headers for the descriptor fetch. */
|
|
820
|
+
configHeaders?: Record<string, string>;
|
|
821
|
+
user: {
|
|
822
|
+
id: string;
|
|
823
|
+
/** Display name fallback when descriptor.auth doesn't return one. */
|
|
824
|
+
name?: string;
|
|
825
|
+
departmentId?: string;
|
|
826
|
+
/**
|
|
827
|
+
* Session JWT (Cognito/Auth0/firebase/etc) — passed as bearer to
|
|
828
|
+
* `descriptor.auth.endpoint`. Can be a string (static for the session)
|
|
829
|
+
* or a getter that re-resolves on each refresh.
|
|
830
|
+
*/
|
|
831
|
+
token: SessionTokenProvider;
|
|
832
|
+
};
|
|
833
|
+
/** Optional escape hatches; merge over descriptor-driven defaults. */
|
|
834
|
+
hooks?: {
|
|
835
|
+
upload?: UploadAdapter;
|
|
836
|
+
history?: ConversationHistoryAdapter;
|
|
837
|
+
onError?: (err: Error) => void;
|
|
838
|
+
};
|
|
839
|
+
/** Per-mount visual overrides. */
|
|
840
|
+
overrides?: Partial<WidgetConfigDescriptor>;
|
|
841
|
+
/**
|
|
842
|
+
* Inline descriptor used when the slug fetch fails (e.g. 404, network
|
|
843
|
+
* error). Lets host apps ship without requiring the aikaara backend to be
|
|
844
|
+
* seeded — useful for demos / first-run / offline dev. When the fetch
|
|
845
|
+
* succeeds the response wins; this is purely a safety net.
|
|
846
|
+
*/
|
|
847
|
+
fallbackConfig?: WidgetConfigDescriptor;
|
|
848
|
+
}
|
|
849
|
+
|
|
697
850
|
declare type SubscriptionCallback = (data: unknown) => void;
|
|
698
851
|
|
|
699
852
|
declare interface TemplateMessageEvent {
|
|
@@ -1099,6 +1252,28 @@ export declare interface WidgetConfigDescriptor {
|
|
|
1099
1252
|
historyApiBase?: string;
|
|
1100
1253
|
historyPageSize?: number;
|
|
1101
1254
|
historyPathTemplate?: string;
|
|
1255
|
+
/**
|
|
1256
|
+
* Server-side session-token exchange. When set, the SDK exchanges the
|
|
1257
|
+
* caller-supplied `sessionToken` for a chat JWT + conversation requestId
|
|
1258
|
+
* itself — the host app no longer needs a `tokenProvider` callback.
|
|
1259
|
+
*/
|
|
1260
|
+
auth?: SessionAuthDescriptor;
|
|
1261
|
+
/**
|
|
1262
|
+
* Built-in upload strategy. `mode: "presigned-3step"` runs sign → PUT →
|
|
1263
|
+
* register entirely from descriptor config; `mode: "direct"` POSTs as
|
|
1264
|
+
* multipart to a single endpoint; `mode: "none"` disables uploads. Host
|
|
1265
|
+
* apps can still override with `opts.uploadAdapter`.
|
|
1266
|
+
*/
|
|
1267
|
+
upload?: {
|
|
1268
|
+
mode: 'none';
|
|
1269
|
+
} | {
|
|
1270
|
+
mode: 'direct';
|
|
1271
|
+
endpoint: string;
|
|
1272
|
+
fieldName?: string;
|
|
1273
|
+
extraFields?: Record<string, string>;
|
|
1274
|
+
} | ({
|
|
1275
|
+
mode: 'presigned-3step';
|
|
1276
|
+
} & Presigned3StepAdapterConfig);
|
|
1102
1277
|
}
|
|
1103
1278
|
|
|
1104
1279
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { r as o } from "./
|
|
2
|
-
import { A as
|
|
3
|
-
import { FormBridge as
|
|
1
|
+
import { r as o } from "./MountTenant-DT5Vr6Yr.mjs";
|
|
2
|
+
import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as b, h as f, i as T, j as v, k as S, C as w, l as y, m as M, E, M as x, S as B, T as F, n as U, o as I, p as j, q, s as H, t as P, u as W, v as K, w as L, x as O } from "./MountTenant-DT5Vr6Yr.mjs";
|
|
3
|
+
import { FormBridge as z } from "./headless.mjs";
|
|
4
4
|
function l(e) {
|
|
5
5
|
o();
|
|
6
6
|
const a = document.createElement("aikaara-chat-widget"), r = {
|
|
@@ -18,9 +18,9 @@ function l(e) {
|
|
|
18
18
|
welcomeMessage: "welcome-message",
|
|
19
19
|
avatarUrl: "avatar-url"
|
|
20
20
|
};
|
|
21
|
-
for (const [
|
|
22
|
-
const t = e[
|
|
23
|
-
t != null && a.setAttribute(
|
|
21
|
+
for (const [s, i] of Object.entries(r)) {
|
|
22
|
+
const t = e[s];
|
|
23
|
+
t != null && a.setAttribute(i, String(t));
|
|
24
24
|
}
|
|
25
25
|
return a.configure(e), document.body.appendChild(a), a;
|
|
26
26
|
}
|
|
@@ -29,34 +29,37 @@ function d() {
|
|
|
29
29
|
e && e.remove();
|
|
30
30
|
}
|
|
31
31
|
export {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
u as ActionCableClient,
|
|
33
|
+
m as AikaaraChatBubble,
|
|
34
|
+
g as AikaaraChatClient,
|
|
35
|
+
h as AikaaraChatHeader,
|
|
36
|
+
k as AikaaraChatInput,
|
|
37
|
+
A as AikaaraChatWidget,
|
|
38
|
+
C as AikaaraErrorBanner,
|
|
39
39
|
b as AikaaraMessageBubble,
|
|
40
40
|
f as AikaaraMessageList,
|
|
41
41
|
T as AikaaraStreamingMessage,
|
|
42
42
|
v as AikaaraTypingIndicator,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
S as ApiClient,
|
|
44
|
+
w as ChannelSubscription,
|
|
45
|
+
y as ConnectionManager,
|
|
46
|
+
M as ConversationManager,
|
|
47
|
+
E as EventEmitter,
|
|
48
|
+
z as FormBridge,
|
|
49
49
|
x as MessageStore,
|
|
50
|
-
B as
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
B as SessionAuthAdapter,
|
|
51
|
+
F as TiledeskTransport,
|
|
52
|
+
U as clearPersistedConversationId,
|
|
53
|
+
I as createFetchUploadAdapter,
|
|
54
|
+
j as createPresigned3StepUploadAdapter,
|
|
55
|
+
q as createTiledeskHistoryAdapter,
|
|
56
|
+
H as extractTiledeskFileEnvelope,
|
|
57
|
+
P as inferTiledeskRole,
|
|
58
|
+
W as isTiledeskSelfEcho,
|
|
57
59
|
l as mount,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
K as mountFromSlug,
|
|
61
|
+
L as mountTenantWidget,
|
|
62
|
+
O as parseTiledeskTemplate,
|
|
60
63
|
o as registerComponents,
|
|
61
64
|
d as unmount
|
|
62
65
|
};
|
package/dist/ui.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-B4Py61gI.cjs");exports.AikaaraChat=a.AikaaraChat;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraModalAction=a.AikaaraModalAction;exports.AikaaraOptionList=a.AikaaraOptionList;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraSubmitAction=a.AikaaraSubmitAction;exports.AikaaraSystemPill=a.AikaaraSystemPill;exports.AikaaraTemplateRenderer=a.AikaaraTemplateRenderer;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;
|
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();
|
package/dist/ui.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { y as i, a as s, c as e, d as t, e as A, f as k, g as n, h as o, z as g, B as d, i as h, D as l, F as m, G as p, j as C, r as b } from "./MountTenant-DT5Vr6Yr.mjs";
|
|
2
2
|
export {
|
|
3
|
-
i as
|
|
4
|
-
s as
|
|
5
|
-
e as
|
|
6
|
-
t as
|
|
7
|
-
A as
|
|
8
|
-
k as
|
|
9
|
-
n as
|
|
10
|
-
o as
|
|
11
|
-
g as
|
|
12
|
-
d as
|
|
3
|
+
i as AikaaraChat,
|
|
4
|
+
s as AikaaraChatBubble,
|
|
5
|
+
e as AikaaraChatHeader,
|
|
6
|
+
t as AikaaraChatInput,
|
|
7
|
+
A as AikaaraChatWidget,
|
|
8
|
+
k as AikaaraErrorBanner,
|
|
9
|
+
n as AikaaraMessageBubble,
|
|
10
|
+
o as AikaaraMessageList,
|
|
11
|
+
g as AikaaraModalAction,
|
|
12
|
+
d as AikaaraOptionList,
|
|
13
|
+
h as AikaaraStreamingMessage,
|
|
13
14
|
l as AikaaraSubmitAction,
|
|
14
15
|
m as AikaaraSystemPill,
|
|
15
16
|
p as AikaaraTemplateRenderer,
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
C as AikaaraTypingIndicator,
|
|
18
|
+
b as registerComponents
|
|
18
19
|
};
|