@antipopp/agno-react 0.8.0 → 0.10.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/README.md CHANGED
@@ -33,6 +33,12 @@ function App() {
33
33
  mode: 'agent',
34
34
  agentId: 'your-agent-id',
35
35
  userId: 'user-123', // Optional: Link sessions to a user
36
+ headers: { // Optional: Global headers for all requests
37
+ 'X-API-Version': 'v2'
38
+ },
39
+ params: { // Optional: Global query params for all requests
40
+ locale: 'en-US'
41
+ }
36
42
  }}
37
43
  >
38
44
  <YourComponents />
@@ -134,6 +140,17 @@ await sendMessage(formData);
134
140
  await sendMessage('Hello!', {
135
141
  headers: { 'X-Custom': 'value' }
136
142
  });
143
+
144
+ // Send with query parameters
145
+ await sendMessage('Hello!', {
146
+ params: { temperature: '0.7', max_tokens: '500' }
147
+ });
148
+
149
+ // Send with both headers and params
150
+ await sendMessage('Hello!', {
151
+ headers: { 'X-Request-ID': '12345' },
152
+ params: { debug: 'true' }
153
+ });
137
154
  ```
138
155
 
139
156
  #### `clearMessages()`
@@ -164,14 +181,20 @@ function SessionList() {
164
181
  const { sessions, loadSession, fetchSessions } = useAgnoSession();
165
182
 
166
183
  useEffect(() => {
167
- fetchSessions();
184
+ // Fetch sessions with optional query params
185
+ fetchSessions({ params: { limit: '50', status: 'active' } });
168
186
  }, [fetchSessions]);
169
187
 
188
+ const handleLoadSession = (sessionId: string) => {
189
+ // Load session with optional params
190
+ loadSession(sessionId, { params: { include_metadata: 'true' } });
191
+ };
192
+
170
193
  return (
171
194
  <ul>
172
195
  {sessions.map((session) => (
173
196
  <li key={session.session_id}>
174
- <button onClick={() => loadSession(session.session_id)}>
197
+ <button onClick={() => handleLoadSession(session.session_id)}>
175
198
  {session.session_name}
176
199
  </button>
177
200
  </li>
@@ -201,13 +224,19 @@ const {
201
224
 
202
225
  ```tsx
203
226
  function InitComponent() {
204
- const { initialize, updateConfig, isInitializing } = useAgnoActions();
227
+ const { initialize, fetchAgents, updateConfig, isInitializing } = useAgnoActions();
205
228
  const { state } = useAgnoChat();
206
229
 
207
230
  useEffect(() => {
208
- initialize();
231
+ // Initialize with optional params
232
+ initialize({ params: { filter: 'active' } });
209
233
  }, [initialize]);
210
234
 
235
+ const loadMoreAgents = () => {
236
+ // Fetch agents with custom params
237
+ fetchAgents({ params: { page: '2', limit: '20' } });
238
+ };
239
+
211
240
  const switchAgent = (agentId: string) => {
212
241
  updateConfig({ agentId, mode: 'agent' });
213
242
  };
@@ -222,6 +251,7 @@ function InitComponent() {
222
251
  {agent.name}
223
252
  </button>
224
253
  ))}
254
+ <button onClick={loadMoreAgents}>Load More</button>
225
255
  </div>
226
256
  );
227
257
  }
package/dist/index.d.mts CHANGED
@@ -1,16 +1,37 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import React from 'react';
3
- import { AgnoClient } from '@antipopp/agno-client';
4
1
  import * as _antipopp_agno_types from '@antipopp/agno-types';
