@agentable-ui/react 0.1.0 → 0.1.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/README.md +57 -24
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,51 +1,84 @@
|
|
|
1
1
|
# @agentable-ui/react
|
|
2
2
|
|
|
3
|
-
React
|
|
3
|
+
Connect React components to the [Agentable registry](../core). Use a provider for setup, hooks for custom tools, and scopes to group related features.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
4
6
|
|
|
5
7
|
```bash
|
|
6
8
|
npm install @agentable-ui/react @agentable-ui/core
|
|
7
9
|
```
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
Requires React 18.2+ or React 19. Use a client component in frameworks that distinguish server and client components.
|
|
12
|
+
|
|
13
|
+
## Add a tool
|
|
10
14
|
|
|
11
15
|
```tsx
|
|
12
16
|
import { AgentableProvider, useTool } from "@agentable-ui/react";
|
|
13
17
|
|
|
14
|
-
function
|
|
18
|
+
function OrderSummary() {
|
|
19
|
+
useTool({
|
|
20
|
+
name: "count_orders",
|
|
21
|
+
description: "Return the number of demo orders.",
|
|
22
|
+
annotations: { readOnlyHint: true },
|
|
23
|
+
execute: () => ({ count: 2 }),
|
|
24
|
+
});
|
|
25
|
+
return <p>2 orders</p>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default function App() {
|
|
15
29
|
return (
|
|
16
30
|
<AgentableProvider budget={12}>
|
|
17
|
-
<
|
|
31
|
+
<OrderSummary />
|
|
18
32
|
</AgentableProvider>
|
|
19
33
|
);
|
|
20
34
|
}
|
|
21
|
-
|
|
22
|
-
function Orders() {
|
|
23
|
-
useTool({
|
|
24
|
-
name: "refresh_orders",
|
|
25
|
-
description: "Reload the orders list.",
|
|
26
|
-
annotations: { readOnlyHint: true },
|
|
27
|
-
execute: () => refetch(),
|
|
28
|
-
});
|
|
29
|
-
return <table>…</table>;
|
|
30
|
-
}
|
|
31
35
|
```
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
The provider owns one registry and adds the WebMCP adapter plus a built-in confirmation dialog. Browser support is optional for rendering your app. Add [devtools](../devtools) to inspect and call tools locally.
|
|
38
|
+
|
|
39
|
+
## Provider options
|
|
40
|
+
|
|
41
|
+
| Prop | Purpose |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `budget` | Maximum resident tools, including discovery tools; default 12. |
|
|
44
|
+
| `confirm` | Custom async confirmation handler. Omit for the built-in dialog. `false` explicitly disables confirmation. |
|
|
45
|
+
| `renderConfirm` | Customize the confirmation UI. |
|
|
46
|
+
| `agentable` | Supply an existing registry instead of creating one. |
|
|
47
|
+
|
|
48
|
+
For full registry options, see [core](../core). Imported registries retain their own configuration.
|
|
49
|
+
|
|
50
|
+
## Declare tools
|
|
51
|
+
|
|
52
|
+
**`useTool(options)`** is the shorthand for a single tool. Give it `name`, `description`, `inputSchema` when needed, and `execute`. Its capability id defaults to `tool.<name>`. Set `enabled: false` to disable it without unmounting.
|
|
34
53
|
|
|
35
|
-
|
|
54
|
+
**`useCapability(capability | null)`** accepts the full descriptor, including tier, priority, group, fan-in, and render metadata. Pass `null` to remove the declaration.
|
|
36
55
|
|
|
37
|
-
|
|
56
|
+
Callbacks use the latest render's values. Changing a callback alone does not re-register the tool; changing its static descriptor can. Tool names and capability ids should stay stable across renders.
|
|
38
57
|
|
|
39
|
-
|
|
58
|
+
Mark pure reads with `annotations: { readOnlyHint: true }`. They skip confirmation and cache by default. Use `cache: false` if each call must re-read changing state or update UI. Mutations ask for confirmation unless explicitly configured otherwise.
|
|
59
|
+
|
|
60
|
+
## Group a feature
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { ToolScope } from "@agentable-ui/react";
|
|
64
|
+
|
|
65
|
+
<ToolScope group="orders" describe="Order management" demoteAfter={5000}>
|
|
66
|
+
<OrderSummary />
|
|
67
|
+
</ToolScope>
|
|
68
|
+
```
|
|
40
69
|
|
|
41
|
-
|
|
70
|
+
Scopes provide group metadata to descendants. When their region stays offscreen for `demoteAfter` milliseconds, eligible tools move from tier 0 to tier 1. Scrolling back restores their eligibility within the budget. Offscreen is different from unmounted: an unmounted component releases its declaration.
|
|
42
71
|
|
|
43
|
-
|
|
72
|
+
## Read registry state
|
|
44
73
|
|
|
45
|
-
|
|
74
|
+
| Hook | Returns |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `useAgentable()` | Nearest registry, or `null` outside a provider. |
|
|
77
|
+
| `useAgentableSnapshot()` | Current tools, budget, cache stats, adapters, warnings, and token estimate. Re-renders on registry changes. |
|
|
78
|
+
| `useAgentPresent()` | Whether the registry has received an agent invocation. This is a heuristic, not a browser presence event. |
|
|
46
79
|
|
|
47
|
-
##
|
|
80
|
+
## Lifecycle and rendering
|
|
48
81
|
|
|
49
|
-
Registration happens in effects
|
|
82
|
+
Registration happens in effects, so SSR does not register browser tools. Declarations are reference-counted, and provider cleanup is deferred to survive React StrictMode's development mount cycle. Without a provider, optional `agent` props are inert and a warning is emitted.
|
|
50
83
|
|
|
51
|
-
MIT
|
|
84
|
+
MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentable-ui/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "React bindings for @agentable-ui/core: AgentableProvider, useTool, useCapability, ToolScope.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@agentable-ui/core": "^0.
|
|
37
|
+
"@agentable-ui/core": "^0.2.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "^18.2.0 || ^19.0.0"
|