react-websocket/ag-ui
Run AG-UI agents over a WebSocket. The guide is AG-UI over WebSockets.
The entry has no React dependency. useAgUiAgent comes from react-websocket. createAgUiAgent is about 3.5 kB min+gzip, including the runs and feeds it uses, which it shares with the other entries.
createAgUiAgent
Returns an AgUiAgent<S>:
AgUiThread
AgUiMessage has AG-UI's message fields: id, role, content, and toolCalls (each { id, type: 'function', function: { name, arguments } }) for assistant messages, toolCallId for tool messages, and activityType for activity messages.
useAgUiAgent
From react-websocket. The agent's thread, re-rendering on every event.
applyAgUiEvent
Fold one AG-UI event into a thread without changing it. createAgUiAgent uses it to reduce each run. Use it yourself to reduce AG-UI events from another source, or wrap it to handle CUSTOM events:
A STATE_DELTA that can't be applied returns the thread with stale: true and the state unchanged, and later deltas are skipped until a STATE_SNAPSHOT.
applyPatch
Apply a JSON Patch (add, remove, replace, move, copy, test) without changing document: what changes is copied, and the rest is shared. Throws if an operation can't be applied, such as a missing path, an index out of range (an array's length isn't one of its members), a pointer that doesn't start with /, or a failed test, and document stays as it was. A key such as __proto__ is added as a property of its own, as JSON.parse would.