@agentuity/react 0.0.3 → 0.0.5

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 (3) hide show
  1. package/AGENTS.md +97 -0
  2. package/README.md +152 -0
  3. package/package.json +2 -1
package/AGENTS.md ADDED
@@ -0,0 +1,97 @@
1
+ # Agent Guidelines for @agentuity/react
2
+
3
+ ## Package Overview
4
+
5
+ React hooks and components for building Agentuity web applications. Provides type-safe hooks for calling agents and WebSocket communication.
6
+
7
+ ## Commands
8
+
9
+ - **Build**: `bun run build` (compiles for browser target)
10
+ - **Typecheck**: `bun run typecheck` (runs TypeScript type checking)
11
+ - **Clean**: `bun run clean` (removes dist/)
12
+
13
+ ## Architecture
14
+
15
+ - **Runtime**: Browser only (uses browser APIs like fetch, WebSocket)
16
+ - **Build target**: Browser with ESNext
17
+ - **Dependencies**: Requires `@agentuity/core` (workspace dependency)
18
+ - **Peer dependencies**: React 18+ or 19+
19
+
20
+ ## Structure
21
+
22
+ ```
23
+ src/
24
+ ├── index.ts # Main entry point
25
+ ├── context.tsx # AgentuityProvider and AgentuityContext
26
+ ├── run.ts # useAgent hook for HTTP calls
27
+ ├── websocket.ts # useWebsocket hook for WebSocket
28
+ ├── types.ts # Type definitions for agent registry
29
+ ├── url.ts # URL building utilities
30
+ └── env.ts # Environment helpers
31
+ ```
32
+
33
+ ## Code Style
34
+
35
+ - **React hooks** - Follow React hooks conventions
36
+ - **TypeScript generics** - Heavy use of generics for type safety
37
+ - **Functional components** - All components are functional
38
+ - **Context API** - Use React Context for configuration
39
+ - **Error boundaries** - Throw errors that can be caught by error boundaries
40
+
41
+ ## Important Conventions
42
+
43
+ - **Provider required** - All hooks must be used within `AgentuityProvider`
44
+ - **Type inference** - Agent types are inferred from generated types (AgentRegistry)
45
+ - **Base URL** - Defaults to current origin if not provided
46
+ - **WebSocket protocol** - Auto-converts http:// to ws:// and https:// to wss://
47
+ - **Serialization** - Automatically handles JSON serialization/deserialization
48
+
49
+ ## Hooks API
50
+
51
+ ### useAgent
52
+
53
+ ```typescript
54
+ const { data, run } = useAgent('agentName');
55
+ ```
56
+
57
+ - Returns last response in `data`
58
+ - `run()` function for calling the agent
59
+ - Supports custom headers, query params, subpaths
60
+
61
+ ### useWebsocket
62
+
63
+ ```typescript
64
+ const { connected, send, setHandler, close } = useWebsocket('/path');
65
+ ```
66
+
67
+ - Auto-reconnection on connection loss
68
+ - Message queuing when disconnected
69
+ - Type-safe message handlers
70
+
71
+ ## Generated Types
72
+
73
+ This package expects a `AgentRegistry` type to be augmented by generated code:
74
+
75
+ ```typescript
76
+ // Generated by bundler
77
+ export interface AgentRegistry {
78
+ 'my-agent': {
79
+ inputSchema: z.ZodObject<...>;
80
+ outputSchema: z.ZodObject<...>;
81
+ };
82
+ }
83
+ ```
84
+
85
+ ## Testing
86
+
87
+ - Test with React Testing Library
88
+ - Mock fetch and WebSocket APIs
89
+ - Test error boundaries
90
+ - Test with and without provider
91
+
92
+ ## Publishing Checklist
93
+
94
+ 1. Run `bun run build` to compile for browser
95
+ 2. Verify `dist/` contains browser-compatible code (no Node.js APIs)
96
+ 3. Ensure peer dependencies are correctly specified
97
+ 4. Must publish **after** @agentuity/core
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # @agentuity/react
2
+
3
+ React hooks and components for building Agentuity web applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @agentuity/react
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ `@agentuity/react` provides React hooks and context providers for seamlessly integrating with Agentuity agents from your frontend application.
14
+
15
+ ## Features
16
+
17
+ - **Type-safe agent calls** - Fully typed React hooks for calling agents
18
+ - **WebSocket support** - Real-time bidirectional communication with agents
19
+ - **Context provider** - Simple setup with React Context
20
+ - **Automatic data management** - Built-in state management for agent responses
21
+
22
+ ## Quick Start
23
+
24
+ ### 1. Setup Provider
25
+
26
+ Wrap your app with the `AgentuityProvider`:
27
+
28
+ ```tsx
29
+ import { AgentuityProvider } from '@agentuity/react';
30
+
31
+ function App() {
32
+ return (
33
+ <AgentuityProvider baseUrl="http://localhost:3000">
34
+ <YourApp />
35
+ </AgentuityProvider>
36
+ );
37
+ }
38
+ ```
39
+
40
+ ### 2. Use Agents
41
+
42
+ Call agents with type-safety using the `useAgent` hook:
43
+
44
+ ```tsx
45
+ import { useAgent } from '@agentuity/react';
46
+
47
+ function MyComponent() {
48
+ const { data, run } = useAgent('myAgent');
49
+
50
+ const handleClick = async () => {
51
+ const result = await run({ message: 'Hello' });
52
+ console.log(result);
53
+ };
54
+
55
+ return (
56
+ <div>
57
+ <button onClick={handleClick}>Call Agent</button>
58
+ {data && <div>Response: {JSON.stringify(data)}</div>}
59
+ </div>
60
+ );
61
+ }
62
+ ```
63
+
64
+ ### 3. WebSocket Communication
65
+
66
+ For real-time communication:
67
+
68
+ ```tsx
69
+ import { useWebsocket } from '@agentuity/react';
70
+
71
+ function ChatComponent() {
72
+ const { connected, send, setHandler } = useWebsocket('/chat');
73
+
74
+ useEffect(() => {
75
+ setHandler((message) => {
76
+ console.log('Received:', message);
77
+ });
78
+ }, []);
79
+
80
+ const sendMessage = () => {
81
+ send({ text: 'Hello, agent!' });
82
+ };
83
+
84
+ return (
85
+ <div>
86
+ <div>Status: {connected ? 'Connected' : 'Disconnected'}</div>
87
+ <button onClick={sendMessage} disabled={!connected}>
88
+ Send Message
89
+ </button>
90
+ </div>
91
+ );
92
+ }
93
+ ```
94
+
95
+ ## API Reference
96
+
97
+ ### AgentuityProvider
98
+
99
+ Context provider for Agentuity configuration.
100
+
101
+ **Props:**
102
+ - `baseUrl?: string` - Base URL for agent API calls (defaults to current origin)
103
+ - `children: ReactNode` - Child components
104
+
105
+ ### useAgent
106
+
107
+ Hook for calling agents via HTTP.
108
+
109
+ ```typescript
110
+ const { data, run } = useAgent<TName>(name);
111
+ ```
112
+
113
+ **Parameters:**
114
+ - `name: string` - Agent name
115
+
116
+ **Returns:**
117
+ - `data?: TOutput` - Last response data
118
+ - `run: (input: TInput, options?: RunArgs) => Promise<TOutput>` - Function to invoke the agent
119
+
120
+ **RunArgs:**
121
+ - `query?: URLSearchParams` - Query parameters
122
+ - `headers?: Record<string, string>` - Custom headers
123
+ - `subpath?: string` - Subpath to append to agent URL
124
+ - `method?: string` - HTTP method (default: POST)
125
+ - `signal?: AbortSignal` - Abort signal for cancellation
126
+
127
+ ### useWebsocket
128
+
129
+ Hook for WebSocket connections to agents.
130
+
131
+ ```typescript
132
+ const { connected, send, setHandler, readyState, close } = useWebsocket<TInput, TOutput>(path, options);
133
+ ```
134
+
135
+ **Parameters:**
136
+ - `path: string` - WebSocket path
137
+ - `options?: WebsocketArgs` - Connection options
138
+
139
+ **Returns:**
140
+ - `connected: boolean` - Connection status
141
+ - `send: (data: TInput) => void` - Send data to server
142
+ - `setHandler: (handler: (data: TOutput) => void) => void` - Set message handler
143
+ - `readyState: number` - WebSocket ready state
144
+ - `close: () => void` - Close connection
145
+
146
+ ## TypeScript
147
+
148
+ All hooks are fully typed and will infer input/output types from your agent definitions when using the generated types.
149
+
150
+ ## License
151
+
152
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/react",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -11,6 +11,7 @@
11
11
  }
12
12
  },
13
13
  "files": [
14
+ "AGENTS.md",
14
15
  "README.md",
15
16
  "dist"
16
17
  ],