@elementor/editor-mcp 4.1.0-788 → 4.1.0-790
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +55 -10
- package/dist/index.d.ts +55 -10
- package/dist/index.js +301 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +295 -88
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/adapters/angie-adapter.ts +60 -0
- package/src/adapters/types.ts +48 -0
- package/src/adapters/web-mcp-adapter.ts +143 -0
- package/src/index.ts +2 -1
- package/src/init.ts +18 -22
- package/src/mcp-registry.ts +92 -57
- package/src/test-utils/mock-mcp-registry.ts +0 -3
- package/src/utils/get-active-chat-info.ts +19 -0
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils/get-sdk.ts","../src/init.ts","../src/mcp-registry.ts","../src/angie-annotations.ts","../src/test-utils/mock-mcp-registry.ts","../src/utils/is-angie-available.ts","../src/utils/is-angie-sidebar-open.ts","../src/sampler.ts","../src/utils/prompt-builder.ts","../src/utils/send-prompt-to-angie.ts","../src/utils/redirect-to-installation.ts","../src/utils/redirect-to-app-admin.ts","../src/utils/install-angie-plugin.ts"],"sourcesContent":["import { getSDK } from './utils/get-sdk';\nexport { getAngieIframe, MessageEventType as AngieMessageEvenetType } from './utils/get-sdk';\n\nexport {\n\tMcpServer,\n\tResourceTemplate,\n\ttype RegisteredResource,\n\ttype ToolCallback,\n} from '@modelcontextprotocol/sdk/server/mcp.js';\nexport { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';\nexport { init } from './init';\nexport { isAngieAvailable } from './utils/is-angie-available';\nexport { isAngieSidebarOpen } from './utils/is-angie-sidebar-open';\nexport * from './mcp-registry';\nexport { createSampler } from './sampler';\nexport { toolPrompts } from './utils/prompt-builder';\nexport { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';\nexport { sendPromptToAngie } from './utils/send-prompt-to-angie';\nexport { redirectToInstallation } from './utils/redirect-to-installation';\nexport { redirectToAppAdmin } from './utils/redirect-to-app-admin';\nexport { installAngiePlugin, type InstallAngieResult } from './utils/install-angie-plugin';\nexport const getAngieSdk = () => getSDK();\n","import { AngieMcpSdk } from '@elementor-external/angie-sdk';\nexport { getAngieIframe, MessageEventType } from '@elementor-external/angie-sdk';\n\nlet sdk: AngieMcpSdk;\n\nexport const getSDK = () => {\n\t// @ts-ignore - QUnit fails this\n\tconst isMCPDisabled = !! ( globalThis as Record< string, unknown > ).__ELEMENTOR_MCP_DISABLED__;\n\tif ( isMCPDisabled ) {\n\t\treturn {} as unknown as AngieMcpSdk;\n\t}\n\tif ( ! sdk ) {\n\t\tsdk = new AngieMcpSdk();\n\t}\n\treturn sdk;\n};\n","import { isExperimentActive } from '@elementor/editor-v1-adapters';\n\nimport { activateMcpRegistration } from './mcp-registry';\nimport { getSDK } from './utils/get-sdk';\nimport { isAngieAvailable } from './utils/is-angie-available';\n\nexport function init() {\n\tif ( isExperimentActive( 'editor_mcp' ) && isAngieAvailable() ) {\n\t\treturn getSDK().waitForReady();\n\t}\n\treturn Promise.resolve();\n}\n\nexport function startMCPServer() {\n\tif ( isExperimentActive( 'editor_mcp' ) && isAngieAvailable() ) {\n\t\tconst sdk = getSDK();\n\t\tsdk.waitForReady().then( () => activateMcpRegistration( sdk ) );\n\t}\n\treturn Promise.resolve();\n}\n\ndocument.addEventListener(\n\t'DOMContentLoaded',\n\t() => {\n\t\tstartMCPServer();\n\t},\n\t{\n\t\tonce: true,\n\t}\n);\n","import { z, type z3 } from '@elementor/schema';\nimport { type AngieMcpSdk } from '@elementor-external/angie-sdk';\nimport { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\nimport {\n\tANGIE_MODEL_PREFERENCES,\n\tANGIE_REQUIRED_RESOURCES,\n\ttype AngieModelPreferences,\n\tcreateDefaultModelPreferences,\n} from './angie-annotations';\nimport { mockMcpRegistry } from './test-utils/mock-mcp-registry';\nimport { getSDK } from './utils/get-sdk';\n\ntype ZodRawShape = z3.ZodRawShape;\n\nconst mcpRegistry: { [ namespace: string ]: McpServer } = {};\nconst mcpDescriptions: { [ namespace: string ]: string } = {};\n// @ts-ignore - QUnit fails this\nconst isMcpRegistrationActivated = false || typeof globalThis.jest !== 'undefined';\n\nexport const registerMcp = ( mcp: McpServer, name: string ) => {\n\tconst mcpName = isAlphabet( name );\n\tmcpRegistry[ mcpName ] = mcp;\n};\n\nexport async function activateMcpRegistration( sdk: AngieMcpSdk, entries = Object.entries( mcpRegistry ), retry = 3 ) {\n\tif ( retry === 0 ) {\n\t\t/* eslint-disable-next-line no-console */\n\t\tconsole.error( 'Failed to register MCP after 3 retries. failed entries: ', entries );\n\t\treturn;\n\t}\n\tif ( entries.length === 0 ) {\n\t\treturn;\n\t}\n\tconst failed = [];\n\tfor await ( const entry of entries ) {\n\t\tconst [ key, mcpServer ] = entry;\n\t\ttry {\n\t\t\tawait sdk.registerLocalServer( {\n\t\t\t\ttitle: toMCPTitle( key ),\n\t\t\t\tname: `editor-${ key }`,\n\t\t\t\tserver: mcpServer,\n\t\t\t\tversion: '1.0.0',\n\t\t\t\tdescription: mcpDescriptions[ key ] || key,\n\t\t\t} );\n\t\t} catch {\n\t\t\tfailed.push( entry );\n\t\t}\n\t}\n\tif ( failed.length > 0 ) {\n\t\treturn activateMcpRegistration( sdk, failed, retry - 1 );\n\t}\n}\n\nconst isAlphabet = ( str: string ): string | never => {\n\tconst passes = !! str && /^[a-z_]+$/.test( str );\n\tif ( ! passes ) {\n\t\tthrow new Error( 'Not alphabet' );\n\t}\n\treturn str;\n};\n\nexport const toMCPTitle = ( namespace: string ): string => {\n\tconst capitalized = namespace.charAt( 0 ).toUpperCase() + namespace.slice( 1 );\n\treturn `Editor ${ capitalized }`;\n};\n\n/**\n *\n * @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.\n * @param options\n * @param options.instructions\n */\nexport const getMCPByDomain = ( namespace: string, options?: { instructions?: string } ): MCPRegistryEntry => {\n\tconst mcpName = `editor-${ isAlphabet( namespace ) }`;\n\tconst title = toMCPTitle( namespace );\n\t// @ts-ignore - QUnit fails this\n\tif ( typeof globalThis.jest !== 'undefined' ) {\n\t\treturn mockMcpRegistry();\n\t}\n\tif ( ! mcpRegistry[ namespace ] ) {\n\t\tmcpRegistry[ namespace ] = new McpServer(\n\t\t\t{\n\t\t\t\tname: mcpName,\n\t\t\t\ttitle,\n\t\t\t\tversion: '1.0.0',\n\t\t\t},\n\t\t\t{\n\t\t\t\tinstructions: options?.instructions,\n\t\t\t}\n\t\t);\n\t}\n\tconst mcpServer = mcpRegistry[ namespace ];\n\tconst { addTool } = createToolRegistry( mcpServer );\n\treturn {\n\t\twaitForReady: () => getSDK().waitForReady(),\n\t\t// @ts-expect-error: TS is unable to infer the type here\n\t\tresource: async ( ...args: Parameters< McpServer[ 'registerResource' ] > ) => {\n\t\t\tawait getSDK().waitForReady();\n\t\t\treturn mcpServer.registerResource( ...args );\n\t\t},\n\t\tsendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {\n\t\t\treturn getSDK()\n\t\t\t\t.waitForReady()\n\t\t\t\t.then( () => mcpServer.server.sendResourceUpdated( ...args ) )\n\t\t\t\t.catch( ( error: Error ) => {\n\t\t\t\t\tif ( error?.message?.includes( 'Not connected' ) ) {\n\t\t\t\t\t\treturn; // Expected when no MCP client is connected yet\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t} );\n\t\t},\n\t\tmcpServer,\n\t\taddTool,\n\t\tsetMCPDescription: ( description: string ) => {\n\t\t\tmcpDescriptions[ namespace ] = description;\n\t\t},\n\t\tgetActiveChatInfo: () => {\n\t\t\tconst info = localStorage.getItem( 'angie_active_chat_id' );\n\t\t\tif ( ! info ) {\n\t\t\t\treturn {\n\t\t\t\t\texpiresAt: 0,\n\t\t\t\t\tsessionId: '',\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst rawData = JSON.parse( info );\n\t\t\treturn {\n\t\t\t\texpiresAt: rawData.expiresAt as number,\n\t\t\t\tsessionId: rawData.sessionId as string,\n\t\t\t};\n\t\t},\n\t};\n};\n\nexport interface MCPRegistryEntry {\n\taddTool: < T extends undefined | z.ZodRawShape = undefined, O extends undefined | z.ZodRawShape = undefined >(\n\t\topts: ToolRegistrationOptions< T, O >\n\t) => void;\n\tsetMCPDescription: ( description: string ) => void;\n\tgetActiveChatInfo: () => { sessionId: string; expiresAt: number };\n\tsendResourceUpdated: McpServer[ 'server' ][ 'sendResourceUpdated' ];\n\tresource: McpServer[ 'registerResource' ];\n\tmcpServer: McpServer;\n\twaitForReady: () => Promise< void >;\n}\n\ntype ResourceList = {\n\turi: string;\n\tdescription: string;\n}[];\n\ntype ToolRegistrationOptions<\n\tInputArgs extends undefined | z.ZodRawShape = undefined,\n\tOutputSchema extends undefined | z.ZodRawShape = undefined,\n\tExpectedOutput = OutputSchema extends z.ZodRawShape ? z.objectOutputType< OutputSchema, z.ZodTypeAny > : string,\n> = {\n\tname: string;\n\tdescription: string;\n\tschema?: InputArgs;\n\t/**\n\t * Auto added fields:\n\t * @param errors z.string().optional().describe('Error message if the tool failed')\n\t */\n\toutputSchema?: OutputSchema;\n\thandler: InputArgs extends z.ZodRawShape\n\t\t? (\n\t\t\t\targs: z.objectOutputType< InputArgs, z.ZodTypeAny >,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >\n\t\t: (\n\t\t\t\targs: unknown,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >;\n\tisDestructive?: boolean;\n\trequiredResources?: ResourceList;\n\tmodelPreferences?: AngieModelPreferences;\n};\n\nfunction createToolRegistry( server: McpServer ) {\n\tfunction addTool<\n\t\tT extends undefined | z.ZodRawShape = undefined,\n\t\tO extends undefined | z.ZodRawShape = undefined,\n\t>( opts: ToolRegistrationOptions< T, O > ) {\n\t\tconst outputSchema = opts.outputSchema as ZodRawShape | undefined;\n\t\tif ( outputSchema ) {\n\t\t\tObject.assign(\n\t\t\t\toutputSchema,\n\t\t\t\toutputSchema.errors ?? {\n\t\t\t\t\terrors: z.string().optional().describe( 'Error message if the tool failed' ),\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t\t// @ts-ignore: TS is unable to infer the type here\n\t\tconst inputSchema: ZodRawShape = opts.schema ? opts.schema : {};\n\t\tconst toolCallback: ToolCallback< ZodRawShape > = async function ( args, extra ) {\n\t\t\ttry {\n\t\t\t\tconst invocationResult = await opts.handler( opts.schema ? args : {}, extra );\n\t\t\t\treturn {\n\t\t\t\t\t// structuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\t\ttypeof invocationResult === 'string'\n\t\t\t\t\t\t\t\t\t? invocationResult\n\t\t\t\t\t\t\t\t\t: JSON.stringify( invocationResult ),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t} catch ( error ) {\n\t\t\t\treturn {\n\t\t\t\t\tisError: true,\n\t\t\t\t\tstructuredContent: {\n\t\t\t\t\t\terrors: ( error as Error ).message || 'Unknown error',\n\t\t\t\t\t},\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: ( error as Error ).message || 'Unknown error',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\t\tconst annotations: Record< string, unknown > = {\n\t\t\tdestructiveHint: opts.isDestructive,\n\t\t\treadOnlyHint: opts.isDestructive ? false : undefined,\n\t\t\ttitle: opts.name,\n\t\t};\n\t\tconst angieAnnotations = {\n\t\t\t[ ANGIE_MODEL_PREFERENCES ]: opts.modelPreferences ?? createDefaultModelPreferences(),\n\t\t\t[ ANGIE_REQUIRED_RESOURCES ]: opts.requiredResources ?? undefined,\n\t\t};\n\t\tserver.registerTool(\n\t\t\topts.name,\n\t\t\t{\n\t\t\t\tdescription: opts.description,\n\t\t\t\tinputSchema,\n\t\t\t\t// TODO: Uncomment this when the outputSchema is stable\n\t\t\t\t// outputSchema,\n\t\t\t\ttitle: opts.name,\n\t\t\t\tannotations,\n\t\t\t\t_meta: angieAnnotations,\n\t\t\t},\n\t\t\ttoolCallback\n\t\t);\n\t\tif ( isMcpRegistrationActivated ) {\n\t\t\tserver.sendToolListChanged();\n\t\t}\n\t}\n\treturn {\n\t\taddTool,\n\t};\n}\n","export const ANGIE_MODEL_PREFERENCES = 'angie/modelPreferences' as const;\nexport const ANGIE_REQUIRED_RESOURCES = 'angie/requiredResources' as const;\n\nexport interface AngieModelPreferences {\n\thints?: Array< { name: string } >;\n\tcostPriority?: number; // 0-1 (future use)\n\tspeedPriority?: number; // 0-1 (future use)\n\tintelligencePriority?: number; // 0-1 (future use)\n}\n\nexport function createDefaultModelPreferences(): AngieModelPreferences {\n\treturn {\n\t\thints: [ { name: 'claude-sonnet-4-5' } ],\n\t\tintelligencePriority: 0.8,\n\t\tspeedPriority: 0.7,\n\t};\n}\n","import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n\nimport { type MCPRegistryEntry } from '../mcp-registry';\n\nconst mock = new Proxy(\n\t{},\n\t{\n\t\tget: () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\tfunction mockedFn( ..._: unknown[] ) {}\n\t\t\treturn mockedFn;\n\t\t},\n\t}\n);\n\nexport const mockMcpRegistry = (): MCPRegistryEntry => {\n\treturn {\n\t\t// @ts-ignore\n\t\tresource: async () => {},\n\t\t// @ts-ignore\n\t\tsendResourceUpdated: () => {},\n\t\taddTool: () => {},\n\t\tsetMCPDescription: () => {},\n\t\tgetActiveChatInfo() {\n\t\t\treturn { sessionId: 'mock-session-id', expiresAt: Date.now() + 3600000 };\n\t\t},\n\t\tmcpServer: mock as McpServer,\n\t};\n};\n","import { getAngieIframe } from '@elementor-external/angie-sdk';\n\nexport const isAngieAvailable = (): boolean => {\n\treturn !! getAngieIframe();\n};\n","import { ANGIE_SIDEBAR_STATE_OPEN, getAngieSidebarSavedState } from '@elementor-external/angie-sdk';\n\nexport const isAngieSidebarOpen = (): boolean => {\n\treturn getAngieSidebarSavedState() === ANGIE_SIDEBAR_STATE_OPEN;\n};\n","import { type z } from '@elementor/schema';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { SamplingMessageSchema, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\ntype Server = RequestHandlerExtra< ServerRequest, ServerNotification >;\ntype Opts = {\n\tmaxTokens?: number;\n\tmodelPreferences?: string;\n\tmodel?: string;\n};\n\nconst DEFAULT_OPTS: Opts = {\n\tmaxTokens: 10000,\n\tmodelPreferences: 'openai',\n\tmodel: 'gpt-4o',\n};\n\ntype SamplingOpts = {\n\tsystemPrompt?: string;\n\tstructuredOutput?: z.ZodTypeAny;\n\tmessages: { role: 'user' | 'assistant'; content: { type: 'text'; text: string } }[];\n\trequestParams?: { [ key: string ]: string };\n};\n\nconst DEFAULT_STRUCTURED_OUTPUT = {\n\ttype: 'object',\n\tproperties: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tdescription: 'Result',\n\t\t},\n\t},\n\trequired: [ 'content' ],\n\tadditionalProperties: false,\n};\n\nexport const createSampler = ( server: Server, opts: Opts = DEFAULT_OPTS ) => {\n\tconst { maxTokens = 1000, modelPreferences = 'openai', model = 'gpt-4o' } = opts;\n\tconst exec = async ( payload: SamplingOpts ) => {\n\t\tconst systemPromptObject = { ...( payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} ) };\n\t\tconst requestParams = payload.requestParams || {};\n\t\tconst result = await server.sendRequest(\n\t\t\t{\n\t\t\t\tmethod: 'sampling/createMessage',\n\t\t\t\tparams: {\n\t\t\t\t\t...requestParams,\n\t\t\t\t\tmaxTokens,\n\t\t\t\t\tmodelPreferences: {\n\t\t\t\t\t\thints: [ { name: modelPreferences } ],\n\t\t\t\t\t},\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t...systemPromptObject,\n\t\t\t\t\t\t...{ structured_output: payload.structuredOutput || DEFAULT_STRUCTURED_OUTPUT },\n\t\t\t\t\t},\n\t\t\t\t\tmessages: payload.messages,\n\t\t\t\t},\n\t\t\t\t// ...systemPromptObject,\n\t\t\t},\n\t\t\tSamplingMessageSchema\n\t\t);\n\t\treturn result.content;\n\t};\n\treturn exec;\n};\n","class ToolPrompts {\n\tpublic _description = '';\n\tpublic _parameters: Record< string, string > = {};\n\tpublic _examples: string[] = [];\n\tpublic _furtherInstructions: string[] = [];\n\n\tconstructor( public name: string ) {}\n\n\tdescription(): string;\n\tdescription( desc: string ): this;\n\tdescription( desc?: string | undefined ) {\n\t\tif ( typeof desc === 'undefined' ) {\n\t\t\treturn this._description;\n\t\t}\n\t\tthis._description = desc;\n\t\treturn this;\n\t}\n\n\tparameter( key: string ): string;\n\tparameter( key: string, description: string ): this;\n\tparameter( key: string, description?: string ) {\n\t\tif ( typeof description === 'undefined' ) {\n\t\t\treturn this._parameters[ key ];\n\t\t}\n\t\tthis._parameters[ key ] = `**${ key }**:\\n${ description }`;\n\t\treturn this;\n\t}\n\n\tinstruction( instruction: string ): this {\n\t\tthis._furtherInstructions.push( instruction );\n\t\treturn this;\n\t}\n\n\texample( example: string ): this {\n\t\tthis._examples.push( example );\n\t\treturn this;\n\t}\n\n\tpublic get examples() {\n\t\treturn this._examples.join( '\\n\\n' );\n\t}\n\n\tprompt(): string {\n\t\treturn `# ${ this.name }\n# Description\n${ this._description }\n\n${ this._parameters.length ? '# Parameters' : '' }\n${ Object.values( this._parameters ).join( '\\n\\n' ) }\n\n${ this._examples.length ? '# Examples' : '' }\n${ this.examples }\n\n${ this._furtherInstructions.length ? '# Further Instructions' : '' }\n${ this._furtherInstructions.join( '\\n\\n' ) }\n`.trim();\n\t}\n}\n\nexport const toolPrompts = ( name: string ) => {\n\treturn new ToolPrompts( name );\n};\n","import { getAngieIframe, toggleAngieSidebar } from '@elementor-external/angie-sdk';\n\nexport const sendPromptToAngie = ( prompt?: string ) => {\n\tconst angieSidebar = getAngieIframe();\n\n\tif ( ! angieSidebar ) {\n\t\treturn;\n\t}\n\n\ttoggleAngieSidebar( angieSidebar, true );\n\n\tif ( ! prompt ) {\n\t\treturn;\n\t}\n\n\twindow.location.hash = `angie-prompt=${ encodeURIComponent( prompt ) }`;\n};\n","import { setReferrerRedirect } from '@elementor-external/angie-sdk';\n\nconst ANGIE_INSTALL_URL = '/wp-admin/plugin-install.php?s=angie&tab=search&type=term';\n\nexport const redirectToInstallation = ( prompt: string ) => {\n\tconst success = setReferrerRedirect( window.location.href, prompt );\n\n\tif ( ! success ) {\n\t\treturn;\n\t}\n\n\twindow.location.href = ANGIE_INSTALL_URL;\n};\n","import { setReferrerRedirect } from '@elementor-external/angie-sdk';\n\nconst ANGIE_APP_URL = '/wp-admin/admin.php?page=angie-app';\n\nexport const redirectToAppAdmin = ( prompt: string ) => {\n\tconst success = setReferrerRedirect( window.location.href, prompt );\n\n\tif ( ! success ) {\n\t\treturn;\n\t}\n\n\twindow.location.href = ANGIE_APP_URL;\n};\n","import apiFetch from '@wordpress/api-fetch';\n\ntype PluginResponse = {\n\tplugin: string;\n\tstatus: 'active' | 'inactive';\n\tname: string;\n};\n\ntype PluginErrorResponse = {\n\tcode: string;\n\tmessage: string;\n};\n\nexport type InstallAngieResult = { success: true } | { success: false; error: string; code?: string };\n\nconst ANGIE_SLUG = 'angie';\n\nconst isPluginErrorResponse = ( response: unknown ): response is PluginErrorResponse => {\n\treturn typeof response === 'object' && response !== null && 'code' in response && 'message' in response;\n};\n\nconst activatePlugin = async ( pluginPath: string ): Promise< PluginResponse > => {\n\treturn apiFetch< PluginResponse >( {\n\t\tpath: `/wp/v2/plugins/${ pluginPath }`,\n\t\tmethod: 'POST',\n\t\tdata: { status: 'active' },\n\t} );\n};\n\nconst installPlugin = async (): Promise< PluginResponse > => {\n\ttry {\n\t\treturn await apiFetch< PluginResponse >( {\n\t\t\tpath: '/wp/v2/plugins',\n\t\t\tmethod: 'POST',\n\t\t\tdata: {\n\t\t\t\tslug: ANGIE_SLUG,\n\t\t\t\tstatus: 'active',\n\t\t\t},\n\t\t} );\n\t} catch ( error: unknown ) {\n\t\tif ( isPluginErrorResponse( error ) && error.code === 'folder_exists' ) {\n\t\t\treturn activatePlugin( `${ ANGIE_SLUG }/${ ANGIE_SLUG }` );\n\t\t}\n\n\t\tthrow error;\n\t}\n};\n\nexport const installAngiePlugin = async (): Promise< InstallAngieResult > => {\n\ttry {\n\t\tawait installPlugin();\n\n\t\treturn { success: true };\n\t} catch ( error: unknown ) {\n\t\tif ( isPluginErrorResponse( error ) ) {\n\t\t\treturn { success: false, error: error.message, code: error.code };\n\t\t}\n\n\t\treturn { success: false, error: 'Unknown error occurred' };\n\t}\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAA4B;AAC5B,IAAAA,oBAAiD;AAEjD,IAAI;AAEG,IAAM,SAAS,MAAM;AAE3B,QAAM,gBAAgB,CAAC,CAAI,WAA0C;AACrE,MAAK,eAAgB;AACpB,WAAO,CAAC;AAAA,EACT;AACA,MAAK,CAAE,KAAM;AACZ,UAAM,IAAI,6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IAAK,UAAW,EAAG;AAAA,IAC1D;AAEA,UAAM;AAAA,EACP;AACD;AAEO,IAAM,qBAAqB,YAA2C;AAC5E,MAAI;AACH,UAAM,cAAc;AAEpB,WAAO,EAAE,SAAS,KAAK;AAAA,EACxB,SAAU,OAAiB;AAC1B,QAAK,sBAAuB,KAAM,GAAI;AACrC,aAAO,EAAE,SAAS,OAAO,OAAO,MAAM,SAAS,MAAM,MAAM,KAAK;AAAA,IACjE;AAEA,WAAO,EAAE,SAAS,OAAO,OAAO,yBAAyB;AAAA,EAC1D;AACD;;;AbvCO,IAAM,cAAc,MAAM,OAAO;","names":["import_angie_sdk","import_mcp","import_types","sdk","import_angie_sdk","sdk","import_angie_sdk","import_angie_sdk","import_angie_sdk","import_angie_sdk","apiFetch"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils/get-sdk.ts","../src/utils/is-angie-available.ts","../src/utils/is-angie-sidebar-open.ts","../src/mcp-registry.ts","../src/angie-annotations.ts","../src/test-utils/mock-mcp-registry.ts","../src/sampler.ts","../src/utils/prompt-builder.ts","../src/utils/get-active-chat-info.ts","../src/utils/send-prompt-to-angie.ts","../src/utils/redirect-to-installation.ts","../src/utils/redirect-to-app-admin.ts","../src/utils/install-angie-plugin.ts","../src/adapters/angie-adapter.ts","../src/adapters/web-mcp-adapter.ts","../src/init.ts"],"sourcesContent":["import { getSDK } from './utils/get-sdk';\nexport { getAngieIframe, MessageEventType as AngieMessageEvenetType } from './utils/get-sdk';\n\nexport {\n\tMcpServer,\n\tResourceTemplate,\n\ttype RegisteredResource,\n\ttype ToolCallback,\n} from '@modelcontextprotocol/sdk/server/mcp.js';\nexport { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';\nexport { isAngieAvailable } from './utils/is-angie-available';\nexport { isAngieSidebarOpen } from './utils/is-angie-sidebar-open';\nexport * from './mcp-registry';\nexport { createSampler } from './sampler';\nexport { toolPrompts } from './utils/prompt-builder';\nexport { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';\nexport { getActiveChatInfo, type ActiveChatInfo } from './utils/get-active-chat-info';\nexport { sendPromptToAngie } from './utils/send-prompt-to-angie';\nexport { redirectToInstallation } from './utils/redirect-to-installation';\nexport { redirectToAppAdmin } from './utils/redirect-to-app-admin';\nexport { installAngiePlugin, type InstallAngieResult } from './utils/install-angie-plugin';\nexport const getAngieSdk = () => getSDK();\nexport * from './init';\n","import { AngieMcpSdk } from '@elementor-external/angie-sdk';\nexport { getAngieIframe, MessageEventType } from '@elementor-external/angie-sdk';\n\nlet sdk: AngieMcpSdk;\n\nexport const getSDK = () => {\n\t// @ts-ignore - QUnit fails this\n\tconst isMCPDisabled = !! ( globalThis as Record< string, unknown > ).__ELEMENTOR_MCP_DISABLED__;\n\tif ( isMCPDisabled ) {\n\t\treturn {} as unknown as AngieMcpSdk;\n\t}\n\tif ( ! sdk ) {\n\t\tsdk = new AngieMcpSdk();\n\t}\n\treturn sdk;\n};\n","import { getAngieIframe } from '@elementor-external/angie-sdk';\n\nexport const isAngieAvailable = (): boolean => {\n\treturn !! getAngieIframe();\n};\n","import { ANGIE_SIDEBAR_STATE_OPEN, getAngieSidebarSavedState } from '@elementor-external/angie-sdk';\n\nexport const isAngieSidebarOpen = (): boolean => {\n\treturn getAngieSidebarSavedState() === ANGIE_SIDEBAR_STATE_OPEN;\n};\n","import { z, type z3 } from '@elementor/schema';\nimport { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { UriTemplate } from '@modelcontextprotocol/sdk/shared/uriTemplate.js';\nimport { type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\nimport { type IMcpRegistrationAdapter, type McpResourceHandler, type McpResourceUriOrTemplate } from './adapters/types';\nimport {\n\tANGIE_MODEL_PREFERENCES,\n\tANGIE_REQUIRED_RESOURCES,\n\ttype AngieModelPreferences,\n\tcreateDefaultModelPreferences,\n} from './angie-annotations';\nimport { mockMcpRegistry } from './test-utils/mock-mcp-registry';\n\ntype ZodRawShape = z3.ZodRawShape;\n\nconst mcpRegistry: { [ namespace: string ]: McpServer } = {};\nconst mcpDescriptions: { [ namespace: string ]: string } = {};\n// @ts-ignore - QUnit fails this\nconst isMcpRegistrationActivated = false || typeof globalThis.jest !== 'undefined';\n\nconst registrationAdapters: IMcpRegistrationAdapter[] = [];\nconst bufferedTools: Parameters< IMcpRegistrationAdapter[ 'onToolRegistered' ] >[] = [];\nconst bufferedResources: Parameters< IMcpRegistrationAdapter[ 'onResourceRegistered' ] >[] = [];\n\nlet resolveReady!: () => void;\nconst readyPromise = new Promise< void >( ( resolve ) => {\n\tresolveReady = resolve;\n} );\n\nexport const registerMcpAdapter = ( adapter: IMcpRegistrationAdapter ): void => {\n\tregistrationAdapters.push( adapter );\n\tfor ( const tool of bufferedTools ) {\n\t\ttry {\n\t\t\tadapter.onToolRegistered( tool[ 0 ], tool[ 1 ] );\n\t\t} catch {\n\t\t\t// exit quietly\n\t\t}\n\t}\n\tfor ( const resource of bufferedResources ) {\n\t\ttry {\n\t\t\tadapter.onResourceRegistered( ...resource );\n\t\t} catch {\n\t\t\t// exit quietly\n\t\t}\n\t}\n};\n\nexport const signalMcpReady = (): void => resolveReady();\n\nexport const activateAdapters = (): void => callAdapters( ( adapter ) => adapter.activate() );\n\nfunction callAdapters( fn: ( adapter: IMcpRegistrationAdapter ) => void ): void {\n\tfor ( const adapter of registrationAdapters ) {\n\t\ttry {\n\t\t\tfn( adapter );\n\t\t} catch {\n\t\t\t// adapter failed — exit quietly, continue to next\n\t\t}\n\t}\n}\n\nexport const registerMcp = ( mcp: McpServer, name: string ) => {\n\tconst mcpName = isAlphabet( name );\n\tmcpRegistry[ mcpName ] = mcp;\n};\n\nexport const getRegisteredMcpServers = (): Array< [ string, McpServer, string ] > => {\n\treturn Object.entries( mcpRegistry ).map( ( [ key, server ] ) => [ key, server, mcpDescriptions[ key ] || key ] );\n};\n\nconst isAlphabet = ( str: string ): string | never => {\n\tconst passes = !! str && /^[a-z_]+$/.test( str );\n\tif ( ! passes ) {\n\t\tthrow new Error( 'Not alphabet' );\n\t}\n\treturn str;\n};\n\nexport const toMCPTitle = ( namespace: string ): string => {\n\tconst capitalized = namespace.charAt( 0 ).toUpperCase() + namespace.slice( 1 );\n\treturn `Editor ${ capitalized }`;\n};\n\n/**\n *\n * @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.\n * @param options\n * @param options.instructions\n */\nexport const getMCPByDomain = ( namespace: string, options?: { instructions?: string } ): MCPRegistryEntry => {\n\tconst mcpName = `editor-${ isAlphabet( namespace ) }`;\n\tconst title = toMCPTitle( namespace );\n\t// @ts-ignore - QUnit fails this\n\tif ( typeof globalThis.jest !== 'undefined' ) {\n\t\treturn mockMcpRegistry();\n\t}\n\tif ( ! mcpRegistry[ namespace ] ) {\n\t\tmcpRegistry[ namespace ] = new McpServer(\n\t\t\t{\n\t\t\t\tname: mcpName,\n\t\t\t\ttitle,\n\t\t\t\tversion: '1.0.0',\n\t\t\t},\n\t\t\t{\n\t\t\t\tinstructions: options?.instructions,\n\t\t\t\tcapabilities: { resources: { subscribe: true } },\n\t\t\t}\n\t\t);\n\t\tif ( !! options?.instructions ) {\n\t\t\tcallAdapters( ( adapter ) =>\n\t\t\t\tadapter.onResourceRegistered( `${ mcpName }`, { uriTemplate: new UriTemplate( mcpName ) }, () =>\n\t\t\t\t\tPromise.resolve( { contents: [ { text: options.instructions ?? '' } ] } )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\tconst mcpServer = mcpRegistry[ namespace ];\n\tconst { addTool } = createToolRegistry( mcpServer, mcpName );\n\treturn {\n\t\twaitForReady: () => readyPromise,\n\t\t// @ts-expect-error: TS is unable to infer the type here\n\t\tresource: async ( ...args: Parameters< McpServer[ 'registerResource' ] > ) => {\n\t\t\tconst [ name, uriOrTemplate, ...rest ] = args as [ string, unknown, ...unknown[] ];\n\t\t\tconst handler = rest[ rest.length - 1 ] as McpResourceHandler;\n\t\t\tconst resourceArgs: Parameters< IMcpRegistrationAdapter[ 'onResourceRegistered' ] > = [\n\t\t\t\tname,\n\t\t\t\turiOrTemplate as McpResourceUriOrTemplate,\n\t\t\t\thandler,\n\t\t\t];\n\t\t\tbufferedResources.push( resourceArgs );\n\t\t\tcallAdapters( ( adapter ) => adapter.onResourceRegistered( ...resourceArgs ) );\n\t\t\treturn mcpServer.registerResource( ...args );\n\t\t},\n\t\tsendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {\n\t\t\tcallAdapters( ( adapter ) => adapter.sendResourceUpdated( { uri: args[ 0 ].uri } ) );\n\t\t\treturn Promise.resolve( mcpServer.server.sendResourceUpdated( ...args ) ).catch( ( error: Error ) => {\n\t\t\t\tif ( error?.message?.includes( 'Not connected' ) ) {\n\t\t\t\t\treturn; // Expected when no MCP client is connected yet\n\t\t\t\t}\n\t\t\t\tif ( error?.message?.includes( 'does not support notifying about resources' ) ) {\n\t\t\t\t\treturn; // Server capability not declared — safe to ignore\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t} );\n\t\t},\n\t\taddTool,\n\t\tsetMCPDescription: ( description: string ) => {\n\t\t\tmcpDescriptions[ namespace ] = description;\n\t\t},\n\t};\n};\n\nexport interface MCPRegistryEntry {\n\taddTool: < T extends undefined | z.ZodRawShape = undefined, O extends undefined | z.ZodRawShape = undefined >(\n\t\topts: ToolRegistrationOptions< T, O >\n\t) => void;\n\tsetMCPDescription: ( description: string ) => void;\n\tsendResourceUpdated: McpServer[ 'server' ][ 'sendResourceUpdated' ];\n\tresource: McpServer[ 'registerResource' ];\n\twaitForReady: () => Promise< void >;\n}\n\ntype ResourceList = {\n\turi: string;\n\tdescription: string;\n}[];\n\ntype ToolRegistrationOptions<\n\tInputArgs extends undefined | z.ZodRawShape = undefined,\n\tOutputSchema extends undefined | z.ZodRawShape = undefined,\n\tExpectedOutput = OutputSchema extends z.ZodRawShape ? z.objectOutputType< OutputSchema, z.ZodTypeAny > : string,\n> = {\n\tname: string;\n\tdescription: string;\n\tschema?: InputArgs;\n\t/**\n\t * Auto added fields:\n\t * @param errors z.string().optional().describe('Error message if the tool failed')\n\t */\n\toutputSchema?: OutputSchema;\n\thandler: InputArgs extends z.ZodRawShape\n\t\t? (\n\t\t\t\targs: z.objectOutputType< InputArgs, z.ZodTypeAny >,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >\n\t\t: (\n\t\t\t\targs: unknown,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >;\n\tisDestructive?: boolean;\n\trequiredResources?: ResourceList;\n\tmodelPreferences?: AngieModelPreferences;\n};\n\nfunction createToolRegistry( server: McpServer, serverName: string ) {\n\tfunction addTool<\n\t\tT extends undefined | z.ZodRawShape = undefined,\n\t\tO extends undefined | z.ZodRawShape = undefined,\n\t>( opts: ToolRegistrationOptions< T, O > ) {\n\t\tconst outputSchema = opts.outputSchema as ZodRawShape | undefined;\n\t\tif ( outputSchema ) {\n\t\t\tObject.assign(\n\t\t\t\toutputSchema,\n\t\t\t\toutputSchema.errors ?? {\n\t\t\t\t\terrors: z.string().optional().describe( 'Error message if the tool failed' ),\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t\t// @ts-ignore: TS is unable to infer the type here\n\t\tconst inputSchema: ZodRawShape = opts.schema ? opts.schema : {};\n\t\tconst toolCallback: ToolCallback< ZodRawShape > = async function ( args, extra ) {\n\t\t\ttry {\n\t\t\t\tconst invocationResult = await opts.handler( opts.schema ? args : {}, extra );\n\t\t\t\treturn {\n\t\t\t\t\t// structuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\t\ttypeof invocationResult === 'string'\n\t\t\t\t\t\t\t\t\t? invocationResult\n\t\t\t\t\t\t\t\t\t: JSON.stringify( invocationResult ),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t} catch ( error ) {\n\t\t\t\treturn {\n\t\t\t\t\tisError: true,\n\t\t\t\t\tstructuredContent: {\n\t\t\t\t\t\terrors: ( error as Error ).message || 'Unknown error',\n\t\t\t\t\t},\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: ( error as Error ).message || 'Unknown error',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\t\tconst annotations: Record< string, unknown > = {\n\t\t\tdestructiveHint: opts.isDestructive,\n\t\t\treadOnlyHint: opts.isDestructive ? false : undefined,\n\t\t\ttitle: opts.name,\n\t\t};\n\t\tconst angieAnnotations = {\n\t\t\t[ ANGIE_MODEL_PREFERENCES ]: opts.modelPreferences ?? createDefaultModelPreferences(),\n\t\t\t[ ANGIE_REQUIRED_RESOURCES ]: opts.requiredResources ?? undefined,\n\t\t};\n\t\tserver.registerTool(\n\t\t\topts.name,\n\t\t\t{\n\t\t\t\tdescription: opts.description,\n\t\t\t\tinputSchema,\n\t\t\t\t// TODO: Uncomment this when the outputSchema is stable\n\t\t\t\t// outputSchema,\n\t\t\t\ttitle: opts.name,\n\t\t\t\tannotations,\n\t\t\t\t_meta: angieAnnotations,\n\t\t\t},\n\t\t\ttoolCallback\n\t\t);\n\t\tconst toolDescriptor = {\n\t\t\tname: opts.name,\n\t\t\tdescription: opts.description,\n\t\t\tinputSchema: inputSchema as object,\n\t\t\texecute: ( params: Record< string, unknown > ) =>\n\t\t\t\tPromise.resolve(\n\t\t\t\t\ttoolCallback(\n\t\t\t\t\t\tparams as Parameters< typeof toolCallback >[ 0 ],\n\t\t\t\t\t\t/* WebMCP: no protocol session — handlers must not rely on `extra` here */\n\t\t\t\t\t\t{} as RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t};\n\t\tconst extraData = {\n\t\t\tresources: [ `Server resource name: ${ serverName }, Required to fetch!` ],\n\t\t\trequiredResources: opts.requiredResources?.map( ( resource ) => resource.uri ) ?? [],\n\t\t};\n\t\tbufferedTools.push( [ toolDescriptor, extraData ] );\n\t\tcallAdapters( ( adapter ) => adapter.onToolRegistered( toolDescriptor, extraData ) );\n\t\tif ( isMcpRegistrationActivated ) {\n\t\t\tserver.sendToolListChanged();\n\t\t}\n\t}\n\treturn {\n\t\taddTool,\n\t};\n}\n","export const ANGIE_MODEL_PREFERENCES = 'angie/modelPreferences' as const;\nexport const ANGIE_REQUIRED_RESOURCES = 'angie/requiredResources' as const;\n\nexport interface AngieModelPreferences {\n\thints?: Array< { name: string } >;\n\tcostPriority?: number; // 0-1 (future use)\n\tspeedPriority?: number; // 0-1 (future use)\n\tintelligencePriority?: number; // 0-1 (future use)\n}\n\nexport function createDefaultModelPreferences(): AngieModelPreferences {\n\treturn {\n\t\thints: [ { name: 'claude-sonnet-4-5' } ],\n\t\tintelligencePriority: 0.8,\n\t\tspeedPriority: 0.7,\n\t};\n}\n","import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n\nimport { type MCPRegistryEntry } from '../mcp-registry';\n\nconst mock = new Proxy(\n\t{},\n\t{\n\t\tget: () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\tfunction mockedFn( ..._: unknown[] ) {}\n\t\t\treturn mockedFn;\n\t\t},\n\t}\n);\n\nexport const mockMcpRegistry = (): MCPRegistryEntry => {\n\treturn {\n\t\t// @ts-ignore\n\t\tresource: async () => {},\n\t\t// @ts-ignore\n\t\tsendResourceUpdated: () => {},\n\t\taddTool: () => {},\n\t\tsetMCPDescription: () => {},\n\t\tmcpServer: mock as McpServer,\n\t};\n};\n","import { type z } from '@elementor/schema';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { SamplingMessageSchema, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\ntype Server = RequestHandlerExtra< ServerRequest, ServerNotification >;\ntype Opts = {\n\tmaxTokens?: number;\n\tmodelPreferences?: string;\n\tmodel?: string;\n};\n\nconst DEFAULT_OPTS: Opts = {\n\tmaxTokens: 10000,\n\tmodelPreferences: 'openai',\n\tmodel: 'gpt-4o',\n};\n\ntype SamplingOpts = {\n\tsystemPrompt?: string;\n\tstructuredOutput?: z.ZodTypeAny;\n\tmessages: { role: 'user' | 'assistant'; content: { type: 'text'; text: string } }[];\n\trequestParams?: { [ key: string ]: string };\n};\n\nconst DEFAULT_STRUCTURED_OUTPUT = {\n\ttype: 'object',\n\tproperties: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tdescription: 'Result',\n\t\t},\n\t},\n\trequired: [ 'content' ],\n\tadditionalProperties: false,\n};\n\nexport const createSampler = ( server: Server, opts: Opts = DEFAULT_OPTS ) => {\n\tconst { maxTokens = 1000, modelPreferences = 'openai', model = 'gpt-4o' } = opts;\n\tconst exec = async ( payload: SamplingOpts ) => {\n\t\tconst systemPromptObject = { ...( payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} ) };\n\t\tconst requestParams = payload.requestParams || {};\n\t\tconst result = await server.sendRequest(\n\t\t\t{\n\t\t\t\tmethod: 'sampling/createMessage',\n\t\t\t\tparams: {\n\t\t\t\t\t...requestParams,\n\t\t\t\t\tmaxTokens,\n\t\t\t\t\tmodelPreferences: {\n\t\t\t\t\t\thints: [ { name: modelPreferences } ],\n\t\t\t\t\t},\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t...systemPromptObject,\n\t\t\t\t\t\t...{ structured_output: payload.structuredOutput || DEFAULT_STRUCTURED_OUTPUT },\n\t\t\t\t\t},\n\t\t\t\t\tmessages: payload.messages,\n\t\t\t\t},\n\t\t\t\t// ...systemPromptObject,\n\t\t\t},\n\t\t\tSamplingMessageSchema\n\t\t);\n\t\treturn result.content;\n\t};\n\treturn exec;\n};\n","class ToolPrompts {\n\tpublic _description = '';\n\tpublic _parameters: Record< string, string > = {};\n\tpublic _examples: string[] = [];\n\tpublic _furtherInstructions: string[] = [];\n\n\tconstructor( public name: string ) {}\n\n\tdescription(): string;\n\tdescription( desc: string ): this;\n\tdescription( desc?: string | undefined ) {\n\t\tif ( typeof desc === 'undefined' ) {\n\t\t\treturn this._description;\n\t\t}\n\t\tthis._description = desc;\n\t\treturn this;\n\t}\n\n\tparameter( key: string ): string;\n\tparameter( key: string, description: string ): this;\n\tparameter( key: string, description?: string ) {\n\t\tif ( typeof description === 'undefined' ) {\n\t\t\treturn this._parameters[ key ];\n\t\t}\n\t\tthis._parameters[ key ] = `**${ key }**:\\n${ description }`;\n\t\treturn this;\n\t}\n\n\tinstruction( instruction: string ): this {\n\t\tthis._furtherInstructions.push( instruction );\n\t\treturn this;\n\t}\n\n\texample( example: string ): this {\n\t\tthis._examples.push( example );\n\t\treturn this;\n\t}\n\n\tpublic get examples() {\n\t\treturn this._examples.join( '\\n\\n' );\n\t}\n\n\tprompt(): string {\n\t\treturn `# ${ this.name }\n# Description\n${ this._description }\n\n${ this._parameters.length ? '# Parameters' : '' }\n${ Object.values( this._parameters ).join( '\\n\\n' ) }\n\n${ this._examples.length ? '# Examples' : '' }\n${ this.examples }\n\n${ this._furtherInstructions.length ? '# Further Instructions' : '' }\n${ this._furtherInstructions.join( '\\n\\n' ) }\n`.trim();\n\t}\n}\n\nexport const toolPrompts = ( name: string ) => {\n\treturn new ToolPrompts( name );\n};\n","export type ActiveChatInfo = {\n\tsessionId: string;\n\texpiresAt: number;\n};\n\nexport const getActiveChatInfo = (): ActiveChatInfo => {\n\tconst info = localStorage.getItem( 'angie_active_chat_id' );\n\tif ( ! info ) {\n\t\treturn {\n\t\t\texpiresAt: 0,\n\t\t\tsessionId: '',\n\t\t};\n\t}\n\tconst rawData = JSON.parse( info );\n\treturn {\n\t\texpiresAt: rawData.expiresAt as number,\n\t\tsessionId: rawData.sessionId as string,\n\t};\n};\n","import { getAngieIframe, toggleAngieSidebar } from '@elementor-external/angie-sdk';\n\nexport const sendPromptToAngie = ( prompt?: string ) => {\n\tconst angieSidebar = getAngieIframe();\n\n\tif ( ! angieSidebar ) {\n\t\treturn;\n\t}\n\n\ttoggleAngieSidebar( angieSidebar, true );\n\n\tif ( ! prompt ) {\n\t\treturn;\n\t}\n\n\twindow.location.hash = `angie-prompt=${ encodeURIComponent( prompt ) }`;\n};\n","import { setReferrerRedirect } from '@elementor-external/angie-sdk';\n\nconst ANGIE_INSTALL_URL = '/wp-admin/plugin-install.php?s=angie&tab=search&type=term';\n\nexport const redirectToInstallation = ( prompt: string ) => {\n\tconst success = setReferrerRedirect( window.location.href, prompt );\n\n\tif ( ! success ) {\n\t\treturn;\n\t}\n\n\twindow.location.href = ANGIE_INSTALL_URL;\n};\n","import { setReferrerRedirect } from '@elementor-external/angie-sdk';\n\nconst ANGIE_APP_URL = '/wp-admin/admin.php?page=angie-app';\n\nexport const redirectToAppAdmin = ( prompt: string ) => {\n\tconst success = setReferrerRedirect( window.location.href, prompt );\n\n\tif ( ! success ) {\n\t\treturn;\n\t}\n\n\twindow.location.href = ANGIE_APP_URL;\n};\n","import apiFetch from '@wordpress/api-fetch';\n\ntype PluginResponse = {\n\tplugin: string;\n\tstatus: 'active' | 'inactive';\n\tname: string;\n};\n\ntype PluginErrorResponse = {\n\tcode: string;\n\tmessage: string;\n};\n\nexport type InstallAngieResult = { success: true } | { success: false; error: string; code?: string };\n\nconst ANGIE_SLUG = 'angie';\n\nconst isPluginErrorResponse = ( response: unknown ): response is PluginErrorResponse => {\n\treturn typeof response === 'object' && response !== null && 'code' in response && 'message' in response;\n};\n\nconst activatePlugin = async ( pluginPath: string ): Promise< PluginResponse > => {\n\treturn apiFetch< PluginResponse >( {\n\t\tpath: `/wp/v2/plugins/${ pluginPath }`,\n\t\tmethod: 'POST',\n\t\tdata: { status: 'active' },\n\t} );\n};\n\nconst installPlugin = async (): Promise< PluginResponse > => {\n\ttry {\n\t\treturn await apiFetch< PluginResponse >( {\n\t\t\tpath: '/wp/v2/plugins',\n\t\t\tmethod: 'POST',\n\t\t\tdata: {\n\t\t\t\tslug: ANGIE_SLUG,\n\t\t\t\tstatus: 'active',\n\t\t\t},\n\t\t} );\n\t} catch ( error: unknown ) {\n\t\tif ( isPluginErrorResponse( error ) && error.code === 'folder_exists' ) {\n\t\t\treturn activatePlugin( `${ ANGIE_SLUG }/${ ANGIE_SLUG }` );\n\t\t}\n\n\t\tthrow error;\n\t}\n};\n\nexport const installAngiePlugin = async (): Promise< InstallAngieResult > => {\n\ttry {\n\t\tawait installPlugin();\n\n\t\treturn { success: true };\n\t} catch ( error: unknown ) {\n\t\tif ( isPluginErrorResponse( error ) ) {\n\t\t\treturn { success: false, error: error.message, code: error.code };\n\t\t}\n\n\t\treturn { success: false, error: 'Unknown error occurred' };\n\t}\n};\n","import { type AngieMcpSdk } from '@elementor-external/angie-sdk';\n\nimport { getRegisteredMcpServers, toMCPTitle } from '../mcp-registry';\nimport { type IMcpRegistrationAdapter } from './types';\n\nconst MAX_RETRIES = 3;\n\nexport class AngieMcpAdapter implements IMcpRegistrationAdapter {\n\tconstructor( private readonly sdk: AngieMcpSdk ) {}\n\n\tasync activate(): Promise< void > {\n\t\tawait this.sdk.waitForReady();\n\t\tawait this.registerEntries( getRegisteredMcpServers(), MAX_RETRIES );\n\t}\n\n\tprivate async registerEntries(\n\t\tentries: ReturnType< typeof getRegisteredMcpServers >,\n\t\tretry: number\n\t): Promise< void > {\n\t\tif ( retry === 0 ) {\n\t\t\t/* eslint-disable-next-line no-console */\n\t\t\tconsole.error(\n\t\t\t\t'Failed to register MCP after 3 retries. failed entries: ',\n\t\t\t\tentries.map( ( [ key ] ) => key )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst failed: typeof entries = [];\n\t\tfor ( const [ key, mcpServer, description ] of entries ) {\n\t\t\ttry {\n\t\t\t\tawait this.sdk.registerLocalServer( {\n\t\t\t\t\ttitle: toMCPTitle( key ),\n\t\t\t\t\tname: `editor-${ key }`,\n\t\t\t\t\tserver: mcpServer,\n\t\t\t\t\tversion: '1.0.0',\n\t\t\t\t\tdescription,\n\t\t\t\t} );\n\t\t\t} catch {\n\t\t\t\tfailed.push( [ key, mcpServer, description ] );\n\t\t\t}\n\t\t}\n\n\t\tif ( failed.length > 0 ) {\n\t\t\treturn this.registerEntries( failed, retry - 1 );\n\t\t}\n\t}\n\n\tonToolRegistered(): void {\n\t\t// Angie tools are registered via McpServer (at activate time).\n\t}\n\n\tonResourceRegistered(): void {\n\t\t// Resources are registered on the McpServer instance directly.\n\t}\n\n\tsendResourceUpdated(): void {\n\t\t// Resource update notifications are sent via MCPRegistryEntry.sendResourceUpdated.\n\t}\n}\n","import { zodToJsonSchema } from 'zod-to-json-schema';\nimport { z, type z3 } from '@elementor/schema';\n\nimport {\n\ttype IMcpRegistrationAdapter,\n\ttype McpResourceHandler,\n\ttype McpResourceUriOrTemplate,\n\ttype McpToolDescriptor,\n\ttype UriTemplate,\n} from './types';\n\ntype ZodRawShape = z3.ZodRawShape;\n\nexport type ModelContext = {\n\tregisterTool: ( tool: McpToolDescriptor ) => void;\n\tunregisterTool: ( name: string ) => void;\n};\n\ntype ResourceEntry = {\n\tpattern: string;\n\tmatch: ( uri: string ) => Record< string, string | string[] > | null;\n\thandler: McpResourceHandler;\n};\n\nexport class WebMCPAdapter implements IMcpRegistrationAdapter {\n\tprivate readonly registeredToolNames = new Set< string >();\n\tprivate readonly resourceEntries: ResourceEntry[] = [];\n\tprivate activated = false;\n\n\tconstructor( private readonly ctx: ModelContext ) {}\n\n\tactivate(): void {\n\t\tif ( this.activated ) {\n\t\t\treturn;\n\t\t}\n\t\tthis.activated = true;\n\t\tthis.ctx.registerTool( {\n\t\t\tname: 'editor-resource-getter',\n\t\t\tdescription:\n\t\t\t\t'Get an editor resource by URI, or search for available resources by partial URI. Pass a full URI to retrieve content, or a partial string to discover matching patterns.',\n\t\t\tinputSchema: {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {\n\t\t\t\t\turi: {\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'A full resource URI (e.g. elementor://styles/best-practices) or a partial string to search across available resource patterns.',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [ 'uri' ],\n\t\t\t},\n\t\t\texecute: async ( params ) => {\n\t\t\t\tconst query = params.uri as string;\n\t\t\t\tconst entries = this.resourceEntries;\n\n\t\t\t\tif ( entries.length === 0 ) {\n\t\t\t\t\treturn 'No resources are registered yet.';\n\t\t\t\t}\n\n\t\t\t\t// Exact URI match\n\t\t\t\tfor ( const entry of entries ) {\n\t\t\t\t\tconst variables = entry.match( query );\n\t\t\t\t\tif ( variables !== null ) {\n\t\t\t\t\t\tlet resourceUrl: URL;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tresourceUrl = new URL( query );\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\treturn `Invalid URI '${ query }'. Provide a valid resource URI or a partial string to search patterns.`;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst result = await entry.handler( resourceUrl, variables );\n\t\t\t\t\t\treturn result.contents?.[ 0 ]?.text ?? JSON.stringify( result );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Partial search fallback\n\t\t\t\tconst matches = entries.map( ( e ) => e.pattern ).filter( ( pattern ) => pattern.includes( query ) );\n\t\t\t\tif ( matches.length > 0 ) {\n\t\t\t\t\treturn `Found ${ matches.length } matching resource pattern(s):\\n${ matches.join(\n\t\t\t\t\t\t'\\n'\n\t\t\t\t\t) }\\n\\nProvide a full URI to retrieve the resource content.`;\n\t\t\t\t}\n\n\t\t\t\tconst available = entries.map( ( e ) => e.pattern ).join( '\\n' );\n\t\t\t\tthrow new Error( `No resource matched '${ query }'.\\n\\nAvailable patterns:\\n${ available }` );\n\t\t\t},\n\t\t} );\n\t}\n\n\tonToolRegistered(\n\t\ttool: McpToolDescriptor,\n\t\textraData?: { resources: string[]; requiredResources: string[] }\n\t): void {\n\t\tlet jsonSchema: object;\n\t\ttry {\n\t\t\tjsonSchema = zodToJsonSchema( z.object( tool.inputSchema as ZodRawShape ) );\n\t\t} catch {\n\t\t\tjsonSchema = tool.inputSchema;\n\t\t}\n\n\t\tif ( this.registeredToolNames.has( tool.name ) ) {\n\t\t\tthis.ctx.unregisterTool( tool.name );\n\t\t}\n\n\t\tlet resourcesDescription = '';\n\t\tif ( extraData ) {\n\t\t\tif ( extraData.resources?.length > 0 ) {\n\t\t\t\tresourcesDescription += `#Resources:\\n${ extraData.resources?.join( '\\n' ) }\\n\\n`;\n\t\t\t}\n\t\t\tif ( extraData.requiredResources?.length > 0 ) {\n\t\t\t\tresourcesDescription += `#Required Resources:\\n${ extraData.requiredResources?.join( '\\n' ) }\\n\\n`;\n\t\t\t}\n\t\t\tresourcesDescription += `To read resources, use editor-resource-getter tool.\\n\\n`;\n\t\t}\n\t\tthis.ctx.registerTool( {\n\t\t\tname: tool.name,\n\t\t\tdescription: `${ resourcesDescription }${ tool.description }`,\n\t\t\tinputSchema: jsonSchema,\n\t\t\texecute: tool.execute,\n\t\t} );\n\t\tthis.registeredToolNames.add( tool.name );\n\t}\n\n\tonResourceRegistered( _name: string, uriOrTemplate: McpResourceUriOrTemplate, handler: McpResourceHandler ): void {\n\t\tif ( typeof uriOrTemplate === 'string' ) {\n\t\t\tthis.resourceEntries.push( {\n\t\t\t\tpattern: uriOrTemplate,\n\t\t\t\tmatch: ( uri ) => ( uri === uriOrTemplate ? {} : null ),\n\t\t\t\thandler,\n\t\t\t} );\n\t\t} else {\n\t\t\tconst template = uriOrTemplate.uriTemplate as UriTemplate;\n\t\t\tthis.resourceEntries.push( {\n\t\t\t\tpattern: template.toString(),\n\t\t\t\tmatch: ( uri ) => template.match( uri ),\n\t\t\t\thandler,\n\t\t\t} );\n\t\t}\n\t}\n\n\tsendResourceUpdated(): void {\n\t\t// WebMCP has no server-push mechanism — no-op\n\t}\n}\n","import { AngieMcpAdapter } from './adapters/angie-adapter';\nimport { type ModelContext, WebMCPAdapter } from './adapters/web-mcp-adapter';\nimport { activateAdapters, registerMcpAdapter, signalMcpReady } from './mcp-registry';\nimport { getSDK } from './utils/get-sdk';\nimport { isAngieAvailable } from './utils/is-angie-available';\n\nexport function startMCPServer() {\n\tif ( typeof navigator !== 'undefined' && 'modelContext' in navigator ) {\n\t\tregisterMcpAdapter(\n\t\t\tnew WebMCPAdapter( ( navigator as unknown as { modelContext: ModelContext } ).modelContext )\n\t\t);\n\t}\n\n\tif ( isAngieAvailable() ) {\n\t\tregisterMcpAdapter( new AngieMcpAdapter( getSDK() ) );\n\t}\n\n\tactivateAdapters();\n\tsignalMcpReady();\n}\n\nif ( typeof document !== 'undefined' ) {\n\tdocument.addEventListener( 'DOMContentLoaded', () => startMCPServer(), { once: true } );\n} else {\n\tstartMCPServer();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAA4B;AAC5B,IAAAA,oBAAiD;AAEjD,IAAI;AAEG,IAAM,SAAS,MAAM;AAE3B,QAAM,gBAAgB,CAAC,CAAI,WAA0C;AACrE,MAAK,eAAgB;AACpB,WAAO,CAAC;AAAA,EACT;AACA,MAAK,CAAE,KAAM;AACZ,UAAM,IAAI,6BAAY;AAAA,EACvB;AACA,SAAO;AACR;;;ADZA,IAAAC,cAKO;AACP,IAAAC,gBAAsC;;;AETtC,IAAAC,oBAA+B;AAExB,IAAM,mBAAmB,MAAe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O;AACN,iBAAe;AAChB;;;AhBJO,IAAM,cAAc,MAAM,OAAO;","names":["import_angie_sdk","import_mcp","import_types","import_angie_sdk","import_angie_sdk","import_angie_sdk","import_angie_sdk","import_angie_sdk","apiFetch","sdk","import_schema"]}
|
package/dist/index.mjs
CHANGED
|
@@ -20,12 +20,22 @@ import {
|
|
|
20
20
|
} from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
21
21
|
import { SamplingMessageSchema as SamplingMessageSchema2 } from "@modelcontextprotocol/sdk/types.js";
|
|
22
22
|
|
|
23
|
-
// src/
|
|
24
|
-
import {
|
|
23
|
+
// src/utils/is-angie-available.ts
|
|
24
|
+
import { getAngieIframe as getAngieIframe2 } from "@elementor-external/angie-sdk";
|
|
25
|
+
var isAngieAvailable = () => {
|
|
26
|
+
return !!getAngieIframe2();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/utils/is-angie-sidebar-open.ts
|
|
30
|
+
import { ANGIE_SIDEBAR_STATE_OPEN, getAngieSidebarSavedState } from "@elementor-external/angie-sdk";
|
|
31
|
+
var isAngieSidebarOpen = () => {
|
|
32
|
+
return getAngieSidebarSavedState() === ANGIE_SIDEBAR_STATE_OPEN;
|
|
33
|
+
};
|
|
25
34
|
|
|
26
35
|
// src/mcp-registry.ts
|
|
27
36
|
import { z } from "@elementor/schema";
|
|
28
37
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
38
|
+
import { UriTemplate } from "@modelcontextprotocol/sdk/shared/uriTemplate.js";
|
|
29
39
|
|
|
30
40
|
// src/angie-annotations.ts
|
|
31
41
|
var ANGIE_MODEL_PREFERENCES = "angie/modelPreferences";
|
|
@@ -61,9 +71,6 @@ var mockMcpRegistry = () => {
|
|
|
61
71
|
},
|
|
62
72
|
setMCPDescription: () => {
|
|
63
73
|
},
|
|
64
|
-
getActiveChatInfo() {
|
|
65
|
-
return { sessionId: "mock-session-id", expiresAt: Date.now() + 36e5 };
|
|
66
|
-
},
|
|
67
74
|
mcpServer: mock
|
|
68
75
|
};
|
|
69
76
|
};
|
|
@@ -72,37 +79,45 @@ var mockMcpRegistry = () => {
|
|
|
72
79
|
var mcpRegistry = {};
|
|
73
80
|
var mcpDescriptions = {};
|
|
74
81
|
var isMcpRegistrationActivated = typeof globalThis.jest !== "undefined";
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
var registrationAdapters = [];
|
|
83
|
+
var bufferedTools = [];
|
|
84
|
+
var bufferedResources = [];
|
|
85
|
+
var resolveReady;
|
|
86
|
+
var readyPromise = new Promise((resolve) => {
|
|
87
|
+
resolveReady = resolve;
|
|
88
|
+
});
|
|
89
|
+
var registerMcpAdapter = (adapter) => {
|
|
90
|
+
registrationAdapters.push(adapter);
|
|
91
|
+
for (const tool of bufferedTools) {
|
|
92
|
+
try {
|
|
93
|
+
adapter.onToolRegistered(tool[0], tool[1]);
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
86
96
|
}
|
|
87
|
-
const
|
|
88
|
-
for await (const entry of entries) {
|
|
89
|
-
const [key, mcpServer] = entry;
|
|
97
|
+
for (const resource of bufferedResources) {
|
|
90
98
|
try {
|
|
91
|
-
|
|
92
|
-
title: toMCPTitle(key),
|
|
93
|
-
name: `editor-${key}`,
|
|
94
|
-
server: mcpServer,
|
|
95
|
-
version: "1.0.0",
|
|
96
|
-
description: mcpDescriptions[key] || key
|
|
97
|
-
});
|
|
99
|
+
adapter.onResourceRegistered(...resource);
|
|
98
100
|
} catch {
|
|
99
|
-
failed.push(entry);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
};
|
|
104
|
+
var signalMcpReady = () => resolveReady();
|
|
105
|
+
var activateAdapters = () => callAdapters((adapter) => adapter.activate());
|
|
106
|
+
function callAdapters(fn) {
|
|
107
|
+
for (const adapter of registrationAdapters) {
|
|
108
|
+
try {
|
|
109
|
+
fn(adapter);
|
|
110
|
+
} catch {
|
|
111
|
+
}
|
|
104
112
|
}
|
|
105
113
|
}
|
|
114
|
+
var registerMcp = (mcp, name) => {
|
|
115
|
+
const mcpName = isAlphabet(name);
|
|
116
|
+
mcpRegistry[mcpName] = mcp;
|
|
117
|
+
};
|
|
118
|
+
var getRegisteredMcpServers = () => {
|
|
119
|
+
return Object.entries(mcpRegistry).map(([key, server]) => [key, server, mcpDescriptions[key] || key]);
|
|
120
|
+
};
|
|
106
121
|
var isAlphabet = (str) => {
|
|
107
122
|
const passes = !!str && /^[a-z_]+$/.test(str);
|
|
108
123
|
if (!passes) {
|
|
@@ -128,49 +143,56 @@ var getMCPByDomain = (namespace, options) => {
|
|
|
128
143
|
version: "1.0.0"
|
|
129
144
|
},
|
|
130
145
|
{
|
|
131
|
-
instructions: options?.instructions
|
|
146
|
+
instructions: options?.instructions,
|
|
147
|
+
capabilities: { resources: { subscribe: true } }
|
|
132
148
|
}
|
|
133
149
|
);
|
|
150
|
+
if (!!options?.instructions) {
|
|
151
|
+
callAdapters(
|
|
152
|
+
(adapter) => adapter.onResourceRegistered(
|
|
153
|
+
`${mcpName}`,
|
|
154
|
+
{ uriTemplate: new UriTemplate(mcpName) },
|
|
155
|
+
() => Promise.resolve({ contents: [{ text: options.instructions ?? "" }] })
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
}
|
|
134
159
|
}
|
|
135
160
|
const mcpServer = mcpRegistry[namespace];
|
|
136
|
-
const { addTool } = createToolRegistry(mcpServer);
|
|
161
|
+
const { addTool } = createToolRegistry(mcpServer, mcpName);
|
|
137
162
|
return {
|
|
138
|
-
waitForReady: () =>
|
|
163
|
+
waitForReady: () => readyPromise,
|
|
139
164
|
// @ts-expect-error: TS is unable to infer the type here
|
|
140
165
|
resource: async (...args) => {
|
|
141
|
-
|
|
166
|
+
const [name, uriOrTemplate, ...rest] = args;
|
|
167
|
+
const handler = rest[rest.length - 1];
|
|
168
|
+
const resourceArgs = [
|
|
169
|
+
name,
|
|
170
|
+
uriOrTemplate,
|
|
171
|
+
handler
|
|
172
|
+
];
|
|
173
|
+
bufferedResources.push(resourceArgs);
|
|
174
|
+
callAdapters((adapter) => adapter.onResourceRegistered(...resourceArgs));
|
|
142
175
|
return mcpServer.registerResource(...args);
|
|
143
176
|
},
|
|
144
177
|
sendResourceUpdated: (...args) => {
|
|
145
|
-
|
|
178
|
+
callAdapters((adapter) => adapter.sendResourceUpdated({ uri: args[0].uri }));
|
|
179
|
+
return Promise.resolve(mcpServer.server.sendResourceUpdated(...args)).catch((error) => {
|
|
146
180
|
if (error?.message?.includes("Not connected")) {
|
|
147
181
|
return;
|
|
148
182
|
}
|
|
183
|
+
if (error?.message?.includes("does not support notifying about resources")) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
149
186
|
throw error;
|
|
150
187
|
});
|
|
151
188
|
},
|
|
152
|
-
mcpServer,
|
|
153
189
|
addTool,
|
|
154
190
|
setMCPDescription: (description) => {
|
|
155
191
|
mcpDescriptions[namespace] = description;
|
|
156
|
-
},
|
|
157
|
-
getActiveChatInfo: () => {
|
|
158
|
-
const info = localStorage.getItem("angie_active_chat_id");
|
|
159
|
-
if (!info) {
|
|
160
|
-
return {
|
|
161
|
-
expiresAt: 0,
|
|
162
|
-
sessionId: ""
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
const rawData = JSON.parse(info);
|
|
166
|
-
return {
|
|
167
|
-
expiresAt: rawData.expiresAt,
|
|
168
|
-
sessionId: rawData.sessionId
|
|
169
|
-
};
|
|
170
192
|
}
|
|
171
193
|
};
|
|
172
194
|
};
|
|
173
|
-
function createToolRegistry(server) {
|
|
195
|
+
function createToolRegistry(server, serverName) {
|
|
174
196
|
function addTool(opts) {
|
|
175
197
|
const outputSchema = opts.outputSchema;
|
|
176
198
|
if (outputSchema) {
|
|
@@ -231,6 +253,24 @@ function createToolRegistry(server) {
|
|
|
231
253
|
},
|
|
232
254
|
toolCallback
|
|
233
255
|
);
|
|
256
|
+
const toolDescriptor = {
|
|
257
|
+
name: opts.name,
|
|
258
|
+
description: opts.description,
|
|
259
|
+
inputSchema,
|
|
260
|
+
execute: (params) => Promise.resolve(
|
|
261
|
+
toolCallback(
|
|
262
|
+
params,
|
|
263
|
+
/* WebMCP: no protocol session — handlers must not rely on `extra` here */
|
|
264
|
+
{}
|
|
265
|
+
)
|
|
266
|
+
)
|
|
267
|
+
};
|
|
268
|
+
const extraData = {
|
|
269
|
+
resources: [`Server resource name: ${serverName}, Required to fetch!`],
|
|
270
|
+
requiredResources: opts.requiredResources?.map((resource) => resource.uri) ?? []
|
|
271
|
+
};
|
|
272
|
+
bufferedTools.push([toolDescriptor, extraData]);
|
|
273
|
+
callAdapters((adapter) => adapter.onToolRegistered(toolDescriptor, extraData));
|
|
234
274
|
if (isMcpRegistrationActivated) {
|
|
235
275
|
server.sendToolListChanged();
|
|
236
276
|
}
|
|
@@ -240,42 +280,6 @@ function createToolRegistry(server) {
|
|
|
240
280
|
};
|
|
241
281
|
}
|
|
242
282
|
|
|
243
|
-
// src/utils/is-angie-available.ts
|
|
244
|
-
import { getAngieIframe as getAngieIframe2 } from "@elementor-external/angie-sdk";
|
|
245
|
-
var isAngieAvailable = () => {
|
|
246
|
-
return !!getAngieIframe2();
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
// src/init.ts
|
|
250
|
-
function init() {
|
|
251
|
-
if (isExperimentActive("editor_mcp") && isAngieAvailable()) {
|
|
252
|
-
return getSDK().waitForReady();
|
|
253
|
-
}
|
|
254
|
-
return Promise.resolve();
|
|
255
|
-
}
|
|
256
|
-
function startMCPServer() {
|
|
257
|
-
if (isExperimentActive("editor_mcp") && isAngieAvailable()) {
|
|
258
|
-
const sdk2 = getSDK();
|
|
259
|
-
sdk2.waitForReady().then(() => activateMcpRegistration(sdk2));
|
|
260
|
-
}
|
|
261
|
-
return Promise.resolve();
|
|
262
|
-
}
|
|
263
|
-
document.addEventListener(
|
|
264
|
-
"DOMContentLoaded",
|
|
265
|
-
() => {
|
|
266
|
-
startMCPServer();
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
once: true
|
|
270
|
-
}
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
// src/utils/is-angie-sidebar-open.ts
|
|
274
|
-
import { ANGIE_SIDEBAR_STATE_OPEN, getAngieSidebarSavedState } from "@elementor-external/angie-sdk";
|
|
275
|
-
var isAngieSidebarOpen = () => {
|
|
276
|
-
return getAngieSidebarSavedState() === ANGIE_SIDEBAR_STATE_OPEN;
|
|
277
|
-
};
|
|
278
|
-
|
|
279
283
|
// src/sampler.ts
|
|
280
284
|
import { SamplingMessageSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
281
285
|
var DEFAULT_OPTS = {
|
|
@@ -379,6 +383,22 @@ var toolPrompts = (name) => {
|
|
|
379
383
|
return new ToolPrompts(name);
|
|
380
384
|
};
|
|
381
385
|
|
|
386
|
+
// src/utils/get-active-chat-info.ts
|
|
387
|
+
var getActiveChatInfo = () => {
|
|
388
|
+
const info = localStorage.getItem("angie_active_chat_id");
|
|
389
|
+
if (!info) {
|
|
390
|
+
return {
|
|
391
|
+
expiresAt: 0,
|
|
392
|
+
sessionId: ""
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const rawData = JSON.parse(info);
|
|
396
|
+
return {
|
|
397
|
+
expiresAt: rawData.expiresAt,
|
|
398
|
+
sessionId: rawData.sessionId
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
|
|
382
402
|
// src/utils/send-prompt-to-angie.ts
|
|
383
403
|
import { getAngieIframe as getAngieIframe3, toggleAngieSidebar } from "@elementor-external/angie-sdk";
|
|
384
404
|
var sendPromptToAngie = (prompt) => {
|
|
@@ -457,6 +477,189 @@ var installAngiePlugin = async () => {
|
|
|
457
477
|
}
|
|
458
478
|
};
|
|
459
479
|
|
|
480
|
+
// src/adapters/angie-adapter.ts
|
|
481
|
+
var MAX_RETRIES = 3;
|
|
482
|
+
var AngieMcpAdapter = class {
|
|
483
|
+
constructor(sdk2) {
|
|
484
|
+
this.sdk = sdk2;
|
|
485
|
+
}
|
|
486
|
+
async activate() {
|
|
487
|
+
await this.sdk.waitForReady();
|
|
488
|
+
await this.registerEntries(getRegisteredMcpServers(), MAX_RETRIES);
|
|
489
|
+
}
|
|
490
|
+
async registerEntries(entries, retry) {
|
|
491
|
+
if (retry === 0) {
|
|
492
|
+
console.error(
|
|
493
|
+
"Failed to register MCP after 3 retries. failed entries: ",
|
|
494
|
+
entries.map(([key]) => key)
|
|
495
|
+
);
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const failed = [];
|
|
499
|
+
for (const [key, mcpServer, description] of entries) {
|
|
500
|
+
try {
|
|
501
|
+
await this.sdk.registerLocalServer({
|
|
502
|
+
title: toMCPTitle(key),
|
|
503
|
+
name: `editor-${key}`,
|
|
504
|
+
server: mcpServer,
|
|
505
|
+
version: "1.0.0",
|
|
506
|
+
description
|
|
507
|
+
});
|
|
508
|
+
} catch {
|
|
509
|
+
failed.push([key, mcpServer, description]);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
if (failed.length > 0) {
|
|
513
|
+
return this.registerEntries(failed, retry - 1);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
onToolRegistered() {
|
|
517
|
+
}
|
|
518
|
+
onResourceRegistered() {
|
|
519
|
+
}
|
|
520
|
+
sendResourceUpdated() {
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
// src/adapters/web-mcp-adapter.ts
|
|
525
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
526
|
+
import { z as z2 } from "@elementor/schema";
|
|
527
|
+
var WebMCPAdapter = class {
|
|
528
|
+
constructor(ctx) {
|
|
529
|
+
this.ctx = ctx;
|
|
530
|
+
}
|
|
531
|
+
registeredToolNames = /* @__PURE__ */ new Set();
|
|
532
|
+
resourceEntries = [];
|
|
533
|
+
activated = false;
|
|
534
|
+
activate() {
|
|
535
|
+
if (this.activated) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
this.activated = true;
|
|
539
|
+
this.ctx.registerTool({
|
|
540
|
+
name: "editor-resource-getter",
|
|
541
|
+
description: "Get an editor resource by URI, or search for available resources by partial URI. Pass a full URI to retrieve content, or a partial string to discover matching patterns.",
|
|
542
|
+
inputSchema: {
|
|
543
|
+
type: "object",
|
|
544
|
+
properties: {
|
|
545
|
+
uri: {
|
|
546
|
+
type: "string",
|
|
547
|
+
description: "A full resource URI (e.g. elementor://styles/best-practices) or a partial string to search across available resource patterns."
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
required: ["uri"]
|
|
551
|
+
},
|
|
552
|
+
execute: async (params) => {
|
|
553
|
+
const query = params.uri;
|
|
554
|
+
const entries = this.resourceEntries;
|
|
555
|
+
if (entries.length === 0) {
|
|
556
|
+
return "No resources are registered yet.";
|
|
557
|
+
}
|
|
558
|
+
for (const entry of entries) {
|
|
559
|
+
const variables = entry.match(query);
|
|
560
|
+
if (variables !== null) {
|
|
561
|
+
let resourceUrl;
|
|
562
|
+
try {
|
|
563
|
+
resourceUrl = new URL(query);
|
|
564
|
+
} catch {
|
|
565
|
+
return `Invalid URI '${query}'. Provide a valid resource URI or a partial string to search patterns.`;
|
|
566
|
+
}
|
|
567
|
+
const result = await entry.handler(resourceUrl, variables);
|
|
568
|
+
return result.contents?.[0]?.text ?? JSON.stringify(result);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const matches = entries.map((e) => e.pattern).filter((pattern) => pattern.includes(query));
|
|
572
|
+
if (matches.length > 0) {
|
|
573
|
+
return `Found ${matches.length} matching resource pattern(s):
|
|
574
|
+
${matches.join(
|
|
575
|
+
"\n"
|
|
576
|
+
)}
|
|
577
|
+
|
|
578
|
+
Provide a full URI to retrieve the resource content.`;
|
|
579
|
+
}
|
|
580
|
+
const available = entries.map((e) => e.pattern).join("\n");
|
|
581
|
+
throw new Error(`No resource matched '${query}'.
|
|
582
|
+
|
|
583
|
+
Available patterns:
|
|
584
|
+
${available}`);
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
onToolRegistered(tool, extraData) {
|
|
589
|
+
let jsonSchema;
|
|
590
|
+
try {
|
|
591
|
+
jsonSchema = zodToJsonSchema(z2.object(tool.inputSchema));
|
|
592
|
+
} catch {
|
|
593
|
+
jsonSchema = tool.inputSchema;
|
|
594
|
+
}
|
|
595
|
+
if (this.registeredToolNames.has(tool.name)) {
|
|
596
|
+
this.ctx.unregisterTool(tool.name);
|
|
597
|
+
}
|
|
598
|
+
let resourcesDescription = "";
|
|
599
|
+
if (extraData) {
|
|
600
|
+
if (extraData.resources?.length > 0) {
|
|
601
|
+
resourcesDescription += `#Resources:
|
|
602
|
+
${extraData.resources?.join("\n")}
|
|
603
|
+
|
|
604
|
+
`;
|
|
605
|
+
}
|
|
606
|
+
if (extraData.requiredResources?.length > 0) {
|
|
607
|
+
resourcesDescription += `#Required Resources:
|
|
608
|
+
${extraData.requiredResources?.join("\n")}
|
|
609
|
+
|
|
610
|
+
`;
|
|
611
|
+
}
|
|
612
|
+
resourcesDescription += `To read resources, use editor-resource-getter tool.
|
|
613
|
+
|
|
614
|
+
`;
|
|
615
|
+
}
|
|
616
|
+
this.ctx.registerTool({
|
|
617
|
+
name: tool.name,
|
|
618
|
+
description: `${resourcesDescription}${tool.description}`,
|
|
619
|
+
inputSchema: jsonSchema,
|
|
620
|
+
execute: tool.execute
|
|
621
|
+
});
|
|
622
|
+
this.registeredToolNames.add(tool.name);
|
|
623
|
+
}
|
|
624
|
+
onResourceRegistered(_name, uriOrTemplate, handler) {
|
|
625
|
+
if (typeof uriOrTemplate === "string") {
|
|
626
|
+
this.resourceEntries.push({
|
|
627
|
+
pattern: uriOrTemplate,
|
|
628
|
+
match: (uri) => uri === uriOrTemplate ? {} : null,
|
|
629
|
+
handler
|
|
630
|
+
});
|
|
631
|
+
} else {
|
|
632
|
+
const template = uriOrTemplate.uriTemplate;
|
|
633
|
+
this.resourceEntries.push({
|
|
634
|
+
pattern: template.toString(),
|
|
635
|
+
match: (uri) => template.match(uri),
|
|
636
|
+
handler
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
sendResourceUpdated() {
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
// src/init.ts
|
|
645
|
+
function startMCPServer() {
|
|
646
|
+
if (typeof navigator !== "undefined" && "modelContext" in navigator) {
|
|
647
|
+
registerMcpAdapter(
|
|
648
|
+
new WebMCPAdapter(navigator.modelContext)
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
if (isAngieAvailable()) {
|
|
652
|
+
registerMcpAdapter(new AngieMcpAdapter(getSDK()));
|
|
653
|
+
}
|
|
654
|
+
activateAdapters();
|
|
655
|
+
signalMcpReady();
|
|
656
|
+
}
|
|
657
|
+
if (typeof document !== "undefined") {
|
|
658
|
+
document.addEventListener("DOMContentLoaded", () => startMCPServer(), { once: true });
|
|
659
|
+
} else {
|
|
660
|
+
startMCPServer();
|
|
661
|
+
}
|
|
662
|
+
|
|
460
663
|
// src/index.ts
|
|
461
664
|
var getAngieSdk = () => getSDK();
|
|
462
665
|
export {
|
|
@@ -465,19 +668,23 @@ export {
|
|
|
465
668
|
McpServer2 as McpServer,
|
|
466
669
|
ResourceTemplate,
|
|
467
670
|
SamplingMessageSchema2 as SamplingMessageSchema,
|
|
468
|
-
|
|
671
|
+
activateAdapters,
|
|
469
672
|
createSampler,
|
|
673
|
+
getActiveChatInfo,
|
|
470
674
|
getAngieIframe,
|
|
471
675
|
getAngieSdk,
|
|
472
676
|
getMCPByDomain,
|
|
473
|
-
|
|
677
|
+
getRegisteredMcpServers,
|
|
474
678
|
installAngiePlugin,
|
|
475
679
|
isAngieAvailable,
|
|
476
680
|
isAngieSidebarOpen,
|
|
477
681
|
redirectToAppAdmin,
|
|
478
682
|
redirectToInstallation,
|
|
479
683
|
registerMcp,
|
|
684
|
+
registerMcpAdapter,
|
|
480
685
|
sendPromptToAngie,
|
|
686
|
+
signalMcpReady,
|
|
687
|
+
startMCPServer,
|
|
481
688
|
toMCPTitle,
|
|
482
689
|
toolPrompts
|
|
483
690
|
};
|