@salesforce/vite-plugin-lwc-ui-bundle 1.130.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.
Files changed (43) hide show
  1. package/LICENSE.txt +82 -0
  2. package/README.md +222 -0
  3. package/dist/discovery.d.ts +3 -0
  4. package/dist/discovery.d.ts.map +1 -0
  5. package/dist/index.d.ts +10 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +509 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/plugins/lightning-npm.d.ts +4 -0
  10. package/dist/plugins/lightning-npm.d.ts.map +1 -0
  11. package/dist/plugins/lwc-bridge.d.ts +3 -0
  12. package/dist/plugins/lwc-bridge.d.ts.map +1 -0
  13. package/dist/plugins/lwc-wrapper.d.ts +6 -0
  14. package/dist/plugins/lwc-wrapper.d.ts.map +1 -0
  15. package/dist/plugins/missing-css.d.ts +3 -0
  16. package/dist/plugins/missing-css.d.ts.map +1 -0
  17. package/dist/plugins/proxy.d.ts +26 -0
  18. package/dist/plugins/proxy.d.ts.map +1 -0
  19. package/dist/plugins/scoped-providers.d.ts +4 -0
  20. package/dist/plugins/scoped-providers.d.ts.map +1 -0
  21. package/dist/providers/access-check.d.ts +3 -0
  22. package/dist/providers/access-check.d.ts.map +1 -0
  23. package/dist/providers/client.d.ts +3 -0
  24. package/dist/providers/client.d.ts.map +1 -0
  25. package/dist/providers/gate.d.ts +3 -0
  26. package/dist/providers/gate.d.ts.map +1 -0
  27. package/dist/providers/i18n.d.ts +7 -0
  28. package/dist/providers/i18n.d.ts.map +1 -0
  29. package/dist/providers/index.d.ts +13 -0
  30. package/dist/providers/index.d.ts.map +1 -0
  31. package/dist/providers/index.js +462 -0
  32. package/dist/providers/index.js.map +1 -0
  33. package/dist/providers/label.d.ts +3 -0
  34. package/dist/providers/label.d.ts.map +1 -0
  35. package/dist/providers/lightning-graphql.d.ts +17 -0
  36. package/dist/providers/lightning-graphql.d.ts.map +1 -0
  37. package/dist/providers/primitive-utils.d.ts +3 -0
  38. package/dist/providers/primitive-utils.d.ts.map +1 -0
  39. package/dist/types.d.ts +44 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/docs/chat-wrapper-guide.md +134 -0
  42. package/docs/user-guide.md +377 -0
  43. package/package.json +74 -0
