@antipopp/agno-react 0.9.0 → 0.11.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
@@ -38,6 +38,10 @@ function App() {
38
38
  },
39
39
  params: { // Optional: Global query params for all requests
40
40
  locale: 'en-US'
41
+ },
42
+ dependencies: { // Optional: Global run dependencies for sendMessage
43
+ tenantId: 'tenant-1',
44
+ locale: 'en-US'
41
45
  }
42
46
  }}
43
47
  >
@@ -133,9 +137,14 @@ await sendMessage('Hello!');
133
137
  // Send with FormData (for file uploads)
134
138
  const formData = new FormData();
135
139
  formData.append('message', 'Hello!');
136
- formData.append('file', file);
140
+ formData.append('files', file);
137
141
  await sendMessage(formData);
138
142
 
143
+ // Send with files option
144
+ await sendMessage('Hello!', {
145
+ files: [file]
146
+ });
147
+
139
148
  // Send with custom headers
140
149
  await sendMessage('Hello!', {
141
150
  headers: { 'X-Custom': 'value' }
@@ -151,6 +160,14 @@ await sendMessage('Hello!', {
151
160
  headers: { 'X-Request-ID': '12345' },
152
161
  params: { debug: 'true' }
153
162
  });
163
+
164
+ // Send with per-request dependencies (merged with/override provider config)
165
+ await sendMessage('Hello!', {
166
+ dependencies: {
167
+ locale: 'fr-FR', // overrides global dependency
168
+ feature: 'rag' // merged as a new dependency key
169
+ }
170
+ });
154
171
  ```
155
172
 
156
173
  #### `clearMessages()`
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, { ReactNode } 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
  /**
@@ -21,11 +42,16 @@ declare function useAgnoClient(): AgnoClient;
21
42
  /**
22
43
  * Tool handler function type (now supports generative UI)
23
44
  */
24
- type ToolHandler = (args: Record<string, any>) => Promise<any>;
45
+ type ToolHandler = (args: Record<string, unknown> | string) => Promise<unknown>;
25
46
  /**
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
  */
@@ -108,7 +134,7 @@ interface ToolHandlerProviderProps {
108
134
  * </ToolHandlerProvider>
109
135
  * ```
110
136
  */
111
- 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;
112
138
  /**
113
139
  * Hook to access global tool handlers
114
140
  *
@@ -122,24 +148,62 @@ declare function ToolHandlerProvider({ handlers: initialHandlers, children }: To
122
148
  declare function useToolHandlers(): ToolHandlerContextValue | null;
123
149
 
124
150
  /**
125
- * Generative UI Renderer
126
- *
127
- * Renders UI components based on specifications from the agent.
128
- * Supports both registry-based components and custom render functions.
151
+ * Hook for common actions like initialization, fetching agents/teams
129
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
+ };
130
173
 
131
- interface GenerativeUIRendererProps {
132
- /** The UI component specification to render */
133
- spec: UIComponentSpec;
134
- /** Optional className for styling */
135
- className?: string;
136
- /** Error boundary fallback */
137
- onError?: (error: Error) => void;
138
- }
139
174
  /**
140
- * Main Generative UI Renderer component
175
+ * Main hook for chat interactions
176
+ * Provides messages, state, and methods to interact with the agent
141
177
  */
142
- declare function GenerativeUIRenderer({ spec, className, onError, }: GenerativeUIRendererProps): React.ReactElement;
178
+ declare function useAgnoChat(): {
179
+ messages: ChatMessage[];
180
+ sendMessage: (message: string | FormData, options?: Parameters<(message: string | FormData, options?: _antipopp_agno_types.SendMessageOptions) => Promise<void>>[1]) => Promise<void>;
181
+ clearMessages: () => void;
182
+ cancelRun: () => Promise<void>;
183
+ isStreaming: boolean;
184
+ isRefreshing: boolean;
185
+ isPaused: boolean;
186
+ isCancelling: boolean;
187
+ currentRunId: string | undefined;
188
+ error: string | undefined;
189
+ state: ClientState;
190
+ };
191
+
192
+ /**
193
+ * Hook for session management
194
+ */
195
+ declare function useAgnoSession(): {
196
+ sessions: SessionEntry[];
197
+ currentSessionId: string | undefined;
198
+ loadSession: (sessionId: string, options?: {
199
+ params?: Record<string, string>;
200
+ }) => Promise<ChatMessage[]>;
201
+ fetchSessions: (options?: {
202
+ params?: Record<string, string>;
203
+ }) => Promise<SessionEntry[]>;
204
+ isLoading: boolean;
205
+ error: string | undefined;
206
+ };
143
207
 
144
208
  /**
145
209
  * Component Registry for Generative UI
@@ -147,16 +211,17 @@ declare function GenerativeUIRenderer({ spec, className, onError, }: GenerativeU
147
211
  * Maps component specifications to actual React components.
148
212
  * Allows registering custom components at runtime.
149
213
  */
214
+
150
215
  /**
151
216
  * Component renderer function type
152
217
  */
153
- type ComponentRenderer = (props: any) => any;
218
+ type ComponentRenderer = (props: Record<string, unknown>) => ReactNode;
154
219
  /**
155
220
  * Component registry class
156
221
  */
157
222
  declare class ComponentRegistry {
158
223
  private static instance;
159
- private components;
224
+ private readonly components;
160
225
  private constructor();
161
226
  /**
162
227
  * Get the singleton instance
@@ -190,6 +255,12 @@ declare class ComponentRegistry {
190
255
  * Clear all registered components
191
256
  */
192
257
  clear(): void;
258
+ /**
259
+ * Reset the singleton instance.
260
+ * Call this during cleanup (e.g., when AgnoProvider unmounts) to prevent memory leaks.
261
+ * After calling this, getInstance() will create a fresh instance.
262
+ */
263
+ static resetInstance(): void;
193
264
  }
194
265
  /**
195
266
  * Get the global component registry instance
@@ -211,6 +282,12 @@ declare function getChartComponent(name: string): ComponentRenderer | undefined;
211
282
  * manually constructing the full specification object.
212
283
  */
213
284
 
285
+ type DataRow = Record<string, unknown>;
286
+ type SeriesInput = Array<{
287
+ key: string;
288
+ label?: string;
289
+ color?: string;
290
+ }>;
214
291
  /**
215
292
  * Chart helper options
216
293
  */
@@ -220,7 +297,7 @@ interface ChartHelperOptions {
220
297
  /** Chart description */
221
298
  description?: string;
222
299
  /** Layout preference */
223
- layout?: 'inline' | 'artifact';
300
+ layout?: "inline" | "artifact";
224
301
  /** Show legend */
225
302
  showLegend?: boolean;
226
303
  /** Show grid */
@@ -233,40 +310,28 @@ interface ChartHelperOptions {
233
310
  /**
234
311
  * Create a bar chart specification
235
312
  */
236
- declare function createBarChart(data: any[], xKey: string, bars: Array<{
237
- key: string;
238
- label?: string;
239
- color?: string;
240
- }>, options?: ChartHelperOptions): ChartComponentSpec;
313
+ declare function createBarChart(data: DataRow[], xKey: string, bars: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
241
314
  /**
242
315
  * Create a line chart specification
243
316
  */
244
- declare function createLineChart(data: any[], xKey: string, lines: Array<{
245
- key: string;
246
- label?: string;
247
- color?: string;
248
- }>, options?: ChartHelperOptions): ChartComponentSpec;
317
+ declare function createLineChart(data: DataRow[], xKey: string, lines: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
249
318
  /**
250
319
  * Create a pie chart specification
251
320
  */
252
- declare function createPieChart(data: any[], dataKey: string, nameKey: string, options?: ChartHelperOptions & {
321
+ declare function createPieChart(data: DataRow[], dataKey: string, nameKey: string, options?: ChartHelperOptions & {
253
322
  showLabel?: boolean;
254
323
  }): ChartComponentSpec;
255
324
  /**
256
325
  * Create an area chart specification
257
326
  */
258
- declare function createAreaChart(data: any[], xKey: string, areas: Array<{
259
- key: string;
260
- label?: string;
261
- color?: string;
262
- }>, options?: ChartHelperOptions): ChartComponentSpec;
327
+ declare function createAreaChart(data: DataRow[], xKey: string, areas: SeriesInput, options?: ChartHelperOptions): ChartComponentSpec;
263
328
  /**
264
329
  * Card grid helper options
265
330
  */
266
331
  interface CardGridHelperOptions {
267
332
  title?: string;
268
333
  description?: string;
269
- layout?: 'inline' | 'artifact';
334
+ layout?: "inline" | "artifact";
270
335
  columns?: {
271
336
  default?: number;
272
337
  sm?: number;
@@ -274,7 +339,7 @@ interface CardGridHelperOptions {
274
339
  lg?: number;
275
340
  xl?: number;
276
341
  };
277
- variant?: 'default' | 'bordered' | 'elevated';
342
+ variant?: "default" | "bordered" | "elevated";
278
343
  }
279
344
  /**
280
345
  * Create a card grid specification
@@ -285,8 +350,8 @@ declare function createCardGrid(cards: CardData[], options?: CardGridHelperOptio
285
350
  */
286
351
  declare function createCard(id: string, title: string, description?: string, options?: {
287
352
  image?: string;
288
- metadata?: Record<string, any>;
289
- actions?: CardData['actions'];
353
+ metadata?: Record<string, unknown>;
354
+ actions?: CardData["actions"];
290
355
  }): CardData;
291
356
  /**
292
357
  * Table helper options
@@ -294,27 +359,27 @@ declare function createCard(id: string, title: string, description?: string, opt
294
359
  interface TableHelperOptions {
295
360
  title?: string;
296
361
  description?: string;
297
- layout?: 'inline' | 'artifact';
362
+ layout?: "inline" | "artifact";
298
363
  sortable?: boolean;
299
364
  filterable?: boolean;
300
365
  pagination?: {
301
366
  pageSize?: number;
302
367
  pageSizeOptions?: number[];
303
368
  };
304
- density?: 'comfortable' | 'compact';
369
+ density?: "comfortable" | "compact";
305
370
  }
306
371
  /**
307
372
  * Create a table specification
308
373
  */
309
- declare function createTable(data: Record<string, any>[], columns: TableColumn[], options?: TableHelperOptions): TableComponentSpec;
374
+ declare function createTable(data: DataRow[], columns: TableColumn[], options?: TableHelperOptions): TableComponentSpec;
310
375
  /**
311
376
  * Create a table column definition
312
377
  */
313
378
  declare function createColumn(key: string, header: string, options?: {
314
379
  width?: number | string;
315
380
  sortable?: boolean;
316
- cellType?: 'text' | 'number' | 'date' | 'badge' | 'link';
317
- format?: TableColumn['format'];
381
+ cellType?: "text" | "number" | "date" | "badge" | "link";
382
+ format?: TableColumn["format"];
318
383
  }): TableColumn;
319
384
  /**
320
385
  * Create a markdown specification
@@ -322,7 +387,7 @@ declare function createColumn(key: string, header: string, options?: {
322
387
  declare function createMarkdown(content: string, options?: {
323
388
  title?: string;
324
389
  description?: string;
325
- layout?: 'inline' | 'artifact';
390
+ layout?: "inline" | "artifact";
326
391
  syntaxHighlight?: boolean;
327
392
  }): MarkdownComponentSpec;
328
393
  /**
@@ -331,35 +396,31 @@ declare function createMarkdown(content: string, options?: {
331
396
  declare function createArtifact(content: UIComponentSpec[], options?: {
332
397
  title?: string;
333
398
  description?: string;
334
- variant?: 'default' | 'bordered' | 'elevated';
399
+ variant?: "default" | "bordered" | "elevated";
335
400
  }): ArtifactComponentSpec;
336
401
  /**
337
402
  * Smart chart creator - automatically chooses the best chart type based on data
338
403
  */
339
- declare function createSmartChart(data: any[], options?: {
404
+ declare function createSmartChart(data: DataRow[], options?: {
340
405
  title?: string;
341
406
  description?: string;
342
- layout?: 'inline' | 'artifact';
407
+ layout?: "inline" | "artifact";
343
408
  xKey?: string;
344
409
  yKeys?: string[];
345
- preferredType?: 'bar' | 'line' | 'area' | 'pie';
410
+ preferredType?: "bar" | "line" | "area" | "pie";
346
411
  }): ChartComponentSpec;
347
412
  /**
348
413
  * Wrap data and UI into a ToolHandlerResult
349
414
  */
350
- declare function createToolResult(data: any, ui: UIComponentSpec): ToolHandlerResult;
415
+ declare function createToolResult(data: unknown, ui: UIComponentSpec): ToolHandlerResult;
351
416
  /**
352
417
  * Quick helper: create a tool result with a bar chart
353
418
  */
354
- declare function resultWithBarChart(data: any[], xKey: string, bars: Array<{
355
- key: string;
356
- label?: string;
357
- color?: string;
358
- }>, options?: ChartHelperOptions): ToolHandlerResult;
419
+ declare function resultWithBarChart(data: DataRow[], xKey: string, bars: SeriesInput, options?: ChartHelperOptions): ToolHandlerResult;
359
420
  /**
360
421
  * Quick helper: create a tool result with a smart chart
361
422
  */
362
- declare function resultWithSmartChart(data: any[], options?: Parameters<typeof createSmartChart>[1]): ToolHandlerResult;
423
+ declare function resultWithSmartChart(data: DataRow[], options?: Parameters<typeof createSmartChart>[1]): ToolHandlerResult;
363
424
  /**
364
425
  * Quick helper: create a tool result with a card grid
365
426
  */
@@ -367,64 +428,6 @@ declare function resultWithCardGrid(cards: CardData[], options?: CardGridHelperO
367
428
  /**
368
429
  * Quick helper: create a tool result with a table
369
430
  */
370
- declare function resultWithTable(data: Record<string, any>[], columns: TableColumn[], options?: TableHelperOptions): ToolHandlerResult;
371
-
372
- /**
373
- * Main hook for chat interactions
374
- * Provides messages, state, and methods to interact with the agent
375
- */
376
- declare function useAgnoChat(): {
377
- messages: ChatMessage[];
378
- sendMessage: (message: string | FormData, options?: {
379
- headers?: Record<string, string>;
380
- params?: Record<string, string>;
381
- }) => Promise<void>;
382
- clearMessages: () => void;
383
- isStreaming: boolean;
384
- isRefreshing: boolean;
385
- isPaused: boolean;
386
- error: string | undefined;
387
- state: ClientState;
388
- };
389
-
390
- /**
391
- * Hook for session management
392
- */
393
- declare function useAgnoSession(): {
394
- sessions: SessionEntry[];
395
- currentSessionId: string | undefined;
396
- loadSession: (sessionId: string, options?: {
397
- params?: Record<string, string>;
398
- }) => Promise<ChatMessage[]>;
399
- fetchSessions: (options?: {
400
- params?: Record<string, string>;
401
- }) => Promise<SessionEntry[]>;
402
- isLoading: boolean;
403
- error: string | undefined;
404
- };
405
-
406
- /**
407
- * Hook for common actions like initialization, fetching agents/teams
408
- */
409
- declare function useAgnoActions(): {
410
- initialize: (options?: {
411
- params?: Record<string, string>;
412
- }) => Promise<{
413
- agents: AgentDetails[];
414
- teams: TeamDetails[];
415
- }>;
416
- checkStatus: (options?: {
417
- params?: Record<string, string>;
418
- }) => Promise<boolean>;
419
- fetchAgents: (options?: {
420
- params?: Record<string, string>;
421
- }) => Promise<AgentDetails[]>;
422
- fetchTeams: (options?: {
423
- params?: Record<string, string>;
424
- }) => Promise<TeamDetails[]>;
425
- updateConfig: (updates: Partial<Parameters<(updates: Partial<_antipopp_agno_types.AgnoClientConfig>) => void>[0]>) => void;
426
- isInitializing: boolean;
427
- error: string | undefined;
428
- };
431
+ declare function resultWithTable(data: DataRow[], columns: TableColumn[], options?: TableHelperOptions): ToolHandlerResult;
429
432
 
430
- 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 };
433
+ 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 };