@aikaara/chat-sdk 0.8.1 → 0.8.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
@@ -292,8 +292,18 @@ export declare class ApiClient {
292
292
  private baseUrl;
293
293
  private apiKey?;
294
294
  private authToken?;
295
- private userToken;
295
+ protected userToken: string;
296
+ private refreshHook;
296
297
  constructor(baseUrl: string, userToken: string, apiKey?: string, authToken?: string);
298
+ /**
299
+ * Install a refresh hook. When a request returns 401 the client invokes
300
+ * the hook, replaces its in-memory `authToken`, and retries exactly once.
301
+ */
302
+ setAuthRefreshHook(hook: AuthRefreshHook | null): void;
303
+ /** Surface the current bearer (e.g. for upload adapters that share it). */
304
+ getAuthToken(): string | undefined;
305
+ /** Replace the bearer used by subsequent requests. */
306
+ setAuthToken(next: string | undefined): void;
297
307
  createConversation(params: {
298
308
  systemPromptId?: number;
299
309
  channel?: string;
@@ -304,8 +314,17 @@ export declare class ApiClient {
304
314
  getMessages(conversationId: string): Promise<Message[]>;
305
315
  private mapMessage;
306
316
  private request;
317
+ private fetchWithHeaders;
307
318
  }
308
319
 
320
+ export declare type ApiPanelFieldFormat = 'text' | 'currency' | 'date' | 'number';
321
+
322
+ export declare type ApiPanelRefresh = 'load' | 'assistant' | 'interval' | '30s' | '5m' | 'manual';
323
+
324
+ export declare type ApiPanelRender = 'fields' | 'steps';
325
+
326
+ export declare type ApiPanelSource = 'api' | 'paste';
327
+
309
328
  export declare interface AppContext {
310
329
  /** Current page/route path in the host app (e.g., '/products/42') */
311
330
  currentPage: string;
@@ -321,6 +340,30 @@ export declare interface AppContext {
321
340
  custom?: Record<string, unknown>;
322
341
  }
323
342
 
343
+ /**
344
+ * Static page metadata written by the dashboard's App Layout tab.
345
+ * The hosted-shell renders top/bottom nav from this list; SDK code
346
+ * doesn't consume it.
347
+ */
348
+ export declare interface AppPageDef {
349
+ id: string;
350
+ name: string;
351
+ /** Icon name from the shell's icon set (Chat, Sparkle, Book, …). */
352
+ icon?: string;
353
+ /** `"chat"` (default surface) or `"static"` (placeholder). */
354
+ kind?: 'chat' | 'static';
355
+ hint?: string;
356
+ }
357
+
358
+ /**
359
+ * Hook the API client uses to recover from a 401. Wired up by the higher
360
+ * level mount when `descriptor.sso.autoRefresh === true`: the discovered
361
+ * partner token is re-read, exchanged for a fresh chat JWT, and the
362
+ * `authToken` field below is updated in place so the retry sends the new
363
+ * bearer. Returning `null` (or throwing) lets the original 401 propagate.
364
+ */
365
+ declare type AuthRefreshHook = () => Promise<string | null>;
366
+
324
367
  export declare class ChannelSubscription {
325
368
  readonly identifier: string;
326
369
  private callbacks;
@@ -475,6 +518,16 @@ export declare class ConversationManager {
475
518
  private saveToStorage;
476
519
  }
477
520
 
521
+ export declare interface CookieSourceConfig {
522
+ /** Cookie name. */
523
+ name?: string;
524
+ /**
525
+ * Informational only. The browser enforces the actual domain scope; we
526
+ * surface this so dashboards can document intent.
527
+ */
528
+ domain?: string;
529
+ }
530
+
478
531
  declare interface CreateConversationResponse {
479
532
  id: string;
480
533
  status: string;
@@ -488,6 +541,23 @@ export declare function createTiledeskHistoryAdapter(config: TiledeskHistoryAdap
488
541
 
489
542
  export declare type CredentialProviders = Record<string, () => string | Promise<string>>;
490
543
 
544
+ export declare interface DiscoveredToken {
545
+ /** The raw partner token. */
546
+ token: string;
547
+ /** Echoed so callers can log + alert when the source changes mid-flow. */
548
+ source: TokenSourceKind;
549
+ }
550
+
551
+ /**
552
+ * Dispatcher. Resolves the partner token according to
553
+ * `descriptor.tokenSource`. Returns a Promise so async-only sources
554
+ * (`postmsg`, `global`) share the same surface as synchronous ones.
555
+ *
556
+ * Throws when the token can't be found — callers decide whether to
557
+ * fall back to a login screen (per `descriptor.fallback`).
558
+ */
559
+ export declare function discoverToken(opts: TokenDiscoveryOptions): Promise<DiscoveredToken>;
560
+
491
561
  export declare interface EditEntityAction {
492
562
  action: 'edit_entity';
493
563
  entity_type: string;
@@ -665,8 +735,25 @@ export declare interface FormRegistration {
665
735
  getCurrentValues: () => Record<string, unknown>;
666
736
  }
667
737
 
738
+ export declare interface GlobalSourceConfig {
739
+ /** Dot-path into `window` (e.g. `"PartnerSDK.session.token"`). */
740
+ path?: string;
741
+ /** Max poll time in ms (default 2000). */
742
+ timeoutMs?: number;
743
+ /** Poll interval in ms (default 100). */
744
+ intervalMs?: number;
745
+ }
746
+
747
+ export declare interface HashSourceConfig {
748
+ /** Hash key (after `#…&key=value&…`). Default `"token"`. */
749
+ key?: string;
750
+ }
751
+
668
752
  export declare function inferTiledeskRole(message: TiledeskMessage, cfg: TiledeskRoleConfig): TiledeskRole;
669
753
 
754
+ export declare interface InitSourceConfig {
755
+ }
756
+
670
757
  /**
671
758
  * Self-echo detector — Tiledesk fans the user's outgoing publish back
672
759
  * as a `clientadded` event on the same connection. UI must dedupe against
@@ -802,6 +889,21 @@ export declare interface NavigateAction {
802
889
 
803
890
  export declare function parseTiledeskTemplate(message: TiledeskMessage): TiledeskParsedTemplate;
804
891
 
892
+ export declare interface PostMsgSourceConfig {
893
+ /** Message envelope `type` field that gates which postMessage we accept. */
894
+ type?: string;
895
+ /** Property inside `event.data` carrying the token. Default `"token"`. */
896
+ key?: string;
897
+ /**
898
+ * Allowed origins (comma-separated or single string). When set, messages
899
+ * from any other origin are ignored. When unset every origin is accepted
900
+ * — partners are encouraged to set this in production.
901
+ */
902
+ origins?: string;
903
+ /** Milliseconds to wait before rejecting. Default 30_000. */
904
+ timeoutMs?: number;
905
+ }
906
+
805
907
  /**
806
908
  * One HTTP call run by the SDK before auth. Failure of `soft: true` steps
807
909
  * is logged and ignored; failure of strict steps aborts the mount.
@@ -851,8 +953,68 @@ export declare interface Presigned3StepAdapterConfig {
851
953
  extraHeaders?: Record<string, string>;
852
954
  }
853
955
 
956
+ export declare interface QuerySourceConfig {
957
+ /** Query-string parameter name. Default `"token"`. */
958
+ key?: string;
959
+ }
960
+
854
961
  export declare function registerComponents(): void;
855
962
 
963
+ /**
964
+ * One slot's component pointer. The `kind` discriminator picks which
965
+ * loader runs. Both kinds resolve to a `Promise<HTMLElement>` after load,
966
+ * which the runtime appends into the slot anchor.
967
+ */
968
+ export declare type RemoteComponent = {
969
+ kind: 'iife-element';
970
+ /** URL of an IIFE bundle that calls `customElements.define(tag, …)`. */
971
+ scriptUrl: string;
972
+ /** Custom-element tag the bundle registers. */
973
+ tag: string;
974
+ /** Optional method-call map: `{ setLayout: "stacked" }` becomes
975
+ * `el.setLayout("stacked")` after mount. */
976
+ props?: Record<string, unknown>;
977
+ } | {
978
+ kind: 'remote-dom';
979
+ /** URL of an IIFE bundle that, when executed, leaves a global at
980
+ * `globalName` exposing `mount({ target, ctx, complete, props })`.
981
+ * Authored via `@aikaara/chat-sdk/remote-author`. */
982
+ scriptUrl: string;
983
+ /** Optional global name; defaults to the slot id with non-alphanumeric
984
+ * chars replaced by underscores (e.g. "screen:login" → "screen_login"). */
985
+ globalName?: string;
986
+ /** Sandbox kind. Today only `iframe`; `worker` reserved for later. */
987
+ sandbox?: 'iframe' | 'worker';
988
+ /** Forwarded to the bundle's `mount({ props })` call. */
989
+ props?: Record<string, unknown>;
990
+ };
991
+
992
+ /**
993
+ * One route in `descriptor.app.routes`.
994
+ *
995
+ * `path` is matched against the URL pathname AFTER the tenant's slug
996
+ * prefix is stripped (in subpath mode). Supports trailing wildcards (`/*`)
997
+ * and named params (`/:id`) — the parser is intentionally tiny.
998
+ *
999
+ * `component` references a slot in `descriptor.components`.
1000
+ *
1001
+ * `guards` are simple predicate names the shell evaluates against runtime
1002
+ * session state. Today: `'sso'` (SSO exchange done), `'authed'` (user
1003
+ * has any session), `'panVerified'` (PAN flow finished). Tenants can
1004
+ * extend by exposing flags via `complete(payload)` from preceding screens.
1005
+ *
1006
+ * `redirectIfFails` lets a guard send the user to another route id
1007
+ * instead of erroring. Useful for `'authed'` failing → redirect to login.
1008
+ */
1009
+ export declare interface RouteDef {
1010
+ path: string;
1011
+ component: string;
1012
+ guards?: string[];
1013
+ redirectIfFails?: string;
1014
+ /** Optional layout slot wrapping this route's component. */
1015
+ layout?: string;
1016
+ }
1017
+
856
1018
  export declare interface SaveEntityAction {
857
1019
  action: 'save_entity';
858
1020
  }
@@ -915,6 +1077,41 @@ export declare interface SessionAuthDescriptor {
915
1077
 
916
1078
  export declare type SessionTokenProvider = string | (() => string | Promise<string>);
917
1079
 
1080
+ export declare interface SidePanelDef {
1081
+ enabled?: boolean;
1082
+ type: SidePanelType;
1083
+ title?: string;
1084
+ mobile?: SidePanelMobile;
1085
+ steps?: Array<{
1086
+ name: string;
1087
+ hint?: string;
1088
+ }>;
1089
+ emptyText?: string;
1090
+ allowUpload?: boolean;
1091
+ summaryFields?: string[];
1092
+ supportPhone?: string;
1093
+ supportHours?: string;
1094
+ showHumanHandoff?: boolean;
1095
+ source?: ApiPanelSource;
1096
+ endpoint?: string;
1097
+ sampleJson?: string;
1098
+ refresh?: ApiPanelRefresh;
1099
+ intervalSec?: number;
1100
+ render?: ApiPanelRender;
1101
+ fields?: Array<{
1102
+ label: string;
1103
+ path: string;
1104
+ format?: ApiPanelFieldFormat;
1105
+ }>;
1106
+ stepsPath?: string;
1107
+ stepStatusKey?: string;
1108
+ customUrl?: string;
1109
+ }
1110
+
1111
+ export declare type SidePanelMobile = 'drawer' | 'hidden';
1112
+
1113
+ export declare type SidePanelType = 'steps' | 'files' | 'summary' | 'support' | 'api' | 'custom';
1114
+
918
1115
  export declare interface SlugMountedWidget extends MountedTenantWidget {
919
1116
  fullName: string;
920
1117
  /** Resolved descriptor (fallback ⊕ fetched ⊕ overrides). Host reads
@@ -922,6 +1119,13 @@ export declare interface SlugMountedWidget extends MountedTenantWidget {
922
1119
  descriptor: WidgetConfigDescriptor;
923
1120
  /** Force a fresh /chatbuddy/auth-style refetch (clears cached requestId). */
924
1121
  refreshAuth(): Promise<void>;
1122
+ /**
1123
+ * Re-discover the partner token (per `descriptor.sso.tokenSource`) and
1124
+ * re-exchange for a fresh chat JWT. Returns the new bearer or null when
1125
+ * discovery fails. Only available when `descriptor.sso.autoRefresh` is
1126
+ * `true`; returns `null` immediately otherwise.
1127
+ */
1128
+ refreshPartnerAuth(): Promise<string | null>;
925
1129
  }
926
1130
 
927
1131
  export declare interface SlugMountOptions {
@@ -965,6 +1169,13 @@ export declare interface SlugMountOptions {
965
1169
  * without host code per call.
966
1170
  */
967
1171
  identity?: Record<string, string | undefined>;
1172
+ /**
1173
+ * Partner token supplied directly by the embedding host. Used by
1174
+ * `descriptor.sso.tokenSource === "init"` (v2 sign-in flow) — every
1175
+ * other source kind discovers the token from the page itself
1176
+ * (query / hash / cookie / storage / postMessage / global).
1177
+ */
1178
+ partnerToken?: string;
968
1179
  };
969
1180
  /** Optional escape hatches; merge over descriptor-driven defaults. */
970
1181
  hooks?: {
@@ -1025,8 +1236,37 @@ export declare interface SsoDescriptor {
1025
1236
  apiKey?: string;
1026
1237
  /** Extra static headers attached to the exchange POST. */
1027
1238
  headers?: Record<string, string>;
1028
- /** Browser credential collection spec. */
1029
- collect: SsoCollectSpec[];
1239
+ /**
1240
+ * Legacy v1 shape — explicit list of credential sources the browser
1241
+ * reads + posts to the exchange endpoint. Still supported for the
1242
+ * bandhan-itr / myfinancials cohort that shipped before the v2
1243
+ * sign-in tab. Mutually exclusive with `tokenSource` (v2).
1244
+ */
1245
+ collect?: SsoCollectSpec[];
1246
+ /** Provider family. `"partner"` is the only value today. */
1247
+ provider?: string;
1248
+ /** Recipe id paired with this descriptor (e.g. `partner_token_to_backend_jwt`). */
1249
+ flow?: string;
1250
+ /** Skip the login screen entirely — read token, exchange, mount chat. */
1251
+ skipLogin?: boolean;
1252
+ /** Re-read the token source on any request that 401s. */
1253
+ autoRefresh?: boolean;
1254
+ /** Selects which token reader runs at boot. */
1255
+ tokenSource?: TokenSourceKind;
1256
+ /** Per-source config (only the matching block is emitted by the dashboard). */
1257
+ tokenSourceConfig?: TokenSourceConfig;
1258
+ /** What to do when token-discovery fails — show a fallback screen. */
1259
+ fallback?: {
1260
+ enabled?: boolean;
1261
+ method?: 'phone' | 'email';
1262
+ };
1263
+ /** Dot-paths into the partner identity payload returned by `auth`. */
1264
+ map?: {
1265
+ id?: string;
1266
+ email?: string;
1267
+ name?: string;
1268
+ phone?: string;
1269
+ };
1030
1270
  }
1031
1271
 
1032
1272
  export declare class SsoExchangeAdapter {
@@ -1086,6 +1326,15 @@ export declare interface SsoIdentity {
1086
1326
  */
1087
1327
  export declare type SsoSourceKind = 'cookie' | 'localStorage' | 'sessionStorage' | 'url_param' | 'header_meta' | 'callback';
1088
1328
 
1329
+ export declare interface StorageSourceConfig {
1330
+ /** `"local"` (default) or `"session"`. */
1331
+ store?: 'local' | 'session';
1332
+ /** Storage key. */
1333
+ key?: string;
1334
+ /** Optional dot-path. When set the value is JSON.parsed and walked. */
1335
+ path?: string;
1336
+ }
1337
+
1089
1338
  declare type SubscriptionCallback = (data: unknown) => void;
1090
1339
 
1091
1340
  declare interface TemplateMessageEvent {
@@ -1370,6 +1619,102 @@ export declare interface TiledeskTransportConfig {
1370
1619
  debug?: boolean;
1371
1620
  }
1372
1621
 
1622
+ export declare interface TokenDiscoveryDescriptor {
1623
+ /** `"partner"` today; reserved for future SSO families. */
1624
+ provider?: string;
1625
+ /** Recipe id the backend pairs with this descriptor. */
1626
+ flow?: string;
1627
+ /** When true the embedded SDK skips the login UI entirely. */
1628
+ skipLogin?: boolean;
1629
+ /** When true the SDK re-reads the source on 401 retries. */
1630
+ autoRefresh?: boolean;
1631
+ /** One of the seven supported source kinds. */
1632
+ tokenSource: TokenSourceKind;
1633
+ /** Source-specific config; only the matching block is read. */
1634
+ tokenSourceConfig?: TokenSourceConfig;
1635
+ /** Fallback (e.g. show a phone OTP screen) when discovery fails. */
1636
+ fallback?: {
1637
+ enabled?: boolean;
1638
+ method?: 'phone' | 'email';
1639
+ };
1640
+ /** Dot-paths into the partner identity payload returned by the auth call. */
1641
+ map?: {
1642
+ id?: string;
1643
+ email?: string;
1644
+ name?: string;
1645
+ phone?: string;
1646
+ };
1647
+ }
1648
+
1649
+ export declare class TokenDiscoveryError extends Error {
1650
+ readonly source: string;
1651
+ constructor(source: string, msg: string);
1652
+ }
1653
+
1654
+ export declare interface TokenDiscoveryOptions {
1655
+ /** Descriptor from `widget_configs/:slug` (`configurations.sso`). */
1656
+ descriptor: TokenDiscoveryDescriptor;
1657
+ /**
1658
+ * Initial token explicitly passed to the SDK by the parent caller. Used
1659
+ * by the `init` source kind; ignored by every other.
1660
+ */
1661
+ initToken?: string;
1662
+ }
1663
+
1664
+ /**
1665
+ * Thin wrapper that re-runs `discoverToken` on demand. Used by
1666
+ * `ApiClient` when a request 401s and `descriptor.sso.autoRefresh` is set.
1667
+ *
1668
+ * The first call caches the token; `.refresh()` forces a re-read of the
1669
+ * source. `init` mode can't be refreshed (the partner already gave us the
1670
+ * single token) — callers should fall through to fallback there.
1671
+ */
1672
+ export declare class TokenDiscoveryReader {
1673
+ private readonly opts;
1674
+ private cached;
1675
+ constructor(opts: TokenDiscoveryOptions);
1676
+ get descriptor(): TokenDiscoveryDescriptor;
1677
+ /** Resolve the token. Returns cache if present. */
1678
+ get(): Promise<DiscoveredToken>;
1679
+ /**
1680
+ * Re-evaluate the source. For `init` mode (where the SDK has no way to
1681
+ * re-read) this returns the cached token unchanged — callers should
1682
+ * treat repeated 401s after a refresh attempt as terminal.
1683
+ */
1684
+ refresh(): Promise<DiscoveredToken>;
1685
+ }
1686
+
1687
+ export declare type TokenSourceConfig = InitSourceConfig | QuerySourceConfig | HashSourceConfig | PostMsgSourceConfig | CookieSourceConfig | StorageSourceConfig | GlobalSourceConfig;
1688
+
1689
+ /**
1690
+ * Partner-token discovery dispatcher (v2 sign-in flow).
1691
+ *
1692
+ * The dashboard's Sign-in tab writes a `descriptor.sso` block that names
1693
+ * one of seven token-source modes plus a per-mode config block. At runtime
1694
+ * the SDK reads the descriptor, dispatches to the matching reader, and
1695
+ * returns the raw partner token. When `descriptor.sso.skipLogin === true`
1696
+ * the host shell uses the token directly to do the auth exchange; when
1697
+ * `descriptor.sso.autoRefresh === true` the reader is re-evaluated on any
1698
+ * request that returned 401 (see {@link ApiClient}).
1699
+ *
1700
+ * Reading flows:
1701
+ * - `init` — supplied at construction (e.g. `Aikaara.init({token})`).
1702
+ * - `query` — `URLSearchParams(location.search).get(cfg.key)`.
1703
+ * - `hash` — `location.hash` parsed as URLSearchParams; cfg.key wins.
1704
+ * - `postmsg` — `window.addEventListener('message')` filtered by
1705
+ * `cfg.type` + `cfg.key`; origins allowlist optional.
1706
+ * - `cookie` — `document.cookie` parsed; domain scope is informational
1707
+ * (browser already enforces it for the running page).
1708
+ * - `storage` — `(localStorage|sessionStorage).getItem(cfg.key)`; when
1709
+ * `cfg.path` is set, parsed as JSON + dot-path resolved.
1710
+ * - `global` — `window[cfg.path]` resolved via dot-path; polled for
1711
+ * up to 2 seconds for late-loading partner SDKs.
1712
+ *
1713
+ * The dispatcher is intentionally side-effect-free apart from
1714
+ * `postmsg` (which has to attach a listener). Callers control caching.
1715
+ */
1716
+ export declare type TokenSourceKind = 'init' | 'query' | 'hash' | 'postmsg' | 'cookie' | 'storage' | 'global';
1717
+
1373
1718
  export declare interface ToolCall {
1374
1719
  id: string;
1375
1720
  type: 'function';
@@ -1654,6 +1999,65 @@ export declare interface WidgetConfigDescriptor {
1654
1999
  scriptUrl?: string;
1655
2000
  props?: Record<string, unknown>;
1656
2001
  }>;
2002
+ /**
2003
+ * Multi-screen app definition. When present, the hosted-shell renders a
2004
+ * History-API router rooted at the tenant's mount path. Each route
2005
+ * names a slot key that resolves to a `components[slot]` entry.
2006
+ *
2007
+ * When absent, behaviour is the today's single-screen mount (chat
2008
+ * widget at root). No breaking change for existing tenants.
2009
+ */
2010
+ app?: {
2011
+ /** Route id rendered when path matches `/` (or `/<slug>/` in subpath). */
2012
+ defaultRoute: string;
2013
+ /** Map of route id → definition. */
2014
+ routes: Record<string, RouteDef>;
2015
+ /**
2016
+ * Static page list rendered by the hosted-shell's top/bottom nav. The
2017
+ * dashboard's App Layout tab writes this; the SDK doesn't read it.
2018
+ * Surfaced here so descriptor consumers get a typed view.
2019
+ */
2020
+ pages?: AppPageDef[];
2021
+ /** Side panels wrapping the chat — see {@link SidePanelDef}. */
2022
+ panels?: {
2023
+ left?: SidePanelDef;
2024
+ right?: SidePanelDef;
2025
+ };
2026
+ };
2027
+ /**
2028
+ * Tenant-side API config consumed by the side-panel runtime. Right now
2029
+ * only the `api`-type panel uses this — it prefixes `panel.endpoint`
2030
+ * with `api.baseUrl` and sends the chat JWT as `Authorization`. Other
2031
+ * descriptor blocks (`upload`, `historyApiBase`, etc.) keep their own
2032
+ * fields for backwards compatibility.
2033
+ */
2034
+ api?: {
2035
+ /** Absolute base URL for tenant API calls. No trailing slash. */
2036
+ baseUrl?: string;
2037
+ };
2038
+ /**
2039
+ * Unified slot map. Supersedes `templates` and the bespoke
2040
+ * `linkHandlers[].render` mechanism. Each key is a slot id that some
2041
+ * piece of the runtime knows to look up:
2042
+ *
2043
+ * "template:<contentTypeOrTemplateId>" — Tiledesk contentType=300 templates
2044
+ * "screen:login" | "screen:prechat" | "screen:chat" | … — full screens
2045
+ * "panel:header" | "panel:left-rail" | … — chat-shell side panels
2046
+ * "viewer:file" | "viewer:compare-plans" | … — link-modal renderers
2047
+ *
2048
+ * Two component kinds today:
2049
+ * - `iife-element` : tenant ships an IIFE that calls customElements.define;
2050
+ * SDK loads the script + creates `<tag>` and dispatches.
2051
+ * - `remote-dom` : tenant ships a remote-dom bundle (React/Preact/Svelte
2052
+ * JSX); SDK lazy-loads `@aikaara/chat-sdk/remote-host`,
2053
+ * creates a hidden iframe with DOMRemoteReceiver, and
2054
+ * mirrors the tenant's tree into the host slot.
2055
+ *
2056
+ * Backwards compat: at mount time, every entry in `templates` is mirrored
2057
+ * into `components['template:'+id]` as kind:'iife-element' if a matching
2058
+ * key isn't already present. Tenants on the old shape see no change.
2059
+ */
2060
+ components?: Record<string, RemoteComponent>;
1657
2061
  }
1658
2062
 
1659
2063
  /**
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { r as o } from "./MountTenant-BVimPLfY.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 S, j as T, k as v, C as y, l as w, m as M, E, M as x, S as B, n as F, T as U, o as I, p as j, q, s as H, t as P, u as W, v as z, w as K, x as L, y as O, z as R } from "./MountTenant-BVimPLfY.mjs";
3
- import { FormBridge as G } from "./headless.mjs";
1
+ import { r as o } from "./MountTenant-CxO7hJgs.mjs";
2
+ import { A as u, a as m, b as k, c as g, d as h, e as A, f as C, g as T, h as b, i as v, j as f, k as y, C as S, l as w, m as E, E as M, M as x, S as B, n as F, T as U, o as D, p as I, q as j, s as q, t as H, u as P, v as R, w as W, x as z, y as K, z as L, B as O, D as G, F as J } from "./MountTenant-CxO7hJgs.mjs";
3
+ import { FormBridge as Q } from "./headless.mjs";
4
4
  function l(e) {
5
5
  o();
6
6
  const a = document.createElement("aikaara-chat-widget"), r = {
@@ -31,37 +31,40 @@ function d() {
31
31
  export {
32
32
  u as ActionCableClient,
33
33
  m as AikaaraChatBubble,
34
- g as AikaaraChatClient,
35
- h as AikaaraChatHeader,
36
- k as AikaaraChatInput,
34
+ k as AikaaraChatClient,
35
+ g as AikaaraChatHeader,
36
+ h as AikaaraChatInput,
37
37
  A as AikaaraChatWidget,
38
38
  C as AikaaraErrorBanner,
39
- b as AikaaraMessageBubble,
40
- f as AikaaraMessageList,
41
- S as AikaaraStreamingMessage,
42
- T as AikaaraTypingIndicator,
43
- v as ApiClient,
44
- y as ChannelSubscription,
39
+ T as AikaaraMessageBubble,
40
+ b as AikaaraMessageList,
41
+ v as AikaaraStreamingMessage,
42
+ f as AikaaraTypingIndicator,
43
+ y as ApiClient,
44
+ S as ChannelSubscription,
45
45
  w as ConnectionManager,
46
- M as ConversationManager,
47
- E as EventEmitter,
48
- G as FormBridge,
46
+ E as ConversationManager,
47
+ M as EventEmitter,
48
+ Q as FormBridge,
49
49
  x as MessageStore,
50
50
  B as SessionAuthAdapter,
51
51
  F as SsoExchangeAdapter,
52
52
  U as TiledeskTransport,
53
- I as clearPersistedConversationId,
54
- j as collectSsoCredentials,
55
- q as createFetchUploadAdapter,
56
- H as createPresigned3StepUploadAdapter,
57
- P as createTiledeskHistoryAdapter,
58
- W as extractTiledeskFileEnvelope,
59
- z as inferTiledeskRole,
60
- K as isTiledeskSelfEcho,
53
+ D as TokenDiscoveryError,
54
+ I as TokenDiscoveryReader,
55
+ j as clearPersistedConversationId,
56
+ q as collectSsoCredentials,
57
+ H as createFetchUploadAdapter,
58
+ P as createPresigned3StepUploadAdapter,
59
+ R as createTiledeskHistoryAdapter,
60
+ W as discoverToken,
61
+ z as extractTiledeskFileEnvelope,
62
+ K as inferTiledeskRole,
63
+ L as isTiledeskSelfEcho,
61
64
  l as mount,
62
- L as mountFromSlug,
63
- O as mountTenantWidget,
64
- R as parseTiledeskTemplate,
65
+ O as mountFromSlug,
66
+ G as mountTenantWidget,
67
+ J as parseTiledeskTemplate,
65
68
  o as registerComponents,
66
69
  d as unmount
67
70
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=1;function p(s){let n=!1,t=null;const c=o=>{window.parent?.postMessage({aikaara:r,type:"complete",payload:o},"*")},i=o=>{window.parent?.postMessage({aikaara:r,type:"error",message:o},"*")};window.addEventListener("message",o=>{const e=o.data;!e||e.aikaara!==r||(e.type==="bootstrap"&&!n?(n=!0,t={target:document.body,ctx:e.ctx,props:e.props??{},complete:c,fail:i},Promise.resolve(s(t)).catch(a=>i(a?.message??String(a)))):e.type==="update"&&t&&(t={...t,props:{...t.props,...e.props}},Promise.resolve(s(t)).catch(a=>i(a?.message??String(a)))))}),window.parent?.postMessage({aikaara:r,type:"ready"},"*")}function d(s){p(s)}exports.initRemoteAuthor=p;exports.mount=d;
@@ -0,0 +1,62 @@
1
+ export declare interface AuthorMountArgs {
2
+ /** DOM node to render into — the iframe's `document.body`. */
3
+ target: HTMLElement;
4
+ /** Snapshot of host state at bootstrap time. */
5
+ ctx: RemoteAuthorContext | undefined;
6
+ /** Tenant-supplied props from `descriptor.components[slot].props`. */
7
+ props: Record<string, unknown>;
8
+ /** Signal flow completion. Host receives via its `onComplete` callback. */
9
+ complete: (payload: unknown) => void;
10
+ /** Surface a tenant error to the host. */
11
+ fail: (message: string) => void;
12
+ }
13
+
14
+ /**
15
+ * Wire up the host protocol and call `render` once bootstrap arrives.
16
+ * Subsequent host `update` messages re-invoke `render` so the bundle can
17
+ * re-render with new props (or just accept the changes if React-managed).
18
+ */
19
+ export declare function initRemoteAuthor(render: Renderer): void;
20
+
21
+ /** Convenience wrapper for the common "render once, ignore updates" case. */
22
+ export declare function mount(render: Renderer): void;
23
+
24
+ /**
25
+ * `@aikaara/chat-sdk/remote-author` — tiny tenant-side helper.
26
+ *
27
+ * Pull this into a tenant component bundle. The bundle, when loaded by the
28
+ * shell's RemoteComponentLoader (kind: 'remote-dom'), runs inside a
29
+ * sandboxed iframe. It needs to:
30
+ *
31
+ * 1. Tell the host it's ready.
32
+ * 2. Receive a `bootstrap` message carrying `ctx` + `props`.
33
+ * 3. Render whatever it wants into `document.body`.
34
+ * 4. Optionally call `complete(payload)` to signal the flow finished.
35
+ *
36
+ * This module wraps that protocol so tenants don't have to write
37
+ * postMessage boilerplate. They write a `mount(target, ctx, complete, props)`
38
+ * function (or just call `init(...)` with a render callback).
39
+ *
40
+ * Framework-agnostic: works with React, Preact, Svelte, Vue, vanilla JS.
41
+ *
42
+ * @example React
43
+ * import { initRemoteAuthor } from '@aikaara/chat-sdk/remote-author';
44
+ * import { createRoot } from 'react-dom/client';
45
+ * import LoginScreen from './LoginScreen';
46
+ *
47
+ * initRemoteAuthor(({ target, ctx, complete, props }) => {
48
+ * createRoot(target).render(
49
+ * <LoginScreen ctx={ctx} complete={complete} {...props} />
50
+ * );
51
+ * });
52
+ */
53
+ export declare interface RemoteAuthorContext {
54
+ slug: string;
55
+ theme?: Record<string, unknown>;
56
+ identity?: Record<string, unknown>;
57
+ extras?: Record<string, unknown>;
58
+ }
59
+
60
+ declare type Renderer = (args: AuthorMountArgs) => void | Promise<void>;
61
+
62
+ export { }
@@ -0,0 +1,31 @@
1
+ function n(s) {
2
+ let r = !1, t = null;
3
+ const i = (a) => {
4
+ window.parent?.postMessage(
5
+ { aikaara: 1, type: "complete", payload: a },
6
+ "*"
7
+ );
8
+ }, p = (a) => {
9
+ window.parent?.postMessage(
10
+ { aikaara: 1, type: "error", message: a },
11
+ "*"
12
+ );
13
+ };
14
+ window.addEventListener("message", (a) => {
15
+ const e = a.data;
16
+ !e || e.aikaara !== 1 || (e.type === "bootstrap" && !r ? (r = !0, t = {
17
+ target: document.body,
18
+ ctx: e.ctx,
19
+ props: e.props ?? {},
20
+ complete: i,
21
+ fail: p
22
+ }, Promise.resolve(s(t)).catch((o) => p(o?.message ?? String(o)))) : e.type === "update" && t && (t = { ...t, props: { ...t.props, ...e.props } }, Promise.resolve(s(t)).catch((o) => p(o?.message ?? String(o)))));
23
+ }), window.parent?.postMessage({ aikaara: 1, type: "ready" }, "*");
24
+ }
25
+ function O(s) {
26
+ n(s);
27
+ }
28
+ export {
29
+ n as initRemoteAuthor,
30
+ O as mount
31
+ };