@thegreataxios/webmcp-elements 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +47 -2
- package/dist/index.cjs +277 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +258 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sawyer Cutler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @thegreataxios/webmcp-elements
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Framework-agnostic Web Components for the [W3C WebMCP](https://github.com/webmachinelearning/webmcp) API — works in plain HTML, Lit, Astro, htmx, or any framework.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @thegreataxios/webmcp-elements @thegreataxios/webmcp-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<webmcp-provider>
|
|
15
|
+
<webmcp-tool
|
|
16
|
+
id="search-tool"
|
|
17
|
+
name="search_catalog"
|
|
18
|
+
title="Search Catalog"
|
|
19
|
+
description="Search products by keyword"
|
|
20
|
+
read-only
|
|
21
|
+
>
|
|
22
|
+
<script type="application/json" slot="input-schema">
|
|
23
|
+
{"type":"object","properties":{"q":{"type":"string"}},"required":["q"]}
|
|
24
|
+
</script>
|
|
25
|
+
</webmcp-tool>
|
|
26
|
+
</webmcp-provider>
|
|
27
|
+
|
|
28
|
+
<script type="module">
|
|
29
|
+
import { registerWebMCPElements } from "@thegreataxios/webmcp-elements";
|
|
30
|
+
registerWebMCPElements();
|
|
31
|
+
|
|
32
|
+
document.getElementById("search-tool").addEventListener("webmcp-execute", (e) => {
|
|
33
|
+
e.detail.respondWith({ query: e.detail.args.q, results: [] });
|
|
34
|
+
});
|
|
35
|
+
</script>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Elements
|
|
39
|
+
|
|
40
|
+
| Element | Attributes / Events |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `<webmcp-provider>` | `bridge-url`, `bridge-token`; emits `webmcp-ready`, `webmcp-bridge-status` |
|
|
43
|
+
| `<webmcp-tool>` | `name`, `title`, `description`, `read-only`, `untrusted-content`, `consequential`, `debugging`, `exposed-to`; `.execute` property or `webmcp-execute` event |
|
|
44
|
+
| `<webmcp-journey>` | `name`, `tools` (CSV), `active`, `description` |
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
WEBMCP_ELEMENT_TAGS: () => WEBMCP_ELEMENT_TAGS,
|
|
24
|
+
registerWebMCPElements: () => registerWebMCPElements
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_webmcp_core = require("@thegreataxios/webmcp-core");
|
|
28
|
+
var WEBMCP_ELEMENT_TAGS = {
|
|
29
|
+
PROVIDER: "webmcp-provider",
|
|
30
|
+
TOOL: "webmcp-tool",
|
|
31
|
+
JOURNEY: "webmcp-journey"
|
|
32
|
+
};
|
|
33
|
+
function parseJsonSlot(el, slotName) {
|
|
34
|
+
const script = el.querySelector(`script[type="application/json"][slot="${slotName}"]`);
|
|
35
|
+
if (!script?.textContent) return void 0;
|
|
36
|
+
const parsed = JSON.parse(script.textContent);
|
|
37
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
38
|
+
throw new DOMException(`${slotName} must be a JSON object`, "SyntaxError");
|
|
39
|
+
}
|
|
40
|
+
return parsed;
|
|
41
|
+
}
|
|
42
|
+
function parseCsvAttr(el, name) {
|
|
43
|
+
const raw = el.getAttribute(name);
|
|
44
|
+
if (!raw) return void 0;
|
|
45
|
+
const list = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
46
|
+
return list.length > 0 ? list : void 0;
|
|
47
|
+
}
|
|
48
|
+
var providerCtor = null;
|
|
49
|
+
var toolCtor = null;
|
|
50
|
+
var journeyCtor = null;
|
|
51
|
+
function ensureElementClasses() {
|
|
52
|
+
if (typeof HTMLElement === "undefined") return;
|
|
53
|
+
if (providerCtor && toolCtor && journeyCtor) return;
|
|
54
|
+
providerCtor = class WebMCPProviderElement extends HTMLElement {
|
|
55
|
+
#bridgeClient = null;
|
|
56
|
+
connectedCallback() {
|
|
57
|
+
(0, import_webmcp_core.installPolyfill)();
|
|
58
|
+
const bridgeUrl = this.getAttribute("bridge-url");
|
|
59
|
+
const bridgeToken = this.getAttribute("bridge-token");
|
|
60
|
+
if (bridgeUrl && bridgeToken) {
|
|
61
|
+
this.#bridgeClient = (0, import_webmcp_core.createPageBridgeClient)({
|
|
62
|
+
url: bridgeUrl,
|
|
63
|
+
token: bridgeToken,
|
|
64
|
+
onStatusChange: (status) => {
|
|
65
|
+
this.dispatchEvent(
|
|
66
|
+
new CustomEvent("webmcp-bridge-status", { detail: { status }, bubbles: true })
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.#bridgeClient.connect();
|
|
71
|
+
}
|
|
72
|
+
this.dispatchEvent(new CustomEvent("webmcp-ready", { bubbles: true }));
|
|
73
|
+
}
|
|
74
|
+
disconnectedCallback() {
|
|
75
|
+
this.#bridgeClient?.disconnect();
|
|
76
|
+
this.#bridgeClient = null;
|
|
77
|
+
(0, import_webmcp_core.cleanupPolyfill)();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
toolCtor = class WebMCPToolElement extends HTMLElement {
|
|
81
|
+
static get observedAttributes() {
|
|
82
|
+
return [
|
|
83
|
+
"name",
|
|
84
|
+
"title",
|
|
85
|
+
"description",
|
|
86
|
+
"read-only",
|
|
87
|
+
"untrusted-content",
|
|
88
|
+
"consequential",
|
|
89
|
+
"debugging",
|
|
90
|
+
"exposed-to"
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
#controller = null;
|
|
94
|
+
#execute = null;
|
|
95
|
+
#inputSchema;
|
|
96
|
+
#outputSchema;
|
|
97
|
+
#waitingForReady = null;
|
|
98
|
+
get execute() {
|
|
99
|
+
return this.#execute;
|
|
100
|
+
}
|
|
101
|
+
set execute(fn) {
|
|
102
|
+
this.#execute = fn;
|
|
103
|
+
if (this.isConnected) {
|
|
104
|
+
this.#reregister();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
get inputSchema() {
|
|
108
|
+
return this.#inputSchema;
|
|
109
|
+
}
|
|
110
|
+
set inputSchema(schema) {
|
|
111
|
+
this.#inputSchema = schema;
|
|
112
|
+
if (this.isConnected) {
|
|
113
|
+
this.#reregister();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
get outputSchema() {
|
|
117
|
+
return this.#outputSchema;
|
|
118
|
+
}
|
|
119
|
+
set outputSchema(schema) {
|
|
120
|
+
this.#outputSchema = schema;
|
|
121
|
+
if (this.isConnected) {
|
|
122
|
+
this.#reregister();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
connectedCallback() {
|
|
126
|
+
this.#reregister();
|
|
127
|
+
}
|
|
128
|
+
attributeChangedCallback() {
|
|
129
|
+
if (this.isConnected) {
|
|
130
|
+
this.#reregister();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
disconnectedCallback() {
|
|
134
|
+
if (this.#waitingForReady && typeof document !== "undefined") {
|
|
135
|
+
document.removeEventListener("webmcp-ready", this.#waitingForReady);
|
|
136
|
+
this.#waitingForReady = null;
|
|
137
|
+
}
|
|
138
|
+
this.#controller?.abort();
|
|
139
|
+
this.#controller = null;
|
|
140
|
+
}
|
|
141
|
+
#readAnnotations() {
|
|
142
|
+
const hasAny = this.hasAttribute("read-only") || this.hasAttribute("untrusted-content") || this.hasAttribute("consequential") || this.hasAttribute("debugging");
|
|
143
|
+
if (!hasAny) return void 0;
|
|
144
|
+
return {
|
|
145
|
+
readOnlyHint: this.hasAttribute("read-only"),
|
|
146
|
+
untrustedContentHint: this.hasAttribute("untrusted-content"),
|
|
147
|
+
consequentialHint: this.hasAttribute("consequential"),
|
|
148
|
+
debugging: this.hasAttribute("debugging")
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
#reregister() {
|
|
152
|
+
this.#controller?.abort();
|
|
153
|
+
this.#controller = null;
|
|
154
|
+
if (typeof document === "undefined") return;
|
|
155
|
+
if (!document.modelContext) {
|
|
156
|
+
if (!this.#waitingForReady) {
|
|
157
|
+
this.#waitingForReady = () => {
|
|
158
|
+
if (this.#waitingForReady) {
|
|
159
|
+
document.removeEventListener("webmcp-ready", this.#waitingForReady);
|
|
160
|
+
this.#waitingForReady = null;
|
|
161
|
+
}
|
|
162
|
+
if (this.isConnected) {
|
|
163
|
+
this.#reregister();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
document.addEventListener("webmcp-ready", this.#waitingForReady);
|
|
167
|
+
}
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const name = this.getAttribute("name")?.trim();
|
|
171
|
+
const description = this.getAttribute("description")?.trim();
|
|
172
|
+
if (!name || !description) return;
|
|
173
|
+
const controller = new AbortController();
|
|
174
|
+
this.#controller = controller;
|
|
175
|
+
let inputSchema;
|
|
176
|
+
let outputSchema;
|
|
177
|
+
try {
|
|
178
|
+
inputSchema = this.#inputSchema ?? parseJsonSlot(this, "input-schema");
|
|
179
|
+
outputSchema = this.#outputSchema ?? parseJsonSlot(this, "output-schema");
|
|
180
|
+
} catch (error) {
|
|
181
|
+
this.dispatchEvent(
|
|
182
|
+
new CustomEvent("webmcp-error", { detail: { name, error }, bubbles: true })
|
|
183
|
+
);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const exposedTo = parseCsvAttr(this, "exposed-to");
|
|
187
|
+
const title = this.getAttribute("title") ?? void 0;
|
|
188
|
+
const annotations = this.#readAnnotations();
|
|
189
|
+
const execute = async (args, options) => {
|
|
190
|
+
if (this.#execute) {
|
|
191
|
+
return await this.#execute(args, options);
|
|
192
|
+
}
|
|
193
|
+
let responded = false;
|
|
194
|
+
let responseValue;
|
|
195
|
+
const detail = {
|
|
196
|
+
args,
|
|
197
|
+
signal: options?.signal,
|
|
198
|
+
respondWith(value) {
|
|
199
|
+
responded = true;
|
|
200
|
+
responseValue = value;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
this.dispatchEvent(new CustomEvent("webmcp-execute", { detail, bubbles: true }));
|
|
204
|
+
if (!responded) {
|
|
205
|
+
throw new DOMException(
|
|
206
|
+
`No execute handler or webmcp-execute listener responded for "${name}"`,
|
|
207
|
+
"OperationError"
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return await responseValue;
|
|
211
|
+
};
|
|
212
|
+
document.modelContext.registerTool(
|
|
213
|
+
{ name, title, description, inputSchema, outputSchema, annotations, execute },
|
|
214
|
+
{ signal: controller.signal, exposedTo }
|
|
215
|
+
).catch(() => {
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
journeyCtor = class WebMCPJourneyElement extends HTMLElement {
|
|
220
|
+
static get observedAttributes() {
|
|
221
|
+
return ["name", "tools", "active", "description"];
|
|
222
|
+
}
|
|
223
|
+
#registeredName = null;
|
|
224
|
+
connectedCallback() {
|
|
225
|
+
this.#sync();
|
|
226
|
+
}
|
|
227
|
+
attributeChangedCallback() {
|
|
228
|
+
if (this.isConnected) {
|
|
229
|
+
this.#sync();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
disconnectedCallback() {
|
|
233
|
+
const registry = (0, import_webmcp_core.getJourneyRegistry)();
|
|
234
|
+
if (registry && this.#registeredName) {
|
|
235
|
+
registry.unregister(this.#registeredName);
|
|
236
|
+
}
|
|
237
|
+
this.#registeredName = null;
|
|
238
|
+
}
|
|
239
|
+
#sync() {
|
|
240
|
+
const name = this.getAttribute("name")?.trim();
|
|
241
|
+
if (!name) return;
|
|
242
|
+
let registry = (0, import_webmcp_core.getJourneyRegistry)();
|
|
243
|
+
if (!registry) {
|
|
244
|
+
registry = (0, import_webmcp_core.experimental_createJourneyRegistry)();
|
|
245
|
+
(0, import_webmcp_core.setJourneyRegistry)(registry);
|
|
246
|
+
}
|
|
247
|
+
if (this.#registeredName && this.#registeredName !== name) {
|
|
248
|
+
registry.unregister(this.#registeredName);
|
|
249
|
+
}
|
|
250
|
+
const tools = parseCsvAttr(this, "tools") ?? [];
|
|
251
|
+
const description = this.getAttribute("description") ?? void 0;
|
|
252
|
+
registry.register({ name, description, tools });
|
|
253
|
+
registry.setJourneyActive(name, this.hasAttribute("active"));
|
|
254
|
+
this.#registeredName = name;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function registerWebMCPElements() {
|
|
259
|
+
if (typeof customElements === "undefined") return;
|
|
260
|
+
ensureElementClasses();
|
|
261
|
+
if (!providerCtor || !toolCtor || !journeyCtor) return;
|
|
262
|
+
if (!customElements.get(WEBMCP_ELEMENT_TAGS.PROVIDER)) {
|
|
263
|
+
customElements.define(WEBMCP_ELEMENT_TAGS.PROVIDER, providerCtor);
|
|
264
|
+
}
|
|
265
|
+
if (!customElements.get(WEBMCP_ELEMENT_TAGS.TOOL)) {
|
|
266
|
+
customElements.define(WEBMCP_ELEMENT_TAGS.TOOL, toolCtor);
|
|
267
|
+
}
|
|
268
|
+
if (!customElements.get(WEBMCP_ELEMENT_TAGS.JOURNEY)) {
|
|
269
|
+
customElements.define(WEBMCP_ELEMENT_TAGS.JOURNEY, journeyCtor);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
273
|
+
0 && (module.exports = {
|
|
274
|
+
WEBMCP_ELEMENT_TAGS,
|
|
275
|
+
registerWebMCPElements
|
|
276
|
+
});
|
|
277
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n cleanupPolyfill,\n createPageBridgeClient,\n experimental_createJourneyRegistry,\n getJourneyRegistry,\n installPolyfill,\n setJourneyRegistry,\n type JsonSchema,\n type ToolAnnotations,\n type ToolExecuteCallback,\n type ToolExecuteCallbackOptions,\n} from \"@thegreataxios/webmcp-core\";\n\nexport const WEBMCP_ELEMENT_TAGS = {\n PROVIDER: \"webmcp-provider\",\n TOOL: \"webmcp-tool\",\n JOURNEY: \"webmcp-journey\",\n} as const;\n\nexport interface WebMCPExecuteEventDetail {\n args: Record<string, unknown>;\n signal?: AbortSignal;\n respondWith: (value: unknown | Promise<unknown>) => void;\n}\n\nexport interface WebMCPToolElementInstance extends HTMLElement {\n execute: ToolExecuteCallback | null;\n inputSchema: JsonSchema | undefined;\n outputSchema: JsonSchema | undefined;\n}\n\nfunction parseJsonSlot(el: HTMLElement, slotName: string): JsonSchema | undefined {\n const script = el.querySelector(`script[type=\"application/json\"][slot=\"${slotName}\"]`);\n if (!script?.textContent) return undefined;\n const parsed = JSON.parse(script.textContent) as unknown;\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n throw new DOMException(`${slotName} must be a JSON object`, \"SyntaxError\");\n }\n return parsed as JsonSchema;\n}\n\nfunction parseCsvAttr(el: HTMLElement, name: string): string[] | undefined {\n const raw = el.getAttribute(name);\n if (!raw) return undefined;\n const list = raw\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n return list.length > 0 ? list : undefined;\n}\n\nlet providerCtor: CustomElementConstructor | null = null;\nlet toolCtor: CustomElementConstructor | null = null;\nlet journeyCtor: CustomElementConstructor | null = null;\n\nfunction ensureElementClasses(): void {\n if (typeof HTMLElement === \"undefined\") return;\n if (providerCtor && toolCtor && journeyCtor) return;\n\n providerCtor = class WebMCPProviderElement extends HTMLElement {\n #bridgeClient: ReturnType<typeof createPageBridgeClient> | null = null;\n\n connectedCallback(): void {\n installPolyfill();\n const bridgeUrl = this.getAttribute(\"bridge-url\");\n const bridgeToken = this.getAttribute(\"bridge-token\");\n if (bridgeUrl && bridgeToken) {\n this.#bridgeClient = createPageBridgeClient({\n url: bridgeUrl,\n token: bridgeToken,\n onStatusChange: (status) => {\n this.dispatchEvent(\n new CustomEvent(\"webmcp-bridge-status\", { detail: { status }, bubbles: true }),\n );\n },\n });\n this.#bridgeClient.connect();\n }\n this.dispatchEvent(new CustomEvent(\"webmcp-ready\", { bubbles: true }));\n }\n\n disconnectedCallback(): void {\n this.#bridgeClient?.disconnect();\n this.#bridgeClient = null;\n cleanupPolyfill();\n }\n };\n\n toolCtor = class WebMCPToolElement extends HTMLElement implements WebMCPToolElementInstance {\n static get observedAttributes(): string[] {\n return [\n \"name\",\n \"title\",\n \"description\",\n \"read-only\",\n \"untrusted-content\",\n \"consequential\",\n \"debugging\",\n \"exposed-to\",\n ];\n }\n\n #controller: AbortController | null = null;\n #execute: ToolExecuteCallback | null = null;\n #inputSchema: JsonSchema | undefined;\n #outputSchema: JsonSchema | undefined;\n #waitingForReady: (() => void) | null = null;\n\n get execute(): ToolExecuteCallback | null {\n return this.#execute;\n }\n\n set execute(fn: ToolExecuteCallback | null) {\n this.#execute = fn;\n if (this.isConnected) {\n this.#reregister();\n }\n }\n\n get inputSchema(): JsonSchema | undefined {\n return this.#inputSchema;\n }\n\n set inputSchema(schema: JsonSchema | undefined) {\n this.#inputSchema = schema;\n if (this.isConnected) {\n this.#reregister();\n }\n }\n\n get outputSchema(): JsonSchema | undefined {\n return this.#outputSchema;\n }\n\n set outputSchema(schema: JsonSchema | undefined) {\n this.#outputSchema = schema;\n if (this.isConnected) {\n this.#reregister();\n }\n }\n\n connectedCallback(): void {\n this.#reregister();\n }\n\n attributeChangedCallback(): void {\n if (this.isConnected) {\n this.#reregister();\n }\n }\n\n disconnectedCallback(): void {\n if (this.#waitingForReady && typeof document !== \"undefined\") {\n document.removeEventListener(\"webmcp-ready\", this.#waitingForReady);\n this.#waitingForReady = null;\n }\n this.#controller?.abort();\n this.#controller = null;\n }\n\n #readAnnotations(): ToolAnnotations | undefined {\n const hasAny =\n this.hasAttribute(\"read-only\") ||\n this.hasAttribute(\"untrusted-content\") ||\n this.hasAttribute(\"consequential\") ||\n this.hasAttribute(\"debugging\");\n if (!hasAny) return undefined;\n return {\n readOnlyHint: this.hasAttribute(\"read-only\"),\n untrustedContentHint: this.hasAttribute(\"untrusted-content\"),\n consequentialHint: this.hasAttribute(\"consequential\"),\n debugging: this.hasAttribute(\"debugging\"),\n };\n }\n\n #reregister(): void {\n this.#controller?.abort();\n this.#controller = null;\n\n if (typeof document === \"undefined\") return;\n if (!document.modelContext) {\n if (!this.#waitingForReady) {\n this.#waitingForReady = () => {\n if (this.#waitingForReady) {\n document.removeEventListener(\"webmcp-ready\", this.#waitingForReady);\n this.#waitingForReady = null;\n }\n if (this.isConnected) {\n this.#reregister();\n }\n };\n document.addEventListener(\"webmcp-ready\", this.#waitingForReady);\n }\n return;\n }\n const name = this.getAttribute(\"name\")?.trim();\n const description = this.getAttribute(\"description\")?.trim();\n if (!name || !description) return;\n\n const controller = new AbortController();\n this.#controller = controller;\n\n let inputSchema: JsonSchema | undefined;\n let outputSchema: JsonSchema | undefined;\n try {\n inputSchema = this.#inputSchema ?? parseJsonSlot(this, \"input-schema\");\n outputSchema = this.#outputSchema ?? parseJsonSlot(this, \"output-schema\");\n } catch (error) {\n this.dispatchEvent(\n new CustomEvent(\"webmcp-error\", { detail: { name, error }, bubbles: true }),\n );\n return;\n }\n const exposedTo = parseCsvAttr(this, \"exposed-to\");\n const title = this.getAttribute(\"title\") ?? undefined;\n const annotations = this.#readAnnotations();\n\n const execute: ToolExecuteCallback = async (\n args: Record<string, unknown>,\n options?: ToolExecuteCallbackOptions,\n ) => {\n if (this.#execute) {\n return await this.#execute(args, options);\n }\n let responded = false;\n let responseValue: unknown;\n const detail: WebMCPExecuteEventDetail = {\n args,\n signal: options?.signal,\n respondWith(value) {\n responded = true;\n responseValue = value;\n },\n };\n this.dispatchEvent(new CustomEvent(\"webmcp-execute\", { detail, bubbles: true }));\n if (!responded) {\n throw new DOMException(\n `No execute handler or webmcp-execute listener responded for \"${name}\"`,\n \"OperationError\",\n );\n }\n return await responseValue;\n };\n\n document.modelContext\n .registerTool(\n { name, title, description, inputSchema, outputSchema, annotations, execute },\n { signal: controller.signal, exposedTo },\n )\n .catch(() => {});\n }\n };\n\n journeyCtor = class WebMCPJourneyElement extends HTMLElement {\n static get observedAttributes(): string[] {\n return [\"name\", \"tools\", \"active\", \"description\"];\n }\n\n #registeredName: string | null = null;\n\n connectedCallback(): void {\n this.#sync();\n }\n\n attributeChangedCallback(): void {\n if (this.isConnected) {\n this.#sync();\n }\n }\n\n disconnectedCallback(): void {\n const registry = getJourneyRegistry();\n if (registry && this.#registeredName) {\n registry.unregister(this.#registeredName);\n }\n this.#registeredName = null;\n }\n\n #sync(): void {\n const name = this.getAttribute(\"name\")?.trim();\n if (!name) return;\n\n let registry = getJourneyRegistry();\n if (!registry) {\n registry = experimental_createJourneyRegistry();\n setJourneyRegistry(registry);\n }\n\n if (this.#registeredName && this.#registeredName !== name) {\n registry.unregister(this.#registeredName);\n }\n\n const tools = parseCsvAttr(this, \"tools\") ?? [];\n const description = this.getAttribute(\"description\") ?? undefined;\n registry.register({ name, description, tools });\n registry.setJourneyActive(name, this.hasAttribute(\"active\"));\n this.#registeredName = name;\n }\n };\n}\n\n/**\n * Define `<webmcp-provider>`, `<webmcp-tool>`, and `<webmcp-journey>` custom elements.\n * Safe to call multiple times or in SSR environments.\n */\nexport function registerWebMCPElements(): void {\n if (typeof customElements === \"undefined\") return;\n ensureElementClasses();\n if (!providerCtor || !toolCtor || !journeyCtor) return;\n\n if (!customElements.get(WEBMCP_ELEMENT_TAGS.PROVIDER)) {\n customElements.define(WEBMCP_ELEMENT_TAGS.PROVIDER, providerCtor);\n }\n if (!customElements.get(WEBMCP_ELEMENT_TAGS.TOOL)) {\n customElements.define(WEBMCP_ELEMENT_TAGS.TOOL, toolCtor);\n }\n if (!customElements.get(WEBMCP_ELEMENT_TAGS.JOURNEY)) {\n customElements.define(WEBMCP_ELEMENT_TAGS.JOURNEY, journeyCtor);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAWO;AAEA,IAAM,sBAAsB;AAAA,EACjC,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AACX;AAcA,SAAS,cAAc,IAAiB,UAA0C;AAChF,QAAM,SAAS,GAAG,cAAc,yCAAyC,QAAQ,IAAI;AACrF,MAAI,CAAC,QAAQ,YAAa,QAAO;AACjC,QAAM,SAAS,KAAK,MAAM,OAAO,WAAW;AAC5C,MAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,MAAM,QAAQ,MAAM,GAAG;AAC1E,UAAM,IAAI,aAAa,GAAG,QAAQ,0BAA0B,aAAa;AAAA,EAC3E;AACA,SAAO;AACT;AAEA,SAAS,aAAa,IAAiB,MAAoC;AACzE,QAAM,MAAM,GAAG,aAAa,IAAI;AAChC,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,OAAO,IACV,MAAM,GAAG,EACT,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EACnB,OAAO,OAAO;AACjB,SAAO,KAAK,SAAS,IAAI,OAAO;AAClC;AAEA,IAAI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B,YAAa;AAC3C,uBAAqB;AACrB,MAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,YAAa;AAEhD,MAAI,CAAC,eAAe,IAAI,oBAAoB,QAAQ,GAAG;AACrD,mBAAe,OAAO,oBAAoB,UAAU,YAAY;AAAA,EAClE;AACA,MAAI,CAAC,eAAe,IAAI,oBAAoB,IAAI,GAAG;AACjD,mBAAe,OAAO,oBAAoB,MAAM,QAAQ;AAAA,EAC1D;AACA,MAAI,CAAC,eAAe,IAAI,oBAAoB,OAAO,GAAG;AACpD,mBAAe,OAAO,oBAAoB,SAAS,WAAW;AAAA,EAChE;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ToolExecuteCallback, JsonSchema } from '@thegreataxios/webmcp-core';
|
|
2
|
+
|
|
3
|
+
declare const WEBMCP_ELEMENT_TAGS: {
|
|
4
|
+
readonly PROVIDER: "webmcp-provider";
|
|
5
|
+
readonly TOOL: "webmcp-tool";
|
|
6
|
+
readonly JOURNEY: "webmcp-journey";
|
|
7
|
+
};
|
|
8
|
+
interface WebMCPExecuteEventDetail {
|
|
9
|
+
args: Record<string, unknown>;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
respondWith: (value: unknown | Promise<unknown>) => void;
|
|
12
|
+
}
|
|
13
|
+
interface WebMCPToolElementInstance extends HTMLElement {
|
|
14
|
+
execute: ToolExecuteCallback | null;
|
|
15
|
+
inputSchema: JsonSchema | undefined;
|
|
16
|
+
outputSchema: JsonSchema | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Define `<webmcp-provider>`, `<webmcp-tool>`, and `<webmcp-journey>` custom elements.
|
|
20
|
+
* Safe to call multiple times or in SSR environments.
|
|
21
|
+
*/
|
|
22
|
+
declare function registerWebMCPElements(): void;
|
|
23
|
+
|
|
24
|
+
export { WEBMCP_ELEMENT_TAGS, type WebMCPExecuteEventDetail, type WebMCPToolElementInstance, registerWebMCPElements };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ToolExecuteCallback, JsonSchema } from '@thegreataxios/webmcp-core';
|
|
2
|
+
|
|
3
|
+
declare const WEBMCP_ELEMENT_TAGS: {
|
|
4
|
+
readonly PROVIDER: "webmcp-provider";
|
|
5
|
+
readonly TOOL: "webmcp-tool";
|
|
6
|
+
readonly JOURNEY: "webmcp-journey";
|
|
7
|
+
};
|
|
8
|
+
interface WebMCPExecuteEventDetail {
|
|
9
|
+
args: Record<string, unknown>;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
respondWith: (value: unknown | Promise<unknown>) => void;
|
|
12
|
+
}
|
|
13
|
+
interface WebMCPToolElementInstance extends HTMLElement {
|
|
14
|
+
execute: ToolExecuteCallback | null;
|
|
15
|
+
inputSchema: JsonSchema | undefined;
|
|
16
|
+
outputSchema: JsonSchema | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Define `<webmcp-provider>`, `<webmcp-tool>`, and `<webmcp-journey>` custom elements.
|
|
20
|
+
* Safe to call multiple times or in SSR environments.
|
|
21
|
+
*/
|
|
22
|
+
declare function registerWebMCPElements(): void;
|
|
23
|
+
|
|
24
|
+
export { WEBMCP_ELEMENT_TAGS, type WebMCPExecuteEventDetail, type WebMCPToolElementInstance, registerWebMCPElements };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
cleanupPolyfill,
|
|
4
|
+
createPageBridgeClient,
|
|
5
|
+
experimental_createJourneyRegistry,
|
|
6
|
+
getJourneyRegistry,
|
|
7
|
+
installPolyfill,
|
|
8
|
+
setJourneyRegistry
|
|
9
|
+
} from "@thegreataxios/webmcp-core";
|
|
10
|
+
var WEBMCP_ELEMENT_TAGS = {
|
|
11
|
+
PROVIDER: "webmcp-provider",
|
|
12
|
+
TOOL: "webmcp-tool",
|
|
13
|
+
JOURNEY: "webmcp-journey"
|
|
14
|
+
};
|
|
15
|
+
function parseJsonSlot(el, slotName) {
|
|
16
|
+
const script = el.querySelector(`script[type="application/json"][slot="${slotName}"]`);
|
|
17
|
+
if (!script?.textContent) return void 0;
|
|
18
|
+
const parsed = JSON.parse(script.textContent);
|
|
19
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
20
|
+
throw new DOMException(`${slotName} must be a JSON object`, "SyntaxError");
|
|
21
|
+
}
|
|
22
|
+
return parsed;
|
|
23
|
+
}
|
|
24
|
+
function parseCsvAttr(el, name) {
|
|
25
|
+
const raw = el.getAttribute(name);
|
|
26
|
+
if (!raw) return void 0;
|
|
27
|
+
const list = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
28
|
+
return list.length > 0 ? list : void 0;
|
|
29
|
+
}
|
|
30
|
+
var providerCtor = null;
|
|
31
|
+
var toolCtor = null;
|
|
32
|
+
var journeyCtor = null;
|
|
33
|
+
function ensureElementClasses() {
|
|
34
|
+
if (typeof HTMLElement === "undefined") return;
|
|
35
|
+
if (providerCtor && toolCtor && journeyCtor) return;
|
|
36
|
+
providerCtor = class WebMCPProviderElement extends HTMLElement {
|
|
37
|
+
#bridgeClient = null;
|
|
38
|
+
connectedCallback() {
|
|
39
|
+
installPolyfill();
|
|
40
|
+
const bridgeUrl = this.getAttribute("bridge-url");
|
|
41
|
+
const bridgeToken = this.getAttribute("bridge-token");
|
|
42
|
+
if (bridgeUrl && bridgeToken) {
|
|
43
|
+
this.#bridgeClient = createPageBridgeClient({
|
|
44
|
+
url: bridgeUrl,
|
|
45
|
+
token: bridgeToken,
|
|
46
|
+
onStatusChange: (status) => {
|
|
47
|
+
this.dispatchEvent(
|
|
48
|
+
new CustomEvent("webmcp-bridge-status", { detail: { status }, bubbles: true })
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
this.#bridgeClient.connect();
|
|
53
|
+
}
|
|
54
|
+
this.dispatchEvent(new CustomEvent("webmcp-ready", { bubbles: true }));
|
|
55
|
+
}
|
|
56
|
+
disconnectedCallback() {
|
|
57
|
+
this.#bridgeClient?.disconnect();
|
|
58
|
+
this.#bridgeClient = null;
|
|
59
|
+
cleanupPolyfill();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
toolCtor = class WebMCPToolElement extends HTMLElement {
|
|
63
|
+
static get observedAttributes() {
|
|
64
|
+
return [
|
|
65
|
+
"name",
|
|
66
|
+
"title",
|
|
67
|
+
"description",
|
|
68
|
+
"read-only",
|
|
69
|
+
"untrusted-content",
|
|
70
|
+
"consequential",
|
|
71
|
+
"debugging",
|
|
72
|
+
"exposed-to"
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
#controller = null;
|
|
76
|
+
#execute = null;
|
|
77
|
+
#inputSchema;
|
|
78
|
+
#outputSchema;
|
|
79
|
+
#waitingForReady = null;
|
|
80
|
+
get execute() {
|
|
81
|
+
return this.#execute;
|
|
82
|
+
}
|
|
83
|
+
set execute(fn) {
|
|
84
|
+
this.#execute = fn;
|
|
85
|
+
if (this.isConnected) {
|
|
86
|
+
this.#reregister();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
get inputSchema() {
|
|
90
|
+
return this.#inputSchema;
|
|
91
|
+
}
|
|
92
|
+
set inputSchema(schema) {
|
|
93
|
+
this.#inputSchema = schema;
|
|
94
|
+
if (this.isConnected) {
|
|
95
|
+
this.#reregister();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
get outputSchema() {
|
|
99
|
+
return this.#outputSchema;
|
|
100
|
+
}
|
|
101
|
+
set outputSchema(schema) {
|
|
102
|
+
this.#outputSchema = schema;
|
|
103
|
+
if (this.isConnected) {
|
|
104
|
+
this.#reregister();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
connectedCallback() {
|
|
108
|
+
this.#reregister();
|
|
109
|
+
}
|
|
110
|
+
attributeChangedCallback() {
|
|
111
|
+
if (this.isConnected) {
|
|
112
|
+
this.#reregister();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
disconnectedCallback() {
|
|
116
|
+
if (this.#waitingForReady && typeof document !== "undefined") {
|
|
117
|
+
document.removeEventListener("webmcp-ready", this.#waitingForReady);
|
|
118
|
+
this.#waitingForReady = null;
|
|
119
|
+
}
|
|
120
|
+
this.#controller?.abort();
|
|
121
|
+
this.#controller = null;
|
|
122
|
+
}
|
|
123
|
+
#readAnnotations() {
|
|
124
|
+
const hasAny = this.hasAttribute("read-only") || this.hasAttribute("untrusted-content") || this.hasAttribute("consequential") || this.hasAttribute("debugging");
|
|
125
|
+
if (!hasAny) return void 0;
|
|
126
|
+
return {
|
|
127
|
+
readOnlyHint: this.hasAttribute("read-only"),
|
|
128
|
+
untrustedContentHint: this.hasAttribute("untrusted-content"),
|
|
129
|
+
consequentialHint: this.hasAttribute("consequential"),
|
|
130
|
+
debugging: this.hasAttribute("debugging")
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
#reregister() {
|
|
134
|
+
this.#controller?.abort();
|
|
135
|
+
this.#controller = null;
|
|
136
|
+
if (typeof document === "undefined") return;
|
|
137
|
+
if (!document.modelContext) {
|
|
138
|
+
if (!this.#waitingForReady) {
|
|
139
|
+
this.#waitingForReady = () => {
|
|
140
|
+
if (this.#waitingForReady) {
|
|
141
|
+
document.removeEventListener("webmcp-ready", this.#waitingForReady);
|
|
142
|
+
this.#waitingForReady = null;
|
|
143
|
+
}
|
|
144
|
+
if (this.isConnected) {
|
|
145
|
+
this.#reregister();
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
document.addEventListener("webmcp-ready", this.#waitingForReady);
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const name = this.getAttribute("name")?.trim();
|
|
153
|
+
const description = this.getAttribute("description")?.trim();
|
|
154
|
+
if (!name || !description) return;
|
|
155
|
+
const controller = new AbortController();
|
|
156
|
+
this.#controller = controller;
|
|
157
|
+
let inputSchema;
|
|
158
|
+
let outputSchema;
|
|
159
|
+
try {
|
|
160
|
+
inputSchema = this.#inputSchema ?? parseJsonSlot(this, "input-schema");
|
|
161
|
+
outputSchema = this.#outputSchema ?? parseJsonSlot(this, "output-schema");
|
|
162
|
+
} catch (error) {
|
|
163
|
+
this.dispatchEvent(
|
|
164
|
+
new CustomEvent("webmcp-error", { detail: { name, error }, bubbles: true })
|
|
165
|
+
);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const exposedTo = parseCsvAttr(this, "exposed-to");
|
|
169
|
+
const title = this.getAttribute("title") ?? void 0;
|
|
170
|
+
const annotations = this.#readAnnotations();
|
|
171
|
+
const execute = async (args, options) => {
|
|
172
|
+
if (this.#execute) {
|
|
173
|
+
return await this.#execute(args, options);
|
|
174
|
+
}
|
|
175
|
+
let responded = false;
|
|
176
|
+
let responseValue;
|
|
177
|
+
const detail = {
|
|
178
|
+
args,
|
|
179
|
+
signal: options?.signal,
|
|
180
|
+
respondWith(value) {
|
|
181
|
+
responded = true;
|
|
182
|
+
responseValue = value;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
this.dispatchEvent(new CustomEvent("webmcp-execute", { detail, bubbles: true }));
|
|
186
|
+
if (!responded) {
|
|
187
|
+
throw new DOMException(
|
|
188
|
+
`No execute handler or webmcp-execute listener responded for "${name}"`,
|
|
189
|
+
"OperationError"
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return await responseValue;
|
|
193
|
+
};
|
|
194
|
+
document.modelContext.registerTool(
|
|
195
|
+
{ name, title, description, inputSchema, outputSchema, annotations, execute },
|
|
196
|
+
{ signal: controller.signal, exposedTo }
|
|
197
|
+
).catch(() => {
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
journeyCtor = class WebMCPJourneyElement extends HTMLElement {
|
|
202
|
+
static get observedAttributes() {
|
|
203
|
+
return ["name", "tools", "active", "description"];
|
|
204
|
+
}
|
|
205
|
+
#registeredName = null;
|
|
206
|
+
connectedCallback() {
|
|
207
|
+
this.#sync();
|
|
208
|
+
}
|
|
209
|
+
attributeChangedCallback() {
|
|
210
|
+
if (this.isConnected) {
|
|
211
|
+
this.#sync();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
disconnectedCallback() {
|
|
215
|
+
const registry = getJourneyRegistry();
|
|
216
|
+
if (registry && this.#registeredName) {
|
|
217
|
+
registry.unregister(this.#registeredName);
|
|
218
|
+
}
|
|
219
|
+
this.#registeredName = null;
|
|
220
|
+
}
|
|
221
|
+
#sync() {
|
|
222
|
+
const name = this.getAttribute("name")?.trim();
|
|
223
|
+
if (!name) return;
|
|
224
|
+
let registry = getJourneyRegistry();
|
|
225
|
+
if (!registry) {
|
|
226
|
+
registry = experimental_createJourneyRegistry();
|
|
227
|
+
setJourneyRegistry(registry);
|
|
228
|
+
}
|
|
229
|
+
if (this.#registeredName && this.#registeredName !== name) {
|
|
230
|
+
registry.unregister(this.#registeredName);
|
|
231
|
+
}
|
|
232
|
+
const tools = parseCsvAttr(this, "tools") ?? [];
|
|
233
|
+
const description = this.getAttribute("description") ?? void 0;
|
|
234
|
+
registry.register({ name, description, tools });
|
|
235
|
+
registry.setJourneyActive(name, this.hasAttribute("active"));
|
|
236
|
+
this.#registeredName = name;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function registerWebMCPElements() {
|
|
241
|
+
if (typeof customElements === "undefined") return;
|
|
242
|
+
ensureElementClasses();
|
|
243
|
+
if (!providerCtor || !toolCtor || !journeyCtor) return;
|
|
244
|
+
if (!customElements.get(WEBMCP_ELEMENT_TAGS.PROVIDER)) {
|
|
245
|
+
customElements.define(WEBMCP_ELEMENT_TAGS.PROVIDER, providerCtor);
|
|
246
|
+
}
|
|
247
|
+
if (!customElements.get(WEBMCP_ELEMENT_TAGS.TOOL)) {
|
|
248
|
+
customElements.define(WEBMCP_ELEMENT_TAGS.TOOL, toolCtor);
|
|
249
|
+
}
|
|
250
|
+
if (!customElements.get(WEBMCP_ELEMENT_TAGS.JOURNEY)) {
|
|
251
|
+
customElements.define(WEBMCP_ELEMENT_TAGS.JOURNEY, journeyCtor);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
export {
|
|
255
|
+
WEBMCP_ELEMENT_TAGS,
|
|
256
|
+
registerWebMCPElements
|
|
257
|
+
};
|
|
258
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n cleanupPolyfill,\n createPageBridgeClient,\n experimental_createJourneyRegistry,\n getJourneyRegistry,\n installPolyfill,\n setJourneyRegistry,\n type JsonSchema,\n type ToolAnnotations,\n type ToolExecuteCallback,\n type ToolExecuteCallbackOptions,\n} from \"@thegreataxios/webmcp-core\";\n\nexport const WEBMCP_ELEMENT_TAGS = {\n PROVIDER: \"webmcp-provider\",\n TOOL: \"webmcp-tool\",\n JOURNEY: \"webmcp-journey\",\n} as const;\n\nexport interface WebMCPExecuteEventDetail {\n args: Record<string, unknown>;\n signal?: AbortSignal;\n respondWith: (value: unknown | Promise<unknown>) => void;\n}\n\nexport interface WebMCPToolElementInstance extends HTMLElement {\n execute: ToolExecuteCallback | null;\n inputSchema: JsonSchema | undefined;\n outputSchema: JsonSchema | undefined;\n}\n\nfunction parseJsonSlot(el: HTMLElement, slotName: string): JsonSchema | undefined {\n const script = el.querySelector(`script[type=\"application/json\"][slot=\"${slotName}\"]`);\n if (!script?.textContent) return undefined;\n const parsed = JSON.parse(script.textContent) as unknown;\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n throw new DOMException(`${slotName} must be a JSON object`, \"SyntaxError\");\n }\n return parsed as JsonSchema;\n}\n\nfunction parseCsvAttr(el: HTMLElement, name: string): string[] | undefined {\n const raw = el.getAttribute(name);\n if (!raw) return undefined;\n const list = raw\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n return list.length > 0 ? list : undefined;\n}\n\nlet providerCtor: CustomElementConstructor | null = null;\nlet toolCtor: CustomElementConstructor | null = null;\nlet journeyCtor: CustomElementConstructor | null = null;\n\nfunction ensureElementClasses(): void {\n if (typeof HTMLElement === \"undefined\") return;\n if (providerCtor && toolCtor && journeyCtor) return;\n\n providerCtor = class WebMCPProviderElement extends HTMLElement {\n #bridgeClient: ReturnType<typeof createPageBridgeClient> | null = null;\n\n connectedCallback(): void {\n installPolyfill();\n const bridgeUrl = this.getAttribute(\"bridge-url\");\n const bridgeToken = this.getAttribute(\"bridge-token\");\n if (bridgeUrl && bridgeToken) {\n this.#bridgeClient = createPageBridgeClient({\n url: bridgeUrl,\n token: bridgeToken,\n onStatusChange: (status) => {\n this.dispatchEvent(\n new CustomEvent(\"webmcp-bridge-status\", { detail: { status }, bubbles: true }),\n );\n },\n });\n this.#bridgeClient.connect();\n }\n this.dispatchEvent(new CustomEvent(\"webmcp-ready\", { bubbles: true }));\n }\n\n disconnectedCallback(): void {\n this.#bridgeClient?.disconnect();\n this.#bridgeClient = null;\n cleanupPolyfill();\n }\n };\n\n toolCtor = class WebMCPToolElement extends HTMLElement implements WebMCPToolElementInstance {\n static get observedAttributes(): string[] {\n return [\n \"name\",\n \"title\",\n \"description\",\n \"read-only\",\n \"untrusted-content\",\n \"consequential\",\n \"debugging\",\n \"exposed-to\",\n ];\n }\n\n #controller: AbortController | null = null;\n #execute: ToolExecuteCallback | null = null;\n #inputSchema: JsonSchema | undefined;\n #outputSchema: JsonSchema | undefined;\n #waitingForReady: (() => void) | null = null;\n\n get execute(): ToolExecuteCallback | null {\n return this.#execute;\n }\n\n set execute(fn: ToolExecuteCallback | null) {\n this.#execute = fn;\n if (this.isConnected) {\n this.#reregister();\n }\n }\n\n get inputSchema(): JsonSchema | undefined {\n return this.#inputSchema;\n }\n\n set inputSchema(schema: JsonSchema | undefined) {\n this.#inputSchema = schema;\n if (this.isConnected) {\n this.#reregister();\n }\n }\n\n get outputSchema(): JsonSchema | undefined {\n return this.#outputSchema;\n }\n\n set outputSchema(schema: JsonSchema | undefined) {\n this.#outputSchema = schema;\n if (this.isConnected) {\n this.#reregister();\n }\n }\n\n connectedCallback(): void {\n this.#reregister();\n }\n\n attributeChangedCallback(): void {\n if (this.isConnected) {\n this.#reregister();\n }\n }\n\n disconnectedCallback(): void {\n if (this.#waitingForReady && typeof document !== \"undefined\") {\n document.removeEventListener(\"webmcp-ready\", this.#waitingForReady);\n this.#waitingForReady = null;\n }\n this.#controller?.abort();\n this.#controller = null;\n }\n\n #readAnnotations(): ToolAnnotations | undefined {\n const hasAny =\n this.hasAttribute(\"read-only\") ||\n this.hasAttribute(\"untrusted-content\") ||\n this.hasAttribute(\"consequential\") ||\n this.hasAttribute(\"debugging\");\n if (!hasAny) return undefined;\n return {\n readOnlyHint: this.hasAttribute(\"read-only\"),\n untrustedContentHint: this.hasAttribute(\"untrusted-content\"),\n consequentialHint: this.hasAttribute(\"consequential\"),\n debugging: this.hasAttribute(\"debugging\"),\n };\n }\n\n #reregister(): void {\n this.#controller?.abort();\n this.#controller = null;\n\n if (typeof document === \"undefined\") return;\n if (!document.modelContext) {\n if (!this.#waitingForReady) {\n this.#waitingForReady = () => {\n if (this.#waitingForReady) {\n document.removeEventListener(\"webmcp-ready\", this.#waitingForReady);\n this.#waitingForReady = null;\n }\n if (this.isConnected) {\n this.#reregister();\n }\n };\n document.addEventListener(\"webmcp-ready\", this.#waitingForReady);\n }\n return;\n }\n const name = this.getAttribute(\"name\")?.trim();\n const description = this.getAttribute(\"description\")?.trim();\n if (!name || !description) return;\n\n const controller = new AbortController();\n this.#controller = controller;\n\n let inputSchema: JsonSchema | undefined;\n let outputSchema: JsonSchema | undefined;\n try {\n inputSchema = this.#inputSchema ?? parseJsonSlot(this, \"input-schema\");\n outputSchema = this.#outputSchema ?? parseJsonSlot(this, \"output-schema\");\n } catch (error) {\n this.dispatchEvent(\n new CustomEvent(\"webmcp-error\", { detail: { name, error }, bubbles: true }),\n );\n return;\n }\n const exposedTo = parseCsvAttr(this, \"exposed-to\");\n const title = this.getAttribute(\"title\") ?? undefined;\n const annotations = this.#readAnnotations();\n\n const execute: ToolExecuteCallback = async (\n args: Record<string, unknown>,\n options?: ToolExecuteCallbackOptions,\n ) => {\n if (this.#execute) {\n return await this.#execute(args, options);\n }\n let responded = false;\n let responseValue: unknown;\n const detail: WebMCPExecuteEventDetail = {\n args,\n signal: options?.signal,\n respondWith(value) {\n responded = true;\n responseValue = value;\n },\n };\n this.dispatchEvent(new CustomEvent(\"webmcp-execute\", { detail, bubbles: true }));\n if (!responded) {\n throw new DOMException(\n `No execute handler or webmcp-execute listener responded for \"${name}\"`,\n \"OperationError\",\n );\n }\n return await responseValue;\n };\n\n document.modelContext\n .registerTool(\n { name, title, description, inputSchema, outputSchema, annotations, execute },\n { signal: controller.signal, exposedTo },\n )\n .catch(() => {});\n }\n };\n\n journeyCtor = class WebMCPJourneyElement extends HTMLElement {\n static get observedAttributes(): string[] {\n return [\"name\", \"tools\", \"active\", \"description\"];\n }\n\n #registeredName: string | null = null;\n\n connectedCallback(): void {\n this.#sync();\n }\n\n attributeChangedCallback(): void {\n if (this.isConnected) {\n this.#sync();\n }\n }\n\n disconnectedCallback(): void {\n const registry = getJourneyRegistry();\n if (registry && this.#registeredName) {\n registry.unregister(this.#registeredName);\n }\n this.#registeredName = null;\n }\n\n #sync(): void {\n const name = this.getAttribute(\"name\")?.trim();\n if (!name) return;\n\n let registry = getJourneyRegistry();\n if (!registry) {\n registry = experimental_createJourneyRegistry();\n setJourneyRegistry(registry);\n }\n\n if (this.#registeredName && this.#registeredName !== name) {\n registry.unregister(this.#registeredName);\n }\n\n const tools = parseCsvAttr(this, \"tools\") ?? [];\n const description = this.getAttribute(\"description\") ?? undefined;\n registry.register({ name, description, tools });\n registry.setJourneyActive(name, this.hasAttribute(\"active\"));\n this.#registeredName = name;\n }\n };\n}\n\n/**\n * Define `<webmcp-provider>`, `<webmcp-tool>`, and `<webmcp-journey>` custom elements.\n * Safe to call multiple times or in SSR environments.\n */\nexport function registerWebMCPElements(): void {\n if (typeof customElements === \"undefined\") return;\n ensureElementClasses();\n if (!providerCtor || !toolCtor || !journeyCtor) return;\n\n if (!customElements.get(WEBMCP_ELEMENT_TAGS.PROVIDER)) {\n customElements.define(WEBMCP_ELEMENT_TAGS.PROVIDER, providerCtor);\n }\n if (!customElements.get(WEBMCP_ELEMENT_TAGS.TOOL)) {\n customElements.define(WEBMCP_ELEMENT_TAGS.TOOL, toolCtor);\n }\n if (!customElements.get(WEBMCP_ELEMENT_TAGS.JOURNEY)) {\n customElements.define(WEBMCP_ELEMENT_TAGS.JOURNEY, journeyCtor);\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAEA,IAAM,sBAAsB;AAAA,EACjC,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AACX;AAcA,SAAS,cAAc,IAAiB,UAA0C;AAChF,QAAM,SAAS,GAAG,cAAc,yCAAyC,QAAQ,IAAI;AACrF,MAAI,CAAC,QAAQ,YAAa,QAAO;AACjC,QAAM,SAAS,KAAK,MAAM,OAAO,WAAW;AAC5C,MAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,MAAM,QAAQ,MAAM,GAAG;AAC1E,UAAM,IAAI,aAAa,GAAG,QAAQ,0BAA0B,aAAa;AAAA,EAC3E;AACA,SAAO;AACT;AAEA,SAAS,aAAa,IAAiB,MAAoC;AACzE,QAAM,MAAM,GAAG,aAAa,IAAI;AAChC,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,OAAO,IACV,MAAM,GAAG,EACT,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EACnB,OAAO,OAAO;AACjB,SAAO,KAAK,SAAS,IAAI,OAAO;AAClC;AAEA,IAAI,eAAgD;AACpD,IAAI,WAA4C;AAChD,IAAI,cAA+C;AAEnD,SAAS,uBAA6B;AACpC,MAA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hD,MAAI,CAAC,eAAe,IAAI,oBAAoB,QAAQ,GAAG;AACrD,mBAAe,OAAO,oBAAoB,UAAU,YAAY;AAAA,EAClE;AACA,MAAI,CAAC,eAAe,IAAI,oBAAoB,IAAI,GAAG;AACjD,mBAAe,OAAO,oBAAoB,MAAM,QAAQ;AAAA,EAC1D;AACA,MAAI,CAAC,eAAe,IAAI,oBAAoB,OAAO,GAAG;AACpD,mBAAe,OAAO,oBAAoB,SAAS,WAAW;AAAA,EAChE;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thegreataxios/webmcp-elements",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Framework-agnostic Web Components (<webmcp-provider>, <webmcp-tool>, <webmcp-journey>) for W3C WebMCP",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "bun test"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"webmcp",
|
|
28
|
+
"web-components",
|
|
29
|
+
"custom-elements",
|
|
30
|
+
"document.modelContext"
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/TheGreatAxios/webmcp"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@thegreataxios/webmcp-core": "0.2.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@happy-dom/global-registrator": "^20.0.0",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
46
|
+
}
|
|
47
|
+
}
|