@salesforcedevs/dx-components 1.31.2 → 1.31.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/lwc.config.json CHANGED
@@ -6,6 +6,7 @@
6
6
  ],
7
7
  "expose": [
8
8
  "dx/agenda",
9
+ "dx/agentMiawUi",
9
10
  "dx/alert",
10
11
  "dx/audio",
11
12
  "dx/banner",
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.31.2",
3
+ "version": "1.31.4",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
7
- "node": "20.x"
7
+ "node": "22.x"
8
8
  },
9
9
  "publishConfig": {
10
10
  "access": "public"
@@ -44,5 +44,5 @@
44
44
  "luxon": "3.4.4",
45
45
  "msw": "^2.12.4"
46
46
  },
47
- "gitHead": "c9d5f51d2ff55d5879b966fdfe4d2c6b49870f67"
47
+ "gitHead": "e07990b3a28e027251ddb123cc36599ca9a983da"
48
48
  }
@@ -0,0 +1,4 @@
1
+ :host {
2
+ position: relative;
3
+ z-index: 2147483000;
4
+ }
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <div lwc:dom="manual" class="miaw-host"></div>
3
+ </template>
@@ -0,0 +1,120 @@
1
+ /* eslint-disable @lwc/lwc/no-document-query */
2
+ import { LightningElement, api } from "lwc";
3
+ import { waitUntilResolved } from "dxUtils/async";
4
+
5
+ const HOSTED_MIAW_UI_TAG = "page-builder-miaw-ui";
6
+ const SCRIPT_SRC =
7
+ "https://a.sfdcstatic.com/digital/@sfdc-www-emu/page-builder-miaw-ui/v1-stable/page-builder-miaw-ui.js";
8
+ const DEFINE_TIMEOUT_MS = 60000;
9
+ const WHEN_DEFINED_TIMEOUT_MESSAGE =
10
+ `MIAW UI embed (${HOSTED_MIAW_UI_TAG}) did not register within ${
11
+ DEFINE_TIMEOUT_MS / 1000
12
+ }s. ` +
13
+ "Confirm the script loads (network tab), your origin is allowed, and CSP permits this script.";
14
+
15
+ let scriptLoaded: Promise<void> | null = null;
16
+
17
+ async function ensureMiawScriptAndDefinition(): Promise<void> {
18
+ if (customElements.get(HOSTED_MIAW_UI_TAG)) {
19
+ return;
20
+ }
21
+
22
+ let script = document.querySelector(
23
+ `script[src="${SCRIPT_SRC}"]`
24
+ ) as HTMLScriptElement | null;
25
+
26
+ if (!script) {
27
+ script = document.createElement("script");
28
+ script.type = "module";
29
+ script.src = SCRIPT_SRC;
30
+ await new Promise<void>((resolve, reject) => {
31
+ script!.addEventListener("load", () => resolve(), { once: true });
32
+ script!.addEventListener(
33
+ "error",
34
+ () =>
35
+ reject(
36
+ new Error(
37
+ `Failed to load MIAW UI embed script (${SCRIPT_SRC}). Check status code and referrer rules.`
38
+ )
39
+ ),
40
+ { once: true }
41
+ );
42
+ document.head.appendChild(script!);
43
+ });
44
+ }
45
+ await waitUntilResolved(
46
+ customElements.whenDefined(HOSTED_MIAW_UI_TAG),
47
+ DEFINE_TIMEOUT_MS,
48
+ WHEN_DEFINED_TIMEOUT_MESSAGE
49
+ );
50
+ }
51
+
52
+ /** Loads the MIAW UI script if it is not already loaded. This occurs only once per module instance. */
53
+ function loadMiawUiScript(): Promise<void> {
54
+ if (!scriptLoaded) {
55
+ scriptLoaded = ensureMiawScriptAndDefinition();
56
+ }
57
+ return scriptLoaded;
58
+ }
59
+
60
+ export default class AgentMiawUi extends LightningElement {
61
+ /** Salesforce org id (15- or 18-character Id). */
62
+ @api orgId!: string;
63
+ /** Messaging endpoint host URL (e.g. https://org62.my.salesforce-scrt.com). */
64
+ @api messagingUrl!: string;
65
+ @api deploymentDevName = "page_builder_miaw_ui";
66
+ @api richComponentVersion = "v1-stable";
67
+ @api routingAttributes?: string;
68
+ /**
69
+ * JSON array of suggested prompt strings for the MIAW UI (e.g.
70
+ * `["Show me an Agentforce demo","Help me build a business case"]`); forwarded as `prompts` on the embed.
71
+ */
72
+ @api prompts?: string;
73
+ /** When set, forwarded to the embed as `welcome-text` (greeting / headline copy). */
74
+ @api welcomeText?: string;
75
+
76
+ /** After first mount attempt is scheduled, we do not run it again for this instance. */
77
+ private hasRendered = false;
78
+
79
+ renderedCallback(): void {
80
+ if (!this.hasRendered) {
81
+ this.hasRendered = true;
82
+ this.mountMiawHost();
83
+ }
84
+ }
85
+
86
+ private async mountMiawHost(): Promise<void> {
87
+ try {
88
+ await loadMiawUiScript();
89
+ const container = this.template.querySelector(".miaw-host");
90
+ if (!container) {
91
+ return;
92
+ }
93
+ const el = document.createElement(HOSTED_MIAW_UI_TAG);
94
+ el.setAttribute("org-id", this.orgId);
95
+ el.setAttribute("messaging-url", this.messagingUrl);
96
+ el.setAttribute("deployment-dev-name", this.deploymentDevName);
97
+ el.setAttribute("input-variant", "mini-sidebar");
98
+ el.setAttribute("is-on-digital-domain", "false");
99
+ el.setAttribute(
100
+ "rich-component-version",
101
+ this.richComponentVersion
102
+ );
103
+ if (this.routingAttributes) {
104
+ el.setAttribute(
105
+ "routing-attributes",
106
+ this.routingAttributes
107
+ );
108
+ }
109
+ if (this.prompts) {
110
+ el.setAttribute("prompts", this.prompts);
111
+ }
112
+ if (this.welcomeText) {
113
+ el.setAttribute("welcome-text", this.welcomeText);
114
+ }
115
+ container.appendChild(el);
116
+ } catch (e) {
117
+ console.error(e);
118
+ }
119
+ }
120
+ }
@@ -43,3 +43,35 @@ export function pollUntil(
43
43
  }
44
44
  });
45
45
  }
46
+
47
+ /**
48
+ * Returns the same settled value or rejection as `promise`, or rejects after `forMaximumMs`
49
+ * if it does not settle in time. When `forMaximumMs` is omitted or non-positive, returns
50
+ * `promise` unchanged. Clears the timeout when `promise` settles first.
51
+ */
52
+ export function waitUntilResolved<T>(
53
+ promise: Promise<T>,
54
+ forMaximumMs?: number,
55
+ timeoutMessage = "Timed out waiting for promise to settle."
56
+ ): Promise<T> {
57
+ if (forMaximumMs == null || forMaximumMs <= 0) {
58
+ return promise;
59
+ }
60
+
61
+ return new Promise<T>((resolve, reject) => {
62
+ const timeoutId = setTimeout(() => {
63
+ reject(new Error(timeoutMessage));
64
+ }, forMaximumMs);
65
+
66
+ promise.then(
67
+ (value) => {
68
+ clearTimeout(timeoutId);
69
+ resolve(value);
70
+ },
71
+ (reason: unknown) => {
72
+ clearTimeout(timeoutId);
73
+ reject(reason);
74
+ }
75
+ );
76
+ });
77
+ }