@antipopp/agno-react 0.1.0 → 0.3.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/dist/index.d.mts +343 -49
- package/dist/index.d.ts +343 -49
- package/dist/index.js +741 -174
- package/dist/index.mjs +706 -173
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { AgnoClient } from '@antipopp/agno-client';
|
|
4
4
|
import * as _antipopp_agno_types from '@antipopp/agno-types';
|
|
5
|
-
import { AgnoClientConfig, ChatMessage, ClientState, SessionEntry, AgentDetails, TeamDetails
|
|
6
|
-
export { AgentDetails, AgnoClientConfig, ChatMessage, ClientState, RunEvent, SessionEntry, TeamDetails, ToolCall } 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';
|
|
6
|
+
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';
|
|
7
7
|
|
|
8
8
|
interface AgnoProviderProps {
|
|
9
9
|
config: AgnoClientConfig;
|
|
@@ -19,53 +19,13 @@ declare function AgnoProvider({ config, children }: AgnoProviderProps): react_js
|
|
|
19
19
|
declare function useAgnoClient(): AgnoClient;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
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
|
|
22
|
+
* Tool handler function type (now supports generative UI)
|
|
51
23
|
*/
|
|
52
|
-
|
|
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
|
-
|
|
24
|
+
type ToolHandler = (args: Record<string, any>) => Promise<any>;
|
|
65
25
|
/**
|
|
66
|
-
*
|
|
26
|
+
* Get a custom render function by key
|
|
67
27
|
*/
|
|
68
|
-
|
|
28
|
+
declare function getCustomRender(key: string): CustomRenderFunction | undefined;
|
|
69
29
|
/**
|
|
70
30
|
* Tool execution event payload
|
|
71
31
|
*/
|
|
@@ -77,7 +37,7 @@ interface ToolExecutionEvent {
|
|
|
77
37
|
/**
|
|
78
38
|
* Hook for handling frontend tool execution (HITL)
|
|
79
39
|
*
|
|
80
|
-
* @param handlers - Map of tool names to handler functions
|
|
40
|
+
* @param handlers - Map of tool names to handler functions (local handlers)
|
|
81
41
|
* @param autoExecute - Whether to automatically execute tools when paused (default: true)
|
|
82
42
|
*
|
|
83
43
|
* @example
|
|
@@ -96,7 +56,7 @@ interface ToolExecutionEvent {
|
|
|
96
56
|
* const { isPaused, isExecuting, pendingTools } = useAgnoToolExecution(toolHandlers);
|
|
97
57
|
* ```
|
|
98
58
|
*/
|
|
99
|
-
declare function useAgnoToolExecution(handlers
|
|
59
|
+
declare function useAgnoToolExecution(handlers?: Record<string, ToolHandler>, autoExecute?: boolean): {
|
|
100
60
|
/** Whether the run is currently paused awaiting tool execution */
|
|
101
61
|
isPaused: boolean;
|
|
102
62
|
/** Whether tools are currently being executed */
|
|
@@ -113,4 +73,338 @@ declare function useAgnoToolExecution(handlers: Record<string, ToolHandler>, aut
|
|
|
113
73
|
executionError: string | undefined;
|
|
114
74
|
};
|
|
115
75
|
|
|
116
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Context value for tool handler registry
|
|
78
|
+
*/
|
|
79
|
+
interface ToolHandlerContextValue {
|
|
80
|
+
handlers: Record<string, ToolHandler>;
|
|
81
|
+
registerHandler: (name: string, handler: ToolHandler) => void;
|
|
82
|
+
unregisterHandler: (name: string) => void;
|
|
83
|
+
}
|
|
84
|
+
interface ToolHandlerProviderProps {
|
|
85
|
+
handlers?: Record<string, ToolHandler>;
|
|
86
|
+
children: React.ReactNode;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Provider component that manages global tool handlers
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* const globalHandlers = {
|
|
94
|
+
* fill_form: async (args) => {
|
|
95
|
+
* // Implementation
|
|
96
|
+
* return { success: true };
|
|
97
|
+
* }
|
|
98
|
+
* };
|
|
99
|
+
*
|
|
100
|
+
* <ToolHandlerProvider handlers={globalHandlers}>
|
|
101
|
+
* <App />
|
|
102
|
+
* </ToolHandlerProvider>
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function ToolHandlerProvider({ handlers: initialHandlers, children }: ToolHandlerProviderProps): react_jsx_runtime.JSX.Element;
|
|
106
|
+
/**
|
|
107
|
+
* Hook to access global tool handlers
|
|
108
|
+
*
|
|
109
|
+
* @returns Tool handler context value or null if not within ToolHandlerProvider
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```tsx
|
|
113
|
+
* const { handlers, registerHandler } = useToolHandlers() || { handlers: {} };
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function useToolHandlers(): ToolHandlerContextValue | null;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Generative UI Renderer
|
|
120
|
+
*
|
|
121
|
+
* Renders UI components based on specifications from the agent.
|
|
122
|
+
* Supports both registry-based components and custom render functions.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
interface GenerativeUIRendererProps {
|
|
126
|
+
/** The UI component specification to render */
|
|
127
|
+
spec: UIComponentSpec;
|
|
128
|
+
/** Optional className for styling */
|
|
129
|
+
className?: string;
|
|
130
|
+
/** Error boundary fallback */
|
|
131
|
+
onError?: (error: Error) => void;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Main Generative UI Renderer component
|
|
135
|
+
*/
|
|
136
|
+
declare function GenerativeUIRenderer({ spec, className, onError, }: GenerativeUIRendererProps): React.ReactElement;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Component Registry for Generative UI
|
|
140
|
+
*
|
|
141
|
+
* Maps component specifications to actual React components.
|
|
142
|
+
* Allows registering custom components at runtime.
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* Component renderer function type
|
|
146
|
+
*/
|
|
147
|
+
type ComponentRenderer = (props: any) => any;
|
|
148
|
+
/**
|
|
149
|
+
* Component registry class
|
|
150
|
+
*/
|
|
151
|
+
declare class ComponentRegistry {
|
|
152
|
+
private static instance;
|
|
153
|
+
private components;
|
|
154
|
+
private constructor();
|
|
155
|
+
/**
|
|
156
|
+
* Get the singleton instance
|
|
157
|
+
*/
|
|
158
|
+
static getInstance(): ComponentRegistry;
|
|
159
|
+
/**
|
|
160
|
+
* Register a component renderer
|
|
161
|
+
*/
|
|
162
|
+
register(type: string, renderer: ComponentRenderer): void;
|
|
163
|
+
/**
|
|
164
|
+
* Register multiple components at once
|
|
165
|
+
*/
|
|
166
|
+
registerBatch(components: Record<string, ComponentRenderer>): void;
|
|
167
|
+
/**
|
|
168
|
+
* Get a registered component renderer
|
|
169
|
+
*/
|
|
170
|
+
get(type: string): ComponentRenderer | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* Check if a component is registered
|
|
173
|
+
*/
|
|
174
|
+
has(type: string): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Unregister a component
|
|
177
|
+
*/
|
|
178
|
+
unregister(type: string): void;
|
|
179
|
+
/**
|
|
180
|
+
* Get all registered component types
|
|
181
|
+
*/
|
|
182
|
+
getRegisteredTypes(): string[];
|
|
183
|
+
/**
|
|
184
|
+
* Clear all registered components
|
|
185
|
+
*/
|
|
186
|
+
clear(): void;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get the global component registry instance
|
|
190
|
+
*/
|
|
191
|
+
declare function getComponentRegistry(): ComponentRegistry;
|
|
192
|
+
/**
|
|
193
|
+
* Helper to register a chart component
|
|
194
|
+
*/
|
|
195
|
+
declare function registerChartComponent(name: string, renderer: ComponentRenderer): void;
|
|
196
|
+
/**
|
|
197
|
+
* Helper to get a chart component
|
|
198
|
+
*/
|
|
199
|
+
declare function getChartComponent(name: string): ComponentRenderer | undefined;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Helper utilities for creating UI component specifications
|
|
203
|
+
*
|
|
204
|
+
* These helpers make it easy to create common UI patterns without
|
|
205
|
+
* manually constructing the full specification object.
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Chart helper options
|
|
210
|
+
*/
|
|
211
|
+
interface ChartHelperOptions {
|
|
212
|
+
/** Chart title */
|
|
213
|
+
title?: string;
|
|
214
|
+
/** Chart description */
|
|
215
|
+
description?: string;
|
|
216
|
+
/** Layout preference */
|
|
217
|
+
layout?: 'inline' | 'artifact';
|
|
218
|
+
/** Show legend */
|
|
219
|
+
showLegend?: boolean;
|
|
220
|
+
/** Show grid */
|
|
221
|
+
showGrid?: boolean;
|
|
222
|
+
/** Chart height */
|
|
223
|
+
height?: number | string;
|
|
224
|
+
/** Chart width */
|
|
225
|
+
width?: number | string;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Create a bar chart specification
|
|
229
|
+
*/
|
|
230
|
+
declare function createBarChart(data: any[], xKey: string, bars: Array<{
|
|
231
|
+
key: string;
|
|
232
|
+
label?: string;
|
|
233
|
+
color?: string;
|
|
234
|
+
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
235
|
+
/**
|
|
236
|
+
* Create a line chart specification
|
|
237
|
+
*/
|
|
238
|
+
declare function createLineChart(data: any[], xKey: string, lines: Array<{
|
|
239
|
+
key: string;
|
|
240
|
+
label?: string;
|
|
241
|
+
color?: string;
|
|
242
|
+
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
243
|
+
/**
|
|
244
|
+
* Create a pie chart specification
|
|
245
|
+
*/
|
|
246
|
+
declare function createPieChart(data: any[], dataKey: string, nameKey: string, options?: ChartHelperOptions & {
|
|
247
|
+
showLabel?: boolean;
|
|
248
|
+
}): ChartComponentSpec;
|
|
249
|
+
/**
|
|
250
|
+
* Create an area chart specification
|
|
251
|
+
*/
|
|
252
|
+
declare function createAreaChart(data: any[], xKey: string, areas: Array<{
|
|
253
|
+
key: string;
|
|
254
|
+
label?: string;
|
|
255
|
+
color?: string;
|
|
256
|
+
}>, options?: ChartHelperOptions): ChartComponentSpec;
|
|
257
|
+
/**
|
|
258
|
+
* Card grid helper options
|
|
259
|
+
*/
|
|
260
|
+
interface CardGridHelperOptions {
|
|
261
|
+
title?: string;
|
|
262
|
+
description?: string;
|
|
263
|
+
layout?: 'inline' | 'artifact';
|
|
264
|
+
columns?: {
|
|
265
|
+
default?: number;
|
|
266
|
+
sm?: number;
|
|
267
|
+
md?: number;
|
|
268
|
+
lg?: number;
|
|
269
|
+
xl?: number;
|
|
270
|
+
};
|
|
271
|
+
variant?: 'default' | 'bordered' | 'elevated';
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Create a card grid specification
|
|
275
|
+
*/
|
|
276
|
+
declare function createCardGrid(cards: CardData[], options?: CardGridHelperOptions): CardGridComponentSpec;
|
|
277
|
+
/**
|
|
278
|
+
* Create a simple card
|
|
279
|
+
*/
|
|
280
|
+
declare function createCard(id: string, title: string, description?: string, options?: {
|
|
281
|
+
image?: string;
|
|
282
|
+
metadata?: Record<string, any>;
|
|
283
|
+
actions?: CardData['actions'];
|
|
284
|
+
}): CardData;
|
|
285
|
+
/**
|
|
286
|
+
* Table helper options
|
|
287
|
+
*/
|
|
288
|
+
interface TableHelperOptions {
|
|
289
|
+
title?: string;
|
|
290
|
+
description?: string;
|
|
291
|
+
layout?: 'inline' | 'artifact';
|
|
292
|
+
sortable?: boolean;
|
|
293
|
+
filterable?: boolean;
|
|
294
|
+
pagination?: {
|
|
295
|
+
pageSize?: number;
|
|
296
|
+
pageSizeOptions?: number[];
|
|
297
|
+
};
|
|
298
|
+
density?: 'comfortable' | 'compact';
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Create a table specification
|
|
302
|
+
*/
|
|
303
|
+
declare function createTable(data: Record<string, any>[], columns: TableColumn[], options?: TableHelperOptions): TableComponentSpec;
|
|
304
|
+
/**
|
|
305
|
+
* Create a table column definition
|
|
306
|
+
*/
|
|
307
|
+
declare function createColumn(key: string, header: string, options?: {
|
|
308
|
+
width?: number | string;
|
|
309
|
+
sortable?: boolean;
|
|
310
|
+
cellType?: 'text' | 'number' | 'date' | 'badge' | 'link';
|
|
311
|
+
format?: TableColumn['format'];
|
|
312
|
+
}): TableColumn;
|
|
313
|
+
/**
|
|
314
|
+
* Create a markdown specification
|
|
315
|
+
*/
|
|
316
|
+
declare function createMarkdown(content: string, options?: {
|
|
317
|
+
title?: string;
|
|
318
|
+
description?: string;
|
|
319
|
+
layout?: 'inline' | 'artifact';
|
|
320
|
+
syntaxHighlight?: boolean;
|
|
321
|
+
}): MarkdownComponentSpec;
|
|
322
|
+
/**
|
|
323
|
+
* Create an artifact container with multiple child components
|
|
324
|
+
*/
|
|
325
|
+
declare function createArtifact(content: UIComponentSpec[], options?: {
|
|
326
|
+
title?: string;
|
|
327
|
+
description?: string;
|
|
328
|
+
variant?: 'default' | 'bordered' | 'elevated';
|
|
329
|
+
}): ArtifactComponentSpec;
|
|
330
|
+
/**
|
|
331
|
+
* Smart chart creator - automatically chooses the best chart type based on data
|
|
332
|
+
*/
|
|
333
|
+
declare function createSmartChart(data: any[], options?: {
|
|
334
|
+
title?: string;
|
|
335
|
+
description?: string;
|
|
336
|
+
layout?: 'inline' | 'artifact';
|
|
337
|
+
xKey?: string;
|
|
338
|
+
yKeys?: string[];
|
|
339
|
+
preferredType?: 'bar' | 'line' | 'area' | 'pie';
|
|
340
|
+
}): ChartComponentSpec;
|
|
341
|
+
/**
|
|
342
|
+
* Wrap data and UI into a ToolHandlerResult
|
|
343
|
+
*/
|
|
344
|
+
declare function createToolResult(data: any, ui: UIComponentSpec): ToolHandlerResult;
|
|
345
|
+
/**
|
|
346
|
+
* Quick helper: create a tool result with a bar chart
|
|
347
|
+
*/
|
|
348
|
+
declare function resultWithBarChart(data: any[], xKey: string, bars: Array<{
|
|
349
|
+
key: string;
|
|
350
|
+
label?: string;
|
|
351
|
+
color?: string;
|
|
352
|
+
}>, options?: ChartHelperOptions): ToolHandlerResult;
|
|
353
|
+
/**
|
|
354
|
+
* Quick helper: create a tool result with a smart chart
|
|
355
|
+
*/
|
|
356
|
+
declare function resultWithSmartChart(data: any[], options?: Parameters<typeof createSmartChart>[1]): ToolHandlerResult;
|
|
357
|
+
/**
|
|
358
|
+
* Quick helper: create a tool result with a card grid
|
|
359
|
+
*/
|
|
360
|
+
declare function resultWithCardGrid(cards: CardData[], options?: CardGridHelperOptions): ToolHandlerResult;
|
|
361
|
+
/**
|
|
362
|
+
* Quick helper: create a tool result with a table
|
|
363
|
+
*/
|
|
364
|
+
declare function resultWithTable(data: Record<string, any>[], columns: TableColumn[], options?: TableHelperOptions): ToolHandlerResult;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Main hook for chat interactions
|
|
368
|
+
* Provides messages, state, and methods to interact with the agent
|
|
369
|
+
*/
|
|
370
|
+
declare function useAgnoChat(): {
|
|
371
|
+
messages: ChatMessage[];
|
|
372
|
+
sendMessage: (message: string | FormData, options?: {
|
|
373
|
+
headers?: Record<string, string>;
|
|
374
|
+
}) => Promise<void>;
|
|
375
|
+
clearMessages: () => void;
|
|
376
|
+
isStreaming: boolean;
|
|
377
|
+
isPaused: boolean;
|
|
378
|
+
error: string | undefined;
|
|
379
|
+
state: ClientState;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Hook for session management
|
|
384
|
+
*/
|
|
385
|
+
declare function useAgnoSession(): {
|
|
386
|
+
sessions: SessionEntry[];
|
|
387
|
+
currentSessionId: string | undefined;
|
|
388
|
+
loadSession: (sessionId: string) => Promise<ChatMessage[]>;
|
|
389
|
+
fetchSessions: () => Promise<SessionEntry[]>;
|
|
390
|
+
isLoading: boolean;
|
|
391
|
+
error: string | undefined;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Hook for common actions like initialization, fetching agents/teams
|
|
396
|
+
*/
|
|
397
|
+
declare function useAgnoActions(): {
|
|
398
|
+
initialize: () => Promise<{
|
|
399
|
+
agents: AgentDetails[];
|
|
400
|
+
teams: TeamDetails[];
|
|
401
|
+
}>;
|
|
402
|
+
checkStatus: () => Promise<boolean>;
|
|
403
|
+
fetchAgents: () => Promise<AgentDetails[]>;
|
|
404
|
+
fetchTeams: () => Promise<TeamDetails[]>;
|
|
405
|
+
updateConfig: (updates: Partial<Parameters<(updates: Partial<_antipopp_agno_types.AgnoClientConfig>) => void>[0]>) => void;
|
|
406
|
+
isInitializing: boolean;
|
|
407
|
+
error: string | undefined;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
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 };
|