@salesforce/vite-plugin-lwc-ui-bundle 1.134.5 → 1.135.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.
@@ -1 +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 type { JSONSchema } from \"@conduit-client/jsonschema-validate\";\nimport { init, parse } from \"es-module-lexer\";\nimport MagicString from \"magic-string\";\nimport type { Plugin } from \"vite\";\nimport type { ReadInvokerShape } from \"./types\";\n\n// prefix to write into transformed source code\nconst ADAPTER_PREFIX = \"sf-lds-adapter:\";\n// prefix used to ID the adapter when loading the virtual module\nconst ADAPTER_ID_PREFIX = \"\\0\" + ADAPTER_PREFIX;\n\n// the source of the adapter base module — reused across virtual modules so\n// each generated specifier emits the createWireAdapter / createMutationAdapter /\n// createReadAdapter factories once\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\n/**\n * Imperative **mutation** adapter. Always an async\n * `(config) => Promise<Data>` that throws on validation or tool error —\n * matching OneStore's `DefaultImperativeBindingsService`, the only service a\n * mutation ever uses on platform. Mutations do not carry an `invokerShape`:\n * `subscribe`/`refresh` make no sense on write, and allowing them here\n * would drift off-platform from on-platform semantics.\n */\nexport interface LdsImperativeMutationAdapterConfig {\n\ttype: \"imperative-mutation\";\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\n/**\n * Public alias for the read-shape union defined in `runtime.ts`. Re-exported\n * from this module so consumers don't have to import from the runtime entry\n * point, while keeping the union pinned to one source of truth.\n *\n * Off-platform there is no store, so `subscribe` is a deliberate no-op\n * (callback never fires, returned unsubscribe is idempotent) and `refresh`\n * re-executes the underlying MCP tool. This preserves the OneStore API\n * surface for code ported verbatim.\n */\nexport type LdsImperativeReadInvokerShape = ReadInvokerShape;\n\nexport interface LdsImperativeReadAdapterConfig {\n\ttype: \"imperative-read\";\n\tinvokerShape: LdsImperativeReadInvokerShape;\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\nexport type LdsAdapterConfig =\n\t| LdsWireAdapterConfig\n\t| LdsImperativeMutationAdapterConfig\n\t| LdsImperativeReadAdapterConfig;\n\nexport type LdsAdapterRegistry = Record<string, Record<string, LdsAdapterConfig>>;\n\n/**\n * Default adapter registry.\n * Maps LDS module specifiers to MCP tool-backed implementations. Entries can be\n * wire adapters (`type: 'wire'`), imperative mutations (`type: 'imperative-mutation'`),\n * or imperative reads (`type: 'imperative-read'` + `invokerShape`).\n * Add entries here to support additional lightning/* exports.\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\tlayoutTypes: {\n\t\t\t\t\t\tanyOf: [{ type: \"array\", items: { type: \"string\" } }, { type: \"null\" }],\n\t\t\t\t\t},\n\t\t\t\t\tfields: {\n\t\t\t\t\t\tanyOf: [{ type: \"array\", items: { type: \"string\" } }, { type: \"null\" }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [\"recordId\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t\tanyOf: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tfields: { type: \"array\", items: { type: \"string\" }, minItems: 1 },\n\t\t\t\t\t\t},\n\t\t\t\t\t\trequired: [\"fields\"],\n\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tlayoutTypes: {\n\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\titems: { type: \"string\" },\n\t\t\t\t\t\t\t\tminItems: 1,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\trequired: [\"layoutTypes\"],\n\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tcreateRecord: {\n\t\t\ttype: \"imperative-mutation\",\n\t\t\ttoolName: \"createRecordMcpTool\",\n\t\t\tconfigJsonSchema: {\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tapiName: { type: \"string\" },\n\t\t\t\t\tfields: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {},\n\t\t\t\t\t\trequired: [],\n\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [\"apiName\", \"fields\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t},\n\t\t},\n\t\tupdateRecord: {\n\t\t\ttype: \"imperative-mutation\",\n\t\t\ttoolName: \"updateRecordMcpTool\",\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: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {},\n\t\t\t\t\t\trequired: [],\n\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [\"recordId\", \"fields\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t},\n\t\t},\n\t},\n\t\"lightning/uiObjectInfoApi\": {\n\t\t// On-platform this is a `{ invoke, subscribe }` callback surface\n\t\t// emitting `{ data, error }`. The legacy invoker shape preserves that\n\t\t// contract verbatim, so ported consumers keep their call sites.\n\t\tgetObjectInfo_imperative: {\n\t\t\ttype: \"imperative-read\",\n\t\t\tinvokerShape: \"legacy\",\n\t\t\ttoolName: \"getObjectInfoMcpTool\",\n\t\t\tconfigJsonSchema: {\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tobjectApiName: { type: \"string\" },\n\t\t\t\t},\n\t\t\t\trequired: [\"objectApiName\"],\n\t\t\t\tadditionalProperties: false,\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\n/**\n * LDS provider — rewrites registered `lightning/*` imports (e.g.\n * `lightning/uiRecordApi`) to MCP-tool-backed virtual modules. Unregistered\n * exports pass through to the normal `lightning/*` resolution.\n *\n * Three Vite hooks do the work:\n *\n * - **`transform`** — parses each `.js` / `.ts` file with `es-module-lexer`,\n * finds named imports from registered specifiers, and rewrites them to pull\n * registered names from `sf-lds-adapter:<specifier>` while leaving\n * unregistered names pointing at the original specifier.\n *\n * - **`resolveId`** — maps `sf-lds-adapter:<specifier>` to a `\\0`-prefixed\n * virtual module ID, preventing Rollup from attempting a filesystem lookup.\n *\n * - **`load`** — generates the virtual module, emitting an MCP-backed\n * `createWireAdapter(...)` class for every `type: 'wire'` entry,\n * `createMutationAdapter(...)` for every `type: 'imperative-mutation'` entry,\n * and `createReadAdapter(...)` for every `type: 'imperative-read'` entry.\n *\n * Only specifiers present in the `adapters` registry are intercepted; imports from\n * unregistered specifiers pass through unchanged.\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\t// create lines of code used to create MCP tool based adapters\n\t\t\tconst lines: string[] = [adapterBaseSource];\n\t\t\tfor (const [name, entry] of Object.entries(moduleAdapters)) {\n\t\t\t\tconst { type, ...cfg } = entry;\n\t\t\t\tconst factory =\n\t\t\t\t\ttype === \"wire\"\n\t\t\t\t\t\t? \"createWireAdapter\"\n\t\t\t\t\t\t: type === \"imperative-mutation\"\n\t\t\t\t\t\t\t? \"createMutationAdapter\"\n\t\t\t\t\t\t\t: \"createReadAdapter\";\n\t\t\t\tlines.push(\n\t\t\t\t\t`export const ${name} = ${factory}(${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":";;;;;AAeA,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB,OAAO;AAKjC,MAAM,oBAAoB;AAAA,EACzB,KAAK,QAAQ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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 { JSONSchema } from \"@conduit-client/jsonschema-validate\";\nimport { init, parse } from \"es-module-lexer\";\nimport MagicString from \"magic-string\";\nimport type { Plugin } from \"vite\";\nimport type { ReadInvokerShape } from \"./types\";\n\n// prefix to write into transformed source code\nconst ADAPTER_PREFIX = \"sf-lds-adapter:\";\n// prefix used to ID the adapter when loading the virtual module\nconst ADAPTER_ID_PREFIX = \"\\0\" + ADAPTER_PREFIX;\n\n// the source of the adapter base module — reused across virtual modules so\n// each generated specifier emits the factories once.\n//\n// Top-level exports from the runtime module are stripped so every factory and\n// `gql` becomes a private binding inside the virtual module. The load hook\n// then controls exactly which names are exported per specifier: adapter\n// entries from the registry, plus `gql` for graphql specifiers. Without this,\n// the built `runtime.js` (trailing `export { …, gql, createWireAdapter, … }`)\n// and the source `runtime.ts` (per-declaration `export function gql …`) both\n// produce a `SyntaxError: Duplicate export of 'gql'` when the load hook also\n// appends `export { gql };`. They also leak the factory names as exports on\n// every LDS virtual module, which isn't a public contract we want.\nconst adapterBaseSource = stripTopLevelExports(\n\treadFileSync(join(dirname(fileURLToPath(import.meta.url)), \"runtime.js\"), \"utf-8\"),\n);\n\n/**\n * Removes top-level ES-module `export` keywords from the embedded runtime\n * source so its declarations survive as private bindings inside the virtual\n * module. Handles two shapes:\n * 1. Per-declaration: `export function foo …` / `export async function foo`\n * → the `export ` prefix is dropped.\n * 2. Trailing re-export clause: `export { foo, bar };` → deleted entirely.\n * Inner occurrences (inside function bodies, comments, strings) are not\n * affected because the source is a flat module with exports only at column 0.\n */\nfunction stripTopLevelExports(source: string): string {\n\treturn source\n\t\t.replace(/^export\\s+(?=(?:async\\s+)?function\\s)/gm, \"\")\n\t\t.replace(/^export\\s*\\{[^}]*};?\\s*$/gm, \"\");\n}\n\nexport interface LdsWireAdapterConfig {\n\ttype: \"wire\";\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\n/**\n * Imperative **mutation** adapter. Always an async\n * `(config) => Promise<Data>` that throws on validation or tool error —\n * matching OneStore's `DefaultImperativeBindingsService`, the only service a\n * mutation ever uses on platform. Mutations do not carry an `invokerShape`:\n * `subscribe`/`refresh` make no sense on write, and allowing them here\n * would drift off-platform from on-platform semantics.\n */\nexport interface LdsImperativeMutationAdapterConfig {\n\ttype: \"imperative-mutation\";\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\n/**\n * Public alias for the read-shape union defined in `runtime.ts`. Re-exported\n * from this module so consumers don't have to import from the runtime entry\n * point, while keeping the union pinned to one source of truth.\n *\n * Off-platform there is no store, so `subscribe` is a deliberate no-op\n * (callback never fires, returned unsubscribe is idempotent) and `refresh`\n * re-executes the underlying MCP tool. This preserves the OneStore API\n * surface for code ported verbatim.\n */\nexport type LdsImperativeReadInvokerShape = ReadInvokerShape;\n\nexport interface LdsImperativeReadAdapterConfig {\n\ttype: \"imperative-read\";\n\tinvokerShape: LdsImperativeReadInvokerShape;\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\n/**\n * GraphQL wire adapter. Emits `{ data, errors, refresh }` (distinct from the\n * base wire `{ data, error }`). No `configJsonSchema` — the adapter passes\n * `{ query, variables }` through to the configured MCP tool.\n */\nexport interface LdsGraphqlWireAdapterConfig {\n\ttype: \"graphql-wire\";\n\ttoolName: string;\n}\n\n/**\n * Imperative GraphQL mutation — `(config) => Promise<{ data, errors }>`.\n * Errors are routed in-band to the `errors[]` envelope rather than thrown,\n * matching on-platform `toGraphQLResponseFromFailure`.\n */\nexport interface LdsGraphqlMutationAdapterConfig {\n\ttype: \"graphql-mutation\";\n\ttoolName: string;\n}\n\n/**\n * Read-shape discriminator for imperative GraphQL adapters. Mirrors the\n * `imperative-read` `invokerShape` field so the two families share a pattern:\n * one `type` discriminator + a shape field that selects the return surface.\n *\n * - `query` — `Promise<{ data, errors, subscribe }>` (on-platform\n * `GraphQLImperativeBindingsService` without `exposeRefresh`).\n * - `query-refreshable` — `Promise<{ data, errors, subscribe, refresh }>`\n * (same service with `exposeRefresh: true`).\n * - `legacy` — `{ invoke(config, context, callback),\n * subscribe(config, context, callback): Unsubscribe }`, the older callback\n * surface served by `GraphQLLegacyImperativeBindingsService`.\n *\n * `subscribe` is a deliberate no-op off-platform (no reactive store).\n */\nexport type LdsGraphqlImperativeReadInvokerShape = \"query\" | \"query-refreshable\" | \"legacy\";\n\n/**\n * Imperative GraphQL read adapter. The `invokerShape` picks the return\n * surface — see {@link LdsGraphqlImperativeReadInvokerShape}. Errors are\n * routed in-band to `errors[]` (for `query`/`query-refreshable`) or into the\n * callback payload (for `legacy`); no shape throws on tool errors.\n */\nexport interface LdsGraphqlImperativeReadAdapterConfig {\n\ttype: \"graphql-imperative-read\";\n\tinvokerShape: LdsGraphqlImperativeReadInvokerShape;\n\ttoolName: string;\n}\n\nexport type LdsAdapterConfig =\n\t| LdsWireAdapterConfig\n\t| LdsImperativeMutationAdapterConfig\n\t| LdsImperativeReadAdapterConfig\n\t| LdsGraphqlWireAdapterConfig\n\t| LdsGraphqlMutationAdapterConfig\n\t| LdsGraphqlImperativeReadAdapterConfig;\n\nexport type LdsAdapterRegistry = Record<string, Record<string, LdsAdapterConfig>>;\n\n/**\n * Default adapter registry.\n * Maps LDS module specifiers to MCP tool-backed implementations. Entries can be\n * wire adapters (`type: 'wire'`), imperative mutations (`type: 'imperative-mutation'`),\n * or imperative reads (`type: 'imperative-read'` + `invokerShape`).\n * Add entries here to support additional lightning/* exports.\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\tlayoutTypes: {\n\t\t\t\t\t\tanyOf: [{ type: \"array\", items: { type: \"string\" } }, { type: \"null\" }],\n\t\t\t\t\t},\n\t\t\t\t\tfields: {\n\t\t\t\t\t\tanyOf: [{ type: \"array\", items: { type: \"string\" } }, { type: \"null\" }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [\"recordId\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t\tanyOf: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tfields: { type: \"array\", items: { type: \"string\" }, minItems: 1 },\n\t\t\t\t\t\t},\n\t\t\t\t\t\trequired: [\"fields\"],\n\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tlayoutTypes: {\n\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\titems: { type: \"string\" },\n\t\t\t\t\t\t\t\tminItems: 1,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\trequired: [\"layoutTypes\"],\n\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tcreateRecord: {\n\t\t\ttype: \"imperative-mutation\",\n\t\t\ttoolName: \"createRecordMcpTool\",\n\t\t\tconfigJsonSchema: {\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tapiName: { type: \"string\" },\n\t\t\t\t\tfields: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {},\n\t\t\t\t\t\trequired: [],\n\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [\"apiName\", \"fields\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t},\n\t\t},\n\t\tupdateRecord: {\n\t\t\ttype: \"imperative-mutation\",\n\t\t\ttoolName: \"updateRecordMcpTool\",\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: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {},\n\t\t\t\t\t\trequired: [],\n\t\t\t\t\t\tadditionalProperties: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [\"recordId\", \"fields\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t},\n\t\t},\n\t},\n\t\"lightning/uiObjectInfoApi\": {\n\t\t// On-platform this is a `{ invoke, subscribe }` callback surface\n\t\t// emitting `{ data, error }`. The legacy invoker shape preserves that\n\t\t// contract verbatim, so ported consumers keep their call sites.\n\t\tgetObjectInfo_imperative: {\n\t\t\ttype: \"imperative-read\",\n\t\t\tinvokerShape: \"legacy\",\n\t\t\ttoolName: \"getObjectInfoMcpTool\",\n\t\t\tconfigJsonSchema: {\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties: {\n\t\t\t\t\tobjectApiName: { type: \"string\" },\n\t\t\t\t},\n\t\t\t\trequired: [\"objectApiName\"],\n\t\t\t\tadditionalProperties: false,\n\t\t\t},\n\t\t},\n\t},\n\t// `lightning/graphql` — on-platform exports `gql`, the `graphql` wire\n\t// adapter, and `executeMutation`. Only `graphql` and `executeMutation`\n\t// are registry entries; `gql` rides along automatically for any specifier\n\t// that has at least one graphql-typed entry (emitted by the load hook).\n\t\"lightning/graphql\": {\n\t\tgraphql: { type: \"graphql-wire\", toolName: \"graphqlQuery\" },\n\t\texecuteMutation: { type: \"graphql-mutation\", toolName: \"graphqlQuery\" },\n\t},\n};\n\n/** True when any entry in a module's adapter map is a `graphql-*` type. */\nfunction isGraphqlSpecifier(moduleAdapters: Record<string, LdsAdapterConfig>): boolean {\n\treturn Object.values(moduleAdapters).some(\n\t\t(entry) =>\n\t\t\tentry.type === \"graphql-wire\" ||\n\t\t\tentry.type === \"graphql-mutation\" ||\n\t\t\tentry.type === \"graphql-imperative-read\",\n\t);\n}\n\n/** Maps a config discriminator to the factory name emitted in the virtual module. */\nfunction factoryFor(type: LdsAdapterConfig[\"type\"]): string {\n\tswitch (type) {\n\t\tcase \"wire\":\n\t\t\treturn \"createWireAdapter\";\n\t\tcase \"imperative-mutation\":\n\t\t\treturn \"createMutationAdapter\";\n\t\tcase \"imperative-read\":\n\t\t\treturn \"createReadAdapter\";\n\t\tcase \"graphql-wire\":\n\t\t\treturn \"createGraphQLWireAdapter\";\n\t\tcase \"graphql-mutation\":\n\t\t\treturn \"createGraphQLMutationAdapter\";\n\t\tcase \"graphql-imperative-read\":\n\t\t\treturn \"createGraphQLImperativeReadAdapter\";\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\n/**\n * Deep-merges user overrides onto the default registry: every specifier from\n * both sides is preserved, and per-specifier entries are merged so a consumer\n * can override `getRecord` without losing `createRecord`, or register a new\n * entry on `lightning/graphql` without losing `graphql` / `executeMutation`.\n * Pass an empty object to get just the defaults. To opt out of a default\n * entry, pass the same specifier with a different entry of the same key.\n */\nfunction mergeWithDefaults(overrides: LdsAdapterRegistry): LdsAdapterRegistry {\n\tconst merged: LdsAdapterRegistry = { ...DEFAULT_ADAPTERS };\n\tfor (const [specifier, entries] of Object.entries(overrides)) {\n\t\tmerged[specifier] = { ...(DEFAULT_ADAPTERS[specifier] ?? {}), ...entries };\n\t}\n\treturn merged;\n}\n\n/**\n * LDS provider — rewrites registered `lightning/*` imports (e.g.\n * `lightning/uiRecordApi`) to MCP-tool-backed virtual modules. Unregistered\n * exports pass through to the normal `lightning/*` resolution.\n *\n * Three Vite hooks do the work:\n *\n * - **`transform`** — parses each `.js` / `.ts` file with `es-module-lexer`,\n * finds named imports from registered specifiers, and rewrites them to pull\n * registered names from `sf-lds-adapter:<specifier>` while leaving\n * unregistered names pointing at the original specifier.\n *\n * - **`resolveId`** — maps `sf-lds-adapter:<specifier>` to a `\\0`-prefixed\n * virtual module ID, preventing Rollup from attempting a filesystem lookup.\n *\n * - **`load`** — generates the virtual module, emitting an MCP-backed\n * `createWireAdapter(...)` class for every `type: 'wire'` entry,\n * `createMutationAdapter(...)` for every `type: 'imperative-mutation'` entry,\n * and `createReadAdapter(...)` for every `type: 'imperative-read'` entry.\n *\n * Only specifiers present in the `adapters` registry are intercepted; imports from\n * unregistered specifiers pass through unchanged.\n */\nexport function lds(overrides: LdsAdapterRegistry = {}): Plugin {\n\tconst adapters = mergeWithDefaults(overrides);\n\t// Graphql specifiers are owned whole by the virtual module — every export\n\t// (adapters + `gql`) lives there, so the transform hook should not split\n\t// their imports. Non-graphql specifiers still go through transform so\n\t// unregistered names pass through to the real `lightning/*` module.\n\tconst graphqlSpecifiers = new Set<string>(\n\t\tObject.entries(adapters)\n\t\t\t.filter(([, moduleAdapters]) => isGraphqlSpecifier(moduleAdapters))\n\t\t\t.map(([specifier]) => specifier),\n\t);\n\tconst transformSpecifiers = Object.keys(adapters).filter((s) => !graphqlSpecifiers.has(s));\n\tconst specifierSnippets = transformSpecifiers.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) =>\n\t\t\t\t\timp.d === -1 && imp.n !== undefined && imp.n in adapters && !graphqlSpecifiers.has(imp.n),\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\t// Graphql specifiers are intercepted raw — no transform hook split\n\t\t\t// — and mapped into the same `\\0sf-lds-adapter:` virtual namespace\n\t\t\t// so the load hook emits one module per specifier.\n\t\t\tif (graphqlSpecifiers.has(id)) return ADAPTER_ID_PREFIX + 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\t// create lines of code used to create MCP tool based adapters\n\t\t\tconst lines: string[] = [adapterBaseSource];\n\t\t\tfor (const [name, entry] of Object.entries(moduleAdapters)) {\n\t\t\t\tconst { type, ...cfg } = entry;\n\t\t\t\tlines.push(\n\t\t\t\t\t`export const ${name} = ${factoryFor(type)}(${JSON.stringify(name)}, ${JSON.stringify(cfg)});`,\n\t\t\t\t);\n\t\t\t}\n\t\t\t// `gql` rides along with any specifier that declares a graphql\n\t\t\t// adapter, so `import { gql } from 'lightning/graphql'` (or any\n\t\t\t// aliased form) keeps resolving even when no adapters are\n\t\t\t// imported alongside it. The binding itself is a private function\n\t\t\t// inside `adapterBaseSource` after `stripTopLevelExports`.\n\t\t\tif (graphqlSpecifiers.has(specifier)) {\n\t\t\t\tlines.push(\"export { gql };\");\n\t\t\t}\n\t\t\treturn lines.join(\"\\n\");\n\t\t},\n\t};\n}\n"],"names":[],"mappings":";;;;;AAeA,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB,OAAO;AAcjC,MAAM,oBAAoB;AAAA,EACzB,aAAa,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC,GAAG,YAAY,GAAG,OAAO;AAClF;AAYA,SAAS,qBAAqB,QAAwB;AACrD,SAAO,OACL,QAAQ,2CAA2C,EA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ChatSDK();
27
+ if (typeof sdk.callTool !== "function") {
28
+ throw new Error(
29
+ `[${adapterName}] 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.`
30
+ );
31
+ }
32
+ return sdk.callTool.bind(sdk);
33
+ }
25
34
  function extractToolErrorText(raw) {
26
35
  const content = raw.content;
27
36
  if (!Array.isArray(content)) return "";
@@ -41,15 +50,8 @@ class McpToolCommand {
41
50
  }
42
51
  async execute() {
43
52
  try {
44
- const app = await getChatSDK();
45
- if (!app.callTool) {
46
- return err(
47
- new Error(
48
- `[${this.adapterName}] 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.`
49
- )
50
- );
51
- }
52
- const raw = await app.callTool({
53
+ const callTool = await getCallTool(this.adapterName);
54
+ const raw = await callTool({
53
55
  toolName: this.toolName,
54
56
  params: this.params ?? void 0
55
57
  });
@@ -81,6 +83,13 @@ class McpToolSubscribableCommand {
81
83
  this.unwrap
82
84
  );
83
85
  const result = await base.execute();
86
+ const subscribers = /* @__PURE__ */ new Set();
87
+ const subscribe = (cb) => {
88
+ subscribers.add(cb);
89
+ return () => {
90
+ subscribers.delete(cb);
91
+ };
92
+ };
84
93
  const refresh = async () => {
85
94
  const next = await new McpToolCommand(
86
95
  this.adapterName,
@@ -88,9 +97,10 @@ class McpToolSubscribableCommand {
88
97
  this.params,
89
98
  this.unwrap
90
99
  ).execute();
100
+ subscribers.forEach((cb) => cb(next));
91
101
  return next.isOk() ? ok(void 0) : err(next.error);
92
102
  };
93
- return buildSubscribableResult(result, noopSubscribe, refresh);
103
+ return buildSubscribableResult(result, subscribe, refresh);
94
104
  }
95
105
  }
96
106
  const defaultImperativeService = buildDefaultImperativeBindingsServiceDescriptor().service;
@@ -160,9 +170,146 @@ function createWireAdapter(name, cfg) {
160
170
  cfg.configJsonSchema
161
171
  );
162
172
  }
173
+ function gql(strings, ...values) {
174
+ let result = "";
175
+ strings.forEach((string, i) => {
176
+ result += string;
177
+ if (i < values.length) result += String(values[i]);
178
+ });
179
+ return result.trim();
180
+ }
181
+ async function runGraphqlQuery(adapterName, toolName, config) {
182
+ const { query, variables } = config;
183
+ if (!query) return { data: void 0, errors: void 0 };
184
+ const callTool = await getCallTool(adapterName);
185
+ const raw = await callTool({
186
+ toolName,
187
+ params: { query, variables: variables ?? {} }
188
+ });
189
+ return normalizeMcpResponse(raw) ?? {};
190
+ }
191
+ function toGraphqlErrorResult(error) {
192
+ return { data: void 0, errors: [{ message: error.message }] };
193
+ }
194
+ async function runGraphqlQuerySafe(adapterName, toolName, config) {
195
+ try {
196
+ return await runGraphqlQuery(adapterName, toolName, config);
197
+ } catch (error) {
198
+ return toGraphqlErrorResult(error);
199
+ }
200
+ }
201
+ function createGraphQLWireAdapter(name, cfg) {
202
+ return class {
203
+ _dataCallback;
204
+ _config;
205
+ _connected = false;
206
+ constructor(dataCallback) {
207
+ this._dataCallback = dataCallback;
208
+ }
209
+ connect() {
210
+ this._connected = true;
211
+ void this._fetch();
212
+ }
213
+ disconnect() {
214
+ this._connected = false;
215
+ }
216
+ update(config) {
217
+ this._config = config;
218
+ if (!this._connected || this._config === void 0) {
219
+ return;
220
+ }
221
+ void this._fetch();
222
+ }
223
+ refresh() {
224
+ return this._fetch();
225
+ }
226
+ async _fetch() {
227
+ this._emit(await runGraphqlQuerySafe(name, cfg.toolName, this._config ?? {}));
228
+ }
229
+ _emit({ data, errors }) {
230
+ this._dataCallback({
231
+ data,
232
+ errors: errors?.length ? errors : void 0,
233
+ refresh: () => this.refresh()
234
+ });
235
+ }
236
+ };
237
+ }
238
+ function createGraphQLMutationAdapter(name, cfg) {
239
+ return async (config) => {
240
+ if (!config?.query) return { data: void 0, errors: [{ message: "No query provided" }] };
241
+ return runGraphqlQuerySafe(name, cfg.toolName, config);
242
+ };
243
+ }
244
+ function createGraphQLImperativeReadAdapter(name, cfg) {
245
+ if (cfg.invokerShape === "legacy") {
246
+ async function run(config, callback) {
247
+ if (!config?.query) {
248
+ callback({ data: void 0, errors: void 0 });
249
+ return;
250
+ }
251
+ const result = await runGraphqlQuerySafe(name, cfg.toolName, config);
252
+ callback({
253
+ data: result.data,
254
+ errors: result.errors?.length ? result.errors : void 0
255
+ });
256
+ }
257
+ return {
258
+ invoke(config, _context, callback) {
259
+ void run(config, callback);
260
+ },
261
+ subscribe(config, _context, callback) {
262
+ void run(config, callback);
263
+ return noopUnsubscribe;
264
+ }
265
+ };
266
+ }
267
+ if (cfg.invokerShape === "query-refreshable") {
268
+ return async (config) => {
269
+ const result = await runGraphqlQuerySafe(name, cfg.toolName, config);
270
+ if (result.errors?.length) {
271
+ return { data: void 0, errors: result.errors };
272
+ }
273
+ const subscribers = /* @__PURE__ */ new Set();
274
+ return {
275
+ data: result.data,
276
+ errors: void 0,
277
+ subscribe: (cb) => {
278
+ subscribers.add(cb);
279
+ return () => {
280
+ subscribers.delete(cb);
281
+ };
282
+ },
283
+ refresh: async () => {
284
+ const fresh = await runGraphqlQuerySafe(name, cfg.toolName, config);
285
+ const payload = {
286
+ data: fresh.data,
287
+ errors: fresh.errors?.length ? fresh.errors : void 0
288
+ };
289
+ subscribers.forEach((cb) => cb(payload));
290
+ }
291
+ };
292
+ };
293
+ }
294
+ return async (config) => {
295
+ const result = await runGraphqlQuerySafe(name, cfg.toolName, config);
296
+ if (result.errors?.length) {
297
+ return { data: void 0, errors: result.errors };
298
+ }
299
+ return {
300
+ data: result.data,
301
+ errors: void 0,
302
+ subscribe: noopSubscribe
303
+ };
304
+ };
305
+ }
163
306
  export {
307
+ createGraphQLImperativeReadAdapter,
308
+ createGraphQLMutationAdapter,
309
+ createGraphQLWireAdapter,
164
310
  createMutationAdapter,
165
311
  createReadAdapter,
166
- createWireAdapter
312
+ createWireAdapter,
313
+ gql
167
314
  };
168
315
  //# sourceMappingURL=runtime.js.map
@@ -1 +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 type { ResultCommand, SubscribableResultCommand } from \"@conduit-client/bindings-utils/v1\";\nimport type { assertIsValid, JSONSchema } from \"@conduit-client/jsonschema-validate\";\nimport {\n\tbuildDefaultImperativeBindingsServiceDescriptor,\n\tbuildLegacyImperativeBindingsServiceDescriptor,\n\tbuildQueryImperativeBindingsServiceDescriptor,\n\tbuildSubscribableImperativeBindingsServiceDescriptor,\n} from \"@conduit-client/service-bindings-imperative/v1\";\nimport { buildLWCWireBindingsServiceDescriptor } from \"@conduit-client/service-bindings-lwc/v1\";\nimport {\n\tbuildSubscribableResult,\n\terr,\n\tok,\n\ttoError,\n\ttype Callback,\n\ttype Result,\n\ttype Unsubscribe,\n} from \"@conduit-client/utils\";\nimport { getChatSDK } from \"@salesforce/sdk-chat\";\nimport type { ReadInvokerShape } from \"./types\";\nimport { normalizeMcpResponse } from \"../shared/normalize-mcp-response\";\n\ninterface WireAdapterConfig {\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\ninterface MutationAdapterConfig {\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\ninterface ReadAdapterConfig {\n\tinvokerShape: ReadInvokerShape;\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\n/**\n * Optional envelope splitter. Converts the normalized MCP payload into a\n * `Result<Data, Error>` — used by the wire adapter so tools that return\n * `{ data, error }` land on OneStore's Err branch when `error` is set.\n * Imperative callers leave this unset and get the raw payload wrapped in\n * `ok(...)`.\n */\ntype UnwrapEnvelope<Data> = (payload: unknown) => Result<Data, Error>;\n\n/**\n * Pulls a human-readable message out of an MCP error response\n * (`{ isError: true, content: [{ type: 'text', text: ... }, ...] }`).\n * Returns an empty string if no text content is present so the caller can\n * supply a fallback.\n */\nfunction extractToolErrorText(raw: unknown): string {\n\tconst content = (raw as { content?: unknown }).content;\n\tif (!Array.isArray(content)) return \"\";\n\treturn content\n\t\t.map((c) => {\n\t\t\tif (c && typeof c === \"object\" && (c as { type?: string }).type === \"text\") {\n\t\t\t\treturn (c as { text?: string }).text ?? \"\";\n\t\t\t}\n\t\t\treturn \"\";\n\t\t})\n\t\t.join(\" \")\n\t\t.trim();\n}\n\n/**\n * `Command` implementation that calls the configured MCP tool. One class,\n * reused across imperative and wire adapters.\n *\n * `execute()` returns a `Result<Data, unknown>`:\n * - `ok(data)` when the tool resolves — `data` is the unwrapped payload from\n * `normalizeMcpResponse` (or the result of the optional `unwrap` hook).\n * - `err(error)` when the tool rejects, when `sdk.callTool` is unavailable,\n * or when the `unwrap` hook returns `err(...)`.\n *\n * OneStore's `DefaultImperativeBindingsService` wraps this: on `ok(v)` it\n * deep-freezes and returns `v`; on `err(e)` it re-throws via `toError`. Sync\n * throws from `assertIsValid` in the `getCommand` factory are funneled through\n * `throwUserlandError`. `LWCWireBindingsService` wraps the same command\n * differently — it emits `{ data, error }` to the wire callback and attaches\n * freeze / race-guard / incomplete-config behavior.\n */\nclass McpToolCommand<Data> implements ResultCommand<Data, Error> {\n\tconstructor(\n\t\tprivate readonly adapterName: string,\n\t\tprivate readonly toolName: string,\n\t\tprivate readonly params: unknown,\n\t\tprivate readonly unwrap?: UnwrapEnvelope<Data>,\n\t) {}\n\n\tasync execute(): Promise<Result<Data, Error>> {\n\t\ttry {\n\t\t\tconst app = await getChatSDK();\n\t\t\tif (!app.callTool) {\n\t\t\t\treturn err(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t`[${this.adapterName}] 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 \" +\n\t\t\t\t\t\t\t\"in an MCP Apps / OpenAI chat context.\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst raw = await app.callTool({\n\t\t\t\ttoolName: this.toolName,\n\t\t\t\tparams: (this.params as Record<string, unknown>) ?? undefined,\n\t\t\t});\n\t\t\t// The MCP SDK converts handler throws into a resolved tool response\n\t\t\t// with `{ isError: true, content: [...] }` — not a transport\n\t\t\t// rejection. Surface it as an Err here so the default invoker\n\t\t\t// re-throws and the wire/legacy adapters route it through their\n\t\t\t// error channel.\n\t\t\tif (raw && typeof raw === \"object\" && (raw as { isError?: boolean }).isError) {\n\t\t\t\treturn err(new Error(extractToolErrorText(raw) || \"MCP tool error\"));\n\t\t\t}\n\t\t\tconst payload = normalizeMcpResponse(raw);\n\t\t\treturn this.unwrap ? this.unwrap(payload) : ok(payload as Data);\n\t\t} catch (e) {\n\t\t\treturn err(e instanceof Error ? e : new Error(String(e)));\n\t\t}\n\t}\n}\n\n// Off-platform has no store to observe. `subscribe` never fires the callback;\n// the returned unsubscribe is a safe no-op. Module-level so `refresh()`\n// doesn't re-allocate.\nconst noopUnsubscribe: Unsubscribe = () => {\n\t// no store to unsubscribe from off-platform\n};\nconst noopSubscribe = (_cb: Callback<Result<unknown, unknown>>): Unsubscribe => noopUnsubscribe;\n\n/**\n * Adapts `McpToolCommand` into a `SubscribableResultCommand`. Wraps the\n * command's `Result` with `buildSubscribableResult`, supplying:\n * - `subscribe`: no-op — off-platform has no store, so the callback never\n * fires. Returned unsubscribe is idempotent.\n * - `refresh`: builds a fresh `McpToolCommand` and re-executes it so each\n * refresh issues a new MCP tool call. Returns `Result<void, Error>`\n * (ok → undefined; err → the error from the fresh execute).\n *\n * This shim is what lets OneStore's Subscribable and Legacy services run\n * verbatim against MCP: their invokers gate on `isSubscribableResult`, which\n * requires the command's `execute()` to resolve a `SubscribableResult` (not\n * a plain `Result`). The deliberate \"subscribe that doesn't subscribe\"\n * preserves the OneStore API surface so ported code keeps its call sites.\n */\nclass McpToolSubscribableCommand<Data> implements SubscribableResultCommand<Data, Error> {\n\tconstructor(\n\t\tprivate readonly adapterName: string,\n\t\tprivate readonly toolName: string,\n\t\tprivate readonly params: unknown,\n\t\tprivate readonly unwrap?: UnwrapEnvelope<Data>,\n\t) {}\n\n\tasync execute() {\n\t\tconst base = new McpToolCommand<Data>(\n\t\t\tthis.adapterName,\n\t\t\tthis.toolName,\n\t\t\tthis.params,\n\t\t\tthis.unwrap,\n\t\t);\n\t\tconst result = await base.execute();\n\t\tconst refresh = async () => {\n\t\t\tconst next = await new McpToolCommand<Data>(\n\t\t\t\tthis.adapterName,\n\t\t\t\tthis.toolName,\n\t\t\t\tthis.params,\n\t\t\t\tthis.unwrap,\n\t\t\t).execute();\n\t\t\treturn next.isOk() ? ok<void, Error>(undefined) : err(next.error);\n\t\t};\n\t\treturn buildSubscribableResult(result, noopSubscribe, refresh);\n\t}\n}\n\nconst defaultImperativeService = buildDefaultImperativeBindingsServiceDescriptor().service;\nconst queryImperativeService = buildQueryImperativeBindingsServiceDescriptor().service;\nconst subscribableImperativeService =\n\tbuildSubscribableImperativeBindingsServiceDescriptor().service;\nconst legacyImperativeService = buildLegacyImperativeBindingsServiceDescriptor().service;\n\n/**\n * Mutation-shape factory. Builds an async `(config) => Promise<Data>` via\n * OneStore's `DefaultImperativeBindingsService`. Throws on validation error\n * (`throwUserlandError`) or tool error (`toError`). This is the only shape a\n * mutation ever takes on platform — mutation adapters do not carry an\n * `invokerShape` at all.\n */\nexport function createMutationAdapter(name: string, cfg: MutationAdapterConfig) {\n\tconst getCommand = (options: { params: unknown[]; assertIsValid: typeof assertIsValid }) => {\n\t\toptions.assertIsValid(options.params[0], cfg.configJsonSchema);\n\t\treturn new McpToolCommand<unknown>(name, cfg.toolName, options.params[0]);\n\t};\n\tconst invoker = defaultImperativeService.bind<unknown[], unknown>(getCommand);\n\treturn (...params: unknown[]) => Promise.resolve(invoker(...params));\n}\n\n/**\n * Read-shape factory. Dispatches on `cfg.invokerShape`:\n *\n * - `legacy` — `{ invoke, subscribe }` callback surface with `{ data, error }`.\n * `subscribe` fires the callback once from the initial execute's `data`,\n * returns a no-op unsubscribe, and never fires again off-platform.\n * - `query` — `(config) => Promise<{ data }>`; one-shot read.\n * - `subscribable` — `(config) => Promise<{ data, subscribe }>`. Callback\n * passed to `subscribe` never fires; unsubscribe is a no-op.\n * - `subscribable-refreshable` — `(config) => Promise<{ data, subscribe, refresh }>`.\n * `refresh()` re-executes the MCP tool; `subscribe` is still a no-op.\n *\n * All four delegate to an OneStore service (Query / Subscribable / Legacy)\n * over `McpToolSubscribableCommand`, which preserves OneStore's deep-freeze\n * and error-funnel semantics end-to-end.\n */\nexport function createReadAdapter(name: string, cfg: ReadAdapterConfig) {\n\tconst getSubscribableCommand = (options: {\n\t\tparams: unknown[];\n\t\tassertIsValid: typeof assertIsValid;\n\t}) => {\n\t\toptions.assertIsValid(options.params[0], cfg.configJsonSchema);\n\t\treturn new McpToolSubscribableCommand<unknown>(name, cfg.toolName, options.params[0]);\n\t};\n\n\tswitch (cfg.invokerShape) {\n\t\tcase \"query\": {\n\t\t\tconst getCommand = (options: { params: unknown[]; assertIsValid: typeof assertIsValid }) => {\n\t\t\t\toptions.assertIsValid(options.params[0], cfg.configJsonSchema);\n\t\t\t\treturn new McpToolCommand<unknown>(name, cfg.toolName, options.params[0]);\n\t\t\t};\n\t\t\tconst invoker = queryImperativeService.bind<unknown[], unknown>(getCommand);\n\t\t\treturn (...params: unknown[]) => Promise.resolve(invoker(...params));\n\t\t}\n\t\tcase \"subscribable\": {\n\t\t\tconst invoker = subscribableImperativeService.bind<unknown[], unknown>(\n\t\t\t\tgetSubscribableCommand,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\treturn (...params: unknown[]) => Promise.resolve(invoker(...params));\n\t\t}\n\t\tcase \"subscribable-refreshable\": {\n\t\t\tconst invoker = subscribableImperativeService.bind<unknown[], unknown>(\n\t\t\t\tgetSubscribableCommand,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t\treturn (...params: unknown[]) => Promise.resolve(invoker(...params));\n\t\t}\n\t\tcase \"legacy\": {\n\t\t\t// Legacy service passes `{ config, assertIsValid }`, not `{ params, ... }`.\n\t\t\tconst getLegacyCommand = (options: {\n\t\t\t\tconfig: unknown;\n\t\t\t\tassertIsValid: typeof assertIsValid;\n\t\t\t}) => {\n\t\t\t\toptions.assertIsValid(options.config, cfg.configJsonSchema);\n\t\t\t\treturn new McpToolSubscribableCommand<unknown>(name, cfg.toolName, options.config);\n\t\t\t};\n\t\t\treturn legacyImperativeService.bind<unknown, unknown>(getLegacyCommand);\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(\n\t\t\t\t`[${name}] unsupported invokerShape: ${String((cfg as { invokerShape: unknown }).invokerShape)}. ` +\n\t\t\t\t\t`Expected 'legacy' | 'query' | 'subscribable' | 'subscribable-refreshable'.`,\n\t\t\t);\n\t}\n}\n\nconst lwcWireBindingsService = buildLWCWireBindingsServiceDescriptor().service;\n\n/**\n * Splits the MCP tool's `{ data, error }` envelope into a `Result`. Used as\n * the `unwrap` hook on `McpToolCommand` so OneStore's wire invoker sees the\n * error branch directly instead of receiving an envelope wrapped in `ok(...)`.\n *\n * Tools that don't emit the envelope (e.g. imperative) never go through this\n * path — the default imperative invoker doesn't pass `unwrap`.\n */\nfunction unwrapWireEnvelope<Data>(payload: unknown): Result<Data, Error> {\n\tconst envelope = payload as { data?: unknown; error?: unknown } | null | undefined;\n\tif (envelope && envelope.error !== undefined && envelope.error !== null) {\n\t\treturn err(toError(envelope.error));\n\t}\n\treturn ok(envelope?.data as Data);\n}\n\n/**\n * Creates an LWC wire adapter class that calls an MCP tool. Delegates to\n * OneStore's `LWCWireBindingsService`, so the returned class inherits the\n * full `CommandWireAdapterConstructor` contract: initial empty emit, config\n * `sanitize()`, `MissingRequiredPropertyError` → wait-for-next-config gating,\n * deep-freeze on success, race guard on stale resolves, and unsubscriber\n * management on disconnect.\n *\n * The `McpToolCommand` class is reused verbatim — the wire call-site only\n * supplies an `unwrap` hook so the tool's `{ data, error }` envelope lands\n * on OneStore's Err branch rather than being leaked through as an `ok(...)`\n * envelope.\n *\n * @param name - Wire adapter export name, used in MCP error messages.\n * @param cfg - MCP tool name and JSON Schema for valid wire configs.\n */\nexport function createWireAdapter(name: string, cfg: WireAdapterConfig) {\n\treturn lwcWireBindingsService.bind<unknown>(\n\t\t(config) => new McpToolCommand(name, cfg.toolName, config, unwrapWireEnvelope),\n\t\tcfg.configJsonSchema,\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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AY,CAAC;AAAA,MAAA;AAAA,EAE/F;AAEH;AAEA,MAAM,yBAAyB,wCAAwC;AAUvE,SAAS,mBAAyB,SAAuC;AACxE,QAAM,WAAW;AACjB,MAAI,YAAY,SAAS,UAAU,UAAa,SAAS,UAAU,MAAM;AACxE,WAAO,IAAI,QAAQ,SAAS,KAAK,CAAC;AAAA,EACnC;AACA,SAAO,GAAG,UAAU,IAAY;AACjC;AAkBO,SAAS,kBAAkB,MAAc,KAAwB;AACvE,SAAO,uBAAuB;AAAA,IAC7B,CAAC,WAAW,IAAI,eAAe,MAAM,IAAI,UAAU,QAAQ,kBAAkB;AAAA,IAC7E,IAAI;AAAA,EAAA;AAEN;"}
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 type { ResultCommand, SubscribableResultCommand } from \"@conduit-client/bindings-utils/v1\";\nimport type { assertIsValid, JSONSchema } from \"@conduit-client/jsonschema-validate\";\nimport {\n\tbuildDefaultImperativeBindingsServiceDescriptor,\n\tbuildLegacyImperativeBindingsServiceDescriptor,\n\tbuildQueryImperativeBindingsServiceDescriptor,\n\tbuildSubscribableImperativeBindingsServiceDescriptor,\n} from \"@conduit-client/service-bindings-imperative/v1\";\nimport { buildLWCWireBindingsServiceDescriptor } from \"@conduit-client/service-bindings-lwc/v1\";\nimport {\n\tbuildSubscribableResult,\n\terr,\n\tok,\n\ttoError,\n\ttype Callback,\n\ttype Result,\n\ttype Unsubscribe,\n} from \"@conduit-client/utils\";\nimport { getChatSDK } from \"@salesforce/sdk-chat\";\nimport type { ReadInvokerShape } from \"./types\";\nimport { normalizeMcpResponse } from \"../shared/normalize-mcp-response\";\n\ninterface WireAdapterConfig {\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\ninterface MutationAdapterConfig {\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\ninterface ReadAdapterConfig {\n\tinvokerShape: ReadInvokerShape;\n\ttoolName: string;\n\tconfigJsonSchema: JSONSchema;\n}\n\n/**\n * Optional envelope splitter. Converts the normalized MCP payload into a\n * `Result<Data, Error>` — used by the wire adapter so tools that return\n * `{ data, error }` land on OneStore's Err branch when `error` is set.\n * Imperative callers leave this unset and get the raw payload wrapped in\n * `ok(...)`.\n */\ntype UnwrapEnvelope<Data> = (payload: unknown) => Result<Data, Error>;\n\n/**\n * Resolves the MCP chat SDK and returns its `callTool` function, or throws a\n * consistent \"[adapter] sdk.callTool is not available\" error. Shared by the\n * LDS `McpToolCommand` and the graphql `runGraphqlQuery` — the check and\n * message are identical on both paths.\n */\nasync function getCallTool(\n\tadapterName: string,\n): Promise<(args: { toolName: string; params?: Record<string, unknown> }) => Promise<unknown>> {\n\tconst sdk = await getChatSDK();\n\tif (typeof sdk.callTool !== \"function\") {\n\t\tthrow new Error(\n\t\t\t`[${adapterName}] sdk.callTool is not available on this surface. ` +\n\t\t\t\t\"Make sure window.openai is configured or the component is running \" +\n\t\t\t\t\"in an MCP Apps / OpenAI chat context.\",\n\t\t);\n\t}\n\treturn sdk.callTool.bind(sdk);\n}\n\n/**\n * Pulls a human-readable message out of an MCP error response\n * (`{ isError: true, content: [{ type: 'text', text: ... }, ...] }`).\n * Returns an empty string if no text content is present so the caller can\n * supply a fallback.\n */\nfunction extractToolErrorText(raw: unknown): string {\n\tconst content = (raw as { content?: unknown }).content;\n\tif (!Array.isArray(content)) return \"\";\n\treturn content\n\t\t.map((c) => {\n\t\t\tif (c && typeof c === \"object\" && (c as { type?: string }).type === \"text\") {\n\t\t\t\treturn (c as { text?: string }).text ?? \"\";\n\t\t\t}\n\t\t\treturn \"\";\n\t\t})\n\t\t.join(\" \")\n\t\t.trim();\n}\n\n/**\n * `Command` implementation that calls the configured MCP tool. One class,\n * reused across imperative and wire adapters.\n *\n * `execute()` returns a `Result<Data, unknown>`:\n * - `ok(data)` when the tool resolves — `data` is the unwrapped payload from\n * `normalizeMcpResponse` (or the result of the optional `unwrap` hook).\n * - `err(error)` when the tool rejects, when `sdk.callTool` is unavailable,\n * or when the `unwrap` hook returns `err(...)`.\n *\n * OneStore's `DefaultImperativeBindingsService` wraps this: on `ok(v)` it\n * deep-freezes and returns `v`; on `err(e)` it re-throws via `toError`. Sync\n * throws from `assertIsValid` in the `getCommand` factory are funneled through\n * `throwUserlandError`. `LWCWireBindingsService` wraps the same command\n * differently — it emits `{ data, error }` to the wire callback and attaches\n * freeze / race-guard / incomplete-config behavior.\n */\nclass McpToolCommand<Data> implements ResultCommand<Data, Error> {\n\tconstructor(\n\t\tprivate readonly adapterName: string,\n\t\tprivate readonly toolName: string,\n\t\tprivate readonly params: unknown,\n\t\tprivate readonly unwrap?: UnwrapEnvelope<Data>,\n\t) {}\n\n\tasync execute(): Promise<Result<Data, Error>> {\n\t\ttry {\n\t\t\tconst callTool = await getCallTool(this.adapterName);\n\t\t\tconst raw = await callTool({\n\t\t\t\ttoolName: this.toolName,\n\t\t\t\tparams: (this.params as Record<string, unknown>) ?? undefined,\n\t\t\t});\n\t\t\t// The MCP SDK converts handler throws into a resolved tool response\n\t\t\t// with `{ isError: true, content: [...] }` — not a transport\n\t\t\t// rejection. Surface it as an Err here so the default invoker\n\t\t\t// re-throws and the wire/legacy adapters route it through their\n\t\t\t// error channel.\n\t\t\tif (raw && typeof raw === \"object\" && (raw as { isError?: boolean }).isError) {\n\t\t\t\treturn err(new Error(extractToolErrorText(raw) || \"MCP tool error\"));\n\t\t\t}\n\t\t\tconst payload = normalizeMcpResponse(raw);\n\t\t\treturn this.unwrap ? this.unwrap(payload) : ok(payload as Data);\n\t\t} catch (e) {\n\t\t\treturn err(e instanceof Error ? e : new Error(String(e)));\n\t\t}\n\t}\n}\n\n// Off-platform has no store to observe. For shapes that have no `refresh`,\n// nothing can ever trigger a post-initial update, so `subscribe` is a\n// deliberate no-op: the callback never fires and the returned unsubscribe is\n// idempotent. Shapes that *do* expose `refresh` wire subscribers into the\n// refresh path instead (see `McpToolSubscribableCommand` and the\n// `query-refreshable` graphql shape).\nconst noopUnsubscribe: Unsubscribe = () => {\n\t// no store to unsubscribe from off-platform\n};\nconst noopSubscribe = (_cb: unknown): Unsubscribe => noopUnsubscribe;\n\n/**\n * Adapts `McpToolCommand` into a `SubscribableResultCommand`. Wraps the\n * command's `Result` with `buildSubscribableResult`, supplying:\n * - `subscribe`: per-execution subscriber set. Each `execute()` call has\n * its own set so sibling invocations don't cross-pollinate. Returned\n * unsubscribe removes the callback and is idempotent.\n * - `refresh`: builds a fresh `McpToolCommand`, re-executes it, and\n * broadcasts the fresh `Result` to every registered subscriber before\n * resolving. Returns `Result<void, Error>` (ok → undefined; err → the\n * error from the fresh execute).\n *\n * Wiring subscribers into refresh mirrors on-platform behavior, where the\n * reactive store fans `refresh` results out to every listener. Off-platform\n * there is no store, so the subscriber set lives on the command itself. This\n * shim is what lets OneStore's Subscribable and Legacy services run verbatim\n * against MCP: their invokers gate on `isSubscribableResult`, which requires\n * the command's `execute()` to resolve a `SubscribableResult` (not a plain\n * `Result`).\n */\nclass McpToolSubscribableCommand<Data> implements SubscribableResultCommand<Data, Error> {\n\tconstructor(\n\t\tprivate readonly adapterName: string,\n\t\tprivate readonly toolName: string,\n\t\tprivate readonly params: unknown,\n\t\tprivate readonly unwrap?: UnwrapEnvelope<Data>,\n\t) {}\n\n\tasync execute() {\n\t\tconst base = new McpToolCommand<Data>(\n\t\t\tthis.adapterName,\n\t\t\tthis.toolName,\n\t\t\tthis.params,\n\t\t\tthis.unwrap,\n\t\t);\n\t\tconst result = await base.execute();\n\t\tconst subscribers = new Set<Callback<Result<Data, Error>>>();\n\t\tconst subscribe = (cb: Callback<Result<Data, Error>>): Unsubscribe => {\n\t\t\tsubscribers.add(cb);\n\t\t\treturn () => {\n\t\t\t\tsubscribers.delete(cb);\n\t\t\t};\n\t\t};\n\t\tconst refresh = async () => {\n\t\t\tconst next = await new McpToolCommand<Data>(\n\t\t\t\tthis.adapterName,\n\t\t\t\tthis.toolName,\n\t\t\t\tthis.params,\n\t\t\t\tthis.unwrap,\n\t\t\t).execute();\n\t\t\tsubscribers.forEach((cb) => cb(next));\n\t\t\treturn next.isOk() ? ok<void, Error>(undefined) : err(next.error);\n\t\t};\n\t\treturn buildSubscribableResult(result, subscribe, refresh);\n\t}\n}\n\nconst defaultImperativeService = buildDefaultImperativeBindingsServiceDescriptor().service;\nconst queryImperativeService = buildQueryImperativeBindingsServiceDescriptor().service;\nconst subscribableImperativeService =\n\tbuildSubscribableImperativeBindingsServiceDescriptor().service;\nconst legacyImperativeService = buildLegacyImperativeBindingsServiceDescriptor().service;\n\n/**\n * Mutation-shape factory. Builds an async `(config) => Promise<Data>` via\n * OneStore's `DefaultImperativeBindingsService`. Throws on validation error\n * (`throwUserlandError`) or tool error (`toError`). This is the only shape a\n * mutation ever takes on platform — mutation adapters do not carry an\n * `invokerShape` at all.\n */\nexport function createMutationAdapter(name: string, cfg: MutationAdapterConfig) {\n\tconst getCommand = (options: { params: unknown[]; assertIsValid: typeof assertIsValid }) => {\n\t\toptions.assertIsValid(options.params[0], cfg.configJsonSchema);\n\t\treturn new McpToolCommand<unknown>(name, cfg.toolName, options.params[0]);\n\t};\n\tconst invoker = defaultImperativeService.bind<unknown[], unknown>(getCommand);\n\treturn (...params: unknown[]) => Promise.resolve(invoker(...params));\n}\n\n/**\n * Read-shape factory. Dispatches on `cfg.invokerShape`:\n *\n * - `legacy` — `{ invoke, subscribe }` callback surface with `{ data, error }`.\n * `subscribe` fires the callback once from the initial execute's `data`,\n * returns a no-op unsubscribe, and never fires again off-platform.\n * - `query` — `(config) => Promise<{ data }>`; one-shot read.\n * - `subscribable` — `(config) => Promise<{ data, subscribe }>`. Callback\n * passed to `subscribe` never fires; unsubscribe is a no-op.\n * - `subscribable-refreshable` — `(config) => Promise<{ data, subscribe, refresh }>`.\n * `refresh()` re-executes the MCP tool; `subscribe` is still a no-op.\n *\n * All four delegate to an OneStore service (Query / Subscribable / Legacy)\n * over `McpToolSubscribableCommand`, which preserves OneStore's deep-freeze\n * and error-funnel semantics end-to-end.\n */\nexport function createReadAdapter(name: string, cfg: ReadAdapterConfig) {\n\tconst getSubscribableCommand = (options: {\n\t\tparams: unknown[];\n\t\tassertIsValid: typeof assertIsValid;\n\t}) => {\n\t\toptions.assertIsValid(options.params[0], cfg.configJsonSchema);\n\t\treturn new McpToolSubscribableCommand<unknown>(name, cfg.toolName, options.params[0]);\n\t};\n\n\tswitch (cfg.invokerShape) {\n\t\tcase \"query\": {\n\t\t\tconst getCommand = (options: { params: unknown[]; assertIsValid: typeof assertIsValid }) => {\n\t\t\t\toptions.assertIsValid(options.params[0], cfg.configJsonSchema);\n\t\t\t\treturn new McpToolCommand<unknown>(name, cfg.toolName, options.params[0]);\n\t\t\t};\n\t\t\tconst invoker = queryImperativeService.bind<unknown[], unknown>(getCommand);\n\t\t\treturn (...params: unknown[]) => Promise.resolve(invoker(...params));\n\t\t}\n\t\tcase \"subscribable\": {\n\t\t\tconst invoker = subscribableImperativeService.bind<unknown[], unknown>(\n\t\t\t\tgetSubscribableCommand,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\treturn (...params: unknown[]) => Promise.resolve(invoker(...params));\n\t\t}\n\t\tcase \"subscribable-refreshable\": {\n\t\t\tconst invoker = subscribableImperativeService.bind<unknown[], unknown>(\n\t\t\t\tgetSubscribableCommand,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t\treturn (...params: unknown[]) => Promise.resolve(invoker(...params));\n\t\t}\n\t\tcase \"legacy\": {\n\t\t\t// Legacy service passes `{ config, assertIsValid }`, not `{ params, ... }`.\n\t\t\tconst getLegacyCommand = (options: {\n\t\t\t\tconfig: unknown;\n\t\t\t\tassertIsValid: typeof assertIsValid;\n\t\t\t}) => {\n\t\t\t\toptions.assertIsValid(options.config, cfg.configJsonSchema);\n\t\t\t\treturn new McpToolSubscribableCommand<unknown>(name, cfg.toolName, options.config);\n\t\t\t};\n\t\t\treturn legacyImperativeService.bind<unknown, unknown>(getLegacyCommand);\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(\n\t\t\t\t`[${name}] unsupported invokerShape: ${String((cfg as { invokerShape: unknown }).invokerShape)}. ` +\n\t\t\t\t\t`Expected 'legacy' | 'query' | 'subscribable' | 'subscribable-refreshable'.`,\n\t\t\t);\n\t}\n}\n\nconst lwcWireBindingsService = buildLWCWireBindingsServiceDescriptor().service;\n\n/**\n * Splits the MCP tool's `{ data, error }` envelope into a `Result`. Used as\n * the `unwrap` hook on `McpToolCommand` so OneStore's wire invoker sees the\n * error branch directly instead of receiving an envelope wrapped in `ok(...)`.\n *\n * Tools that don't emit the envelope (e.g. imperative) never go through this\n * path — the default imperative invoker doesn't pass `unwrap`.\n */\nfunction unwrapWireEnvelope<Data>(payload: unknown): Result<Data, Error> {\n\tconst envelope = payload as { data?: unknown; error?: unknown } | null | undefined;\n\tif (envelope && envelope.error !== undefined && envelope.error !== null) {\n\t\treturn err(toError(envelope.error));\n\t}\n\treturn ok(envelope?.data as Data);\n}\n\n/**\n * Creates an LWC wire adapter class that calls an MCP tool. Delegates to\n * OneStore's `LWCWireBindingsService`, so the returned class inherits the\n * full `CommandWireAdapterConstructor` contract: initial empty emit, config\n * `sanitize()`, `MissingRequiredPropertyError` → wait-for-next-config gating,\n * deep-freeze on success, race guard on stale resolves, and unsubscriber\n * management on disconnect.\n *\n * The `McpToolCommand` class is reused verbatim — the wire call-site only\n * supplies an `unwrap` hook so the tool's `{ data, error }` envelope lands\n * on OneStore's Err branch rather than being leaked through as an `ok(...)`\n * envelope.\n *\n * @param name - Wire adapter export name, used in MCP error messages.\n * @param cfg - MCP tool name and JSON Schema for valid wire configs.\n */\nexport function createWireAdapter(name: string, cfg: WireAdapterConfig) {\n\treturn lwcWireBindingsService.bind<unknown>(\n\t\t(config) => new McpToolCommand(name, cfg.toolName, config, unwrapWireEnvelope),\n\t\tcfg.configJsonSchema,\n\t);\n}\n\n// ─── GraphQL adapters ─────────────────────────────────────────────────────────\n\n/**\n * GraphQL adapters diverge from the base wire / mutation shapes in two ways:\n *\n * 1. Envelope is `{ data, errors[] }` instead of `{ data, error }`. Errors\n * are collected; an empty array collapses to `undefined`.\n * 2. The `_fetch` path routes thrown errors **into** the `errors[]`\n * envelope on the wire callback (never throws to the LWC host). Mutation\n * likewise resolves with `{ data, errors }` rather than rejecting.\n *\n * Dispatch is MCP-only: `getChatSDK().callTool({ toolName, params })` with\n * `normalizeMcpResponse` unwrapping. No `globalThis.__sfdc_sdk__` shortcut —\n * the on-platform behaviour is already covered by real `lightning/graphql`,\n * and every off-platform caller routes through an MCP tool like every other\n * LDS adapter.\n */\ninterface GraphqlAdapterConfig {\n\ttoolName: string;\n}\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 GraphqlWireCallback = (result: {\n\tdata: unknown;\n\terrors: { message: string }[] | undefined;\n\trefresh: () => Promise<void>;\n}) => void;\n\n/**\n * Template-literal tag that stitches the string into a plain `query` string.\n * Deliberately minimal — no AST parsing, no fragment substitution, no opaque\n * doc emulation. Matches the shape used by today's off-platform `gql`.\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.trim();\n}\n\nasync function runGraphqlQuery(\n\tadapterName: string,\n\ttoolName: string,\n\tconfig: GraphqlConfig,\n): Promise<GraphqlResult> {\n\tconst { query, variables } = config;\n\tif (!query) return { data: undefined, errors: undefined };\n\n\tconst callTool = await getCallTool(adapterName);\n\tconst raw = await callTool({\n\t\ttoolName,\n\t\tparams: { query, variables: variables ?? {} },\n\t});\n\n\treturn (normalizeMcpResponse(raw) as GraphqlResult) ?? {};\n}\n\n/** Wraps a thrown Error into the graphql `{ data, errors[] }` envelope. */\nfunction toGraphqlErrorResult(error: unknown): GraphqlResult {\n\treturn { data: undefined, errors: [{ message: (error as Error).message }] };\n}\n\n/**\n * `runGraphqlQuery` wrapped in try/catch so thrown errors land on `errors[]`\n * instead of rejecting. Used by every graphql shape that routes errors\n * in-band (wire, mutation, imperative-read query/query-refreshable, legacy).\n */\nasync function runGraphqlQuerySafe(\n\tadapterName: string,\n\ttoolName: string,\n\tconfig: GraphqlConfig,\n): Promise<GraphqlResult> {\n\ttry {\n\t\treturn await runGraphqlQuery(adapterName, toolName, config);\n\t} catch (error) {\n\t\treturn toGraphqlErrorResult(error);\n\t}\n}\n\n/**\n * GraphQL wire adapter factory. Emits `{ data, errors, refresh }` to the wire\n * callback. Mirrors the `constructor(callback)` → `connect` / `disconnect` /\n * `update(config)` / `refresh()` contract used by the LWC wire service.\n * Thrown fetch errors are routed into `errors[0].message`.\n *\n * `_fetch` is gated on `_connected` so that the common wire lifecycle\n * (`constructor` → `update(config)` → `connect`) doesn't fire two requests:\n * the initial `update(config)` arrives before `connect()`, stores the config,\n * and waits. `connect()` does the one fetch; later `update(config)` while\n * connected re-fetches. This matches luvio's `LWCLuvioWireAdapter`, which\n * gates on the same flag to prevent duplicate endpoint calls.\n */\nexport function createGraphQLWireAdapter(name: string, cfg: GraphqlAdapterConfig) {\n\treturn class {\n\t\t_dataCallback: GraphqlWireCallback;\n\t\t_config: GraphqlConfig | undefined;\n\t\t_connected = false;\n\n\t\tconstructor(dataCallback: GraphqlWireCallback) {\n\t\t\tthis._dataCallback = dataCallback;\n\t\t}\n\n\t\tconnect() {\n\t\t\tthis._connected = true;\n\t\t\tvoid this._fetch();\n\t\t}\n\n\t\tdisconnect() {\n\t\t\tthis._connected = false;\n\t\t}\n\n\t\tupdate(config: GraphqlConfig | undefined) {\n\t\t\tthis._config = config;\n\n\t\t\tif (!this._connected || this._config === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvoid this._fetch();\n\t\t}\n\n\t\trefresh() {\n\t\t\treturn this._fetch();\n\t\t}\n\n\t\tasync _fetch() {\n\t\t\tthis._emit(await runGraphqlQuerySafe(name, cfg.toolName, this._config ?? {}));\n\t\t}\n\n\t\t_emit({ data, errors }: GraphqlResult) {\n\t\t\tthis._dataCallback({\n\t\t\t\tdata,\n\t\t\t\terrors: errors?.length ? errors : undefined,\n\t\t\t\trefresh: () => this.refresh(),\n\t\t\t});\n\t\t}\n\t};\n}\n\n/**\n * GraphQL mutation factory. Returns `async (config) => Promise<{ data, errors }>`.\n * Empty-query guard short-circuits with\n * `{ data: undefined, errors: [{ message: \"No query provided\" }] }`.\n * All other errors are routed in-band to the `errors[]` envelope — the\n * function never rejects.\n */\nexport function createGraphQLMutationAdapter(name: string, cfg: GraphqlAdapterConfig) {\n\treturn async (config: GraphqlConfig): Promise<GraphqlResult> => {\n\t\tif (!config?.query) return { data: undefined, errors: [{ message: \"No query provided\" }] };\n\t\treturn runGraphqlQuerySafe(name, cfg.toolName, config);\n\t};\n}\n\ntype GraphqlImperativeReadInvokerShape = \"query\" | \"query-refreshable\" | \"legacy\";\n\ninterface GraphqlImperativeReadAdapterConfig extends GraphqlAdapterConfig {\n\tinvokerShape: GraphqlImperativeReadInvokerShape;\n}\n\ntype GraphqlImperativeResult = GraphqlResult & {\n\tsubscribe?: (cb: (result: GraphqlResult) => void) => Unsubscribe;\n\trefresh?: () => Promise<void>;\n};\n\ntype LegacyGraphqlCallback = (result: GraphqlResult) => void;\n\n/**\n * Imperative GraphQL read factory — single entry point for all imperative\n * graphql read shapes, mirroring the LDS `createReadAdapter` pattern. The\n * `invokerShape` selects the return surface:\n *\n * - `query` — `async (config) => Promise<{ data, errors, subscribe }>`.\n * Mirrors on-platform `GraphQLImperativeBindingsService` without\n * `exposeRefresh`. Errors are routed in-band; the function never throws.\n * - `query-refreshable` — same as `query` plus `refresh()` that re-runs the\n * underlying MCP tool. Mirrors the same service with `exposeRefresh: true`.\n * - `legacy` — `{ invoke(config, context, callback),\n * subscribe(config, context, callback): Unsubscribe }`. The callback\n * always receives `{ data, errors }`; neither method throws. `context` is\n * accepted but ignored.\n *\n * In every shape `subscribe` is a deliberate no-op off-platform (no reactive\n * store); returned unsubscribes are idempotent.\n */\nexport function createGraphQLImperativeReadAdapter(\n\tname: string,\n\tcfg: GraphqlImperativeReadAdapterConfig,\n) {\n\tif (cfg.invokerShape === \"legacy\") {\n\t\tasync function run(\n\t\t\tconfig: GraphqlConfig | undefined,\n\t\t\tcallback: LegacyGraphqlCallback,\n\t\t): Promise<void> {\n\t\t\tif (!config?.query) {\n\t\t\t\tcallback({ data: undefined, errors: undefined });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await runGraphqlQuerySafe(name, cfg.toolName, config);\n\t\t\tcallback({\n\t\t\t\tdata: result.data,\n\t\t\t\terrors: result.errors?.length ? result.errors : undefined,\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tinvoke(\n\t\t\t\tconfig: GraphqlConfig | undefined,\n\t\t\t\t_context: unknown,\n\t\t\t\tcallback: LegacyGraphqlCallback,\n\t\t\t): void {\n\t\t\t\tvoid run(config, callback);\n\t\t\t},\n\t\t\tsubscribe(\n\t\t\t\tconfig: GraphqlConfig | undefined,\n\t\t\t\t_context: unknown,\n\t\t\t\tcallback: LegacyGraphqlCallback,\n\t\t\t): Unsubscribe {\n\t\t\t\tvoid run(config, callback);\n\t\t\t\treturn noopUnsubscribe;\n\t\t\t},\n\t\t};\n\t}\n\n\tif (cfg.invokerShape === \"query-refreshable\") {\n\t\t// Per-invocation subscriber set: each call to the returned function\n\t\t// gets its own adapter instance with an isolated subscriber list.\n\t\t// `refresh()` re-runs the MCP tool and broadcasts the fresh\n\t\t// `{ data, errors }` to every registered callback, which mirrors the\n\t\t// on-platform contract where `refresh` causes store updates that fan\n\t\t// out through the `subscribe` fan-in. Without this wiring, `refresh`\n\t\t// would re-run the query off-platform but nothing could observe the\n\t\t// new payload (no store, noop subscribe).\n\t\treturn async (config: GraphqlConfig): Promise<GraphqlImperativeResult> => {\n\t\t\tconst result = await runGraphqlQuerySafe(name, cfg.toolName, config);\n\t\t\tif (result.errors?.length) {\n\t\t\t\treturn { data: undefined, errors: result.errors };\n\t\t\t}\n\t\t\tconst subscribers = new Set<(result: GraphqlResult) => void>();\n\t\t\treturn {\n\t\t\t\tdata: result.data,\n\t\t\t\terrors: undefined,\n\t\t\t\tsubscribe: (cb) => {\n\t\t\t\t\tsubscribers.add(cb);\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tsubscribers.delete(cb);\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\trefresh: async () => {\n\t\t\t\t\tconst fresh = await runGraphqlQuerySafe(name, cfg.toolName, config);\n\t\t\t\t\tconst payload: GraphqlResult = {\n\t\t\t\t\t\tdata: fresh.data,\n\t\t\t\t\t\terrors: fresh.errors?.length ? fresh.errors : undefined,\n\t\t\t\t\t};\n\t\t\t\t\tsubscribers.forEach((cb) => cb(payload));\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\t}\n\n\t// `query` shape: no refresh → nothing can trigger a post-initial update\n\t// off-platform, so `subscribe` stays a noop. The on-platform contract\n\t// allows subscribe callbacks to fire from unrelated store writes; off-\n\t// platform there is no store, so the callback is correctly unreachable.\n\treturn async (config: GraphqlConfig): Promise<GraphqlImperativeResult> => {\n\t\tconst result = await runGraphqlQuerySafe(name, cfg.toolName, config);\n\t\tif (result.errors?.length) {\n\t\t\treturn { data: undefined, errors: result.errors };\n\t\t}\n\t\treturn {\n\t\t\tdata: result.data,\n\t\t\terrors: undefined,\n\t\t\tsubscribe: noopSubscribe,\n\t\t};\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,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 -23,8 +23,10 @@ The plugin supports two tiers of usage:
23
23
  | **Tier 1: Off-Platform Build** | Static bundle with mock data, labels, i18n | No |
24
24
  | **Tier 2: Live Org Connection** | Real GraphQL queries, live Salesforce data | Yes (via `sf` CLI) |
25
25
 
26
- Start with Tier 1. Add Tier 2 later if your components use `lightning/graphql` or
27
- need live data.
26
+ Start with Tier 1. Add Tier 2 later if your components need live org data via
27
+ `@salesforce/sdk-data` (`/services/*` calls). `lightning/graphql` dispatches
28
+ through MCP (`builtins.lds()`) in both tiers — route the `graphqlQuery` tool at
29
+ your MCP host rather than reaching for `lwcProxy()`.
28
30
 
29
31
  ---
30
32
 
@@ -268,8 +270,11 @@ npm run preview
268
270
 
269
271
  ## Tier 2: Live Org Connection (lwcProxy)
270
272
 
271
- If your components use `lightning/graphql` or need live Salesforce data, add
272
- `lwcProxy()` to connect to a real org during development.
273
+ If your components need live Salesforce data via `@salesforce/sdk-data` (e.g.
274
+ `/services/*` calls from `lightning/*` modules), add `lwcProxy()` to connect to
275
+ a real org during development. `lightning/graphql` itself routes through MCP
276
+ via `builtins.lds()` regardless of `lwcProxy` — point the `graphqlQuery` tool
277
+ at your org via your MCP host if you need live GraphQL.
273
278
 
274
279
  ### Prerequisites
275
280
 
@@ -284,8 +289,8 @@ npm install @salesforce/sdk-data @salesforce/ui-bundle
284
289
 
285
290
  ### Step 2: Update `vite.config.js`
286
291
 
287
- Add `lwcProxy()` before `lwcVitePlugin()` and add `builtins.lightningGraphql()`
288
- to providers:
292
+ Add `lwcProxy()` before `lwcVitePlugin()` and add `builtins.lds()` to providers
293
+ (this registers GraphQL plus the other LDS adapters by default):
289
294
 
290
295
  ```js
291
296
  import { defineConfig } from "vite";
@@ -311,7 +316,7 @@ export default defineConfig({
311
316
  builtins.client(),
312
317
  builtins.gate(),
313
318
  builtins.accessCheck(),
314
- builtins.lightningGraphql(),
319
+ builtins.lds(),
315
320
  ],
316
321
  }),
317
322
  viteSingleFile(),
@@ -352,9 +357,11 @@ npm run dev
352
357
  # Open http://localhost:5173
353
358
  ```
354
359
 
355
- Components using `@wire(graphql, ...)` will now execute real GraphQL queries
356
- against your connected org. The proxy intercepts `/services/*` calls inside
357
- the Vite dev server no separate proxy process needed.
360
+ `lwcProxy()` intercepts `/services/*` calls inside the Vite dev server — no
361
+ separate proxy process needed. This unlocks `lightning/*` modules that reach
362
+ Salesforce directly through `@salesforce/sdk-data`. `@wire(graphql, ...)` still
363
+ dispatches through MCP (`builtins.lds()` → `graphqlQuery` tool) rather than
364
+ the proxy; wire it through your MCP host if you want live GraphQL in dev.
358
365
 
359
366
  > **Note:** `lwcProxy()` works with `npm run dev` only. The production build
360
367
  > (`dist/index.html`) does not include the proxy — it's a static file. For
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/vite-plugin-lwc-ui-bundle",
3
- "version": "1.134.5",
3
+ "version": "1.135.0",
4
4
  "description": "Vite plugin for compiling LWC components into static bundles for off-platform and MCP use",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Salesforce",
@@ -34,10 +34,6 @@
34
34
  "types": "./dist/providers/lds/index.d.ts",
35
35
  "import": "./dist/providers/lds/index.js"
36
36
  },
37
- "./providers/lightning-graphql": {
38
- "types": "./dist/providers/lightning-graphql/index.d.ts",
39
- "import": "./dist/providers/lightning-graphql/index.js"
40
- },
41
37
  "./package.json": "./package.json"
42
38
  },
