@webmcpui/core 0.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/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/chunk-ADS4GRIL.js +14 -0
- package/dist/index.d.ts +378 -0
- package/dist/index.js +1002 -0
- package/dist/testing.d.ts +34 -0
- package/dist/testing.js +47 -0
- package/dist/webmcp-DEspBoqq.d.ts +47 -0
- package/dist/webmcpui.global.js +343 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gary Pfaff (Pfaff Digital)
|
|
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
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @webmcpui/core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic, WebMCP-native custom elements. Phase 1 ships form
|
|
4
|
+
primitives — shared behavior (form association, validation, WebMCP exposure,
|
|
5
|
+
theming) lives in a `WmcpFormControl` base class; each element is a thin
|
|
6
|
+
subclass that supplies its control and specifics.
|
|
7
|
+
|
|
8
|
+
Shipped so far: `<wmcp-input>`, `<wmcp-textarea>`, `<wmcp-select>`, `<wmcp-checkbox>`.
|
|
9
|
+
|
|
10
|
+
One source of truth (vanilla custom elements built with [Lit](https://lit.dev)),
|
|
11
|
+
two distribution channels: an ESM package for build tools, and a single-file
|
|
12
|
+
CDN bundle for no-build environments (Webflow, WordPress, plain HTML).
|
|
13
|
+
|
|
14
|
+
## Install (build-tool consumers)
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @webmcpui/core @webmcpui/tokens
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { defineComponents } from '@webmcpui/core';
|
|
22
|
+
import '@webmcpui/tokens/css'; // the theme tokens (CSS custom properties)
|
|
23
|
+
|
|
24
|
+
defineComponents(); // registers <wmcp-input> (and future <wmcp-*> elements)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<wmcp-input label="Email" name="email" type="email"></wmcp-input>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Importing the package does **not** register elements — you call
|
|
32
|
+
`defineComponents()` so you control timing. (The CDN bundle below registers
|
|
33
|
+
automatically.)
|
|
34
|
+
|
|
35
|
+
## No build? Drop a script tag
|
|
36
|
+
|
|
37
|
+
For Webflow / WordPress / hand-written HTML — one tag, elements auto-register:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@webmcpui/tokens/dist/css/tokens.css" />
|
|
41
|
+
<script src="https://cdn.jsdelivr.net/npm/@webmcpui/core/dist/webmcpui.global.js"></script>
|
|
42
|
+
|
|
43
|
+
<wmcp-input label="Email" name="email" type="email"></wmcp-input>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
See `examples/plain-html.html` for a working local version.
|
|
47
|
+
|
|
48
|
+
## Standard Schema validation
|
|
49
|
+
|
|
50
|
+
Bring any [Standard Schema](https://standardschema.dev) validator — Zod,
|
|
51
|
+
Valibot, ArkType — set it as the `schema` property. No bespoke schema language.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { z } from 'zod';
|
|
55
|
+
|
|
56
|
+
const input = document.querySelector('wmcp-input')!;
|
|
57
|
+
input.schema = z.string().email('Enter a valid email');
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Validation runs on input and during native form validation; failures set
|
|
61
|
+
`aria-invalid`, render an error message in a live region, and propagate to the
|
|
62
|
+
containing `<form>` via ElementInternals.
|
|
63
|
+
|
|
64
|
+
> **Note:** Standard Schema validates values but does not emit JSON Schema, so
|
|
65
|
+
> the WebMCP tool's parameter schema is derived from the input `type`, not from
|
|
66
|
+
> the validator. Richer tool schemas are a future enhancement.
|
|
67
|
+
|
|
68
|
+
## WebMCP exposure
|
|
69
|
+
|
|
70
|
+
Opt in with `expose`. The element registers an imperative WebMCP tool
|
|
71
|
+
(`navigator.modelContext.registerTool`) on connect and unregisters on
|
|
72
|
+
disconnect. It is feature-detected — a complete no-op when no agent/host is
|
|
73
|
+
present (the common case today), so the input is always a good form control
|
|
74
|
+
first.
|
|
75
|
+
|
|
76
|
+
```html
|
|
77
|
+
<wmcp-input label="Email" name="email" expose></wmcp-input>
|
|
78
|
+
<!-- registers a "fill_email" tool an agent can call -->
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Testing without a real agent
|
|
82
|
+
|
|
83
|
+
No mainstream agent calls WebMCP yet, so `@webmcpui/core/testing` ships a fake
|
|
84
|
+
host to exercise exposure end to end (and seeds the future inspector):
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { installFakeAgent } from '@webmcpui/core/testing';
|
|
88
|
+
|
|
89
|
+
const agent = installFakeAgent();
|
|
90
|
+
// ... connect a <wmcp-input expose> ...
|
|
91
|
+
await agent.call('fill_email', { value: 'agent@webmcpui.com' });
|
|
92
|
+
agent.restore();
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Build & test
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pnpm build # tsup → dist/ (ESM + IIFE + d.ts)
|
|
99
|
+
pnpm typecheck # tsc --noEmit
|
|
100
|
+
pnpm test # @web/test-runner in real Chromium (form association,
|
|
101
|
+
# validation a11y, WebMCP exposure)
|
|
102
|
+
pnpm test:smoke # node smoke check against the built dist
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Tests run in a genuine browser via the Playwright launcher — form-associated
|
|
106
|
+
custom elements and ElementInternals don't work under jsdom. First run needs
|
|
107
|
+
the browser binary:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pnpm exec playwright install chromium
|
|
111
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
__decorateClass
|
|
14
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import * as lit from 'lit';
|
|
2
|
+
import { LitElement, CSSResultGroup, TemplateResult, nothing } from 'lit';
|
|
3
|
+
import { J as JSONSchema } from './webmcp-DEspBoqq.js';
|
|
4
|
+
export { T as ToolDisposer, W as WebMCPToolDefinition, a as WebMCPToolResult, b as WebMCPToolResultContent, e as exposeTool, i as isWebMCPAvailable } from './webmcp-DEspBoqq.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimal Standard Schema v1 types + a validation helper.
|
|
8
|
+
*
|
|
9
|
+
* We deliberately depend only on the interop spec (https://standardschema.dev),
|
|
10
|
+
* never on a specific validator. Devs bring Zod, Valibot, ArkType — anything
|
|
11
|
+
* that implements `~standard`. This is the Skillet-avoidance decision: no
|
|
12
|
+
* bespoke schema language, zero learning curve.
|
|
13
|
+
*/
|
|
14
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
15
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
16
|
+
}
|
|
17
|
+
declare namespace StandardSchemaV1 {
|
|
18
|
+
interface Props<Input = unknown, Output = Input> {
|
|
19
|
+
readonly version: 1;
|
|
20
|
+
readonly vendor: string;
|
|
21
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
22
|
+
readonly types?: Types<Input, Output>;
|
|
23
|
+
}
|
|
24
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
25
|
+
interface SuccessResult<Output> {
|
|
26
|
+
readonly value: Output;
|
|
27
|
+
readonly issues?: undefined;
|
|
28
|
+
}
|
|
29
|
+
interface FailureResult {
|
|
30
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
31
|
+
}
|
|
32
|
+
interface Issue {
|
|
33
|
+
readonly message: string;
|
|
34
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment>;
|
|
35
|
+
}
|
|
36
|
+
interface PathSegment {
|
|
37
|
+
readonly key: PropertyKey;
|
|
38
|
+
}
|
|
39
|
+
interface Types<Input = unknown, Output = Input> {
|
|
40
|
+
readonly input: Input;
|
|
41
|
+
readonly output: Output;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
interface ValidationOutcome<Output> {
|
|
45
|
+
/** True when the value passed validation. */
|
|
46
|
+
readonly valid: boolean;
|
|
47
|
+
/** The (possibly transformed) output value when valid. */
|
|
48
|
+
readonly value?: Output;
|
|
49
|
+
/** Flat list of human-readable messages when invalid. */
|
|
50
|
+
readonly errors: readonly string[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Run a Standard Schema validator and normalize the result into a flat outcome
|
|
54
|
+
* the components can consume. Awaits async validators transparently.
|
|
55
|
+
*/
|
|
56
|
+
declare function validateStandard<Output>(schema: StandardSchemaV1<unknown, Output>, value: unknown): Promise<ValidationOutcome<Output>>;
|
|
57
|
+
/** Duck-type check that an unknown value is a Standard Schema. */
|
|
58
|
+
declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Base class for form-associated, agent-operable controls.
|
|
62
|
+
*
|
|
63
|
+
* Owns everything shared across the form primitives:
|
|
64
|
+
* - native `<form>` participation via ElementInternals (`formAssociated`)
|
|
65
|
+
* - Standard Schema validation + a11y error wiring
|
|
66
|
+
* - imperative WebMCP exposure (feature-detected, no-op when absent)
|
|
67
|
+
* - label / control / message layout and the shared themed appearance
|
|
68
|
+
*
|
|
69
|
+
* Subclasses implement {@link renderControl} (the actual `<input>` /
|
|
70
|
+
* `<textarea>` / …) and may override {@link controlNoun} and
|
|
71
|
+
* {@link toolInputSchema}. Abstract — not registered on its own.
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* Text-field box appearance for the `.control` element. Used by input,
|
|
75
|
+
* textarea, and select — the controls that render as a bordered field.
|
|
76
|
+
*/
|
|
77
|
+
declare const textFieldStyles: lit.CSSResult;
|
|
78
|
+
declare abstract class WmcpFormControl extends LitElement {
|
|
79
|
+
static formAssociated: boolean;
|
|
80
|
+
static styles: CSSResultGroup;
|
|
81
|
+
/** Visible label text. */
|
|
82
|
+
label: string;
|
|
83
|
+
/** Form control name (used for submission and the default tool name). */
|
|
84
|
+
name: string;
|
|
85
|
+
/** Current value (reflected to the form). */
|
|
86
|
+
value: string;
|
|
87
|
+
placeholder: string;
|
|
88
|
+
required: boolean;
|
|
89
|
+
disabled: boolean;
|
|
90
|
+
/** Helper text shown below the control when there is no error. */
|
|
91
|
+
helperText: string;
|
|
92
|
+
/** Message shown when a `required` control is empty. */
|
|
93
|
+
requiredMessage: string;
|
|
94
|
+
/** Whether to expose this control as a WebMCP tool. */
|
|
95
|
+
expose: boolean;
|
|
96
|
+
/** Override the generated WebMCP tool name. */
|
|
97
|
+
toolName: string;
|
|
98
|
+
/** Override the generated WebMCP tool description. */
|
|
99
|
+
toolDescription: string;
|
|
100
|
+
/**
|
|
101
|
+
* Standard Schema validator (Zod, Valibot, ArkType, …). Set as a property,
|
|
102
|
+
* not an attribute. Validation runs on input and on form validation.
|
|
103
|
+
*/
|
|
104
|
+
schema?: StandardSchemaV1<unknown, unknown>;
|
|
105
|
+
protected error: string;
|
|
106
|
+
protected readonly internals: ElementInternals;
|
|
107
|
+
private toolDisposer;
|
|
108
|
+
/** Noun used in default tool names/descriptions when `name` is empty. */
|
|
109
|
+
protected get controlNoun(): string;
|
|
110
|
+
/** The rendered control element (`<input>` / `<textarea>` / `<select>`). */
|
|
111
|
+
protected get control(): HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null;
|
|
112
|
+
/** Id to point the control's `aria-describedby` at, if any. */
|
|
113
|
+
protected get describedBy(): string | undefined;
|
|
114
|
+
connectedCallback(): void;
|
|
115
|
+
/**
|
|
116
|
+
* The value contributed to the containing form. Defaults to the string
|
|
117
|
+
* `value`; controls with a conditional contribution (e.g. an unchecked
|
|
118
|
+
* checkbox) override this and may return `null` to contribute nothing.
|
|
119
|
+
*/
|
|
120
|
+
protected getFormValue(): string | File | FormData | null;
|
|
121
|
+
/** Push the current form value into ElementInternals. */
|
|
122
|
+
protected syncFormValue(): void;
|
|
123
|
+
/**
|
|
124
|
+
* The value passed to the schema validator. Defaults to the string `value`;
|
|
125
|
+
* boolean controls (checkbox) override to validate their checked state.
|
|
126
|
+
*/
|
|
127
|
+
protected get validationValue(): unknown;
|
|
128
|
+
/**
|
|
129
|
+
* Whether the control counts as empty for the `required` constraint.
|
|
130
|
+
* Defaults to an empty string value; boolean controls (checkbox) override.
|
|
131
|
+
*/
|
|
132
|
+
protected get isEmpty(): boolean;
|
|
133
|
+
/** Default message for the `required` constraint when none is provided. */
|
|
134
|
+
protected get requiredMessageDefault(): string;
|
|
135
|
+
disconnectedCallback(): void;
|
|
136
|
+
updated(changed: Map<string, unknown>): void;
|
|
137
|
+
/** The resolved WebMCP tool name. */
|
|
138
|
+
get resolvedToolName(): string;
|
|
139
|
+
protected registerTool(): void;
|
|
140
|
+
/**
|
|
141
|
+
* Apply the agent's tool arguments to component state. Defaults to treating
|
|
142
|
+
* `args.value` as the new string value; controls with a different shape
|
|
143
|
+
* (e.g. checkbox's `args.checked`) override this.
|
|
144
|
+
*/
|
|
145
|
+
protected applyAgentValue(args: Record<string, unknown>): Promise<void>;
|
|
146
|
+
/** Human-readable current state, used in the tool's result message. */
|
|
147
|
+
protected stateDescription(): string;
|
|
148
|
+
/** JSON Schema for the WebMCP tool's args. Defaults to a single string. */
|
|
149
|
+
protected toolInputSchema(): JSONSchema;
|
|
150
|
+
/** Apply a value as if a user typed it: update, validate, announce. */
|
|
151
|
+
setValueFromAgent(value: string): Promise<void>;
|
|
152
|
+
protected onInput(event: Event): Promise<void>;
|
|
153
|
+
/** Compute validity: the `required` constraint first, then the schema. */
|
|
154
|
+
private computeValidity;
|
|
155
|
+
/**
|
|
156
|
+
* Validate and reflect the result to the form via ElementInternals.
|
|
157
|
+
*
|
|
158
|
+
* @param show When true (default, on interaction) the error is also made
|
|
159
|
+
* visible. When false (on connect/reset) validity is set for
|
|
160
|
+
* `form.checkValidity()` but the message stays hidden until the form is
|
|
161
|
+
* actually reported (native-style — the `invalid` event reveals it).
|
|
162
|
+
*/
|
|
163
|
+
validate(show?: boolean): Promise<boolean>;
|
|
164
|
+
/** Reveal the validation message when the form reports validity (submit). */
|
|
165
|
+
private readonly onInvalid;
|
|
166
|
+
/** Called by the form when it resets. */
|
|
167
|
+
formResetCallback(): void;
|
|
168
|
+
/** Subclasses render their control element here (id/class "control"). */
|
|
169
|
+
protected abstract renderControl(): TemplateResult;
|
|
170
|
+
protected renderMessage(): TemplateResult<1> | typeof nothing;
|
|
171
|
+
render(): TemplateResult<1>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
type WmcpInputType = 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'search' | 'date';
|
|
175
|
+
/**
|
|
176
|
+
* `<wmcp-input>` — a form-associated, agent-operable single-line text input.
|
|
177
|
+
*
|
|
178
|
+
* Behavior (form association, validation, WebMCP exposure, theming) comes from
|
|
179
|
+
* {@link WmcpFormControl}; this adds the `type` attribute and the `<input>`.
|
|
180
|
+
*
|
|
181
|
+
* Not auto-registered — call `defineComponents()` (or load the CDN bundle).
|
|
182
|
+
*/
|
|
183
|
+
declare class WmcpInput extends WmcpFormControl {
|
|
184
|
+
static readonly tagName = "wmcp-input";
|
|
185
|
+
static styles: lit.CSSResultGroup[];
|
|
186
|
+
/** HTML input type. */
|
|
187
|
+
type: WmcpInputType;
|
|
188
|
+
protected get controlNoun(): string;
|
|
189
|
+
protected toolInputSchema(): JSONSchema;
|
|
190
|
+
protected renderControl(): lit.TemplateResult<1>;
|
|
191
|
+
}
|
|
192
|
+
declare global {
|
|
193
|
+
interface HTMLElementTagNameMap {
|
|
194
|
+
'wmcp-input': WmcpInput;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* `<wmcp-textarea>` — a form-associated, agent-operable multi-line text input.
|
|
200
|
+
*
|
|
201
|
+
* Behavior comes from {@link WmcpFormControl}; this adds the `rows` attribute
|
|
202
|
+
* and the `<textarea>`. It shares the input token surface (`--input-*`) and
|
|
203
|
+
* adds `--textarea-min-height`.
|
|
204
|
+
*
|
|
205
|
+
* Not auto-registered — call `defineComponents()` (or load the CDN bundle).
|
|
206
|
+
*/
|
|
207
|
+
declare class WmcpTextarea extends WmcpFormControl {
|
|
208
|
+
static readonly tagName = "wmcp-textarea";
|
|
209
|
+
static styles: lit.CSSResultGroup[];
|
|
210
|
+
/** Initial visible number of text lines. */
|
|
211
|
+
rows: number;
|
|
212
|
+
protected get controlNoun(): string;
|
|
213
|
+
protected renderControl(): lit.TemplateResult<1>;
|
|
214
|
+
}
|
|
215
|
+
declare global {
|
|
216
|
+
interface HTMLElementTagNameMap {
|
|
217
|
+
'wmcp-textarea': WmcpTextarea;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
interface WmcpSelectOption {
|
|
222
|
+
value: string;
|
|
223
|
+
label: string;
|
|
224
|
+
disabled?: boolean;
|
|
225
|
+
}
|
|
226
|
+
interface WmcpSelectOptionGroup {
|
|
227
|
+
label: string;
|
|
228
|
+
options: WmcpSelectOption[];
|
|
229
|
+
}
|
|
230
|
+
type WmcpSelectItem = WmcpSelectOption | WmcpSelectOptionGroup;
|
|
231
|
+
/**
|
|
232
|
+
* `<wmcp-select>` — a form-associated, agent-operable single-select dropdown.
|
|
233
|
+
*
|
|
234
|
+
* Wraps a native `<select>` (correct keyboard nav, screen-reader behavior, and
|
|
235
|
+
* mobile pickers for free). Options come from declarative `<option>` /
|
|
236
|
+
* `<optgroup>` children (HTML-native, works with no build) or from the
|
|
237
|
+
* `options` property (for JS / framework callers).
|
|
238
|
+
*
|
|
239
|
+
* The value is a single string, so form association and WebMCP fill behavior
|
|
240
|
+
* come from {@link WmcpFormControl}; this adds the option model and a tool
|
|
241
|
+
* schema whose `value` is an `enum` of the valid option values.
|
|
242
|
+
*
|
|
243
|
+
* Not auto-registered — call `defineComponents()` (or load the CDN bundle).
|
|
244
|
+
*/
|
|
245
|
+
declare class WmcpSelect extends WmcpFormControl {
|
|
246
|
+
static readonly tagName = "wmcp-select";
|
|
247
|
+
static styles: lit.CSSResultGroup[];
|
|
248
|
+
/**
|
|
249
|
+
* Options as data. When non-empty, takes precedence over declarative
|
|
250
|
+
* `<option>` children. Set as a property, not an attribute.
|
|
251
|
+
*/
|
|
252
|
+
options: WmcpSelectItem[];
|
|
253
|
+
/** The normalized option model actually rendered (property or declarative). */
|
|
254
|
+
private resolvedOptions;
|
|
255
|
+
private optionObserver?;
|
|
256
|
+
protected get controlNoun(): string;
|
|
257
|
+
connectedCallback(): void;
|
|
258
|
+
disconnectedCallback(): void;
|
|
259
|
+
willUpdate(changed: Map<string, unknown>): void;
|
|
260
|
+
updated(changed: Map<string, unknown>): void;
|
|
261
|
+
private syncOptions;
|
|
262
|
+
private readDeclarativeOptions;
|
|
263
|
+
/** All selectable options, flattened across groups. */
|
|
264
|
+
flatOptions(): WmcpSelectOption[];
|
|
265
|
+
protected toolInputSchema(): JSONSchema;
|
|
266
|
+
private renderOption;
|
|
267
|
+
protected renderControl(): lit.TemplateResult<1>;
|
|
268
|
+
}
|
|
269
|
+
declare global {
|
|
270
|
+
interface HTMLElementTagNameMap {
|
|
271
|
+
'wmcp-select': WmcpSelect;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* `<wmcp-checkbox>` — a form-associated, agent-operable boolean checkbox.
|
|
277
|
+
*
|
|
278
|
+
* The first non-string control. Its primary state is the boolean `checked`;
|
|
279
|
+
* `value` is the string submitted to the form *when checked* (native default
|
|
280
|
+
* `"on"`). This is why {@link WmcpFormControl} exposes hooks: checkbox overrides
|
|
281
|
+
* `getFormValue` (conditional), `validationValue` (the boolean),
|
|
282
|
+
* `applyAgentValue` / `toolInputSchema` (a `checked` boolean), and
|
|
283
|
+
* `formResetCallback` (restore the initial checked state).
|
|
284
|
+
*
|
|
285
|
+
* Not auto-registered — call `defineComponents()` (or load the CDN bundle).
|
|
286
|
+
*/
|
|
287
|
+
declare class WmcpCheckbox extends WmcpFormControl {
|
|
288
|
+
static readonly tagName = "wmcp-checkbox";
|
|
289
|
+
static styles: lit.CSSResultGroup[];
|
|
290
|
+
/** Whether the box is checked. */
|
|
291
|
+
checked: boolean;
|
|
292
|
+
private defaultChecked;
|
|
293
|
+
constructor();
|
|
294
|
+
protected get controlNoun(): string;
|
|
295
|
+
connectedCallback(): void;
|
|
296
|
+
protected getFormValue(): string | File | FormData | null;
|
|
297
|
+
protected get validationValue(): unknown;
|
|
298
|
+
protected get isEmpty(): boolean;
|
|
299
|
+
protected get requiredMessageDefault(): string;
|
|
300
|
+
protected toolInputSchema(): JSONSchema;
|
|
301
|
+
protected applyAgentValue(args: Record<string, unknown>): Promise<void>;
|
|
302
|
+
protected stateDescription(): string;
|
|
303
|
+
formResetCallback(): void;
|
|
304
|
+
private onToggle;
|
|
305
|
+
protected renderControl(): lit.TemplateResult<1>;
|
|
306
|
+
render(): lit.TemplateResult<1>;
|
|
307
|
+
}
|
|
308
|
+
declare global {
|
|
309
|
+
interface HTMLElementTagNameMap {
|
|
310
|
+
'wmcp-checkbox': WmcpCheckbox;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
interface WmcpRadioOption {
|
|
315
|
+
value: string;
|
|
316
|
+
label: string;
|
|
317
|
+
disabled?: boolean;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* `<wmcp-radio>` — a data member of a `<wmcp-radio-group>`.
|
|
321
|
+
*
|
|
322
|
+
* Like `<option>` is to `<select>`: it carries `value` / `label` / `disabled`
|
|
323
|
+
* and renders nothing itself. The group reads these and renders the actual
|
|
324
|
+
* radio inputs. Registered so it hides itself when used declaratively.
|
|
325
|
+
*/
|
|
326
|
+
declare class WmcpRadio extends HTMLElement {
|
|
327
|
+
static readonly tagName = "wmcp-radio";
|
|
328
|
+
get value(): string;
|
|
329
|
+
get label(): string;
|
|
330
|
+
get disabled(): boolean;
|
|
331
|
+
connectedCallback(): void;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* `<wmcp-radio-group>` — a form-associated, agent-operable single-choice group.
|
|
335
|
+
*
|
|
336
|
+
* The group is the form participant (owns name, value, validation, exposure);
|
|
337
|
+
* `<wmcp-radio>` children are data. The group renders the native radio inputs
|
|
338
|
+
* in its own shadow DOM under one internal name, so native single-selection,
|
|
339
|
+
* roving tabindex, and arrow-key navigation all work. Options come from
|
|
340
|
+
* declarative `<wmcp-radio>` children or the `options` property.
|
|
341
|
+
*
|
|
342
|
+
* Not auto-registered — call `defineComponents()` (or load the CDN bundle).
|
|
343
|
+
*/
|
|
344
|
+
declare class WmcpRadioGroup extends WmcpFormControl {
|
|
345
|
+
static readonly tagName = "wmcp-radio-group";
|
|
346
|
+
static styles: lit.CSSResultGroup[];
|
|
347
|
+
/** Options as data. When non-empty, takes precedence over `<wmcp-radio>`. */
|
|
348
|
+
options: WmcpRadioOption[];
|
|
349
|
+
private resolvedOptions;
|
|
350
|
+
private optionObserver?;
|
|
351
|
+
/** Internal name shared by the rendered inputs (groups them natively). */
|
|
352
|
+
private readonly groupName;
|
|
353
|
+
protected get controlNoun(): string;
|
|
354
|
+
connectedCallback(): void;
|
|
355
|
+
disconnectedCallback(): void;
|
|
356
|
+
willUpdate(changed: Map<string, unknown>): void;
|
|
357
|
+
updated(changed: Map<string, unknown>): void;
|
|
358
|
+
private syncOptions;
|
|
359
|
+
private readDeclarativeOptions;
|
|
360
|
+
protected toolInputSchema(): JSONSchema;
|
|
361
|
+
private onSelect;
|
|
362
|
+
protected renderControl(): lit.TemplateResult<1>;
|
|
363
|
+
render(): lit.TemplateResult<1>;
|
|
364
|
+
}
|
|
365
|
+
declare global {
|
|
366
|
+
interface HTMLElementTagNameMap {
|
|
367
|
+
'wmcp-radio': WmcpRadio;
|
|
368
|
+
'wmcp-radio-group': WmcpRadioGroup;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Register all webmcpui custom elements. Idempotent — safe to call more than
|
|
374
|
+
* once and safe alongside the CDN bundle (already-defined tags are skipped).
|
|
375
|
+
*/
|
|
376
|
+
declare function defineComponents(): void;
|
|
377
|
+
|
|
378
|
+
export { JSONSchema, StandardSchemaV1, type ValidationOutcome, WmcpCheckbox, WmcpFormControl, WmcpInput, type WmcpInputType, WmcpRadio, WmcpRadioGroup, type WmcpRadioOption, WmcpSelect, type WmcpSelectItem, type WmcpSelectOption, type WmcpSelectOptionGroup, WmcpTextarea, defineComponents, isStandardSchema, textFieldStyles, validateStandard };
|