@artooi/ag-ui-web-component 0.12.0 → 0.13.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/CHANGELOG.md CHANGED
@@ -7,6 +7,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.13.0] — 2026-07-27
11
+
12
+ ### Added
13
+
14
+ - **AG-UI shared state.** `<ag-ui-chat>` now speaks the protocol's own state
15
+ channel: assign `chat.sharedState = {...}` to seed it, listen for the
16
+ `ag-ui-state` event (`detail.state`) to react when the agent changes it.
17
+ State rides `RunAgentInput.state` on every run and is replaced in place when
18
+ the server streams `STATE_SNAPSHOT` / `STATE_DELTA`.
19
+ - **Adoption, not implementation.** `@ag-ui/client` already applies both
20
+ events to `agent.state` and exposes an `onStateChanged` subscriber hook;
21
+ what was missing was seeding it (`initialState`) and surfacing it to the
22
+ host. Deriving state from the raw event stream ourselves would have
23
+ duplicated — and eventually contradicted — the client's own handling,
24
+ including its JSON-Patch delta application.
25
+ - Assigning **after** the conversation has started pushes through to the live
26
+ agent rather than waiting for a new one, so a host that seeds state late
27
+ isn't silently stranded.
28
+ - The event is `composed: true`, so a host listening on `document` receives it
29
+ through the shadow boundary.
30
+ - **Distinct from `registerPageState`**, which exposes host state to the agent
31
+ as ordinary *tools*. Use shared state when agent and page edit the same
32
+ object; use page-state tools when the agent should *ask* — a tool call is
33
+ visible in the transcript and can be gated by a confirmation card, which
34
+ state events cannot.
35
+
36
+ ### Changed
37
+
38
+ - **`registerStateHook` is now `registerPageState`** (and `createStateHookTools` /
39
+ `StateHook` are `createPageStateTools` / `PageState`). **The old names implied a
40
+ feature that does not exist**: they read as AG-UI shared-state sync —
41
+ `STATE_SNAPSHOT` / `STATE_DELTA`, the protocol events that carry a state object
42
+ between agent and client — which neither this component nor `django-ag-ui`
43
+ implements. What the method actually does is generate two ordinary client tools
44
+ (`read_<name>` / `set_<name>`) over host page state, which the agent calls like
45
+ any other tool. `page` matches the vocabulary already used throughout the
46
+ component (`page_map`, `page_action_tools`, `route_map`, the DOM driver).
47
+ - **Not a hard break.** The old spellings are kept as deprecated aliases and
48
+ behave identically; they will be removed in a future major. A rename is only
49
+ ever cheaper the earlier it happens, which is why this ships now rather than
50
+ waiting for state support to exist.
51
+
52
+ ### Documentation
53
+
54
+ - **The README now distinguishes the two state mechanisms**, which the old
55
+ method name conflated. `sharedState` is the protocol's state channel;
56
+ `registerPageState` generates ordinary client tools. The rename and the
57
+ feature landed together, so the docs answer "which one" rather than leaving
58
+ two similar names side by side.
59
+
10
60
  ## [0.12.0] — 2026-07-27
11
61
 
12
62
  ### Added
@@ -528,7 +578,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
528
578
  ### Notes
529
579
  - First release — exercising the automated npm OIDC publish pipeline end-to-end.
530
580
 