43
39
  "main": "./dist/index.js",
@@ -49,7 +45,7 @@
49
45
  "skills"
50
46
  ],
51
47
  "scripts": {
52
- "build": "vite build && vite build --mode runtime-lds && vite build --mode runtime-lightning-graphql",
48
+ "build": "vite build && vite build --mode runtime-lds",
53
49
  "clean": "rm -rf dist",
54
50
  "dev": "vite build --watch",
55
51
  "test": "vitest run",
@@ -79,7 +75,7 @@
79
75
  "@conduit-client/service-bindings-imperative": "3.19.3",
80
76
  "@conduit-client/service-bindings-lwc": "3.19.3",
81
77
  "@conduit-client/utils": "3.19.3",
82
- "@salesforce/sdk-chat": "^1.134.5",
78
+ "@salesforce/sdk-chat": "^1.135.0",
83
79
  "typescript": "^5.9.3",
84
80
  "vite": "^7.0.0",
85
81
  "vite-plugin-dts": "^4.5.4",
@@ -162,8 +162,9 @@ Report what you found — plainly, so the user can correct misdetections:
162
162
  > - 3 label imports: `c.appTitle`, `c.greeting`, `c.save`
163
163
  > - Uses `lightning-card` → needs lightning-base-components + the
164
164
  > gate/accessCheck/primitiveUtils providers
165
- > - Uses `lightning/graphql` → needs `builtins.lightningGraphql()` + a
166
- > graphql mock branch in `bootstrap.js`
165
+ > - Uses `lightning/graphql` → needs `builtins.lds()` (graphql specifiers
166
+ > are registered by default) + a `graphqlQuery` mock branch in
167
+ > `bootstrap.js`
167
168
  > - Uses `lightning/uiRecordApi` → needs `builtins.lds()` + a
168
169
  > `getRecordMcpTool` mock branch"
169
170
 
@@ -297,21 +298,30 @@ See "Step 2" in the consumer guide for the template.
297
298
 
298
299
  **Import providers from the plugin, do not reimplement them.** All
299
300
  provider names (`label`, `i18n`, `client`, `gate`, `accessCheck`,
300
- `primitiveUtils`, `lightningGraphql`, `lds`) must come from the `builtins`
301
- export of `@salesforce/vite-plugin-lwc-ui-bundle`. Calling them invokes
302
- the plugin's real runtime — which includes
303
- `lightning/graphql` wire adapter, `normalizeMcpResponse` envelope
304
- parsing, LDS wire adapter, and more. Hand-rolling any of them bypasses
305
- all that and breaks host integration (see
306
- `references/known-pitfalls.md#3`).
301
+ `primitiveUtils`, `lds`) must come from the `builtins` export of
302
+ `@salesforce/vite-plugin-lwc-ui-bundle`. Calling them invokes the
303
+ plugin's real runtime — which includes the `lightning/graphql` wire
304
+ adapter, `normalizeMcpResponse` envelope parsing, LDS wire/read/mutation
305
+ adapters, and more. Hand-rolling any of them bypasses all that and
306
+ breaks host integration (see `references/known-pitfalls.md#3`).
307
307
 
