@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.
Files changed (2) hide show
  1. package/README.md +57 -24
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,51 +1,84 @@
1
1
  # @agentable-ui/react
2
2
 
3
- React bindings for [`@agentable-ui/core`](../core): `AgentableProvider`, `useCapability`, `useTool`, `ToolScope`.
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
- ## Usage
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 App() {
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
- <Orders />
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
- ## API
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
- **`<AgentableProvider>`** creates the registry with the WebMCP adapter and a built-in confirmation dialog. Pass `confirm` for your own handler, `confirm={false}` to run consequential tools unconfirmed (a dev warning is logged), `renderConfirm` for custom UI, or `agentable` to bring your own registry.
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
- **`useCapability(cap | null)`** declares a full capability descriptor. The registry only sees a new declaration when the static shape changes, so a fresh `execute` closure every render costs nothing. Pass `null` to switch the agent layer off for that component.
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
- **`useTool(options)`** is the shorthand for a single hand-rolled tool; `id` defaults to `tool.<name>`, and `enabled: false` disables it without unmounting.
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
- **`<ToolScope group describe>`** groups the capabilities inside it and demotes them from tier 0 to tier 1 once the region has been offscreen for `demoteAfter` ms (default 5000). Scrolling back promotes them again with no re-declare.
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
- **`useAgentableSnapshot()`** returns the live registry snapshot — resident tools, budget, cache stats, adapters, warnings, estimated tokens. Re-renders on every registry change, so use it sparingly. **`useAgentPresent()`** is true once the first agent call arrives.
72
+ ## Read registry state
44
73
 
45
- **`useAgentable()`** returns the registry from the nearest provider, or `null`.
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
- ## SSR and StrictMode
80
+ ## Lifecycle and rendering
48
81
 
49
- Registration happens in effects only, so nothing runs during SSR. Declarations are refcounted and identity-stable across re-renders. The provider defers its `dispose()` by a macrotask so StrictMode's mount → unmount → remount cycle cannot tear down the registry the second mount reuses.
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.0",
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.1.0"
37
+ "@agentable-ui/core": "^0.2.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^18.2.0 || ^19.0.0"