@ada-support/embed2 1.13.6 → 1.14.4

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Embed 2
2
2
 
3
- Embed 2 allows clients to setup Ada Web Chat in their web application. For further information on how to use Embed, check out our [documentation](https://developers.ada.cx/reference/add-chat-to-website).
3
+ Embed 2 allows clients to setup Ada Web Chat in their web application. For further information on how to use Embed, check out our [documentation](https://docs.ada.cx/chat/web/getting-started).
4
4
 
5
5
  ## 1. Installation
6
6
 
@@ -34,4 +34,4 @@ adaEmbed.start({
34
34
  });
35
35
  ```
36
36
 
37
- In the example above the `handle` key is a part of `AdaSettings`. To learn more about other settings, consult the [API reference](https://developers.ada.cx/reference/embed2-reference).
37
+ In the example above the `handle` key is a part of `AdaSettings`. To learn more about other settings, consult the [API reference](https://docs.ada.cx/chat/web/sdk-api-reference).
@@ -1,3 +1,8 @@
1
1
  import type { Client } from "common/models/client";
2
+ import type { AdaCluster } from "common/types";
2
3
  import type { MessagePayload } from "common/types/events";
3
- export declare function storeChatterEventDataInBrowser(client: Client, payload: MessagePayload): void;
4
+ export declare function storeChatterEventDataInBrowser(client: Client, payload: MessagePayload, { cluster, domain, privateMode, }?: {
5
+ cluster?: AdaCluster;
6
+ domain?: string;
7
+ privateMode?: boolean;
8
+ }): void;
@@ -0,0 +1,5 @@
1
+ import type { PayloadByEvent } from "common/lib/channel";
2
+ /** Strips the internal `proactive_conversation` tracker for getMetaFields(). */
3
+ export declare function toHostFacingMetaFields(metaFields: Record<string, unknown> | undefined): PayloadByEvent["GET_META_FIELDS_RESPONSE"];
4
+ /** Merges a proactive_conversation key onto existing metaFields. */
5
+ export declare function withProactiveKey(metaFields: Record<string, unknown> | undefined, key: string): Record<string, unknown>;
@@ -10,6 +10,7 @@ export declare function createEmbed(adaSettings: StartOptions): {
10
10
  readonly adaSettings: StartOptions;
11
11
  readonly getInfo: () => Promise<WindowInfo>;
12
12
  readonly setMetaFields: (options: MetaFieldPayload) => Promise<void>;
13
+ readonly getMetaFields: () => Promise<MetaFieldPayload>;
13
14
  readonly setSensitiveMetaFields: (options: MetaFieldPayload) => Promise<void>;
14
15
  readonly stop: () => Promise<void>;
15
16
  readonly deleteHistory: () => Promise<void>;
@@ -59,6 +59,8 @@ export declare const GET_INFO = "GET_INFO";
59
59
  export declare const GET_INFO_RESPONSE = "GET_INFO_RESPONSE";
60
60
  export declare const SET_META_FIELDS = "SET_META_FIELDS";
61
61
  export declare const SET_META_FIELDS_RESPONSE = "SET_META_FIELDS_RESPONSE";
62
+ export declare const GET_META_FIELDS = "GET_META_FIELDS";
63
+ export declare const GET_META_FIELDS_RESPONSE = "GET_META_FIELDS_RESPONSE";
62
64
  export declare const STOP = "STOP";
63
65
  export declare const STOP_RESPONSE = "STOP_RESPONSE";
64
66
  export declare const DELETE_HISTORY = "DELETE_HISTORY";
@@ -3,6 +3,7 @@ export type HostTelemetrySurface = "mobile" | "browser";
3
3
  export type HostTelemetryPlatform = "ios" | "android" | "react-native" | "web" | "unknown";
4
4
  export type HostTelemetryWebSdkOrigin = "legacy" | "messaging";
5
5
  export type HostTelemetryMobileShell = "messaging-sdk" | "legacy-sdk";
6
+ export type HostTelemetryMode = "headless" | "visible";
6
7
  export interface HostTelemetryContext {
7
8
  surface: HostTelemetrySurface;
8
9
  hostPlatform: HostTelemetryPlatform;
@@ -10,6 +11,13 @@ export interface HostTelemetryContext {
10
11
  mobileShell?: HostTelemetryMobileShell;
11
12
  mobilePackage?: string;
12
13
  mobileVersion?: string;
14
+ /**
15
+ * MES-981 P1 #10: distinguishes SDK-driven headless sessions from
16
+ * sessions with a visible chat surface. Tagged on every log/RUM line
17
+ * emitted through `setGlobalLogContext(toMonitoringContext(...))` so
18
+ * dashboards can filter by mode without a separate event.
19
+ */
20
+ mode?: HostTelemetryMode;
13
21
  }
14
22
  export declare const HOST_TELEMETRY_QUERY_PARAM = "ada_host_telemetry";
15
23
  type StartOptionsWithHostTelemetry = StartOptions & {
@@ -0,0 +1,34 @@
1
+ import type { AdaCluster } from "common/types";
2
+ export interface MessagingAuthState {
3
+ messagingToken: string;
4
+ messagingTokenExpiresAt: number;
5
+ sessionRefreshToken: string;
6
+ refreshGeneration: number;
7
+ }
8
+ type MessagingAuthStatePersistence = "normal" | "session" | "private" | string | null | undefined;
9
+ declare const MESSAGING_AUTH_STATE_STORAGE_KEY: "messagingAuthState";
10
+ export declare function buildMessagingAuthStateStorageKey({ handle, cluster, domain, }: {
11
+ handle: string | null | undefined;
12
+ cluster?: AdaCluster;
13
+ domain?: string;
14
+ }): typeof MESSAGING_AUTH_STATE_STORAGE_KEY | null;
15
+ export declare function parseMessagingAuthState(value: unknown): MessagingAuthState | null;
16
+ export declare function readMessagingAuthStateFromStorage({ handle, cluster, domain, }: {
17
+ handle: string | null | undefined;
18
+ cluster?: AdaCluster;
19
+ domain?: string;
20
+ }): MessagingAuthState | undefined;
21
+ export declare function writeMessagingAuthStateToStorage({ handle, cluster, domain, persistence, state, }: {
22
+ handle: string | null | undefined;
23
+ cluster?: AdaCluster;
24
+ domain?: string;
25
+ persistence: MessagingAuthStatePersistence;
26
+ state: MessagingAuthState | null | undefined;
27
+ }): boolean;
28
+ export declare function clearAllMessagingAuthStatesFromStorage(): void;
29
+ export declare function clearMessagingAuthStateFromStorage({ handle, cluster, domain, }: {
30
+ handle: string | null | undefined;
31
+ cluster?: AdaCluster;
32
+ domain?: string;
33
+ }): void;
34
+ export {};
@@ -0,0 +1,5 @@
1
+ import { AdaEmbedError } from "common/helpers/errors";
2
+ export declare const PROGRAMMATIC_CONTROL_DISABLED_ERROR: AdaEmbedError;
3
+ export declare function isProgrammaticControlEnabled(adaSettings: object | undefined | null): boolean;
4
+ export declare function requireProgrammaticControl(adaSettings: object | undefined | null): void;
5
+ export declare function shouldDeliverTranscriptEvent(eventKey: string, adaSettings: object | undefined | null): boolean;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Race `promise` against a timeout. If the timeout fires first, reject
3
+ * with an AdaEmbedError carrying `errorMessage`. If the promise settles
4
+ * first (resolve or reject), clear the pending timer so it doesn't
5
+ * keep the event loop alive past resolution.
6
+ *
7
+ * MES-981 P1 #7: used to cap host-supplied beforeSend hooks so a
8
+ * never-resolving delegate can't hang sendMessage forever.
9
+ */
10
+ export declare function withTimeout<T>(promise: PromiseLike<T> | T, ms: number, errorMessage: string): Promise<T>;
@@ -15,7 +15,10 @@ export interface EmbedRequestPayloadByEvent {
15
15
  DISPATCH: StoreDispatchPayload;
16
16
  EVAL_CAMPAIGN_CONDITIONS: CampaignParams;
17
17
  GET: StoreGetPayload;
18
+ GET_CONVERSATION: unknown;
18
19
  GET_INFO: unknown;
20
+ GET_MESSAGES: unknown;
21
+ GET_META_FIELDS: unknown;
19
22
  GET_STATE: unknown;
20
23
  RESET: ResetParams;
21
24
  SET_META_FIELDS: MetaFieldPayload;
@@ -34,6 +37,12 @@ export interface EmbedRequestPayloadByEvent {
34
37
  SET_LANGUAGE: {
35
38
  language: string;
36
39
  };
40
+ SET_COMPOSER_TEXT: {
41
+ text: string;
42
+ };
43
+ SEND_MESSAGE: {
44
+ text: string;
45
+ };
37
46
  TRIGGER_PROACTIVE: TriggerProactiveParams;
38
47
  INJECT_PROACTIVE_CONVERSATION: {
39
48
  key: string;
@@ -51,8 +60,42 @@ export interface EmbedResponsePayloadByEvent {
51
60
  "DISPATCH_RESPONSE": StoreState;
52
61
  "EVAL_CAMPAIGN_CONDITIONS_RESPONSE": unknown;
53
62
  "GET_RESPONSE": StoreState[keyof StoreState];
63
+ "GET_CONVERSATION_RESPONSE": {
64
+ id: string | null;
65
+ handoff: {
66
+ inLiveChat: boolean;
67
+ agent?: {
68
+ id: string;
69
+ name: string;
70
+ avatarUrl?: string;
71
+ };
72
+ };
73
+ };
54
74
  "GET_INFO_RESPONSE": unknown;
75
+ "GET_MESSAGES_RESPONSE": Array<{
76
+ id: string;
77
+ role: "user" | "bot" | "agent";
78
+ type: string;
79
+ body?: string;
80
+ createdAt: number;
81
+ agent?: {
82
+ id: string;
83
+ name: string;
84
+ avatarUrl?: string;
85
+ };
86
+ }>;
87
+ "GET_META_FIELDS_RESPONSE": MetaFieldPayload;
55
88
  "GET_STATE_RESPONSE": StoreState;
89
+ "SEND_MESSAGE_RESPONSE": {
90
+ id: string;
91
+ } | {
92
+ error: string;
93
+ };
94
+ "SET_COMPOSER_TEXT_RESPONSE": {
95
+ ok: true;
96
+ } | {
97
+ error: string;
98
+ };
56
99
  "GREETING": unknown;
57
100
  "JWT_AUTH_RESPONSE": unknown;
58
101
  "RESET_RESPONSE": unknown;
@@ -0,0 +1,191 @@
1
+ import type { AdaEmbedAPI, AdaEventContext, AdaEventKey, AdaEventSubscriptionCallback, StartOptions } from "@ada-support/embed-types";
2
+ import type { MetaFieldPayload } from "common/types/store";
3
+ /**
4
+ * MES-981: new ada:* event keys + their payload shapes, added alongside
5
+ * the existing `@ada-support/embed-types` `AdaEventDataKeyedByEvent` union.
6
+ * Once the upstream package is updated these are folded back in and this
7
+ * file goes away.
8
+ */
9
+ export interface ExtendedAdaEventDataKeyedByEvent {
10
+ /**
11
+ * MES-981 P1 #10: tagged with `mode` so downstream consumers can
12
+ * distinguish between visible-drawer sessions and SDK-driven headless
13
+ * sessions.
14
+ */
15
+ "ada:ready": {
16
+ mode: "headless" | "visible";
17
+ };
18
+ "ada:message:sent": {
19
+ message: Message;
20
+ };
21
+ "ada:message:received": {
22
+ message: Message;
23
+ };
24
+ "ada:typing:start": {
25
+ agentId: string;
26
+ };
27
+ "ada:typing:stop": {
28
+ agentId: string;
29
+ };
30
+ "ada:connection:change": {
31
+ state: "connected" | "reconnecting" | "disconnected";
32
+ };
33
+ "ada:conversation:change": {
34
+ id: string;
35
+ };
36
+ }
37
+ export type ExtendedAdaEventKey = AdaEventKey | keyof ExtendedAdaEventDataKeyedByEvent;
38
+ /**
39
+ * MES-981: forward-compatible start options that include the new
40
+ * MES-981 flags. The flags are consumed at runtime by `embed-2`; the
41
+ * type augmentation here lets host pages set them without a type error
42
+ * while the upstream `@ada-support/embed-types` package is being updated.
43
+ */
44
+ export type ExtendedStartOptions = StartOptions & {
45
+ /** Loads chat without rendering the default button/drawer. */
46
+ headless?: boolean;
47
+ /**
48
+ * Opt-in to the programmatic transcript-bearing surface introduced by
49
+ * MES-981: `sendMessage`, `setComposerText`, `getMessages`, `setDelegate`,
50
+ * and the `ada:message:sent` / `ada:message:received` events.
51
+ *
52
+ * Defaults to `false`. While the flag is off the methods reject with an
53
+ * explicit error and the events are not delivered to host subscribers,
54
+ * because every script that lives in the host page (analytics, GTM, ad
55
+ * pixels, session replay tools, supply-chain XSS) inherits the host's
56
+ * trust — and the host site's product/security team should explicitly
57
+ * accept the transcript-exposure risk before that capability is reachable.
58
+ */
59
+ enableProgrammaticControl?: boolean;
60
+ };
61
+ /**
62
+ * Local augmentation of the public AdaEmbedAPI surface for methods that are
63
+ * being rolled out via MES-981 ahead of a matching release of
64
+ * @ada-support/embed-types. Once those types are published, the methods below
65
+ * should be moved into the upstream interface and this file can be removed.
66
+ */
67
+ export interface ExtendedAdaEmbedAPI extends AdaEmbedAPI {
68
+ /**
69
+ * MES-981: widened start() overload that accepts the new ExtendedStartOptions
70
+ * (`headless`, `enableProgrammaticControl`) without requiring an `as`
71
+ * cast at the call site. Returns void to match the upstream signature.
72
+ */
73
+ start(adaSettings: ExtendedStartOptions): Promise<void>;
74
+ /**
75
+ * Convenience accessor for whether the chat drawer is currently open.
76
+ * Equivalent to `(await getInfo()).isChatOpen`.
77
+ *
78
+ * Rejects with `EMBED_NOT_INITIALIZED_ERROR` if called before `start()`.
79
+ *
80
+ * @example
81
+ * if (await adaEmbed.isOpen()) {
82
+ * // chat is visible
83
+ * }
84
+ */
85
+ isOpen(): Promise<boolean>;
86
+ /**
87
+ * Returns the metaFields currently held in embed-2's state. Reflects the
88
+ * value initially passed to `start({ metaFields })` plus any subsequent
89
+ * `setMetaFields` updates. Sensitive metaFields are deliberately not
90
+ * exposed.
91
+ *
92
+ * Rejects with `EMBED_NOT_INITIALIZED_ERROR` if called before `start()`.
93
+ */
94
+ getMetaFields(): Promise<MetaFieldPayload>;
95
+ /**
96
+ * Pre-fills the chat composer input with `text` without sending it.
97
+ * The value can still be edited or cleared by the end user.
98
+ *
99
+ * Rejects with `EMBED_NOT_INITIALIZED_ERROR` if called before `start()`,
100
+ * or with an `AdaEmbedError` if the chat frame is not yet ready.
101
+ */
102
+ setComposerText(text: string): Promise<void>;
103
+ /**
104
+ * Returns metadata about the current conversation: its id (or `null`
105
+ * if there is no active conversation), and the handoff state — whether
106
+ * the conversation is in live chat and, if so, basic info about the
107
+ * connected agent.
108
+ *
109
+ * Rejects with `EMBED_NOT_INITIALIZED_ERROR` if called before `start()`,
110
+ * or with an `AdaEmbedError` if the chat frame is not yet ready.
111
+ */
112
+ getConversation(): Promise<ConversationInfo>;
113
+ /**
114
+ * Returns the full in-memory message list for the current session.
115
+ * Generative has no server-side history endpoint, so this returns
116
+ * what the client has rendered (user, bot, and any handoff messages).
117
+ * Returns an empty array if no messages have been exchanged yet.
118
+ *
119
+ * Rejects with `EMBED_NOT_INITIALIZED_ERROR` if called before `start()`,
120
+ * or with an `AdaEmbedError` if the chat frame is not yet ready.
121
+ */
122
+ getMessages(): Promise<Message[]>;
123
+ /**
124
+ * Sends a free-text user message through the same path as the visible
125
+ * composer (POSTs to `/message/chat/`). Resolves with the generated
126
+ * message id so the caller can correlate it with later `getMessages()`
127
+ * reads.
128
+ *
129
+ * Generative does not support per-message metadata; user-level metadata
130
+ * is set via `setMetaFields`.
131
+ *
132
+ * Rejects with `EMBED_NOT_INITIALIZED_ERROR` if called before `start()`,
133
+ * an `AdaEmbedError` if the chat frame is not yet ready, or an
134
+ * `AdaEmbedError` if `text` is empty.
135
+ */
136
+ sendMessage(text: string): Promise<{
137
+ id: string;
138
+ }>;
139
+ /**
140
+ * Registers a host-side interceptor that runs in embed-2 before
141
+ * outgoing messages are forwarded to chat. Use `beforeSend` to
142
+ * modify, cancel, or pass through the user message. Set `beforeSend`
143
+ * to `undefined` to clear an existing delegate.
144
+ *
145
+ * The delegate may be synchronous or async. Returning `false` (or a
146
+ * Promise of `false`) cancels the send and causes `sendMessage` to
147
+ * reject with `DelegateRejected`.
148
+ */
149
+ setDelegate(delegate: Delegate): void;
150
+ /**
151
+ * MES-981: widened subscribeEvent overload to accept the new ada:* event
152
+ * keys until @ada-support/embed-types is republished. The upstream signature
153
+ * is preserved for the original key set via the union return type.
154
+ */
155
+ subscribeEvent<K extends ExtendedAdaEventKey>(eventKey: K, callback: K extends AdaEventKey ? AdaEventSubscriptionCallback<K> : K extends keyof ExtendedAdaEventDataKeyedByEvent ? (data: ExtendedAdaEventDataKeyedByEvent[K], context: AdaEventContext) => void : never): Promise<number>;
156
+ }
157
+ export type BeforeSend = (message: {
158
+ text: string;
159
+ }) => {
160
+ text: string;
161
+ } | false | Promise<{
162
+ text: string;
163
+ } | false>;
164
+ export interface Delegate {
165
+ beforeSend?: BeforeSend;
166
+ }
167
+ export interface ConversationInfo {
168
+ id: string | null;
169
+ handoff: {
170
+ inLiveChat: boolean;
171
+ agent?: {
172
+ id: string;
173
+ name: string;
174
+ avatarUrl?: string;
175
+ };
176
+ };
177
+ }
178
+ export type MessageRole = "user" | "bot" | "agent";
179
+ export interface Message {
180
+ id: string;
181
+ role: MessageRole;
182
+ type: string;
183
+ body?: string;
184
+ /** Unix epoch seconds (subsecond precision), as stored by the chat session. */
185
+ createdAt: number;
186
+ agent?: {
187
+ id: string;
188
+ name: string;
189
+ avatarUrl?: string;
190
+ };
191
+ }
@@ -1,5 +1,5 @@
1
- import type { AdaEmbedAPI } from "@ada-support/embed-types";
2
1
  import type { ActionTypes } from "common/constants/actions";
2
+ import type { ExtendedAdaEmbedAPI } from "./extended-api";
3
3
  import type { StoreState } from "./store-state";
4
4
  export * from "./interface";
5
5
  export interface StoreAction {
@@ -30,7 +30,7 @@ export interface TriggerCampaignParams {
30
30
  ignoreFrequency?: boolean;
31
31
  }
32
32
  export interface CustomWindow extends Window {
33
- adaEmbed: AdaEmbedAPI;
33
+ adaEmbed: ExtendedAdaEmbedAPI;
34
34
  navigator: Navigator;
35
35
  adaEmbedLoadedCallback?: () => void;
36
36
  }
@@ -1,11 +1,13 @@
1
1
  import type { Modality, StartOptions } from "@ada-support/embed-types";
2
2
  import type { ConnectionState } from "common/constants/events";
3
+ import type { MessagingAuthState } from "common/helpers/messaging-auth-state";
3
4
  import type { Client } from "common/models/client";
4
5
  import type { AdaCluster } from "common/types";
5
6
  export interface StoreState extends StartOptionsNoFunction {
6
7
  chatterCreated: string | undefined;
7
8
  chatterToken: string | undefined;
8
9
  sessionToken: string | undefined;
10
+ messagingAuthState?: MessagingAuthState;
9
11
  client?: Client;
10
12
  enabledLanguages: string[];
11
13
  isDrawerOpen: boolean;
@@ -65,4 +67,8 @@ export interface StartOptionsNoFunction {
65
67
  testMode?: boolean;
66
68
  preload?: boolean;
67
69
  showFallbackOnTimeout?: boolean;
70
+ /** MES-981: programmatic-only mode — entry UI is hidden, host renders its own surface */
71
+ headless?: boolean;
72
+ /** MES-981 P0 #4: opt-in for the transcript-bearing programmatic surface. */
73
+ enableProgrammaticControl?: boolean;
68
74
  }
@@ -1,2 +1,2 @@
1
- declare const _default: import("@ada-support/embed-types").AdaEmbedAPI;
1
+ declare const _default: import("./common/types/extended-api").ExtendedAdaEmbedAPI;
2
2
  export default _default;