308
308
  ```js
309
309
  import lwcVitePlugin, { builtins } from "@salesforce/vite-plugin-lwc-ui-bundle";
310
310
 
311
311
  // inside plugins -> lwcVitePlugin({ providers: [...] })
312
- builtins.lightningGraphql(), // default tool name: "graphqlQuery"
313
- builtins.lightningGraphql({ toolName: "yourCustomTool" }), // override
314
- builtins.lds(), // default registry
312
+ builtins.lds(), // default registry:
313
+ // lightning/uiRecordApi, uiObjectInfoApi,
314
+ // and lightning/graphql (tool: "graphqlQuery")
315
+
316
+ // Add to / override the default registry. The argument is deep-merged onto
317
+ // the defaults per specifier, so you only declare what you are changing —
318
+ // unmentioned entries (e.g. `getRecord`, `createRecord`) are preserved.
319
+ builtins.lds({
320
+ "lightning/graphql": {
321
+ graphql: { type: "graphql-wire", toolName: "myGraphqlTool" },
322
+ executeMutation: { type: "graphql-mutation", toolName: "myGraphqlTool" },
323
+ },
324
+ }),
315
325
  ```
316
326
 
317
327
  Adapt based on earlier findings:
@@ -319,21 +329,21 @@ Adapt based on earlier findings:
319
329
  - Set `dirs` for the detected project structure (SFDX vs namespaced).
