@antipopp/agno-react 0.1.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/LICENSE +21 -0
- package/README.md +340 -0
- package/dist/index.d.mts +116 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +416 -0
- package/dist/index.mjs +384 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 antipopp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
# @antipopp/agno-react
|
|
2
|
+
|
|
3
|
+
React hooks for Agno client with full TypeScript support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @antipopp/agno-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package includes `@antipopp/agno-client` and `@antipopp/agno-types` as dependencies.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- ✅ **Easy Integration** - Drop-in React hooks for Agno agents
|
|
16
|
+
- ✅ **Context Provider** - Manages client lifecycle automatically
|
|
17
|
+
- ✅ **Real-time Updates** - React state synced with streaming updates
|
|
18
|
+
- ✅ **Type-Safe** - Full TypeScript support
|
|
19
|
+
- ✅ **Familiar API** - Matches the original Agno React hooks design
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Wrap Your App with AgnoProvider
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { AgnoProvider } from '@antipopp/agno-react';
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
return (
|
|
30
|
+
<AgnoProvider
|
|
31
|
+
config={{
|
|
32
|
+
endpoint: 'http://localhost:7777',
|
|
33
|
+
mode: 'agent',
|
|
34
|
+
agentId: 'your-agent-id',
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<YourComponents />
|
|
38
|
+
</AgnoProvider>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Use Hooks in Your Components
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { useAgnoChat, useAgnoActions } from '@antipopp/agno-react';
|
|
47
|
+
|
|
48
|
+
function ChatComponent() {
|
|
49
|
+
const { messages, sendMessage, isStreaming, error } = useAgnoChat();
|
|
50
|
+
const { initialize } = useAgnoActions();
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
initialize();
|
|
54
|
+
}, [initialize]);
|
|
55
|
+
|
|
56
|
+
const handleSend = async () => {
|
|
57
|
+
await sendMessage('Hello, agent!');
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div>
|
|
62
|
+
{messages.map((msg, i) => (
|
|
63
|
+
<div key={i}>
|
|
64
|
+
<strong>{msg.role}:</strong> {msg.content}
|
|
65
|
+
</div>
|
|
66
|
+
))}
|
|
67
|
+
{error && <div>Error: {error}</div>}
|
|
68
|
+
<button onClick={handleSend} disabled={isStreaming}>
|
|
69
|
+
{isStreaming ? 'Sending...' : 'Send'}
|
|
70
|
+
</button>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## API Reference
|
|
77
|
+
|
|
78
|
+
### AgnoProvider
|
|
79
|
+
|
|
80
|
+
Provider component that creates and manages an `AgnoClient` instance.
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
<AgnoProvider config={config}>
|
|
84
|
+
{children}
|
|
85
|
+
</AgnoProvider>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Props:**
|
|
89
|
+
- `config` (AgnoClientConfig) - Client configuration
|
|
90
|
+
- `children` (ReactNode) - Child components
|
|
91
|
+
|
|
92
|
+
### useAgnoClient()
|
|
93
|
+
|
|
94
|
+
Access the underlying `AgnoClient` instance.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
const client = useAgnoClient();
|
|
98
|
+
|
|
99
|
+
// Use client methods directly
|
|
100
|
+
await client.sendMessage('Hello!');
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### useAgnoChat()
|
|
104
|
+
|
|
105
|
+
Main hook for chat interactions.
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
const {
|
|
109
|
+
messages, // ChatMessage[] - Current messages
|
|
110
|
+
sendMessage, // (message, options?) => Promise<void>
|
|
111
|
+
clearMessages, // () => void
|
|
112
|
+
isStreaming, // boolean - Is currently streaming
|
|
113
|
+
error, // string | undefined - Current error
|
|
114
|
+
state, // ClientState - Full client state
|
|
115
|
+
} = useAgnoChat();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Methods:**
|
|
119
|
+
|
|
120
|
+
#### `sendMessage(message, options?)`
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
// Send a text message
|
|
124
|
+
await sendMessage('Hello!');
|
|
125
|
+
|
|
126
|
+
// Send with FormData (for file uploads)
|
|
127
|
+
const formData = new FormData();
|
|
128
|
+
formData.append('message', 'Hello!');
|
|
129
|
+
formData.append('file', file);
|
|
130
|
+
await sendMessage(formData);
|
|
131
|
+
|
|
132
|
+
// Send with custom headers
|
|
133
|
+
await sendMessage('Hello!', {
|
|
134
|
+
headers: { 'X-Custom': 'value' }
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### `clearMessages()`
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
clearMessages(); // Clears all messages and resets session
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### useAgnoSession()
|
|
145
|
+
|
|
146
|
+
Hook for session management.
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
const {
|
|
150
|
+
sessions, // SessionEntry[] - Available sessions
|
|
151
|
+
currentSessionId, // string | undefined - Current session ID
|
|
152
|
+
loadSession, // (sessionId) => Promise<ChatMessage[]>
|
|
153
|
+
fetchSessions, // () => Promise<SessionEntry[]>
|
|
154
|
+
isLoading, // boolean - Is loading session
|
|
155
|
+
error, // string | undefined - Current error
|
|
156
|
+
} = useAgnoSession();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Example:**
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
function SessionList() {
|
|
163
|
+
const { sessions, loadSession, fetchSessions } = useAgnoSession();
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
fetchSessions();
|
|
167
|
+
}, [fetchSessions]);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<ul>
|
|
171
|
+
{sessions.map((session) => (
|
|
172
|
+
<li key={session.session_id}>
|
|
173
|
+
<button onClick={() => loadSession(session.session_id)}>
|
|
174
|
+
{session.session_name}
|
|
175
|
+
</button>
|
|
176
|
+
</li>
|
|
177
|
+
))}
|
|
178
|
+
</ul>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### useAgnoActions()
|
|
184
|
+
|
|
185
|
+
Hook for common actions and initialization.
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
const {
|
|
189
|
+
initialize, // () => Promise<{ agents, teams }>
|
|
190
|
+
checkStatus, // () => Promise<boolean>
|
|
191
|
+
fetchAgents, // () => Promise<AgentDetails[]>
|
|
192
|
+
fetchTeams, // () => Promise<TeamDetails[]>
|
|
193
|
+
updateConfig, // (updates) => void
|
|
194
|
+
isInitializing, // boolean
|
|
195
|
+
error, // string | undefined
|
|
196
|
+
} = useAgnoActions();
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Example:**
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
function InitComponent() {
|
|
203
|
+
const { initialize, updateConfig, isInitializing } = useAgnoActions();
|
|
204
|
+
const { state } = useAgnoChat();
|
|
205
|
+
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
initialize();
|
|
208
|
+
}, [initialize]);
|
|
209
|
+
|
|
210
|
+
const switchAgent = (agentId: string) => {
|
|
211
|
+
updateConfig({ agentId, mode: 'agent' });
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
if (isInitializing) return <div>Loading...</div>;
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<div>
|
|
218
|
+
<h3>Agents</h3>
|
|
219
|
+
{state.agents.map((agent) => (
|
|
220
|
+
<button key={agent.id} onClick={() => switchAgent(agent.id)}>
|
|
221
|
+
{agent.name}
|
|
222
|
+
</button>
|
|
223
|
+
))}
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Complete Example
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
import { useState, useEffect } from 'react';
|
|
233
|
+
import {
|
|
234
|
+
AgnoProvider,
|
|
235
|
+
useAgnoChat,
|
|
236
|
+
useAgnoSession,
|
|
237
|
+
useAgnoActions,
|
|
238
|
+
} from '@antipopp/agno-react';
|
|
239
|
+
|
|
240
|
+
function App() {
|
|
241
|
+
return (
|
|
242
|
+
<AgnoProvider
|
|
243
|
+
config={{
|
|
244
|
+
endpoint: 'http://localhost:7777',
|
|
245
|
+
mode: 'agent',
|
|
246
|
+
agentId: 'my-agent',
|
|
247
|
+
}}
|
|
248
|
+
>
|
|
249
|
+
<ChatApp />
|
|
250
|
+
</AgnoProvider>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function ChatApp() {
|
|
255
|
+
const [input, setInput] = useState('');
|
|
256
|
+
const { messages, sendMessage, isStreaming, error, clearMessages } = useAgnoChat();
|
|
257
|
+
const { sessions, loadSession, fetchSessions } = useAgnoSession();
|
|
258
|
+
const { initialize, state } = useAgnoActions();
|
|
259
|
+
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
initialize().then(() => fetchSessions());
|
|
262
|
+
}, [initialize, fetchSessions]);
|
|
263
|
+
|
|
264
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
265
|
+
e.preventDefault();
|
|
266
|
+
if (!input.trim() || isStreaming) return;
|
|
267
|
+
|
|
268
|
+
await sendMessage(input);
|
|
269
|
+
setInput('');
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<div>
|
|
274
|
+
<aside>
|
|
275
|
+
<h2>Sessions</h2>
|
|
276
|
+
<button onClick={() => clearMessages()}>New Chat</button>
|
|
277
|
+
<ul>
|
|
278
|
+
{sessions.map((session) => (
|
|
279
|
+
<li key={session.session_id}>
|
|
280
|
+
<button onClick={() => loadSession(session.session_id)}>
|
|
281
|
+
{session.session_name}
|
|
282
|
+
</button>
|
|
283
|
+
</li>
|
|
284
|
+
))}
|
|
285
|
+
</ul>
|
|
286
|
+
</aside>
|
|
287
|
+
|
|
288
|
+
<main>
|
|
289
|
+
<div className="messages">
|
|
290
|
+
{messages.map((msg, i) => (
|
|
291
|
+
<div key={i} className={`message ${msg.role}`}>
|
|
292
|
+
<strong>{msg.role}:</strong>
|
|
293
|
+
<p>{msg.content}</p>
|
|
294
|
+
{msg.tool_calls && (
|
|
295
|
+
<details>
|
|
296
|
+
<summary>Tool Calls</summary>
|
|
297
|
+
<pre>{JSON.stringify(msg.tool_calls, null, 2)}</pre>
|
|
298
|
+
</details>
|
|
299
|
+
)}
|
|
300
|
+
</div>
|
|
301
|
+
))}
|
|
302
|
+
{error && <div className="error">Error: {error}</div>}
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
<form onSubmit={handleSubmit}>
|
|
306
|
+
<input
|
|
307
|
+
value={input}
|
|
308
|
+
onChange={(e) => setInput(e.target.value)}
|
|
309
|
+
placeholder="Type a message..."
|
|
310
|
+
disabled={isStreaming}
|
|
311
|
+
/>
|
|
312
|
+
<button type="submit" disabled={isStreaming}>
|
|
313
|
+
{isStreaming ? 'Sending...' : 'Send'}
|
|
314
|
+
</button>
|
|
315
|
+
</form>
|
|
316
|
+
</main>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export default App;
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## TypeScript
|
|
325
|
+
|
|
326
|
+
All hooks and components are fully typed. Import types as needed:
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
import type {
|
|
330
|
+
AgnoClientConfig,
|
|
331
|
+
ChatMessage,
|
|
332
|
+
SessionEntry,
|
|
333
|
+
AgentDetails,
|
|
334
|
+
TeamDetails,
|
|
335
|
+
} from '@antipopp/agno-react';
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## License
|
|
339
|
+
|
|
340
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { AgnoClient } from '@antipopp/agno-client';
|
|
4
|
+
import * as _antipopp_agno_types from '@antipopp/agno-types';
|
|
5
|
+
import { AgnoClientConfig, ChatMessage, ClientState, SessionEntry, AgentDetails, TeamDetails, ToolCall } from '@antipopp/agno-types';
|
|
6
|
+
export { AgentDetails, AgnoClientConfig, ChatMessage, ClientState, RunEvent, SessionEntry, TeamDetails, ToolCall } from '@antipopp/agno-types';
|
|
7
|
+
|
|
8
|
+
interface AgnoProviderProps {
|
|
9
|
+
config: AgnoClientConfig;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Provider component that creates and manages an AgnoClient instance
|
|
14
|
+
*/
|
|
15
|
+
declare function AgnoProvider({ config, children }: AgnoProviderProps): react_jsx_runtime.JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* Hook to access the AgnoClient instance
|
|
18
|
+
*/
|
|
19
|
+
declare function useAgnoClient(): AgnoClient;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Main hook for chat interactions
|
|
23
|
+
* Provides messages, state, and methods to interact with the agent
|
|
24
|
+
*/
|
|
25
|
+
declare function useAgnoChat(): {
|
|
26
|
+
messages: ChatMessage[];
|
|
27
|
+
sendMessage: (message: string | FormData, options?: {
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
clearMessages: () => void;
|
|
31
|
+
isStreaming: boolean;
|
|
32
|
+
isPaused: boolean;
|
|
33
|
+
error: string | undefined;
|
|
34
|
+
state: ClientState;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Hook for session management
|
|
39
|
+
*/
|
|
40
|
+
declare function useAgnoSession(): {
|
|
41
|
+
sessions: SessionEntry[];
|
|
42
|
+
currentSessionId: string | undefined;
|
|
43
|
+
loadSession: (sessionId: string) => Promise<ChatMessage[]>;
|
|
44
|
+
fetchSessions: () => Promise<SessionEntry[]>;
|
|
45
|
+
isLoading: boolean;
|
|
46
|
+
error: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Hook for common actions like initialization, fetching agents/teams
|
|
51
|
+
*/
|
|
52
|
+
declare function useAgnoActions(): {
|
|
53
|
+
initialize: () => Promise<{
|
|
54
|
+
agents: AgentDetails[];
|
|
55
|
+
teams: TeamDetails[];
|
|
56
|
+
}>;
|
|
57
|
+
checkStatus: () => Promise<boolean>;
|
|
58
|
+
fetchAgents: () => Promise<AgentDetails[]>;
|
|
59
|
+
fetchTeams: () => Promise<TeamDetails[]>;
|
|
60
|
+
updateConfig: (updates: Partial<Parameters<(updates: Partial<_antipopp_agno_types.AgnoClientConfig>) => void>[0]>) => void;
|
|
61
|
+
isInitializing: boolean;
|
|
62
|
+
error: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Tool handler function type
|
|
67
|
+
*/
|
|
68
|
+
type ToolHandler = (args: Record<string, any>) => Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Tool execution event payload
|
|
71
|
+
*/
|
|
72
|
+
interface ToolExecutionEvent {
|
|
73
|
+
runId?: string;
|
|
74
|
+
sessionId?: string;
|
|
75
|
+
tools: ToolCall[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Hook for handling frontend tool execution (HITL)
|
|
79
|
+
*
|
|
80
|
+
* @param handlers - Map of tool names to handler functions
|
|
81
|
+
* @param autoExecute - Whether to automatically execute tools when paused (default: true)
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* const toolHandlers = {
|
|
86
|
+
* navigate_to_page: async (args) => {
|
|
87
|
+
* window.location.href = args.url;
|
|
88
|
+
* return { success: true };
|
|
89
|
+
* },
|
|
90
|
+
* fill_form: async (args) => {
|
|
91
|
+
* document.querySelector(args.selector).value = args.value;
|
|
92
|
+
* return { filled: true };
|
|
93
|
+
* }
|
|
94
|
+
* };
|
|
95
|
+
*
|
|
96
|
+
* const { isPaused, isExecuting, pendingTools } = useAgnoToolExecution(toolHandlers);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function useAgnoToolExecution(handlers: Record<string, ToolHandler>, autoExecute?: boolean): {
|
|
100
|
+
/** Whether the run is currently paused awaiting tool execution */
|
|
101
|
+
isPaused: boolean;
|
|
102
|
+
/** Whether tools are currently being executed */
|
|
103
|
+
isExecuting: boolean;
|
|
104
|
+
/** Tools awaiting execution */
|
|
105
|
+
pendingTools: ToolCall[];
|
|
106
|
+
/** Execute all pending tools and continue the run */
|
|
107
|
+
executeAndContinue: () => Promise<void>;
|
|
108
|
+
/** Execute specific tools and return results without continuing */
|
|
109
|
+
executeTools: (tools: ToolCall[]) => Promise<ToolCall[]>;
|
|
110
|
+
/** Continue the run with manually provided tool results */
|
|
111
|
+
continueWithResults: (tools: ToolCall[]) => Promise<void>;
|
|
112
|
+
/** Error from tool execution, if any */
|
|
113
|
+
executionError: string | undefined;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export { AgnoProvider, type AgnoProviderProps, type ToolExecutionEvent, type ToolHandler, useAgnoActions, useAgnoChat, useAgnoClient, useAgnoSession, useAgnoToolExecution };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { AgnoClient } from '@antipopp/agno-client';
|
|
4
|
+
import * as _antipopp_agno_types from '@antipopp/agno-types';
|
|
5
|
+
import { AgnoClientConfig, ChatMessage, ClientState, SessionEntry, AgentDetails, TeamDetails, ToolCall } from '@antipopp/agno-types';
|
|
6
|
+
export { AgentDetails, AgnoClientConfig, ChatMessage, ClientState, RunEvent, SessionEntry, TeamDetails, ToolCall } from '@antipopp/agno-types';
|
|
7
|
+
|
|
8
|
+
interface AgnoProviderProps {
|
|
9
|
+
config: AgnoClientConfig;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Provider component that creates and manages an AgnoClient instance
|
|
14
|
+
*/
|
|
15
|
+
declare function AgnoProvider({ config, children }: AgnoProviderProps): react_jsx_runtime.JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* Hook to access the AgnoClient instance
|
|
18
|
+
*/
|
|
19
|
+
declare function useAgnoClient(): AgnoClient;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Main hook for chat interactions
|
|
23
|
+
* Provides messages, state, and methods to interact with the agent
|
|
24
|
+
*/
|
|
25
|
+
declare function useAgnoChat(): {
|
|
26
|
+
messages: ChatMessage[];
|
|
27
|
+
sendMessage: (message: string | FormData, options?: {
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
clearMessages: () => void;
|
|
31
|
+
isStreaming: boolean;
|
|
32
|
+
isPaused: boolean;
|
|
33
|
+
error: string | undefined;
|
|
34
|
+
state: ClientState;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Hook for session management
|
|
39
|
+
*/
|
|
40
|
+
declare function useAgnoSession(): {
|
|
41
|
+
sessions: SessionEntry[];
|
|
42
|
+
currentSessionId: string | undefined;
|
|
43
|
+
loadSession: (sessionId: string) => Promise<ChatMessage[]>;
|
|
44
|
+
fetchSessions: () => Promise<SessionEntry[]>;
|
|
45
|
+
isLoading: boolean;
|
|
46
|
+
error: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Hook for common actions like initialization, fetching agents/teams
|
|
51
|
+
*/
|
|
52
|
+
declare function useAgnoActions(): {
|
|
53
|
+
initialize: () => Promise<{
|
|
54
|
+
agents: AgentDetails[];
|
|
55
|
+
teams: TeamDetails[];
|
|
56
|
+
}>;
|
|
57
|
+
checkStatus: () => Promise<boolean>;
|
|
58
|
+
fetchAgents: () => Promise<AgentDetails[]>;
|
|
59
|
+
fetchTeams: () => Promise<TeamDetails[]>;
|
|
60
|
+
updateConfig: (updates: Partial<Parameters<(updates: Partial<_antipopp_agno_types.AgnoClientConfig>) => void>[0]>) => void;
|
|
61
|
+
isInitializing: boolean;
|
|
62
|
+
error: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Tool handler function type
|
|
67
|
+
*/
|
|
68
|
+
type ToolHandler = (args: Record<string, any>) => Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Tool execution event payload
|
|
71
|
+
*/
|
|
72
|
+
interface ToolExecutionEvent {
|
|
73
|
+
runId?: string;
|
|
74
|
+
sessionId?: string;
|
|
75
|
+
tools: ToolCall[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Hook for handling frontend tool execution (HITL)
|
|
79
|
+
*
|
|
80
|
+
* @param handlers - Map of tool names to handler functions
|
|
81
|
+
* @param autoExecute - Whether to automatically execute tools when paused (default: true)
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* const toolHandlers = {
|
|
86
|
+
* navigate_to_page: async (args) => {
|
|
87
|
+
* window.location.href = args.url;
|
|
88
|
+
* return { success: true };
|
|
89
|
+
* },
|
|
90
|
+
* fill_form: async (args) => {
|
|
91
|
+
* document.querySelector(args.selector).value = args.value;
|
|
92
|
+
* return { filled: true };
|
|
93
|
+
* }
|
|
94
|
+
* };
|
|
95
|
+
*
|
|
96
|
+
* const { isPaused, isExecuting, pendingTools } = useAgnoToolExecution(toolHandlers);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function useAgnoToolExecution(handlers: Record<string, ToolHandler>, autoExecute?: boolean): {
|
|
100
|
+
/** Whether the run is currently paused awaiting tool execution */
|
|
101
|
+
isPaused: boolean;
|
|
102
|
+
/** Whether tools are currently being executed */
|
|
103
|
+
isExecuting: boolean;
|
|
104
|
+
/** Tools awaiting execution */
|
|
105
|
+
pendingTools: ToolCall[];
|
|
106
|
+
/** Execute all pending tools and continue the run */
|
|
107
|
+
executeAndContinue: () => Promise<void>;
|
|
108
|
+
/** Execute specific tools and return results without continuing */
|
|
109
|
+
executeTools: (tools: ToolCall[]) => Promise<ToolCall[]>;
|
|
110
|
+
/** Continue the run with manually provided tool results */
|
|
111
|
+
continueWithResults: (tools: ToolCall[]) => Promise<void>;
|
|
112
|
+
/** Error from tool execution, if any */
|
|
113
|
+
executionError: string | undefined;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export { AgnoProvider, type AgnoProviderProps, type ToolExecutionEvent, type ToolHandler, useAgnoActions, useAgnoChat, useAgnoClient, useAgnoSession, useAgnoToolExecution };
|