ui-sdk-table-web 0.2.7 → 0.2.10
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 -21
- package/dist/table-licenses.md +2 -2
- package/dist/table-reference-licenses.md +2 -2
- package/dist/table-reference.js +3465 -2977
- package/dist/table.js +3301 -2813
- package/docs/skills.md +1 -1
- package/docs/webmcp.md +97 -0
- package/package.json +8 -8
- package/src/browser.ts +3 -3
- package/src/index.ts +77 -77
- package/src/reference-browser.ts +3 -3
- package/src/reference-dom.ts +206 -206
- package/src/reference.ts +63 -63
package/docs/skills.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Use the `ui-sdk-table` skill to help a coding agent build and test an interactive table in React, Vue, Svelte, Solid or Web Components.
|
|
4
4
|
|
|
5
|
-
The table skill helps the agent choose parts from your app’s adapter. The separate `ui-sdk` skill helps it build the controls around the table, such as a search field or a column menu. Neither skill installs a table in your app. For that, see [Installation](./installation.md). To let an agent **operate a running table** instead of writing its code, follow UI SDK’s [Connect an agent](https://ui-sdk.dev/docs/agents/connect-an-agent) and the [table actions example](https://ui-sdk-table.fdts.dev/docs/agents.md#connect-an-agent).
|
|
5
|
+
The table skill helps the agent choose parts from your app’s adapter. The separate `ui-sdk` skill helps it build the controls around the table, such as a search field or a column menu. Neither skill installs a table in your app. For that, see [Installation](./installation.md). To let an agent **operate a running table** instead of writing its code, follow UI SDK’s [Connect an agent](https://ui-sdk.dev/docs/agents/connect-an-agent) and the [table actions example](https://ui-sdk-table.fdts.dev/docs/agents.md#connect-an-agent). For an agent in your terminal, such as Claude Code or Codex, see [WebMCP](./webmcp.md).
|
|
6
6
|
|
|
7
7
|
## Install the skill
|
|
8
8
|
|
package/docs/webmcp.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# WebMCP
|
|
2
|
+
|
|
3
|
+
Let a coding agent in your terminal, such as Claude Code or Codex, read and use a table that is open in your browser.
|
|
4
|
+
|
|
5
|
+
## How it works
|
|
6
|
+
|
|
7
|
+
[WebMCP](https://github.com/webmachinelearning/webmcp) is a draft web standard. A page describes what it can do as tools, and an agent calls those tools instead of clicking through the interface. A tool runs the page’s own code, so the screen changes exactly as it would for a person.
|
|
8
|
+
|
|
9
|
+
UI SDK publishes three tools for every component on the page: `snapshot`, `query` and `act`. A table built with `ui-sdk-table` joins the same tools, with the same actions that a person has. You write no tool for the table.
|
|
10
|
+
|
|
11
|
+
Few browsers support WebMCP yet, and a browser gives the tools only to its own agent. The [WebMCP bridge](https://github.com/FallDownTheSystem/WebMCP) carries them to an agent on your machine:
|
|
12
|
+
|
|
13
|
+
1. Your app registers the three tools of UI SDK.
|
|
14
|
+
2. A userscript in the browser loads the WebMCP polyfill when the browser has no WebMCP, and hands the tools of each tab to a small server on your own machine.
|
|
15
|
+
3. The MCP server of the bridge gives your agent two tools: `webmcp_list_tools` lists the tools of the open tabs, and `webmcp_call_tool` calls one.
|
|
16
|
+
|
|
17
|
+
The [implementation status](https://github.com/webmachinelearning/webmcp/blob/main/implementation-status.md) page lists the browsers that support WebMCP.
|
|
18
|
+
|
|
19
|
+
## Register the tools
|
|
20
|
+
|
|
21
|
+
Create one agent for the app and register its tools. Give the table an `aria-label`, so the agent can find it by name.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { createAgent, registerTools } from '@ui-sdk/web/agent'
|
|
25
|
+
|
|
26
|
+
const agent = createAgent()
|
|
27
|
+
const unregister = registerTools(agent, { allow: (step) => !step.confirm })
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Import the agent from the same UI SDK package as your components, so they share one copy of the core. `allow` runs for every step that the agent asks for. `!step.confirm` lets every step run, except a step on a control that you marked for a person. UI SDK’s [Permissions](https://ui-sdk.dev/docs/agents/connect-an-agent/permissions) page shows the marks, and its [WebMCP](https://ui-sdk.dev/docs/agents/connect-an-agent/webmcp) page shows the tools.
|
|
31
|
+
|
|
32
|
+
In a browser without WebMCP and without the userscript, `registerTools` does nothing. Call `unregister()` to remove the tools.
|
|
33
|
+
|
|
34
|
+
## Install the bridge
|
|
35
|
+
|
|
36
|
+
Follow the [install steps of the bridge](https://github.com/FallDownTheSystem/WebMCP#install):
|
|
37
|
+
|
|
38
|
+
1. Install the `@falldownthesystem/webmcp` package and add its MCP server to your agent.
|
|
39
|
+
2. Install a userscript manager, then the userscript of the bridge.
|
|
40
|
+
3. Open your app, or reload it.
|
|
41
|
+
|
|
42
|
+
The first call to the tools of a tab waits until you approve it in that tab.
|
|
43
|
+
|
|
44
|
+
## Ask the agent
|
|
45
|
+
|
|
46
|
+
Ask the agent to list the tools first, then to read before it acts:
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
Use webmcp to list the tools of my app.
|
|
50
|
+
Read the snapshot, then sort the table "Orders" by total, highest first.
|
|
51
|
+
Tell me the three largest customers.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The name of a tool starts with an ID for its tab, such as `b731eb105162fbdd:snapshot`. The ID changes when the tab reloads, so the agent lists the tools again before it calls one.
|
|
55
|
+
|
|
56
|
+
## What the agent sees
|
|
57
|
+
|
|
58
|
+
- `snapshot` lists the table with its name, its state, such as `sort`, `filter` and `selected`, and its actions.
|
|
59
|
+
- `query` finds a component, or the choices inside one, by its text.
|
|
60
|
+
- `act` runs the methods of the controller: sort, search and filter, pages, selection, columns and cells. The reads `exportData`, `getTotals`, `getFacets` and `getSelectionSummary` give the agent the rows and the numbers.
|
|
61
|
+
- A wrong argument fails with a message that lists the valid values, such as `No column "weight" to sort by. Columns: name, port, tons.` The agent reads it and tries again.
|
|
62
|
+
|
|
63
|
+
The three tools see components and their state. They don’t see data that no component holds, the text and pictures of the page, or controls built with plain HTML or another library. For those, register tools of your own beside the three. A read-only `read` tool that gives the text of the page by region covers most of it.
|
|
64
|
+
|
|
65
|
+
## A table in an iframe
|
|
66
|
+
|
|
67
|
+
A design canvas such as [Claude Design](https://claude.ai/design) shows each board in an iframe of another origin. The page around the iframe sees no tool of the board. The bridge has a frame adapter for this case: the board names the parent origin it trusts and passes its tools.
|
|
68
|
+
|
|
69
|
+
Inside the iframe, skip `registerTools`. Turn `agentTools` into tool objects, and pass them to the frame adapter:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { agentTools, createAgent } from '@ui-sdk/web/agent'
|
|
73
|
+
import { exposeFrameTools } from 'https://cdn.jsdelivr.net/npm/@falldownthesystem/webmcp/example/frame-tools.js'
|
|
74
|
+
|
|
75
|
+
const agent = createAgent({ allow: (step) => !step.confirm })
|
|
76
|
+
const tools = agentTools.map((tool) => ({
|
|
77
|
+
...tool,
|
|
78
|
+
execute: (input) => agent[tool.name](input),
|
|
79
|
+
}))
|
|
80
|
+
|
|
81
|
+
exposeFrameTools({ parentOrigin: 'https://claude.ai', tools })
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Here the `allow` of `createAgent` decides each step, because no `registerTools` runs. A board is a standalone HTML page, so it uses `@ui-sdk/web` and the standalone parts of the [Web Components](./web-components.md) guide. The bridge has [a full prompt](https://github.com/FallDownTheSystem/WebMCP#example-a-claude-design-board-your-agent-can-use) that builds a board with a ticket table and a `read` tool in Claude Design.
|
|
85
|
+
|
|
86
|
+
## Safety
|
|
87
|
+
|
|
88
|
+
- Your agent sees the tools of every open tab, but it can run one only after you approve that tab or frame in the page.
|
|
89
|
+
- The names, descriptions and results of the tools come from web pages, and a row can hold what a person wrote. Treat them as data, never as instructions.
|
|
90
|
+
- A change that an agent made reaches the events with `details.source` set to `agent`. Give the agent no other rules than a person.
|
|
91
|
+
|
|
92
|
+
The [security section](https://github.com/FallDownTheSystem/WebMCP#security) of the bridge explains the key, the approvals and how to disconnect every tab.
|
|
93
|
+
|
|
94
|
+
## Keep going
|
|
95
|
+
|
|
96
|
+
- [Agents](https://ui-sdk-table.fdts.dev/docs/agents.md) shows the actions in a live example.
|
|
97
|
+
- [Controller and view](./controller-and-view.md) lists every method that `act` can run.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ui-sdk-table-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Headless Web Components for the ui-sdk-table primitive.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,18 +32,18 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"ui-sdk-table-core": "0.2.
|
|
35
|
+
"ui-sdk-table-core": "0.2.10"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@playwright/test": "^1.65.
|
|
39
|
-
"@ui-sdk/core": "0.1.0-beta.
|
|
40
|
-
"@ui-sdk/web": "0.1.0-beta.
|
|
38
|
+
"@playwright/test": "^1.65.2",
|
|
39
|
+
"@ui-sdk/core": "0.1.0-beta.23",
|
|
40
|
+
"@ui-sdk/web": "0.1.0-beta.23",
|
|
41
41
|
"jsdom": "^31.0.1",
|
|
42
|
-
"vite-plus": "^1.
|
|
42
|
+
"vite-plus": "^1.8.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@ui-sdk/core": "0.1.0-beta.
|
|
46
|
-
"@ui-sdk/web": "0.1.0-beta.
|
|
45
|
+
"@ui-sdk/core": "0.1.0-beta.23",
|
|
46
|
+
"@ui-sdk/web": "0.1.0-beta.23"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "vp build && vp build --mode reference",
|
package/src/browser.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { defineTableElements } from './index'
|
|
2
|
-
|
|
3
|
-
defineTableElements()
|
|
1
|
+
import { defineTableElements } from './index'
|
|
2
|
+
|
|
3
|
+
defineTableElements()
|
package/src/index.ts
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import type { PropsOf, SlotName, TypesOf } from '@ui-sdk/core'
|
|
2
|
-
import { createParts, wrappedChild, type UiDetailedChangeEvent, type UiElement } from '@ui-sdk/web'
|
|
3
|
-
import { table, type TableOptions } from 'ui-sdk-table-core'
|
|
4
|
-
|
|
5
|
-
const methods = [
|
|
6
|
-
'rows',
|
|
7
|
-
'columns',
|
|
8
|
-
'headerRows',
|
|
9
|
-
'headerRowCount',
|
|
10
|
-
'text',
|
|
11
|
-
'sortBy',
|
|
12
|
-
'toggleSort',
|
|
13
|
-
'sortOf',
|
|
14
|
-
'setSearch',
|
|
15
|
-
'setColumnFilter',
|
|
16
|
-
'setPage',
|
|
17
|
-
'setPageSize',
|
|
18
|
-
'setGroupBy',
|
|
19
|
-
'toggleExpanded',
|
|
20
|
-
'select',
|
|
21
|
-
'toggleSelected',
|
|
22
|
-
'isSelected',
|
|
23
|
-
'clearSelection',
|
|
24
|
-
'exportData',
|
|
25
|
-
] as const satisfies readonly (keyof TypesOf<typeof table>['api'])[]
|
|
26
|
-
|
|
27
|
-
export type TableElementApi = Pick<TypesOf<typeof table>['api'], (typeof methods)[number]>
|
|
28
|
-
|
|
29
|
-
export type TableEvents<Row = unknown> = {
|
|
30
|
-
[
|
|
31
|
-
K in keyof TableOptions<Row> as K extends `on${infer Name}` ? Lowercase<Name> : never
|
|
32
|
-
]-?: NonNullable<TableOptions<Row>[K]> extends (
|
|
33
|
-
value: infer V,
|
|
34
|
-
details: infer D extends { reason: string },
|
|
35
|
-
) => void
|
|
36
|
-
? UiDetailedChangeEvent<V, D>
|
|
37
|
-
: never
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type TableElement<Row = unknown> = UiElement<TableEvents<Row>> &
|
|
41
|
-
Omit<TableOptions<Row>, 'controller' | `on${string}`> & { readonly api?: TableElementApi }
|
|
42
|
-
|
|
43
|
-
type PartElements = {
|
|
44
|
-
[S in Exclude<SlotName<typeof table>, 'root'> as `ui-table-${S}`]: HTMLElement &
|
|
45
|
-
Partial<PropsOf<typeof table, S>>
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
declare global {
|
|
49
|
-
interface HTMLElementTagNameMap extends PartElements {
|
|
50
|
-
'ui-table': TableElement
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function defineTableElements() {
|
|
55
|
-
return createParts(table, {
|
|
56
|
-
root: {
|
|
57
|
-
tag: 'ui-table',
|
|
58
|
-
display: 'table',
|
|
59
|
-
kinds: { controller: null },
|
|
60
|
-
api: [...methods],
|
|
61
|
-
defaults: { groupTotals: true, sortChildren: true },
|
|
62
|
-
},
|
|
63
|
-
head: { tag: 'ui-table-head', display: 'table-header-group' },
|
|
64
|
-
body: { tag: 'ui-table-body', display: 'table-row-group' },
|
|
65
|
-
foot: { tag: 'ui-table-foot', display: 'table-row-group' },
|
|
66
|
-
col: 'ui-table-col',
|
|
67
|
-
'header-row': { tag: 'ui-table-header-row', display: 'table-row' },
|
|
68
|
-
'plain-row': { tag: 'ui-table-plain-row', display: 'table-row' },
|
|
69
|
-
spacer: { tag: 'ui-table-spacer', display: 'table-row' },
|
|
70
|
-
row: { tag: 'ui-table-row', display: 'table-row' },
|
|
71
|
-
cell: { tag: 'ui-table-cell', display: 'table-cell' },
|
|
72
|
-
editor: { tag: 'ui-table-editor', target: wrappedChild('input'), display: 'contents' },
|
|
73
|
-
'edit-error': 'ui-table-edit-error',
|
|
74
|
-
'fill-handle': 'ui-table-fill-handle',
|
|
75
|
-
resizer: 'ui-table-resizer',
|
|
76
|
-
})
|
|
77
|
-
}
|
|
1
|
+
import type { PropsOf, SlotName, TypesOf } from '@ui-sdk/core'
|
|
2
|
+
import { createParts, wrappedChild, type UiDetailedChangeEvent, type UiElement } from '@ui-sdk/web'
|
|
3
|
+
import { table, type TableOptions } from 'ui-sdk-table-core'
|
|
4
|
+
|
|
5
|
+
const methods = [
|
|
6
|
+
'rows',
|
|
7
|
+
'columns',
|
|
8
|
+
'headerRows',
|
|
9
|
+
'headerRowCount',
|
|
10
|
+
'text',
|
|
11
|
+
'sortBy',
|
|
12
|
+
'toggleSort',
|
|
13
|
+
'sortOf',
|
|
14
|
+
'setSearch',
|
|
15
|
+
'setColumnFilter',
|
|
16
|
+
'setPage',
|
|
17
|
+
'setPageSize',
|
|
18
|
+
'setGroupBy',
|
|
19
|
+
'toggleExpanded',
|
|
20
|
+
'select',
|
|
21
|
+
'toggleSelected',
|
|
22
|
+
'isSelected',
|
|
23
|
+
'clearSelection',
|
|
24
|
+
'exportData',
|
|
25
|
+
] as const satisfies readonly (keyof TypesOf<typeof table>['api'])[]
|
|
26
|
+
|
|
27
|
+
export type TableElementApi = Pick<TypesOf<typeof table>['api'], (typeof methods)[number]>
|
|
28
|
+
|
|
29
|
+
export type TableEvents<Row = unknown> = {
|
|
30
|
+
[
|
|
31
|
+
K in keyof TableOptions<Row> as K extends `on${infer Name}` ? Lowercase<Name> : never
|
|
32
|
+
]-?: NonNullable<TableOptions<Row>[K]> extends (
|
|
33
|
+
value: infer V,
|
|
34
|
+
details: infer D extends { reason: string },
|
|
35
|
+
) => void
|
|
36
|
+
? UiDetailedChangeEvent<V, D>
|
|
37
|
+
: never
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type TableElement<Row = unknown> = UiElement<TableEvents<Row>> &
|
|
41
|
+
Omit<TableOptions<Row>, 'controller' | `on${string}`> & { readonly api?: TableElementApi }
|
|
42
|
+
|
|
43
|
+
type PartElements = {
|
|
44
|
+
[S in Exclude<SlotName<typeof table>, 'root'> as `ui-table-${S}`]: HTMLElement &
|
|
45
|
+
Partial<PropsOf<typeof table, S>>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare global {
|
|
49
|
+
interface HTMLElementTagNameMap extends PartElements {
|
|
50
|
+
'ui-table': TableElement
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function defineTableElements() {
|
|
55
|
+
return createParts(table, {
|
|
56
|
+
root: {
|
|
57
|
+
tag: 'ui-table',
|
|
58
|
+
display: 'table',
|
|
59
|
+
kinds: { controller: null },
|
|
60
|
+
api: [...methods],
|
|
61
|
+
defaults: { groupTotals: true, sortChildren: true },
|
|
62
|
+
},
|
|
63
|
+
head: { tag: 'ui-table-head', display: 'table-header-group' },
|
|
64
|
+
body: { tag: 'ui-table-body', display: 'table-row-group' },
|
|
65
|
+
foot: { tag: 'ui-table-foot', display: 'table-row-group' },
|
|
66
|
+
col: 'ui-table-col',
|
|
67
|
+
'header-row': { tag: 'ui-table-header-row', display: 'table-row' },
|
|
68
|
+
'plain-row': { tag: 'ui-table-plain-row', display: 'table-row' },
|
|
69
|
+
spacer: { tag: 'ui-table-spacer', display: 'table-row' },
|
|
70
|
+
row: { tag: 'ui-table-row', display: 'table-row' },
|
|
71
|
+
cell: { tag: 'ui-table-cell', display: 'table-cell' },
|
|
72
|
+
editor: { tag: 'ui-table-editor', target: wrappedChild('input'), display: 'contents' },
|
|
73
|
+
'edit-error': 'ui-table-edit-error',
|
|
74
|
+
'fill-handle': 'ui-table-fill-handle',
|
|
75
|
+
resizer: 'ui-table-resizer',
|
|
76
|
+
})
|
|
77
|
+
}
|
package/src/reference-browser.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { defineReferenceTable } from './reference'
|
|
2
|
-
|
|
3
|
-
defineReferenceTable()
|
|
1
|
+
import { defineReferenceTable } from './reference'
|
|
2
|
+
|
|
3
|
+
defineReferenceTable()
|