@salesforce/vite-plugin-lwc-ui-bundle 1.131.2 → 1.132.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 (32) hide show
  1. package/README.md +36 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +14 -4
  4. package/dist/index.js.map +1 -1
  5. package/dist/providers/index.d.ts +3 -1
  6. package/dist/providers/index.d.ts.map +1 -1
  7. package/dist/providers/index.js +4 -163
  8. package/dist/providers/index.js.map +1 -1
  9. package/dist/providers/lds/index.d.ts +10 -0
  10. package/dist/providers/lds/index.d.ts.map +1 -0
  11. package/dist/providers/lds/index.js +106 -0
  12. package/dist/providers/lds/index.js.map +1 -0
  13. package/dist/providers/lds/runtime.js +96 -0
  14. package/dist/providers/lds/runtime.js.map +1 -0
  15. package/dist/providers/lds/types.d.ts +22 -0
  16. package/dist/providers/lds/types.d.ts.map +1 -0
  17. package/dist/providers/lightning-graphql/index.d.ts +10 -0
  18. package/dist/providers/lightning-graphql/index.d.ts.map +1 -0
  19. package/dist/providers/lightning-graphql/index.js +24 -0
  20. package/dist/providers/lightning-graphql/index.js.map +1 -0
  21. package/dist/providers/lightning-graphql/runtime.js +103 -0
  22. package/dist/providers/lightning-graphql/runtime.js.map +1 -0
  23. package/dist/providers/shared/normalize-mcp-response.d.ts +20 -0
  24. package/dist/providers/shared/normalize-mcp-response.d.ts.map +1 -0
  25. package/dist/types.d.ts +1 -1
  26. package/dist/types.d.ts.map +1 -1
  27. package/docs/consumer-guide.md +429 -0
  28. package/package.json +21 -6
  29. package/skills/setup-lwc-vite-plugin/SKILL.md +242 -0
  30. package/dist/providers/lightning-graphql.d.ts +0 -17
  31. package/dist/providers/lightning-graphql.d.ts.map +0 -1
  32. package/docs/user-guide.md +0 -377