320
330
  - Populate `builtins.label({...})` with values from Step 6.
321
331
  - Include `builtins.primitiveUtils()` if using `lightning-base-components`.
322
- - Include `builtins.lightningGraphql()` only if GraphQL was detected.
323
- - Include `builtins.lds()` if any component uses `lightning/uiRecordApi`.
332
+ - Include `builtins.lds()` if any component uses `lightning/uiRecordApi`,
333
+ `lightning/uiObjectInfoApi`, or `lightning/graphql`.
324
334
  - Include `viteSingleFile()` — without it, `vite build` emits multi-file
325
335
  output and the MCP host can't inline the bundle. See
326
- `known-pitfalls.md#7` for the full config block.
336
+ `known-pitfalls.md#6` for the full config block.
327
337
  - Remove `npm: ["lightning-base-components"]` if no base components used.
328
338
 
329
339
  **Tool names** (canonical list — referenced elsewhere):
330
340
 
331
341
  - `builtins.lds()` default for `lightning/uiRecordApi.getRecord`:
332
342
  `getRecordMcpTool`. Override via
333
- `builtins.lds({ "lightning/uiRecordApi": { getRecord: { toolName: "..." } } })`.
334
- - `builtins.lightningGraphql()` default: `graphqlQuery` (**not**
335
- `"graphql"` or `"lightningGraphql"`). Override via
336
- `builtins.lightningGraphql({ toolName: "..." })`.
343
+ `builtins.lds({ "lightning/uiRecordApi": { getRecord: { type: "wire", toolName: "..." } } })`.
344
+ - `builtins.lds()` default for `lightning/graphql` (both `graphql` wire
345
+ and `executeMutation`): `graphqlQuery`. Override by registering the
346
+ specifier explicitly see example above.
337
347
 
