@ada-cx/messaging-sdk 1.0.0-setup.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/README.md +211 -0
- package/dist/client/ada-settings-reader.d.ts +10 -0
- package/dist/client/client-channel-handlers.d.ts +92 -0
- package/dist/client/client-errors.d.ts +7 -0
- package/dist/client/client-frame-constants.d.ts +41 -0
- package/dist/client/client-frame-runtime.d.ts +54 -0
- package/dist/client/client-host-runtime.d.ts +73 -0
- package/dist/client/client-types.d.ts +231 -0
- package/dist/client/client.d.ts +843 -0
- package/dist/client/config-helpers.d.ts +157 -0
- package/dist/client/constants.d.ts +61 -0
- package/dist/client/core-channel-test-harness.d.ts +47 -0
- package/dist/client/embed-interface.d.ts +172 -0
- package/dist/client/embed-lifecycle.d.ts +12 -0
- package/dist/client/fallback-html.d.ts +1 -0
- package/dist/client/frame-manager.d.ts +64 -0
- package/dist/client/frame-styles.d.ts +164 -0
- package/dist/client/frame-visibility.d.ts +53 -0
- package/dist/client/integration-manager.d.ts +73 -0
- package/dist/client/legacy-callback-adapter.d.ts +22 -0
- package/dist/client/mask-element.d.ts +19 -0
- package/dist/client/proactive/index.d.ts +5 -0
- package/dist/client/proactive/proactive-channel.d.ts +33 -0
- package/dist/client/proactive/proactive-runtime.d.ts +65 -0
- package/dist/client/proactive/proactive-utils.d.ts +51 -0
- package/dist/client/sdk-error-reporter.d.ts +22 -0
- package/dist/client/sdk-event-bus.d.ts +116 -0
- package/dist/client/service-worker-notifications.d.ts +1 -0
- package/dist/client/url-business-events.d.ts +19 -0
- package/dist/frame-channel/frame-channel.d.ts +64 -0
- package/dist/frame-channel/frame-child.d.ts +45 -0
- package/dist/frame-channel/index.d.ts +3 -0
- package/dist/frame-channel/types.d.ts +736 -0
- package/dist/helpers/rollout.d.ts +18 -0
- package/dist/host-telemetry.d.ts +15 -0
- package/dist/index.d.ts +8 -0
- package/dist/logger.d.ts +59 -0
- package/dist/mobile-webview-runtime.d.ts +122 -0
- package/dist/npm/build-info.d.cts +17 -0
- package/dist/npm/build-info.d.ts +17 -0
- package/dist/npm/index.cjs +276 -0
- package/dist/npm/index.cjs.map +1 -0
- package/dist/npm/index.d.cts +15 -0
- package/dist/npm/index.d.ts +9 -0
- package/dist/npm/index.js +270 -0
- package/dist/npm/index.js.map +1 -0
- package/dist/npm/loader.d.cts +120 -0
- package/dist/npm/loader.d.ts +120 -0
- package/dist/npm/testing.cjs +155 -0
- package/dist/npm/testing.cjs.map +1 -0
- package/dist/npm/testing.d.cts +39 -0
- package/dist/npm/testing.d.ts +39 -0
- package/dist/npm/testing.js +154 -0
- package/dist/npm/testing.js.map +1 -0
- package/dist/sdk-module-loader.d.ts +1 -0
- package/dist/shared-utils/clusters.d.ts +5 -0
- package/dist/shared-utils/csat.d.ts +116 -0
- package/dist/shared-utils/host-telemetry.d.ts +35 -0
- package/dist/shared-utils/index.d.ts +3 -0
- package/dist/voice/voice-manager.d.ts +120 -0
- package/package.json +77 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { CSAT_INTEGRATION_ID, CSAT_SUBMIT_ACTION, normalizeCsatSubmitAction, VALID_ADA_CLUSTERS } from "../shared-utils/index.js";
|
|
2
|
+
import type { MetaFieldValue } from "./client-types.js";
|
|
3
|
+
export declare const LOCALHOST_CLUSTER = "localhost";
|
|
4
|
+
export declare const DEFAULT_ADA_DOMAIN = "ada";
|
|
5
|
+
export { VALID_ADA_CLUSTERS };
|
|
6
|
+
export declare const KNOWN_ADA_BASE_DOMAINS: Set<string>;
|
|
7
|
+
export declare const HANDLE_PATTERN: RegExp;
|
|
8
|
+
export declare const LOCALHOST_API_PROXY_BASE = "https://messaging-demo.net:5040/api";
|
|
9
|
+
export declare const LOOPBACK_API_PROXY_PORT = 5040;
|
|
10
|
+
/** Hostname of the local messaging asset server (the /etc/hosts alias serving the SDK
|
|
11
|
+
* on :4900). When the SDK loads from here the demo-server proxy (:5040) is running
|
|
12
|
+
* too, so the bot API is reached through it — not the direct-bot fallback. */
|
|
13
|
+
export declare const LOCAL_ASSETS_HOSTNAME = "messaging-assets.net";
|
|
14
|
+
/** The api's default local `APP_PORT`. A `<handle>.localhost` host page (e.g. the
|
|
15
|
+
* app dashboard's Test Chat) talks to its bot api directly on this port. */
|
|
16
|
+
export declare const LOCAL_BOT_API_PORT = 8000;
|
|
17
|
+
export declare function deriveLocalhostApiProxyBase(sdkUrl: string, pageHost?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* The `adaSettings.styles` keys that reach a token. `tintColor` is the only one:
|
|
20
|
+
* `surfaceColor`/`surfaceColorDark` have no token target in either design system, and
|
|
21
|
+
* a per-mode brand color does not exist at all (server config carries one mode-agnostic
|
|
22
|
+
* `tint_color`). Accepting the other three only made the surface look wider than it was.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SUPPORTED_THEME_STYLE_KEYS: readonly ["tintColor"];
|
|
25
|
+
export declare function normalizeIdentityToken(value: unknown): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Normalize the custom app frame URL (`appUrl`), warning when a
|
|
28
|
+
* supplied value is dropped. Core re-validates through the same shared helper
|
|
29
|
+
* — a host page can post `sdk.config.set` straight at the core frame, so this
|
|
30
|
+
* is a convenience gate, not the security boundary.
|
|
31
|
+
*
|
|
32
|
+
* The drop logs through `logger.dataLoss` — host config the SDK accepted and
|
|
33
|
+
* then discarded is exactly the ungated channel's contract, and the GA docs
|
|
34
|
+
* promise a console warning here without a debug opt-in.
|
|
35
|
+
*/
|
|
36
|
+
export declare function normalizeAppUrlOverride(value: unknown): string | undefined;
|
|
37
|
+
export declare const INTEGRATION_FRAME_IDS: readonly ["zendesk", "zendeskMessaging", "oauth", "csat"];
|
|
38
|
+
export type IntegrationFrameId = (typeof INTEGRATION_FRAME_IDS)[number];
|
|
39
|
+
export interface IntegrationCommand {
|
|
40
|
+
integration: string;
|
|
41
|
+
action: string;
|
|
42
|
+
payload?: Record<string, unknown>;
|
|
43
|
+
commandId?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface IntegrationResultPayload {
|
|
46
|
+
commandId?: string;
|
|
47
|
+
integration: string;
|
|
48
|
+
action: string;
|
|
49
|
+
status: "success" | "error";
|
|
50
|
+
data?: Record<string, unknown>;
|
|
51
|
+
error?: {
|
|
52
|
+
code: string;
|
|
53
|
+
message: string;
|
|
54
|
+
details?: Record<string, unknown>;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface TrackedIntegrationCommand {
|
|
58
|
+
frameId: IntegrationFrameId;
|
|
59
|
+
integration: string;
|
|
60
|
+
action: string;
|
|
61
|
+
/** True only after the command crossed the ready frame channel. */
|
|
62
|
+
dispatched: boolean;
|
|
63
|
+
/** Correlation needed to fail the exact optimistic message if the frame hangs. */
|
|
64
|
+
messageId?: string;
|
|
65
|
+
requestId?: string;
|
|
66
|
+
zendeskOperationSeq?: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Normalize and validate a customer-provided endpoint override.
|
|
70
|
+
* Throws on invalid input so the constructor surfaces config errors early.
|
|
71
|
+
*/
|
|
72
|
+
export declare function validateEndpointOverride(endpoint: string): string;
|
|
73
|
+
/** Append `/api/` to a base URL, avoiding double-appending if already present. */
|
|
74
|
+
export declare function buildApiEndpoint(apiBase: string): string;
|
|
75
|
+
export declare function normalizeClusterInput(value: string | null | undefined): string | null;
|
|
76
|
+
export declare function validateCluster(cluster: string, label: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Parse and validate the `handle`, `cluster`, and `domain` config values into a
|
|
79
|
+
* handle plus a canonical base-domain `cluster`. `domain` is the embed-2 base
|
|
80
|
+
* segment (e.g. "ada-dev2"); a full URL override belongs in `endpoint`, not here.
|
|
81
|
+
*/
|
|
82
|
+
export declare function parseClientIdentity(rawHandle: string, rawCluster?: string | null, rawDomain?: string | null): {
|
|
83
|
+
handle: string;
|
|
84
|
+
cluster: string | null;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Attempt to detect an Ada base domain from the SDK asset URL.
|
|
88
|
+
* Returns the longest matching suffix from KNOWN_ADA_BASE_DOMAINS, or null.
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolveAdaBaseDomainFromSdkUrl(sdkUrl: string): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* Derive the default API base URL from the handle, SDK URL, and optional cluster.
|
|
93
|
+
* Used when no explicit `endpoint` override is provided in config.
|
|
94
|
+
*/
|
|
95
|
+
export declare function deriveDefaultApiBase(handle: string, sdkUrl: string, cluster?: string | null): string;
|
|
96
|
+
/** Strip non-primitive values and empty keys from a metafield record.
|
|
97
|
+
* Also enforces key/value length limits and a maximum entry count to
|
|
98
|
+
* prevent oversized payloads from reaching the API (which would 413).
|
|
99
|
+
* Sensitive records still report data loss, but never name their keys. */
|
|
100
|
+
export declare function sanitizeMetaFieldRecord(fields: Record<string, unknown>, options?: {
|
|
101
|
+
sensitive?: boolean;
|
|
102
|
+
}): Record<string, MetaFieldValue>;
|
|
103
|
+
/** Query-param prefix that the standalone `chat.html` forwards as conversation
|
|
104
|
+
* metaFields: `?mf_email=…&mf_bot_handle=…` → `metaFields: { email, bot_handle }`.
|
|
105
|
+
* Lets a host (e.g. the dashboard "Ask for Help" popup) pass context to the bot
|
|
106
|
+
* without baking business keys into the entry point. */
|
|
107
|
+
export declare const CHAT_HTML_META_FIELD_PREFIX = "mf_";
|
|
108
|
+
export interface ChatHtmlConfig {
|
|
109
|
+
handle: string;
|
|
110
|
+
cluster?: string;
|
|
111
|
+
language?: string;
|
|
112
|
+
greeting?: string;
|
|
113
|
+
metaFields: Record<string, MetaFieldValue>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Build the standalone `chat.html` SDK config (sans `parentElement`) from its
|
|
117
|
+
* query string. Reads `ada_handle` (required) / `ada_cluster` / `language` /
|
|
118
|
+
* `greeting`, and forwards every `mf_<key>` param as a sanitized `metaFields`
|
|
119
|
+
* entry. Returns `null` when `ada_handle` is absent.
|
|
120
|
+
*/
|
|
121
|
+
export declare function resolveChatHtmlConfig(search: string | URLSearchParams): ChatHtmlConfig | null;
|
|
122
|
+
/**
|
|
123
|
+
* Return only the host overrides that are both supported and safe to paint.
|
|
124
|
+
*
|
|
125
|
+
* Carries no defaults. Core treats every key it receives here as "the host asked for
|
|
126
|
+
* this", so seeding a default would hand every bot the same hardcoded tint in place of
|
|
127
|
+
* the one configured in its dashboard.
|
|
128
|
+
*/
|
|
129
|
+
export declare function sanitizeThemeStyles(styles: Record<string, string> | undefined): Record<string, string>;
|
|
130
|
+
/**
|
|
131
|
+
* Determine which live-agent platform is active based on the command.
|
|
132
|
+
* `handoff.request` and `fileUpload` commands carry platform hints.
|
|
133
|
+
*/
|
|
134
|
+
export declare function normalizeLiveAgentPlatform(command: IntegrationCommand, activePlatform: string | null): string | null;
|
|
135
|
+
/** Normalize CSAT action strings; pass all other actions through unchanged. */
|
|
136
|
+
export declare function normalizeIntegrationAction(integration: string, action: string): string;
|
|
137
|
+
/**
|
|
138
|
+
* Resolve which integration iframe should handle the given command,
|
|
139
|
+
* also returning the updated active live-agent platform.
|
|
140
|
+
*/
|
|
141
|
+
export declare function resolveIntegrationTarget(command: IntegrationCommand, activePlatform: string | null): {
|
|
142
|
+
frameId: IntegrationFrameId | null;
|
|
143
|
+
nextActivePlatform: string | null;
|
|
144
|
+
};
|
|
145
|
+
export { CSAT_INTEGRATION_ID, CSAT_SUBMIT_ACTION, normalizeCsatSubmitAction };
|
|
146
|
+
/**
|
|
147
|
+
* Check whether the embedding page URL contains a private-mode override.
|
|
148
|
+
*
|
|
149
|
+
* Detects:
|
|
150
|
+
* - ?private=true
|
|
151
|
+
* - ?private=1
|
|
152
|
+
* - #private (hash must be exactly "#private")
|
|
153
|
+
*
|
|
154
|
+
* When any of these is present, storage is forced to "private" mode
|
|
155
|
+
* regardless of the client config's persistence setting.
|
|
156
|
+
*/
|
|
157
|
+
export declare function detectPrivateUrlOverride(location?: Pick<Location, "search" | "hash">): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central source of truth for all numeric limits and timeouts used across SDK modules.
|
|
3
|
+
* Import from here instead of defining local constants to avoid drift.
|
|
4
|
+
*/
|
|
5
|
+
/** Milliseconds to wait for a top-level frame to fire its load event */
|
|
6
|
+
export declare const FRAME_LOAD_TIMEOUT_MS = 10000;
|
|
7
|
+
/**
|
|
8
|
+
* Milliseconds to wait after the host opens chat before publishing the legacy
|
|
9
|
+
* timeout event when activation has not completed.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CHAT_ACTIVATION_TIMEOUT_EVENT_MS = 5000;
|
|
12
|
+
/**
|
|
13
|
+
* Parent-element embeds are visible while their public and engaged config are
|
|
14
|
+
* still loading, and headless starts without the launcher's config-fetch head
|
|
15
|
+
* start, so the floating widget's 5-second diagnostic is too eager for those
|
|
16
|
+
* paths. This remains an early signal, well before the fallback UI budget.
|
|
17
|
+
*/
|
|
18
|
+
export declare const CHAT_ACTIVATION_TIMEOUT_EVENT_PARENT_ELEMENT_MS = 15000;
|
|
19
|
+
/**
|
|
20
|
+
* Milliseconds to wait after the host opens chat before auto-showing the
|
|
21
|
+
* self-contained fallback document when one bounded activation step has made
|
|
22
|
+
* no progress. Core completion checkpoints re-arm this inactivity budget.
|
|
23
|
+
*
|
|
24
|
+
* Every startup request is bounded to at most 20 seconds and bot-domain
|
|
25
|
+
* storage hydration is bounded to 6 seconds. Thirty seconds therefore leaves
|
|
26
|
+
* margin for a healthy chatter create/identify POST without navigating its
|
|
27
|
+
* owning core frame away while the server commit may still be in flight.
|
|
28
|
+
*/
|
|
29
|
+
export declare const CHAT_FALLBACK_DELAY_MS = 30000;
|
|
30
|
+
/**
|
|
31
|
+
* Absolute visible-activation ceiling. Progress from an unrelated recovery or
|
|
32
|
+
* reset may share the same internal channel, so re-arming cannot be unbounded.
|
|
33
|
+
*/
|
|
34
|
+
export declare const CHAT_FALLBACK_MAX_TOTAL_MS = 120000;
|
|
35
|
+
/**
|
|
36
|
+
* Milliseconds to wait for a frame to send its `frame.origin.report` message.
|
|
37
|
+
* After this window, the SDK falls back to the expected origin (if known) or
|
|
38
|
+
* logs a warning, so queued messages are not held indefinitely.
|
|
39
|
+
*/
|
|
40
|
+
export declare const ORIGIN_REPORT_TIMEOUT_MS = 3000;
|
|
41
|
+
/**
|
|
42
|
+
* Bound the parent-to-intro handshake used when a host strips the iframe's
|
|
43
|
+
* referrer. The child cannot flush its queued origin/ready reports until it
|
|
44
|
+
* receives one trusted parent message, while a broken child must not be pinged
|
|
45
|
+
* for the rest of the page's lifetime.
|
|
46
|
+
*/
|
|
47
|
+
export declare const INTRO_CHANNEL_UNLOCK_MAX_ATTEMPTS = 20;
|
|
48
|
+
/** Maximum number of integration commands that can be buffered per frame */
|
|
49
|
+
export declare const MAX_PENDING_COMMANDS = 64;
|
|
50
|
+
/** Maximum number of integration commands tracked for result callbacks */
|
|
51
|
+
export declare const MAX_TRACKED_COMMANDS = 256;
|
|
52
|
+
/** Milliseconds before an integration command result callback times out */
|
|
53
|
+
export declare const COMMAND_RESULT_TIMEOUT_MS = 20000;
|
|
54
|
+
/** Per-step inactivity budget for reset/deleteHistory durable acknowledgements. */
|
|
55
|
+
export declare const RESET_ACK_TIMEOUT_MS = 30000;
|
|
56
|
+
/** Absolute ceiling for progress-rearmed destructive-operation acknowledgements. */
|
|
57
|
+
export declare const RESET_ACK_MAX_TOTAL_MS: number;
|
|
58
|
+
/** Per-step inactivity budget for a cold programmatic send. */
|
|
59
|
+
export declare const SEND_MESSAGE_TIMEOUT_MS = 30000;
|
|
60
|
+
/** Absolute ceiling for a progress-rearmed cold programmatic send. */
|
|
61
|
+
export declare const SEND_MESSAGE_MAX_TOTAL_MS = 120000;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AdaMessagingClient } from "./client.js";
|
|
2
|
+
export type CoreHandler = (message: {
|
|
3
|
+
payload: unknown;
|
|
4
|
+
}) => void;
|
|
5
|
+
/** Install a connected core channel without mounting a real iframe. */
|
|
6
|
+
export declare function installCoreChannel(client: AdaMessagingClient): {
|
|
7
|
+
channel: {
|
|
8
|
+
send: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
9
|
+
on: import("vitest").Mock<(type: string, handler: CoreHandler) => void>;
|
|
10
|
+
};
|
|
11
|
+
handlers: Map<string, CoreHandler>;
|
|
12
|
+
};
|
|
13
|
+
/** Wire the production core handlers onto the stub channel. */
|
|
14
|
+
export declare function installRealCoreHandlers(client: AdaMessagingClient, options?: {
|
|
15
|
+
ready?: boolean;
|
|
16
|
+
}): {
|
|
17
|
+
channel: {
|
|
18
|
+
send: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
19
|
+
on: import("vitest").Mock<(type: string, handler: CoreHandler) => void>;
|
|
20
|
+
};
|
|
21
|
+
handlers: Map<string, CoreHandler>;
|
|
22
|
+
};
|
|
23
|
+
/** Wire production handlers onto the Core frame manager already mounted by the client. */
|
|
24
|
+
export declare function attachRealCoreHandlers(client: AdaMessagingClient, options?: {
|
|
25
|
+
ready?: boolean;
|
|
26
|
+
}): {
|
|
27
|
+
channel: {
|
|
28
|
+
send: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
29
|
+
on: import("vitest").Mock<(type: string, handler: CoreHandler) => void>;
|
|
30
|
+
disconnect: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
31
|
+
};
|
|
32
|
+
handlers: Map<string, CoreHandler>;
|
|
33
|
+
};
|
|
34
|
+
export declare function requestIdsFor(channel: {
|
|
35
|
+
send: {
|
|
36
|
+
mock: {
|
|
37
|
+
calls: unknown[][];
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}, type: string): string[];
|
|
41
|
+
export declare function requestIdFor(channel: {
|
|
42
|
+
send: {
|
|
43
|
+
mock: {
|
|
44
|
+
calls: unknown[][];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}, type: string): string;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { AdaMessagingStartOptions, AdaSdkEventCallback, ConversationInfo, Delegate, MetaFieldValue, PublicMessage, ResetParams, SendMessageResult, WindowInfo } from "./client-types.js";
|
|
2
|
+
/** One queued call captured by the embed loader before the SDK was ready. */
|
|
3
|
+
export interface LoaderQueueAction {
|
|
4
|
+
method: string;
|
|
5
|
+
arguments: unknown[];
|
|
6
|
+
}
|
|
7
|
+
/** Whether a replayed loader-queue action resolved or rejected. */
|
|
8
|
+
export type LoaderQueueActionOutcome = "resolve" | "reject";
|
|
9
|
+
/** Reports the raw object identity from the host-writable loader queue. */
|
|
10
|
+
export type LoaderQueueActionOutcomeHandler = (action: object, outcome: LoaderQueueActionOutcome, detail: unknown) => void;
|
|
11
|
+
/**
|
|
12
|
+
* The public host-page facade, exposed as `window.adaEmbed`. Create it with
|
|
13
|
+
* {@link createAdaEmbedInterface}; every method resolves once the underlying
|
|
14
|
+
* client has accepted the action. Methods other than `start`, `subscribe*`,
|
|
15
|
+
* and `setDelegate` reject until `start()` has instantiated a client.
|
|
16
|
+
*/
|
|
17
|
+
export interface AdaEmbedInterface {
|
|
18
|
+
/**
|
|
19
|
+
* Instantiate and start the Messaging client with the merged settings
|
|
20
|
+
* (`window.adaSettings`, then earlier settings, then this call's).
|
|
21
|
+
* Rejects with `AdaEmbedError("start_already_active")` when already
|
|
22
|
+
* started and `"start_interrupted"` when a callback stops it mid-start.
|
|
23
|
+
* `settings.handle` is required unless it was already provided.
|
|
24
|
+
*/
|
|
25
|
+
start: (settings?: AdaMessagingStartOptions) => Promise<void>;
|
|
26
|
+
/** Stop and tear down the running client. A later start() may run again. */
|
|
27
|
+
stop: () => Promise<void>;
|
|
28
|
+
/** Open the chat drawer when closed, or close it when open. */
|
|
29
|
+
toggle: () => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Permanently clear the chatter's conversation history and persisted
|
|
32
|
+
* state. Resolves on durable confirmation from the runtime.
|
|
33
|
+
*/
|
|
34
|
+
deleteHistory: () => Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Reset the session. By default this clears history and creates a new
|
|
37
|
+
* chatter; pass `resetChatHistory: false` to update config while keeping
|
|
38
|
+
* history. Caller-supplied `metaFields` apply on a full reset only when
|
|
39
|
+
* the host opted in via `allowMetaFieldsInReset`.
|
|
40
|
+
*/
|
|
41
|
+
reset: (params?: ResetParams) => Promise<void>;
|
|
42
|
+
/** Merge non-sensitive metafield key/value pairs onto the chatter. */
|
|
43
|
+
setMetaFields: (fields: Record<string, unknown>) => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Merge sensitive metafield key/value pairs, delivered over the secure
|
|
46
|
+
* storage transport and never readable back via getMetaFields().
|
|
47
|
+
*/
|
|
48
|
+
setSensitiveMetaFields: (fields: Record<string, unknown>) => Promise<void>;
|
|
49
|
+
/** Show a test-mode banner with the given label, or remove it with null. */
|
|
50
|
+
setTestModeBanner: (label: string | null) => Promise<void>;
|
|
51
|
+
/** Read the current window state (open/drawer/chatter flags). */
|
|
52
|
+
getInfo: () => Promise<WindowInfo>;
|
|
53
|
+
/** Read the chatter's non-sensitive metafields. Sensitive fields are never returned. */
|
|
54
|
+
getMetaFields: () => Promise<Record<string, MetaFieldValue>>;
|
|
55
|
+
/** Whether the chat is currently visible to the user. */
|
|
56
|
+
isOpen: () => Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Read the active conversation id and live-agent handoff state.
|
|
59
|
+
* Requires `enableProgrammaticControl`; rejects when the gate is off.
|
|
60
|
+
*/
|
|
61
|
+
getConversation: () => Promise<ConversationInfo>;
|
|
62
|
+
/**
|
|
63
|
+
* Read the conversation transcript as public message shapes.
|
|
64
|
+
* Requires `enableProgrammaticControl`; rejects when the gate is off.
|
|
65
|
+
*/
|
|
66
|
+
getMessages: () => Promise<PublicMessage[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Replace the composer input text. Requires `enableProgrammaticControl`;
|
|
69
|
+
* throws `HeadlessModeError` in headless mode (there is no composer).
|
|
70
|
+
*/
|
|
71
|
+
setComposerText: (text: string) => Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Register a delegate whose `beforeSend` hook may rewrite or veto outgoing
|
|
74
|
+
* text. Callable before start(); requires `enableProgrammaticControl`
|
|
75
|
+
* once a client is running. Pass null/undefined to clear.
|
|
76
|
+
*/
|
|
77
|
+
setDelegate: (delegate: Delegate | null | undefined) => void;
|
|
78
|
+
/** Send a custom analytics event for conversation tracking. */
|
|
79
|
+
trackEvent: (key: string, value?: number, meta?: Record<string, unknown>) => Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Subscribe to a public `ada:*` event key. Resolves a subscription id for
|
|
82
|
+
* unsubscribeEvent(). Callable before start(); subscriptions replay onto
|
|
83
|
+
* each started client.
|
|
84
|
+
*/
|
|
85
|
+
subscribeEvent: (key: string, callback: AdaSdkEventCallback) => Promise<number>;
|
|
86
|
+
/** Remove a subscription created by subscribeEvent() or subscribeAll(). */
|
|
87
|
+
unsubscribeEvent: (id: number) => Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Subscribe to every broadcast event. The gated transcript events
|
|
90
|
+
* (`ada:message:sent` / `ada:message:received`) are exact-subscription
|
|
91
|
+
* only and never delivered to wildcard subscribers.
|
|
92
|
+
*/
|
|
93
|
+
subscribeAll: (callback: (key: string, data: unknown) => void) => Promise<number>;
|
|
94
|
+
/** Open the chat drawer. No-op in headless mode. */
|
|
95
|
+
open: () => Promise<void>;
|
|
96
|
+
/** Close the chat drawer. */
|
|
97
|
+
close: () => Promise<void>;
|
|
98
|
+
/** Switch the conversation language (e.g. "en", "fr"). */
|
|
99
|
+
setLanguage: (language: string) => Promise<void>;
|
|
100
|
+
/** Set the color scheme; "auto" follows the OS preference. */
|
|
101
|
+
setTheme: (theme: "light" | "dark" | "auto") => Promise<void>;
|
|
102
|
+
/** Register a push-notification device token for this chatter. */
|
|
103
|
+
setDeviceToken: (token: string) => Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Send a message into the conversation as the user. Requires
|
|
106
|
+
* `enableProgrammaticControl`; resolves the accepted message id.
|
|
107
|
+
*/
|
|
108
|
+
sendMessage: (body: string) => Promise<SendMessageResult>;
|
|
109
|
+
/** Open the chat in response to a host-handled push notification tap. */
|
|
110
|
+
handleNotification: () => Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Prompt for web-notification permission via the browser. Call it from a
|
|
113
|
+
* user gesture; resolves the resulting permission, or null when the
|
|
114
|
+
* Notification API is unavailable.
|
|
115
|
+
*/
|
|
116
|
+
requestNotifications: () => Promise<NotificationPermission | null>;
|
|
117
|
+
/** @deprecated Messaging supports only generative features; scripted/declarative proactive messages are ignored. */
|
|
118
|
+
createProactive: (body: string, duration?: number, responseId?: string) => Promise<void>;
|
|
119
|
+
/** @deprecated Messaging supports only generative features; scripted/declarative campaigns are ignored. */
|
|
120
|
+
triggerCampaign: (campaignKey: string, options?: Record<string, unknown>) => Promise<void>;
|
|
121
|
+
/** @deprecated Messaging supports only generative features; scripted/declarative campaigns are ignored. */
|
|
122
|
+
evaluateCampaignConditions: (options?: Record<string, unknown>) => Promise<void>;
|
|
123
|
+
/** Close the currently displayed proactive or campaign bubble. */
|
|
124
|
+
closeCampaign: () => Promise<void>;
|
|
125
|
+
/** Trigger a generative Answer by its response id. */
|
|
126
|
+
triggerAnswer: (answerId: string) => Promise<void>;
|
|
127
|
+
/** Trigger a proactive message by key, with optional template params. */
|
|
128
|
+
triggerProactive: (messageKeyOrOptions: string | {
|
|
129
|
+
messageKey: string;
|
|
130
|
+
params?: Record<string, string>;
|
|
131
|
+
}, params?: Record<string, string>) => Promise<void>;
|
|
132
|
+
/** Re-evaluate and show the configured greeting for the bot. */
|
|
133
|
+
triggerGreeting: (handle?: string) => Promise<void>;
|
|
134
|
+
/** Tear down all frames, channels, and subscriptions permanently. */
|
|
135
|
+
destroy: () => Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
declare global {
|
|
138
|
+
interface Window {
|
|
139
|
+
__AdaEmbedLoaderInitialActionQueue?: LoaderQueueAction[];
|
|
140
|
+
/**
|
|
141
|
+
* @deprecated Subscribe to `ada:embed_loaded` or use
|
|
142
|
+
* `window.adaSettings.onAdaEmbedLoaded` instead.
|
|
143
|
+
*/
|
|
144
|
+
adaEmbedLoadedCallback?: () => void;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Create the public `adaEmbed` facade around a lazily-created
|
|
149
|
+
* {@link AdaMessagingClient}. Settings merge in priority order: this call's
|
|
150
|
+
* `initialSettings` over `window.adaSettings`, then `start(settings)` over
|
|
151
|
+
* both. Subscriptions and a delegate registered before `start()` are queued
|
|
152
|
+
* and replayed onto each started client.
|
|
153
|
+
*/
|
|
154
|
+
export declare function createAdaEmbedInterface(initialSettings?: AdaMessagingStartOptions): AdaEmbedInterface;
|
|
155
|
+
/**
|
|
156
|
+
* Backward-compatible method-event replay for already-released loaders.
|
|
157
|
+
*
|
|
158
|
+
* Keep this frozen-queue Promise chain separate from atomic replay. Existing
|
|
159
|
+
* loaders observe synchronous validation and one Promise reaction per API call.
|
|
160
|
+
*/
|
|
161
|
+
export declare function dispatchEmbedLoaderInitialActionQueue(api: object): void;
|
|
162
|
+
/**
|
|
163
|
+
* Replays for a loader that can restore legacy after genuine startup failure.
|
|
164
|
+
* Terminal validation and invocation outcomes use exact action identity. The
|
|
165
|
+
* returned promise is only the startup decision, while `onQueueDrained` closes
|
|
166
|
+
* retained-facade routing synchronously.
|
|
167
|
+
* An already-empty queue can invoke `onQueueDrained` before this function returns,
|
|
168
|
+
* so the loader must finish its handoff state changes before calling this function.
|
|
169
|
+
* If the frozen queue has no `start`, startup is accepted immediately; a `start`
|
|
170
|
+
* appended later is still replayed and exact-settled but cannot reopen rollback.
|
|
171
|
+
*/
|
|
172
|
+
export declare function dispatchEmbedLoaderInitialActionQueueForAtomicHandoff(api: object, onOutcome: LoaderQueueActionOutcomeHandler, onQueueDrained: () => void): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle channel between `createAdaEmbedInterface` and the npm loader's
|
|
3
|
+
* memo: a non-enumerable getter over closure state, so the loader never
|
|
4
|
+
* mutates the public surface and `Object.freeze` on the facade still works.
|
|
5
|
+
* `Symbol.for` because the loader and the CDN runtime are separate builds;
|
|
6
|
+
* a runtime that predates the getter yields `undefined` — degrade gracefully.
|
|
7
|
+
*/
|
|
8
|
+
export declare const EMBED_LIFECYCLE_STOPPED: unique symbol;
|
|
9
|
+
/** Read the facade's stopped flag; `undefined` when the runtime predates it. */
|
|
10
|
+
export declare function readEmbedStoppedFlag(ada: object): boolean | undefined;
|
|
11
|
+
/** Define the getter at facade creation time, before any host freeze. */
|
|
12
|
+
export declare function defineEmbedStoppedFlag(ada: object, readStopped: () => boolean): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getFallbackDataURI(): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { FrameChannel, FrameName, FrameRegistry } from "../frame-channel/index.js";
|
|
2
|
+
export interface FrameManagerOptions {
|
|
3
|
+
handle: string;
|
|
4
|
+
/** Resolved asset rollout cluster (e.g. "ada.support") */
|
|
5
|
+
cluster: string;
|
|
6
|
+
/** Value of import.meta.env.VITE_ASSETS_ORIGIN */
|
|
7
|
+
assetsOrigin: string;
|
|
8
|
+
/** Value of import.meta.env.VITE_COMMIT_SHA — omit for un-versioned assets */
|
|
9
|
+
commitSha?: string;
|
|
10
|
+
container: HTMLElement;
|
|
11
|
+
onFrameTimeout: (name: FrameName, message: string) => void;
|
|
12
|
+
setupCoreChannel: (channel: FrameChannel) => void;
|
|
13
|
+
setupButtonChannel: (channel: FrameChannel) => void;
|
|
14
|
+
setupIntroChannel: (channel: FrameChannel) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* FrameManager — owns the iframe registry, postMessage channels, and frame
|
|
18
|
+
* load lifecycle.
|
|
19
|
+
*
|
|
20
|
+
* All low-level DOM operations delegate to the pure-function helpers in
|
|
21
|
+
* `client-frame-runtime.ts`. This class provides the stateful wrapper that
|
|
22
|
+
* wires those functions together and holds the shared state they need.
|
|
23
|
+
*
|
|
24
|
+
* Responsibilities:
|
|
25
|
+
* - buildAssetUrl: construct versioned asset URLs with ada_handle/cluster params
|
|
26
|
+
* - mountFrame: create an iframe, append it to the container, start load timeout
|
|
27
|
+
* - sendToCore: send a typed postMessage to the core frame channel
|
|
28
|
+
* - getFrameOrigin: derive the expected origin from a frame's src
|
|
29
|
+
* - teardown: cancel timers, disconnect channels, remove container from DOM
|
|
30
|
+
*/
|
|
31
|
+
export declare class FrameManager {
|
|
32
|
+
private readonly _frames;
|
|
33
|
+
private readonly _channels;
|
|
34
|
+
private readonly _loadTimers;
|
|
35
|
+
private readonly _options;
|
|
36
|
+
constructor(options: FrameManagerOptions);
|
|
37
|
+
/** The container element that holds all managed iframes. */
|
|
38
|
+
get container(): HTMLElement;
|
|
39
|
+
/** Read-only view of the iframe registry — used by channel-setup and proactive helpers. */
|
|
40
|
+
get frames(): FrameRegistry;
|
|
41
|
+
/** Read-only view of the channel map — used by channel-setup and proactive helpers. */
|
|
42
|
+
get channels(): Map<FrameName, FrameChannel>;
|
|
43
|
+
/** Construct a versioned asset URL for the given package and path. */
|
|
44
|
+
buildAssetUrl(packageName: "sdk" | "integrations", path: string): string;
|
|
45
|
+
/** Create an iframe, append it to the container, and register a load timeout. */
|
|
46
|
+
mountFrame(name: FrameName, options: {
|
|
47
|
+
style: string;
|
|
48
|
+
}): void;
|
|
49
|
+
/** Send a typed postMessage to the core frame. No-op if the channel is not yet open. */
|
|
50
|
+
sendToCore<T>(type: string, payload: T): void;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve a frame's absolute origin from its src attribute.
|
|
53
|
+
* Returns null for invalid or non-http(s) URLs.
|
|
54
|
+
*/
|
|
55
|
+
getFrameOrigin(frame: HTMLIFrameElement): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* Tear down all managed state:
|
|
58
|
+
* - disconnect all frame channels
|
|
59
|
+
* - clear load timers
|
|
60
|
+
* - remove the container from the DOM
|
|
61
|
+
*/
|
|
62
|
+
teardown(): void;
|
|
63
|
+
private _onFrameLoaded;
|
|
64
|
+
}
|