@@ -0,0 +1,106 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join, dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { init, parse } from "es-module-lexer";
5
+ import MagicString from "magic-string";
6
+ const ADAPTER_PREFIX = "sf-lds-adapter:";
7
+ const ADAPTER_ID_PREFIX = "\0" + ADAPTER_PREFIX;
8
+ const adapterBaseSource = readFileSync(
9
+ join(dirname(fileURLToPath(import.meta.url)), "runtime.js"),
10
+ "utf-8"
11
+ );
12
+ const DEFAULT_ADAPTERS = {
13
+ "lightning/uiRecordApi": {
14
+ getRecord: {
15
+ type: "wire",
16
+ toolName: "getRecordMcpTool",
17
+ configJsonSchema: {
18
+ type: "object",
19
+ properties: {
20
+ recordId: { type: "string" },
21
+ fields: { type: "array", items: { type: "string" } }
22
+ },
23
+ required: ["recordId"]
24
+ }
25
+ }
26
+ }
27
+ };
28
+ function parseImportSpecifiers(bracesContent) {
29
+ return bracesContent.split(",").map((s) => s.trim()).filter(Boolean).map((entry) => {
30
+ const asIdx = entry.indexOf(" as ");
31
+ const original = asIdx !== -1 ? entry.slice(0, asIdx).trim() : entry.trim();
32
+ return { original, full: entry };
33
+ });
34
+ }
35
+ function lds(adapters = DEFAULT_ADAPTERS) {
36
+ const specifierSnippets = Object.keys(adapters).flatMap((s) => [`'${s}'`, `"${s}"`]);
37
+ return {
38
+ name: "vite-plugin-lds",
39
+ enforce: "pre",
40
+ async transform(code, id) {
41
+ const cleanId = id.split("?")[0] ?? id;
42
+ if (!cleanId.endsWith(".js") && !cleanId.endsWith(".ts")) return null;
43
+ if (cleanId.includes("/node_modules/")) return null;
44
+ if (!specifierSnippets.some((snippet) => code.includes(snippet))) return null;
45
+ await init;
46
+ let imports;
47
+ try {
48
+ [imports] = parse(code);
49
+ } catch {
50
+ return null;
51
+ }
52
+ const relevant = imports.filter(
53
+ (imp) => imp.d === -1 && imp.n !== void 0 && imp.n in adapters
54
+ );
55
+ if (relevant.length === 0) return null;
56
+ const s = new MagicString(code);
57
+ let changed = false;
58
+ for (const imp of relevant) {
59
+ const { ss: start, se: end, n: specifier } = imp;
60
+ const statement = code.slice(start, end);
61
+ const openBrace = statement.indexOf("{");
62
+ const closeBrace = statement.indexOf("}");
63
+ if (openBrace === -1 || closeBrace === -1) continue;
64
+ const bracesContent = statement.slice(openBrace + 1, closeBrace);
65
+ const moduleAdapters = adapters[specifier];
66
+ const parsedImport = parseImportSpecifiers(bracesContent);
67
+ const registered = parsedImport.filter((p) => p.original in moduleAdapters);
68
+ const unregistered = parsedImport.filter((p) => !(p.original in moduleAdapters));
69
+ if (registered.length === 0) continue;
70
+ const parts = [
71
+ `import { ${registered.map((p) => p.full).join(", ")} } from '${ADAPTER_PREFIX}${specifier}';`
72
+ ];
73
+ if (unregistered.length > 0) {
74
+ parts.push(
75
+ `import { ${unregistered.map((p) => p.full).join(", ")} } from '${specifier}';`
76
+ );
77
+ }
78
+ s.overwrite(start, end, parts.join("\n"));
79
+ changed = true;
80
+ }
81
+ if (!changed) return null;
82
+ return { code: s.toString(), map: s.generateMap({ hires: true }) };
83
+ },
84
+ resolveId(id) {
85
+ if (id.startsWith(ADAPTER_PREFIX)) return ADAPTER_ID_PREFIX + id.slice(ADAPTER_PREFIX.length);
86
+ return null;
87
+ },
88
+ load(id) {
89
+ if (!id.startsWith(ADAPTER_ID_PREFIX)) return null;
90
+ const specifier = id.slice(ADAPTER_ID_PREFIX.length);
91
+ const moduleAdapters = adapters[specifier];
92
+ if (!moduleAdapters) return null;
93
+ const lines = [adapterBaseSource];
94
+ for (const [name, { type: _type, ...cfg }] of Object.entries(moduleAdapters)) {
95
+ lines.push(
96
+ `export const ${name} = createWireAdapter(${JSON.stringify(name)}, ${JSON.stringify(cfg)});`
97
+ );
98
+ }
99
+ return lines.join("\n");
100
+ }
101
+ };
102
+ }
103
+ export {
104
+ lds
105
+ };
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/providers/lds/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport { readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { init, parse } from \"es-module-lexer\";\nimport MagicString from \"magic-string\";\nimport type { Plugin } from \"vite\";\nimport type { JsonSchema } from \"./types\";\n\nconst ADAPTER_PREFIX = \"sf-lds-adapter:\";\nconst ADAPTER_ID_PREFIX = \"\\0\" + ADAPTER_PREFIX;\n\nconst adapterBaseSource = readFileSync(\n\tjoin(dirname(fileURLToPath(import.meta.url)), \"runtime.js\"),\n\t\"utf-8\",\n);\n\nexport interface LdsWireAdapterConfig {\n\ttype: \"wire\";\n\ttoolName: string;\n\tconfigJsonSchema: JsonSchema;\n}\n\nexport type LdsAdapterRegistry = Record<string, Record<string, LdsWireAdapterConfig>>;\n\nconst DEFAULT_ADAPTERS: LdsAdapterRegistry = {\n\t\"lightning/uiRecordApi\": {\n\t\tgetRecord: {\n\t\t\ttype: \"wire\",\n\t\t\ttoolName: \"getRecordMcpTool\",\n\t\t\tconfigJsonSchema: {\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\trecordId: { type: \"string\" },\n\t\t\t\t\tfields: { type: \"array\", items: { type: \"string\" } },\n\t\t\t\t},\n\t\t\t\trequired: [\"recordId\"],\n\t\t\t},\n\t\t},\n\t},\n};\n\nfunction parseImportSpecifiers(bracesContent: string): { original: string; full: string }[] {\n\treturn bracesContent\n\t\t.split(\",\")\n\t\t.map((s) => s.trim())\n\t\t.filter(Boolean)\n\t\t.map((entry) => {\n\t\t\tconst asIdx = entry.indexOf(\" as \");\n\t\t\tconst original = asIdx !== -1 ? entry.slice(0, asIdx).trim() : entry.trim();\n\t\t\treturn { original, full: entry };\n\t\t});\n}\n\nexport function lds(adapters: LdsAdapterRegistry = DEFAULT_ADAPTERS): Plugin {\n\tconst specifierSnippets = Object.keys(adapters).flatMap((s) => [`'${s}'`, `\"${s}\"`]);\n\n\treturn {\n\t\tname: \"vite-plugin-lds\",\n\t\tenforce: \"pre\",\n\n\t\tasync transform(code, id) {\n\t\t\tconst cleanId = id.split(\"?\")[0] ?? id;\n\t\t\tif (!cleanId.endsWith(\".js\") && !cleanId.endsWith(\".ts\")) return null;\n\t\t\tif (cleanId.includes(\"/node_modules/\")) return null;\n\t\t\tif (!specifierSnippets.some((snippet) => code.includes(snippet))) return null;\n\n\t\t\tawait init;\n\n\t\t\tlet imports: ReturnType<typeof parse>[0];\n\t\t\ttry {\n\t\t\t\t[imports] = parse(code);\n\t\t\t} catch {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst relevant = imports.filter(\n\t\t\t\t(imp) => imp.d === -1 && imp.n !== undefined && imp.n in adapters,\n\t\t\t);\n\t\t\tif (relevant.length === 0) return null;\n\n\t\t\tconst s = new MagicString(code);\n\t\t\tlet changed = false;\n\n\t\t\tfor (const imp of relevant) {\n\t\t\t\tconst { ss: start, se: end, n: specifier } = imp;\n\t\t\t\tconst statement = code.slice(start, end);\n\n\t\t\t\tconst openBrace = statement.indexOf(\"{\");\n\t\t\t\tconst closeBrace = statement.indexOf(\"}\");\n\t\t\t\tif (openBrace === -1 || closeBrace === -1) continue;\n\n\t\t\t\tconst bracesContent = statement.slice(openBrace + 1, closeBrace);\n\t\t\t\tconst moduleAdapters = adapters[specifier!]!;\n\t\t\t\tconst parsedImport = parseImportSpecifiers(bracesContent);\n\t\t\t\tconst registered = parsedImport.filter((p) => p.original in moduleAdapters);\n\t\t\t\tconst unregistered = parsedImport.filter((p) => !(p.original in moduleAdapters));\n\n\t\t\t\tif (registered.length === 0) continue;\n\n\t\t\t\tconst parts: string[] = [\n\t\t\t\t\t`import { ${registered.map((p) => p.full).join(\", \")} } from '${ADAPTER_PREFIX}${specifier}';`,\n\t\t\t\t];\n\n\t\t\t\tif (unregistered.length > 0) {\n\t\t\t\t\tparts.push(\n\t\t\t\t\t\t`import { ${unregistered.map((p) => p.full).join(\", \")} } from '${specifier}';`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\ts.overwrite(start, end, parts.join(\"\\n\"));\n\t\t\t\tchanged = true;\n\t\t\t}\n\n\t\t\tif (!changed) return null;\n\t\t\treturn { code: s.toString(), map: s.generateMap({ hires: true }) };\n\t\t},\n\n\t\tresolveId(id) {\n\t\t\tif (id.startsWith(ADAPTER_PREFIX)) return ADAPTER_ID_PREFIX + id.slice(ADAPTER_PREFIX.length);\n\t\t\treturn null;\n\t\t},\n\n\t\tload(id) {\n\t\t\tif (!id.startsWith(ADAPTER_ID_PREFIX)) return null;\n\n\t\t\tconst specifier = id.slice(ADAPTER_ID_PREFIX.length);\n\t\t\tconst moduleAdapters = adapters[specifier];\n\t\t\tif (!moduleAdapters) return null;\n\n\t\t\tconst lines: string[] = [adapterBaseSource];\n\t\t\tfor (const [name, { type: _type, ...cfg }] of Object.entries(moduleAdapters)) {\n\t\t\t\tlines.push(\n\t\t\t\t\t`export const ${name} = createWireAdapter(${JSON.stringify(name)}, ${JSON.stringify(cfg)});`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn lines.join(\"\\n\");\n\t\t},\n\t};\n}\n"],"names":[],"mappings":";;;;;AAaA,MAAM,iBAAiB;AACvB,MAAM,oBAAoB,OAAO;AAEjC,MAAM,oBAAoB;AAAA,EACzB,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC,GAAG,YAAY;AAAA,EAC1D;AACD;AAUA,MAAM,mBAAuC;AAAA,EAC5C,yBAAyB;AAAA,IACxB,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,MACV,kBAAkB;AAAA,QACjB,MAAM;AAAA,QACN,YAAY;AAAA,UACX,UAAU,EAAE,MAAM,SAAA;AAAA,UAClB,QAAQ,EAAE,MAAM,SAAS,OAAO,EAAE,MAAM,WAAS;AAAA,QAAE;AAAA,QAEpD,UAAU,CAAC,UAAU;AAAA,MAAA;AAAA,IACtB;AAAA,EACD;AAEF;AAEA,SAAS,sBAAsB,eAA6D;AAC3F,SAAO,cACL,MAAM,GAAG,EACT,IAAI,CAAC,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OAAO,QAAQ,cAAc,GAAG;AAC7E,cAAM;AAAA,UACL,gBAAgB,IAAI,wBAAwB,KAAK,UAAU,IAAI,CAAC,KAAK,KAAK,UAAU,GAAG,CAAC;AAAA,QAAA;AAAA,MAE1F;AACA,aAAO,MAAM,KAAK,IAAI;AAAA,IACvB;AAAA,EAAA;AAEF;"}
@@ -0,0 +1,96 @@
1
+ import { getChatSDK } from "@salesforce/sdk-chat";
2
+ import { z } from "zod";
3
+ function normalizeMcpResponse(raw) {
4
+ if (raw && typeof raw === "object" && "structuredContent" in raw) {
5
+ return raw.structuredContent;
6
+ }
7
+ if (raw && typeof raw === "object" && typeof raw.result === "string") {
8
+ const parsed = JSON.parse(raw.result);
9
+ if (Array.isArray(parsed)) {
10
+ const textBlock = parsed.find(
11
+ (b) => b && b.type === "text" && typeof b.text === "string"
12
+ );
13
+ const text = textBlock ? textBlock.text : null;
14
+ if (text) {
15
+ return JSON.parse(text);
16
+ }
17
+ return {};
18
+ }
19
+ return parsed;
20
+ }
21
+ return raw ?? {};
22
+ }
23
+ function buildSchema(schema) {
24
+ switch (schema.type) {
25
+ case "string":
26
+ return z.string();
27
+ case "number":
28
+ return z.number();
29
+ case "integer":
30
+ return z.number().int();
31
+ case "boolean":
32
+ return z.boolean();
33
+ case "array":
34
+ return z.array(buildSchema(schema.items));
35
+ case "object": {
36
+ const required = new Set(schema.required ?? []);
37
+ const shape = Object.fromEntries(
38
+ Object.entries(schema.properties ?? {}).map(
39
+ ([key, val]) => [key, required.has(key) ? buildSchema(val) : buildSchema(val).optional()]
40
+ )
41
+ );
42
+ return z.object(shape);
43
+ }
44
+ default:
45
+ return z.unknown();
46
+ }
47
+ }
48
+ function createWireAdapter(name, cfg) {
49
+ const toolName = cfg.toolName;
50
+ const schema = buildSchema(cfg.configJsonSchema);
51
+ class McpToolBackedWireAdapter {
52
+ callback;
53
+ config = null;
54
+ constructor(callback) {
55
+ this.callback = callback;
56
+ this.config = null;
57
+ }
58
+ connect() {
59
+ this.run();
60
+ }
61
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
62
+ disconnect() {
63
+ }
64
+ update(config) {
65
+ this.config = config;
66
+ this.run();
67
+ }
68
+ async run() {
69
+ if (!schema.safeParse(this.config).success) {
70
+ this.callback({ data: void 0, error: void 0 });
71
+ return;
72
+ }
73
+ try {
74
+ const app = await getChatSDK();
75
+ if (!app.callTool) {
76
+ throw new Error(
77
+ `[${name}] sdk.callTool is not available on this surface. Make sure window.openai is configured or the component is running in an MCP Apps / OpenAI chat context.`
78
+ );
79
+ }
80
+ const raw = await app.callTool({
81
+ toolName,
82
+ params: this.config ?? void 0
83
+ });
84
+ const result = normalizeMcpResponse(raw);
85
+ this.callback({ data: result?.data, error: result?.error });
86
+ } catch (e) {
87
+ this.callback({ data: void 0, error: e });
88
+ }
89
+ }
90
+ }
91
+ return McpToolBackedWireAdapter;
92
+ }
93
+ export {
94
+ createWireAdapter
95
+ };
96
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sources":["../../../src/providers/shared/normalize-mcp-response.ts","../../../src/providers/lds/runtime.ts"],"sourcesContent":["/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\n\n/**\n * Unwraps the MCP tool transport envelope and returns the tool's payload as-is.\n *\n * Handles the three surface shapes `sdk.callTool()` can resolve with:\n * - MCP Apps surface: `{ structuredContent, content }`\n * - OpenAI surface: `{ result: \"<JSON string>\" }`, where the JSON may itself be\n * an MCP content array (`[{ type: 'text', text: \"<JSON string>\" }, ...]`)\n * - Fallback: the raw value returned by `callTool`\n *\n * The shape of the unwrapped payload is the tool's responsibility — this helper\n * does not project out `data` / `error` / `errors`. Callers read whichever keys\n * their tool contract defines.\n */\nexport function normalizeMcpResponse(raw: unknown): unknown {\n\tif (raw && typeof raw === \"object\" && \"structuredContent\" in raw) {\n\t\treturn (raw as { structuredContent: unknown }).structuredContent;\n\t}\n\n\tif (raw && typeof raw === \"object\" && typeof (raw as { result?: unknown }).result === \"string\") {\n\t\tconst parsed = JSON.parse((raw as { result: string }).result);\n\t\tif (Array.isArray(parsed)) {\n\t\t\tconst textBlock = parsed.find(\n\t\t\t\t(b: { type?: string; text?: string }) =>\n\t\t\t\t\tb && b.type === \"text\" && typeof b.text === \"string\",\n\t\t\t);\n\t\t\tconst text = textBlock ? textBlock.text : null;\n\t\t\tif (text) {\n\t\t\t\treturn JSON.parse(text);\n\t\t\t}\n\t\t\treturn {};\n\t\t}\n\t\treturn parsed;\n\t}\n\n\treturn raw ?? {};\n}\n","/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport { getChatSDK } from \"@salesforce/sdk-chat\";\nimport { z, type ZodType } from \"zod\";\nimport type { JsonSchema } from \"./types\";\nimport { normalizeMcpResponse } from \"../shared/normalize-mcp-response\";\n\nexport type { JsonSchema };\n\ntype WireCallback = (result: { data: unknown; error: unknown }) => void;\n\nfunction buildSchema(schema: JsonSchema): ZodType {\n\tswitch (schema.type) {\n\t\tcase \"string\":\n\t\t\treturn z.string();\n\t\tcase \"number\":\n\t\t\treturn z.number();\n\t\tcase \"integer\":\n\t\t\treturn z.number().int();\n\t\tcase \"boolean\":\n\t\t\treturn z.boolean();\n\t\tcase \"array\":\n\t\t\treturn z.array(buildSchema(schema.items as JsonSchema));\n\t\tcase \"object\": {\n\t\t\tconst required = new Set<string>((schema.required as string[]) ?? []);\n\t\t\tconst shape = Object.fromEntries(\n\t\t\t\tObject.entries((schema.properties as Record<string, JsonSchema>) ?? {}).map(\n\t\t\t\t\t([key, val]) => [key, required.has(key) ? buildSchema(val) : buildSchema(val).optional()],\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn z.object(shape);\n\t\t}\n\t\tdefault:\n\t\t\treturn z.unknown();\n\t}\n}\n\ninterface AdapterConfig {\n\ttoolName: string;\n\tconfigJsonSchema: JsonSchema;\n}\n\nexport function createWireAdapter(name: string, cfg: AdapterConfig) {\n\tconst toolName = cfg.toolName;\n\tconst schema = buildSchema(cfg.configJsonSchema);\n\tclass McpToolBackedWireAdapter {\n\t\tcallback: WireCallback;\n\t\tconfig: Record<string, unknown> | null = null;\n\n\t\tconstructor(callback: WireCallback) {\n\t\t\tthis.callback = callback;\n\t\t\tthis.config = null;\n\t\t}\n\n\t\tconnect() {\n\t\t\tthis.run();\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-empty-function\n\t\tdisconnect() {}\n\n\t\tupdate(config: Record<string, unknown> | null) {\n\t\t\tthis.config = config;\n\t\t\tthis.run();\n\t\t}\n\n\t\tasync run() {\n\t\t\tif (!schema.safeParse(this.config).success) {\n\t\t\t\tthis.callback({ data: undefined, error: undefined });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst app = await getChatSDK();\n\n\t\t\t\tif (!app.callTool) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[${name}] sdk.callTool is not available on this surface. ` +\n\t\t\t\t\t\t\t\"Make sure window.openai is configured or the component is running in \" +\n\t\t\t\t\t\t\t\"an MCP Apps / OpenAI chat context.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst raw = await app.callTool({\n\t\t\t\t\ttoolName,\n\t\t\t\t\tparams: this.config ?? undefined,\n\t\t\t\t});\n\n\t\t\t\tconst result = normalizeMcpResponse(raw) as { data?: unknown; error?: unknown };\n\n\t\t\t\tthis.callback({ data: result?.data, error: result?.error });\n\t\t\t} catch (e) {\n\t\t\t\tthis.callback({ data: undefined, error: e });\n\t\t\t}\n\t\t}\n\t}\n\n\treturn McpToolBackedWireAdapter;\n}\n"],"names":[],"mappings":";;AAmBO,SAAS,qBAAqB,KAAuB;AAC3D,MAAI,OAAO,OAAO,QAAQ,YAAY,uBAAuB,KAAK;AACjE,WAAQ,IAAuC;AAAA,EAChD;AAEA,MAAI,OAAO,OAAO,QAAQ,YAAY,OAAQ,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A,IAEzC,YAAY,UAAwB;AACnC,WAAK,WAAW;AAChB,WAAK,SAAS;AAAA,IACf;AAAA,IAEA,UAAU;AACT,WAAK,IAAA;AAAA,IACN;AAAA;AAAA,IAGA,aAAa;AAAA,IAAC;AAAA,IAEd,OAAO,QAAwC;AAC9C,WAAK,SAAS;AACd,WAAK,IAAA;AAAA,IACN;AAAA,IAEA,MAAM,MAAM;AACX,UAAI,CAAC,OAAO,UAAU,KAAK,MAAM,EAAE,SAAS;AAC3C,aAAK,SAAS,EAAE,MAAM,QAAW,OAAO,QAAW;AACnD;AAAA,MACD;AACA,UAAI;AACH,cAAM,MAAM,MAAM,WAAA;AAElB,YAAI,CAAC,IAAI,UAAU;AAClB,gBAAM,IAAI;AAAA,YACT,IAAI,IAAI;AAAA,UAAA;AAAA,QAIV;AAEA,cAAM,MAAM,MAAM,IAAI,SAAS;AAAA,UAC9B;AAAA,UACA,QAAQ,KAAK,UAAU;AAAA,QAAA,CACvB;AAED,cAAM,SAAS,qBAAqB,GAAG;AAEvC,aAAK,SAAS,EAAE,MAAM,QAAQ,MAAM,OAAO,QAAQ,OAAO;AAAA,MAC3D,SAAS,GAAG;AACX,aAAK,SAAS,EAAE,MAAM,QAAW,OAAO,GAAG;AAAA,MAC5C;AAAA,IACD;AAAA,EAAA;AAGD,SAAO;AACR;"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ export type JsonSchema = {
7
+ type: "string";
8
+ } | {
9
+ type: "number";
10
+ } | {
11
+ type: "integer";
12
+ } | {
13
+ type: "boolean";
14
+ } | {
15
+ type: "array";
16
+ items: JsonSchema;
17
+ } | {
18
+ type: "object";
19
+ properties?: Record<string, JsonSchema>;
20
+ required?: string[];
21
+ } | Record<string, unknown>;
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/lds/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,UAAU,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAChF,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Provider } from '../../types';
2
+ export interface LightningGraphqlOptions {
3
+ /**
4
+ * Name of the MCP tool to call for GraphQL query execution.
5
+ * Defaults to `'graphqlQuery'`.
6
+ */
7
+ toolName?: string;
8
+ }
9
+ export declare function lightningGraphql(options?: LightningGraphqlOptions): Provider;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/lightning-graphql/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,uBAAuB;IACvC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAOD,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,QAAQ,CAUhF"}
@@ -0,0 +1,24 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join, dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ const runtimeSource = readFileSync(
5
+ join(dirname(fileURLToPath(import.meta.url)), "runtime.js"),
6
+ "utf-8"
7
+ );
8
+ function lightningGraphql(options = {}) {
9
+ const toolName = options.toolName ?? "graphqlQuery";
10
+ const source = `${runtimeSource}
11
+ TOOL_NAME = ${JSON.stringify(toolName)};
12
+ `;
13
+ return {
14
+ match: (id) => id === "lightning/graphql",
15
+ resolve(specifier) {
16
+ if (specifier !== "lightning/graphql") return null;
17
+ return source;
18
+ }
19
+ };
20
+ }
21
+ export {
22
+ lightningGraphql
23
+ };
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/providers/lightning-graphql/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport { readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { Provider } from \"../../types\";\n\nexport interface LightningGraphqlOptions {\n\t/**\n\t * Name of the MCP tool to call for GraphQL query execution.\n\t * Defaults to `'graphqlQuery'`.\n\t */\n\ttoolName?: string;\n}\n\nconst runtimeSource = readFileSync(\n\tjoin(dirname(fileURLToPath(import.meta.url)), \"runtime.js\"),\n\t\"utf-8\",\n);\n\nexport function lightningGraphql(options: LightningGraphqlOptions = {}): Provider {\n\tconst toolName = options.toolName ?? \"graphqlQuery\";\n\tconst source = `${runtimeSource}\\nTOOL_NAME = ${JSON.stringify(toolName)};\\n`;\n\treturn {\n\t\tmatch: (id) => id === \"lightning/graphql\",\n\t\tresolve(specifier) {\n\t\t\tif (specifier !== \"lightning/graphql\") return null;\n\t\t\treturn source;\n\t\t},\n\t};\n}\n"],"names":[],"mappings":";;;AAkBA,MAAM,gBAAgB;AAAA,EACrB,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC,GAAG,YAAY;AAAA,EAC1D;AACD;AAEO,SAAS,iBAAiB,UAAmC,IAAc;AACjF,QAAM,WAAW,QAAQ,YAAY;AACrC,QAAM,SAAS,GAAG,aAAa;AAAA,cAAiB,KAAK,UAAU,QAAQ,CAAC;AAAA;AACxE,SAAO;AAAA,IACN,OAAO,CAAC,OAAO,OAAO;AAAA,IACtB,QAAQ,WAAW;AAClB,UAAI,cAAc,oBAAqB,QAAO;AAC9C,aAAO;AAAA,IACR;AAAA,EAAA;AAEF;"}
@@ -0,0 +1,103 @@
1
+ import { getChatSDK } from "@salesforce/sdk-chat";
2
+ function normalizeMcpResponse(raw) {
3
+ if (raw && typeof raw === "object" && "structuredContent" in raw) {
4
+ return raw.structuredContent;
5
+ }
6
+ if (raw && typeof raw === "object" && typeof raw.result === "string") {
7
+ const parsed = JSON.parse(raw.result);
8
+ if (Array.isArray(parsed)) {
9
+ const textBlock = parsed.find(
10
+ (b) => b && b.type === "text" && typeof b.text === "string"
11
+ );
12
+ const text = textBlock ? textBlock.text : null;
13
+ if (text) {
14
+ return JSON.parse(text);
15
+ }
16
+ return {};
17
+ }
18
+ return parsed;
19
+ }
20
+ return raw ?? {};
21
+ }
22
+ let TOOL_NAME = "graphqlQuery";
23
+ function gql(strings, ...values) {
24
+ let result = "";
25
+ strings.forEach((string, i) => {
26
+ result += string;
27
+ if (i < values.length) result += String(values[i]);
28
+ });
29
+ return result;
30
+ }
31
+ async function runQuery(config) {
32
+ const { query, variables } = config;
33
+ if (!query) return { data: void 0, errors: void 0 };
34
+ if (typeof globalThis.__sfdc_sdk__ === "object" && typeof globalThis.__sfdc_sdk__?.graphql === "function") {
35
+ const sdkGraphql = globalThis.__sfdc_sdk__.graphql;
36
+ const result = await sdkGraphql({ query, variables: variables ?? {} });
37
+ return { data: result?.data, errors: result?.errors };
38
+ }
39
+ const sdk = await getChatSDK();
40
+ if (typeof sdk.callTool !== "function") {
41
+ throw new Error(
42
+ "[lightning/graphql] No data surface available. Either initialise globalThis.__sfdc_sdk__ with createDataSDK, or run inside a ChatGPT / MCP Apps context."
43
+ );
44
+ }
45
+ const raw = await sdk.callTool({
46
+ toolName: TOOL_NAME,
47
+ params: { query, variables: variables ?? {} }
48
+ });
49
+ return normalizeMcpResponse(raw) ?? {};
50
+ }
51
+ class graphql {
52
+ _dataCallback;
53
+ _config;
54
+ constructor(dataCallback) {
55
+ this._dataCallback = dataCallback;
56
+ }
57
+ connect() {
58
+ this._fetch();
59
+ }
60
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
61
+ disconnect() {
62
+ }
63
+ update(config) {
64
+ this._config = config;
65
+ this._fetch();
66
+ }
67
+ refresh() {
68
+ return this._fetch();
69
+ }
70
+ async _fetch() {
71
+ try {
72
+ const result = await runQuery(this._config ?? {});
73
+ this._emit(result);
74
+ } catch (error) {
75
+ this._emit({
76
+ data: void 0,
77
+ errors: [{ message: error.message }]
78
+ });
79
+ }
80
+ }
81
+ _emit({ data, errors }) {
82
+ this._dataCallback({
83
+ data,
84
+ errors: errors?.length ? errors : void 0,
85
+ refresh: () => this.refresh()
86
+ });
87
+ }
88
+ }
89
+ async function executeMutation(config) {
90
+ if (!config?.query) return { data: void 0, errors: [{ message: "No query provided" }] };
91
+ try {
92
+ return await runQuery(config);
93
+ } catch (error) {
94
+ return { data: void 0, errors: [{ message: error.message }] };
95
+ }
96
+ }
97
+ export {
98
+ TOOL_NAME,
99
+ executeMutation,
100
+ gql,
101
+ graphql
102
+ };
103
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sources":["../../../src/providers/shared/normalize-mcp-response.ts","../../../src/providers/lightning-graphql/runtime.ts"],"sourcesContent":["/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\n\n/**\n * Unwraps the MCP tool transport envelope and returns the tool's payload as-is.\n *\n * Handles the three surface shapes `sdk.callTool()` can resolve with:\n * - MCP Apps surface: `{ structuredContent, content }`\n * - OpenAI surface: `{ result: \"<JSON string>\" }`, where the JSON may itself be\n * an MCP content array (`[{ type: 'text', text: \"<JSON string>\" }, ...]`)\n * - Fallback: the raw value returned by `callTool`\n *\n * The shape of the unwrapped payload is the tool's responsibility — this helper\n * does not project out `data` / `error` / `errors`. Callers read whichever keys\n * their tool contract defines.\n */\nexport function normalizeMcpResponse(raw: unknown): unknown {\n\tif (raw && typeof raw === \"object\" && \"structuredContent\" in raw) {\n\t\treturn (raw as { structuredContent: unknown }).structuredContent;\n\t}\n\n\tif (raw && typeof raw === \"object\" && typeof (raw as { result?: unknown }).result === \"string\") {\n\t\tconst parsed = JSON.parse((raw as { result: string }).result);\n\t\tif (Array.isArray(parsed)) {\n\t\t\tconst textBlock = parsed.find(\n\t\t\t\t(b: { type?: string; text?: string }) =>\n\t\t\t\t\tb && b.type === \"text\" && typeof b.text === \"string\",\n\t\t\t);\n\t\t\tconst text = textBlock ? textBlock.text : null;\n\t\t\tif (text) {\n\t\t\t\treturn JSON.parse(text);\n\t\t\t}\n\t\t\treturn {};\n\t\t}\n\t\treturn parsed;\n\t}\n\n\treturn raw ?? {};\n}\n","/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport { getChatSDK } from \"@salesforce/sdk-chat\";\nimport { normalizeMcpResponse } from \"../shared/normalize-mcp-response\";\n\n// Overwritten at plugin-load time by the `lightningGraphql` Vite shim, which\n// appends `TOOL_NAME = \"<configured-name>\";` to the bundled output. The initial\n// value is the default.\n// eslint-disable-next-line prefer-const\nexport let TOOL_NAME = \"graphqlQuery\";\n\ninterface GraphqlConfig {\n\tquery?: string;\n\tvariables?: Record<string, unknown>;\n}\n\ninterface GraphqlResult {\n\tdata?: unknown;\n\terrors?: { message: string }[];\n}\n\ntype WireCallback = (result: {\n\tdata: unknown;\n\terrors: { message: string }[] | undefined;\n\trefresh: () => Promise<void>;\n}) => void;\n\nexport function gql(strings: TemplateStringsArray, ...values: unknown[]): string {\n\tlet result = \"\";\n\tstrings.forEach((string, i) => {\n\t\tresult += string;\n\t\tif (i < values.length) result += String(values[i]);\n\t});\n\treturn result;\n}\n\nasync function runQuery(config: GraphqlConfig): Promise<GraphqlResult> {\n\tconst { query, variables } = config;\n\tif (!query) return { data: undefined, errors: undefined };\n\n\t// 1. UIBundle / local dev: use globalThis.__sfdc_sdk__.graphql if available\n\tif (\n\t\ttypeof (globalThis as Record<string, unknown>).__sfdc_sdk__ === \"object\" &&\n\t\ttypeof ((globalThis as Record<string, unknown>).__sfdc_sdk__ as Record<string, unknown>)\n\t\t\t?.graphql === \"function\"\n\t) {\n\t\tconst sdkGraphql = (\n\t\t\t(globalThis as Record<string, unknown>).__sfdc_sdk__ as Record<string, unknown>\n\t\t).graphql as (args: {\n\t\t\tquery: string;\n\t\t\tvariables: Record<string, unknown>;\n\t\t}) => Promise<GraphqlResult>;\n\t\tconst result = await sdkGraphql({ query, variables: variables ?? {} });\n\t\treturn { data: result?.data, errors: result?.errors };\n\t}\n\n\t// 2. MCP surface: use getChatSDK().callTool\n\tconst sdk = await getChatSDK();\n\tif (typeof sdk.callTool !== \"function\") {\n\t\tthrow new Error(\n\t\t\t\"[lightning/graphql] No data surface available. \" +\n\t\t\t\t\"Either initialise globalThis.__sfdc_sdk__ with createDataSDK, \" +\n\t\t\t\t\"or run inside a ChatGPT / MCP Apps context.\",\n\t\t);\n\t}\n\n\tconst raw = await sdk.callTool({\n\t\ttoolName: TOOL_NAME,\n\t\tparams: { query, variables: variables ?? {} },\n\t});\n\n\treturn (normalizeMcpResponse(raw) as GraphqlResult) ?? {};\n}\n\nexport class graphql {\n\t_dataCallback: WireCallback;\n\t_config: GraphqlConfig | undefined;\n\n\tconstructor(dataCallback: WireCallback) {\n\t\tthis._dataCallback = dataCallback;\n\t}\n\n\tconnect() {\n\t\tthis._fetch();\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-empty-function\n\tdisconnect() {}\n\n\tupdate(config: GraphqlConfig) {\n\t\tthis._config = config;\n\t\tthis._fetch();\n\t}\n\n\trefresh() {\n\t\treturn this._fetch();\n\t}\n\n\tasync _fetch() {\n\t\ttry {\n\t\t\tconst result = await runQuery(this._config ?? {});\n\t\t\tthis._emit(result);\n\t\t} catch (error) {\n\t\t\tthis._emit({\n\t\t\t\tdata: undefined,\n\t\t\t\terrors: [{ message: (error as Error).message }],\n\t\t\t});\n\t\t}\n\t}\n\n\t_emit({ data, errors }: GraphqlResult) {\n\t\tthis._dataCallback({\n\t\t\tdata,\n\t\t\terrors: errors?.length ? errors : undefined,\n\t\t\trefresh: () => this.refresh(),\n\t\t});\n\t}\n}\n\nexport async function executeMutation(config: GraphqlConfig): Promise<GraphqlResult> {\n\tif (!config?.query) return { data: undefined, errors: [{ message: \"No query provided\" }] };\n\ttry {\n\t\treturn await runQuery(config);\n\t} catch (error) {\n\t\treturn { data: undefined, errors: [{ message: (error as Error).message }] };\n\t}\n}\n"],"names":[],"mappings":";AAmBO,SAAS,qBAAqB,KAAuB;AAC3D,MAAI,OAAO,OAAO,QAAQ,YAAY,uBAAuB,KAAK;AACjE,WAAQ,IAAuC;AAAA,EAChD;AAEA,MAAI,OAAO,OAAO,QAAQ,YAAY,OAAQ,IAA6B,WAAW,UAAU;AAC/F,UAAM,SAAS,KAAK,MAAO,IAA2B,MAAM;AAC5D,QAAI,MAAM,QAAQ,MAAM,GAAG;AAC1B,YAAM,YAAY,OAAO;AAAA,QACxB,CAAC,MACA,KAAK,EAAE,SAAS,UAAU,OAAO,EAAE,SAAS;AAAA,MAAA;AAE9C,YAAM,OAAO,YAAY,UAAU,OAAO;AAC1C,UAAI,MAAM;AACT,eAAO,KAAK,MAAM,IAAI;AAAA,MACvB;AACA,aAAO,CAAA;AAAA,IACR;AACA,WAAO;AAAA,EACR;AAEA,SAAO,OAAO,CAAA;AACf;AC7BO,IAAI,YAAY;AAkBhB,SAAS,IAAI,YAAkC,QAA2B;AAChF,MAAI,SAAS;AACb,UAAQ,QAAQ,CAAC,QAAQ,MAAM;AAC9B,cAAU;AACV,QAAI,IAAI,OAAO,kBAAkB,OAAO,OAAO,CAAC,CAAC;AAAA,EAClD,CAAC;AACD,SAAO;AACR;AAEA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AM,EAAE,MAAM,UAAyB;AACtC,SAAK,cAAc;AAAA,MAClB;AAAA,MACA,QAAQ,QAAQ,SAAS,SAAS;AAAA,MAClC,SAAS,MAAM,KAAK,QAAA;AAAA,IAAQ,CAC5B;AAAA,EACF;AACD;AAEA,eAAsB,gBAAgB,QAA+C;AACpF,MAAI,CAAC,QAAQ,MAAO,QAAO,EAAE,MAAM,QAAW,QAAQ,CAAC,EAAE,SAAS,oBAAA,CAAqB,EAAA;AACvF,MAAI;AACH,WAAO,MAAM,SAAS,MAAM;AAAA,EAC7B,SAAS,OAAO;AACf,WAAO,EAAE,MAAM,QAAW,QAAQ,CAAC,EAAE,SAAU,MAAgB,QAAA,CAAS,EAAA;AAAA,EACzE;AACD;"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ /**
7
+ * Unwraps the MCP tool transport envelope and returns the tool's payload as-is.
8
+ *
9
+ * Handles the three surface shapes `sdk.callTool()` can resolve with:
10
+ * - MCP Apps surface: `{ structuredContent, content }`
11
+ * - OpenAI surface: `{ result: "<JSON string>" }`, where the JSON may itself be
12
+ * an MCP content array (`[{ type: 'text', text: "<JSON string>" }, ...]`)
13
+ * - Fallback: the raw value returned by `callTool`
14
+ *
15
+ * The shape of the unwrapped payload is the tool's responsibility — this helper
16
+ * does not project out `data` / `error` / `errors`. Callers read whichever keys
17
+ * their tool contract defines.
18
+ */
19
+ export declare function normalizeMcpResponse(raw: unknown): unknown;
20
+ //# sourceMappingURL=normalize-mcp-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-mcp-response.d.ts","sourceRoot":"","sources":["../../../src/providers/shared/normalize-mcp-response.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAsB1D"}
package/dist/types.d.ts CHANGED
@@ -21,7 +21,7 @@ export interface PassthroughRule {
21
21
  }
22
22
  export interface LwcVitePluginOptions {
23
23
  modules?: ModuleConfig;
24
- providers?: Provider[];
24
+ providers?: (Provider | Plugin)[];
25
25
  stubs?: Record<string, string>;
26
26
  lwcOptions?: Record<string, unknown>;
27
27
  ignorePatterns?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,MAAM,WAAW,QAAQ;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IAChC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAC9B,GAAG,CAAC,EAAE,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACpC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,cAAc,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