338
348
  Whatever tool names you settle on here **must match** the branches in
339
349
  `bootstrap.js` mocks (Step 8).
@@ -393,15 +403,15 @@ open dist/index.html
393
403
  ```
394
404
 
395
405
  A correctly built `dist/index.html` is typically 100 KB+. A 1-2 KB file
396
- is the un-inlined stub (see `known-pitfalls.md#7`).
406
+ is the un-inlined stub (see `known-pitfalls.md#6`).
397
407
 
398
408
  If the build fails, diagnose via `references/known-pitfalls.md`. The most
399
409
  frequent issues have symptoms that map directly to specific entries:
400
410
 
401
411
  - "Cannot find native binding" inside rolldown → pitfall #1 (Node)
402
412
  - "No matching version found for \<pkg\>" → pitfall #2 (stale dep pins)
403
- - Missing `isOpen` / missing `lightning/button` → pitfalls #9 / #7
404
- - `force/someModule` not resolved → pitfall #10
413
+ - Missing `isOpen` / missing `lightning/button` → pitfalls #8 / #6
414
+ - `force/someModule` not resolved → pitfall #9
405
415
  - Component renders but unstyled → missing SLDS CSS import in
406
416
  `bootstrap.js`
407
417
 
@@ -424,8 +434,8 @@ Open `http://localhost:5173` and confirm:
424
434
 
425
435
  If something renders wrong, check `references/known-pitfalls.md`. The
426
436
  most common dev-time issues are graphql wire adapters returning empty
427
- data (pitfalls #3, #4, #5) and mapper returning `null` on Avro-wrapped
428
- payloads (#6).
437
+ data (pitfalls #3, #4) and mapper returning `null` on Avro-wrapped
438
+ payloads (#5).
429
439
 
430
440
  The same compiled `dist/index.html` runs in ChatGPT — the guard in
431
441
  `bootstrap.js` ensures local mocks are skipped when the host provides