@elementor/editor-mcp 4.0.0-manual → 4.0.1
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 +22 -5
- package/dist/index.d.ts +22 -5
- package/dist/index.js +156 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/angie-annotations.ts +9 -0
- package/src/index.ts +5 -1
- package/src/mcp-registry.ts +54 -27
- package/src/utils/install-angie-plugin.ts +61 -0
- package/src/utils/is-angie-sidebar-open.ts +5 -0
- package/src/utils/redirect-to-app-admin.ts +13 -0
- package/src/utils/redirect-to-installation.ts +13 -0
- package/src/utils/send-prompt-to-angie.ts +17 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import * as _elementor_external_angie_sdk from '@elementor-external/angie-sdk';
|
|
2
2
|
import { AngieMcpSdk } from '@elementor-external/angie-sdk';
|
|
3
|
-
import { z } from '@elementor/schema';
|
|
4
|
-
export { z as zod } from '@elementor/schema';
|
|
5
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
4
|
export { McpServer, RegisteredResource, ResourceTemplate, ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
7
5
|
import { ServerRequest, ServerNotification } from '@modelcontextprotocol/sdk/types.js';
|
|
8
6
|
export { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { z } from '@elementor/schema';
|
|
9
8
|
import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
10
9
|
|
|
11
10
|
declare function init(): Promise<void>;
|
|
12
11
|
|
|
13
12
|
declare const isAngieAvailable: () => boolean;
|
|
14
13
|
|
|
14
|
+
declare const isAngieSidebarOpen: () => boolean;
|
|
15
|
+
|
|
15
16
|
declare const ANGIE_MODEL_PREFERENCES: "angie/modelPreferences";
|
|
16
17
|
interface AngieModelPreferences {
|
|
17
18
|
hints?: Array<{
|
|
@@ -23,7 +24,8 @@ interface AngieModelPreferences {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
declare const registerMcp: (mcp: McpServer, name: string) => void;
|
|
26
|
-
declare function activateMcpRegistration(sdk: AngieMcpSdk): Promise<void>;
|
|
27
|
+
declare function activateMcpRegistration(sdk: AngieMcpSdk, entries?: [string, McpServer][], retry?: number): Promise<void>;
|
|
28
|
+
declare const toMCPTitle: (namespace: string) => string;
|
|
27
29
|
/**
|
|
28
30
|
*
|
|
29
31
|
* @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.
|
|
@@ -41,7 +43,7 @@ interface MCPRegistryEntry {
|
|
|
41
43
|
expiresAt: number;
|
|
42
44
|
};
|
|
43
45
|
sendResourceUpdated: McpServer['server']['sendResourceUpdated'];
|
|
44
|
-
resource: McpServer['
|
|
46
|
+
resource: McpServer['registerResource'];
|
|
45
47
|
mcpServer: McpServer;
|
|
46
48
|
waitForReady: () => Promise<void>;
|
|
47
49
|
}
|
|
@@ -330,6 +332,21 @@ declare class ToolPrompts {
|
|
|
330
332
|
}
|
|
331
333
|
declare const toolPrompts: (name: string) => ToolPrompts;
|
|
332
334
|
|
|
335
|
+
declare const sendPromptToAngie: (prompt?: string) => void;
|
|
336
|
+
|
|
337
|
+
declare const redirectToInstallation: (prompt: string) => void;
|
|
338
|
+
|
|
339
|
+
declare const redirectToAppAdmin: (prompt: string) => void;
|
|
340
|
+
|
|
341
|
+
type InstallAngieResult = {
|
|
342
|
+
success: true;
|
|
343
|
+
} | {
|
|
344
|
+
success: false;
|
|
345
|
+
error: string;
|
|
346
|
+
code?: string;
|
|
347
|
+
};
|
|
348
|
+
declare const installAngiePlugin: () => Promise<InstallAngieResult>;
|
|
349
|
+
|
|
333
350
|
declare const getAngieSdk: () => _elementor_external_angie_sdk.AngieMcpSdk;
|
|
334
351
|
|
|
335
|
-
export { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences, type MCPRegistryEntry, activateMcpRegistration, createSampler, getAngieSdk, getMCPByDomain, init, isAngieAvailable, registerMcp, toolPrompts };
|
|
352
|
+
export { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences, type InstallAngieResult, type MCPRegistryEntry, activateMcpRegistration, createSampler, getAngieSdk, getMCPByDomain, init, installAngiePlugin, isAngieAvailable, isAngieSidebarOpen, redirectToAppAdmin, redirectToInstallation, registerMcp, sendPromptToAngie, toMCPTitle, toolPrompts };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import * as _elementor_external_angie_sdk from '@elementor-external/angie-sdk';
|
|
2
2
|
import { AngieMcpSdk } from '@elementor-external/angie-sdk';
|
|
3
|
-
import { z } from '@elementor/schema';
|
|
4
|
-
export { z as zod } from '@elementor/schema';
|
|
5
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
4
|
export { McpServer, RegisteredResource, ResourceTemplate, ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
7
5
|
import { ServerRequest, ServerNotification } from '@modelcontextprotocol/sdk/types.js';
|
|
8
6
|
export { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { z } from '@elementor/schema';
|
|
9
8
|
import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
10
9
|
|
|
11
10
|
declare function init(): Promise<void>;
|
|
12
11
|
|
|
13
12
|
declare const isAngieAvailable: () => boolean;
|
|
14
13
|
|
|
14
|
+
declare const isAngieSidebarOpen: () => boolean;
|
|
15
|
+
|
|
15
16
|
declare const ANGIE_MODEL_PREFERENCES: "angie/modelPreferences";
|
|
16
17
|
interface AngieModelPreferences {
|
|
17
18
|
hints?: Array<{
|
|
@@ -23,7 +24,8 @@ interface AngieModelPreferences {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
declare const registerMcp: (mcp: McpServer, name: string) => void;
|
|
26
|
-
declare function activateMcpRegistration(sdk: AngieMcpSdk): Promise<void>;
|
|
27
|
+
declare function activateMcpRegistration(sdk: AngieMcpSdk, entries?: [string, McpServer][], retry?: number): Promise<void>;
|
|
28
|
+
declare const toMCPTitle: (namespace: string) => string;
|
|
27
29
|
/**
|
|
28
30
|
*
|
|
29
31
|
* @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.
|
|
@@ -41,7 +43,7 @@ interface MCPRegistryEntry {
|
|
|
41
43
|
expiresAt: number;
|
|
42
44
|
};
|
|
43
45
|
sendResourceUpdated: McpServer['server']['sendResourceUpdated'];
|
|
44
|
-
resource: McpServer['
|
|
46
|
+
resource: McpServer['registerResource'];
|
|
45
47
|
mcpServer: McpServer;
|
|
46
48
|
waitForReady: () => Promise<void>;
|
|
47
49
|
}
|
|
@@ -330,6 +332,21 @@ declare class ToolPrompts {
|
|
|
330
332
|
}
|
|
331
333
|
declare const toolPrompts: (name: string) => ToolPrompts;
|
|
332
334
|
|
|
335
|
+
declare const sendPromptToAngie: (prompt?: string) => void;
|
|
336
|
+
|
|
337
|
+
declare const redirectToInstallation: (prompt: string) => void;
|
|
338
|
+
|
|
339
|
+
declare const redirectToAppAdmin: (prompt: string) => void;
|
|
340
|
+
|
|
341
|
+
type InstallAngieResult = {
|
|
342
|
+
success: true;
|
|
343
|
+
} | {
|
|
344
|
+
success: false;
|
|
345
|
+
error: string;
|
|
346
|
+
code?: string;
|
|
347
|
+
};
|
|
348
|
+
declare const installAngiePlugin: () => Promise<InstallAngieResult>;
|
|
349
|
+
|
|
333
350
|
declare const getAngieSdk: () => _elementor_external_angie_sdk.AngieMcpSdk;
|
|
334
351
|
|
|
335
|
-
export { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences, type MCPRegistryEntry, activateMcpRegistration, createSampler, getAngieSdk, getMCPByDomain, init, isAngieAvailable, registerMcp, toolPrompts };
|
|
352
|
+
export { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences, type InstallAngieResult, type MCPRegistryEntry, activateMcpRegistration, createSampler, getAngieSdk, getMCPByDomain, init, installAngiePlugin, isAngieAvailable, isAngieSidebarOpen, redirectToAppAdmin, redirectToInstallation, registerMcp, sendPromptToAngie, toMCPTitle, toolPrompts };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -29,10 +39,15 @@ __export(index_exports, {
|
|
|
29
39
|
getAngieSdk: () => getAngieSdk,
|
|
30
40
|
getMCPByDomain: () => getMCPByDomain,
|
|
31
41
|
init: () => init,
|
|
42
|
+
installAngiePlugin: () => installAngiePlugin,
|
|
32
43
|
isAngieAvailable: () => isAngieAvailable,
|
|
44
|
+
isAngieSidebarOpen: () => isAngieSidebarOpen,
|
|
45
|
+
redirectToAppAdmin: () => redirectToAppAdmin,
|
|
46
|
+
redirectToInstallation: () => redirectToInstallation,
|
|
33
47
|
registerMcp: () => registerMcp,
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
sendPromptToAngie: () => sendPromptToAngie,
|
|
49
|
+
toMCPTitle: () => toMCPTitle,
|
|
50
|
+
toolPrompts: () => toolPrompts
|
|
36
51
|
});
|
|
37
52
|
module.exports = __toCommonJS(index_exports);
|
|
38
53
|
|
|
@@ -51,7 +66,6 @@ var getSDK = () => {
|
|
|
51
66
|
};
|
|
52
67
|
|
|
53
68
|
// src/index.ts
|
|
54
|
-
var import_schema2 = require("@elementor/schema");
|
|
55
69
|
var import_mcp2 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
56
70
|
var import_types2 = require("@modelcontextprotocol/sdk/types.js");
|
|
57
71
|
|
|
@@ -64,6 +78,14 @@ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
64
78
|
|
|
65
79
|
// src/angie-annotations.ts
|
|
66
80
|
var ANGIE_MODEL_PREFERENCES = "angie/modelPreferences";
|
|
81
|
+
var ANGIE_REQUIRED_RESOURCES = "angie/requiredResources";
|
|
82
|
+
function createDefaultModelPreferences() {
|
|
83
|
+
return {
|
|
84
|
+
hints: [{ name: "claude-sonnet-4-5" }],
|
|
85
|
+
intelligencePriority: 0.8,
|
|
86
|
+
speedPriority: 0.7
|
|
87
|
+
};
|
|
88
|
+
}
|
|
67
89
|
|
|
68
90
|
// src/test-utils/mock-mcp-registry.ts
|
|
69
91
|
var mock = new Proxy(
|
|
@@ -103,20 +125,31 @@ var registerMcp = (mcp, name) => {
|
|
|
103
125
|
const mcpName = isAlphabet(name);
|
|
104
126
|
mcpRegistry[mcpName] = mcp;
|
|
105
127
|
};
|
|
106
|
-
async function activateMcpRegistration(sdk2) {
|
|
107
|
-
if (
|
|
128
|
+
async function activateMcpRegistration(sdk2, entries = Object.entries(mcpRegistry), retry = 3) {
|
|
129
|
+
if (retry === 0) {
|
|
130
|
+
console.error("Failed to register MCP after 3 retries. failed entries: ", entries);
|
|
108
131
|
return;
|
|
109
132
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
133
|
+
if (entries.length === 0) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const failed = [];
|
|
137
|
+
for await (const entry of entries) {
|
|
113
138
|
const [key, mcpServer] = entry;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
139
|
+
try {
|
|
140
|
+
await sdk2.registerLocalServer({
|
|
141
|
+
title: toMCPTitle(key),
|
|
142
|
+
name: `editor-${key}`,
|
|
143
|
+
server: mcpServer,
|
|
144
|
+
version: "1.0.0",
|
|
145
|
+
description: mcpDescriptions[key] || key
|
|
146
|
+
});
|
|
147
|
+
} catch {
|
|
148
|
+
failed.push(entry);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (failed.length > 0) {
|
|
152
|
+
return activateMcpRegistration(sdk2, failed, retry - 1);
|
|
120
153
|
}
|
|
121
154
|
}
|
|
122
155
|
var isAlphabet = (str) => {
|
|
@@ -126,8 +159,13 @@ var isAlphabet = (str) => {
|
|
|
126
159
|
}
|
|
127
160
|
return str;
|
|
128
161
|
};
|
|
162
|
+
var toMCPTitle = (namespace) => {
|
|
163
|
+
const capitalized = namespace.charAt(0).toUpperCase() + namespace.slice(1);
|
|
164
|
+
return `Editor ${capitalized}`;
|
|
165
|
+
};
|
|
129
166
|
var getMCPByDomain = (namespace, options) => {
|
|
130
167
|
const mcpName = `editor-${isAlphabet(namespace)}`;
|
|
168
|
+
const title = toMCPTitle(namespace);
|
|
131
169
|
if (typeof globalThis.jest !== "undefined") {
|
|
132
170
|
return mockMcpRegistry();
|
|
133
171
|
}
|
|
@@ -135,6 +173,7 @@ var getMCPByDomain = (namespace, options) => {
|
|
|
135
173
|
mcpRegistry[namespace] = new import_mcp.McpServer(
|
|
136
174
|
{
|
|
137
175
|
name: mcpName,
|
|
176
|
+
title,
|
|
138
177
|
version: "1.0.0"
|
|
139
178
|
},
|
|
140
179
|
{
|
|
@@ -149,12 +188,14 @@ var getMCPByDomain = (namespace, options) => {
|
|
|
149
188
|
// @ts-expect-error: TS is unable to infer the type here
|
|
150
189
|
resource: async (...args) => {
|
|
151
190
|
await getSDK().waitForReady();
|
|
152
|
-
return mcpServer.
|
|
191
|
+
return mcpServer.registerResource(...args);
|
|
153
192
|
},
|
|
154
193
|
sendResourceUpdated: (...args) => {
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
|
|
194
|
+
return getSDK().waitForReady().then(() => mcpServer.server.sendResourceUpdated(...args)).catch((error) => {
|
|
195
|
+
if (error?.message?.includes("Not connected")) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
throw error;
|
|
158
199
|
});
|
|
159
200
|
},
|
|
160
201
|
mcpServer,
|
|
@@ -194,7 +235,6 @@ function createToolRegistry(server) {
|
|
|
194
235
|
try {
|
|
195
236
|
const invocationResult = await opts.handler(opts.schema ? args : {}, extra);
|
|
196
237
|
return {
|
|
197
|
-
// TODO: Uncomment this when the outputSchema is stable
|
|
198
238
|
// structuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,
|
|
199
239
|
content: [
|
|
200
240
|
{
|
|
@@ -223,12 +263,10 @@ function createToolRegistry(server) {
|
|
|
223
263
|
readOnlyHint: opts.isDestructive ? false : void 0,
|
|
224
264
|
title: opts.name
|
|
225
265
|
};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
annotations[ANGIE_MODEL_PREFERENCES] = opts.modelPreferences;
|
|
231
|
-
}
|
|
266
|
+
const angieAnnotations = {
|
|
267
|
+
[ANGIE_MODEL_PREFERENCES]: opts.modelPreferences ?? createDefaultModelPreferences(),
|
|
268
|
+
[ANGIE_REQUIRED_RESOURCES]: opts.requiredResources ?? void 0
|
|
269
|
+
};
|
|
232
270
|
server.registerTool(
|
|
233
271
|
opts.name,
|
|
234
272
|
{
|
|
@@ -237,7 +275,8 @@ function createToolRegistry(server) {
|
|
|
237
275
|
// TODO: Uncomment this when the outputSchema is stable
|
|
238
276
|
// outputSchema,
|
|
239
277
|
title: opts.name,
|
|
240
|
-
annotations
|
|
278
|
+
annotations,
|
|
279
|
+
_meta: angieAnnotations
|
|
241
280
|
},
|
|
242
281
|
toolCallback
|
|
243
282
|
);
|
|
@@ -280,6 +319,12 @@ document.addEventListener(
|
|
|
280
319
|
}
|
|
281
320
|
);
|
|
282
321
|
|
|
322
|
+
// src/utils/is-angie-sidebar-open.ts
|
|
323
|
+
var import_angie_sdk3 = require("@elementor-external/angie-sdk");
|
|
324
|
+
var isAngieSidebarOpen = () => {
|
|
325
|
+
return (0, import_angie_sdk3.getAngieSidebarSavedState)() === import_angie_sdk3.ANGIE_SIDEBAR_STATE_OPEN;
|
|
326
|
+
};
|
|
327
|
+
|
|
283
328
|
// src/sampler.ts
|
|
284
329
|
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
285
330
|
var DEFAULT_OPTS = {
|
|
@@ -383,6 +428,84 @@ var toolPrompts = (name) => {
|
|
|
383
428
|
return new ToolPrompts(name);
|
|
384
429
|
};
|
|
385
430
|
|
|
431
|
+
// src/utils/send-prompt-to-angie.ts
|
|
432
|
+
var import_angie_sdk4 = require("@elementor-external/angie-sdk");
|
|
433
|
+
var sendPromptToAngie = (prompt) => {
|
|
434
|
+
const angieSidebar = (0, import_angie_sdk4.getAngieIframe)();
|
|
435
|
+
if (!angieSidebar) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
(0, import_angie_sdk4.toggleAngieSidebar)(angieSidebar, true);
|
|
439
|
+
if (!prompt) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
window.location.hash = `angie-prompt=${encodeURIComponent(prompt)}`;
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
// src/utils/redirect-to-installation.ts
|
|
446
|
+
var import_angie_sdk5 = require("@elementor-external/angie-sdk");
|
|
447
|
+
var ANGIE_INSTALL_URL = "/wp-admin/plugin-install.php?s=angie&tab=search&type=term";
|
|
448
|
+
var redirectToInstallation = (prompt) => {
|
|
449
|
+
const success = (0, import_angie_sdk5.setReferrerRedirect)(window.location.href, prompt);
|
|
450
|
+
if (!success) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
window.location.href = ANGIE_INSTALL_URL;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
// src/utils/redirect-to-app-admin.ts
|
|
457
|
+
var import_angie_sdk6 = require("@elementor-external/angie-sdk");
|
|
458
|
+
var ANGIE_APP_URL = "/wp-admin/admin.php?page=angie-app";
|
|
459
|
+
var redirectToAppAdmin = (prompt) => {
|
|
460
|
+
const success = (0, import_angie_sdk6.setReferrerRedirect)(window.location.href, prompt);
|
|
461
|
+
if (!success) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
window.location.href = ANGIE_APP_URL;
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// src/utils/install-angie-plugin.ts
|
|
468
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
469
|
+
var ANGIE_SLUG = "angie";
|
|
470
|
+
var isPluginErrorResponse = (response) => {
|
|
471
|
+
return typeof response === "object" && response !== null && "code" in response && "message" in response;
|
|
472
|
+
};
|
|
473
|
+
var activatePlugin = async (pluginPath) => {
|
|
474
|
+
return (0, import_api_fetch.default)({
|
|
475
|
+
path: `/wp/v2/plugins/${pluginPath}`,
|
|
476
|
+
method: "POST",
|
|
477
|
+
data: { status: "active" }
|
|
478
|
+
});
|
|
479
|
+
};
|
|
480
|
+
var installPlugin = async () => {
|
|
481
|
+
try {
|
|
482
|
+
return await (0, import_api_fetch.default)({
|
|
483
|
+
path: "/wp/v2/plugins",
|
|
484
|
+
method: "POST",
|
|
485
|
+
data: {
|
|
486
|
+
slug: ANGIE_SLUG,
|
|
487
|
+
status: "active"
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
} catch (error) {
|
|
491
|
+
if (isPluginErrorResponse(error) && error.code === "folder_exists") {
|
|
492
|
+
return activatePlugin(`${ANGIE_SLUG}/${ANGIE_SLUG}`);
|
|
493
|
+
}
|
|
494
|
+
throw error;
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
var installAngiePlugin = async () => {
|
|
498
|
+
try {
|
|
499
|
+
await installPlugin();
|
|
500
|
+
return { success: true };
|
|
501
|
+
} catch (error) {
|
|
502
|
+
if (isPluginErrorResponse(error)) {
|
|
503
|
+
return { success: false, error: error.message, code: error.code };
|
|
504
|
+
}
|
|
505
|
+
return { success: false, error: "Unknown error occurred" };
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
|
|
386
509
|
// src/index.ts
|
|
387
510
|
var getAngieSdk = () => getSDK();
|
|
388
511
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -396,9 +519,14 @@ var getAngieSdk = () => getSDK();
|
|
|
396
519
|
getAngieSdk,
|
|
397
520
|
getMCPByDomain,
|
|
398
521
|
init,
|
|
522
|
+
installAngiePlugin,
|
|
399
523
|
isAngieAvailable,
|
|
524
|
+
isAngieSidebarOpen,
|
|
525
|
+
redirectToAppAdmin,
|
|
526
|
+
redirectToInstallation,
|
|
400
527
|
registerMcp,
|
|
401
|
-
|
|
402
|
-
|
|
528
|
+
sendPromptToAngie,
|
|
529
|
+
toMCPTitle,
|
|
530
|
+
toolPrompts
|
|
403
531
|
});
|
|
404
532
|
//# sourceMappingURL=index.js.map
|
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/sampler.ts","../src/utils/prompt-builder.ts"],"sourcesContent":["import { getSDK } from './utils/get-sdk';\nexport { z as zod } from '@elementor/schema';\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 * from './mcp-registry';\nexport { createSampler } from './sampler';\nexport { toolPrompts } from './utils/prompt-builder';\nexport { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';\nexport const getAngieSdk = () => getSDK();\n","import { AngieMcpSdk } 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 { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } 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\nlet 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 ) {\n\tif ( isMcpRegistrationActivated ) {\n\t\treturn;\n\t}\n\tisMcpRegistrationActivated = true;\n\tconst mcpServerList = Object.entries( mcpRegistry );\n\tfor await ( const entry of mcpServerList ) {\n\t\tconst [ key, mcpServer ] = entry;\n\t\tawait sdk.registerLocalServer( {\n\t\t\tname: `editor-${ key }`,\n\t\t\tserver: mcpServer,\n\t\t\tversion: '1.0.0',\n\t\t\tdescription: mcpDescriptions[ key ] || key,\n\t\t} );\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\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\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\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[ 'resource' ] > ) => {\n\t\t\tawait getSDK().waitForReady();\n\t\t\treturn mcpServer.resource( ...args );\n\t\t},\n\t\tsendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {\n\t\t\treturn new Promise( async () => {\n\t\t\t\tawait getSDK().waitForReady();\n\t\t\t\tmcpServer.server.sendResourceUpdated( ...args );\n\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[ 'resource' ];\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// TODO: Uncomment this when the outputSchema is stable\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\tif ( opts.requiredResources ) {\n\t\t\tannotations[ 'angie/requiredResources' ] = opts.requiredResources;\n\t\t}\n\t\tif ( opts.modelPreferences ) {\n\t\t\tannotations[ ANGIE_MODEL_PREFERENCES ] = opts.modelPreferences;\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},\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;\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","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 { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAA4B;AAE5B,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;;;ADbA,IAAAA,iBAAyB;AAEzB,IAAAC,cAKO;AACP,IAAAC,gBAAsC;;;AETtC,gCAAmC;;;ACAnC,oBAA2B;AA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E,KAAM,MAAO,CAAE;AAAA;AAAA,EAEjD,KAAK,UAAU,SAAS,eAAe,EAAG;AAAA,EAC1C,KAAK,QAAS;AAAA;AAAA,EAEd,KAAK,qBAAqB,SAAS,2BAA2B,EAAG;AAAA,EACjE,KAAK,qBAAqB,KAAM,MAAO,CAAE;AAAA,EAC1C,KAAK;AAAA,EACN;AACD;AAEO,IAAM,cAAc,CAAE,SAAkB;AAC9C,SAAO,IAAI,YAAa,IAAK;AAC9B;;;AR7CO,IAAM,cAAc,MAAM,OAAO;","names":["import_schema","import_mcp","import_types","sdk","import_angie_sdk","sdk"]}
|
|
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';\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';\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;;;ACAA,uBAA4B;AAE5B,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,IAAAA,cAKO;AACP,IAAAC,gBAAsC;;;AERtC,gCAAmC;;;ACAnC,oBAA2B;AAE3B,iBAA6C;;;ACFtC,IAAM,0BAA0B;AAChC,IAAM,2BAA2B;AASjC,SAAS,gCAAuD;AACtE,SAAO;AAAA,IACN,OAAO,CAAE,EAAE,MAAM,oBAAoB,CAAE;AAAA,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M,MAAM,KAAK;AAAA,IACjE;AAEA,WAAO,EAAE,SAAS,OAAO,OAAO,yBAAyB;AAAA,EAC1D;AACD;;;AbxCO,IAAM,cAAc,MAAM,OAAO;","names":["import_mcp","import_types","sdk","import_angie_sdk","sdk","import_angie_sdk","import_angie_sdk","import_angie_sdk","import_angie_sdk","apiFetch"]}
|
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,6 @@ var getSDK = () => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
// src/index.ts
|
|
16
|
-
import { z as z2 } from "@elementor/schema";
|
|
17
16
|
import {
|
|
18
17
|
McpServer as McpServer2,
|
|
19
18
|
ResourceTemplate
|
|
@@ -29,6 +28,14 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
29
28
|
|
|
30
29
|
// src/angie-annotations.ts
|
|
31
30
|
var ANGIE_MODEL_PREFERENCES = "angie/modelPreferences";
|
|
31
|
+
var ANGIE_REQUIRED_RESOURCES = "angie/requiredResources";
|
|
32
|
+
function createDefaultModelPreferences() {
|
|
33
|
+
return {
|
|
34
|
+
hints: [{ name: "claude-sonnet-4-5" }],
|
|
35
|
+
intelligencePriority: 0.8,
|
|
36
|
+
speedPriority: 0.7
|
|
37
|
+
};
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
// src/test-utils/mock-mcp-registry.ts
|
|
34
41
|
var mock = new Proxy(
|
|
@@ -68,20 +75,31 @@ var registerMcp = (mcp, name) => {
|
|
|
68
75
|
const mcpName = isAlphabet(name);
|
|
69
76
|
mcpRegistry[mcpName] = mcp;
|
|
70
77
|
};
|
|
71
|
-
async function activateMcpRegistration(sdk2) {
|
|
72
|
-
if (
|
|
78
|
+
async function activateMcpRegistration(sdk2, entries = Object.entries(mcpRegistry), retry = 3) {
|
|
79
|
+
if (retry === 0) {
|
|
80
|
+
console.error("Failed to register MCP after 3 retries. failed entries: ", entries);
|
|
73
81
|
return;
|
|
74
82
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
if (entries.length === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const failed = [];
|
|
87
|
+
for await (const entry of entries) {
|
|
78
88
|
const [key, mcpServer] = entry;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
try {
|
|
90
|
+
await sdk2.registerLocalServer({
|
|
91
|
+
title: toMCPTitle(key),
|
|
92
|
+
name: `editor-${key}`,
|
|
93
|
+
server: mcpServer,
|
|
94
|
+
version: "1.0.0",
|
|
95
|
+
description: mcpDescriptions[key] || key
|
|
96
|
+
});
|
|
97
|
+
} catch {
|
|
98
|
+
failed.push(entry);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (failed.length > 0) {
|
|
102
|
+
return activateMcpRegistration(sdk2, failed, retry - 1);
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
105
|
var isAlphabet = (str) => {
|
|
@@ -91,8 +109,13 @@ var isAlphabet = (str) => {
|
|
|
91
109
|
}
|
|
92
110
|
return str;
|
|
93
111
|
};
|
|
112
|
+
var toMCPTitle = (namespace) => {
|
|
113
|
+
const capitalized = namespace.charAt(0).toUpperCase() + namespace.slice(1);
|
|
114
|
+
return `Editor ${capitalized}`;
|
|
115
|
+
};
|
|
94
116
|
var getMCPByDomain = (namespace, options) => {
|
|
95
117
|
const mcpName = `editor-${isAlphabet(namespace)}`;
|
|
118
|
+
const title = toMCPTitle(namespace);
|
|
96
119
|
if (typeof globalThis.jest !== "undefined") {
|
|
97
120
|
return mockMcpRegistry();
|
|
98
121
|
}
|
|
@@ -100,6 +123,7 @@ var getMCPByDomain = (namespace, options) => {
|
|
|
100
123
|
mcpRegistry[namespace] = new McpServer(
|
|
101
124
|
{
|
|
102
125
|
name: mcpName,
|
|
126
|
+
title,
|
|
103
127
|
version: "1.0.0"
|
|
104
128
|
},
|
|
105
129
|
{
|
|
@@ -114,12 +138,14 @@ var getMCPByDomain = (namespace, options) => {
|
|
|
114
138
|
// @ts-expect-error: TS is unable to infer the type here
|
|
115
139
|
resource: async (...args) => {
|
|
116
140
|
await getSDK().waitForReady();
|
|
117
|
-
return mcpServer.
|
|
141
|
+
return mcpServer.registerResource(...args);
|
|
118
142
|
},
|
|
119
143
|
sendResourceUpdated: (...args) => {
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
144
|
+
return getSDK().waitForReady().then(() => mcpServer.server.sendResourceUpdated(...args)).catch((error) => {
|
|
145
|
+
if (error?.message?.includes("Not connected")) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
123
149
|
});
|
|
124
150
|
},
|
|
125
151
|
mcpServer,
|
|
@@ -159,7 +185,6 @@ function createToolRegistry(server) {
|
|
|
159
185
|
try {
|
|
160
186
|
const invocationResult = await opts.handler(opts.schema ? args : {}, extra);
|
|
161
187
|
return {
|
|
162
|
-
// TODO: Uncomment this when the outputSchema is stable
|
|
163
188
|
// structuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,
|
|
164
189
|
content: [
|
|
165
190
|
{
|
|
@@ -188,12 +213,10 @@ function createToolRegistry(server) {
|
|
|
188
213
|
readOnlyHint: opts.isDestructive ? false : void 0,
|
|
189
214
|
title: opts.name
|
|
190
215
|
};
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
annotations[ANGIE_MODEL_PREFERENCES] = opts.modelPreferences;
|
|
196
|
-
}
|
|
216
|
+
const angieAnnotations = {
|
|
217
|
+
[ANGIE_MODEL_PREFERENCES]: opts.modelPreferences ?? createDefaultModelPreferences(),
|
|
218
|
+
[ANGIE_REQUIRED_RESOURCES]: opts.requiredResources ?? void 0
|
|
219
|
+
};
|
|
197
220
|
server.registerTool(
|
|
198
221
|
opts.name,
|
|
199
222
|
{
|
|
@@ -202,7 +225,8 @@ function createToolRegistry(server) {
|
|
|
202
225
|
// TODO: Uncomment this when the outputSchema is stable
|
|
203
226
|
// outputSchema,
|
|
204
227
|
title: opts.name,
|
|
205
|
-
annotations
|
|
228
|
+
annotations,
|
|
229
|
+
_meta: angieAnnotations
|
|
206
230
|
},
|
|
207
231
|
toolCallback
|
|
208
232
|
);
|
|
@@ -245,6 +269,12 @@ document.addEventListener(
|
|
|
245
269
|
}
|
|
246
270
|
);
|
|
247
271
|
|
|
272
|
+
// src/utils/is-angie-sidebar-open.ts
|
|
273
|
+
import { ANGIE_SIDEBAR_STATE_OPEN, getAngieSidebarSavedState } from "@elementor-external/angie-sdk";
|
|
274
|
+
var isAngieSidebarOpen = () => {
|
|
275
|
+
return getAngieSidebarSavedState() === ANGIE_SIDEBAR_STATE_OPEN;
|
|
276
|
+
};
|
|
277
|
+
|
|
248
278
|
// src/sampler.ts
|
|
249
279
|
import { SamplingMessageSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
250
280
|
var DEFAULT_OPTS = {
|
|
@@ -348,6 +378,84 @@ var toolPrompts = (name) => {
|
|
|
348
378
|
return new ToolPrompts(name);
|
|
349
379
|
};
|
|
350
380
|
|
|
381
|
+
// src/utils/send-prompt-to-angie.ts
|
|
382
|
+
import { getAngieIframe as getAngieIframe2, toggleAngieSidebar } from "@elementor-external/angie-sdk";
|
|
383
|
+
var sendPromptToAngie = (prompt) => {
|
|
384
|
+
const angieSidebar = getAngieIframe2();
|
|
385
|
+
if (!angieSidebar) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
toggleAngieSidebar(angieSidebar, true);
|
|
389
|
+
if (!prompt) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
window.location.hash = `angie-prompt=${encodeURIComponent(prompt)}`;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// src/utils/redirect-to-installation.ts
|
|
396
|
+
import { setReferrerRedirect } from "@elementor-external/angie-sdk";
|
|
397
|
+
var ANGIE_INSTALL_URL = "/wp-admin/plugin-install.php?s=angie&tab=search&type=term";
|
|
398
|
+
var redirectToInstallation = (prompt) => {
|
|
399
|
+
const success = setReferrerRedirect(window.location.href, prompt);
|
|
400
|
+
if (!success) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
window.location.href = ANGIE_INSTALL_URL;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// src/utils/redirect-to-app-admin.ts
|
|
407
|
+
import { setReferrerRedirect as setReferrerRedirect2 } from "@elementor-external/angie-sdk";
|
|
408
|
+
var ANGIE_APP_URL = "/wp-admin/admin.php?page=angie-app";
|
|
409
|
+
var redirectToAppAdmin = (prompt) => {
|
|
410
|
+
const success = setReferrerRedirect2(window.location.href, prompt);
|
|
411
|
+
if (!success) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
window.location.href = ANGIE_APP_URL;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// src/utils/install-angie-plugin.ts
|
|
418
|
+
import apiFetch from "@wordpress/api-fetch";
|
|
419
|
+
var ANGIE_SLUG = "angie";
|
|
420
|
+
var isPluginErrorResponse = (response) => {
|
|
421
|
+
return typeof response === "object" && response !== null && "code" in response && "message" in response;
|
|
422
|
+
};
|
|
423
|
+
var activatePlugin = async (pluginPath) => {
|
|
424
|
+
return apiFetch({
|
|
425
|
+
path: `/wp/v2/plugins/${pluginPath}`,
|
|
426
|
+
method: "POST",
|
|
427
|
+
data: { status: "active" }
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
var installPlugin = async () => {
|
|
431
|
+
try {
|
|
432
|
+
return await apiFetch({
|
|
433
|
+
path: "/wp/v2/plugins",
|
|
434
|
+
method: "POST",
|
|
435
|
+
data: {
|
|
436
|
+
slug: ANGIE_SLUG,
|
|
437
|
+
status: "active"
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
} catch (error) {
|
|
441
|
+
if (isPluginErrorResponse(error) && error.code === "folder_exists") {
|
|
442
|
+
return activatePlugin(`${ANGIE_SLUG}/${ANGIE_SLUG}`);
|
|
443
|
+
}
|
|
444
|
+
throw error;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
var installAngiePlugin = async () => {
|
|
448
|
+
try {
|
|
449
|
+
await installPlugin();
|
|
450
|
+
return { success: true };
|
|
451
|
+
} catch (error) {
|
|
452
|
+
if (isPluginErrorResponse(error)) {
|
|
453
|
+
return { success: false, error: error.message, code: error.code };
|
|
454
|
+
}
|
|
455
|
+
return { success: false, error: "Unknown error occurred" };
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
|
|
351
459
|
// src/index.ts
|
|
352
460
|
var getAngieSdk = () => getSDK();
|
|
353
461
|
export {
|
|
@@ -360,9 +468,14 @@ export {
|
|
|
360
468
|
getAngieSdk,
|
|
361
469
|
getMCPByDomain,
|
|
362
470
|
init,
|
|
471
|
+
installAngiePlugin,
|
|
363
472
|
isAngieAvailable,
|
|
473
|
+
isAngieSidebarOpen,
|
|
474
|
+
redirectToAppAdmin,
|
|
475
|
+
redirectToInstallation,
|
|
364
476
|
registerMcp,
|
|
365
|
-
|
|
366
|
-
|
|
477
|
+
sendPromptToAngie,
|
|
478
|
+
toMCPTitle,
|
|
479
|
+
toolPrompts
|
|
367
480
|
};
|
|
368
481
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/get-sdk.ts","../src/index.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/sampler.ts","../src/utils/prompt-builder.ts"],"sourcesContent":["import { AngieMcpSdk } 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 { getSDK } from './utils/get-sdk';\nexport { z as zod } from '@elementor/schema';\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 * from './mcp-registry';\nexport { createSampler } from './sampler';\nexport { toolPrompts } from './utils/prompt-builder';\nexport { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';\nexport const getAngieSdk = () => getSDK();\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 { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } 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\nlet 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 ) {\n\tif ( isMcpRegistrationActivated ) {\n\t\treturn;\n\t}\n\tisMcpRegistrationActivated = true;\n\tconst mcpServerList = Object.entries( mcpRegistry );\n\tfor await ( const entry of mcpServerList ) {\n\t\tconst [ key, mcpServer ] = entry;\n\t\tawait sdk.registerLocalServer( {\n\t\t\tname: `editor-${ key }`,\n\t\t\tserver: mcpServer,\n\t\t\tversion: '1.0.0',\n\t\t\tdescription: mcpDescriptions[ key ] || key,\n\t\t} );\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\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\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\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[ 'resource' ] > ) => {\n\t\t\tawait getSDK().waitForReady();\n\t\t\treturn mcpServer.resource( ...args );\n\t\t},\n\t\tsendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {\n\t\t\treturn new Promise( async () => {\n\t\t\t\tawait getSDK().waitForReady();\n\t\t\t\tmcpServer.server.sendResourceUpdated( ...args );\n\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[ 'resource' ];\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// TODO: Uncomment this when the outputSchema is stable\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\tif ( opts.requiredResources ) {\n\t\t\tannotations[ 'angie/requiredResources' ] = opts.requiredResources;\n\t\t}\n\t\tif ( opts.modelPreferences ) {\n\t\t\tannotations[ ANGIE_MODEL_PREFERENCES ] = opts.modelPreferences;\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},\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;\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","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 { 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"],"mappings":";AAAA,SAAS,mBAAmB;AAE5B,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,YAAY;AAAA,EACvB;AACA,SAAO;AACR;;;ACbA,SAAc,KAALA,UAAgB;AAEzB;AAAA,EACC,aAAAC;AAAA,EACA;AAAA,OAGM;AACP,SAAS,yBAAAC,8BAA6B;;;ACTtC,SAAS,0BAA0B;;;ACAnC,SAAS,SAAkB;AAE3B,SAAS,iBAAoC;;;ACFtC,IAAM,0BAA0B;;;ACIvC,IAAM,OAAO,IAAI;AAAA,EAChB,CAAC;AAAA,EACD;AAAA,IACC,KAAK,MAAM;AAEV,eAAS,YAAa,GAAe;AAAA,MAAC;AACtC,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEO,IAAM,kBAAkB,MAAwB;AACtD,SAAO;AAAA;AAAA,IAEN,UAAU,YAAY;AAAA,IAAC;AAAA;AAAA,IAEvB,qBAAqB,MAAM;AAAA,I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,cAAc,MAAM,OAAO;","names":["z","McpServer","SamplingMessageSchema","sdk","sdk"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/get-sdk.ts","../src/index.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 { AngieMcpSdk } 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 { getSDK } 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 { 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,SAAS,mBAAmB;AAE5B,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,YAAY;AAAA,EACvB;AACA,SAAO;AACR;;;ACZA;AAAA,EACC,aAAAA;AAAA,EACA;AAAA,OAGM;AACP,SAAS,yBAAAC,8BAA6B;;;ACRtC,SAAS,0BAA0B;;;ACAnC,SAAS,SAAkB;AAE3B,SAAS,iBAAoC;;;ACFtC,IAAM,0BAA0B;AAChC,IAAM,2BAA2B;AASjC,SAAS,gCAAuD;AACtE,SAAO;AAAA,IACN,OAAO,CAAE,EAAE,MAAM,oBAAoB,CAAE;AAAA,IACvC,sBAAsB;AAAA,IACtB,eAAe;AAAA,EAChB;AACD;;;ACZA,IAAM,OAAO,IAAI;AAAA,EAChB,CAAC;AAAA,EACD;AAAA,IACC,KAAK,MAAM;AAEV,eAAS,YAAa,GAAe;AAAA,MAAC;AACtC,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEO,IAAM,kBAAkB,MAAwB;AACtD,SAAO;AAAA;AAAA,IAEN,UAAU,YAAY;AAAA,IAAC;AAAA;AAAA,IAEvB,qBAAqB,MAAM;AAAA,IAAC;AAAA,IAC5B,SAAS,MAAM;AAAA,IAAC;AAAA,IAChB,mBAAmB,MAAM;AAAA,IAAC;AAAA,IAC1B,oBAAoB;AACn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Aa;AAEnB,IAAM,wBAAwB,CAAE,aAAwD;AACvF,SAAO,OAAO,aAAa,YAAY,aAAa,QAAQ,UAAU,YAAY,aAAa;AAChG;AAEA,IAAM,iBAAiB,OAAQ,eAAmD;AACjF,SAAO,SAA4B;AAAA,IAClC,MAAM,kBAAmB,UAAW;AAAA,IACpC,QAAQ;AAAA,IACR,MAAM,EAAE,QAAQ,SAAS;AAAA,EAC1B,CAAE;AACH;AAEA,IAAM,gBAAgB,YAAuC;AAC5D,MAAI;AACH,WAAO,MAAM,SAA4B;AAAA,MACxC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,QACL,MAAM;AAAA,QACN,QAAQ;AAAA,MACT;AAAA,IACD,CAAE;AAAA,EACH,SAAU,OAAiB;AAC1B,QAAK,sBAAuB,KAAM,KAAK,MAAM,SAAS,iBAAkB;AACvE,aAAO,eAAgB,GAAI,UAAW,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;;;AZxCO,IAAM,cAAc,MAAM,OAAO;","names":["McpServer","SamplingMessageSchema","sdk","sdk","getAngieIframe","setReferrerRedirect"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-mcp",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -42,11 +42,12 @@
|
|
|
42
42
|
"tsup": "^8.3.5"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@elementor-external/angie-sdk": "npm:@elementor/angie-sdk@^1.
|
|
46
|
-
"@elementor/editor-v1-adapters": "4.0.
|
|
47
|
-
"@elementor/schema": "4.0.
|
|
48
|
-
"@elementor/store": "4.0.
|
|
45
|
+
"@elementor-external/angie-sdk": "npm:@elementor/angie-sdk@^1.4.5",
|
|
46
|
+
"@elementor/editor-v1-adapters": "4.0.1",
|
|
47
|
+
"@elementor/schema": "4.0.1",
|
|
48
|
+
"@elementor/store": "4.0.1",
|
|
49
49
|
"@modelcontextprotocol/sdk": "1.27.1",
|
|
50
|
+
"@wordpress/api-fetch": "^6.42.0",
|
|
50
51
|
"zod-to-json-schema": "3.24.6"
|
|
51
52
|
}
|
|
52
53
|
}
|
package/src/angie-annotations.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const ANGIE_MODEL_PREFERENCES = 'angie/modelPreferences' as const;
|
|
2
|
+
export const ANGIE_REQUIRED_RESOURCES = 'angie/requiredResources' as const;
|
|
2
3
|
|
|
3
4
|
export interface AngieModelPreferences {
|
|
4
5
|
hints?: Array< { name: string } >;
|
|
@@ -6,3 +7,11 @@ export interface AngieModelPreferences {
|
|
|
6
7
|
speedPriority?: number; // 0-1 (future use)
|
|
7
8
|
intelligencePriority?: number; // 0-1 (future use)
|
|
8
9
|
}
|
|
10
|
+
|
|
11
|
+
export function createDefaultModelPreferences(): AngieModelPreferences {
|
|
12
|
+
return {
|
|
13
|
+
hints: [ { name: 'claude-sonnet-4-5' } ],
|
|
14
|
+
intelligencePriority: 0.8,
|
|
15
|
+
speedPriority: 0.7,
|
|
16
|
+
};
|
|
17
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getSDK } from './utils/get-sdk';
|
|
2
|
-
export { z as zod } from '@elementor/schema';
|
|
3
2
|
|
|
4
3
|
export {
|
|
5
4
|
McpServer,
|
|
@@ -10,8 +9,13 @@ export {
|
|
|
10
9
|
export { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
11
10
|
export { init } from './init';
|
|
12
11
|
export { isAngieAvailable } from './utils/is-angie-available';
|
|
12
|
+
export { isAngieSidebarOpen } from './utils/is-angie-sidebar-open';
|
|
13
13
|
export * from './mcp-registry';
|
|
14
14
|
export { createSampler } from './sampler';
|
|
15
15
|
export { toolPrompts } from './utils/prompt-builder';
|
|
16
16
|
export { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';
|
|
17
|
+
export { sendPromptToAngie } from './utils/send-prompt-to-angie';
|
|
18
|
+
export { redirectToInstallation } from './utils/redirect-to-installation';
|
|
19
|
+
export { redirectToAppAdmin } from './utils/redirect-to-app-admin';
|
|
20
|
+
export { installAngiePlugin, type InstallAngieResult } from './utils/install-angie-plugin';
|
|
17
21
|
export const getAngieSdk = () => getSDK();
|
package/src/mcp-registry.ts
CHANGED
|
@@ -4,7 +4,12 @@ import { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/m
|
|
|
4
4
|
import { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
5
5
|
import { type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ANGIE_MODEL_PREFERENCES,
|
|
9
|
+
ANGIE_REQUIRED_RESOURCES,
|
|
10
|
+
type AngieModelPreferences,
|
|
11
|
+
createDefaultModelPreferences,
|
|
12
|
+
} from './angie-annotations';
|
|
8
13
|
import { mockMcpRegistry } from './test-utils/mock-mcp-registry';
|
|
9
14
|
import { getSDK } from './utils/get-sdk';
|
|
10
15
|
|
|
@@ -13,27 +18,39 @@ type ZodRawShape = z3.ZodRawShape;
|
|
|
13
18
|
const mcpRegistry: { [ namespace: string ]: McpServer } = {};
|
|
14
19
|
const mcpDescriptions: { [ namespace: string ]: string } = {};
|
|
15
20
|
// @ts-ignore - QUnit fails this
|
|
16
|
-
|
|
21
|
+
const isMcpRegistrationActivated = false || typeof globalThis.jest !== 'undefined';
|
|
17
22
|
|
|
18
23
|
export const registerMcp = ( mcp: McpServer, name: string ) => {
|
|
19
24
|
const mcpName = isAlphabet( name );
|
|
20
25
|
mcpRegistry[ mcpName ] = mcp;
|
|
21
26
|
};
|
|
22
27
|
|
|
23
|
-
export async function activateMcpRegistration( sdk: AngieMcpSdk ) {
|
|
24
|
-
if (
|
|
28
|
+
export async function activateMcpRegistration( sdk: AngieMcpSdk, entries = Object.entries( mcpRegistry ), retry = 3 ) {
|
|
29
|
+
if ( retry === 0 ) {
|
|
30
|
+
/* eslint-disable-next-line no-console */
|
|
31
|
+
console.error( 'Failed to register MCP after 3 retries. failed entries: ', entries );
|
|
25
32
|
return;
|
|
26
33
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
if ( entries.length === 0 ) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const failed = [];
|
|
38
|
+
for await ( const entry of entries ) {
|
|
30
39
|
const [ key, mcpServer ] = entry;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
try {
|
|
41
|
+
await sdk.registerLocalServer( {
|
|
42
|
+
title: toMCPTitle( key ),
|
|
43
|
+
name: `editor-${ key }`,
|
|
44
|
+
server: mcpServer,
|
|
45
|
+
version: '1.0.0',
|
|
46
|
+
description: mcpDescriptions[ key ] || key,
|
|
47
|
+
} );
|
|
48
|
+
} catch {
|
|
49
|
+
failed.push( entry );
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if ( failed.length > 0 ) {
|
|
53
|
+
return activateMcpRegistration( sdk, failed, retry - 1 );
|
|
37
54
|
}
|
|
38
55
|
}
|
|
39
56
|
|
|
@@ -45,6 +62,11 @@ const isAlphabet = ( str: string ): string | never => {
|
|
|
45
62
|
return str;
|
|
46
63
|
};
|
|
47
64
|
|
|
65
|
+
export const toMCPTitle = ( namespace: string ): string => {
|
|
66
|
+
const capitalized = namespace.charAt( 0 ).toUpperCase() + namespace.slice( 1 );
|
|
67
|
+
return `Editor ${ capitalized }`;
|
|
68
|
+
};
|
|
69
|
+
|
|
48
70
|
/**
|
|
49
71
|
*
|
|
50
72
|
* @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.
|
|
@@ -53,6 +75,7 @@ const isAlphabet = ( str: string ): string | never => {
|
|
|
53
75
|
*/
|
|
54
76
|
export const getMCPByDomain = ( namespace: string, options?: { instructions?: string } ): MCPRegistryEntry => {
|
|
55
77
|
const mcpName = `editor-${ isAlphabet( namespace ) }`;
|
|
78
|
+
const title = toMCPTitle( namespace );
|
|
56
79
|
// @ts-ignore - QUnit fails this
|
|
57
80
|
if ( typeof globalThis.jest !== 'undefined' ) {
|
|
58
81
|
return mockMcpRegistry();
|
|
@@ -61,6 +84,7 @@ export const getMCPByDomain = ( namespace: string, options?: { instructions?: st
|
|
|
61
84
|
mcpRegistry[ namespace ] = new McpServer(
|
|
62
85
|
{
|
|
63
86
|
name: mcpName,
|
|
87
|
+
title,
|
|
64
88
|
version: '1.0.0',
|
|
65
89
|
},
|
|
66
90
|
{
|
|
@@ -73,15 +97,20 @@ export const getMCPByDomain = ( namespace: string, options?: { instructions?: st
|
|
|
73
97
|
return {
|
|
74
98
|
waitForReady: () => getSDK().waitForReady(),
|
|
75
99
|
// @ts-expect-error: TS is unable to infer the type here
|
|
76
|
-
resource: async ( ...args: Parameters< McpServer[ '
|
|
100
|
+
resource: async ( ...args: Parameters< McpServer[ 'registerResource' ] > ) => {
|
|
77
101
|
await getSDK().waitForReady();
|
|
78
|
-
return mcpServer.
|
|
102
|
+
return mcpServer.registerResource( ...args );
|
|
79
103
|
},
|
|
80
104
|
sendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
mcpServer.server.sendResourceUpdated( ...args )
|
|
84
|
-
|
|
105
|
+
return getSDK()
|
|
106
|
+
.waitForReady()
|
|
107
|
+
.then( () => mcpServer.server.sendResourceUpdated( ...args ) )
|
|
108
|
+
.catch( ( error: Error ) => {
|
|
109
|
+
if ( error?.message?.includes( 'Not connected' ) ) {
|
|
110
|
+
return; // Expected when no MCP client is connected yet
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
} );
|
|
85
114
|
},
|
|
86
115
|
mcpServer,
|
|
87
116
|
addTool,
|
|
@@ -112,7 +141,7 @@ export interface MCPRegistryEntry {
|
|
|
112
141
|
setMCPDescription: ( description: string ) => void;
|
|
113
142
|
getActiveChatInfo: () => { sessionId: string; expiresAt: number };
|
|
114
143
|
sendResourceUpdated: McpServer[ 'server' ][ 'sendResourceUpdated' ];
|
|
115
|
-
resource: McpServer[ '
|
|
144
|
+
resource: McpServer[ 'registerResource' ];
|
|
116
145
|
mcpServer: McpServer;
|
|
117
146
|
waitForReady: () => Promise< void >;
|
|
118
147
|
}
|
|
@@ -169,7 +198,6 @@ function createToolRegistry( server: McpServer ) {
|
|
|
169
198
|
try {
|
|
170
199
|
const invocationResult = await opts.handler( opts.schema ? args : {}, extra );
|
|
171
200
|
return {
|
|
172
|
-
// TODO: Uncomment this when the outputSchema is stable
|
|
173
201
|
// structuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,
|
|
174
202
|
content: [
|
|
175
203
|
{
|
|
@@ -201,12 +229,10 @@ function createToolRegistry( server: McpServer ) {
|
|
|
201
229
|
readOnlyHint: opts.isDestructive ? false : undefined,
|
|
202
230
|
title: opts.name,
|
|
203
231
|
};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
annotations[ ANGIE_MODEL_PREFERENCES ] = opts.modelPreferences;
|
|
209
|
-
}
|
|
232
|
+
const angieAnnotations = {
|
|
233
|
+
[ ANGIE_MODEL_PREFERENCES ]: opts.modelPreferences ?? createDefaultModelPreferences(),
|
|
234
|
+
[ ANGIE_REQUIRED_RESOURCES ]: opts.requiredResources ?? undefined,
|
|
235
|
+
};
|
|
210
236
|
server.registerTool(
|
|
211
237
|
opts.name,
|
|
212
238
|
{
|
|
@@ -216,6 +242,7 @@ function createToolRegistry( server: McpServer ) {
|
|
|
216
242
|
// outputSchema,
|
|
217
243
|
title: opts.name,
|
|
218
244
|
annotations,
|
|
245
|
+
_meta: angieAnnotations,
|
|
219
246
|
},
|
|
220
247
|
toolCallback
|
|
221
248
|
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
2
|
+
|
|
3
|
+
type PluginResponse = {
|
|
4
|
+
plugin: string;
|
|
5
|
+
status: 'active' | 'inactive';
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type PluginErrorResponse = {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type InstallAngieResult = { success: true } | { success: false; error: string; code?: string };
|
|
15
|
+
|
|
16
|
+
const ANGIE_SLUG = 'angie';
|
|
17
|
+
|
|
18
|
+
const isPluginErrorResponse = ( response: unknown ): response is PluginErrorResponse => {
|
|
19
|
+
return typeof response === 'object' && response !== null && 'code' in response && 'message' in response;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const activatePlugin = async ( pluginPath: string ): Promise< PluginResponse > => {
|
|
23
|
+
return apiFetch< PluginResponse >( {
|
|
24
|
+
path: `/wp/v2/plugins/${ pluginPath }`,
|
|
25
|
+
method: 'POST',
|
|
26
|
+
data: { status: 'active' },
|
|
27
|
+
} );
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const installPlugin = async (): Promise< PluginResponse > => {
|
|
31
|
+
try {
|
|
32
|
+
return await apiFetch< PluginResponse >( {
|
|
33
|
+
path: '/wp/v2/plugins',
|
|
34
|
+
method: 'POST',
|
|
35
|
+
data: {
|
|
36
|
+
slug: ANGIE_SLUG,
|
|
37
|
+
status: 'active',
|
|
38
|
+
},
|
|
39
|
+
} );
|
|
40
|
+
} catch ( error: unknown ) {
|
|
41
|
+
if ( isPluginErrorResponse( error ) && error.code === 'folder_exists' ) {
|
|
42
|
+
return activatePlugin( `${ ANGIE_SLUG }/${ ANGIE_SLUG }` );
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const installAngiePlugin = async (): Promise< InstallAngieResult > => {
|
|
50
|
+
try {
|
|
51
|
+
await installPlugin();
|
|
52
|
+
|
|
53
|
+
return { success: true };
|
|
54
|
+
} catch ( error: unknown ) {
|
|
55
|
+
if ( isPluginErrorResponse( error ) ) {
|
|
56
|
+
return { success: false, error: error.message, code: error.code };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { success: false, error: 'Unknown error occurred' };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { setReferrerRedirect } from '@elementor-external/angie-sdk';
|
|
2
|
+
|
|
3
|
+
const ANGIE_APP_URL = '/wp-admin/admin.php?page=angie-app';
|
|
4
|
+
|
|
5
|
+
export const redirectToAppAdmin = ( prompt: string ) => {
|
|
6
|
+
const success = setReferrerRedirect( window.location.href, prompt );
|
|
7
|
+
|
|
8
|
+
if ( ! success ) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
window.location.href = ANGIE_APP_URL;
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { setReferrerRedirect } from '@elementor-external/angie-sdk';
|
|
2
|
+
|
|
3
|
+
const ANGIE_INSTALL_URL = '/wp-admin/plugin-install.php?s=angie&tab=search&type=term';
|
|
4
|
+
|
|
5
|
+
export const redirectToInstallation = ( prompt: string ) => {
|
|
6
|
+
const success = setReferrerRedirect( window.location.href, prompt );
|
|
7
|
+
|
|
8
|
+
if ( ! success ) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
window.location.href = ANGIE_INSTALL_URL;
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getAngieIframe, toggleAngieSidebar } from '@elementor-external/angie-sdk';
|
|
2
|
+
|
|
3
|
+
export const sendPromptToAngie = ( prompt?: string ) => {
|
|
4
|
+
const angieSidebar = getAngieIframe();
|
|
5
|
+
|
|
6
|
+
if ( ! angieSidebar ) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
toggleAngieSidebar( angieSidebar, true );
|
|
11
|
+
|
|
12
|
+
if ( ! prompt ) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
window.location.hash = `angie-prompt=${ encodeURIComponent( prompt ) }`;
|
|
17
|
+
};
|