@@ -0,0 +1,134 @@
1
+ # Chat Wrapper Authoring Guide
2
+
3
+ ## Purpose
4
+
5
+ Use this guide to add a chat-aware wrapper around an existing LWC component without
6
+ changing the component internals.
7
+
8
+ The wrapper reads tool output from ChatGPT/MCP, maps it into stable component props,
9
+ and renders the existing component.
10
+
11
+ ## Architecture
12
+
13
+ - **Wrapper (chat-aware):** reads tool output and reacts to updates.
14
+ - **Mapper (shape-normalizer):** converts tool output variants into one prop contract.
15
+ - **Core component (unchanged):** consumes `@api` props as if running in normal app code.
16
+
17
+ Keep this rule: business UI stays in the core component, chat glue stays in wrapper/mapper.
18
+
19
+ ## Files and Responsibilities
20
+
21
+ - `sf/lwc/bcx/chatContextAdapter/chatContextAdapter.js`
22
+ - `accessToolOutput()` for initial state.
23
+ - `subscribeToolOutput(listener)` for live updates.
24
+ - `sf/lwc/bcx/<component>ChatMapper/<component>ChatMapper.js`
25
+ - Converts raw tool output into a strict prop object or `null`.
26
+ - `sf/lwc/bcx/<component>ChatWrapper/<component>ChatWrapper.js`
27
+ - Calls mapper, stores mapped state, renders waiting/ready UI.
28
+ - `sf/lwc/bcx/<component>ChatWrapper/<component>ChatWrapper.html`
29
+ - Renders loading state, waiting state, and wrapped component.
30
+ - `src/app/bootstrap.js`
31
+ - Chooses which wrapper to mount at startup.
32
+
33
+ ## Step-by-Step: Create a New Wrapper
34
+
35
+ ### 1) Define the target prop contract
36
+
37
+ Write down exactly what props the core component needs. Example (`recordDetail`):
38
+
39
+ - `data`
40
+ - `recordId`
41
+ - `fieldMetadata`
42
+ - `layout`
43
+ - `picklistValues`
44
+ - `changedFields`
45
+ - `expandable`
46
+
47
+ The mapper should always output this shape (or `null`).
48
+
49
+ ### 2) Implement mapper first
50
+
51
+ Mapper requirements:
52
+
53
+ - Accept both wrapped and raw shapes (`structuredContent`, raw object, nested aliases).
54
+ - Normalize key aliases (`recordDetail` vs `record_detail`, etc).
55
+ - Unwrap transport wrappers (`properties`, `oneOf*`) if present.
56
+ - Return `null` when required data is missing (do not throw for bad payloads).
57
+ - Keep pure and side-effect free.
58
+
59
+ ### 3) Implement wrapper component
60
+
61
+ Wrapper behavior:
62
+
63
+ - On `connectedCallback`, read initial output with `accessToolOutput()`.
64
+ - Subscribe with `subscribeToolOutput()` for updates.
65
+ - Call mapper and update tracked state.
66
+ - Render:
67
+ - loading text while initializing,
68
+ - waiting text when mapping fails or no data,
69
+ - wrapped component when mapping succeeds.
70
+
71
+ ### 4) Keep fallback behavior explicit
72
+
73
+ Current pattern is **no local sample-data fallback** inside chat wrappers.
74
+
75
+ If tool output is absent, show waiting state and do not render partial UI.
76
+
77
+ ### 5) Add logs while debugging, remove noise after validation
78
+
79
+ Temporary logs in wrapper are useful when validating event delivery/mapping.
80
+ Keep logs concise and prefixed per wrapper.
81
+
82
+ ## RecordDetail Reference (Current)
83
+
84
+ `recordDetail` currently supports:
85
+
86
+ - `toolOutput.structuredContent.recordDetail`
87
+ - `toolOutput.structuredContent.record_detail`
88
+ - compatible direct structured/raw payload shapes
89
+
90
+ Key mapping in `recordDetail` wrapper:
91
+
92
+ - `data` -> `data`
93
+ - `recordId` -> `record-id`
94
+ - `fieldMetadata` -> `field-metadata`
95
+ - `layout` -> `layout`
96
+ - `picklistValues` -> `picklist-values`
97
+ - `changedFields` -> `changed-fields`
98
+ - `expandable` -> `expandable`
99
+
100
+ ## Manual Component Swap in `bootstrap.js`
101
+
102
+ This branch uses one bootstrap path and mounts one wrapper directly.
103
+
104
+ To test `recordList` wrapper instead of `recordDetail`, replace the import + tag in
105
+ `src/app/bootstrap.js` with:
106
+
107
+ ```js
108
+ const { default: RecordListChatWrapper } =
109
+ await import("../../sf/lwc/bcx/recordListChatWrapper/recordListChatWrapper.js");
110
+ const wrapper = createElement("bcx-record-list-chat-wrapper", {
111
+ is: RecordListChatWrapper,
112
+ });
113
+ mountNode.appendChild(wrapper);
114
+ ```
115
+
116
+ To switch back to `recordDetail`, restore:
117
+
118
+ ```js
119
+ const { default: RecordDetailChatWrapper } =
120
+ await import("../../sf/lwc/bcx/recordDetailChatWrapper/recordDetailChatWrapper.js");
121
+ const wrapper = createElement("bcx-record-detail-chat-wrapper", {
122
+ is: RecordDetailChatWrapper,
123
+ });
124
+ mountNode.appendChild(wrapper);
125
+ ```
126
+
127
+ ## Validation Checklist for Any New Wrapper
128
+
129
+ - Mapper returns stable shape for valid payloads.
130
+ - Mapper returns `null` for invalid/incomplete payloads.
131
+ - Wrapper updates on `openai:set_globals`.
132
+ - Waiting state shown when no tool output exists.
133
+ - Wrapped component renders with mapped props when data exists.
134
+ - `npm run build` succeeds after wrapper swap in `bootstrap.js`.
@@ -0,0 +1,377 @@
1
+ # User Guide: Compiling LWC Components into a Static Bundle
2
+
3
+ This guide walks through using `@salesforce/vite-plugin-lwc-ui-bundle` to compile
4
+ your existing LWC components into a single self-contained `dist/index.html` —
5
+ no server required, opens directly in a browser.
6
+
7
+ ---
8
+
9
+ ## Prerequisites
10
+
11
+ - Node.js >= 20.0.0
12
+ - Your LWC components already exist in a Salesforce DX project
13
+
14
+ ---
15
+
16
+ ## Project Structure
17
+
18
+ The example project `my-lwc-app` uses the standard Salesforce DX flat structure:
19
+
20
+ ```
21
+ my-lwc-app/
22
+ ├── force-app/main/default/lwc/
23
+ │ ├── helloApp/ ← component directly, no namespace folder
24
+ │ │ ├── helloApp.js
25
+ │ │ ├── helloApp.html
26
+ │ │ └── helloApp.js-meta.xml
27
+ │ └── helloMessage/
28
+ │ ├── helloMessage.js
29
+ │ ├── helloMessage.html
30
+ │ └── helloMessage.js-meta.xml
31
+ ├── src/
32
+ │ └── bootstrap.js ← mounts root component
33
+ ├── index.html ← entry point
34
+ ├── vite.config.js ← plugin config
35
+ └── package.json
36
+ ```
37
+
38
+ Use `namespace: 'c'` in `vite.config.js` to tell the plugin to treat this flat
39
+ structure as namespace `c` — components are then importable as `'c/helloApp'`.
40
+
41
+ ---
42
+
43
+ ## Step 1: Add Files
44
+
45
+ ### `package.json`
46
+
47
+ ```json
48
+ {
49
+ "name": "my-lwc-app",
50
+ "version": "1.0.0",
51
+ "type": "module",
52
+ "scripts": {
53
+ "build": "vite build",
54
+ "dev": "vite",
55
+ "preview": "vite preview"
56
+ },
57
+ "devDependencies": {
58
+ "@lwc/rollup-plugin": "^9.0.0",
59
+ "@salesforce/vite-plugin-lwc-ui-bundle": "^1.0.0",
60
+ "vite": "^7.0.0",
61
+ "vite-plugin-singlefile": "^2.3.0"
62
+ },
63
+ "dependencies": {
64
+ "@salesforce-ux/design-system": "^2.29.1",
65
+ "lightning-base-components": "^1.28.17-alpha",
66
+ "lwc": "^9.0.0"
67
+ }
68
+ }
69
+ ```
70
+
71
+ ### `vite.config.js`
72
+
73
+ ```js
74
+ import { defineConfig } from "vite";
75
+ import lwcVitePlugin from "@salesforce/vite-plugin-lwc-ui-bundle";
76
+ import { viteSingleFile } from "vite-plugin-singlefile";
77
+
78
+ export default defineConfig({
79
+ build: {
80
+ target: "esnext", // required for top-level await in bootstrap.js
81
+ },
82
+ plugins: [
83
+ lwcVitePlugin({
84
+ modules: {
85
+ // Flat DX structure: specify { path, namespace } per directory
86
+ // Use a plain string if your dir already has namespace sub-folders
87
+ dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }],
88
+
89
+ // Include if your components use lightning/* base components
90
+ npm: ["lightning-base-components"],
91
+ },
92
+ }),
93
+ viteSingleFile(), // inlines everything into a single index.html
94
+ ],
95
+ });
96
+ ```
97
+
98
+ ### `index.html`
99
+
100
+ ```html
101
+ <!doctype html>
102
+ <html lang="en">
103
+ <head>
104
+ <meta charset="UTF-8" />
105
+ <title>My LWC App</title>
106
+ </head>
107
+ <body>
108
+ <div id="app"></div>
109
+ <script>
110
+ globalThis.lwcRuntimeFlags = { DISABLE_SYNTHETIC_SHADOW: true };
111
+ </script>
112
+ <script type="module" src="/src/bootstrap.js"></script>
113
+ </body>
114
+ </html>
115
+ ```
116
+
117
+ ### `src/bootstrap.js`
118
+
119
+ ```js
120
+ import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
121
+ import "@lwc/synthetic-shadow";
122
+ import { createElement } from "lwc";
123
+
124
+ // Import your root component using its LWC specifier: <namespace>/<componentName>
125
+ import App from "c/helloApp";
126
+
127
+ // Mount it — tag name is the kebab-case version of the specifier
128
+ const el = createElement("c-hello-app", { is: App });
129
+ document.getElementById("app").appendChild(el);
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Step 2: Install Dependencies
135
+
136
+ ```bash
137
+ npm install
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Step 3: Build
143
+
144
+ ```bash
145
+ npm run build
146
+ ```
147
+
148
+ Output: `dist/index.html` — a single file with all JS and CSS inlined.
149
+
150
+ ---
151
+
152
+ ## Step 4: Test
153
+
154
+ **Option A — Open directly in browser:**
155
+
156
+ ```bash
157
+ open dist/index.html
158
+ ```
159
+
160
+ **Option B — Dev server with live reload:**
161
+
162
+ ```bash
163
+ npm run dev
164
+ # Open http://localhost:5173
165
+ ```
166
+
167
+ **Option C — Preview the production build:**
168
+
169
+ ```bash
170
+ npm run preview
171
+ # Open http://localhost:4173
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Component Namespace Convention
177
+
178
+ The plugin supports two directory structures:
179
+
180
+ ### Flat DX structure (standard Salesforce DX)
181
+
182
+ ```
183
+ force-app/main/default/lwc/
184
+ helloApp/
185
+ helloApp.js
186
+ ```
187
+
188
+ Use `{ path, namespace }` per directory to specify the namespace:
189
+
190
+ ```js
191
+ modules: {
192
+ dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }];
193
+ }
194
+ ```
195
+
196
+ | Directory | LWC Specifier | HTML Tag |
197
+ | ------------------- | ------------------ | ----------------- |
198
+ | `lwc/helloApp/` | `'c/helloApp'` | `c-hello-app` |
199
+ | `lwc/helloMessage/` | `'c/helloMessage'` | `c-hello-message` |
200
+
201
+ ### Namespaced structure
202
+
203
+ ```
204
+ modules/
205
+ records/
206
+ accountOutputName/
207
+ accountOutputName.js
208
+ ```
209
+
210
+ Omit `namespace` — the sub-directory name is used as the namespace:
211
+
212
+ ```js
213
+ modules: {
214
+ dirs: ["modules"];
215
+ }
216
+ ```
217
+
218
+ | Directory | LWC Specifier | HTML Tag |
219
+ | ------------------------------------ | ----------------------------- | ----------------------------- |
220
+ | `modules/records/accountOutputName/` | `'records/accountOutputName'` | `records-account-output-name` |
221
+
222
+ ---
223
+
224
+ ## Common Errors
225
+
226
+ ### `Rollup failed to resolve import "lightning/button"`
227
+
228
+ Your component uses a Lightning Base Component. Add to `vite.config.js`:
229
+
230
+ ```js
231
+ modules: {
232
+ npm: ["lightning-base-components"];
233
+ }
234
+ ```
235
+
236
+ ### `[scoped-module-providers] Unhandled import: @salesforce/label/...`
237
+
238
+ Expected — the plugin returns the label key as display text by default.
239
+ To provide real label values:
240
+
241
+ ```js
242
+ import { builtins } from "@salesforce/vite-plugin-lwc-ui-bundle";
243
+
244
+ lwcVitePlugin({
245
+ providers: [builtins.label({ "c.Save": "Save", "c.Cancel": "Cancel" })],
246
+ });
247
+ ```
248
+
249
+ ### Component renders but looks unstyled
250
+
251
+ Add SLDS import to `src/bootstrap.js`:
252
+
253
+ ```js
254
+ import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
255
+ ```
256
+
257
+ ### `[scoped-module-providers] Unhandled import: @salesforce/user/Id`
258
+
259
+ Expected warning — `@salesforce/user/*` imports return `undefined` by default.
260
+ To provide real values (e.g. current user ID), add the user provider:
261
+
262
+ ```js
263
+ import { builtins } from "@salesforce/vite-plugin-lwc-ui-bundle";
264
+
265
+ lwcVitePlugin({
266
+ providers: [
267
+ builtins.user({ Id: "005xx000001X8AAAA" }), // optional: override user fields
268
+ ],
269
+ });
270
+ ```
271
+
272
+ ### `Top-level await is not available in the configured target environment`
273
+
274
+ Your `bootstrap.js` uses top-level `await` (required when initialising the Data
275
+ SDK). Add `target: 'esnext'` to the build config:
276
+
277
+ ```js
278
+ export default defineConfig({
279
+ build: { target: "esnext" },
280
+ plugins: [...],
281
+ });
282
+ ```
283
+
284
+ ### `Rollup failed to resolve import "force/someModule"`
285
+
286
+ Core-only module — add a stub:
287
+
288
+ ```js
289
+ // stubs/someModule.js
290
+ export const someExport = () => {};
291
+ ```
292
+
293
+ ```js
294
+ // vite.config.js
295
+ lwcVitePlugin({ stubs: { "force/someModule": "./stubs/someModule.js" } });
296
+ ```
297
+
298
+ ---
299
+
300
+ ## Connecting to a Real Salesforce Org (lwcProxy)
301
+
302
+ By default the plugin runs fully off-platform with mock data. To connect your
303
+ components to a real Salesforce org in local dev — enabling `lightning/graphql`
304
+ to execute real queries — add `lwcProxy()` alongside `lwcVitePlugin()`.
305
+
306
+ ### Prerequisites
307
+
308
+ - Salesforce CLI installed and an org connected: `sf org display`
309
+ - Additional packages: `@salesforce/sdk-data` and `@salesforce/ui-bundle`
310
+
311
+ ```bash
312
+ npm install @salesforce/sdk-data @salesforce/ui-bundle
313
+ ```
314
+
315
+ ### 1. Add lwcProxy to vite.config.js
316
+
317
+ ```js
318
+ import { defineConfig } from "vite";
319
+ import lwcVitePlugin, { lwcProxy } from "@salesforce/vite-plugin-lwc-ui-bundle";
320
+ import { viteSingleFile } from "vite-plugin-singlefile";
321
+
322
+ export default defineConfig({
323
+ build: {
324
+ target: "esnext", // required for top-level await in bootstrap.js
325
+ },
326
+ plugins: [
327
+ lwcProxy(), // auto-reads sf CLI default org credentials
328
+ // lwcProxy({ orgAlias: "my-org", debug: true }) // explicit org + verbose logging
329
+ lwcVitePlugin({
330
+ modules: {
331
+ dirs: [{ path: "force-app/main/default/lwc", namespace: "c" }],
332
+ },
333
+ }),
334
+ viteSingleFile(),
335
+ ],
336
+ });
337
+ ```
338
+
339
+ ### 2. Initialise the Data SDK in bootstrap.js
340
+
341
+ The SDK must be initialised before any component that uses `lightning/graphql`
342
+ mounts. Use a top-level `await` import to guarantee ordering:
343
+
344
+ ```js
345
+ import "@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.css";
346
+ import "@lwc/synthetic-shadow";
347
+ import { createElement } from "lwc";
348
+
349
+ // Initialise the Data SDK — lwcProxy() handles /services/* on the Vite dev server
350
+ import { createDataSDK } from "@salesforce/sdk-data";
351
+ try {
352
+ globalThis.__sfdc_sdk__ = await createDataSDK({
353
+ uiBundle: { basePath: "/" },
354
+ });
355
+ } catch (_err) {
356
+ globalThis.__sfdc_sdk__ = {};
357
+ }
358
+
359
+ import App from "c/helloApp";
360
+ const el = createElement("c-hello-app", { is: App });
361
+ document.getElementById("app").appendChild(el);
362
+ ```
363
+
364
+ ### 3. Run the dev server
365
+
366
+ ```bash
367
+ npm run dev
368
+ # Terminal shows: [lwc-proxy] Connected to https://your-org.my.salesforce.com
369
+ # Open http://localhost:5173
370
+ ```
371
+
372
+ Components using `lightning/graphql` will now execute real GraphQL queries
373
+ against your org. The proxy intercepts `/services/*` calls inside the Vite dev
374
+ server — no separate proxy process needed.
375
+
376
+ > **Note:** The `basePath: '/'` setting works for `npm run dev` only. For
377
+ > production builds (`dist/index.html`), a standalone proxy server is required.
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@salesforce/vite-plugin-lwc-ui-bundle",
3
+ "version": "1.130.0",
4
+ "description": "Vite plugin for compiling LWC components into static bundles for off-platform and MCP use",
5
+ "license": "SEE LICENSE IN LICENSE.txt",
6
+ "author": "Salesforce",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/salesforce-experience-platform-emu/webapps",
11
+ "directory": "packages/vite-plugin-lwc-ui-bundle"
12
+ },
13
+ "keywords": [
14
+ "vite",
15
+ "vite-plugin",
16
+ "lwc",
17
+ "lightning-web-components",
18
+ "salesforce",
19
+ "mcp",
20
+ "agentic",
21
+ "off-platform",
22
+ "compiler"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./providers": {
30
+ "types": "./dist/providers/index.d.ts",
31
+ "import": "./dist/providers/index.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "main": "./dist/index.js",
36
+ "types": "./dist/index.d.ts",
37
+ "files": [
38
+ "dist",
39
+ "README.md",
40
+ "docs"
41
+ ],
42
+ "scripts": {
43
+ "build": "vite build",
44
+ "clean": "rm -rf dist",
45
+ "dev": "vite build --watch",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest",
48
+ "test:coverage": "vitest run --coverage"
49
+ },
50
+ "peerDependencies": {
51
+ "@lwc/rollup-plugin": "^9.0.0",
52
+ "@salesforce/sdk-chat": "^1.123.0",
53
+ "@salesforce/ui-bundle": "^1.123.0",
54
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "@salesforce/ui-bundle": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "devDependencies": {
62
+ "@salesforce/sdk-chat": "^1.130.0",
63
+ "typescript": "^5.9.3",
64
+ "vite": "^7.0.0",
65
+ "vite-plugin-dts": "^4.5.4",
66
+ "vitest": "^4.0.6"
67
+ },
68
+ "engines": {
69
+ "node": ">=20.0.0"
70
+ },
71
+ "publishConfig": {
72
+ "access": "public"
73
+ }
74
+ }