@page-mcp/vue2 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -39
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# @page-mcp/vue2
|
|
2
2
|
|
|
3
|
-
Page MCP SDK
|
|
3
|
+
Vue 2 adapter for the Page MCP SDK. Provides a Plugin and Mixin for easy integration.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> 🌐 **Live Preview:** [https://page-mcp.org](https://page-mcp.org)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
npm install @page-mcp/core @page-mcp/vue2
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Quick Start
|
|
12
14
|
|
|
13
|
-
###
|
|
15
|
+
### 1. Install Plugin
|
|
14
16
|
|
|
15
17
|
```javascript
|
|
16
18
|
// main.js
|
|
@@ -20,60 +22,73 @@ import { PageMcpPlugin } from '@page-mcp/vue2';
|
|
|
20
22
|
Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
###
|
|
25
|
+
### 2. Option A: Component Options (Recommended)
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
export default {
|
|
27
|
-
methods: {
|
|
28
|
-
async init() {
|
|
29
|
-
// 注册工具
|
|
30
|
-
this.$pageMcp.host.registerTool({
|
|
31
|
-
name: 'search',
|
|
32
|
-
description: '搜索',
|
|
33
|
-
parameters: { type: 'object', properties: { q: { type: 'string' } } },
|
|
34
|
-
handler: async (args) => this.doSearch(args.q)
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// 获取工具列表
|
|
38
|
-
const tools = await this.$pageMcp.client.listTools();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### 方式二:组件选项自动注册(推荐)
|
|
27
|
+
Declare tools, resources, and skills directly in component options. They are auto-registered on `created` and cleaned up on `beforeDestroy`.
|
|
45
28
|
|
|
46
29
|
```javascript
|
|
47
30
|
export default {
|
|
48
31
|
pageMcpTools: [
|
|
49
32
|
{
|
|
50
33
|
name: 'getTableData',
|
|
51
|
-
description: '
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
description: 'Get current table data',
|
|
35
|
+
inputSchema: { type: 'object', properties: {} },
|
|
36
|
+
execute: async function() { return this.tableData; }
|
|
54
37
|
}
|
|
55
38
|
],
|
|
56
39
|
|
|
57
40
|
pageMcpResources: [
|
|
58
41
|
{
|
|
59
42
|
uri: 'page://table/data',
|
|
60
|
-
name: '
|
|
61
|
-
description: '
|
|
43
|
+
name: 'Table Data',
|
|
44
|
+
description: 'Data displayed in the table',
|
|
62
45
|
handler: async () => ({ rows: store.state.tableData })
|
|
63
46
|
}
|
|
64
47
|
]
|
|
65
48
|
};
|
|
66
49
|
```
|
|
67
50
|
|
|
51
|
+
### 2. Option B: Use `this.$pageMcp` Directly
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
export default {
|
|
55
|
+
methods: {
|
|
56
|
+
async init() {
|
|
57
|
+
// Register a tool
|
|
58
|
+
this.$pageMcp.host.registerTool({
|
|
59
|
+
name: 'search',
|
|
60
|
+
description: 'Search records',
|
|
61
|
+
inputSchema: { type: 'object', properties: { q: { type: 'string' } } },
|
|
62
|
+
execute: async (args) => this.doSearch(args.q)
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Discover tools from AI side
|
|
66
|
+
const tools = await this.$pageMcp.client.listTools();
|
|
67
|
+
console.log('Available tools:', tools);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
68
73
|
## API
|
|
69
74
|
|
|
70
|
-
| API |
|
|
71
|
-
|
|
72
|
-
| `this.$pageMcp.host` | PageMcpHost
|
|
73
|
-
| `this.$pageMcp.client` | PageMcpClient
|
|
74
|
-
| `this.$pageMcp.bus` | EventBus
|
|
75
|
-
| `pageMcpTools`
|
|
76
|
-
| `pageMcpResources`
|
|
77
|
-
| `pageMcpSkills`
|
|
75
|
+
| API | Description |
|
|
76
|
+
|---|---|
|
|
77
|
+
| `this.$pageMcp.host` | `PageMcpHost` instance |
|
|
78
|
+
| `this.$pageMcp.client` | `PageMcpClient` instance |
|
|
79
|
+
| `this.$pageMcp.bus` | `EventBus` instance |
|
|
80
|
+
| `pageMcpTools` option | Array of tools auto-registered on component create |
|
|
81
|
+
| `pageMcpResources` option | Array of resources auto-registered on component create |
|
|
82
|
+
| `pageMcpSkills` option | Array of skills auto-registered on component create |
|
|
83
|
+
|
|
84
|
+
## How It Works
|
|
85
|
+
|
|
86
|
+
- `PageMcpPlugin` creates `EventBus`, `PageMcpHost`, and `PageMcpClient` instances and attaches them to `Vue.prototype.$pageMcp`.
|
|
87
|
+
- A global mixin reads `pageMcpTools`, `pageMcpResources`, and `pageMcpSkills` from component options and registers them during `created`, cleaning up in `beforeDestroy`.
|
|
88
|
+
- The Host is started automatically when the Plugin is installed.
|
|
89
|
+
|
|
90
|
+
For detailed documentation, see the [main README](../../README.md#vue-2-page-mcpvue2).
|
|
91
|
+
|
|
92
|
+
## License
|
|
78
93
|
|
|
79
|
-
|
|
94
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -74,6 +74,15 @@ var pageMcpAutoRegisterMixin = {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
const prompts = this.$options.pageMcpPrompts;
|
|
78
|
+
if (prompts && Array.isArray(prompts)) {
|
|
79
|
+
for (const prompt of prompts) {
|
|
80
|
+
try {
|
|
81
|
+
host.registerPrompt(prompt);
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
77
86
|
}
|
|
78
87
|
};
|
|
79
88
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================\n// @page-mcp/vue2 — Vue 2 Adapter for Page MCP SDK\n// ============================================================\n\nimport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n type ToolDefinition,\n type ResourceDefinition,\n type SkillDefinition,\n type HostInfo,\n} from '@page-mcp/core';\n\n// ------ Types for Vue 2 ------\n\ninterface Vue2ComponentOptions {\n beforeCreate?: () => void;\n created?: () => void;\n beforeDestroy?: () => void;\n [key: string]: unknown;\n}\n\ninterface Vue2Instance {\n $pageMcp?: PageMcpInjection;\n $options: {\n pageMcpTools?: ToolDefinition[];\n pageMcpResources?: ResourceDefinition[];\n pageMcpSkills?: SkillDefinition[];\n parent?: Vue2Instance;\n [key: string]: unknown;\n };\n $root: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface Vue2Constructor {\n mixin(mixin: Vue2ComponentOptions): void;\n prototype: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface PageMcpInjection {\n host: PageMcpHost;\n client: PageMcpClient;\n bus: EventBus;\n hostInfo: HostInfo;\n}\n\n// ------ Plugin ------\n\nexport interface PageMcpPluginOptions {\n name: string;\n version: string;\n bus?: EventBus;\n}\n\n/**\n * Vue 2 Plugin. Install globally:\n *\n * ```js\n * import Vue from 'vue';\n * import { PageMcpPlugin } from '@page-mcp/vue2';\n *\n * Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });\n * ```\n *\n * After installation, `this.$pageMcp` is available in all components:\n * - `this.$pageMcp.host` — PageMcpHost instance\n * - `this.$pageMcp.client` — PageMcpClient instance\n * - `this.$pageMcp.bus` — EventBus instance\n */\nexport const PageMcpPlugin = {\n install(Vue: Vue2Constructor, options: PageMcpPluginOptions): void {\n const bus = options.bus ?? new EventBus();\n const host = new PageMcpHost({ name: options.name, version: options.version, bus });\n const client = new PageMcpClient({ bus });\n const hostInfo: HostInfo = { name: options.name, version: options.version };\n\n host.start();\n client.connect();\n\n const injection: PageMcpInjection = { host, client, bus, hostInfo };\n\n // Make $pageMcp available in all components\n Vue.prototype.$pageMcp = injection;\n\n // Install the auto-registration mixin\n Vue.mixin(pageMcpAutoRegisterMixin);\n },\n};\n\n// ------ Mixin ------\n\n/**\n * Mixin that auto-registers tools/resources/skills defined in component options.\n *\n * ```js\n * export default {\n * pageMcpTools: [\n * {\n * name: 'search',\n * description: 'Search products',\n * parameters: { type: 'object', properties: { q: { type: 'string' } } },\n * handler: async (args) => this.searchProducts(args.q),\n * }\n * ],\n * pageMcpResources: [...],\n * pageMcpSkills: [...],\n * }\n * ```\n */\nconst pageMcpAutoRegisterMixin: Vue2ComponentOptions = {\n created(this: Vue2Instance) {\n const pageMcp = this.$pageMcp;\n if (!pageMcp) return;\n\n const { host } = pageMcp;\n\n // Register tools from component options\n const tools = this.$options.pageMcpTools;\n if (tools && Array.isArray(tools)) {\n for (const tool of tools) {\n try {\n host.registerTool(tool);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register resources from component options\n const resources = this.$options.pageMcpResources;\n if (resources && Array.isArray(resources)) {\n for (const resource of resources) {\n try {\n host.registerResource(resource);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register skills from component options\n const skills = this.$options.pageMcpSkills;\n if (skills && Array.isArray(skills)) {\n for (const skill of skills) {\n try {\n host.registerSkill(skill);\n } catch {\n // Already registered\n }\n }\n }\n },\n};\n\n/**\n * Standalone mixin for manual use (without the plugin).\n * Useful when you want to use the mixin pattern explicitly.\n */\nexport { pageMcpAutoRegisterMixin as pageMcpMixin };\n\n// ------ Re-exports ------\n\nexport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n} from '@page-mcp/core';\n\nexport type {\n ToolDefinition,\n ToolInfo,\n ResourceDefinition,\n ResourceInfo,\n SkillDefinition,\n SkillInfo,\n SkillResult,\n HostInfo,\n} from '@page-mcp/core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================\n// @page-mcp/vue2 — Vue 2 Adapter for Page MCP SDK\n// ============================================================\n\nimport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n type ToolDefinition,\n type ResourceDefinition,\n type SkillDefinition,\n type PromptDefinition,\n type HostInfo,\n} from '@page-mcp/core';\n\n// ------ Types for Vue 2 ------\n\ninterface Vue2ComponentOptions {\n beforeCreate?: () => void;\n created?: () => void;\n beforeDestroy?: () => void;\n [key: string]: unknown;\n}\n\ninterface Vue2Instance {\n $pageMcp?: PageMcpInjection;\n $options: {\n pageMcpTools?: ToolDefinition[];\n pageMcpResources?: ResourceDefinition[];\n pageMcpSkills?: SkillDefinition[];\n pageMcpPrompts?: PromptDefinition[];\n parent?: Vue2Instance;\n [key: string]: unknown;\n };\n $root: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface Vue2Constructor {\n mixin(mixin: Vue2ComponentOptions): void;\n prototype: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface PageMcpInjection {\n host: PageMcpHost;\n client: PageMcpClient;\n bus: EventBus;\n hostInfo: HostInfo;\n}\n\n// ------ Plugin ------\n\nexport interface PageMcpPluginOptions {\n name: string;\n version: string;\n bus?: EventBus;\n}\n\n/**\n * Vue 2 Plugin. Install globally:\n *\n * ```js\n * import Vue from 'vue';\n * import { PageMcpPlugin } from '@page-mcp/vue2';\n *\n * Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });\n * ```\n *\n * After installation, `this.$pageMcp` is available in all components:\n * - `this.$pageMcp.host` — PageMcpHost instance\n * - `this.$pageMcp.client` — PageMcpClient instance\n * - `this.$pageMcp.bus` — EventBus instance\n */\nexport const PageMcpPlugin = {\n install(Vue: Vue2Constructor, options: PageMcpPluginOptions): void {\n const bus = options.bus ?? new EventBus();\n const host = new PageMcpHost({ name: options.name, version: options.version, bus });\n const client = new PageMcpClient({ bus });\n const hostInfo: HostInfo = { name: options.name, version: options.version };\n\n host.start();\n client.connect();\n\n const injection: PageMcpInjection = { host, client, bus, hostInfo };\n\n // Make $pageMcp available in all components\n Vue.prototype.$pageMcp = injection;\n\n // Install the auto-registration mixin\n Vue.mixin(pageMcpAutoRegisterMixin);\n },\n};\n\n// ------ Mixin ------\n\n/**\n * Mixin that auto-registers tools/resources/skills defined in component options.\n *\n * ```js\n * export default {\n * pageMcpTools: [\n * {\n * name: 'search',\n * description: 'Search products',\n * parameters: { type: 'object', properties: { q: { type: 'string' } } },\n * handler: async (args) => this.searchProducts(args.q),\n * }\n * ],\n * pageMcpResources: [...],\n * pageMcpSkills: [...],\n * }\n * ```\n */\nconst pageMcpAutoRegisterMixin: Vue2ComponentOptions = {\n created(this: Vue2Instance) {\n const pageMcp = this.$pageMcp;\n if (!pageMcp) return;\n\n const { host } = pageMcp;\n\n // Register tools from component options\n const tools = this.$options.pageMcpTools;\n if (tools && Array.isArray(tools)) {\n for (const tool of tools) {\n try {\n host.registerTool(tool);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register resources from component options\n const resources = this.$options.pageMcpResources;\n if (resources && Array.isArray(resources)) {\n for (const resource of resources) {\n try {\n host.registerResource(resource);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register skills from component options\n const skills = this.$options.pageMcpSkills;\n if (skills && Array.isArray(skills)) {\n for (const skill of skills) {\n try {\n host.registerSkill(skill);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register prompts from component options\n const prompts = this.$options.pageMcpPrompts;\n if (prompts && Array.isArray(prompts)) {\n for (const prompt of prompts) {\n try {\n host.registerPrompt(prompt);\n } catch {\n // Already registered\n }\n }\n }\n },\n};\n\n/**\n * Standalone mixin for manual use (without the plugin).\n * Useful when you want to use the mixin pattern explicitly.\n */\nexport { pageMcpAutoRegisterMixin as pageMcpMixin };\n\n// ------ Re-exports ------\n\nexport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n} from '@page-mcp/core';\n\nexport type {\n ToolDefinition,\n ToolInfo,\n ResourceDefinition,\n ResourceInfo,\n SkillDefinition,\n SkillInfo,\n SkillResult,\n PromptDefinition,\n PromptInfo,\n HostInfo,\n} from '@page-mcp/core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBASO;AAsKP,IAAAA,eAIO;AA7GA,IAAM,gBAAgB;AAAA,EACzB,QAAQ,KAAsB,SAAqC;AAC/D,UAAM,MAAM,QAAQ,OAAO,IAAI,qBAAS;AACxC,UAAM,OAAO,IAAI,wBAAY,EAAE,MAAM,QAAQ,MAAM,SAAS,QAAQ,SAAS,IAAI,CAAC;AAClF,UAAM,SAAS,IAAI,0BAAc,EAAE,IAAI,CAAC;AACxC,UAAM,WAAqB,EAAE,MAAM,QAAQ,MAAM,SAAS,QAAQ,QAAQ;AAE1E,SAAK,MAAM;AACX,WAAO,QAAQ;AAEf,UAAM,YAA8B,EAAE,MAAM,QAAQ,KAAK,SAAS;AAGlE,QAAI,UAAU,WAAW;AAGzB,QAAI,MAAM,wBAAwB;AAAA,EACtC;AACJ;AAsBA,IAAM,2BAAiD;AAAA,EACnD,UAA4B;AACxB,UAAM,UAAU,KAAK;AACrB,QAAI,CAAC,QAAS;AAEd,UAAM,EAAE,KAAK,IAAI;AAGjB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,SAAS,MAAM,QAAQ,KAAK,GAAG;AAC/B,iBAAW,QAAQ,OAAO;AACtB,YAAI;AACA,eAAK,aAAa,IAAI;AAAA,QAC1B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,YAAY,KAAK,SAAS;AAChC,QAAI,aAAa,MAAM,QAAQ,SAAS,GAAG;AACvC,iBAAW,YAAY,WAAW;AAC9B,YAAI;AACA,eAAK,iBAAiB,QAAQ;AAAA,QAClC,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,SAAS,KAAK,SAAS;AAC7B,QAAI,UAAU,MAAM,QAAQ,MAAM,GAAG;AACjC,iBAAW,SAAS,QAAQ;AACxB,YAAI;AACA,eAAK,cAAc,KAAK;AAAA,QAC5B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,UAAU,KAAK,SAAS;AAC9B,QAAI,WAAW,MAAM,QAAQ,OAAO,GAAG;AACnC,iBAAW,UAAU,SAAS;AAC1B,YAAI;AACA,eAAK,eAAe,MAAM;AAAA,QAC9B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;","names":["import_core"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PageMcpHost, PageMcpClient, EventBus, HostInfo, ToolDefinition, ResourceDefinition, SkillDefinition } from '@page-mcp/core';
|
|
2
|
-
export { EventBus, HostInfo, PageMcpClient, PageMcpHost, ResourceDefinition, ResourceInfo, SkillDefinition, SkillInfo, SkillResult, ToolDefinition, ToolInfo } from '@page-mcp/core';
|
|
1
|
+
import { PageMcpHost, PageMcpClient, EventBus, HostInfo, ToolDefinition, ResourceDefinition, SkillDefinition, PromptDefinition } from '@page-mcp/core';
|
|
2
|
+
export { EventBus, HostInfo, PageMcpClient, PageMcpHost, PromptDefinition, PromptInfo, ResourceDefinition, ResourceInfo, SkillDefinition, SkillInfo, SkillResult, ToolDefinition, ToolInfo } from '@page-mcp/core';
|
|
3
3
|
|
|
4
4
|
interface Vue2ComponentOptions {
|
|
5
5
|
beforeCreate?: () => void;
|
|
@@ -13,6 +13,7 @@ interface Vue2Instance {
|
|
|
13
13
|
pageMcpTools?: ToolDefinition[];
|
|
14
14
|
pageMcpResources?: ResourceDefinition[];
|
|
15
15
|
pageMcpSkills?: SkillDefinition[];
|
|
16
|
+
pageMcpPrompts?: PromptDefinition[];
|
|
16
17
|
parent?: Vue2Instance;
|
|
17
18
|
[key: string]: unknown;
|
|
18
19
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PageMcpHost, PageMcpClient, EventBus, HostInfo, ToolDefinition, ResourceDefinition, SkillDefinition } from '@page-mcp/core';
|
|
2
|
-
export { EventBus, HostInfo, PageMcpClient, PageMcpHost, ResourceDefinition, ResourceInfo, SkillDefinition, SkillInfo, SkillResult, ToolDefinition, ToolInfo } from '@page-mcp/core';
|
|
1
|
+
import { PageMcpHost, PageMcpClient, EventBus, HostInfo, ToolDefinition, ResourceDefinition, SkillDefinition, PromptDefinition } from '@page-mcp/core';
|
|
2
|
+
export { EventBus, HostInfo, PageMcpClient, PageMcpHost, PromptDefinition, PromptInfo, ResourceDefinition, ResourceInfo, SkillDefinition, SkillInfo, SkillResult, ToolDefinition, ToolInfo } from '@page-mcp/core';
|
|
3
3
|
|
|
4
4
|
interface Vue2ComponentOptions {
|
|
5
5
|
beforeCreate?: () => void;
|
|
@@ -13,6 +13,7 @@ interface Vue2Instance {
|
|
|
13
13
|
pageMcpTools?: ToolDefinition[];
|
|
14
14
|
pageMcpResources?: ResourceDefinition[];
|
|
15
15
|
pageMcpSkills?: SkillDefinition[];
|
|
16
|
+
pageMcpPrompts?: PromptDefinition[];
|
|
16
17
|
parent?: Vue2Instance;
|
|
17
18
|
[key: string]: unknown;
|
|
18
19
|
};
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,15 @@ var pageMcpAutoRegisterMixin = {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
const prompts = this.$options.pageMcpPrompts;
|
|
58
|
+
if (prompts && Array.isArray(prompts)) {
|
|
59
|
+
for (const prompt of prompts) {
|
|
60
|
+
try {
|
|
61
|
+
host.registerPrompt(prompt);
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
57
66
|
}
|
|
58
67
|
};
|
|
59
68
|
export {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================\n// @page-mcp/vue2 — Vue 2 Adapter for Page MCP SDK\n// ============================================================\n\nimport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n type ToolDefinition,\n type ResourceDefinition,\n type SkillDefinition,\n type HostInfo,\n} from '@page-mcp/core';\n\n// ------ Types for Vue 2 ------\n\ninterface Vue2ComponentOptions {\n beforeCreate?: () => void;\n created?: () => void;\n beforeDestroy?: () => void;\n [key: string]: unknown;\n}\n\ninterface Vue2Instance {\n $pageMcp?: PageMcpInjection;\n $options: {\n pageMcpTools?: ToolDefinition[];\n pageMcpResources?: ResourceDefinition[];\n pageMcpSkills?: SkillDefinition[];\n parent?: Vue2Instance;\n [key: string]: unknown;\n };\n $root: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface Vue2Constructor {\n mixin(mixin: Vue2ComponentOptions): void;\n prototype: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface PageMcpInjection {\n host: PageMcpHost;\n client: PageMcpClient;\n bus: EventBus;\n hostInfo: HostInfo;\n}\n\n// ------ Plugin ------\n\nexport interface PageMcpPluginOptions {\n name: string;\n version: string;\n bus?: EventBus;\n}\n\n/**\n * Vue 2 Plugin. Install globally:\n *\n * ```js\n * import Vue from 'vue';\n * import { PageMcpPlugin } from '@page-mcp/vue2';\n *\n * Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });\n * ```\n *\n * After installation, `this.$pageMcp` is available in all components:\n * - `this.$pageMcp.host` — PageMcpHost instance\n * - `this.$pageMcp.client` — PageMcpClient instance\n * - `this.$pageMcp.bus` — EventBus instance\n */\nexport const PageMcpPlugin = {\n install(Vue: Vue2Constructor, options: PageMcpPluginOptions): void {\n const bus = options.bus ?? new EventBus();\n const host = new PageMcpHost({ name: options.name, version: options.version, bus });\n const client = new PageMcpClient({ bus });\n const hostInfo: HostInfo = { name: options.name, version: options.version };\n\n host.start();\n client.connect();\n\n const injection: PageMcpInjection = { host, client, bus, hostInfo };\n\n // Make $pageMcp available in all components\n Vue.prototype.$pageMcp = injection;\n\n // Install the auto-registration mixin\n Vue.mixin(pageMcpAutoRegisterMixin);\n },\n};\n\n// ------ Mixin ------\n\n/**\n * Mixin that auto-registers tools/resources/skills defined in component options.\n *\n * ```js\n * export default {\n * pageMcpTools: [\n * {\n * name: 'search',\n * description: 'Search products',\n * parameters: { type: 'object', properties: { q: { type: 'string' } } },\n * handler: async (args) => this.searchProducts(args.q),\n * }\n * ],\n * pageMcpResources: [...],\n * pageMcpSkills: [...],\n * }\n * ```\n */\nconst pageMcpAutoRegisterMixin: Vue2ComponentOptions = {\n created(this: Vue2Instance) {\n const pageMcp = this.$pageMcp;\n if (!pageMcp) return;\n\n const { host } = pageMcp;\n\n // Register tools from component options\n const tools = this.$options.pageMcpTools;\n if (tools && Array.isArray(tools)) {\n for (const tool of tools) {\n try {\n host.registerTool(tool);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register resources from component options\n const resources = this.$options.pageMcpResources;\n if (resources && Array.isArray(resources)) {\n for (const resource of resources) {\n try {\n host.registerResource(resource);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register skills from component options\n const skills = this.$options.pageMcpSkills;\n if (skills && Array.isArray(skills)) {\n for (const skill of skills) {\n try {\n host.registerSkill(skill);\n } catch {\n // Already registered\n }\n }\n }\n },\n};\n\n/**\n * Standalone mixin for manual use (without the plugin).\n * Useful when you want to use the mixin pattern explicitly.\n */\nexport { pageMcpAutoRegisterMixin as pageMcpMixin };\n\n// ------ Re-exports ------\n\nexport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n} from '@page-mcp/core';\n\nexport type {\n ToolDefinition,\n ToolInfo,\n ResourceDefinition,\n ResourceInfo,\n SkillDefinition,\n SkillInfo,\n SkillResult,\n HostInfo,\n} from '@page-mcp/core';\n"],"mappings":";AAIA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================\n// @page-mcp/vue2 — Vue 2 Adapter for Page MCP SDK\n// ============================================================\n\nimport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n type ToolDefinition,\n type ResourceDefinition,\n type SkillDefinition,\n type PromptDefinition,\n type HostInfo,\n} from '@page-mcp/core';\n\n// ------ Types for Vue 2 ------\n\ninterface Vue2ComponentOptions {\n beforeCreate?: () => void;\n created?: () => void;\n beforeDestroy?: () => void;\n [key: string]: unknown;\n}\n\ninterface Vue2Instance {\n $pageMcp?: PageMcpInjection;\n $options: {\n pageMcpTools?: ToolDefinition[];\n pageMcpResources?: ResourceDefinition[];\n pageMcpSkills?: SkillDefinition[];\n pageMcpPrompts?: PromptDefinition[];\n parent?: Vue2Instance;\n [key: string]: unknown;\n };\n $root: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface Vue2Constructor {\n mixin(mixin: Vue2ComponentOptions): void;\n prototype: Vue2Instance;\n [key: string]: unknown;\n}\n\ninterface PageMcpInjection {\n host: PageMcpHost;\n client: PageMcpClient;\n bus: EventBus;\n hostInfo: HostInfo;\n}\n\n// ------ Plugin ------\n\nexport interface PageMcpPluginOptions {\n name: string;\n version: string;\n bus?: EventBus;\n}\n\n/**\n * Vue 2 Plugin. Install globally:\n *\n * ```js\n * import Vue from 'vue';\n * import { PageMcpPlugin } from '@page-mcp/vue2';\n *\n * Vue.use(PageMcpPlugin, { name: 'my-app', version: '1.0' });\n * ```\n *\n * After installation, `this.$pageMcp` is available in all components:\n * - `this.$pageMcp.host` — PageMcpHost instance\n * - `this.$pageMcp.client` — PageMcpClient instance\n * - `this.$pageMcp.bus` — EventBus instance\n */\nexport const PageMcpPlugin = {\n install(Vue: Vue2Constructor, options: PageMcpPluginOptions): void {\n const bus = options.bus ?? new EventBus();\n const host = new PageMcpHost({ name: options.name, version: options.version, bus });\n const client = new PageMcpClient({ bus });\n const hostInfo: HostInfo = { name: options.name, version: options.version };\n\n host.start();\n client.connect();\n\n const injection: PageMcpInjection = { host, client, bus, hostInfo };\n\n // Make $pageMcp available in all components\n Vue.prototype.$pageMcp = injection;\n\n // Install the auto-registration mixin\n Vue.mixin(pageMcpAutoRegisterMixin);\n },\n};\n\n// ------ Mixin ------\n\n/**\n * Mixin that auto-registers tools/resources/skills defined in component options.\n *\n * ```js\n * export default {\n * pageMcpTools: [\n * {\n * name: 'search',\n * description: 'Search products',\n * parameters: { type: 'object', properties: { q: { type: 'string' } } },\n * handler: async (args) => this.searchProducts(args.q),\n * }\n * ],\n * pageMcpResources: [...],\n * pageMcpSkills: [...],\n * }\n * ```\n */\nconst pageMcpAutoRegisterMixin: Vue2ComponentOptions = {\n created(this: Vue2Instance) {\n const pageMcp = this.$pageMcp;\n if (!pageMcp) return;\n\n const { host } = pageMcp;\n\n // Register tools from component options\n const tools = this.$options.pageMcpTools;\n if (tools && Array.isArray(tools)) {\n for (const tool of tools) {\n try {\n host.registerTool(tool);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register resources from component options\n const resources = this.$options.pageMcpResources;\n if (resources && Array.isArray(resources)) {\n for (const resource of resources) {\n try {\n host.registerResource(resource);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register skills from component options\n const skills = this.$options.pageMcpSkills;\n if (skills && Array.isArray(skills)) {\n for (const skill of skills) {\n try {\n host.registerSkill(skill);\n } catch {\n // Already registered\n }\n }\n }\n\n // Register prompts from component options\n const prompts = this.$options.pageMcpPrompts;\n if (prompts && Array.isArray(prompts)) {\n for (const prompt of prompts) {\n try {\n host.registerPrompt(prompt);\n } catch {\n // Already registered\n }\n }\n }\n },\n};\n\n/**\n * Standalone mixin for manual use (without the plugin).\n * Useful when you want to use the mixin pattern explicitly.\n */\nexport { pageMcpAutoRegisterMixin as pageMcpMixin };\n\n// ------ Re-exports ------\n\nexport {\n PageMcpHost,\n PageMcpClient,\n EventBus,\n} from '@page-mcp/core';\n\nexport type {\n ToolDefinition,\n ToolInfo,\n ResourceDefinition,\n ResourceInfo,\n SkillDefinition,\n SkillInfo,\n SkillResult,\n PromptDefinition,\n PromptInfo,\n HostInfo,\n} from '@page-mcp/core';\n"],"mappings":";AAIA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAMG;AAsKP;AAAA,EACI,eAAAA;AAAA,EACA,iBAAAC;AAAA,EACA,YAAAC;AAAA,OACG;AA7GA,IAAM,gBAAgB;AAAA,EACzB,QAAQ,KAAsB,SAAqC;AAC/D,UAAM,MAAM,QAAQ,OAAO,IAAI,SAAS;AACxC,UAAM,OAAO,IAAI,YAAY,EAAE,MAAM,QAAQ,MAAM,SAAS,QAAQ,SAAS,IAAI,CAAC;AAClF,UAAM,SAAS,IAAI,cAAc,EAAE,IAAI,CAAC;AACxC,UAAM,WAAqB,EAAE,MAAM,QAAQ,MAAM,SAAS,QAAQ,QAAQ;AAE1E,SAAK,MAAM;AACX,WAAO,QAAQ;AAEf,UAAM,YAA8B,EAAE,MAAM,QAAQ,KAAK,SAAS;AAGlE,QAAI,UAAU,WAAW;AAGzB,QAAI,MAAM,wBAAwB;AAAA,EACtC;AACJ;AAsBA,IAAM,2BAAiD;AAAA,EACnD,UAA4B;AACxB,UAAM,UAAU,KAAK;AACrB,QAAI,CAAC,QAAS;AAEd,UAAM,EAAE,KAAK,IAAI;AAGjB,UAAM,QAAQ,KAAK,SAAS;AAC5B,QAAI,SAAS,MAAM,QAAQ,KAAK,GAAG;AAC/B,iBAAW,QAAQ,OAAO;AACtB,YAAI;AACA,eAAK,aAAa,IAAI;AAAA,QAC1B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,YAAY,KAAK,SAAS;AAChC,QAAI,aAAa,MAAM,QAAQ,SAAS,GAAG;AACvC,iBAAW,YAAY,WAAW;AAC9B,YAAI;AACA,eAAK,iBAAiB,QAAQ;AAAA,QAClC,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,SAAS,KAAK,SAAS;AAC7B,QAAI,UAAU,MAAM,QAAQ,MAAM,GAAG;AACjC,iBAAW,SAAS,QAAQ;AACxB,YAAI;AACA,eAAK,cAAc,KAAK;AAAA,QAC5B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,UAAU,KAAK,SAAS;AAC9B,QAAI,WAAW,MAAM,QAAQ,OAAO,GAAG;AACnC,iBAAW,UAAU,SAAS;AAC1B,YAAI;AACA,eAAK,eAAe,MAAM;AAAA,QAC9B,QAAQ;AAAA,QAER;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;","names":["PageMcpHost","PageMcpClient","EventBus"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@page-mcp/vue2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Vue 2 adapter for Page MCP SDK — Plugin + Mixin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"vue": "^2.7.0",
|
|
35
35
|
"tsup": "^8.0.0",
|
|
36
36
|
"typescript": "^5.4.0",
|
|
37
|
-
"@page-mcp/core": "^1.
|
|
37
|
+
"@page-mcp/core": "^1.1.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup",
|