5
- import { AgnoClientConfig, ToolCall, CustomRenderFunction, UIComponentSpec, ChartComponentSpec, CardData, CardGridComponentSpec, TableColumn, TableComponentSpec, MarkdownComponentSpec, ArtifactComponentSpec, ToolHandlerResult, ChatMessage, ClientState, SessionEntry, AgentDetails, TeamDetails } from '@antipopp/agno-types';
2
+ import { UIComponentSpec, AgnoClientConfig, ToolCall, CustomRenderFunction, AgentDetails, TeamDetails, ChatMessage, ClientState, SessionEntry, ChartComponentSpec, ArtifactComponentSpec, CardData, CardGridComponentSpec, TableColumn, MarkdownComponentSpec, TableComponentSpec, ToolHandlerResult } from '@antipopp/agno-types';
6
3
  export { AgentDetails, AgnoClientConfig, ArtifactComponentSpec, CardData, CardGridComponentSpec, ChartComponentSpec, ChartSeries, ChatMessage, ClientState, CustomComponentSpec, GenerativeUIData, MarkdownComponentSpec, RunEvent, SessionEntry, TableColumn, TableComponentSpec, TeamDetails, ToolCall, ToolHandlerResult, UIComponentSpec } from '@antipopp/agno-types';
4
+ import React from 'react';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
+ import { AgnoClient } from '@antipopp/agno-client';
7
+
8
+ /**
9
+ * Generative UI Renderer
10
+ *
11
+ * Renders UI components based on specifications from the agent.
12
+ * Supports both registry-based components and custom render functions.
13
+ */
14
+
15
+ interface GenerativeUIRendererProps {
16
+ /** The UI component specification to render */
17
+ spec: UIComponentSpec;
18
+ /** Optional className for styling */
19
+ className?: string;
20
+ /** Error boundary fallback */
21
+ onError?: (error: Error) => void;
22
+ }
23
+ /**
24
+ * Main Generative UI Renderer component
25
+ */
26
+ declare function GenerativeUIRenderer({ spec, className, onError, }: GenerativeUIRendererProps): React.ReactElement;
7
27
 
8
28
  interface AgnoProviderProps {
9
29
  config: AgnoClientConfig;
10
30
  children: React.ReactNode;
11
31
  }
12
32
  /**
13
- * Provider component that creates and manages an AgnoClient instance
33
+ * Provider component that creates and manages an AgnoClient instance.
34
+ * Handles cleanup of all module-level registries on unmount to prevent memory leaks.
14
35
  */
15
36
  declare function AgnoProvider({ config, children }: AgnoProviderProps): react_jsx_runtime.JSX.Element;
16
37
  /**
@@ -26,6 +47,11 @@ type ToolHandler = (args: Record<string, any>) => Promise<any>;
26
47
  * Get a custom render function by key
27
48
  */
28
49
  declare function getCustomRender(key: string): CustomRenderFunction | undefined;
50
+ /**
51
+ * Clear all custom render functions from the registry.
52
+ * Call this during cleanup (e.g., when AgnoProvider unmounts) to prevent memory leaks.
53
+ */
54
+ declare function clearCustomRenderRegistry(): void;
29
55
  /**
30
56
  * Tool execution event payload
31
57
  */
@@ -71,7 +97,10 @@ declare function useAgnoToolExecution(handlers?: Record<string, ToolHandler>, au
71
97
  /** Execute specific tools and return results without continuing */
72
98
  executeTools: (tools: ToolCall[]) => Promise<ToolCall[]>;
73
99
  /** Continue the run with manually provided tool results */
74
- continueWithResults: (tools: ToolCall[]) => Promise<void>;
100
+ continueWithResults: (tools: ToolCall[], options?: {
101
+ headers?: Record<string, string>;
102
+ params?: Record<string, string>;
103
+ }) => Promise<void>;
75
104
  /** Error from tool execution, if any */
76
105
  executionError: string | undefined;
77
106
  };