531
- [Unreleased]: https://github.com/Artui/ag-ui-web-component/compare/v0.12.0...HEAD
581
+ [Unreleased]: https://github.com/Artui/ag-ui-web-component/compare/v0.13.0...HEAD
582
+ [0.13.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.12.0...v0.13.0
532
583
  [0.12.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.11.0...v0.12.0
533
584
  [0.11.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.10.0...v0.11.0
534
585
  [0.10.0]: https://github.com/Artui/ag-ui-web-component/compare/v0.9.0...v0.10.0
package/README.md CHANGED
@@ -191,7 +191,9 @@ the django-ag-ui `@tool` registry), whose schema never reaches the browser — e
191
191
  labels are fetched automatically — per card, `x-summary` → an explicit
192
192
  `toolSummaries` entry → the fetched catalog → the raw name.
193
193
 
194
- **Methods**: `registerTool`, `registerStateHook`, `setSkills`, `appendMessage`, `newChat`,
194
+ **Properties** (selected): `sharedState` AG-UI shared state (documented under Tools & state).
195
+
196
+ **Methods**: `registerTool`, `registerPageState`, `setSkills`, `appendMessage`, `newChat`,
195
197
  `setCollapsed`, `toggleCollapsed`.
196
198
 
197
199
  A self-contained live playground lives in [`demo/`](demo/) — run `make demo` to serve it against a
@@ -621,12 +623,12 @@ so it reflects the page the agent is currently looking at:
621
623
  chat.getPageMap = () => ({ fields: introspectForm(), buttons: visibleButtons() });
622
624
  ```
623
625
 
624
- **`registerStateHook({ name, read, write?, schema? })`** — ergonomic sugar over `registerTool` for
626
+ **`registerPageState({ name, read, write?, schema? })`** — ergonomic sugar over `registerTool` for
625
627
  SPA app state (Redux/Zustand/signals). It auto-generates a `read_<name>` (read-only) tool and, when
626
628
  `write` is supplied, a `set_<name>` tool stamped `x-destructive`:
627
629
 
628
630
  ```js
629
- chat.registerStateHook({
631
+ chat.registerPageState({
630
632
  name: "cart",
631
633
  read: () => store.getState().cart,
632
634
  write: ({ items }) => store.dispatch(setCart(items)),
@@ -634,6 +636,42 @@ chat.registerStateHook({
634
636
  });
635
637
  ```
636
638
 
639
+ **This is not AG-UI shared state** — that is `sharedState`, below. `registerPageState` generates two
640
+ ordinary client tools; the agent reads or writes your store by *calling a tool*. The method was
641
+ called `registerStateHook` through 0.12, a name that read as protocol state sync; the old spelling
642
+ still works and is deprecated.
643
+
644
+ **`sharedState`** *(property)* — AG-UI **shared state**: the protocol's own state channel, sent as
645
+ `RunAgentInput.state` on every run and replaced in place when the server streams `STATE_SNAPSHOT` /
646
+ `STATE_DELTA`. Assign to seed it, listen for `ag-ui-state` to react:
647
+
648
+ ```js
649
+ chat.sharedState = { document: "" };
650
+
651
+ chat.addEventListener("ag-ui-state", (e) => {
652
+ editor.value = e.detail.state.document; // the agent rewrote it
653
+ });
654
+ ```
655
+
656
+ Server-side, a tool mutates `ctx.deps.state` and returns the snapshot as `ToolReturn` metadata —
657
+ pydantic-ai does not emit deltas for you:
658
+
659
+ ```python
660
+ @tool(registry)
661
+ async def write_document(ctx: RunContext[AgentDeps], body: str) -> ToolReturn:
662
+ """Replace the shared document."""
663
+ ctx.deps.state = {**(ctx.deps.state or {}), "document": body}
664
+ return ToolReturn(
665
+ return_value="written",
666
+ metadata=[StateSnapshotEvent(type=EventType.STATE_SNAPSHOT, snapshot=ctx.deps.state)],
667
+ )
668
+ ```
669
+
670
+ Use this when the agent and the page are editing **the same object** (a document, a form, a
671
+ canvas). Use `registerPageState` when the agent should *ask* for a value or *request* a change —
672
+ the tool call is visible in the transcript and can be gated by a confirmation card, which state
673
+ events cannot.
674
+
637
675
  **`navigate(path): void`** *(optional)* — a host routing callback. **This single seam is what
638
676
  distinguishes an SPA from an MPA.** When set, `navigate_to_route` routes client-side (no reload) and
639
677
  the in-memory run loop simply continues — the whole resumable-loop / checkpoint machinery is
@@ -798,8 +836,8 @@ re-export point. Internal modules import from leaf paths.
798
836
  | `RouteWithParams` | type | A route resolved with `:param` path segments + leftover query params. |
799
837
  | `createPageMapContext(...)` | function | Build the per-run `page_map` context entry. |
800
838
  | `PageMap` | type | The compact page-surface shape. |
801
- | `createStateHookTools(hook)` | function | Build `read_<name>` / `set_<name>` tools. |
802
- | `StateHook` | type | A state-binding declaration. |
839
+ | `createPageStateTools(binding)` | function | Build `read_<name>` / `set_<name>` tools. |
840
+ | `PageState` | type | A page-state binding declaration. |
803
841
  | `Skill` | type | A launchable prompt (chip / `/`-command). |
804
842
 
805
843
  ### Durability