@antipopp/agno-client 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 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,294 @@
1
+ # @antipopp/agno-client
2
+
3
+ Core stateful client library for Agno agents with streaming support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @antipopp/agno-client
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - ✅ **Stateful Management** - Manages messages, sessions, and configuration
14
+ - ✅ **Event-Driven** - Subscribe to real-time updates via EventEmitter
15
+ - ✅ **Streaming Support** - Real-time streaming of agent responses
16
+ - ✅ **Session Management** - Load and manage conversation sessions
17
+ - ✅ **Type-Safe** - Full TypeScript support with comprehensive types
18
+ - ✅ **Framework Agnostic** - Works with any JavaScript/TypeScript project
19
+
20
+ ## Quick Start
21
+
22
+ ```typescript
23
+ import { AgnoClient } from '@antipopp/agno-client';
24
+
25
+ // Create a client instance
26
+ const client = new AgnoClient({
27
+ endpoint: 'http://localhost:7777',
28
+ mode: 'agent',
29
+ agentId: 'your-agent-id',
30
+ authToken: 'optional-auth-token',
31
+ });
32
+
33
+ // Listen to message updates
34
+ client.on('message:update', (messages) => {
35
+ console.log('New messages:', messages);
36
+ });
37
+
38
+ // Listen to errors
39
+ client.on('message:error', (error) => {
40
+ console.error('Error:', error);
41
+ });
42
+
43
+ // Send a message
44
+ await client.sendMessage('Hello, agent!');
45
+
46
+ // Get current messages
47
+ const messages = client.getMessages();
48
+
49
+ // Clear chat
50
+ client.clearMessages();
51
+ ```
52
+
53
+ ## API Reference
54
+
55
+ ### Constructor
56
+
57
+ ```typescript
58
+ new AgnoClient(config: AgnoClientConfig)
59
+ ```
60
+
61
+ **Config Options:**
62
+ - `endpoint` (string, required) - Base endpoint URL
63
+ - `authToken` (string, optional) - Authentication token
64
+ - `mode` ('agent' | 'team', optional) - Operation mode (default: 'agent')
65
+ - `agentId` (string, optional) - Agent ID (required if mode is 'agent')
66
+ - `teamId` (string, optional) - Team ID (required if mode is 'team')
67
+ - `dbId` (string, optional) - Database ID
68
+ - `sessionId` (string, optional) - Current session ID
69
+
70
+ ### Methods
71
+
72
+ #### `sendMessage(message, options?)`
73
+
74
+ Send a message to the agent/team.
75
+
76
+ ```typescript
77
+ await client.sendMessage('Hello!');
78
+
79
+ // With FormData (for file uploads)
80
+ const formData = new FormData();
81
+ formData.append('message', 'Hello!');
82
+ formData.append('file', fileBlob);
83
+ await client.sendMessage(formData);
84
+
85
+ // With custom headers
86
+ await client.sendMessage('Hello!', {
87
+ headers: { 'X-Custom-Header': 'value' }
88
+ });
89
+ ```
90
+
91
+ #### `getMessages()`
92
+
93
+ Get current messages.
94
+
95
+ ```typescript
96
+ const messages: ChatMessage[] = client.getMessages();
97
+ ```
98
+
99
+ #### `clearMessages()`
100
+
101
+ Clear all messages and reset session.
102
+
103
+ ```typescript
104
+ client.clearMessages();
105
+ ```
106
+
107
+ #### `loadSession(sessionId)`
108
+
109
+ Load a specific session.
110
+
111
+ ```typescript
112
+ const messages = await client.loadSession('session-id');
113
+ ```
114
+
115
+ #### `fetchSessions()`
116
+
117
+ Fetch all sessions for current agent/team.
118
+
119
+ ```typescript
120
+ const sessions = await client.fetchSessions();
121
+ ```
122
+
123
+ #### `initialize()`
124
+
125
+ Initialize client (check status and fetch agents/teams).
126
+
127
+ ```typescript
128
+ const { agents, teams } = await client.initialize();
129
+ ```
130
+
131
+ #### `updateConfig(updates)`
132
+
133
+ Update client configuration.
134
+
135
+ ```typescript
136
+ client.updateConfig({
137
+ agentId: 'new-agent-id',
138
+ authToken: 'new-token',
139
+ });
140
+ ```
141
+
142
+ ### Events
143
+
144
+ Subscribe to events using `client.on(event, handler)`:
145
+
146
+ - `message:update` - Emitted when messages are updated during streaming
147
+ - `message:complete` - Emitted when a message stream completes
148
+ - `message:error` - Emitted when an error occurs
149
+ - `session:loaded` - Emitted when a session is loaded
150
+ - `session:created` - Emitted when a new session is created
151
+ - `stream:start` - Emitted when streaming starts
152
+ - `stream:end` - Emitted when streaming ends
153
+ - `state:change` - Emitted when client state changes
154
+ - `config:change` - Emitted when configuration changes
155
+
156
+ ```typescript
157
+ // Subscribe to events
158
+ client.on('message:update', (messages) => {
159
+ console.log('Messages:', messages);
160
+ });
161
+
162
+ // Unsubscribe from events
163
+ const handler = (messages) => console.log(messages);
164
+ client.on('message:update', handler);
165
+ client.off('message:update', handler);
166
+ ```
167
+
168
+ ## Utilities
169
+
170
+ ### Logger
171
+
172
+ The package includes a secure Logger utility for production-safe debugging:
173
+
174
+ ```typescript
175
+ import { Logger } from '@antipopp/agno-client';
176
+
177
+ // Debug and info messages only log in development mode
178
+ Logger.debug('Debug message', { someData: 'value' });
179
+ Logger.info('Client initialized', { endpoint: 'http://localhost:7777' });
180
+
181
+ // Warnings and errors always log
182
+ Logger.warn('Connection issue detected');
183
+ Logger.error('Failed to send message', error);
184
+
185
+ // Sensitive data is automatically sanitized
186
+ Logger.debug('Config loaded', {
187
+ endpoint: 'http://localhost:7777',
188
+ authToken: 'secret-token' // Will be logged as [REDACTED]
189
+ });
190
+ ```
191
+
192
+ **Features:**
193
+ - **Automatic sanitization** - Sensitive fields (authToken, Authorization, token, password, apiKey) are automatically redacted
194
+ - **Environment-aware** - Debug/info logs only appear in development mode (NODE_ENV === 'development')
195
+ - **Always-on errors** - Warnings and errors always log, even in production
196
+ - **Production-safe** - Prevents accidental exposure of secrets in production logs
197
+
198
+ **Sanitized Fields:**
199
+ - `authToken`, `Authorization`, `token`, `password`, `apiKey` and any field containing these words (case-insensitive)
200
+
201
+ ## Advanced Usage
202
+
203
+ ### Session Management
204
+
205
+ ```typescript
206
+ // Fetch all sessions
207
+ const sessions = await client.fetchSessions();
208
+
209
+ // Load a specific session
210
+ const messages = await client.loadSession(sessions[0].session_id);
211
+
212
+ // Current session ID
213
+ const sessionId = client.getConfig().sessionId;
214
+ ```
215
+
216
+ ### State Management
217
+
218
+ ```typescript
219
+ // Get current state
220
+ const state = client.getState();
221
+ console.log(state.isStreaming);
222
+ console.log(state.isEndpointActive);
223
+ console.log(state.agents);
224
+ console.log(state.teams);
225
+ ```
226
+
227
+ ### Error Handling
228
+
229
+ ```typescript
230
+ client.on('message:error', (error) => {
231
+ console.error('Streaming error:', error);
232
+ });
233
+
234
+ try {
235
+ await client.sendMessage('Hello!');
236
+ } catch (error) {
237
+ console.error('Failed to send:', error);
238
+ }
239
+ ```
240
+
241
+ ### Request Cancellation
242
+
243
+ Use `AbortController` to cancel ongoing requests. This is essential for preventing memory leaks when components unmount or users navigate away during streaming:
244
+
245
+ ```typescript
246
+ const controller = new AbortController();
247
+
248
+ // Pass signal to sendMessage options
249
+ await client.sendMessage('Hello!', {
250
+ signal: controller.signal
251
+ });
252
+
253
+ // Cancel the request (e.g., on component unmount)
254
+ controller.abort();
255
+ ```
256
+
257
+ **React Example:**
258
+
259
+ ```typescript
260
+ import { useEffect } from 'react';
261
+ import { AgnoClient } from '@antipopp/agno-client';
262
+
263
+ function ChatComponent() {
264
+ const client = new AgnoClient(config);
265
+
266
+ useEffect(() => {
267
+ const controller = new AbortController();
268
+
269
+ // Send message with abort signal
270
+ client.sendMessage('Hello!', {
271
+ signal: controller.signal
272
+ });
273
+
274
+ // Cleanup: cancel request on unmount
275
+ return () => {
276
+ controller.abort();
277
+ };
278
+ }, []);
279
+
280
+ return <div>Chat</div>;
281
+ }
282
+ ```
283
+
284
+ **Use Cases:**
285
+ - **Component unmounting** - Cancel requests when user navigates away
286
+ - **Request timeouts** - Implement custom timeout logic
287
+ - **User cancellation** - Allow users to cancel long-running requests
288
+ - **Preventing memory leaks** - Ensure streaming stops when components are destroyed
289
+
290
+ **Note:** Aborted requests will not trigger the `onError` callback - they complete silently.
291
+
292
+ ## License
293
+
294
+ MIT
@@ -0,0 +1,120 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ import { AgnoClientConfig, ChatMessage, ClientState, SessionEntry, ToolCall, AgentDetails, TeamDetails } from '@antipopp/agno-types';
3
+ export { AgentDetails, AgnoClientConfig, AudioData, ChatMessage, ClientState, ImageData, MessageExtraData, ResponseAudioData, RunEvent, RunResponse, RunResponseContent, SessionEntry, TeamDetails, ToolCall, VideoData } from '@antipopp/agno-types';
4
+
5
+ /**
6
+ * Main Agno client class
7
+ * Provides stateful management of agent/team interactions with streaming support
8
+ */
9
+ declare class AgnoClient extends EventEmitter {
10
+ private messageStore;
11
+ private configManager;
12
+ private sessionManager;
13
+ private eventProcessor;
14
+ private state;
15
+ constructor(config: AgnoClientConfig);
16
+ /**
17
+ * Get current messages
18
+ */
19
+ getMessages(): ChatMessage[];
20
+ /**
21
+ * Get current configuration
22
+ */
23
+ getConfig(): AgnoClientConfig;
24
+ /**
25
+ * Get current state
26
+ */
27
+ getState(): ClientState;
28
+ /**
29
+ * Update configuration
30
+ */
31
+ updateConfig(updates: Partial<AgnoClientConfig>): void;
32
+ /**
33
+ * Clear all messages
34
+ */
35
+ clearMessages(): void;
36
+ /**
37
+ * Send a message to the agent/team (streaming)
38
+ */
39
+ sendMessage(message: string | FormData, options?: {
40
+ headers?: Record<string, string>;
41
+ }): Promise<void>;
42
+ /**
43
+ * Handle streaming chunk
44
+ */
45
+ private handleChunk;
46
+ /**
47
+ * Handle error
48
+ */
49
+ private handleError;
50
+ /**
51
+ * Load a session
52
+ */
53
+ loadSession(sessionId: string): Promise<ChatMessage[]>;
54
+ /**
55
+ * Fetch all sessions
56
+ */
57
+ fetchSessions(): Promise<SessionEntry[]>;
58
+ /**
59
+ * Delete a session
60
+ */
61
+ deleteSession(sessionId: string): Promise<void>;
62
+ /**
63
+ * Delete a team session
64
+ */
65
+ deleteTeamSession(teamId: string, sessionId: string): Promise<void>;
66
+ /**
67
+ * Continue a paused run after executing external tools
68
+ */
69
+ continueRun(tools: ToolCall[], options?: {
70
+ headers?: Record<string, string>;
71
+ }): Promise<void>;
72
+ /**
73
+ * Check endpoint status
74
+ */
75
+ checkStatus(): Promise<boolean>;
76
+ /**
77
+ * Fetch agents from endpoint
78
+ */
79
+ fetchAgents(): Promise<AgentDetails[]>;
80
+ /**
81
+ * Fetch teams from endpoint
82
+ */
83
+ fetchTeams(): Promise<TeamDetails[]>;
84
+ /**
85
+ * Initialize client (check status and fetch agents/teams)
86
+ * Automatically selects the first available agent or team if none is configured
87
+ */
88
+ initialize(): Promise<{
89
+ agents: AgentDetails[];
90
+ teams: TeamDetails[];
91
+ }>;
92
+ }
93
+
94
+ /**
95
+ * Logger utility with sensitive data sanitization
96
+ * Only logs in development mode to prevent auth token exposure
97
+ */
98
+ /**
99
+ * Logger class with sanitization and environment-aware logging
100
+ */
101
+ declare class Logger {
102
+ /**
103
+ * Log debug information (only in development)
104
+ */
105
+ static debug(message: string, data?: unknown): void;
106
+ /**
107
+ * Log informational messages (only in development)
108
+ */
109
+ static info(message: string, data?: unknown): void;
110
+ /**
111
+ * Log warnings (always logs)
112
+ */
113
+ static warn(message: string, data?: unknown): void;
114
+ /**
115
+ * Log errors (always logs)
116
+ */
117
+ static error(message: string, data?: unknown): void;
118
+ }
119
+
120
+ export { AgnoClient, Logger };
@@ -0,0 +1,120 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ import { AgnoClientConfig, ChatMessage, ClientState, SessionEntry, ToolCall, AgentDetails, TeamDetails } from '@antipopp/agno-types';
3
+ export { AgentDetails, AgnoClientConfig, AudioData, ChatMessage, ClientState, ImageData, MessageExtraData, ResponseAudioData, RunEvent, RunResponse, RunResponseContent, SessionEntry, TeamDetails, ToolCall, VideoData } from '@antipopp/agno-types';
4
+
5
+ /**
6
+ * Main Agno client class
7
+ * Provides stateful management of agent/team interactions with streaming support
8
+ */
9
+ declare class AgnoClient extends EventEmitter {
10
+ private messageStore;
11
+ private configManager;
12
+ private sessionManager;
13
+ private eventProcessor;
14
+ private state;
15
+ constructor(config: AgnoClientConfig);
16
+ /**
17
+ * Get current messages
18
+ */
19
+ getMessages(): ChatMessage[];
20
+ /**
21
+ * Get current configuration
22
+ */
23
+ getConfig(): AgnoClientConfig;
24
+ /**
25
+ * Get current state
26
+ */
27
+ getState(): ClientState;
28
+ /**
29
+ * Update configuration
30
+ */
31
+ updateConfig(updates: Partial<AgnoClientConfig>): void;
32
+ /**
33
+ * Clear all messages
34
+ */
35
+ clearMessages(): void;
36
+ /**
37
+ * Send a message to the agent/team (streaming)
38
+ */
39
+ sendMessage(message: string | FormData, options?: {
40
+ headers?: Record<string, string>;
41
+ }): Promise<void>;
42
+ /**
43
+ * Handle streaming chunk
44
+ */
45
+ private handleChunk;
46
+ /**
47
+ * Handle error
48
+ */
49
+ private handleError;
50
+ /**
51
+ * Load a session
52
+ */
53
+ loadSession(sessionId: string): Promise<ChatMessage[]>;
54
+ /**
55
+ * Fetch all sessions
56
+ */
57
+ fetchSessions(): Promise<SessionEntry[]>;
58
+ /**
59
+ * Delete a session
60
+ */
61
+ deleteSession(sessionId: string): Promise<void>;
62
+ /**
63
+ * Delete a team session
64
+ */
65
+ deleteTeamSession(teamId: string, sessionId: string): Promise<void>;
66
+ /**
67
+ * Continue a paused run after executing external tools
68
+ */
69
+ continueRun(tools: ToolCall[], options?: {
70
+ headers?: Record<string, string>;
71
+ }): Promise<void>;
72
+ /**
73
+ * Check endpoint status
74
+ */
75
+ checkStatus(): Promise<boolean>;
76
+ /**
77
+ * Fetch agents from endpoint
78
+ */
79
+ fetchAgents(): Promise<AgentDetails[]>;
80
+ /**
81
+ * Fetch teams from endpoint
82
+ */
83
+ fetchTeams(): Promise<TeamDetails[]>;
84
+ /**
85
+ * Initialize client (check status and fetch agents/teams)
86
+ * Automatically selects the first available agent or team if none is configured
87
+ */
88
+ initialize(): Promise<{
89
+ agents: AgentDetails[];
90
+ teams: TeamDetails[];
91
+ }>;
92
+ }
93
+
94
+ /**
95
+ * Logger utility with sensitive data sanitization
96
+ * Only logs in development mode to prevent auth token exposure
97
+ */
98
+ /**
99
+ * Logger class with sanitization and environment-aware logging
100
+ */
101
+ declare class Logger {
102
+ /**
103
+ * Log debug information (only in development)
104
+ */
105
+ static debug(message: string, data?: unknown): void;
106
+ /**
107
+ * Log informational messages (only in development)
108
+ */
109
+ static info(message: string, data?: unknown): void;
110
+ /**
111
+ * Log warnings (always logs)
112
+ */
113
+ static warn(message: string, data?: unknown): void;
114
+ /**
115
+ * Log errors (always logs)
116
+ */
117
+ static error(message: string, data?: unknown): void;
118
+ }
119
+
120
+ export { AgnoClient, Logger };