@@ -105,7 +134,7 @@ interface ToolHandlerProviderProps {
105
134
  * </ToolHandlerProvider>
106
135
  * ```
107
136
  */
108
- declare function ToolHandlerProvider({ handlers: initialHandlers, children }: ToolHandlerProviderProps): react_jsx_runtime.JSX.Element;
137
+ declare function ToolHandlerProvider({ handlers: initialHandlers, children, }: ToolHandlerProviderProps): react_jsx_runtime.JSX.Element;
109
138
  /**
110
139
  * Hook to access global tool handlers
111
140
  *
@@ -119,24 +148,65 @@ declare function ToolHandlerProvider({ handlers: initialHandlers, children }: To
119
148
  declare function useToolHandlers(): ToolHandlerContextValue | null;
120
149
 
121
150
  /**
122
- * Generative UI Renderer
123
- *
124
- * Renders UI components based on specifications from the agent.
125
- * Supports both registry-based components and custom render functions.
151
+ * Hook for common actions like initialization, fetching agents/teams
126
152
  */
153
+ declare function useAgnoActions(): {
154
+ initialize: (options?: {
155
+ params?: Record<string, string>;
156
+ }) => Promise<{
157
+ agents: AgentDetails[];
158
+ teams: TeamDetails[];
159
+ }>;
160
+ checkStatus: (options?: {
161
+ params?: Record<string, string>;
162
+ }) => Promise<boolean>;
163
+ fetchAgents: (options?: {
164
+ params?: Record<string, string>;
165
+ }) => Promise<AgentDetails[]>;
166
+ fetchTeams: (options?: {
167
+ params?: Record<string, string>;
168
+ }) => Promise<TeamDetails[]>;
169
+ updateConfig: (updates: Partial<Parameters<(updates: Partial<_antipopp_agno_types.AgnoClientConfig>) => void>[0]>) => void;
170
+ isInitializing: boolean;
171
+ error: string | undefined;
172
+ };
127
173
 
128
- interface GenerativeUIRendererProps {
129
- /** The UI component specification to render */
130
- spec: UIComponentSpec;
131
- /** Optional className for styling */
132
- className?: string;
133
- /** Error boundary fallback */
134
- onError?: (error: Error) => void;
135
- }
136
174
  /**
137
- * Main Generative UI Renderer component
175
+ * Main hook for chat interactions
176
+ * Provides messages, state, and methods to interact with the agent
138
177
  */
139
- declare function GenerativeUIRenderer({ spec, className, onError, }: GenerativeUIRendererProps): React.ReactElement;
178
+ declare function useAgnoChat(): {
179
+ messages: ChatMessage[];
180
+ sendMessage: (message: string | FormData, options?: {
181
+ headers?: Record<string, string>;
182
+ params?: Record<string, string>;
183
+ }) => Promise<void>;
184
+ clearMessages: () => void;
185
+ cancelRun: () => Promise<void>;
186
+ isStreaming: boolean;
187
+ isRefreshing: boolean;
188
+ isPaused: boolean;
189
+ isCancelling: boolean;
190
+ currentRunId: string | undefined;
191
+ error: string | undefined;
192
+ state: ClientState;
193
+ };
194
+
195
+ /**
196
+ * Hook for session management
197
+ */
198
+ declare function useAgnoSession(): {
199
+ sessions: SessionEntry[];
200
+ currentSessionId: string | undefined;
201
+ loadSession: (sessionId: string, options?: {
202
+ params?: Record<string, string>;
203
+ }) => Promise<ChatMessage[]>;
204
+ fetchSessions: (options?: {
205
+ params?: Record<string, string>;
206
+ }) => Promise<SessionEntry[]>;
207
+ isLoading: boolean;
208
+ error: string | undefined;
209
+ };
140
210
 
141
211
  /**
142
212
  * Component Registry for Generative UI
@@ -153,7 +223,7 @@ type ComponentRenderer = (props: any) => any;
153
223
  */
154
224
  declare class ComponentRegistry {
155
225
  private static instance;
156
- private components;
226
+ private readonly components;
157
227
  private constructor();
158
228
  /**
159
229
  * Get the singleton instance
@@ -187,6 +257,12 @@ declare class ComponentRegistry {
187
257
  * Clear all registered components
188
258
  */
189
259
  clear(): void;
260
+ /**
261
+ * Reset the singleton instance.
262
+ * Call this during cleanup (e.g., when AgnoProvider unmounts) to prevent memory leaks.
263
+ * After calling this, getInstance() will create a fresh instance.
264
+ */
265
+ static resetInstance(): void;
190
266
  }
191
267
  /**
192
268
  * Get the global component registry instance
@@ -217,7 +293,7 @@ interface ChartHelperOptions {
217
293
  /** Chart description */
218
294
  description?: string;
219
295
  /** Layout preference */
220
- layout?: 'inline' | 'artifact';
296
+ layout?: "inline" | "artifact";
221
297
  /** Show legend */
222
298
  showLegend?: boolean;
223
299
  /** Show grid */
@@ -263,7 +339,7 @@ declare function createAreaChart(data: any[], xKey: string, areas: Array<{
263
339
  interface CardGridHelperOptions {
264
340
  title?: string;
265
341
  description?: string;
266
- layout?: 'inline' | 'artifact';
342
+ layout?: "inline" | "artifact";
267
343
  columns?: {
268
344
  default?: number;
269
345
  sm?: number;
@@ -271,7 +347,7 @@ interface CardGridHelperOptions {
271
347
  lg?: number;
272
348
  xl?: number;
273
349
  };
274
- variant?: 'default' | 'bordered' | 'elevated';
350
+ variant?: "default" | "bordered" | "elevated";
275
351
  }
276
352
  /**
277
353
  * Create a card grid specification
@@ -283,7 +359,7 @@ declare function createCardGrid(cards: CardData[], options?: CardGridHelperOptio
283
359
  declare function createCard(id: string, title: string, description?: string, options?: {
284
360
  image?: string;
285
361
  metadata?: Record<string, any>;
286
- actions?: CardData['actions'];
362
+ actions?: CardData["actions"];
287
363
  }): CardData;
288
364
  /**
289
365
  * Table helper options
@@ -291,14 +367,14 @@ declare function createCard(id: string, title: string, description?: string, opt
291
367
  interface TableHelperOptions {
292
368
  title?: string;
293
369
  description?: string;
294
- layout?: 'inline' | 'artifact';
370
+ layout?: "inline" | "artifact";
295
371
  sortable?: boolean;
296
372
  filterable?: boolean;
297
373
  pagination?: {
298
374
  pageSize?: number;
299
375
  pageSizeOptions?: number[];
300
376
  };
301
- density?: 'comfortable' | 'compact';
377
+ density?: "comfortable" | "compact";
302
378
  }
303
379
  /**
304
380
  * Create a table specification
@@ -310,8 +386,8 @@ declare function createTable(data: Record<string, any>[], columns: TableColumn[]
310
386
  declare function createColumn(key: string, header: string, options?: {
311
387
  width?: number | string;
312
388
  sortable?: boolean;
313
- cellType?: 'text' | 'number' | 'date' | 'badge' | 'link';
314
- format?: TableColumn['format'];
389
+ cellType?: "text" | "number" | "date" | "badge" | "link";
390
+ format?: TableColumn["format"];
315
391
  }): TableColumn;
316
392
  /**
317
393
  * Create a markdown specification
@@ -319,7 +395,7 @@ declare function createColumn(key: string, header: string, options?: {
319
395
  declare function createMarkdown(content: string, options?: {
320
396
  title?: string;
321
397
  description?: string;
322
- layout?: 'inline' | 'artifact';
398
+ layout?: "inline" | "artifact";
323
399
  syntaxHighlight?: boolean;
324
400
  }): MarkdownComponentSpec;
325
401
  /**
@@ -328,7 +404,7 @@ declare function createMarkdown(content: string, options?: {
328
404
  declare function createArtifact(content: UIComponentSpec[], options?: {
329
405
  title?: string;
330
406
  description?: string;
331
- variant?: 'default' | 'bordered' | 'elevated';
407
+ variant?: "default" | "bordered" | "elevated";
332
408
  }): ArtifactComponentSpec;
333
409
  /**
334
410
  * Smart chart creator - automatically chooses the best chart type based on data
@@ -336,10 +412,10 @@ declare function createArtifact(content: UIComponentSpec[], options?: {
336
412
  declare function createSmartChart(data: any[], options?: {
337
413
  title?: string;
338
414
  description?: string;
339
- layout?: 'inline' | 'artifact';
415
+ layout?: "inline" | "artifact";
340
416
  xKey?: string;
341
417
  yKeys?: string[];
342
- preferredType?: 'bar' | 'line' | 'area' | 'pie';
418
+ preferredType?: "bar" | "line" | "area" | "pie";
343
419
  }): ChartComponentSpec;
344
420
  /**
345
421
  * Wrap data and UI into a ToolHandlerResult
@@ -366,49 +442,4 @@ declare function resultWithCardGrid(cards: CardData[], options?: CardGridHelperO
366
442
  */
367
443
  declare function resultWithTable(data: Record<string, any>[], columns: TableColumn[], options?: TableHelperOptions): ToolHandlerResult;
368
444
 
369
- /**
370
- * Main hook for chat interactions
371
- * Provides messages, state, and methods to interact with the agent
372
- */
373
- declare function useAgnoChat(): {
374
- messages: ChatMessage[];
375
- sendMessage: (message: string | FormData, options?: {
376
- headers?: Record<string, string>;
377
- }) => Promise<void>;
378
- clearMessages: () => void;
379
- isStreaming: boolean;
380
- isRefreshing: boolean;
381
- isPaused: boolean;
382
- error: string | undefined;
383
- state: ClientState;
384
- };
385
-
386
- /**
387
- * Hook for session management
388
- */
389
- declare function useAgnoSession(): {
390
- sessions: SessionEntry[];
391
- currentSessionId: string | undefined;
392
- loadSession: (sessionId: string) => Promise<ChatMessage[]>;
393
- fetchSessions: () => Promise<SessionEntry[]>;
394
- isLoading: boolean;
395
- error: string | undefined;
396
- };
397
-
398
- /**
399
- * Hook for common actions like initialization, fetching agents/teams
400
- */
401
- declare function useAgnoActions(): {
402
- initialize: () => Promise<{
403
- agents: AgentDetails[];
404
- teams: TeamDetails[];
405
- }>;
406
- checkStatus: () => Promise<boolean>;
407
- fetchAgents: () => Promise<AgentDetails[]>;
408
- fetchTeams: () => Promise<TeamDetails[]>;
409
- updateConfig: (updates: Partial<Parameters<(updates: Partial<_antipopp_agno_types.AgnoClientConfig>) => void>[0]>) => void;
410
- isInitializing: boolean;
411
- error: string | undefined;
412
- };
413
-
414
- export { AgnoProvider, type AgnoProviderProps, type CardGridHelperOptions, type ChartHelperOptions, ComponentRegistry, type ComponentRenderer, GenerativeUIRenderer, type GenerativeUIRendererProps, type TableHelperOptions, type ToolExecutionEvent, type ToolHandler, type ToolHandlerContextValue, ToolHandlerProvider, type ToolHandlerProviderProps, createAreaChart, createArtifact, createBarChart, createCard, createCardGrid, createColumn, createLineChart, createMarkdown, createPieChart, createSmartChart, createTable, createToolResult, getChartComponent, getComponentRegistry, getCustomRender, registerChartComponent, resultWithBarChart, resultWithCardGrid, resultWithSmartChart, resultWithTable, useAgnoActions, useAgnoChat, useAgnoClient, useAgnoSession, useAgnoToolExecution, useToolHandlers };
445
+ export { AgnoProvider, type AgnoProviderProps, type CardGridHelperOptions, type ChartHelperOptions, ComponentRegistry, type ComponentRenderer, GenerativeUIRenderer, type GenerativeUIRendererProps, type TableHelperOptions, type ToolExecutionEvent, type ToolHandler, type ToolHandlerContextValue, ToolHandlerProvider, type ToolHandlerProviderProps, clearCustomRenderRegistry, createAreaChart, createArtifact, createBarChart, createCard, createCardGrid, createColumn, createLineChart, createMarkdown, createPieChart, createSmartChart, createTable, createToolResult, getChartComponent, getComponentRegistry, getCustomRender, registerChartComponent, resultWithBarChart, resultWithCardGrid, resultWithSmartChart, resultWithTable, useAgnoActions, useAgnoChat, useAgnoClient, useAgnoSession, useAgnoToolExecution, useToolHandlers };